Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(ARM).Porting TCP-IP programmer's guide.Ver 1.4.pdf
Скачиваний:
31
Добавлен:
23.08.2013
Размер:
2.79 Mб
Скачать

ARM-specific Functions

10.15uart.c interface functions

The majority of the functions in uart.c involve interfacing between the modem dialer code in dialer.c and the UART hardware.

Each UART within the system has a UART structure associated with it:

typedef struct uart {

 

 

 

volatile t_ureg* uart;

/*

hardware registers */

t_ring

rx;

 

/*

received data ring buffer */

t_ring

tx;

 

/*

transmit data ring buffer */

volatile unsigned

tx_en;

/*

transmit irqs are enabled */

volatile unsigned

get_char; /*

count of calls to getchar */

volatile unsigned

put_char;

/*

count of calls to putchar */

volatile unsigned

tx_irqs;

/*

count of transmit */

 

 

 

/*

interrupts */

volatile unsigned

tx_wait;

/*

count of times we have had */

 

 

 

/*

to wait for tx space */

volatile unsigned

tx_char;

/*

count of characters sent */

 

 

 

/*

to uart */

volatile unsigned

rx_irqs;

/*

count of receive */

 

 

 

/*

interrupts */

volatile unsigned

rx_char;

/*

count of characters */

 

 

 

/*

received from uart */

volatile unsigned

rx_drop;

/*

count of characters */

 

 

 

/*

dropped from uart */

volatile unsigned

mdm_irqs; /*

count of modem interrupts */

unsigned unit;

 

/*

unit number */

} t_uart;

 

 

 

 

Most of the fields within this structure are used for statistics gathering and are not particularly important. The more important fields are:

uart

points to a structure that describes the hardware registers of the UART

 

device

rx

a ring buffer for holding data received by the UART

tx

a ring buffer for holding data to be transmitted by the UART

tx_en

a flag indicating that the transmit interrupt is enabled.

The interface functions are as follows:

uart_getc() on page 10-23

uart_DCD() on page 10-24

uart_delay() on page 10-24

10-22

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B

ARM-specific Functions

uart_do_irq() on page 10-25

uart_init() on page 10-26

uart_irq() on page 10-26

uart_putc() on page 10-27

uart_ready() on page 10-27

uart_reset() on page 10-28

uart_setup() on page 10-29

uart_stats() on page 10-30.

10.15.1 uart_getc()

This function reads a character from a UART. It retrieves a character from the receive ring buffer, if available, and returns it to the caller.

Syntax

int uart_getc(int unit)

where:

unit

is the UART unit number.

Return value

Returns one of the following:

character

the character returned from the ring buffer, if available.

–1

if no characters are available.

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

10-23

ARM-specific Functions

10.15.2 uart_DCD()

This function returns the Data Carrier Detect (DCD) state.

Syntax

int uart_DCD(int unit)

where:

unit

is the UART unit number.

Return value

Returns one of the following:

TRUE if the carrier detect line or signal is down.

FALSE if the carrier detect line or signal is up.

Usage

This function is used by the modem dialer code to monitor the state of the DCD input.

10.15.3 uart_delay()

This function causes a delay for a specified number of clock ticks.

Syntax

static void uart_delay(unsigned long ticks)

where:

ticks is the number of clock ticks to delay for.

Return value

None.

Usage

This function can be used to block execution for a short amount of time. This function loops, calling YIELD(), until the number of ticks specified has elapsed. Ticks occur TPS times per second. TPS is defined in the ipport.h file. See Timers and multitasking on page 2-8 for more information.

10-24

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B

ARM-specific Functions

10.15.4 uart_do_irq()

This function handles interrupts for a specific UART.

Syntax

static void uart_do_irq(struct uart *pUart)

where:

pUart is the pointer to the UART structure of the interrupting UART.

Usage

This function is called from the uart_irq() function when it has determined which UART has caused the interrupt. It examines the interrupt status from the UART and processes the interrupt accordingly.

For line status and modem status interrupts, no processing is done other than to clear the source of the interrupt.

If the interrupt was caused because there are characters available in the receive FIFO, these characters are added to the receive ring buffer. If the receive ring buffer is full, the extra characters are read from the UART and discarded.

If the interrupt was caused by a transmit interrupt, up to 16 characters are copied from the transmit ring buffer to the UART transmit FIFO.

If the transmit ring buffer is emptied, transmit interrupts are no longer appropriate, so they are disabled.

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

10-25