Atmel Software Framework

sam/applications/starter_kit_bootloader_demo/main/main.c File Reference

Main application of Starter Kit Bootloader Demo.

Copyright (c) 2013-2015 Atmel Corporation. All rights reserved.

#include <asf.h>
#include <string.h>
#include "conf_example.h"
#include "multi_language_display.h"

Macros

#define BUFFER_SIZE   (128)
 
#define DATA_SIZE   (512)
 Size of the data to write/read. More...
 
#define IRQ_PRIOR_PIO   (0)
 

Enumerations

enum  language_mode {
  LANGUAGE_ENGLISH = 0,
  LANGUAGE_CHINESE,
  LANGUAGE_FRENCH,
  LANGUAGE_JAPANESE,
  LANGUAGE_SPANISH,
  LANGUAGE_NUMBER
}
 

Functions

static void button1_handler (uint32_t id, uint32_t mask)
 Handler for Button 1 rising edge interrupt. More...
 
static void button2_handler (uint32_t id, uint32_t mask)
 Handler for Button 2 rising edge interrupt. More...
 
static void button3_handler (uint32_t id, uint32_t mask)
 Handler for Button 3 rising edge interrupt. More...
 
static void check_valid_firmware (void)
 Check for valid firmware in SD card. More...
 
static void configure_adc (void)
 Configure the ADC for the light sensor. More...
 
static void configure_buttons (void)
 Configure the Pushbuttons. More...
 
static void display_sd_files_unicode (void)
 Show SD card content on the OLED screen. More...
 
static void display_sd_info (void)
 Show SD card status on the OLED screen. More...
 
static void get_num_files_on_sd (void)
 Get the number of files at the root of the SD card. More...
 
static void jump_to_bootloader (void)
 Set the trigger for bootloader and perform a software reset to let the bootloader to perform firmware update process. More...
 
int main (void)
 The main application. More...
 
static void process_button_event (uint8_t uc_button)
 Process Buttons Events. More...
 
static void sd_detect_handler (uint32_t id, uint32_t mask)
 Handler for SD card detect rising edge interrupt. More...
 
static void ssd1306_clear_char (void)
 Clear one character at the cursor current position on the OLED screen. More...
 
static void ssd1306_draw_graph (uint8_t col, uint8_t page, uint8_t width, uint8_t height, uint8_t *tab)
 Draw graph on the OLED screen using the provided point array. More...
 
static void sw0_handler (uint32_t id, uint32_t mask)
 Handler for SW0 rising edge interrupt. More...
 

Variables

volatile uint32_t app_mode = 2
 
volatile uint32_t app_mode_switch = 1
 
DIR dir
 
uint8_t file_name_ascii [5][12]
 
TCHAR file_name_unicode [5][14]
 
FIL file_object
 
volatile uint32_t firmware_type = 0
 
FATFS fs
 
volatile uint32_t reset_flag = 0
 
volatile uint32_t sd_fs_found = 0
 
volatile uint32_t sd_listing_pos = 0
 
volatile uint32_t sd_num_files = 0
 
volatile uint32_t sd_update = 0
 
static uint8_t trigger_page [DATA_SIZE]
 
volatile uint32_t valid_firmware_found = 0
 

#define BUFFER_SIZE   (128)

Referenced by main().

#define DATA_SIZE   (512)

Size of the data to write/read.

#define IRQ_PRIOR_PIO   (0)

Referenced by configure_buttons().

Enumerator
LANGUAGE_ENGLISH 
LANGUAGE_CHINESE 
LANGUAGE_FRENCH 
LANGUAGE_JAPANESE 
LANGUAGE_SPANISH 
LANGUAGE_NUMBER 

static void button1_handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for Button 1 rising edge interrupt.

Parameters
idThe button ID.
maskThe button mask.

References process_button_event().

Referenced by configure_buttons().

static void button2_handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for Button 2 rising edge interrupt.

Parameters
idThe button ID.
maskThe button mask.

References process_button_event().

Referenced by configure_buttons().

static void button3_handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for Button 3 rising edge interrupt.

Parameters
idThe button ID.
maskThe button mask.

References process_button_event().

Referenced by configure_buttons().

static void configure_adc ( void  )
static
static void configure_buttons ( void  )
static

Configure the Pushbuttons.

Configure the PIO as inputs and generate corresponding interrupt when pressed or released.

References button1_handler(), button2_handler(), button3_handler(), IRQ_PRIOR_PIO, pio_enable_interrupt(), pio_set_debounce_filter(), pmc_enable_periph_clk(), sd_detect_handler(), and sw0_handler().

Referenced by main().

static void display_sd_files_unicode ( void  )
static

Show SD card content on the OLED screen.

Note
Does not browse sub folders.

References _MAX_LFN, f_opendir(), f_readdir(), FILINFO::fname, FR_OK, multi_language_show_file_name(), res, and sd_listing_pos.

Referenced by main().

static void get_num_files_on_sd ( void  )
static

Get the number of files at the root of the SD card.

