Define I2C_WATCHDOG_VALUE_REINIT and I2C_WATCHDOG_VALUE_REBOOT and make them work when assigned to I2C_WATCHDOG.
This commit is contained in:
@@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
// Macros:
|
// Macros:
|
||||||
|
|
||||||
|
#define I2C_WATCHDOG_VALUE_REINIT 1
|
||||||
|
#define I2C_WATCHDOG_VALUE_REBOOT 2
|
||||||
|
|
||||||
// #define DEBUG_OVER_SPI
|
// #define DEBUG_OVER_SPI
|
||||||
|
// #define I2C_WATCHDOG I2C_WATCHDOG_VALUE_REINIT
|
||||||
|
// #define I2C_WATCHDOG I2C_WATCHDOG_VALUE_REBOOT
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,22 +3,16 @@
|
|||||||
#include "i2c_watchdog.h"
|
#include "i2c_watchdog.h"
|
||||||
#include "test_led.h"
|
#include "test_led.h"
|
||||||
#include "init_peripherals.h"
|
#include "init_peripherals.h"
|
||||||
#include "main.h"
|
#include "config.h"
|
||||||
|
|
||||||
/* NOTE: Because of a bug in the ROM bootloader of the KL03Z, the watchdog timer is disabled and cannot be re-enabled.
|
/* NOTE: Because of a bug in the ROM bootloader of the KL03Z, the watchdog timer is disabled and cannot be re-enabled.
|
||||||
* See https://community.nxp.com/thread/457893
|
* See https://community.nxp.com/thread/457893
|
||||||
* Therefore the hardware watchdog timer cannot be used without an extra way to enter bootloader or application mode.
|
* Therefore the hardware watchdog timer cannot be used without an extra way to enter bootloader or application mode.
|
||||||
*/
|
*/
|
||||||
#if KEY_USE_I2C_WATCHDOG_TIMER
|
#ifdef I2C_WATCHDOG
|
||||||
static uint32_t prevWatchdogCounter = 0;
|
static uint32_t prevWatchdogCounter = 0;
|
||||||
static uint32_t I2cWatchdog_RecoveryCounter; /* counter for how many times we had to recover and restart */
|
static uint32_t I2cWatchdog_RecoveryCounter; /* counter for how many times we had to recover and restart */
|
||||||
#endif
|
|
||||||
|
|
||||||
void InitI2cWatchdog(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#if KEY_USE_I2C_WATCHDOG_TIMER
|
|
||||||
void RunWatchdog(void)
|
void RunWatchdog(void)
|
||||||
{
|
{
|
||||||
static volatile uint32_t I2cWatchdog_WatchCounter = 0; /* counter for timer */
|
static volatile uint32_t I2cWatchdog_WatchCounter = 0; /* counter for timer */
|
||||||
@@ -32,10 +26,14 @@ void RunWatchdog(void)
|
|||||||
|
|
||||||
if (I2cWatchdog_WatchCounter>10) { /* do not check within the first 1000 ms, as I2C might not be running yet */
|
if (I2cWatchdog_WatchCounter>10) { /* do not check within the first 1000 ms, as I2C might not be running yet */
|
||||||
if (I2C_Watchdog == prevWatchdogCounter) { // Restart I2C if there hasn't been any interrupt during 100 ms. I2C_Watchdog gets incremented for every I2C transaction
|
if (I2C_Watchdog == prevWatchdogCounter) { // Restart I2C if there hasn't been any interrupt during 100 ms. I2C_Watchdog gets incremented for every I2C transaction
|
||||||
// NVIC_SystemReset();
|
|
||||||
I2cWatchdog_RecoveryCounter++;
|
I2cWatchdog_RecoveryCounter++;
|
||||||
|
#if I2C_WATCHDOG == I2C_WATCHDOG_VALUE_REBOOT
|
||||||
|
NVIC_SystemReset();
|
||||||
|
#endif
|
||||||
|
#if I2C_WATCHDOG == I2C_WATCHDOG_VALUE_REINIT
|
||||||
I2C_SlaveDeinit(I2C_BUS_BASEADDR);
|
I2C_SlaveDeinit(I2C_BUS_BASEADDR);
|
||||||
InitI2c();
|
InitI2c();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prevWatchdogCounter = I2C_Watchdog; /* remember previous counter */
|
prevWatchdogCounter = I2C_Watchdog; /* remember previous counter */
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
void InitI2cWatchdog(void);
|
|
||||||
void RunWatchdog(void);
|
void RunWatchdog(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -88,7 +88,4 @@ void InitPeripherals(void)
|
|||||||
LedPwm_Init();
|
LedPwm_Init();
|
||||||
DebugOverSpi_Init();
|
DebugOverSpi_Init();
|
||||||
InitI2c();
|
InitI2c();
|
||||||
#if KEY_USE_I2C_WATCHDOG_TIMER
|
|
||||||
InitI2cWatchdog();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
#include "fsl_lptmr.h"
|
#include "fsl_lptmr.h"
|
||||||
#include "key_scanner.h"
|
#include "key_scanner.h"
|
||||||
#include "main.h"
|
#include "config.h"
|
||||||
#if KEY_USE_I2C_WATCHDOG_TIMER
|
|
||||||
#include "i2c_watchdog.h"
|
#include "i2c_watchdog.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
void KEY_SCANNER_HANDLER(void)
|
void KEY_SCANNER_HANDLER(void)
|
||||||
{
|
{
|
||||||
KeyMatrix_ScanRow(&keyMatrix);
|
KeyMatrix_ScanRow(&keyMatrix);
|
||||||
#if KEY_USE_I2C_WATCHDOG_TIMER
|
#ifdef I2C_WATCHDOG
|
||||||
RunWatchdog();
|
RunWatchdog();
|
||||||
#endif
|
#endif
|
||||||
LPTMR_ClearStatusFlags(KEY_SCANNER_LPTMR_BASEADDR, kLPTMR_TimerCompareFlag);
|
LPTMR_ClearStatusFlags(KEY_SCANNER_LPTMR_BASEADDR, kLPTMR_TimerCompareFlag);
|
||||||
|
|||||||
@@ -14,6 +14,4 @@
|
|||||||
|
|
||||||
extern key_matrix_t keyMatrix;
|
extern key_matrix_t keyMatrix;
|
||||||
|
|
||||||
#define KEY_USE_I2C_WATCHDOG_TIMER (1) /* if set to 1, every 100 ms the I2C communication is checked */
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user