New Arduino Port of NIL

Discussions and support about ChibiOS/NIL, the almost nil RTOS.
wgreiman
Posts: 33
Joined: Sun Oct 23, 2011 3:21 pm
Been thanked: 2 times

New Arduino Port of NIL

Postby wgreiman » Mon Jan 16, 2017 9:43 pm

This is mainly a thank-you to Giovanni.

I decided to update my old Arduino port of NIL. An Arduino AVR library based on a recent trunk download is here.

I is very small. Here is a minimal NIL blink on ATmega328P Uno:

Code: Select all

// compare sizes - MinBlinkArduino vs MinBlinkChNil

#include "ChNil.h"
// Declare a stack with 64 bytes beyond context switch and interrupt needs.
THD_WORKING_AREA(waThread1, 64);

// Declare the thread function for thread 1.
THD_FUNCTION(Thread1, arg) {
  (void)arg;
  pinMode(LED_BUILTIN, OUTPUT); 
  bool level = true;
  while (TRUE) {
    digitalWrite(LED_BUILTIN, level = !level);
    chThdSleep(500);   
  }
}
// Threads static table, one entry per thread.  A thread's priority is
// determined by its position in the table with highest priority first.
THD_TABLE_BEGIN
  THD_TABLE_ENTRY(waThread1, "thread1", Thread1, NULL)
THD_TABLE_END

void setup() {
  chBegin();
}
void loop() {
}

The sizes:

Code: Select all

Sketch uses 1352 bytes (4%) of program storage space. Maximum is 32256 bytes.
Global variables use 179 bytes (8%) of dynamic memory, leaving 1869 bytes for local variables. Maximum is 2048 bytes.


Here is an equivalent Arduino program without the NIL thread.

Code: Select all

// compare sizes - MinBlinkArduino vs MinBlinkChNil

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}
bool level = true;
void loop() {
  digitalWrite(LED_BUILTIN, level = !level);
  delay(500);
}

Sizes:

Code: Select all

Sketch uses 930 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 11 bytes (0%) of dynamic memory, leaving 2037 bytes for local variables. Maximum is 2048 bytes.


Only 422 bytes added to run a thread!

I added a ADC read function like the Arduino analogRead() that sleeps while the ADC is busy. It saves over 100 microseconds for every read. The AVR ADC is slow!

So thanks again Giovanni.

User avatar
Giovanni
Site Admin
Posts: 10148
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 206 times
Been thanked: 184 times
Contact:

Re: New Arduino Port of NIL

Postby Giovanni » Tue Jan 17, 2017 8:41 am

Hi,

Great work, I am glad you introduced the new version.

Do you have an official homepage for your ports? I could link it from the ChibiOS home.

Giovanni


Return to “ChibiOS/NIL”

Who is online

Users browsing this forum: No registered users and 1 guest