cocoOS  5.0.1
os_task.c File Reference
#include "cocoos.h"
#include <stdlib.h>

Data Structures

struct  tcb
 

Functions

void os_task_init (void)
 
uint8_t task_create (taskproctype taskproc, void *data, uint8_t prio, Msg_t *msgPool, uint8_t poolSize, uint16_t msgSize)
 
TaskState_t task_state_get (uint8_t tid)
 
void task_kill (uint8_t tid)
 
void * task_get_data ()
 
uint8_t os_task_highest_prio_ready_task (void)
 
uint8_t os_task_next_ready_task (void)
 
void os_task_release_waiting_task (Sem_t sem)
 
uint8_t os_task_waiting_this_semaphore (Sem_t sem)
 
void os_task_wait_sem_set (uint8_t tid, Sem_t sem)
 
void os_task_ready_set (uint8_t tid)
 
void os_task_suspend (uint8_t tid)
 
void os_task_resume (uint8_t tid)
 
void os_task_kill (uint8_t tid)
 
uint8_t os_task_prio_get (uint8_t tid)
 
void os_task_clear_wait_queue (uint8_t tid)
 
void os_task_wait_time_set (uint8_t tid, uint8_t id, uint16_t time)
 
void os_task_wait_event (uint8_t tid, Evt_t eventId, uint8_t waitSingleEvent, uint16_t timeout)
 
void os_task_tick (uint8_t id, uint16_t tickSize)
 
void os_task_signal_event (Evt_t eventId)
 
void os_task_run (void)
 
uint16_t os_task_internal_state_get (uint8_t tid)
 
void os_task_internal_state_set (uint8_t tid, uint16_t state)
 
MsgQ_t os_task_msgQ_get (uint8_t tid)
 
void os_task_set_wait_queue (uint8_t tid, MsgQ_t queue)
 
MsgQ_t os_task_get_wait_queue (uint8_t tid)
 
void os_task_set_change_event (uint8_t tid, Evt_t event)
 
Evt_t os_task_get_change_event (uint8_t tid)
 
void os_task_set_msg_result (uint8_t tid, uint8_t result)
 
uint8_t os_task_get_msg_result (uint8_t tid)
 
uint16_t os_task_timeout_get (uint8_t tid)
 

Function Documentation

uint8_t task_create ( taskproctype  taskproc,
void *  data,
uint8_t  prio,
Msg_t msgPool,
uint8_t  poolSize,
uint16_t  msgSize 
)

Creates a task scheduled by the os. The task is put in the ready state.

Parameters
taskprocFunction pointer to the task procedure.
data[optional] Pointer to task data
prioTask priority on a scale 0-255 where 0 is the highest priority.
msgPool[optional] Pointer to the message pool, containing messages. Ignored if poolSize is 0.
poolSize[optional] Size, in nr of messages, of the message pool. Set to 0 if no message pool needed for the task
msgSize[optional] Size of the message type held in the message queue
Returns
Task id of the created task.
Remarks
Usage:
Should be called early in system setup, before starting the task execution. Only one task per priority level is allowed.
1  static uint8_t taskId;
2  static Msg_t msgpool_1[ POOL_SIZE ];
3 
4 int main(void) {
5  system_init();
6  os_init();
7  taskId = task_create( myTaskProc, 0, 1, msgpool_1, POOL_SIZE, sizeof(Msg_t) );
8  ...
9 }
void* task_get_data ( )

Gets a pointer to the data structure associated with the task

Returns
pointer to task data
1 static uint32_t taskData;
2 
3 static void taskProc(void)
4 {
5  task_open();
6  for (;;) {
7  task_wait( 100 );
8  uint32_t *data = (uint32_t*)task_get_data();
9  *data++;
10  }
11  task_close();
12 }
13 
14 int main() {
15  ...
16  task_create(taskProc, (void*)&taskData, ...);
17  ...
18 }
void task_kill ( uint8_t  tid)

Puts the task associated with the specified id in the killed state. A killed task, cannot be resumed.

Parameters
task_idid of the task.
Returns
None
1 static uint8_t taskId;
2 
3 static void waitingTask(void)
4 {
5  task_open();
6 
7  event_wait( event );
8 
9  if ( event_signaling_taskId_get( event ) == taskId ) {
10  task_kill( taskId );
11  }
12 
13  task_close();
14 
15 }
16 
17 
18 static void signalingTask1(void)
19 {
20  task_open();
21 
22  task_wait( 900 );
23 
24  event_signal(event);
25 
26  task_close();
27 
28 }
29 
30 int main() {
31  ...
32  taskId = task_create(signalingTask1, ...);
33  ...
34 }