1
0
Fork 0

Implement split comms watchdog (#18599)

This commit is contained in:
Dasky 2022-10-06 10:52:42 +01:00 committed by GitHub
parent a9414f4840
commit c255174cf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 115 additions and 1 deletions

View file

@ -74,6 +74,46 @@ static inline bool usbIsActive(void) {
}
#endif
#if defined(SPLIT_WATCHDOG_ENABLE)
# if !defined(SPLIT_WATCHDOG_TIMEOUT)
# if defined(SPLIT_USB_TIMEOUT)
# define SPLIT_WATCHDOG_TIMEOUT (SPLIT_USB_TIMEOUT + 100)
# else
# define SPLIT_WATCHDOG_TIMEOUT 3000
# endif
# endif
# if defined(SPLIT_USB_DETECT)
_Static_assert(SPLIT_USB_TIMEOUT < SPLIT_WATCHDOG_TIMEOUT, "SPLIT_WATCHDOG_TIMEOUT should not be below SPLIT_USB_TIMEOUT.");
# endif
_Static_assert(SPLIT_MAX_CONNECTION_ERRORS > 0, "SPLIT_WATCHDOG_ENABLE requires SPLIT_MAX_CONNECTION_ERRORS be above 0 for a functioning disconnection check.");
static uint32_t split_watchdog_started = 0;
static bool split_watchdog_done = false;
void split_watchdog_init(void) {
split_watchdog_started = timer_read32();
}
void split_watchdog_update(bool done) {
split_watchdog_done = done;
}
bool split_watchdog_check(void) {
if (!is_transport_connected()) {
split_watchdog_done = false;
}
return split_watchdog_done;
}
void split_watchdog_task(void) {
if (!split_watchdog_done && !is_keyboard_master()) {
if (timer_elapsed32(split_watchdog_started) > SPLIT_WATCHDOG_TIMEOUT) {
mcu_reset();
}
}
}
#endif // defined(SPLIT_WATCHDOG_ENABLE)
#ifdef SPLIT_HAND_MATRIX_GRID
void matrix_io_delay(void);
@ -179,6 +219,9 @@ void split_pre_init(void) {
void split_post_init(void) {
if (!is_keyboard_master()) {
transport_slave_init();
#if defined(SPLIT_WATCHDOG_ENABLE)
split_watchdog_init();
#endif
}
}

View file

@ -14,3 +14,7 @@ void split_post_init(void);
bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]);
bool is_transport_connected(void);
void split_watchdog_update(bool done);
void split_watchdog_task(void);
bool split_watchdog_check(void);

View file

@ -84,6 +84,10 @@ enum serial_transaction_id {
PUT_POINTING_CPI,
#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
#if defined(SPLIT_WATCHDOG_ENABLE)
PUT_WATCHDOG,
#endif // defined(SPLIT_WATCHDOG_ENABLE)
#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
PUT_RPC_INFO,
PUT_RPC_REQ_DATA,

View file

@ -718,6 +718,36 @@ static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s
#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
////////////////////////////////////////////////////
// WATCHDOG
#if defined(SPLIT_WATCHDOG_ENABLE)
static bool watchdog_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
bool okay = true;
if (!split_watchdog_check()) {
okay = transport_write(PUT_WATCHDOG, &okay, sizeof(okay));
split_watchdog_update(okay);
}
return okay;
}
static void watchdog_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
split_watchdog_update(split_shmem->watchdog_pinged);
}
# define TRANSACTIONS_WATCHDOG_MASTER() TRANSACTION_HANDLER_MASTER(watchdog)
# define TRANSACTIONS_WATCHDOG_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(watchdog)
# define TRANSACTIONS_WATCHDOG_REGISTRATIONS [PUT_WATCHDOG] = trans_initiator2target_initializer(watchdog_pinged),
#else // defined(SPLIT_WATCHDOG_ENABLE)
# define TRANSACTIONS_WATCHDOG_MASTER()
# define TRANSACTIONS_WATCHDOG_SLAVE()
# define TRANSACTIONS_WATCHDOG_REGISTRATIONS
#endif // defined(SPLIT_WATCHDOG_ENABLE)
////////////////////////////////////////////////////
split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = {
@ -744,6 +774,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = {
TRANSACTIONS_OLED_REGISTRATIONS
TRANSACTIONS_ST7565_REGISTRATIONS
TRANSACTIONS_POINTING_REGISTRATIONS
TRANSACTIONS_WATCHDOG_REGISTRATIONS
// clang-format on
#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
@ -770,6 +801,7 @@ bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix
TRANSACTIONS_OLED_MASTER();
TRANSACTIONS_ST7565_MASTER();
TRANSACTIONS_POINTING_MASTER();
TRANSACTIONS_WATCHDOG_MASTER();
return true;
}
@ -789,6 +821,7 @@ void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[
TRANSACTIONS_OLED_SLAVE();
TRANSACTIONS_ST7565_SLAVE();
TRANSACTIONS_POINTING_SLAVE();
TRANSACTIONS_WATCHDOG_SLAVE();
}
#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)

View file

@ -188,6 +188,10 @@ typedef struct _split_shared_memory_t {
split_slave_pointing_sync_t pointing;
#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
#if defined(SPLIT_WATCHDOG_ENABLE)
bool watchdog_pinged;
#endif // defined(SPLIT_WATCHDOG_ENABLE)
#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
rpc_sync_info_t rpc_info;
uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE];