Beispiel #1
0
signed char DeallocateOneSecondTimer(tTimerId TimerId)
{
  signed char result = -1;

  if ( TimerId < 0 )
  {
    PrintString("Invalid Timer Id\r\n");
  }

  ENTER_CRITICAL_REGION_QUICK();

  if ( OneSecondTimers[TimerId].Allocated == 1 )
  {
    OneSecondTimers[TimerId].Allocated = 0;
    OneSecondTimers[TimerId].Running = 0;
    OneSecondTimers[TimerId].Expired = 0;
    result = TimerId;
  }

  LEAVE_CRITICAL_REGION_QUICK();

  if ( result < 0 )
  {
    PrintString("Unable to deallocate timer!\r\n");
  }

  return result;
}
static void RemoveUser(unsigned char User)
{
  ENTER_CRITICAL_REGION_QUICK();

  switch (User)
  {
  case 0: TA0CCTL0 = 0; break;
  case 1: TA0CCTL1 = 0; break;
  case 2: TA0CCTL2 = 0; break;
  case 3: TA0CCTL3 = 0; break;
  case 4: TA0CCTL4 = 0; break;
  default: break;
    
  }
  
  /* remove a user */
  Timer0Users &= ~(1 << User);
    
  /* disable timer if no one is using it */
  if ( Timer0Users == 0 )
  {
    TA0CTL = 0;  
  }
  
  LEAVE_CRITICAL_REGION_QUICK();
  
}
Beispiel #3
0
void Timer_Change(TimerHandle timer, TimerCallback callback, void *context)
{
	ENTER_CRITICAL_REGION_QUICK();
	((TIMER_ENTRY*)timer)->callback = callback;
	((TIMER_ENTRY*)timer)->context = context;
	LEAVE_CRITICAL_REGION_QUICK();
}
Beispiel #4
0
tTimerId AllocateOneSecondTimer(void)
{
  signed char result = -1;
  unsigned char i;

  ENTER_CRITICAL_REGION_QUICK();
  for(i = 0; i < TOTAL_ONE_SECOND_TIMERS; i++)
  {
    if ( OneSecondTimers[i].Allocated == 0 )
    {
      OneSecondTimers[i].Allocated = 1;
      result = i;
      break;
    }

  }

  LEAVE_CRITICAL_REGION_QUICK();

  if ( result < 0 )
  {
    PrintString("Unable to allocate Timer\r\n");
  }

  return result;
}
void SetDMAHandler(int channel, DMACallback callback)
{
	ENTER_CRITICAL_REGION_QUICK();
	if (callback == NULL)
		dmaCallbacks[channel] = DummyCallback;
	else
		dmaCallbacks[channel] = callback;
	LEAVE_CRITICAL_REGION_QUICK();
}
Beispiel #6
0
void StopOneSecondTimer(tTimerId TimerId)
{
  ENTER_CRITICAL_REGION_QUICK();

  OneSecondTimers[TimerId].Running = 0;
  OneSecondTimers[TimerId].Expired = 0;

  LEAVE_CRITICAL_REGION_QUICK();
}
void SetRTCPrescaleInterrupt(int enable)
{
	ENTER_CRITICAL_REGION_QUICK();
	if (enable)
		RTCPS0CTL |= RT0PSIE;
	else
		RTCPS0CTL &= ~RT0PSIE;
	LEAVE_CRITICAL_REGION_QUICK();
}
extern "C" void Battery_Unregister(Battery_Notify_Handle handle)
{
	if (handle == 0)
		return;
	ENTER_CRITICAL_REGION_QUICK();
	s_notifications[handle - 1].notify = 0;
	s_notifications[handle - 1].callback = NULL;
	s_notifications[handle - 1].context = NULL;
	LEAVE_CRITICAL_REGION_QUICK();
}
Beispiel #9
0
extern "C" void Adc_Request(Adc_Request_Type request, Adc_Callback callback, void *context)
{
	ENTER_CRITICAL_REGION_QUICK();
	requests[nextRequest].request = request;
	requests[nextRequest].callback = callback;
	requests[nextRequest].context = context;
	if (!requestActive)
		Launch(nextRequest);
	nextRequest++;
	if (nextRequest >= MAX_REQUESTS)
		nextRequest = 0;
	LEAVE_CRITICAL_REGION_QUICK();
}
static void WriteTxBuffer(signed char * const pBuf)
{
  unsigned char i = 0;
  unsigned char LocalCount = TxCount;
 
  /* if there isn't enough room in the buffer then characters are lost */
  while ( pBuf[i] != 0 && LocalCount < TX_BUFFER_SIZE )
  { 
    TxBuffer[WriteIndex] = pBuf[i++];
    IncrementWriteIndex();
    LocalCount++;
  }    

  /* keep a sticky bit for lost characters */
  if ( pBuf[i] != 0 )
  {
    gAppStats.DebugUartOverflow = 1;
  }
  
  /* 
   * update the count (which can be decremented in the ISR 
   * and start sending characters if the UART is currently idle 
  */
  if ( i > 0 )
  {
    ENTER_CRITICAL_REGION_QUICK();
    
    TxCount += i;
    
#if 0
    if ( TxCount > TX_BUFFER_SIZE )
    {
      while(1);  
    }
#endif
    
    if ( TxBusy == 0 )
    {
      EnableSmClkUser(BT_DEBUG_UART_USER);
      UCA3TXBUF = TxBuffer[ReadIndex];
      IncrementReadIndex();
      TxBusy = 1;
      TxCount--;  
    }
    
    LEAVE_CRITICAL_REGION_QUICK();
  }
}
Beispiel #11
0
void StartOneSecondTimer(tTimerId TimerId)
{
  if (  OneSecondTimers[TimerId].Allocated == 0 ||
        OneSecondTimers[TimerId].CallbackMsgType == InvalidMessage )
  {
    PrintString("Cannot start timer with invalid parameters\r\n");
    return;
  }

  ENTER_CRITICAL_REGION_QUICK();

  OneSecondTimers[TimerId].Running = 1;
  OneSecondTimers[TimerId].Expired = 0;
  OneSecondTimers[TimerId].DownCounter = OneSecondTimers[TimerId].Timeout;

  LEAVE_CRITICAL_REGION_QUICK();
}
Beispiel #12
0
void Timer_Reset(TimerHandle timer, TimerLength delay, int repeats)
{
	unsigned long muldiv = delay;
	muldiv *= RTC_TICKS_PER_SECOND;
	muldiv /= 1000;
	ENTER_CRITICAL_REGION_QUICK();
	((TIMER_ENTRY*)timer)->delay = muldiv;
	if (repeats)
		((TIMER_ENTRY*)timer)->flags |= TIMER_REPEATS;
	else
		((TIMER_ENTRY*)timer)->flags &= ~TIMER_REPEATS;
	((TIMER_ENTRY*)timer)->current = ((TIMER_ENTRY*)timer)->delay;
	if (((TIMER_ENTRY*)timer)->current > 0)
	{
		((TIMER_ENTRY*)timer)->flags |= TIMER_ACTIVE;
		if (((TIMER_ENTRY*)timer)->current < RTC_TICKS_PER_SECOND)
			SetRTCPrescaleInterrupt(1);
	}
	LEAVE_CRITICAL_REGION_QUICK();
}
Beispiel #13
0
/* setup a timer so the Restart timer function can be used */
void SetupOneSecondTimer(tTimerId TimerId,
                         unsigned int Timeout,
                         unsigned char RepeatCount,
                         eMessageType CallbackMsgType,
                         unsigned char MsgOptions)
{

  if (   OneSecondTimers[TimerId].Allocated == 0
      || TimerId < 0 )
  {
    PrintString("Timer not Allocated\r\n");
    return;
  }

  ENTER_CRITICAL_REGION_QUICK();

  OneSecondTimers[TimerId].RepeatCount = RepeatCount;
  OneSecondTimers[TimerId].Timeout = Timeout;
  OneSecondTimers[TimerId].CallbackMsgType = CallbackMsgType;
  OneSecondTimers[TimerId].CallbackMsgOptions = MsgOptions;

  LEAVE_CRITICAL_REGION_QUICK();
}
extern "C" Battery_Notify_Handle Battery_Register(Battery_Callback callback, unsigned int notify, void *context)
{
	if (notify == 0)
		return 0;
	Battery_Notify_Handle result = 0;
	ENTER_CRITICAL_REGION_QUICK();
	for (int i = 0; i < BATTERY_MAX_NOTIFY; i++)
	{
		if (s_notifications[i].notify == 0)
		{
			result = i + 1;
			break;
		}
	}
	if (result != 0)
	{
		s_notifications[result - 1].notify = notify;
		s_notifications[result - 1].callback = callback;
		s_notifications[result - 1].context = context;
	}
	LEAVE_CRITICAL_REGION_QUICK();
	return result;
}
Beispiel #15
0
TimerHandle Timer_Create(TimerCallback callback, void *context, TimerLength delay, int repeats)
{
	int i;
	TIMER_ENTRY *entry;

	entry = NULL;
	ENTER_CRITICAL_REGION_QUICK();
	for (i = 0; i < MAX_TIMERS; i++)
	{
		if (!(Timer_List[i].flags & TIMER_ALLOCATED))
		{
			entry = Timer_List + i;
			break;
		}
	}
	if (entry != NULL)
	{
		entry->flags |= TIMER_ALLOCATED;
		Timer_Change((TimerHandle*)entry, callback, context);
		Timer_Reset((TimerHandle*)entry, delay, repeats);
	}
	LEAVE_CRITICAL_REGION_QUICK();
	return entry;
}
static void AddUser(unsigned char User,unsigned int CrystalTicks)
{
  ENTER_CRITICAL_REGION_QUICK();
  
  /* minimum value of 1 tick */
  if ( CrystalTicks < 1 )
  {
    CrystalTicks = 1;
  }  
  
  unsigned int CaptureTime = TA0R + CrystalTicks;

  /* clear ifg, add to ccr register, enable interrupt */
  switch (User)
  {
  case 0: TA0CCTL0 = 0; TA0CCR0 = CaptureTime; TA0CCTL0 = CCIE; break;
  case 1: TA0CCTL1 = 0; TA0CCR1 = CaptureTime; TA0CCTL1 = CCIE; break;
  case 2: TA0CCTL2 = 0; TA0CCR2 = CaptureTime; TA0CCTL2 = CCIE; break;
  case 3: TA0CCTL3 = 0; TA0CCR3 = CaptureTime; TA0CCTL3 = CCIE; break;
  case 4: TA0CCTL4 = 0; TA0CCR4 = CaptureTime; TA0CCTL4 = CCIE; break;
  default: break;
    
  }
  
  /* start counting up in continuous mode if not already doing so */
  if ( Timer0Users == 0 )
  {
    TA0CTL |= TASSEL_1 | MC_2 | ID_2; 
  }
  
  /* keep track of users */
  Timer0Users |= (1 << User);
  
  LEAVE_CRITICAL_REGION_QUICK();
  
}
Beispiel #17
0
void Timer_Destroy(TimerHandle timer)
{
	ENTER_CRITICAL_REGION_QUICK();
	((TIMER_ENTRY*)timer)->flags = 0;
	LEAVE_CRITICAL_REGION_QUICK();
}