void serial_putc(serial_t *obj, int c) { #ifdef CONFIG_MBED_ENABLED if (obj->index == UART_3) { log_uart_putc(&stdio_uart_log, (char)c); // UnMask LOG_UART TX FIFO empty IRQ if (serial_log_irq_en & SERIAL_TX_IRQ_EN) { log_uart_t *log_obj = &stdio_uart_log; HAL_LOG_UART_ADAPTER *pUartAdapter=(PHAL_LOG_UART_ADAPTER)&(log_obj->log_hal_uart); pUartAdapter->IntEnReg |= IER_ETBEI; HalLogUartSetIntEn(pUartAdapter); } return; } #endif PHAL_RUART_ADAPTER pHalRuartAdapter=(PHAL_RUART_ADAPTER)&(obj->hal_uart_adp); u8 uart_idx = pHalRuartAdapter->UartIndex; while (!serial_writable(obj)); HAL_RUART_WRITE32(uart_idx, RUART_TRAN_HOLD_REG_OFF, (c & 0xFF)); if (serial_irq_en[uart_idx] & SERIAL_TX_IRQ_EN) { // UnMask TX FIFO empty IRQ pHalRuartAdapter->Interrupts |= RUART_IER_ETBEI; HalRuartSetIMRRtl8195a (pHalRuartAdapter); } }
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) { #ifdef CONFIG_MBED_ENABLED if (obj->index == UART_3) { if (irq == RxIrq) { log_uart_irq_set(&stdio_uart_log, IIR_RX_RDY, enable); } else { log_uart_irq_set(&stdio_uart_log, IIR_THR_EMPTY, enable); } return; } #endif PHAL_RUART_ADAPTER pHalRuartAdapter; PHAL_RUART_OP pHalRuartOp; u8 uart_idx; pHalRuartAdapter = &(obj->hal_uart_adp); pHalRuartOp = &(obj->hal_uart_op); uart_idx = pHalRuartAdapter->UartIndex; if (enable) { if (irq == RxIrq) { pHalRuartAdapter->Interrupts |= RUART_IER_ERBI | RUART_IER_ELSI; serial_irq_en[uart_idx] |= SERIAL_RX_IRQ_EN; HalRuartSetIMRRtl8195a (pHalRuartAdapter); } else { serial_irq_en[uart_idx] |= SERIAL_TX_IRQ_EN; } pHalRuartOp->HalRuartRegIrq(pHalRuartAdapter); //log_uart pHalRuartOp->HalRuartIntEnable(pHalRuartAdapter); } else { // disable if (irq == RxIrq) { pHalRuartAdapter->Interrupts &= ~(RUART_IER_ERBI | RUART_IER_ELSI); serial_irq_en[uart_idx] &= ~SERIAL_RX_IRQ_EN; } else { pHalRuartAdapter->Interrupts &= ~RUART_IER_ETBEI; serial_irq_en[uart_idx] &= ~SERIAL_TX_IRQ_EN; } HalRuartSetIMRRtl8195a (pHalRuartAdapter); if (pHalRuartAdapter->Interrupts == 0) { InterruptUnRegister(&pHalRuartAdapter->IrqHandle); InterruptDis(&pHalRuartAdapter->IrqHandle); } } }
/****************************************************************************** * INTERRUPTS HANDLING ******************************************************************************/ static void SerialTxDoneCallBack(VOID *pAdapter) { PHAL_RUART_ADAPTER pHalRuartAdapter = pAdapter; u8 uart_idx = pHalRuartAdapter->UartIndex; // Mask UART TX FIFO empty pHalRuartAdapter->Interrupts &= ~RUART_IER_ETBEI; HalRuartSetIMRRtl8195a (pHalRuartAdapter); if (irq_handler[uart_idx] != NULL) { irq_handler[uart_idx](serial_irq_ids[uart_idx], TxIrq); } }
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) { PHAL_RUART_ADAPTER pHalRuartAdapter; PHAL_RUART_OP pHalRuartOp; u8 uart_idx; pHalRuartAdapter = &(obj->hal_uart_adp); pHalRuartOp = &(obj->hal_uart_op); uart_idx = pHalRuartAdapter->UartIndex; if (enable) { if (irq == RxIrq) { pHalRuartAdapter->Interrupts |= RUART_IER_ERBI | RUART_IER_ELSI; serial_irq_en[uart_idx] |= SERIAL_RX_IRQ_EN; HalRuartSetIMRRtl8195a (pHalRuartAdapter); } else { serial_irq_en[uart_idx] |= SERIAL_TX_IRQ_EN; } pHalRuartOp->HalRuartRegIrq(pHalRuartAdapter); pHalRuartOp->HalRuartIntEnable(pHalRuartAdapter); } else { // disable if (irq == RxIrq) { pHalRuartAdapter->Interrupts &= ~(RUART_IER_ERBI | RUART_IER_ELSI); serial_irq_en[uart_idx] &= ~SERIAL_RX_IRQ_EN; } else { pHalRuartAdapter->Interrupts &= RUART_IER_ETBEI; serial_irq_en[uart_idx] &= ~SERIAL_TX_IRQ_EN; } HalRuartSetIMRRtl8195a (pHalRuartAdapter); if (pHalRuartAdapter->Interrupts == 0) { InterruptUnRegister(&pHalRuartAdapter->IrqHandle); InterruptDis(&pHalRuartAdapter->IrqHandle); } } }
void serial_putc(serial_t *obj, int c) { PHAL_RUART_ADAPTER pHalRuartAdapter=(PHAL_RUART_ADAPTER)&(obj->hal_uart_adp); u8 uart_idx = pHalRuartAdapter->UartIndex; while (!serial_writable(obj)); HAL_RUART_WRITE32(uart_idx, RUART_TRAN_HOLD_REG_OFF, (c & 0xFF)); if (serial_irq_en & SERIAL_TX_IRQ_EN) { // UnMask TX FIFO empty IRQ pHalRuartAdapter->Interrupts |= RUART_IER_ETBEI; HalRuartSetIMRRtl8195a (pHalRuartAdapter); } }