Beispiel #1
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);
}
Beispiel #2
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;

  posAtomicSet(&counter, 0);

  /* Create a semaphore, initialize to 2.
   * You may vary the initialization count between
   * 1 and 3 and observe the output of this program.
   *
   * The initialization semaphore count limits the number
   * of tasks that are allowed to access a shared resource
   * at the same time.
   */
  semaphore = posSemaCreate(2);

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

  /* 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");
  }

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

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

  /* continue execution in function task1 */
  task1(arg);
}