Define I2C_WATCHDOG_VALUE_REINIT and I2C_WATCHDOG_VALUE_REBOOT and make them work when assigned to I2C_WATCHDOG.

This commit is contained in:
László Monda
2017-12-27 17:07:04 +01:00
parent c51542795f
commit 43587c2e1f
6 changed files with 15 additions and 20 deletions

View File

@@ -3,6 +3,11 @@
// Macros:
#define I2C_WATCHDOG_VALUE_REINIT 1
#define I2C_WATCHDOG_VALUE_REBOOT 2
// #define DEBUG_OVER_SPI
// #define I2C_WATCHDOG I2C_WATCHDOG_VALUE_REINIT
// #define I2C_WATCHDOG I2C_WATCHDOG_VALUE_REBOOT
#endif

View File

@@ -3,22 +3,16 @@
#include "i2c_watchdog.h"
#include "test_led.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.
* 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.
*/
#if KEY_USE_I2C_WATCHDOG_TIMER
#ifdef I2C_WATCHDOG
static uint32_t prevWatchdogCounter = 0;
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)
{
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 (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++;
#if I2C_WATCHDOG == I2C_WATCHDOG_VALUE_REBOOT
NVIC_SystemReset();
#endif
#if I2C_WATCHDOG == I2C_WATCHDOG_VALUE_REINIT
I2C_SlaveDeinit(I2C_BUS_BASEADDR);
InitI2c();
#endif
}
}
prevWatchdogCounter = I2C_Watchdog; /* remember previous counter */

View File

@@ -13,7 +13,6 @@
// Functions:
void InitI2cWatchdog(void);
void RunWatchdog(void);
#endif

View File

@@ -88,7 +88,4 @@ void InitPeripherals(void)
LedPwm_Init();
DebugOverSpi_Init();
InitI2c();
#if KEY_USE_I2C_WATCHDOG_TIMER
InitI2cWatchdog();
#endif
}

View File

@@ -1,14 +1,12 @@
#include "fsl_lptmr.h"
#include "key_scanner.h"
#include "main.h"
#if KEY_USE_I2C_WATCHDOG_TIMER
#include "i2c_watchdog.h"
#endif
#include "config.h"
#include "i2c_watchdog.h"
void KEY_SCANNER_HANDLER(void)
{
KeyMatrix_ScanRow(&keyMatrix);
#if KEY_USE_I2C_WATCHDOG_TIMER
#ifdef I2C_WATCHDOG
RunWatchdog();
#endif
LPTMR_ClearStatusFlags(KEY_SCANNER_LPTMR_BASEADDR, kLPTMR_TimerCompareFlag);

View File

@@ -14,6 +14,4 @@
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