Koduino
Public Member Functions | List of all members
BulkSerial Class Reference

Fixed length bulk serial data transfers using DMA. More...

#include <BulkSerial.h>

Detailed Description

Fixed length bulk serial data transfers using DMA.

No interrupts are used for either RX or TX, but the tradeoff is that the transfer length must be known beforehand. Since the DMA availability depends on the chip, this is only supported on some USARTSs, and the connections from USART to DMA must be hardcoded here.

Usage

TODO!

Example (on MBLC 0.5 to talk to the OpenLog)

#include <BulkSerial.h>
// Logging
BulkSerial openLog(MBLC_OPENLOG);
struct StateVector {
uint16_t align = 0xbbaa;//endianness reverses bytes to aabb
uint32_t t;
float x;
uint8_t bit;
} __attribute__ ((packed));
StateVector state;
void setup() {
openLog.begin(115200, sizeof(state), &state, 0);
openLog.initOpenLog("t,pi,bit", "IfB");
openLog.enable(true);
}
void loop() {
state.t = millis();
state.x = PI;
state.bit = 1;
openLog.write();
delay(10);
}

Example (on MBLC 0.5 to talk to the raspberry pi serial port)

#include <BulkSerial.h>
BulkSerial rpi(MBLC_RPI);
uint8_t txBuf[10]= {0xaa, 0xbb, 1, 2, 3, 4, 5, 6, 7, 8};
uint8_t rxBuf[10] = {0,0,0,0,0,0,0,0,0,0};
volatile uint32_t lastWrite = 0, lastRx = 0;
void controlLoop() {
uint32_t t = millis();
// this will print when it receives a full packet, aligned with {0xaa,0xbb}
int res = rpi.received(0xbbaa, rxBuf);
if (res) {
lastRx = t;
Serial1 << t << "\t";
for (int i=0; i<10; ++i) {
Serial1 << rxBuf[i] << "\t";
}
Serial1 << "\n";
}
if (t - lastWrite > 9) {
digitalWrite(PD0, TOGGLE);
rpi.write();//send the txBuf
lastWrite = t;
}
}
void setup() {
pinMode(PD0, OUTPUT);
Serial1.begin(115200);
rpi.begin(115200, 10, txBuf, 10);
rpi.enable(true);// this enables the transmit
attachTimerInterrupt(0, controlLoop, 1000);
}
void loop() {
}

Public Member Functions

 BulkSerial (const BulkSerialSettings &bss)
 Constructor needs a BulkSerialSettings instance. More...
 
void begin (uint32_t baud, uint16_t sizeTx, void *bufTx, uint16_t sizeRx)
 Call this in setup. More...
 
void enable (bool flag)
 TX can be disabled or enabled (default is disabled) More...
 
void write ()
 Sends the TX buffer.
 
int received (uint16_t alignment, uint8_t *dest)
 Flag to check if a new packet was received (call this often) More...
 
void initOpenLog (const char *header, const char *fmt)
 special function to init OpenLog before bulk transmits start More...
 

Constructor & Destructor Documentation

BulkSerial::BulkSerial ( const BulkSerialSettings bss)
inline

Constructor needs a BulkSerialSettings instance.

Use predefined MBLC_OPENLOG or MBLC_RPI for now

Member Function Documentation

void BulkSerial::begin ( uint32_t  baud,
uint16_t  sizeTx,
void *  bufTx,
uint16_t  sizeRx 
)

Call this in setup.

[long description]

Parameters
baudBaud rate
sizeTxSet 0 to disable TX, otherwise specify the packet size in bytes
bufTxPointer to TX struct (can pass NULL if sizeTx is 0)
sizeRxSet 0 to disable RX, otherwise specify the packet size in bytes
void BulkSerial::enable ( bool  flag)
inline

TX can be disabled or enabled (default is disabled)

This is to maintain compatibility with OpenLog functionality

Parameters
flagenable TX
void BulkSerial::initOpenLog ( const char *  header,
const char *  fmt 
)

special function to init OpenLog before bulk transmits start

Parameters
headersee OpenLog::init()
fmtsee OpenLog::init()
int BulkSerial::received ( uint16_t  alignment,
uint8_t *  dest 
)

Flag to check if a new packet was received (call this often)

Once this is called, the flag is reset, and will return

Parameters
alignmentalignment word (remember this is little endian!)
destcopies the received buffer here starting with alignment on success
Returns
1 when there is a new packet, 0 if not new, -1 if it failed to find the alignment

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