diff options
| author | Dasky <32983009+daskygit@users.noreply.github.com> | 2022-10-06 10:52:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-06 20:52:42 +1100 |
| commit | c255174cf3e55483f14351a69689e24e849445a0 (patch) | |
| tree | 0ac6490f9b99d15c2a6a3dba862cf44901a6e812 /quantum/split_common | |
| parent | a9414f48405b6cc2019425077f22f0b162855c08 (diff) | |
Implement split comms watchdog (#18599)
Diffstat (limited to 'quantum/split_common')
| -rw-r--r-- | quantum/split_common/split_util.c | 43 | ||||
| -rw-r--r-- | quantum/split_common/split_util.h | 4 | ||||
| -rw-r--r-- | quantum/split_common/transaction_id_define.h | 4 | ||||
| -rw-r--r-- | quantum/split_common/transactions.c | 33 | ||||
| -rw-r--r-- | quantum/split_common/transport.h | 4 |
5 files changed, 88 insertions, 0 deletions
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index 0b3338ed6f..9f57c7b9fc 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c | |||
| @@ -74,6 +74,46 @@ static inline bool usbIsActive(void) { | |||
| 74 | } | 74 | } |
| 75 | #endif | 75 | #endif |
| 76 | 76 | ||
| 77 | #if defined(SPLIT_WATCHDOG_ENABLE) | ||
| 78 | # if !defined(SPLIT_WATCHDOG_TIMEOUT) | ||
| 79 | # if defined(SPLIT_USB_TIMEOUT) | ||
| 80 | # define SPLIT_WATCHDOG_TIMEOUT (SPLIT_USB_TIMEOUT + 100) | ||
| 81 | # else | ||
| 82 | # define SPLIT_WATCHDOG_TIMEOUT 3000 | ||
| 83 | # endif | ||
| 84 | # endif | ||
| 85 | # if defined(SPLIT_USB_DETECT) | ||
| 86 | _Static_assert(SPLIT_USB_TIMEOUT < SPLIT_WATCHDOG_TIMEOUT, "SPLIT_WATCHDOG_TIMEOUT should not be below SPLIT_USB_TIMEOUT."); | ||
| 87 | # endif | ||
| 88 | _Static_assert(SPLIT_MAX_CONNECTION_ERRORS > 0, "SPLIT_WATCHDOG_ENABLE requires SPLIT_MAX_CONNECTION_ERRORS be above 0 for a functioning disconnection check."); | ||
| 89 | |||
| 90 | static uint32_t split_watchdog_started = 0; | ||
| 91 | static bool split_watchdog_done = false; | ||
| 92 | |||
| 93 | void split_watchdog_init(void) { | ||
| 94 | split_watchdog_started = timer_read32(); | ||
| 95 | } | ||
| 96 | |||
| 97 | void split_watchdog_update(bool done) { | ||
| 98 | split_watchdog_done = done; | ||
| 99 | } | ||
| 100 | |||
| 101 | bool split_watchdog_check(void) { | ||
| 102 | if (!is_transport_connected()) { | ||
| 103 | split_watchdog_done = false; | ||
| 104 | } | ||
| 105 | return split_watchdog_done; | ||
| 106 | } | ||
| 107 | |||
| 108 | void split_watchdog_task(void) { | ||
| 109 | if (!split_watchdog_done && !is_keyboard_master()) { | ||
| 110 | if (timer_elapsed32(split_watchdog_started) > SPLIT_WATCHDOG_TIMEOUT) { | ||
| 111 | mcu_reset(); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | } | ||
| 115 | #endif // defined(SPLIT_WATCHDOG_ENABLE) | ||
| 116 | |||
| 77 | #ifdef SPLIT_HAND_MATRIX_GRID | 117 | #ifdef SPLIT_HAND_MATRIX_GRID |
| 78 | void matrix_io_delay(void); | 118 | void matrix_io_delay(void); |
| 79 | 119 | ||
| @@ -179,6 +219,9 @@ void split_pre_init(void) { | |||
| 179 | void split_post_init(void) { | 219 | void split_post_init(void) { |
| 180 | if (!is_keyboard_master()) { | 220 | if (!is_keyboard_master()) { |
| 181 | transport_slave_init(); | 221 | transport_slave_init(); |
| 222 | #if defined(SPLIT_WATCHDOG_ENABLE) | ||
| 223 | split_watchdog_init(); | ||
| 224 | #endif | ||
| 182 | } | 225 | } |
| 183 | } | 226 | } |
| 184 | 227 | ||
diff --git a/quantum/split_common/split_util.h b/quantum/split_common/split_util.h index c7eabea233..5c9a260a14 100644 --- a/quantum/split_common/split_util.h +++ b/quantum/split_common/split_util.h | |||
| @@ -14,3 +14,7 @@ void split_post_init(void); | |||
| 14 | 14 | ||
| 15 | bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]); | 15 | bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]); |
| 16 | bool is_transport_connected(void); | 16 | bool is_transport_connected(void); |
| 17 | |||
| 18 | void split_watchdog_update(bool done); | ||
| 19 | void split_watchdog_task(void); | ||
| 20 | bool split_watchdog_check(void); \ No newline at end of file | ||
diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 761a8884f4..8c19948107 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h | |||
| @@ -84,6 +84,10 @@ enum serial_transaction_id { | |||
| 84 | PUT_POINTING_CPI, | 84 | PUT_POINTING_CPI, |
| 85 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | 85 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) |
| 86 | 86 | ||
| 87 | #if defined(SPLIT_WATCHDOG_ENABLE) | ||
| 88 | PUT_WATCHDOG, | ||
| 89 | #endif // defined(SPLIT_WATCHDOG_ENABLE) | ||
| 90 | |||
| 87 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 91 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) |
| 88 | PUT_RPC_INFO, | 92 | PUT_RPC_INFO, |
| 89 | PUT_RPC_REQ_DATA, | 93 | PUT_RPC_REQ_DATA, |
diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 67986e4340..527b2f4caf 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c | |||
| @@ -719,6 +719,36 @@ static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s | |||
| 719 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | 719 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) |
| 720 | 720 | ||
| 721 | //////////////////////////////////////////////////// | 721 | //////////////////////////////////////////////////// |
| 722 | // WATCHDOG | ||
| 723 | |||
| 724 | #if defined(SPLIT_WATCHDOG_ENABLE) | ||
| 725 | |||
| 726 | static bool watchdog_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { | ||
| 727 | bool okay = true; | ||
| 728 | if (!split_watchdog_check()) { | ||
| 729 | okay = transport_write(PUT_WATCHDOG, &okay, sizeof(okay)); | ||
| 730 | split_watchdog_update(okay); | ||
| 731 | } | ||
| 732 | return okay; | ||
| 733 | } | ||
| 734 | |||
| 735 | static void watchdog_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { | ||
| 736 | split_watchdog_update(split_shmem->watchdog_pinged); | ||
| 737 | } | ||
| 738 | |||
| 739 | # define TRANSACTIONS_WATCHDOG_MASTER() TRANSACTION_HANDLER_MASTER(watchdog) | ||
| 740 | # define TRANSACTIONS_WATCHDOG_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(watchdog) | ||
| 741 | # define TRANSACTIONS_WATCHDOG_REGISTRATIONS [PUT_WATCHDOG] = trans_initiator2target_initializer(watchdog_pinged), | ||
| 742 | |||
| 743 | #else // defined(SPLIT_WATCHDOG_ENABLE) | ||
| 744 | |||
| 745 | # define TRANSACTIONS_WATCHDOG_MASTER() | ||
| 746 | # define TRANSACTIONS_WATCHDOG_SLAVE() | ||
| 747 | # define TRANSACTIONS_WATCHDOG_REGISTRATIONS | ||
| 748 | |||
| 749 | #endif // defined(SPLIT_WATCHDOG_ENABLE) | ||
| 750 | |||
| 751 | //////////////////////////////////////////////////// | ||
| 722 | 752 | ||
| 723 | split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { | 753 | split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { |
| 724 | // Set defaults | 754 | // Set defaults |
| @@ -744,6 +774,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { | |||
| 744 | TRANSACTIONS_OLED_REGISTRATIONS | 774 | TRANSACTIONS_OLED_REGISTRATIONS |
| 745 | TRANSACTIONS_ST7565_REGISTRATIONS | 775 | TRANSACTIONS_ST7565_REGISTRATIONS |
| 746 | TRANSACTIONS_POINTING_REGISTRATIONS | 776 | TRANSACTIONS_POINTING_REGISTRATIONS |
| 777 | TRANSACTIONS_WATCHDOG_REGISTRATIONS | ||
| 747 | // clang-format on | 778 | // clang-format on |
| 748 | 779 | ||
| 749 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 780 | #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 | |||
| 770 | TRANSACTIONS_OLED_MASTER(); | 801 | TRANSACTIONS_OLED_MASTER(); |
| 771 | TRANSACTIONS_ST7565_MASTER(); | 802 | TRANSACTIONS_ST7565_MASTER(); |
| 772 | TRANSACTIONS_POINTING_MASTER(); | 803 | TRANSACTIONS_POINTING_MASTER(); |
| 804 | TRANSACTIONS_WATCHDOG_MASTER(); | ||
| 773 | return true; | 805 | return true; |
| 774 | } | 806 | } |
| 775 | 807 | ||
| @@ -789,6 +821,7 @@ void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[ | |||
| 789 | TRANSACTIONS_OLED_SLAVE(); | 821 | TRANSACTIONS_OLED_SLAVE(); |
| 790 | TRANSACTIONS_ST7565_SLAVE(); | 822 | TRANSACTIONS_ST7565_SLAVE(); |
| 791 | TRANSACTIONS_POINTING_SLAVE(); | 823 | TRANSACTIONS_POINTING_SLAVE(); |
| 824 | TRANSACTIONS_WATCHDOG_SLAVE(); | ||
| 792 | } | 825 | } |
| 793 | 826 | ||
| 794 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 827 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) |
diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index 06778ad14a..833633edc2 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h | |||
| @@ -188,6 +188,10 @@ typedef struct _split_shared_memory_t { | |||
| 188 | split_slave_pointing_sync_t pointing; | 188 | split_slave_pointing_sync_t pointing; |
| 189 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) | 189 | #endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) |
| 190 | 190 | ||
| 191 | #if defined(SPLIT_WATCHDOG_ENABLE) | ||
| 192 | bool watchdog_pinged; | ||
| 193 | #endif // defined(SPLIT_WATCHDOG_ENABLE) | ||
| 194 | |||
| 191 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) | 195 | #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) |
| 192 | rpc_sync_info_t rpc_info; | 196 | rpc_sync_info_t rpc_info; |
| 193 | uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; | 197 | uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; |
