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