/************************************************************************** * * Copyright (c) 2026-2027 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file NVMsgQ.c * * @author (original) Arpita Srivastava * @date (original) 6-Aug-2026 * ***************************************************************************/ #include "Common.h" #include "NVMsgQ.h" /** * @addtogroup NVMsgQ * @{ */ // ********** private definitions ********** #define QUEUE_MAX_SIZE 20U ///< Max queue size. #define QUEUE_START_INDEX 0U ///< Queue start index. static NVM_MSG_REQUEST_Q_T requestQueue[ QUEUE_MAX_SIZE ]; ///< Request queue jobs. static U08 requestQueueRearIndex; ///< Request queue rear index. static U08 requestQueueFrontIndex; ///< Request queue front index. static U08 requestQueueCount; ///< Request queue count. static NVM_MSG_REQUEST_Q_T currentNVMsgRequest; ///< Request queue current job. // ********** private data ********** /*********************************************************************//** * @brief * The initNVMsgQ function initializes the NV message queue and related * state variables. * @details \b Inputs: none * @details \b Outputs: requestQueueRearIndex, requestQueueFrontIndex, * requestQueueCount, * @return none *************************************************************************/ void initNVMsgQ ( void ) { requestQueueRearIndex = QUEUE_START_INDEX; requestQueueFrontIndex = QUEUE_START_INDEX; requestQueueCount = 0; } /*********************************************************************//** * @brief * The enqueueNVMsgRequest function enqueues an NV message request * into the request queue and updates the queue indices and count. * @details \b Inputs: requestQueueRearIndex, * requestQueueCount * @details \b Outputs: requestQueue, * requestQueueRearIndex, requestQueueCount * @param request NV message request to be queued * @return none *************************************************************************/ void enqueueNVMsgRequest( NVM_MSG_REQUEST_Q_T request ) { requestQueue[ requestQueueRearIndex ] = request; requestQueueCount++; requestQueueRearIndex = INC_WRAP( requestQueueRearIndex, 0, QUEUE_MAX_SIZE - 1 ); } /*********************************************************************//** * @brief * The dequeueNVMsgRequest function removes a record job from the queue. * It updates the front index, retrieves the job, and updates the * queue count. * @details \b Inputs: requestQueueFrontIndex, requestQueueCount, * requestQueue * @details \b Outputs: requestQueueFrontIndex, requestQueueCount, * currentNVMsgRequest * @return none *************************************************************************/ void dequeueNVMsgRequest( void ) { U32 tempIndex; _disable_IRQ(); tempIndex = requestQueueFrontIndex; if ( FALSE == isNVMsgRequestQueueEmpty() ) { requestQueueFrontIndex = INC_WRAP( requestQueueFrontIndex, 0, QUEUE_MAX_SIZE - 1 ); currentNVMsgRequest = requestQueue[ tempIndex ]; } if ( requestQueueCount > 0 ) { requestQueueCount--; } _enable_IRQ(); } /*********************************************************************//** * @brief * The isNVMsgRequestQueueEmpty function checks whether the record queue is * empty. It returns the status based on the queue count. * @details \b Inputs: requestQueueCount * @details \b Outputs: none * @return TRUE if queue is empty otherwise FALSE *************************************************************************/ BOOL isNVMsgRequestQueueEmpty( void ) { BOOL isEmpty = TRUE; if ( requestQueueCount > 0 ) { isEmpty = FALSE; } return isEmpty; } /*********************************************************************//** * @brief * The isNVMsgRequestQueueFull function checks whether the record queue is * full based on the maximum queue size. * @details \b Inputs: requestQueueCount * @details \b Outputs: none * @return TRUE if queue is full otherwise FALSE *************************************************************************/ BOOL isNVMsgRequestQueueFull( void ) { BOOL isFull = FALSE; if ( requestQueueCount >= ( QUEUE_MAX_SIZE - 1 ) ) { isFull = TRUE; } return isFull; } /*********************************************************************//** * @brief * The getAvailableNVMsgRequestQueueCount function returns the number of * available record queue slots based on the current queue count. * @details \b Inputs: requestQueueCount * @details \b Outputs: none * @return available record queues *************************************************************************/ U32 getAvailableNVMsgRequestQueueCount( void ) { return QUEUE_MAX_SIZE - requestQueueCount; } /*********************************************************************//** * @brief * The getCurrentNVMsgRequest function gets the current message request * from the processing queue. * @details \b Inputs: currentNVMsgRequest * @details \b Outputs: none * @return currentNVMsgRequest *************************************************************************/ NVM_MSG_REQUEST_Q_T getCurrentNVMsgRequest( void ) { return currentNVMsgRequest; } // ********** private function prototypes ********** /**@}*/