BootloaderCDC.c File Reference

#include "BootloaderCDC.h"
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#include <avr/eeprom.h>
#include <avr/power.h>
#include <stdbool.h>
#include <LUFA/Drivers/USB/USB.h>

Functions

int main (void)
void SetupHardware (void)
void ResetHardware (void)
void EVENT_USB_Device_ConfigurationChanged (void)
void EVENT_USB_Device_UnhandledControlRequest (void)
static void ReadWriteMemoryBlock (const uint8_t Command)
static uint8_t FetchNextCommandByte (void)
static void WriteNextResponseByte (const uint8_t Response)
void CDC_Task (void)

Variables

CDC_Line_Coding_t LineCoding
uint32_t CurrAddress
bool RunBootloader = true

Detailed Description

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


Function Documentation

void CDC_Task ( void   ) 

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_UnhandledControlRequest ( void   ) 

Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific control requests that are not handled internally by the USB library, so that they can be handled appropriately for the application.

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
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] Command Single character AVR910 protocol command indicating what memory operation to perform
void ResetHardware ( void   ) 

Resets all configured hardware required for the bootloader back to their original states.

void SetupHardware ( void   ) 

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] Response Next response byte to send to the host

Variable Documentation

uint32_t CurrAddress

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.)

Initial value:
 { .BaudRateBPS = 9600,
                                 .CharFormat  = OneStopBit,
                                 .ParityType  = Parity_None,
                                 .DataBits    = 8            }

Line coding options for the virtual serial port. Although the virtual serial port data is never sent through a physical serial port, the line encoding data must still be read and preserved from the host, or the host will detect a problem and fail to open the port. This structure contains the current encoding options, including baud rate, character format, parity mode and total number of bits in each data chunk.

bool RunBootloader = true

Flag to indicate if the bootloader should be running, or should exit and allow the application code to run via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application jumped to via an indirect jump to location 0x0000.

Generated by  doxygen 1.6.3