//--------------------------------------------------------------------------- // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // // Except as contained in this notice, the name of Dallas Semiconductor // shall not be used except as stated in the Dallas Semiconductor // Branding Policy. //-------------------------------------------------------------------------- // // owMem.c - Goes through the testing the memory bank for different parts. // Version 2.00 // #define DEBUG 1 #include #include #include "ownet.h" #include "rawmem.h" #include "mbshaee.h" // Defines for the menu lists #define MAIN_MENU 0 #define BANK_MENU 1 #define ENTRY_MENU 2 // Defines for the switch statements for Main Menu #define MAIN_SELECT_DEVICE 0 #define MAIN_QUIT 1 // Defines for the switch statements for Memory Bank #define BANK_INFO 0 #define BANK_READ_BLOCK 1 #define BANK_READ_PAGE 2 #define BANK_READ_UDP 3 #define BANK_WRITE_BLOCK 4 #define BANK_WRITE_UDP 5 #define BANK_NEW_BANK 6 #define BANK_MAIN_MENU 7 // Defines for the switch statements for data entry #define MODE_TEXT 0 #define MODE_HEX 1 // Number of devices to list #define MAXDEVICES 10 // Max number for data entry #define MAX_LEN 256 // External functions extern int owNext(int,int,int); extern void owSerialNum(int,uchar *,int); extern int owAcquire(int,char *); extern void owRelease(int portnum); extern int redirectPage(int bank, int portnum, uchar *SNum, int page, int newPage); extern int lockPage(int bank, int portnum, uchar *SNum, int page); extern int lockRedirectPage(int bank, int portnum, uchar *SNum, int page); extern int getData(uchar*, int, SMALLINT); // Local functions int menuSelect(int menu); SMALLINT selectDevice(int numDevices, uchar AllDevices[][8]); void printDeviceInfo (int portnum, uchar SNum[8]); SMALLINT selectBank(SMALLINT bank, uchar *SNum); void displayBankInformation (SMALLINT bank, int portnum, uchar SNum[8]); int getNumber (int min, int max); SMALLINT dumpBankBlock (SMALLINT bank, int portnum, uchar SNum[8], int addr, int len); SMALLINT dumpBankPage (SMALLINT bank, int portnum, uchar SNum[8], int pg); SMALLINT dumpBankPagePacket(SMALLINT bank, int portnum, uchar SNum[8], int pg); SMALLINT bankWriteBlock (SMALLINT bank, int portnum, uchar SNum[8], int addr, uchar *data, int length); SMALLINT bankWritePacket(SMALLINT bank, int portnum, uchar SNum[8], int pg, uchar *data, int length); SMALLINT optionSHAEE(SMALLINT bank, int portnum, uchar *SNum); // Global necessary for screenio int VERBOSE; uchar AllSN[MAXDEVICES][8]; int main(int argc, char **argv) { int len, addr, page, answer; int done = FALSE; SMALLINT bank = 1; uchar data[8000]; int portnum = 0; uchar AllSN[MAXDEVICES][8]; int NumDevices; int owd; char msg[132]; // check for required port name if (argc != 2) { sprintf(msg,"1-Wire Net name required on command line!\n" " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" " "(Linux DS2480),\"1\" (Win32 TMEX)\n"); printf("%s\n",msg); return 0; } printf("\n1-Wire Memory utility console application Version 0.01\n"); if(!owAcquire(portnum,argv[1])) { OWERROR_DUMP(stdout); return 0; } else { // loop to do menu do { // Main menu switch (menuSelect(MAIN_MENU)) { case MAIN_SELECT_DEVICE : // find all parts // loop to find all of the devices up to MAXDEVICES NumDevices = 0; do { // perform the search if (!owNext(portnum,TRUE, FALSE)) break; owSerialNum(portnum,AllSN[NumDevices], TRUE); NumDevices++; } while (NumDevices < (MAXDEVICES - 1)); // select a device owd = selectDevice(NumDevices,&AllSN[0]); // display device info printDeviceInfo(portnum,&AllSN[owd][0]); // select a bank bank = selectBank(bank, &AllSN[owd][0]); if((AllSN[owd][0] == 0x33) || (AllSN[owd][0] == 0xB3)) bank = optionSHAEE(bank,portnum,&AllSN[owd][0]); // display bank information displayBankInformation(bank,portnum,&AllSN[owd][0]); // loop on bank menu do { switch (menuSelect(BANK_MENU)) { case BANK_INFO : // display bank information displayBankInformation(bank,portnum,&AllSN[owd][0]); break; case BANK_READ_BLOCK : // read a block printf("Enter the address to start reading: "); addr = getNumber(0, (owGetSize(bank,&AllSN[owd][0])-1)); printf("\n"); printf("Enter the length of data to read: "); len = getNumber(0, owGetSize(bank, &AllSN[owd][0])); printf("\n"); if(!dumpBankBlock(bank,portnum,&AllSN[owd][0],addr,len)) OWERROR_DUMP(stderr); break; case BANK_READ_PAGE : printf("Enter the page number to read: "); page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1)); printf("\n"); if(!dumpBankPage(bank,portnum,&AllSN[owd][0],page)) OWERROR_DUMP(stderr); break; case BANK_READ_UDP : printf("Enter the page number to read: "); page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1)); printf("\n"); if(!dumpBankPagePacket(bank,portnum,&AllSN[owd][0],page)) OWERROR_DUMP(stderr); break; case BANK_WRITE_BLOCK : // write a block printf("Enter the address to start writing: "); addr = getNumber(0, (owGetSize(bank,&AllSN[owd][0])-1)); if(menuSelect(ENTRY_MENU) == MODE_TEXT) len = getData(data,MAX_LEN,MODE_TEXT); else len = getData(data,MAX_LEN,MODE_HEX); if(!bankWriteBlock(bank,portnum,&AllSN[owd][0],addr,data,len)) { OWERROR_DUMP(stderr); break; } if(owCanRedirectPage(bank,&AllSN[owd][0])) { printf("Enter if you want to redirect page (0 no, 1 yes): "); answer = getNumber(0,1); if(answer) { printf("What page would you like to redirect:"); page = getNumber(0,255); printf("Where would you like to redirect:"); addr = getNumber(0,255); if(!redirectPage(bank,portnum,&AllSN[owd][0],page,addr)) { OWERROR_DUMP(stderr); break; } } } if(owCanLockPage(bank,&AllSN[owd][0])) { printf("Enter if you want to lock page (0 no, 1 yes):"); answer = getNumber(0,1); if(answer) { printf("What page would you like to lock?"); page = getNumber(0,255); if(!lockPage(bank,portnum,&AllSN[owd][0],page)) { OWERROR_DUMP(stderr); break; } } } if(owCanLockRedirectPage(bank,&AllSN[owd][0])) { printf("Enter if you want to lock redirected page (0 no, 1 yes):"); answer = getNumber(0,1); if(answer) { printf("Which redirected page do you want to lock:"); page = getNumber(0,255); if(!lockRedirectPage(bank,portnum,&AllSN[owd][0],page)) { OWERROR_DUMP(stderr); break; } } } break; case BANK_WRITE_UDP : printf("Enter the page number to write a UDP to: "); page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1)); if(menuSelect(ENTRY_MENU) == MODE_TEXT) len = getData(data,MAX_LEN,MODE_TEXT); else len = getData(data,MAX_LEN,MODE_HEX); if(!bankWritePacket(bank,portnum,&AllSN[owd][0],page,data,len)) OWERROR_DUMP(stderr); break; case BANK_NEW_BANK : // select a bank bank = selectBank(bank,&AllSN[owd][0]); if((AllSN[owd][0] == 0x33) || (AllSN[owd][0] == 0xB3)) bank = optionSHAEE(bank,portnum,&AllSN[owd][0]); // display bank information displayBankInformation(bank,portnum,&AllSN[owd][0]); break; case BANK_MAIN_MENU : done = TRUE; break; } } while (!done); done = FALSE; break; case MAIN_QUIT : done = TRUE; break; } // Main menu switch } while (!done); // loop to do menu owRelease(portnum); } // else for owAcquire return 1; } //-------- //-------- Read methods //-------- /** * Read a block from a memory bank and print in hex * * bank MemoryBank to read a block from * portnum port number * SNum the serial number for the device * addr address to start reading from * len length of data to read * * @return 'true' if the dumping of the memory bank * worked. */ SMALLINT dumpBankBlock (SMALLINT bank, int portnum, uchar SNum[8], int addr, int len) { uchar read_buf[8000]; // make larger if the data being read is larger int i; if(!owRead(bank,portnum,SNum,addr,FALSE,&read_buf[0],len)) return FALSE; for(i=0;i=0;j--) printf("%02X ",AllDevices[i][j]); printf("\n"); } return getNumber(0,numDevices-1); } /** * Create a menu of memory banks from the provided OneWireContainer * allow the user to select one. * * bank the memory bank to be used. * SNum The serial number for the chosen device. * * @return MemoryBank memory bank selected */ SMALLINT selectBank(SMALLINT bank, uchar *SNum) { int i; int numberBanks = 0; printf("Memory Bank Selection for "); for(i=7;i>=0;i--) printf("%02X ",SNum[i]); printf("\n"); numberBanks = owGetNumberBanks(SNum[0]); // get the banks for (i=0;i0 && (value>max || value=0;i--) printf("%02X ",SNum[i]); printf("\n"); printf("* iButton Description: %s\n",owGetDescription(&SNum[0])); printf("*************************************************************************\n"); /* System.out.println( "* Device Max speed: " + ((owd.getMaxSpeed() == DSPortAdapter.SPEED_OVERDRIVE) ? "Overdrive" : "Normal"));*/ } /** * Display the information about the current memory back provided. * * portnum port number for the device * SNum serial number for the device */ void displayBankInformation (SMALLINT bank, int portnum, uchar SNum[8]) { printf("\n"); printf("|------------------------------------------------------------------------\n"); printf("| Bank: %s\n",owGetBankDescription(bank,SNum)); printf("| Size: %d starting at physical address %d\n",owGetSize(bank,SNum), owGetStartingAddress(bank,SNum)); printf("| Features: "); if(owIsReadWrite(bank,portnum,SNum)) printf("Read/Write "); if(owIsWriteOnce(bank,portnum,SNum)) printf("Write-once "); if(owIsReadOnly(bank,portnum,SNum)) printf("Read-only "); if(owIsGeneralPurposeMemory(bank,SNum)) printf("general-purpose "); else printf("not-general-purpose "); if(owIsNonVolatile(bank,SNum)) printf("non-volatile\n"); else printf("volatile\n"); if(owNeedsProgramPulse(bank,SNum)) printf("|\tneeds-program-pulse \n"); if(owNeedsPowerDelivery(bank,SNum)) printf("|\tneeds-power-delivery \n"); printf("| Pages: %d pages of length %d bytes ", owGetNumberPages(bank,SNum),owGetPageLength(bank,SNum)); if(owIsGeneralPurposeMemory(bank,SNum)) printf("giving %d bytes Packet data payload",owGetMaxPacketDataLength(bank,SNum)); printf("\n| Page Features: "); if(owHasPageAutoCRC(bank,SNum)) printf("page-device-CRC "); if(owCanRedirectPage(bank,SNum)) printf("pages-redirectable "); if(owCanLockPage(bank,SNum)) printf("pages-lockable \n"); if((owCanLockPage(bank,SNum)) && (owCanLockRedirectPage(bank,SNum))) printf("|\tredirection-lockable\n"); else if(owCanLockRedirectPage(bank,SNum)) printf("redirection-lockable."); if(!owCanLockPage(bank,SNum)) printf("\n"); if(owHasExtraInfo(bank,SNum)) printf("| Extra information for each page: %s length %d\n", owGetExtraInfoDesc(bank,SNum), owGetExtraInfoLength(bank,SNum)); printf("|------------------------------------------------------------------------\n\n"); }