Skip to content

Commit

Permalink
Changes to allow pins_rs485.h to be used with both mega0/xTiny chips …
Browse files Browse the repository at this point in the history
…as well as older AVRs (PORTx vs VPORTx stuff.)

Also adjust the build info included in the BIGBOOT image.
  • Loading branch information
WestfW committed Jun 28, 2021
1 parent 084c69c commit bcc7143
Show file tree
Hide file tree
Showing 2 changed files with 376 additions and 540 deletions.
31 changes: 19 additions & 12 deletions optiboot/bootloaders/optiboot/optiboot.c
Expand Up @@ -797,11 +797,11 @@ int main(void) {
#endif // soft_uart

#ifdef RS485
RS485_DDR |= _BV(RS485);
RS485_DDR |= _BV(RS485_BIT);
#ifdef RS485_INVERT
RS485_PORT |= _BV(RS485);
RS485_PORT |= _BV(RS485_BIT);
#else
RS485_PORT &= ~_BV(RS485);
RS485_PORT &= ~_BV(RS485_BIT);
#endif
#endif

Expand Down Expand Up @@ -1102,19 +1102,19 @@ void putch(char ch) {
UART_SRA = x;
// put transceiver to output mode
# ifdef RS485_INVERT
RS485_PORT &= ~_BV(RS485);
RS485_PORT &= ~_BV(RS485_BIT);
# else
RS485_PORT |= _BV(RS485);
RS485_PORT |= _BV(RS485_BIT);
# endif
// put char
UART_UDR = ch;
// wait for char transmitted
while (!(UART_SRA & _BV(TXC0))) { /* Spin */ }
// put transceiver to input mode
# ifdef RS485_INVERT
RS485_PORT |= _BV(RS485);
RS485_PORT |= _BV(RS485_BIT);
# else
RS485_PORT &= ~_BV(RS485);
RS485_PORT &= ~_BV(RS485_BIT);
# endif
#else //not RS485
while (!(UART_SRA & _BV(UDRE0))) { /* Spin */ }
Expand All @@ -1130,9 +1130,9 @@ void putch(char ch) {
#ifdef RS485
// put transceiver to output mode
#ifdef RS485_INVERT
RS485_PORT &= ~_BV(RS485);
RS485_PORT &= ~_BV(RS485_BIT);
#else
RS485_PORT |= _BV(RS485);
RS485_PORT |= _BV(RS485_BIT);
#endif
#endif
__asm__ __volatile__ (
Expand Down Expand Up @@ -1161,9 +1161,9 @@ void putch(char ch) {
#ifdef RS485
// put transceiver to input mode
#ifdef RS485_INVERT
RS485_PORT |= _BV(RS485);
RS485_PORT |= _BV(RS485_BIT);
#else
RS485_PORT &= ~_BV(RS485);
RS485_PORT &= ~_BV(RS485_BIT);
#endif
#endif
#endif // SOFT_UART
Expand Down Expand Up @@ -1528,6 +1528,9 @@ static void do_spm(uint16_t address, uint8_t command, uint16_t data) {
*/
#define xstr(s) str(s)
#define str(s) #s

__attribute__((section(".fini9"))) const char f_delimit = 0xFF;

#define OPTFLASHSECT __attribute__((section(".fini8")))
#define OPT2FLASH(o) OPTFLASHSECT const char f##o[] = #o "=" xstr(o)

Expand All @@ -1548,6 +1551,10 @@ OPTFLASHSECT const char f_LED[] = "LED=" LED_NAME;
#if SUPPORT_EEPROM
OPT2FLASH(SUPPORT_EEPROM);
#endif

#if defined(RS485)
OPTFLASHSECT const char f_rs485[] = "RS485=" RS485_NAME;
#endif
#if BAUD_RATE
OPT2FLASH(BAUD_RATE);
#endif
Expand All @@ -1567,7 +1574,7 @@ OPTFLASHSECT const char f_boot[] = "Virtual_Boot_Partition";
#endif
OPT2FLASH(F_CPU);
OPTFLASHSECT const char f_device[] = "Device=" xstr(__AVR_DEVICE_NAME__);
#ifdef OPTIBOOT_CUSTOMVER
#if OPTIBOOT_CUSTOMVER
OPT2FLASH(OPTIBOOT_CUSTOMVER);
#endif
OPTFLASHSECT const char f_version[] = "Version=" xstr(OPTIBOOT_MAJVER) "." xstr(OPTIBOOT_MINVER);
Expand Down

0 comments on commit bcc7143

Please sign in to comment.