mirror of https://github.com/commaai/panda.git
clean up can interrupts, still failing
This commit is contained in:
parent
e8b38fc426
commit
b737d987cb
|
@ -100,8 +100,10 @@ void can_init(uint8_t bus_number) {
|
|||
CAN->FMR &= ~(CAN_FMR_FINIT);
|
||||
|
||||
// enable all CAN interrupts
|
||||
CAN->IER = 0xFFFFFFFF;
|
||||
//CAN->IER = 0xFFFFFFFF;
|
||||
//CAN->IER = CAN_IER_TMEIE | CAN_IER_FMPIE0 | CAN_IER_FMPIE1;
|
||||
//CAN->IER = CAN_IER_TMEIE;
|
||||
CAN->IER = CAN_IER_TMEIE | CAN_IER_FMPIE0;
|
||||
}
|
||||
|
||||
void can_init_all() {
|
||||
|
|
49
board/main.c
49
board/main.c
|
@ -50,26 +50,36 @@ can_ring *can_queues[] = {&can_tx1_q, &can_tx2_q, &can_tx3_q};
|
|||
// ********************* interrupt safe queue *********************
|
||||
|
||||
int pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
|
||||
int ret = 0;
|
||||
|
||||
__disable_irq();
|
||||
if (q->w_ptr != q->r_ptr) {
|
||||
*elem = q->elems[q->r_ptr];
|
||||
if ((q->r_ptr + 1) == q->fifo_size) q->r_ptr = 0;
|
||||
else q->r_ptr += 1;
|
||||
return 1;
|
||||
ret = 1;
|
||||
}
|
||||
return 0;
|
||||
__enable_irq();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
|
||||
int ret = 0;
|
||||
uint32_t next_w_ptr;
|
||||
|
||||
__disable_irq();
|
||||
if ((q->w_ptr + 1) == q->fifo_size) next_w_ptr = 0;
|
||||
else next_w_ptr = q->w_ptr + 1;
|
||||
if (next_w_ptr != q->r_ptr) {
|
||||
q->elems[q->w_ptr] = *elem;
|
||||
q->w_ptr = next_w_ptr;
|
||||
return 1;
|
||||
ret = 1;
|
||||
}
|
||||
__enable_irq();
|
||||
|
||||
puts("push failed!\n");
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ***************************** serial port queues *****************************
|
||||
|
@ -254,13 +264,26 @@ void process_can(uint8_t can_number) {
|
|||
#endif
|
||||
|
||||
// add successfully transmitted message to my fifo
|
||||
if ((CAN->TSR & CAN_TSR_TXOK0) == CAN_TSR_TXOK0) {
|
||||
CAN_FIFOMailBox_TypeDef to_push;
|
||||
to_push.RIR = CAN->sTxMailBox[0].TIR;
|
||||
to_push.RDTR = (CAN->sTxMailBox[0].TDTR & 0xFFFF000F) | ((CAN_BUS_RET_FLAG | bus_number) << 4);
|
||||
to_push.RDLR = CAN->sTxMailBox[0].TDLR;
|
||||
to_push.RDHR = CAN->sTxMailBox[0].TDHR;
|
||||
push(&can_rx_q, &to_push);
|
||||
if ((CAN->TSR & CAN_TSR_RQCP0) == CAN_TSR_RQCP0) {
|
||||
if ((CAN->TSR & CAN_TSR_TXOK0) == CAN_TSR_TXOK0) {
|
||||
CAN_FIFOMailBox_TypeDef to_push;
|
||||
to_push.RIR = CAN->sTxMailBox[0].TIR;
|
||||
to_push.RDTR = (CAN->sTxMailBox[0].TDTR & 0xFFFF000F) | ((CAN_BUS_RET_FLAG | bus_number) << 4);
|
||||
to_push.RDLR = CAN->sTxMailBox[0].TDLR;
|
||||
to_push.RDHR = CAN->sTxMailBox[0].TDHR;
|
||||
push(&can_rx_q, &to_push);
|
||||
}
|
||||
|
||||
if ((CAN->TSR & CAN_TSR_TERR0) == CAN_TSR_TERR0) {
|
||||
puts("CAN TX ERROR!\n");
|
||||
}
|
||||
|
||||
if ((CAN->TSR & CAN_TSR_ALST0) == CAN_TSR_ALST0) {
|
||||
puts("CAN TX ARBITRATION LOST!\n");
|
||||
}
|
||||
|
||||
// clear interrupt
|
||||
CAN->TSR |= CAN_TSR_RQCP0;
|
||||
}
|
||||
|
||||
// check for empty mailbox
|
||||
|
@ -274,9 +297,6 @@ void process_can(uint8_t can_number) {
|
|||
CAN->sTxMailBox[0].TIR = to_send.RIR;
|
||||
}
|
||||
}
|
||||
|
||||
// clear interrupt
|
||||
CAN->TSR |= CAN_TSR_RQCP0;
|
||||
}
|
||||
|
||||
void send_can(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number);
|
||||
|
@ -311,7 +331,6 @@ void can_rx(uint8_t can_number) {
|
|||
|
||||
// modify RDTR for our API
|
||||
to_push.RDTR = (to_push.RDTR & 0xFFFF000F) | (bus_number << 4);
|
||||
|
||||
safety_rx_hook(&to_push);
|
||||
|
||||
#ifdef PANDA
|
||||
|
|
|
@ -113,9 +113,9 @@ class Panda(object):
|
|||
cmd = "make clean"
|
||||
else:
|
||||
cmd = "true"
|
||||
os.system("cd %s && %s && make" % (os.path.join(BASEDIR, "board"), cmd))
|
||||
# TODO: check for errors
|
||||
ret = os.system("cd %s && %s && make" % (os.path.join(BASEDIR, "board"), cmd))
|
||||
time.sleep(1)
|
||||
return ret==0
|
||||
|
||||
@staticmethod
|
||||
def list():
|
||||
|
|
|
@ -8,7 +8,7 @@ from nose.tools import timed, assert_equal, assert_less, assert_greater
|
|||
# must run first
|
||||
def test_build_download_connect():
|
||||
# download the latest code
|
||||
Panda.program(True)
|
||||
assert(Panda.program(True))
|
||||
|
||||
# connect to the panda
|
||||
p = Panda()
|
||||
|
@ -81,19 +81,24 @@ def test_reliability():
|
|||
p.set_can_loopback(True)
|
||||
p.set_can_speed_kbps(0, 1000)
|
||||
|
||||
addrs = range(100, 100+MSG_COUNT)
|
||||
ts = [(j, 0, "\xaa"*8, 0) for j in addrs]
|
||||
|
||||
# 100 loops
|
||||
for i in range(LOOP_COUNT):
|
||||
st = time.time()
|
||||
p.can_send_many([(0x1aa, 0, "\xaa"*8, 0)]*MSG_COUNT)
|
||||
|
||||
p.can_send_many(ts)
|
||||
r = []
|
||||
while len(r) < 200 and (time.time() - st) < 3:
|
||||
while len(r) < 200 and (time.time() - st) < 0.5:
|
||||
r.extend(p.can_recv())
|
||||
|
||||
sent_echo = filter(lambda x: x[3] == 0x80, r)
|
||||
loopback_resp = filter(lambda x: x[3] == 0, r)
|
||||
|
||||
assert_equal(len(sent_echo), 100)
|
||||
assert_equal(len(loopback_resp), 100)
|
||||
assert_equal(sorted(map(lambda x: x[0], loopback_resp)), addrs)
|
||||
assert_equal(sorted(map(lambda x: x[0], sent_echo)), addrs)
|
||||
assert_equal(len(r), 200)
|
||||
|
||||
# take sub 20ms
|
||||
et = (time.time()-st)*1000.0
|
||||
|
|
Loading…
Reference in New Issue