6 Commits

18 changed files with 90 additions and 66 deletions

View File

@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to the [UHK Versioning](VERSIONING.md) conventions. and this project adheres to the [UHK Versioning](VERSIONING.md) conventions.
## [8.0.1] - 2017-12-25
Device Protocol: 4.1.0 | Module Protocol: 4.0.0 | User Config: 4.0.0 | Hardware Config: 1.0.0
- Implement I2C watchdog for the left keyboard half which should resolve the occasional hangs of the left keyboard half.
## [8.0.0] - 2017-12-15 ## [8.0.0] - 2017-12-15
Device Protocol: 4.**1.0** | Module Protocol: **4.0.0** | User Config: 4.0.0 | Hardware Config: 1.0.0 Device Protocol: 4.**1.0** | Module Protocol: **4.0.0** | User Config: 4.0.0 | Hardware Config: 1.0.0

View File

@@ -50,7 +50,7 @@
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="2331"/> <intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="2331"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/> <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/> <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="false"/> <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/> <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/> <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/> <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
@@ -77,6 +77,6 @@
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/> <listEntry value="4"/>
</listAttribute> </listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#10;"/> <stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/> <stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration> </launchConfiguration>

View File

@@ -77,6 +77,6 @@
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/> <listEntry value="4"/>
</listAttribute> </listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#10;"/> <stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/> <stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration> </launchConfiguration>

View File

@@ -3,36 +3,42 @@
#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"
//static uint32_t prevWatchdogCounter = 0; /* NOTE: Because of a bug in the ROM bootloader of the KL03Z, the watchdog timer is disabled and cannot be re-enabled.
uint32_t I2cWatchdog_RecoveryCounter; * See https://community.nxp.com/thread/457893
volatile uint32_t I2cWatchdog_WatchCounter; * Therefore the hardware watchdog timer cannot be used without an extra way to enter bootloader or application mode.
*/
#if KEY_USE_I2C_WATCHDOG_TIMER
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) 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) #if KEY_USE_I2C_WATCHDOG_TIMER
void RunWatchdog(void)
{ {
TEST_LED_TOGGLE(); static volatile uint32_t I2cWatchdog_WatchCounter = 0; /* counter for timer */
I2cWatchdog_WatchCounter++; static int cntr = 0;
if (I2C_Watchdog == prevWatchdogCounter) { // Restart I2C if there hasn't been any interrupt during 100 ms cntr++;
// NVIC_SystemReset(); if (cntr==100) { /* we get called from KEY_SCANNER_HANDLER() which runs at 1ms, thus scaling down by 100 here to get 100 ms period */
I2cWatchdog_RecoveryCounter++; cntr=0;
I2C_SlaveDeinit(I2C_BUS_BASEADDR); TEST_LED_TOGGLE();
InitI2c(); I2cWatchdog_WatchCounter++;
}
prevWatchdogCounter = I2C_Watchdog; 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
LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag); // NVIC_SystemReset();
I2cWatchdog_RecoveryCounter++;
I2C_SlaveDeinit(I2C_BUS_BASEADDR);
InitI2c();
}
}
prevWatchdogCounter = I2C_Watchdog; /* remember previous counter */
}
} }
*/ #endif

View File

@@ -10,6 +10,7 @@
#include "slave_protocol_handler.h" #include "slave_protocol_handler.h"
#include "i2c_watchdog.h" #include "i2c_watchdog.h"
#include "debug_over_spi.h" #include "debug_over_spi.h"
#include "main.h"
i2c_slave_config_t slaveConfig; i2c_slave_config_t slaveConfig;
i2c_slave_handle_t slaveHandle; i2c_slave_handle_t slaveHandle;
@@ -85,7 +86,9 @@ void InitPeripherals(void)
InitLedDriver(); InitLedDriver();
InitTestLed(); InitTestLed();
LedPwm_Init(); LedPwm_Init();
// InitI2cWatchdog();
DebugOverSpi_Init(); DebugOverSpi_Init();
InitI2c(); InitI2c();
#if KEY_USE_I2C_WATCHDOG_TIMER
InitI2cWatchdog();
#endif
} }

View File

@@ -1,10 +1,16 @@
#include "fsl_lptmr.h" #include "fsl_lptmr.h"
#include "key_scanner.h" #include "key_scanner.h"
#include "main.h" #include "main.h"
#if KEY_USE_I2C_WATCHDOG_TIMER
#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
RunWatchdog();
#endif
LPTMR_ClearStatusFlags(KEY_SCANNER_LPTMR_BASEADDR, kLPTMR_TimerCompareFlag); LPTMR_ClearStatusFlags(KEY_SCANNER_LPTMR_BASEADDR, kLPTMR_TimerCompareFlag);
} }

View File

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

View File

