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