Exemplo n.º 1
0
Arquivo: sched.c Projeto: iplusu/sarp
/*
 * GALSC_run_next_task()
 *
 * Remove the task at the head of the queue and execute it, freeing
 * the queue entry. Return 1 if a task was executed, 0 if the queue
 * is empty.
 *
 */
bool GALSC_run_next_task () {
    __nesc_atomic_t fInterruptFlags;
    void (*func)(void);

    // If there is an event in the GALSC queue, trigger the port
    // associated with the event (activate the task).  Otherwise, run
    // any queued TOS tasks.
    if (GALSC_eventqueue_count > 0) {
        // If there are any buffered TinyGUYS, update them now.
        if (GALSC_params_buffer_flag) {
            fInterruptFlags = __nesc_atomic_start();
            GALSC_copy_params();
            __nesc_atomic_end(fInterruptFlags);            
        }

        fInterruptFlags = __nesc_atomic_start();
        func = GALSC_eventqueue[GALSC_eventqueue_head].tp;
        GALSC_eventqueue[GALSC_eventqueue_head].tp = 0;
        GALSC_eventqueue_head = ((GALSC_eventqueue_head + 1) >= GALSC_EVENTQUEUE_SIZE) ? 0 : GALSC_eventqueue_head + 1;
        GALSC_eventqueue_count--;
        __nesc_atomic_end(fInterruptFlags);
        
        func(); // Called function will remove tokens from port queues.
        return 1;
    } else {
        return TOSH_run_next_task();
    }
}
Exemplo n.º 2
0
bool TOSH_run_next_task ()
{
  __nesc_atomic_t fInterruptFlags;
  uint8_t old_full;
  void (*func)(void);
  
  fInterruptFlags = __nesc_atomic_start();
  old_full = TOSH_sched_full;
  func = TOSH_queue[old_full].tp;
  if (func == NULL)
    {
      __nesc_atomic_sleep();
      return 0;
    }

#ifdef TASK_QUEUE_DEBUG
  occupancy--;
#endif
  TOSH_queue[old_full].tp = NULL;
  TOSH_sched_full = (old_full + 1) & TOSH_TASK_BITMASK;
  TOSH_queue[old_full].executeTime = OSCR0;
  __nesc_atomic_end(fInterruptFlags);
  func();
  TOSH_queue[old_full].executeTime = OSCR0 - TOSH_queue[old_full].executeTime;
  
  return 1;
}
Exemplo n.º 3
0
void TOSH_reset_debug_counters() {
  __nesc_atomic_t fInterruptFlags;
#ifdef TASK_QUEUE_DEBUG
  fInterruptFlags = __nesc_atomic_start();
  max_occupancy = 0;
   __nesc_atomic_end(fInterruptFlags);
#endif
}
Exemplo n.º 4
0
bool TOSH_run_next_task ()
{
  __nesc_atomic_t fInterruptFlags;
  uint8_t old_full;
  void (*func)(void);
  
  fInterruptFlags = __nesc_atomic_start();
  old_full = TOSH_sched_full;
  func = TOSH_queue[old_full].tp;
  if (func == NULL)
    {
      __nesc_atomic_end(fInterruptFlags);
      return 0;
    }

  TOSH_queue[old_full].tp = NULL;
  TOSH_sched_full = (old_full + 1) & TOSH_TASK_BITMASK;
  __nesc_atomic_end(fInterruptFlags);
  func();

  return 1;
}
Exemplo n.º 5
0
//#line 31
//# 59 "/opt/tinyos-2.x-contrib/diku/common/lib/ReverseGPIOP.nc"
static  /*inline*/  void /*PlatformLedsC.Led0_rev*/ReverseGPIOP__0__Out__toggle(void )
//#line 59
{
//#line 59
  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 59
    {
//#line 59
      /*PlatformLedsC.Led0_rev*/ReverseGPIOP__0__In__toggle();
    }
//#line 60
    __nesc_atomic_end(__nesc_atomic); }
}
Exemplo n.º 6
0
//#line 159
static  /*inline*/  error_t SchedulerBasicP__TaskBasic__postTask(uint8_t id)
{
  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 161
    {
//#line 161
      {
        unsigned char __nesc_temp = 
//#line 161
        SchedulerBasicP__pushTask(id) ? SUCCESS : EBUSY;

        {
//#line 161
          __nesc_atomic_end(__nesc_atomic); 
//#line 161
          return __nesc_temp;
        }
      }
    }
//#line 164
    __nesc_atomic_end(__nesc_atomic); }
}
Exemplo n.º 7
0
//#line 53
//# 52 "/opt/tinyos-2.x/tos/system/RealMainP.nc"
  int main(void )
