Index: NVDataMgmt.c =================================================================== diff -u -ra26f096ba8f55604062fa36bfacc3f3e7f4acecd -r82fa83e4d882fdcd96b4b5bdf706044d45a82c70 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision a26f096ba8f55604062fa36bfacc3f3e7f4acecd) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 82fa83e4d882fdcd96b4b5bdf706044d45a82c70) @@ -76,9 +76,8 @@ // Data addresses and length in RTC RAM #define LOG_RECORD_START_ADDRESS 0x00000000 // 0 ///< Log record start address in RTC RAM (0). #define HD_USAGE_INFO_START_ADDRESS 0x00000010 // 16 ///< HD usage info start address in RTC RAM (16). -#define DG_USAGE_INFO_START_ADDRESS 0x00000020 // 32 ///< DG usage info start address in RTC RAM (32). -#define SERVICE_RECORD_START_ADDRESS 0x00000030 // 48 ///< Service date record start address in RTC RAM (HD/DG) (48). -#define DG_SCHEDULED_RUNS_START_ADDRESS (SERVICE_RECORD_START_ADDRESS + sizeof(DG_SERVICE_GROUP_T)) ///< DG scheduled runs start address in RTC RAM. +#define DG_USAGE_INFO_START_ADDRESS 0x00000030 // 48 ///< DG usage info start address in RTC RAM (48). +#define DG_SCHEDULED_RUNS_START_ADDRESS (DG_USAGE_INFO_START_ADDRESS + sizeof(DG_SERVICE_GROUP_T)) ///< DG scheduled runs start address in RTC RAM. #define DG_HEATERS_INFO_START_ADDRESS (DG_SCHEDULED_RUNS_START_ADDRESS + sizeof(DG_HEATERS_INFO_GROUP_T))///< DG heaters info start address in RTC RAM. #define SW_CONFIGS_START_ADDRESS 0x00000100 // 256 ///< Software configurations start address in RTC RAM. @@ -92,11 +91,11 @@ #define RECORD_DATA_RECEIVE_TIMEOUT_MS (4 * MS_PER_SECOND) ///< Record data receive all the data packets timeout in ms. #define RECORD_DATA_MAX_MESSAGE_DFFIRENCE 1 ///< Calibration data receive message different from the previous message. #define RECORD_DATA_FIRST_RECEIVING_MSG_NUM 1 ///< Calibration data first receiving message number. -#define SYSTEM_RECORD_NV_MEM_START_ADDRESS BANK7_SECTOR0_START_ADDRESS ///< System record storage start address in NV memory. -#define CAL_RECORD_NV_MEM_START_ADDRESS BANK7_SECTOR0_START_ADDRESS + 4096 ///< Calibration record storage start address in NV memory. +#define SYSTEM_RECORD_NV_MEM_START_ADDRESS (BANK7_SECTOR0_START_ADDRESS) ///< System record storage start address in NV memory. +#define SERVICE_RECORD_NV_MEM_START_ADDRESS (BANK7_SECTOR0_START_ADDRESS + BITS_12_FULL_SCALE) ///< Service record storage start address in NV memory. +#define CAL_RECORD_NV_MEM_START_ADDRESS (SERVICE_RECORD_NV_MEM_START_ADDRESS + BITS_12_FULL_SCALE) ///< Calibration record storage start address in NV memory. #define RECORD_BYTE_SIZE(r) (sizeof(r) + sizeof(U16)) ///< Record byte size macro. - // Padding length calculation: (DG struct size % bytes to write(16) == 0 ? 0 : ((DG struct size / bytes to write(16)) + 1) * bytes to write(16)) - DG struct size. // NOTE: assuming the macro is calculating the padding length for a non-volatile memory. For NV, 16 bytes is used and buffer and for the RTC RAM 64 bytes is used. // If the size of the structure + a 2-byte crc mod 16 is 0, then the size of the padding is 0 @@ -114,8 +113,7 @@ #define RECORD_DEFAULT_OFFSET 0.0F ///< Record default offset. #define RECORD_DEFAULT_CONST 0.0F ///< Record default constant. #define RECORD_DEFAULT_RATIO 1.0F ///< Record default ratio. -// The service record interval is equivalent to 6 months -#define RECORD_DEFAULT_SERVICE_INTERVAL_S 15768000U ///< Record default service interval in seconds. +#define RECORD_DEFAULT_SERVICE_INTERVAL_S 15768000U ///< Record default service interval in seconds (6 months). #define RECORD_DEFAULT_CHARACTER ' ' ///< Record default character. // Once a new calibration data is available the driver, sets a signal for the defined time. Once the time is out, it turns the signal off. @@ -430,7 +428,7 @@ // Start address Size of the job Max write bytes per job Max read bytes per job Record structure pointer Record CRC pointer Memory location {CAL_RECORD_NV_MEM_START_ADDRESS, sizeof(DG_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DG_CALIBRATION_RECORD_T), (U08*)&dgCalibrationRecord, (U08*)&dgCalibrationRecord.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_CALIBRATION_RECORD {SYSTEM_RECORD_NV_MEM_START_ADDRESS, sizeof(DG_SYSTEM_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DG_SYSTEM_GROUP_T), (U08*)&dgSystemGroup, (U08*)&dgSystemGroup.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_SYSTEM_RECORD - {SERVICE_RECORD_START_ADDRESS, sizeof(DG_SERVICE_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgServiceGroup, (U08*)&dgServiceGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_SERVICE_RECORD + {SERVICE_RECORD_NV_MEM_START_ADDRESS, sizeof(DG_SERVICE_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DG_SERVICE_GROUP_T), (U08*)&dgServiceGroup, (U08*)&dgServiceGroup.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_SERVICE_RECORD #ifndef _RELEASE_ {SW_CONFIGS_START_ADDRESS, sizeof(DG_SW_CONFIG_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgSWConfigGroup, (U08*)&dgSWConfigGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_SW_CONFIG_RECORD #endif @@ -450,13 +448,13 @@ #endif // Process records specifications const PROCESS_RECORD_SPECS_T RECORDS_SPECS [ NUM_OF_NVDATMGMT_RECORDS_JOBS ] = { - {CAL_RECORD_NV_MEM_START_ADDRESS, sizeof(HD_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(HD_CALIBRATION_RECORD_T), (U08*)&hdCalibrationRecord, (U08*)&hdCalibrationRecord.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_CALIBRATION_RECORD - {SYSTEM_RECORD_NV_MEM_START_ADDRESS, sizeof(HD_SYSTEM_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(HD_SYSTEM_GROUP_T), (U08*)&hdSystemGroup, (U08*)&hdSystemGroup.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_SYSTEM_RECORD - {SERVICE_RECORD_START_ADDRESS, sizeof(HD_SERVICE_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&hdServiceGroup, (U08*)&hdServiceGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_PROCESS_LAST_SERVICE_RECORD + {CAL_RECORD_NV_MEM_START_ADDRESS, sizeof(HD_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(HD_CALIBRATION_RECORD_T), (U08*)&hdCalibrationRecord, (U08*)&hdCalibrationRecord.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_CALIBRATION_RECORD + {SYSTEM_RECORD_NV_MEM_START_ADDRESS, sizeof(HD_SYSTEM_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(HD_SYSTEM_GROUP_T), (U08*)&hdSystemGroup, (U08*)&hdSystemGroup.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_SYSTEM_RECORD + {SERVICE_RECORD_NV_MEM_START_ADDRESS, sizeof(HD_SERVICE_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(HD_SERVICE_GROUP_T), (U08*)&hdServiceGroup, (U08*)&hdServiceGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_PROCESS_LAST_SERVICE_RECORD #ifndef _RELEASE_ - {SW_CONFIGS_START_ADDRESS, sizeof(HD_SW_CONFIG_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&hdSWConfigGroup, (U08*)&hdSWConfigGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_SW_CONFIG_RECORD + {SW_CONFIGS_START_ADDRESS, sizeof(HD_SW_CONFIG_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&hdSWConfigGroup, (U08*)&hdSWConfigGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_SW_CONFIG_RECORD #endif - {HD_USAGE_INFO_START_ADDRESS, sizeof(HD_USAGE_INFO_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&hdUsageInfoGroup, (U08*)&hdUsageInfoGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_USAGE_INFO + {HD_USAGE_INFO_START_ADDRESS, sizeof(HD_USAGE_INFO_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&hdUsageInfoGroup, (U08*)&hdUsageInfoGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_USAGE_INFO }; #endif @@ -1591,12 +1589,12 @@ if ( FALSE == hasSWConfigRecordPassed ) { - enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, NVDATAMGMT_SW_CONFIG_RECORD ); + enqueueRecordJob( NVDATAMGMT_WRITE, RECORDS_SPECS[ NVDATAMGMT_SW_CONFIG_RECORD ].dataLoc, NVDATAMGMT_SW_CONFIG_RECORD ); } if ( FALSE == hasServiceRecordPassed ) { - enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, NVDATAMGMT_SERVICE_RECORD ); + enqueueRecordJob( NVDATAMGMT_WRITE, RECORDS_SPECS[ NVDATAMGMT_SERVICE_RECORD ].dataLoc, NVDATAMGMT_SERVICE_RECORD ); } // Check if the records' entire CRCs as well as the individual CRCs passed @@ -1692,34 +1690,25 @@ } else if ( ( NVDATAMGMT_READ == ops ) && ( NVDATAMGMT_EEPROM == location ) ) { - if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) - { - Fapi_doMarginRead( (U32*)startAddress, (U32*)bufferAddress, maxBufferLength, Fapi_NormalRead ); + Fapi_doMarginRead( (U32*)startAddress, (U32*)bufferAddress, maxBufferLength, Fapi_NormalRead ); - currentTime = getMSTimerCount(); - state = NVDATAMGMT_EXEC_STATE_READ_FROM_EEPROM; - } + currentTime = getMSTimerCount(); + state = NVDATAMGMT_EXEC_STATE_READ_FROM_EEPROM; } else if ( ( NVDATAMGMT_WRITE == ops ) && ( NVDATAMGMT_RTC == location ) ) { - //if ( ( RTC_RAM_STATE_READY == getRTCRAMState() ) && ( TRUE == getSemaphore( SEMAPHORE_RTC ) ) ) - { - writeToRAM( startAddress, bufferAddress, maxBufferLength ); + writeToRAM( startAddress, bufferAddress, maxBufferLength ); - currentTime = getMSTimerCount(); - state = NVDATAMGMT_EXEC_STATE_WRITE_TO_RTC; - } + currentTime = getMSTimerCount(); + state = NVDATAMGMT_EXEC_STATE_WRITE_TO_RTC; } else if ( ( NVDATAMGMT_READ == ops ) && ( NVDATAMGMT_RTC == location) ) { - //if ( ( RTC_RAM_STATE_READY == getRTCRAMState() ) && ( TRUE == getSemaphore( SEMAPHORE_RTC ) ) ) - { - readFromRAM( startAddress, maxBufferLength ); - //currentJob.externalAddress->status = NVDATAMGMT_READ_IN_PROGRESS; // TODO Phase 1B for logging + readFromRAM( startAddress, maxBufferLength ); + //currentJob.externalAddress->status = NVDATAMGMT_READ_IN_PROGRESS; // TODO Phase 1B for logging - currentTime = getMSTimerCount(); - state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; - } + currentTime = getMSTimerCount(); + state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; } } @@ -2040,17 +2029,13 @@ NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; BOOL timeoutStatus = didCommandTimeout ( ALARM_ID_RTC_RAM_OPS_ERROR, (U08*)&state ); - if ( ( ( FALSE == isSemaphoreReleased( SEMAPHORE_RTC ) ) && ( RTC_RAM_STATUS_IDLE == getRTCRAMStatus() ) ) || ( TRUE == timeoutStatus ) ) + if ( ( ( TRUE == isSemaphoreReleased( SEMAPHORE_RTC ) ) && ( RTC_RAM_STATUS_IDLE == getRTCRAMStatus() ) ) || ( TRUE == timeoutStatus ) ) { - U08* bufferPtr = 0; - U32 length = 0; - RECORD_JOBS_STATE_T job = recordCurrentJob.recordJob; PROCESS_RECORD_SPECS_T jobSpecs = RECORDS_SPECS [ job ]; + U08* bufferPtr = jobSpecs.structAddressPtr; + U32 length = jobSpecs.sizeofJob; - bufferPtr = jobSpecs.structAddressPtr; - length = jobSpecs.sizeofJob; - /*if ( NVDATAMGMT_PROCESS_RECORDS == activeQueue ) { RECORD_JOBS_STATE_T job = recordCurrentJob.recordJob; @@ -2600,7 +2585,7 @@ if ( FALSE == isQueueFull() ) { - enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, SERVICE_RECORD_START_ADDRESS, (U08*)&hdServiceGroup, 0, sizeof( HD_SERVICE_RECORD_T ) ); + enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, SERVICE_RECORD_NV_MEM_START_ADDRESS, (U08*)&hdServiceGroup, 0, sizeof( HD_SERVICE_RECORD_T ) ); hasServiceRecordBeenUpdated = TRUE; } #endif @@ -3815,6 +3800,7 @@ enqueueRecordJob( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_SYSTEM_RECORD ); + enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_SERVICE_RECORD ); status = TRUE; } @@ -3830,17 +3816,27 @@ *************************************************************************/ static void enqueuePOSTReadRecords( void ) { - enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); + RECORD_JOBS_STATE_T record; + NVDATAMGMT_LOCATION_STATE_T location; + + for ( record = NVDATAMGMT_CALIBRATION_RECORD; record < NUM_OF_NVDATMGMT_RECORDS_JOBS; record++ ) + { + location = RECORDS_SPECS[ record ].dataLoc; + + enqueueRecordJob( NVDATAMGMT_READ, location, record ); + } + + /*enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_SYSTEM_RECORD ); - enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_RTC, NVDATAMGMT_SERVICE_RECORD ); - enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_RTC, NVDATAMGMT_USAGE_INFO_RECORD ); + enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_SERVICE_RECORD ); + enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_RTC, NVDATAMGMT_USAGE_INFO_RECORD ); #ifdef _DG_ enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_RTC, NVDATAMGMT_SCHEDULED_RUNS_RECORD ); #endif #ifndef _RELEASE_ enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_RTC, NVDATAMGMT_SW_CONFIG_RECORD ); -#endif +#endif*/ // Set the status to records were queued successfully recordsReadStatus = NVDATAMGMT_RECORDS_QUEUED; Index: NVDataMgmt.h =================================================================== diff -u -rfd1a4ea5198033bcbd17986c3079967afb1f220f -r82fa83e4d882fdcd96b4b5bdf706044d45a82c70 --- NVDataMgmt.h (.../NVDataMgmt.h) (revision fd1a4ea5198033bcbd17986c3079967afb1f220f) +++ NVDataMgmt.h (.../NVDataMgmt.h) (revision 82fa83e4d882fdcd96b4b5bdf706044d45a82c70) @@ -71,7 +71,9 @@ NVDATAMGMT_CALIBRATION_RECORD = 0, ///< NVDataMgmt process write calibration record. NVDATAMGMT_SYSTEM_RECORD, ///< NVDataMgmt process write system record. NVDATAMGMT_SERVICE_RECORD, ///< NVDataMgmt process service record. +#ifndef _RELEASE NVDATAMGMT_SW_CONFIG_RECORD, ///< NVDataMgmt process software record. +#endif #ifdef _DG_ NVDATAMGMT_SCHEDULED_RUNS_RECORD, ///< NVDataMgmt process scheduled runs record. NVDATAMGMT_HEATERS_INFO_RECORD, ///< NVDataMgmt process heaters info record. Index: Utilities.c =================================================================== diff -u -r839935998cfe2a1a7594e6b6810301ad3c2aa872 -r82fa83e4d882fdcd96b4b5bdf706044d45a82c70 --- Utilities.c (.../Utilities.c) (revision 839935998cfe2a1a7594e6b6810301ad3c2aa872) +++ Utilities.c (.../Utilities.c) (revision 82fa83e4d882fdcd96b4b5bdf706044d45a82c70) @@ -26,19 +26,22 @@ // ********** private definitions ********** -#define INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function -#define INITIAL_CRC08_VAL 0x00 ///< Seed for 8-bit CRC function +#define INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function +#define INITIAL_CRC08_VAL 0x00 ///< Seed for 8-bit CRC function -#define ASCII_CODE_LETTER_A 0x41 ///< ASCII code in hex for letter A. -#define ASCII_CODE_NUMBER_ZERO 0x30 ///< ASCII code in hex for number zero. -#define ASCII_CODE_NUMBER_SEVEN 0x37 ///< ASCII code in hex for number seven. +#define ASCII_CODE_LETTER_A 0x41 ///< ASCII code in hex for letter A. +#define ASCII_CODE_NUMBER_ZERO 0x30 ///< ASCII code in hex for number zero. +#define ASCII_CODE_NUMBER_SEVEN 0x37 ///< ASCII code in hex for number seven. + +#define SEMAPHORE_IN_USE_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Taken semaphore timeout in milliseconds. // ********** private data ********** /// Semaphore data structure typedef struct { - volatile BOOL isSemaphoreTaken; ///< Flag to indicate whether the semaphore is taken or not. + U32 semaphoreStartTimeMS; ///< Semaphore start time in milliseconds. + volatile BOOL isSemaphoreTaken; ///< Flag to indicate whether the semaphore is taken or not. } SEMAPHORE_STATUS_T; /// CRC-32 look-up table. @@ -671,9 +674,14 @@ _disable_IRQ(); if ( FALSE == sempahoreStatus[ s ].isSemaphoreTaken ) { - sempahoreStatus[ s ].isSemaphoreTaken = TRUE; - result = TRUE; + sempahoreStatus[ s ].semaphoreStartTimeMS = getMSTimerCount(); + sempahoreStatus[ s ].isSemaphoreTaken = TRUE; + result = TRUE; } + else if ( TRUE == didTimeout( sempahoreStatus[ s ].semaphoreStartTimeMS, SEMAPHORE_IN_USE_TIMEOUT_MS ) ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_SEMAPHORE_IN_USE_TIMEOUT, (U32)s ) + } _enable_IRQ(); return result; @@ -696,9 +704,17 @@ } } +/*********************************************************************//** + * @brief + * The isSemaphoreReleased function returns the status of a taken semaphore + * @details Inputs: none + * @details Outputs: sempahoreStatus + * @param s which is the semaphore to check + * @return status of the semaphore + *************************************************************************/ BOOL isSemaphoreReleased( SEMAPHORE_T s ) { - return sempahoreStatus[ s ].isSemaphoreTaken; + return ( TRUE == sempahoreStatus[ s ].isSemaphoreTaken ? FALSE : TRUE ); } /**@}*/