]> rtime.felk.cvut.cz Git - arc.git/blob - examples/os_simple/os_simple.c
Merge with e3d24894e6cb082a255328755604b04b0542b39e
[arc.git] / examples / os_simple / os_simple.c
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
6  * This source code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15
16
17 #include "Os.h"
18 #include "Mcu.h"
19 #include "arc.h"
20
21 #define USE_LDEBUG_PRINTF // Uncomment this to turn debug statements on.
22 #include "debug.h"
23
24 // How many errors to keep in error log.
25 #define ERROR_LOG_SIZE 20
26
27
28 /**
29  * Just an example of a basic task.
30  */
31
32 void bTask3( void ) {
33         StackInfoType si;
34         TaskType currTask;
35         LDEBUG_PRINTF("[%08u] bTask3 start\n", (unsigned)GetOsTick() );
36
37         GetTaskID(&currTask);
38         Os_Arc_GetStackInfo(currTask,&si);
39         LDEBUG_PRINTF("bTask3: %u%% stack usage\n",
40                         (unsigned)OS_STACK_USAGE(&si));
41
42         TerminateTask();
43 }
44
45 /**
46  * An extended task is auto-started and is also triggered by an alarm
47  * that sets event 2.
48  */
49
50 void eTask1( void ) {
51         volatile float tryFloatingPoint = 0.0F;
52         StackInfoType si;
53         TaskType currTask;
54
55         LDEBUG_FPUTS("eTask1 start\n");
56
57         ActivateTask(TASK_ID_eTask2);
58         for(;;) {
59                 SetEvent(TASK_ID_eTask2,EVENT_MASK_Event2);
60                 WaitEvent(EVENT_MASK_Event1);
61                 ClearEvent(EVENT_MASK_Event1);
62                 tryFloatingPoint += 1.0F;
63                 GetTaskID(&currTask);
64                 Os_Arc_GetStackInfo(currTask,&si);
65                 LDEBUG_PRINTF("eTask1: %u%% stack usage\n",
66                                 (unsigned)OS_STACK_USAGE(&si));
67
68         }
69 }
70
71 /**
72  * An extended task that receives events from someone
73  * and activates task: bTask3.
74  */
75 void eTask2( void ) {
76         LDEBUG_FPUTS("eTask2 start\n");
77
78         for(;;) {
79                 WaitEvent(EVENT_MASK_Event2);
80                 ClearEvent(EVENT_MASK_Event2);
81                 ActivateTask(TASK_ID_bTask3);
82                 {
83                         StackInfoType si;
84                         TaskType currTask;
85                         GetTaskID(&currTask);
86                         Os_Arc_GetStackInfo(currTask,&si);
87                         LDEBUG_PRINTF("eTask2: %u%% stack usage\n",
88                                         (unsigned)OS_STACK_USAGE(&si));
89                 }
90         }
91 }
92
93
94 /*
95  * Functions that must be supplied by the example
96  */
97
98 void OsIdle( void ) {
99         for(;;) {}
100 }