Data Structures | |
struct | _BUS_BUFFER |
struct | _BUSES_INFO |
Defines | |
#define | BUFTYPE BYTE |
#define | BUS_COUNT (BUSID_MAX) |
#define | BUSBUFFER_SIZE 512ul |
#define | busDisabled(busId) (busInfo.stat[busId] &= ~BUSSTAT_ENABLED) |
#define | busEmptyRxBuf(busId) {busInfo.buf[busId].getRx = busInfo.buf[busId].putRx = busInfo.buf[busId].rxCount = 0;} |
#define | busEmptyTxBuf(busId) {busInfo.buf[busId].getTx = busInfo.buf[busId].putTx = busInfo.buf[busId].txCount = 0;} |
#define | busEnable(busId) (busInfo.stat[busId] |= BUSSTAT_ENABLED) |
#define | busGetStat(busId) (busInfo.stat[busId]) |
#define | busIsEnabled(busId) (busInfo.stat[busId] & BUSSTAT_ENABLED) |
#define | busIsRxBufEmpty(busId) (busInfo.buf[busId].rxCount == 0) |
#define | busIsRxBufFull(busId) (busInfo.buf[busId].rxCount == busInfo.buf[busId].rxBufSize) |
#define | busIsTxBufEmpty(busId) (busInfo.buf[busId].txCount == 0) |
#define | busIsTxBufFull(busId) (busInfo.buf[busId].txCount == busInfo.buf[busId].txBufSize) |
#define | busIsTxing(busId) (busInfo.stat[busId] & BUSSTAT_TXING) |
#define | busPeekByteRxBuf(busId) (*(busInfo.buf[busId].rxBuf + busInfo.buf[busId].getRx)) |
#define | busPeekByteTxBuf(busId) (*(busInfo.buf[busId].txBuf + busInfo.buf[busId].getTx)) |
#define | busPutByteRxBuf(busId, b) {*(busInfo.buf[busId].rxBuf + busInfo.buf[busId].putRx) = b; /* Write byte to buf */ if((++busInfo.buf[busId].putRx)==busInfo.buf[busId].rxBufSize) {busInfo.buf[busId].putRx = 0;} busInfo.buf[busId].rxCount++; /*One more byte available in buffer*/} |
#define | busPutByteTxBuf(busId, b) {*(busInfo.buf[busId].txBuf + busInfo.buf[busId].putTx) = b; /* Write byte to buf */ if((++busInfo.buf[busId].putTx)==busInfo.buf[busId].txBufSize) {busInfo.buf[busId].putTx = 0;} busInfo.buf[busId].txCount++; /*One more byte available in buffer*/} |
#define | busRemoveByteRxBuf(busId) { if((++busInfo.buf[busId].getRx)==busInfo.buf[busId].rxBufSize) {busInfo.buf[busId].getRx = 0;} busInfo.buf[busId].rxCount--; /*Update available data left in rx buffer*/} |
#define | busRemoveByteTxBuf(busId) { if((++busInfo.buf[busId].getTx)==busInfo.buf[busId].txBufSize) {busInfo.buf[busId].getTx = 0;} busInfo.buf[busId].txCount--; /*Update available data left in tx buffer*/} |
#define | busRxBufHasData(busId) (busInfo.buf[busId].rxCount != 0) |
#define | busRxBufNotFull(busId) (busInfo.buf[busId].rxCount != busInfo.buf[busId].rxBufSize) |
#define | BUSSTAT_ENABLED 0x80 |
#define | BUSSTAT_RX_OVERRUN 0x10 |
#define | BUSSTAT_TX_OVERRUN 0x01 |
#define | BUSSTAT_TXING 0x02 |
#define | BUSSTAT_UDP_ENABLE 0x01 |
#define | busStatClearOverrun(busId) (busInfo.stat[busId] &= (~(BUSSTAT_TX_OVERRUN | BUSSTAT_RX_OVERRUN)) ) |
#define | busTxBufHasData(busId) (busInfo.buf[busId].txCount != 0) |
Typedefs | |
typedef struct _BUS_BUFFER | BUS_BUFFER |
typedef struct _BUSES_INFO | BUS_INFO |
Enumerations | |
enum | BUSES { BUSID_SER1 = 0, BUSID_I2C1, BUSID_SPI1, BUSID_MAX } |
Functions | |
void | busInfoInit (void) |
void | busInit (void) |
void | busNetInit (void) |
void | busService (BYTE busId) |
void | busTask (void) |
Variables | |
BUS_INFO | busInfo |
//********************************************************************* //-------------------- Buses Configuration -------------------- //********************************************************************* //The default UDP port to use for the UDP 1 Port. //#define DEFAULT_BUS_UDP1PORT (54125ul) // //The default UDP port to use for the UDP 2 Port. //#define DEFAULT_BUS_UDP2PORT (54126ul) // //UDP1 Port //#define BUS_UDP1PORT DEFAULT_BUS_UDP1PORT // //UDP2 Port //#define BUS_UDP2PORT DEFAULT_BUS_UDP2PORT // //Serial Port 1 buffer sizes //#define BUS_SER1_TXBUFSIZE 50 //#define BUS_SER1_RXBUFSIZE 100 // //Serial Port 2 buffer sizes //#define BUS_SER2_TXBUFSIZE 20 //#define BUS_SER2_RXBUFSIZE 20 // //I2C Port 1 buffer sizes //#define BUS_I2C1_TXBUFSIZE 100 //#define BUS_I2C1_RXBUFSIZE 20 // //SPI Port 1 buffer sizes //#define BUS_SPI1_TXBUFSIZE 20 //#define BUS_SPI1_RXBUFSIZE 20 //
//********************************************************************* //-------------------- Buses Configuration -------------------- //********************************************************************* //Default "UDP Command Port" //#define DEFAULT_CMD_UDPPORT (54123)
#define BUFTYPE BYTE |
#define BUS_COUNT (BUSID_MAX) |
The number of buses
#define BUSBUFFER_SIZE 512ul |
#define busDisabled | ( | busId | ) | (busInfo.stat[busId] &= ~BUSSTAT_ENABLED) |
Disaable the given bus.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busEmptyRxBuf | ( | busId | ) | {busInfo.buf[busId].getRx = busInfo.buf[busId].putRx = busInfo.buf[busId].rxCount = 0;} |
Empty the given buses receive buffer. Any data contained in the receive buffer is lost.
busId | The bus whos receive buffer has to be cleared. Is a BUSID_XXX variable |
#define busEmptyTxBuf | ( | busId | ) | {busInfo.buf[busId].getTx = busInfo.buf[busId].putTx = busInfo.buf[busId].txCount = 0;} |
Empty the given buses transmit buffer. Any data contained in the transmit buffer is lost.
busId | The bus whos transmit buffer has to be cleared. Is a BUSID_XXX variable |
#define busEnable | ( | busId | ) | (busInfo.stat[busId] |= BUSSTAT_ENABLED) |
Enable the given bus.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busGetStat | ( | busId | ) | (busInfo.stat[busId]) |
Reads a byte from the given bus's receive buffer. Ensure that the bus has data before calling this function! The read byte is removed from the buses receive buffer.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busIsEnabled | ( | busId | ) | (busInfo.stat[busId] & BUSSTAT_ENABLED) |
Indicates if this bus is enabled.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busIsRxBufEmpty | ( | busId | ) | (busInfo.buf[busId].rxCount == 0) |
Checks if the given bus's receive buffer is empty - it has no pending data in it's receive buffer.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busIsRxBufFull | ( | busId | ) | (busInfo.buf[busId].rxCount == busInfo.buf[busId].rxBufSize) |
Checks if the given bus's receive buffer is full - no more space for adding data.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busIsTxBufEmpty | ( | busId | ) | (busInfo.buf[busId].txCount == 0) |
Checks if the given bus's transmit buffer is empty - it has nothing to transmit.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busIsTxBufFull | ( | busId | ) | (busInfo.buf[busId].txCount == busInfo.buf[busId].txBufSize) |
Checks if the given bus's transmit buffer is full - no more space for adding data.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busIsTxing | ( | busId | ) | (busInfo.stat[busId] & BUSSTAT_TXING) |
Indicates if this bus is currently transmitting - returns the status of the BUSSTAT_TX flag. For interrupt driven buses, this means that a transmit interrupt can occur at any time, and clear this flag.
When checking if the bus is transmitting, it should be remembered that a transmit interrupt can occur at any time, and clear the trasmitting flag. This means that if this function returns true, it could change to false (transmit interrupt occurs) by the time we receive the true reply. To prevent this, this function should be called in a critical section, so that no interrupt can occur while calling it.
When checking if the bus is NOT transmitting, it does not have to be performed in a critical section. Not transmitting, means no transmit interrupt can occur and change this flag.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busPeekByteRxBuf | ( | busId | ) | (*(busInfo.buf[busId].rxBuf + busInfo.buf[busId].getRx)) |
Gets a byte from the RX Buffer, without removing it. The byte is NOT removed from the buffer, and the buffer pointers are NOT updated! To remove the byte, and update the pointers, call the busRemoveByteRxBuf() function.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busPeekByteTxBuf | ( | busId | ) | (*(busInfo.buf[busId].txBuf + busInfo.buf[busId].getTx)) |
Gets a byte from the TX Buffer, without removing it. The byte is NOT removed from the buffer, and the buffer pointers are NOT updated! To remove the byte, and update the pointers, call the busRemoveByteTxBuf() function.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busPutByteRxBuf | ( | busId, | |||
b | ) | {*(busInfo.buf[busId].rxBuf + busInfo.buf[busId].putRx) = b; /* Write byte to buf */ if((++busInfo.buf[busId].putRx)==busInfo.buf[busId].rxBufSize) {busInfo.buf[busId].putRx = 0;} busInfo.buf[busId].rxCount++; /*One more byte available in buffer*/} |
Adds a byte to the RX Buffer, and updates the buffer pointers.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable | |
b | Byte to add to the buffer |
#define busPutByteTxBuf | ( | busId, | |||
b | ) | {*(busInfo.buf[busId].txBuf + busInfo.buf[busId].putTx) = b; /* Write byte to buf */ if((++busInfo.buf[busId].putTx)==busInfo.buf[busId].txBufSize) {busInfo.buf[busId].putTx = 0;} busInfo.buf[busId].txCount++; /*One more byte available in buffer*/} |
Adds a byte to the TX Buffer, and updates the buffer pointers.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable | |
b | Byte to add to the buffer |
#define busRemoveByteRxBuf | ( | busId | ) | { if((++busInfo.buf[busId].getRx)==busInfo.buf[busId].rxBufSize) {busInfo.buf[busId].getRx = 0;} busInfo.buf[busId].rxCount--; /*Update available data left in rx buffer*/} |
Gets a byte from the RX Buffer. The buffer pointers are NOT updated! After calling this function, the
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busRemoveByteTxBuf | ( | busId | ) | { if((++busInfo.buf[busId].getTx)==busInfo.buf[busId].txBufSize) {busInfo.buf[busId].getTx = 0;} busInfo.buf[busId].txCount--; /*Update available data left in tx buffer*/} |
Gets a byte from the TX Buffer. The buffer pointers are NOT updated! After calling this function, the
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busRxBufHasData | ( | busId | ) | (busInfo.buf[busId].rxCount != 0) |
Checks if the given bus's receive buffer contains data.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busRxBufNotFull | ( | busId | ) | (busInfo.buf[busId].rxCount != busInfo.buf[busId].rxBufSize) |
Checks if the given bus's receive buffer still has space - more space for adding data.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define BUSSTAT_ENABLED 0x80 |
The buffer is enabled
#define BUSSTAT_RX_OVERRUN 0x10 |
The transmit buffer has overrun. Must be cleared by the user with busStatClearOverrun() function.
#define BUSSTAT_TX_OVERRUN 0x01 |
The transmit buffer has overrun. Must be cleared by the user with busStatClearOverrun() function.
#define BUSSTAT_TXING 0x02 |
Indicates if this bus is currently transmitting. For interrupt driven buses, this means that a transmit interrupt can occur at any time. Checking this function should be performed in a critical section, so that no interrupt can occur while checking!
#define BUSSTAT_UDP_ENABLE 0x01 |
#define busStatClearOverrun | ( | busId | ) | (busInfo.stat[busId] &= (~(BUSSTAT_TX_OVERRUN | BUSSTAT_RX_OVERRUN)) ) |
Get the current status of this module. The following flags are cleared during this function:
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
#define busTxBufHasData | ( | busId | ) | (busInfo.buf[busId].txCount != 0) |
Checks if the given bus's transmit buffer contains data.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
typedef struct _BUS_BUFFER BUS_BUFFER |
Structure containing buffer data for a single bus.
The "txCount" member gives the number of entries currently contained in the buffer. It is also used to indicate when the buffer is emptey: txCount == 0.
To test if the buffer is full, check if txCount == txBufSize
DO NOT use putTx == putTx to test if buffer is empty! This will be true when the buffer is empty AND when it is full!
typedef struct _BUSES_INFO BUS_INFO |
Structure containing bus data.
enum BUSES |
void busInfoInit | ( | void | ) |
Initializes the busInfo structure with pointers to all buffers.
void busInit | ( | void | ) |
Initialization code.
void busNetInit | ( | void | ) |
Initialize bus network components
void busService | ( | BYTE | busId | ) |
Service the given bus. If our code has a section where it has to wait for the transmit buffer of a bus to be empties, it should call this function while waiting.
busId | The bus ID of the requested bus. Is a BUSID_XXX variable |
void busTask | ( | void | ) |
Must be called every couple of ms