@@ -64,10 +64,10 @@
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/> <intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/> <stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/> <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="uhk60-right_debug/uhk-right.elf"/> <stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="uhk60-right_debug_standalone/uhk-right.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="uhk-right"/> <stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="uhk-right"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/> <booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="ilg.gnuarmeclipse.managedbuild.cross.config.elf.release.1939339834.1692217331.1297236062.2081695142"/> <stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/uhk-right"/> <listEntry value="/uhk-right"/>
</listAttribute> </listAttribute>
@@ -77,6 +77,6 @@
<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> <listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/> <listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
</listAttribute> </listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#10;"/> <stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/> <stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration> </launchConfiguration>

View File

@@ -1,5 +1,5 @@
#include "fsl_common.h" #include "fsl_common.h"
#include "usb_commands/usb_command_get_property.h" #include "usb_commands/usb_command_get_device_property.h"
#include "usb_protocol_handler.h" #include "usb_protocol_handler.h"
#include "eeprom.h" #include "eeprom.h"
#include "versions.h" #include "versions.h"
@@ -41,7 +41,7 @@ version_t protocolVersions[] =
uint16_t configSizes[] = {HARDWARE_CONFIG_SIZE, USER_CONFIG_SIZE}; uint16_t configSizes[] = {HARDWARE_CONFIG_SIZE, USER_CONFIG_SIZE};
void UsbCommand_GetProperty(void) void UsbCommand_GetDeviceProperty(void)
{ {
uint8_t propertyId = GetUsbRxBufferUint8(1); uint8_t propertyId = GetUsbRxBufferUint8(1);
@@ -56,7 +56,7 @@ void UsbCommand_GetProperty(void)
memcpy(GenericHidOutBuffer+1, (uint8_t*)&configSizes, sizeof(configSizes)); memcpy(GenericHidOutBuffer+1, (uint8_t*)&configSizes, sizeof(configSizes));
break; break;
default: default:
SetUsbTxBufferUint8(0, UsbStatusCode_GetProperty_InvalidProperty); SetUsbTxBufferUint8(0, UsbStatusCode_GetDeviceProperty_InvalidProperty);
break; break;
} }
} }

View File

@@ -1,5 +1,5 @@
#ifndef __USB_COMMAND_GET_PROPERTY_H__ #ifndef __USB_COMMAND_GET_DEVICE_PROPERTY_H__
#define __USB_COMMAND_GET_PROPERTY_H__ #define __USB_COMMAND_GET_DEVICE_PROPERTY_H__
// Typedefs: // Typedefs:
@@ -10,11 +10,11 @@
} system_property_t; } system_property_t;
typedef enum { typedef enum {
UsbStatusCode_GetProperty_InvalidProperty = 2, UsbStatusCode_GetDeviceProperty_InvalidProperty = 2,
} usb_status_code_get_property_t; } usb_status_code_get_device_property_t;
// Functions: // Functions:
void UsbCommand_GetProperty(void); void UsbCommand_GetDeviceProperty(void);
#endif #endif

View File

@@ -1,14 +0,0 @@
#ifndef __USB_COMMAND_GET_MODULE_PROPERTIES_H__
#define __USB_COMMAND_GET_MODULE_PROPERTIES_H__
// Functions:
void UsbCommand_GetModuleProperties();
// Typedefs:
typedef enum {
UsbStatusCode_ReadConfig_InvalidModuleSlotId = 2,
} usb_status_code_get_module_properties_t;
#endif

View File

