diff --git a/right/src/i2c_watchdog.c b/right/src/i2c_watchdog.c index ce63733..ac1d930 100644 --- a/right/src/i2c_watchdog.c +++ b/right/src/i2c_watchdog.c @@ -10,12 +10,16 @@ #define PIT_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_BusClk) static uint32_t prevWatchdogCounter = 0; +uint32_t I2C_WatchdogInnerCounter; +uint32_t I2C_WatchdogOuterCounter; // This function is designed to restart and reinstall the I2C handler // when a disconnection of the left side makes the master I2C bus unresponsive. void PIT_I2C_WATCHDOG_HANDLER(void) { + I2C_WatchdogOuterCounter++; if (I2C_Watchdog == prevWatchdogCounter) { // Restart I2C if there hasn't be any interrupt during 1 sec + I2C_WatchdogInnerCounter++; i2c_master_config_t masterConfig; I2C_MasterGetDefaultConfig(&masterConfig); I2C_MasterDeinit(I2C_MAIN_BUS_BASEADDR); diff --git a/right/src/i2c_watchdog.h b/right/src/i2c_watchdog.h index ef109be..9ae7714 100644 --- a/right/src/i2c_watchdog.h +++ b/right/src/i2c_watchdog.h @@ -4,5 +4,6 @@ // Functions: extern void InitI2cWatchdog(); - + extern uint32_t I2C_WatchdogInnerCounter; + extern uint32_t I2C_WatchdogOuterCounter; #endif diff --git a/right/src/slave_scheduler.c b/right/src/slave_scheduler.c index 4488bd2..d6287ba 100644 --- a/right/src/slave_scheduler.c +++ b/right/src/slave_scheduler.c @@ -10,6 +10,7 @@ uint8_t previousSlaveId = 0; uint8_t currentSlaveId = 0; +uint32_t BridgeCounter; uhk_slave_t Slaves[] = { { .initializer = UhkModuleSlaveDriver_Init, .updater = UhkModuleSlaveDriver_Update, .perDriverId = UhkModuleId_LeftKeyboardHalf }, @@ -22,6 +23,7 @@ static void bridgeProtocolCallback(I2C_Type *base, i2c_master_handle_t *handle, IsI2cTransferScheduled = false; do { + BridgeCounter++; if (TestStates.disableI2c) { return; } @@ -36,6 +38,9 @@ static void bridgeProtocolCallback(I2C_Type *base, i2c_master_handle_t *handle, } currentSlave->updater(currentSlave->perDriverId); + if (IsI2cTransferScheduled) { + currentSlave->isConnected = true; + } previousSlaveId = currentSlaveId; currentSlaveId++; diff --git a/right/src/slave_scheduler.h b/right/src/slave_scheduler.h index 79b7fee..fe7659e 100644 --- a/right/src/slave_scheduler.h +++ b/right/src/slave_scheduler.h @@ -26,6 +26,7 @@ // Variables: extern uhk_slave_t Slaves[]; + extern uint32_t BridgeCounter; // Functions: diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index 45d3a94..a10d7f7 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -14,7 +14,7 @@ #include "eeprom.h" #include "keymaps.h" #include "microseconds/microseconds_pit.c" - +#include "i2c_watchdog.h" // Functions for setting error statuses void setError(uint8_t error) @@ -206,6 +206,21 @@ void getDebugInfo(void) GenericHidOutBuffer[3] = I2C_Watchdog >> 16; GenericHidOutBuffer[4] = I2C_Watchdog >> 24; + GenericHidOutBuffer[5] = BridgeCounter >> 0; + GenericHidOutBuffer[6] = BridgeCounter >> 8; + GenericHidOutBuffer[7] = BridgeCounter >> 16; + GenericHidOutBuffer[8] = BridgeCounter >> 24; + + GenericHidOutBuffer[9] = I2C_WatchdogOuterCounter >> 0; + GenericHidOutBuffer[10] = I2C_WatchdogOuterCounter >> 8; + GenericHidOutBuffer[11] = I2C_WatchdogOuterCounter >> 16; + GenericHidOutBuffer[12] = I2C_WatchdogOuterCounter >> 24; + + GenericHidOutBuffer[13] = I2C_WatchdogInnerCounter >> 0; + GenericHidOutBuffer[14] = I2C_WatchdogInnerCounter >> 8; + GenericHidOutBuffer[15] = I2C_WatchdogInnerCounter >> 16; + GenericHidOutBuffer[16] = I2C_WatchdogInnerCounter >> 24; +/* uint64_t ticks = microseconds_get_ticks(); uint32_t microseconds = microseconds_convert_to_microseconds(ticks); uint32_t milliseconds = microseconds/1000; @@ -218,7 +233,7 @@ void getDebugInfo(void) GenericHidOutBuffer[6] = (ticks >> 40) & 0xff; GenericHidOutBuffer[7] = (ticks >> 48) & 0xff; GenericHidOutBuffer[8] = (ticks >> 56) & 0xff; -} +*/} // The main protocol handler function