NilRTOS - A Fast Tiny Preemptive RTOS

I am using my own UNO, BTooth serial, sdfatlib20121217.zip and latest nilrtos from your repo.
Your pito.zip shows

!   C:\Documents and Settings\igi\Desktop\pito.zip: Unexpected end of archive

I downloaded pito.zip and extracted the libraries with 7-zip on a Windows 7 machine.

The contents diff OK.

Edit: I tried the Windows extractor and it works too.

firefox under xp has a problem to download it, IE8 did it .. :~
but still the same issue..
I'll try with usb serial dongle..
..the same..

fyi - this is the bench from the sdfat:

Type any character to start
Free RAM: 1019
Type is FAT32
File size 5MB
Buffer size 100 bytes
Starting write test.  Please wait up to a minute
Write 135.23 KB/sec
Maximum latency: 54924 usec, Minimum Latency: 88 usec, Avg Latency: 733 usec

Starting read test.  Please wait up to a minute
Read 284.79 KB/sec
Maximum latency: 4656 usec, Minimum Latency: 84 usec, Avg Latency: 345 usec

Done

Type any character to start

I opened the example from your lib and did only this change:
Serial.begin(115200);
..no luck..

Again - I took vanilla demo and run @9k6 (usb dongle, your libs from pito.zip, IDE 1.5.1r2, UNO 328p @16MHz):

type any character to begin
type any character to endþtype any character to begin
type any character to endþtype any character to begin
../nilFifoDataLogger.cpp.hex 
Binary sketch size: 13,546 bytes (of a 32,256 byte maximum)

ser.jpg

pito,

I can't reproduce your problem so I don't know what to do. I only do the Serial.begin(115200) change with 1.5.1r2 on an Uno and get.

type any character to begin
type any character to end
Done
Maximum SD write latency: 65008 usec
Unused Stack: 57 454

I get the same result with all line endings.

To see the performance of printField(), run the PrintBenchmark example with the new SdFat. You should get something like this:

Test of println(uint16_t)
Time 10.09 sec
File size 128.89 KB
Write 12.78 KB/sec
Maximum latency: 62460 usec, Minimum Latency: 176 usec, Avg Latency: 497 usec

Test of printField(uint16_t, char)
Time 3.26 sec
File size 128.89 KB
Write 39.60 KB/sec
Maximum latency: 67240 usec, Minimum Latency: 60 usec, Avg Latency: 156 usec

The two files are identical but printField() runs three times faster.

Edit: Try making the stack for thread 1 larger like this:

NIL_WORKING_AREA(waThread1, 100);
Type any character to start
Free RAM: 1109
Type is FAT32
Starting print test.  Please wait.

Test of println(uint16_t)
Time 9.97 sec
File size 128.89 KB
Write 12.93 KB/sec
Maximum latency: 20828 usec, Minimum Latency: 176 usec, Avg Latency: 491 usec

Test of printField(uint16_t, char)
Time 3.15 sec
File size 128.89 KB
Write 40.92 KB/sec
Maximum latency: 18748 usec, Minimum Latency: 60 usec, Avg Latency: 150 usec

Test of println(double)
Time 15.06 sec
File size 149.00 KB
Write 9.89 KB/sec
Maximum latency: 19160 usec, Minimum Latency: 572 usec, Avg Latency: 746 usec

Done!

Type any character to start

Edit: Try making the stack for thread 1 larger like this:
Code:
NIL_WORKING_AREA(waThread1, 100);

..no luck..

Do the other NilRTOS examples work?

I can't do anything more since everything I try works fine. I don't have a working xp system.

Edit: Here is one more idea. Change nilSysBegin() to nilSysBeginNoFill(). This will prevent filling stacks when NilRTOS starts so the final message will be wrong.

Change nilSysBegin() to nilSysBeginNoFill().

..the same issue..

other stuff ie.:
nilblink blinks

nilBlinkPrint:

Count: 628299, Unused Stack: 57 28 1663
Count: 628306, Unused Stack: 57 28 1663
Count: 628304, Unused Stack: 57 28 1663
Count: 628302, Unused Stack: 57 28 1663

nilSemTest:

micros overhead = 4
sem switch tasks micros = 28
Thd1 Done
sem immediate timeout = 4
sem immediate OK = 4
Thd2 Done

It may be a problem with Serial.read(). nilFifoDataLogger is the only example with Serial.read().

I have tried many Arduino boards and two Windows 7 computers with no problem.

Load the nilTemplate1 example and put the following at the beginning of loop() like this.

void loop() {
  int c = Serial.read();
  if (c < 0) return;
  Serial.print((char)c);
  return;

Run the example and type one or two characters into the serial monitor and see if they are echoed.

Also run nilFifoDataLogger with no SD card and see if this prints:

type any character to begin
SD problem
SD errorCode: 0X1,0X0

Also run nilFifoDataLogger with no SD card and see if this prints:
Quote
type any character to begin
SD problem
SD errorCode: 0X1,0X0

type any character to begin
SD problem
SD errorCode: 0X1,0X0

Yes they are echoed (after pushing Send):

33
54
pito
Q

:slight_smile:

type any character to begin
type any character to end
Done
Unused Stack: 141 342

** overrun errors **

with:

// SD chip select pin.
const uint8_t sdChipSelect = 10; //SS;

pito,

Could you put a continue statement in thread 1 like this so no data is taken.

  while (1) {
    // Sleep until time for next data point
    nilThdSleep(intervalTicks);
    continue;

Let me know what happens.

type any character to begin
type any character to end
Done
Unused Stack: 141 445

data.csv is 0kB

No idea what is the issue, with "continue" it always works, with "//continue" it sometimes works, sometimes does not.

How was this run? Was any data recorded?

type any character to begin
type any character to end
Done
Unused Stack: 141 342

** overrun errors **

with:
Code:

// SD chip select pin.
const uint8_t sdChipSelect = 10; //SS;

The output is from the old example. It should look like this from today's pito.zip file.

type any character to begin
type any character to end
Done
Maximum SD write latency: 3748 usec
Unused Stack: 57 407

Yes, when ran the old one I got csv data (100-200kB).

I cannot get it working with the new version yet.. Still the same issue, with =10 or =SS.. It works with "continue;" only:

type any character to begin
type any character to end
Done
Maximum SD write latency: 0 usec
Unused Stack: 57 480

No idea what to do in order to get it working..

With new one I get now this

type any character to begin
type any character to end
Done
Maximum SD write latency: 48548 usec
Unused Stack: 141 372

with:

// Read ADC data.
    p->value = 555; //analogRead(0);

Strange..

It seems this does the trick (the original example, 115k2) :

void setup() {

  Serial.begin(115200);
  
  analogReference(INTERNAL);

:cold_sweat:

type any character to begin
type any character to end
Done
Maximum SD write latency: 19736 usec
Unused Stack: 57 456
NA	252	0
1024	41	0
1024	47	0
1024	48	0
1024	46	0
1024	45	0
1024	36	0
1024	33	0

I need to think about this. I don't touch the ADC stuff.

I must go out with my wife now.

Another issue I've found - I have to use:

struct FifoItem_t {
  uint16_t usec;        // Low 16-bit of time in usec.
  uint16_t value;  // ADC value.
  uint8_t error;   // Overrun count since last point.
};

otherwise the adc value read is not correctly passed to p->value. It seems our compiler has got a problem with passing values to bitfields ..