Microchip® Advanced Software Framework

oven_classb.c File Reference

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[])
 

Error cause string list enumerator.

Enumerator
ERR_NONE 
ERR_AIO 
ERR_CRC 
ERR_FRQ 
ERR_INT 
ERR_CPU 
ERR_SRAM 
ERR_WDT 
ERR_TMP 
ERR_OTHER 

static void adc_foul_callback ( ADC_t *  adc,
uint8_t  ch_mask,
adc_result_t  res 
)
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_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

  • Change clock frequency: Changes the peripheral clock divider, simulating that the clock system has malfunctioned. This should be detected by the Class B frequency consistency test.
  • Mess with test timer: Changes how often periodic tests are performed, simulating an error with an interrupt timer. This should be detected by the Class B interrupt monitor.
  • Change a Flash section: Changes the string for the menu title stored in program memory to "Out of cheese", simulating Flash memory corruption. This can be changed back by selecting the menu item again. This should be detected by the Class B Flash CRC test.
  • Scramble SRAM section: Starts a continuous DMA transfer in the background to a memory location, simulating transient SRAM corruption. This should be detected by the periodic and power-on Class B SRAM test.
  • Enter infinite loop: Simulates a runaway program counter by looping forever. This should be detected by the watchdog timer system which is tested on device power-up.
  • Change ADC reference: Enables a callback function for the ADC, which will change the voltage reference after the next completed conversion. This will cause the analog IO test to fail when user turns up the power to the plate.

References ADC_CH0, 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 void oven_classb_flash_corrupter ( void  )
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.

Note
This has been made global and volatile so debuggers will display it correctly.
char* classb_error_messages[]
Initial value:
= {
"No error",
"Analog IO",
"CRC Checksum",
"CPU Clock frequency",
"Interrupt monitor",
"Register file",
"SRAM",
"Watchdog Timer",
"Temp sanity",
"Other - unknown"
}

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
Initial value:
= {
error_menu_title,
6,
0
}
PROGMEM_STRING_T error_menu_strings[]
Definition: oven_classb.c:96
PROGMEM_STRING_T error_menu_strings[]
Initial value:
= {
error_menu_1,
error_menu_2,
error_menu_3,
error_menu_4,
error_menu_5,
error_menu_6,
error_menu_7,
}
uint16_t flash_scramble_buf[FLASH_PAGE_SIZE/2] = {0xCC}
static

Page buffer used when changing Flash contents.

Referenced by oven_classb_flash_corrupter().

volatile uint16_t variable_for_sram_error = 0xBEEF
static

Memory location that will be scrambled on SRAM error insertion.

Referenced by oven_classb_error_insertion().