##// END OF EJS Templates
imanay -
r238:239
parent child
Show More
@@ -1,1195 +1,1196
1 1 /*
2 2 * Servidor.c
3 3 *
4 4 * Created on: Nov 3, 2009
5 5 * Author: Jose Francisco Quenta
6 6 *
7 7 * Se implementa:
8 8 * -Carga en memoria los apuntes contenidos en un archivo de experimentos: apunte0 -> GPIO
9 9 * -Cambio de apunte.
10 10 * -Lectura del estado actual del apunte y grabado del mismo en un archivo
11 11 *
12 12 * Modified by Iván Manay since Nov 2012
13 13 * -From UDP to TCP.
14 14 * -Use of a frame for TCP communications with the central control module.
15 15 */
16 16
17 17 #include <stdio.h>
18 18 #include <stdlib.h>
19 19 #include <string.h>
20 20 #include <unistd.h>
21 21 #include <errno.h>
22 22
23 23 #include <sys/types.h>
24 24 #include <sys/socket.h>
25 25 #include <netinet/in.h>
26 26 #include <arpa/inet.h>
27 27 #include <netdb.h>
28 28 #include <time.h>
29 29 #include <math.h>
30 30
31 31 #include "./Librerias/at91gpio.h"
32 32 //#include "./Librerias/Mensajes.h"
33 33 #include "./Librerias/at91adc.h"
34 34 //clock
35 35 #include "./Librerias/at91sysclock.h"
36 36
37 37 #define PUERTO_SERVIDOR 5500
38 38 #define TAM_BUFFER 1024
39 39
40 40 #define maskc_out_beam PC30+PC28+PC26+PC24+PC22+PC20 //MSB-UP-LSB MSB-DOWN-LSB //APUNTE
41 41 #define maskc_out_cntl PC4+PC5+PC6 //MONITORING CONTROL
42 42
43 43 #define mask_sel_canal PC4 //MONITORING CONTROL
44 44 #define mask_sel_atenuacion PC5
45 45 #define mask_sel_calibracion PC6
46 46
47 47 #define maskb_in PB16+PB18+PB20+PB30+PB24+PB22 //MSB-UP-LSB MSB-DOWN-LSB //VERIFICACION
48 48
49 49 #define maskc_in_adc PC0+PC1
50 50
51 51 #define bit_up_2 0x00010000 //Mascara de cada bit a revisar: bit_up_2 es MSB
52 52 #define bit_up_1 0x00040000
53 53 #define bit_up_0 0x00100000
54 54 #define bit_dow_2 0x40000000
55 55 #define bit_dow_1 0x01000000
56 56 #define bit_dow_0 0x00400000
57 57
58 58 #define MyID 11
59 59 #define MAXPENDING 5 /* Maximum outstanding connection requests */
60 60
61 61 //parameters for the name of the output file
62 62 #define FPRE "AD" //prefix for the output file name
63 63 #define FEXT ".out" //file extension for the output file
64 64 #define FNAMELEN 40
65 65
66 66 //ADC parameters
67 67 #define REP 1 //defines how many times the data acquisation loop is repeated
68 68 #define NSAMPLES 10 //defines how many samples are taken in one data acqu-
69 69 // isation loop
70 70
71 71 #define NLOOPS 200 // Number of loops for the transmisor checking
72 72 #define CNVTIME 14.3 //defines how long it takes to get one sample. Value
73 73 // is only needed for the output file, doesn't change
74 74 // any ADC configurations
75 75 #define UREF 3.3 //Reference Voltage of ADC (max. ADC Voltage)
76 76 #define ADCRES 1023 //Resolution of ADC (10bit=1023)
77 77
78 78
79 79 char *buff_experimento= NULL;
80 80
81 81 AT91S_PIO *pioc;
82 82 AT91S_PIO *piob;
83 83 AT91S_PIO *pio_adc;
84 84 AT91S_ADC *padc;
85 85 AT91S_ADC *padd;
86 86
87 87 struct control_module_parameters {
88 88 char ID[20];
89 89 char param2[20];
90 90 char param3[20];
91 91 char param4[20];
92 92 };
93 93
94 94 typedef struct control_module_parameters cmp;
95 95
96 96 char *header = NULL;
97 97 char *TypeOfInstrument = NULL;
98 98 char *iDSource = NULL;
99 99 char *iDDestino = NULL;
100 100 char *rx_len = NULL;
101 101 char *cmd = NULL;
102 102 char *rx_data = NULL;
103 103 char *crc = NULL;
104 104
105 105 cmp parameters;
106 106 /*
107 107 * Zona de declaracion de cabeceras.
108 108 */
109 109 cmp inicializa_modulo(cmp p, char *filename);
110 110 int inicializa_ethernet();
111 111 int rxData(int, char*);
112 112 void txData(int, char*);
113 113 void inicializa_gpio();
114 114 void inicializa_adc();
115 115 void procesa_peticion(char *rx_buffer, char *tx_buffer);
116 116 int cambia_apuntamiento(char *puntero_char);
117 117 int carga_experimento(char *nombre_archivo);
118 118 char *chequeo_sistema(char *filename, char *numero_muestras);
119 119 void escribe_experimento(char *data, char filename[]);
120 120 char *Lee_experimento(char *filename);
121 121 void consigue_nombre_experimento(char *rx_data, char filename[]);
122 122 void SplitFrame(char *frame);
123 123 void intToStr( int number, char* str );
124 124 int update_app(char *filename, char *ip_number);
125 125
126 126 //ABS monitoring
127 127 //int ABS_monitoreo(int sel_atenuador, int sel_calibracion, float umbral, int pulsewidth);
128 128 char* ABS_monitoreo(int sel_atenuador, int sel_calibracion, float umbral, int pulsewidth);
129 129 AT91S_ADC * configADC1(void);
130 130 AT91S_ADC * configADC2(void);
131 131
132 132 FILE * create_Output(char*, time_t);
133 133
134 134 void writeOutput(float resultado, FILE * output);
135 135
136 136 int checkTx(long int results1[],long int results2[], float umbral, int pulsewidth);
137 137
138 138 double mediana(long int *results, unsigned int cuenta);
139 139 float getPhase(long int results1[], long int results2[]);
140 140
141 141 int fExists(char *);
142 142 int configCLK();
143 143 //
144 144
145 145 /*
146 146 *
147 147 */
148 148 int main(int argc, char *argv[]){
149 149 // arg[1] : Archivo de configuracion del modulo de control
150 150 int servSocket;
151 151 int clntSocket;
152 152
153 153 char *rx_buffer = (char *) malloc(TAM_BUFFER);
154 154 char *tx_buffer = (char *) malloc(TAM_BUFFER);
155 155 /* Inicializa parametros del modulo*/
156 156 parameters = inicializa_modulo(parameters, argv[1]);
157 157 printf("%s\n%s\n%s\n%s\n",parameters.ID, parameters.param2, parameters.param3, parameters.param4);
158 158 /* Inicializa red*/
159 159 servSocket = inicializa_ethernet();
160 160 /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */
161 161 inicializa_gpio();
162 162 inicializa_adc();
163 163
164 164 while(1){
165 165 // Recepción TCP de petición
166 166 clntSocket = rxData(servSocket, rx_buffer);
167 167 //testpoint
168 168 printf("rx:%s\n",rx_buffer);
169 169 // Procesamiento de la petición
170 170 procesa_peticion(rx_buffer, tx_buffer);
171 171 //testpoint
172 172 printf("tx:%s\n",tx_buffer);
173 173 // Respuesta del modulo de control
174 174 txData(clntSocket, tx_buffer);
175 175
176 176 }
177 177 }
178 178
179 179
180 180 int inicializa_ethernet(){
181 181
182 182 struct sockaddr_in inf_servidor;
183 183
184 184 int servSocket;
185 185
186 186 int resultado;
187 187
188 188 /* Haciendo la estructura local*/
189 189 memset(&inf_servidor, 0, sizeof(inf_servidor));
190 190 inf_servidor.sin_family= AF_INET;
191 191 inf_servidor.sin_port= htons(PUERTO_SERVIDOR);
192 192 inf_servidor.sin_addr.s_addr= INADDR_ANY;
193 193
194 194 /* Se establece el socket */
195 195 servSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP);
196 196 if (servSocket == -1){
197 197 printf("No se establecio correctamente el socket: socket()\n");
198 198 //ERROR_FATAL("No se establecio correctamente el socket: socket()\n");
199 199 exit(-1);
200 200 }
201 201
202 202 /* Se asocia el socket a un puerto y una IP */
203 203 resultado = bind(servSocket,(struct sockaddr *)&inf_servidor,sizeof(inf_servidor));
204 204 if (resultado== -1){
205 205 printf("No se establecio correctamente el socket: bind()\n");
206 206 //ERROR_FATAL("No se establecio correctamente el socket: bind()\n");
207 207 exit(-1);
208 208 }
209 209
210 210 if (listen(servSocket, MAXPENDING) < 0){
211 211 printf("listen() failed\n");
212 212 exit(-1);
213 213 }
214 214
215 215 return servSocket;
216 216
217 217 }
218 218
219 219 int rxData(int servSocket, char* rx_buffer){
220 220
221 221 int clntSocket;
222 222 struct sockaddr_in inf_cliente;
223 223 int numbytes_recibidos;
224 224 unsigned int inf_client_Len;
225 225
226 226 printf("\nEsperando solicitud de cliente...\n");
227 227
228 228 /* Set the size of the in-out parameter */
229 229 inf_client_Len = sizeof(inf_cliente);
230 230 /* Se espera hasta que un cliente se conecte */
231 231 if ((clntSocket = accept(servSocket, (struct sockaddr *) &inf_cliente,
232 232 &inf_client_Len)) < 0)
233 233 printf("accept() failed\n");
234 234
235 235 if ((numbytes_recibidos = recv(clntSocket, rx_buffer, TAM_BUFFER, 0)) < 0)
236 236 printf("recv() failed\n");
237 237
238 238 /* Se procede a procesar los datos recibidos */
239 239 rx_buffer[numbytes_recibidos]= '\0';
240 240
241 241 return clntSocket;
242 242 }
243 243
244 244 void txData(int clntSocket, char* data){
245 245
246 246 /* Echo message back to client */
247 247 if (send(clntSocket, data, strlen(data), 0) != strlen(data))
248 248 printf("send() failed\n");
249 249
250 250 close(clntSocket); /* Close client socket */
251 251 }
252 252
253 253 /*
254 254 * Esta funcion incializa el puerto GPIO
255 255 */
256 256 void inicializa_gpio(){
257 257
258 258 int desplazamiento_beam[6]={30,28,26,24,22,20}; //Desplazamientos para los pines de apunte
259 259 int desplazamiento_cntl[3]={4,5,6}; //Desplazamientos para los pines de control de monitoreo
260 260 unsigned long acumulado_ceros=0;
261 261 int i;
262 262
263 263 // Configuracion de los pines de APUNTE y control de monitoreo
264 264 pioc = pio_map(PIOC_BASE);
265 265 pio_enable(pioc, maskc_out_beam + maskc_out_cntl);
266 266 pio_disable_irq(pioc, maskc_out_beam + maskc_out_cntl);
267 267 pio_disable_multiple_driver(pioc, maskc_out_beam + maskc_out_cntl);
268 268 pio_disable_pull_ups(pioc, maskc_out_beam + maskc_out_cntl);
269 269 pio_synchronous_data_output(pioc, maskc_out_beam + maskc_out_cntl);
270 270 pio_output_enable(pioc, maskc_out_beam + maskc_out_cntl);
271 271
272 272 // Configuracion de los pines de VERIFICACION
273 273 piob = pio_map(PIOB_BASE);
274 274 pio_enable(piob, maskb_in);
275 275 pio_disable_irq(piob, maskb_in);
276 276 pio_disable_multiple_driver(piob, maskb_in);
277 277 pio_disable_pull_ups(piob, maskb_in);
278 278 pio_input_enable(piob, maskb_in);
279 279
280 280 //Pînes de ADC
281 281 pio_adc = pio_map(PIOC_BASE);
282 282 pin_adc_enable(pio_adc,maskc_in_adc); //Habilitamos PC0 para usar con ADC0 y 1
283 283 pio_disable_irq(pio_adc, maskc_in_adc);
284 284 pio_disable_multiple_driver(pio_adc, maskc_in_adc);
285 285 pio_disable_pull_ups(pio_adc, maskc_in_adc);
286 286 pio_input_enable(pio_adc, maskc_in_adc);
287 287
288 288 //Inicializando a cero los pines de apunte
289 289 for(i=0;i<6;i++)
290 290 acumulado_ceros= acumulado_ceros + (1 << desplazamiento_beam[i]);
291 291 pio_out(pioc, maskc_out_beam, acumulado_ceros, 0);
292 292
293 293 //Inicializando a cero los pines de control de monitoreo: atenuacion, calibracion y canal
294 294 for(i=0;i<3;i++)
295 295 acumulado_ceros= acumulado_ceros + (1 << desplazamiento_cntl[i]);
296 296 pio_out(pioc, maskc_out_cntl, acumulado_ceros, 0);
297 297
298 298 }
299 299
300 300 void inicializa_adc(){
301 301
302 302 if (configCLK() == 1)
303 303 printf("clock ADC enable.\n");
304 304 //configure ADC Settings
305 305 padc=configADC1();
306 306 padd=configADC2();
307 307 }
308 308
309 309
310 310 /*
311 311 * Divide rx frame into the frame components
312 312 */
313 313 void SplitFrame(char *frame){
314 314 header = malloc(4);
315 315 *header = *frame;
316 316 *(header + 1) = *(frame + 1);
317 317 *(header + 2) = *(frame + 2);
318 318 *(header + 3) = '\0';
319 319 TypeOfInstrument = malloc(4);
320 320 *TypeOfInstrument = *(frame + 3);
321 321 *(TypeOfInstrument + 1) = *(frame + 4);
322 322 *(TypeOfInstrument + 2) = *(frame + 5);
323 323 *(TypeOfInstrument + 3) = '\0';
324 324 iDSource = malloc(8);
325 325 *iDSource = *(frame + 6);
326 326 *(iDSource + 1) = *(frame + 7);
327 327 *(iDSource + 2) = *(frame + 8);
328 328 *(iDSource + 3) = *(frame + 9);
329 329 *(iDSource + 4) = *(frame + 10);
330 330 *(iDSource + 5) = *(frame + 11);
331 331 *(iDSource + 6) = *(frame + 12);
332 332 *(iDSource + 7) = '\0';
333 333 iDDestino = malloc(8);
334 334 *iDDestino = *(frame + 13);
335 335 *(iDDestino + 1) = *(frame + 14);
336 336 *(iDDestino + 2) = *(frame + 15);
337 337 *(iDDestino + 3) = *(frame + 16);
338 338 *(iDDestino + 4) = *(frame + 17);
339 339 *(iDDestino + 5) = *(frame + 18);
340 340 *(iDDestino + 6) = *(frame + 19);
341 341 *(iDDestino + 7) = '\0';
342 342 rx_len = malloc(7);
343 343 *rx_len = *(frame + 20);
344 344 *(rx_len + 1) = *(frame + 21);
345 345 *(rx_len + 2) = *(frame + 22);
346 346 *(rx_len + 3) = *(frame + 23);
347 347 *(rx_len + 4) = *(frame + 24);
348 348 *(rx_len + 5) = *(frame + 25);
349 349 *(rx_len + 6) = '\0';
350 350 cmd = malloc(5);
351 351 *cmd = *(frame + 26);
352 352 *(cmd + 1) = *(frame + 27);
353 353 *(cmd + 2) = *(frame + 28);
354 354 *(cmd + 3) = *(frame + 29);
355 355 *(cmd + 4) = '\0';
356 356
357 357 int l = atoi(rx_len);
358 358 rx_data = malloc(l + 1);
359 359 int i;
360 360 for (i = 30; i < 30 + l; i++)
361 361 *(rx_data + (i-30)) = *(frame + i);
362 362 *(rx_data + l) = '\0';
363 363 crc = malloc(2);
364 364 *crc = *(frame + 30 + l);
365 365 *(crc + 1) = '\0';
366 366 }
367 367
368 368 /*
369 369 * Esta funcion procesa el mensaje de peticion y genera respuesta
370 370 */
371 371 void procesa_peticion(char *rx_buffer, char *tx_buffer){
372 372 // int n = 0;
373 373 char filename1[50];
374 374 char filename2[] = "verificacion.txt";
375 375 char *tx_data = NULL;
376 376 char *tx_len = NULL;
377 377 SplitFrame(rx_buffer);
378 378
379 379 if ((cmd == NULL) || (rx_data == NULL)){
380 380 printf("procesarPeticion: formato de mensaje incorrecto");
381 381 //ERROR("procesarPeticion: formato de mensaje incorrecto");
382 382
383 383 }
384 384 else{
385 385 if(strcmp(cmd,"SNDF") == 0){
386 386 escribe_experimento(rx_data,filename1);
387 387 carga_experimento(filename1);
388 388 cambia_apuntamiento("0");
389 389 tx_data = (char*)malloc(3);
390 390 tx_data = "OK";
391 391 }
392 392 else if(strcmp(cmd,"GETF") == 0){
393 393 consigue_nombre_experimento(rx_data,filename1); //get a filename from frame
394 394 tx_data = Lee_experimento(filename1); //return a pointer to the content of the filename
395 395 printf("%s\n",tx_data);
396 396 printf("tp1\n");
397 397 }
398 398 else if(strcmp(cmd,"CHGB") == 0){
399 399 cambia_apuntamiento(rx_data);
400 400 tx_data = (char*)malloc(3);
401 401 tx_data = "OK";
402 402 }
403 403 else if(strcmp(cmd,"ANST") == 0){
404 404 tx_data = chequeo_sistema(filename2,rx_data);
405 405 printf("%s\n",tx_data);
406 406 }
407 407 else if(strcmp(cmd,"BGPH") == 0){
408 408 tx_data = ABS_monitoreo(1, 0, 50, 10);
409 409 // tx_data = "Not implemented\n";
410 410 printf("%s\n",tx_data);
411 411 }
412 412 else if(strcmp(cmd,"LWPH") == 0){
413 413 tx_data = ABS_monitoreo(0, 0, 50, 10);
414 414 // tx_data = "Not implemented\n";
415 415 printf("%s\n",tx_data);
416 416 }
417 417 else if(strcmp(cmd,"NTST") == 0){
418 418 tx_data = malloc(strlen(parameters.ID) + 1);
419 419 strcpy(tx_data,parameters.ID);
420 420 printf("%s\n",tx_data);
421 421 }
422 422 else if(strcmp(cmd,"UAPP") == 0){
423 423 tx_data = malloc(strlen(parameters.ID) + 1);
424 424 strcpy(tx_data,parameters.ID);
425 425 printf("%s\n",tx_data);
426 426 }
427 427 else{
428 428 tx_data = (char*)malloc(6);
429 429 tx_data = "Error";
430 430 printf("procesa_peticion: comando no reconocido");
431 431 //ERROR("procesa_peticion: comando no reconocido");
432 432 }
433 433
434 434 tx_len = malloc(7);
435 435 int number = strlen(tx_data);
436 436 intToStr(number, tx_len );
437 437
438 438 strcpy(tx_buffer,header); //3
439 439 strcat(tx_buffer,TypeOfInstrument); //3
440 440 strcat(tx_buffer,parameters.ID); //7
441 441 strcat(tx_buffer,iDSource); //7
442 442 strcat(tx_buffer,tx_len); //6
443 443 strcat(tx_buffer,cmd); //4
444 444 strcat(tx_buffer,tx_data); //?
445 445 strcat(tx_buffer,crc); //1
446 446
447 447 }
448 448
449 449 }
450 450
451 451
452 452 char* Lee_experimento(char filename[]){
453 453 char *buffer = NULL;
454 454 FILE * fd = fopen(filename,"r");
455 455 fseek(fd, 0, SEEK_END);
456 456 size_t sz = ftell(fd);
457 457 fseek(fd, 0, SEEK_SET);
458 buffer = malloc(sz);
458 buffer = malloc(sz + 1);
459 459 fread(buffer,sizeof(char),sz,fd);
460 buffer[sz] = '\0';
460 461 fclose(fd);
461 462 return buffer;
462 463 }
463 464 /*
464 465 * Esta función genera el archivo de experimento a partir de la trama TCP recibida
465 466 */
466 467 void escribe_experimento(char *p_data, char filename[]){
467 468 FILE *fd;
468 469 int i = 0;
469 470
470 471 while (*p_data != '\n'){
471 472 filename[i] = *p_data;
472 473 i++;
473 474 p_data++;
474 475 }
475 476 filename[i] = '\0';
476 477 p_data = p_data - i;
477 478 fd = fopen(filename,"w");
478 479 fprintf(fd, p_data);
479 480 fclose(fd);
480 481 }
481 482
482 483 void consigue_nombre_experimento(char *p_data, char filename[]){
483 484
484 485 int i = 0;
485 486
486 487 while (*p_data != '\n'){
487 488 filename[i] = *p_data;
488 489 i++;
489 490 p_data++;
490 491 }
491 492 filename[i] = '\0';
492 493 }
493 494
494 495 /*
495 496 * Esta funcion carga un archivo en un buffer que esta ubicado en memoria, luego
496 497 * este buffer es usado en la funcion "cambia_apuntamiento" para obtener el dato
497 498 * que sera usado en el cambio de apuntamiento.
498 499 */
499 500 int carga_experimento(char *nombre_archivo){
500 501
501 502 FILE *Archivo_Fd;
502 503
503 504 char *cadena = (char *) malloc(25);
504 505
505 506 int longitud_cadena;
506 507 int num_bytes= 0;
507 508 int num_filas= 0;
508 509
509 510 Archivo_Fd = fopen(nombre_archivo,"r"); // Se procede a abrir el archivo, segun la ruta especificada
510 511 if(!Archivo_Fd){
511 512 printf("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n");
512 513 //ERROR("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n");
513 514 return -1;
514 515 }else{
515 516
516 517 while(!feof(Archivo_Fd)){ // Se procede a calcular la longitud del archivo para separar memoria
517 518 fgets(cadena,20,Archivo_Fd);
518 519 longitud_cadena= strlen(cadena);
519 520 cadena[longitud_cadena-1] = '\0';
520 521 num_bytes = num_bytes + longitud_cadena;
521 522 num_filas++;
522 523 }
523 524
524 525 rewind(Archivo_Fd); // Se reinicia el puntero del archivo
525 526
526 527 char *buffer_temporal = (char *) malloc(num_bytes+1); // Se separa espacio de memoria segun
527 528 // la longitud del archivo
528 529 fread(buffer_temporal, sizeof(char), num_bytes, Archivo_Fd);
529 530
530 531 char *puntero= strstr(buffer_temporal,".ab1"); // Se procede a eliminar la cabecera del archivo
531 532 puntero= puntero + 12;
532 533
533 534 buff_experimento = (char *) malloc(7*(num_filas-3)); // num_bytes_fila*(num_filas-3);
534 535 strncpy(buff_experimento,puntero,7*(num_filas-3)); // Se carga en memoria la informacion del archivo
535 536
536 537 fclose(Archivo_Fd);
537 538
538 539 return 1;
539 540 }
540 541 }
541 542
542 543 /*
543 544 * Esta funcion recibe un numero en formato char, el dato se transforma a su equivalente en
544 545 * un numero entero, que sera usado para sacar un dato del buffer "buff_experimento", esta
545 546 * dato es el valor que se enviara al sistema de conmutacion RF para el cambio de apunte a
546 547 * traves del puerto GPIO.
547 548 */
548 549 int cambia_apuntamiento(char *puntero_char){
549 550
550 551 /*MSB-UP-LSB MSB-DOWN-LSB*/
551 552 int desplazamiento[6]={30,28,26,24,22,20}; // Defino los dezplazamientos que se aplicara
552 553 // al dato que ingresa para formar el número
553 554 // entero que se le pasara al puerto GPIO
554 555 // Estos números son los pines del puerto GPIO
555 556 // que se estan usando para el control
556 557
557 558 int puntero= atoi(puntero_char); // Se convierte a entero la direccion del puntero
558 559
559 560 int base= 7*puntero; // base= cantidad_bytes del dato x puntero
560 561 // cantidad de bytes es el numero de bytes que
561 562 printf("%s\n",puntero_char); // contiene cada dato, para este caso es 7
562 563 // porque es 6 bits de datos + 1 bit del cambio
563 564 // de linea.
564 565 char valor_char;
565 566 unsigned long valor;
566 567 unsigned long acumulado_ceros=0;
567 568 unsigned long acumulado_unos=0;
568 569
569 570 int offset; // Defino offset para el desplazamiento a traves
570 571 for(offset=0;offset<6;offset++){ // de cada dato que se obtiene del "buff_experimento"
571 572
572 573 valor_char= buff_experimento[base+offset]; // Obtengo el dato
573 574
574 575 if (valor_char == '0'){ // Obtengo el número acumulado segun sea un cero o un uno
575 576 valor= 0;
576 577 acumulado_ceros= acumulado_ceros + (1 << desplazamiento[offset]);
577 578 }else{
578 579 valor= 1;
579 580 acumulado_unos= acumulado_unos + (1 << desplazamiento[offset]);
580 581 }
581 582 }
582 583 pio_out(pioc, maskc_out_beam, acumulado_unos, 1);
583 584 pio_out(pioc, maskc_out_beam, acumulado_ceros, 0);
584 585
585 586 return 1;
586 587
587 588 }
588 589
589 590 /*
590 591 * Esta funcion lee "n" veces el estado del APUNTE actual y reporta
591 592 * una cadena de Verificacion.
592 593 */
593 594 char* chequeo_sistema(char *filename, char *numero_muestras){
594 595
595 596 int i;
596 597 int cnt = 0;
597 598 unsigned int entradac= 0;
598 599
599 600 char page0[250];
600 601
601 602 /*strcpy(page0,"Verificacion\n");
602 603 strcat(page0,parameters.ID);*/
603 604 strcpy(page0,parameters.ID);
604 605 strcat(page0,"\n-------\n");
605 606
606 607 char page1[8];
607 608
608 609 do{
609 610 //Inicializando arreglo
610 611 for(i=0;i<6;i++)
611 612 page1[i]='0';
612 613 page1[6] = '\n';
613 614 page1[7] = '\0';
614 615 //Lectura de puerto
615 616 entradac= pio_in(piob,maskb_in);
616 617 //Dandole formato al dato
617 618 if (!(entradac & bit_up_2))
618 619 page1[0] = '1';
619 620 if (!(entradac & bit_up_1))
620 621 page1[1] = '1';
621 622 if (!(entradac & bit_up_0))
622 623 page1[2] = '1';
623 624 if (!(entradac & bit_dow_2))
624 625 page1[3] = '1';
625 626 if (!(entradac & bit_dow_1))
626 627 page1[4] = '1';
627 628 if (!(entradac & bit_dow_0))
628 629 page1[5] = '1';
629 630
630 631 strcat(page0, page1);
631 632 cnt=cnt+1;
632 633 usleep(1*1000*1000);
633 634
634 635 }while(cnt < atoi(numero_muestras));
635 636
636 637 page0[strlen(page0)] = '\0';
637 638
638 639 char *all_pages = malloc(strlen(page0)+1);
639 640 strcpy(all_pages, page0);
640 641 return all_pages;
641 642 }
642 643
643 644 int update_app(char *filename, char *ip_number){
644 645
645 646 char cmd[80];
646 647 strcpy(cmd,"tftp -gr");
647 648 strcat(cmd," ");
648 649 strcat(cmd,filename);
649 650 strcat(cmd," ");
650 651 strcat(cmd,ip_number);
651 652
652 653 system(cmd);
653 654
654 655 printf(cmd);
655 656
656 657 return 0;
657 658 }
658 659
659 660 /*
660 661 *
661 662 */
662 663 cmp inicializa_modulo(cmp p, char *filename){
663 664 //FILE *fd = fopen("configuration.txt","r");
664 665 FILE *fd = fopen(filename,"r");
665 666 fgets(p.ID,20,fd);
666 667 p.ID[7]='\0';
667 668 fgets(p.param2,20,fd);
668 669 p.param2[10]='\0';
669 670 fgets(p.param3,20,fd);
670 671 p.param3[10]='\0';
671 672 fgets(p.param4,20,fd);
672 673 p.param4[10]='\0';
673 674 fclose(fd);
674 675 return p;
675 676 }
676 677
677 678 /*
678 679 *
679 680 */
680 681 void intToStr( int number, char* str )
681 682
682 683 {
683 684 int index = 0;
684 685
685 686 while( number > 0 )
686 687 {
687 688 int digit = number%10;
688 689 str[index++] = digit + '0';
689 690 number /= 10;
690 691 }
691 692 str[index] = '\0';
692 693 //Adding zero to the left
693 694 int n= strlen(str);
694 695 if (n == 1) {
695 696 strcat(str,"00000");
696 697 index = index + 5;
697 698 }else if(n == 2){
698 699 strcat(str,"0000");
699 700 index = index + 4;
700 701 }else if(n == 3){
701 702 strcat(str,"000");
702 703 index = index + 3;
703 704 }else if(n == 4){
704 705 strcat(str,"00");
705 706 index = index + 2;
706 707 }else if(n == 5){
707 708 strcat(str,"0");
708 709 index = index + 1;
709 710 }
710 711 //Now reverse the numbers in the string.
711 712 int position;
712 713 for( position = 0; position <= (index-1)/2; ++position )
713 714 {
714 715 char tmp = str[position];
715 716 str[position] = str[(index-1)-position];
716 717 str[(index-1)-position] = tmp;
717 718 }
718 719 }
719 720
720 721
721 722 //*****************************************************************
722 723 //ABS_monitoreo es la funci�n principal del proyecto ABS_Monitoreo.
723 724 //Esta funci�n es la que se debe agregar en otros c�digos.
724 725 //*****************************************************************
725 726 char* ABS_monitoreo(int sel_atenuador, int sel_calibracion, float umbral, int pulsewidth){
726 727
727 728 //local variables
728 729 /* AT91S_PIO *pioc;
729 730 pioc = pio_map(PIOC_BASE);
730 731 unsigned int mask_sel_canal =PC4; //Aqu� se indican los pines que se desean usar como salidas. Las constantes PCx est�n defiidas en el header at91gpio.h
731 732 unsigned int mask_sel_atenuacion =PC5;
732 733 unsigned int mask_sel_calibracion =PC6;*/
733 734
734 735 unsigned long acumulado_ceros=0;
735 736 unsigned long acumulado_unos=0;
736 737 /* AT91S_ADC *padc;
737 738 AT91S_ADC *padd;*/
738 739 FILE *fp;
739 740 long int results1[NSAMPLES], results2[NSAMPLES], results3[NSAMPLES], results4[NSAMPLES];
740 741 unsigned int i=0;
741 742 char fname[FNAMELEN];
742 743 int j=0;
743 744 time_t now;
744 745 FILE *archivo;
745 746 float phase1;
746 747 float phase2;
747 748 char page0[30];
748 749 char page1[20];
749 750
750 751 int cnt = 0;
751 752 //system("./map_clock");
752 753 /*
753 754 if (configCLK() == 1)
754 755 printf("clock ADC enable.\n");
755 756 */
756 757 /*
757 758 //configurar tres pines como salida usando als m�scaras mask_sel_canal, mask_sel_atenuacion y mask_sel_calibracion. En este caso corresponden a los pines pc4, pc5 y pc6.
758 759 pio_enable(pioc, mask_sel_canal);
759 760 pio_enable(pioc, mask_sel_atenuacion);
760 761 pio_enable(pioc, mask_sel_calibracion);
761 762 pio_output_enable(pioc, mask_sel_canal); //configurar pc4 como salida
762 763 pio_output_enable(pioc, mask_sel_atenuacion); //configurar pc5 como salida
763 764 pio_output_enable(pioc, mask_sel_calibracion); //configurar pc6 como salida
764 765 */
765 766
766 767 //Se modifican las salidas correspondientes a la selecci�n del atenuador y calibraci�n, de acuerdo a los par�metros ingresados en la funci�n ABS_monitoreo.
767 768 /*if ( sel_atenuador == 1)
768 769 pio_out(pioc, mask_sel_atenuacion, sel_atenuador,1);
769 770 else
770 771 pio_out(pioc, mask_sel_atenuacion, sel_atenuador,0);
771 772 if ( sel_calibracion == 1)
772 773 pio_out(pioc, mask_sel_calibracion, sel_calibracion,1);
773 774 else
774 775 pio_out(pioc, mask_sel_calibracion, sel_calibracion,0);*/
775 776
776 777 if ( sel_atenuador == 1)
777 778 acumulado_unos = acumulado_unos + (1 << 5);
778 779 else
779 780 acumulado_ceros = acumulado_ceros + (1 << 5);
780 781 if ( sel_calibracion == 1)
781 782 acumulado_unos = acumulado_unos + (1 << 6);
782 783 else
783 784 acumulado_ceros = acumulado_ceros + (1 << 6);
784 785
785 786
786 787 strcpy (fname, "/mnt/sd/absmonitoreo.txt"); //Direcci�n y nombre del archivo donde se desea guardar los datos.
787 788
788 789 if (fExists(fname)==0){ //si el archivo no existe, crea uno y le asigna el titulo
789 790 archivo = fopen(fname,"a+");
790 791 fprintf(archivo,"%s"," Registro de datos del ABS Control \n");
791 792 fprintf(archivo,"%s"," Fecha y hora Fase UP Fase DOWN\n");
792 793 fclose(archivo);
793 794 }
794 795
795 796 /*
796 797 //configure ADC Settings
797 798 padc=configADC1();
798 799 padd=configADC2();
799 800 */
800 801 //while (1){
801 802
802 803 ENABLE_CHANNEL(padc, ADC_CH0+ADC_CH1);
803 804 printf("\nAdquiriendo datos...\n"); //Indica en el terminal que se est�n adquiriendo datos (muestreando la se�al).
804 805
805 806
806 807 now = time(0); //Get current Time for File Name
807 808
808 809 //Se pone la salida de selecci�n de canal para seleccionar el canal 1 del detector de fase
809 810 acumulado_ceros = acumulado_ceros + (1 << 4);
810 811 pio_out(pioc, maskc_out_cntl, acumulado_ceros, 0);
811 812 pio_out(pioc, maskc_out_cntl, acumulado_unos, 1);
812 813 sleep(1);
813 814
814 815 //Se toman muestras para el canal 1 del detector de fase
815 816 /*while(1){
816 817 for(i=0; i < NSAMPLES; i++){
817 818
818 819 ADC_INIT(padc);
819 820 results1[i] = GET_ADC0(padc);
820 821 results2[i] = GET_ADC1(padd);
821 822 }
822 823
823 824 if (checkTx(results1, results2, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 1 del datector de fase //correspondan a un pulso.
824 825 break;
825 826 }
826 827
827 828 }*/
828 829
829 830 do{
830 831 for(i=0; i < NSAMPLES; i++){
831 832
832 833 ADC_INIT(padc);
833 834 results1[i] = GET_ADC0(padc);
834 835 results2[i] = GET_ADC1(padd);
835 836 }
836 837
837 838 if (checkTx(results1, results2, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 1 del datector de fase //correspondan a un pulso.
838 839 break;
839 840 }
840 841 cnt += 1;
841 842 }while (cnt < NLOOPS);
842 843
843 844 //Se pone la salida de selecci�n de canal para seleccionar el canal 2 del detector de fase
844 845 acumulado_ceros = acumulado_ceros - (1 << 4);
845 846 acumulado_unos = acumulado_unos + (1 << 4);
846 847 pio_out(pioc, maskc_out_cntl, acumulado_ceros, 0);
847 848 pio_out(pioc, maskc_out_cntl, acumulado_unos, 1);
848 849 sleep(1);
849 850
850 851
851 852 //Setoman muestras para el canal 2 del detector de fase
852 853 /* while(1){
853 854 for(i=0; i < NSAMPLES; i++){
854 855
855 856 ADC_INIT(padc);
856 857 results3[i] = GET_ADC0(padc);
857 858 results4[i] = GET_ADC1(padd);
858 859 }
859 860
860 861 if (checkTx(results3, results4, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 2 del detector de fase //correspondan a un pulso.
861 862 break;
862 863 }
863 864 }*/
864 865 cnt = 0;
865 866 do{
866 867 for(i=0; i < NSAMPLES; i++){
867 868
868 869 ADC_INIT(padc);
869 870 results3[i] = GET_ADC0(padc);
870 871 results4[i] = GET_ADC1(padd);
871 872 }
872 873
873 874 if (checkTx(results3, results4, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 2 del detector de fase //correspondan a un pulso.
874 875 break;
875 876 }
876 877 cnt += 1;
877 878 }while(cnt < NLOOPS);
878 879
879 880 //Una vez que se ha encontrado un pulso en cada canal, se calcula la fase de ambos.
880 881
881 882 phase1 = getPhase(results1, results2); //Calcular la fase del canal 1 del detector de fase.
882 883 phase2 = getPhase(results3, results4); //Calcular la fase del canal 2 del detector de fase.
883 884 //create Output File
884 885
885 886 strcpy (fname, "/mnt/sd/absmonitoreo.txt");
886 887 printf("\nTerminada la prueba # %d \n", j++);
887 888 fp=create_Output(fname, now); //Coloca la fecha y la hora en el archivo de texto
888 889 printf("mediana ch1 = %1.2f\n", phase1); //muestra resultado en terminal
889 890 printf("mediana ch2 = %1.2f\n", phase2); //muestra resultado en terminal
890 891 writeOutput(phase1, fp); //graba el resultado en el archivo de texto
891 892 writeOutput(phase2, fp); //graba el resultado en el archivo de texto
892 893 fprintf(fp, "\n"); //Pasa a la siguiente l�nea del archivo de texto
893 894 fclose(fp);
894 895 printf("Resultado guardado en %s \n", fname);
895 896
896 897 sleep(1);
897 898
898 899 strcpy(page0,parameters.ID);
899 900 strcat(page0,"\n-------\n");
900 901
901 902 //sprintf(page1,"UP:%1.2f DW:%1.2f\n",phase1, phase2);
902 903 sprintf(page1,"%1.2f %1.2f\n",phase1, phase2);
903 904 strcat(page0,page1);
904 905 char *all_pages = malloc(strlen(page0)+1);
905 906 strcpy(all_pages, page0);
906 907 return all_pages;
907 908
908 909 // }
909 910 // return 0;
910 911 }
911 912 /*=============================================================================
912 913 Function definitions
913 914 =============================================================================*/
914 915
915 916 // Configures ADC registers in order to get a sample every 10us
916 917 AT91S_ADC * configADC1(void){
917 918 //Variables a usar:
918 919 /*
919 920 unsigned int maskc_adc =PC0; //Usamos ADC0 y ADC1
920 921
921 922 //configuro pin:
922 923 AT91S_PIO *pioc;
923 924 pioc = pio_map(PIOC_BASE);
924 925 pin_adc_enable(pioc,maskc_adc); //Habilitamos PC0 para usar con ADC0 y 1
925 926 pio_disable_irq(pioc, maskc_adc);
926 927 pio_disable_multiple_driver(pioc, maskc_adc);
927 928 pio_disable_pull_ups(pioc, maskc_adc);
928 929 pio_input_enable(pioc, maskc_adc);
929 930 */
930 931
931 932 //Configuro el ADC:
932 933 //AT91S_ADC *padc;
933 934
934 935 padc = adc_map1(ADC_BASE);
935 936
936 937 //clock ADC = 1MHz
937 938 //time startup = 8us
938 939 //time sample and hold = 2us
939 940 // hold
940 941 // ___________
941 942 // start ___________| |___________
942 943 //
943 944 // | --1.2us-- | --0.15us-- |
944 945 //ADC_RESET(padc);
945 946 CONFIG_ADC(padc,ADC_TRGEN_DIS | ADC_RES_10BIT | ADC_SLEEP_NORMAL_MODE | ADC_PRESCAL | ADC_STARTUP | ADC_SHTIM);
946 947 ENABLE_CHANNEL(padc,ADC_CH0); //habilito canal 0
947 948 return padc;
948 949 }
949 950
950 951 AT91S_ADC * configADC2(void){
951 952 //Variables a usar:
952 953 /*
953 954 unsigned int maskc_adc =PC1; //Usamos ADC0 y ADC1
954 955
955 956 //configuro pin:
956 957 AT91S_PIO *piod;
957 958 piod = pio_map(PIOC_BASE);
958 959 pin_adc_enable(piod,maskc_adc); //Habilitamos PC1 para usar con ADC0 y 1
959 960 pio_disable_irq(piod, maskc_adc);
960 961 pio_disable_multiple_driver(piod, maskc_adc);
961 962 pio_disable_pull_ups(piod, maskc_adc);
962 963 pio_input_enable(piod, maskc_adc);
963 964 */
964 965 //Configuro el ADC:
965 966 //AT91S_ADC *padd;
966 967
967 968 padd = adc_map1(ADC_BASE);
968 969
969 970 //clock ADC = 1MHz
970 971 //time startup = 8us
971 972 //time sample and hold = 2us
972 973 // hold
973 974 // ___________
974 975 // start ___________| |___________
975 976 //
976 977 // | --1.2us-- | --0.15us-- |
977 978 //ADC_RESET(padc);
978 979 CONFIG_ADC(padd,ADC_TRGEN_DIS | ADC_RES_10BIT | ADC_SLEEP_NORMAL_MODE | ADC_PRESCAL | ADC_STARTUP | ADC_SHTIM);
979 980 ENABLE_CHANNEL(padd,ADC_CH1); //habilito canal 1
980 981 return padd;
981 982 }
982 983
983 984
984 985 //++++++++++++++++++++
985 986
986 987 //creats the output file with a timestamp in the name
987 988 FILE * create_Output(char *fname, time_t rawtime){
988 989 FILE *file;
989 990 char timestamp[80];//, counter[5]="dcv";
990 991 //char str[4];
991 992 struct tm * timeinfo;
992 993
993 994 //format time
994 995 timeinfo = localtime ( &rawtime );
995 996 strftime (timestamp,sizeof(timestamp),"%a %y-%m-%d %H:%M:%S %Z",timeinfo);
996 997
997 998
998 999 //Creates the file name out of the #define parameters
999 1000
1000 1001 strcpy (fname, "/mnt/sd/absmonitoreo.txt");
1001 1002 file = fopen(fname,"a+");
1002 1003 fprintf(file,"%s", timestamp);
1003 1004 //printf("\nTerminada la prueba # %d. Guardando resultado en %s\n",r, fname);
1004 1005 //printf("\nTerminada la prueba # %d/%d. Writing data to the file %s\n",r+1 , REP, fname);
1005 1006 //printf("\nAAAAAAAAAA %d...%s\n", counter[1], fname);
1006 1007 // return file pointer
1007 1008 return file;
1008 1009 }
1009 1010
1010 1011 //++++++++++++++++++++
1011 1012
1012 1013 //tests if a file already exists. returns 1 if it exists and 0 if it doesn't
1013 1014
1014 1015
1015 1016
1016 1017 //Funci�n checkTx verifica que la se�al muestreada corresponda a un pulso.
1017 1018 //results1 y results2 son los arreglos que contienen los datos muestreados por ambos canales del ADC del embebido.
1018 1019 //umbral indica qu� valor debe superar una muestra para considerarla un posible pulso o pico.
1019 1020 //pulsewidth indica cu�ntas muestras consecutivas deben superar el umbral para que se considere que se ha detectado un pulso.
1020 1021 int checkTx(long int results1[],long int results2[], float umbral, int pulsewidth){
1021 1022
1022 1023 int i, cont;
1023 1024 float z[NSAMPLES], sum, avg;
1024 1025 int isSignal, pulse;
1025 1026
1026 1027 for(i=0;i<NSAMPLES;i++){
1027 1028
1028 1029 z[i] =sqrt(1.0*results1[i]*results1[i]+1.0*results2[i]*results2[i]);
1029 1030 }
1030 1031
1031 1032 pulse = 0;
1032 1033 isSignal = 0;
1033 1034 cont =0;
1034 1035
1035 1036 sum = 0;
1036 1037 for(i=0;i<NSAMPLES;i++){
1037 1038
1038 1039 sum += z[i];
1039 1040 avg = sum/(i+1);
1040 1041 if ((z[i] - avg) > umbral){
1041 1042 if (isSignal == 1){
1042 1043 cont += 1;
1043 1044 }
1044 1045 if (cont == pulsewidth){
1045 1046 pulse = 1;
1046 1047 break;
1047 1048 }
1048 1049 isSignal = 1;
1049 1050 continue;
1050 1051 isSignal = 0;
1051 1052 cont = 0;
1052 1053 }
1053 1054 }
1054 1055
1055 1056 return pulse; //devuelve un entero: 1 si se ha detectado pulso, de lo contrario, 0.
1056 1057 }
1057 1058
1058 1059
1059 1060 int fExists(char * fname){
1060 1061 FILE * file;
1061 1062
1062 1063 file = fopen (fname, "r");
1063 1064 if (file == NULL)
1064 1065 {
1065 1066 return 0;
1066 1067 }
1067 1068 fclose(file);
1068 1069 return 1;
1069 1070 }
1070 1071
1071 1072
1072 1073 //Funci�n que calcula la mediana de un conjunto de muestras
1073 1074 double mediana(long int *results,unsigned int cuenta){
1074 1075 unsigned int i=0,j=0,aux=0;
1075 1076
1076 1077 double median=0;
1077 1078 /*Calculo mediana */
1078 1079
1079 1080 for(i=0;i<cuenta-1;i++){
1080 1081 for (j=i+1;j<cuenta;j++){
1081 1082 if(results[i]>results[j] ){
1082 1083
1083 1084 aux=results[i];
1084 1085 results[i]=results[j];
1085 1086 results[j]=aux;
1086 1087
1087 1088 }
1088 1089 }
1089 1090
1090 1091 }
1091 1092 median=results[cuenta/2];
1092 1093 return median;
1093 1094 }
1094 1095
1095 1096
1096 1097
1097 1098 //Funci�n que halla la fase de la se�al.
1098 1099 //Tiene como entradas las muestras correspondientes a la parte real e imaginaria de la se�al.
1099 1100 float getPhase(long int results1[],long int results2[]){
1100 1101
1101 1102 unsigned int count=0, i=0,umbral=1000;
1102 1103 //long int results1[];
1103 1104 //long int results2[];
1104 1105 long int power[NSAMPLES];
1105 1106 long int sumI=0,sumQ=0,I[NSAMPLES], Q[NSAMPLES],II[NSAMPLES], QQ[NSAMPLES];
1106 1107 double median1=0,median2=0;
1107 1108 long int promedioI=0,promedioQ=0;/*Calculo mediana 1*/
1108 1109 float resultado=0;
1109 1110
1110 1111 for(i=0;i<NSAMPLES;i++){
1111 1112
1112 1113 I[i] =results1[i];
1113 1114 Q[i] =results2[i];
1114 1115 }
1115 1116
1116 1117 /*Calculo mediana 1*/
1117 1118 median1=mediana(I,NSAMPLES);
1118 1119
1119 1120 /*Calculo mediana 2*/
1120 1121 median2=mediana(Q,NSAMPLES);
1121 1122
1122 1123
1123 1124
1124 1125
1125 1126
1126 1127
1127 1128 for(i=0;i<NSAMPLES;i++){
1128 1129
1129 1130 I[i] =results1[i];
1130 1131 Q[i] =results2[i];
1131 1132
1132 1133 }
1133 1134
1134 1135
1135 1136
1136 1137 for(i = 0; i < NSAMPLES ; i++){
1137 1138
1138 1139 I[i]=(I[i]-median1);
1139 1140 Q[i]=(Q[i]-median2);
1140 1141
1141 1142 }
1142 1143
1143 1144 for(i = 0; i < NSAMPLES ; i++){
1144 1145
1145 1146 power[i]=I[i]*I[i]+Q[i]*Q[i];
1146 1147
1147 1148 if(power[i] > umbral)
1148 1149 {
1149 1150
1150 1151 II[count]=I[i];
1151 1152 QQ[count]=Q[i];
1152 1153 count=count+1;
1153 1154
1154 1155 }
1155 1156
1156 1157 }
1157 1158
1158 1159 for(i = 0; i < count ; i++){
1159 1160
1160 1161 sumI=sumI+II[i];
1161 1162 sumQ=sumQ+QQ[i];
1162 1163
1163 1164 }
1164 1165
1165 1166 promedioI=sumI;
1166 1167 promedioQ=sumQ;
1167 1168
1168 1169 resultado = atan2(1.0*promedioI,1.0*promedioQ)*180/3.1416+62-44;
1169 1170
1170 1171
1171 1172 return resultado;
1172 1173
1173 1174 }
1174 1175
1175 1176
1176 1177
1177 1178 //Funci�n que muestra la fase detectada en el terminal y tambi�n la graba en el archivo de texto.
1178 1179 void writeOutput(float resultado, FILE * output){
1179 1180
1180 1181
1181 1182 //
1182 1183
1183 1184 fprintf(output," %1.2f ",resultado); //graba resultado en archivo .txt
1184 1185 //
1185 1186
1186 1187 }
1187 1188
1188 1189 int configCLK(){
1189 1190 //configuro pin:
1190 1191 AT91S_PMC *sys_clock;
1191 1192 sys_clock = clock_map(CLOCK_BASE);
1192 1193 enable_clock_adc(sys_clock);
1193 1194 //printf("clock ADC enable.\n");
1194 1195 return 1;
1195 1196 }
General Comments 0
You need to be logged in to leave comments. Login now