Skip to content

Commit

Permalink
working on gmbitbang
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Jun 10, 2018
1 parent 875c2bd commit a577583
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 6 deletions.
81 changes: 75 additions & 6 deletions board/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,83 @@ void CAN3_SCE_IRQHandler() { can_sce(CAN3); }

#endif

void set_bitbanged_gmlan(int val) {
if (val) {
GPIOB->ODR |= (1 << 13);
} else {
GPIOB->ODR &= ~(1 << 13);
}
}

void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
puts("called bitbang_gmlan\n");
puth(can_num_lookup[3]);
puts("\n");
char test_pkt[] = \
{0, // SOF
0,0,0,0, // ID10-ID7
1, // bitstuff
0,0,1,0,1,0,0, // ID6-ID0
0, // RTR
0, // IDE
0, // reserved
1, // bitstuff
0,0,0,1, // len
0,0,0,0,0, // 1st byte 7-3
1, // bitstuff
0,0,1, // 1st byte 2-0

// start CRC
0,1,0,0,0,0,1,1,0,0,0,0,0,
1, // bitstuff
0,0, // CRC field
1, // CRC delimiter

1, // ACK
1, // ACK delimiter
1,1,1,1,1,1,1, // EOF
1,1,1, // IFS
};
/*char test_pkt[] = {
0,1,0,1, 0,1,0,1, 0,1,0,1,
1,1,1,1,
0,1,0,1, 0,1,0,1, 0,1,0,1,
0,0,0,0,0,0,0,0,
0,1,0,1, 0,1,0,1, 0,1,0,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,0,1, 0,1,0,1, 0,1,0,1,};*/

#define SPEEED 30

// bitbang loop
set_bitbanged_gmlan(1); // recessive
set_gpio_mode(GPIOB, 13, MODE_OUTPUT);
enter_critical_section();
int init = TIM2->CNT;
for (int i = 0; i < sizeof(test_pkt); i++) {
while ((TIM2->CNT - init) < (SPEEED*i));
set_bitbanged_gmlan(test_pkt[i]);
}
exit_critical_section();
set_gpio_mode(GPIOB, 13, MODE_INPUT);

puts("bitbang done\n");
}

void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number) {
if (safety_tx_hook(to_push) && !can_autobaud_enabled[bus_number]) {
if (bus_number < BUS_MAX) {
// add CAN packet to send queue
// bus number isn't passed through
to_push->RDTR &= 0xF;
can_push(can_queues[bus_number], to_push);
process_can(CAN_NUM_FROM_BUS_NUM(bus_number));
//if (bus_number == 3) { //&& can_num_lookup[3] == -1) {
// TODO: why uint8 bro? only int8?
if (bus_number == 3 && can_num_lookup[3] == 0xFF) {
bitbang_gmlan(to_push);
} else {
if (bus_number < BUS_MAX) {
// add CAN packet to send queue
// bus number isn't passed through
to_push->RDTR &= 0xF;
can_push(can_queues[bus_number], to_push);
process_can(CAN_NUM_FROM_BUS_NUM(bus_number));
}
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions tests/gmbitbang/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
import time
from panda import Panda

p1 = Panda('430026000951363338383037')
p2 = Panda('380016000551363338383037')

# this is a test, no safety
p1.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
p2.set_safety_mode(Panda.SAFETY_ALLOUTPUT)

# get versions
print(p1.get_version())
print(p2.get_version())

# this sets bus 2 to actually be GMLAN
p2.set_gmlan(bus=2)

# send w bitbang then without
p1.set_gmlan(bus=None)
p1.can_send(20, "\x01", bus=3)
p1.set_gmlan(bus=2)
p1.can_send(20, "\x01", bus=3)
#time.sleep(0.1)
#p1.set_gmlan(bus=None)
#p1.can_send(20, "\x01", bus=3)

# test echo
# (to send on GMLAN, set bus=3)
time.sleep(0.1)
print p2.can_recv()

0 comments on commit a577583

Please sign in to comment.