bootloader_firmware/main.c File Reference

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#include "usbdrv.h"
#include "bootloaderconfig.h"

Go to the source code of this file.

Defines

#define USBBOOT_FUNC_WRITE_PAGE   2
#define USBBOOT_FUNC_LEAVE_BOOT   1
#define USBBOOT_FUNC_GET_PAGESIZE   3
#define STATE_IDLE   0
#define STATE_WRITE_PAGE   1

Functions

uchar usbFunctionSetup (uchar data[8])
uchar usbFunctionWrite (uchar *data, uchar len)
int main (void)

Variables

void(* jump_to_app )(void)


Define Documentation

#define STATE_IDLE   0

Definition at line 37 of file main.c.

Referenced by usbFunctionWrite().

#define STATE_WRITE_PAGE   1

Definition at line 38 of file main.c.

Referenced by usbFunctionSetup(), and usbFunctionWrite().

#define USBBOOT_FUNC_GET_PAGESIZE   3

Definition at line 35 of file main.c.

Referenced by usbFunctionSetup().

#define USBBOOT_FUNC_LEAVE_BOOT   1

Definition at line 34 of file main.c.

Referenced by usbFunctionSetup().

#define USBBOOT_FUNC_WRITE_PAGE   2

Definition at line 33 of file main.c.

Referenced by usbFunctionSetup().


Function Documentation

int main ( void   ) 

Definition at line 124 of file main.c.

00125 {
00126     /* initialize hardware */
00127     BOOTLOADER_INIT;
00128 
00129     /* jump to application if jumper is set */
00130     if (!BOOTLOADER_CONDITION) {
00131       leaveBootloader();
00132     }
00133 
00134     GICR = (1 << IVCE);  /* enable change of interrupt vectors */
00135     GICR = (1 << IVSEL); /* move interrupts to boot flash section */
00136 
00137     usbInit();
00138     sei();
00139     for(;;){    /* main event loop */
00140         usbPoll();
00141     }
00142     return 0;
00143 }

uchar usbFunctionSetup ( uchar  data[8]  ) 

Definition at line 55 of file main.c.

00056 {
00057     uchar len = 0;
00058     
00059     if (data[1] == USBBOOT_FUNC_LEAVE_BOOT) {
00060       leaveBootloader();
00061     } else if (data[1] == USBBOOT_FUNC_WRITE_PAGE) {
00062 
00063       state = STATE_WRITE_PAGE;
00064 
00065       page_address = (data[3] << 8) | data[2]; /* page address */
00066       page_offset = 0;
00067 
00068       eeprom_busy_wait();
00069       cli();
00070       boot_page_erase(page_address); /* erase page */
00071       sei();
00072       boot_spm_busy_wait(); /* wait until page is erased */
00073 
00074       len = 0xff; /* multiple out */
00075 
00076     } else if (data[1] == USBBOOT_FUNC_GET_PAGESIZE) {
00077 
00078       replyBuffer[0] = SPM_PAGESIZE >> 8;
00079       replyBuffer[1] = SPM_PAGESIZE & 0xff;
00080       len = 2;
00081 
00082     }
00083 
00084     usbMsgPtr = replyBuffer;
00085 
00086     return len;
00087 }

uchar usbFunctionWrite ( uchar *  data,
uchar  len 
)

Definition at line 90 of file main.c.

00091 {
00092 
00093   uchar i;
00094 
00095   /* check if we are in correct state */
00096   if (state != STATE_WRITE_PAGE)
00097     return 0xff;
00098   
00099   for (i = 0; i < len; i+=2) {
00100 
00101     cli();    
00102     boot_page_fill(page_address + page_offset, data[i] | (data[i + 1] << 8));
00103     sei();
00104     page_offset += 2;
00105 
00106     /* check if we are at the end of a page */
00107     if (page_offset >= SPM_PAGESIZE) {
00108       
00109       /* write page */
00110       cli();
00111       boot_page_write(page_address);
00112       sei();
00113       boot_spm_busy_wait();
00114 
00115       state = STATE_IDLE;
00116       return 1;
00117     }
00118 
00119   }
00120   
00121   return 0;
00122 }


Variable Documentation

void(* jump_to_app)(void)

Definition at line 45 of file main.c.

00047                        {
00048       cli();
00049       boot_rww_enable();
00050       GICR = (1 << IVCE);  /* enable change of interrupt vectors */
00051       GICR = (0 << IVSEL); /* move interrupts to application flash section */
00052       jump_to_app();
00053 }


Generated on Fri Oct 30 15:43:34 2009 for USB IR HID Device by  doxygen 1.5.8