aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/AT91SAM7/serial_lld.c
diff options
context:
space:
mode:
authorliamstask <liamstask@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-04-24 21:16:10 +0000
committerliamstask <liamstask@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-04-24 21:16:10 +0000
commit9da7f0b661c0f776a14d9f69295f23ed486de584 (patch)
treeba226a3f5043f584063866b7f6b77e30d8275bdc /os/hal/platforms/AT91SAM7/serial_lld.c
parent2ccc6ff2927737d88d2df025fa5ca120f09b11d1 (diff)
downloadChibiOS-9da7f0b661c0f776a14d9f69295f23ed486de584.tar.gz
ChibiOS-9da7f0b661c0f776a14d9f69295f23ed486de584.tar.bz2
ChibiOS-9da7f0b661c0f776a14d9f69295f23ed486de584.zip
* add serial support for the AT91SAM7 DBGU peripheral
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1888 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms/AT91SAM7/serial_lld.c')
-rw-r--r--os/hal/platforms/AT91SAM7/serial_lld.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/os/hal/platforms/AT91SAM7/serial_lld.c b/os/hal/platforms/AT91SAM7/serial_lld.c
index 4e0e74c23..39e6540d4 100644
--- a/os/hal/platforms/AT91SAM7/serial_lld.c
+++ b/os/hal/platforms/AT91SAM7/serial_lld.c
@@ -36,6 +36,8 @@
#define SAM7_USART0_TX AT91C_PA6_TXD0
#define SAM7_USART1_RX AT91C_PA21_RXD1
#define SAM7_USART1_TX AT91C_PA22_TXD1
+#define SAM7_DBGU_RX AT91C_PA9_DRXD
+#define SAM7_DBGU_TX AT91C_PA10_DTXD
#elif SAM7_PLATFORM == SAM7X256
@@ -43,6 +45,8 @@
#define SAM7_USART0_TX AT91C_PA1_TXD0
#define SAM7_USART1_RX AT91C_PA5_RXD1
#define SAM7_USART1_TX AT91C_PA6_TXD1
+#define SAM7_DBGU_RX AT91C_PA27_DRXD
+#define SAM7_DBGU_TX AT91C_PA28_DTXD
#else
#error "serial lines not defined for this SAM7 version"
@@ -62,6 +66,11 @@ SerialDriver SD1;
SerialDriver SD2;
#endif
+#if USE_SAM7_DBGU_UART || defined(__DOXYGEN__)
+/** @brief DBGU_UART serial driver identifier.*/
+SerialDriver SD3;
+#endif
+
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
@@ -145,12 +154,15 @@ static void set_error(SerialDriver *sdp, AT91_REG csr) {
#if defined(__GNU__)
__attribute__((noinline))
#endif
+#if !USE_SAM7_DBGU_UART
+static
+#endif
/**
* @brief Common IRQ handler.
*
* @param[in] sdp communication channel associated to the USART
*/
-static void serve_interrupt(SerialDriver *sdp) {
+void sd_lld_serve_interrupt(SerialDriver *sdp) {
uint32_t csr;
AT91PS_USART u = sdp->usart;
@@ -195,6 +207,13 @@ static void notify2(void) {
}
#endif
+#if USE_SAM7_DBGU_UART || defined(__DOXYGEN__)
+static void notify3(void) {
+
+ AT91C_BASE_DBGU->DBGU_IER = AT91C_US_TXRDY;
+}
+#endif
+
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
@@ -203,9 +222,8 @@ static void notify2(void) {
CH_IRQ_HANDLER(USART0IrqHandler) {
CH_IRQ_PROLOGUE();
-
- serve_interrupt(&SD1);
-
+ sd_lld_serve_interrupt(&SD1);
+ AT91C_BASE_AIC->AIC_EOICR = 0;
CH_IRQ_EPILOGUE();
}
#endif
@@ -214,13 +232,15 @@ CH_IRQ_HANDLER(USART0IrqHandler) {
CH_IRQ_HANDLER(USART1IrqHandler) {
CH_IRQ_PROLOGUE();
-
- serve_interrupt(&SD2);
-
+ sd_lld_serve_interrupt(&SD2);
+ AT91C_BASE_AIC->AIC_EOICR = 0;
CH_IRQ_EPILOGUE();
}
#endif
+// note - DBGU_UART IRQ is the SysIrq in board.c
+// since it's not vectored separately by the AIC
+
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
@@ -251,6 +271,17 @@ void sd_lld_init(void) {
AT91C_AIC_SRCTYPE_HIGH_LEVEL | SAM7_USART1_PRIORITY,
USART1IrqHandler);
#endif
+
+#if USE_SAM7_DBGU_UART
+ sdObjectInit(&SD3, NULL, notify3);
+ // this is a little cheap, but OK for now since there's enough overlap
+ // between dbgu and usart register maps. it means we can reuse all the
+ // same usart interrupt handling and config that already exists
+ SD3.usart = (AT91PS_USART)AT91C_BASE_DBGU;
+ AT91C_BASE_PIOA->PIO_PDR = SAM7_DBGU_RX | SAM7_DBGU_TX;
+ AT91C_BASE_PIOA->PIO_ASR = SAM7_DBGU_RX | SAM7_DBGU_TX;
+ AT91C_BASE_PIOA->PIO_PPUDR = SAM7_DBGU_RX | SAM7_DBGU_TX;
+#endif
}
/**
@@ -283,6 +314,7 @@ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
AIC_EnableIT(AT91C_ID_US1);
}
#endif
+ // note - no explicit start for SD3 (DBGU_UART) since it's not included in the AIC or PMC
}
usart_init(sdp, config);
}
@@ -312,6 +344,12 @@ void sd_lld_stop(SerialDriver *sdp) {
return;
}
#endif
+#if USE_SAM7_DBGU_UART
+ if (&SD3 == sdp) {
+ AT91C_BASE_DBGU->DBGU_IDR = 0xFFFFFFFF;
+ return;
+ }
+#endif
}
}