int main() { u08 i; i = 0; u08 adc_0, adc_1; setup(); while(1==1) { adc_0 = a2dConvert8bit(ADC_CH_ADC0); adc_1 = a2dConvert8bit(ADC_CH_ADC1); rprintfu08(adc_0); rprintfu08(adc_1); rprintfChar(0); // rprintfCRLF(); _delay_ms(32); /* i++; if(i<=128) { sbi(PORTB, PB3); } if(i>128) { cbi(PORTB, PB3); } */ //_delay_ms(32); //_delay_ms(32); //_delay_ms(32); } return 0; }
unsigned char ataWriteSectors(unsigned char Drive, unsigned long lba, unsigned int numsectors, unsigned char *Buffer) { unsigned int cyl, head, sect; unsigned char temp; // check if drive supports native LBA mode if(ataDriveInfo.LBAsupport) { // drive supports using native LBA temp = ataWriteSectorsLBA(Drive, lba, numsectors, Buffer); } else { // drive required CHS access #ifdef DEBUG_ATA // do this defore destroying lba rprintfProgStrM("ATA LBA for CHS write: "); rprintfProgStrM("LBA="); rprintfu32(lba); rprintfProgStrM(" "); #endif // convert LBA to pseudo CHS // remember to offset the sector count by one sect = (u08) (lba % ataDriveInfo.sectors)+1; lba = lba / ataDriveInfo.sectors; head = (u08) (lba % ataDriveInfo.heads); lba = lba / ataDriveInfo.heads; cyl = (u16) lba; #ifdef DEBUG_ATA rprintfProgStrM("C:H:S="); rprintfu16(cyl); rprintfProgStrM(":"); rprintfu08(head); rprintfProgStrM(":"); rprintfu08(sect); rprintfCRLF(); #endif temp = ataWriteSectorsCHS( Drive, head, cyl, sect, numsectors, Buffer ); } if(temp) ataDiskErr(); return temp; }
void ataDiskErr(void) { unsigned char b; b = ataReadByte(ATA_REG_ERROR); rprintfProgStrM("ATA Error: "); rprintfu08(b); rprintfCRLF(); }
void dallasPrintROM(dallas_rom_id_T* rom_id) { s08 i; // print out the rom in the format: xx xx xx xx xx xx xx xx for(i=7; i>=0; i--) { rprintfu08(rom_id->byte[i]); rprintfChar(' '); } }
void dallasPrintROM(dallas_rom_id_T* rom_id) { s08 i; // print out the rom in the format: xx xx xx xx xx xx xx xx for(i=7;i>=0;i--) { rprintfu08(rom_id->byte[i]); rprintfChar(' '); } // print out the rom in the format: 0xXXXXXXXXXXXXXXXX rprintfProgStrM(" (0x"); for(i=7;i>=0;i--) { rprintfu08(rom_id->byte[i]); } rprintfProgStrM("ULL)"); }
void ataShowRegisters(unsigned char DriveNo) { ataWriteByte(ATA_REG_HDDEVSEL, 0xA0 + (DriveNo ? 0x10:0x00)); // Select drive rprintfProgStrM("R0: DATALOW = 0x"); rprintfu08(ataReadByte(ATA_REG_DATAL )); rprintfProgStrM(" \r\n"); rprintfProgStrM("R1: ERROR = 0x"); rprintfu08(ataReadByte(ATA_REG_ERROR )); rprintfProgStrM(" \r\n"); rprintfProgStrM("R2: SECT CNT = 0x"); rprintfu08(ataReadByte(ATA_REG_SECCOUNT)); rprintfProgStrM(" \r\n"); rprintfProgStrM("R3: SECT NUM = 0x"); rprintfu08(ataReadByte(ATA_REG_STARTSEC)); rprintfProgStrM(" \r\n"); rprintfProgStrM("R4: CYL LOW = 0x"); rprintfu08(ataReadByte(ATA_REG_CYLLO )); rprintfProgStrM(" \r\n"); rprintfProgStrM("R5: CYL HIGH = 0x"); rprintfu08(ataReadByte(ATA_REG_CYLHI )); rprintfProgStrM(" \r\n"); rprintfProgStrM("R6: HEAD/DEV = 0x"); rprintfu08(ataReadByte(ATA_REG_HDDEVSEL)); rprintfProgStrM(" \r\n"); rprintfProgStrM("R7: CMD/STA = 0x"); rprintfu08(ataReadByte(ATA_REG_CMDSTATUS1)); rprintfProgStrM("\r\n"); }
void ataPrintSector( u08 *Buffer) { u08 i; u16 j; u08 *buf; u08 s; buf = Buffer; // print the low order address indicies rprintfProgStrM(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\r\n"); rprintfProgStrM(" ----------------------------------------------- ---- ASCII -----\r\n"); // print the data for(j=0; j<0x20; j++) { // print the high order address index for this line rprintfu16(j<<4); rprintfProgStrM(" "); // print the hex data for(i=0; i<0x10; i++) { rprintfu08(buf[(j<<4)+i]); rprintfProgStrM(" "); } // leave some space rprintfProgStrM(" "); // print the ascii data for(i=0; i<0x10; i++) { s = buf[(j<<4)+i]; // make sure character is printable if(s >= 0x20) { rprintfChar(s); } else { rprintfChar(0x20); } } rprintfCRLF(); } }
void icmpPrintHeader(icmpip_hdr* packet) { rprintfProgStrM("ICMP Packet:\n"); // print source IP address rprintfProgStrM("SrcIpAddr: "); netPrintIPAddr(htonl(packet->ip.srcipaddr)); rprintfCRLF(); // print dest IP address rprintfProgStrM("DstIpAddr: "); netPrintIPAddr(htonl(packet->ip.destipaddr)); rprintfCRLF(); // print type rprintfProgStrM("Type : "); switch(packet->icmp.type) { case ICMP_TYPE_ECHOREQUEST: rprintfProgStrM("ECHO REQUEST"); break; case ICMP_TYPE_ECHOREPLY: rprintfProgStrM("ECHO REPLY"); break; default: rprintfProgStrM("UNKNOWN"); break; } rprintfCRLF(); // print code rprintfProgStrM("Code : 0x"); rprintfu08(packet->icmp.icode); rprintfCRLF(); }
int main(void) { u08 adc_1, adc_2, adc_3, adc_4, adc_5; u08 i; setup(); while(1==1) { //rprintfStr("Hello"); adc_1 = a2dConvert8bit(ADC_CH_ADC1); adc_2 = a2dConvert8bit(ADC_CH_ADC2); adc_3 = a2dConvert8bit(ADC_CH_ADC3); adc_4 = a2dConvert8bit(ADC_CH_ADC4); adc_5 = a2dConvert8bit(ADC_CH_ADC5); rprintfu08(adc_1); // rprintfu08(adc_2); // rprintfu08(adc_3); // rprintfu08(adc_4); // rprintfu08(adc_5); rprintfCRLF(); _delay_ms(32); i++; } return 0; }
void i2cMasterReceive(u08 deviceAddr, u08 length, u08* data) { u08 i; // wait for interface to be ready rprintf("Waiting for Interface"); while(I2cState); // set state I2cState = I2C_MASTER_RX; // save data I2cDeviceAddrRW = (deviceAddr|0x01); // RW set: read operation I2cReceiveDataIndex = 0; I2cReceiveDataLength = length; // send start condition i2cSendStart(); // wait for data rprintf("Sending Start"); while(I2cState); // return data for(i=0; i<length; i++) { *data++ = I2cReceiveData[i]; rprintfu08(I2cReceiveData[i]); } }
void ad9854ShowRegisters(void) { // read and print all registers rprintfStr("Phase1 : 0x"); rprintfu08(ad9854Read(AD9854_REG_PHASE1H)); rprintfu08(ad9854Read(AD9854_REG_PHASE1L)); rprintfCRLF(); rprintfStr("Phase2 : 0x"); rprintfu08(ad9854Read(AD9854_REG_PHASE2H)); rprintfu08(ad9854Read(AD9854_REG_PHASE2L)); rprintfCRLF(); rprintfStr("Freq1 : 0x"); rprintfu08(ad9854Read(AD9854_REG_FREQ15)); rprintfu08(ad9854Read(AD9854_REG_FREQ14)); rprintfu08(ad9854Read(AD9854_REG_FREQ13)); rprintfu08(ad9854Read(AD9854_REG_FREQ12)); rprintfu08(ad9854Read(AD9854_REG_FREQ11)); rprintfu08(ad9854Read(AD9854_REG_FREQ10)); rprintfCRLF(); rprintfStr("Freq2 : 0x"); rprintfu08(ad9854Read(AD9854_REG_FREQ25)); rprintfu08(ad9854Read(AD9854_REG_FREQ24)); rprintfu08(ad9854Read(AD9854_REG_FREQ23)); rprintfu08(ad9854Read(AD9854_REG_FREQ22)); rprintfu08(ad9854Read(AD9854_REG_FREQ21)); rprintfu08(ad9854Read(AD9854_REG_FREQ20)); rprintfCRLF(); rprintfStr("DeltaFreq : 0x"); rprintfu08(ad9854Read(AD9854_REG_DELTA5)); rprintfu08(ad9854Read(AD9854_REG_DELTA4)); rprintfu08(ad9854Read(AD9854_REG_DELTA3)); rprintfu08(ad9854Read(AD9854_REG_DELTA2)); rprintfu08(ad9854Read(AD9854_REG_DELTA1)); rprintfu08(ad9854Read(AD9854_REG_DELTA0)); rprintfCRLF(); rprintfStr("Update Clock: 0x"); rprintfu08(ad9854Read(AD9854_REG_UPDCLOCK3)); rprintfu08(ad9854Read(AD9854_REG_UPDCLOCK2)); rprintfu08(ad9854Read(AD9854_REG_UPDCLOCK1)); rprintfu08(ad9854Read(AD9854_REG_UPDCLOCK0)); rprintfCRLF(); rprintfStr("Ramp Rate : 0x"); rprintfu08(ad9854Read(AD9854_REG_RAMPCLOCK2)); rprintfu08(ad9854Read(AD9854_REG_RAMPCLOCK1)); rprintfu08(ad9854Read(AD9854_REG_RAMPCLOCK0)); rprintfCRLF(); rprintfStr("Control : 0x"); rprintfu08(ad9854Read(AD9854_REG_CTRL3)); rprintfu08(ad9854Read(AD9854_REG_CTRL2)); rprintfu08(ad9854Read(AD9854_REG_CTRL1)); rprintfu08(ad9854Read(AD9854_REG_CTRL0)); rprintfCRLF(); rprintfStr("Amplitude I : 0x"); rprintfu08(ad9854Read(AD9854_REG_AMPLIH)); rprintfu08(ad9854Read(AD9854_REG_AMPLIL)); rprintfCRLF(); rprintfStr("Amplitude Q : 0x"); rprintfu08(ad9854Read(AD9854_REG_AMPLQH)); rprintfu08(ad9854Read(AD9854_REG_AMPLQL)); rprintfCRLF(); }
u08 tsipProcess(cBuffer* rxBuffer) { u08 foundpacket = FALSE; u08 startFlag = FALSE; u08 data; u08 i,j,k; u08 TsipPacketIdx; // process the receive buffer // go through buffer looking for packets while(rxBuffer->datalength > 1) { // look for a potential start of TSIP packet if(bufferGetAtIndex(rxBuffer,0) == DLE) { // make sure the next byte is not DLE or ETX data = bufferGetAtIndex(rxBuffer,1); if((data != DLE) && (data != ETX)) { // found potential start startFlag = TRUE; // done looking for start break; } } else // not DLE, dump character from buffer bufferGetFromFront(rxBuffer); } // if we detected a start, look for end of packet if(startFlag) { for(i=1; i<(rxBuffer->datalength)-1; i++) { // check for potential end of TSIP packet if((bufferGetAtIndex(rxBuffer,i) == DLE) && (bufferGetAtIndex(rxBuffer,i+1) == ETX)) { // have a packet end // dump initial DLE bufferGetFromFront(rxBuffer); // copy data to TsipPacket TsipPacketIdx = 0; for(j=0; j<(i-1); j++) { data = bufferGetFromFront(rxBuffer); if(data == DLE) { if(bufferGetAtIndex(rxBuffer,0) == DLE) { // found double-DLE escape sequence, skip one of them bufferGetFromFront(rxBuffer); j++; } } TsipPacket[TsipPacketIdx++] = data; } // dump ending DLE+ETX bufferGetFromFront(rxBuffer); bufferGetFromFront(rxBuffer); // found a packet if(debug) { rprintf("Rx TSIP packet type: 0x%x len: %d rawlen: %d\r\n", TsipPacket[0], TsipPacketIdx, i); for(k=0; k<TsipPacketIdx; k++) { rprintfu08(TsipPacket[k]); rprintfChar(' '); } //rprintfu08(bufferGetFromFront(rxBuffer)); rprintfChar(' '); //rprintfu08(bufferGetFromFront(rxBuffer)); rprintfChar(' '); rprintfCRLF(); } // done with this processing session foundpacket = TRUE; break; } } } if(foundpacket) { // switch on the packet type switch(TsipPacket[0]) { case TSIPTYPE_GPSTIME: tsipProcessGPSTIME(TsipPacket); break; case TSIPTYPE_POSFIX_XYZ_SP: tsipProcessPOSFIX_XYZ_SP(TsipPacket); break; case TSIPTYPE_VELFIX_XYZ: tsipProcessVELFIX_XYZ(TsipPacket); break; case TSIPTYPE_POSFIX_LLA_SP: tsipProcessPOSFIX_LLA_SP(TsipPacket); break; case TSIPTYPE_VELFIX_ENU: tsipProcessVELFIX_ENU(TsipPacket); break; case TSIPTYPE_RAWDATA: break; default: //if(debug) rprintf("Unhandled TSIP packet type: 0x%x\r\n",TsipPacket[0]); break; } } return foundpacket; }
void rprintfTest(void) { u16 val; u08 mydata; u08 mystring[10]; float b; u08 small; u16 medium; u32 big; // print a little intro message so we know things are working rprintf("\r\nThis is my cool program!\r\n"); rprintf("\r\nWelcome to rprintf Test!\r\n"); // print single characters rprintfChar('H'); rprintfChar('e'); rprintfChar('l'); rprintfChar('l'); rprintfChar('o'); // print a constant string stored in FLASH rprintfProgStrM(" World!"); // print a carriage return, line feed combination rprintfCRLF(); // note that using rprintfCRLF() is more memory-efficient than // using rprintf("\r\n"), especially if you do it repeatedly mystring[0] = 'A'; mystring[1] = ' '; mystring[2] = 'S'; mystring[3] = 't'; mystring[4] = 'r'; mystring[5] = 'i'; mystring[6] = 'n'; mystring[7] = 'g'; mystring[8] = '!'; mystring[9] = 0; // null termination // print a null-terminated string from RAM rprintfStr(mystring); rprintfCRLF(); // print a section of a string from RAM // - start at index 2 // - print 6 characters rprintfStrLen(mystring, 2, 6); rprintfCRLF(); val = 24060; mydata = 'L'; // print a decimal number rprintf("This is a decimal number: %d\r\n", val); // print a hex number rprintf("This is a hex number: %x\r\n", mydata); // print a character rprintf("This is a character: %c\r\n", mydata); // print hex numbers small = 0x12; // a char medium = 0x1234; // a short big = 0x12345678; // a long rprintf("This is a 2-digit hex number (char) : "); rprintfu08(small); rprintfCRLF(); rprintf("This is a 4-digit hex number (short): "); rprintfu16(medium); rprintfCRLF(); rprintf("This is a 8-digit hex number (long) : "); rprintfu32(big); rprintfCRLF(); // print a formatted decimal number // - use base 10 // - use 8 characters // - the number is signed [TRUE] // - pad with '.' periods rprintf("This is a formatted decimal number: "); rprintfNum(10, 8, TRUE, '.', val); rprintfCRLF(); b = 1.23456; // print a floating point number // use 10-digit precision // NOTE: TO USE rprintfFloat() YOU MUST ENABLE SUPPORT IN global.h // use the following in your global.h: #define RPRINTF_FLOAT //rprintf("This is a floating point number: "); //rprintfFloat(8, b); //rprintfCRLF(); }
void ax88796RegDump(void) { unsigned char result; result = ax88796Read(TR); rprintf("Media State: "); if(!(result & AUTOD)) rprintf("Autonegotiation\r\n"); else if(result & RST_B) rprintf("PHY in Reset \r\n"); else if(!(result & RST_10B)) rprintf("10BASE-T \r\n"); else if(!(result & RST_TXB)) rprintf("100BASE-T \r\n"); //rprintf("TR regsiter : %x\r\n",result); //result = read_mii(0x10,0); //rprintf("MII regsiter 0x10: %x\r\n",result); rprintfProgStrM("Page0: CR BNRY PSR PST ISR TSR RSR MMR TR GPI\r\n"); rprintfProgStrM(" "); rprintfu08(ax88796Read(CR)); rprintfProgStrM(" "); rprintfu08(ax88796Read(BNRY)); rprintfProgStrM(" "); rprintfu08(ax88796Read(PSTART)); rprintfProgStrM(" "); rprintfu08(ax88796Read(PSTOP)); rprintfProgStrM(" "); rprintfu08(ax88796Read(ISR)); rprintfProgStrM(" "); rprintfu08(ax88796Read(TSR)); rprintfProgStrM(" "); rprintfu08(ax88796Read(RSR)); rprintfProgStrM(" "); rprintfu08(ax88796Read(MEMR)); rprintfProgStrM(" "); rprintfu08(ax88796Read(TR)); rprintfProgStrM(" "); rprintfu08(ax88796Read(GPI)); rprintfCRLF(); ax88796Write(CR,ax88796Read(CR)|PS0); rprintf("Page1: CR PAR CPR\r\n"); rprintfProgStrM(" "); rprintfu08(ax88796Read(CR)); rprintfProgStrM(" "); rprintfChar(ax88796Read(PAR0)); rprintfChar(ax88796Read(PAR1)); rprintfChar(ax88796Read(PAR2)); rprintfChar(ax88796Read(PAR3)); rprintfChar(ax88796Read(PAR4)); rprintfChar(ax88796Read(PAR5)); rprintfProgStrM(" "); rprintfu08(ax88796Read(CPR)); ax88796Write(CR,ax88796Read(CR)&~PS0); delay_ms(25); }
// Print a part of memory as a formatted hex table with ascii translation void debugPrintHexTable(u16 length, u08 *buffer) { u08 i; u16 j; u08 *buf; u08 s; buf = buffer; // print the low order address indicies and ASCII header rprintfProgStrM(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\r\n"); rprintfProgStrM(" ----------------------------------------------- ---- ASCII -----\r\n"); // print the data for(j=0; j<((length+15)>>4); j++) { // print the high order address index for this line rprintfu16(j<<4); rprintfChar(' '); // print the hex data for(i=0; i<0x10; i++) { // be nice and print only up to the exact end of the data if( ((j<<4)+i) < length) { // print hex byte rprintfu08(buf[(j<<4)+i]); rprintfChar(' '); } else { // we're past the end of the data's length // print spaces rprintfProgStrM(" "); } } // leave some space rprintfChar(' '); // print the ascii data for(i=0; i<0x10; i++) { // be nice and print only up to the exact end of the data if( ((j<<4)+i) < length) { // get the character s = buf[(j<<4)+i]; // make sure character is printable if(s >= 0x20) rprintfChar(s); else rprintfChar('.'); } else { // we're past the end of the data's length // print a space rprintfChar(' '); } } rprintfCRLF(); } }
/******************************************************************* * rprintf_test *******************************************************************/ void rprintf_test(void) { u16 val; u08 mydata; u08 mystring[10]; double b; u08 small; u16 medium; u32 big; // initialize the UART (serial port) uartInit(); // set the baud rate of the UART for our debug/reporting output uartSetBaudRate(38400); // initialize rprintf system // - use uartSendByte as the output for all rprintf statements // this will cause all rprintf library functions to direct their // output to the uart // - rprintf can be made to output to any device which takes characters. // You must write a function which takes an unsigned char as an argument // and then pass this to rprintfInit like this: rprintfInit(YOUR_FUNCTION); rprintfInit(uartSendByte); // initialize vt100 library vt100Init(); // clear the terminal screen vt100ClearScreen(); while (!(getkey() == 1)) //do the folling block until enter is pressed { // print a little intro message so we know things are working rprintf("\r\nWelcome to rprintf Test!\r\n"); // print single characters rprintfChar('H'); rprintfChar('e'); rprintfChar('l'); rprintfChar('l'); rprintfChar('o'); // print a constant string stored in FLASH rprintfProgStrM(" World!"); // print a carriage return, line feed combination rprintfCRLF(); // note that using rprintfCRLF() is more memory-efficient than // using rprintf("\r\n"), especially if you do it repeatedly mystring[0] = 'A'; mystring[1] = ' '; mystring[2] = 'S'; mystring[3] = 't'; mystring[4] = 'r'; mystring[5] = 'i'; mystring[6] = 'n'; mystring[7] = 'g'; mystring[8] = '!'; mystring[9] = 0; // null termination // print a null-terminated string from RAM rprintfStr(mystring); rprintfCRLF(); // print a section of a string from RAM // - start at index 2 // - print 6 characters rprintfStrLen(mystring, 2, 6); rprintfCRLF(); val = 24060; mydata = 'L'; // print a decimal number rprintf("This is a decimal number: %d\r\n", val); // print a hex number rprintf("This is a hex number: %x\r\n", mydata); // print a character rprintf("This is a character: %c\r\n", mydata); // print hex numbers small = 0x12; // a char medium = 0x1234; // a short big = 0x12345678; // a long rprintf("This is a 2-digit hex number (char) : "); rprintfu08(small); rprintfCRLF(); rprintf("This is a 4-digit hex number (short): "); rprintfu16(medium); rprintfCRLF(); rprintf("This is a 8-digit hex number (long) : "); rprintfu32(big); rprintfCRLF(); // print a formatted decimal number // - use base 10 // - use 8 characters // - the number is signed [TRUE] // - pad with '.' periods rprintf("This is a formatted decimal number: "); rprintfNum(10, 8, TRUE, '.', val); rprintfCRLF(); b = 1.23456; // print a floating point number // use 10-digit precision // NOTE: TO USE rprintfFloat() YOU MUST ENABLE SUPPORT IN global.h // use the following in your global.h: #define RPRINTF_FLOAT rprintf("This is a floating point number: "); rprintfFloat(8, b); rprintfCRLF(); } }