greiman / nilrtos-arduino Goto Github PK
View Code? Open in Web Editor NEWA tiny RTOS for Arduino AVR boards
A tiny RTOS for Arduino AVR boards
Hi,
I hope you can help. I have a thread that monitors incoming serial communications but it only reads 3 characters - the first 2 and the last one.
For instance, if I enter 123456 and press send in the arduino serial monitor, I get this:
----------------------SerialIn = 126
The arduino library code in Hardware.h/.cpp *works( as expected.
I have looked at the code for Serial.read. It seems pretty straightforward and just gets a character from the USB data register.
/**
* Unbuffered read
* @return -1 if no character is available or an available character.
*/
int NilSerialClass::read() {
if (UCSR0A & (1 << RXC0)) return UDR0;
return -1;
}
I have tried with different baud rates (down to 2400) with no change in behaviour.
Here is the code: (comment out the #define in line 2 to use default, working Serial implementation)
#include <NilSerial.h>
#define Serial NilSerial
char buffer[11];
int offset;
void setup()
{
Serial.begin(115200);
offset = 0;
memset(buffer, 0, sizeof(buffer));
}
void loop()
{
int value = Serial.read();
if (value == -1)
{
if (offset)
{
Serial.print("SerialIn");
Serial.println(buffer);
offset = 0;
memset(buffer, 0, sizeof(buffer));
}
// nilThdSleep(1);
}
else
{
//psPrintf(Serial, "X");
buffer[offset++] = value;
}
}
I'm now stuck. Any help would be appreciated.
Regards,
Mark
On 1.8.0 IDE on UNO:
On this fragment:
SEMAPHORE_DECL(semRGB, 0);
...
NIL_THREAD(ThreadRGB, arg) {
while (true) {
static systime_t WaitMillis = 10;
msg_t semmsg = nilSemWaitTimeout(&semRGB, WaitMillis);
if (semmsg == NIL_MSG_TMO) {
...
} else { // got signaled
...
}
}
... on timeout conditions never enters the if true block. semmsg prints out as 0, which I take is NIL_MSG_OK. The elapsed time of the requested timeout is correct.
As such one cannot distinguish between a timeout and receiving a message as per the documentation:
/**
the following special values are allowed:
- @a TIME_IMMEDIATE immediate timeout.
- @a TIME_INFINITE no timeout.
.
released from the semaphore.
semaphore has been signaled.
the specified timeout.
nilSysLock();
msg = nilSemWaitTimeoutS(sp, timeout);
nilSysUnlock();
return msg;
}
There is evidence that the semiphore/task system is set up properly as
nilSemWait() properly fires when signaled.
Is there a reference manual that is generated by these headers?
I find the online reference here: http://chibios.sourceforge.net/docs3/nil/structnil__semaphore.html
confusing because it reads like a mashup of Chibi and NIL, with many references to ch
prefixed items.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.