Implement I2C watchdog for the left half. Disable the watchdog because it causes a hard fault. Don't update the test LED inside of SlaveCommand_SetTestLed due to testing purposes until the watchdog issue gets resolved.
This commit is contained in:
36
left/src/i2c_watchdog.c
Normal file
36
left/src/i2c_watchdog.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "fsl_i2c.h"
|
||||
#include "i2c.h"
|
||||
#include "i2c_watchdog.h"
|
||||
#include "test_led.h"
|
||||
#include "init_peripherals.h"
|
||||
|
||||
static uint32_t prevWatchdogCounter = 0;
|
||||
uint32_t I2C_WatchdogInnerCounter;
|
||||
volatile uint32_t I2C_WatchdogOuterCounter;
|
||||
|
||||
void InitI2cWatchdog(void)
|
||||
{
|
||||
lptmr_config_t lptmrConfig;
|
||||
LPTMR_GetDefaultConfig(&lptmrConfig);
|
||||
LPTMR_Init(LPTMR0, &lptmrConfig);
|
||||
LPTMR_SetTimerPeriod(LPTMR0, USEC_TO_COUNT(LPTMR_USEC_COUNT, LPTMR_SOURCE_CLOCK));
|
||||
LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
|
||||
EnableIRQ(LPTMR0_IRQn);
|
||||
LPTMR_StartTimer(LPTMR0);
|
||||
}
|
||||
|
||||
void I2C_WATCHDOG_LPTMR_HANDLER(void)
|
||||
{
|
||||
I2C_WatchdogOuterCounter++;
|
||||
TEST_LED_TOGGLE();
|
||||
|
||||
if (I2C_Watchdog == prevWatchdogCounter && I2C_WatchdogOuterCounter>10) { // Restart I2C if there hasn't been any interrupt during 100 ms
|
||||
I2C_WatchdogInnerCounter++;
|
||||
I2C_SlaveDeinit(I2C_BUS_BASEADDR);
|
||||
//InitI2c();
|
||||
}
|
||||
|
||||
prevWatchdogCounter = I2C_Watchdog;
|
||||
|
||||
LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
|
||||
}
|
||||
19
left/src/i2c_watchdog.h
Normal file
19
left/src/i2c_watchdog.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef __I2C_WATCHDOG_H__
|
||||
#define __I2C_WATCHDOG_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "fsl_lptmr.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define I2C_WATCHDOG_LPTMR_HANDLER LPTMR0_IRQHandler
|
||||
#define LPTMR_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_LpoClk)
|
||||
#define LPTMR_USEC_COUNT 100000U
|
||||
|
||||
// Functions:
|
||||
|
||||
extern void InitI2cWatchdog(void);
|
||||
extern void RunWatchdog(void);
|
||||
|
||||
#endif
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "i2c.h"
|
||||
#include "led_pwm.h"
|
||||
#include "slave_protocol_handler.h"
|
||||
#include "i2c_watchdog.h"
|
||||
|
||||
static void i2cSlaveCallback(I2C_Type *base, i2c_slave_transfer_t *xfer, void *userData)
|
||||
{
|
||||
@@ -34,6 +35,12 @@ static void i2cSlaveCallback(I2C_Type *base, i2c_slave_transfer_t *xfer, void *u
|
||||
}
|
||||
}
|
||||
|
||||
void InitInterruptPriorities()
|
||||
{
|
||||
NVIC_SetPriority(I2C0_IRQn, 1);
|
||||
NVIC_SetPriority(TPM1_IRQn, 1);
|
||||
}
|
||||
|
||||
void InitI2c(void) {
|
||||
port_pin_config_t pinConfig = {
|
||||
.pullSelect = kPORT_PullUp,
|
||||
@@ -66,8 +73,10 @@ void InitLedDriver(void) {
|
||||
|
||||
void InitPeripherals(void)
|
||||
{
|
||||
InitInterruptPriorities();
|
||||
InitLedDriver();
|
||||
InitTestLed();
|
||||
LedPwm_Init();
|
||||
InitI2c();
|
||||
//InitI2cWatchdog();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
// Functions:
|
||||
|
||||
void InitPeripherals(void);
|
||||
extern void InitPeripherals(void);
|
||||
extern void InitI2c(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -40,7 +40,7 @@ void SlaveProtocolHandler(void)
|
||||
case SlaveCommand_SetTestLed:
|
||||
SlaveTxSize = 0;
|
||||
bool isLedOn = SlaveRxBuffer[1];
|
||||
TEST_LED_SET(isLedOn);
|
||||
// TEST_LED_SET(isLedOn);
|
||||
break;
|
||||
case SlaveCommand_SetLedPwmBrightness:
|
||||
SlaveTxSize = 0;
|
||||
|
||||
Reference in New Issue
Block a user