Ejemplo n.º 1
0
void EVNT_SetEvent(EVNT_Handle event) {
  CS1_CriticalVariable()

  CS1_EnterCritical();
  SET_EVENT(event);
  CS1_ExitCritical();
}
Ejemplo n.º 2
0
void EVNT_ClearEvent(EVNT_Handle event) {
  CS1_CriticalVariable()

  CS1_EnterCritical();
  CLR_EVENT(event);
  CS1_ExitCritical();
}
Ejemplo n.º 3
0
/*!
 * \brief Goes through the list of triggers and returns TRUE in case we have to call a callback.
 * \return Returns TRUE if we have called a callback.
 */
static bool CheckCallbacks(void) {
  TRG_TriggerKind i;
  TRG_Callback callback;
  TRG_CallBackDataPtr data;
  bool calledCallBack = FALSE;
  CS1_CriticalVariable()


  for(i=(TRG_TriggerKind)0;i<TRG_NOF_TRIGGERS;i++) {
	  CS1_EnterCritical();
    if (TRG_Triggers[i].ticks==0 && TRG_Triggers[i].callback != NULL) { /* trigger! */
      callback = TRG_Triggers[i].callback; /* get a copy */
      data = TRG_Triggers[i].data; /* get backup of data, as we overwrite it below */
      /* reset trigger structure, as callback might setup this trigger again */
      TRG_Triggers[i].callback = NULL; /* NULL callback prevents that we are called again */
      CS1_ExitCritical();
      callback(data);
      calledCallBack = TRUE; /* callback may have set a trigger at the current time: rescan trigger list */
    } else {
      CS1_ExitCritical();
    }
  } /* for */

  return calledCallBack;
}
Ejemplo n.º 4
0
void setPlayback(void) {
	CS1_CriticalVariable()
	;
	CS1_EnterCritical()
	;
	playback = TRUE;
	CS1_ExitCritical()
	;
}
Ejemplo n.º 5
0
void clearPlayback(void) {
	CS1_CriticalVariable()
	;
	CS1_EnterCritical()
	;
	playback = FALSE;
	CS1_ExitCritical()
	;
}
Ejemplo n.º 6
0
bool EVNT_EventIsSetAutoClear(EVNT_Handle event) {
	bool res;
	CS1_EnterCritical();
	res = GET_EVENT(event);
	if (res) {
		CLR_EVENT(event); /* automatically clear event */
	}
	CS1_ExitCritical();
	return res;
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
bool PlaybackIsSet(void) {
	bool tmp;
	CS1_CriticalVariable()
	;
	CS1_EnterCritical()
	;
	tmp = playback;
	CS1_ExitCritical()
	;
	return tmp;
}
Ejemplo n.º 9
0
/*
** ===================================================================
**     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();
}
Ejemplo n.º 10
0
/*
** ===================================================================
**     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;
}
Ejemplo n.º 11
0
/*
** ===================================================================
**     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();
}
Ejemplo n.º 12
0
/*
** ===================================================================
**     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;
}
Ejemplo n.º 13
0
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 */
}
Ejemplo n.º 14
0
/*
** ===================================================================
**     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.
      */
   }
}
Ejemplo n.º 16
0
/*
** ===================================================================
**     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;
}
Ejemplo n.º 17
0
bool EVNT_EventIsSet(EVNT_Handle event) {
	CS1_EnterCritical();
	bool tmp = GET_EVENT(event);
	CS1_ExitCritical();
	return tmp;
}