unsigned char ataWriteSectorsLBA( unsigned char Drive, unsigned long lba, unsigned int numsectors, unsigned char *Buffer) { unsigned int cyl, head, sect; unsigned char temp; #ifdef DEBUG_ATA rprintfProgStrM("ATA LBA write "); rprintfu32(lba); rprintfProgStrM(" "); rprintfu16(numsectors); rprintfProgStrM(" "); rprintfu16((unsigned int)Buffer); rprintfCRLF(); #endif sect = (int) ( lba & 0x000000ffL ); lba = lba >> 8; cyl = (int) ( lba & 0x0000ffff ); lba = lba >> 16; head = ( (int) ( lba & 0x0fL ) ) | ATA_HEAD_USE_LBA; temp = ataWriteSectorsCHS( Drive, head, cyl, sect, numsectors, Buffer ); if(temp) ataDiskErr(); return temp; }
void cs8900RegDump(void) { rprintfProgStrM("CS8900 PacketPage Registers\r\n"); rprintfProgStrM("CHIP ID: "); rprintfu16(cs8900ReadReg(PP_ChipID)); rprintfCRLF(); rprintfProgStrM("PP_ISAIOB: "); rprintfu16(cs8900ReadReg(PP_ISAIOB)); rprintfCRLF(); rprintfProgStrM("MAC addr: "); rprintfu16(cs8900ReadReg(PP_IA+0)); rprintfu16(cs8900ReadReg(PP_IA+2)); rprintfu16(cs8900ReadReg(PP_IA+4)); rprintfCRLF(); }
void cs8900IORegDump(void) { rprintfProgStrM("CS8900 I/O Registers\r\n"); rprintfProgStrM(" FRAME ISQ ADDR DATA0 DATA1\r\n"); rprintfProgStrM("-------------------------------\r\n"); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_RXTX_DATA_PORT0)); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_ISQ)); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_PP_PTR)); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_PP_DATA_PORT0)); rprintfProgStrM(" "); rprintfu16(cs8900Read16(CS8900_IO_PP_DATA_PORT1)); rprintfCRLF(); }
void ds18b20Print(u16 result, u08 resolution) { // print raw value rprintfProgStrM(" 0x"); rprintfu16(result); rprintfChar(' '); // print real temp rprintfNum(10, 4, TRUE , ' ', result>>4); rprintf("."); rprintfNum(10, 4, FALSE, '0', (10000*((u32)(result&0x000F)))/16 ); rprintfProgStrM(" C"); }
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(); } }
int netstackService(void) { int len; struct netEthHeader* ethPacket; // look for a packet len = nicPoll(NETSTACK_BUFFERSIZE, NetBuffer); if(len) { ethPacket = (struct netEthHeader*)&NetBuffer[0]; #if NET_DEBUG >= 5 rprintf("Received packet len: %d, type:", len); rprintfu16(htons(ethPacket->type)); rprintfCRLF(); rprintf("Packet Contents\r\n"); debugPrintHexTable(len, NetBuffer); #endif if(ethPacket->type == htons(ETHTYPE_IP)) { // process an IP packet #ifdef NETSTACK_DEBUG rprintfProgStrM("NET Rx: IP packet\r\n"); #endif // add the source to the ARP cache // also correctly set the ethernet packet length before processing? arpIpIn((struct netEthIpHeader*)&NetBuffer[0]); //arpPrintTable(); netstackIPProcess( len-ETH_HEADER_LEN, (ip_hdr*)&NetBuffer[ETH_HEADER_LEN] ); } else if(ethPacket->type == htons(ETHTYPE_ARP)) { // process an ARP packet #ifdef NETSTACK_DEBUG rprintfProgStrM("NET Rx: ARP packet\r\n"); #endif arpArpIn(len, ((struct netEthArpHeader*)&NetBuffer[0]) ); #ifdef NETSTACK_DEBUG //arpPrintTable(); #endif } } return len; }
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 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(); }
// 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(); } }