Microchip® Advanced Software Framework

i2c_slave_bootloader.c File Reference

SAM I2C Slave Bootloader.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include "conf_bootloader.h"

Functions

static void check_boot_mode (void)
 Function for checking whether to enter boot mode or application mode. More...
 
static void configure_i2c (void)
 Function for configuring I2C slave module. More...
 
static void fetch_data (uint8_t *buffer, uint16_t len)
 Function for fetching data to be programmed. More...
 
static uint32_t get_length (void)
 Function for fetching length of file to be programmed. More...
 
int main (void)
 Main application. More...
 
static void program_memory (uint32_t address, uint8_t *buffer, uint16_t len)
 Function for programming data to Flash. More...
 
static void send_ack (void)
 Function for sending acknowledgement to I2C Master. More...
 
static void start_application (void)
 Function for starting application. More...
 

Variables

struct i2c_slave_packet packet
 
struct i2c_slave_module slave
 

static void check_boot_mode ( void  )
static

Function for checking whether to enter boot mode or application mode.

This function will check the state of BOOT_LOAD_PIN. If it is pressed, it continues execution in bootloader mode. Else, it reads the first location from the application section and checks whether it is 0xFFFFFFFF. If yes, then the application section is empty and it waits indefinitely there. If not, it jumps to the application and starts execution from there. Access to direct peripheral registers are made in this routine to enable quick decision on application or bootloader mode.

References i2c_slave_config::address, i2c_slave_config::address_mode, configure_i2c(), I2C_SLAVE_ADDRESS_MODE_MASK, i2c_slave_enable(), i2c_slave_get_config_defaults(), i2c_slave_init(), i2c_slave_config::pinmux_pad0, i2c_slave_config::pinmux_pad1, slave, and SLAVE_ADDRESS.

Referenced by main().

static void configure_i2c ( void  )
static

Function for configuring I2C slave module.

This function will configure the I2C slave module with the SERCOM module to be used, required slave address, address mode mask and pinmux settings

static void fetch_data ( uint8_t *  buffer,
uint16_t  len 
)
static

Function for fetching data to be programmed.

This function will read a number of bytes from master for programming the device.

Parameters
bufferpointer to the buffer to store data from I2C master
lenlength of the data that will be sent by I2C master

References buffer, i2c_slave_packet::data, i2c_slave_packet::data_length, i2c_slave_read_packet_wait(), len, packet, slave, and STATUS_OK.

Referenced by main().

static uint32_t get_length ( void  )
static

Function for fetching length of file to be programmed.

Master initially transmits 4 bytes - which is the length of the the data to be programmed to the device.

References i2c_slave_packet::data, i2c_slave_packet::data_length, i2c_slave_read_packet_wait(), len, MSB0W, MSB1W, MSB2W, MSB3W, packet, read_buffer, slave, and STATUS_OK.

Referenced by main().

static void program_memory ( uint32_t  address,
uint8_t *  buffer,
uint16_t  len 
)
static

Function for programming data to Flash.

This function will check whether the data is greater than Flash page size. If it is greater, it splits and writes pagewise.

Parameters
addressaddress of the Flash page to be programmed
bufferpointer to the buffer containing data to be programmed
lenlength of the data to be programmed to Flash

References nvm_erase_row(), and nvm_write_buffer().

Referenced by main().

static void send_ack ( void  )
static

Function for sending acknowledgement to I2C Master.

This function will write an acknowledgement byte 's' on I2C bus to indicate the master that it has received and programmed the data.

References i2c_slave_packet::data, i2c_slave_packet::data_length, i2c_slave_write_packet_wait(), packet, slave, and STATUS_OK.

Referenced by main().

static void start_application ( void  )
static

Function for starting application.

This function will configure the WDT module and enable it. The LED is kept toggling till WDT reset occurs.

References wdt_conf::clock_source, GCLK_GENERATOR_4, port_pin_set_output_level(), wdt_conf::timeout_period, wdt_get_config_defaults(), WDT_PERIOD_256CLK, and wdt_set_config().

Referenced by main().

struct i2c_slave_packet packet

Referenced by fetch_data(), get_length(), and send_ack().

struct i2c_slave_module slave