OSK5912 UART Module
The UART module communicates through the on-chip UART peripheral to the RS232 Serial Connector. The UART API provides functions to send and receive 8-bit data serially to an external device. To use the module, you must use the OSK5912_UART_open( ) call to get a handle of type OSK5912_UART_Handle which is then passed as a parameter to the other functions.
OSK5912_UART_open()
Description
Open a UART device at the specified baud rate and return a UART device handle
Required Headers
osk5912.h
osk5912_uart.h
Required Libraries
osk5912bsl.lib
Function Prototype
OSK5912_UART_Handle OSK5912_UART_open( Int16 devid, Int16 baudrate, OSK5912_UART_Config *Config )
Parameters
devid - Device id (possible values 0,1,2)
baudrate - Baud rate (possible values are:)
UART_BAUD_RATE_300 UART_BAUD_RATE_600
UART_BAUD_RATE_1200 UART_BAUD_RATE_2400
UART_BAUD_RATE_4800 UART_BAUD_RATE_9600
UART_BAUD_RATE_14400 UART_BAUD_RATE_19200
UART_BAUD_RATE_28800 UART_BAUD_RATE_38400
UART_BAUD_RATE_57600 UART_BAUD_RATE_115200
UART_BAUD_RATE_230400 UART_BAUD_RATE_460800
UART_BAUD_RATE_921600 UART_BAUD_RATE_1834200
UART_BAUD_RATE_3686400
config - Pointer to a UART registers config structure, declared in OSK5912.uart.h. For more information on these registers & each register field, please refer to “OMAP5912 Dual-Core Processor Universal Asynchronous Receiver/Transmitter (UART)/Infrared Data Association (IrDA) Module Reference Guide” ( SPRU604 ).
Return Value
Device handle
Example
OSK5912_UART_Handle hUart;
OSK5912_UART_Config uartcfg = {
0x00, // IER
0x00, // FCR
0x03, // LCR
0x00 // MCR
};
/* Open UART 0 at 115200 baud in normal( non-FIFO mode ) */
hUart = OSK5912_UART_open( 0, OSK5912_UART_BAUD_115200,
&uartcfg );
OSK5912_UART_rget()
Description
Get UART register value
Required Headers
osk5912.h
osk5912_uart.h
Required Libraries
osk5912bsl.lib
Function Prototype
Uint8 OSK5912_UART_rget( OSK5912_UART_Handle hUart, Int16 regnum )
Parameters
hUart - Device handle
regnum - Index of register to get ( Defined in 5912.h as UART_XXX where XXX is the name of the register )
Return Value
8-bit register value
Example
/* Get the value of the LCR register */
Uint8 data;
data = OSK5912_UART_rget( hUart, UART_LCR );
OSK5912_UART_rset()
Description
Set UART register value
Required Headers
osk5912.h
osk5912_uart.h
Required Libraries
osk5912bsl.lib
Function Prototype
void OSK5912_UART_rset( OSK5912_UART_Handle hUart, Int16 regnum, Uint8 regval )
Parameters
hUart - Device handle
regnum- Index of register to get ( Defined in 5912.h as UART_XXX where XXX is the name of the register )
regval - 8-bit register value
Return Value
None
Example
/* Set the value of the LCR register to 0x03 */
OSK5912_UART_rset( hUart, UART_LCR, 0x03 );
OSK5912_UART_rcvReady()
Description
Check if the UART is ready to be read
Required Headers
osk5912.h
osk5912_uart.h
Required Libraries
osk5912bsl.lib
Function Prototype
Uint8 OSK5912_UART_rcvReady( OSK5912_UART_Handle hUart )
Parameters
hUart - Device handle
Return Value
0 - No data waiting to be read
1 - Data waiting to be read
Example
Int16 data;
/* Wait until UART is ready to be read */
while( ! OSK5912_UART_rcvReady( hUart ) );
/* Read a character */
data = OSK5912_UART_getChar( hUart );
OSK5912_UART_getChar()
Description
Get a character from the UART, used in conjunction with OSK5912_UART_rcvReady
Required Headers
osk5912.h
osk5912_uart.h
Required Libraries
osk5912bsl.lib
Function Prototype
Uint8 OSK5912_UART_getChar( OSK5912_UART_Handle hUart )
Parameters
hUart - Device handle
Return Value
8-bit character
Example
Int16 data;
/* Wait until UART is ready to be read */
while( ! OSK5912_UART_rcvReady( hUart ) );
/* Read a character */
data = OSK5912_UART_getChar( hUart );
OSK5912_UART_xmtReady()
Description
Check if UART is ready to send data
Required Headers
osk5912.h
osk5912_uart.h
Required Libraries
osk5912bsl.lib
Function Prototype
Uint8 OSK5912_UART_xmtReady( OSK5912_UART_Handle hUart )
Parameters
hUart - Device handle
Return Value
0 - UART not ready to send data
1 - UART ready to send data
Example
/* Wait until UART is ready to send */
while( ! OSK5912_UART_xmtReady( hUart ) );
/* Send the character ‘A’ */
OSK5912_UART_putChar( hUart, ‘A’ );
OSK5912_UART_putChar()
Description
Send a character through the UART, used in conjunction with OSK5912_UART_xmtReady
Required Headers
osk5912.h
osk5912_uart.h
Required Libraries
osk5912bsl.lib
Function Prototype
void OSK5912_UART_putChar( OSK5912_UART_Handle hUart, Uint8 data )
Parameters
hUart - Device handle
data - 8-bit character
Return Value
None
Example
/* Wait until UART is ready to send */
while( ! OSK5912_UART_xmtReady( hUart ) );
/* Send the character ‘A’ */
OSK5912_UART_putChar( hUart, ‘A’ );
|