uart.h File Reference


Functions

uint8 uart_init ()
uint16 uart_write (uint8 *buf, uint16 size)
void uart_send (char *s)
void uart_sendc (char c)
uint16 uart_write_block (uint8 *buf, uint16 size)
void uart_flush ()
uint16 uart_available ()
uint16 uart_read (uint8 *dest, uint16 size)
uint16 uart_readstr (char *dest, uint16 size)
uint16 uart_readln (char *dest, uint16 size, char nl)
bool uart_requeue (uint8 *src, uint16 size)
void uart_wait ()
void uart_set_bps (uint32 bps)
void uart_set_parity (char par)
void uart_set_spi_rate (uint32 bps)
void uart_set_watermarks (uint16 high, uint16 low)
float uart_get_spi_rate ()
void uart_write_prio (uint8 *buf, uint16 size, uint8 *dest, uint32 irq_bytes)
bool uart_wait_prio (uint8 timeout)
uint8 uart_firmware_ver ()
void uart_close ()

Function Documentation

uint16 uart_available (  ) 

return the number of bytes available for reading.

Returns:
number of bytes available for reading

void uart_close (  ) 

close the device.

uint8 uart_firmware_ver (  ) 

get device firmware version.

Returns:
firmware version

void uart_flush (  ) 

wait until all bytes have been written to the device.

float uart_get_spi_rate (  ) 

get the effective baudrate used for sending bytes over the spi bus.

Returns:
baudrate (bytes per second)

uint8 uart_init (  ) 

initialize uart library.

waits for the device to be ready.

Returns:
timer irq used (0-3) or 0xff in case of error

uint16 uart_read ( uint8 *  dest,
uint16  size 
)

read from the uart device.

Parameters:
dest destination buffer
size size of destination buffer
Returns:
number of bytes copied to destination buffer

uint16 uart_readln ( char *  dest,
uint16  size,
char  nl 
)

read a line from the uart device.

this function returns all characters up (and including) the newline-character. the resulting string is null- terminated.

Parameters:
dest destination string
size size of destination string (in bytes)
nl newline character (e.g. '
');
Returns:
characters copied to destination buffer

uint16 uart_readstr ( char *  dest,
uint16  size 
)

read a string from the uart device.

this function is a helper function that produces a null- terminated string and returns the number of characters (excluding the final null).

Parameters:
dest destination string
size size of destination string (in bytes)
Returns:
characters copied to destination buffer

bool uart_requeue ( uint8 *  src,
uint16  size 
)

put the content of a buffer back into the head of the input queue.

Parameters:
src buffer
size number of bytes to copy
Returns:
true if successful, false if no bytes have been copied because queue is full

void uart_send ( char *  s  ) 

send a string over the uart device.

this function is a helper function that returns only after all characters have been put into the output queue.

Parameters:
s null-terminated string to send

void uart_sendc ( char  c  ) 

send a character over the uart device.

this function is a helper function that returns only after the character has been put into the output queue.

Parameters:
c character to send

void uart_set_bps ( uint32  bps  ) 

set the baudrate to use on the uart side.

115200 bps seems not to work because of baud rate errors (see p. 196 of the datasheet), the true baudrate is about 126984 there.

Parameters:
bps baudrate (bytes per second)

void uart_set_parity ( char  par  ) 

set the parity used for the uart device.

this function needs firmware version 0x11 or higher to work.

Parameters:
par 'n' (none, default), 'e' (even), 'o' (odd)

void uart_set_spi_rate ( uint32  bps  ) 

set the baudrate to use for sending bytes over the spi bus.

this function adjusts the internal timer frequency. the default baudrate is being defined by UART_SPI_RATE in uart.c (100Hz at the moment).

Parameters:
bps baudrate (bytes per second)

void uart_set_watermarks ( uint16  high,
uint16  low 
)

set watermarks.

watermarks are used to signal the communication partner to cease sending bytes because the user-program does not read the input buffer fast enough (or at all) and the input queue is about to overflow. the uart-device can use watermarks to do hardware flow- control. watermarks are disabled by default.

Parameters:
high level for high water (1-100, 0 to disable)
low level for low water (1-100, 0 to disable)

void uart_wait (  ) 

wait for a uart event to occur.

this function returns after a uart timer or spi line irq. it can be used for waiting for some input data to become available.

bool uart_wait_prio ( uint8  timeout  ) 

wait until the priority-write transmission has been completed.

Parameters:
timeout timeout in seconds (or zero to disable)
Returns:
true if successful, false for timeout

uint16 uart_write ( uint8 *  buf,
uint16  size 
)

write the content of a buffer to the uart device.

this function internally escapes null-bytes and backspace chars.

Parameters:
buf buffer
size number of bytes to write
Returns:
number of bytes written

uint16 uart_write_block ( uint8 *  buf,
uint16  size 
)

write the content of a buffer to the uart device as a block.

this function is useful if you have tight timing contraints. the function returns after the last byte has been send over the uart device.

Parameters:
buf buffer
size number of bytes to write (up to 32 bytes are currently supported)
Returns:
number of bytes written

void uart_write_prio ( uint8 *  buf,
uint16  size,
uint8 *  dest,
uint32  irq_bytes 
)

do a priority-write to the uart device.

the content of buf are added to the head of the output queue, and are guaranteed to fit in there (as other bytes are being descarded to make some room). the content is also not being escaped and the response to each byte stored in the dest buffer (which can be the same as buf). additionally, irq_bytes holds a bitmask for which bytes the library should way for an irq from the uart-device before reading in the next byte over spi.

Parameters:
buf buffer
size number of bytes to write
dest destination buffer (can be the same as buf)
irq_bytes bitmask (see above; 0x01 is last byte of buf)