Go Down

Topic: Nil RTOS update - Fast and Tiny! (Read 30652 times) previous topic - next topic

pito

#30
Aug 24, 2013, 09:37 pm Last Edit: Aug 24, 2013, 09:44 pm by pito Reason: 1
This is how I did the error states handling inside a thread. The thread starts based on a signal from CLI. Is there any better option how to handle the error states within a Nilrtos thread?
Code: [Select]
// Declare the thread function
NIL_THREAD(SdBench, arg) {
while (TRUE) {
// Wait for signal from CLI
nilSemWait(&sdbench);

// initialize the SD card at SPI_FULL_SPEED for best performance.
// try SPI_HALF_SPEED if bus errors occur.
if (!sd.begin(chipSelect, SPI_FULL_SPEED)) {
error("\nsd.init failed");
goto thrdend1;
}
..
// open or create file - truncate existing file.
if (!file.open("BENCH.DAT", O_CREAT | O_TRUNC | O_RDWR)) {
error("open failed");
goto thrdend1;
}
..
for (uint32_t i = 0; i < n; i++) {
uint32_t m = micros();
if (file.write(buf, sizeof(buf)) != sizeof(buf)) {
error("write failed");
goto thrdend1;
}
..
for (uint32_t i = 0; i < n; i++) {
buf[BUF_SIZE-1] = 0;
uint32_t m = micros();
if (file.read(buf, sizeof(buf)) != sizeof(buf)) {
error("read failed");
goto thrdend1;
}
..
if (buf[BUF_SIZE-1] != '\n') {
error("data check");
goto thrdend1;
}
..
thrdend1: file.close();
}     // This is the While ()
}   // This is the NIL_THREAD()


PS: Plz do not discuss goto here.. :)

fat16lib

Quote
The issue is they use SdFat and Sd2Card


SdInfo was meant to be a standalone diagnostic so I didn't use the SdFat class which wraps Sd2Card, SdVolume, and the root file.

I wanted to first initialize the SD card and get info that didn't depend on the card format.  I then initialize SdVolume and check the format.

You probably have two copies of SdVolume.  Surprised it works.

Quote
STACK
Stack Sizes: 197 85 85 101 101 85 117 85 117 197 85 197 165 197 197 309 309 10107
Unused Stack: 165 55 55 47 49 55 87 55 87 58 55 167 41 71 167 192 50 9995

Looks like you are going beyond the design thread count for Nil.   I removed this when I made the thread count dynamic.
Code: [Select]

#if NIL_CFG_NUM_THREADS > 12
#error "Nil is not recommended for thread-intensive applications, consider" \
       "ChibiOS/RT instead"
#endif

Nil uses very simple algorithms for scheduling that involve scanning tables.  ChibiOS uses more conventional linked lists to order objects for more efficiency when there are many objects.  This also allows dynamic priorities and priority inheritance for a mutex.

Quote

Is there any better option how to handle the error states within a Nilrtos thread?

Alarms, events, and logging are major components of large embedded systems.  Usually there is an API for threads to communicate with this module using something like mail boxes.  Error messages are logged and displayed for operators.  Operators can acknowledge errors and reply to threads.

Here are two links that illustrate the scale of this subsystem.

An old link to FANL which had the Tevatron http://www-ad.fnal.gov/controls/micro_p/errlog.html#ch-2

A newer link for an LHC experiment at CERN http://iopscience.iop.org/1742-6596/396/1/012038/pdf/1742-6596_396_1_012038.pdf

Quote
BTW the FreeRam() does not work under Nil well.

That's why Stack Size and Unused Stack exist in Nil. 

pito

#32
Aug 25, 2013, 03:20 am Last Edit: Aug 25, 2013, 03:23 am by pito Reason: 1
Here is the NIL_CFG_NUM_THREADS at the default level (2).. Surprised how well the stuff work..

pito

#33
Aug 28, 2013, 11:06 am Last Edit: Aug 28, 2013, 02:41 pm by pito Reason: 1
Q2: when I print out the cnt_t of my semaphores (semaphores initiated to 0 and not signaled), I get -1 as the result
Quote
..
SEMAPHORE_DECL(sdlog, 0);
..
// Declare the thread function
NIL_THREAD(SdLog, arg) {
   while (TRUE) {
      nilSemWait(&sdlog);
..

Code: [Select]
..
Serial.print("sdlog = ");
Serial.println(nilSemGetCounter(&sdlog));
..
sdlog = -1

Is that ok?

Thanks.

fat16lib

#34
Aug 28, 2013, 03:06 pm Last Edit: Aug 28, 2013, 03:09 pm by fat16lib Reason: 1
Code: [Select]

  nilSemWait(&sdlog);

Makes the count -1.

Quote

A counting semaphore is a synchronization object that can have an arbitrarily large number of states. The internal state is defined by a signed integer variable, the counter. The counter value (N) has a precise meaning:

   Negative, there are exactly -N threads queued on the semaphore.
   Zero, no waiting threads, a wait operation would put in queue the invoking thread.
   Positive, no waiting threads, a wait operation would not put in queue the invoking thread.

Two operations are defined for counting semaphores:

    Wait (chSemWait() in ChibiOS/RT). This operation decreases the semaphore counter, if the result is negative then the invoking thread is queued.

    Signal (chSemSignal() in ChibiOS/RT). This operation increases the semaphore counter, if the result is non-negative then a waiting thread is removed from the queue and resumed.


pito

There are some updates related to Nilrtos at chibios.org - do you plan an update too?

fat16lib

Quote
There are some updates related to Nilrtos at chibios.org - do you plan an update too?


I plan to port the new version.  This will actually be a large change.

Quote

the convergence process between Nil (now ChibiOS/NIL) and ChibiOS/RT is almost complete. Nil gained events and the API now is almost equal to the ChibiOS/RT API.

Now Nil has been integrated in the ChibiOS 3.0 development branch and is able to use the full HAL, the very same HAL used by ChibiOS/RT.

Starting from ChibiOS 3.0 Nil will be included in the same releases of the other products:
1) ChibiOS/RT
2) ChibiOS/NIL
3) ChibiOS/HAL

Added to Nil:
1) Support for stack checking.
2) Events.
3) Port to M3/M4.
4) Simplified task declaration macros.
5) Demos for F0/F3 Discovery boards.
6) Strong commonality with ChibiOS/RT API and ports (very few differences in port files).


I will be be away for the last two weeks in September so I will start work on the new Nil in October.

vysocan

Great work fat16lib. I'm building home security system based on 644P and I hope I can create the software on top of NIl. I will be using serial 485 communication between nodes, 8 ADC, 6 Digital, GSM SMS, maybe ethernet, radio ... long run :).

Now and than I try your examples and also read the forum here. So far I'm getting away from my mistakes and not very good C. But what bothers me, is some of my threads stop working after some time and unused stack of other threads suddenly goes to 0. Do you have some advice?

Go Up