aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/AVR
diff options
context:
space:
mode:
authorFabio Utzig <utzig@utzig.org>2016-10-19 11:50:33 +0000
committerFabio Utzig <utzig@utzig.org>2016-10-19 11:50:33 +0000
commit5855f8f53c208e6d69af6b8f0d1085f6f1dd161d (patch)
tree28fefadc0c7628c4323ee6aa32dedd404e5c473e /os/hal/ports/AVR
parent8b55eca786713090d638f1d4a62874bec685f74a (diff)
downloadChibiOS-5855f8f53c208e6d69af6b8f0d1085f6f1dd161d.tar.gz
ChibiOS-5855f8f53c208e6d69af6b8f0d1085f6f1dd161d.tar.bz2
ChibiOS-5855f8f53c208e6d69af6b8f0d1085f6f1dd161d.zip
Added support for ATmega162
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9867 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/ports/AVR')
-rw-r--r--os/hal/ports/AVR/avr_pins.h2
-rw-r--r--os/hal/ports/AVR/hal_serial_lld.c58
-rw-r--r--os/hal/ports/AVR/hal_st_lld.h2
3 files changed, 50 insertions, 12 deletions
diff --git a/os/hal/ports/AVR/avr_pins.h b/os/hal/ports/AVR/avr_pins.h
index ae094e165..b89325aff 100644
--- a/os/hal/ports/AVR/avr_pins.h
+++ b/os/hal/ports/AVR/avr_pins.h
@@ -21,7 +21,7 @@
#if AVR_SPI_USE_SPI1
-#if defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__)
+#if defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega162__)
#define PIN_SPI1 PINB
#define PORT_SPI1 PORTB
#define DDR_SPI1 DDRB
diff --git a/os/hal/ports/AVR/hal_serial_lld.c b/os/hal/ports/AVR/hal_serial_lld.c
index bf1e65729..ab0d7f47b 100644
--- a/os/hal/ports/AVR/hal_serial_lld.c
+++ b/os/hal/ports/AVR/hal_serial_lld.c
@@ -45,6 +45,9 @@ SerialDriver SD1;
#elif defined(USART_RX_vect)
#define AVR_SD1_RX_VECT USART_RX_vect
#define AVR_SD1_TX_VECT USART_UDRE_vect
+ #elif defined(USART0_RXC_vect)
+ #define AVR_SD1_RX_VECT USART0_RXC_vect
+ #define AVR_SD1_TX_VECT USART0_UDRE_vect
#else
#error "Cannot find USART to use for SD1"
#endif
@@ -62,6 +65,9 @@ SerialDriver SD2;
#ifdef USART1_RX_vect
#define AVR_SD2_RX_VECT USART1_RX_vect
#define AVR_SD2_TX_VECT USART1_UDRE_vect
+ #elif defined (USART1_RXC_vect)
+ #define AVR_SD2_RX_VECT USART1_RXC_vect
+ #define AVR_SD2_TX_VECT USART1_UDRE_vect
#else
#error "Cannot find USART to use for SD2"
#endif
@@ -130,28 +136,40 @@ static void notify1(io_queue_t *qp) {
*/
static void usart0_init(const SerialConfig *config) {
+ uint8_t ucsr0c;
+
UBRR0L = config->sc_brr;
+#if defined(__AVR_ATmega162__)
+ UBRR0H = (config->sc_brr >> 8) & 0x0f;
+#else
UBRR0H = config->sc_brr >> 8;
+#endif
UCSR0A = 0;
UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
switch (config->sc_bits_per_char) {
case USART_CHAR_SIZE_5:
- UCSR0C = 0;
+ ucsr0c = 0;
break;
case USART_CHAR_SIZE_6:
- UCSR0C = (1 << UCSZ00);
+ ucsr0c = (1 << UCSZ00);
break;
case USART_CHAR_SIZE_7:
- UCSR0C = (1 << UCSZ01);
+ ucsr0c = (1 << UCSZ01);
break;
case USART_CHAR_SIZE_9:
UCSR0B |= (1 << UCSZ02);
- UCSR0C = (1 << UCSZ00) | (1 << UCSZ01);
+ ucsr0c = (1 << UCSZ00) | (1 << UCSZ01);
break;
case USART_CHAR_SIZE_8:
default:
- UCSR0C = (1 << UCSZ00) | (1 << UCSZ01);
+ ucsr0c = (1 << UCSZ00) | (1 << UCSZ01);
}
+
+#if defined(__AVR_ATmega162__)
+ UCSR0C = (1 << URSEL0) | ucsr0c;
+#else
+ UCSR0C = ucsr0c;
+#endif
}
/**
@@ -161,7 +179,11 @@ static void usart0_deinit(void) {
UCSR0A = 0;
UCSR0B = 0;
+#if defined(__AVR_ATmega162__)
+ UCSR0C = (1 << URSEL0) | 0;
+#else
UCSR0C = 0;
+#endif
}
#endif
@@ -179,28 +201,40 @@ static void notify2(io_queue_t *qp) {
*/
static void usart1_init(const SerialConfig *config) {
+ uint8_t ucsr1c;
+
UBRR1L = config->sc_brr;
+#if defined(__AVR_ATmega162__)
+ UBRR1H = (config->sc_brr >> 8) & 0x0f;
+#else
UBRR1H = config->sc_brr >> 8;
+#endif
UCSR1A = 0;
UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1);
switch (config->sc_bits_per_char) {
case USART_CHAR_SIZE_5:
- UCSR1C = 0;
+ ucsr1c = 0;
break;
case USART_CHAR_SIZE_6:
- UCSR1C = (1 << UCSZ10);
+ ucsr1c = (1 << UCSZ10);
break;
case USART_CHAR_SIZE_7:
- UCSR1C = (1 << UCSZ11);
+ ucsr1c = (1 << UCSZ11);
break;
case USART_CHAR_SIZE_9:
UCSR1B |= (1 << UCSZ12);
- UCSR1C = (1 << UCSZ10) | (1 << UCSZ11);
+ ucsr1c = (1 << UCSZ10) | (1 << UCSZ11);
break;
case USART_CHAR_SIZE_8:
default:
- UCSR1C = (1 << UCSZ10) | (1 << UCSZ11);
+ ucsr1c = (1 << UCSZ10) | (1 << UCSZ11);
}
+
+#if defined(__AVR_ATmega162__)
+ UCSR1C = (1 << URSEL1) | ucsr1c;
+#else
+ UCSR1C = ucsr1c;
+#endif
}
/**
@@ -210,7 +244,11 @@ static void usart1_deinit(void) {
UCSR1A = 0;
UCSR1B = 0;
+#if defined(__AVR_ATmega162__)
+ UCSR1C = (1 << URSEL1) | 0;
+#else
UCSR1C = 0;
+#endif
}
#endif
diff --git a/os/hal/ports/AVR/hal_st_lld.h b/os/hal/ports/AVR/hal_st_lld.h
index 223a6ed37..eb20633e4 100644
--- a/os/hal/ports/AVR/hal_st_lld.h
+++ b/os/hal/ports/AVR/hal_st_lld.h
@@ -70,7 +70,7 @@ extern "C" {
}
#endif
-#ifdef __AVR_ATmega128__
+#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega162__)
#define TIFR_REG TIFR
#define TIMSK_REG TIMSK
#else