/* ################################################################### ** This component module is generated by Processor Expert. Do not modify it. ** Filename : InputRB1.h ** Project : FRDM-K64F_Generator ** Processor : MK64FN1M0VLL12 ** Component : RingBuffer ** Version : Component 01.054, Driver 01.00, CPU db: 3.00.000 ** Compiler : GNU C Compiler ** Date/Time : 2020-08-14, 06:24, # CodeGen: 679 ** Abstract : ** This component implements a ring buffer for different integer data type. ** Settings : ** Component name : InputRB1 ** Buffer Size : 10 ** Contents : ** Clear - void InputRB1_Clear(void); ** Put - uint8_t InputRB1_Put(InputRB1_ElementType elem); ** Get - uint8_t InputRB1_Get(InputRB1_ElementType *elemP); ** Peek - uint8_t InputRB1_Peek(InputRB1_BufSizeType index, InputRB1_ElementType *elemP); ** Update - uint8_t InputRB1_Update(InputRB1_BufSizeType index, InputRB1_ElementType... ** Putn - uint8_t InputRB1_Putn(InputRB1_ElementType *elem, InputRB1_BufSizeType nof); ** Getn - uint8_t InputRB1_Getn(InputRB1_ElementType *buf, InputRB1_BufSizeType nof); ** Compare - uint8_t InputRB1_Compare(InputRB1_BufSizeType index, InputRB1_ElementType... ** Delete - uint8_t InputRB1_Delete(void); ** NofElements - InputRB1_BufSizeType InputRB1_NofElements(void); ** NofFreeElements - InputRB1_BufSizeType InputRB1_NofFreeElements(void); ** Deinit - void InputRB1_Deinit(void); ** Init - void InputRB1_Init(void); ** ** * Copyright (c) 2014-2020, Erich Styger ** * Web: https://mcuoneclipse.com ** * SourceForge: https://sourceforge.net/projects/mcuoneclipse ** * Git: https://github.com/ErichStyger/McuOnEclipse_PEx ** * All rights reserved. ** * ** * Redistribution and use in source and binary forms, with or without modification, ** * are permitted provided that the following conditions are met: ** * ** * - Redistributions of source code must retain the above copyright notice, this list ** * of conditions and the following disclaimer. ** * ** * - Redistributions in binary form must reproduce the above copyright notice, this ** * list of conditions and the following disclaimer in the documentation and/or ** * other materials provided with the distribution. ** * ** * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ** * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ** * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ** * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ** * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ** * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ** * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ** * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ** * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ** ###################################################################*/ /*! ** @file InputRB1.h ** @version 01.00 ** @brief ** This component implements a ring buffer for different integer data type. */ /*! ** @addtogroup InputRB1_module InputRB1 module documentation ** @{ */ /* MODULE InputRB1. */ #include "InputRB1.h" #if InputRB1_CONFIG_REENTRANT #define InputRB1_DEFINE_CRITICAL() McuCriticalSection_CriticalVariable() #define InputRB1_ENTER_CRITICAL() McuCriticalSection_EnterCritical() #define InputRB1_EXIT_CRITICAL() McuCriticalSection_ExitCritical() #else #define InputRB1_DEFINE_CRITICAL() /* nothing */ #define InputRB1_ENTER_CRITICAL() /* nothing */ #define InputRB1_EXIT_CRITICAL() /* nothing */ #endif static InputRB1_ElementType InputRB1_buffer[InputRB1_CONFIG_BUF_SIZE]; /* ring buffer */ static InputRB1_BufSizeType InputRB1_inIdx; /* input index */ static InputRB1_BufSizeType InputRB1_outIdx; /* output index */ static InputRB1_BufSizeType InputRB1_inSize; /* size data in buffer */ /* ** =================================================================== ** Method : Put (component RingBuffer) ** ** Description : ** Puts a new element into the buffer ** Parameters : ** NAME - DESCRIPTION ** elem - New element to be put into the buffer ** Returns : ** --- - Error code ** =================================================================== */ uint8_t InputRB1_Put(InputRB1_ElementType elem) { uint8_t res = ERR_OK; InputRB1_DEFINE_CRITICAL(); InputRB1_ENTER_CRITICAL(); if (InputRB1_inSize==InputRB1_CONFIG_BUF_SIZE) { res = ERR_TXFULL; } else { InputRB1_buffer[InputRB1_inIdx] = elem; InputRB1_inIdx++; if (InputRB1_inIdx==InputRB1_CONFIG_BUF_SIZE) { InputRB1_inIdx = 0; } InputRB1_inSize++; } InputRB1_EXIT_CRITICAL(); return res; } /* ** =================================================================== ** Method : Putn (component RingBuffer) ** ** Description : ** Put a number new element into the buffer. ** Parameters : ** NAME - DESCRIPTION ** * elem - Pointer to new elements to be put into ** the buffer ** nof - number of elements ** Returns : ** --- - Error code ** =================================================================== */ uint8_t InputRB1_Putn(InputRB1_ElementType *elem, InputRB1_BufSizeType nof) { uint8_t res = ERR_OK; while(nof>0) { res = InputRB1_Put(*elem); if (res!=ERR_OK) { break; } elem++; nof--; } return res; } /* ** =================================================================== ** Method : Get (component RingBuffer) ** ** Description : ** Removes an element from the buffer ** Parameters : ** NAME - DESCRIPTION ** * elemP - Pointer to where to store the received ** element ** Returns : ** --- - Error code ** =================================================================== */ uint8_t InputRB1_Get(InputRB1_ElementType *elemP) { uint8_t res = ERR_OK; InputRB1_DEFINE_CRITICAL(); InputRB1_ENTER_CRITICAL(); if (InputRB1_inSize==0) { res = ERR_RXEMPTY; } else { *elemP = InputRB1_buffer[InputRB1_outIdx]; InputRB1_inSize--; InputRB1_outIdx++; if (InputRB1_outIdx==InputRB1_CONFIG_BUF_SIZE) { InputRB1_outIdx = 0; } } InputRB1_EXIT_CRITICAL(); return res; } /* ** =================================================================== ** Method : Getn (component RingBuffer) ** ** Description : ** Get a number elements into a buffer. ** Parameters : ** NAME - DESCRIPTION ** * buf - Pointer to buffer where to store the ** elements ** nof - number of elements ** Returns : ** --- - Error code ** =================================================================== */ uint8_t InputRB1_Getn(InputRB1_ElementType *buf, InputRB1_BufSizeType nof) { uint8_t res = ERR_OK; while(nof>0) { res = InputRB1_Get(buf); if (res!=ERR_OK) { break; } buf++; nof--; } return res; } /* ** =================================================================== ** Method : NofElements (component RingBuffer) ** ** Description : ** Returns the actual number of elements in the buffer. ** Parameters : None ** Returns : ** --- - Number of elements in the buffer. ** =================================================================== */ InputRB1_BufSizeType InputRB1_NofElements(void) { return InputRB1_inSize; } /* ** =================================================================== ** Method : NofFreeElements (component RingBuffer) ** ** Description : ** Returns the actual number of free elements/space in the ** buffer. ** Parameters : None ** Returns : ** --- - Number of elements in the buffer. ** =================================================================== */ InputRB1_BufSizeType InputRB1_NofFreeElements(void) { return (InputRB1_BufSizeType)(InputRB1_CONFIG_BUF_SIZE-InputRB1_inSize); } /* ** =================================================================== ** Method : Init (component RingBuffer) ** ** Description : ** Initializes the data structure ** Parameters : None ** Returns : Nothing ** =================================================================== */ void InputRB1_Init(void) { InputRB1_inIdx = 0; InputRB1_outIdx = 0; InputRB1_inSize = 0; } /* ** =================================================================== ** Method : Clear (component RingBuffer) ** ** Description : ** Clear (empty) the ring buffer. ** Parameters : None ** Returns : Nothing ** =================================================================== */ void InputRB1_Clear(void) { InputRB1_DEFINE_CRITICAL(); InputRB1_ENTER_CRITICAL(); InputRB1_Init(); InputRB1_EXIT_CRITICAL(); } /* ** =================================================================== ** Method : Peek (component RingBuffer) ** ** Description : ** Returns an element of the buffer without removiing it. ** Parameters : ** NAME - DESCRIPTION ** index - Index of element. 0 peeks the top ** element, 1 the next, and so on. ** * elemP - Pointer to where to store the received ** element ** Returns : ** --- - Error code ** =================================================================== */ uint8_t InputRB1_Peek(InputRB1_BufSizeType index, InputRB1_ElementType *elemP) { uint8_t res = ERR_OK; int idx; /* index inside ring buffer */ InputRB1_DEFINE_CRITICAL(); InputRB1_ENTER_CRITICAL(); if (index>=InputRB1_CONFIG_BUF_SIZE) { res = ERR_OVERFLOW; /* asking for an element outside of ring buffer size */ } else if (index0) { res = InputRB1_Peek(index, &val); if (res!=ERR_OK) { /* general failure? */ cmpResult = (uint8_t)-1; /* no match */ break; } if (val!=*elemP) { /* mismatch */ cmpResult = (uint8_t)-1; /* no match */ break; } elemP++; index++; nof--; } return cmpResult; } /* ** =================================================================== ** Method : Deinit (component RingBuffer) ** ** Description : ** Driver de-initialization ** Parameters : None ** Returns : Nothing ** =================================================================== */ /** void InputRB1_Deinit(void) { ** Function is implemented as macro in the header file } */ /* ** =================================================================== ** Method : Delete (component RingBuffer) ** ** Description : ** Removes an element from the buffer ** Parameters : None ** Returns : ** --- - Error code ** =================================================================== */ uint8_t InputRB1_Delete(void) { uint8_t res = ERR_OK; InputRB1_DEFINE_CRITICAL(); InputRB1_ENTER_CRITICAL(); if (InputRB1_inSize==0) { res = ERR_RXEMPTY; } else { InputRB1_inSize--; InputRB1_outIdx++; if (InputRB1_outIdx==InputRB1_CONFIG_BUF_SIZE) { InputRB1_outIdx = 0; } } InputRB1_EXIT_CRITICAL(); return res; } /* ** =================================================================== ** Method : Update (component RingBuffer) ** ** Description : ** Updates the data of an element. ** Parameters : ** NAME - DESCRIPTION ** index - Index of element. 0 peeks the top ** element, 1 the next, and so on. ** * elemP - Pointer to where to store the received ** element ** Returns : ** --- - Error code ** =================================================================== */ uint8_t InputRB1_Update(InputRB1_BufSizeType index, InputRB1_ElementType *elemP) { uint8_t res = ERR_OK; int idx; /* index inside ring buffer */ InputRB1_DEFINE_CRITICAL(); InputRB1_ENTER_CRITICAL(); if (index>=InputRB1_CONFIG_BUF_SIZE) { res = ERR_OVERFLOW; /* asking for an element outside of ring buffer size */ } else if (index