Exemplo n.º 1
0
Arquivo: mbox.c Projeto: XNerv/brtos
uint8_t OSMboxDelete (BRTOS_Mbox **event)
{
  OS_SR_SAVE_VAR
  BRTOS_Mbox *pont_event;

  if (iNesting > 0) {                                // See if caller is an interrupt
      return(IRQ_PEND_ERR);                          // Can't be delete by interrupt
  }
    
  // Enter Critical Section
  OSEnterCritical();
  
  pont_event = *event;
  pont_event->OSEventAllocated   = 0;
  pont_event->OSEventPointer     = NULL;
  pont_event->OSEventWait        = 0;
  pont_event->OSEventState       = NO_MESSAGE;
  
  pont_event->OSEventWaitList=0;
  
  *event = NULL;
  
  // Exit Critical Section
  OSExitCritical();
  
  return(DELETE_EVENT_OK);
}
Exemplo n.º 2
0
static void BRTOS_TimerTaskSleep(TIMER_CNT next_time_to_wake)
{
  
  OS_SR_SAVE_VAR
  
  ContextType *Task = (ContextType*)&ContextTask[currentTask];      
  
  Task->TimeToWait = next_time_to_wake;
  
  OSEnterCritical();
  
  // Put task into delay list
  IncludeTaskIntoDelayList();
  
  #if (VERBOSE == 1)
    Task->State = SUSPENDED;
    Task->SuspendedType = DELAY;
  #endif
  
  OSReadyList = OSReadyList & ~(PriorityMask[Task->Priority]);
  
  // Change context
  // Return to task when occur delay overflow
  ChangeContext();
  
  OSExitCritical();
    
}
Exemplo n.º 3
0
INT8U OSMutexDelete (BRTOS_Mutex **event)
{
  OS_SR_SAVE_VAR
  BRTOS_Mutex *pont_event;

  if (iNesting > 0) {                                // See if caller is an interrupt
      return(IRQ_PEND_ERR);                          // Can't be delete by interrupt
  }
    
  // Enter Critical Section
  OSEnterCritical();
  
  pont_event = *event;  
  pont_event->OSEventAllocated   = 0;
  pont_event->OSEventState       = 0;
  pont_event->OSEventOwner       = 0;                        
  pont_event->OSMaxPriority      = 0;                      
  pont_event->OSOriginalPriority = 0;                
  pont_event->OSEventWait        = 0;  
  
  pont_event->OSEventWaitList=0;
  
  *event = NULL;
  
  // Exit Critical Section
  OSExitCritical();
  
  return(DELETE_EVENT_OK);
}
Exemplo n.º 4
0
INT8U OSMboxCreate (BRTOS_Mbox **event, void *message)
{
  OS_SR_SAVE_VAR
  INT16S i = 0;  
  BRTOS_Mbox *pont_event;

  if (iNesting > 0) {                                // See if caller is an interrupt
      return(IRQ_PEND_ERR);                          // Can't be create by interrupt
  }
    
  // Enter critical Section
  if (currentTask)
     OSEnterCritical();
  
  // Verifica se ainda há blocos de controle de eventos disponíveis
  for(i=0;i<=BRTOS_MAX_MBOX;i++)
  {
    
    if(i >= BRTOS_MAX_MBOX)
    {
      // Caso não haja mais blocos disponíveis, retorna exceção
      
      // Exit critical Section
      if (currentTask)
         OSExitCritical();      
      
      return(NO_AVAILABLE_EVENT);
    }
          
    
    if(BRTOS_Mbox_Table[i].OSEventAllocated != TRUE)
    {
      BRTOS_Mbox_Table[i].OSEventAllocated = TRUE;
      pont_event = &BRTOS_Mbox_Table[i];
      break;      
    }
  }    
    
  if (message != NULL)
  {
    pont_event->OSEventState = AVAILABLE_MESSAGE;
  }
  else
  {
    pont_event->OSEventState = NO_MESSAGE;
  }
  
  pont_event->OSEventPointer   = message;
  pont_event->OSEventWait      = 0;  
  pont_event->OSEventWaitList=0;
  
  
  *event = pont_event;
  
  // Exit critical Section
  if (currentTask)
     OSExitCritical();  
  
  return(ALLOC_EVENT_OK);
}
Exemplo n.º 5
0
Arquivo: BRTOS.c Projeto: brtos/brtos
uint8_t OSBlockPriority(uint8_t iPriority)
{
  OS_SR_SAVE_VAR
  uint8_t BlockedTask = 0;
  
  if (iNesting > 0) {                                // See if caller is an interrupt
     return(IRQ_PEND_ERR);                           // Can't be blocked by interrupt
  }
      
  // Enter critical Section
  if (currentTask)  
    OSEnterCritical();


  // Detects the task priority
  BlockedTask = PriorityVector[iPriority];  
  // Block task with priority iPriority
  #if (VERBOSE == 1)
  ContextTask[BlockedTask].Blocked = TRUE;
  #endif
  
  OSBlockedList = OSBlockedList & ~(PriorityMask[iPriority]);
   
  
  if (currentTask == BlockedTask)
  {
     ChangeContext();
  }

  // Exit critical Section
  if (currentTask)
    OSExitCritical();
  
  return OK;
}
Exemplo n.º 6
0
/**
  \fn TIMER_CNT BRTOS_TimerGet (BRTOS_TIMER p)
  \brief public function to get remaining time of a soft timer
  \param p  soft timer
  \return timeout value or "0" as error code
*/
TIMER_CNT OSTimerGet (BRTOS_TIMER p)
{
     
     OS_SR_SAVE_VAR
     TIMER_CNT timeout;
     TIMER_CNT tickcount;
     
     if((p!= NULL) && (p->state == TIMER_RUNNING))
     {
     
        if (currentTask)
            OSEnterCritical();                      
             
            tickcount =  OSGetCount();  
            if(p->timeout >= tickcount)
            {                
                timeout = (TIMER_CNT)(p->timeout - tickcount);                   
            }
            else
            {
                timeout =  (TIMER_CNT)(TIMER_MAX_COUNTER - tickcount +  p->timeout + 1); 
            }  
                          
        if (currentTask)               
            OSExitCritical(); 
        
        return timeout;
      } 
      return 0;  /* "0" null event pointer or timer not running */
    
}
Exemplo n.º 7
0
INT8U OSSemDelete (BRTOS_Sem **event)
{
  OS_SR_SAVE_VAR
  BRTOS_Sem *pont_event;

  if (iNesting > 0) {                                // See if caller is an interrupt
      return(IRQ_PEND_ERR);                          // Can't be delete by interrupt
  }
    
  // Enter Critical Section
  OSEnterCritical();
  
  pont_event = *event;  
  pont_event->OSEventAllocated = 0;
  pont_event->OSEventCount     = 0;                      
  pont_event->OSEventWait      = 0;
  
  pont_event->OSEventWaitList=0;
  
  *event = NULL;
  
  // Exit Critical Section
  OSExitCritical();
  
  return(DELETE_EVENT_OK);
}
Exemplo n.º 8
0
INT8U OSSemBinaryCreate (INT8U bit, BRTOS_Sem **event)
{
  OS_SR_SAVE_VAR
  int i=0;

  BRTOS_Sem *pont_event;

  if (iNesting > 0) {                                // See if caller is an interrupt
     return(IRQ_PEND_ERR);                           // Can't be create by interrupt
  }

  // Enter critical Section
  if (currentTask)
     OSEnterCritical();

  // Verifica se ainda há blocos de controle de eventos disponíveis
  for(i=0;i<=BRTOS_MAX_SEM;i++)
  {

    if(i >= BRTOS_MAX_SEM)
    {
      // Caso não haja mais blocos disponíveis, retorna exceção

      // Exit critical Section
      if (currentTask)
         OSExitCritical();

      return(NO_AVAILABLE_EVENT);
    }


    if(BRTOS_Sem_Table[i].OSEventAllocated != TRUE)
    {
      BRTOS_Sem_Table[i].OSEventAllocated = TRUE;
      pont_event = &BRTOS_Sem_Table[i];
      break;
    }
  }
  
  // Exit Critical
  if (bit > 1)
  {
	  pont_event->OSEventCount = TRUE;                      // Set semaphore bit value
  }else
  {
	  pont_event->OSEventCount = FALSE;                      // Set semaphore bit value
  }
  pont_event->OSEventWait  = 0;
  pont_event->Binary = TRUE;
  pont_event->OSEventWaitList=0;
  
  *event = pont_event;
  
  // Exit critical Section
  if (currentTask)
     OSExitCritical();
  
  return(ALLOC_EVENT_OK);
}
Exemplo n.º 9
0
/*
  This optional function does a "fast" critical region protection and returns
  the previous protection level. This function is only called during very short
  critical regions. An embedded system which supports ISR-based drivers might
  want to implement this function by disabling interrupts. Task-based systems
  might want to implement this by using a mutex or disabling tasking. This
  function should support recursive calls from the same task or interrupt. In
  other words, sys_arch_protect() could be called while already protected. In
  that case the return value indicates that it is already protected.

  sys_arch_protect() is only required if your port is supporting an operating
  system.
*/
sys_prot_t sys_arch_protect(void)
{
	OS_SR_SAVE_VAR
    
	// Enter Critical Section
    OSEnterCritical();
	return CPU_SR;
}
Exemplo n.º 10
0
/******************************************************************************
 *
 *    @name       Virtual_Com_App
 *
 *    @brief      Implements Loopback COM Port
 *
 *    @param      None
 *
 *    @return     None
 *
 *****************************************************************************
 * Receives data from USB Host and transmits back to the Host
 *****************************************************************************/
