Pages: 1 2 [3]   Go Down
Author Topic: Nil RTOS update - Fast and Tiny!  (Read 6729 times)
0 Members and 1 Guest are viewing this topic.
Rapa Nui
Offline Offline
Edison Member
*
Karma: 52
Posts: 1990
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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.. smiley
« Last Edit: August 24, 2013, 02:44:53 pm by pito » Logged

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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. 
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 52
Posts: 1990
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the NIL_CFG_NUM_THREADS at the default level (2).. Surprised how well the stuff work..
« Last Edit: August 24, 2013, 08:23:28 pm by pito » Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 52
Posts: 1990
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
..
Serial.print("sdlog = ");
Serial.println(nilSemGetCounter(&sdlog));
..
sdlog = -1
Is that ok?

Thanks.
« Last Edit: August 28, 2013, 07:41:35 am by pito » Logged

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  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.

« Last Edit: August 28, 2013, 08:09:44 am by fat16lib » Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 52
Posts: 1990
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Brno@Czech Republic
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley.
 
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?
Logged

Pages: 1 2 [3]   Go Up
Jump to: