Index: firmware/App/Common.h =================================================================== diff -u -r07a5add2dff254f7be3699e4efac2b99d3554847 -r9a9d04b84f4345fca87fb14d26f09d497b08aae8 --- firmware/App/Common.h (.../Common.h) (revision 07a5add2dff254f7be3699e4efac2b99d3554847) +++ firmware/App/Common.h (.../Common.h) (revision 9a9d04b84f4345fca87fb14d26f09d497b08aae8) @@ -23,16 +23,17 @@ #ifndef _VECTORCAST_ // #define RM46_EVAL_BOARD_TARGET 1 -// #define ACK_IMPLEMENTED 1 // #define SIMULATE_UI 1 - #define DEBUG_ENABLED 1 +// #define DEBUG_ENABLED 1 #ifdef DEBUG_ENABLED #include #include #endif #endif +#define ACK_IMPLEMENTED 1 + // ********** public definitions ********** // **** Types **** Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r07a5add2dff254f7be3699e4efac2b99d3554847 -r9a9d04b84f4345fca87fb14d26f09d497b08aae8 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 07a5add2dff254f7be3699e4efac2b99d3554847) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 9a9d04b84f4345fca87fb14d26f09d497b08aae8) @@ -135,6 +135,7 @@ static BLOOD_PUMP_STATE_T handleBloodPumpRampingUpState( void ); static BLOOD_PUMP_STATE_T handleBloodPumpRampingDownState( void ); static BLOOD_PUMP_STATE_T handleBloodPumpControlToTargetState( void ); +static void setBloodPumpControlSignalPWM( F32 newPWM ); static void stopBloodPump( void ); static void releaseBloodPumpStop( void ); static void setBloodPumpDirection( MOTOR_DIR_T dir ); @@ -338,7 +339,7 @@ { // set initial PWM duty cycle bloodPumpPWMDutyCyclePctSet = BP_PWM_ZERO_OFFSET + MAX_BLOOD_PUMP_PWM_STEP_CHANGE; - etpwmSetCmpA( etpwmREG1, (U32)( (S32)( ( bloodPumpPWMDutyCyclePctSet * (F32)(etpwmREG1->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setBloodPumpControlSignalPWM( bloodPumpPWMDutyCyclePctSet ); // allow blood pump to run in requested direction setBloodPumpDirection( bloodPumpDirection ); releaseBloodPumpStop(); @@ -368,7 +369,7 @@ { // start ramp down to stop bloodPumpPWMDutyCyclePctSet -= MAX_BLOOD_PUMP_PWM_STEP_CHANGE; - etpwmSetCmpA( etpwmREG1, (U32)( (S32)( ( bloodPumpPWMDutyCyclePctSet * (F32)(etpwmREG1->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setBloodPumpControlSignalPWM( bloodPumpPWMDutyCyclePctSet ); result = BLOOD_PUMP_RAMPING_DOWN_STATE; } // have we reached end of ramp up? @@ -382,7 +383,7 @@ else { bloodPumpPWMDutyCyclePctSet += MAX_BLOOD_PUMP_PWM_STEP_CHANGE; - etpwmSetCmpA( etpwmREG1, (U32)( (S32)( ( bloodPumpPWMDutyCyclePctSet * (F32)(etpwmREG1->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setBloodPumpControlSignalPWM( bloodPumpPWMDutyCyclePctSet ); } return result; @@ -419,7 +420,7 @@ else { bloodPumpPWMDutyCyclePctSet -= MAX_BLOOD_PUMP_PWM_STEP_CHANGE; - etpwmSetCmpA( etpwmREG1, (U32)( (S32)( ( bloodPumpPWMDutyCyclePctSet * (F32)(etpwmREG1->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setBloodPumpControlSignalPWM( bloodPumpPWMDutyCyclePctSet ); } return result; @@ -447,14 +448,29 @@ { newPWM = runPIController( PI_CONTROLLER_ID_BLOOD_FLOW, tgtFlow, actFlow ); bloodPumpPWMDutyCyclePctSet = newPWM; - etpwmSetCmpA( etpwmREG1, (U32)( (S32)( ( bloodPumpPWMDutyCyclePctSet * (F32)(etpwmREG1->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setBloodPumpControlSignalPWM( newPWM ); bpControlTimerCounter = 0; } return result; } /************************************************************************* + * @brief setBloodPumpControlSignalPWM + * The setBloodPumpControlSignalPWM function sets the PWM duty cycle for \n + * the blood pump to a given %. + * @details + * Inputs : none + * Outputs : blood pump stop signal activated, PWM duty cycle zeroed + * @param newPWM : new duty cycle % to apply to PWM + * @return none + *************************************************************************/ +static void setBloodPumpControlSignalPWM( F32 newPWM ) +{ + etpwmSetCmpA( etpwmREG1, (U32)( (S32)( ( newPWM * (F32)(etpwmREG1->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); +} + +/************************************************************************* * @brief stopBloodPump * The stopBloodPump function sets the blood pump stop signal. * @details Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r9864b14f76782f1e68bf266dcd843451748715a0 -r9a9d04b84f4345fca87fb14d26f09d497b08aae8 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 9864b14f76782f1e68bf266dcd843451748715a0) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 9a9d04b84f4345fca87fb14d26f09d497b08aae8) @@ -136,6 +136,7 @@ static DIAL_IN_PUMP_STATE_T handleDialInPumpRampingUpState( void ); static DIAL_IN_PUMP_STATE_T handleDialInPumpRampingDownState( void ); static DIAL_IN_PUMP_STATE_T handleDialInPumpControlToTargetState( void ); +static void setDialInPumpControlSignalPWM( F32 newPWM ); static void stopDialInPump( void ); static void releaseDialInPumpStop( void ); static void setDialInPumpDirection( MOTOR_DIR_T dir ); @@ -339,7 +340,7 @@ { // set initial PWM duty cycle dialInPumpPWMDutyCyclePctSet = DIP_PWM_ZERO_OFFSET + MAX_DIAL_IN_PUMP_PWM_STEP_CHANGE; - etpwmSetCmpA( etpwmREG2, (U32)( (S32)( ( dialInPumpPWMDutyCyclePctSet * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setDialInPumpControlSignalPWM( dialInPumpPWMDutyCyclePctSet ); // allow dialIn pump to run in requested direction setDialInPumpDirection( dialInPumpDirection ); releaseDialInPumpStop(); @@ -369,7 +370,7 @@ { // start ramp down to stop dialInPumpPWMDutyCyclePctSet -= MAX_DIAL_IN_PUMP_PWM_STEP_CHANGE; - etpwmSetCmpA( etpwmREG2, (U32)( (S32)( ( dialInPumpPWMDutyCyclePctSet * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setDialInPumpControlSignalPWM( dialInPumpPWMDutyCyclePctSet ); result = DIAL_IN_PUMP_RAMPING_DOWN_STATE; } // have we reached end of ramp up? @@ -383,7 +384,7 @@ else { dialInPumpPWMDutyCyclePctSet += MAX_DIAL_IN_PUMP_PWM_STEP_CHANGE; - etpwmSetCmpA( etpwmREG2, (U32)( (S32)( ( dialInPumpPWMDutyCyclePctSet * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setDialInPumpControlSignalPWM( dialInPumpPWMDutyCyclePctSet ); } return result; @@ -420,7 +421,7 @@ else { dialInPumpPWMDutyCyclePctSet -= MAX_DIAL_IN_PUMP_PWM_STEP_CHANGE; - etpwmSetCmpA( etpwmREG2, (U32)( (S32)( ( dialInPumpPWMDutyCyclePctSet * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setDialInPumpControlSignalPWM( dialInPumpPWMDutyCyclePctSet ); } return result; @@ -448,14 +449,29 @@ { newPWM = runPIController( PI_CONTROLLER_ID_DIALYSATE_FLOW, tgtFlow, actFlow ); dialInPumpPWMDutyCyclePctSet = newPWM; - etpwmSetCmpA( etpwmREG2, (U32)( (S32)( ( dialInPumpPWMDutyCyclePctSet * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); + setDialInPumpControlSignalPWM( newPWM ); dipControlTimerCounter = 0; } return result; } /************************************************************************* + * @brief setDialInPumpControlSignalPWM + * The setDialInPumpControlSignalPWM function sets the PWM duty cycle for \n + * the dialysate inlet pump to a given %. + * @details + * Inputs : none + * Outputs : dialIn pump stop signal activated, PWM duty cycle zeroed + * @param newPWM : new duty cycle % to apply to PWM + * @return none + *************************************************************************/ +static void setDialInPumpControlSignalPWM( F32 newPWM ) +{ + etpwmSetCmpA( etpwmREG2, (U32)( (S32)( ( newPWM * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); +} + +/************************************************************************* * @brief stopDialInPump * The stopDialInPump function sets the dialIn pump stop signal. * @details Index: firmware/App/Services/MsgQueues.h =================================================================== diff -u -r9864b14f76782f1e68bf266dcd843451748715a0 -r9a9d04b84f4345fca87fb14d26f09d497b08aae8 --- firmware/App/Services/MsgQueues.h (.../MsgQueues.h) (revision 9864b14f76782f1e68bf266dcd843451748715a0) +++ firmware/App/Services/MsgQueues.h (.../MsgQueues.h) (revision 9a9d04b84f4345fca87fb14d26f09d497b08aae8) @@ -33,7 +33,7 @@ typedef struct { #ifdef ACK_IMPLEMENTED - U16 seqNo; // sequence # (and ACK required bit) of message + S16 seqNo; // sequence # (and ACK required bit) of message #endif U16 msgID; // ID of message U08 payloadLen; // length of payload in bytes Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r07a5add2dff254f7be3699e4efac2b99d3554847 -r9a9d04b84f4345fca87fb14d26f09d497b08aae8 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 07a5add2dff254f7be3699e4efac2b99d3554847) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 9a9d04b84f4345fca87fb14d26f09d497b08aae8) @@ -662,28 +662,25 @@ if ( msgSize > 0 ) { + MESSAGE_WRAPPER_T rcvMsg; + U08 *dataPtr = data+1; // skip over sync byte + // consume message (+sync byte) msgSize = getFromCommBuffer( MSG_IN_BUFFERS[ i ], data, msgSize + 1 ); - // if message data is at least minimum size, convert received message data to a message and add to message queue - if ( msgSize > MESSAGE_OVERHEAD_SIZE ) - { - MESSAGE_WRAPPER_T rcvMsg; - U08 *dataPtr = data+1; // skip over sync byte - - messagesInBuffer = TRUE; - // blank the new message record - blankMessageInWrapper( &rcvMsg ); - // copy message header portion of message data to the new message - memcpy( &(rcvMsg.msg.hdr), dataPtr, sizeof(MESSAGE_HEADER_T) ); - dataPtr += sizeof(MESSAGE_HEADER_T); - // copy message payload portion of message data to the new message - memcpy( &(rcvMsg.msg.payload), dataPtr, rcvMsg.msg.hdr.payloadLen ); - dataPtr += rcvMsg.msg.hdr.payloadLen; - // copy CRC portion of message data to the new message - rcvMsg.crc = *dataPtr; - // add new message to queue for later processing - addToMsgQueue( MSG_Q_IN, &rcvMsg ); - } // message is at least as large as minimum size + // convert received message data to a message and add to message queue + messagesInBuffer = TRUE; + // blank the new message record + blankMessageInWrapper( &rcvMsg ); + // copy message header portion of message data to the new message + memcpy( &(rcvMsg.msg.hdr), dataPtr, sizeof(MESSAGE_HEADER_T) ); + dataPtr += sizeof(MESSAGE_HEADER_T); + // copy message payload portion of message data to the new message + memcpy( &(rcvMsg.msg.payload), dataPtr, rcvMsg.msg.hdr.payloadLen ); + dataPtr += rcvMsg.msg.hdr.payloadLen; + // copy CRC portion of message data to the new message + rcvMsg.crc = *dataPtr; + // add new message to queue for later processing + addToMsgQueue( MSG_Q_IN, &rcvMsg ); } // looks like there is a complete message in the comm buffer } // enough data left in comm buffer to possibly be a complete message } // while loop to get all complete messages for each comm buffer @@ -750,7 +747,7 @@ // if a minimum sized msg would fit in remaining, continue if ( remSize >= MESSAGE_OVERHEAD_SIZE ) { - payloadSize = data[ pos + sizeof( U16 ) ]; + payloadSize = data[ pos + sizeof( U16 ) + sizeof( U16) ]; msgSize = MESSAGE_OVERHEAD_SIZE + payloadSize; // we now know the size of the message - we can now know if full message is contained in buffer if ( msgSize <= remSize ) @@ -889,7 +886,11 @@ { pendingAckList[ i ].used = TRUE; _enable_IRQ(); - pendingAckList[ i ].seqNo = msg->hdr.seqNo &= ~MSG_ACK_BIT; + if ( msg->hdr.seqNo < 0 ) + { + msg->hdr.seqNo *= -1; + } + pendingAckList[ i ].seqNo = msg->hdr.seqNo; pendingAckList[ i ].channel = channel; pendingAckList[ i ].timeStamp = getMSTimerCount(); pendingAckList[ i ].retries = MSG_NOT_ACKED_MAX_RETRIES; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r07a5add2dff254f7be3699e4efac2b99d3554847 -r9a9d04b84f4345fca87fb14d26f09d497b08aae8 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 07a5add2dff254f7be3699e4efac2b99d3554847) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 9a9d04b84f4345fca87fb14d26f09d497b08aae8) @@ -118,7 +118,7 @@ _enable_IRQ(); if ( TRUE == ackReq ) { - msg.hdr.seqNo |= MSG_ACK_BIT; + msg.hdr.seqNo *= -1; } #endif @@ -180,8 +180,7 @@ // create a message record blankMessage( &msg ); // send ACK back with same seq. #, but w/o ACK bit - msg.hdr.seqNo = message->hdr.seqNo; - msg.hdr.seqNo &= ~MSG_ACK_BIT; + msg.hdr.seqNo = ( message->hdr.seqNo < 0 ? message->hdr.seqNo * -1 : message->hdr.seqNo ); // ACK messages always have this ID msg.hdr.msgID = MSG_ID_ACK;