Skip to content

Commit 986a14c

Browse files
committed
don't alias pointers
1 parent 9b8472e commit 986a14c

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

board/pedal/README

+22
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,25 @@ The comma pedal is a gas pedal interceptor for Honda/Acura. It allows you to "vi
44

55
This is the open source software. Open source hardware coming soon.
66

7+
== Test Plan ==
8+
9+
* Startup
10+
** Confirm STATE_FAULT_STARTUP
11+
* Timeout
12+
** Send value
13+
** Confirm value is output
14+
** Stop sending messages
15+
** Confirm value is passthru after 100ms
16+
** Confirm STATE_FAULT_TIMEOUT
17+
* Random values
18+
** Send random 6 byte messages
19+
** Confirm random values cause passthru
20+
** Confirm STATE_FAULT_BAD_CHECKSUM
21+
* Same message lockout
22+
** Send same message repeated
23+
** Confirm timeout behavior
24+
* Don't set enable
25+
** Confirm no output
26+
* Set enable and values
27+
** Confirm output
28+

board/pedal/main.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ uint32_t current_index = 0;
121121
#define STATE_FAULT_SEND 2
122122
#define STATE_FAULT_SCE 3
123123
#define STATE_FAULT_STARTUP 4
124+
#define STATE_FAULT_TIMEOUT 5
124125
uint8_t state = STATE_FAULT_STARTUP;
125126

126127
void CAN1_RX0_IRQHandler() {
@@ -146,15 +147,14 @@ void CAN1_RX0_IRQHandler() {
146147
if (enable) {
147148
gas_set_0 = value_0;
148149
gas_set_1 = value_1;
149-
// clear the timeout
150-
timeout = 0;
151150
} else {
151+
// clear the fault state if values are 0
152+
if (value_0 == 0 && value_1 == 0) state = STATE_GOOD;
152153
gas_set_0 = gas_set_1 = 0;
153-
// clear the fault state
154-
state = STATE_GOOD;
155154
}
155+
// clear the timeout
156+
timeout = 0;
156157
}
157-
// TODO: better lockout? prevents same spam
158158
current_index = index;
159159
} else {
160160
// wrong checksum = fault
@@ -195,9 +195,8 @@ void TIM3_IRQHandler() {
195195
dat[3] = (pdl1>>0)&0xFF;
196196
dat[4] = state;
197197
dat[5] = can_cksum(dat, 5, CAN_GAS_OUTPUT, pkt_idx);
198-
dat[6] = dat[7] = 0;
199-
CAN->sTxMailBox[0].TDLR = ((uint32_t*)dat)[0];
200-
CAN->sTxMailBox[0].TDHR = ((uint32_t*)dat)[1];
198+
CAN->sTxMailBox[0].TDLR = dat[0] | (dat[1]<<8) | (dat[2]<<16) | (dat[3]<<24);
199+
CAN->sTxMailBox[0].TDHR = dat[4] | (dat[5]<<8);
201200
CAN->sTxMailBox[0].TDTR = 6; // len of packet is 5
202201
CAN->sTxMailBox[0].TIR = (CAN_GAS_OUTPUT << 21) | 1;
203202
++pkt_idx;
@@ -217,7 +216,11 @@ void TIM3_IRQHandler() {
217216
TIM3->SR = 0;
218217

219218
// up timeout for gas set
220-
timeout = min(timeout+1, MAX_TIMEOUT);
219+
if (timeout == MAX_TIMEOUT) {
220+
state = STATE_FAULT_TIMEOUT;
221+
} else {
222+
timeout += 1;
223+
}
221224
}
222225

223226
// ***************************** main code *****************************

0 commit comments

Comments
 (0)