Skip to content

Commit

Permalink
Remove recovery, might create more problems than solving things
Browse files Browse the repository at this point in the history
  • Loading branch information
kauwua committed Jun 9, 2024
1 parent 93f5062 commit 5b30426
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 52 deletions.
1 change: 0 additions & 1 deletion hydradancer/firmware_hydradancer/User/definitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ __attribute__((aligned(16))) volatile uint8_t boards_ready __attribute__((sectio
__attribute__((aligned(16))) volatile bool event_transfer_finished = true;
__attribute__((aligned(16))) volatile bool start_polling = false;
__attribute__((aligned(16))) volatile hydradancer_event_t _events_buffer[EVENT_QUEUE_SIZE] __attribute__((section(".DMADATA")));
uint64_t MAX_BUSY_WAIT_CYCLES = 1234567899; //set to a lower value in main, after bsp_init

HYDRA_POOL_DEF(ep_queue, ep_queue_member_t, 100);

Expand Down
3 changes: 0 additions & 3 deletions hydradancer/firmware_hydradancer/User/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
#define BLINK_USB3 (250) // Blink LED each 500ms (250*2)
#define BLINK_USB2 (1000) // Blink LED each 2000ms (1000*2)

#define MAX_BUSY_WAIT_CYCLES_MS 5
extern uint64_t MAX_BUSY_WAIT_CYCLES;

typedef struct __attribute__((packed))
{
uint8_t ep_in_status;
Expand Down
1 change: 0 additions & 1 deletion hydradancer/firmware_hydradancer/User/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ int main()
bsp_gpio_init();
/* Init BSP (MCU Frequency & SysTick) */
bsp_init(FREQ_SYS);
MAX_BUSY_WAIT_CYCLES = bsp_ms_nbcycles * (uint64_t)MAX_BUSY_WAIT_CYCLES_MS;

LOG_INIT(FREQ_SYS);
hydra_interrupt_queue_init();
Expand Down
51 changes: 4 additions & 47 deletions hydradancer/firmware_hydradancer/User/usb_emulation_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,45 +87,24 @@ bool _usb_emulation_endp0_passthrough_setup_callback(uint8_t* data)
uint8_t* ptr = ((ep_queue_member_t*)data)->ptr;
uint16_t size = ((ep_queue_member_t*)data)->size;

// we need to wait here, because we can't NAK a packet with PID setup
// the only accepted answer is ACK, so we have to store it and wait for Facedancer to be ready
uint64_t start = bsp_get_SysTickCNT();
uint64_t curr = 0;
uint64_t delta = 0;

while (hydradancer_status.ep_out_status & (0x01 << 0) && delta < MAX_BUSY_WAIT_CYCLES)
while (hydradancer_status.ep_out_status & (0x01 << 0))
{
if (start_polling)
hydradancer_send_event();
WWDG_SetCounter(0); // rearm the watchdog
curr = bsp_get_SysTickCNT();
delta = start - curr; // SysTickCNT is decremented so comparison is inverted
}

hydradancer_status_set_out(0);
endp_tx_set_new_buffer(&usb_device_1, endpoint_mapping[0], ptr, size);
write_event(EVENT_OUT_BUFFER_AVAILABLE, 0);

// wait for the packet to be transmitted or count to reach MAX_COUNT
// we still miss some interrupts, count attemps to mitigate this issue by considering
// the packet has been sent after some time
start = bsp_get_SysTickCNT();
curr = 0;
delta = 0;
while (hydradancer_status.ep_out_status & (0x01 << 0) && delta < MAX_BUSY_WAIT_CYCLES)
while (hydradancer_status.ep_out_status & (0x01 << 0))
{
if (start_polling)
hydradancer_send_event();
WWDG_SetCounter(0); // rearm the watchdog
curr = bsp_get_SysTickCNT();
delta = start - curr; // SysTickCNT is decremented so comparison is inverted
}

if (delta >= MAX_BUSY_WAIT_CYCLES)
{
LOG_IF_LEVEL(LOG_LEVEL_CRITICAL, "_usb_emulation_endp0_passthrough_setup_callback RECOVERY\r\n");
hydradancer_recover_out_interrupt(0);
}
return true;
}

Expand Down Expand Up @@ -159,24 +138,13 @@ static bool _usb_emulation_endp_rx_callback(uint8_t* data)
endp_tx_set_new_buffer(&usb_device_1, endpoint_mapping[ep_queue_member->ep_num], ep_queue_member->ptr, ep_queue_member->size);
write_event(EVENT_OUT_BUFFER_AVAILABLE, ep_queue_member->ep_num);

uint64_t start = bsp_get_SysTickCNT();
uint64_t curr = 0;
uint64_t delta = 0;

while (hydradancer_status.ep_out_status & (0x01 << ep_queue_member->ep_num) && delta < MAX_BUSY_WAIT_CYCLES)
while (hydradancer_status.ep_out_status & (0x01 << ep_queue_member->ep_num))
{
if (start_polling)
hydradancer_send_event();
WWDG_SetCounter(0); // rearm the watchdog
curr = bsp_get_SysTickCNT();
delta = start - curr; // SysTickCNT is decremented so comparison is inverted
}

if (delta >= MAX_BUSY_WAIT_CYCLES)
{
LOG_IF_LEVEL(LOG_LEVEL_CRITICAL, "_usb_emulation_endp_rx_callback RECOVERY\r\n");
hydradancer_recover_out_interrupt(ep_queue_member->ep_num);
}
return true;
}

Expand Down Expand Up @@ -220,24 +188,13 @@ bool _usb_emulation_endp0_rx_callback(uint8_t* data)
endp_tx_set_new_buffer(&usb_device_1, endpoint_mapping[0], ptr, size);
write_event(EVENT_OUT_BUFFER_AVAILABLE, 0);

uint64_t start = bsp_get_SysTickCNT();
uint64_t curr = 0;
uint64_t delta = 0;

while (hydradancer_status.ep_out_status & (0x01 << 0) && delta < MAX_BUSY_WAIT_CYCLES)
while (hydradancer_status.ep_out_status & (0x01 << 0))
{
if (start_polling)
hydradancer_send_event();
WWDG_SetCounter(0); // rearm the watchdog
curr = bsp_get_SysTickCNT();
delta = start - curr; // SysTickCNT is decremented so comparison is inverted
}

if (delta >= MAX_BUSY_WAIT_CYCLES)
{
LOG_IF_LEVEL(LOG_LEVEL_CRITICAL, "_usb_emulation_endp0_rx_callback RECOVERY\r\n");
hydradancer_recover_out_interrupt(0);
}
return true;
}

Expand Down

0 comments on commit 5b30426

Please sign in to comment.