VYSOKÉ UČENÍ TECHNICKÉ V BRNĚ BRNO UNIVERSITY OF TECHNOLOGY
FAKULTA ELEKTROTECHNIKY A KOMUNIKAČNÍCH TECHNOLOGIÍ ÚSTAV AUTOMATIZACE A MĚŘICÍ TECHNIKY FACULTY OF ELECTRICAL ENGINEERING AND COMMUNICATION DEPARTMENT OF CONTROL AND INSTRUMENTATION
ZÁZNAMOVÁ JEDNOTKA DO UL LETADLA DATALOGGER FOR UL AIRCRAFT
PŘÍLOHA DIPLOMOVÉ PRÁCE AUTOR PRÁCE
Bc. MICHAL MAREK
AUTHOR
VEDOUCÍ PRÁCE SUPERVISOR BRNO 2013
Ing. STANISLAV KLUSÁČEK, Ph.D.
Zdrojové kódy programu Deska plošných spojů Schéma
2
kodPIC.c
Strana: 1/29
C:\SKOLA\_Diplomka\podklady\
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62:
/******** ZLD *******/ /** Zapisovac letovych udaju **/ // ***Michal Marek*** // // // /* MCU PIC24FJ64GA004 */ // // pin oznaceni // 2 RC6 // 3 RC7 RP23 // 4 RC8 RP24 // 5 RC9 RP25 // 8 RB10 RP10 // 10 AN12 RB12 AN12 // 11 AN11 RB13 AN11 // 15 AN9 RB15 AN9 // 25 AN6 RC0 AN6 // 26 AN7 RC1 AN7 // 27 AN8 RC2 AN8 // 33 RB6 RP6 // 36 RC3 RP19 // 37 RC4 RP20 // 38 RC5 RP21 // #include #include #include #include
Poslední změna: 19.5.2013 16:59:36
funkce teplota OW SD CS SD MOSI SD CLK SD MISO AD rychlost AD vyska AD napeti AD gmetr X AD gmetr Y AD gmetr Z vstup RPM Tx2 PC Rx2 PC Rx1 GPS
typ cidla DS18B20
MPX5010DP MPX5100AP MMA7260
citac impulsu
gps-04
"gmetr.h" "gps_parse.h" "eeprom.h" "DS1820.h"
unsigned int rtc_ms=0; unsigned int rtc_wh=0; unsigned short rtc_s=0; unsigned short rtc_m=0; unsigned short rtc_h=0; char batteryFlag=0; char batteryCounter=0; char ready=0; char output[200]; char change = 0; char vnc2OK=1; struct gps dataGPS = {"0000000","00","0","000000","00000","00000","0", "0000000000","0","000000000","0","0000000000","000000", N00°00.0000","0000000000"}; char kk=0; float fx_g=0; float fy_g=0; float fz_g=0; float temp_air; unsigned error2; unsigned short int offset[5]; char command = 0; unsigned int rpm; unsigned int rpm_tmp; unsigned adc_value; unsigned adc_vyska; unsigned adc_rychlost; unsigned adc_napeti_sit; unsigned adc_napeti_bat; unsigned adc_teplota; unsigned pom_adc;
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 2/29
C:\SKOLA\_Diplomka\podklady\
63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99:
Poslední změna: 19.5.2013 16:59:36
unsigned int time_old; unsigned int start_year; unsigned adc; float g; float temp_calc; float napeti_sit=0; float napeti_bat=0; unsigned rychlost; float vyska; unsigned head_temperature; float temp_pressure; char output2[50]; char uart_rd; char iic_read=2; char iic_read2=0; char uart2_rd; int vinbuf; int l=0; int lenStr=5; char txttmp[6]; bit LED_Y ; bit LED_G ; char txt[200]; char txt2[50]; signed int latitude, longitude; char *string="aaaste"; char *g_string="aaa"; char *pom="00000"; char string2[6]; int ii=0; int ii2=0; char filename[]="123456AC.csv"; char fileset = 0; char filewait = 0; // MMC module connections sbit Mmc_Chip_Select at LATC7_bit; // for writing to output pin always use latch sbit Mmc_Chip_Select_Direction at TRISC7_bit; // eof MMC module connections = "FAT16 not found"; char err_txt[20] unsigned short loop, loop2; unsigned long i, size; Buffer[512]; char char counter=0;
100: 101: 102: 103: 104: 105: 106: 107: 108: void uartinterrupt() iv IVT_ADDR_U1RXINTERRUPT ics ICS_AUTO { 109: if (U1RXIF_bit == 1) { 110: uart_rd = UART1_Read(); 111: ii++; 112: if ( uart_rd == '$') ii=0; 113: txt[ii] = uart_rd; 114: if (uart_rd == 13) 115: { 116: pom = memcpy(output,txt,ii+1); 117: ready = 1; // Ready for parsing GPS data 118: } 119: } 120: U1RXIF_bit = 0; // Set RCIF to 0 121: } 122: 123: void M_Open_File_Append() { 124: Mmc_Fat_Write(Buffer, lenStr); 125: }
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 3/29
C:\SKOLA\_Diplomka\podklady\
126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189:
Poslední změna: 19.5.2013 16:59:36
void IntDetection() org 0x003C{ //Interrupt on INT1 rpm_tmp++; IFS1.F4 = 0; //interrupt flag cleared } void RTCInterrupt() org 0x000090{ RTCIF_bit= 0; ALRMEN_bit=1; change=1; rpm=rpm_tmp*60; rpm_tmp=0; } void rtc_get(){ RTCWREN_bit=1; if (!RTCSYNC_bit) { RTCPTR_0_bit=1; RTCPTR_1_bit=0; rtc_wh=RTCVAL;
// povolení úprav // probíhající synchronizace?
rtc_ms=RTCVAL; } RTCWREN_bit=0; rtc_s= bcd2dec(rtc_ms & 0xFF); rtc_m= bcd2dec((rtc_ms>>8)& 0xFF) ; rtc_h= bcd2dec(rtc_wh & 0xFF);
// // // // //
nastavení ukazatele na registr nastavení ukazatele na registr čtení registru WKDYHR, ukazatel automaticky -1 čtení registru MINSEC
// // // //
zakázání úprav zpracování hodnot zpracování hodnot zpracování hodnot
} void vinculumSend(char* datasend, int len) { int sendcounter=0; for (sendcounter=0;sendcounter
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 4/29
C:\SKOLA\_Diplomka\podklady\
190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251:
Poslední změna: 19.5.2013 16:59:36
asm disi #5 asm mov #0x55, w7 asm mov w7, NVMKEY asm mov #0xAA, w8 asm mov w8, NVMKEY asm bset RCFGCAL, #13 asm nop asm nop RTCWREN_bit=1; RTCPTR_0_bit=1; RTCPTR_1_bit=0; RTCVAL=0; RTCVAL=0; AMASK_0_bit=1; AMASK_1_bit=0; AMASK_2_bit=0; AMASK_3_bit=0; ALRMEN_bit=1; RTCEN_bit=1; RTCWREN_bit=0; ADPCFG = 0x003F; TRISA = 0x0600; LATA = 0x0000; TRISB = 0xE010; LATB = 0x0000; TRISC = 0x0135; LATC = 0x0000; ODC1_bit=1; IPC5 = IPC5 | 0x0010; IPC2 = IPC2 | 0x7000;
// Initialize AN pins as digital // Initialize PORTA as output // Initialize PORTA value // Initialize PORTB as output // Initialize PORTB value // Initialize PORTC as output // Initialize PORTC value
LATB12_bit = 1; // batery rele on LATC1_bit = 0; // reset vinculum LATA8_bit = 0; // reset gps LATA0_bit = 0; // vnc cts Unlock_IOLOCK(); PPS_Mapping_NoLock(24, _OUTPUT,_SDO1); // MOSI PPS_Mapping_NoLock(25, _OUTPUT,_SCK1OUT); // CLK PPS_Mapping_NoLock(10, _INPUT,_SDI1); // MISO PPS_Mapping_NoLock(6, _INPUT,_INT1); // RPM PPS_Mapping_NoLock(21, _INPUT,_U1RX); // GPS RX PPS_Mapping_NoLock(7, _OUTPUT,_U1TX); // GPS TX PPS_Mapping_NoLock(19, _INPUT,_U2RX); // PC RX PPS_Mapping_NoLock(20, _OUTPUT,_U2TX); // PC TX Lock_IOLOCK(); ADC1_Init(); asm CLRWDT; ready = 0; // Initialize variables i = 0; counter=0; fileset = 0; filewait = 0; SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_64, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE); // LATA1_bit =~ LATA1_bit; Delay_ms(300); UART1_Init(9600); // Initialize UART module at 9600
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 5/29
C:\SKOLA\_Diplomka\podklady\
Poslední změna: 19.5.2013 16:59:36
252: Delay_ms(300); 253: UART2_Init(115200); // Initialize UART module at 57600 254: Delay_ms(300); 255: //LATA1_bit =~ LATA1_bit; 256: DS18B20_init(&PORTC,6); 257: // Delay_ms(100); 258: // UART2_Write_Text("RESET"); 259: // UART2_Write(13); 260: URXISEL_1_U1STA_bit = 0; 261: URXISEL_1_U2STA_bit = 0; 262: NSTDIS_bit = 1; // no nesting of interrupts 263: U1RXIF_bit = 0; // ensure interrupt not pending 264: U1RXIE_bit = 1; 265: U2RXIF_bit = 0; // ensure interrupt not pending 266: U2RXIE_bit = 1; 267: 268: INT1IE_bit=1; 269: INT1EP_bit=1; 270: //--- init the FAT library 271: if (!Mmc_Fat_Init()) { 272: // reinitialize spi at higher speed 273: SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_4, 274: _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE); 275: } 276: else { 277: onerror (); 278: } 279: 280: asm CLRWDT; 281: I2C1_Init(100000); 282: Delay_ms(100); 283: TRISB.B2 = 1; 284: TRISB.B3 = 1; 285: I2C2_Init(100000); 286: Delay_ms(100); 287: asm CLRWDT; 288: 289: } 290: void napeti() 291: { 292: adc_napeti_sit = ADC1_Get_Sample(9); 293: adc_napeti_bat = ADC1_Get_Sample(10); 294: napeti_sit = adc_napeti_sit*0.0322266*1.15; 295: if (napeti_sit>10) 296: { 297: batteryFlag='M'; 298: LATA1_bit =0; 299: } 300: else 301: { 302: napeti_bat = adc_napeti_bat*0.0322266*1.17; 303: batteryFlag='B'; 304: LATA1_bit =~ LATA1_bit; 305: if ((rpm<100)&&(rychlost==0)) 306: { 307: batteryCounter++; 308: asm CLRWDT; 309: if(batteryCounter>2) 310: { 311: LATA1_bit=0; 312: Delay_ms(100); 313: LATA1_bit=1;
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 6/29
C:\SKOLA\_Diplomka\podklady\
Poslední změna: 19.5.2013 16:59:36
314: Delay_ms(100); 315: LATA1_bit=0; 316: Delay_ms(100); 317: LATA1_bit=1; 318: Delay_ms(100); 319: Mmc_Fat_Close(); 320: LATB12_bit=0; 321: } 322: } 323: else 324: { 325: batteryCounter=0; 326: } 327: } 328: } 329: void main() { 330: 331: init(); 332: Delay_ms(1000); 333: asm CLRWDT; 334: if (Button(&PORTA, 9, 10, 0)) 335: { 336: LATA7_bit=1; 337: LATC1_bit = 1; // start vinculum 338: 339: while(1) 340: { 341: asm CLRWDT; 342: LATA1_bit =~ LATA1_bit; 343: adc_napeti_sit = ADC1_Get_Sample(9); 344: napeti_sit = adc_napeti_sit*0.0322266; 345: if (napeti_sit<10) 346: LATB12_bit=0; 347: Delay_ms(1000); 348: } 349: } 350: LATA8_bit=1; // start GPS 351: LATA1_bit=0; 352: LATC1_bit = 1; // start vinculum 353: asm CLRWDT; 354: Delay_ms(1000); 355: 356: get_offset(&offset); 357: asm CLRWDT; 358: RTCIE_bit=1; 359: while(1) 360: { 361: OERR_bit = 0; // Set OERR to 0 362: FERR_bit = 0; // Set FERR to 0 363: 364: if (ready==1){ 365: ready = gps_parse_f(&dataGPS,&output); 366: } 367: if ((fileset==0)&&(filewait==0)) 368: { 369: if (strcmp(datagps.Date, "000000")) 370: { 371: filename[0]=dataGPS.Date[4]; 372: filename[1]=dataGPS.Date[5]; 373: filename[2]=dataGPS.Date[2]; 374: filename[3]=dataGPS.Date[3]; 375: filename[4]=dataGPS.Date[0]; 376: filename[5]=dataGPS.Date[1]; 377: Mmc_Fat_Assign(filename, 0x80);
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 7/29
C:\SKOLA\_Diplomka\podklady\
378:
Poslední změna: 19.5.2013 16:59:36
Mmc_Fat_Append(); append vinculumSend(filename,8); filewait=1; LATA1_bit=1; } loop++; if (loop>50) { LATA1_bit =~ LATA1_bit; loop=0; } Delay_ms(10); } if (filewait==1) { if(vnc2OK==1) fileset=1; } if ((change==1)&&(fileset==1)) { asm CLRWDT; napeti(); gmetr_f(&fx_g, &fy_g, &fz_g, &offset); asm CLRWDT; adc_teplota = ADC1_Get_Sample(6); temp_air=DS18B20_teplota();
// Prepare file for
379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: I2C2_Start(); // issue I2C start signal 403: I2C2_Write(0x9B); // send byte via I2C (device address + R) 404: adc_rychlost = I2C2_Read(0); // Read the data (NO acknowledge) 405: adc_rychlost = (adc_rychlost<<8) + I2C2_Read(1); // Read the data (NO acknowledge)I2C1_Read(0); // Read the data (NO acknowledge) 406: I2C2_Stop(); 407: 408: I2C1_Start(); // issue I2C start signal 409: I2C1_Write(0x9B); // send byte via I2C (device address + R) 410: adc_vyska = I2C1_Read(0); // Read the data (NO acknowledge) 411: adc_vyska = (adc_vyska<<8) + I2C1_Read(1); // Read the data (NO acknowledge)I2C1_Read(0); // Read the data (NO acknowledge) 412: I2C1_Stop(); 413: asm CLRWDT; 414: 415: counter++; 416: if (counter>20){ 417: if ((!strcmp(datagps.Altitude, "0000000"))|(!strcmp(datagps.Longitude, "0000000000"))) 418: { asm RESET; } 419: else {counter=0;} 420: } 421: temp_calc=3.6*sqrt(4.4288 * adc_rychlost - 725.624) + *offset - 128 ; 422: if (temp_calc <40 ) temp_calc = 0; 423: rychlost = temp_calc; 424: asm CLRWDT; 425: temp_pressure = 27.1267*adc_vyska + 10555.56; 426: 427: temp_calc = -(log(temp_pressure)-11.5261)*27671.23 + *(offset+1) - 128 ; 428: vyska = temp_calc; 429: 430: temp_calc=-35*log(adc_teplota*0.00322266) + 41; 431: head_temperature=temp_calc; 432: rtc_get(); 433: 434: asm CLRWDT; 435: sprintf(Buffer,"%.2s-%.2s-20%.2s,%.2s:%.2s:%.2s,%s%.3s°%.2s.%.4s %s%.2s°%.2s.%.4s,%s,%s,%s,%.2s:%.2s:%.2s,%s,%s,%02u:%02u:%02u,%u,%.1f,%.1f,%1.2f, %1.2f,%1.2f,%c,%.2f,%.2f,%u,%u,%.2f\n",
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 8/29
C:\SKOLA\_Diplomka\podklady\
436: 437: 438:
439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497:
Poslední změna: 19.5.2013 16:59:36
datagps.Date,datagps.Date+2,datagps.Date+4, datagps.UTC_Time,datagps.UTC_Time+2,datagps.UTC_Time+4, dataGPS.Indicator_E_or_W,datagps.Longitude,datagps.Longitude+3, datagps.Longitude+6,datagps.Indicator_N_or_S,datagps.Latitude,datagps.Latitude+2, datagps.Latitude+5, datagps.RMC_Status, datagps.Course_Over_Ground, datagps.Speed_Over_Ground, datagps.UTC_Time_Alt,datagps.UTC_Time_Alt+2,datagps.UTC_Time_Alt+4, datagps.Altitude, datagps.Satelit, rtc_h,rtc_m,rtc_s, rychlost,//rychlost vyska,temp_pressure,//vyska fx_g, fy_g, fz_g, batteryFlag,napeti_sit,//napeti sit napeti_bat,//napeti baterie rpm, head_temperature,//adc_teplota,//teplota hlav temp_air ); asm CLRWDT; lenStr= strlen(Buffer); M_Open_File_Append(); asm CLRWDT; vinculumSend(&Buffer, lenStr); change=0; } } }
******************************************************************* gps_parse.h ******************************************************************* #ifndef GPS_PARSE_H #define GPS_PARSE_H struct gps{ char Altitude[8]; char Satelit[3]; char Mode[2]; char Date[7]; char Course_Over_Ground[6]; char Speed_Over_Ground[6]; char Indicator_E_or_W[2]; char Longitude[11]; char Indicator_N_or_S[2]; char Latitude[10]; char RMC_Status[2]; char UTC_Time[11]; char Message_ID[7]; char Position[25]; char UTC_Time_Alt[11]; } ;
char gps_parse_f(struct gps * dataGPS, char*output); #endif
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 9/29
C:\SKOLA\_Diplomka\podklady\
498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561:
Poslední změna: 19.5.2013 16:59:36
******************************************************************* gps_parse.c ******************************************************************* #include "gps_parse.h"
char j=0; char k=0; char nn=0;
char gps_parse_f(struct gps * dataGPS, char* output) { asm CLRWDT; if (output[0]=='$') {if (output[1]=='G') {if (output[2]=='P') {if (output[3]=='R') {if (output[4]=='M') {if (output[5]=='C') { j=1; }}}}}} if (output[0]=='$') {if (output[1]=='G') {if (output[2]=='P') {if (output[3]=='G') {if (output[4]=='G') {if (output[5]=='A') { j=2; }}}}}} if(j == 1) { k=0; nn=0; while(output[k]!=',') { if (nn>6) break; dataGPS->Message_ID[nn]=output[k]; nn++; k++; } k++; dataGPS->Message_ID[nn]='\0'; nn=0; while(output[k]!=',') { if (nn>10) break; dataGPS->UTC_Time[nn]=output[k]; nn++; k++; } k++; dataGPS->UTC_Time[nn]='\0'; nn=0; while(output[k]!=',') { if (nn>1) break; dataGPS->RMC_Status[nn]=output[k]; nn++; k++; } k++; dataGPS->RMC_Status[nn]='\0'; nn=0;
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 10/29
C:\SKOLA\_Diplomka\podklady\
562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625:
Poslední změna: 19.5.2013 16:59:36
while(output[k]!=',') { if (nn>9) break; dataGPS->Latitude[nn]=output[k]; nn++; k++; } k++; dataGPS->Latitude[nn]='\0'; nn=0; while(output[k]!=',') { if (nn>1) break; dataGPS->Indicator_N_or_S[nn]=output[k]; nn++; k++; } k++; dataGPS->Indicator_N_or_S[nn]='\0'; nn=0; while(output[k]!=',') { if (nn>10) break; dataGPS->Longitude[nn]=output[k]; nn++; k++; } k++; dataGPS->Longitude[nn]='\0'; nn=0; while(output[k]!=',') { if (nn>1) break; dataGPS->Indicator_E_or_W[nn]=output[k]; nn++; k++; } k++; dataGPS->Indicator_E_or_W[nn]='\0'; nn=0; while(output[k]!=',') { if (nn>5) break; dataGPS->Speed_Over_Ground[nn]=output[k]; nn++; k++; } k++; dataGPS->Speed_Over_Ground[nn]='\0'; nn=0; while(output[k]!=',') { if (nn>5) break; dataGPS->Course_Over_Ground[nn]=output[k]; nn++; k++; } k++; dataGPS->Course_Over_Ground[nn]='\0'; nn=0; while(output[k]!=',') { if (nn>6) break; dataGPS->Date[nn]=output[k];
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 11/29
C:\SKOLA\_Diplomka\podklady\
626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689:
Poslední změna: 19.5.2013 16:59:36
nn++; k++; } asm CLRWDT; dataGPS->Date[nn]='\0'; dataGPS->Mode[0]=output[k+3]; dataGPS->Mode[1]='\0'; j=0; } asm CLRWDT; if(j == 2) { // LATA1_bit = ~LATA1_bit; k=0; nn=0; while(output[k]!=',') { if (nn>6) break; dataGPS->Message_ID[nn]=output[k]; nn++; k++; } k++; dataGPS->Message_ID[nn]='\0'; nn=0; while(output[k]!=',') { if (nn>10) break; dataGPS->UTC_Time_Alt[nn]=output[k]; nn++; k++; } k++; dataGPS->UTC_Time[nn]='\0'; nn=0; while(output[k]!=',') { k++; } k++; while(output[k]!=',') { k++; } k++; while(output[k]!=',') { k++; } k++; while(output[k]!=',') { k++; } k++; while(output[k]!=',') { k++; } k++; nn=0; while(output[k]!=',') { if (nn>2) break;
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 12/29
C:\SKOLA\_Diplomka\podklady\
690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753:
Poslední změna: 19.5.2013 16:59:36
dataGPS->Satelit[nn]=output[k]; nn++; k++; } k++; dataGPS->Satelit[nn]='\0'; while(output[k]!=',') { k++; } k++; nn=0; while(output[k]!=',') { if (nn>7) break; dataGPS->Altitude[nn]=output[k]; nn++; k++; } k++; dataGPS->Altitude[nn]='\0'; j=0; } asm CLRWDT; return 0; }
******************************************************************* ds1820.h ******************************************************************* #ifndef _DS1820_H #define _DS1820_H void DS18B20_init(char * iport, unsigned int ipin); float DS18B20_teplota(); #endif
******************************************************************* ds1820.c *******************************************************************
unsigned int xpin; char * xport; unsigned int temp; unsigned int temp_fraction; float temp_out=0.0; char text[8]; signed char negative;
void DS18B20_init() { Ow_Reset(&PORTC, Ow_Write(&PORTC, Ow_Write(&PORTC, Ow_Write(&PORTC, Ow_Write(&PORTC, Ow_Write(&PORTC, }
PSPad editor 4.5.6 (2427) www.pspad.com
6); 6, 0xCC); 6, 0x4E); 6, 0x00); 6, 0x00); 6, 0x3F);
// // // // // //
19.5.2013 23:40:38
Reset signál Příkaz SKIP_ROM Příkaz nastavení Th+Tl+config Th Tl config - 10bit rozlišení
Michal
kodPIC.c
Strana: 13/29
C:\SKOLA\_Diplomka\podklady\
754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817:
Poslední změna: 19.5.2013 16:59:36
float DS18B20_teplota() { Ow_Reset(&PORTC, 6); Ow_Write(&PORTC, 6, 0xCC); Ow_Write(&PORTC, 6, 0x44); Delay_us(120); Ow_Reset(&PORTC, 6); Ow_Write(&PORTC, 6, 0xCC); Ow_Write(&PORTC, 6, 0xBE); temp = Ow_Read(&PORTC, 6); temp = (Ow_Read(&PORTC, 6) << 8) + temp;
// // // // // // // // //
Reset signál Příkaz SKIP_ROM Příkaz CONVERT_T Doba nutná pro převod T Reset signál Příkaz SKIP_ROM Příkaz READ_SCRATCHPAD čtení prvního byte čtení druhého byte
if (temp & 0x8000) { temp = ~temp + 1; negative = -1; } else { negative = 1; }
// kontrola záporné teploty
temp_out = temp >> 4; temp_fraction = temp >> 2 ; temp_fraction &= 0x03; temp_out = temp_out + temp_fraction * 0.25; temp_out *= negative;
// // // // //
return temp_out;
// zjištěná teplota
// převod na kladné číslo // nastavení koeficeintu
// nastavení koeficeintu
získání získání získání výpočet výpočet
celé části desetinné části desetinné části teploty teploty
}
******************************************************************* gmetr.h ******************************************************************* #ifndef GMETR_H #define GMETR_H void gmetr_f(float * x, float * y, float * z,unsigned short int * offset); #endif ******************************************************************* gmetr.c ******************************************************************* #include "gmetr.h" signed char x_g; signed char y_g; signed char z_g; void gmetr_f(float * x, float * y, float * z, unsigned short int * offset){ I2C1_Start(); // issue I2C start signal I2C1_Write(0x3A); // send byte via I2C (device address + W) I2C1_Write(0x16); // send byte (address of EEPROM location) I2C1_Write(0x01); // send data (data to be written) I2C1_Stop(); // issue I2C stop signal I2C1_Start(); // issue I2C start signal I2C1_Write(0x3A); // send byte via I2C (device address + W) I2C1_Write(0x06); // send byte (data address) I2C1_Restart(); // issue I2C signal repeated start I2C1_Write(0x3B); // send byte (device address + R)
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 14/29
C:\SKOLA\_Diplomka\podklady\
818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876: 877: 878: 879: 880: 881:
x_g = I2C1_Read(1); I2C1_Stop(); I2C1_Start(); I2C1_Write(0x3A); I2C1_Write(0x07); I2C1_Restart(); I2C1_Write(0x3B); y_g = I2C1_Read(1); I2C1_Stop(); I2C1_Start(); I2C1_Write(0x3A); I2C1_Write(0x08); I2C1_Restart(); I2C1_Write(0x3B); z_g = I2C1_Read(1); I2C1_Stop();
Poslední změna: 19.5.2013 16:59:36
// Read the data (NO acknowledge) // issue I2C stop signal // issue I2C start signal // send byte via I2C (device address + W) // send byte (data address) // issue I2C signal repeated start // send byte (device address + R) // Read the data (NO acknowledge) // issue I2C stop signal // issue I2C start signal // send byte via I2C (device address + W) // send byte (data address) // issue I2C signal repeated start // send byte (device address + R) // Read the data (NO acknowledge) // issue I2C stop signal
*x = 0.063*(x_g+*(offset+2)-128); *y = 0.063*(y_g+*(offset+3)-128); *z = 0.063*(z_g+*(offset+4)-128); }
******************************************************************* eeprom.h ******************************************************************* #ifndef EEPROM_H #define EEPROM_H void set_offset(signed int * offset); void get_offset(signed int * offset); #endif ******************************************************************* eeprom.c ******************************************************************* #include "eeprom.h" char ei=0; char ea=0; void set_offset(unsigned short int * offset){ for ( ei = 0; ei<5; ei++ ) { ea = *(offset+ei); I2C2_Start(); // issue I2C start signal I2C2_Write(0xA0); // send byte via I2C (device address + W) I2C2_Write(ei+10); // send byte (address of EEPROM location) I2C2_Write(ea); // send data (data to be written) I2C2_Stop(); // issue I2C stop signal Delay_5ms(); } } void get_offset(unsigned short int * offset){ for ( ei = 0; ei<5; ei++ ) {
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 15/29
C:\SKOLA\_Diplomka\podklady\
882: 883: 884: 885: 886: 887: 888: 889: 890: 891: 892: 893: 894: 895: 896: 897: 898: 899: 900: 901: 902: 903: 904: 905: 906: 907: 908: 909: 910:
I2C2_Start(); // I2C2_Write(0xA0); // I2C2_Write(ei+10); I2C2_Restart(); // I2C2_Write(0xA1); // *(offset+ei) = I2C2_Read(1); I2C2_Stop(); // Delay_5ms(); }
Poslední změna: 19.5.2013 16:59:36
issue I2C start signal send byte via I2C (device address + W) // send byte (address of EEPROM location) issue I2C signal repeated start send byte (device address + R) // Read the data (NO acknowledge) issue I2C stop signal
}
******************************************************************* ******************************************************************* Vinculum-II ******************************************************************* *******************************************************************
/* ** Filename: ZLD_iomux.c ** ** Automatically created by Application Wizard 2.0.0 ** ** Part of solution ZLD in project ZLD ** ** Comments: ** ** Important: Sections between markers "FTDI:S*" and "FTDI:E*" will be overwritten by 911: ** the Application Wizard 912: */ 913: #include "vos.h" 914: 915: void iomux_setup() 916: { 917: /* FTDI:SIO IOMux Functions */ 918: unsigned char packageType; 919: 920: packageType = vos_get_package_type(); 921: if (packageType == VINCULUM_II_32_PIN) 922: { 923: // Debugger to pin 11 as Bi-Directional. 924: vos_iomux_define_bidi(199, IOMUX_IN_DEBUGGER, IOMUX_OUT_DEBUGGER); 925: // GPIO_Port_A_1 to pin 12 as OUTPUT. 926: //vos_iomux_define_output(12, IOMUX_OUT_GPIO_PORT_A_1); 927: // GPIO_Port_A_2 to pin 14 as OUTPUT. 928: vos_iomux_define_output(14, IOMUX_OUT_GPIO_PORT_A_2); 929: // GPIO_Port_A_3 to pin 15 as OUTPUT. 930: vos_iomux_define_output(15, IOMUX_OUT_GPIO_PORT_A_3); 931: // UART_TXD to pin 23 as Output. 932: vos_iomux_define_output(23, IOMUX_OUT_UART_TXD); 933: // UART_RXD to pin 24 as Input. 934: vos_iomux_define_input(24, IOMUX_IN_UART_RXD); 935: // UART_RTS_N to pin 25 as Output. 936: vos_iomux_define_output(25, IOMUX_OUT_UART_RTS_N); 937: // UART_CTS_N to pin 26 as Input. 938: vos_iomux_define_input(26, IOMUX_IN_UART_CTS_N); 939: // GPIO_Port_A_4 to pin 29 as Input. 940: //vos_iomux_define_output(29, IOMUX_OUT_GPIO_PORT_A_4); 941: // GPIO_Port_B_5 to pin 30 as Input. 942: //vos_iomux_define_input(30, IOMUX_IN_GPIO_PORT_B_5); 943: // GPIO_Port_B_6 to pin 31 as Input. 944: vos_iomux_define_input(31, IOMUX_IN_GPIO_PORT_B_6);
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 16/29
C:\SKOLA\_Diplomka\podklady\
945: 946: 947: 948: 949: 950: 951: 952: 953: 954: 955: 956: 957: 958: 959: 960: 961: 962: 963: 964:
Poslední změna: 19.5.2013 16:59:36
// GPIO_Port_B_7 to pin 32 as Input. //vos_iomux_define_input(32, IOMUX_IN_GPIO_PORT_B_7); } /* FTDI:EIO */ } *************************************************************
/* ** Filename: ZLD.c ** ** Automatically created by Application Wizard 2.0.0 ** ** Part of solution ZLD in project ZLD ** ** Comments: ** ** Important: Sections between markers "FTDI:S*" and "FTDI:E*" will be overwritten by 965: ** the Application Wizard 966: */ 967: 968: #include "ZLD.h" 969: 970: /* Default settings for UART interface */ 971: #define DEF_UART_BAUD UART_BAUD_115200 972: #define DEF_UART_DATA_BITS UART_DATA_BITS_8 973: #define DEF_UART_FLOW UART_FLOW_RTS_CTS 974: #define DEF_UART_STOP_BITS UART_STOP_BITS_1 975: #define DEF_UART_PARITY UART_PARITY_NONE 976: 977: /* FTDI:STP Thread Prototypes */ 978: vos_tcb_t *tcbSETUP; 979: vos_tcb_t *tcbUART; 980: vos_tcb_t *tcbBOMS; 981: //vos_tcb_t *tcbFIRMWARE; 982: vos_tcb_t *tcbCOPYD; 983: 984: void setup(); 985: void UART(); 986: void BOMS(); 987: void COPYD(); 988: //void firmware(); 989: /* FTDI:ETP */ 990: 991: /* FTDI:SDH Driver Handles */ 992: VOS_HANDLE hUSBHOST_1; // USB Host Port 1 993: VOS_HANDLE hUSBHOST_2; // USB Host Port 2 994: VOS_HANDLE hUART; // UART Interface Driver 995: VOS_HANDLE hGPIO_PORT_A; // GPIO Port A Driver 996: VOS_HANDLE hFAT_FILE_SYSTEM_1; // FAT File System for FAT32 and FAT16 997: VOS_HANDLE hFAT_FILE_SYSTEM_2; // FAT File System for FAT32 and FAT16 998: VOS_HANDLE hBOMS_1; // Bulk Only Mass Storage for USB disks 999: VOS_HANDLE hBOMS_2; // Bulk Only Mass Storage for USB disks 1000: VOS_HANDLE hGPIO_PORT_B; 1001: /* FTDI:EDH */ 1002: 1003: vos_semaphore_t setupSem; 1004: vos_semaphore_t command; 1005: vos_semaphore_t cmdCpy; 1006: //vos_semaphore_t write; 1007: vos_semaphore_t dataSem;
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 17/29
C:\SKOLA\_Diplomka\podklady\
1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023:
Poslední změna: 19.5.2013 16:59:36
vos_mutex_t mBufAccess; fat_context fatContext1; fat_context fatContext2; FILE *file; unsigned char buf[300]; unsigned short pBuf = 0; unsigned char filenameu[] = "TESTZLD .CSV"; unsigned char fileuart = 0; unsigned char usbout = 0; /* Declaration for IOMUx setup function */ void iomux_setup(); void monError(); void LED1(); void NLED1(); unsigned char copyFile(fat_context fatContextSrc, fat_context fatContextDest, char *filename); unsigned char changeDirUp(fat_context fatContext); unsigned char copyDir(fat_context fatContextSrc, fat_context fatContextDest); unsigned char copyDisk(fat_context fatContextSrc, fat_context fatContextDest); //fat_context *opendisk(VOS_HANDLE hUsbHost, VOS_HANDLE hBoms);
1024: 1025: 1026: 1027: 1028: 1029: /* Main code - entry point to firmware */ 1030: void main() 1031: { 1032: /* FTDI:SDD Driver Declarations */ 1033: // UART Driver configuration context 1034: uart_context_t uartContext; 1035: // GPIO Port A configuration context 1036: gpio_context_t gpioContextA; 1037: gpio_context_t gpioContextB; 1038: // USB Host configuration context 1039: usbhost_context_t usbhostContext; 1040: /* FTDI:EDD */ 1041: 1042: /* FTDI:SKI Kernel Initialisation */ 1043: vos_init(50, VOS_TICK_INTERVAL, VOS_NUMBER_DEVICES); 1044: vos_set_clock_frequency(VOS_48MHZ_CLOCK_FREQUENCY); 1045: vos_set_idle_thread_tcb_size(400); 1046: /* FTDI:EKI */ 1047: 1048: iomux_setup(); 1049: 1050: /* FTDI:SDI Driver Initialisation */ 1051: // Initialise UART 1052: uartContext.buffer_size = VOS_BUFFER_SIZE_256_BYTES; 1053: uart_init(VOS_DEV_UART,&uartContext); 1054: 1055: // Initialise GPIO A 1056: gpioContextA.port_identifier = GPIO_PORT_A; 1057: gpio_init(VOS_DEV_GPIO_PORT_A,&gpioContextA); 1058: // Initialise GPIO B 1059: gpioContextA.port_identifier = GPIO_PORT_B; 1060: gpio_init(VOS_DEV_GPIO_PORT_B,&gpioContextB); 1061: 1062: fat_init(); 1063: 1064: // Initialise FAT File System Driver 1065: fatdrv_init(VOS_DEV_FAT_FILE_SYSTEM_1); 1066: 1067: // Initialise FAT File System Driver 1068: fatdrv_init(VOS_DEV_FAT_FILE_SYSTEM_2); 1069: 1070: // Initialise BOMS Device Driver
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 18/29
C:\SKOLA\_Diplomka\podklady\
1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124: 1125: 1126: 1127: 1128: 1129: 1130: 1131: 1132: 1133: 1134:
Poslední změna: 19.5.2013 16:59:36
boms_init(VOS_DEV_BOMS_1); // Initialise BOMS Device Driver boms_init(VOS_DEV_BOMS_2); // Initialise USB Host usbhostContext.if_count = 8; usbhostContext.ep_count = 16; usbhostContext.xfer_count = 2; usbhostContext.iso_xfer_count = 2; usbhost_init(VOS_DEV_USBHOST_1, VOS_DEV_USBHOST_2, &usbhostContext); /* FTDI:EDI */ /* FTDI:SCT Thread Creation */ tcbCOPYD = vos_create_thread_ex(24,2000, COPYD, "Copydisc", 0); tcbSETUP = vos_create_thread_ex(25,800, setup, "Setup", 0); tcbUART = vos_create_thread_ex(24,1200, UART, "Read", 0); tcbBOMS = vos_create_thread_ex(24,1000, BOMS, "Write", 0);
/* FTDI:ECT */ vos_init_semaphore(&setupSem, 0); vos_init_semaphore(&command, 0); vos_init_semaphore(&dataSem, 0); vos_init_semaphore(&cmdCpy, 0); vos_init_mutex(&mBufAccess, VOS_MUTEX_UNLOCKED); vos_start_scheduler(); main_loop: goto main_loop; } unsigned char usbhost_connect_state(VOS_HANDLE hUSB) { unsigned char connectstate = PORT_STATE_DISCONNECTED; usbhost_ioctl_cb_t hc_iocb; if (hUSB) { hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_CONNECT_STATE; hc_iocb.get = &connectstate; vos_dev_ioctl(hUSB, &hc_iocb); // repeat if connected to see if we move to enumerated if (connectstate == PORT_STATE_CONNECTED) { vos_dev_ioctl(hUSB, &hc_iocb); } } return connectstate; }
VOS_HANDLE fat_attach(VOS_HANDLE hMSI, unsigned char devFAT) { fat_ioctl_cb_t fat_ioctl; fatdrv_ioctl_cb_attach_t fat_att; VOS_HANDLE hFAT; // currently the MSI (BOMS or other) must be open // open the FAT driver hFAT = vos_dev_open(devFAT);
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 19/29
C:\SKOLA\_Diplomka\podklady\
1135: 1136: 1137: 1138: 1139: 1140: 1141: 1142: 1143: 1144: 1145: 1146: 1147: 1148: 1149: 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163: 1164: 1165: 1166: 1167: 1168: 1169: 1170: 1171: 1172: 1173: 1174: 1175: 1176: 1177: 1178: 1179: 1180: 1181: 1182: 1183: 1184: 1185: 1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198:
Poslední změna: 19.5.2013 16:59:36
// attach the FAT driver to the MSI driver fat_ioctl.ioctl_code = FAT_IOCTL_FS_ATTACH; fat_ioctl.set = &fat_att; fat_att.msi_handle = hMSI; fat_att.partition = 0; if (vos_dev_ioctl(hFAT, &fat_ioctl) != FAT_OK) { // unable to open the FAT driver vos_dev_close(hFAT); monError(); return NULL; } return hFAT; } void fat_detach(VOS_HANDLE hFAT) { fat_ioctl_cb_t fat_ioctl; if (hFAT) { fat_ioctl.ioctl_code = FAT_IOCTL_FS_DETACH; fat_ioctl.set = NULL; fat_ioctl.get = NULL; vos_dev_ioctl(hFAT, &fat_ioctl); vos_dev_close(hFAT); } }
VOS_HANDLE boms_attach(VOS_HANDLE hUSB, unsigned char devBOMS) { usbhost_device_handle_ex ifDisk = 0; usbhost_ioctl_cb_t hc_iocb; usbhost_ioctl_cb_class_t hc_iocb_class; msi_ioctl_cb_t boms_iocb; boms_ioctl_cb_attach_t boms_att; VOS_HANDLE hBOMS; char mystate=0; // find BOMS class device hc_iocb_class.dev_class = USB_CLASS_MASS_STORAGE; hc_iocb_class.dev_subclass = USB_SUBCLASS_MASS_STORAGE_SCSI; hc_iocb_class.dev_protocol = USB_PROTOCOL_MASS_STORAGE_BOMS; // user ioctl to find first hub device hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_FIND_HANDLE_BY_CLASS; hc_iocb.handle.dif = NULL; hc_iocb.set = &hc_iocb_class; hc_iocb.get = &ifDisk; if (vos_dev_ioctl(hUSB, &hc_iocb) != USBHOST_OK) { return NULL; } // now we have a device, intialise a BOMS driver with it hBOMS = vos_dev_open(devBOMS); // perform attach boms_att.hc_handle = hUSB;
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 20/29
C:\SKOLA\_Diplomka\podklady\
1199: 1200: 1201: 1202: 1203: 1204: 1205: 1206: 1207: 1208: 1209: 1210: 1211: 1212: 1213: 1214: 1215: 1216: 1217: 1218: 1219: 1220: 1221: 1222: 1223: 1224: 1225: 1226: 1227: 1228: 1229: 1230: 1231: 1232: 1233: 1234: 1235: 1236: 1237: 1238: 1239: 1240: 1241: 1242: 1243: 1244: 1245: 1246: 1247: 1248: 1249: 1250: 1251: 1252: 1253: 1254: 1255: 1256: 1257: 1258: 1259: 1260: 1261: 1262:
Poslední změna: 19.5.2013 16:59:36
boms_att.ifDev = ifDisk; boms_iocb.ioctl_code = MSI_IOCTL_BOMS_ATTACH; boms_iocb.set = &boms_att; boms_iocb.get = NULL; mystate = vos_dev_ioctl(hBOMS, &boms_iocb); if (mystate != MSI_OK) { vos_dev_close(hBOMS); hBOMS = NULL; monError(); return NULL; } return hBOMS; } void boms_detach(VOS_HANDLE hBOMS) { msi_ioctl_cb_t boms_iocb; if (hBOMS) { boms_iocb.ioctl_code = MSI_IOCTL_BOMS_DETACH; boms_iocb.set = NULL; boms_iocb.get = NULL; vos_dev_ioctl(hBOMS, &boms_iocb); vos_dev_close(hBOMS); } } /* FTDI:ESP */ /* Application Threads */
void monError() { unsigned char data; vos_gpio_read_port(GPIO_PORT_A, &data); data |= 0x04; vos_gpio_write_port(GPIO_PORT_A, data); while(1); } void setup() { // Open a handle to all our devices... unsigned char vstup=0; hGPIO_PORT_A = vos_dev_open(VOS_DEV_GPIO_PORT_A); hGPIO_PORT_B = vos_dev_open(VOS_DEV_GPIO_PORT_B); vos_gpio_set_port_mode(GPIO_PORT_A, 0xff); vos_gpio_set_port_mode(GPIO_PORT_B, 0x00); vos_gpio_write_port(GPIO_PORT_A, 0); vos_gpio_read_port(GPIO_PORT_B, &vstup); vstup=vstup & 0x40; //vstup=vstup >>4; switch (vstup) { case 0x40: LED1();vos_signal_semaphore(&cmdCpy);break; fileuart=1;vos_signal_semaphore(&command);break; default:
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 21/29
C:\SKOLA\_Diplomka\podklady\
1263: 1264: 1265: 1266: 1267: 1268: 1269: 1270: 1271: 1272: 1273: 1274: 1275: 1276: 1277: 1278: 1279: 1280: 1281: 1282: 1283: 1284: 1285: 1286: 1287: 1288: 1289: 1290: 1291: 1292: 1293: 1294: 1295: 1296: 1297: 1298: 1299: 1300: 1301: 1302: 1303: 1304: 1305: 1306: 1307: 1308: 1309: 1310: 1311: 1312: 1313: 1314: 1315: 1316: 1317: 1318: 1319: 1320: 1321: 1322: 1323: 1324: 1325: 1326:
Poslední změna: 19.5.2013 16:59:36
} }
void UART() { unsigned short numRead; common_ioctl_cb_t uart_iocb; unsigned short dataAvail = 0; unsigned char counter=0; unsigned int handle; usbhost_ioctl_cb_t hc_iocb; // common_ioctl_cb_t uart_iocb; unsigned char connect1, connect2; unsigned char state1, state2; vos_wait_semaphore(&command);
hUSBHOST_1 = vos_dev_open(VOS_DEV_USBHOST_1); hUSBHOST_2 = vos_dev_open(VOS_DEV_USBHOST_2); state1 = state2 = PORT_STATE_DISCONNECTED; fat_init(); counter=0; while (usbhost_connect_state(hUSBHOST_1) != PORT_STATE_ENUMERATED) { vos_delay_msecs(250); LED1(); vos_delay_msecs(250); NLED1(); } state1=usbhost_connect_state(hUSBHOST_1); counter=0; while (usbhost_connect_state(hUSBHOST_2) != PORT_STATE_ENUMERATED) { // wait for enumeration to complete vos_delay_msecs(100); if (counter>30) { usbout=1; break; } counter++; } state2=usbhost_connect_state(hUSBHOST_2); hUART = vos_dev_open(VOS_DEV_UART); uart_iocb.ioctl_code = VOS_IOCTL_COMMON_ENABLE_DMA; uart_iocb.set.param = DMA_ACQUIRE_AS_REQUIRED; vos_dev_ioctl(hUART, &uart_iocb); // UART set baud rate uart_iocb.ioctl_code = VOS_IOCTL_UART_SET_BAUD_RATE; uart_iocb.set.uart_baud_rate = DEF_UART_BAUD; vos_dev_ioctl(hUART, &uart_iocb); // UART set flow control
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 22/29
C:\SKOLA\_Diplomka\podklady\
1327: 1328: 1329: 1330: 1331: 1332: 1333: 1334: 1335: 1336: 1337: 1338: 1339: 1340: 1341: 1342: 1343: 1344: 1345: 1346: 1347: 1348: 1349: 1350: 1351: 1352: 1353: 1354: 1355: 1356: 1357: 1358: 1359: 1360: 1361: 1362: 1363: 1364: 1365: 1366: 1367: 1368: 1369: 1370: 1371: 1372: 1373: 1374: 1375: 1376: 1377: 1378: 1379: 1380: 1381: 1382: 1383: 1384: 1385: 1386: 1387: 1388: 1389: 1390:
Poslední změna: 19.5.2013 16:59:36
uart_iocb.ioctl_code = VOS_IOCTL_UART_SET_FLOW_CONTROL; uart_iocb.set.param = DEF_UART_FLOW; vos_dev_ioctl(hUART, &uart_iocb); // UART set data bits uart_iocb.ioctl_code = VOS_IOCTL_UART_SET_DATA_BITS; uart_iocb.set.param = DEF_UART_DATA_BITS; vos_dev_ioctl(hUART, &uart_iocb); // UART set stop bits uart_iocb.ioctl_code = VOS_IOCTL_UART_SET_STOP_BITS; uart_iocb.set.param = DEF_UART_STOP_BITS; vos_dev_ioctl(hUART, &uart_iocb); // UART set parity uart_iocb.ioctl_code = VOS_IOCTL_UART_SET_PARITY; uart_iocb.set.param = DEF_UART_PARITY; vos_dev_ioctl(hUART, &uart_iocb); fatContext1 = fatContext2 = NULL; if ((state1 == PORT_STATE_ENUMERATED)) { hBOMS_1 = boms_attach(hUSBHOST_1, VOS_DEV_BOMS_1); if (hBOMS_1) { fatContext1 = fat_open(hBOMS_1, 0, NULL); if (!fatContext1) { monError(); } } } if ((state2 == PORT_STATE_ENUMERATED)) { hBOMS_2 = boms_attach(hUSBHOST_2, VOS_DEV_BOMS_2); if (hBOMS_2) { fatContext2 = fat_open(hBOMS_2, 0, NULL); if (!fatContext2) { monError(); } } }
hFAT_FILE_SYSTEM_1 = fat_attach(hBOMS_1, VOS_DEV_FAT_FILE_SYSTEM_1); if (hFAT_FILE_SYSTEM_1 == NULL) { monError(); } if (fatContext2) { hFAT_FILE_SYSTEM_2 = fat_attach(hBOMS_2, VOS_DEV_FAT_FILE_SYSTEM_2); if (hFAT_FILE_SYSTEM_2 == NULL) {
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 23/29
C:\SKOLA\_Diplomka\podklady\
1391: 1392: 1393: 1394: 1395: 1396: 1397: 1398: 1399: 1400: 1401: 1402: 1403: 1404: 1405: 1406: 1407: 1408: 1409: 1410: 1411: 1412: 1413: 1414: 1415: 1416: 1417: 1418: 1419: 1420: 1421: 1422: 1423: 1424: 1425: 1426: 1427: 1428: 1429: 1430: 1431: 1432: 1433: 1434: 1435: 1436: 1437: 1438: 1439: 1440: 1441: 1442: 1443: 1444: 1445: 1446: 1447: 1448: 1449: 1450: 1451: 1452: 1453: 1454:
Poslední změna: 19.5.2013 16:59:36
monError();return; } }
while(1) { // get bytes available... uart_iocb.ioctl_code = VOS_IOCTL_COMMON_GET_RX_QUEUE_STATUS; vos_dev_ioctl(hUART, &uart_iocb); dataAvail = uart_iocb.get.queue_stat; // How much data to read? if (dataAvail) { if (dataAvail > (sizeof(buf) - pBuf)) dataAvail = (sizeof(buf) - pBuf); vos_lock_mutex(&mBufAccess); vos_dev_read(hUART, &buf[pBuf], dataAvail, &numRead); pBuf += numRead; vos_unlock_mutex(&mBufAccess); vos_signal_semaphore(&dataSem); } } } void BOMS() { file_context_t FILEC; unsigned char status; unsigned char OKstatus={'#','V', 13}; while(1) { vos_wait_semaphore(&dataSem);
if (pBuf) { if ((fileuart==1)&&(pBuf>7)) //zmena z 8 na 7 { vos_lock_mutex(&mBufAccess); pBuf=0; for (pBuf=0;pBuf<8; pBuf++) { filenameu[pBuf]=buf[pBuf]; } pBuf=0; fileuart=0; vos_dev_write(hUART, &OKstatus, 3, NULL); vos_unlock_mutex(&mBufAccess); } if (fileuart!=1) { vos_lock_mutex(&mBufAccess); fsAttach(hFAT_FILE_SYSTEM_1); file = fopen(filenameu, "a+"); if (file) { fwrite(buf, (size_t)pBuf, sizeof(char), file); fclose(file); file = NULL; } else {
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 24/29
C:\SKOLA\_Diplomka\podklady\
1455: 1456: 1457: 1458: 1459: 1460: 1461: 1462: 1463: 1464: 1465: 1466: 1467: 1468: 1469: 1470: 1471: 1472: 1473: 1474: 1475: 1476: 1477: 1478: 1479: 1480: 1481: 1482: 1483: 1484: 1485: 1486: 1487: 1488: 1489: 1490: 1491: 1492: 1493: 1494: 1495: 1496: 1497: 1498: 1499: 1500: 1501: 1502: 1503: 1504: 1505: 1506: 1507: 1508: 1509: 1510: 1511: 1512: 1513: 1514: 1515: 1516: 1517:
Poslední změna: 19.5.2013 16:59:36
monError(); } if (fatContext2) { fsAttach(hFAT_FILE_SYSTEM_2); file = fopen(filenameu, "a+"); if (file) { fwrite(buf, (size_t)pBuf, sizeof(char), file); fclose(file); file = NULL; } else { monError(); } } pBuf = 0; vos_unlock_mutex(&mBufAccess); } } } } /* ** copyFile ** ** Copy a file from the source to the destination disk. ** Source file is opened for read only, destination is opened for write. ** Destination file will be overwritten if it exists. ** ** Parameters: handle to source file system ** handle to destination file system ** filename ** Returns: status of file system operation ** Comments: */ unsigned char copyFile(fat_context fatContextSrc, fat_context fatContextDest, char *filename) { unsigned char status; // file handles for source and destination files static file_context_t fileSource; static file_context_t fileDest; unsigned long length; status = fat_fileOpen(fatContextSrc, &fileSource, filename, FILE_MODE_READ); status = fat_fileOpen(fatContextDest, &fileDest, filename, FILE_MODE_WRITE); length = fat_dirEntrySize(&fileSource); status = fat_fileCopy(&fileSource, &fileDest); // close the file handles fat_fileClose(&fileSource); fat_fileClose(&fileDest); return status; } /* ** changeDirUp ** ** Change directory up one level on selected file system.
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 25/29
C:\SKOLA\_Diplomka\podklady\
1518: 1519: 1520: 1521: 1522: 1523: 1524: 1525: 1526: 1527: 1528: 1529: 1530: 1531: 1532: 1533: 1534: 1535: 1536: 1537: 1538: 1539: 1540: 1541: 1542: 1543: 1544: 1545: 1546: 1547: 1548: 1549: 1550: 1551: 1552: 1553: 1554: 1555: 1556: 1557: 1558: 1559: 1560: 1561: 1562: 1563: 1564: 1565: 1566: 1567: 1568: 1569: 1570: 1571: 1572: 1573: 1574: 1575: 1576: 1577: 1578: 1579: 1580: 1581:
Poslední změna: 19.5.2013 16:59:36
** ** Parameters: handle to file system ** Returns: status of file system operation ** Comments: */ unsigned char changeDirUp(fat_context fatContext) { unsigned char status; status = fat_dirChangeDir(fatContext, ".. return status;
");
} /* ** ** ** ** ** ** ** ** */
copyDir Recursively copy a directory from the source to the destination disk. Parameters: handle to source file system handle to destination file system Returns: status of file system operation Comments:
unsigned char copyDir(fat_context fatContextSrc, fat_context fatContextDest) { file_context_t fileFind; char filename[12]; unsigned char status; memset(filename, 0, sizeof(filename)); if (fat_dirTableFindFirst(fatContextSrc, &fileFind) == FAT_OK) { do { if (fat_dirEntryIsValid(&fileFind)) { fat_dirEntryName(&fileFind, filename); if (fat_dirEntryIsDirectory(&fileFind)) { status = fat_dirChangeDir(fatContextSrc, (char *) filename); if (status == FAT_OK) { status = fat_dirCreateDir(fatContextDest, (char *) filename); if ((status == FAT_OK) || (status == FAT_EXISTS)) { status = fat_dirChangeDir(fatContextDest, (char *) filename); if (status == FAT_OK) { copyDir(fatContextSrc, fatContextDest); status = changeDirUp(fatContextDest); if (status == FAT_OK) { } } } status = changeDirUp(fatContextSrc);
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 26/29
C:\SKOLA\_Diplomka\podklady\
1582: 1583: 1584: 1585: 1586: 1587: 1588: 1589: 1590: 1591: 1592: 1593: 1594: 1595: 1596: 1597: 1598: 1599: 1600: 1601: 1602: 1603: 1604: 1605: 1606: 1607: 1608: 1609: 1610: 1611: 1612: 1613: 1614: 1615: 1616: 1617: 1618: 1619: 1620: 1621: 1622: 1623: 1624: 1625: 1626: 1627: 1628: 1629: 1630: 1631: 1632: 1633: 1634: 1635: 1636: 1637: 1638: 1639: 1640: 1641: 1642: 1643: 1644: 1645:
Poslední změna: 19.5.2013 16:59:36
if (status == FAT_OK) { } } } else { copyFile(fatContextSrc, fatContextDest, filename); } } } while (fat_dirTableFindNext(fatContextSrc, &fileFind) == FAT_OK); } return status; } /* ** copyDisk ** ** Copy the source disk from the current directory to the destination disk ** current directory. ** ** Parameters: handle to source file system ** handle to destination file system ** Returns: status of file system operation ** Comments: */ unsigned char copyDisk(fat_context fatContextSrc, fat_context fatContextDest) { return copyDir(fatContextSrc, fatContextDest); } unsigned char destMakeUniqueDir(fat_context fatContext) { file_context_t fileFind;
char dirName[12] = "ZLD_0000 unsigned short count = 1; unsigned short dirnum; unsigned char i; unsigned char status;
\0";
do { if (count > 9999) break; dirName[4] dirName[5] dirName[6] dirName[7]
= = = =
((count / 1000) % 10) + '0'; ((count / 100) % 10) + '0'; ((count / 10) % 10) + '0'; (count % 10) + '0';
status = fat_dirTableFind(fatContext, &fileFind, (char *) dirName); if (status != FAT_OK) { status = fat_dirCreateDir(fatContext, (char *) dirName); if (status == FAT_OK) {
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 27/29
C:\SKOLA\_Diplomka\podklady\
Poslední změna: 19.5.2013 16:59:36
1646: status = fat_dirChangeDir(fatContext, (char *) dirName); 1647: 1648: if (status == FAT_OK) 1649: { 1650: return 0; // passed 1651: } 1652: } 1653: 1654: break; 1655: } 1656: 1657: count++; 1658: } 1659: while (1); 1660: 1661: return -1; // failed 1662: } 1663: 1664: void COPYD() 1665: { 1666: unsigned char status; 1667: unsigned int handle; 1668: usbhost_ioctl_cb_t hc_iocb; 1669: unsigned char connect1, connect2; 1670: unsigned char state1, state2; 1671: 1672: vos_wait_semaphore(&cmdCpy); 1673: 1674: LED1(); 1675: 1676: hUSBHOST_1 = vos_dev_open(VOS_DEV_USBHOST_1); 1677: hUSBHOST_2 = vos_dev_open(VOS_DEV_USBHOST_2); 1678: 1679: state1 = state2 = PORT_STATE_DISCONNECTED; 1680: 1681: fat_init(); 1682: 1683: while (usbhost_connect_state(hUSBHOST_1) != PORT_STATE_ENUMERATED) 1684: { 1685: // wait for enumeration to complete 1686: vos_delay_msecs(100); 1687: 1688: } 1689: state1=usbhost_connect_state(hUSBHOST_1); 1690: 1691: while (usbhost_connect_state(hUSBHOST_2) != PORT_STATE_ENUMERATED) 1692: { 1693: // wait for enumeration to complete 1694: vos_delay_msecs(250); 1695: LED1(); 1696: vos_delay_msecs(250); 1697: NLED1(); 1698: } 1699: state2=usbhost_connect_state(hUSBHOST_2); 1700: LED1(); 1701: 1702: 1703: if ((state1 == PORT_STATE_ENUMERATED) && (state2 == PORT_STATE_ENUMERATED)) 1704: { 1705: fatContext1 = fatContext2 = NULL; 1706: 1707: hBOMS_1 = boms_attach(hUSBHOST_1, VOS_DEV_BOMS_1); 1708: 1709: if (hBOMS_1)
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 28/29
C:\SKOLA\_Diplomka\podklady\
1710: 1711: 1712: 1713: 1714: 1715: 1716: 1717: 1718: 1719: 1720: 1721: 1722: 1723: 1724: 1725: 1726: 1727: 1728: 1729: 1730: 1731: 1732: 1733: 1734: 1735: 1736: 1737: 1738: 1739: 1740: 1741: 1742: 1743: 1744: 1745: 1746: 1747: 1748: 1749:
Poslední změna: 19.5.2013 16:59:36
{ fatContext1 = fat_open(hBOMS_1, 0, NULL); if (!fatContext1) { monError(); } } hBOMS_2 = boms_attach(hUSBHOST_2, VOS_DEV_BOMS_2); if (hBOMS_2) { fatContext2 = fat_open(hBOMS_2, 0, NULL); if (!fatContext2) { if (fatContext1) fat_close(fatContext1); if (fatContext2) fat_close(fatContext2); boms_detach(hBOMS_1); boms_detach(hBOMS_2); while(1) { vos_delay_msecs(200); LED1(); vos_delay_msecs(200); NLED1(); } } } if ((fatContext1) && (fatContext2)) { // create (if required) and change into target direcory on destination disk
1750: 1751: 1752: 1753: 1754: 1755: 1756: 1757: 1758: 1759: 1760: 1761: 1762: 1763: 1764: 1765: 1766: 1767: 1768: 1769: 1770: 1771: 1772:
if (destMakeUniqueDir(fatContext2) == 0) { copyDisk(fatContext1, fatContext2); // restore destination disk to top level directory changeDirUp(fatContext2); } // restore source disk to top level directory changeDirUp(fatContext1); } if (fatContext1) fat_close(fatContext1); if (fatContext2) fat_close(fatContext2); boms_detach(hBOMS_1); boms_detach(hBOMS_2); // copy once only
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal
kodPIC.c
Strana: 29/29
C:\SKOLA\_Diplomka\podklady\
1773: 1774: 1775: 1776: 1777: 1778: 1779: 1780: 1781: 1782: 1783: 1784: 1785: 1786: 1787: 1788: 1789: 1790: 1791: 1792: 1793: 1794: 1795: 1796: 1797: 1798: 1799: 1800: 1801:
Poslední změna: 19.5.2013 16:59:36
while (1) { vos_delay_msecs(1000); LED1(); vos_delay_msecs(1000); NLED1(); } } } void LED1() { unsigned char data; vos_gpio_read_port(GPIO_PORT_A, &data); data |= 0x08; vos_gpio_write_port(GPIO_PORT_A, data); } void NLED1() { unsigned char data; vos_gpio_read_port(GPIO_PORT_A, &data); data &= (~0x08); vos_gpio_write_port(GPIO_PORT_A, data); }
PSPad editor 4.5.6 (2427) www.pspad.com
19.5.2013 23:40:38
Michal