Implemented transmission end event.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2693 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2011-01-30 16:18:24 +00:00
parent ae9a53c802
commit cee541cfa3
4 changed files with 29 additions and 12 deletions

View File

@ -35,15 +35,15 @@
/*===========================================================================*/ /*===========================================================================*/
/** @brief Parity error happened.*/ /** @brief Parity error happened.*/
#define SD_PARITY_ERROR 16 #define SD_PARITY_ERROR 32
/** @brief Framing error happened.*/ /** @brief Framing error happened.*/
#define SD_FRAMING_ERROR 32 #define SD_FRAMING_ERROR 64
/** @brief Overflow happened.*/ /** @brief Overflow happened.*/
#define SD_OVERRUN_ERROR 64 #define SD_OVERRUN_ERROR 128
/** @brief Noise on the line.*/ /** @brief Noise on the line.*/
#define SD_NOISE_ERROR 128 #define SD_NOISE_ERROR 256
/** @brief Break detected.*/ /** @brief Break detected.*/
#define SD_BREAK_DETECTED 256 #define SD_BREAK_DETECTED 512
/*===========================================================================*/ /*===========================================================================*/
/* Driver pre-compile time settings. */ /* Driver pre-compile time settings. */

View File

@ -140,8 +140,6 @@ static void set_error(SerialDriver *sdp, uint16_t sr) {
sts |= SD_FRAMING_ERROR; sts |= SD_FRAMING_ERROR;
if (sr & USART_SR_NE) if (sr & USART_SR_NE)
sts |= SD_NOISE_ERROR; sts |= SD_NOISE_ERROR;
if (sr & USART_SR_LBD)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr(); chSysLockFromIsr();
chIOAddFlagsI(sdp, sts); chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr(); chSysUnlockFromIsr();
@ -158,16 +156,23 @@ static void serve_interrupt(SerialDriver *sdp) {
uint16_t sr = u->SR; /* SR reset step 1.*/ uint16_t sr = u->SR; /* SR reset step 1.*/
uint16_t dr = u->DR; /* SR reset step 2.*/ uint16_t dr = u->DR; /* SR reset step 2.*/
if (sr & (USART_SR_LBD | USART_SR_ORE | USART_SR_NE | /* Error condition detection.*/
USART_SR_FE | USART_SR_PE)) { if (sr & (USART_SR_ORE | USART_SR_NE | USART_SR_FE | USART_SR_PE))
set_error(sdp, sr); set_error(sdp, sr);
u->SR = 0; /* Clears the LBD bit in the SR.*/ /* Special case, LIN break detection.*/
if (sr & USART_SR_LBD) {
chSysLockFromIsr();
chIOAddFlagsI(sdp, SD_BREAK_DETECTED);
chSysUnlockFromIsr();
u->SR &= ~USART_SR_LBD;
} }
/* Data available.*/
if (sr & USART_SR_RXNE) { if (sr & USART_SR_RXNE) {
chSysLockFromIsr(); chSysLockFromIsr();
sdIncomingDataI(sdp, (uint8_t)dr); sdIncomingDataI(sdp, (uint8_t)dr);
chSysUnlockFromIsr(); chSysUnlockFromIsr();
} }
/* Transmission buffer empty.*/
if ((cr1 & USART_CR1_TXEIE) && (sr & USART_SR_TXE)) { if ((cr1 & USART_CR1_TXEIE) && (sr & USART_SR_TXE)) {
msg_t b; msg_t b;
chSysLockFromIsr(); chSysLockFromIsr();
@ -180,6 +185,14 @@ static void serve_interrupt(SerialDriver *sdp) {
u->DR = b; u->DR = b;
chSysUnlockFromIsr(); chSysUnlockFromIsr();
} }
/* Physical transmission end.*/
if (sr & USART_SR_TC) {
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_TRANSMISSION_END);
chSysUnlockFromIsr();
u->CR1 = cr1 & ~USART_CR1_TCIE;
u->SR &= ~USART_SR_TC;
}
} }
#endif #endif
@ -187,7 +200,7 @@ static void serve_interrupt(SerialDriver *sdp) {
static void notify1(GenericQueue *qp) { static void notify1(GenericQueue *qp) {
(void)qp; (void)qp;
USART1->CR1 |= USART_CR1_TXEIE; USART1->CR1 |= USART_CR1_TXEIE | USART_CR1_TCIE;
} }
#endif #endif
@ -195,7 +208,7 @@ static void notify1(GenericQueue *qp) {
static void notify2(GenericQueue *qp) { static void notify2(GenericQueue *qp) {
(void)qp; (void)qp;
USART2->CR1 |= USART_CR1_TXEIE; USART2->CR1 |= USART_CR1_TXEIE | USART_CR1_TCIE;
} }
#endif #endif

View File

@ -239,6 +239,8 @@ typedef struct {
#define IO_INPUT_AVAILABLE 4 #define IO_INPUT_AVAILABLE 4
/** @brief Output queue empty.*/ /** @brief Output queue empty.*/
#define IO_OUTPUT_EMPTY 8 #define IO_OUTPUT_EMPTY 8
/** @brief Transmission end.*/
#define IO_TRANSMISSION_END 16
/** /**
* @brief Type of an I/O condition flags mask. * @brief Type of an I/O condition flags mask.

View File

@ -69,6 +69,8 @@
***************************************************************************** *****************************************************************************
*** 2.3.0 *** *** 2.3.0 ***
- NEW: Implemented new event IO_TRANSMISSION_END in the generic serial
driver. This event marks the physical transmission end of a data stream.
*** 2.1.8 *** *** 2.1.8 ***
- FIX: Fixed error in STM32 ADC driver macro names (bug 3160306)(backported - FIX: Fixed error in STM32 ADC driver macro names (bug 3160306)(backported