/* ################################################################### ** This component module is generated by Processor Expert. Do not modify it. ** Filename : McuTimeout.h ** Project : FRDM-K64F_Generator ** Processor : MK64FN1M0VLL12 ** Component : Timeout ** Version : Component 01.038, Driver 01.00, CPU db: 3.00.000 ** Compiler : GNU C Compiler ** Date/Time : 2020-08-14, 06:24, # CodeGen: 679 ** Abstract : ** The module implements timeout functionality. With this implementation, it is possible to wait for a given time, and the time is counted by a periodic interrupt. ** Settings : ** Component name : McuTimeout ** Maximum counters : 1 ** Counter tick period (ms) : 10 ** RTOS : Disabled ** Contents : ** GetCounter - McuTimeout_CounterHandle McuTimeout_GetCounter(McuTimeout_CounterType nofTicks); ** LeaveCounter - void McuTimeout_LeaveCounter(McuTimeout_CounterHandle handle); ** Value - McuTimeout_CounterType McuTimeout_Value(McuTimeout_CounterHandle handle); ** SetCounter - McuTimeout_CounterType McuTimeout_SetCounter(McuTimeout_CounterHandle handle,... ** CounterExpired - bool McuTimeout_CounterExpired(McuTimeout_CounterHandle handle); ** AddTick - void McuTimeout_AddTick(void); ** Init - void McuTimeout_Init(void); ** ** * Copyright (c) 2011-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 McuTimeout.h ** @version 01.00 ** @brief ** The module implements timeout functionality. With this implementation, it is possible to wait for a given time, and the time is counted by a periodic interrupt. */ /*! ** @addtogroup McuTimeout_module McuTimeout module documentation ** @{ */ /* MODULE McuTimeout. */ #include "McuTimeout.h" #define McuTimeout_NOF_COUNTERS 1 /* number of timeout counters available */ static McuTimeout_CounterType McuTimeout_Counters[McuTimeout_NOF_COUNTERS]; /* array of timeout counters */ static bool McuTimeout_FreeCounters[McuTimeout_NOF_COUNTERS]; /* array to indicate which counters are free */ /* ** =================================================================== ** Method : GetCounter (component Timeout) ** ** Description : ** Initializes a new timeout counter and returns the handle to ** it. At the end, use LeaveCounter() to free up the resource. ** Parameters : ** NAME - DESCRIPTION ** nofTicks - Number of ticks for the counter ** until it expires. ** Returns : ** --- - Handle to the counter, to be used for ** further API calls. ** =================================================================== */ McuTimeout_CounterHandle McuTimeout_GetCounter(McuTimeout_CounterType nofTicks) { McuTimeout_CounterHandle handle; McuCriticalSection_CriticalVariable(); handle = 0; if (nofTicks==0) { nofTicks = 1; /* wait at least for one tick, otherwise will timeout immediately */ } McuCriticalSection_EnterCritical(); while (handle0) { McuTimeout_Counters[i]--; } } McuCriticalSection_ExitCritical(); } /* ** =================================================================== ** Method : Init (component Timeout) ** ** Description : ** Initialization of the driver ** Parameters : None ** Returns : Nothing ** =================================================================== */ void McuTimeout_Init(void) { uint8_t i; for(i=0;i