LUFA Library - CDC Class Bootloader
BootloaderCDC.c File Reference
#include "BootloaderCDC.h"

Functions

void Application_Jump_Check (void)
 
int main (void)
 
static void SetupHardware (void)
 
 ISR (TIMER1_OVF_vect, ISR_BLOCK)
 
void EVENT_USB_Device_ConfigurationChanged (void)
 
void EVENT_USB_Device_ControlRequest (void)
 
static void ReadWriteMemoryBlock (const uint8_t Command)
 
static uint8_t FetchNextCommandByte (void)
 
static void WriteNextResponseByte (const uint8_t Response)
 
static void CDC_Task (void)
 

Variables

static CDC_LineEncoding_t LineEncoding
 
static uint32_t CurrAddress
 
static bool RunBootloader = true
 
uint16_t MagicBootKey
 

Detailed Description

Main source file for the CDC class bootloader. This file contains the complete bootloader logic.

Function Documentation

void Application_Jump_Check ( void  )

Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application start key has been loaded into MagicBootKey. If the bootloader started via the watchdog and the key is valid, this will force the user application to start via a software jump.

static void CDC_Task ( void  )
static

Task to read in AVR910 commands from the CDC data OUT endpoint, process them, perform the required actions and send the appropriate response back to the host.

void EVENT_USB_Device_ConfigurationChanged ( void  )

Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready to relay data to and from the attached USB host.

void EVENT_USB_Device_ControlRequest ( void  )

Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to the device from the USB host before passing along unhandled control requests to the library for processing internally.

static uint8_t FetchNextCommandByte ( void  )
static

Retrieves the next byte from the host in the CDC data OUT endpoint, and clears the endpoint bank if needed to allow reception of the next data packet from the host.

Returns
Next received byte from the host in the CDC data OUT endpoint
ISR ( TIMER1_OVF_vect  ,
ISR_BLOCK   
)

ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active.

int main ( void  )

Main program entry point. This routine configures the hardware required by the bootloader, then continuously runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start the loaded application code.

static void ReadWriteMemoryBlock ( const uint8_t  Command)
static

Reads or writes a block of EEPROM or FLASH memory to or from the appropriate CDC data endpoint, depending on the AVR910 protocol command issued.

Parameters
[in]CommandSingle character AVR910 protocol command indicating what memory operation to perform
static void SetupHardware ( void  )
static

Configures all hardware required for the bootloader.

static void WriteNextResponseByte ( const uint8_t  Response)
static

Writes the next response byte to the CDC data IN endpoint, and sends the endpoint back if needed to free up the bank when full ready for the next byte in the packet to the host.

Parameters
[in]ResponseNext response byte to send to the host

Variable Documentation

uint32_t CurrAddress
static

Current address counter. This stores the current address of the FLASH or EEPROM as set by the host, and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued command.)

CDC_LineEncoding_t LineEncoding
static
Initial value:
= { .BaudRateBPS = 0,
.CharFormat = CDC_LINEENCODING_OneStopBit,
.ParityType = CDC_PARITY_None,
.DataBits = 8 }

Contains the current baud rate and other settings of the first virtual serial port. This must be retained as some operating systems will not open the port unless the settings can be set successfully.

uint16_t MagicBootKey

Magic lock for forced application start. If the HWBE fuse is programmed and BOOTRST is unprogrammed, the bootloader will start if the /HWB line of the AVR is held low and the system is reset. However, if the /HWB line is still held low when the application attempts to start via a watchdog reset, the bootloader will re-start. If set to the value MAGIC_BOOT_KEY the special init function Application_Jump_Check() will force the application to start.

bool RunBootloader = true
static

Flag to indicate if the bootloader should be running, or should exit and allow the application code to run via a watchdog reset. When cleared the bootloader will exit, starting the watchdog and entering an infinite loop until the AVR restarts and the application runs.