bootloader/bootloaderconfig.h

Go to the documentation of this file.
00001 
00031 #ifndef __bootloaderconfig_h_included__
00032 #define __bootloaderconfig_h_included__
00033 
00034 /* ---------------------------- Hardware Config ---------------------------- */
00035 
00039 #define USB_CFG_IOPORTNAME      D
00040 
00043 #define USB_CFG_DMINUS_BIT      0
00044 
00048 #define USB_CFG_DPLUS_BIT       2
00049 
00055 #define USB_CFG_CLOCK_KHZ       (F_CPU/1000)
00056 
00057 /* ----------------------- Optional Hardware Config ------------------------ */
00058 
00059 /* If you connect the 1.5k pullup resistor from D- to a port pin instead of
00060  * V+, you can connect and disconnect the device from firmware by calling
00061  * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
00062  * This constant defines the port on which the pullup resistor is connected.
00063  */
00064 /* #define USB_CFG_PULLUP_IOPORTNAME   D */
00065 /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
00066  * above) where the 1.5k pullup resistor is connected. See description
00067  * above for details.
00068  */
00069 /* #define USB_CFG_PULLUP_BIT          4 */
00070 
00071 /* ------------------------------------------------------------------------- */
00072 /* ---------------------- feature / code size options ---------------------- */
00073 /* ------------------------------------------------------------------------- */
00074 
00081 #define HAVE_EEPROM_PAGED_ACCESS    1
00082 
00087 #define HAVE_EEPROM_BYTE_ACCESS     1
00088 
00091 #define BOOTLOADER_CAN_EXIT         1
00092 
00097 #define SIGNATURE_BYTES             0x1e, 0x95, 0x02, 0     /* ATMega32 */
00098 
00099 /* The following block guesses feature options so that the resulting code
00100  * should fit into 2k bytes boot block with the given device and clock rate.
00101  * Activate by passing "-DUSE_AUTOCONFIG=1" to the compiler.
00102  * This requires gcc 3.4.6 for small enough code size!
00103  */
00104 #if USE_AUTOCONFIG
00105 #   undef HAVE_EEPROM_PAGED_ACCESS
00106 #   define HAVE_EEPROM_PAGED_ACCESS     (USB_CFG_CLOCK_KHZ >= 16000)
00107 #   undef HAVE_EEPROM_BYTE_ACCESS
00108 #   define HAVE_EEPROM_BYTE_ACCESS      1
00109 #   undef BOOTLOADER_CAN_EXIT
00110 #   define BOOTLOADER_CAN_EXIT          1
00111 #   undef SIGNATURE_BYTES
00112 #endif /* USE_AUTOCONFIG */
00113 
00114 /* ------------------------------------------------------------------------- */
00115 
00116 #ifndef __ASSEMBLER__   /* assembler cannot parse function definitions */
00117 
00118 uint8_t ledcounter = 0; 
00119 uint8_t ledstate = 0;   
00120 
00125 static inline void bootLoaderInit(void) {
00126     // switch on leds
00127     DDRD  |= (1 << PIND4) | (1 << PIND5) | (1 << PIND6);
00128     PORTD &= ~((1 << PIND4) | (1 << PIND5) | (1 << PIND6));
00129     // choose matrix position for hotkey. we use KEY_KPminus, so we set row 13
00130     // and later look for pin 7
00131     DDRA  = 0x00;
00132     PORTA = 0xff;
00133     DDRC  = (1 << DDC2);
00134     PORTC = ~(1 << PINC2);
00135 }
00136 
00140 static inline void bootLoaderExit(void) {
00141     // switch off leds
00142     PORTD |= (1 << PIND4) | (1 << PIND5) | (1 << PIND6);
00143 }
00144 
00151 static inline uint8_t bootLoaderCondition() {
00152     // look for pin 7
00153     if (!(PINB & (1 << PINB7))) {
00154         // boot loader active, blink leds
00155         _delay_ms(1);
00156         ledcounter++;
00157         if (ledcounter == 127) {
00158             switch (ledstate) {
00159                 case 0:
00160                     PORTD &= ~(1 << PIND6);
00161                     PORTD |= (1 << PIND4) | (1 << PIND5);
00162                     ledstate = 1;
00163                     break;
00164                 case 1:
00165                     PORTD &= ~(1 << PIND5);
00166                     PORTD |= (1 << PIND4) | (1 << PIND6);
00167                     ledstate = 2;
00168                     break;
00169                 case 2:
00170                     PORTD &= ~(1 << PIND4);
00171                     PORTD |= (1 << PIND5) | (1 << PIND6);
00172                     ledstate = 0;
00173                     break;
00174                 default:
00175                     ledstate = 0;
00176             }
00177             ledcounter = 0;
00178         }
00179         return 1;
00180     } else {
00181         // no boot loader
00182         return 0;
00183     }
00184 }
00185 
00186 #endif /* __ASSEMBLER__ */
00187 
00188 /* ------------------------------------------------------------------------- */
00189 
00190 #endif /* __bootloader_h_included__ */

Generated on Sat Jul 12 22:27:14 2008 for Dulcimer by  doxygen 1.5.4