2009-11-29 08:50:13 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2012-01-21 14:29:42 +00:00
|
|
|
2011,2012 Giovanni Di Sirio.
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @file AT91SAM7/serial_lld.c
|
|
|
|
* @brief AT91SAM7 low level serial driver code.
|
|
|
|
*
|
2010-10-25 20:34:08 +00:00
|
|
|
* @addtogroup SERIAL
|
2009-11-29 08:50:13 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-11-29 13:37:19 +00:00
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2012-04-14 11:12:37 +00:00
|
|
|
#if (SAM7_PLATFORM == SAM7S64) || (SAM7_PLATFORM == SAM7S128) || \
|
|
|
|
(SAM7_PLATFORM == SAM7S256) || (SAM7_PLATFORM == SAM7S512)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
#define SAM7_USART0_RX AT91C_PA5_RXD0
|
|
|
|
#define SAM7_USART0_TX AT91C_PA6_TXD0
|
|
|
|
#define SAM7_USART1_RX AT91C_PA21_RXD1
|
|
|
|
#define SAM7_USART1_TX AT91C_PA22_TXD1
|
2010-04-24 21:16:10 +00:00
|
|
|
#define SAM7_DBGU_RX AT91C_PA9_DRXD
|
|
|
|
#define SAM7_DBGU_TX AT91C_PA10_DTXD
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2012-04-14 11:12:37 +00:00
|
|
|
#elif (SAM7_PLATFORM == SAM7X128) || (SAM7_PLATFORM == SAM7X256) || \
|
|
|
|
(SAM7_PLATFORM == SAM7X512)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
#define SAM7_USART0_RX AT91C_PA0_RXD0
|
|
|
|
#define SAM7_USART0_TX AT91C_PA1_TXD0
|
|
|
|
#define SAM7_USART1_RX AT91C_PA5_RXD1
|
|
|
|
#define SAM7_USART1_TX AT91C_PA6_TXD1
|
2010-04-24 21:16:10 +00:00
|
|
|
#define SAM7_DBGU_RX AT91C_PA27_DRXD
|
|
|
|
#define SAM7_DBGU_TX AT91C_PA28_DTXD
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#error "serial lines not defined for this SAM7 version"
|
|
|
|
#endif
|
|
|
|
|
2009-12-29 11:40:09 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
#if USE_SAM7_USART0 || defined(__DOXYGEN__)
|
|
|
|
/** @brief USART0 serial driver identifier.*/
|
|
|
|
SerialDriver SD1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_SAM7_USART1 || defined(__DOXYGEN__)
|
|
|
|
/** @brief USART1 serial driver identifier.*/
|
|
|
|
SerialDriver SD2;
|
|
|
|
#endif
|
|
|
|
|
2010-04-24 21:16:10 +00:00
|
|
|
#if USE_SAM7_DBGU_UART || defined(__DOXYGEN__)
|
|
|
|
/** @brief DBGU_UART serial driver identifier.*/
|
|
|
|
SerialDriver SD3;
|
|
|
|
#endif
|
|
|
|
|
2009-12-29 11:40:09 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/** @brief Driver default configuration.*/
|
2010-01-01 13:41:31 +00:00
|
|
|
static const SerialConfig default_config = {
|
2010-01-02 13:02:43 +00:00
|
|
|
SERIAL_DEFAULT_BITRATE,
|
2009-11-29 08:50:13 +00:00
|
|
|
AT91C_US_USMODE_NORMAL | AT91C_US_CLKS_CLOCK |
|
|
|
|
AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT
|
|
|
|
};
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2009-12-29 11:40:09 +00:00
|
|
|
/* Driver local functions. */
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief USART initialization.
|
2010-01-01 13:41:31 +00:00
|
|
|
*
|
2010-04-20 15:39:07 +00:00
|
|
|
* @param[in] sdp communication channel associated to the USART
|
|
|
|
* @param[in] config the architecture-dependent serial driver configuration
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-04-19 15:29:44 +00:00
|
|
|
static void usart_init(SerialDriver *sdp, const SerialConfig *config) {
|
2010-01-22 14:51:54 +00:00
|
|
|
AT91PS_USART u = sdp->usart;
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/* Disables IRQ sources and stop operations.*/
|
|
|
|
u->US_IDR = 0xFFFFFFFF;
|
|
|
|
u->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA;
|
|
|
|
|
|
|
|
/* New parameters setup.*/
|
2010-04-19 15:29:44 +00:00
|
|
|
if (config->sc_mr & AT91C_US_OVER)
|
|
|
|
u->US_BRGR = MCK / (config->sc_speed * 8);
|
2009-11-29 08:50:13 +00:00
|
|
|
else
|
2010-04-19 15:29:44 +00:00
|
|
|
u->US_BRGR = MCK / (config->sc_speed * 16);
|
|
|
|
u->US_MR = config->sc_mr;
|
2009-11-29 08:50:13 +00:00
|
|
|
u->US_RTOR = 0;
|
|
|
|
u->US_TTGR = 0;
|
|
|
|
|
|
|
|
/* Enables operations and IRQ sources.*/
|
|
|
|
u->US_CR = AT91C_US_RXEN | AT91C_US_TXEN | AT91C_US_DTREN | AT91C_US_RTSEN;
|
|
|
|
u->US_IER = AT91C_US_RXRDY | AT91C_US_OVRE | AT91C_US_FRAME | AT91C_US_PARE |
|
|
|
|
AT91C_US_RXBRK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief USART de-initialization.
|
|
|
|
*
|
|
|
|
* @param[in] u pointer to an USART I/O block
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
static void usart_deinit(AT91PS_USART u) {
|
|
|
|
|
|
|
|
/* Disables IRQ sources and stop operations.*/
|
|
|
|
u->US_IDR = 0xFFFFFFFF;
|
|
|
|
u->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA;
|
|
|
|
u->US_MR = 0;
|
|
|
|
u->US_RTOR = 0;
|
|
|
|
u->US_TTGR = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief Error handling routine.
|
|
|
|
*
|
|
|
|
* @param[in] err USART CSR register value
|
|
|
|
* @param[in] sdp communication channel associated to the USART
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-01-01 13:41:31 +00:00
|
|
|
static void set_error(SerialDriver *sdp, AT91_REG csr) {
|
2012-05-08 17:09:20 +00:00
|
|
|
chnflags_t sts = 0;
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
if (csr & AT91C_US_OVRE)
|
|
|
|
sts |= SD_OVERRUN_ERROR;
|
|
|
|
if (csr & AT91C_US_PARE)
|
|
|
|
sts |= SD_PARITY_ERROR;
|
|
|
|
if (csr & AT91C_US_FRAME)
|
|
|
|
sts |= SD_FRAMING_ERROR;
|
|
|
|
if (csr & AT91C_US_RXBRK)
|
|
|
|
sts |= SD_BREAK_DETECTED;
|
|
|
|
chSysLockFromIsr();
|
2012-05-08 17:09:20 +00:00
|
|
|
chnAddFlagsI(sdp, sts);
|
2009-11-29 08:50:13 +00:00
|
|
|
chSysUnlockFromIsr();
|
|
|
|
}
|
|
|
|
|
2010-10-16 17:23:07 +00:00
|
|
|
#if defined(__GNUC__)
|
2009-11-29 08:50:13 +00:00
|
|
|
__attribute__((noinline))
|
|
|
|
#endif
|
2010-04-24 21:16:10 +00:00
|
|
|
#if !USE_SAM7_DBGU_UART
|
|
|
|
static
|
|
|
|
#endif
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief Common IRQ handler.
|
2010-01-01 13:41:31 +00:00
|
|
|
*
|
2010-04-20 15:39:07 +00:00
|
|
|
* @param[in] sdp communication channel associated to the USART
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-04-24 21:16:10 +00:00
|
|
|
void sd_lld_serve_interrupt(SerialDriver *sdp) {
|
2010-01-01 13:41:31 +00:00
|
|
|
uint32_t csr;
|
2010-01-22 14:51:54 +00:00
|
|
|
AT91PS_USART u = sdp->usart;
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2010-01-01 13:41:31 +00:00
|
|
|
csr = u->US_CSR;
|
|
|
|
if (csr & AT91C_US_RXRDY) {
|
2009-11-29 08:50:13 +00:00
|
|
|
chSysLockFromIsr();
|
|
|
|
sdIncomingDataI(sdp, u->US_RHR);
|
|
|
|
chSysUnlockFromIsr();
|
|
|
|
}
|
2010-01-01 13:41:31 +00:00
|
|
|
if ((u->US_IMR & AT91C_US_TXRDY) && (csr & AT91C_US_TXRDY)) {
|
|
|
|
msg_t b;
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
chSysLockFromIsr();
|
2010-01-22 14:51:54 +00:00
|
|
|
b = chOQGetI(&sdp->oqueue);
|
2010-01-01 13:41:31 +00:00
|
|
|
if (b < Q_OK) {
|
2012-05-08 17:09:20 +00:00
|
|
|
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
|
2009-11-29 08:50:13 +00:00
|
|
|
u->US_IDR = AT91C_US_TXRDY;
|
2010-01-01 13:41:31 +00:00
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
else
|
|
|
|
u->US_THR = b;
|
2010-01-01 13:41:31 +00:00
|
|
|
chSysUnlockFromIsr();
|
2009-11-29 08:50:13 +00:00
|
|
|
}
|
2010-01-01 13:41:31 +00:00
|
|
|
csr &= (AT91C_US_OVRE | AT91C_US_FRAME | AT91C_US_PARE | AT91C_US_RXBRK);
|
|
|
|
if (csr != 0) {
|
|
|
|
set_error(sdp, csr);
|
2009-11-29 08:50:13 +00:00
|
|
|
u->US_CR = AT91C_US_RSTSTA;
|
|
|
|
}
|
|
|
|
AT91C_BASE_AIC->AIC_EOICR = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_SAM7_USART0 || defined(__DOXYGEN__)
|
2011-01-02 14:58:51 +00:00
|
|
|
static void notify1(GenericQueue *qp) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2011-01-02 14:58:51 +00:00
|
|
|
(void)qp;
|
2009-11-29 08:50:13 +00:00
|
|
|
AT91C_BASE_US0->US_IER = AT91C_US_TXRDY;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_SAM7_USART1 || defined(__DOXYGEN__)
|
2011-01-02 14:58:51 +00:00
|
|
|
static void notify2(GenericQueue *qp) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2011-01-02 14:58:51 +00:00
|
|
|
(void)qp;
|
2009-11-29 08:50:13 +00:00
|
|
|
AT91C_BASE_US1->US_IER = AT91C_US_TXRDY;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-24 21:16:10 +00:00
|
|
|
#if USE_SAM7_DBGU_UART || defined(__DOXYGEN__)
|
2011-01-02 14:58:51 +00:00
|
|
|
static void notify3(GenericQueue *qp) {
|
2010-04-24 21:16:10 +00:00
|
|
|
|
2011-01-02 14:58:51 +00:00
|
|
|
(void)qp;
|
2010-04-24 21:16:10 +00:00
|
|
|
AT91C_BASE_DBGU->DBGU_IER = AT91C_US_TXRDY;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
2009-12-29 11:40:09 +00:00
|
|
|
/* Driver interrupt handlers. */
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#if USE_SAM7_USART0 || defined(__DOXYGEN__)
|
2010-10-04 17:16:18 +00:00
|
|
|
/**
|
|
|
|
* @brief USART0 interrupt handler.
|
|
|
|
*
|
2011-03-18 18:38:08 +00:00
|
|
|
* @isr
|
2010-10-04 17:16:18 +00:00
|
|
|
*/
|
2009-11-29 08:50:13 +00:00
|
|
|
CH_IRQ_HANDLER(USART0IrqHandler) {
|
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
2010-04-24 21:16:10 +00:00
|
|
|
sd_lld_serve_interrupt(&SD1);
|
|
|
|
AT91C_BASE_AIC->AIC_EOICR = 0;
|
2009-11-29 08:50:13 +00:00
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_SAM7_USART1 || defined(__DOXYGEN__)
|
2010-10-04 17:16:18 +00:00
|
|
|
/**
|
|
|
|
* @brief USART1 interrupt handler.
|
|
|
|
*
|
|
|
|
* @isr
|
|
|
|
*/
|
2009-11-29 08:50:13 +00:00
|
|
|
CH_IRQ_HANDLER(USART1IrqHandler) {
|
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
2010-04-24 21:16:10 +00:00
|
|
|
sd_lld_serve_interrupt(&SD2);
|
|
|
|
AT91C_BASE_AIC->AIC_EOICR = 0;
|
2009-11-29 08:50:13 +00:00
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-10-17 19:40:36 +00:00
|
|
|
/* note - DBGU_UART IRQ is the SysIrq in board.c
|
|
|
|
since it's not vectored separately by the AIC.*/
|
2010-04-24 21:16:10 +00:00
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
2009-12-29 11:40:09 +00:00
|
|
|
/* Driver exported functions. */
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief Low level serial driver initialization.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
void sd_lld_init(void) {
|
|
|
|
|
|
|
|
#if USE_SAM7_USART0
|
|
|
|
sdObjectInit(&SD1, NULL, notify1);
|
2010-01-22 14:51:54 +00:00
|
|
|
SD1.usart = AT91C_BASE_US0;
|
2009-11-29 08:50:13 +00:00
|
|
|
AT91C_BASE_PIOA->PIO_PDR = SAM7_USART0_RX | SAM7_USART0_TX;
|
|
|
|
AT91C_BASE_PIOA->PIO_ASR = SAM7_USART0_RX | SAM7_USART0_TX;
|
|
|
|
AT91C_BASE_PIOA->PIO_PPUDR = SAM7_USART0_RX | SAM7_USART0_TX;
|
|
|
|
AIC_ConfigureIT(AT91C_ID_US0,
|
|
|
|
AT91C_AIC_SRCTYPE_HIGH_LEVEL | SAM7_USART0_PRIORITY,
|
|
|
|
USART0IrqHandler);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_SAM7_USART1
|
|
|
|
sdObjectInit(&SD2, NULL, notify2);
|
2010-01-22 14:51:54 +00:00
|
|
|
SD2.usart = AT91C_BASE_US1;
|
2009-11-29 08:50:13 +00:00
|
|
|
AT91C_BASE_PIOA->PIO_PDR = SAM7_USART1_RX | SAM7_USART1_TX;
|
|
|
|
AT91C_BASE_PIOA->PIO_ASR = SAM7_USART1_RX | SAM7_USART1_TX;
|
|
|
|
AT91C_BASE_PIOA->PIO_PPUDR = SAM7_USART1_RX | SAM7_USART1_TX;
|
|
|
|
AIC_ConfigureIT(AT91C_ID_US1,
|
|
|
|
AT91C_AIC_SRCTYPE_HIGH_LEVEL | SAM7_USART1_PRIORITY,
|
|
|
|
USART1IrqHandler);
|
|
|
|
#endif
|
2010-04-24 21:16:10 +00:00
|
|
|
|
|
|
|
#if USE_SAM7_DBGU_UART
|
|
|
|
sdObjectInit(&SD3, NULL, notify3);
|
2010-10-17 19:40:36 +00:00
|
|
|
/* 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.*/
|
2010-04-24 21:16:10 +00:00
|
|
|
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
|
2009-11-29 08:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief Low level serial driver configuration and (re)start.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2010-04-20 15:39:07 +00:00
|
|
|
* @param[in] sdp pointer to a @p SerialDriver object
|
|
|
|
* @param[in] config the architecture-dependent serial driver configuration.
|
|
|
|
* If this parameter is set to @p NULL then a default
|
|
|
|
* configuration is used.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-04-19 15:29:44 +00:00
|
|
|
void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2010-04-19 15:29:44 +00:00
|
|
|
if (config == NULL)
|
|
|
|
config = &default_config;
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2010-01-22 14:51:54 +00:00
|
|
|
if (sdp->state == SD_STOP) {
|
2009-11-29 08:50:13 +00:00
|
|
|
#if USE_SAM7_USART0
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD1 == sdp) {
|
|
|
|
/* Starts the clock and clears possible sources of immediate interrupts.*/
|
|
|
|
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US0);
|
|
|
|
/* Enables associated interrupt vector.*/
|
|
|
|
AIC_EnableIT(AT91C_ID_US0);
|
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
|
|
|
#if USE_SAM7_USART1
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD2 == sdp) {
|
|
|
|
/* Starts the clock and clears possible sources of immediate interrupts.*/
|
|
|
|
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US1);
|
|
|
|
/* Enables associated interrupt vector.*/
|
|
|
|
AIC_EnableIT(AT91C_ID_US1);
|
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
2011-03-18 18:38:08 +00:00
|
|
|
/* Note - no explicit start for SD3 (DBGU_UART) since it's not included
|
2010-10-17 19:40:36 +00:00
|
|
|
in the AIC or PMC.*/
|
2010-01-01 13:41:31 +00:00
|
|
|
}
|
2010-04-19 15:29:44 +00:00
|
|
|
usart_init(sdp, config);
|
2009-11-29 08:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief Low level serial driver stop.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details De-initializes the USART, stops the associated clock, resets the
|
|
|
|
* interrupt vector.
|
|
|
|
*
|
2010-04-20 15:39:07 +00:00
|
|
|
* @param[in] sdp pointer to a @p SerialDriver object
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
void sd_lld_stop(SerialDriver *sdp) {
|
|
|
|
|
2010-01-22 14:51:54 +00:00
|
|
|
if (sdp->state == SD_READY) {
|
|
|
|
usart_deinit(sdp->usart);
|
2009-11-29 08:50:13 +00:00
|
|
|
#if USE_SAM7_USART0
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD1 == sdp) {
|
|
|
|
AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_US0);
|
|
|
|
AIC_DisableIT(AT91C_ID_US0);
|
|
|
|
return;
|
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
|
|
|
#if USE_SAM7_USART1
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD2 == sdp) {
|
|
|
|
AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_US1);
|
|
|
|
AIC_DisableIT(AT91C_ID_US1);
|
|
|
|
return;
|
|
|
|
}
|
2010-04-24 21:16:10 +00:00
|
|
|
#endif
|
|
|
|
#if USE_SAM7_DBGU_UART
|
|
|
|
if (&SD3 == sdp) {
|
|
|
|
AT91C_BASE_DBGU->DBGU_IDR = 0xFFFFFFFF;
|
|
|
|
return;
|
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
2010-01-01 13:41:31 +00:00
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#endif /* HAL_USE_SERIAL */
|
2009-11-29 13:37:19 +00:00
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/** @} */
|