mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-03 03:43:00 +02:00
Rate-limit core0 card_status polling loops
This commit is contained in:
@@ -345,7 +345,13 @@ void driver_exec_finished_cont_ccid(uint8_t itf, uint16_t size_next, uint16_t of
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ccid_task(void) {
|
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++) {
|
for (uint8_t itf = 0; itf < ITF_SC_TOTAL; 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));
|
int status = card_status(sc_itf_to_usb_itf(itf));
|
||||||
if (status == PICOKEYS_OK) {
|
if (status == PICOKEYS_OK) {
|
||||||
driver_exec_finished_ccid(itf, finished_data_size);
|
driver_exec_finished_ccid(itf, finished_data_size);
|
||||||
@@ -353,6 +359,7 @@ void ccid_task(void) {
|
|||||||
else if (status == PICOKEYS_ERR_BLOCKED) {
|
else if (status == PICOKEYS_ERR_BLOCKED) {
|
||||||
driver_exec_timeout_ccid(itf);
|
driver_exec_timeout_ccid(itf);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (ccid_tx[itf].w_ptr > ccid_tx[itf].r_ptr) {
|
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) {
|
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) {
|
void hid_task(void) {
|
||||||
|
const uint32_t status_poll_interval_ms = 1;
|
||||||
|
static uint32_t last_status_poll_ms = 0;
|
||||||
#ifdef ENABLE_EMULATION
|
#ifdef ENABLE_EMULATION
|
||||||
uint16_t rx_len = emul_read(ITF_HID);
|
uint16_t rx_len = emul_read(ITF_HID);
|
||||||
if (rx_len) {
|
if (rx_len) {
|
||||||
@@ -620,6 +622,9 @@ void hid_task(void) {
|
|||||||
if (proc_pkt == 0) {
|
if (proc_pkt == 0) {
|
||||||
driver_process_usb_nopacket_hid();
|
driver_process_usb_nopacket_hid();
|
||||||
}
|
}
|
||||||
|
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);
|
int status = card_status(ITF_HID);
|
||||||
if (status == PICOKEYS_OK) {
|
if (status == PICOKEYS_OK) {
|
||||||
driver_exec_finished_hid(finished_data_size);
|
driver_exec_finished_hid(finished_data_size);
|
||||||
@@ -627,6 +632,7 @@ void hid_task(void) {
|
|||||||
else if (status == PICOKEYS_ERR_BLOCKED) {
|
else if (status == PICOKEYS_ERR_BLOCKED) {
|
||||||
send_keepalive();
|
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 (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) {
|
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) {
|
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()) {
|
if (!rest_core1_job_pending_load()) {
|
||||||
rest_route_handler_t handler = rest_background_job_pop();
|
rest_route_handler_t handler = rest_background_job_pop();
|
||||||
if (handler != NULL) {
|
if (handler != NULL) {
|
||||||
@@ -219,6 +221,12 @@ void rest_task(void) {
|
|||||||
}
|
}
|
||||||
return;
|
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);
|
int status = card_status(ITF_LWIP);
|
||||||
if (status != PICOKEYS_OK) {
|
if (status != PICOKEYS_OK) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user