/********************************************************************* * Function: BYTE MPFSGet(void) * * PreCondition: MPFSOpen() != MPFS_INVALID && * MPFSGetBegin() == TRUE * * Input: None * * Output: Data byte from current address. * * Side Effects: None * * Overview: Reads a byte from current address. * * Note: Caller must call MPFSIsEOF() to check for end of * file condition ********************************************************************/ BYTE MPFSGet(void) { BYTE t; #if defined(MPFS_USE_PGRM) t = (BYTE)*_currentHandle; #else t = XEERead(); #endif _currentHandle++; if ( t == MPFS_DLE ) { #if defined(MPFS_USE_PGRM) t = (BYTE)*_currentHandle; #else t = XEERead(); #endif _currentHandle++; } else if ( t == MPFS_ETX ) { _currentHandle = MPFS_INVALID; } return t; }
static WORD initdata() { union { WORD tempvar; struct { BYTE LoByte; BYTE HiByte; } bytes; } TWOBYTES; BYTE programflags; XEEBeginRead(sizeof(AppConfig)+ 49000); //This is a cheat, needs to fix memory map properly! programflags = XEERead(); //ONLY autorun program on first execution if (initflag == 0) { initflag=1; runprogram = CHECK_BIT(programflags,0); debugoutput = CHECK_BIT(programflags,1); } TWOBYTES.bytes.HiByte = XEERead(); TWOBYTES.bytes.LoByte = XEERead(); return(TWOBYTES.tempvar); }
/********************************************************************* * Function: XEE_RESULT XEEReadArray(unsigned char control, * XEE_ADDR address, * unsigned char *buffer, * unsigned char length) * * PreCondition: XEEInit() is already called. * * Input: control - EEPROM control and address code. * address - Address from where array is to be read * buffer - Caller supplied buffer to hold the data * length - Number of bytes to read. * * Output: XEE_SUCCESS if successful * other value if failed. * * Side Effects: None * * Overview: Reads desired number of bytes in sequential mode. * This function performs all necessary steps * and releases the bus when finished. * * Note: None ********************************************************************/ XEE_RESULT XEEReadArray(unsigned char control, XEE_ADDR address, unsigned char *buffer, unsigned char length) { XEE_RESULT r; r = XEEBeginRead(control, address); if ( r != XEE_SUCCESS ) return r; while( length-- ) *buffer++ = XEERead(); r = XEEEndRead(); return r; }
/***************************************************************************** Function: BOOL MPFSGet(MPFS_HANDLE hMPFS, BYTE* c) Description: Reads a byte from a file. Precondition: The file handle referenced by hMPFS is already open. Parameters: hMPFS - the file handle from which to read c - Where to store the byte that was read Return Values: TRUE - The byte was successfully read FALSE - No byte was read because either the handle was invalid or the end of the file has been reached. ***************************************************************************/ BOOL MPFSGet(MPFS_HANDLE hMPFS, BYTE* c) { // Make sure we're reading a valid address if(hMPFS > MAX_MPFS_HANDLES) return FALSE; if( MPFSStubs[hMPFS].addr == MPFS_INVALID || MPFSStubs[hMPFS].bytesRem == 0u) return FALSE; if(c == NULL) { MPFSStubs[hMPFS].addr++; MPFSStubs[hMPFS].bytesRem--; return TRUE; } // Read function for EEPROM #if defined(MPFS_USE_EEPROM) // For performance, cache the last read address if(MPFSStubs[hMPFS].addr != lastRead+1) XEEBeginRead(MPFSStubs[hMPFS].addr + MPFS_HEAD); *c = XEERead(); lastRead = MPFSStubs[hMPFS].addr; MPFSStubs[hMPFS].addr++; #elif defined(MPFS_USE_SPI_FLASH) #if (GRAPHICS_PICTAIL_VERSION == 3) SST25ReadArray(MPFSStubs[hMPFS].addr + MPFS_HEAD, c, 1); #else xSemaphoreTake(QVGASemaphore, portMAX_DELAY); SST39PMPInit(); SST39ReadArray(MPFSStubs[hMPFS].addr + MPFS_HEAD, c, 1); LCDPMPInit(); xSemaphoreGive(QVGASemaphore); #endif MPFSStubs[hMPFS].addr++; #else #if defined(__C30__) { DWORD addr; DWORD_VAL read; BYTE i; // MPFS Images are addressed by the byte; Program memory by the word. // // Flash program memory is 24 bits wide and only even words are // implemented. The upper byte of the upper word is read as 0x00. // Address in program memory of any given byte is (MPFSAddr * 2) / 3 // // We will read 24 bits at a time, but need to support using only // fractions of the first and last byte. // Find the beginning address in program memory. addr = (MPFSStubs[hMPFS].addr / 3) << 1; // Find where to start in that first 3 bytes read.Val = (addr * 3) >> 1; if(read.Val == MPFSStubs[hMPFS].addr) i = 0; else if(read.Val+1 == MPFSStubs[hMPFS].addr) i = 1; else i = 2; // Add in the MPFS starting address offset addr += MPFS_HEAD; // Update the MPFS Handle MPFSStubs[hMPFS].addr++; // Read the DWORD read.Val = ReadProgramMemory(addr & 0x00FFFFFF); *c = read.v[i]; } #else { DWORD dwHITECHWorkaround = MPFS_HEAD; *c = *((ROM BYTE*)(MPFSStubs[hMPFS].addr+dwHITECHWorkaround)); MPFSStubs[hMPFS].addr++; } #endif #endif MPFSStubs[hMPFS].bytesRem--; return TRUE; }
/********************************************************************* * Function: BYTE MPFSGet(void) * * PreCondition: MPFSOpen() != MPFS_INVALID && * MPFSGetBegin() == TRUE * * Input: None * * Output: Data byte from current address. * * Side Effects: None * * Overview: Reads a byte from current address. * * Note: Caller must call MPFSIsEOF() to check for end of * file condition ********************************************************************/ BYTE MPFSGet(void) { BYTE t; #if defined(MPFS_USE_EEPROM) t = XEERead(); _currentHandle++; #elif defined(MPFS_USE_SPI_FLASH) //SPIFlashReadArray(_currentHandle++, (BYTE*)&t, 1); //orig SPIFlashReadArray(_currentHandle, (BYTE*)&t, 1); //ccs workaround _currentHandle++; //ccs workaround #else #if defined(__C30__) && !defined(__PCD__) //__CCS__ change { DWORD_VAL i; // The uppermost byte, ((DWORD_VAL*)&_currentHandle)->v[3]), is the byte lane to read from. // 16 bit PICs have a 24 bit wide Flash program word. Bytes 0-2 are the actual address, but // odd addresses aren't implemented. i.Val = ReadProgramMemory(_currentHandle & 0x00FFFFFF); t = i.v[((DWORD_VAL*)&_currentHandle)->v[3]++]; if(((DWORD_VAL*)&_currentHandle)->v[3] >= 3) { _currentHandle = (_currentHandle + 2) & 0x00FFFFFF; } } #else //t = (BYTE)*_currentHandle; //__ccs__ change because MPFS isn't rom pointer memcpypgm2ram(&t, _currentHandle, 1); //__ccs__ change because MPFS isn't rom pointer _currentHandle++; #endif #endif if(t == MPFS_DLE) { #if defined(MPFS_USE_EEPROM) t = XEERead(); _currentHandle++; #elif defined(MPFS_USE_SPI_FLASH) //SPIFlashReadArray(_currentHandle++, (BYTE*)&t, 1); //orig SPIFlashReadArray(_currentHandle, (BYTE*)&t, 1); //ccs workaround _currentHandle++; //ccs workaround #else #if defined(__C30__) && !defined(__PCD__) //__CCS__ change { DWORD_VAL i; // The uppermost byte, ((DWORD_VAL*)&_currentHandle)->v[3]), is the byte lane to read from. // 16 bit PICs have a 24 bit wide Flash program word. Bytes 0-2 are the actual address, but // odd addresses aren't implemented. i.Val = ReadProgramMemory(_currentHandle & 0x00FFFFFF); t = i.v[((DWORD_VAL*)&_currentHandle)->v[3]++]; if(((DWORD_VAL*)&_currentHandle)->v[3] >= 3) { _currentHandle = (_currentHandle + 2) & 0x00FFFFFF; } } #else //t = (BYTE)*_currentHandle; //__ccs__ change because MPFS isn't rom pointer memcpypgm2ram(&t, _currentHandle, 1); //__ccs__ change because MPFS isn't rom pointer _currentHandle++; #endif #endif } else if(t == MPFS_ETX) { _currentHandle = MPFS_INVALID; } //printf(UserPutc, " ret=%X\r\n", t); return t; }
/********************************************************************* * Function: BYTE MPFSGet(void) * * PreCondition: MPFSOpen() != MPFS_INVALID && * MPFSGetBegin() == TRUE * * Input: None * * Output: Data byte from current address. * * Side Effects: None * * Overview: Reads a byte from current address. * * Note: Caller must call MPFSIsEOF() to check for end of * file condition ********************************************************************/ BYTE MPFSGet(void) { BYTE t; #if defined(MPFS_USE_EEPROM) t = XEERead(); _currentHandle++; #else #if defined(__C30__) { DWORD_VAL i; // The uppermost byte, ((DWORD_VAL*)&_currentHandle)->v[3]), is the byte lane to read from. // 16 bit PICs have a 24 bit wide Flash program word. Bytes 0-2 are the actual address, but // odd addresses aren't implemented. i.Val = ReadProgramMemory(_currentHandle & 0x00FFFFFF); t = i.v[((DWORD_VAL*)&_currentHandle)->v[3]++]; if(((DWORD_VAL*)&_currentHandle)->v[3] >= 3) { _currentHandle = (_currentHandle + 2) & 0x00FFFFFF; } } #else t = (BYTE)*_currentHandle; _currentHandle++; #endif #endif if(t == MPFS_DLE) { #if defined(MPFS_USE_EEPROM) t = XEERead(); _currentHandle++; #else #if defined(__C30__) { DWORD_VAL i; // The uppermost byte, ((DWORD_VAL*)&_currentHandle)->v[3]), is the byte lane to read from. // 16 bit PICs have a 24 bit wide Flash program word. Bytes 0-2 are the actual address, but // odd addresses aren't implemented. i.Val = ReadProgramMemory(_currentHandle & 0x00FFFFFF); t = i.v[((DWORD_VAL*)&_currentHandle)->v[3]++]; if(((DWORD_VAL*)&_currentHandle)->v[3] >= 3) { _currentHandle = (_currentHandle + 2) & 0x00FFFFFF; } } #else t = (BYTE)*_currentHandle; _currentHandle++; #endif #endif } else if(t == MPFS_ETX) { _currentHandle = MPFS_INVALID; } return t; }
/***************************************************************************** Function: bool MPFSGet(MPFS_HANDLE hMPFS, uint8_t* c) Description: Reads a byte from a file. Precondition: The file handle referenced by hMPFS is already open. Parameters: hMPFS - the file handle from which to read c - Where to store the byte that was read Return Values: true - The byte was successfully read false - No byte was read because either the handle was invalid or the end of the file has been reached. ***************************************************************************/ bool MPFSGet(MPFS_HANDLE hMPFS, uint8_t* c) { // Make sure we're reading a valid address if(hMPFS > MAX_MPFS_HANDLES) return false; if( MPFSStubs[hMPFS].addr == MPFS_INVALID || MPFSStubs[hMPFS].bytesRem == 0u) return false; if(c == NULL) { MPFSStubs[hMPFS].addr++; MPFSStubs[hMPFS].bytesRem--; return true; } // Read function for EEPROM #if defined(MPFS_USE_EEPROM) // For performance, cache the last read address if(MPFSStubs[hMPFS].addr != lastRead+1) XEEBeginRead(MPFSStubs[hMPFS].addr + MPFS_HEAD); *c = XEERead(); lastRead = MPFSStubs[hMPFS].addr; MPFSStubs[hMPFS].addr++; #elif defined(MPFS_USE_SPI_FLASH) SPIFlashReadArray(MPFSStubs[hMPFS].addr + MPFS_HEAD, c, 1); MPFSStubs[hMPFS].addr++; #else #if defined(__C30__) { uint32_t addr; TCPIP_UINT32_VAL read; uint8_t i; // MPFS Images are addressed by the byte; Program memory by the word. // // Flash program memory is 24 bits wide and only even words are // implemented. The upper byte of the upper word is read as 0x00. // Address in program memory of any given byte is (MPFSAddr * 2) / 3 // // We will read 24 bits at a time, but need to support using only // fractions of the first and last byte. // Find the beginning address in program memory. addr = (MPFSStubs[hMPFS].addr / 3) << 1; // Find where to start in that first 3 bytes read.Val = (addr * 3) >> 1; if(read.Val == MPFSStubs[hMPFS].addr) i = 0; else if(read.Val+1 == MPFSStubs[hMPFS].addr) i = 1; else i = 2; // Add in the MPFS starting address offset addr += MPFS_HEAD; // Update the MPFS Handle MPFSStubs[hMPFS].addr++; // Read the uint32_t read.Val = ReadProgramMemory(addr & 0x00FFFFFF); *c = read.v[i]; } #else { uint32_t dwHITECHWorkaround = MPFS_HEAD; *c = *((const uint8_t*)(MPFSStubs[hMPFS].addr+dwHITECHWorkaround)); MPFSStubs[hMPFS].addr++; } #endif #endif MPFSStubs[hMPFS].bytesRem--; return true; }
/********************************************************************* * Function: void InitAppConfig(void) * * PreCondition: MPFSInit() is already called. * * Input: None * * Output: Write/Read non-volatile config variables. * * Side Effects: None * * Overview: None * * Note: None ********************************************************************/ static void InitAppConfig(void) { #if defined(MPFS_USE_EEPROM) BYTE c; BYTE *p; #endif /* * Load default configuration into RAM. */ AppConfig.MyIPAddr.v[0] = MY_DEFAULT_IP_ADDR_BYTE1; AppConfig.MyIPAddr.v[1] = MY_DEFAULT_IP_ADDR_BYTE2; AppConfig.MyIPAddr.v[2] = MY_DEFAULT_IP_ADDR_BYTE3; AppConfig.MyIPAddr.v[3] = MY_DEFAULT_IP_ADDR_BYTE4; AppConfig.MyMask.v[0] = MY_DEFAULT_MASK_BYTE1; AppConfig.MyMask.v[1] = MY_DEFAULT_MASK_BYTE2; AppConfig.MyMask.v[2] = MY_DEFAULT_MASK_BYTE3; AppConfig.MyMask.v[3] = MY_DEFAULT_MASK_BYTE4; AppConfig.MyGateway.v[0] = MY_DEFAULT_GATE_BYTE1; AppConfig.MyGateway.v[1] = MY_DEFAULT_GATE_BYTE2; AppConfig.MyGateway.v[2] = MY_DEFAULT_GATE_BYTE3; AppConfig.MyGateway.v[3] = MY_DEFAULT_GATE_BYTE4; AppConfig.MyMACAddr.v[0] = MY_DEFAULT_MAC_BYTE1; AppConfig.MyMACAddr.v[1] = MY_DEFAULT_MAC_BYTE2; AppConfig.MyMACAddr.v[2] = MY_DEFAULT_MAC_BYTE3; AppConfig.MyMACAddr.v[3] = MY_DEFAULT_MAC_BYTE4; AppConfig.MyMACAddr.v[4] = MY_DEFAULT_MAC_BYTE5; AppConfig.MyMACAddr.v[5] = MY_DEFAULT_MAC_BYTE6; #if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING) AppConfig.Flags.bIsDHCPEnabled = TRUE; #else AppConfig.Flags.bIsDHCPEnabled = FALSE; #endif #if defined(MPFS_USE_EEPROM) p = (BYTE*)&AppConfig; XEEBeginRead(EEPROM_CONTROL, 0x00); c = XEERead(); XEEEndRead(); /* * When a record is saved, first byte is written as 0x55 to indicate * that a valid record was saved. */ if ( c == 0x55 ) { XEEBeginRead(EEPROM_CONTROL, 0x01); for ( c = 0; c < sizeof(AppConfig); c++ ) *p++ = XEERead(); XEEEndRead(); } else SaveAppConfig(); #endif }