aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/AVR-AT90CANx-GCC/board.c2
-rw-r--r--demos/AVR-ATmega128-GCC/board.c2
-rw-r--r--ports/AVR/avr_serial.c63
-rw-r--r--ports/AVR/avr_serial.h63
-rw-r--r--ports/AVR/port.dox20
5 files changed, 115 insertions, 35 deletions
diff --git a/demos/AVR-AT90CANx-GCC/board.c b/demos/AVR-AT90CANx-GCC/board.c
index 96b6c7e53..3119b82be 100644
--- a/demos/AVR-AT90CANx-GCC/board.c
+++ b/demos/AVR-AT90CANx-GCC/board.c
@@ -82,5 +82,5 @@ void hwinit(void) {
/*
* Other initializations.
*/
- InitSerial();
+ serial_init();
}
diff --git a/demos/AVR-ATmega128-GCC/board.c b/demos/AVR-ATmega128-GCC/board.c
index 0a6201eed..490dd0362 100644
--- a/demos/AVR-ATmega128-GCC/board.c
+++ b/demos/AVR-ATmega128-GCC/board.c
@@ -82,5 +82,5 @@ void hwinit(void) {
/*
* Other initializations.
*/
- InitSerial();
+ serial_init();
}
diff --git a/ports/AVR/avr_serial.c b/ports/AVR/avr_serial.c
index c9e2b0b10..b69a43213 100644
--- a/ports/AVR/avr_serial.c
+++ b/ports/AVR/avr_serial.c
@@ -17,6 +17,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * @file ports/AVR/avr_serial.c
+ * @brief AVR Serial driver code.
+ * @addtogroup AVR_SERIAL
+ * @{
+ */
+
#include <ch.h>
#include "avr_serial.h"
@@ -35,8 +42,10 @@ static void SetError(uint8_t sra, FullDuplexDriver *com) {
chSysUnlockFromIsr();
}
-#ifdef USE_AVR_USART0
+#if USE_AVR_USART0 || defined(__DOXYGEN__)
+/** @brief USART0 serial driver identifier.*/
FullDuplexDriver SER1;
+
static uint8_t ib1[SERIAL_BUFFERS_SIZE];
static uint8_t ob1[SERIAL_BUFFERS_SIZE];
@@ -71,20 +80,20 @@ CH_IRQ_HANDLER(USART0_UDRE_vect) {
CH_IRQ_EPILOGUE();
}
-/*
- * Invoked by the high driver when one or more bytes are inserted in the
- * output queue.
- */
static void OutNotify1(void) {
UCSR0B |= (1 << UDRIE);
}
-/*
- * USART setup, must be invoked with interrupts disabled.
- * NOTE: Does not reset I/O queues.
+/**
+ * @brief USART0 setup.
+ * @details This function must be invoked with interrupts disabled.
+ * @param[in] brr the divider value as calculated by the @p UBRR() macro
+ * @param[in] csrc the value for the @p UCSR0C register
+ * @note Must be invoked with interrupts disabled.
+ * @note Does not reset the I/O queues.
*/
-void SetUSART0I(uint16_t brr, uint8_t csrc) {
+void usart0_setup(uint16_t brr, uint8_t csrc) {
UBRR0L = brr;
UBRR0H = brr >> 8;
@@ -94,8 +103,10 @@ void SetUSART0I(uint16_t brr, uint8_t csrc) {
}
#endif /* USE_AVR_USART0 */
-#ifdef USE_AVR_USART1
+#if USE_AVR_USART1 || defined(__DOXYGEN__)
+/** @brief USART1 serial driver identifier.*/
FullDuplexDriver SER2;
+
static uint8_t ib2[SERIAL_BUFFERS_SIZE];
static uint8_t ob2[SERIAL_BUFFERS_SIZE];
@@ -130,20 +141,20 @@ CH_IRQ_HANDLER(USART1_UDRE_vect) {
CH_IRQ_EPILOGUE();
}
-/*
- * Invoked by the high driver when one or more bytes are inserted in the
- * output queue.
- */
static void OutNotify2(void) {
UCSR1B |= (1 << UDRIE);
}
-/*
- * USART setup, must be invoked with interrupts disabled.
- * NOTE: Does not reset I/O queues.
+/**
+ * @brief USART1 setup.
+ * @details This function must be invoked with interrupts disabled.
+ * @param[in] brr the divider value as calculated by the @p UBRR() macro
+ * @param[in] csrc the value for the @p UCSR1C register
+ * @note Must be invoked with interrupts disabled.
+ * @note Does not reset the I/O queues.
*/
-void SetUSART1(uint16_t brr, uint8_t csrc) {
+void usart1_setup(uint16_t brr, uint8_t csrc) {
UBRR1L = brr;
UBRR1H = brr >> 8;
@@ -153,16 +164,22 @@ void SetUSART1(uint16_t brr, uint8_t csrc) {
}
#endif /* USE_AVR_USART1 */
-void InitSerial(void) {
+/**
+ * @brief Serial driver initialization.
+ * @note The serial ports are initialized at @p 38400-8-N-1 by default.
+ */
+void serial_init(void) {
-#ifdef USE_AVR_USART0
+#if USE_AVR_USART0
/* I/O queues setup.*/
chFDDInit(&SER1, ib1, sizeof ib1, NULL, ob1, sizeof ob1, OutNotify1);
- SetUSART0(UBRR(38400), (1 << UCSZ1) | (1 << UCSZ0));
+ usart0_setup(UBRR(DEFAULT_USART_BITRATE), (1 << UCSZ1) | (1 << UCSZ0));
#endif
-#ifdef USE_AVR_USART1
+#if USE_AVR_USART1
chFDDInit(&SER2, ib2, sizeof ib2, NULL, ob2, sizeof ob2, OutNotify2);
- SetUSART1(UBRR(38400), (1 << UCSZ1) | (1 << UCSZ0));
+ usart1_setup(UBRR(DEFAULT_USART_BITRATE), (1 << UCSZ1) | (1 << UCSZ0));
#endif
}
+
+/** @} */
diff --git a/ports/AVR/avr_serial.h b/ports/AVR/avr_serial.h
index 555dae522..3b87ff938 100644
--- a/ports/AVR/avr_serial.h
+++ b/ports/AVR/avr_serial.h
@@ -17,33 +17,76 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * @file ports/AVR/avr_serial.h
+ * @brief AVR Serial driver macros and structures.
+ * @addtogroup AVR_SERIAL
+ * @{
+ */
+
#ifndef _AVR_SERIAL_H_
#define _AVR_SERIAL_H_
-/*
- * Configuration parameter, you can change the depth of the queue buffers
- * depending on the requirements of your application.
+/**
+ * @brief Serial buffers size.
+ * @details Configuration parameter, you can change the depth of the queue
+ * buffers depending on the requirements of your application.
+ * @note The default is 32 bytes for both the transmission and receive buffers.
*/
+#ifndef SERIAL_BUFFERS_SIZE
#define SERIAL_BUFFERS_SIZE 32
+#endif
-//#define USE_AVR_USART0
-#define USE_AVR_USART1
+/**
+ * @brief Default bit rate.
+ * @details Configuration parameter, at startup the UARTs are configured at
+ * this speed.
+ * @note It is possible to use @p SetUART() in order to change the working
+ * parameters at runtime.
+ */
+#if !defined(DEFAULT_USART_BITRATE) || defined(__DOXYGEN__)
+#define DEFAULT_USART_BITRATE 38400
+#endif
-/*
- * Macro for baud rate computation.
+
+/**
+ * @brief USART0 driver enable switch.
+ * @details If set to @p TRUE the support for USART0 is included.
+ * @note The default is @p FALSE.
+ */
+#if !defined(USE_AVR_USART0) || defined(__DOXYGEN__)
+#define USE_AVR_USART0 FALSE
+#endif
+
+/**
+ * @brief USART1 driver enable switch.
+ * @details If set to @p TRUE the support for USART1 is included.
+ * @note The default is @p TRUE.
+ */
+#if !defined(USE_AVR_USART1) || defined(__DOXYGEN__)
+#define USE_AVR_USART1 TRUE
+#endif
+
+/**
+ * @brief Macro for baud rate computation.
+ * @note Make sure the final baud rate is within tolerance.
*/
#define UBRR(b) ((F_CPU / (b << 4)) - 1)
#ifdef __cplusplus
extern "C" {
#endif
- void InitSerial(void);
- void SetUSART0(uint16_t brr, uint8_t csrc);
- void SetUSART1(uint16_t brr, uint8_t csrc);
+ void serial_init(void);
+ void usart0_setup(uint16_t brr, uint8_t csrc);
+ void usart1_setup(uint16_t brr, uint8_t csrc);
#ifdef __cplusplus
}
#endif
+/** @cond never*/
extern FullDuplexDriver SER1, SER2;
+/** @endcond*/
#endif /* _AVR_SERIAL_H_ */
+
+/** @} */
diff --git a/ports/AVR/port.dox b/ports/AVR/port.dox
index 817da5a64..8634db686 100644
--- a/ports/AVR/port.dox
+++ b/ports/AVR/port.dox
@@ -64,3 +64,23 @@
* @file ports/AVR/chcore.c Port related code.
*/
/** @} */
+
+/**
+ * @defgroup AVR_DRIVERS AVR Drivers
+ * @{
+ * @brief Device drivers included in the AVR support.
+ *
+ * @ingroup AVR
+ */
+/** @} */
+
+/**
+ * @defgroup AVR_SERIAL USART Support
+ * @{
+ * @brief USART support.
+ * @details The serial driver supports both the AVR USARTs in asynchronous
+ * mode.
+ *
+ * @ingroup AVR_DRIVERS
+ */
+/** @} */