diff --git a/left/build/kds/.project b/left/build/kds/.project
index b625fe7..dbebd5c 100644
--- a/left/build/kds/.project
+++ b/left/build/kds/.project
@@ -81,6 +81,16 @@
1
PARENT-3-PROJECT_LOC/lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_i2c.h
+
+ drivers/fsl_lptmr.c
+ 1
+ PARENT-3-PROJECT_LOC/lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_lptmr.c
+
+
+ drivers/fsl_lptmr.h
+ 1
+ PARENT-3-PROJECT_LOC/lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_lptmr.h
+
drivers/fsl_port.h
1
diff --git a/left/build/kds/uhk-left debug jlink.launch b/left/build/kds/uhk-left debug jlink.launch
index e832647..942e2b6 100644
--- a/left/build/kds/uhk-left debug jlink.launch
+++ b/left/build/kds/uhk-left debug jlink.launch
@@ -70,13 +70,13 @@
-
+
-
+
diff --git a/left/src/i2c_watchdog.c b/left/src/i2c_watchdog.c
new file mode 100644
index 0000000..d9aa11e
--- /dev/null
+++ b/left/src/i2c_watchdog.c
@@ -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);
+}
diff --git a/left/src/i2c_watchdog.h b/left/src/i2c_watchdog.h
new file mode 100644
index 0000000..87920cf
--- /dev/null
+++ b/left/src/i2c_watchdog.h
@@ -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
diff --git a/left/src/init_peripherals.c b/left/src/init_peripherals.c
index 2a5a379..1e538ca 100644
--- a/left/src/init_peripherals.c
+++ b/left/src/init_peripherals.c
@@ -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();
}
diff --git a/left/src/init_peripherals.h b/left/src/init_peripherals.h
index 77cc793..a0011c1 100644
--- a/left/src/init_peripherals.h
+++ b/left/src/init_peripherals.h
@@ -10,6 +10,7 @@
// Functions:
- void InitPeripherals(void);
+ extern void InitPeripherals(void);
+ extern void InitI2c(void);
#endif
diff --git a/left/src/slave_protocol_handler.c b/left/src/slave_protocol_handler.c
index c5f8a50..7f8993c 100644
--- a/left/src/slave_protocol_handler.c
+++ b/left/src/slave_protocol_handler.c
@@ -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;
diff --git a/lib/KSDK_2.0_MKL03Z8xxx4 b/lib/KSDK_2.0_MKL03Z8xxx4
index c02d0df..ac55fc2 160000
--- a/lib/KSDK_2.0_MKL03Z8xxx4
+++ b/lib/KSDK_2.0_MKL03Z8xxx4
@@ -1 +1 @@
-Subproject commit c02d0df05b5987f243a1c16e93a4304916bceb6e
+Subproject commit ac55fc28ee6aa68cddcac00f6b76398cd8c0b541
diff --git a/right/build/kds/uhk-right debug jlink.launch b/right/build/kds/uhk-right debug jlink.launch
index 2c9896a..98aaba7 100644
--- a/right/build/kds/uhk-right debug jlink.launch
+++ b/right/build/kds/uhk-right debug jlink.launch
@@ -77,6 +77,6 @@
-
+