1
0
mirror of https://github.com/Optiboot/optiboot.git synced 2025-08-19 09:02:05 +03:00

Change the compile option symbols to be true/false instead of sometimes defined/undefined, so that specifying "LED_START_ON=0" doesn't actually cause the same behvaior as "LED_START_ON=1"

This commit is contained in:
WestfW
2020-06-18 00:48:08 -07:00
parent 243ee94ffa
commit 6f98751c6d
2 changed files with 90 additions and 63 deletions

View File

@@ -131,6 +131,41 @@
/* one hardware uart (644P, 1284P, etc) */ /* one hardware uart (644P, 1284P, etc) */
/* */ /* */
/**********************************************************/ /**********************************************************/
/*
* default values.
*/
#if !defined(BIGBOOT)
# define BIGBOOT 0
#endif
#if !defined(SUPPORT_EEPROM)
# define SUPPORT_EEPROM 0
#endif
#if !defined(SOFT_UART)
# define SOFT_UART 0
#endif
#if !defined(UART)
#define UART 0
#endif
#if !defined(SINGLESPEED)
#define SINGLESPEED 0
#endif
#if !defined(APP_NOSPM)
#define APP_NOSPM 0
#endif
#if !defined(LED_START_FLASHES)
#define LED_START_FLASHES 0
#endif
#if !defined(LED_DATA_FLASH)
# define LED_DATA_FLASH 0
#endif
#if !defined(LED_START_ON)
# define LED_START_ON 0
#endif
/**********************************************************/ /**********************************************************/
/* Version Numbers! */ /* Version Numbers! */
@@ -313,10 +348,6 @@ typedef union {
*/ */
#include "stk500.h" #include "stk500.h"
#ifndef LED_START_FLASHES
#define LED_START_FLASHES 0
#endif
/* set the UART baud rate defaults */ /* set the UART baud rate defaults */
#ifndef BAUD_RATE #ifndef BAUD_RATE
#if F_CPU >= 8000000L #if F_CPU >= 8000000L
@@ -330,12 +361,8 @@ typedef union {
#endif #endif
#endif #endif
#ifndef UART #if (SOFT_UART == 0)
#define UART 0 #if SINGLESPEED
#endif
#ifndef SOFT_UART
#ifdef SINGLESPEED
/* Single speed option */ /* Single speed option */
#define BAUD_SETTING (( (F_CPU + BAUD_RATE * 8L) / ((BAUD_RATE * 16L))) - 1 ) #define BAUD_SETTING (( (F_CPU + BAUD_RATE * 8L) / ((BAUD_RATE * 16L))) - 1 )
#define BAUD_ACTUAL (F_CPU/(16 * ((BAUD_SETTING)+1))) #define BAUD_ACTUAL (F_CPU/(16 * ((BAUD_SETTING)+1)))
@@ -539,10 +566,10 @@ void pre_main(void) {
// features etc // features etc
asm volatile ( asm volatile (
" rjmp 1f\n" " rjmp 1f\n"
#ifndef APP_NOSPM #if APP_NOSPM
" rjmp do_spm\n"
#else
" ret\n" // if do_spm isn't include, return without doing anything " ret\n" // if do_spm isn't include, return without doing anything
#else
" rjmp do_spm\n"
#endif #endif
"1:\n" "1:\n"
); );
@@ -675,11 +702,11 @@ int main(void) {
#endif #endif
#ifndef SOFT_UART #if (SOFT_UART == 0)
#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega8515__) || \ #if defined(__AVR_ATmega8__) || defined (__AVR_ATmega8515__) || \
defined (__AVR_ATmega8535__) || defined (__AVR_ATmega16__) || \ defined (__AVR_ATmega8535__) || defined (__AVR_ATmega16__) || \
defined (__AVR_ATmega32__) defined (__AVR_ATmega32__)
#ifndef SINGLESPEED #if (SINGLESPEED == 0)
UCSRA = _BV(U2X); //Double speed mode USART UCSRA = _BV(U2X); //Double speed mode USART
#endif //singlespeed #endif //singlespeed
UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
@@ -695,7 +722,7 @@ int main(void) {
LINCR = _BV(LENA) | _BV(LCMD2) | _BV(LCMD1) | _BV(LCMD0); LINCR = _BV(LENA) | _BV(LCMD2) | _BV(LCMD1) | _BV(LCMD0);
LINDAT=0; LINDAT=0;
#else #else
#ifndef SINGLESPEED #if (SINGLESPEED == 0)
UART_SRA = _BV(U2X0); //Double speed mode USART0 UART_SRA = _BV(U2X0); //Double speed mode USART0
#endif #endif
UART_SRB = _BV(RXEN0) | _BV(TXEN0); UART_SRB = _BV(RXEN0) | _BV(TXEN0);
@@ -708,12 +735,12 @@ int main(void) {
// Set up watchdog to trigger after desired timeout // Set up watchdog to trigger after desired timeout
watchdogConfig(WDTPERIOD); watchdogConfig(WDTPERIOD);
#if (LED_START_FLASHES > 0) || defined(LED_DATA_FLASH) || defined(LED_START_ON) #if (LED_START_FLASHES > 0) || LED_DATA_FLASH || LED_START_ON
/* Set LED pin as output */ /* Set LED pin as output */
LED_DDR |= _BV(LED); LED_DDR |= _BV(LED);
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
/* Set TX pin as output */ /* Set TX pin as output */
UART_DDR |= _BV(UART_TX_BIT); UART_DDR |= _BV(UART_TX_BIT);
#endif #endif
@@ -722,7 +749,7 @@ int main(void) {
/* Flash onboard LED to signal entering of bootloader */ /* Flash onboard LED to signal entering of bootloader */
flash_led(LED_START_FLASHES * 2); flash_led(LED_START_FLASHES * 2);
#else #else
#if defined(LED_START_ON) #if LED_START_ON
/* Turn on LED to indicate starting bootloader (less code!) */ /* Turn on LED to indicate starting bootloader (less code!) */
LED_PORT |= _BV(LED); LED_PORT |= _BV(LED);
#endif #endif
@@ -983,7 +1010,7 @@ int main(void) {
} }
void putch(char ch) { void putch(char ch) {
#ifndef SOFT_UART #if (SOFT_UART == 0)
#ifndef LIN_UART #ifndef LIN_UART
while (!(UART_SRA & _BV(UDRE0))) { /* Spin */ } while (!(UART_SRA & _BV(UDRE0))) { /* Spin */ }
#else #else
@@ -1021,7 +1048,7 @@ void putch(char ch) {
uint8_t getch(void) { uint8_t getch(void) {
uint8_t ch; uint8_t ch;
#ifdef LED_DATA_FLASH #if LED_DATA_FLASH
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega8515__) || \ #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega8515__) || \
defined(__AVR_ATmega8535__) || defined(__AVR_ATmega16__) || \ defined(__AVR_ATmega8535__) || defined(__AVR_ATmega16__) || \
defined(__AVR_ATmega162__) || defined(__AVR_ATmega32__) || \ defined(__AVR_ATmega162__) || defined(__AVR_ATmega32__) || \
@@ -1032,7 +1059,7 @@ uint8_t getch(void) {
#endif #endif
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
watchdogReset(); watchdogReset();
__asm__ __volatile__ ( __asm__ __volatile__ (
"1: sbic %[uartPin],%[uartBit]\n" // Wait for start edge "1: sbic %[uartPin],%[uartBit]\n" // Wait for start edge
@@ -1079,7 +1106,7 @@ uint8_t getch(void) {
ch = UART_UDR; ch = UART_UDR;
#endif #endif
#ifdef LED_DATA_FLASH #if LED_DATA_FLASH
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega8515__) || \ #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega8515__) || \
defined(__AVR_ATmega8535__) || defined(__AVR_ATmega16__) || \ defined(__AVR_ATmega8535__) || defined(__AVR_ATmega16__) || \
defined(__AVR_ATmega162__) || defined(__AVR_ATmega32__) || \ defined(__AVR_ATmega162__) || defined(__AVR_ATmega32__) || \
@@ -1093,7 +1120,7 @@ uint8_t getch(void) {
return ch; return ch;
} }
#ifdef SOFT_UART #if SOFT_UART
// AVR305 equation: #define UART_B_VALUE (((F_CPU/BAUD_RATE)-23)/6) // AVR305 equation: #define UART_B_VALUE (((F_CPU/BAUD_RATE)-23)/6)
// Adding 3 to numerator simulates nearest rounding for more accurate baud rates // Adding 3 to numerator simulates nearest rounding for more accurate baud rates
#define UART_B_VALUE (((F_CPU/BAUD_RATE)-20)/6) #define UART_B_VALUE (((F_CPU/BAUD_RATE)-20)/6)
@@ -1158,7 +1185,7 @@ void flash_led(uint8_t count) {
LED_PIN |= _BV(LED); LED_PIN |= _BV(LED);
#endif #endif
watchdogReset(); watchdogReset();
#ifndef SOFT_UART #if (SOFT_UART == 0)
/* /*
* While in theory, the STK500 initial commands would be buffered * While in theory, the STK500 initial commands would be buffered
* by the UART hardware, avrdude sends several attempts in rather * by the UART hardware, avrdude sends several attempts in rather
@@ -1214,7 +1241,7 @@ static inline void writebuffer(int8_t memtype, addr16_t mybuff,
{ {
switch (memtype) { switch (memtype) {
case 'E': // EEPROM case 'E': // EEPROM
#if defined(SUPPORT_EEPROM) || defined(BIGBOOT) #if SUPPORT_EEPROM || BIGBOOT
while(len--) { while(len--) {
eeprom_write_byte((address.bptr++), *(mybuff.bptr++)); eeprom_write_byte((address.bptr++), *(mybuff.bptr++));
} }
@@ -1281,7 +1308,7 @@ static inline void read_mem(uint8_t memtype, addr16_t address, pagelen_t length)
switch (memtype) { switch (memtype) {
#if defined(SUPPORT_EEPROM) || defined(BIGBOOT) #if SUPPORT_EEPROM || BIGBOOT
case 'E': // EEPROM case 'E': // EEPROM
do { do {
putch(eeprom_read_byte((address.bptr++))); putch(eeprom_read_byte((address.bptr++)));
@@ -1316,7 +1343,7 @@ static inline void read_mem(uint8_t memtype, addr16_t address, pagelen_t length)
} }
#ifndef APP_NOSPM #if (APP_NOSPM == 0)
/* /*
* Separate function for doing spm stuff * Separate function for doing spm stuff
@@ -1369,7 +1396,7 @@ static void do_spm(uint16_t address, uint8_t command, uint16_t data) {
#ifdef BIGBOOT #if BIGBOOT
/* /*
* Optiboot is designed to fit in 512 bytes, with a minimum feature set. * Optiboot is designed to fit in 512 bytes, with a minimum feature set.
* Some chips have a minimum bootloader size of 1024 bytes, and sometimes * Some chips have a minimum bootloader size of 1024 bytes, and sometimes
@@ -1390,34 +1417,34 @@ static void do_spm(uint16_t address, uint8_t command, uint16_t data) {
#define OPT2FLASH(o) OPTFLASHSECT const char f##o[] = #o "=" xstr(o) #define OPT2FLASH(o) OPTFLASHSECT const char f##o[] = #o "=" xstr(o)
#ifdef LED_START_FLASHES #if LED_START_FLASHES
OPT2FLASH(LED_START_FLASHES); OPT2FLASH(LED_START_FLASHES);
#endif #endif
#ifdef LED_DATA_FLASH #if LED_DATA_FLASH
OPT2FLASH(LED_DATA_FLASH); OPT2FLASH(LED_DATA_FLASH);
#endif #endif
#ifdef LED_START_ON #if LED_START_ON
OPT2FLASH(LED_START_ON); OPT2FLASH(LED_START_ON);
#endif #endif
#ifdef LED_NAME #ifdef LED_NAME
OPTFLASHSECT const char f_LED[] = "LED=" LED_NAME; OPTFLASHSECT const char f_LED[] = "LED=" LED_NAME;
#endif #endif
#ifdef SUPPORT_EEPROM #if SUPPORT_EEPROM
OPT2FLASH(SUPPORT_EEPROM); OPT2FLASH(SUPPORT_EEPROM);
#endif #endif
#ifdef BAUD_RATE #if BAUD_RATE
OPT2FLASH(BAUD_RATE); OPT2FLASH(BAUD_RATE);
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
OPT2FLASH(SOFT_UART); OPT2FLASH(SOFT_UART);
#endif #endif
#ifdef UART #if defined(UART)
OPT2FLASH(UART); OPT2FLASH(UART);
#endif #endif
OPTFLASHSECT const char f_date[] = "Built:" __DATE__ ":" __TIME__; OPTFLASHSECT const char f_date[] = "Built:" __DATE__ ":" __TIME__;
#ifdef BIGBOOT #if BIGBOOT
OPT2FLASH(BIGBOOT); OPT2FLASH(BIGBOOT);
#endif #endif
#ifdef VIRTUAL_BOOT_PARTITION #ifdef VIRTUAL_BOOT_PARTITION

View File

@@ -28,7 +28,7 @@
#endif #endif
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTD #define UART_PORT PORTD
#define UART_PIN PIND #define UART_PIN PIND
#define UART_DDR DDRD #define UART_DDR DDRD
@@ -42,7 +42,7 @@
* Note that mega8/m32 still needs special handling, because ubrr is handled * Note that mega8/m32 still needs special handling, because ubrr is handled
* differently. * differently.
*/ */
#ifndef SOFT_UART #if (SOFT_UART == 0)
#if UART == 0 #if UART == 0
#if defined(UDR0) #if defined(UDR0)
# define UART_SRA UCSR0A # define UART_SRA UCSR0A
@@ -94,7 +94,7 @@
# define UART_SRL UBRR3L # define UART_SRL UBRR3L
# define UART_UDR UDR3 # define UART_UDR UDR3
#endif #endif
#endif //end #ifndef SOFT_UART #endif //end #if SOFT_UART==0
#if defined(__AVR_ATmega8__) \ #if defined(__AVR_ATmega8__) \
|| defined (__AVR_ATmega32__) \ || defined (__AVR_ATmega32__) \
@@ -137,7 +137,7 @@
#define WDTCSR WDTCR #define WDTCSR WDTCR
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTD #define UART_PORT PORTD
#define UART_PIN PIND #define UART_PIN PIND
#define UART_DDR DDRD #define UART_DDR DDRD
@@ -180,7 +180,7 @@
#endif #endif
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTD #define UART_PORT PORTD
#define UART_PIN PIND #define UART_PIN PIND
#define UART_DDR DDRD #define UART_DDR DDRD
@@ -281,7 +281,7 @@
#define UMSEL21 UMSEL1 #define UMSEL21 UMSEL1
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTD #define UART_PORT PORTD
#define UART_PIN PIND #define UART_PIN PIND
#define UART_DDR DDRD #define UART_DDR DDRD
@@ -303,7 +303,7 @@
//#define SPMCR SPMCSR //#define SPMCR SPMCSR
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTE #define UART_PORT PORTE
#define UART_PIN PINE #define UART_PIN PINE
#define UART_DDR DDRE #define UART_DDR DDRE
@@ -324,7 +324,7 @@
#endif #endif
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTE #define UART_PORT PORTE
#define UART_PIN PINE #define UART_PIN PINE
#define UART_DDR DDRE #define UART_DDR DDRE
@@ -341,7 +341,7 @@
#endif #endif
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTE #define UART_PORT PORTE
#define UART_PIN PINE #define UART_PIN PINE
#define UART_DDR DDRE #define UART_DDR DDRE
@@ -375,7 +375,7 @@
#define UCSZ01 UCSZ1 #define UCSZ01 UCSZ1
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTE #define UART_PORT PORTE
#define UART_PIN PINE #define UART_PIN PINE
#define UART_DDR DDRE #define UART_DDR DDRE
@@ -397,7 +397,7 @@
#define WDTCSR WDTCR #define WDTCSR WDTCR
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTE #define UART_PORT PORTE
#define UART_PIN PINE #define UART_PIN PINE
#define UART_DDR DDRE #define UART_DDR DDRE
@@ -413,7 +413,7 @@
#endif #endif
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTE #define UART_PORT PORTE
#define UART_PIN PINE #define UART_PIN PINE
#define UART_DDR DDRE #define UART_DDR DDRE
@@ -447,7 +447,7 @@
#define UCSZ01 UCSZ1 #define UCSZ01 UCSZ1
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTE #define UART_PORT PORTE
#define UART_PIN PINE #define UART_PIN PINE
#define UART_DDR DDRE #define UART_DDR DDRE
@@ -469,7 +469,7 @@
#define WDTCSR WDTCR #define WDTCSR WDTCR
/* Ports for soft UART */ /* Ports for soft UART */
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTE #define UART_PORT PORTE
#define UART_PIN PINE #define UART_PIN PINE
#define UART_DDR DDRE #define UART_DDR DDRE
@@ -487,7 +487,7 @@
#endif #endif
#define TIFR1 TIFR #define TIFR1 TIFR
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTA #define UART_PORT PORTA
#define UART_PIN PINA #define UART_PIN PINA
#define UART_DDR DDRA #define UART_DDR DDRA
@@ -505,7 +505,7 @@
#define LED B2 #define LED B2
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTA #define UART_PORT PORTA
#define UART_PIN PINA #define UART_PIN PINA
#define UART_DDR DDRA #define UART_DDR DDRA
@@ -522,7 +522,7 @@
#define LED B2 #define LED B2
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTA #define UART_PORT PORTA
#define UART_PIN PINA #define UART_PIN PINA
#define UART_DDR DDRA #define UART_DDR DDRA
@@ -538,7 +538,7 @@
#define LED B2 #define LED B2
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTA #define UART_PORT PORTA
#define UART_PIN PINA #define UART_PIN PINA
#define UART_DDR DDRA #define UART_DDR DDRA
@@ -555,7 +555,7 @@
#define LED B2 #define LED B2
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTA #define UART_PORT PORTA
#define UART_PIN PINA #define UART_PIN PINA
#define UART_DDR DDRA #define UART_DDR DDRA
@@ -572,7 +572,7 @@
#define LED B2 #define LED B2
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTB #define UART_PORT PORTB
#define UART_PIN PINB #define UART_PIN PINB
#define UART_DDR DDRB #define UART_DDR DDRB
@@ -589,7 +589,7 @@
#define LED B2 #define LED B2
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTB #define UART_PORT PORTB
#define UART_PIN PINB #define UART_PIN PINB
#define UART_DDR DDRB #define UART_DDR DDRB
@@ -606,7 +606,7 @@
#define LED B3 #define LED B3
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTA #define UART_PORT PORTA
#define UART_PIN PINA #define UART_PIN PINA
#define UART_DDR DDRA #define UART_DDR DDRA
@@ -623,7 +623,7 @@
#define LED B3 #define LED B3
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTA #define UART_PORT PORTA
#define UART_PIN PINA #define UART_PIN PINA
#define UART_DDR DDRA #define UART_DDR DDRA
@@ -640,7 +640,7 @@
#define LED B5 #define LED B5
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTD #define UART_PORT PORTD
#define UART_PIN PIND #define UART_PIN PIND
#define UART_DDR DDRD #define UART_DDR DDRD
@@ -657,7 +657,7 @@
#define LED B5 #define LED B5
#endif #endif
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTD #define UART_PORT PORTD
#define UART_PIN PIND #define UART_PIN PIND
#define UART_DDR DDRD #define UART_DDR DDRD
@@ -703,7 +703,7 @@
#define U2X0 U2X #define U2X0 U2X
#ifdef SOFT_UART #if SOFT_UART
#define UART_PORT PORTA #define UART_PORT PORTA
#define UART_PIN PINA #define UART_PIN PINA
#define UART_DDR DDRA #define UART_DDR DDRA