git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@262 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2008-04-13 10:53:48 +00:00
parent 18030639fb
commit 9e2c8595c8
3 changed files with 35 additions and 12 deletions

View File

@ -51,7 +51,7 @@ static void SetError(AT91_REG csr, FullDuplexDriver *com) {
static void ServeInterrupt(AT91PS_USART u, FullDuplexDriver *com) {
if (u->US_CSR & AT91C_US_RXRDY)
chFDDIncomingDataI(com, u->US_RHR);
chFDDIncomingDataI(com, u->US_RHR);
if (u->US_CSR & AT91C_US_TXRDY) {
msg_t b = chFDDRequestDataI(com);
if (b < Q_OK)

View File

@ -51,10 +51,30 @@ static void SetError(uint16_t sr, FullDuplexDriver *com) {
sts |= SD_FRAMING_ERROR;
if (sr & SR_LBD)
sts |= SD_BREAK_DETECTED;
chSysLock();
chFDDAddFlagsI(com, sts);
chSysUnlock();
}
static void ServeInterrupt(USART_TypeDef *u, FullDuplexDriver *com) {
uint16_t sr = u->SR;
if (sr & (SR_ORE | SR_FE | SR_PE | SR_LBD))
SetError(sr, com);
if (sr & SR_RXNE) {
chSysLock();
chFDDIncomingDataI(com, u->DR);
chSysUnlock();
}
if (sr & SR_TXE) {
chSysLock();
msg_t b = chFDDRequestDataI(com);
chSysUnlock();
if (b < Q_OK)
u->CR1 &= ~CR1_TXEIE;
else
u->DR = b;
}
}
#ifdef USE_USART1
@ -150,15 +170,18 @@ void SetUSARTI(USART_TypeDef *u, uint32_t speed, uint16_t cr1,
*/
void InitSerial(uint32_t prio1, uint32_t prio2, uint32_t prio3) {
/* I/O queues setup.*/
#ifdef USE_USART1
chFDDInit(&COM1, ib1, sizeof ib1, NULL, ob1, sizeof ob1, OutNotify1);
#endif
#ifdef USE_USART2
chFDDInit(&COM2, ib2, sizeof ib2, NULL, ob2, sizeof ob2, OutNotify2);
#endif
#ifdef USE_USART3
chFDDInit(&COM3, ib3, sizeof ib3, NULL, ob3, sizeof ob3, OutNotify3);
SetUSARTI(USART1, 38400, 0, CR2_STOP1_BITS | CR2_LINEN, 0);
#endif
#ifdef USE_USART2
chFDDInit(&COM2, ib2, sizeof ib2, NULL, ob2, sizeof ob2, OutNotify2);
SetUSARTI(USART2, 38400, 0, CR2_STOP1_BITS | CR2_LINEN, 0);
#endif
#ifdef USE_USART3
chFDDInit(&COM3, ib3, sizeof ib3, NULL, ob3, sizeof ob3, OutNotify3);
SetUSARTI(USART3, 38400, 0, CR2_STOP1_BITS | CR2_LINEN, 0);
#endif
}

View File

@ -67,10 +67,10 @@
#define CR2_CPOL (1 << 10)
#define CR2_CLKEN (1 << 11)
#define CR2_STOP_MASK (3 << 12)
#define CR2_STOP1_BITS (0 << 12
#define CR2_STOP0P5_BITS (1 << 12
#define CR2_STOP2_BITS (2 << 12
#define CR2_STOP1P5_BITS (3 << 12
#define CR2_STOP1_BITS (0 << 12)
#define CR2_STOP0P5_BITS (1 << 12)
#define CR2_STOP2_BITS (2 << 12)
#define CR2_STOP1P5_BITS (3 << 12)
#define CR2_LINEN (1 << 14)
#define CR3_EIE (1 << 0)