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