Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r48558494898419baa0697009318fb543fe0b8a46 -rb442c93bd71649c2e7473c7013d32c534334cdcb --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 48558494898419baa0697009318fb543fe0b8a46) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision b442c93bd71649c2e7473c7013d32c534334cdcb) @@ -46,6 +46,7 @@ #include "ModePreGenPermeateDefeatured.h" #include "ModePostGenDialysate.h" #include "ModeStandby.h" +#include "NVMsgQ.h" #include "OperationModes.h" #include "PAL.h" #include "PermeateTank.h" @@ -266,6 +267,7 @@ { MSG_ID_DD_BICARB_CHAMBER_FILL_REQUEST_OVERRIDE_REQUEST, &testBiCarbChamberFillRequestOverride }, { MSG_ID_DD_BICART_DRAIN_REQUEST_OVERRIDE_REQUEST, &testDryBiCartDrainRequestOverride }, { MSG_ID_DD_BICART_CARTRIDGE_SELECT_OVERRIDE_REQUEST, &testDryBiCartTypeOverride }, + { MSG_ID_DD_NVM_GET_RECORD, &testDDGetNVRecord }, { MSG_ID_FP_RO_REJECTION_RATIO_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testRORejectionRatioDataPublishIntervalOverride }, { MSG_ID_FP_RO_FILTERED_REJECTION_RATIO_OVERRIDE_REQUEST, &testRORejectionRatioFilteredOverride }, { MSG_ID_FP_SET_TEST_CONFIGURATION, &testSetTestConfiguration }, Index: firmware/App/Services/NVMsgQ.c =================================================================== diff -u -r43e60a63eae841e599ff9106f43177a8f63d22be -rb442c93bd71649c2e7473c7013d32c534334cdcb --- firmware/App/Services/NVMsgQ.c (.../NVMsgQ.c) (revision 43e60a63eae841e599ff9106f43177a8f63d22be) +++ firmware/App/Services/NVMsgQ.c (.../NVMsgQ.c) (revision b442c93bd71649c2e7473c7013d32c534334cdcb) @@ -15,6 +15,7 @@ #include // For memcpy #include // For ceilf function #include "Common.h" +#include "MsgDefs.h" #include "NVMsgQ.h" #include "NVRecordsDD.h" #include "TaskGeneral.h" @@ -31,8 +32,8 @@ #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_CAL_PAYLOAD 150U ///< Number of bytes per calibration payload. -#define CAL_DATA_SEND_INTERVAL_COUNT (MS_PER_SECOND / (5 * TASK_GENERAL_INTERVAL)) ///< Calibration data send time interval in counts. +#define NUM_OF_BYTES_PER_RECORD_PAYLOAD ( MAX_MSG_PAYLOAD_SIZE - ( sizeof( U32 ) * 3 ) ) ///< Number of bytes per calibration payload. +#define RECORD_DATA_SEND_INTERVAL_COUNT (MS_PER_SECOND / (5 * TASK_GENERAL_INTERVAL)) ///< Calibration data send time interval in counts. #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. @@ -48,6 +49,14 @@ NUM_OF_NVDATAMGMT_PROCESS_RECORD_STATES ///< Number of NVDataMgmt process records state. } PROCESS_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. +} RECEIVE_RECORD_STATE_T; + /// Memory operations structure. typedef struct { @@ -57,13 +66,13 @@ U32 length; ///< Length of a buffer. } MEMORY_OPS_T; -/// NVDataMgmt receive records states -typedef enum NVDataMgmt_Receive_Records_States +typedef struct { - 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. -} RECEIVE_RECORD_STATE_T; + U32 payloadCurrNum; + U32 payloadTotalNum; + U32 length; + U08 data[NUM_OF_BYTES_PER_RECORD_PAYLOAD]; +} DD_NVM_RECORD_PAYLOAD_T; // ********** private data ********** @@ -79,11 +88,12 @@ 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 BOOL hasPublishRecordBeenRequested; ///< Record state machine publish request flag. -static U32 calPublishMessageCount; ///< Calibration data publish message counter. -static U32 calPublishTotalMessages; ///< Calibration data total number of messages to be sent. -static U32 calSendDataIntervalCounter; ///< Calibration data send to CAN bust interval counter. -static U32 previousCalMessageNum; ///< Calibration previous message number. +static RECORD_JOBS_STATE_T nvPublishRecordState; +static BOOL hasPublishRecordBeenRequested[ 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; ///< DG 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. @@ -93,6 +103,9 @@ // Process record functions static PROCESS_RECORD_STATE_T handleExecProcessRecordIdleState( void ); static PROCESS_RECORD_STATE_T handleExecProcessRecordSendRecordState( void ); +static BOOL sendDDRecord( MSG_ID_T msgId, U32 payloadCurrNum, U32 payloadTotalNum, U32 length, U08* calRcrdAddress ); +//static RECORD_JOBS_STATE_T getNVMRecordJobState( MSG_ID_T msgID ); +static MSG_ID_T getNVMRecordResponseMsgId (RECORD_JOBS_STATE_T job ); static void monitorNewCalSignal( void ); void initNVMsgQ ( void ) @@ -106,14 +119,24 @@ isNewCalAvailable = FALSE; nvDataMgmtExecProcessRecordState = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - hasPublishRecordBeenRequested = FALSE; + nvPublishRecordState = NVDATAMGMT_CALIBRATION_RECORD; + hasPublishRecordBeenRequested[ NVDATAMGMT_CALIBRATION_RECORD ] = FALSE; + hasPublishRecordBeenRequested[ NVDATAMGMT_SYSTEM_RECORD ] = FALSE; + hasPublishRecordBeenRequested[ NVDATAMGMT_SERVICE_RECORD ] = FALSE; + hasPublishRecordBeenRequested[ NVDATAMGMT_SCHEDULED_RUNS_RECORD ] = FALSE; + hasPublishRecordBeenRequested[ NVDATAMGMT_HEATERS_INFO_RECORD ] = FALSE; + hasPublishRecordBeenRequested[ NVDATAMGMT_USAGE_INFO_RECORD ] = FALSE; +#ifndef _RELEASE_ + hasPublishRecordBeenRequested[ NVDATAMGMT_SW_CONFIG_RECORD ] = FALSE; +#endif + newCalStartTimer = 0; - calPublishMessageCount = 1; - calPublishTotalMessages = 1; - calSendDataIntervalCounter = 0; - previousCalMessageNum = 0; + recordPublishMsgCount = 1; + recordPublishTotalMsgs = 1; + recordSendDataIntervalCounter = 0; + previousRecordMessageNum = 0; recordReceiveStartTime = 0; } @@ -169,109 +192,91 @@ * @brief * The handleExecProcessRecordIdleState handles the idle state of the * exec cal state machine. - * @details Inputs: hasPublishRecordBeenRequested, calPublishTotalMessages, - * calPublishMessageCount, calSendDataIntervalCounter - * @details Outputs: hasPublishRecordBeenRequested, calPublishTotalMessages, - * calPublishMessageCount, calSendDataIntervalCounter + * @details Inputs: hasPublishRecordBeenRequested, recordPublishTotalMsgs, + * recordPublishMsgCount, recordSendDataIntervalCounter + * @details Outputs: hasPublishRecordBeenRequested, recordPublishTotalMsgs, + * recordPublishMsgCount, recordSendDataIntervalCounter * @return next state of the state machine *************************************************************************/ static PROCESS_RECORD_STATE_T handleExecProcessRecordIdleState( void ) { PROCESS_RECORD_STATE_T state = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; - if ( TRUE == hasPublishRecordBeenRequested ) + if ( TRUE == hasPublishRecordBeenRequested[ nvPublishRecordState ] ) { + recordToPublish = nvPublishRecordState; + // Set the publish flag to FALSE - hasPublishRecordBeenRequested = FALSE; + hasPublishRecordBeenRequested[ 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. - calPublishTotalMessages = (U32)ceilf( (F32)recordSpec.sizeofJob / (F32)NUM_OF_BYTES_PER_CAL_PAYLOAD ); - calPublishMessageCount = 0; + recordPublishTotalMsgs = (U32)ceilf( (F32)recordSpec.sizeofJob / (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 - calSendDataIntervalCounter = CAL_DATA_SEND_INTERVAL_COUNT; + recordSendDataIntervalCounter = RECORD_DATA_SEND_INTERVAL_COUNT; state = NVDATAMGMT_PROCESS_RECORD_STATE_SEND_RECORD; } + nvPublishRecordState = nvPublishRecordState + 1; + if(nvPublishRecordState >= NUM_OF_NVDATMGMT_RECORDS_JOBS) + { + nvPublishRecordState = 0; + } + return state; } /*********************************************************************//** * @brief * The handleExecProcessRecordSendRecordState handles the send calibration * record state of the state machine. - * @details Inputs: dgCalibrationRecord, calPublishTotalMessages, - * calPublishMessageCount, calSendDataIntervalCounter - * @details Outputs: calPublishTotalMessages, calPublishMessageCount, - * calSendDataIntervalCounter + * @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 ) { PROCESS_RECORD_STATE_T state = NVDATAMGMT_PROCESS_RECORD_STATE_SEND_RECORD; + MSG_ID_T msgId; // If the current message number is less than the total, keep sending - if ( calPublishMessageCount < calPublishTotalMessages ) + if ( recordPublishMsgCount < recordPublishTotalMsgs ) { // If it is time to send data - if ( ++calSendDataIntervalCounter >= CAL_DATA_SEND_INTERVAL_COUNT ) + if ( ++recordSendDataIntervalCounter >= RECORD_DATA_SEND_INTERVAL_COUNT ) { // Set to default cal data payload length -// U32 length = NUM_OF_BYTES_PER_CAL_PAYLOAD; + U32 length = NUM_OF_BYTES_PER_RECORD_PAYLOAD; PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( recordToPublish ); U08* startPtr = recordSpec.structAddressPtr; // If this is the last calibration data payload, calculate the remainder of the bytes to send - if ( ( calPublishMessageCount + 1 ) == calPublishTotalMessages ) + if ( ( recordPublishMsgCount + 1 ) == recordPublishTotalMsgs ) { -// length = recordSpec.sizeofJob - ( calPublishMessageCount * NUM_OF_BYTES_PER_CAL_PAYLOAD ); + length = recordSpec.sizeofJob - ( 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 - startPtr += calPublishMessageCount * NUM_OF_BYTES_PER_CAL_PAYLOAD; + startPtr += recordPublishMsgCount * NUM_OF_BYTES_PER_RECORD_PAYLOAD; - switch( recordToPublish ) - { - case NVDATAMGMT_CALIBRATION_RECORD: - // Pass the information to the CAN bus -// sendDGCalibrationRecord( calPublishMessageCount + 1, calPublishTotalMessages, length, startPtr ); - break; + // Get th message id of the NVM record response + msgId = getNVMRecordResponseMsgId( recordToPublish ); - case NVDATAMGMT_SYSTEM_RECORD: - // Pass the information to the CAN bus -// sendDGSystemRecord( calPublishMessageCount + 1, calPublishTotalMessages, length, startPtr ); - break; + // Send the NVM record + sendDDRecord( msgId, recordPublishMsgCount + 1, recordPublishTotalMsgs, length, startPtr ); - case NVDATAMGMT_SERVICE_RECORD: - // Pass the information to the CAN bus -// sendDGServiceRecord( calPublishMessageCount + 1, calPublishTotalMessages, length, startPtr ); - break; - - -#ifndef _RELEASE_ - case NVDATAMGMT_SW_CONFIG_RECORD: -// sendDGSWConfigRecord( calPublishMessageCount + 1, calPublishTotalMessages, length, startPtr ); - break; -#endif - - case NVDATAMGMT_USAGE_INFO_RECORD: -// sendDGUsageInfoRecord( calPublishMessageCount + 1, calPublishTotalMessages, length, startPtr ); - break; - - default: - //Ignore - break; - } - - calPublishMessageCount++; - calSendDataIntervalCounter = 0; + recordPublishMsgCount++; + recordSendDataIntervalCounter = 0; } } else @@ -438,38 +443,42 @@ return recordsReadStatus; } -/*********************************************************************//** - * @brief - * The sendRecordToDialin function prepares the process record state machine - * to send a record to Dialin. - * @details Inputs: nvDataMgmtExecProcessRecordState - * @details Outputs: hasPublishRecordBeenRequested, recordToPublish - * @param job type of job that is requested (i.e. get calibration record, ...) - * @return TRUE if the request was successfully registered - *************************************************************************/ -BOOL sendRecordToDialin( RECORD_JOBS_STATE_T job ) +BOOL testDDGetNVRecord( MESSAGE_T *message ) { - BOOL status = FALSE; + BOOL result = FALSE; + RECORD_JOBS_STATE_T job; - // Check if the state machine is in idle state and then set the request - if ( NVDATAMGMT_PROCESS_RECORD_STATE_IDLE == nvDataMgmtExecProcessRecordState ) + // verify payload length + if ( 1 == message->hdr.payloadLen ) { - hasPublishRecordBeenRequested = TRUE; - recordToPublish = job; - status = TRUE; + job = message->payload[ 0 ]; +// job = getNVMRecordJobState( msgID ); + + if ( ( job >= NVDATAMGMT_CALIBRATION_RECORD ) && ( job < NUM_OF_NVDATMGMT_RECORDS_JOBS ) + && ( NVDATAMGMT_PROCESS_RECORD_STATE_IDLE == nvDataMgmtExecProcessRecordState ) ) + { + // 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; +// } + } + } - return status; + return result; } /*********************************************************************//** * @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, - * previousCalMessageNum, totalMessages, previousCalMessageNum, + * previousRecordMessageNum, totalMessages, previousRecordMessageNum, * @details Outputs: nvDataMgmtExecReceiveRecordState, recordReceiveStartTime, - * previousCalMessageNum, recordUpdateAddress, recordUpdateAddress + * 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 * @param totalMessages: total number of messages from Dialin @@ -486,15 +495,15 @@ { nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_RECEIVE; recordReceiveStartTime = getMSTimerCount(); - previousCalMessageNum = 0; + previousRecordMessageNum = 0; recordUpdateAddress = 0; } // Check if there is still a message left to be received if ( ( NVDATAMGMT_RECEIVE_RECORD_RECEIVE == nvDataMgmtExecReceiveRecordState ) && ( currentMessage <= totalMessages ) ) { // Check if the current message is different from the previous message by 1 - if ( RECORD_DATA_MAX_MESSAGE_DFFIRENCE == ( currentMessage - previousCalMessageNum ) ) + if ( RECORD_DATA_MAX_MESSAGE_DFFIRENCE == ( currentMessage - previousRecordMessageNum ) ) { // Define a pointer that points to the DG calibration record PROCESS_RECORD_SPECS_T recordSpec = getProcessRecord( job ); @@ -547,7 +556,7 @@ recordUpdateAddress += length; // Now the current message is the previous message - previousCalMessageNum = currentMessage; + previousRecordMessageNum = currentMessage; } } } @@ -557,6 +566,108 @@ /*********************************************************************//** * @brief + * The sendDDCalibrationRecord function sends out the DD calibration + * record. + * @details Inputs: none + * @details Outputs: DG calibration record msg constructed and queued + * @param msgId : Message Id for response record + * @param msgCurrNum: current payload number + * @param msgTotalNum: total number of payloads + * @param length: buffer length to be written + * @param recordAddress: start address of the calibration record + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +static BOOL sendDDRecord( MSG_ID_T msgId, U32 payloadCurrNum, U32 payloadTotalNum, U32 length, U08* recordAddress ) +{ + BOOL result = FALSE; + U08 payloadLen = 0; + DD_NVM_RECORD_PAYLOAD_T payload; + + payloadLen = sizeof( U32 ) + sizeof( U32 ) + sizeof( U32 ) + length; + payload.payloadCurrNum = payloadCurrNum; + payload.payloadTotalNum = payloadTotalNum; + payload.length = length; + memcpy(payload.data, recordAddress, length); + result = sendMessage( msgId, COMM_BUFFER_OUT_DD_CAN_PC, (U08 *)&payload, payloadLen); + + return result; +} + +//static RECORD_JOBS_STATE_T getNVMRecordJobState( MSG_ID_T msgID ) +//{ +// RECORD_JOBS_STATE_T job; +// +// switch( msgID ) +// { +// case MSG_ID_DD_NVM_GET_CALIBRATION_RECORD: +// job = NVDATAMGMT_CALIBRATION_RECORD; +// break; +// +// case MSG_ID_DD_NVM_GET_SYSTEM_RECORD: +// job = NVDATAMGMT_SYSTEM_RECORD; +// break; +// +// case MSG_ID_DD_NVM_GET_SERVICE_RECORD: +// job = NVDATAMGMT_SERVICE_RECORD; +// break; +// +// case MSG_ID_DD_NVM_GET_USAGE_INFO_RECORD: +// job = NVDATAMGMT_USAGE_INFO_RECORD; +// break; +// +//#ifndef _RELEASE_ +// case MSG_ID_DD_NVM_GET_SW_CONFIG_RECORD: +// job = NVDATAMGMT_SW_CONFIG_RECORD; +// break; +//#endif +// +// default: +// // Software Fault +// break; +// +// } +// +// return job; +//} + +static MSG_ID_T getNVMRecordResponseMsgId(RECORD_JOBS_STATE_T job ) +{ + MSG_ID_T msgID; + + switch( job ) + { + case NVDATAMGMT_CALIBRATION_RECORD: + msgID = MSG_ID_DD_NVM_SEND_CALIBRATION_RECORD; + break; + + case NVDATAMGMT_SYSTEM_RECORD: + msgID = MSG_ID_DD_NVM_SEND_SYSTEM_RECORD; + break; + + case NVDATAMGMT_SERVICE_RECORD: + msgID = MSG_ID_DD_NVM_SEND_SERVICE_RECORD; + break; + + case NVDATAMGMT_USAGE_INFO_RECORD: + msgID = MSG_ID_DD_NVM_SEND_USAGE_INFO_RECORD; + break; + +#ifndef _RELEASE_ + case NVDATAMGMT_SW_CONFIG_RECORD: + msgID = MSG_ID_DD_NVM_SEND_SW_CONFIG_RECORD; + break; +#endif + + default: + // Software fault + break; + } + + return msgID; +} + +/*********************************************************************//** + * @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 Index: firmware/App/Services/NVMsgQ.h =================================================================== diff -u -r43e60a63eae841e599ff9106f43177a8f63d22be -rb442c93bd71649c2e7473c7013d32c534334cdcb --- firmware/App/Services/NVMsgQ.h (.../NVMsgQ.h) (revision 43e60a63eae841e599ff9106f43177a8f63d22be) +++ firmware/App/Services/NVMsgQ.h (.../NVMsgQ.h) (revision b442c93bd71649c2e7473c7013d32c534334cdcb) @@ -63,7 +63,8 @@ BOOL enqueueSector0Records( void ); void enqueuePOSTReadRecords( void ); -BOOL sendRecordToDialin( RECORD_JOBS_STATE_T job ); +BOOL testDDGetNVRecord( MESSAGE_T *message ); +BOOL testDDSetNVRecord( MESSAGE_T *message ); BOOL receiveRecordFromDialin( RECORD_JOBS_STATE_T job, U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); BOOL isNewCalibrationRecordAvailable( void );