JSAPI for STM32F0xx MCU  1.10
JSAPI_USART Class Reference

USART abstraction. printf IO redirection is supported. Currenty only asyncrhonous mode is supported. More...

#include <jsapi_st_mcu.h>

Public Member Functions

void SetPins (JSAPI_GPIO *tx_port, unsigned tx_pin_no, unsigned tx_af, JSAPI_GPIO *rx_port, unsigned rx_pin_no, unsigned rx_af)
 Associate GPIO pins with USART functions. More...
 
void MakeUSART (unsigned baud, unsigned bits, unsigned stop, enum FLOW_CONTROL fc)
 Make a USART unit. SetPins() should be called prior to this. More...
 
void MakeUSART (unsigned baud, unsigned bits, unsigned stop, int fc)
 
int ControlStreamBuffering (FILE *stream, bool isBuffered)
 Controi the buffered state of the stdin and stdout. This is only useful when printf/scanf redirection is used. By default these I/O streams are unbuffered, which means that a call to "putchar" for example will result in the character being sent to the serial port immediately. If the stream is set to be buffered, the output is buffered internally until an EOL character (0x0D) is written, at which time, the whole buffer is written out. The size of the internal buffer is GCC library dependent but is probably at least 128 bytes. More...
 
int SetIntrBuffers (unsigned char *txbuff, unsigned txlen, unsigned char *rxbuff, unsigned rxlen, int priority)
 Enable interrupt driven IO. You must supply the buffers. Make sure that the buffers are either global or static variables and not local variables as local variables disappear once the defining function returns. More...
 
int SetIntrBuffers (unsigned char *txbuff, unsigned txlen, unsigned char *rxbuff, unsigned rxlen)
 See SetIntrBuffers(..., 0) with priority of 0.
 
int SetIntrMode (int priority)
 Enable interrupt driven IO using builtin buffers of 12 bytes each for input and output. More...
 
int SetIntrMode (void)
 Enable interrupt driven IO using builtin buffers of 12 bytes each for input and output. Interrupt Priority will be set to 0. More...
 
int SetReadFilter (int(*readHandler)(unsigned char c), int *pbytes)
 Associate a read filter with interrupt driven IO. If set with a readHandler, when a character comes in, the readHandler is called with the character. The readHandler should return the character it wants to deposit to the buffer (which may be the same character as its input). More...
 
enum usart_mode GetMode (void)
 return operating mode
 
void SetBaudrate (unsigned baud)
 Set the BAUD rate of the USART. More...
 
int putchar (int ch)
 Write data to USART. If interrupt driven IO is used, then the data is written to the internal buffer and will be written out as the hardware transmit FIFO is clear. More...
 
int getchar (void)
 Read data from USART. More...
 
int kbhit (void)
 In interrupt driven IO, check to see if data is available for reading. More...
 
void Enable (void)
 Enable USART.
 
void Disable (void)
 Disable USART.
 

Detailed Description

USART abstraction. printf IO redirection is supported. Currenty only asyncrhonous mode is supported.

Member Function Documentation

int JSAPI_USART::ControlStreamBuffering ( FILE *  stream,
bool  isBuffered 
)

Controi the buffered state of the stdin and stdout. This is only useful when printf/scanf redirection is used. By default these I/O streams are unbuffered, which means that a call to "putchar" for example will result in the character being sent to the serial port immediately. If the stream is set to be buffered, the output is buffered internally until an EOL character (0x0D) is written, at which time, the whole buffer is written out. The size of the internal buffer is GCC library dependent but is probably at least 128 bytes.

Parameters
streameither stdin or stdout (stdio.h is included by jsapi.h).
isBufferedset to unbuffered if zero/false. Set to buffered otherwise.
Returns
0 if success, -1 if bad stream, -2 other error.
int JSAPI_USART::getchar ( void  )

Read data from USART.

Returns
input data. In In polled mode, will wait until data is available. In interrupt driven mode, it will return -1 if no data is available, and data from the buffer is available.
int JSAPI_USART::kbhit ( void  )

In interrupt driven IO, check to see if data is available for reading.

Returns
zero/false if no data is available. Nonzero/true otherwise.
void JSAPI_USART::MakeUSART ( unsigned  baud,
unsigned  bits,
unsigned  stop,
enum FLOW_CONTROL  fc 
)

Make a USART unit. SetPins() should be called prior to this.

Parameters
baudBAUD rate. Typical value is 9600, 14400, 512000 etc. May not be precise, depending on the HCLK.
bitsnumber of data bits, usually 8. Hardware may or may not support 9.
stopnumber of stop bits, usually 1 or 2.
fcflow control protocol. One of the "enum FLOW_CONTROL" values. Usually FC_NONE. If FC_HARDWARE (hardware flow control) is used, then you must set up the RTS and CTS pins.
Todo:
FC_SOFTWARE (software flow control) is NOT YET IMPLEMENTED.
int JSAPI_USART::putchar ( int  ch)

Write data to USART. If interrupt driven IO is used, then the data is written to the internal buffer and will be written out as the hardware transmit FIFO is clear.

Parameters
chdata to be written.
Returns
"ch"
void JSAPI_USART::SetBaudrate ( unsigned  baud)

Set the BAUD rate of the USART.

Parameters
baudBAUD rate. Typical value is 9600, 14400, 512000 etc. May not be precise, depending on the HCLK.
int JSAPI_USART::SetIntrBuffers ( unsigned char *  txbuff,
unsigned  txlen,
unsigned char *  rxbuff,
unsigned  rxlen,
int  priority 
)

Enable interrupt driven IO. You must supply the buffers. Make sure that the buffers are either global or static variables and not local variables as local variables disappear once the defining function returns.

Parameters
txbuffbuffer to store output characters.
txlenlength of "txbuf".
rxbuffbuffer to store input characters.
rxlenlength of "rxbuf".
priorityinterrupt priority.
Returns
0 if success, -1 if error (e.g. 0 length buffer etc.).
int JSAPI_USART::SetIntrMode ( int  priority)

Enable interrupt driven IO using builtin buffers of 12 bytes each for input and output.

Parameters
priorityinterrupt priority.
Returns
0.
int JSAPI_USART::SetIntrMode ( void  )
inline

Enable interrupt driven IO using builtin buffers of 12 bytes each for input and output. Interrupt Priority will be set to 0.

Returns
0.
void JSAPI_USART::SetPins ( JSAPI_GPIO tx_port,
unsigned  tx_pin_no,
unsigned  tx_af,
JSAPI_GPIO rx_port,
unsigned  rx_pin_no,
unsigned  rx_af 
)

Associate GPIO pins with USART functions.

Parameters
tx_portGPIO port for TX (Transmit pin).
tx_pin_nopin number for TX.
tx_afalternate function code for TX.
rx_portGPIO port for RX (Receive pin).
rx_pin_nopin number for RX.
rx_afalternate function code for RX.
int JSAPI_USART::SetReadFilter ( int(*)(unsigned char c)  readHandler,
int *  pbytes 
)

Associate a read filter with interrupt driven IO. If set with a readHandler, when a character comes in, the readHandler is called with the character. The readHandler should return the character it wants to deposit to the buffer (which may be the same character as its input).

Parameters
readHandleruser function to call when a character arrives. It should return: -1: remove the readHandler from further processing chain. >0: (must be between 0 and 255), the byte to write to the read buffer. It can be the same as the original incoming character "c" or other character mapped by the readHandler.
[out]pbytesif non-null, once readHandler returns, *pbytes contains the number of bytes currently in the input buffer.
Returns
0 if success, negative error code otherwise.

The documentation for this class was generated from the following file: