Пример #1
0
static void nano_init(void *arg)
{
#if NOSCFG_FEATURE_REGISTRY != 0
  REGELEM_t re;
#endif
  POS_SETTASKNAME(posCurrentTask_g, "root task");
#if POSCFG_TASKSTACKTYPE == 0
  posCurrentTask_g->nosstkroot = arg;
  posCurrentTask_g->exithook = nos_taskExitHook;
#else
  (void) arg;
#if NOSCFG_FEATURE_REGISTRY != 0
  posCurrentTask_g->exithook = nos_taskExitHook;
#endif
#endif

#if NOSCFG_FEATURE_CPUUSAGE != 0
  nano_initCpuUsage();
#endif
#if NOSCFG_FEATURE_REGISTRY != 0
  nos_initRegistry();
#endif
#if (NOSCFG_FEATURE_CONIN != 0) || (NOSCFG_FEATURE_CONOUT != 0)
  nos_initConIO();
#endif
#if NOSCFG_FEATURE_BOTTOMHALF != 0
  nos_initBottomHalfs();
#endif

#if NOSCFG_FEATURE_REGISTRY != 0
  re = nos_regNewSysKey(REGTYPE_TASK, "root-task");
  if (re != NULL)
  {
    nos_regEnableSysKey(re, posTaskGetCurrent());
  }
#endif

  (taskparams_g.func)(taskparams_g.arg);
}
Пример #2
0
static void task1(void *arg)
{
    POSTASK_t  self;
    POSTIMER_t timer;
    VAR_t      curprio;

    (void) arg;

    /* get handle and priority of current task */
    self    = posTaskGetCurrent();
    curprio = posTaskGetPriority(self);

    /* try to increase current priority */
    posTaskSetPriority(self, curprio + 1);
    curprio = posTaskGetPriority(self);

    /* start the printer task */
    printertask_g = startTask(task_printer, NULL, curprio + 1);

    /* print first message */
    print("HELLO WORLD!\n");

    /* start three tasks that do busy waiting */
    startTask(task_poll, " P1 ", curprio - 1);
    posTaskSleep(HZ/8);
    startTask(task_poll, " P2 ", curprio - 1);
    posTaskSleep(HZ/8);
    startTask(task_poll, " P3 ", curprio - 1);

    /* register software interrupt handler */
    posSoftIntSetHandler(4, softint_handler);

    /* start a task that rises software interrupts */
    startTask(task_softint, (void*) 4, curprio - 1);

    /* allocate a flag object */
    flags_g = posFlagCreate();
    if (flags_g == NULL)
        print("\nCan not allocate a flag object\n");

    /* start flag task */
    startTask(task_flag, NULL, curprio + 2);

    /* allocate a semaphore object */
    timersem_g = posSemaCreate(0);
    if (timersem_g == NULL)
        print("\nCan not allocate a semaphore\n");

    /* start timer task */
    startTask(task_timer, NULL, curprio + 2);

    /* allocate a timer object and set the timer up */
    timer = posTimerCreate();
    if (timer == NULL)
        print("\nCan not allocate a timer\n");
    posTimerSet(timer, timersem_g, 2*HZ, 2*HZ);

    /* Start the timer. The timer triggers every 2 seconds. */
    posTimerStart(timer);

    /* allocate a mutex object for mutex test */
    mutex_g = posMutexCreate();
    if (mutex_g == NULL)
        print("\nCan not allocate a mutex\n");

    /* start three mutex tasks */
    startTask(task_mutex, ":M1 ", curprio+1);
    startTask(task_mutex, ":M2 ", curprio+1);
    startTask(task_mutex, ":M3 ", curprio+1);

    /* allocate semaphore object for semaphore test,
       allow 2 tasks to get the semaphore */
    sema_g = posSemaCreate(2);
    if (sema_g == NULL)
        print("\nCan not allocate a semaphore\n");

    /* start three semaphore tasks */
    posTaskSleep(HZ/6);
    startTask(task_semas, (void*) (int) '1', curprio+2);
    posTaskSleep(HZ/6);
    startTask(task_semas, (void*) (int) '2', curprio+2);
    posTaskSleep(HZ/6);
    startTask(task_semas, (void*) (int) '3', curprio+2);

    /* Our main loop. We will set the flag number 2 every 3 seconds. */
    for (;;)
    {
        /* suspend this task for 3 seconds */
        posTaskSleep(3*HZ);

        /* set flag number 2 */
        posFlagSet(flags_g, 2);
    }
}
Пример #3
0
void uosResourceDiag()
{
#if NOSCFG_FEATURE_CONOUT == 1 && NOSCFG_FEATURE_PRINTF == 1

#ifdef POS_DEBUGHELP
  int taskCount = 0;
  int eventCount = 0;
  int i;
  struct PICOTASK* task;
  struct PICOEVENT* event;
#endif

#if POSCFG_ARGCHECK > 1

#if UOSCFG_NEWLIB_SYSCALLS == 1 && NOSCFG_MEM_MANAGER_TYPE != 1

  uint32_t heapUsed = (char*)sbrk(0) - (char*)__heap_start;
  uint32_t heapSize = (char*)__heap_end - (char*)__heap_start;
  nosPrintf("Heap used: %u (%d %%)\n", heapUsed, 100 * heapUsed / heapSize);

#endif

  nosPrint("Stack unused amounts:\n");

  int freeStack;
  unsigned char* sp;

  freeStack = 0;

#ifndef unix
  sp = portIrqStack;
  while (*sp == PORT_STACK_MAGIC) {
    ++sp;
    ++freeStack;
  }

  nosPrintf("  IRQ %d\n", freeStack);
#endif

#endif

#ifdef POS_DEBUGHELP

  struct PICOTASK* allTasks[POSCFG_MAX_TASKS];
  const char* name;

  memset(allTasks, '\0', sizeof(allTasks));

  posTaskSchedLock();
  task = picodeb_tasklist;
  while (task != NULL) {

    allTasks[taskCount] = task;
    taskCount++;
    task = task->next;
  }

  posTaskSchedUnlock();

#if POSCFG_ARGCHECK > 1

  for (i = 0; i < taskCount; i++) {

    task = allTasks[i];

    if (task->state == task_notExisting)
      continue;

    freeStack = 0;

    sp = task->handle->stack;
    while (*sp == PORT_STACK_MAGIC) {
      ++sp;
      ++freeStack;
    }

    name = (task->name != NULL) ? task->name : "?";
    nosPrintf("  %06X task %s %d\n", task->handle, name, freeStack);
  }

#endif

  posTaskSchedLock();

  event = picodeb_eventlist;
  while (event != NULL) {

    eventCount++;
    event = event->next;
  }

  posTaskSchedUnlock();

  nosPrintf("%d tasks, %d events in use\n", taskCount, eventCount);
  nosPrintf("%d tasks, %d events conf max\n", POSCFG_MAX_TASKS, POSCFG_MAX_EVENTS);

#else
#if POSCFG_ARGCHECK > 1 && POSCFG_FEATURE_GETTASK == 1
  
  POSTASK_t current = posTaskGetCurrent();

  freeStack = 0;
  sp = current->stack;
  while (*sp == PORT_STACK_MAGIC) {
    ++sp;
    ++freeStack;
  }

  nosPrintf("  current task %d\n", freeStack);

#endif

#endif
#endif
}