Exemplo n.º 1
0
void netInit()
{
  POSTASK_t t;
  int i;

  uipGiant = posSemaCreate(0);
  uipMutex = posMutexCreate();

  pollTicks = INFINITE;
  P_ASSERT("netInit", uipGiant != NULL && uipMutex != NULL);

  POS_SETEVENTNAME(uipGiant, "uip:giant");
  POS_SETEVENTNAME(uipMutex, "uip:mutex");

// uosFS setup

  netFS.base.mountPoint = "/socket";
  netFS.base.cf = &netFSConf;
 
  uosMount(&netFS.base);
  
// Initialize contiki-style timers (used by uip code)

  etimer_init();

  dataToSend = 0;

  for(i = 0; i < UIP_CONNS; i++)
    uip_conns[i].appstate.file = NULL;

#if UIP_UDP
  for(i = 0; i < UIP_UDP_CONNS; i++)
    uip_udp_conns[i].appstate.file = NULL;
#endif /* UIP_UDP */

  netInterfaceInit();
  uip_init();

#if NETSTACK_CONF_WITH_IPV6 == 0
  uip_arp_init();
#endif

  t = posTaskCreate(netMainThread, NULL, NETCFG_TASK_PRIORITY, NETCFG_STACK_SIZE);
  P_ASSERT("netInit2", t != NULL);
  POS_SETTASKNAME(t, "uip:main");
}
Exemplo n.º 2
0
UosFile* netSockAlloc(NetSockState initialState)
{
  int      slot;

  UosFile* file = uosFileAlloc();
  if (file == NULL)
    return NULL;

  slot = UOS_BITTAB_ALLOC(netSocketTable);
  if (slot == -1) {

    uosFileFree(file);
    nosPrintf("netSockAlloc: table full\n");
    return NULL;
  }

  NetSock* sock = UOS_BITTAB_ELEM(netSocketTable, slot);
  sock->state = initialState;
  sock->mutex = posMutexCreate();
  sock->sockChange = posFlagCreate();
  sock->uipChange = posFlagCreate();
  sock->timeout = INFINITE;
  sock->buf = NULL;
  sock->len = 0;
  sock->max = 0;

  P_ASSERT("netSockAlloc", sock->mutex != NULL && sock->sockChange != NULL && sock->uipChange != NULL);

  POS_SETEVENTNAME(sock->mutex, "sock:mutex");
  POS_SETEVENTNAME(sock->sockChange, "sock:api");
  POS_SETEVENTNAME(sock->uipChange, "sock:uip");

  file->fs     = &netFS.base;
  file->cf     = &netSockConf;
  file->fsPriv = sock;

  return file;
}
Exemplo n.º 3
0
/* This is the first function that is called in the multitasking context.
 * (See file ex_init4.c for how to setup pico]OS).
 */
void firsttask(void *arg)
{
  POSTASK_t  t;

  /* Note: You may uncomment the source below by setting the #if to
   *       zero and then observe the output of this program.
   *       This is a nice example of how synchronization works.
   */
#if 1

  /* create a mutex */
  mutex = posMutexCreate();

  if (mutex == NULL)
  {
    nosPrint("Failed to create a mutex!\n");
    return;
  }

#endif

  /* start a second task */
  t = nosTaskCreate(task2,      /* pointer to new task-function            */
                    NULL,       /* optional argument for the task-function */
                    2,          /* priority level of the new task          */
                    0,          /* stack size (0 = default size)           */
                    "task2");   /* optional name of the second task        */

  if (t == NULL)
  {
    nosPrint("Failed to start second task!\n");
  }

  /* continue execution in function task1 */
  task1(arg);
}
Exemplo n.º 4
0
NOSMUTEX_t POSCALL nosMutexCreate(UVAR_t options, const char *name)
{
  POSMUTEX_t mtx;
  REGELEM_t re;

  re = nos_regNewSysKey(REGTYPE_MUTEX,
                        name == NULL ? (const char*)"m*" : name);
  if (re == NULL)
    return NULL;

  (void) options;
  mtx = posMutexCreate();

  if (mtx == NULL)
  {
    nos_regDelSysKey(REGTYPE_MUTEX, NULL, re);
  }
  else
  {
    nos_regEnableSysKey(re, mtx);
    POS_SETEVENTNAME(mtx, re->name);
  }
  return (NOSMUTEX_t) mtx;
}
Exemplo n.º 5
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);
    }
}