mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-02 19:33:01 +02:00
Rate-limit core0 card_status polling loops
This commit is contained in:
@@ -345,13 +345,20 @@ void driver_exec_finished_cont_ccid(uint8_t itf, uint16_t size_next, uint16_t of
|
||||
}
|
||||
|
||||
void ccid_task(void) {
|
||||
const uint32_t status_poll_interval_ms = 1;
|
||||
static uint32_t last_status_poll_ms[8] = {0};
|
||||
uint32_t now_ms = board_millis();
|
||||
for (uint8_t itf = 0; itf < ITF_SC_TOTAL; itf++) {
|
||||
int status = card_status(sc_itf_to_usb_itf(itf));
|
||||
if (status == PICOKEYS_OK) {
|
||||
driver_exec_finished_ccid(itf, finished_data_size);
|
||||
}
|
||||
else if (status == PICOKEYS_ERR_BLOCKED) {
|
||||
driver_exec_timeout_ccid(itf);
|
||||
if (itf < (sizeof(last_status_poll_ms) / sizeof(last_status_poll_ms[0])) &&
|
||||
now_ms - last_status_poll_ms[itf] >= status_poll_interval_ms) {
|
||||
last_status_poll_ms[itf] = now_ms;
|
||||
int status = card_status(sc_itf_to_usb_itf(itf));
|
||||
if (status == PICOKEYS_OK) {
|
||||
driver_exec_finished_ccid(itf, finished_data_size);
|
||||
}
|
||||
else if (status == PICOKEYS_ERR_BLOCKED) {
|
||||
driver_exec_timeout_ccid(itf);
|
||||
}
|
||||
}
|
||||
if (ccid_tx[itf].w_ptr > ccid_tx[itf].r_ptr) {
|
||||
if (driver_write_ccid(itf, ccid_tx[itf].buffer + ccid_tx[itf].r_ptr, ccid_tx[itf].w_ptr - ccid_tx[itf].r_ptr) > 0) {
|
||||
|
||||
@@ -601,6 +601,8 @@ void driver_exec_finished_cont_hid(uint8_t itf, uint16_t size_next, uint16_t off
|
||||
}
|
||||
|
||||
void hid_task(void) {
|
||||
const uint32_t status_poll_interval_ms = 1;
|
||||
static uint32_t last_status_poll_ms = 0;
|
||||
#ifdef ENABLE_EMULATION
|
||||
uint16_t rx_len = emul_read(ITF_HID);
|
||||
if (rx_len) {
|
||||
@@ -620,12 +622,16 @@ void hid_task(void) {
|
||||
if (proc_pkt == 0) {
|
||||
driver_process_usb_nopacket_hid();
|
||||
}
|
||||
int status = card_status(ITF_HID);
|
||||
if (status == PICOKEYS_OK) {
|
||||
driver_exec_finished_hid(finished_data_size);
|
||||
}
|
||||
else if (status == PICOKEYS_ERR_BLOCKED) {
|
||||
send_keepalive();
|
||||
uint32_t now_ms = board_millis();
|
||||
if (now_ms - last_status_poll_ms >= status_poll_interval_ms) {
|
||||
last_status_poll_ms = now_ms;
|
||||
int status = card_status(ITF_HID);
|
||||
if (status == PICOKEYS_OK) {
|
||||
driver_exec_finished_hid(finished_data_size);
|
||||
}
|
||||
else if (status == PICOKEYS_ERR_BLOCKED) {
|
||||
send_keepalive();
|
||||
}
|
||||
}
|
||||
if (hid_tx[ITF_HID_CTAP].w_ptr > hid_tx[ITF_HID_CTAP].r_ptr && last_write_result[ITF_HID_CTAP] != WRITE_PENDING) {
|
||||
if (driver_write_hid(ITF_HID_CTAP, hid_tx[ITF_HID_CTAP].buffer + hid_tx[ITF_HID_CTAP].r_ptr, 64) > 0) {
|
||||
|
||||
@@ -209,6 +209,8 @@ static void send_json_error(rest_conn_t *conn, int status_code, const char *erro
|
||||
}
|
||||
|
||||
void rest_task(void) {
|
||||
const uint32_t status_poll_interval_ms = 1;
|
||||
static uint32_t last_status_poll_ms = 0;
|
||||
if (!rest_core1_job_pending_load()) {
|
||||
rest_route_handler_t handler = rest_background_job_pop();
|
||||
if (handler != NULL) {
|
||||
@@ -219,6 +221,12 @@ void rest_task(void) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
uint32_t now_ms = board_millis();
|
||||
if (now_ms - last_status_poll_ms < status_poll_interval_ms) {
|
||||
return;
|
||||
}
|
||||
last_status_poll_ms = now_ms;
|
||||
|
||||
int status = card_status(ITF_LWIP);
|
||||
if (status != PICOKEYS_OK) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user