SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
io.h
1
#include "
Canbus.h
"
2
3
#include "SDBC.def"
4
#include "WProgram.h"
5
6
namespace
IO {
7
8
#define ACTIVE_NODE_WRITE EXPAND_CONCAT(ACTIVE_NODE, _WRITE)
9
#define ACTIVE_NODE_READ EXPAND_CONCAT(ACTIVE_NODE, _READ)
10
#define ACTIVE_NODE_PINS EXPAND_CONCAT(ACTIVE_NODE, _PINS)
11
#define ACTIVE_NODE_SYNC_ EXPAND_CONCAT(ACTIVE_NODE, _SYNC_)
12
#define ACTIVE_NODE_SYNC_NODES EXPAND_CONCAT(ACTIVE_NODE, _SYNC_NODES)
13
14
#define PIN_ANALOG_INPUT(name)
15
#define PIN_DIGITAL_INPUT(name)
16
#define PIN_ANALOG_OUTPUT(name) inline void name(uint32_t val);
17
#define PIN_DIGITAL_OUTPUT(name) inline void name(bool val);
18
// GPIO Pin, Node owner name, name of pin, INPUT|OUTPUT, INTERNAL|EXTERNAL, ANALOG|DIGITAL
19
#define GPIO(pin_i, pin_no, node_n, name, io_t, ie_t, ad_t) PIN_##ad_t##_##io_t(name)
20
#define VIRT(pin_i, pin_no, node_n, name, io_t, ie_t, ad_t) PIN_##ad_t##_##io_t(name)
21
22
#define SIG_INTERNAL(address, node_n, name, bits, pos, conv_t, format) inline void name(conv_t val);
23
#define SIG_EXTERNAL(address, node_n, name, bits, pos, conv_t, format)
24
// Message address, node_name, name, bit-size, byte/bit pos, INTERNAL|EXTERNAL, conversion type, format
25
#define __SIG(address, node_n, name, bits, pos, ie_t, conv_t, format) SIG_##ie_t(address, node_n, name, bits, pos, conv_t, format)
26
#define SIG(address, node_n, name, bits, pos, ie_t, conv_t, format) __SIG(address, node_n, name, bits, pos, ie_t, conv_t, format)
27
28
// SYNC NODE struct generator
29
#define NODE_true_EXTERNAL(node_name) \
30
struct node_name { \
31
EXPAND_CONCAT(ACTIVE_NODE_SYNC_, node_name) \
32
} node_name;
33
#define NODE_true_INTERNAL(name)
34
#define NODE_false_INTERNAL(name)
35
#define NODE_false_EXTERNAL(name)
36
#define __NODE(node_name, logic, ie_t) NODE_##logic##_##ie_t(node_name)
37
#define NODE(node_name, logic, ie_t) __NODE(node_name, logic, ie_t)
38
39
// MSG signal extractor/container
40
#define MSG_true(c, addr, name, sig_c, sig_def, ie_t) \
41
struct name { \
42
sig_def \
43
} name;
44
#define MSG_false(c, addr, name, sig_c, sig_def, ie_t) sig_def
45
46
#define MSG(c, addr, name, sig_c, sig_def, ie_t, contained) MSG_##contained(c, addr, name, sig_c, sig_def, ie_t)
47
48
// NODE WRITE
49
struct
ACTIVE_NODE_WRITE
{
50
ACTIVE_NODE_PINS
51
EXPAND_CONCAT(ACTIVE_NODE, _MSGS)
52
EVAL(ACTIVE_NODE_SYNC_NODES)
53
#undef NODE_true_EXTERNAL
54
#define NODE_true_EXTERNAL(name)
55
EVAL(NODES)
56
};
57
58
#undef PIN_ANALOG_INPUT
59
#undef PIN_DIGITAL_INPUT
60
#undef PIN_ANALOG_OUTPUT
61
#undef PIN_DIGITAL_OUTPUT
62
#undef SIG_INTERNAL
63
#undef SIG_EXTERNAL
64
#undef NODE_true_EXTERNAL
65
#undef NODE_false_EXTERNAL
66
67
#define PIN_ANALOG_INPUT(name) inline uint32_t name();
68
#define PIN_DIGITAL_INPUT(name) inline bool name();
69
#define PIN_ANALOG_OUTPUT(name) inline uint32_t name();
70
#define PIN_DIGITAL_OUTPUT(name) inline bool name();
71
#define SIG_INTERNAL(address, node_n, name, bits, pos, conv_t, format) inline conv_t name();
72
#define SIG_EXTERNAL(address, node_n, name, bits, pos, conv_t, format) inline conv_t name();
73
74
// Expose CAN signals
75
#define NODE_true_EXTERNAL(node_name) \
76
struct node_name { \
77
EXPAND_CONCAT(ACTIVE_NODE_SYNC_, node_name) \
78
EXPAND_CONCAT(node_name, _MSGS) \
79
} node_name;
80
81
// Expose CAN signals
82
#define NODE_false_EXTERNAL(node_name) \
83
struct node_name { \
84
EXPAND_CONCAT(node_name, _MSGS) \
85
} node_name;
86
87
// NODE READ
88
struct
ACTIVE_NODE_READ
{
89
ACTIVE_NODE_PINS
90
EXPAND_CONCAT(ACTIVE_NODE, _MSGS)
91
EVAL(ACTIVE_NODE_SYNC_NODES)
92
#undef NODE_true_EXTERNAL
93
#define NODE_true_EXTERNAL(name)
94
EVAL(NODES)
95
};
96
97
static
ACTIVE_NODE_WRITE
WRITE;
98
static
ACTIVE_NODE_READ
READ;
99
100
void
reset();
101
102
#undef __NODE
103
#undef NODE
104
#undef MSG
105
#undef MSG_true
106
#undef MSG_false
107
#undef __SIG
108
#undef SIG_INTERNAL
109
#undef SIG_EXTERNAL
110
#undef VIRT
111
#undef GPIO
112
#undef PIN_ANALOG_INPUT
113
#undef PIN_DIGITAL_INPUT
114
#undef PIN_ANALOG_OUTPUT
115
#undef PIN_DIGITAL_OUTPUT
116
117
}
// namespace IO
118
119
void
test() {
120
// IO::WRITE.WHEEL_SPEED_BACK_LEFT(25);
121
// IO::WRITE.ONBOARD_LED(true);
122
// IO::WRITE.FRONT_ECU.ONBOARD_LED(true);
123
// IO::READ.FRONT_ECU.WHEEL_SPEED_FRONT_LEFT();
124
// IO::READ.MC0.FAULTS.FAULT_GEN_5();
125
}
Canbus.h
FlexCAN_T4 wrapper.
IO::ACTIVE_NODE_READ
Definition
io.h:88
IO::ACTIVE_NODE_WRITE
Definition
io.h:49
libraries
IO
io.h
Generated by
1.9.8