diff --git a/pio/can2040.pio b/pio/can2040.pio index c303b57..3842df8 100644 --- a/pio/can2040.pio +++ b/pio/can2040.pio @@ -18,22 +18,22 @@ // State machine "sync" code - clock and start/end of message signaling sync_recessive_edge: - jmp y--, sync_scan_edge ; cp=31,33,35 - jmp x--, sync_signal_sample ; cp=4 + jmp y--, sync_scan_edge ; cp=31,33,35,37 + jmp x--, sync_signal_sample ; cp=6 public sync_found_end_of_message: - set x, 10 [1] ; cp=5 + set x, 8 [1] ; cp=7 sync_loop_end_of_message: jmp pin sync_check_idle public sync_signal_start: irq set 0 sync_scan_edge: - jmp pin sync_recessive_edge ; cp=30,32,34 + jmp pin sync_recessive_edge ; cp=30,32,34,36 public sync_entry: irq clear 0 ; cp=1 sync_got_dominant: - set x, 9 [2] ; cp=2 + set x, 9 [4] ; cp=2 sync_signal_sample: - set y, 2 [18] ; cp=5 + set y, 3 [16] ; cp=7 irq set 4 [1] ; cp=24 jmp pin sync_scan_edge [3] ; cp=26 jmp sync_got_dominant [3] ; cp=30 @@ -85,7 +85,7 @@ public tx_conflict: // Setup for "sync" state machine .program sm_sync_setup set pindirs, 0 - // CPU pushes 106 into tx fifo - to set OSR for alternative slow start mode + // CPU pushes 104 into tx fifo - to set OSR for alternative slow start mode pull ;jmp sync_got_dominant @@ -149,7 +149,7 @@ sync_signal_sample: jmp sync_got_dominant sync_scan_edge: - set y, 2 + set y, 3 sync_loop_scan_edge: jmp pin sync_recessive_edge jmp sync_got_dominant @@ -159,7 +159,7 @@ sync_recessive_edge: jmp sync_found_end_of_message sync_found_end_of_message: - set x, 10 + set x, 8 sync_loop_end_of_message: jmp pin sync_check_idle jmp sync_signal_start diff --git a/src/can2040.c b/src/can2040.c index 2614937..6a029cd 100644 --- a/src/can2040.c +++ b/src/can2040.c @@ -84,13 +84,13 @@ rp2040_gpio_peripheral(uint32_t gpio, int func, int pull_up) static const uint16_t can2040_program_instructions[] = { 0x0085, // 0: jmp y--, 5 0x0048, // 1: jmp x--, 8 - 0xe12a, // 2: set x, 10 [1] + 0xe129, // 2: set x, 9 [1] 0x00cc, // 3: jmp pin, 12 0xc000, // 4: irq nowait 0 0x00c0, // 5: jmp pin, 0 0xc040, // 6: irq clear 0 - 0xe229, // 7: set x, 9 [2] - 0xf242, // 8: set y, 2 [18] + 0xe429, // 7: set x, 9 [4] + 0xf043, // 8: set y, 3 [16] 0xc104, // 9: irq nowait 4 [1] 0x03c5, // 10: jmp pin, 5 [3] 0x0307, // 11: jmp 7 [3] @@ -137,7 +137,7 @@ pio_sync_setup(struct can2040 *cd) | cd->gpio_rx << PIO_SM0_PINCTRL_SET_BASE_LSB); sm->instr = 0xe080; // set pindirs, 0 sm->pinctrl = 0; - pio_hw->txf[0] = PIO_CLOCK_PER_BIT / 2 * 7 - 5 - 1; + pio_hw->txf[0] = 8 + 6 * PIO_CLOCK_PER_BIT / 2; sm->instr = 0x80a0; // pull block sm->instr = can2040_offset_sync_entry; // jmp sync_entry }