aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-07-01 14:10:13 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-07-01 14:10:13 +0000
commit21b907c94677776684b86440ec081a0252cd02e2 (patch)
tree3664934b835409b9b33e83e621ef4adeb796d410 /os/hal/platforms
parent8fabd4641a6d869901256d8b1b4163a6a99b05f6 (diff)
downloadChibiOS-21b907c94677776684b86440ec081a0252cd02e2.tar.gz
ChibiOS-21b907c94677776684b86440ec081a0252cd02e2.tar.bz2
ChibiOS-21b907c94677776684b86440ec081a0252cd02e2.zip
Arduino Mega support.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4379 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms')
-rw-r--r--os/hal/platforms/AVR/pal_lld.c20
-rw-r--r--os/hal/platforms/AVR/pal_lld.h40
-rw-r--r--os/hal/platforms/AVR/serial_lld.c81
-rw-r--r--os/hal/platforms/AVR/serial_lld.h14
4 files changed, 137 insertions, 18 deletions
diff --git a/os/hal/platforms/AVR/pal_lld.c b/os/hal/platforms/AVR/pal_lld.c
index fa2c647df..c5a4785b7 100644
--- a/os/hal/platforms/AVR/pal_lld.c
+++ b/os/hal/platforms/AVR/pal_lld.c
@@ -95,6 +95,26 @@ void _pal_lld_init(const PALConfig *config) {
PORTG = config->portg.out;
DDRG = config->portg.dir;
#endif
+
+#if defined(PORTH) || defined(__DOXYGEN__)
+ PORTH = config->porth.out;
+ DDRH = config->porth.dir;
+#endif
+
+#if defined(PORTJ) || defined(__DOXYGEN__)
+ PORTJ = config->portj.out;
+ DDRJ = config->portj.dir;
+#endif
+
+#if defined(PORTK) || defined(__DOXYGEN__)
+ PORTK = config->portk.out;
+ DDRK = config->portk.dir;
+#endif
+
+#if defined(PORTL) || defined(__DOXYGEN__)
+ PORTL = config->portl.out;
+ DDRL = config->portl.dir;
+#endif
}
/**
diff --git a/os/hal/platforms/AVR/pal_lld.h b/os/hal/platforms/AVR/pal_lld.h
index b0592d816..e07e2ccc3 100644
--- a/os/hal/platforms/AVR/pal_lld.h
+++ b/os/hal/platforms/AVR/pal_lld.h
@@ -102,6 +102,18 @@ typedef struct {
#if defined(PORTG) || defined(__DOXYGEN__)
avr_gpio_setup_t portg;
#endif
+#if defined(PORTH) || defined(__DOXYGEN__)
+ avr_gpio_setup_t porth;
+#endif
+#if defined(PORTJ) || defined(__DOXYGEN__)
+ avr_gpio_setup_t portj;
+#endif
+#if defined(PORTK) || defined(__DOXYGEN__)
+ avr_gpio_setup_t portk;
+#endif
+#if defined(PORTL) || defined(__DOXYGEN__)
+ avr_gpio_setup_t portl;
+#endif
} PALConfig;
/**
@@ -175,6 +187,34 @@ typedef avr_gpio_registers_t *ioportid_t;
#define IOPORT7 ((volatile avr_gpio_registers_t *)&PING)
#endif
+#if defined(PORTH) || defined(__DOXYGEN__)
+/**
+ * @brief GPIO port H identifier.
+ */
+#define IOPORT8 ((volatile avr_gpio_registers_t *)&PINH)
+#endif
+
+#if defined(PORTJ) || defined(__DOXYGEN__)
+/**
+ * @brief GPIO port J identifier.
+ */
+#define IOPORT9 ((volatile avr_gpio_registers_t *)&PINJ)
+#endif
+
+#if defined(PORTK) || defined(__DOXYGEN__)
+/**
+ * @brief GPIO port K identifier.
+ */
+#define IOPORT10 ((volatile avr_gpio_registers_t *)&PINK)
+#endif
+
+#if defined(PORTL) || defined(__DOXYGEN__)
+/**
+ * @brief GPIO port L identifier.
+ */
+#define IOPORT11 ((volatile avr_gpio_registers_t *)&PINL)
+#endif
+
/*===========================================================================*/
/* Implementation, some of the following macros could be implemented as */
/* functions, if so please put them in pal_lld.c. */
diff --git a/os/hal/platforms/AVR/serial_lld.c b/os/hal/platforms/AVR/serial_lld.c
index e070d5448..c35cdca4b 100644
--- a/os/hal/platforms/AVR/serial_lld.c
+++ b/os/hal/platforms/AVR/serial_lld.c
@@ -62,7 +62,7 @@ SerialDriver SD2;
*/
static const SerialConfig default_config = {
UBRR(SERIAL_DEFAULT_BITRATE),
- (1 << UCSZ1) | (1 << UCSZ0)
+ USART_CHAR_SIZE_8
};
/*===========================================================================*/
@@ -71,12 +71,31 @@ static const SerialConfig default_config = {
static void set_error(uint8_t sra, SerialDriver *sdp) {
chnflags_t sts = 0;
+ uint8_t dor = 0;
+ uint8_t upe = 0;
+ uint8_t fe = 0;
- if (sra & (1 << DOR))
+#if USE_AVR_USART0
+ if (&SD1 == sdp) {
+ dor = (1 << DOR0);
+ upe = (1 << UPE0);
+ fe = (1 << FE0);
+ }
+#endif
+
+#if USE_AVR_USART1
+ if (&SD2 == sdp) {
+ dor = (1 << DOR1);
+ upe = (1 << UPE1);
+ fe = (1 << FE1);
+ }
+#endif
+
+ if (sra & dor)
sts |= SD_OVERRUN_ERROR;
- if (sra & (1 << UPE))
+ if (sra & upe)
sts |= SD_PARITY_ERROR;
- if (sra & (1 << FE))
+ if (sra & fe)
sts |= SD_FRAMING_ERROR;
chSysLockFromIsr();
chnAddFlagsI(sdp, sts);
@@ -87,7 +106,7 @@ static void set_error(uint8_t sra, SerialDriver *sdp) {
static void notify1(GenericQueue *qp) {
(void)qp;
- UCSR0B |= (1 << UDRIE);
+ UCSR0B |= (1 << UDRIE0);
}
/**
@@ -100,8 +119,25 @@ static void usart0_init(const SerialConfig *config) {
UBRR0L = config->sc_brr;
UBRR0H = config->sc_brr >> 8;
UCSR0A = 0;
- UCSR0B = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
- UCSR0C = config->sc_csrc;
+ UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
+ switch (config->sc_bits_per_char) {
+ case USART_CHAR_SIZE_5:
+ UCSR0C = 0;
+ break;
+ case USART_CHAR_SIZE_6:
+ UCSR0C = (1 << UCSZ00);
+ break;
+ case USART_CHAR_SIZE_7:
+ UCSR0C = (1 << UCSZ01);
+ break;
+ case USART_CHAR_SIZE_9:
+ UCSR0B |= (1 << UCSZ02);
+ UCSR0C = (1 << UCSZ00) | (1 << UCSZ01);
+ break;
+ case USART_CHAR_SIZE_8:
+ default:
+ UCSR0C = (1 << UCSZ00) | (1 << UCSZ01);
+ }
}
/**
@@ -119,7 +155,7 @@ static void usart0_deinit(void) {
static void notify2(GenericQueue *qp) {
(void)qp;
- UCSR1B |= (1 << UDRIE);
+ UCSR1B |= (1 << UDRIE1);
}
/**
@@ -132,8 +168,25 @@ static void usart1_init(const SerialConfig *config) {
UBRR1L = config->sc_brr;
UBRR1H = config->sc_brr >> 8;
UCSR1A = 0;
- UCSR1B = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
- UCSR1C = config->sc_csrc;
+ UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1);
+ switch (config->sc_bits_per_char) {
+ case USART_CHAR_SIZE_5:
+ UCSR1C = 0;
+ break;
+ case USART_CHAR_SIZE_6:
+ UCSR1C = (1 << UCSZ10);
+ break;
+ case USART_CHAR_SIZE_7:
+ UCSR1C = (1 << UCSZ11);
+ break;
+ case USART_CHAR_SIZE_9:
+ UCSR1B |= (1 << UCSZ12);
+ UCSR1C = (1 << UCSZ10) | (1 << UCSZ11);
+ break;
+ case USART_CHAR_SIZE_8:
+ default:
+ UCSR1C = (1 << UCSZ10) | (1 << UCSZ11);
+ }
}
/**
@@ -163,7 +216,7 @@ CH_IRQ_HANDLER(USART0_RX_vect) {
CH_IRQ_PROLOGUE();
sra = UCSR0A;
- if (sra & ((1 << DOR) | (1 << UPE) | (1 << FE)))
+ if (sra & ((1 << DOR0) | (1 << UPE0) | (1 << FE0)))
set_error(sra, &SD1);
chSysLockFromIsr();
sdIncomingDataI(&SD1, UDR0);
@@ -186,7 +239,7 @@ CH_IRQ_HANDLER(USART0_UDRE_vect) {
b = sdRequestDataI(&SD1);
chSysUnlockFromIsr();
if (b < Q_OK)
- UCSR0B &= ~(1 << UDRIE);
+ UCSR0B &= ~(1 << UDRIE0);
else
UDR0 = b;
@@ -206,7 +259,7 @@ CH_IRQ_HANDLER(USART1_RX_vect) {
CH_IRQ_PROLOGUE();
sra = UCSR1A;
- if (sra & ((1 << DOR) | (1 << UPE) | (1 << FE)))
+ if (sra & ((1 << DOR1) | (1 << UPE1) | (1 << FE1)))
set_error(sra, &SD2);
chSysLockFromIsr();
sdIncomingDataI(&SD2, UDR1);
@@ -229,7 +282,7 @@ CH_IRQ_HANDLER(USART1_UDRE_vect) {
b = sdRequestDataI(&SD2);
chSysUnlockFromIsr();
if (b < Q_OK)
- UCSR1B &= ~(1 << UDRIE);
+ UCSR1B &= ~(1 << UDRIE1);
else
UDR1 = b;
diff --git a/os/hal/platforms/AVR/serial_lld.h b/os/hal/platforms/AVR/serial_lld.h
index f7bea9568..d6f893e74 100644
--- a/os/hal/platforms/AVR/serial_lld.h
+++ b/os/hal/platforms/AVR/serial_lld.h
@@ -76,9 +76,9 @@ typedef struct {
*/
uint16_t sc_brr;
/**
- * @brief Initialization value for the CSRC register.
+ * @brief Number of bits per character (USART_CHAR_SIZE_5 to USART_CHAR_SIZE_9).
*/
- uint8_t sc_csrc;
+ uint8_t sc_bits_per_char;
} SerialConfig;
/**
@@ -112,7 +112,7 @@ typedef struct {
* @brief Macro for baud rate computation when U2Xn == 1.
* @note Make sure the final baud rate is within tolerance.
*/
-#define UBRR2(b) (((F_CPU / b) >> 3) - 1)
+#define UBRR2x(b) (((F_CPU / b) >> 3) - 1)
/**
* @brief Macro for baud rate computation.
@@ -126,7 +126,13 @@ typedef struct {
* @note Make sure the final baud rate is within tolerance.
* @note This version uses floating point math for greater accuracy.
*/
-#define UBRR2_F(b) ((((double) F_CPU / (double) b) / 8.0) - 0.5)
+#define UBRR2x_F(b) ((((double) F_CPU / (double) b) / 8.0) - 0.5)
+
+#define USART_CHAR_SIZE_5 0
+#define USART_CHAR_SIZE_6 1
+#define USART_CHAR_SIZE_7 2
+#define USART_CHAR_SIZE_8 3
+#define USART_CHAR_SIZE_9 4
/*===========================================================================*/
/* External declarations. */