Move watchdog resets to only be in PID

This commit is contained in:
Ben V. Brown
2018-01-26 12:30:09 +11:00
parent 93869b979e
commit 715be0b0b6
4 changed files with 22 additions and 26 deletions

View File

@@ -14,12 +14,14 @@ MMA8652FC::MMA8652FC(I2C_HandleTypeDef* i2cHandle) {
void MMA8652FC::I2C_RegisterWrite(uint8_t reg, uint8_t data) { void MMA8652FC::I2C_RegisterWrite(uint8_t reg, uint8_t data) {
HAL_I2C_Mem_Write(i2c, MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data, 1, 0xFFFF); HAL_I2C_Mem_Write(i2c, MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT,
&data, 1, 500);
} }
uint8_t MMA8652FC::I2C_RegisterRead(uint8_t reg) { uint8_t MMA8652FC::I2C_RegisterRead(uint8_t reg) {
uint8_t tx_data[1]; uint8_t tx_data[1];
HAL_I2C_Mem_Read(i2c, MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, tx_data, 1, 0xFFFF); HAL_I2C_Mem_Read(i2c, MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT,
tx_data, 1, 500);
return tx_data[0]; return tx_data[0];
} }
@@ -41,17 +43,19 @@ void MMA8652FC::initalize() {
I2C_RegisterWrite( HP_FILTER_CUTOFF_REG, 0x03); //select high pass filtered data I2C_RegisterWrite( HP_FILTER_CUTOFF_REG, 0x03); //select high pass filtered data
I2C_RegisterWrite( CTRL_REG1, 0x19); // ODR=12 Hz, Active mode I2C_RegisterWrite( CTRL_REG1, 0x19); // ODR=12 Hz, Active mode
HAL_Delay(2); // ~1ms delay
} }
void MMA8652FC::setSensitivity(uint8_t threshold, uint8_t filterTime) { void MMA8652FC::setSensitivity(uint8_t threshold, uint8_t filterTime) {
uint8_t sens = 9 * 2 + 17; uint8_t sens = 9 * 2 + 17;
sens -= 2 * threshold; sens -= 2 * threshold;
taskENTER_CRITICAL();
I2C_RegisterWrite( CTRL_REG1, 0); // sleep mode I2C_RegisterWrite( CTRL_REG1, 0); // sleep mode
I2C_RegisterWrite(FF_MT_THS_REG, (sens & 0x7F)); // Set accumulation threshold I2C_RegisterWrite(FF_MT_THS_REG, (sens & 0x7F));// Set accumulation threshold
I2C_RegisterWrite(FF_MT_COUNT_REG, filterTime); // Set debounce threshold I2C_RegisterWrite(FF_MT_COUNT_REG, filterTime); // Set debounce threshold
I2C_RegisterWrite( CTRL_REG1, 0x31); // ODR=12 Hz, Active mode I2C_RegisterWrite( CTRL_REG1, 0x31); // ODR=12 Hz, Active mode
taskEXIT_CRITICAL();
} }
bool MMA8652FC::getOrientation() { bool MMA8652FC::getOrientation() {
@@ -69,8 +73,8 @@ bool MMA8652FC::getOrientation() {
void MMA8652FC::getAxisReadings(int16_t *x, int16_t *y, int16_t *z) { void MMA8652FC::getAxisReadings(int16_t *x, int16_t *y, int16_t *z) {
uint8_t tempArr[6]; uint8_t tempArr[6];
taskENTER_CRITICAL(); taskENTER_CRITICAL();
while (HAL_I2C_Mem_Read(i2c, MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*) tempArr, 6, while (HAL_I2C_Mem_Read(i2c, MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG,
0xFFFF) != HAL_OK) { I2C_MEMADD_SIZE_8BIT, (uint8_t*) tempArr, 6, 0xFFFF) != HAL_OK) {
HAL_Delay(5); HAL_Delay(5);
} }
taskEXIT_CRITICAL(); taskEXIT_CRITICAL();

View File

@@ -90,7 +90,7 @@ void OLED::refresh() {
//Because I2C is shared, we cant task switch in the middle of the xfer //Because I2C is shared, we cant task switch in the middle of the xfer
HAL_I2C_Master_Transmit(i2c, DEVICEADDR_OLED, screenBuffer, 12 + 96 * 2 + 1, HAL_I2C_Master_Transmit(i2c, DEVICEADDR_OLED, screenBuffer, 12 + 96 * 2 + 1,
0xFFFF); 500);
taskEXIT_CRITICAL(); taskEXIT_CRITICAL();
} }

View File

@@ -149,7 +149,7 @@ static void MX_ADC1_Init(void) {
static void MX_I2C1_Init(void) { static void MX_I2C1_Init(void) {
hi2c1.Instance = I2C1; hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 100000; hi2c1.Init.ClockSpeed = 20000;
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c1.Init.OwnAddress1 = 0; hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

View File

@@ -166,13 +166,11 @@ static void waitForButtonPress() {
while (buttons) { while (buttons) {
buttons = getButtonState(); buttons = getButtonState();
GUIDelay(); GUIDelay();
HAL_IWDG_Refresh(&hiwdg);
lcd.refresh(); lcd.refresh();
} }
while (!buttons) { while (!buttons) {
buttons = getButtonState(); buttons = getButtonState();
GUIDelay(); GUIDelay();
HAL_IWDG_Refresh(&hiwdg);
lcd.refresh(); lcd.refresh();
} }
} }
@@ -185,7 +183,6 @@ void waitForButtonPressOrTimeout(uint32_t timeout) {
if (buttons) return; if (buttons) return;
if (HAL_GetTick() > timeout) return; if (HAL_GetTick() > timeout) return;
GUIDelay(); GUIDelay();
HAL_IWDG_Refresh(&hiwdg);
} }
} }
@@ -372,7 +369,6 @@ static void gui_settingsMenu() {
lcd.refresh(); // update the LCD lcd.refresh(); // update the LCD
osDelay(20); osDelay(20);
HAL_IWDG_Refresh(&hiwdg);
} }
saveSettings(); saveSettings();
@@ -410,7 +406,7 @@ static int gui_showTipTempWarning() {
lcd.drawSymbol(1); lcd.drawSymbol(1);
} }
} }
if (systemSettings.coolingTempBlink && tipTemp > 50) { if (systemSettings.coolingTempBlink && tipTemp > 70) {
if (HAL_GetTick() % 500 < 250) lcd.clearScreen(); if (HAL_GetTick() % 500 < 250) lcd.clearScreen();
} }
lcd.refresh(); lcd.refresh();
@@ -420,9 +416,8 @@ static int gui_showTipTempWarning() {
else if (buttons == BUTTON_B_SHORT || buttons == BUTTON_BOTH) else if (buttons == BUTTON_B_SHORT || buttons == BUTTON_BOTH)
return 0; return 0;
if (tipTemp < 30) return 0; if (tipTemp < 50) return 0;//Exit the warning screen
HAL_IWDG_Refresh(&hiwdg);
GUIDelay(); GUIDelay();
} }
} }
@@ -493,7 +488,6 @@ static int gui_SolderingSleepingMode() {
} }
lcd.refresh(); lcd.refresh();
GUIDelay(); GUIDelay();
HAL_IWDG_Refresh(&hiwdg);
} }
} }
static void gui_solderingMode() { static void gui_solderingMode() {
@@ -643,7 +637,6 @@ static void gui_solderingMode() {
} }
} }
GUIDelay(); GUIDelay();
HAL_IWDG_Refresh(&hiwdg);
} }
} }
#define ACCELDEBUG 0 #define ACCELDEBUG 0
@@ -798,7 +791,6 @@ void startGUITask(void const *argument) {
lcd.refresh(); lcd.refresh();
animationStep++; animationStep++;
HAL_IWDG_Refresh(&hiwdg);
GUIDelay(); GUIDelay();
} }
} }