void EVNT_ClearEvent(EVNT_Handle event) { CS1_CriticalVariable() CS1_EnterCritical(); CLR_EVENT(event); CS1_ExitCritical(); }
void EVNT_SetEvent(EVNT_Handle event) { CS1_CriticalVariable() CS1_EnterCritical(); SET_EVENT(event); CS1_ExitCritical(); }
void setPlayback(void) { CS1_CriticalVariable() ; CS1_EnterCritical() ; playback = TRUE; CS1_ExitCritical() ; }
void clearPlayback(void) { CS1_CriticalVariable() ; CS1_EnterCritical() ; playback = FALSE; CS1_ExitCritical() ; }
uint8_t TRG_SetTrigger(TRG_TriggerKind trigger, TRG_TriggerTime ticks, TRG_Callback callback, TRG_CallBackDataPtr data) { CS1_CriticalVariable() CS1_EnterCritical(); TRG_Triggers[trigger].ticks = ticks; TRG_Triggers[trigger].callback = callback; TRG_Triggers[trigger].data = data; CS1_ExitCritical(); return ERR_OK; }
bool PlaybackIsSet(void) { bool tmp; CS1_CriticalVariable() ; CS1_EnterCritical() ; tmp = playback; CS1_ExitCritical() ; return tmp; }
/* ** =================================================================== ** Method : TMOUT1_LeaveCounter (component Timeout) ** Description : ** To be called to return the counter. Note that a counter ** always should be returned so it can be reused. ** Parameters : ** NAME - DESCRIPTION ** handle - Counter handle ** Returns : Nothing ** =================================================================== */ void TMOUT1_LeaveCounter(TMOUT1_CounterHandle handle) { CS1_CriticalVariable(); if (handle==TMOUT1_OUT_OF_HANDLE) { return; } CS1_EnterCritical(); TMOUT1_Counters[handle] = 0; TMOUT1_FreeCounters[handle]=TRUE; CS1_ExitCritical(); }
/* ** =================================================================== ** Method : TMOUT1_Value (component Timeout) ** Description : ** Return the current value of the counter (in ticks) ** Parameters : ** NAME - DESCRIPTION ** handle - Handle of the timeout counter ** Returns : ** --- - Returns the value of the timeout counter. ** =================================================================== */ TMOUT1_CounterType TMOUT1_Value(TMOUT1_CounterHandle handle) { TMOUT1_CounterType val; CS1_CriticalVariable(); if (handle==TMOUT1_OUT_OF_HANDLE) { return 0; /* return dummy value */ } CS1_EnterCritical(); val = TMOUT1_Counters[handle]; CS1_ExitCritical(); return val; }
/* ** =================================================================== ** Method : TMOUT1_AddTick (component Timeout) ** Description : ** Method to be called from a periodic timer or interrupt. It ** will decrement all current counters by one down to zero. ** Parameters : None ** Returns : Nothing ** =================================================================== */ void TMOUT1_AddTick(void) { byte i; CS1_CriticalVariable(); CS1_EnterCritical(); for(i=0;i<TMOUT1_NOF_COUNTERS;i++) { if (TMOUT1_Counters[i]>0) { TMOUT1_Counters[i]--; } } CS1_ExitCritical(); }
/* ** =================================================================== ** Method : TMOUT1_CounterExpired (component Timeout) ** Description : ** Returns true if the timeout counter has been expired ** Parameters : ** NAME - DESCRIPTION ** handle - The timeout handle retrieved using ** GetCounter() ** Returns : ** --- - Returns TRUE if the counter has been ** expired, FALSE otherwise ** =================================================================== */ bool TMOUT1_CounterExpired(TMOUT1_CounterHandle handle) { bool res; CS1_CriticalVariable(); if (handle==TMOUT1_OUT_OF_HANDLE) { return TRUE; } CS1_EnterCritical(); res = (bool)(TMOUT1_Counters[handle]==0); CS1_ExitCritical(); return res; }
void TRG_IncTick(void) { TRG_TriggerKind i; CS1_CriticalVariable() CS1_EnterCritical(); for(i=(TRG_TriggerKind)0;i<TRG_NOF_TRIGGERS;i++) { if (TRG_Triggers[i].ticks!=0) { /* prevent underflow */ TRG_Triggers[i].ticks--; } } /* for */ CS1_ExitCritical(); while(CheckCallbacks()) {} /* while we have callbacks, re-iterate the list as this may have added new triggers at the current time */ }
/* ** =================================================================== ** Method : TMOUT1_SetCounter (component Timeout) ** Description : ** Sets the counter to a new value and returns the value just ** prior to the call. ** Parameters : ** NAME - DESCRIPTION ** handle - Counter handle which shall get a new ** value. ** nofTicks - New value (tick count) of the ** timeout counter. Pass zero to have it ** expire immediately. ** Returns : ** --- - Value of counter before reset. ** =================================================================== */ TMOUT1_CounterType TMOUT1_SetCounter(TMOUT1_CounterHandle handle, TMOUT1_CounterType nofTicks) { TMOUT1_CounterType res; CS1_CriticalVariable(); if (handle==TMOUT1_OUT_OF_HANDLE) { return 0; /* return dummy value */ } CS1_EnterCritical(); res = TMOUT1_Counters[handle]; TMOUT1_Counters[handle] = nofTicks; CS1_ExitCritical(); return res; }
void EVENT_HandleEvent(void (*callback)(EVENT_Handle)) { /* Handle the one with the highest priority. Zero is the event with the highest priority. */ EVENT_Handle event; CS1_CriticalVariable(); CS1_EnterCritical(); for (event=(EVENT_Handle)0; event<EVENT_NOF_EVENTS; event++) { /* does a test on every event */ if (GET_EVENT(event)) { /* event present? */ CLR_EVENT(event); /* clear event */ break; /* get out of loop */ } } CS1_ExitCritical(); if (event != EVENT_NOF_EVENTS) { callback(event); /* Note: if the callback sets the event, we will get out of the loop. * We will catch it by the next iteration. */ } }
/* ** =================================================================== ** Method : TMOUT1_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. ** =================================================================== */ TMOUT1_CounterHandle TMOUT1_GetCounter(TMOUT1_CounterType nofTicks) { TMOUT1_CounterHandle handle; CS1_CriticalVariable(); handle = 0; if (nofTicks==0) { nofTicks = 1; /* wait at least for one tick, otherwise will timeout immediately */ } CS1_EnterCritical(); while (!TMOUT1_FreeCounters[handle] && handle<TMOUT1_NOF_COUNTERS) { handle++; } if (handle<TMOUT1_NOF_COUNTERS) { TMOUT1_FreeCounters[handle]=FALSE; TMOUT1_Counters[handle] = nofTicks; } CS1_ExitCritical(); if (handle==TMOUT1_NOF_COUNTERS) { return TMOUT1_OUT_OF_HANDLE; } return handle; }