// --------------------------------------------------------------------------- void USART_IRQHandler(int ComPortNum, int Direction) { LPC_USART_T *usart = USART_REG(ComPortNum); char c; switch (Direction) { case 1: // Transmit if (USART_RemoveCharFromTxBuffer(ComPortNum, c)) { usart->THR = c; // Write data } else { CPU_USART_TxBufferEmptyInterruptEnable(ComPortNum, FALSE); // Disable interrupt } Events_Set(SYSTEM_EVENT_FLAG_COM_OUT); break; case 2: // Receive c = (char)(usart->RBR); // Read data USART_AddCharToRxBuffer(ComPortNum, c); Events_Set(SYSTEM_EVENT_FLAG_COM_IN); break; default: break; } }
void LPC22XX_USART_Driver::UART_IntHandler (void *param) { GLOBAL_LOCK(irq); ASSERT(LPC22XX_USART_Driver::IsValidPortNum((UINT32)param)); char c; UINT32 ComNum = (UINT32)param; UINT32 i,rxcnt; LPC22XX_USART& USARTC = LPC22XX::UART(ComNum); volatile UINT32 IIR_Value; volatile UINT32 LSR_Value; // Read data from Rx FIFO LSR_Value = USARTC.UART_LSR; while (LSR_Value & LPC22XX_USART::UART_LSR_RFDR) { UINT8 rxdata = (UINT8 )USARTC.SEL1.RBR.UART_RBR; rxcnt++; if ( 0 == (LSR_Value & ( LPC22XX_USART::UART_LSR_PEI | LPC22XX_USART::UART_LSR_OEI | LPC22XX_USART::UART_LSR_FEI ) ) ) { // No errors in Rx data USART_AddCharToRxBuffer(ComNum, rxdata); Events_Set( SYSTEM_EVENT_FLAG_COM_IN ); } LSR_Value = USARTC.UART_LSR; } // Send up to 2 bytes of Tx data for (i = 0; i <2; i++) { if (USART_RemoveCharFromTxBuffer( ComNum, c )) { WriteCharToTxBuffer( ComNum, c ); Events_Set( SYSTEM_EVENT_FLAG_COM_OUT ); } else { // Disable further TxBufferEmptyInterrupt. It will be // enabled by the PAL uart driver when a character to the // TxBuffer is added TxBufferEmptyInterruptEnable( ComNum, FALSE ); break; } } // Check if IIR read is required to clear the uart Rx interrupt IIR_Value = USARTC.SEL3.IIR.UART_IIR; }
void PXA271_USART_Driver::USART_ISR( void* param ) { // we lock since we are low priority and anyone might try to add a char in another ISR GLOBAL_LOCK(irq); UINT32 comPort = (UINT32)param; PXA271_USART& USART = PXA271::USART( comPort ); switch( USART.IIR & PXA271_USART::IIR__IID_MASK ) { case PXA271_USART::IIR__IID_RECEIVE_DATA: // If data in input FIFO // if the charger came in and turned off the serial port, bail now, as the source // will be going away if(c_RefFlagRx & g_PXA271_USART_Driver.m_RefFlags[comPort]) { if(USART.LSR & PXA271_USART::LSR__DR) { USART_AddCharToRxBuffer( comPort, (char)(USART.RBR & PXA271_USART::RBR__DATA_MASK8) ); Events_Set( SYSTEM_EVENT_FLAG_COM_IN ); } } break; case PXA271_USART::IIR__IID_TRANSMIT_FIFO: // If transmit FIFO can accept more characters // if the charger came in and turned off the serial port, bail now, as the source // will be going away if(c_RefFlagTx & g_PXA271_USART_Driver.m_RefFlags[comPort]) { char c; if(USART_RemoveCharFromTxBuffer( comPort, c )) { WriteCharToTxBuffer( comPort, c ); } else { // disable further Tx interrupts since we are level triggered TxBufferEmptyInterruptEnable( comPort, FALSE ); } Events_Set( SYSTEM_EVENT_FLAG_COM_OUT ); } break; #if defined(_DEBUG) case PXA271_USART::IIR__IID_RECEIVE_ERROR: // If there was an error receiving a character if(0 != (c_RefFlagRx & g_PXA271_USART_Driver.m_RefFlags[comPort])) { lcd_printf("\fLSR=%02x\r\n", USART.LSR & PXA271_USART::LSR__ERRORS); } break; #endif } }
void STM32F4_USART_Handle_RX_IRQ (int ComPortNum, USART_TypeDef* uart) { INTERRUPT_START; char c = (char)(uart->DR); // read RX data USART_AddCharToRxBuffer(ComPortNum, c); Events_Set(SYSTEM_EVENT_FLAG_COM_IN); INTERRUPT_END; }
void USART_RxISR( UINT32 port ) { char c; GLOBAL_LOCK(irq); volatile unsigned short* rxReg; volatile unsigned char* rxData; switch(port) { case 0: rxReg = &SCIF0.SCFSR.WORD; rxData = &SCIF0.SCFRDR; break; case 1: rxReg = &SCIF1.SCFSR.WORD; rxData = &SCIF1.SCFRDR; break; case 2: rxReg = &SCIF2.SCFSR.WORD; rxData = &SCIF2.SCFRDR; break; default: ASSERT(FALSE); return; } while((*rxReg) & 0x0002) { c = *rxData; *rxReg &= 0xFFFD; if(!USART_AddCharToRxBuffer(port, c)) { break; } Events_Set( SYSTEM_EVENT_FLAG_COM_IN ); } }
void LPC24XX_USART_Driver::UART_IntHandler (void *param) { GLOBAL_LOCK(irq); ASSERT(LPC24XX_USART_Driver::IsValidPortNum((UINT32)param)); char c; UINT32 ComNum = (UINT32)param; UINT32 i; UINT32 rxcnt=0; LPC24XX_USART& USARTC = LPC24XX::UART(ComNum); volatile UINT32 IIR_Value; volatile UINT32 LSR_Value; volatile register UINT32 * regRBR = &(USARTC.SEL1.RBR.UART_RBR); volatile register UINT32 * regLSR = &(USARTC.UART_LSR); IIR_Value = USARTC.SEL3.IIR.UART_IIR & LPC24XX_USART::UART_IIR_IID_mask; if (IIR_Value & LPC24XX_USART::UART_IIR_NIP) ASSERT(0); // Read data from Rx FIFO while (true) { LSR_Value = *regLSR ; if (LSR_Value & LPC24XX_USART::UART_LSR_RFDR) { volatile UINT8 rxdata = (UINT8 ) *regRBR; // No errors in Rx data USART_AddCharToRxBuffer(ComNum, rxdata); } else break; } // Send up to 2 bytes of Tx data for (i = 0; i <2; i++) { if (USART_RemoveCharFromTxBuffer( ComNum, c )) { WriteCharToTxBuffer( ComNum, c ); Events_Set( SYSTEM_EVENT_FLAG_COM_OUT ); } else { // Disable further TxBufferEmptyInterrupt. It will be // enabled by the PAL uart driver when a character to the // TxBuffer is added TxBufferEmptyInterruptEnable( ComNum, FALSE ); break; } } }
void USART_RxErrorISR( UINT32 port ) { GLOBAL_LOCK(irq); volatile unsigned char* rxReg; volatile unsigned char* rxData; CPU_USART_RxBufferFullInterruptEnable(port, FALSE); switch(port) { case 0: rxReg = &SCI0.SCSSR.BYTE; break; case 1: rxReg = &SCI1.SCSSR.BYTE; break; case 2: rxReg = &SCI2.SCSSR.BYTE; break; case 3: rxReg = &SCI4.SCSSR.BYTE; break; default: ASSERT(FALSE); return; } *rxReg &= 0x87; #if 0 USART_AddCharToRxBuffer(port, 'M'); USART_AddCharToRxBuffer(port, 'S'); USART_AddCharToRxBuffer(port, 'p'); USART_AddCharToRxBuffer(port, 'k'); USART_AddCharToRxBuffer(port, 't'); USART_AddCharToRxBuffer(port, 'V'); USART_AddCharToRxBuffer(port, '1'); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x5A); USART_AddCharToRxBuffer(port, 0x2D); USART_AddCharToRxBuffer(port, 0x41); USART_AddCharToRxBuffer(port, 0x79); USART_AddCharToRxBuffer(port, 0x94); USART_AddCharToRxBuffer(port, 0xB9); USART_AddCharToRxBuffer(port, 0x43); USART_AddCharToRxBuffer(port, 0xb7); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x3D); USART_AddCharToRxBuffer(port, 0x24); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x03); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x08); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x02); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); #endif CPU_USART_RxBufferFullInterruptEnable(port, TRUE); }
void USART_RxISR( UINT32 port ) { char c; static bool flag = true; GLOBAL_LOCK(irq); volatile unsigned char* rxReg; volatile unsigned char* rxData; CPU_USART_RxBufferFullInterruptEnable(port, FALSE); switch(port) { case 0: rxReg = &SCI0.SCSSR.BYTE; rxData = &SCI0.SCRDR; break; case 1: rxReg = &SCI1.SCSSR.BYTE; rxData = &SCI1.SCRDR; break; case 2: rxReg = &SCI2.SCSSR.BYTE; rxData = &SCI2.SCRDR; break; case 3: rxReg = &SCI4.SCSSR.BYTE; rxData = &SCI4.SCRDR; break; default: ASSERT(FALSE); return; } *rxReg &= 0xC7; while((*rxReg) & 0x40) { c = *rxData; *rxReg &= 0xBF; if(!USART_AddCharToRxBuffer(port, c)) { break; } #if 0 // Currently this the workaround if(flag) { USART_AddCharToRxBuffer(port, 'S'); USART_AddCharToRxBuffer(port, 'p'); USART_AddCharToRxBuffer(port, 'k'); USART_AddCharToRxBuffer(port, 't'); USART_AddCharToRxBuffer(port, 'V'); USART_AddCharToRxBuffer(port, '1'); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x5A); USART_AddCharToRxBuffer(port, 0x2D); USART_AddCharToRxBuffer(port, 0x41); USART_AddCharToRxBuffer(port, 0x79); USART_AddCharToRxBuffer(port, 0x94); USART_AddCharToRxBuffer(port, 0xB9); USART_AddCharToRxBuffer(port, 0x43); USART_AddCharToRxBuffer(port, 0xb7); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x3D); USART_AddCharToRxBuffer(port, 0x24); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x03); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x08); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x02); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); USART_AddCharToRxBuffer(port, 0x00); flag = false; } #endif } CPU_USART_RxBufferFullInterruptEnable(port, TRUE); }