AutosarOS
App.c
Go to the documentation of this file.
1 
14 #include "assert.h"
15 
16 #include "OS_API.h"
17 
18 #include <avr/io.h>
19 #include <util/delay.h>
20 
21 #if defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true
22 #define DELAY_MS(ms)
23 #else
24 #define DELAY_MS(ms) _delay_ms(ms)
25 #endif /* defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true */
26 
27 volatile bool isrFlag = false;
28 
29 TASK(Idle)
30 {
31  while (1);
32 }
33 
34 TASK(Task1)
35 {
36  StatusType stat = ActivateTask(Task3);
37  assert(stat == E_OK);
38 
39  stat = Schedule();
40  assert(stat == E_OK);
41 
42  stat = TerminateTask();
43  assert(stat == E_OK);
44 }
45 
46 TASK(Task2)
47 {
48  StatusType stat = ActivateTask(Task1);
49  assert(stat == E_OK);
50 
51  EventMaskType mask = 0b10;
52  stat = WaitEvent(mask);
53  assert(stat == E_OK);
54 
55  stat = TerminateTask();
56  assert(stat == E_OK);
57 }
58 
59 TASK(Task3)
60 {
61  StatusType stat = ActivateTask(Task4);
62  assert(stat == E_OK);
63 
64  stat = Schedule();
65  assert(stat == E_OK);
66 
67  stat = TerminateTask();
68  assert(stat == E_OK);
69 }
70 
71 TASK(Task4)
72 {
73  StatusType stat = SetEvent(Task2, 0b10);
74  assert(stat == E_OK);
75 
76  stat = TerminateTask();
77  assert(stat == E_OK);
78 }
79 
80 extern void StartupHook(void)
81 {
82  DDRB = 0xFF; // PB as output
83  PORTB = 0xFF; // keep all LEDs off
84 
85  DDRD = 0x00; // PD as input
86  PORTD = 0xFF; // enable PU on PD
87 
88 #if defined (__AVR_ATmega32__)
89 
90 #elif defined (__AVR_ATmega128__) || defined (__AVR_ATmega1284__)
91  /* Timer 2 */
92 #if defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true
93 #if defined (__AVR_ATmega128__)
94  TCCR2 = (1 << CS20); // Enable Timer2 with Prescaler 1
95  TIMSK |= 1 << TOIE2; // Enable Overflow Interrupt (Timer2)
96 #else /* defined (__AVR_ATmega128__) */
97  TCCR2B = (1 << CS20); // Enable Timer2 with Prescaler 1
98  TIMSK2 |= 1 << TOIE2; // Enable Overflow Interrupt (Timer2)
99 #endif /* defined (__AVR_ATmega128__) */
100 #endif /* defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true */
101 #else /* defined (__AVR_ATmega32__) */
102 #error Unknown CPU defined!
103 #endif /* defined (__AVR_ATmega32__) */
104 
105  uint8_t t = 0;
106 
107  while (t < 6) {
108  uint8_t r = PORTB;
109  r ^= (1 << 7);
110  PORTB = r;
111  DELAY_MS(50);
112  t++;
113  }
114 }
115 
116 extern void ShutdownHook(StatusType error)
117 {
118  DDRB = 0xFF; // PB as output
119  PORTB = 0xFF; // keep all LEDs off
120 
121  for (uint8_t i = 0; i < 11; i++) {
122  PORTB ^= 0xFF;
123  DELAY_MS(1000);
124  }
125 }
126 
127 extern void PreTaskHook(void)
128 {
129  TaskType task;
130  GetTaskID(&task);
131  TaskStateType state = SUSPENDED;
132  GetTaskState(task, &state);
133 }
134 
135 extern void PostTaskHook(void)
136 {
137  TaskType task;
138  GetTaskID(&task);
139  TaskStateType state = SUSPENDED;
140  GetTaskState(task, &state);
141 }
142 
143 extern void ErrorHook(StatusType error)
144 {
145 
146 }
147 
148 ISR(TIMER2_OVF_vect)
149 {
150 
151 }
TaskType
enum tasks_e TaskType
Type for task reference.
Definition: TaskTypes.h:29
EventMaskType
uint8_t EventMaskType
Data type of the event mask.
Definition: EventTypes.h:21
StatusType
enum StatusType_e StatusType
Type for status.
ErrorHook
void ErrorHook(StatusType error)
PostTask hook function.
Definition: App.c:784
Schedule
#define Schedule
Definition: OS_API.h:81
StartupHook
void StartupHook(void)
Definition: App.c:702
WaitEvent
#define WaitEvent
Definition: OS_API.h:48
GetTaskState
#define GetTaskState
Definition: OS_API.h:83
assert.h
Assert macros and functions.
TASK
TASK(Idle)
Definition: App.c:33
E_OK
@ E_OK
Definition: Types.h:40
SetEvent
#define SetEvent
Definition: OS_API.h:45
ISR
ISR(INT0_vect)
Definition: App.c:806
PreTaskHook
void PreTaskHook(void)
PreTask hook function.
Definition: App.c:768
ActivateTask
#define ActivateTask
Definition: OS_API.h:78
assert
#define assert(expression)
Definition: assert.h:37
SUSPENDED
@ SUSPENDED
The task is suspended and will not be scheduled.
Definition: TaskTypes.h:58
TerminateTask
#define TerminateTask
Definition: OS_API.h:80
OS_API.h
Operating System API.
GetTaskID
#define GetTaskID
Definition: OS_API.h:82
isrFlag
volatile bool isrFlag
Definition: App.c:27
PostTaskHook
void PostTaskHook(void)
PostTask hook function.
Definition: App.c:776
DELAY_MS
#define DELAY_MS(ms)
Definition: App.c:24
ShutdownHook
void ShutdownHook(StatusType error)
Definition: App.c:757
TaskStateType
enum OsTaskState_e TaskStateType
Task state.