avr: add ctrl Rx and Tx buffer functions

This commit is contained in:
Bart Van Der Meerssche 2010-10-16 21:25:57 +02:00
parent 215ad57c2e
commit 56848df315
2 changed files with 105 additions and 19 deletions

View File

@ -29,15 +29,27 @@ cBuffer ctrlTxBuffer; // ctrl transmit buffer
static char ctrlRxData[CTRL_RX_BUFFER_SIZE];
static char ctrlTxData[CTRL_TX_BUFFER_SIZE];
void ctrlInit(void) {
void ctrlInit(void)
{
// initialize the CTRL receive buffer
bufferInit(&ctrlRxBuffer, (u08*) ctrlRxData, CTRL_RX_BUFFER_SIZE);
// initialize the CTRL transmit buffer
bufferInit(&ctrlTxBuffer, (u08*) ctrlTxData, CTRL_TX_BUFFER_SIZE);
}
uint8_t ctrlAddToRxBuffer(uint8_t data) {
return bufferAddToEnd(&ctrlRxBuffer, data);
uint8_t ctrlTxBufferIsEmpty(void)
{
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) {
@ -53,15 +65,40 @@ uint8_t ctrlGetFromTxBuffer(uint8_t* data) {
}
}
uint8_t ctrlAddToTxBuffer(uint8_t data) {
return bufferAddToEnd(&ctrlTxBuffer, data);
}
void ctrlLoop(void) {
// source routing
bufferAddToEnd(&ctrlTxBuffer, 'l');
while (ctrlRxBuffer.datalength) {
bufferAddToEnd(&ctrlTxBuffer, bufferGetFromFront(&ctrlRxBuffer));
uint8_t ctrlRxBufferIsEmpty(void)
{
if(ctrlRxBuffer.datalength == 0) {
return TRUE;
}
else {
return FALSE;
}
}
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);
}
}

View File

@ -27,18 +27,67 @@
#include "buffer.h"
#ifndef CTRL_RX_BUFFER_SIZE
#define CTRL_RX_BUFFER_SIZE 16
#define CTRL_RX_BUFFER_SIZE 32
#endif
#ifndef CTRL_TX_BUFFER_SIZE
#define CTRL_TX_BUFFER_SIZE 16
#define CTRL_TX_BUFFER_SIZE 32
#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);
uint8_t ctrlAddToRxBuffer(uint8_t data);
uint8_t ctrlGetFromTxBuffer(uint8_t* data);
/**
* Check whether the ctrl Tx buffer is empty.
*
* @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);
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);