Guest User

Untitled

a guest
Jun 19th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.36 KB | None | 0 0
  1. /* Name: bootloaderconfig.h
  2.  * Project: AVR bootloader HID
  3.  * Author: Christian Starkjohann
  4.  * Creation Date: 2007-03-19
  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 699 2008-11-26 19:50:32Z 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. You may call leaveBootloader()
  28. from this function if you know that the main code should run.
  29.  
  30. bootLoaderCondition() is called immediately after initialization and in each
  31. main loop iteration. If it returns TRUE, the boot loader will be active. If it
  32. returns FALSE, the boot loader jumps to address 0 (the loaded application)
  33. immediately.
  34.  
  35. For compatibility with Thomas Fischl's avrusbboot, we also support the macro
  36. names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
  37. these macros are defined, the boot loader usees them.
  38. */
  39.  
  40. /* ---------------------------- Hardware Config ---------------------------- */
  41.  
  42. #define USB_CFG_IOPORTNAME      D
  43. /* This is the port where the USB bus is connected. When you configure it to
  44.  * "B", the registers PORTB, PINB and DDRB will be used.
  45.  */
  46. #define USB_CFG_DMINUS_BIT      1
  47. /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
  48.  * This may be any bit in the port.
  49.  */
  50. #define USB_CFG_DPLUS_BIT       2
  51. /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
  52.  * This may be any bit in the port. Please note that D+ must also be connected
  53.  * to interrupt pin INT0! [You can also use other interrupts, see section
  54.  * "Optional MCU Description" below, or you can connect D- to the interrupt, as
  55.  * it is required if you use the USB_COUNT_SOF feature. If you use D- for the
  56.  * interrupt, the USB interrupt will also be triggered at Start-Of-Frame
  57.  * markers every millisecond.]
  58.  */
  59. #define USB_CFG_CLOCK_KHZ       (F_CPU/1000)
  60. /* Clock rate of the AVR in MHz. Legal values are 12000, 12800, 15000, 16000,
  61.  * 16500 and 20000. The 12.8 MHz and 16.5 MHz versions of the code require no
  62.  * crystal, they tolerate +/- 1% deviation from the nominal frequency. All
  63.  * other rates require a precision of 2000 ppm and thus a crystal!
  64.  * Default if not specified: 12 MHz
  65.  */
  66.  
  67. /* ----------------------- Optional Hardware Config ------------------------ */
  68.  
  69. /* #define USB_CFG_PULLUP_IOPORTNAME   D */
  70. /* If you connect the 1.5k pullup resistor from D- to a port pin instead of
  71.  * V+, you can connect and disconnect the device from firmware by calling
  72.  * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
  73.  * This constant defines the port on which the pullup resistor is connected.
  74.  */
  75. /* #define USB_CFG_PULLUP_BIT          4 */
  76. /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
  77.  * above) where the 1.5k pullup resistor is connected. See description
  78.  * above for details.
  79.  */
  80.  
  81. /* --------------------------- Functional Range ---------------------------- */
  82.  
  83. #define BOOTLOADER_CAN_EXIT     1
  84. /* If this macro is defined to 1, the boot loader command line utility can
  85.  * initiate a reboot after uploading the FLASH when the "-r" command line
  86.  * option is given. If you define it to 0 or leave it undefined, the "-r"
  87.  * option won't work and you save a couple of bytes in the boot loader. This
  88.  * may be of advantage if you compile with gcc 4 instead of gcc 3 because it
  89.  * generates slightly larger code.
  90.  * If you need to save even more memory, consider using your own vector table.
  91.  * Since only the reset vector and INT0 (the first two vectors) are used,
  92.  * this saves quite a bit of flash. See Alexander Neumann's boot loader for
  93.  * an example: http://git.lochraster.org:2080/?p=fd0/usbload;a=tree
  94.  */
  95.  
  96. /* ------------------------------------------------------------------------- */
  97.  
  98. /* Example configuration: Port D bit 3 is connected to a jumper which ties
  99.  * this pin to GND if the boot loader is requested. Initialization allows
  100.  * several clock cycles for the input voltage to stabilize before
  101.  * bootLoaderCondition() samples the value.
  102.  * We use a function for bootLoaderInit() for convenience and a macro for
  103.  * bootLoaderCondition() for efficiency.
  104.  */
  105.  
  106. #ifndef __ASSEMBLER__   /* assembler cannot parse function definitions */
  107. #include <util/delay.h>
  108.  
  109. static inline void  bootLoaderInit(void)
  110. {
  111.     PORTD = 1 << 3; /* activate pull-up for key */
  112.     _delay_us(10);  /* wait for levels to stabilize */
  113. }
  114.  
  115. #define bootLoaderCondition()   ((PIND & (1 << 3)) == 0)   /* True if jumper is set */
  116.  
  117. #endif
  118.  
  119. /* ------------------------------------------------------------------------- */
  120.  
  121. #endif /* __bootloader_h_included__ */
Advertisement
Add Comment
Please, Sign In to add comment