Revision 13, 1.1 kB
(checked in by phil, 15 years ago)
|
Crossworks Lib Example (multiple tasks)
|
Line | |
---|
1 |
#include <ctl_api.h> |
---|
2 |
|
---|
3 |
CTL_TASK_t main_task, new_task; |
---|
4 |
|
---|
5 |
#define CALLSTACKSIZE 16 // this is only required for AVR builds |
---|
6 |
#define STACKSIZE 64 |
---|
7 |
unsigned new_task_stack[1+STACKSIZE+1]; |
---|
8 |
|
---|
9 |
void |
---|
10 |
new_task_code(void *p) |
---|
11 |
{ |
---|
12 |
unsigned int v=0; |
---|
13 |
while (1) |
---|
14 |
{ |
---|
15 |
// task logic goes here |
---|
16 |
v++; |
---|
17 |
} |
---|
18 |
} |
---|
19 |
|
---|
20 |
void |
---|
21 |
ctl_handle_error(CTL_ERROR_CODE_t e) |
---|
22 |
{ |
---|
23 |
while (1); |
---|
24 |
} |
---|
25 |
|
---|
26 |
int main(void) |
---|
27 |
{ |
---|
28 |
unsigned int v=0; |
---|
29 |
ctl_task_init(&main_task, 255, "main"); // create subsequent tasks whilst running at the highest priority. |
---|
30 |
ctl_start_timer(ctl_increment_tick_from_isr); // start the timer |
---|
31 |
memset(new_task_stack, 0xcd, sizeof(new_task_stack)); // write known values into the stack |
---|
32 |
new_task_stack[0]=new_task_stack[1+STACKSIZE]=0xfacefeed; // put marker values at the words before/after the stack |
---|
33 |
ctl_task_run(&new_task, 1, new_task_code, 0, "new_task", STACKSIZE, new_task_stack+1, CALLSTACKSIZE); |
---|
34 |
ctl_task_set_priority(&main_task, 0); // drop to lowest priority to start created tasks running. |
---|
35 |
while (1) |
---|
36 |
{ |
---|
37 |
// power down can go here if supported |
---|
38 |
v++; |
---|
39 |
} |
---|
40 |
return 0; |
---|
41 |
} |
---|