Result is stored in global sd_num_files.

References _MAX_LFN, f_opendir(), f_readdir(), FILINFO::fname, FR_OK, res, and sd_num_files.

Referenced by display_sd_info().

static void jump_to_bootloader ( void  )
static

Set the trigger for bootloader and perform a software reset to let the bootloader to perform firmware update process.

References delay_ms, file_name_ascii, firmware_type, FLASH_RC_OK, flash_unlock(), flash_write(), IFLASH_ERASE_PAGES_16, IFLASH_ERASE_PAGES_8, LANGUAGE_NUMBER, multi_language_show_end_info(), NULL, rstc_start_software_reset(), ssd1306_clear(), and trigger_page.

Referenced by main().

static void process_button_event ( uint8_t  uc_button)
static

Process Buttons Events.

Parameters
uc_buttonThe button number.

References app_mode, app_mode_switch, pio_disable_interrupt(), sd_fs_found, sd_listing_pos, sd_num_files, and sd_update.

Referenced by button1_handler(), button2_handler(), and button3_handler().

static void sd_detect_handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for SD card detect rising edge interrupt.

Parameters
idThe button ID.
maskThe button mask.

References sd_fs_found, sd_listing_pos, sd_num_files, and sd_update.

Referenced by configure_buttons().

static void ssd1306_clear_char ( void  )
static

Clear one character at the cursor current position on the OLED screen.

References ssd1306_write_data().

Referenced by main().

static void ssd1306_draw_graph ( uint8_t  col,
uint8_t  page,
uint8_t  width,
uint8_t  height,
uint8_t *  tab 
)
static

Draw graph on the OLED screen using the provided point array.

Parameters
colX coordinate.
pageY coordinate (please refer to OLED datasheet for page description).
widthGraph width(columns).
heightGraph height(pages, 1~3).
tabData to draw. Must contain width elements.

References bit_reverse8, SSD1306_CMD_SET_PAGE_START_ADDRESS, ssd1306_set_column_address(), ssd1306_write_command(), and ssd1306_write_data().

Referenced by main().

static void sw0_handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for SW0 rising edge interrupt.

Parameters
idThe button ID.
maskThe button mask.

References reset_flag, and valid_firmware_found.

Referenced by configure_buttons().

volatile uint32_t app_mode = 2

Referenced by main(), and process_button_event().

volatile uint32_t app_mode_switch = 1

Referenced by main(), and process_button_event().

uint8_t file_name_ascii[5][12]
Initial value:
= {
{0x64, 0x65, 0x6D, 0x6F, 0x5F, 0x65, 0x6E, 0x2E, 0x62, 0x69, 0x6E, 0x00},
{0x64, 0x65, 0x6D, 0x6F, 0x5F, 0x63, 0x6E, 0x2E, 0x62, 0x69, 0x6E, 0x00},
{0x64, 0x65, 0x6D, 0x6F, 0x5F, 0x66, 0x72, 0x2E, 0x62, 0x69, 0x6E, 0x00},
{0x64, 0x65, 0x6D, 0x6F, 0x5F, 0x6A, 0x70, 0x2E, 0x62, 0x69, 0x6E, 0x00},
{0x64, 0x65, 0x6D, 0x6F, 0x5F, 0x73, 0x70, 0x2E, 0x62, 0x69, 0x6E, 0x00}
}

Referenced by jump_to_bootloader().

TCHAR file_name_unicode[5][14]
Initial value:
= {
{0x0030, 0x003A, 0x0064, 0x0065, 0x006D, 0x006F, 0x005F,
0x0065, 0x006E, 0x002E, 0x0062, 0x0069, 0x006E, 0x0000},
{0x0030, 0x003A, 0x0064, 0x0065, 0x006D, 0x006F, 0x005F,
0x0063, 0x006E, 0x002E, 0x0062, 0x0069, 0x006E, 0x0000},
{0x0030, 0x003A, 0x0064, 0x0065, 0x006D, 0x006F, 0x005F,
0x0066, 0x0072, 0x002E, 0x0062, 0x0069, 0x006E, 0x0000},
{0x0030, 0x003A, 0x0064, 0x0065, 0x006D, 0x006F, 0x005F,
0x006A, 0x0070, 0x002E, 0x0062, 0x0069, 0x006E, 0x0000},
{0x0030, 0x003A, 0x0064, 0x0065, 0x006D, 0x006F, 0x005F,
0x0073, 0x0070, 0x002E, 0x0062, 0x0069, 0x006E, 0x0000}
}

Referenced by check_valid_firmware().

FIL file_object

Referenced by main().

volatile uint32_t firmware_type = 0
volatile uint32_t reset_flag = 0

Referenced by main(), and sw0_handler().

volatile uint32_t sd_fs_found = 0
volatile uint32_t sd_listing_pos = 0
volatile uint32_t sd_num_files = 0
volatile uint32_t sd_update = 0
uint8_t trigger_page[DATA_SIZE]
static

Referenced by jump_to_bootloader().

volatile uint32_t valid_firmware_found = 0