/*************************************************************** * 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 (USE_SST25VF064) SST25ReadArray(memory->address + offset, (BYTE *)buffer, nCount); #else #error "Please make sure that you have USE_SST25VF064 defined in the Hardware Profile header file." #endif return (nCount); }
/*************************************************************** * 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); }
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); }
/***************************************************************************** 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; }
void taskBackground(void* pvParameter) { static unsigned int val1; static unsigned int val2; time_t time_sec; // vTaskSetApplicationTaskTag( NULL, ( void * ) 'b' ); alarm_st = 0; #ifndef SIM_DEBUG //sysinit wdi_ena = 0; Spi_init(); if(get_time_rtc(&rtc_time)== FALSE) { SetError(RTC_ERR, HARWARE_ALRM_SCR); reset_rtc(); while(clear_os_rtc() == FALSE); init_time_rtc(&rtc_time); // rtc_time.tm_sec = 0; // rtc_time.tm_min = 0; // rtc_time.tm_hour = 0; // rtc_time.tm_mday = 1; // rtc_time.tm_wday = 0; // rtc_time.tm_mon = 0; // rtc_time.tm_year = 100; // rtc_time.tm_yday = 0; // rtc_time.tm_isdst = 0; set_time_rtc(&rtc_time)/*set_date()*/; } else if(mktime(&rtc_time)==-1) { SetError(RTC_ERR, HARWARE_ALRM_SCR); // reset_rtc(); init_time_rtc(&rtc_time); set_time_rtc(&rtc_time)/*set_date()*/; } time_sec = mktime(&rtc_time); set_clock(time_sec); // if(get_days(&calib_date) > 365) // if(time_sec - calib_time >= 31536000L /*365*24*60*60*/) // { // Beep(800); // lcd_clear(); // beep(800,4); // RTclock.timer = 2000; //10sec timeout // draw_text( 15, LCD_TXTLINE1, (uchar*)"SEND THE PUMP", LCD_PIXEL_ON,0); // draw_text( 54, LCD_TXTLINE2, (uchar*)"TO", LCD_PIXEL_ON,0); // draw_text( 29, LCD_TXTLINE3, (uchar*)"CALIBRATE", LCD_PIXEL_ON,0); // while(RTclock.timer > 0); // } SST25ProtDisable(); SST25ReadArray(PARAM_E2PIMG_BASE, &E2pImage, sizeof(E2pImage_t)); if(crc16((unsigned char*)&E2pImage, sizeof(E2pImage_t)) != 0) { SetError(EEPROM_ERR, HARWARE_ALRM_SCR); set_defaults(); } SST25ReadArray(CLBR_E2PIMG_BASE, &Clbr_E2pImage, sizeof(Clbr_E2pImage_t)); if(crc16((unsigned char*)&Clbr_E2pImage, sizeof(Clbr_E2pImage_t)) != 0) { SetError(EEPROM_ERR, HARWARE_ALRM_SCR); set_fact_defaults(); } if(GetError() != 0) { err_code = GetError(); ClearError(); ((unsigned int*)&E2pImage)[sizeof(E2pImage_t)/2 - 1] = crc16(&E2pImage, sizeof(E2pImage_t) - 2); SST25SectorErase(PARAM_E2PIMG_BASE); if(!SST25WriteArray(PARAM_E2PIMG_BASE, &E2pImage, sizeof(E2pImage_t))) /*CriticalError("eeprom err")*/; } MCP23S08Init(); MCP4822Write(0, zero_press1 , 0); MCP4822Write(1, zero_press2 , 0); init_motor(); init_airdet(); #endif init_keypad(); init_clock(); CheckParams(); /* drop task priority */ vTaskPrioritySet( hBACKGRNDTask, tskIDLE_PRIORITY + 1 ); while (1) { vTaskDelay( 50 / portTICK_RATE_MS ); // Wait 50ms if(val1 > 0x0fff) val1 = 0; else val1++; if(val2 > 0x0fff) val1 = 0; else val2++; if(!wdi_ena) toggleExpGPO(WDI_EXTIOBIT); // ClrWdt(); // WD_PIN^= 1; /*toggle external watch dog */ } }