avr: add ctrl Rx and Tx buffer functions
This commit is contained in:
parent
215ad57c2e
commit
56848df315
|
@ -29,15 +29,27 @@ cBuffer ctrlTxBuffer; // ctrl transmit buffer
|
||||||
static char ctrlRxData[CTRL_RX_BUFFER_SIZE];
|
static char ctrlRxData[CTRL_RX_BUFFER_SIZE];
|
||||||
static char ctrlTxData[CTRL_TX_BUFFER_SIZE];
|
static char ctrlTxData[CTRL_TX_BUFFER_SIZE];
|
||||||
|
|
||||||
void ctrlInit(void) {
|
void ctrlInit(void)
|
||||||
|
{
|
||||||
// initialize the CTRL receive buffer
|
// initialize the CTRL receive buffer
|
||||||
bufferInit(&ctrlRxBuffer, (u08*) ctrlRxData, CTRL_RX_BUFFER_SIZE);
|
bufferInit(&ctrlRxBuffer, (u08*) ctrlRxData, CTRL_RX_BUFFER_SIZE);
|
||||||
// initialize the CTRL transmit buffer
|
// initialize the CTRL transmit buffer
|
||||||
bufferInit(&ctrlTxBuffer, (u08*) ctrlTxData, CTRL_TX_BUFFER_SIZE);
|
bufferInit(&ctrlTxBuffer, (u08*) ctrlTxData, CTRL_TX_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ctrlAddToRxBuffer(uint8_t data) {
|
uint8_t ctrlTxBufferIsEmpty(void)
|
||||||
return bufferAddToEnd(&ctrlRxBuffer, data);
|
{
|
||||||
|
if(ctrlTxBuffer.datalength == 0) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ctrlAddToTxBuffer(uint8_t data)
|
||||||
|
{
|
||||||
|
return bufferAddToEnd(&ctrlTxBuffer, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ctrlGetFromTxBuffer(uint8_t* data) {
|
uint8_t ctrlGetFromTxBuffer(uint8_t* data) {
|
||||||
|
@ -53,15 +65,40 @@ uint8_t ctrlGetFromTxBuffer(uint8_t* data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ctrlAddToTxBuffer(uint8_t data) {
|
uint8_t ctrlRxBufferIsEmpty(void)
|
||||||
return bufferAddToEnd(&ctrlTxBuffer, data);
|
{
|
||||||
}
|
if(ctrlRxBuffer.datalength == 0) {
|
||||||
|
return TRUE;
|
||||||
void ctrlLoop(void) {
|
}
|
||||||
// source routing
|
else {
|
||||||
bufferAddToEnd(&ctrlTxBuffer, 'l');
|
return FALSE;
|
||||||
|
}
|
||||||
while (ctrlRxBuffer.datalength) {
|
}
|
||||||
bufferAddToEnd(&ctrlTxBuffer, bufferGetFromFront(&ctrlRxBuffer));
|
|
||||||
|
uint8_t ctrlAddToRxBuffer(uint8_t data)
|
||||||
|
{
|
||||||
|
return bufferAddToEnd(&ctrlRxBuffer, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ctrlGetFromRxBuffer(uint8_t* data)
|
||||||
|
{
|
||||||
|
// make sure we have data in the Rx buffer
|
||||||
|
if(ctrlRxBuffer.datalength) {
|
||||||
|
// get byte from beginning of buffer
|
||||||
|
*data = bufferGetFromFront(&ctrlRxBuffer);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// no data
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ctrlRxToTxLoop(void)
|
||||||
|
{
|
||||||
|
uint8_t data;
|
||||||
|
|
||||||
|
while (ctrlGetFromRxBuffer(&data)) {
|
||||||
|
ctrlAddToTxBuffer(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,18 +27,67 @@
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
#ifndef CTRL_RX_BUFFER_SIZE
|
#ifndef CTRL_RX_BUFFER_SIZE
|
||||||
#define CTRL_RX_BUFFER_SIZE 16
|
#define CTRL_RX_BUFFER_SIZE 32
|
||||||
#endif
|
#endif
|
||||||
#ifndef CTRL_TX_BUFFER_SIZE
|
#ifndef CTRL_TX_BUFFER_SIZE
|
||||||
#define CTRL_TX_BUFFER_SIZE 16
|
#define CTRL_TX_BUFFER_SIZE 32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the ctrl receive and transmit buffers.
|
||||||
|
*
|
||||||
|
* Overrule the default Rx and Tx ctrl buffer size (32 bytes) in the makefile.
|
||||||
|
*/
|
||||||
void ctrlInit(void);
|
void ctrlInit(void);
|
||||||
|
|
||||||
uint8_t ctrlAddToRxBuffer(uint8_t data);
|
/**
|
||||||
|
* Check whether the ctrl Tx buffer is empty.
|
||||||
uint8_t ctrlGetFromTxBuffer(uint8_t* data);
|
*
|
||||||
|
* @return TRUE/FALSE if empty/not empty
|
||||||
|
*/
|
||||||
|
uint8_t ctrlTxBufferIsEmpty(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a byte to the ctrl Tx buffer's tail.
|
||||||
|
*
|
||||||
|
* @param data the byte to be added to the buffer's tail
|
||||||
|
* @return TRUE/FALSE if byte could/could not be written
|
||||||
|
*/
|
||||||
uint8_t ctrlAddToTxBuffer(uint8_t data);
|
uint8_t ctrlAddToTxBuffer(uint8_t data);
|
||||||
|
|
||||||
void ctrlLoop(void);
|
/**
|
||||||
|
* Fetch a byte from the ctrl Tx buffer's head.
|
||||||
|
*
|
||||||
|
* @param data pointer where the byte has to be written
|
||||||
|
* @return TRUE/FALSE if a byte could be fetched/not fetched
|
||||||
|
*/
|
||||||
|
uint8_t ctrlGetFromTxBuffer(uint8_t* data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the ctrl Rx buffer is empty.
|
||||||
|
*
|
||||||
|
* @return TRUE/FALSE if empty/not empty
|
||||||
|
*/
|
||||||
|
uint8_t ctrlRxBufferIsEmpty(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a byte to the ctrl Rx buffer.
|
||||||
|
*
|
||||||
|
* @param data the byte to be added to the buffer's tail
|
||||||
|
* @return TRUE/FALSE if empty/not empty
|
||||||
|
*/
|
||||||
|
uint8_t ctrlAddToRxBuffer(uint8_t data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch a byte from the ctrl Rx buffer's head.
|
||||||
|
*
|
||||||
|
* @param data pointer where the byte has to be written
|
||||||
|
* @return TRUE/FALSE if a byte could be fetched/not fetched
|
||||||
|
*/
|
||||||
|
uint8_t ctrlGetFromRxBuffer(uint8_t* data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loop all bytes from the ctrl Rx to Tx buffer.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void ctrlRxToTxLoop(void);
|
||||||
|
|
Loading…
Reference in New Issue