Index: firmware/App/Drivers/NVDriver.h =================================================================== diff -u -ra68c7679e493224bd41df72321d4c2537207234f -rb878faee61a0800b767d053ab3f65afb3790dacb --- firmware/App/Drivers/NVDriver.h (.../NVDriver.h) (revision a68c7679e493224bd41df72321d4c2537207234f) +++ firmware/App/Drivers/NVDriver.h (.../NVDriver.h) (revision b878faee61a0800b767d053ab3f65afb3790dacb) @@ -52,14 +52,11 @@ /// NVDataMgmt records' jobs states typedef enum NVDataMgmt_Records_Jobs { - NVDATAMGMT_CALIBRATION_RECORD = 0, ///< NVDataMgmt process write calibration record. - NVDATAMGMT_SYSTEM_RECORD, ///< NVDataMgmt process write system record. + NVDATAMGMT_SYSTEM_RECORD = 0, ///< NVDataMgmt process write system record. NVDATAMGMT_SERVICE_RECORD, ///< NVDataMgmt process service record. - NVDATAMGMT_INTITUTIONAL_RECORD, ///< NVDataMgmt process institutional record. + NVDATAMGMT_CALIBRATION_RECORD, ///< NVDataMgmt process write calibration record. + NVDATAMGMT_INSTITUTIONAL_RECORD, ///< NVDataMgmt process institutional record. NVDATAMGMT_USAGE_INFO_RECORD, ///< NVDataMgmt process usage info record. -#ifndef _RELEASE_ - NVDATAMGMT_SW_CONFIG_RECORD, ///< NVDataMgmt process software record. -#endif NUM_OF_NVDATMGMT_RECORDS_JOBS ///< Number of NVDataMgmt records jobs. } RECORD_JOBS_STATE_T; Index: firmware/App/Services/NVMgmtDD.c =================================================================== diff -u -ra68c7679e493224bd41df72321d4c2537207234f -rb878faee61a0800b767d053ab3f65afb3790dacb --- firmware/App/Services/NVMgmtDD.c (.../NVMgmtDD.c) (revision a68c7679e493224bd41df72321d4c2537207234f) +++ firmware/App/Services/NVMgmtDD.c (.../NVMgmtDD.c) (revision b878faee61a0800b767d053ab3f65afb3790dacb) @@ -189,13 +189,13 @@ break; case NVDATAMGMT_WRITE: - writeSector( (U32*)recordFlashAddress, (U08*)bufferAddress, jobSpecs.maxWriteBufferSize ); + writeSector( (U32*)recordFlashAddress, (U08*)bufferAddress, MAX_EEPROM_WRITE_BUFFER_BYTES ); currentTime = getMSTimerCount(); state = NVDATAMGMT_EXEC_STATE_WRITE_TO_EEPROM; break; case NVDATAMGMT_READ: - readSector( (U32*)recordFlashAddress, (U32*)bufferAddress, ( jobSpecs.maxReadBufferSize / EEPROM_OPS_SIZE_OF_CONVERTER ) ); + readSector( (U32*)recordFlashAddress, (U32*)bufferAddress, ( jobSpecs.sizeofRecord / EEPROM_OPS_SIZE_OF_CONVERTER ) ); currentTime = getMSTimerCount(); state = NVDATAMGMT_EXEC_STATE_READ_FROM_EEPROM; break; @@ -266,35 +266,35 @@ { currentTime = getMSTimerCount(); U32 recordFlashAddress = jobSpecs.recordFlashAddress + recordAddressOffset; - U32 maxBufferLength = jobSpecs.maxWriteBufferSize / EEPROM_OPS_SIZE_OF_CONVERTER; + U32 maxBufferLength = MAX_EEPROM_WRITE_BUFFER_BYTES / EEPROM_OPS_SIZE_OF_CONVERTER; // Clear the buffer from the previous content memset( writtenRecordCheckBuffer, 0, sizeof( writtenRecordCheckBuffer ) ); - // Issue a FAPI read command but only the bytes that were written, so use maxWriteBufferSize + // Issue a FAPI read command but only the bytes that were written, so use maxBufferLength readSector( (U32*)recordFlashAddress, (U32*)writtenRecordCheckBuffer, maxBufferLength ); state = NVDATAMGMT_EXEC_STATE_VERIFY_EEPROM_WRITE; } else if ( writtenRecordStatus == NVDATAMGMT_RECORD_VALID ) { // If the data is valid, and if it is at the end of the write, change to idle - if ( jobSpecs.sizeofJob == recordAddressOffset ) + if ( jobSpecs.sizeofRecord == recordAddressOffset ) { state = NVDATAMGMT_EXEC_STATE_IDLE; } else { // Update the variables and issue the next write command currentTime = getMSTimerCount(); - recordAddressOffset += jobSpecs.maxWriteBufferSize; + recordAddressOffset += MAX_EEPROM_WRITE_BUFFER_BYTES; U32 memoryPtr = jobSpecs.recordFlashAddress + recordAddressOffset; U08* structPtr = jobSpecs.structAddressPtr + recordAddressOffset; writtenRecordStatus = NVDATAMGMT_RECORD_NOT_CHECKED; // Issue the write command - writeSector( (U32*)memoryPtr, structPtr, jobSpecs.maxWriteBufferSize ); + writeSector( (U32*)memoryPtr, structPtr, MAX_EEPROM_WRITE_BUFFER_BYTES ); } } } @@ -355,7 +355,7 @@ U08* bufferPtr = jobSpecs.structAddressPtr + recordAddressOffset; // Loop through the bytes in the buffer - for ( i = 0; i < jobSpecs.maxWriteBufferSize; i++ ) + for ( i = 0; i < MAX_EEPROM_WRITE_BUFFER_BYTES; i++ ) { // Check if data in the buffer is not the same as the data in the structure if ( writtenRecordCheckBuffer[ i ] != *bufferPtr ) Index: firmware/App/Services/NVMsgQ.c =================================================================== diff -u -ra68c7679e493224bd41df72321d4c2537207234f -rb878faee61a0800b767d053ab3f65afb3790dacb --- firmware/App/Services/NVMsgQ.c (.../NVMsgQ.c) (revision a68c7679e493224bd41df72321d4c2537207234f) +++ firmware/App/Services/NVMsgQ.c (.../NVMsgQ.c) (revision b878faee61a0800b767d053ab3f65afb3790dacb) @@ -30,7 +30,7 @@ // ********** private definitions ********** -#define QUEUE_MAX_SIZE 50U ///< Max queue size. +#define QUEUE_MAX_SIZE 20U ///< Max queue size. #define QUEUE_START_INDEX 0U ///< Queue start index. #define MAX_JOB_DATA_SIZE_BYTES 32U ///< Max bytes per job (32 bytes). #define NUM_OF_BYTES_PER_RECORD_PAYLOAD ( MAX_MSG_PAYLOAD_SIZE - ( sizeof( U32 ) * 3 ) ) ///< Number of bytes per calibration payload. @@ -42,20 +42,20 @@ // 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. #define NEW_CAL_AVAILABLE_SIGNAL_TIMEOUT_MS (1 * MS_PER_SECOND) ///< New calibration available signal timeout in milliseconds. -/// NVDataMgmt process records states -typedef enum NVDataMgmt_Process_Records_States +/// NVDataMgmt send records states +typedef enum NVDataMgmt_Send_Records_States { - NVDATAMGMT_PROCESS_RECORD_STATE_IDLE = 0, ///< NVDataMgmt process record idle state. - NVDATAMGMT_PROCESS_RECORD_STATE_SEND_RECORD, ///< NVDataMgmt process record send record state. - NUM_OF_NVDATAMGMT_PROCESS_RECORD_STATES ///< Number of NVDataMgmt process records state. -} PROCESS_RECORD_STATE_T; + NVM_SEND_RECORD_STATE_IDLE = 0, ///< NVDataMgmt process record idle state. + NVM_SEND_RECORD_STATE_SEND, ///< NVDataMgmt process record send record state. + NUM_OF_NVM_SEND_RECORD_STATES ///< Number of NVDataMgmt process records state. +} SEND_RECORD_STATE_T; /// NVDataMgmt receive records states typedef enum NVDataMgmt_Receive_Records_States { - NVDATAMGMT_RECEIVE_RECORD_IDLE = 0, ///< NVDataMgmt receive record idle. - NVDATAMGMT_RECEIVE_RECORD_RECEIVE, ///< NVDataMgmt receive record receive. - NUM_OF_NVDATAMGMT_RECEIVE_RECORD_STATES ///< Number of NVDataMgmt receive record. + NVM_RECEIVE_RECORD_STATE_IDLE = 0, ///< NVDataMgmt receive record idle. + NVM_RECEIVE_RECORD_STATE_RECEIVE, ///< NVDataMgmt receive record receive. + NUM_OF_NVM_RECEIVE_RECORD_STATES ///< Number of NVDataMgmt receive record. } RECEIVE_RECORD_STATE_T; /// Memory operations structure. @@ -82,6 +82,17 @@ F32 minInletWaterCondAlarmLimitUSPCM; ///< Min inlet water conductivity alarm limit in uS/cm. } DD_INSTITUTIONAL_VALUES_T; + +/// Process records job structure +typedef struct +{ + RECORD_JOBS_STATE_T job; + U32 currentMessage; + U32 totalMessages; + U32 payloadLength; + U08 payload[NUM_OF_BYTES_PER_RECORD_PAYLOAD]; +} RECEIVE_RECORD_JOB_T; + // ********** private data ********** static PROCESS_RECORD_JOB_T recordJobQueue[ QUEUE_MAX_SIZE ]; ///< Record queue jobs. @@ -91,26 +102,62 @@ static PROCESS_RECORD_JOB_T recordCurrentJob; ///< Record queue current job. static NVDATAMGMT_RECORDS_READ_STATUS_T recordsReadStatus; ///< NVDataMgmt records read status. -static BOOL isNewCalAvailable; ///< Signal to indicate whether a new calibration data is available. +static BOOL isNewNVRecordAvailable; ///< Signal to indicate whether a new NVM data is available. static RECORD_JOBS_STATE_T recordToPublish; ///< Record to publish (i.e. calibration, system) -static PROCESS_RECORD_STATE_T nvDataMgmtExecProcessRecordState; ///< NVDataMgmt exec process record state. -static RECEIVE_RECORD_STATE_T nvDataMgmtExecReceiveRecordState; ///< NVDataMgmt exec receive record state. -static RECORD_JOBS_STATE_T nvPublishRecordState; -static BOOL hasPublishRecordBeenRequested[ NUM_OF_NVDATMGMT_RECORDS_JOBS ]; ///< Record state machine publish request flag. +static SEND_RECORD_STATE_T nvMExecSendRecordState; ///< NVDataMgmt exec process record state. +static RECEIVE_RECORD_STATE_T nvmExecReceiveRecordState; ///< NVDataMgmt exec receive record state. +static RECORD_JOBS_STATE_T nvPublishRecordType; +static BOOL isPublishRecordRequested[ NUM_OF_NVDATMGMT_RECORDS_JOBS ]; ///< Record state machine publish request flag. static U32 recordPublishMsgCount; ///< Record data publish message counter. static U32 recordPublishTotalMsgs; ///< Record data total number of messages to be sent. static U32 recordSendDataIntervalCounter; ///< Record data send to CAN bust interval counter. static U32 previousRecordMessageNum; ///< Record previous message number. static U32 recordUpdateAddress; ///< DD record update address for all the write operations. static U32 recordReceiveStartTime; ///< Time stamp the calibration/service was received. -static U32 newCalStartTimer; ///< New calibration availability start timer. +static U32 newRecordStartTimer; ///< New record availability start timer. +/// Process records specifications structure +typedef struct +{ + U32 sizeofRecord; ///< Jobs spec size of job. + U08* structAddressPtr; ///< Jobs structure address pointer. + U08* structCRCPtr; ///< Jobs structure CRC pointer. +} RECEIVE_RECORD_SPECS_T; + +// Temporary Record variable used only for receiving record before crc verification +static DD_SYSTEM_GROUP_T ddTempReceivedSystemGrp; ///< DD system group structure (including padding and final CRC). +static DD_SERVICE_GROUP_T ddTempReceivedServiceGrp; ///< DD service group structure (including padding and final CRC). +static DD_CALIBRATION_RECORD_T ddTempReceivedCalRecord; ///< DD calibration record structure (including padding and final CRC). +static DD_INSTITUTIONAL_GROUP_T ddTempReceivedInstitGrp; ///< DD institutional group structure (including padding and final CRC). +static DD_USAGE_INFO_GROUP_T ddTempReceivedUsageGrp; ///< DD usage info structure (including padding and final CRC). + +// Temporary Process records specifications +const RECEIVE_RECORD_SPECS_T receivedRecords[ NUM_OF_NVDATMGMT_RECORDS_JOBS ] = { + //Size of the job Max read bytes per job Record structure pointer Record CRC pointer Event calibration record update + sizeof(DD_SYSTEM_GROUP_T), sizeof(DD_SYSTEM_GROUP_T), (U08*)&ddTempRxSystemGrp, (U08*)&ddTempReceivedSystemGrp.crc, }, // NVDATAMGMT_SYSTEM_RECORD + sizeof(DD_SERVICE_GROUP_T), sizeof(DD_SERVICE_GROUP_T), (U08*)&ddTempRxServiceGrp, (U08*)&ddTempReceivedServiceGrp.crc, }, // NVDATAMGMT_SERVICE_RECORD + sizeof(DD_CALIBRATION_RECORD_T), sizeof(DD_CALIBRATION_RECORD_T), (U08*)&ddTempRxCalRecord, (U08*)&ddTempReceivedCalRecord.crc, }, // NVDATAMGMT_CALIBRATION_RECORD + sizeof(DD_INSTITUTIONAL_GROUP_T), sizeof(DD_INSTITUTIONAL_GROUP_T), (U08*)&ddTempRxInstitGrp, (U08*)&ddTempReceivedInstitGrp.crc, }, // NVDATAMGMT_INSTITUTIONAL_RECORD + sizeof(DD_USAGE_INFO_GROUP_T), sizeof(DD_USAGE_INFO_GROUP_T), (U08*)&ddTempRxUsageGrp, (U08*)&ddTempReceivedUsageGrp.crc, }, // NVDATAMGMT_USAGE_INFO_RECORD +}; + +// Process records specifications +static PROCESS_RECORD_SPECS_T receivedRecords[ NUM_OF_NVDATMGMT_RECORDS_JOBS ] + // Start address Size of the job Record structure pointer Record CRC pointer Event calibration record update + {SYSTEM_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_SYSTEM_GROUP_T), (U08*)&ddTempRxSystemGrp, (U08*)&ddTempRxSystemGrp.crc, DD_EVENT_SYSTEM_RECORD_UPDATE }, // NVDATAMGMT_SYSTEM_RECORD + {SERVICE_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_SERVICE_GROUP_T), (U08*)&ddTempRxServiceGrp, (U08*)&ddTempRxServiceGrp.crc, DD_EVENT_SERVICE_UPDATE }, // NVDATAMGMT_SERVICE_RECORD + {CAL_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_CALIBRATION_RECORD_T), (U08*)&ddTempRxCalRecord, (U08*)&ddTempRxCalRecord.crc, DD_EVENT_CAL_RECORD_UPDATE }, // NVDATAMGMT_CALIBRATION_RECORD + {INSTIT_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_INSTITUTIONAL_GROUP_T), (U08*)&ddTempRxInstitGrp, (U08*)&ddTempRxInstitGrp.crc, DD_EVENT_INSTIT_RECORD_UPDATE }, // NVDATAMGMT_INSTITUTIONAL_RECORD + {USAGE_INFO_START_ADDRESS, sizeof(DD_USAGE_INFO_GROUP_T), (U08*)&ddTempRxUsageGrp, (U08*)&ddTempRxUsageGrp.crc, DD_EVENT_USAGE_INFO_UPDATE }, // NVDATAMGMT_USAGE_INFO_RECORD +}; + // ********** private function prototypes ********** // Process record functions -static PROCESS_RECORD_STATE_T handleExecProcessRecordIdleState( void ); -static PROCESS_RECORD_STATE_T handleExecProcessRecordSendRecordState( void ); +static SEND_RECORD_STATE_T handleExecSendRecordIdleState( void ); +static SEND_RECORD_STATE_T handleExecSendRecordSendState( void ); + static void sendInstitutionalRecordToUI( DD_INSTITUTIONAL_LOCAL_RECORD_T* instit ); static void handleDGRequestInstitutionalValues( MESSAGE_T* message ); static BOOL sendDDRecord( MSG_ID_T msgId, U32 payloadCurrNum, U32 payloadTotalNum, U32 length, U08* calRcrdAddress ); @@ -126,17 +173,17 @@ recordQueueCount = 0; recordsReadStatus = NVDATAMGMT_RECORDS_NOT_STARTED; - isNewCalAvailable = FALSE; - nvDataMgmtExecProcessRecordState = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; + isNewNVRecordAvailable = FALSE; + nvMExecSendRecordState = NVM_SEND_RECORD_STATE_IDLE; + nvmExecReceiveRecordState = NVM_RECEIVE_RECORD_STATE_IDLE; - nvPublishRecordState = NVDATAMGMT_CALIBRATION_RECORD; - hasPublishRecordBeenRequested[ NVDATAMGMT_CALIBRATION_RECORD ] = FALSE; - hasPublishRecordBeenRequested[ NVDATAMGMT_SYSTEM_RECORD ] = FALSE; - hasPublishRecordBeenRequested[ NVDATAMGMT_SERVICE_RECORD ] = FALSE; - hasPublishRecordBeenRequested[ NVDATAMGMT_USAGE_INFO_RECORD ] = FALSE; + nvPublishRecordType = NVDATAMGMT_CALIBRATION_RECORD; + isPublishRecordRequested[ NVDATAMGMT_CALIBRATION_RECORD ] = FALSE; + isPublishRecordRequested[ NVDATAMGMT_SYSTEM_RECORD ] = FALSE; + isPublishRecordRequested[ NVDATAMGMT_SERVICE_RECORD ] = FALSE; + isPublishRecordRequested[ NVDATAMGMT_USAGE_INFO_RECORD ] = FALSE; - newCalStartTimer = 0; + newRecordStartTimer = 0; recordPublishMsgCount = 1; recordPublishTotalMsgs = 1; @@ -147,45 +194,44 @@ /*********************************************************************//** * @brief - * The execNVDataMgmtProcessRecord runs the NVDataMgmt send records related + * The execNVMSendRecord runs the NVDataMgmt send records related * to tasks. - * @details Inputs: nvDataMgmtExecProcessRecordState, - * nvDataMgmtExecReceiveRecordState, recordReceiveStartTime - * @details Outputs: nvDataMgmtExecProcessRecordState, - * nvDataMgmtExecReceiveRecordState + * @details Inputs: nvMExecSendRecordState, + * nvmExecReceiveRecordState, recordReceiveStartTime + * @details Outputs: nvMExecSendRecordState, + * nvmExecReceiveRecordState * @return none *************************************************************************/ void execNVDataMgmtProcessRecord( void ) { - switch ( nvDataMgmtExecProcessRecordState ) + switch ( nvMExecSendRecordState ) { - case NVDATAMGMT_PROCESS_RECORD_STATE_IDLE: - nvDataMgmtExecProcessRecordState = handleExecProcessRecordIdleState(); + case NVM_SEND_RECORD_STATE_IDLE: + nvMExecSendRecordState = handleExecSendRecordIdleState(); break; - case NVDATAMGMT_PROCESS_RECORD_STATE_SEND_RECORD: - nvDataMgmtExecProcessRecordState = handleExecProcessRecordSendRecordState(); + case NVM_SEND_RECORD_STATE_SEND: + nvMExecSendRecordState = handleExecSendRecordSendState(); break; default: -// SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_NVDATAMGMT_EXEC_CAL_STATE, nvDataMgmtExecProcessRecordState ); - - nvDataMgmtExecProcessRecordState = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; +// SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_NVDATAMGMT_EXEC_CAL_STATE, nvMExecSendRecordState ); + nvMExecSendRecordState = NVM_SEND_RECORD_STATE_IDLE; break; } // Check if the exec receive records is not idle // This section checks the status of the asynchronous state machine that receives // data from Dialin. - if ( nvDataMgmtExecReceiveRecordState != NVDATAMGMT_RECEIVE_RECORD_IDLE ) + if ( nvmExecReceiveRecordState != NVM_RECEIVE_RECORD_STATE_IDLE ) { // Check if the data receiving process has timed out. The exec receive record // state machine is asynchronous so it is checked in this state machine if ( TRUE == didTimeout( recordReceiveStartTime, RECORD_DATA_RECEIVE_TIMEOUT_MS ) ) { // Exec receive state machine timed out. Schedule a read to update the structure enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_CALIBRATION_RECORD ); - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; + nvmExecReceiveRecordState = NVM_RECEIVE_RECORD_STATE_IDLE; } } @@ -195,62 +241,62 @@ /*********************************************************************//** * @brief - * The handleExecProcessRecordIdleState handles the idle state of the + * The handleExecSendRecordIdleState handles the idle state of the * exec cal state machine. - * @details Inputs: hasPublishRecordBeenRequested, recordPublishTotalMsgs, + * @details Inputs: isPublishRecordRequested, recordPublishTotalMsgs, * recordPublishMsgCount, recordSendDataIntervalCounter - * @details Outputs: hasPublishRecordBeenRequested, recordPublishTotalMsgs, + * @details Outputs: isPublishRecordRequested, recordPublishTotalMsgs, * recordPublishMsgCount, recordSendDataIntervalCounter * @return next state of the state machine *************************************************************************/ -static PROCESS_RECORD_STATE_T handleExecProcessRecordIdleState( void ) +static SEND_RECORD_STATE_T handleExecSendRecordIdleState( void ) { - PROCESS_RECORD_STATE_T state = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_IDLE; - if ( TRUE == hasPublishRecordBeenRequested[ nvPublishRecordState ] ) + if ( TRUE == isPublishRecordRequested[ nvPublishRecordType ] ) { - recordToPublish = ( RECORD_JOBS_STATE_T )nvPublishRecordState; + recordToPublish = ( RECORD_JOBS_STATE_T )nvPublishRecordType; // Set the publish flag to FALSE - hasPublishRecordBeenRequested[ recordToPublish ] = FALSE; + isPublishRecordRequested[ recordToPublish ] = FALSE; // Get the record specifications to find the size of the job PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( recordToPublish ); // Calculate the total number of messages required to be sent using ceilf function. This function rounds up the // value and its result is converted to U32. - recordPublishTotalMsgs = (U32)ceilf( (F32)recordSpec.sizeofJob / (F32)NUM_OF_BYTES_PER_RECORD_PAYLOAD ); + recordPublishTotalMsgs = (U32)ceilf( (F32)recordSpec.sizeofRecord / (F32)NUM_OF_BYTES_PER_RECORD_PAYLOAD ); recordPublishMsgCount = 0; // Time interval in between data to be sent. It is set to the interval count so on the first call // of the send calibration record function, the first packet of data is sent recordSendDataIntervalCounter = RECORD_DATA_SEND_INTERVAL_COUNT; - state = NVDATAMGMT_PROCESS_RECORD_STATE_SEND_RECORD; + state = NVM_SEND_RECORD_STATE_SEND; } - nvPublishRecordState = ( RECORD_JOBS_STATE_T )( nvPublishRecordState + 1 ); - if(nvPublishRecordState >= NUM_OF_NVDATMGMT_RECORDS_JOBS) + nvPublishRecordType = ( RECORD_JOBS_STATE_T )( nvPublishRecordType + 1 ); + if(nvPublishRecordType >= NUM_OF_NVDATMGMT_RECORDS_JOBS) { - nvPublishRecordState = NVDATAMGMT_CALIBRATION_RECORD; + nvPublishRecordType = NVDATAMGMT_CALIBRATION_RECORD; } return state; } /*********************************************************************//** * @brief - * The handleExecProcessRecordSendRecordState handles the send calibration + * The handleExecSendRecordSendState handles the send nvm * record state of the state machine. * @details Inputs: dgCalibrationRecord, recordPublishTotalMsgs, * recordPublishMsgCount, recordSendDataIntervalCounter * @details Outputs: recordPublishTotalMsgs, recordPublishMsgCount, * recordSendDataIntervalCounter * @return next state of the state machine *************************************************************************/ -static PROCESS_RECORD_STATE_T handleExecProcessRecordSendRecordState( void ) +static SEND_RECORD_STATE_T handleExecSendRecordSendState( void ) { - PROCESS_RECORD_STATE_T state = NVDATAMGMT_PROCESS_RECORD_STATE_SEND_RECORD; + SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; MSG_ID_T msgId; // If the current message number is less than the total, keep sending @@ -268,7 +314,7 @@ // If this is the last calibration data payload, calculate the remainder of the bytes to send if ( ( recordPublishMsgCount + 1 ) == recordPublishTotalMsgs ) { - length = recordSpec.sizeofJob - ( recordPublishMsgCount * NUM_OF_BYTES_PER_RECORD_PAYLOAD ); + length = recordSpec.sizeofRecord - ( recordPublishMsgCount * NUM_OF_BYTES_PER_RECORD_PAYLOAD ); } // Find the new location of the pointer which is the start of the calibration payload to be sent @@ -286,7 +332,7 @@ } else { - state = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; + state = NVM_SEND_RECORD_STATE_IDLE; } return state; @@ -398,7 +444,7 @@ { BOOL status = FALSE; - if ( getAvailableRecordQueueCount() >= MIN_JOBS_NEEDED_FOR_SECTOR_0 ) + if ( getAvailableRecordQueueCount() >= MIN_JOBS_NEEDED_FOR_ALL_RECORDS ) { RECORD_JOBS_STATE_T record; @@ -416,6 +462,32 @@ return status; } +BOOL enqueuewriteAllRecords( void ) +{ + BOOL status = FALSE; + + if ( getAvailableRecordQueueCount() >= MIN_JOBS_NEEDED_FOR_ALL_RECORDS ) + { + RECORD_JOBS_STATE_T record; + + // Erase all the sectors + for ( record = NVDATAMGMT_SYSTEM_RECORD; record < NUM_OF_NVDATMGMT_RECORDS_JOBS; record++ ) + { + enqueueRecordJob( NVDATAMGMT_ERASE_SECTOR, record ); + } + + // Write all the records + for ( record = NVDATAMGMT_SYSTEM_RECORD; record < NUM_OF_NVDATMGMT_RECORDS_JOBS; record++ ) + { + enqueueRecordJob( NVDATAMGMT_WRITE, record ); + } + + status = TRUE; + } + + return status; +} + /*********************************************************************//** * @brief * The enqueuePOSTReadRecords enqueues the NV records to be read during POST. @@ -460,15 +532,11 @@ // job = getNVMRecordJobState( msgID ); if ( ( job < NUM_OF_NVDATMGMT_RECORDS_JOBS ) && - ( NVDATAMGMT_PROCESS_RECORD_STATE_IDLE == nvDataMgmtExecProcessRecordState ) ) + ( NVM_SEND_RECORD_STATE_IDLE == nvMExecSendRecordState ) ) { - // Check if the state machine is in idle state and then set the request -// if ( NVDATAMGMT_PROCESS_RECORD_STATE_IDLE == nvDataMgmtExecProcessRecordState ) -// { - hasPublishRecordBeenRequested[ job ] = TRUE; - recordToPublish = job; - result = TRUE; -// } + isPublishRecordRequested[ job ] = TRUE; + recordToPublish = job; + result = TRUE; } } @@ -609,13 +677,15 @@ } } + + /*********************************************************************//** * @brief * The receiveRecordFromDialin function receives the record that has been sent * from Dialin and if the CRCs passed, it schedules a write to the NV data. - * @details Inputs: currentMessage, nvDataMgmtExecReceiveRecordState, + * @details Inputs: currentMessage, nvmExecReceiveRecordState, * previousRecordMessageNum, totalMessages, previousRecordMessageNum, - * @details Outputs: nvDataMgmtExecReceiveRecordState, recordReceiveStartTime, + * @details Outputs: nvmExecReceiveRecordState, recordReceiveStartTime, * previousRecordMessageNum, recordUpdateAddress, recordUpdateAddress * @param job: the job that has to be received and written (i.e. service record) * @param currentMessage: current message number that is received from Dialin @@ -629,21 +699,21 @@ BOOL status = TRUE; // If the calibration message number is the first message number and receive exec state is idle, switch to idle - if ( ( RECORD_DATA_FIRST_RECEIVING_MSG_NUM == currentMessage ) && ( NVDATAMGMT_RECEIVE_RECORD_IDLE == nvDataMgmtExecReceiveRecordState ) ) + if ( ( RECORD_DATA_FIRST_RECEIVING_MSG_NUM == currentMessage ) && ( NVM_RECEIVE_RECORD_STATE_IDLE == nvmExecReceiveRecordState ) ) { - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_RECEIVE; + nvmExecReceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; recordReceiveStartTime = getMSTimerCount(); previousRecordMessageNum = 0; recordUpdateAddress = 0; } // Check if there is still a message left to be received - if ( ( NVDATAMGMT_RECEIVE_RECORD_RECEIVE == nvDataMgmtExecReceiveRecordState ) && ( currentMessage <= totalMessages ) ) + if ( ( NVM_RECEIVE_RECORD_STATE_RECEIVE == nvmExecReceiveRecordState ) && ( currentMessage <= totalMessages ) ) { // Check if the current message is different from the previous message by 1 if ( RECORD_DATA_MAX_MESSAGE_DFFIRENCE == ( currentMessage - previousRecordMessageNum ) ) { - // Define a pointer that points to the DG calibration record + // Define a pointer that points to the DD nvm record PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( job ); U08* ptr = recordSpec.structAddressPtr; @@ -658,11 +728,11 @@ { // Assume the institutional record is fine unless the record is really the institutional record BOOL isInstRcrdValid = TRUE; - U16 calcCRC = crc16 ( recordSpec.structAddressPtr, recordSpec.sizeofJob - sizeof(U16) ); + U16 calcCRC = crc16 ( recordSpec.structAddressPtr, recordSpec.sizeofRecord - sizeof(U16) ); // Get the CRC of the structure without the last 16 bits which is the CRC as well as the padding values U16 recordCRC = *(U16*)recordSpec.structCRCPtr; - if ( NVDATAMGMT_INTITUTIONAL_RECORD == job ) + if ( NVDATAMGMT_INSTITUTIONAL_RECORD == job ) { // isInstRcrdValid = isNVInstitutionalRecordInRange( &ddInstitutionalGroup.ddInstitutionalRecord ); status = isInstRcrdValid; @@ -674,7 +744,7 @@ // CRC failed, request a read to read the data back from NV memory and update the structure enqueueRecordJob( NVDATAMGMT_READ, job ); - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; + nvmExecReceiveRecordState = NVM_RECEIVE_RECORD_STATE_IDLE; status = FALSE; } else @@ -696,14 +766,14 @@ // Signal that there is a new calibration record available. // NOTE: as of now, this signal will be sent even after the system record is sent - newCalStartTimer = getMSTimerCount(); - isNewCalAvailable = TRUE; + newRecordStartTimer = getMSTimerCount(); + isNewNVRecordAvailable = TRUE; // Update the event of the received record that has been accepted SEND_EVENT_WITH_2_U32_DATA( recordSpec.nvEvent, 0, 0 ); // Done with receiving data, go back to idle - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; + nvmExecReceiveRecordState = NVM_RECEIVE_RECORD_STATE_IDLE; } } else @@ -767,14 +837,17 @@ job = NVDATAMGMT_SERVICE_RECORD; break; + case MSG_ID_DD_NVM_SET_INSTITUTIONAL_RECORD: + job = NVDATAMGMT_INSTITUTIONAL_RECORD; + break; + case MSG_ID_DD_NVM_SET_USAGE_INFO_RECORD: job = NVDATAMGMT_USAGE_INFO_RECORD; break; default: // Software Fault break; - } return job; @@ -798,6 +871,10 @@ msgID = MSG_ID_DD_NVM_SEND_SERVICE_RECORD; break; + case NVDATAMGMT_INSTITUTIONAL_RECORD: + msgID = MSG_ID_DD_NVM_SEND_INSTITUTIONAL_RECORD; + break; + case NVDATAMGMT_USAGE_INFO_RECORD: msgID = MSG_ID_DD_NVM_SEND_USAGE_INFO_RECORD; break; @@ -814,15 +891,15 @@ * @brief * The monitorNewCalSignal function monitors the new calibration signal * and if it on and time to on has elapsed, it turns it off. - * @details Inputs: isNewCalAvailable - * @details Outputs: isNewCalAvailable + * @details Inputs: isNewNVRecordAvailable + * @details Outputs: isNewNVRecordAvailable * @return none *************************************************************************/ static void monitorNewCalSignal( void ) { - if ( ( TRUE == didTimeout( newCalStartTimer, NEW_CAL_AVAILABLE_SIGNAL_TIMEOUT_MS ) ) && ( TRUE == isNewCalAvailable ) ) + if ( ( TRUE == didTimeout( newRecordStartTimer, NEW_CAL_AVAILABLE_SIGNAL_TIMEOUT_MS ) ) && ( TRUE == isNewNVRecordAvailable ) ) { - isNewCalAvailable = FALSE; + isNewNVRecordAvailable = FALSE; } } @@ -832,27 +909,27 @@ * new calibration availability. * @details Inputs: none * @details Outputs: none - * @return isNewCalAvailable which is TRUE if new calibration is available, + * @return isNewNVRecordAvailable which is TRUE if new calibration is available, * otherwise FALSE *************************************************************************/ BOOL isNewCalibrationRecordAvailable( void ) { - return isNewCalAvailable; + return isNewNVRecordAvailable; } -void updateNewCalAvailableFlag( BOOL value ) +void updateNewNVRecordAvailableFlag( BOOL value ) { - isNewCalAvailable = value; + isNewNVRecordAvailable = value; } void updateRecordReadStatus( NVDATAMGMT_RECORDS_READ_STATUS_T status ) { recordsReadStatus = status; } -void updateCalStartTimer( U32 value ) +void updateRecordStartTimer( U32 value ) { - newCalStartTimer = value; + newRecordStartTimer = value; } PROCESS_RECORD_JOB_T getCurrentProcessRecordJob ( void ) Index: firmware/App/Services/NVMsgQ.h =================================================================== diff -u -r1be7dc9ec7ae5a6576a4c841e3b22ac77aea8db8 -rb878faee61a0800b767d053ab3f65afb3790dacb --- firmware/App/Services/NVMsgQ.h (.../NVMsgQ.h) (revision 1be7dc9ec7ae5a6576a4c841e3b22ac77aea8db8) +++ firmware/App/Services/NVMsgQ.h (.../NVMsgQ.h) (revision b878faee61a0800b767d053ab3f65afb3790dacb) @@ -43,7 +43,7 @@ #define INSTIT_RECORD_NV_MEM_START_ADDRESS ( BANK7_SECTOR2_START_ADDRESS + INSTIT_RECORD_OFFSET ) #define USAGE_INFO_START_ADDRESS ( BANK7_SECTOR3_START_ADDRESS + USAGE_RECORD_OFFSET ) ///< DD usage info start address in RTC RAM (48). -#define MIN_JOBS_NEEDED_FOR_SECTOR_0 5U ///< Min queue count needed to erase and write all (5) records back in sector 0. +#define MIN_JOBS_NEEDED_FOR_ALL_RECORDS ( NUM_OF_NVDATMGMT_RECORDS_JOBS * 2 ) ///< Min queue count needed to erase and write all records /// NVDataMgmt records read status typedef enum NVDataMgmt_NV_Records_Read_Status @@ -69,15 +69,17 @@ BOOL enqueueSector0Records( void ); void enqueuePOSTReadRecords( void ); +BOOL enqueueNVMReceiveRecord( RECORD_JOBS_STATE_T job, U32 currentMessage, U32 totalMessages, U32 length, U08 *payloadPtr ); + BOOL testDDGetNVRecord( MESSAGE_T *message ); BOOL testDDSetNVRecord( MESSAGE_T *message ); void handleSendInstitutionalRecordToUI( MESSAGE_T* message ); BOOL receiveRecordFromDialin( RECORD_JOBS_STATE_T job, U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); BOOL isNewCalibrationRecordAvailable( void ); -void updateNewCalAvailableFlag( BOOL value ); +void updateNewNVRecordAvailableFlag( BOOL value ); void updateRecordReadStatus( NVDATAMGMT_RECORDS_READ_STATUS_T status ); -void updateCalStartTimer( U32 value ); +void updateRecordStartTimer( U32 value ); PROCESS_RECORD_JOB_T getCurrentProcessRecordJob ( void ); Index: firmware/App/Services/NVRecordsDD.c =================================================================== diff -u -ra68c7679e493224bd41df72321d4c2537207234f -rb878faee61a0800b767d053ab3f65afb3790dacb --- firmware/App/Services/NVRecordsDD.c (.../NVRecordsDD.c) (revision a68c7679e493224bd41df72321d4c2537207234f) +++ firmware/App/Services/NVRecordsDD.c (.../NVRecordsDD.c) (revision b878faee61a0800b767d053ab3f65afb3790dacb) @@ -151,21 +151,21 @@ // ********** private data ********** -// Calibration variables -static DD_CALIBRATION_RECORD_T ddCalibrationRecord; ///< DD calibration record structure (including padding and final CRC). +// NVM Record variables static DD_SYSTEM_GROUP_T ddSystemGroup; ///< DD system group structure (including padding and final CRC). static DD_SERVICE_GROUP_T ddServiceGroup; ///< DD service group structure (including padding and final CRC). +static DD_CALIBRATION_RECORD_T ddCalibrationRecord; ///< DD calibration record structure (including padding and final CRC). static DD_INSTITUTIONAL_GROUP_T ddInstitutionalGroup; ///< DD institutional group structure (including padding and final CRC). static DD_USAGE_INFO_GROUP_T ddUsageInfoGroup; ///< DD usage info structure (including padding and final CRC). // Process records specifications -const PROCESS_RECORD_SPECS_T RECORDS_SPECS[ NUM_OF_NVDATMGMT_RECORDS_JOBS ] = { - // Start address Size of the job Max write bytes per job Max read bytes per job Record structure pointer Record CRC pointer Event calibration record update - {CAL_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DD_CALIBRATION_RECORD_T), (U08*)&ddCalibrationRecord, (U08*)&ddCalibrationRecord.crc, DD_EVENT_CAL_RECORD_UPDATE }, // NVDATAMGMT_CALIBRATION_RECORD - {SYSTEM_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_SYSTEM_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DD_SYSTEM_GROUP_T), (U08*)&ddSystemGroup, (U08*)&ddSystemGroup.crc, DD_EVENT_SYSTEM_RECORD_UPDATE }, // NVDATAMGMT_SYSTEM_RECORD - {SERVICE_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_SERVICE_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DD_SERVICE_GROUP_T), (U08*)&ddServiceGroup, (U08*)&ddServiceGroup.crc, DD_EVENT_SERVICE_UPDATE }, // NVDATAMGMT_SERVICE_RECORD - {INSTIT_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_INSTITUTIONAL_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DD_INSTITUTIONAL_GROUP_T), (U08*)&ddInstitutionalGroup, (U08*)&ddInstitutionalGroup.crc, DD_EVENT_INSTIT_RECORD_UPDATE }, // NVDATAMGMT_INTITUTIONAL_RECORD - {USAGE_INFO_START_ADDRESS, sizeof(DD_USAGE_INFO_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DD_USAGE_INFO_GROUP_T), (U08*)&ddUsageInfoGroup, (U08*)&ddUsageInfoGroup.crc, DD_EVENT_USAGE_INFO_UPDATE }, // NVDATAMGMT_USAGE_INFO_RECORD +const PROCESS_RECORD_SPECS_T RECORDS_SPECS[ NUM_OF_NVDATMGMT_RECORDS_JOBS ] + // Start address Size of the job Record structure pointer Record CRC pointer Event calibration record update + {SYSTEM_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_SYSTEM_GROUP_T), (U08*)&ddSystemGroup, (U08*)&ddSystemGroup.crc, DD_EVENT_SYSTEM_RECORD_UPDATE }, // NVDATAMGMT_SYSTEM_RECORD + {SERVICE_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_SERVICE_GROUP_T), (U08*)&ddServiceGroup, (U08*)&ddServiceGroup.crc, DD_EVENT_SERVICE_UPDATE }, // NVDATAMGMT_SERVICE_RECORD + {CAL_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_CALIBRATION_RECORD_T), (U08*)&ddCalibrationRecord, (U08*)&ddCalibrationRecord.crc, DD_EVENT_CAL_RECORD_UPDATE }, // NVDATAMGMT_CALIBRATION_RECORD + {INSTIT_RECORD_NV_MEM_START_ADDRESS, sizeof(DD_INSTITUTIONAL_GROUP_T), (U08*)&ddInstitutionalGroup, (U08*)&ddInstitutionalGroup.crc, DD_EVENT_INSTIT_RECORD_UPDATE }, // NVDATAMGMT_INSTITUTIONAL_RECORD + {USAGE_INFO_START_ADDRESS, sizeof(DD_USAGE_INFO_GROUP_T), (U08*)&ddUsageInfoGroup, (U08*)&ddUsageInfoGroup.crc, DD_EVENT_USAGE_INFO_UPDATE }, // NVDATAMGMT_USAGE_INFO_RECORD }; static NVDATAMGMT_SELF_TEST_STATE_T nvDataMgmtSelfTestState; ///< NVDataMgmt self-test state variable. @@ -313,8 +313,8 @@ // Check if the records' entire CRCs as well as the individual CRCs passed if ( ( TRUE == haveCalGroupsPassed ) && ( TRUE == hasSystemRecordPassed ) && ( TRUE == hasServiceRecordPassed ) && ( TRUE == hasInstitutionalRecordPassed ) ) { - updateCalStartTimer( getMSTimerCount() ); - updateNewCalAvailableFlag( TRUE ); + updateRecordStartTimer( getMSTimerCount() ); + updateNewNVRecordAvailableFlag( TRUE ); nvDataMgmtSelfTestResult = SELF_TEST_STATUS_PASSED; } @@ -1191,7 +1191,7 @@ { BOOL status = FALSE; - if ( getAvailableRecordQueueCount() >= ( MIN_JOBS_NEEDED_FOR_SECTOR_0 + 1 ) ) + if ( getAvailableRecordQueueCount() >= ( MIN_JOBS_NEEDED_FOR_ALL_RECORDS + 1 ) ) { // When the service record is changed, all the sector 0 must be re-written plus the stack's usage information must be updated. // Therefore, at least 4 queues are needed to be able to update all the records. The usage records are changed: @@ -1463,7 +1463,7 @@ status = enqueueSector0Records(); break; - case NVDATAMGMT_INTITUTIONAL_RECORD: + case NVDATAMGMT_INSTITUTIONAL_RECORD: ddInstitutionalGroup.ddInstitutionalRecord.crc = crc; status = enqueueSector0Records(); break; Index: firmware/App/Services/NVRecordsDD.h =================================================================== diff -u -ra68c7679e493224bd41df72321d4c2537207234f -rb878faee61a0800b767d053ab3f65afb3790dacb --- firmware/App/Services/NVRecordsDD.h (.../NVRecordsDD.h) (revision a68c7679e493224bd41df72321d4c2537207234f) +++ firmware/App/Services/NVRecordsDD.h (.../NVRecordsDD.h) (revision b878faee61a0800b767d053ab3f65afb3790dacb) @@ -36,7 +36,7 @@ #define FLOW_SENSROS_RESERVED_SPACE_COUNT 2 ///< Flow sensors reserved space count. #define TEMP_SENSORS_RESERVED_SPACE_COUNT 2 ///< Temperature sensors reserved space count. #define GENERIC_VOL_RESERVED_SPACE_COUNT 4 ///< Generic volumes reserved space count. -#define MAX_EEPROM_WRITE_BUFFER_BYTES 16U ///< Max allowed bytes for an EEPROM write (16 bytes). +#define MAX_EEPROM_WRITE_BUFFER_BYTES 16U ///< Max allowed bytes for an EEPROM write (16 bytes). /// NVDataMgmt self-test states enumeration. typedef enum NVDataMgmt_Self_Test_States @@ -50,14 +50,11 @@ /// Process records specifications structure typedef struct { - U32 recordFlashAddress; ///< Jobs spec start address. - U32 sizeofJob; ///< Jobs spec size of job. - U32 maxWriteBufferSize; ///< Jobs max write allowed processing buffer size. - U32 maxReadBufferSize; ///< Jobs max read allowed processing buffer size. + U32 recordFlashAddress; ///< Jobs spec start address. + U32 sizeofRecord; ///< Jobs spec size of job. U08* structAddressPtr; ///< Jobs structure address pointer. U08* structCRCPtr; ///< Jobs structure CRC pointer. DD_EVENT_ID_T nvEvent; ///< Jobs non-volatile DD event (i.e calibration, system). - } PROCESS_RECORD_SPECS_T; /// DD available NV data to get