@@ -1,15 +1,15 @@
#include "fsl_common.h" #include "fsl_common.h"
#include "usb_commands/usb_command_get_module_properties.h" #include "usb_commands/usb_command_get_module_property.h"
#include "usb_protocol_handler.h" #include "usb_protocol_handler.h"
#include "slot.h" #include "slot.h"
#include "slave_drivers/uhk_module_driver.h" #include "slave_drivers/uhk_module_driver.h"
void UsbCommand_GetModuleProperties() void UsbCommand_GetModuleProperty()
{ {
slot_t slotId = GetUsbRxBufferUint8(1); slot_t slotId = GetUsbRxBufferUint8(1);
if (!IS_VALID_MODULE_SLOT(slotId)) { if (!IS_VALID_MODULE_SLOT(slotId)) {
SetUsbTxBufferUint8(0, UsbStatusCode_ReadConfig_InvalidModuleSlotId); SetUsbTxBufferUint8(0, UsbStatusCode_GetModuleProperty_InvalidModuleSlotId);
} }
uint8_t moduleDriverId = SLOT_ID_TO_UHK_MODULE_DRIVER_ID(slotId); uint8_t moduleDriverId = SLOT_ID_TO_UHK_MODULE_DRIVER_ID(slotId);

View File

@@ -0,0 +1,14 @@
#ifndef __USB_COMMAND_GET_MODULE_PROPERTY_H__
#define __USB_COMMAND_GET_MODULE_PROPERTY_H__
// Functions:
void UsbCommand_GetModuleProperty();
// Typedefs:
typedef enum {
UsbStatusCode_GetModuleProperty_InvalidModuleSlotId = 2,
} usb_status_code_get_module_property_t;
#endif

View File

@@ -1,6 +1,7 @@
#include "usb_protocol_handler.h" #include "usb_protocol_handler.h"
#include "buffer.h" #include "buffer.h"
#include "usb_commands/usb_command_get_property.h" #include "usb_commands/usb_command_get_device_property.h"
#include "usb_commands/usb_command_get_module_property.h"
#include "usb_commands/usb_command_reenumerate.h" #include "usb_commands/usb_command_reenumerate.h"
#include "usb_commands/usb_command_set_test_led.h" #include "usb_commands/usb_command_set_test_led.h"
#include "usb_commands/usb_command_write_config.h" #include "usb_commands/usb_command_write_config.h"
@@ -19,8 +20,8 @@ void UsbProtocolHandler(void)
bzero(GenericHidOutBuffer, USB_GENERIC_HID_OUT_BUFFER_LENGTH); bzero(GenericHidOutBuffer, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
uint8_t command = GetUsbRxBufferUint8(0); uint8_t command = GetUsbRxBufferUint8(0);
switch (command) { switch (command) {
case UsbCommandId_GetProperty: case UsbCommandId_GetDeviceProperty:
UsbCommand_GetProperty(); UsbCommand_GetDeviceProperty();
break; break;
case UsbCommandId_Reenumerate: case UsbCommandId_Reenumerate:
UsbCommand_Reenumerate(); UsbCommand_Reenumerate();
@@ -61,8 +62,8 @@ void UsbProtocolHandler(void)
case UsbCommandId_SetLedPwmBrightness: case UsbCommandId_SetLedPwmBrightness:
UsbCommand_SetLedPwmBrightness(); UsbCommand_SetLedPwmBrightness();
break; break;
case UsbCommandId_GetModuleProperties: case UsbCommandId_GetModuleProperty:
UsbCommand_GetModuleProperties(); UsbCommand_GetModuleProperty();
break; break;
default: default:
SetUsbTxBufferUint8(0, UsbStatusCode_InvalidCommand); SetUsbTxBufferUint8(0, UsbStatusCode_InvalidCommand);

View File

@@ -13,7 +13,7 @@
// Typedefs: // Typedefs:
typedef enum { typedef enum {
UsbCommandId_GetProperty = 0x00, UsbCommandId_GetDeviceProperty = 0x00,
UsbCommandId_Reenumerate = 0x01, UsbCommandId_Reenumerate = 0x01,
UsbCommandId_JumpToModuleBootloader = 0x02, UsbCommandId_JumpToModuleBootloader = 0x02,
@@ -30,7 +30,7 @@
UsbCommandId_GetDebugBuffer = 0x0b, UsbCommandId_GetDebugBuffer = 0x0b,
UsbCommandId_GetAdcValue = 0x0c, UsbCommandId_GetAdcValue = 0x0c,
UsbCommandId_SetLedPwmBrightness = 0x0d, UsbCommandId_SetLedPwmBrightness = 0x0d,
UsbCommandId_GetModuleProperties = 0x0e, UsbCommandId_GetModuleProperty = 0x0e,
} usb_command_id_t; } usb_command_id_t;
typedef enum { typedef enum {

View File

@@ -15,7 +15,7 @@
"commander": "^2.11.0", "commander": "^2.11.0",
"shelljs": "^0.7.8" "shelljs": "^0.7.8"
}, },
"firmwareVersion": "8.0.0", "firmwareVersion": "8.0.1",
"deviceProtocolVersion": "4.1.0", "deviceProtocolVersion": "4.1.0",
"moduleProtocolVersion": "4.0.0", "moduleProtocolVersion": "4.0.0",
"userConfigVersion": "4.0.0", "userConfigVersion": "4.0.0",

View File

@@ -20,7 +20,7 @@
#define FIRMWARE_MAJOR_VERSION 8 #define FIRMWARE_MAJOR_VERSION 8
#define FIRMWARE_MINOR_VERSION 0 #define FIRMWARE_MINOR_VERSION 0
#define FIRMWARE_PATCH_VERSION 0 #define FIRMWARE_PATCH_VERSION 1
#define DEVICE_PROTOCOL_MAJOR_VERSION 4 #define DEVICE_PROTOCOL_MAJOR_VERSION 4
#define DEVICE_PROTOCOL_MINOR_VERSION 1 #define DEVICE_PROTOCOL_MINOR_VERSION 1