aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-02-07 10:16:14 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-02-07 10:16:14 +0000
commitaaf826b161d38f5d2139d64b6d18898dbc902b19 (patch)
tree923d06b7fd473d60434eadbb66f9540b38fe469c
parentd5f443f74d551831ef4f93c043f70b53d9b1008b (diff)
downloadChibiOS-aaf826b161d38f5d2139d64b6d18898dbc902b19.tar.gz
ChibiOS-aaf826b161d38f5d2139d64b6d18898dbc902b19.tar.bz2
ChibiOS-aaf826b161d38f5d2139d64b6d18898dbc902b19.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@733 35acf78f-673a-0410-8e92-d51de3d6d3f4
-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
+ */
+/** @} */
3'>583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
The GNU General Public License, Version 3, 29 June 2007 (GPLv3)
===============================================================

> Copyright &copy; 2007
> Free Software Foundation, Inc.
> <<http://fsf.org/>>

Everyone is permitted to copy and distribute verbatim copies of this license
document, but changing it is not allowed.


Preamble
--------

The GNU General Public License is a free, copyleft license for software and
other kinds of works.

The licenses for most software and other practical works are designed to take
away your freedom to share and change the works. By contrast, the GNU General
Public License is intended to guarantee your freedom to share and change all
versions of a program--to make sure it remains free software for all its users.
We, the Free Software Foundation, use the GNU General Public License for most of
our software; it applies also to any other work released this way by its
authors. You can apply it to your programs, too.

When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the freedom to
distribute copies of free software (and charge for them if you wish), that you
receive source code or can get it if you want it, that you can change the
software or use pieces of it in new free programs, and that you know you can do
these things.

To protect your rights, we need to prevent others from denying you these rights
or asking you to surrender the rights. Therefore, you have certain
responsibilities if you distribute copies of the software, or if you modify it:
responsibilities to respect the freedom of others.

For example, if you distribute copies of such a program, whether gratis or for a
fee, you must pass on to the recipients the same freedoms that you received. You
must make sure that they, too, receive or can get the source code. And you must
show them these terms so they know their rights.

Developers that use the GNU GPL protect your rights with two steps: (1) assert
copyright on the software, and (2) offer you this License giving you legal
permission to copy, distribute and/or modify it.

For the developers' and authors' protection, the GPL clearly explains that there
is no warranty for this free software. For both users' and authors' sake, the
GPL requires that modified versions be marked as changed, so that their problems
will not be attributed erroneously to authors of previous versions.

Some devices are designed to deny users access to install or run modified
versions of the software inside them, although the manufacturer can do so. This
is fundamentally incompatible with the aim of protecting users' freedom to