📄 lh7a404_uart_driver.c
字号:
{
/* Active high */
status = 1;
}
else
{
/* Active low */
status = 0;
}
break;
case UART_TX_POL_ST:
/* Returns TX signal polarity status */
if ((uartregs->lcr & UART_CNTL_TXP) != 0)
{
/* Active high */
status = 1;
}
else
{
/* Active low */
status = 0;
}
break;
case UART_RX_POL_ST:
/* Returns RX signal polarity status */
if ((uartregs->lcr & UART_CNTL_RXP) != 0)
{
/* Active low */
status = 1;
}
else
{
/* Active high */
status = 0;
}
break;
case SIR_BLANKING_ST:
/* Returns SIR blanking bit status */
if ((uartregs->lcr & UART_CNTL_SIRBD) != 0)
{
/* SIR blanking disabled */
status = 1;
}
else
{
/* SIR blanking enabled */
status = 0;
}
break;
case SIR_LOWPOWER_ST:
/* Returns SIR low power mode status */
if ((uartregs->lcr & UART_CNTL_SIRLP) != 0)
{
/* SIR low power mode enabled */
status = 1;
}
else
{
/* SIR low power mode disabled */
status = 0;
}
break;
default:
/* Unsupported parameter */
status = SMA_BAD_PARAMS;
break;
}
break;
default:
/* Unsupported parameter */
status = SMA_BAD_PARAMS;
}
}
return status;
}
/***********************************************************************
*
* Function: uart_read_polled
*
* Purpose: UART read function for polled mode
*
* Processing:
* If the init flag for the UART structure is FALSE, return 0 to
* the caller. Otherwise, loop until max_bytes equals 0 or until
* the receive FIFO is empty, whichever comes first. Read the data
* from the UART FIFO and place it user buffer. Increment the
* address of the user buffer. Increment bytes, and decrement
* max_bytes. Exit the loop based on the loop conditions and
* return the number of bytes read to the caller.
*
* Parameters:
* devid: Pointer to UART config structure
* buffer: Pointer to data buffer to copy to
* max_bytes: Number of bytes to read
*
* Outputs: None
*
* Returns: Number of bytes actually read from the FIFO
*
* Notes: None
*
**********************************************************************/
INT_32 uart_read_polled(INT_32 devid,
void *buffer,
INT_32 max_bytes)
{
UART_REGS_T *uartregs;
UART_CFG_T *uartcfgptr = (UART_CFG_T *) devid;
UNS_8 *data = (UNS_8 *) buffer;
INT_32 bytes = 0;
if (uartcfgptr->init == TRUE)
{
uartregs = uartcfgptr->regptr;
/* Loop until receive FIFO is empty or until max_bytes
expires */
while ((max_bytes > 0) &&
((uartregs->status & UART_STATUS_RXFE) == 0))
{
/* Read data from FIFO into buffer */
*data = (UNS_8) uartregs->data;
data++;
/* Increment data count and decrement buffer size count */
bytes++;
max_bytes--;
}
}
return bytes;
}
/***********************************************************************
*
* Function: uart_write_polled
*
* Purpose: UART write function for polled mode
*
* Processing:
* If the init flag for the UART structure is FALSE, return 0 to
* the caller. Otherwise, loop until n_bytes equals 0. Loop until
* the transmit FIFO is full insisde the n_bytes loop. Read the data
* from the user buffer and place it in the UART FIFO. Increment
* the address of the user buffer. Increment bytes, and decrement
* n_bytes. Exit the loop based on the loop conditions and
* return the number of actually bytes written to the caller.
*
* Parameters:
* devid: Pointer to UART config structure
* buffer: Pointer to data buffer to copy from
* n_bytes: Number of bytes to write
*
* Outputs: None
*
* Returns: Number of bytes actually written to the FIFO
*
* Notes: None
*
**********************************************************************/
INT_32 uart_write_polled(INT_32 devid,
void *buffer,
INT_32 n_bytes)
{
UART_REGS_T *uartregs;
UART_CFG_T *uartcfgptr = (UART_CFG_T *) devid;
UNS_8 *data = (UNS_8 *) buffer;
INT_32 bytes = 0;
if (uartcfgptr->init == TRUE)
{
uartregs = uartcfgptr->regptr;
/* Loop until n_bytes expires to 0 */
while (n_bytes > 0)
{
if ((uartregs->status & UART_STATUS_TXFF) == 0)
{
/* Write data from buffer into FIFO */
uartregs->data = *data;
data++;
/* Increment data count and decrement buffer size
count */
bytes++;
n_bytes--;
}
}
}
return bytes;
}
/***********************************************************************
*
* Function: uart_read_ring
*
* Purpose: UART read function for interrupt mode (using ring buffers)
*
* Processing:
* If the init flag for the UART structure is FALSE, return 0 to
* the caller. Otherwise, save the state of the receive interrupts
* and disable the receive interrupts. Loop until max_bytes equals
* 0 or until the receive ring buffer is empty, whichever comes
* first. Read the data from the ring buffer indexed by the tail
* pointer and place it into the user buffer. Increment the tail
* pointer and user buffer pointer. If the tail pointer exceeds the
* buffer size, set the tail pointer to 0. Increment bytes, and
* decrement max_bytes. Exit the loop based on the loop conditions,
* re-enable the receive interrupts, and return the number of bytes
* read to the caller.
*
* Parameters:
* devid: Pointer to UART config structure
* buffer: Pointer to data buffer to copy to
* max_bytes: Number of bytes to read
*
* Outputs: None
*
* Returns: Number of bytes actually read from the ring buffer
*
* Notes: None
*
**********************************************************************/
INT_32 uart_read_ring(INT_32 devid,
void *buffer,
INT_32 max_bytes)
{
UART_REGS_T *uartregs;
UNS_32 tmp1;
UART_CFG_T *uartcfgptr = (UART_CFG_T *) devid;
UNS_8 *data = (UNS_8 *) buffer;
INT_32 bytes = 0;
if (uartcfgptr->init == TRUE)
{
uartregs = uartcfgptr->regptr;
/* Temporarily lock out UART receive interrupts during this
read so the UART receive interrupt won't cause problems
with the index values */
tmp1 = uartregs->inte & (UART_INTR_RTI | UART_INTR_RI);
uartregs->inte &= ~(UART_INTR_RTI | UART_INTR_RI);
/* Loop until receive FIFO is empty or until max_bytes
expires */
while ((max_bytes > 0) &&
(uartcfgptr->rb.rx_tail != uartcfgptr->rb.rx_head))
{
/* Read data from ring buffer into user buffer */
*data = uartcfgptr->rb.rx[uartcfgptr->rb.rx_tail];
data++;
/* Update tail pointer */
uartcfgptr->rb.rx_tail++;
/* Make sure tail didn't overflow */
if (uartcfgptr->rb.rx_tail >= UART_RING_BUFSIZE)
{
uartcfgptr->rb.rx_tail = 0;
}
/* Increment data count and decrement buffer size count */
bytes++;
max_bytes--;
}
/* Re-enable UART interrupts */
uartregs->inte |= tmp1;
}
return bytes;
}
/***********************************************************************
*
* Function: uart_write_ring
*
* Purpose: UART write function for interrupt mode (using ring buffers)
*
* Processing:
* If the init flag for the UART structure is FALSE, return 0 to
* the caller. Otherwise, disable the receive interrupts. Loop until
* n_bytes equals 0 or until the transmit ring buffer is full,
* whichever comes first. Write the data from the user buffer to
* the transmit ring buffer indexed by the head pointer. Increment
* the user buffer pointer and head pointer. If the head pointer
* exceeds the buffer size, set the head pointer to 0. Increment
* bytes, and decrement n_bytes. Exit the loop based on the loop
* conditions. If the number bytes written to the ring buffer was
* greater then 0, call the uart_standard_transmit() fucntion.
* Return the number of bytes read to the caller.
*
* Parameters:
* devid: Pointer to UART config structure
* buffer: Pointer to data buffer to copy from
* n_bytes: Number of bytes to write
*
* Outputs: None
*
* Returns: Number of bytes actually written to the ring buffer
*
* Notes:
* You cannot overflow the transmit ring buffer.
*
**********************************************************************/
INT_32 uart_write_ring(INT_32 devid,
void *buffer,
INT_32 n_bytes)
{
UART_REGS_T *uartregs;
UNS_32 savedint;
UART_CFG_T *uartcfgptr = (UART_CFG_T *) devid;
UNS_8 *data = (UNS_8 *) buffer;
INT_32 bytes = 0;
if (uartcfgptr->init == TRUE)
{
uartregs = uartcfgptr->regptr;
/* Temporarily lock out UART transmit interrupts during this
read so the UART transmit interrupt won't cause problems
with the index values */
savedint = uartregs->inte & UART_INTR_TI;
uartregs->inte &= ~UART_INTR_TI;
/* Loop until transmit run buffer is full or until n_bytes
expires */
while ((n_bytes > 0) &&
(uart_get_free_tx_count(uartcfgptr) > 0))
{
/* Write data from buffer into ring buffer */
uartcfgptr->rb.tx[uartcfgptr->rb.tx_head] = *data;
data++;
/* Increment head pointer */
uartcfgptr->rb.tx_head++;
if (uartcfgptr->rb.tx_head >= UART_RING_BUFSIZE)
{
uartcfgptr->rb.tx_head = 0;
}
/* Increment data count and decrement buffer size count */
bytes++;
n_bytes--;
}
/* Now start sending the data - this will also re-enable the
transmit interrupt */
if (bytes > 0)
{
uart_standard_transmit(uartcfgptr);
}
else
{
/* Restore original interrupt state */
uartregs->inte |= savedint;
}
}
return bytes;
}
#if UART_1_ENABLE == 1
/***********************************************************************
*
* Function: uart1_isr
*
* Purpose: UART 1 interrupt function
*
* Processing:
* Calls the standard UART interrupt branch function with the
* UART1 configuration structure pointer.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void uart1_isr(void)
{
uart_standard_interrupt(&uart1cfg);
}
#endif
#if UART_2_ENABLE == 1
/***********************************************************************
*
* Function: uart2_isr
*
* Purpose: UART 2 interrupt function
*
* Processing:
* Calls the standard UART interrupt branch function with the
* UART2 configuration structure pointer.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void uart2_isr(void)
{
uart_standard_interrupt(&uart2cfg);
}
#endif
#if UART_3_ENABLE == 1
/***********************************************************************
*
* Function: uart3_isr
*
* Purpose: UART 3 interrupt function
*
* Processing:
* Calls the standard UART interrupt branch function with the
* UART3 configuration structure pointer.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void uart3_isr(void)
{
uart_standard_interrupt(&uart3cfg);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -