-
Notifications
You must be signed in to change notification settings - Fork 0
/
out.cpp
60 lines (53 loc) · 1.65 KB
/
out.cpp
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
#include "ch.h"
#include "hal.h"
#include "out.h"
#include "Can.h"
uint8_t digitalOutputs[(4 + 7) / 8] = {0}; // Definition and initialization
static THD_WORKING_AREA(waOutThread, 128);
static THD_FUNCTION(OutThread, p)
{
(void)p;
chRegSetThreadName("Out_Thread");
while (true)
{
chMtxLock(&digitalOutputsMutex);
for(uint8_t i = 0; i < 4; i++)
{
switch (i)
{
case 0:
if(ODCZYTAJ_BIT(digitalOutputs, i)) palSetPad(GPIOD, 0);
else palClearPad(GPIOD, 0);
break;
case 1:
if(ODCZYTAJ_BIT(digitalOutputs, i)) palSetPad(GPIOC, 13);
else palClearPad(GPIOC, 13);
break;
case 2:
if(ODCZYTAJ_BIT(digitalOutputs, i)) palSetPad(GPIOC, 14);
else palClearPad(GPIOC, 14);
break;
case 3:
if(ODCZYTAJ_BIT(digitalOutputs, i)) palSetPad(GPIOC, 15);
else palClearPad(GPIOC, 15);
break;
default:
break;
}
}
chMtxUnlock(&digitalOutputsMutex);
chThdSleepMilliseconds(250);
}
}
void startOutThread(void)
{
palSetPadMode(GPIOD, 0, PAL_MODE_OUTPUT_PUSHPULL);
palClearPad(GPIOD, 0);
palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL);
palClearPad(GPIOC, 13);
palSetPadMode(GPIOC, 14, PAL_MODE_OUTPUT_PUSHPULL);
palClearPad(GPIOC, 14);
palSetPadMode(GPIOC, 15, PAL_MODE_OUTPUT_PUSHPULL);
palClearPad(GPIOC, 15);
chThdCreateStatic(waOutThread, sizeof(waOutThread), NORMALPRIO, OutThread, NULL);
}