void cdc_process(void)
{
    static uint_8 status 	 = 0;
    uint_8 		  sem_status = 0;
	uint_8 size;
	OS_SR_SAVE_VAR;

	size = g_send_size;
	g_send_size = 0;

    /*check whether enumeration is complete or not */
     if((start_app==TRUE) && (start_transactions==TRUE))
     {	
		
		OSEnterCritical();
			is_message_sent = 1;
		OSExitCritical();
		
		status = USB_Class_CDC_Interface_DIC_Send_Data(CONTROLLER_ID, g_curr_send_buf,size);
		sem_status = OSSemPend(USB_Sem,500);	   
		
		if (sem_status != OK)
		{
			OSEnterCritical();
				is_message_sent = 0;
			OSExitCritical();
		}
		
        if(status != USB_OK)
        {
            /* Send Data Error Handling Code goes here */
        	status = 0;
        }		
     }
#if 0     
     else
     {
    	  while(GetStart_transactions() == FALSE)
    	  {
    		  DelayTask(100);
    	  }
     }
#endif     


}
Exemplo n.º 11
0
INT8U OSTimerStop (BRTOS_TIMER p, INT8U del){
  
  OS_SR_SAVE_VAR
  BRTOS_TMR_T* list;
  INT8U pos_timer = 0;
  
  if(p != NULL)
  {
  
      if (currentTask)
          OSEnterCritical();
     
        
        if(p->timeout >= OSGetCount())
        {                
           list = BRTOS_TIMER_VECTOR.current;  // remove from current list   
        }
        else
        {
           list = BRTOS_TIMER_VECTOR.future;   // remove from future list
        }  
        
        /* search timer index */
        p->state = TIMER_SEARCH;
        for(pos_timer = 1; pos_timer <= list->count; pos_timer++)
        {
        	if(list->timers[pos_timer]->state == TIMER_SEARCH)
        	{
        		break;
        	}
        }
        
        p->timeout = 0;
        Subir (list->timers, pos_timer); // order it 
        list->timers[1]=list->timers[list->count]; // remove from current list
        list->timers[list->count] = NULL;
        list->count--; 
        Descer (list->timers, 1, list->count); // order it
        
        if(del > 0)
        {                     
          p->state = TIMER_NOT_ALLOCATED; 
          p->func_cb = NULL; 
        }
        else
        {
          p->state = TIMER_STOPPED; 
        }
         
      if (currentTask)               
          OSExitCritical();
      
      return OK;
  }
  return NULL_EVENT_POINTER;
}
Exemplo n.º 12
0
Arquivo: BRTOS.c Projeto: brtos/brtos
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/////      Get the current task handle                 /////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
BRTOS_TH OSGetCurrentTaskHandle(void)
{
	OS_SR_SAVE_VAR
	BRTOS_TH task_handle;

  	OSEnterCritical();
	task_handle = (BRTOS_TH)currentTask;
  	OSExitCritical();
	return task_handle;
}
Exemplo n.º 13
0
Arquivo: BRTOS.c Projeto: brtos/brtos
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/////      Get task priority               			   /////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
OS_CPU_TYPE OSGetTaskPriority(BRTOS_TH task_handle)
{
	OS_SR_SAVE_VAR
	OS_CPU_TYPE task_prio;

  	OSEnterCritical();
	task_prio = (OS_CPU_TYPE)ContextTask[task_handle].Priority;
  	OSExitCritical();
	return task_prio;
}
Exemplo n.º 14
0
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/////      Get the current tick count                  /////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
INT16U OSGetTickCount(void) 
{
  OS_SR_SAVE_VAR
  INT16U cnt;
  
  OSEnterCritical();
  cnt = OSTickCounter;
  OSExitCritical();
  return cnt;
}
Exemplo n.º 15
0
Arquivo: BRTOS.c Projeto: brtos/brtos
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/////      Get the current tick count                  /////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
ostick_t OSGetTickCount(void)
{
  OS_SR_SAVE_VAR
  ostick_t cnt;
  
  OSEnterCritical();
  cnt = OSTickCounter;
  OSExitCritical();
  return cnt;
}
Exemplo n.º 16
0
/**
  \fn INT8U BRTOS_TimerStart (BRTOS_TIMER p, TIMER_CNT time_wait)
  \brief public function to start or restart a soft timer
  \param p  soft timer
  \param time_wait soft timer expiration time
  \return OK success
  \return NULL_EVENT_POINTER error code
*/
INT8U OSTimerStart (BRTOS_TIMER p, TIMER_CNT time_wait){
 
  OS_SR_SAVE_VAR
  INT32U timeout;
  BRTOS_TMR_T* list;
  
  if(p!= NULL && time_wait != 0)
  {
      
      if(time_wait> TIMER_MAX_COUNTER) time_wait = TIMER_MAX_COUNTER;
      
      if (currentTask)
          OSEnterCritical();      
        
      if(time_wait > 0)
      {      
    
        timeout = (INT32U)((INT32U)OSGetCount() + (INT32U)time_wait);
        
        if (timeout >= TICK_COUNT_OVERFLOW)
        {
          p->timeout = (TIMER_CNT)(timeout - TICK_COUNT_OVERFLOW);
          list = BRTOS_TIMER_VECTOR.future;   // add into future list
          list->timers[++list->count] = p; // insert in the end                            
          Subir (list->timers, list->count); // order it 
        }
        else
        {
          p->timeout = (TIMER_CNT)timeout;
          list = BRTOS_TIMER_VECTOR.current;  // add into current list
          list->timers[++list->count] = p; // insert in the end                            
          Subir (list->timers, list->count); // order it 
          
          // may need to change wake time of timer task
          if(currentTask)
          {          
            if(p->timeout == (list->timers[1])->timeout)
            {
              ContextTask[BRTOS_TIMER_VECTOR.handling_task].TimeToWait = p->timeout;
            }
          }
                           
        }      
                
        p->state = TIMER_RUNNING;     
                                              
      }                                       
             
      if (currentTask)               
          OSExitCritical();  
      
      return OK;
  } 
  return NULL_EVENT_POINTER; /* any error number */
}
Exemplo n.º 17
0
void OS_TICK_HANDLER(void)
{
  OS_SR_SAVE_VAR
  INT8U  iPrio = 0;  
  ContextType *Task = Head;  
   
  ////////////////////////////////////////////////////
  // Put task with delay overflow in the ready list //
  ////////////////////////////////////////////////////  
  while(Task != NULL)
  {      
      if (Task->TimeToWait == counter)
      {

        iPrio = Task->Priority;
        
        #if (NESTING_INT == 1)
        OSEnterCritical();
        #endif        

        // Put the task into the ready list
        OSReadyList = OSReadyList | (PriorityMask[iPrio]);
        
        #if (VERBOSE == 1)
            Task->State = READY;        
        #endif
        
        Task->TimeToWait = EXIT_BY_TIMEOUT;
        
        #if (NESTING_INT == 1)
        OSExitCritical();
        #endif                  
          
        // Remove from delay list
        RemoveFromDelayList();
      }
 
      Task = Task->Next;
  }

  //////////////////////////////////////////
  // System Load                          //
  //////////////////////////////////////////
  
  #if (COMPUTES_CPU_LOAD == 1)
  #if(DEBUG == 1)
     if (DutyCnt >= 1024)
     {
       DutyCnt = 0;
       OSDuty = (INT32U)((INT32U)OSDuty + (INT32U)OSDutyTmp);
       LastOSDuty = (INT16U)(OSDuty >> 10);
       OSDuty = 0;
     }else
Exemplo n.º 18
0
void SetTxPower(INT8U power_level){
    
    OS_SR_SAVE_VAR;
    OSEnterCritical();
    
    currentTxPower = power_level;
         
    iNesting++;
      PHYSetLongRAMAddr(RFCTRL3,currentTxPower);
    iNesting--;
    
    OSExitCritical();
  
}
Exemplo n.º 19
0
Arquivo: BRTOS.c Projeto: brtos/brtos
uint8_t OSBlockTask(BRTOS_TH TaskHandle)
{
  OS_SR_SAVE_VAR
  uint8_t iPriority = 0;
  
  if (iNesting > 0) {                                // See if caller is an interrupt
     return(IRQ_PEND_ERR);                           // Can't be blocked by interrupt
  }
    
  // Enter critical Section
  if (currentTask)
    OSEnterCritical();

  // Checks whether the task is uninstalling itself
  if (!TaskHandle){
	  // If so, verify if the currentTask is valid
	  if (currentTask){
		  //If true, currentTask is the task being uninstall
		  TaskHandle = currentTask;
	  }else{
		  // If not, not valid task
		  // Exit Critical Section
		  OSExitCritical();

		  return NOT_VALID_TASK;
	  }
  }

  // Determina a prioridade da função
  #if (VERBOSE == 1)
  ContextTask[TaskHandle].Blocked = TRUE;
  #endif
  iPriority = ContextTask[TaskHandle].Priority;
  
  OSBlockedList = OSBlockedList & ~(PriorityMask[iPriority]);
  
  if (currentTask == TaskHandle)
  {
     ChangeContext();     
  }
  
  // Exit critical Section
  if (currentTask)
    OSExitCritical();  

  return OK;
}
Exemplo n.º 20
0
/*
 * Returns the thread control block for the currently active task. In case
 * of an error the functions returns NULL.
 */
sys_tcb_t
*sys_arch_thread_current( void )
{
	OS_SR_SAVE_VAR
	sys_tcb_t      *p = tasks;
	sys_thread_t   pid = xTaskGetCurrentTaskHandle();

    // Enter Critical Section
    OSEnterCritical();
    while( ( p != NULL ) && ( p->pid != pid ) )
    {
        p = p->next;
    }
    // Exit Critical Section
    OSExitCritical();
    return p;
}
Exemplo n.º 21
0
Arquivo: BRTOS.c Projeto: brtos/brtos
uint8_t OSUnBlockMultipleTask(uint8_t TaskStart, uint8_t TaskNumber)
{
  OS_SR_SAVE_VAR
  uint8_t iTask = 0;
  uint8_t TaskFinish = 0;
  uint8_t iPriority = 0;    
  
  if (iNesting > 0) {                                // See if caller is an interrupt
     return(IRQ_PEND_ERR);                           // Can't be blocked by interrupt
  }
    
  // Enter critical Section
  if (currentTask)
    OSEnterCritical();
  
  TaskFinish = (uint8_t)(TaskStart + TaskNumber);
  
  for (iTask = TaskStart; iTask <TaskFinish; iTask++)
  {
    // Determina a prioridade da função
    if (iTask != currentTask)
    {
      iPriority = ContextTask[iTask].Priority;
      
      #if (VERBOSE == 1)
      ContextTask[iTask].Blocked = FALSE;
      #endif
      
      OSBlockedList = OSBlockedList | (PriorityMask[iPriority]);
    }
  }
  
  // check if we have unblocked a higher priority task  
  if (currentTask)
  {
    if (!iNesting)
    {
       ChangeContext();
    }
	// Exit critical Section
	OSExitCritical();
  } 

  return OK;
}
Exemplo n.º 22
0
sys_thread_t xTaskGetCurrentTaskHandle( void )
{
	OS_SR_SAVE_VAR
	sys_thread_t xReturn;

	/* A critical section is not required as this is not called from
	an interrupt and the current TCB will always be the same for any
	individual execution thread. */
	
    // Enter Critical Section
    OSEnterCritical();
    
	xReturn = &ContextTask[currentTask];
    
	// Exit Critical Section
    OSExitCritical();	

	return xReturn;
}
Exemplo n.º 23
0
/*********************************************************************
 * Function:        void PHYSetShortRAMAddr(BYTE address, BYTE value)
 *
 * PreCondition:    Communication port to the MRF24J40 initialized
 *
 * Input:           BYTE address is the address of the short RAM address
 *                      that you want to write to.  Should use the
 *                      WRITE_ThisAddress definition in the MRF24J40 
 *                      include file.
 *                  BYTE value is the value that you want to write to
 *                      that register
 *
 * Output:          None
 *
 * Side Effects:    The register value is changed
 *
 * Overview:        This function writes a value to a short RAM address
 ********************************************************************/
void PHYSetShortRAMAddr(INT8U address, INT8U value)
{
    INT8U data = 0;
    INT8U local_address = 0;
    OS_SR_SAVE_VAR;

    // Enter Critical Section
    OSEnterCritical();
    
    data = value;
    local_address = address;    
    
    PHY_CS_LOW;
    SPI_SendChar(local_address);
    SPI_SendChar(data);
    PHY_CS_HIGH;
    
    // Exit Critical Section
    OSExitCritical();
}
Exemplo n.º 24
0
/*********************************************************************
 * Function:        void PHYSetLongRAMAddr(WORD address, BYTE value)
 *
 * PreCondition:    Communication port to the MRF24J40 initialized
 *
 * Input:           WORD address is the address of the LONG RAM address
 *                      that you want to write to
 *                  BYTE value is the value that you want to write to
 *                      that register
 *
 * Output:          None
 *
 * Side Effects:    The register value is changed
 *
 * Overview:        This function writes a value to a LONG RAM address
 ********************************************************************/
void PHYSetLongRAMAddr(INT16U address, INT8U value)
{
    INT8U data = 0;
    INT16U local_address = 0;
    OS_SR_SAVE_VAR;
    
    // Enter Critical Section
    OSEnterCritical();
    
    data = value;
    local_address = address;
    
    PHY_CS_LOW;
    SPI_SendChar((((INT8U)(local_address>>3))&0b01111111)|0x80);
    SPI_SendChar((((INT8U)(local_address<<5))&0b11100000)|0x10);
    SPI_SendChar(data);
    PHY_CS_HIGH;
    
    // Exit Critical Section
    OSExitCritical();
}
Exemplo n.º 25
0
Arquivo: BRTOS.c Projeto: brtos/brtos
uint8_t OSUnBlockPriority(uint8_t iPriority)
{
  OS_SR_SAVE_VAR
  #if (VERBOSE == 1)
  uint8_t BlockedTask = 0;
  #endif
  
  
  // Enter Critical Section
  #if (NESTING_INT == 0)
  if (!iNesting)
  #endif
     OSEnterCritical();
    
  // Detects the task priority
  #if (VERBOSE == 1)  
  BlockedTask = PriorityVector[iPriority];  
  ContextTask[BlockedTask].Blocked = FALSE;
  #endif
  
  OSBlockedList = OSBlockedList | (PriorityMask[iPriority]);
  
  // check if we have unblocked a higher priority task  
  if (currentTask)
  {
    if (!iNesting)
    {
       ChangeContext();
    }
  }
  
  // Exit Critical Section
  #if (NESTING_INT == 0)
  if (!iNesting)
  #endif
     OSExitCritical();

  return OK;
}
Exemplo n.º 26
0
Arquivo: BRTOS.c Projeto: brtos/brtos
uint8_t OSUnBlockTask(BRTOS_TH TaskHandle)
{
  OS_SR_SAVE_VAR
  uint8_t iPriority = 0;
  
  // Enter Critical Section
  #if (NESTING_INT == 0)
  if (!iNesting)
  #endif
     OSEnterCritical();

  #if (VERBOSE == 1)
  ContextTask[TaskHandle].Blocked = FALSE;
  #endif
  
  // Determina a prioridade da função  
  iPriority = ContextTask[TaskHandle].Priority;

  OSBlockedList = OSBlockedList | (PriorityMask[iPriority]);
  
  // check if we have unblocked a higher priority task  
  if (currentTask)
  {
    if (!iNesting)
    {
       ChangeContext();
    }
  }
  
  // Exit Critical Section
  #if (NESTING_INT == 0)
  if (!iNesting)
  #endif
     OSExitCritical();

  return OK;  
  
}
Exemplo n.º 27
0
/*********************************************************************
 * Function:        void PHYSetShortRAMAddr(BYTE address, BYTE value)
 *
 * PreCondition:    Communication port to the MRF24J40 initialized
 *
 * Input:           BYTE address is the address of the short RAM address
 *                      that you want to read from.  Should use the
 *                      READ_ThisAddress definition in the MRF24J40 
 *                      include file.
 *
 * Output:          BYTE the value read from the specified short register
 *
 * Side Effects:    None
 *
 * Overview:        This function reads a value from a short RAM address
 ********************************************************************/
INT8U PHYGetShortRAMAddr(INT8U address)
{
    INT8U local_address = 0;
    INT8U toReturn;
    OS_SR_SAVE_VAR;
    
    // Enter Critical Section
    OSEnterCritical();
    
    local_address = address;
    
    PHY_CS_LOW;
    SPI_SendChar(local_address);
    
    // Sai da condição crítica na função SPIGet
    toReturn = SPI_Get();   
    PHY_CS_HIGH;
    
    // Exit Critical Section
    OSExitCritical();
    
    return toReturn;
}
Exemplo n.º 28
0
/* private functions */
static void BRTOS_TimerTaskInit(void)
{
  
  OS_SR_SAVE_VAR 
  INT8U i; 
  
  if (currentTask)
    OSEnterCritical();
        
    BRTOS_TIMER_VECTOR.current = &BRTOS_TMR_PING;
    BRTOS_TIMER_VECTOR.future  = &BRTOS_TMR_PONG;
    
    for(i=0;i<BRTOS_MAX_TIMER;i++)
    {           
      BRTOS_TIMER_VECTOR.mem[i].state = TIMER_NOT_USED;
      BRTOS_TIMER_VECTOR.mem[i].func_cb = NULL;
      BRTOS_TIMER_VECTOR.mem[i].timeout = 0;  
    }  
    
  if (currentTask)
     OSExitCritical();

}
Exemplo n.º 29
0
Arquivo: BRTOS.c Projeto: brtos/brtos
uint8_t OSBlockMultipleTask(uint8_t TaskStart, uint8_t TaskNumber)
{
  OS_SR_SAVE_VAR
  uint8_t iTask = 0;
  uint8_t TaskFinish = 0;
  uint8_t iPriority = 0;  
  
  if (iNesting > 0) {                                // See if caller is an interrupt
     return(IRQ_PEND_ERR);                           // Can't be blocked by interrupt
  }
    
  // Enter critical Section
  if (currentTask)
    OSEnterCritical();
  
  TaskFinish = (uint8_t)(TaskStart + TaskNumber);
  
  for (iTask = TaskStart; iTask <TaskFinish; iTask++)
  {
    if (iTask != currentTask)
    {      
      #if (VERBOSE == 1)
      ContextTask[iTask].Blocked = TRUE;
      #endif
      // Determina a prioridade da função
      iPriority = ContextTask[iTask].Priority;   
      
      OSBlockedList = OSBlockedList & ~(PriorityMask[iPriority]);
    }
  }
  
  // Exit critical Section
  if (currentTask)
    OSExitCritical();

  return OK;
}
Exemplo n.º 30
0
/*********************************************************************
 * Function:        BYTE PHYGetLongRAMAddr(WORD address)
 *
 * PreCondition:    Communication port to the MRF24J40 initialized
 *
 * Input:           WORD address is the address of the long RAM address
 *                      that you want to read from.  
 *
 * Output:          BYTE the value read from the specified Long register
 *
 * Side Effects:    None
 *
 * Overview:        This function reads a value from a long RAM address
 ********************************************************************/
INT8U PHYGetLongRAMAddr(INT16U address)
{
    INT16U local_address = 0;
    INT8U toReturn = 0;
    OS_SR_SAVE_VAR;
    
    // Enter Critical Section
    OSEnterCritical();
    
    local_address = address;    
    
    PHY_CS_LOW;
    SPI_SendChar(((local_address>>3)&0b01111111)|0x80);
    SPI_SendChar(((local_address<<5)&0b11100000));
    
    // Sai da condição crítica na função SPIGet
    toReturn = SPI_Get();
    PHY_CS_HIGH;
    
    // Exit Critical Section
    OSExitCritical();

    return toReturn;
}