[d138c94] | 1 | /* Name: bootloaderconfig.h
|
---|
| 2 | * Project: USBaspLoader
|
---|
| 3 | * Author: Christian Starkjohann
|
---|
| 4 | * Creation Date: 2007-12-08
|
---|
| 5 | * Tabsize: 4
|
---|
| 6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
---|
| 7 | * License: GNU GPL v2 (see License.txt)
|
---|
| 8 | * This Revision: $Id: bootloaderconfig.h 729 2009-03-20 09:03:58Z cs $
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | #ifndef __bootloaderconfig_h_included__
|
---|
| 12 | #define __bootloaderconfig_h_included__
|
---|
| 13 |
|
---|
| 14 | /*
|
---|
| 15 | General Description:
|
---|
| 16 | This file (together with some settings in Makefile) configures the boot loader
|
---|
| 17 | according to the hardware.
|
---|
| 18 |
|
---|
| 19 | This file contains (besides the hardware configuration normally found in
|
---|
| 20 | usbconfig.h) two functions or macros: bootLoaderInit() and
|
---|
| 21 | bootLoaderCondition(). Whether you implement them as macros or as static
|
---|
| 22 | inline functions is up to you, decide based on code size and convenience.
|
---|
| 23 |
|
---|
| 24 | bootLoaderInit() is called as one of the first actions after reset. It should
|
---|
| 25 | be a minimum initialization of the hardware so that the boot loader condition
|
---|
| 26 | can be read. This will usually consist of activating a pull-up resistor for an
|
---|
| 27 | external jumper which selects boot loader mode.
|
---|
| 28 |
|
---|
| 29 | bootLoaderCondition() is called immediately after initialization and in each
|
---|
| 30 | main loop iteration. If it returns TRUE, the boot loader will be active. If it
|
---|
| 31 | returns FALSE, the boot loader jumps to address 0 (the loaded application)
|
---|
| 32 | immediately.
|
---|
| 33 |
|
---|
| 34 | For compatibility with Thomas Fischl's avrusbboot, we also support the macro
|
---|
| 35 | names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
|
---|
| 36 | these macros are defined, the boot loader usees them.
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | /* ---------------------------- Hardware Config ---------------------------- */
|
---|
| 40 |
|
---|
| 41 | #define USB_CFG_IOPORTNAME D
|
---|
| 42 | /* This is the port where the USB bus is connected. When you configure it to
|
---|
| 43 | * "B", the registers PORTB, PINB and DDRB will be used.
|
---|
| 44 | */
|
---|
| 45 | #define USB_CFG_DMINUS_BIT 5
|
---|
| 46 | /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
|
---|
| 47 | * This may be any bit in the port.
|
---|
| 48 | */
|
---|
| 49 | #define USB_CFG_DPLUS_BIT 2
|
---|
| 50 | /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
|
---|
| 51 | * This may be any bit in the port. Please note that D+ must also be connected
|
---|
| 52 | * to interrupt pin INT0!
|
---|
| 53 | */
|
---|
| 54 | #define USB_CFG_CLOCK_KHZ (F_CPU/1000)
|
---|
| 55 | /* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
|
---|
| 56 | * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
|
---|
| 57 | * deviation from the nominal frequency. All other rates require a precision
|
---|
| 58 | * of 2000 ppm and thus a crystal!
|
---|
| 59 | * Default if not specified: 12 MHz
|
---|
| 60 | */
|
---|
| 61 |
|
---|
| 62 | /* ----------------------- Optional Hardware Config ------------------------ */
|
---|
| 63 |
|
---|
| 64 | /* #define USB_CFG_PULLUP_IOPORTNAME D */
|
---|
| 65 | /* If you connect the 1.5k pullup resistor from D- to a port pin instead of
|
---|
| 66 | * V+, you can connect and disconnect the device from firmware by calling
|
---|
| 67 | * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
|
---|
| 68 | * This constant defines the port on which the pullup resistor is connected.
|
---|
| 69 | */
|
---|
| 70 | /* #define USB_CFG_PULLUP_BIT 4 */
|
---|
| 71 | /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
|
---|
| 72 | * above) where the 1.5k pullup resistor is connected. See description
|
---|
| 73 | * above for details.
|
---|
| 74 | */
|
---|
| 75 |
|
---|
| 76 | /* ------------------------------------------------------------------------- */
|
---|
| 77 | /* ---------------------- feature / code size options ---------------------- */
|
---|
| 78 | /* ------------------------------------------------------------------------- */
|
---|
| 79 |
|
---|
| 80 | #define HAVE_EEPROM_PAGED_ACCESS 0
|
---|
| 81 | /* If HAVE_EEPROM_PAGED_ACCESS is defined to 1, page mode access to EEPROM is
|
---|
| 82 | * compiled in. Whether page mode or byte mode access is used by AVRDUDE
|
---|
| 83 | * depends on the target device. Page mode is only used if the device supports
|
---|
| 84 | * it, e.g. for the ATMega88, 168 etc. You can save quite a bit of memory by
|
---|
| 85 | * disabling page mode EEPROM access. Costs ~ 138 bytes.
|
---|
| 86 | */
|
---|
| 87 | #define HAVE_EEPROM_BYTE_ACCESS 1
|
---|
| 88 | /* If HAVE_EEPROM_BYTE_ACCESS is defined to 1, byte mode access to EEPROM is
|
---|
| 89 | * compiled in. Byte mode is only used if the device (as identified by its
|
---|
| 90 | * signature) does not support page mode for EEPROM. It is required for
|
---|
| 91 | * accessing the EEPROM on the ATMega8. Costs ~54 bytes.
|
---|
| 92 | */
|
---|
| 93 | #define BOOTLOADER_CAN_EXIT 0
|
---|
| 94 | /* If this macro is defined to 1, the boot loader will exit shortly after the
|
---|
| 95 | * programmer closes the connection to the device. Costs ~36 bytes.
|
---|
| 96 | */
|
---|
| 97 | #define HAVE_CHIP_ERASE 0
|
---|
| 98 | /* If this macro is defined to 1, the boot loader implements the Chip Erase
|
---|
| 99 | * ISP command. Otherwise pages are erased on demand before they are written.
|
---|
| 100 | */
|
---|
| 101 | //#define SIGNATURE_BYTES 0x1e, 0x93, 0x07, 0 /* ATMega8 */
|
---|
| 102 | /* This macro defines the signature bytes returned by the emulated USBasp to
|
---|
| 103 | * the programmer software. They should match the actual device at least in
|
---|
| 104 | * memory size and features. If you don't define this, values for ATMega8,
|
---|
| 105 | * ATMega88, ATMega168 and ATMega328 are guessed correctly.
|
---|
| 106 | */
|
---|
| 107 |
|
---|
| 108 | /* The following block guesses feature options so that the resulting code
|
---|
| 109 | * should fit into 2k bytes boot block with the given device and clock rate.
|
---|
| 110 | * Activate by passing "-DUSE_AUTOCONFIG=1" to the compiler.
|
---|
| 111 | * This requires gcc 3.4.6 for small enough code size!
|
---|
| 112 | */
|
---|
| 113 | #if USE_AUTOCONFIG
|
---|
| 114 | # undef HAVE_EEPROM_PAGED_ACCESS
|
---|
| 115 | # define HAVE_EEPROM_PAGED_ACCESS (USB_CFG_CLOCK_KHZ >= 16000)
|
---|
| 116 | # undef HAVE_EEPROM_BYTE_ACCESS
|
---|
| 117 | # define HAVE_EEPROM_BYTE_ACCESS 1
|
---|
| 118 | # undef BOOTLOADER_CAN_EXIT
|
---|
| 119 | # define BOOTLOADER_CAN_EXIT 1
|
---|
| 120 | # undef SIGNATURE_BYTES
|
---|
| 121 | #endif /* USE_AUTOCONFIG */
|
---|
| 122 |
|
---|
| 123 | /* ------------------------------------------------------------------------- */
|
---|
| 124 |
|
---|
| 125 | /* Example configuration: Port D bit 3 is connected to a jumper which ties
|
---|
| 126 | * this pin to GND if the boot loader is requested. Initialization allows
|
---|
| 127 | * several clock cycles for the input voltage to stabilize before
|
---|
| 128 | * bootLoaderCondition() samples the value.
|
---|
| 129 | * We use a function for bootLoaderInit() for convenience and a macro for
|
---|
| 130 | * bootLoaderCondition() for efficiency.
|
---|
| 131 | */
|
---|
| 132 |
|
---|
| 133 | #ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */
|
---|
| 134 |
|
---|
| 135 | #define JUMPER_BIT 0 /* jumper is connected to this bit in port D, active low */
|
---|
| 136 |
|
---|
| 137 | #ifndef MCUCSR /* compatibility between ATMega8 and ATMega88 */
|
---|
| 138 | # define MCUCSR MCUSR
|
---|
| 139 | #endif
|
---|
| 140 |
|
---|
| 141 | static inline void bootLoaderInit(void)
|
---|
| 142 | {
|
---|
| 143 | PORTD |= (1 << JUMPER_BIT); /* activate pull-up */
|
---|
| 144 | // if(!(MCUCSR & (1 << EXTRF))) /* If this was not an external reset, ignore */
|
---|
| 145 | // leaveBootloader();
|
---|
| 146 | // MCUCSR = 0; /* clear all reset flags for next time */
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | static inline void bootLoaderExit(void)
|
---|
| 150 | {
|
---|
| 151 | PORTD = 0;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | #define bootLoaderCondition() ((PIND & (1 << JUMPER_BIT)) == 0)
|
---|
| 155 |
|
---|
| 156 | #endif /* __ASSEMBLER__ */
|
---|
| 157 |
|
---|
| 158 | /* ------------------------------------------------------------------------- */
|
---|
| 159 |
|
---|
| 160 | #endif /* __bootloader_h_included__ */
|
---|