//#line 52
{
  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
    {





      {
      }
//#line 60
      ;

      RealMainP__Scheduler__init();





      RealMainP__PlatformInit__init();
      while (RealMainP__Scheduler__runNextTask()) ;





      RealMainP__SoftwareInit__init();
      while (RealMainP__Scheduler__runNextTask()) ;
    }
//#line 77
    __nesc_atomic_end(__nesc_atomic); }


  __nesc_enable_interrupt();

  RealMainP__Boot__booted();


  RealMainP__Scheduler__taskLoop();




  return -1;
}
Exemplo n.º 8
0
//#line 138
static  /*inline*/  void SchedulerBasicP__Scheduler__taskLoop(void )
{
  for (; ; ) 
    {
      uint8_t nextTask;

      { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
        {
          while ((nextTask = SchedulerBasicP__popTask()) == SchedulerBasicP__NO_TASK) 
            {
              SchedulerBasicP__McuSleep__sleep();
            }
        }
//#line 150
        __nesc_atomic_end(__nesc_atomic); }
      SchedulerBasicP__TaskBasic__runTask(nextTask);
    }
}
Exemplo n.º 9
0
Arquivo: sched.c Projeto: iplusu/sarp
bool TOSH_run_next_task () {
  __nesc_atomic_t fInterruptFlags;
  uint8_t old_full;
  void (*func)(void);
  
  if (TOSH_sched_full == TOSH_sched_free) {
    //  dbg(DBG_SCHED, "TOSH_schedule_task: %d empty \n", TOSH_sched_full);
    return 0;
  }
  else {

    fInterruptFlags = __nesc_atomic_start();
    old_full = TOSH_sched_full;
    TOSH_sched_full++;
    TOSH_sched_full &= TOSH_TASK_BITMASK;
    func = TOSH_queue[(int)old_full].tp;
    TOSH_queue[(int)old_full].tp = 0;
    __nesc_atomic_end(fInterruptFlags);
    func();
    return 1;
  }
}
Exemplo n.º 10
0
/**
 * BootLoader_State_Machine
 *
 * The state machine for the boot loader which performs certain tasks
 * based on the current state of the boot loader. The current state must
 * be changed appropriately before calling this fuction.
 *
 */
void BootLoader_State_Machine ()
{
  switch (CurrentState)
  {
    case NORMAL:
      /*FIXME Move the code from main and post the state machine*/
    break;
    case CPY_TO_BOOT:
    {
      uint8_t buffer [61];
      Read_Attribute_Value(BL_ATTR_TYP_PRIMARY_IMG_LOCATION, &GImgAddr);
      Read_Attribute_Value(BL_ATTR_TYP_PRIMARY_IMG_CRC, &GImgCrc);
      Read_Attribute_Value(BL_ATTR_TYP_PRIMARY_IMG_SIZE, &GImgSize);
      __nesc_atomic_t atomic = __nesc_atomic_start();
      if (Move_Image_To_Boot_Loc (CurrImageAddr, CurrImageSize) == FAIL)
        Reboot_Device (); 
      __nesc_atomic_end (atomic);

      TOGGLE_LED (YELLOW);

      if(Change_BootLoader_State_Attribute (SET_LOADED_TO_GOLDEN) == SUCCESS)
      {
        sprintf (buffer, "Successfully copied image to boot location.\n");
        Send_USB_Command_Packet (CMD_BOOTLOADER_MSG, 61, buffer);
        TOS_post (&BootLoader_State_Machine);
      }
      else
      {
        /**
         * If we cant switch state then its hard to determine the problem
         * So let reboot and try to recover.
         */
        sprintf (buffer, "Could not switch to SET_LOADED_TO_GOLDEN. Rebooting\n");
        Send_USB_Error_Packet (ERR_FATAL_ERROR_ABORT, 60, buffer);	   
        Reboot_Device ();
      }
    }
    break;
    case SET_LOADED_TO_GOLDEN:
    {
      uint8_t buffer [61];
      result_t ret = SUCCESS;
      /*It may not be required, but still we dont want an interrupt to stop us*/
      TOGGLE_LED (GREEN);
      __nesc_atomic_t atomic = __nesc_atomic_start();
        ret = Map_Loaded_To_Golden ();
      __nesc_atomic_end (atomic);
      TOGGLE_LED (GREEN);
      if (ret == SUCCESS)
      {
        sprintf (buffer, "Mapped Boot Image to golden. Booting New Image.\n");
        Send_USB_Command_Packet (CMD_CREATED_GOLDEN_IMG, 61, buffer);
        Reboot_Device ();
      }
      else
      {
        /* Very Bad, We dont know exactly where we failed. I Guess the
         * best way is reset the whole primary to secondary switch and
         * reboot.
         */
        sprintf (buffer, "Mark loaded to golden failed. Trying to recover\n");
        Send_USB_Error_Packet (ERR_FATAL_ERROR_ABORT, 60, buffer);
        Reboot_Device ();
      }
    }
    break;
    case SET_BOOT_TO_GOLDEN:
    {
      Change_BootLoader_State_Attribute (NORMAL);
      Reboot_Device ();
    }
    break;
    case BOOT_IMAGE:
    break;
    case CODE_LOAD:
      switch (CLoaderState)
      {
        case REQUEST_IMAGE_DETAIL:
        {
          USBCommand cmd;
          if (!MMU_ENABLED)
          {
            MMU_ENABLED = TRUE;
      	    Enable_MMU ();
          }
          cmd.type = CMD_GET_IMAGE_DETAILS;
          Send_Command_Packet (&cmd, sizeof (USBCommand));
        }
        break;
        case REQUEST_USB_PACKETS:
#ifdef MMU_ENABLE
          Request_Next_Binary_Chunk ();
#else
          Request_Next_Binary_Packet ();
#endif
          break;
        case VERIFY_CURRENT_BUFFER:
          break;
        case VERIFY_CURRENT_IMAGE:
          Send_USB_Command_Packet (CMD_IMG_UPLOAD_COMPLETE, 0, NULL);
          break;
        default:
          break;
      }
    break;
    case VERIFY_IMAGE:
    break;
    case VERIFY_SELF_TEST:
      /*Implemented in Recovery State Machine*/
    break;
    default:
      /* This is fatal, It is very essential to investigate why
       * this might have happened but at the same time we dont
       * want to panic. The best is to go back and try normal
       * operation.
       */
      CurrentState = NORMAL;
    break;
  }
}