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 dhcpPrintHeader(struct netDhcpHeader* packet) { rprintfProgStrM("DHCP Packet:\r\n"); // print op rprintfProgStrM("Op : "); switch (packet->bootp.op) { case BOOTP_OP_BOOTREQUEST: rprintfProgStrM("BOOTREQUEST"); break; case BOOTP_OP_BOOTREPLY: rprintfProgStrM("BOOTREPLY"); break; default: rprintfProgStrM("UNKNOWN"); break; } rprintfCRLF(); // print transaction ID rprintfProgStrM("XID : 0x"); rprintfu32(packet->bootp.xid); rprintfCRLF(); // print client IP address rprintfProgStrM("ClIpAddr: "); netPrintIPAddr(htonl(packet->bootp.ciaddr)); rprintfCRLF(); // print 'your' IP address rprintfProgStrM("YrIpAddr: "); netPrintIPAddr(htonl(packet->bootp.yiaddr)); rprintfCRLF(); // print server IP address rprintfProgStrM("SvIpAddr: "); netPrintIPAddr(htonl(packet->bootp.siaddr)); rprintfCRLF(); // print gateway IP address rprintfProgStrM("GwIpAddr: "); netPrintIPAddr(htonl(packet->bootp.giaddr)); rprintfCRLF(); // print client hardware address rprintfProgStrM("ClHwAddr: "); netPrintEthAddr((struct netEthAddr*)packet->bootp.chaddr); rprintfCRLF(); }
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(); }
u08 mmcWrite(u32 sector, u08* buffer) { u08 r1; u16 i; u16 retries; spiSetClockPhase(SD_CLOCK_PHASE); spiSetBitrate(SD_TRANSFER_SPI_DIV); // assert chip select _mmcEnableCS(); retries = 0; // wait for card not busy, at most 250ms if (cardBusy) { spiTransferByte(0xFF); do { r1 = spiTransferByte(0xFF); retries++; if (!r1) { delay_us(250); } else break; } while (!r1 && retries < 0xFFE); } if (retries == 0xFFE) { _mmcDisableCS(); rprintf("mmcWrite - card still busy, sector "); rprintfu32(sector); rprintfCRLF(); return -1; } // issue command r1 = mmcCommand(MMC_WRITE_BLOCK, sector<<9); #ifdef MMC_DEBUG //rprintf("MMC Write Block R1=0x%x\r\n", r1); #endif // check for valid response if(r1 != 0x00) { _mmcDisableCS(); // Andreas - was reversed rprintf("mmcWrite - invalid response %x\r\n",r1); return r1; } // send dummy spiTransferByte(0xFF); // send data start token spiTransferByte(MMC_STARTBLOCK_WRITE); // write data for(i=0; i<0x200; i++) { spiTransferByte(*buffer++); } // write 16-bit CRC (dummy values) spiTransferByte(0xFF); spiTransferByte(0xFF); // read data response token r1 = spiTransferByte(0xFF); if( (r1&MMC_DR_MASK) != MMC_DR_ACCEPT) { _mmcDisableCS(); return r1; } #ifdef MMC_DEBUG //rprintf("Data Response Token=0x%x\r\n", r1); #endif /* old busy code // wait until card not busy while(!spiTransferByte(0xFF)); */ // Provide card with 8 clock cycles to complete the operation spiTransferByte(0xFF); cardBusy = 1; // release chip select _mmcDisableCS(); // return success return 0; }
u08 mmcRead(u32 sector, u08* buffer) { u08 r1; u16 i; u16 retries; //#ifdef MMC_DEBUG //rprintf("mmcRead("); //rprintfu32(sector); //rprintf(")\r\n"); //#endif spiSetClockPhase(SD_CLOCK_PHASE); spiSetBitrate(SD_TRANSFER_SPI_DIV); _mmcEnableCS(); retries = 0; // wait for card not busy, at most 250ms if (cardBusy) { spiTransferByte(0xFF); do { r1 = spiTransferByte(0xFF); retries++; if (!r1) { delay_us(250); } else break; } while (!r1 && retries < 0xFFE); } if (retries == 0xFFE) { _mmcDisableCS(); rprintf("mmcRead - card still busy, sector "); rprintfu32(sector); rprintfCRLF(); return -1; } do { r1 = spiTransferByte(0xFF); } while (r1 != 0xFF); //rprintf("1: r1 = %u\r\n",r1); mmcCommandNoWait(MMC_READ_SINGLE_BLOCK, sector<<9); // wait for card response do { r1 = spiTransferByte(0xFF); } while (r1 == 0xFF); //rprintf("2: r1 = %u\r\n",r1); spiTransferByte(0xFF); // NOTE TO SELF - Check error tokens // wait for block start retries = 0; do { retries++; //rprintf("mmcRead() - Timed out waiting for startblock: R1=0x%x\r\n", r1); if (retries > 0xFFE) { #ifdef MMC_DEBUG rprintf("mmcRead() - Timed out waiting for startblock: R1=0x%x, 0x%x retries\r\n", r1, retries); #endif _mmcDisableCS(); return -1; } } while((r1 = spiTransferByte(0xFF)) != MMC_STARTBLOCK_READ); //rprintf("Read startblock after 0x%x retries\r\n", retries); // read in data for(i=0; i<0x200; i++) { *buffer++ = spiTransferByte(0xFF); //rprintf("%d\r\n",buffer[i]); } // read 16-bit CRC spiTransferByte(0xFF); spiTransferByte(0xFF); // Provide card with 8 clock cycles to complete the operation spiTransferByte(0xFF); _mmcDisableCS(); cardBusy = 1; // return success return 0; }
/******************************************************************* * 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(); } }