Add I2C_WatchdogOuterCounter, I2C_WatchdogInnerCounter, BridgeCounter and expose them via USB getDebugInfo()

This commit is contained in:
László Monda
2017-08-19 12:12:49 +02:00
parent 35102918b2
commit 58f36cf6c3
5 changed files with 29 additions and 3 deletions

View File

@@ -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);

View File

@@ -4,5 +4,6 @@
// Functions:
extern void InitI2cWatchdog();
extern uint32_t I2C_WatchdogInnerCounter;
extern uint32_t I2C_WatchdogOuterCounter;
#endif

View File

@@ -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++;

View File

@@ -26,6 +26,7 @@
// Variables:
extern uhk_slave_t Slaves[];
extern uint32_t BridgeCounter;
// Functions:

View File

@@ -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