Пример #1
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;
}
Пример #2
0
void firsttask(void *arg) {
	POSTASK_t  t;
	UVAR_t i;

	posAtomicSet(&counter, 0);

	/* creating the flag */
	flagset = posFlagCreate();
  
	if (flagset == NULL)
	{
		nosPrint("Failed to create a set of flags!\n");
		return;
	}

	/* creating semaphore object with set one default value */
	semaphore = posSemaCreate(1);

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

	t = nosTaskCreate(task2,    /* ptr to function:  task2 that is executed 	*/
		NULL,					/* optional argument, not used here             */
		1,						/* priority of the first task                   */
		0,						/* stack size for the first task, 0 = default   */
		"task2");				/* task name       								*/

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

	t = nosTaskCreate(task3,    /* ptr to function: task3 that is executed */
                    NULL,       /* optional argument, not used here             */
                    1,          /* priority of the first task                   */
                    0,          /* stack size for the first task, 0 = default   */
                    "task3");   /* task name       				*/

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

	/* first flag status change */
	posFlagSet(flagset, 1);
	
  	/* task1 handled */
	task1(arg);
}
Пример #3
0
NOSFLAG_t POSCALL nosFlagCreate(const char* name)
{
  POSFLAG_t flg;
  REGELEM_t re;

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

  flg = posFlagCreate();
  if (flg == NULL)
  {
    nos_regDelSysKey(REGTYPE_FLAG, NULL, re);
  }
  else
  {
    nos_regEnableSysKey(re, flg);
    POS_SETEVENTNAME(flg, re->name);
  }
  return (NOSFLAG_t) flg;
}
Пример #4
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);
    }
}