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