Esempio n. 1
0
/***************************************************************
 * WORD ExternalMemoryCallback(IMAGE_EXTERNAL *memory, LONG offset, WORD nCount, void *buffer)
 ***************************************************************/
WORD ExternalMemoryCallback(IMAGE_EXTERNAL *memory, LONG offset, WORD nCount, void *buffer)
{
    // Read data requested into buffer provided
    #if defined (GFX_PICTAIL_V3) || defined (PIC24FJ256DA210_DEV_BOARD) || defined (GFX_PICTAIL_V3E)
    SST25ReadArray(memory->address + offset, // address to read from
    (BYTE *)buffer, nCount);
    #else
    SST39PMPInit();
    SST39ReadArray(memory->address + offset, // address to read from
    (BYTE *)buffer, nCount);
    LCDPMPInit();
    #endif

    return (nCount);
}
Esempio n. 2
0
WORD ExternalMemoryCallback(IMAGE_EXTERNAL *memory, LONG offset, WORD nCount, void *buffer)
{
    if(memory->ID == SST39_MEMORY)
    {

        // Read data requested into buffer provided
        #ifdef GFX_PICTAIL_V2
        SST39PMPInit();
        SST39ReadArray(memory->address + offset, // address to read from
        (BYTE *)buffer, nCount);
        LCDPMPInit();
        #else
        SST25ReadArray(memory->address + offset, // address to read from
        (BYTE *)buffer, nCount);
        #endif
    }

    return (nCount);
}
Esempio n. 3
0
/*****************************************************************************
  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;
}
Esempio n. 4
0
/*****************************************************************************
  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;
}