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  AlarmBaseType base;
35  StatusType stat = GetAlarmBase(INVALID_ALARM, &base);
36  assert(stat == E_OS_ID);
37 
38  TickType tick = 0;
39  stat = GetAlarm(INVALID_ALARM, &tick);
40  assert(stat == E_OS_ID);
41 
42  stat = GetAlarmBase(Alarm1, &base);
43  assert(stat == E_OK);
44 
45  stat = SetRelAlarm(INVALID_ALARM, 0, 0);
46  assert(stat == E_OS_ID);
47 
48  stat = SetRelAlarm(Alarm1, -1, 0);
49  assert(stat == E_OS_VALUE);
50 
51  stat = SetRelAlarm(Alarm1, base.maxallowedvalue + 1, 0);
52  assert(stat == E_OS_VALUE);
53 
54  stat = SetRelAlarm(Alarm1, 1, base.mincycle - 1);
55  assert(stat == E_OS_VALUE);
56 
57  stat = SetRelAlarm(Alarm1, 1, base.maxallowedvalue + 1);
58  assert(stat == E_OS_VALUE);
59 
60  stat = SetAbsAlarm(INVALID_ALARM, 0, 0);
61  assert(stat == E_OS_ID);
62 
63  stat = SetAbsAlarm(Alarm1, -1, 0);
64  assert(stat == E_OS_VALUE);
65 
66  stat = SetAbsAlarm(Alarm1, base.maxallowedvalue + 1, 0);
67  assert(stat == E_OS_VALUE);
68 
69  stat = SetAbsAlarm(Alarm1, 1, base.mincycle - 1);
70  assert(stat == E_OS_VALUE);
71 
72  stat = SetAbsAlarm(Alarm1, 1, base.maxallowedvalue + 1);
73  assert(stat == E_OS_VALUE);
74 
75  stat = CancelAlarm(INVALID_ALARM);
76  assert(stat == E_OS_ID);
77 
78  stat = TerminateTask();
79  assert(stat == E_OK);
80 }
81 
82 extern void StartupHook(void)
83 {
84  DDRB = 0xFF; // PB as output
85  PORTB = 0xFF; // keep all LEDs off
86 
87  DDRD = 0x00; // PD as input
88  PORTD = 0xFF; // enable PU on PD
89 
90 #if defined (__AVR_ATmega32__)
91 
92 #elif defined (__AVR_ATmega128__) || defined (__AVR_ATmega1284__)
93  /* Timer 2 */
94 #if defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true
95 #if defined (__AVR_ATmega128__)
96  TCCR2 = (1 << CS20); // Enable Timer2 with Prescaler 1
97  TIMSK |= 1 << TOIE2; // Enable Overflow Interrupt (Timer2)
98 #else /* defined (__AVR_ATmega128__) */
99  TCCR2B = (1 << CS20); // Enable Timer2 with Prescaler 1
100  TIMSK2 |= 1 << TOIE2; // Enable Overflow Interrupt (Timer2)
101 #endif /* defined (__AVR_ATmega128__) */
102 #endif /* defined (OS_CONFIG_SIM) && OS_CONFIG_SIM == true */
103 #else /* defined (__AVR_ATmega32__) */
104 #error Unknown CPU defined!
105 #endif /* defined (__AVR_ATmega32__) */
106 
107  uint8_t t = 0;
108 
109  while (t < 6) {
110  uint8_t r = PORTB;
111  r ^= (1 << 7);
112  PORTB = r;
113  DELAY_MS(50);
114  t++;
115  }
116 }
117 
118 extern void ShutdownHook(StatusType error)
119 {
120  DDRB = 0xFF; // PB as output
121  PORTB = 0xFF; // keep all LEDs off
122 
123  for (uint8_t i = 0; i < 11; i++) {
124  PORTB ^= 0xFF;
125  DELAY_MS(1000);
126  }
127 }
128 
129 extern void PreTaskHook(void)
130 {
131  TaskType task;
132  GetTaskID(&task);
133  TaskStateType state = SUSPENDED;
134  GetTaskState(task, &state);
135 }
136 
137 extern void PostTaskHook(void)
138 {
139  TaskType task;
140  GetTaskID(&task);
141  TaskStateType state = SUSPENDED;
142  GetTaskState(task, &state);
143 }
144 
145 extern void ErrorHook(StatusType error)
146 {
147 
148 }
149 
150 ISR(TIMER2_OVF_vect)
151 {
152 
153 }
TaskType
enum tasks_e TaskType
Type for task reference.
Definition: TaskTypes.h:29
StatusType
enum StatusType_e StatusType
Type for status.
AlarmBaseType
volatile struct counter_s AlarmBaseType
Type for alarm base.
Definition: AlarmTypes.h:39
ErrorHook
void ErrorHook(StatusType error)
PostTask hook function.
Definition: App.c:784
GetAlarmBase
#define GetAlarmBase
Definition: OS_API.h:25
TickType
uint64_t TickType
Data type of counter values.
Definition: CounterTypes.h:21
StartupHook
void StartupHook(void)
Definition: App.c:702
GetTaskState
#define GetTaskState
Definition: OS_API.h:83
assert.h
Assert macros and functions.
SetAbsAlarm
#define SetAbsAlarm
Definition: OS_API.h:28
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
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_ID
@ E_OS_ID
Definition: Types.h:43
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.
E_OS_VALUE
@ E_OS_VALUE
Definition: Types.h:48