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

Add basic ATtiny167 support. (LIN UART)

This commit is contained in:
WestfW
2018-08-14 19:45:20 -07:00
parent 1f961dfb93
commit 2fd356ff5d
3 changed files with 62 additions and 16 deletions

View File

@@ -274,3 +274,16 @@ attiny828at8_5v:
mv $(PROGRAM)_attiny828.lst $(PROGRAM)_$@.lst mv $(PROGRAM)_attiny828.lst $(PROGRAM)_$@.lst
#-------------------
# ATtiny167 - has LIN UART
#--------------------
attiny167: TARGET = attiny167
attiny167: MCU_TARGET = attiny167
attiny167: AVR_FREQ ?= 8000000L
attiny167: CFLAGS += $(COMMON_OPTIONS) '-DVIRTUAL_BOOT_PARTITION' '-DBAUD_RATE=57600'
attiny167: LDSECTIONS = -Wl,--section-start=.text=0x1d80 -Wl,--section-start=.version=0x1ffe
attiny167: $(PROGRAM)_attiny167.hex
attiny167: $(PROGRAM)_attiny167.lst

View File

@@ -396,10 +396,10 @@ typedef uint8_t pagelen_t;
* supress some compile-time options we want.) * supress some compile-time options we want.)
*/ */
int main(void) __attribute__ ((OS_main)) __attribute__ ((section (".init9"))); int main(void) __attribute__ ((OS_main)) __attribute__ ((section (".init9"))) __attribute__((used));
void __attribute__((noinline)) putch(char); void __attribute__((noinline)) __attribute__((leaf)) putch(char);
uint8_t __attribute__((noinline)) getch(void); uint8_t __attribute__((noinline)) __attribute__((leaf)) getch(void) ;
void __attribute__((noinline)) verifySpace(); void __attribute__((noinline)) verifySpace();
void __attribute__((noinline)) watchdogConfig(uint8_t x); void __attribute__((noinline)) watchdogConfig(uint8_t x);
@@ -574,24 +574,34 @@ int main(void) {
#endif #endif
#ifndef SOFT_UART #ifndef SOFT_UART
#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 #ifndef SINGLESPEED
UCSRA = _BV(U2X); //Double speed mode USART UCSRA = _BV(U2X); //Double speed mode USART
#endif #endif //singlespeed
UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1 UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 ); UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#else #else // mega8/etc
#ifndef SINGLESPEED #ifdef LIN_UART
//DDRB|=3;
LINCR = (1 << LSWRES);
//LINBRRL = (((F_CPU * 10L / 32L / BAUD_RATE) + 5L) / 10L) - 1;
LINBRRL=(uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
LINBTR = (1 << LDISR) | (8 << LBT0);
LINCR = _BV(LENA) | _BV(LCMD2) | _BV(LCMD1) | _BV(LCMD0);
LINDAT=0;
#else
#ifndef SINGLESPEED
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);
UART_SRC = _BV(UCSZ00) | _BV(UCSZ01); UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 ); UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#endif #endif // LIN_UART
#endif #endif // mega8/etc
#endif // soft_uart
// Set up watchdog to trigger after 1s // Set up watchdog to trigger after 1s
watchdogConfig(WATCHDOG_1S); watchdogConfig(WATCHDOG_1S);
@@ -806,8 +816,14 @@ int main(void) {
void putch(char ch) { void putch(char ch) {
#ifndef SOFT_UART #ifndef SOFT_UART
while (!(UART_SRA & _BV(UDRE0))); #ifndef LIN_UART
while (!(UART_SRA & _BV(UDRE0))) { /* Spin */ }
#else
while (!(LINSIR & _BV(LTXOK))) { /* Spin */ }
#endif
UART_UDR = ch; UART_UDR = ch;
#else #else
__asm__ __volatile__ ( __asm__ __volatile__ (
" com %[ch]\n" // ones complement, carry set " com %[ch]\n" // ones complement, carry set
@@ -874,9 +890,13 @@ uint8_t getch(void) {
"r25" "r25"
); );
#else #else
while(!(UART_SRA & _BV(RXC0))) #ifndef LIN_UART
; while(!(UART_SRA & _BV(RXC0))) { /* Spin */ }
if (!(UART_SRA & _BV(FE0))) { if (!(UART_SRA & _BV(FE0))) {
#else
while(!(LINSIR & _BV(LRXOK))) { /* Spin */ }
if (!(LINSIR & _BV(LFERR))) {
#endif
/* /*
* A Framing Error indicates (probably) that something is talking * A Framing Error indicates (probably) that something is talking
* to us at the wrong bit rate. Assume that this is because it * to us at the wrong bit rate. Assume that this is because it
@@ -960,7 +980,11 @@ void flash_led(uint8_t count) {
* quick succession, some of which will be lost and cause us to * quick succession, some of which will be lost and cause us to
* get out of sync. So if we see any data; stop blinking. * get out of sync. So if we see any data; stop blinking.
*/ */
#ifndef LIN_UART
if (UART_SRA & _BV(RXC0)) if (UART_SRA & _BV(RXC0))
#else
if (LINSIR & _BV(LRXOK))
#endif
break; break;
#else #else
// This doesn't seem to work? // This doesn't seem to work?

View File

@@ -43,11 +43,20 @@
* differently. * differently.
*/ */
#if UART == 0 #if UART == 0
#if defined(LINDAT)
#define LIN_UART 1
#define UART_SRA UCSRA
#define UART_SRB UCSRB
#define UART_SRC UCSRC
#define UART_SRL UBRRL
#define UART_UDR LINDAT
#else
# define UART_SRA UCSR0A # define UART_SRA UCSR0A
# define UART_SRB UCSR0B # define UART_SRB UCSR0B
# define UART_SRC UCSR0C # define UART_SRC UCSR0C
# define UART_SRL UBRR0L # define UART_SRL UBRR0L
# define UART_UDR UDR0 # define UART_UDR UDR0
#endif
#elif UART == 1 #elif UART == 1
#if !defined(UDR1) #if !defined(UDR1)
#error UART == 1, but no UART1 on device #error UART == 1, but no UART1 on device