2020-02-15 22:09:55 +01:00
|
|
|
/* Reflow Oven Controller
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*
|
|
|
|
* This file is part of the Reflow Oven Controller Project.
|
|
|
|
*
|
|
|
|
* The reflow oven controller is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
2020-02-21 21:22:01 +01:00
|
|
|
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
|
2020-02-15 22:09:55 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with the reflow oven controller project.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-02-16 17:35:35 +01:00
|
|
|
/**
|
|
|
|
* @file main.c
|
|
|
|
* @brief Main file for firmware
|
|
|
|
*/
|
|
|
|
|
2020-01-26 21:07:54 +01:00
|
|
|
#include <stdlib.h>
|
2020-05-04 21:21:49 +02:00
|
|
|
#include <stdio.h>
|
2020-02-02 00:01:08 +01:00
|
|
|
#include <string.h>
|
2020-02-12 21:00:35 +01:00
|
|
|
#include <stm32/stm32f4xx.h>
|
|
|
|
#include <cmsis/core_cm4.h>
|
|
|
|
#include <setup/system_stm32f4xx.h>
|
|
|
|
#include <reflow-controller/systick.h>
|
|
|
|
#include <reflow-controller/adc-meas.h>
|
|
|
|
#include <reflow-controller/digio.h>
|
2020-04-26 21:23:25 +02:00
|
|
|
#include "fatfs/shimatta_sdio_driver/shimatta_sdio.h"
|
2020-02-12 21:00:35 +01:00
|
|
|
#include <stm-periph/stm32-gpio-macros.h>
|
2020-12-01 21:00:23 +01:00
|
|
|
#include <stm-periph/rcc-manager.h>
|
2020-02-12 21:06:52 +01:00
|
|
|
#include <stm-periph/uart.h>
|
2021-04-08 21:23:25 +02:00
|
|
|
#include <reflow-controller/periph-config/shell-uart-config.h>
|
2020-05-05 18:55:55 +02:00
|
|
|
#include <reflow-controller/oven-driver.h>
|
2020-02-25 20:05:48 +01:00
|
|
|
#include <fatfs/ff.h>
|
2020-11-29 19:04:10 +01:00
|
|
|
#include <reflow-controller/ui/gui.h>
|
2021-11-27 17:41:11 +01:00
|
|
|
#include <reflow-controller/ui/shell.h>
|
|
|
|
#include <reflow-controller/ui/shell-uart.h>
|
2020-07-09 22:31:42 +02:00
|
|
|
#include <reflow-controller/safety/safety-controller.h>
|
2020-08-16 20:33:25 +02:00
|
|
|
#include <reflow-controller/settings/settings.h>
|
2020-12-14 20:29:51 +01:00
|
|
|
#include <reflow-controller/safety/safety-memory.h>
|
|
|
|
#include <reflow-controller/safety/fault.h>
|
|
|
|
#include <reflow-controller/updater/updater.h>
|
2021-05-22 16:40:08 +02:00
|
|
|
#include <reflow-controller/temp-profile/temp-profile-executer.h>
|
2021-01-02 23:04:57 +01:00
|
|
|
#include <reflow-controller/settings/spi-eeprom.h>
|
2021-08-19 21:25:04 +02:00
|
|
|
#include <reflow-controller/main-cycle-counter.h>
|
2021-10-16 23:39:23 +02:00
|
|
|
#include <stm-periph/option-bytes.h>
|
2020-01-26 21:07:54 +01:00
|
|
|
|
2020-06-14 23:22:35 +02:00
|
|
|
static void setup_nvic_priorities(void)
|
2020-01-26 21:07:54 +01:00
|
|
|
{
|
2020-02-02 20:24:44 +01:00
|
|
|
/* No sub priorities */
|
|
|
|
NVIC_SetPriorityGrouping(2);
|
2020-01-26 21:07:54 +01:00
|
|
|
|
2020-02-02 20:24:44 +01:00
|
|
|
/* Setup Priorities */
|
2020-02-05 23:09:23 +01:00
|
|
|
NVIC_SetPriority(ADC_IRQn, 2);
|
2020-09-27 23:23:44 +02:00
|
|
|
/* Measurement ADC DMA */
|
2020-02-05 23:09:23 +01:00
|
|
|
NVIC_SetPriority(DMA2_Stream0_IRQn, 1);
|
2020-09-27 23:23:44 +02:00
|
|
|
/* Shelmatta UART TX */
|
2020-02-12 21:00:35 +01:00
|
|
|
NVIC_SetPriority(DMA2_Stream7_IRQn, 3);
|
2020-11-30 21:43:38 +01:00
|
|
|
NVIC_SetPriority(DMA2_Stream4_IRQn, 2);
|
2020-02-02 00:01:08 +01:00
|
|
|
}
|
|
|
|
|
2020-04-26 21:23:25 +02:00
|
|
|
FATFS fs;
|
2020-08-22 13:33:53 +02:00
|
|
|
#define fs_ptr (&fs)
|
2020-04-26 21:23:25 +02:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/**
|
|
|
|
* @brief Configure UART GPIOs
|
|
|
|
* In case the application is build in debug mode, use the TX/RX Pins on the debug header
|
|
|
|
* else the Pins on the DIGIO header are configured in the digio module and this function does nothing.
|
|
|
|
*/
|
2020-06-14 23:22:35 +02:00
|
|
|
static inline void uart_gpio_config(void)
|
2020-02-24 18:50:09 +01:00
|
|
|
{
|
2020-11-01 21:22:28 +01:00
|
|
|
#if defined(DEBUGBUILD) || defined(UART_ON_DEBUG_HEADER)
|
2020-02-24 18:50:09 +01:00
|
|
|
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(SHELL_UART_PORT_RCC_MASK));
|
|
|
|
SHELL_UART_PORT->MODER &= MODER_DELETE(SHELL_UART_TX_PIN) & MODER_DELETE(SHELL_UART_RX_PIN);
|
|
|
|
SHELL_UART_PORT->MODER |= ALTFUNC(SHELL_UART_RX_PIN) | ALTFUNC(SHELL_UART_TX_PIN);
|
|
|
|
SETAF(SHELL_UART_PORT, SHELL_UART_RX_PIN, SHELL_UART_RX_PIN_ALTFUNC);
|
|
|
|
SETAF(SHELL_UART_PORT, SHELL_UART_TX_PIN, SHELL_UART_TX_PIN_ALTFUNC);
|
2020-06-21 01:29:50 +02:00
|
|
|
|
|
|
|
/* Setup Pullup resistor at UART RX */
|
|
|
|
SHELL_UART_PORT->PUPDR |= PULLUP(SHELL_UART_RX_PIN);
|
2020-02-24 18:50:09 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/**
|
|
|
|
* @brief Mount the SD card if available and not already mounted
|
|
|
|
* @param mounted The current mounting state of the SD card
|
|
|
|
* @return true if mounted, false if an error occured or the SD is not inserted and cannot be mounted
|
|
|
|
*/
|
2020-04-26 21:23:25 +02:00
|
|
|
static bool mount_sd_card_if_avail(bool mounted)
|
|
|
|
{
|
|
|
|
FRESULT res;
|
2020-08-21 23:25:03 +02:00
|
|
|
static uint8_t IN_SECTION(.ccm.bss) inserted_counter = 0;
|
2020-04-26 21:23:25 +02:00
|
|
|
|
|
|
|
if (sdio_check_inserted() && mounted) {
|
|
|
|
memset(fs_ptr, 0, sizeof(FATFS));
|
2020-08-17 22:10:04 +02:00
|
|
|
sdio_stop_clk();
|
|
|
|
inserted_counter = 0;
|
2020-04-26 21:23:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-17 22:10:04 +02:00
|
|
|
if (!sdio_check_inserted() && inserted_counter < 255)
|
|
|
|
inserted_counter++;
|
|
|
|
|
|
|
|
if (!sdio_check_inserted() && !mounted && inserted_counter > 4) {
|
|
|
|
inserted_counter = 0;
|
2020-04-26 21:23:25 +02:00
|
|
|
res = f_mount(fs_ptr, "0:/", 1);
|
2020-08-17 22:26:29 +02:00
|
|
|
if (res == FR_OK) {
|
|
|
|
led_set(1, 1);
|
2020-04-26 21:23:25 +02:00
|
|
|
return true;
|
2021-10-10 20:45:59 +02:00
|
|
|
} else {
|
2020-04-26 21:23:25 +02:00
|
|
|
return false;
|
2021-10-10 20:45:59 +02:00
|
|
|
}
|
2020-04-26 21:23:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return mounted;
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/**
|
|
|
|
* @brief Process the boot status structure in the safety (backup) RAM
|
|
|
|
* Depending on the flags set there, this function will:
|
|
|
|
* - Reboot into the ram code for reflashing
|
|
|
|
* - Display the PANIC message
|
|
|
|
* - Display if the flash has been successfully updated
|
|
|
|
*/
|
2020-12-14 20:29:51 +01:00
|
|
|
static inline void handle_boot_status(void)
|
|
|
|
{
|
|
|
|
struct safety_memory_boot_status status;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = safety_memory_get_boot_status(&status);
|
|
|
|
if (res != 0)
|
|
|
|
panic_mode();
|
2021-05-22 11:59:54 +02:00
|
|
|
|
|
|
|
if (status.reset_from_panic) {
|
|
|
|
/* We've seen a panic */
|
|
|
|
gui_root_menu_message_set("!! PANIC !!", "Check error me- mory!");
|
|
|
|
}
|
|
|
|
|
2020-12-14 20:29:51 +01:00
|
|
|
if (status.reboot_to_bootloader) {
|
|
|
|
status.reboot_to_bootloader = 0UL;
|
|
|
|
safety_memory_set_boot_status(&status);
|
|
|
|
|
|
|
|
led_set(0, 1);
|
|
|
|
led_set(1, 1);
|
|
|
|
|
2021-05-22 11:34:33 +02:00
|
|
|
gui_lcd_write_direct_blocking(0, "Updating...");
|
|
|
|
|
2021-04-06 20:55:41 +02:00
|
|
|
start_updater_ram_code();
|
2020-12-14 20:29:51 +01:00
|
|
|
}
|
2021-04-08 21:35:19 +02:00
|
|
|
|
|
|
|
if (status.code_updated) {
|
|
|
|
status.code_updated = 0x0UL;
|
|
|
|
safety_memory_set_boot_status(&status);
|
2021-05-22 00:14:56 +02:00
|
|
|
|
|
|
|
/* Display notification on GUI */
|
|
|
|
gui_root_menu_message_set("Firmware updated", "[Press Key]");
|
2021-04-08 21:35:19 +02:00
|
|
|
}
|
2020-12-14 20:29:51 +01:00
|
|
|
}
|
|
|
|
|
2021-10-16 23:39:23 +02:00
|
|
|
/**
|
|
|
|
* @brief Read out the option bytes of the STM32 and program them to the desired values.
|
|
|
|
*
|
|
|
|
* - This function currently forces the brown out level to Level 3.
|
|
|
|
*/
|
|
|
|
static void check_and_program_opt_bytes(void)
|
|
|
|
{
|
|
|
|
struct option_bytes opts;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/** - Read option bytes */
|
|
|
|
stm_option_bytes_read(&opts);
|
|
|
|
|
|
|
|
|
|
|
|
if (opts.brown_out_level != 0) {
|
|
|
|
/* Set the brown out level to level 3 => highest brown out limit. */
|
|
|
|
opts.brown_out_level = 0;
|
|
|
|
/** - Program the option bytes if brown out level was not set correctly */
|
|
|
|
err = stm_option_bytes_program(&opts);
|
|
|
|
|
|
|
|
/** - If programming failes, enter panic mode */
|
|
|
|
if (err)
|
|
|
|
panic_mode();
|
|
|
|
|
|
|
|
/** - If programming is successful, reset the system to apply new settings */
|
|
|
|
NVIC_SystemReset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/**
|
|
|
|
* @brief Setup the system.
|
|
|
|
*
|
|
|
|
* This function does all basic initializations of the MCU and its peripherals
|
|
|
|
*/
|
2020-06-14 23:22:35 +02:00
|
|
|
static inline void setup_system(void)
|
2020-05-05 18:55:55 +02:00
|
|
|
{
|
2021-02-15 20:28:45 +01:00
|
|
|
float tmp;
|
|
|
|
|
2021-10-16 23:39:23 +02:00
|
|
|
/** - Read the option bytes and if necessary program them to the desired values */
|
|
|
|
check_and_program_opt_bytes();
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Setup the NVIC priorities of the core peripherals using interrupts */
|
2020-02-02 20:24:44 +01:00
|
|
|
setup_nvic_priorities();
|
2020-12-14 20:29:51 +01:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Init safety controller and safety memory */
|
2020-12-14 20:29:51 +01:00
|
|
|
safety_controller_init();
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Setup the systick module generating the 100us tick fort the GUI and
|
|
|
|
* the 1ms tick for the global systick timestamp
|
|
|
|
*/
|
2020-02-02 00:01:08 +01:00
|
|
|
systick_setup();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Initialize the oven output driver outputting the wavepacket control signal for the SSR and */
|
2020-05-05 18:55:55 +02:00
|
|
|
oven_driver_init();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
2021-12-26 20:36:49 +01:00
|
|
|
/** - Initialize all DIGIO Pins to their default state and pin functions */
|
|
|
|
digio_init();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Set-up the LED outputs */
|
2020-02-10 22:38:24 +01:00
|
|
|
led_setup();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Set-up the loudspeaker / beeper output */
|
2020-02-10 22:38:24 +01:00
|
|
|
loudspeaker_setup();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Initialize the GUI */
|
2020-11-29 19:04:10 +01:00
|
|
|
gui_init();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Initialize the pins for the uart interface. */
|
2020-02-24 18:50:09 +01:00
|
|
|
uart_gpio_config();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Set-up the settings module */
|
2021-01-08 18:39:54 +01:00
|
|
|
settings_setup();
|
2020-12-14 20:29:51 +01:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Load the overtemperature limit from eeprom if available. Otherwise the default value will be used */
|
2021-10-10 20:45:59 +02:00
|
|
|
if (settings_load_overtemp_limit(&tmp) == SETT_LOAD_SUCCESS)
|
2021-02-15 20:28:45 +01:00
|
|
|
safety_controller_set_overtemp_limit(tmp);
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Handle the boot status struct in the safety memory */
|
2020-12-14 20:29:51 +01:00
|
|
|
handle_boot_status();
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Initialize the shell UART */
|
2021-11-27 17:41:11 +01:00
|
|
|
shell_uart_setup();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Enable the ADC for PT1000 measurement */
|
2020-07-28 21:00:37 +02:00
|
|
|
adc_pt1000_setup_meas();
|
2020-05-05 18:55:55 +02:00
|
|
|
}
|
2020-02-09 19:13:37 +01:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/**
|
|
|
|
* @brief Handle the input for the shell instance.
|
|
|
|
*
|
|
|
|
* This function will check if the RX ring buffer of the UART contains data.
|
|
|
|
* If so, it will prowvide it to the shellmatta shell.
|
|
|
|
*
|
|
|
|
* @param shell_handle Handle to the shellmatta instance
|
|
|
|
*/
|
2020-05-11 21:51:32 +02:00
|
|
|
static void handle_shell_uart_input(shellmatta_handle_t shell_handle)
|
2020-05-05 18:55:55 +02:00
|
|
|
{
|
2020-05-11 21:51:32 +02:00
|
|
|
int uart_receive_status;
|
2020-05-05 18:55:55 +02:00
|
|
|
const char *uart_input;
|
|
|
|
size_t uart_input_len;
|
2020-05-11 21:51:32 +02:00
|
|
|
|
2020-06-13 22:47:45 +02:00
|
|
|
/* Handle UART input for shell */
|
2021-11-27 17:41:11 +01:00
|
|
|
uart_receive_status = shell_uart_receive_data_with_dma(&uart_input, &uart_input_len);
|
2020-05-11 21:51:32 +02:00
|
|
|
if (uart_receive_status >= 0)
|
|
|
|
shell_handle_input(shell_handle, uart_input, uart_input_len);
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/**
|
|
|
|
* @brief This is the main function containing the initilizations and the cyclic main loop
|
|
|
|
* @return Don't care. This function will never return. We're on an embedded device...
|
|
|
|
*/
|
2020-06-14 23:22:35 +02:00
|
|
|
int main(void)
|
2020-05-11 21:51:32 +02:00
|
|
|
{
|
2020-08-16 20:33:25 +02:00
|
|
|
bool cal_active;
|
|
|
|
float offset;
|
|
|
|
float sens;
|
|
|
|
int status;
|
2020-05-11 21:51:32 +02:00
|
|
|
bool sd_card_mounted = false;
|
2020-08-16 20:33:25 +02:00
|
|
|
bool sd_old;
|
2020-05-05 18:55:55 +02:00
|
|
|
shellmatta_handle_t shell_handle;
|
2020-06-12 01:35:37 +02:00
|
|
|
int menu_wait_request;
|
2020-06-13 22:47:45 +02:00
|
|
|
uint64_t quarter_sec_timestamp = 0ULL;
|
2022-07-30 16:04:46 +02:00
|
|
|
enum config_weight worst_safety_flag = SAFETY_FLAG_CONFIG_WEIGHT_NONE;
|
2021-01-08 18:39:54 +01:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Setup all the peripherals and external componets like LCD, EEPROM etc. and the safety controller */
|
2020-05-05 18:55:55 +02:00
|
|
|
setup_system();
|
2020-05-04 21:21:49 +02:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Try load the calibration. This will only succeed if there's an EEPROM */
|
2021-01-08 18:39:54 +01:00
|
|
|
status = settings_load_calibration(&sens, &offset);
|
2021-10-10 20:45:59 +02:00
|
|
|
if (!status)
|
2021-01-08 18:39:54 +01:00
|
|
|
adc_pt1000_set_resistance_calibration(offset, sens, true);
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Initialize the shellmatta shell */
|
2021-11-27 17:41:11 +01:00
|
|
|
shell_handle = shell_init(shell_uart_write_callback);
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Print motd to shell */
|
2020-04-26 21:23:25 +02:00
|
|
|
shell_print_motd(shell_handle);
|
2020-02-09 19:13:37 +01:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Set the main cycle counter to 0 */
|
2021-08-19 21:25:04 +02:00
|
|
|
main_cycle_counter_init();
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Do a loop over the following */
|
2020-02-21 23:37:48 +01:00
|
|
|
while (1) {
|
2020-04-26 21:23:25 +02:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - If 250 ms have passed since the last time this step was reached, we try to initialize the
|
|
|
|
* SD card. If the card has been mounted and there is no current resistance calibration,
|
|
|
|
* it is tried to load it from SD card.
|
|
|
|
*/
|
2020-06-14 23:22:35 +02:00
|
|
|
if (systick_ticks_have_passed(quarter_sec_timestamp, 250)) {
|
2022-07-30 15:53:04 +02:00
|
|
|
led_set(1u, 0);
|
2020-08-16 20:33:25 +02:00
|
|
|
sd_old = sd_card_mounted;
|
2020-08-16 12:34:41 +02:00
|
|
|
sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
|
2020-08-16 20:33:25 +02:00
|
|
|
|
|
|
|
if (sd_card_mounted && !sd_old) {
|
|
|
|
adc_pt1000_get_resistance_calibration(NULL, NULL, &cal_active);
|
|
|
|
if (!cal_active) {
|
|
|
|
status = settings_load_calibration(&sens, &offset);
|
2021-10-10 20:45:59 +02:00
|
|
|
if (!status)
|
2020-08-16 20:33:25 +02:00
|
|
|
adc_pt1000_set_resistance_calibration(offset, sens, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-30 15:53:04 +02:00
|
|
|
/* Check if any flags are present, that disable the PID controller. Blink
|
|
|
|
* LED 0 in this case
|
|
|
|
*/
|
2022-07-30 16:04:46 +02:00
|
|
|
if (worst_safety_flag >= SAFETY_FLAG_CONFIG_WEIGHT_PID)
|
2022-07-30 15:53:04 +02:00
|
|
|
led_set(0u, led_get(0u) ? 0 : 1);
|
|
|
|
else
|
|
|
|
led_set(0u, 0);
|
|
|
|
|
2020-06-13 22:47:45 +02:00
|
|
|
quarter_sec_timestamp = systick_get_global_tick();
|
2020-04-20 21:12:40 +02:00
|
|
|
}
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Handle the GUI */
|
2020-11-29 19:04:10 +01:00
|
|
|
menu_wait_request = gui_handle();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Handle the uart input for the shell */
|
2020-06-14 19:09:59 +02:00
|
|
|
handle_shell_uart_input(shell_handle);
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Execute current profile step, if a profile is active */
|
2021-03-19 20:19:37 +01:00
|
|
|
temp_profile_executer_handle();
|
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Handle the safety controller. This must be called! Otherwise a watchdog reset will occur */
|
2022-07-30 16:04:46 +02:00
|
|
|
worst_safety_flag = safety_controller_handle();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - If the Oven PID controller is running, we handle its sample function */
|
2021-10-10 20:45:59 +02:00
|
|
|
if (oven_pid_get_status() == OVEN_PID_RUNNING)
|
2020-11-30 21:43:38 +01:00
|
|
|
oven_pid_handle();
|
2021-10-10 20:45:59 +02:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Apply the power level of the oven driver */
|
2020-07-09 22:31:42 +02:00
|
|
|
oven_driver_apply_power_level();
|
2021-10-11 19:45:13 +02:00
|
|
|
|
|
|
|
/** - Report the main loop timing to the timing monitor to detect a slowed down main loop */
|
2020-08-16 12:34:41 +02:00
|
|
|
safety_controller_report_timing(ERR_TIMING_MAIN_LOOP);
|
2021-01-02 23:04:57 +01:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - If the menu requests a directly following loop run, the main loop will continue.
|
|
|
|
* Otherwise it will wait for the next interrupt
|
|
|
|
*/
|
2020-06-14 01:31:44 +02:00
|
|
|
if (menu_wait_request)
|
2020-05-09 19:56:47 +02:00
|
|
|
__WFI();
|
2020-06-25 23:52:58 +02:00
|
|
|
else
|
|
|
|
__NOP();
|
2021-10-11 19:45:13 +02:00
|
|
|
/** - Increment the main cycle counter */
|
2021-08-19 21:25:04 +02:00
|
|
|
main_cycle_counter_inc();
|
2020-01-26 21:07:54 +01:00
|
|
|
}
|
|
|
|
|
2020-06-14 23:22:35 +02:00
|
|
|
return 0;
|
2020-01-26 21:07:54 +01:00
|
|
|
}
|
2020-02-24 18:50:09 +01:00
|
|
|
|
2021-10-11 19:45:13 +02:00
|
|
|
/**
|
|
|
|
* @brief Callback function for the SDIO driver to wait \p ms milliseconds
|
|
|
|
* @param ms
|
|
|
|
* @warning This function relies on the systick and must not be used in interrupt context.
|
|
|
|
*/
|
2020-02-25 20:05:48 +01:00
|
|
|
void sdio_wait_ms(uint32_t ms)
|
|
|
|
{
|
|
|
|
systick_wait_ms(ms);
|
|
|
|
}
|