summaryrefslogtreecommitdiffstats
path: root/firmware/bootloaderconfig.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/bootloaderconfig.h')
-rw-r--r--firmware/bootloaderconfig.h292
1 files changed, 124 insertions, 168 deletions
diff --git a/firmware/bootloaderconfig.h b/firmware/bootloaderconfig.h
index e1b2a4c..a93e6ff 100644
--- a/firmware/bootloaderconfig.h
+++ b/firmware/bootloaderconfig.h
@@ -12,13 +12,16 @@
#ifndef __bootloaderconfig_h_included__
#define __bootloaderconfig_h_included__
-// uncomment this to enable the 'jumper from d5 to gnd to enable programming' mode
-//#define BUILD_JUMPER_MODE 1
-
-#ifndef BOOTLOADER_ADDRESS
-#define BOOTLOADER_ADDRESS 0
+/*
+ * Bootloader defines
+ */
+
+#ifndef __ASSEMBLER__
+ typedef union {
+ uint16_t w;
+ uint8_t b[2];
+ } uint16_union_t;
#endif
-
/*
General Description:
This file (together with some settings in Makefile) configures the boot loader
@@ -51,46 +54,46 @@ these macros are defined, the boot loader uses them.
#define HARDWARE_CONFIG TINY85_HARDWARE_CONFIG_2
#define USB_CFG_IOPORTNAME B
-/* This is the port where the USB bus is connected. When you configure it to
- * "B", the registers PORTB, PINB and DDRB will be used.
- */
+ /* This is the port where the USB bus is connected. When you configure it to
+ * "B", the registers PORTB, PINB and DDRB will be used.
+ */
#ifndef __AVR_ATtiny85__
-# define USB_CFG_DMINUS_BIT 0
-/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
- * This may be any bit in the port.
- */
-# define USB_CFG_DPLUS_BIT 2
-/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
- * This may be any bit in the port. Please note that D+ must also be connected
- * to interrupt pin INT0!
- */
+ # define USB_CFG_DMINUS_BIT 0
+ /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
+ * This may be any bit in the port.
+ */
+ #define USB_CFG_DPLUS_BIT 2
+ /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
+ * This may be any bit in the port. Please note that D+ must also be connected
+ * to interrupt pin INT0!
+ */
#endif
#if (defined __AVR_ATtiny85__) && (HARDWARE_CONFIG == TINY85_HARDWARE_CONFIG_1)
-# define USB_CFG_DMINUS_BIT 0
-/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
- * This may be any bit in the port.
- */
-# define USB_CFG_DPLUS_BIT 2
-/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
- * This may be any bit in the port, but must be configured as a pin change interrupt.
- */
- #endif
+ #define USB_CFG_DMINUS_BIT 0
+ /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
+ * This may be any bit in the port.
+ */
+ #define USB_CFG_DPLUS_BIT 2
+ /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
+ * This may be any bit in the port, but must be configured as a pin change interrupt.
+ */
+#endif
#if (defined __AVR_ATtiny85__) && (HARDWARE_CONFIG == TINY85_HARDWARE_CONFIG_2)
-# define USB_CFG_DMINUS_BIT 3
+#define USB_CFG_DMINUS_BIT 3
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
* This may be any bit in the port.
*/
-# define USB_CFG_DPLUS_BIT 4
+#define USB_CFG_DPLUS_BIT 4
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
* This may be any bit in the port, but must be configured as a pin change interrupt.
*/
- #endif
+#endif
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
-/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
+/* Clock rate of the AVR in kHz. Legal values are 12000, 16000 or 16500.
* The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
* deviation from the nominal frequency. All other rates require a precision
* of 2000 ppm and thus a crystal!
@@ -114,82 +117,16 @@ these macros are defined, the boot loader uses them.
/* ------------------------------------------------------------------------- */
/* ---------------------- feature / code size options ---------------------- */
/* ------------------------------------------------------------------------- */
-
-//#define HAVE_EEPROM_PAGED_ACCESS 0
-/* If HAVE_EEPROM_PAGED_ACCESS is defined to 1, page mode access to EEPROM is
- * compiled in. Whether page mode or byte mode access is used by AVRDUDE
- * depends on the target device. Page mode is only used if the device supports
- * it, e.g. for the ATMega88, 168 etc. You can save quite a bit of memory by
- * disabling page mode EEPROM access. Costs ~ 138 bytes.
- */
-//#define HAVE_EEPROM_BYTE_ACCESS 0
-/* If HAVE_EEPROM_BYTE_ACCESS is defined to 1, byte mode access to EEPROM is
- * compiled in. Byte mode is only used if the device (as identified by its
- * signature) does not support page mode for EEPROM. It is required for
- * accessing the EEPROM on the ATMega8. Costs ~54 bytes.
- */
-#define BOOTLOADER_CAN_EXIT 1
-/* If this macro is defined to 1, the boot loader will exit shortly after the
- * programmer closes the connection to the device. Costs ~36 bytes.
- * Required for TINY85MODE
- */
-//#define HAVE_CHIP_ERASE 0
-/* If this macro is defined to 1, the boot loader implements the Chip Erase
- * ISP command. Otherwise pages are erased on demand before they are written.
- */
-//#define SIGNATURE_BYTES 0x1e, 0x93, 0x0b, 0 /* ATtiny85 */
-/* This macro defines the signature bytes returned by the emulated USBasp to
- * the programmer software. They should match the actual device at least in
- * memory size and features. If you don't define this, values for ATMega8,
- * ATMega88, ATMega168 and ATMega328 are guessed correctly.
- */
-
-/* The following block guesses feature options so that the resulting code
- * should fit into 2k bytes boot block with the given device and clock rate.
- * Activate by passing "-DUSE_AUTOCONFIG=1" to the compiler.
- * This requires gcc 3.4.6 for small enough code size!
- */
-// #if USE_AUTOCONFIG
-// # undef HAVE_EEPROM_PAGED_ACCESS
-// # define HAVE_EEPROM_PAGED_ACCESS (USB_CFG_CLOCK_KHZ >= 16000)
-// # undef HAVE_EEPROM_BYTE_ACCESS
-// # define HAVE_EEPROM_BYTE_ACCESS 1
-// # undef BOOTLOADER_CAN_EXIT
-// # define BOOTLOADER_CAN_EXIT 1
-// # undef SIGNATURE_BYTES
-// #endif /* USE_AUTOCONFIG */
-
-/* ------------------------------------------------------------------------- */
-
-/* Example configuration: Port D bit 3 is connected to a jumper which ties
- * this pin to GND if the boot loader is requested. Initialization allows
- * several clock cycles for the input voltage to stabilize before
- * bootLoaderCondition() samples the value.
- * We use a function for bootLoaderInit() for convenience and a macro for
- * bootLoaderCondition() for efficiency.
- */
-
-#define JUMPER_BIT 0 /* jumper is connected to this bit in port B, active low */
+/* ----------------------- Optional MCU Description ------------------------ */
/* tiny85 Architecture Specifics */
#ifndef __AVR_ATtiny85__
# error "uBoot is only designed for attiny85"
#endif
-
#define TINY85MODE
-// number of bytes before the boot loader vectors to store the tiny application vector table
-#define TINYVECTOR_RESET_OFFSET 4
-#define TINYVECTOR_USBPLUS_OFFSET 2
-#define TINYVECTOR_OSCCAL_OFFSET 6
-
-#define RESET_VECTOR_OFFSET 0
-#define USBPLUS_VECTOR_OFFSET 2
-
-//#if BOOTLOADER_CAN_EXIT == 0
-//# define BOOTLOADER_CAN_EXIT 1
-//#endif
+/* ------------- Set up interrupt configuration (CPU specific) -------------- */
// setup interrupt for Pin Change for D+
#define USB_INTR_CFG PCMSK
@@ -201,88 +138,105 @@ these macros are defined, the boot loader uses them.
#define USB_INTR_PENDING_BIT PCIF
#define USB_INTR_VECTOR PCINT0_vect
+// Microcontroller vectortable entries in the flash
+#define RESET_VECTOR_OFFSET 0
+#define USBPLUS_VECTOR_OFFSET 2
+
+// number of bytes before the boot loader vectors to store the tiny application vector table
+#define TINYVECTOR_RESET_OFFSET 4
+#define TINYVECTOR_USBPLUS_OFFSET 2
+#define TINYVECTOR_OSCCAL_OFFSET 6
+
+/* ------------------------------------------------------------------------ */
+// postscript are the few bytes at the end of programmable memory which store tinyVectors
+#define POSTSCRIPT_SIZE 6
+#define PROGMEM_SIZE (BOOTLOADER_ADDRESS - POSTSCRIPT_SIZE) /* max size of user program */
+
+/* ------------------------------------------------------------------------- */
+
+/*
+ * Define Bootloader entry condition
+ *
+ * If the entry condition is not met, the bootloader will not be activated and the user program
+ * is executed directly after a reset. If no user program has been loaded, the bootloader
+ * is always active.
+ *
+ * ENTRY_ALWAYS Always activate the bootloader after reset. Requires the least
+ * amount of code.
+ *
+ * ENTRY_WATCHDOG Activate the bootloader after a watchdog reset. This can be used
+ * to enter the bootloader from the user program.
+ * Adds 22 bytes.
+ *
+ * ENTRY_EXT_RESET Activate the bootloader after an external reset was issued by
+ * pulling the reset pin low. It may be necessary to add an external
+ * pull-up resistor to the reset pin if this entry method appears to
+ * behave unreliably.
+ * Adds 22 bytes.
+ *
+ * ENTRY_JUMPER Activate the bootloader when a specific pin is pulled low by an
+ * external jumper.
+ * Adds 34 bytes.
+ *
+ * JUMPER_PIN Pin the jumper is connected to. (e.g. PB0)
+ * JUMPER_PORT Port out register for the jumper (e.g. PORTB)
+ * JUMPER_DDR Port data direction register for the jumper (e.g. DDRB)
+ * JUMPER_INP Port inout register for the jumper (e.g. PINB)
+ *
+ */
+
+#define ENTRYMODE ENTRY_ALWAYS
+
+#define JUMPER_PIN PB0
+#define JUMPER_PORT PORTB
+#define JUMPER_DDR DDRB
+#define JUMPER_INP PINB
-// uncomment for chips with clkdiv8 enabled in fuses
-//#define LOW_POWER_MODE 1
-
-// set clock prescaler to a value before running user program
-//#define SET_CLOCK_PRESCALER _BV(CLKPS0) /* divide by 2 for 8mhz */
-
-
-#ifdef BUILD_JUMPER_MODE
- #define START_JUMPER_PIN 5
- #define digitalRead(pin) (PINB & _BV(pin))
- #define bootLoaderStartCondition() (!digitalRead(START_JUMPER_PIN))
- #define bootLoaderCondition() 1
-
- #ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */
- static inline void bootLoaderInit(void) {
- // DeuxVis pin-5 pullup
- PORTB |= _BV(START_JUMPER_PIN); // has pullup enabled
- _delay_ms(10);
- }
- static inline void bootLoaderExit(void) {
- // DeuxVis pin-5 pullup
- PORTB = 0;
- }
- #endif /* __ASSEMBLER__ */
-
-#else
+#define ENTRY_ALWAYS 1
+#define ENTRY_WATCHDOG 2
+#define ENTRY_EXT_RESET 3
+#define ENTRY_JUMPER 4
+
+#if ENTRYMODE==ENTRY_ALWAYS
+ #define bootLoaderInit()
+ #define bootLoaderExit()
+ #define bootLoaderStartCondition() 1
+#elif ENTRYMODE==ENTRY_WATCHDOG
+ #define bootLoaderInit()
+ #define bootLoaderExit()
+ #define bootLoaderStartCondition() (MCUSR&_BV(WDRF))
+#elif ENTRYMODE==ENTRY_EXT_RESET
#define bootLoaderInit()
#define bootLoaderExit()
- #define bootLoaderCondition() (++idlePolls < (AUTO_EXIT_MS * 10UL))
- #if LOW_POWER_MODE
- // only starts bootloader if USB D- is pulled high on startup - by putting your pullup in to an external connector
- // you can avoid ever entering an out of spec clock speed or waiting on bootloader when that pullup isn't there
- #define bootLoaderStartCondition() \
- (PINB & (_BV(USB_CFG_DMINUS_BIT) | _BV(USB_CFG_DMINUS_BIT))) == _BV(USB_CFG_DMINUS_BIT)
- #else
- #define bootLoaderStartCondition() 1
- #endif
+ #define bootLoaderStartCondition() (MCUSR&_BV(EXTRF))
+#elif ENTRYMODE==ENTRY_JUMPER
+ // Enable pull up on jumper pin and delay to stabilize input
+ #define bootLoaderInit() {JUMPER_DDR&=~_BV(JUMPER_PIN);JUMPER_PORT|=_BV(JUMPER_PIN);_delay_ms(1);}
+ #define bootLoaderExit() {JUMPER_PORT&=~_BV(JUMPER_PIN);}
+ #define bootLoaderStartCondition() (!(JUMPER_INP&_BV(JUMPER_PIN)))
+#else
+ #error "No entry mode defined"
#endif
-/* ----------------------- Optional MCU Description ------------------------ */
-
-/* The following configurations have working defaults in usbdrv.h. You
- * usually don't need to set them explicitly. Only if you want to run
- * the driver on a device which is not yet supported or with a compiler
- * which is not fully supported (such as IAR C) or if you use a different
- * interrupt than INT0, you may have to define some of these.
- */
-/* #define USB_INTR_CFG MCUCR */
-/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */
-/* #define USB_INTR_CFG_CLR 0 */
-/* #define USB_INTR_ENABLE GIMSK */
-/* #define USB_INTR_ENABLE_BIT INT0 */
-/* #define USB_INTR_PENDING GIFR */
-/* #define USB_INTR_PENDING_BIT INTF0 */
-/* #define USB_INTR_VECTOR INT0_vect */
-
-// todo: change to pin 5
-//#define DEUXVIS_JUMPER_PIN 5
-//#define digitalRead(pin) ((PINB >> pin) & 0b00000001)
-//#define bootLoaderStartCondition() (!digitalRead(DEUXVIS_JUMPER_PIN))
-//#define bootLoaderCondition() (1)
-
-#ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */
-
/*
* Define bootloader timeout value.
*
- * These will only be used if is bootLoaderCondition() evaluates idlePolls below!
+ * The bootloader will only time out if a user program was loaded.
*
* AUTO_EXIT_NO_USB_MS The bootloader will exit after this delay if no USB is connected.
* Set to 0 to disable
* Adds ~6 bytes.
* (This will wait for an USB SE0 reset from the host)
+ *
* AUTO_EXIT_MS The bootloader will exit after this delay if no USB communication
* from the host tool was received.
+ * Set to 0 to disable
*
* All values are approx. in milliseconds
*/
#define AUTO_EXIT_NO_USB_MS 0
-#define AUTO_EXIT_MS 6000
+#define AUTO_EXIT_MS 5000
/*
* Defines the setting of the RC-oscillator calibration after quitting the bootloader. (OSCCAL)
@@ -327,13 +281,15 @@ these macros are defined, the boot loader uses them.
#define LED_PORT PORTB
#define LED_PIN PB1
-#define LED_INIT(x) LED_PORT &=~_BV(LED_PIN);
-#define LED_EXIT(x) LED_DDR &=~_BV(LED_PIN);
-#define LED_MACRO(x) if ( x & 0xd ) {LED_DDR&=~_BV(LED_PIN);} else {LED_DDR|=_BV(LED_PIN);}
-
-#endif /* __ASSEMBLER__ */
-
-
+#if LED_PRESENT
+ #define LED_INIT(x) LED_PORT &=~_BV(LED_PIN);
+ #define LED_EXIT(x) LED_DDR &=~_BV(LED_PIN);
+ #define LED_MACRO(x) if ( x & 0xd ) {LED_DDR&=~_BV(LED_PIN);} else {LED_DDR|=_BV(LED_PIN);}
+#else
+ #define LED_INIT(x)
+ #define LED_EXIT(x)
+ #define LED_MACRO(x)
+#endif
/* ------------------------------------------------------------------------- */
#endif /* __bootloader_h_included__ */