-
Notifications
You must be signed in to change notification settings - Fork 13
/
Appli.c
112 lines (90 loc) · 2.52 KB
/
Appli.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// *****************************************************************************
// Filename : Appli.c
//
// Core : STM32F100RB Cortex(R)-M3
//
// Board : STM32VLDISCOVERY
//
// Compiler : ARM(R) Compiler v5.06 for uVision (Keil)
//
// Author : Chalandi Amine
//
// Owner : Chalandi Amine
//
// Date : 04.09.2017
//
// Description : Main function
//
// License : GNU General Public License v3.0
//
// *****************************************************************************
#include"GPIO.h"
#include"TCB.h"
#include"OsAPIs.h"
static void Appli_LedInit(void);
#define TURN_ON_LED_BLUE() GPIOC_ODR.ODR8 = 1
#define TURN_OFF_LED_BLUE() GPIOC_ODR.ODR8 = 0
#define TURN_ON_LED_GREEN() GPIOC_ODR.ODR9 = 1
#define TURN_OFF_LED_GREEN() GPIOC_ODR.ODR9 = 0
#define TOGGLE_BLUE_LED() { OS_DisableAllInterrupts(); GPIOC_ODR.ODR8 ^= 1; OS_EnableAllInterrupts(); }
#define TOGGLE_GREEN_LED() { OS_DisableAllInterrupts(); GPIOC_ODR.ODR9 ^= 1; OS_EnableAllInterrupts(); }
int main(void)
{
Appli_LedInit();
OS_StartOS(APP_MODE_DEFAULT);
return(0);
}
static void Appli_LedInit(void)
{
/* Set PC8 and PC9 output mode */
GPIOC_CRH.CN8 = 0;
GPIOC_CRH.MODE8 = 3;
GPIOC_CRH.CN9 = 0;
GPIOC_CRH.MODE9 = 3;
}
TASK(T1)
{
TURN_ON_LED_BLUE();
const OsEventMaskType OsWaitEventMask = (OsEventMaskType) EVT_BLINK_BLUE_LED;
(void)OS_SetRelAlarm(ALARM_BLUE_LED, 0, 997);
for(;;)
{
OsEventMaskType Events = (OsEventMaskType) 0U;
if(E_OK == OS_WaitEvent(OsWaitEventMask))
{
(void) OS_GetEvent((OsTaskType)T1, &Events);
if((Events & EVT_BLINK_BLUE_LED) == EVT_BLINK_BLUE_LED)
{
OS_ClearEvent(EVT_BLINK_BLUE_LED);
TOGGLE_BLUE_LED();
}
}
else
{
OS_TerminateTask(); /* In case of error we switch off the task */
}
}
}
TASK(Idle)
{
TURN_ON_LED_GREEN();
const OsEventMaskType OsWaitEventMask = (OsEventMaskType) EVT_BLINK_GREEN_LED;
(void)OS_SetRelAlarm(ALARM_GREEN_LED,0, 503);
for(;;)
{
OsEventMaskType Events = (OsEventMaskType) 0U;
if(E_OK == OS_WaitEvent(OsWaitEventMask))
{
(void) OS_GetEvent((OsTaskType)Idle, &Events);
if((Events & EVT_BLINK_GREEN_LED) == EVT_BLINK_GREEN_LED)
{
OS_ClearEvent(EVT_BLINK_GREEN_LED);
TOGGLE_GREEN_LED();
}
}
else
{
OS_TerminateTask(); /* In case of error we switch off the task */
}
}
}