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(Task2);
37  assert(stat == E_OK);
38 
39  ActivateTask(Task3);
40  assert(stat == E_OK);
41 
42  ActivateTask(Task2);
43  assert(stat == E_OK);
44 
45  ActivateTask(Task2);
46  assert(stat == E_OK);
47 
48  ActivateTask(Task3);
49  assert(stat == E_OK);
50 
51  ActivateTask(Task3);
52  assert(stat == E_OK);
53 
54  stat = TerminateTask();
55  assert(stat == E_OK);
56 }
57 
58 TASK(Task2)
59 {
60  StatusType stat = TerminateTask();
61  assert(stat == E_OK);
62 }
63 
64 TASK(Task3)
65 {
66  StatusType stat = TerminateTask();
67  assert(stat == E_OK);
68 }
69 
70 extern void StartupHook(void)
71 {
72  DDRB = 0xFF; // PB as output
73  PORTB = 0xFF; // keep all LEDs off
74 
75  DDRD = 0x00; // PD as input
76  PORTD = 0xFF; // enable PU on PD
77 
78 #if defined (__AVR_ATmega32__)
79 
80 #elif defined (__AVR_ATmega128__) || defined (__AVR_ATmega1284__)
81  /* Timer 2 */
82 #if defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true
83 #if defined (__AVR_ATmega128__)
84  TCCR2 = (1 << CS20); // Enable Timer2 with Prescaler 1
85  TIMSK |= 1 << TOIE2; // Enable Overflow Interrupt (Timer2)
86 #else /* defined (__AVR_ATmega128__) */
87  TCCR2B = (1 << CS20); // Enable Timer2 with Prescaler 1
88  TIMSK2 |= 1 << TOIE2; // Enable Overflow Interrupt (Timer2)
89 #endif /* defined (__AVR_ATmega128__) */
90 #endif /* defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true */
91 #else /* defined (__AVR_ATmega32__) */
92 #error Unknown CPU defined!
93 #endif /* defined (__AVR_ATmega32__) */
94 
95  uint8_t t = 0;
96 
97  while (t < 6) {
98  uint8_t r = PORTB;
99  r ^= (1 << 7);
100  PORTB = r;
101  DELAY_MS(50);
102  t++;
103  }
104 }
105 
106 extern void ShutdownHook(StatusType error)
107 {
108  DDRB = 0xFF; // PB as output
109  PORTB = 0xFF; // keep all LEDs off
110 
111  for (uint8_t i = 0; i < 11; i++) {
112  PORTB ^= 0xFF;
113  DELAY_MS(1000);
114  }
115 }
116 
117 extern void PreTaskHook(void)
118 {
119  TaskType task;
120  GetTaskID(&task);
121  TaskStateType state = SUSPENDED;
122  GetTaskState(task, &state);
123 }
124 
125 extern void PostTaskHook(void)
126 {
127  TaskType task;
128  GetTaskID(&task);
129  TaskStateType state = SUSPENDED;
130  GetTaskState(task, &state);
131 }
132 
133 extern void ErrorHook(StatusType error)
134 {
135 
136 }
137 
138 ISR(TIMER2_OVF_vect)
139 {
140 
141 }
TaskType
enum tasks_e TaskType
Type for task reference.
Definition: TaskTypes.h:29
StatusType
enum StatusType_e StatusType
Type for status.
ErrorHook
void ErrorHook(StatusType error)
PostTask hook function.
Definition: App.c:784
StartupHook
void StartupHook(void)
Definition: App.c:702
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
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
ShutdownHook
void ShutdownHook(StatusType error)
Definition: App.c:757
TaskStateType
enum OsTaskState_e TaskStateType
Task state.
DELAY_MS
#define DELAY_MS(ms)
Definition: App.c:24