/***************************************************************************** Function: WORD MPFSGetArray(MPFS_HANDLE hMPFS, BYTE* cData, WORD wLen) Description: Reads a series of bytes from a file. Precondition: The file handle referenced by hMPFS is already open. Parameters: hMPFS - the file handle from which to read cData - where to store the bytes that were read wLen - how many bytes to read Returns: The number of bytes successfully read. If this is less than wLen, an EOF occurred while attempting to read. ***************************************************************************/ WORD MPFSGetArray(MPFS_HANDLE hMPFS, BYTE* cData, WORD wLen) { // Make sure we're reading a valid address if(hMPFS > MAX_MPFS_HANDLES) return 0; // Determine how many we can actually read if(wLen > MPFSStubs[hMPFS].bytesRem) wLen = MPFSStubs[hMPFS].bytesRem; // Make sure we're reading a valid address if(MPFSStubs[hMPFS].addr == MPFS_INVALID || wLen == 0u) return 0; if(cData == NULL) { MPFSStubs[hMPFS].addr += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; return wLen; } // Read the data #if defined(MPFS_USE_EEPROM) XEEReadArray(MPFSStubs[hMPFS].addr+MPFS_HEAD, cData, wLen); MPFSStubs[hMPFS].addr += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; lastRead = MPFS_INVALID; #elif defined(MPFS_USE_SPI_FLASH) #if (GRAPHICS_PICTAIL_VERSION == 3) SST25ReadArray(MPFSStubs[hMPFS].addr+MPFS_HEAD, cData, wLen); #else xSemaphoreTake(QVGASemaphore, portMAX_DELAY); SST39PMPInit(); SST39ReadArray(MPFSStubs[hMPFS].addr+MPFS_HEAD, cData, wLen); LCDPMPInit(); xSemaphoreGive(QVGASemaphore); #endif MPFSStubs[hMPFS].addr += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; #else #if defined(__C30__) { DWORD addr; DWORD_VAL read; WORD count; 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 += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; // Read the first DWORD read.Val = ReadProgramMemory(addr & 0x00FFFFFF); addr += 2; // Copy values as needed for(count = wLen; count > 0; cData++, count--) { // Copy the next value in *cData = read.v[i++]; // Check if a new DWORD is needed if(i == 3 && count != 1) {// Read in a new DWORD read.Val = ReadProgramMemory(addr & 0x00FFFFFF); addr += 2; i = 0; } } } #else { DWORD dwHITECHWorkaround = MPFS_HEAD; memcpypgm2ram(cData, (ROM void*)(MPFSStubs[hMPFS].addr + dwHITECHWorkaround), wLen); MPFSStubs[hMPFS].addr += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; } #endif #endif return wLen; }
/***************************************************************************** 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: uint16_t MPFSGetArray(MPFS_HANDLE hMPFS, uint8_t* cData, uint16_t wLen) Description: Reads a series of bytes from a file. Precondition: The file handle referenced by hMPFS is already open. Parameters: hMPFS - the file handle from which to read cData - where to store the bytes that were read wLen - how many bytes to read Returns: The number of bytes successfully read. If this is less than wLen, an EOF occurred while attempting to read. ***************************************************************************/ uint16_t MPFSGetArray(MPFS_HANDLE hMPFS, uint8_t* cData, uint16_t wLen) { // Make sure we're reading a valid address if(hMPFS > MAX_MPFS_HANDLES) return 0; // Determine how many we can actually read if(wLen > MPFSStubs[hMPFS].bytesRem) wLen = MPFSStubs[hMPFS].bytesRem; // Make sure we're reading a valid address if(MPFSStubs[hMPFS].addr == MPFS_INVALID || wLen == 0u) return 0; if(cData == NULL) { MPFSStubs[hMPFS].addr += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; return wLen; } // Read the data #if defined(MPFS_USE_EEPROM) XEEReadArray(MPFSStubs[hMPFS].addr+MPFS_HEAD, cData, wLen); MPFSStubs[hMPFS].addr += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; lastRead = MPFS_INVALID; #elif defined(MPFS_USE_SPI_FLASH) SPIFlashReadArray(MPFSStubs[hMPFS].addr+MPFS_HEAD, cData, wLen); MPFSStubs[hMPFS].addr += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; #else #if defined(__C30__) { uint32_t addr; TCPIP_UINT32_VAL read; uint16_t count; 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 += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; // Read the first uint32_t read.Val = ReadProgramMemory(addr & 0x00FFFFFF); addr += 2; // Copy values as needed for(count = wLen; count > 0; cData++, count--) { // Copy the next value in *cData = read.v[i++]; // Check if a new uint32_t is needed if(i == 3 && count != 1) {// Read in a new uint32_t read.Val = ReadProgramMemory(addr & 0x00FFFFFF); addr += 2; i = 0; } } } #else { uint32_t dwHITECHWorkaround = MPFS_HEAD; memcpy(cData, (const void*)(MPFSStubs[hMPFS].addr + dwHITECHWorkaround), wLen); MPFSStubs[hMPFS].addr += wLen; MPFSStubs[hMPFS].bytesRem -= wLen; } #endif #endif return wLen; }
/***************************************************************************** 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; }