Comtrol eCos User Manual

Page 487

Advertising
background image

Chapter 32. µITRON API

#define CYGDAT_UITRON_TASK_INITIALIZERS \

CYG_UIT_TASK("main task", 8, startup,

&stack1, sizeof( stack1 )), \

CYG_UIT_TASK("worker 2" , 9, worktask, &stack2, sizeof( stack2 )), \

CYG_UIT_TASK("worker 3" , 9, worktask, &stack3, sizeof( stack3 )), \

CYG_UIT_TASK("low task" ,20, lowtask,

&stack4, sizeof( stack4 )), \

So this example has all four tasks statically configured to exist, ready to run, from the start of time. The “main
task” runs a routine called

startup()

at priority 8. Two “worker” tasks run both a priority 9, and a “low priority”

task runs at priority 20 to do useful non-urgent background work.

Task ID | Exists at | Function | Priority | Stack

| Stack

number |

startup

|

entry

|

| address | size

--------+-----------+----------+----------+---------+----------

1

|

Yes

|

startup |

8

| &stack1 | CYGNUM...

2

|

Yes

| worktask |

9

| &stack2 | CYGNUM...

3

|

Yes

| worktask |

9

| &stack3 | CYGNUM...

4

|

Yes

|

lowtask |

20

| &stack4 | CYGNUM...

--------+-----------+----------+----------+---------+----------

Q: How can I create µITRON tasks in the program?

You must provide free slots in the task table in which to create new tasks, by configuring the number of tasks
existing initially to be smaller than the total. For a task ID which does not initially exist, it will be told what routine
to call, and what priority it is, when the task is created. But you must still set aside memory for the task to use for
its stack, and give it a name during initialization. For example:

#define CYGNUM_UITRON_TASKS 4

// valid task ids are 1-4

#define CYGNUM_UITRON_TASKS_INITIALLY 1 // only task #1 exists

#define CYGDAT_UITRON_TASK_EXTERNS \

extern "C" void startup( unsigned int ); \

static char stack1[ CYGNUM_UITRON_STACK_SIZE ], \

stack2[ CYGNUM_UITRON_STACK_SIZE ], \

stack3[ CYGNUM_UITRON_STACK_SIZE ], \

stack4[ CYGNUM_UITRON_STACK_SIZE ];

#define CYGDAT_UITRON_TASK_INITIALIZERS \

CYG_UIT_TASK( "main", 8, startup, &stack1, sizeof( stack1 ) ), \

CYG_UIT_TASK_NOEXS( "slave",

&stack2, sizeof( stack2 ) ), \

CYG_UIT_TASK_NOEXS( "slave2",

&stack3, sizeof( stack3 ) ), \

CYG_UIT_TASK_NOEXS( "slave3",

&stack4, sizeof( stack4 ) ), \

So tasks numbered 2,3 and 4 have been given their stacks during startup, though they do not yet exist in terms of

cre_tsk()

and

del_tsk()

so you can create tasks 2–4 at runtime.

Task ID | Exists at | Function | Priority | Stack

| Stack

number |

startup

|

entry

|

| address | size

--------+-----------+----------+----------+---------+----------

1

|

Yes

|

startup |

8

| &stack1 | CYGNUM...

2

|

No

|

N/A

|

N/A

| &stack2 | CYGNUM...

3

|

No

|

N/A

|

N/A

| &stack3 | CYGNUM...

4

|

No

|

N/A

|

N/A

| &stack4 | CYGNUM...

--------+-----------+----------+----------+---------+----------

383

Advertising