SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
io.cpp
1
#include "io.h"
2
#include "stdint.h"
3
4
namespace
IO {
5
6
char
*pin_buf[PIN_BYTE_ALLOC + 1];
7
8
// TODO: mux each value, given id
9
10
#define WRITE_DIGITAL digitalWriteFast
11
#define WRITE_ANALOG analogWrite
12
#define READ_DIGITAL digitalReadFast
13
#define READ_ANALOG analogRead
14
#define WRITE_VIRT_DIGITAL setBit
15
#define WRITE_VIRT_ANALOG setUInt
16
#define READ_VIRT_DIGITAL getBit
17
#define READ_VIRT_ANALOG getUInt
18
19
#define TYPE_SEL_ANALOG uint32_t
20
#define TYPE_SEL_DIGITAL bool
21
22
#define __IO_BUF_FUNC_SET_double(x, _) setDouble(x)
23
#define __IO_BUF_FUNC_SET_uint64_t(x, _) setULong(x)
24
#define __IO_BUF_FUNC_SET_int64_t(x, _) setLong(x)
25
#define __IO_BUF_FUNC_SET_float setFloat
26
#define __IO_BUF_FUNC_SET_uint32_t setUInt
27
#define __IO_BUF_FUNC_SET_int32_t setInt
28
#define __IO_BUF_FUNC_SET_uint16_t setUShort
29
#define __IO_BUF_FUNC_SET_int16_t setShort
30
#define __IO_BUF_FUNC_SET_uint8_t setUByte
31
#define __IO_BUF_FUNC_SET_int8_t setByte
32
#define __IO_BUF_FUNC_SET_bool setBit
33
34
#define __IO_BUF_FUNC_GET_double getDouble
35
#define __IO_BUF_FUNC_GET_uint64_t getULong
36
#define __IO_BUF_FUNC_GET_int64_t getLong
37
#define __IO_BUF_FUNC_GET_float getFloat
38
#define __IO_BUF_FUNC_GET_uint32_t getUInt
39
#define __IO_BUF_FUNC_GET_int32_t getInt
40
#define __IO_BUF_FUNC_GET_uint16_t getUShort
41
#define __IO_BUF_FUNC_GET_int16_t getShort
42
#define __IO_BUF_FUNC_GET_uint8_t getUByte
43
#define __IO_BUF_FUNC_GET_int8_t getByte
44
#define __IO_BUF_FUNC_GET_bool getBit
45
46
#define WRITE_GPIO_INTERNAL_INPUT(index, pin_no, name, ad_t)
47
#define WRITE_GPIO_INTERNAL_OUTPUT(index, pin_no, name, ad_t) \
48
inline void ACTIVE_NODE_WRITE::name(TYPE_SEL_##ad_t val) { \
49
*((TYPE_SEL_##ad_t *)(pin_buf + index)) = val; \
50
WRITE_##ad_t(pin_no, val); \
51
}
52
#define WRITE_VIRT_INTERNAL(pos, addr, name, ad_t) \
53
inline void ACTIVE_NODE_WRITE::name(TYPE_SEL_##ad_t val) { \
54
static auto buf = Canbus.getBuffer(addr); \
55
buf->WRITE_VIRT_##ad_t(val, pos); \
56
}
57
#define WRITE_SIG_INTERNAL(UID, pos, conv_t) \
58
inline void ACTIVE_NODE_WRITE::name(conv_t val) { \
59
static auto buf = Canbus.getBuffer(UID); \
60
buf->__IO_BUF_FUNC_SET_##conv_t(val, pos); \
61
}
62
63
#define READ_GPIO_INTERNAL(index, UID, node_name, name, bit_sz, pos, io_t, ie_t, ad_t, conv_t, is_virt, format) \
64
inline conv_t name() { \
65
return *((conv_t *)(values + index)) = READ_##ad_t(ID); \
66
}
67
68
#define READ_VIRT_INTERNAL(index, UID, node_name, name, bit_sz, pos, io_t, ie_t, ad_t, conv_t, is_virt, format) \
69
inline conv_t name() { \
70
static auto buf = Canbus.getBuffer(UID); \
71
return buf->READ_VIRT_##ad_t(pos); \
72
}
73
74
#define READ_SIG_INTERNAL(index, UID, node_name, name, bit_sz, pos, io_t, ie_t, ad_t, conv_t, is_virt, format) \
75
inline conv_t name() { \
76
static auto buf = Canbus.getBuffer(UID); \
77
return buf->__IO_BUF_FUNC_GET_##conv_t(pos); \
78
}
79
80
// TODO: External Source control
81
#define WRITE_GPIO_EXTERNAL_INPUT(pos, addr, name, ad_t)
82
#define WRITE_GPIO_EXTERNAL_OUTPUT(pos, addr, name, ad_t) \
83
inline void name(TYPE_SEL_##ad_t val) { \
84
static auto buf = Canbus.getBuffer(addr); \
85
buf->WRITE_VIRT_##ad_t(val, pos); \
86
}
87
88
#define WRITE_VIRT_EXTERNAL(pos, addr, name, ad_t) \
89
inline void name(TYPE_SEL_##ad_t val) { \
90
static auto buf = Canbus.getBuffer(addr); \
91
buf->WRITE_VIRT_##ad_t(val, pos); \
92
}
93
94
#define WRITE_SIG_EXTERNAL(index, UID, node_name, name, bit_sz, pos, io_t, ie_t, ad_t, conv_t, is_virt, format)
95
96
#define READ_GPIO_EXTERNAL(index, UID, node_name, name, bit_sz, pos, io_t, ie_t, ad_t, conv_t, is_virt, format) \
97
inline conv_t name() { \
98
static auto buf = Canbus.getBuffer(UID); \
99
return buf->READ_VIRT_##ad_t(pos); \
100
}
101
102
#define READ_VIRT_EXTERNAL(index, UID, node_name, name, bit_sz, pos, io_t, ie_t, ad_t, conv_t, is_virt, format) \
103
inline conv_t name() { \
104
static auto buf = Canbus.getBuffer(UID); \
105
return buf->READ_VIRT_##ad_t(pos); \
106
}
107
108
#define READ_SIG_EXTERNAL(index, UID, node_name, name, bit_sz, pos, io_t, ie_t, ad_t, conv_t, is_virt, format) \
109
inline conv_t name() { \
110
static auto buf = Canbus.getBuffer(UID); \
111
return buf->__IO_BUF_FUNC_GET_##conv_t(pos); \
112
}
113
114
#define _E2C(a, b) a##b
115
#define E2C(a, b) _E2C(a, b)
116
117
#define _GPIO(ie_t, io_t) WRITE_GPIO_##ie_t##io_t
118
#define _VIRT(ie_t) WRITE_VIRT_##ie_t
119
#define GPIO(pin_i, pin_no, node_n, name, io_t, ie_t, ad_t) _GPIO(ie_t, _##io_t)(pin_i, pin_no, name, ad_t)
120
#define VIRT(pin_i, pin_no, node_n, name, io_t, ie_t, ad_t) _VIRT(ie_t)(pin_i, pin_no, name, ad_t)
121
122
EVAL(FRONT_ECU_PINS)
123
EVAL(E2C(ACTIVE_NODE, _PINS))
124
125
#undef GPIO
126
#undef VIRT
127
128
void
receive_sync() {
129
}
130
131
void
run_sync() {
132
}
133
134
void
reset() {
135
memset(pin_buf, 0,
sizeof
(pin_buf));
136
// TODO: set all pins to their corresponding modes.
137
}
138
}
// namespace IO
libraries
IO
io.cpp
Generated by
1.9.8