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
TASK
(Idle)
28
{
29
while
(1);
30
}
31
32
TASK
(Task1)
33
{
34
StatusType
stat =
SetAbsAlarm
(Alarm1, 1, 1);
35
assert
(stat ==
E_OK
);
36
37
stat =
SetAbsAlarm
(Alarm1, 3, 0);
38
assert
(stat ==
E_OS_STATE
);
39
40
stat =
IncrementCounter
(Counter1);
41
assert
(stat ==
E_OK
);
42
43
stat =
Schedule
();
44
assert
(stat ==
E_OK
);
45
46
stat =
IncrementCounter
(Counter1);
47
assert
(stat ==
E_OK
);
48
49
stat =
Schedule
();
50
assert
(stat ==
E_OK
);
51
52
stat =
CancelAlarm
(Alarm1);
53
assert
(stat ==
E_OK
);
54
55
stat =
SetRelAlarm
(Alarm1, 1, 0);
56
assert
(stat ==
E_OK
);
57
58
stat =
SetRelAlarm
(Alarm1, 2, 0);
59
assert
(stat ==
E_OS_STATE
);
60
61
TickType
tick = 0;
62
stat =
GetAlarm
(Alarm1, &tick);
63
assert
(stat ==
E_OK
&& tick == 1);
64
65
stat =
IncrementCounter
(Counter1);
66
assert
(stat ==
E_OK
);
67
68
stat =
Schedule
();
69
assert
(stat ==
E_OK
);
70
71
stat =
TerminateTask
();
72
assert
(stat ==
E_OK
);
73
}
74
75
TASK
(Task2)
76
{
77
StatusType
stat =
WaitEvent
(0b10);
78
assert
(stat ==
E_OK
);
79
80
stat =
ClearEvent
(0b10);
81
assert
(stat ==
E_OK
);
82
83
stat =
WaitEvent
(0b10);
84
assert
(stat ==
E_OK
);
85
86
stat =
ClearEvent
(0b10);
87
assert
(stat ==
E_OK
);
88
89
stat =
WaitEvent
(0b10);
90
assert
(stat ==
E_OK
);
91
92
stat =
TerminateTask
();
93
assert
(stat ==
E_OK
);
94
}
95
96
extern
void
StartupHook
(
void
)
97
{
98
DDRB = 0xFF;
// PB as output
99
PORTB = 0xFF;
// keep all LEDs off
100
101
DDRD = 0x00;
// PD as input
102
PORTD = 0xFF;
// enable PU on PD
103
104
#if defined (__AVR_ATmega32__)
105
106
#elif defined (__AVR_ATmega128__) || defined (__AVR_ATmega1284__)
107
/* Timer 2 */
108
#if defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true
109
#if defined (__AVR_ATmega128__)
110
TCCR2 = (1 << CS20);
// Enable Timer2 with Prescaler 1
111
TIMSK |= 1 << TOIE2;
// Enable Overflow Interrupt (Timer2)
112
#else
/* defined (__AVR_ATmega128__) */
113
TCCR2B = (1 << CS20);
// Enable Timer2 with Prescaler 1
114
TIMSK2 |= 1 << TOIE2;
// Enable Overflow Interrupt (Timer2)
115
#endif
/* defined (__AVR_ATmega128__) */
116
#endif
/* defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true */
117
#else
/* defined (__AVR_ATmega32__) */
118
#error Unknown CPU defined!
119
#endif
/* defined (__AVR_ATmega32__) */
120
121
uint8_t t = 0;
122
123
while
(t < 6) {
124
uint8_t r = PORTB;
125
r ^= (1 << 7);
126
PORTB = r;
127
DELAY_MS
(50);
128
t++;
129
}
130
}
131
132
extern
void
ShutdownHook
(
StatusType
error)
133
{
134
DDRB = 0xFF;
// PB as output
135
PORTB = 0xFF;
// keep all LEDs off
136
137
for
(uint8_t i = 0; i < 11; i++) {
138
PORTB ^= 0xFF;
139
DELAY_MS
(1000);
140
}
141
}
142
143
extern
void
PreTaskHook
(
void
)
144
{
145
TaskType
task;
146
GetTaskID
(&task);
147
TaskStateType
state =
SUSPENDED
;
148
GetTaskState
(task, &state);
149
}
150
151
extern
void
PostTaskHook
(
void
)
152
{
153
TaskType
task;
154
GetTaskID
(&task);
155
TaskStateType
state =
SUSPENDED
;
156
GetTaskState
(task, &state);
157
}
158
159
extern
void
ErrorHook
(
StatusType
error)
160
{
161
162
}
163
164
ISR
(TIMER2_OVF_vect)
165
{
166
167
}
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
Schedule
#define Schedule
Definition:
OS_API.h:81
TickType
uint64_t TickType
Data type of counter values.
Definition:
CounterTypes.h:21
StartupHook
void StartupHook(void)
Definition:
App.c:702
ClearEvent
#define ClearEvent
Definition:
OS_API.h:46
WaitEvent
#define WaitEvent
Definition:
OS_API.h:48
GetTaskState
#define GetTaskState
Definition:
OS_API.h:83
assert.h
Assert macros and functions.
IncrementCounter
#define IncrementCounter
Definition:
OS_API.h:36
SetAbsAlarm
#define SetAbsAlarm
Definition:
OS_API.h:28
TASK
TASK(Idle)
Definition:
App.c:33
E_OK
@ E_OK
Definition:
Types.h:40
DELAY_MS
#define DELAY_MS(ms)
Definition:
App.c:24
ISR
ISR(INT0_vect)
Definition:
App.c:806
PreTaskHook
void PreTaskHook(void)
PreTask hook function.
Definition:
App.c:768
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.
CancelAlarm
#define CancelAlarm
Definition:
OS_API.h:29
SetRelAlarm
#define SetRelAlarm
Definition:
OS_API.h:27
GetAlarm
#define GetAlarm
Definition:
OS_API.h:26
GetTaskID
#define GetTaskID
Definition:
OS_API.h:82
E_OS_STATE
@ E_OS_STATE
Definition:
Types.h:47
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.
test
AM
AM3
App.c
Generated by
1.8.20