/************************************************************************** * * Copyright (c) 2019-2019 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 CommBuffers.c * * @date 08-Oct-2019 * @author S. Nash * * @brief CommBuffers service module. Provides data buffering functionality. \n * Data coming in via CAN/UART Rx interrupts can be placed in a buffer to \n * be processed at a later time. Data is double buffered to prevent \n * contention between Rx interrupt and the thread that is consuming the data \n * at a later time. \n * Data to be transmitted via CAN/UART can be placed in a buffer to be sent \n * when the transmitter becomes available. \n * If a buffer becomes too full to service more data, a s/w fault is triggered. * **************************************************************************/ #include "Common.h" #include "CommBuffers.h" // ********** private definitions ********** // ********** private data ********** static U32 commBufferStartPos[NUM_OF_COMM_BUFFERS][2]; // for each buffer, where is start? static U32 commBufferEndPos[NUM_OF_COMM_BUFFERS][2]; // for each buffer, where is end? static U32 commBufferByteCount[NUM_OF_COMM_BUFFERS][2]; // for each buffer, how many bytes? static U32 activeDoubleBuffers[NUM_OF_COMM_BUFFERS][2]; // for each buffer, which double buffer is being fed? static U08 commBuffers[NUM_OF_COMM_BUFFERS][2][COMM_BUFFER_LENGTH]; // each is double buffered to avoid thread contention /************************************************************************* * @brief initCommBuffers * The initCommBuffers function initializes the CommBuffers module. * @details * Inputs : none * Outputs : CommBuffers module initialized. * @param none * @return none *************************************************************************/ void initCommBuffers( void ) { S32 b,l,d; // reset and zero out all buffers for ( b = 0; b < NUM_OF_COMM_BUFFERS; b++ ) { for ( d = 0; d < 2; d++ ) { commBufferStartPos[b][d] = 0; commBufferEndPos[b][d] = 0; commBufferByteCount[b][d] = 0; activeDoubleBuffers[b][d] = 0; for ( l = 0; l < COMM_BUFFER_LENGTH; l++ ) { commBuffers[b][d][l] = 0; } } } } /************************************************************************* * @brief addToCommBuffer * The addToCommBuffer function adds data of specified length to a specified \n * communication buffer. S/W fault if buffer too full to add data. * @details * Inputs : none * Outputs : commBuffers[] * @param buffer : which comm buffer to add data to * @param data : pointer to byte array containing data to add * @param len : length of data (in bytes) * @return TRUE if data added to buffer successfully, FALSE if not *************************************************************************/ BOOL addToCommBuffer( COMM_BUFFER_T buffer, U08* data, U32 len ) { BOOL result = FALSE; return result; } /************************************************************************* * @brief getFromCommBuffer * The getFromCommBuffer function fills a given byte array with data from \n * a given buffer and returns the number of bytes retrieved from the buffer. * @details * Inputs : none * Outputs : none * @param none * @return the number of bytes retrieved. *************************************************************************/ U32 getFromCommBuffer( COMM_BUFFER_T buffer, U08* data, U32 maxLen ) { U32 result = 0; return result; }