-
Notifications
You must be signed in to change notification settings - Fork 5
/
postconfig.h
167 lines (136 loc) · 4.29 KB
/
postconfig.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Misc configuration here rather than source to avoid cluttering it with non-code
#if BOOTLOADER_ADDRESS % SPM_PAGESIZE != 0
#error "BOOTLOADER_ADDRESS must be on page boundary"
#endif
// Auto-disable features if only 2K bootloader space
#if (FLASHEND - BOOTLOADER_ADDRESS) <= 0x800
#if !defined (HAVE_READ_LOCK_FUSE) && (USB_CFG_CLOCK_KHZ == 15000 || \
USB_CFG_CLOCK_KHZ == 16500 || USB_CFG_CLOCK_KHZ == 12800)
#warning "Disabling HAVE_READ_LOCK_FUSE to fit code budget"
#define HAVE_READ_LOCK_FUSE 0
#endif
#if !defined (HAVE_FLASH_BYTE_READACCESS) && \
(USB_CFG_CLOCK_KHZ == 16500 || USB_CFG_CLOCK_KHZ == 12800)
#warning "Disabling HAVE_FLASH_BYTE_READACCESS to fit code budget"
#define HAVE_FLASH_BYTE_READACCESS 0
#endif
#if !defined (HAVE_EEPROM_BYTE_ACCESS) && USB_CFG_CLOCK_KHZ == 12800
#warning "Disabling HAVE_EEPROM_BYTE_ACCESS to fit code budget"
#define HAVE_EEPROM_BYTE_ACCESS 0
#endif
#if !defined (HAVE_EEPROM_PAGED_ACCESS) && USB_CFG_CLOCK_KHZ == 12800
#warning "Disabling HAVE_EEPROM_PAGED_ACCESS to fit code budget"
#define HAVE_EEPROM_PAGED_ACCESS 0
#endif
#if !defined (HAVE_FLASH_PAGED_READ) && USB_CFG_CLOCK_KHZ == 12800
#warning "Disabling HAVE_FLASH_PAGED_READ to fit code budget"
#define HAVE_FLASH_PAGED_READ 0
#endif
#if !defined (BOOTLOADER_CAN_EXIT) && USB_CFG_CLOCK_KHZ == 12800
#warning "Disabling BOOTLOADER_CAN_EXIT to fit code budget"
#define BOOTLOADER_CAN_EXIT 0
#endif
#if !defined (HAVE_SELF_UPDATE) && USB_CFG_CLOCK_KHZ == 12800
#define HAVE_SELF_UPDATE 0
#endif
#endif
//**** Compatibility with other bootloaders
// Support AVRUSBBoot's bootloaderconfig.h
#ifdef BOOTLOADER_CONDITION
#define bootLoaderCondition() BOOTLOADER_CONDITION
#endif
#ifdef BOOTLOADER_INIT
#define bootLoaderInit() BOOTLOADER_INIT
#define bootLoaderExit()
#ifndef bootLoaderCondition
#define bootLoaderCondition() 1
#endif
#endif
#if HAVE_ONDEMAND_PAGEERASE
#undef HAVE_CHIP_ERASE
#endif
//**** Debugging support
#if NO_FLASH_WRITE
#define SET_IVSEL( b )
#undef boot_page_erase
#define boot_page_erase( addr ) ((void) 0)
#undef boot_page_write
#define boot_page_write( addr ) ((void) 0)
#else
#ifndef GICR
#define GICR MCUCR
#endif
// If b=1, use bootloader's interrupt vectors
#define SET_IVSEL( b ) (GICR = 1<<IVCE, GICR = (b)<<IVSEL)
#endif
//**** Entry/exit
#if BOOTLOADER_ON_POWER
#define AUTO_EXIT_NO_USB 1
#define AUTO_EXIT_MS 4000
#endif
#if BOOTLOADER_ON_USB
#define AUTO_EXIT_NO_USB 1
#endif
#if BOOTLOADER_ON_RESET
static void bootLoaderInit( void ) { if ( !(MCUCSR & (1<<EXTRF)) ) leaveBootloader(); }
#define bootLoaderCondition() 1
static void bootLoaderExit( void ) { }
#endif
#if BOOTLOADER_ON_WDT
static void bootLoaderInit( void ) { if ( !(MCUCSR & (1<<WDRF)) ) leaveBootloader(); }
#define bootLoaderCondition() 1
static void bootLoaderExit( void ) { }
#endif
#if BOOTLOADER_ON_JUMPER
// All macros to delay of not-yet-defined USB_OUTPORT()/USB_INPORT()
#define bootLoaderInit() \
{ USB_OUTPORT(BOOTLOADER_JUMPER_PORT) |= 1<<BOOTLOADER_JUMPER_BIT; }
#define bootLoaderCondition() \
((USB_INPORT( BOOTLOADER_JUMPER_PORT) & (1<<BOOTLOADER_JUMPER_BIT)) == 0)
#define bootLoaderExit() \
{ USB_OUTPORT(BOOTLOADER_JUMPER_PORT) &= ~(1<<BOOTLOADER_JUMPER_BIT); }
#endif
#ifndef bootLoaderCondition
static void bootLoaderInit( void ) { }
#define bootLoaderCondition() 1
static void bootLoaderExit( void ) { }
#endif
#if !LED_PRESENT
#define LED_INIT()
#define LED_EXIT()
#define LED_BLINK()
#elif !defined(LED_BLINK)
#define LED_INIT() { }
#define LED_EXIT() { USB_DDRPORT(LED_PORT) &= ~(1<<LED_BIT); }
#define LED_BLINK() { USB_DDRPORT(LED_PORT) ^= (1<<LED_BIT); }
#endif
//**** Defaults/constraints
#ifndef SIGNATURE_BYTES
#define SIGNATURE_BYTES SIGNATURE_0, SIGNATURE_1, SIGNATURE_2, 0
#endif
#ifndef BOOTLOADER_CAN_EXIT
#define BOOTLOADER_CAN_EXIT 1
#endif
#ifndef HAVE_FLASH_PAGED_READ
#define HAVE_FLASH_PAGED_READ 1
#endif
#ifndef HAVE_EEPROM_PAGED_ACCESS
#define HAVE_EEPROM_PAGED_ACCESS 1
#endif
#ifndef USE_GLOBAL_REGS
#define USE_GLOBAL_REGS 1
#endif
#ifndef __GNUC__
#undef USE_GLOBAL_REGS
#endif
#if AUTO_EXIT_MS
#ifndef AUTO_EXIT_NO_USB
#define AUTO_EXIT_NO_USB 1
#endif
#endif
#if AUTO_EXIT_NO_USB
#define AUTO_EXIT_NO_USB_MS 500
#endif
#if !BOOTLOADER_CAN_EXIT
#undef AUTO_EXIT_NO_USB
#endif