Index: App/Services/MsgQueues.c =================================================================== diff -u -r833095dbbe2b21a989b05f48bd7ddc390ad964cb -ra87b6b9e253c6c0fcc84bca6f5de71959ce18bcc --- App/Services/MsgQueues.c (.../MsgQueues.c) (revision 833095dbbe2b21a989b05f48bd7ddc390ad964cb) +++ App/Services/MsgQueues.c (.../MsgQueues.c) (revision a87b6b9e253c6c0fcc84bca6f5de71959ce18bcc) @@ -10,7 +10,10 @@ * @date 08-Oct-2019 * @author S. Nash * - * @brief MsgQueues service module. Provides message queue functionality. + * @brief MsgQueues service module. Provides message queue functionality. \n + * These queues are NOT thread safe. However, these queue functions are \n + * intended to be called from the General Task thread so no thread safety \n + * is required. * **************************************************************************/ @@ -59,10 +62,10 @@ /************************************************************************* * @brief addToMsgQueue * The addToMsgQueue function adds a message to a given message queue. \n - * A CRC is calculated for the message and included in the message wrapper. + * This function should only be called from the General Task. * @details * Inputs : none - * Outputs : none + * Outputs : message added to queue * @param queue : the message queue to add to * @param msg : a pointer to a message structure to add to the queue * @return TRUE if message added to queue, FALSE if could not @@ -74,39 +77,17 @@ // verify given message queue if ( queue < NUM_OF_MSG_QUEUES ) { - U32 next; - U32 count; - BOOL full = FALSE; - - // thread protection - // TODO - disable interrupts (selectively if possible) - - // reserve next available queue space while under thread protection - next = msgQueueNexts[queue]; - count = msgQueueCounts[queue]; - if ( count < MAX_MSG_QUEUE_SIZE ) - { // increment queue count and next queue indexes while under thread protection - msgQueueCounts[queue]++; - msgQueueNexts[queue] = INC_WRAP(next,0,MAX_MSG_QUEUE_SIZE); - } - else + if ( FALSE == isMsgQueueFull( queue ) ) { - full = TRUE; - } - - // end thread protection - // TODO - re-enable interrupts - - // make sure queue is not full - if ( FALSE == full ) - { + result = TRUE; // add message to queue - msgQueues[queue][next] = *msg; - - // TODO - calculate CRC for given message (just zero for now) - msgQueues[queue][next].crc = 0x0; + msgQueues[queue][msgQueueNexts[queue]] = *msg; + // increment next index to add to + msgQueueNexts[queue] = INC_WRAP(msgQueueNexts[queue],0,MAX_MSG_QUEUE_SIZE); + // increment queue count + msgQueueCounts[queue]++; } - else // message queue is full + else // msg queue is full { // TODO - s/w fault? } @@ -122,12 +103,13 @@ /************************************************************************* * @brief getFromMsgQueue * The getFromMsgQueue function retrieves the next message from a given \n - * message queue. + * message queue. This function should only be called from the General Task. * @details - * Inputs : none - * Outputs : none + * Inputs : queue + * Outputs : message retrieved from the queue * @param queue : the message queue to retrieve from - * @param msg : a pointer to a message structure to stuff + * @param msg : a pointer to a message structure to populate with the retrieved \n + * message. * @return TRUE if a message was found to retrieve, FALSE if not *************************************************************************/ BOOL getFromMsgQueue( MSG_QUEUE_T queue, MESSAGE_WRAPPER_T *msg ) @@ -137,40 +119,19 @@ // verify given message queue if ( queue < NUM_OF_MSG_QUEUES ) { - U32 first; - U32 count; - BOOL empty = FALSE; - - // thread protection - // TODO - disable interrupts (selectively if possible) - - // reserve next available queue space while under thread protection - first = msgQueueStarts[queue]; - count = msgQueueCounts[queue]; - if ( count > 0 ) - { // decrement queue count and increment start queue index while under thread protection - msgQueueCounts[queue]--; - msgQueueStarts[queue] = INC_WRAP(first,0,MAX_MSG_QUEUE_SIZE); - } - else + if ( FALSE == isMsgQueueEmpty( queue ) ) { - empty = TRUE; - } - - // end thread protection - // TODO - re-enable interrupts - - // make sure queue is not empty - if ( FALSE == empty ) - { - // get message from queue - *msg = msgQueues[queue][first]; - result = TRUE; + // get message from queue + *msg = msgQueues[queue][msgQueueStarts[queue]]; + // increment queue next index to get from + msgQueueStarts[queue] = INC_WRAP(msgQueueStarts[queue],0,MAX_MSG_QUEUE_SIZE); + // decrement queue count + msgQueueCounts[queue]--; } - else // message queue is full + else // message queue is empty { - // TODO - s/w fault? + // result already set to FALSE } } else // invalid message queue