My many OS2 projects use the ‘BufferedSerial’ library by Sam Grove. This does what I need perfectly - interrupt driven serial, 100% reliable.
I can not use this in OS6 it seems, and whether I use BufferedSerial or UnbufferedSerial, the code is blocking. Code blocks until the last Tx char has been sent. No good. I need to implement an interrupt driven handler for Tx data at very least. To that end, I looked at ‘sigio’, the scant, terse documentation leading me to think this is used to direct serial interrupts to a handler of my own design. So please help, what’s wrong with the following, or what other methods should I look at instead.
This code does not compile,
[Error] main.cpp@31,34: expected ‘(’ for function-style cast or type construction
[ERROR] ./main.cpp:31:34: error: expected ‘(’ for function-style cast or type construction
but several hours fighting syntax - wasted.
#include "mbed.h"
BufferedSerial pc(USBTX, USBRX);
void pc_Service () {
// Need Tx and Rx interrupt redirecting to here
}
int main()
{
pc.set_blocking(false); // Not convinced this has any effect.
/*
virtual void sigio ( Callback< void()> func )
virtualinherited
Register a callback on state change of the file.
The specified callback will be called on state changes such as when the file can be written to or read from.
The callback may be called in an interrupt context and should not perform expensive operations.
Note! This is not intended as an attach-like asynchronous API, but rather as a building block for constructing such functionality.
The exact timing of when the registered function is called is not guaranteed and is susceptible to change. It should be used as a cue to make read/write/poll calls to find the current state.
Parameters
func Function to call on state change
*/
pc.sigio ( Callback< void()> pc_Service );
printf("This is the bare metal blinky example running on Mbed OS %d.%d.%d.\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
// Set desired properties (9600-8-N-1).
while (1) {
}
}