コード例 #1
0
ファイル: ex_flag3.c プロジェクト: AriZuu/picoos
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);
}
コード例 #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);
}
コード例 #3
0
/* This function is executed by the first task that is started
 * by pico]OS ( see the nosInit()-call in main(), file ex_init4.c ).
 */
void firsttask(void *arg)
{
  NOSTASK_t  t;

  /* Avoid compiler warning. "arg" is the "NULL" in the nosInit()-call */
  (void) arg;

  nosPrint("First task started\n");

  /* start a second task */
  t = nosTaskCreate(secondtask, /* pointer to new task-function            */
                    "Task 2",   /* 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");
  }

  for(;;)
  {
    /* print string: "Task 1" */
    nosPrint("Task 1\n");

    /* sleep (=do nothing) for one second */
    nosTaskSleep(MS(1000));
  }
}
コード例 #4
0
ファイル: sock_server.c プロジェクト: AriZuu/wiced-test
void tcpServerThread(void* arg)
{
  int sockd, sockd2;
  socklen_t addrlen;
  struct sockaddr_in myAddr, peerAddr;
  int status;

  sockd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockd == -1) {

    nosPrintf("Socket creation error\n");
    return;
  }

/* 
 * Bind socket to telnet port so we can test this easily.
 */
  myAddr.sin_family = AF_INET;
  myAddr.sin_addr.s_addr = INADDR_ANY;
  myAddr.sin_port = htons(24);

  status = bind(sockd, (struct sockaddr*)&myAddr, sizeof(myAddr));
  if (status == -1) {

    nosPrintf("Binding error\n");
    return;
  }

  status = listen(sockd, 5);
  if (status == -1) {

    nosPrintf("Listening error\n");
    return;
  }

  nosPrintf("socket server listening\n");
  for(;;) {

/*
 * Wait for new connection. 
 */
    addrlen = sizeof(peerAddr);
    sockd2 = accept(sockd, (struct sockaddr*)&peerAddr, &addrlen);
    if (sockd2 == -1) {

      nosPrintf("Wrong connection\n");
      continue;
    }
/*
 * Create thread to serve connection.
 */
    if (nosTaskCreate(tcpClientThread, (void*)(long)sockd2, 5, 512, "socktest") == NULL)
       close(sockd2);

  }
}
コード例 #5
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;
  VAR_t      status;

  (void) arg;

  /* create a semaphore, initialize to 0 */
  event = posSemaCreate(0);

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

  /* start a second task */
  t = nosTaskCreate(task2,      /* pointer to new task-function            */
                    event,      /* 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");
    return;
  }

  /* install software interrupt handler (no. 4) */
  status = posSoftIntSetHandler(4, softisr);

  if (status != E_OK)
  {
    nosPrint("Failed to install software interrupt handler!\n");
    return;
  }


  /* Signal the interrupt every second.
   * Usually, the software interrupt would be raised
   * asynchronously through eg. a hardware isr handler.
   */
  for(;;)
  {
    /* raise the software interrupt no. 4 */
    posSoftInt(4, 0);

    /* wait 1 second */
    posTaskSleep(MS(1000));
  }
}
コード例 #6
0
ファイル: wwd_rtos.c プロジェクト: AriZuu/wiced-driver
/*
 * Create thread with arg.
 */
wwd_result_t host_rtos_create_thread_with_arg(host_thread_type_t* thread,
                                              void (*entryFunction)(uint32_t),
                                              const char* name,
                                              void* stack,
                                              uint32_t stackSize,
                                              uint32_t priority,
                                              uint32_t arg)
{
  P_ASSERT("Cannot use pre-allocated thread stack.", stack == NULL);

  *thread = nosTaskCreate((POSTASKFUNC_t)entryFunction, (void*)arg, priority, stackSize, name);
  if (*thread == NULL)
    return WWD_THREAD_CREATE_FAILED;

  return WWD_SUCCESS;
}
コード例 #7
0
ファイル: ex_mutx1.c プロジェクト: AriZuu/picoos
/* 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);
}
コード例 #8
0
ファイル: example.c プロジェクト: AriZuu/potato-bus
void potatoStart()
{
  nosTaskCreate(potatoTask, NULL, 2, 4000, "PotatoBus");
}
コード例 #9
0
ファイル: sys_arch.c プロジェクト: AriZuu/picoos-lwip
/*
 * Thread creation, use Pico]OS nano layer directly.
 */
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
{
  return nosTaskCreate(thread, arg, prio, stacksize, name);
}