Class B Error insertion.
Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include "oven.h"
#include "oven_classb.h"
#include "oven_ui.h"
#include <avr/eeprom.h>
#include <string.h>
#include <error_handler.h>
#include <classb_analog.h>
#include <classb_sram.h>
#include <classb_cpu.h>
#include <classb_freq.h>
#include <classb_interrupt_monitor.h>
#include <classb_rtc_common.h>
#include <classb_crc.h>
Functions | |
static void | adc_foul_callback (ADC_t *adc, uint8_t ch_mask, adc_result_t res) |
Callback function that changes ADC settings. More... | |
void | oven_classb_display_error (void) |
Print error message depending on the value of classb_error. More... | |
void | oven_classb_error_insertion (void) |
Show menu for error insertion and handle user's selection. More... | |
static void | oven_classb_flash_corrupter (void) |
Simulate corruption of a part of Flash. More... | |
Class B test initialization and functional test execution | |
void | oven_classb_init_tests (void) |
Initialize Class B tests. More... | |
void | oven_classb_run_tests (void) |
Run all Class B tests. More... | |
Variables | |
Test-related variables | |
uint32_t classb_precalculated_flash_crc | EEMEM = 0x8dbd81d8 |
Pre-calculated CRC32 value for the flash memory, stored in EEPROM. More... | |
static volatile uint16_t | variable_for_sram_error = 0xBEEF |
Memory location that will be scrambled on SRAM error insertion. More... | |
static uint16_t | flash_scramble_buf [FLASH_PAGE_SIZE/2] = {0xCC} |
Page buffer used when changing Flash contents. More... | |
volatile uint32_t | checksum_test_flash = 0 |
Flash CRC value calculated by Class B test. More... | |
Error strings and menu | |
enum | error_string_ids { ERR_NONE, ERR_AIO, ERR_CRC, ERR_FRQ, ERR_INT, ERR_CPU, ERR_SRAM, ERR_WDT, ERR_TMP, ERR_OTHER } |
Error cause string list enumerator. More... | |
PROGMEM_STRING_T | error_menu_strings [] |
struct gfx_mono_menu | error_menu |
char * | classb_error_messages [] |
Class B error cause strings. More... | |
PROGMEM_DECLARE (char const, error_menu_title[]) | |
PROGMEM_DECLARE (char const, error_menu_1[]) | |
PROGMEM_DECLARE (char const, error_menu_2[]) | |
PROGMEM_DECLARE (char const, error_menu_3[]) | |
PROGMEM_DECLARE (char const, error_menu_4[]) | |
PROGMEM_DECLARE (char const, error_menu_5[]) | |
PROGMEM_DECLARE (char const, error_menu_6[]) | |
PROGMEM_DECLARE (char const, error_menu_7[]) | |
enum error_string_ids |
|
static |
Callback function that changes ADC settings.
This callback function for the ADC driver is used to change the ADC reference after the next completed conversion, simulating a problem with the voltage reference. It will be triggered after the next completed conversion.
The fault will be detected when the analog IO test is run, i.e., when the user turns up the power of the plate from 0.
References ADC_REFSEL_INTVCC_gc, adcch_disable_interrupt(), adcch_read_configuration(), and adcch_write_configuration().
Referenced by oven_classb_error_insertion().
void oven_classb_display_error | ( | void | ) |
Print error message depending on the value of classb_error.
References classb_error, CLASSB_ERROR_ANALOG, CLASSB_ERROR_CPU, CLASSB_ERROR_CRC, CLASSB_ERROR_FREQ, CLASSB_ERROR_INT, classb_error_messages, CLASSB_ERROR_NONE, CLASSB_ERROR_OTHER, CLASSB_ERROR_SRAM, CLASSB_ERROR_WDT, ERR_AIO, ERR_CPU, ERR_CRC, ERR_FRQ, ERR_INT, ERR_NONE, ERR_OTHER, ERR_SRAM, ERR_TMP, ERR_WDT, gfx_mono_draw_filled_rect, gfx_mono_draw_string(), GFX_PIXEL_CLR, and sysfont.
Referenced by main().
void oven_classb_error_insertion | ( | void | ) |
Show menu for error insertion and handle user's selection.
This function changes device configurations and does some hacks to make the device behave incorrectly.
The menu entries are
References ADC_CH0, ADC_CH2, adc_foul_callback(), adc_set_callback(), adcch_enable_interrupt(), adcch_read_configuration(), adcch_write_configuration(), GFX_MONO_MENU_EVENT_EXIT, GFX_MONO_MENU_EVENT_IDLE, gfx_mono_menu_init(), gfx_mono_menu_process_key(), keyboard_get_key_state(), KEYBOARD_RELEASE, keyboard_event::keycode, oven_classb_flash_corrupter(), OVEN_PERIODIC_TEMPTEST_TC, oven_wdt_periodic_reset, sysclk_set_prescalers(), keyboard_event::type, and variable_for_sram_error.
Referenced by main().
|
static |
Simulate corruption of a part of Flash.
This function simulates corruption of the Flash by modifying one of the strings in the error insertion menu. More specifically it replaces the "-- Error insertion --" menu title with "Out of cheese!". If called again, the original string is reverted.
References FLASH_PAGE_SIZE, flash_scramble_buf, nvm_flash_atomic_write_app_page(), nvm_flash_flush_buffer(), nvm_flash_load_word_to_buffer(), nvm_flash_read_word(), and oven_wdt_periodic_reset.
Referenced by oven_classb_error_insertion().
void oven_classb_init_tests | ( | void | ) |
Initialize Class B tests.
Set up timers, timer callbacks, initialize interrupt monitor, add interrupts to be monitored.
References classb_freq_setup_timer(), classb_freq_tc_callback(), CLASSB_FREQTEST_TC, classb_intmon_reg_int(), classb_rtc_callback(), CLASSB_RTC_INT_PERIOD, PER_CLASSB_TESTS, RTC32, rtc_set_alarm_relative(), rtc_set_callback(), tc_enable(), tc_set_overflow_interrupt_callback(), and TEMP_SANITY_TEST.
Referenced by main().
void oven_classb_run_tests | ( | void | ) |
Run all Class B tests.
Destructively test ADC and DAC; modules must be reinitialized for application use. Then test the SRAM, CPU registers and CRC of Flash (if enabled).
References adc_enable(), classb_analog_io_test(), classb_error, CLASSB_ERROR_NONE, CLASSB_NSECS, classb_register_test(), classb_sram_test(), dac_enable(), oven_ui_set_status_leds(), S_GREEN, S_ORANGE, and S_RED.
Referenced by ovenctl_turn_on_plate().
PROGMEM_DECLARE | ( | char | const, |
error_menu_title | [] | ||
) |
PROGMEM_DECLARE | ( | char | const, |
error_menu_1 | [] | ||
) |
PROGMEM_DECLARE | ( | char | const, |
error_menu_2 | [] | ||
) |
PROGMEM_DECLARE | ( | char | const, |
error_menu_3 | [] | ||
) |
PROGMEM_DECLARE | ( | char | const, |
error_menu_4 | [] | ||
) |
PROGMEM_DECLARE | ( | char | const, |
error_menu_5 | [] | ||
) |
PROGMEM_DECLARE | ( | char | const, |
error_menu_6 | [] | ||
) |
PROGMEM_DECLARE | ( | char | const, |
error_menu_7 | [] | ||
) |
volatile uint32_t checksum_test_flash = 0 |
Flash CRC value calculated by Class B test.
char* classb_error_messages[] |
Class B error cause strings.
Referenced by oven_classb_display_error().
uint32_t classb_precalculated_flash_crc EEMEM = 0x8dbd81d8 |
Pre-calculated CRC32 value for the flash memory, stored in EEPROM.
struct gfx_mono_menu error_menu |
PROGMEM_STRING_T error_menu_strings[] |
|
static |
Page buffer used when changing Flash contents.
Referenced by oven_classb_flash_corrupter().
|
static |
Memory location that will be scrambled on SRAM error insertion.
Referenced by oven_classb_error_insertion().