fdserial library  v0.86
Functions for connecting with full duplex serial devices
Data Structures | Macros | Typedefs | Functions
fdserial.h File Reference

This library supports creating and managing one or more full duplex serial connections with peripheral devices. The pointer returned when a connection is opened can be used to identify the connection for other calls with fdserial parameter types in this library. The identifier can also be used to identify the serial connection for higher level formatted text transmit/receive functions with text_t parameter types in the simpletext library. More...

#include "simpletext.h"

Go to the source code of this file.

Data Structures

struct  fdserial_struct
 Defines fdserial interface structure of 9 contiguous longs + buffers. More...

Macros

#define FDSERIAL_BUFF_MASK   0x3f
#define FDSERIAL_MODE_NONE   0
#define FDSERIAL_MODE_INVERT_RX   1
#define FDSERIAL_MODE_INVERT_TX   2
#define FDSERIAL_MODE_OPENDRAIN_TX   4
#define FDSERIAL_MODE_IGNORE_TX_ECHO   8

Typedefs

typedef text_t fdserial
 Defines text_t data type as fdserial to allow declarations like fdserial *MyDevice. After storing the value returned by fdserial_start in MyDevice, it can be passed as an identifying parameter to fdserial and simpletext library functions that have fdserial or text_t parameter types.
typedef struct fdserial_struct fdserial_st
 Defines fdserial interface structure of 9 contiguous longs + buffers.

Functions

fdserialfdserial_open (int rxpin, int txpin, int mode, int baudrate)
 Open a full duplex serial connection.
void fdserial_close (fdserial *term)
 Stop stops the cog running the native assembly driver.
int fdserial_rxCheck (fdserial *term)
 Gets a byte from the receive buffer if available, but does not wait if there's nothing in the buffer.
void fdserial_rxFlush (fdserial *term)
 Empties the receive buffer.
int fdserial_rxReady (fdserial *term)
 Check if a byte is ready in the receive buffer.
int fdserial_rxTime (fdserial *term, int ms)
 Gets a byte from the receive buffer if available, or wait for up to timeout ms to receive a byte.
int fdserial_rxChar (fdserial *term)
 Get a byte from the receive buffer, or if it's emtpy, wait until a byte is received.
int fdserial_rxCount (fdserial *term)
 Get number of bytes available in the receive buffer without receiving any. NOTE: This function is not designed for detecting buffer overflow, just for reporting how many bytes have accumulated in the input buffer.
int fdserial_rxPeek (fdserial *term)
 Get a byte from the receive buffer without changing the pointers. The function does not block.
int fdserial_txChar (fdserial *term, int txbyte)
 Send a byte by adding it to the transmit buffer.
int fdserial_txEmpty (fdserial *term)
 Check if the transmit buffer is empty.
void fdserial_txFlush (fdserial *term)
 Remove any bytes that might be waiting in the transmit buffer.

Detailed Description

This library supports creating and managing one or more full duplex serial connections with peripheral devices. The pointer returned when a connection is opened can be used to identify the connection for other calls with fdserial parameter types in this library. The identifier can also be used to identify the serial connection for higher level formatted text transmit/receive functions with text_t parameter types in the simpletext library.

Author
Steve Denson, with naming conventions supplied by Parallax.
Core Usage
Each call to fdserial_open launches an additional cog that can support an additional UART communication process.
Memory Models
Use with CMM or LMM.
Version
0.86
Help Improve this Library
Please submit bug reports, suggestions, and improvements to this code to edito.nosp@m.r@pa.nosp@m.ralla.nosp@m.x.co.nosp@m.m.

Macro Definition Documentation

#define FDSERIAL_BUFF_MASK   0x3f

Defines buffer length. hard coded into asm driver ... s/b bigger

#define FDSERIAL_MODE_IGNORE_TX_ECHO   8

Mode bit 3 can be set to 1 to ignore copy of txpin's signal if received by rxpin.

#define FDSERIAL_MODE_INVERT_RX   1

Mode bit 0 can be set to 1 for inverted signal to rxpin.

#define FDSERIAL_MODE_INVERT_TX   2

Mode bit 1 can be set to 1 for inverted signal from txpin.

#define FDSERIAL_MODE_NONE   0

All mode bits set to 0 for non-inverted asynchronous serial communication.

#define FDSERIAL_MODE_OPENDRAIN_TX   4

Mode bit 2 can be set to 1 to open collector/drain txpin communication with a pull-up resistor on the line.

Function Documentation

void fdserial_close ( fdserial term)

Stop stops the cog running the native assembly driver.

Parameters
*termDevice ID returned by fdserial_open.
fdserial* fdserial_open ( int  rxpin,
int  txpin,
int  mode,
int  baudrate 
)

Open a full duplex serial connection.

Parameters
rxpinSerial receive input pin number.
txpinSerial transmit output pin number.
modeSet/clear bits to define mode: mode bit 0 = invert rx mode bit 1 = invert tx mode bit 2 = open-drain/source tx mode bit 3 = ignore tx echo on rx
baudrateRate binary values are transmitted, like 115200, 57600,..., 9600 etc.
Returns
fdserial pointer for use as an identifier for fdserial and simpletext library functions that have fdserial or text_t parameter types.
int fdserial_rxChar ( fdserial term)

Get a byte from the receive buffer, or if it's emtpy, wait until a byte is received.

Parameters
*termDevice ID returned by fdserial_open.

Oldest byte (0 to 255) in receive buffer

int fdserial_rxCheck ( fdserial term)

Gets a byte from the receive buffer if available, but does not wait if there's nothing in the buffer.

Parameters
*termDevice ID returned by fdserial_open.
Returns
Oldest byte (0 to 255) in receive buffer, or -1 if buffer is empty.
int fdserial_rxCount ( fdserial term)

Get number of bytes available in the receive buffer without receiving any. NOTE: This function is not designed for detecting buffer overflow, just for reporting how many bytes have accumulated in the input buffer.

Parameters
*termDevice ID returned by fdserial_open.
Returns
Number of bytes available.
void fdserial_rxFlush ( fdserial term)

Empties the receive buffer.

Parameters
*termDevice ID returned by fdserial_open.
int fdserial_rxPeek ( fdserial term)

Get a byte from the receive buffer without changing the pointers. The function does not block.

Returns
non-zero if a valid byte is available.
int fdserial_rxReady ( fdserial term)

Check if a byte is ready in the receive buffer.

Parameters
*termDevice ID returned by fdserial_open.
Returns
Non-zero if one or more bytes are waiting in the receive buffer, or 0 if it's empty.
int fdserial_rxTime ( fdserial term,
int  ms 
)

Gets a byte from the receive buffer if available, or wait for up to timeout ms to receive a byte.

Parameters
*termDevice ID returned by fdserial_open.
msis number of milliseconds to wait for a char
Returns
receive byte 0 to 0xff or -1 if none available
int fdserial_txChar ( fdserial term,
int  txbyte 
)

Send a byte by adding it to the transmit buffer.

Parameters
*termDevice ID returned by fdserial_open.
txbyteis byte to send.
Returns
The byte that was sent, or returns the byte that was received if mode bit 3 was set in the fdserial_open call.
int fdserial_txEmpty ( fdserial term)

Check if the transmit buffer is empty.

Parameters
*termDevice ID returned by fdserial_open.
Returns
non-zero if transmit buffer is empty.