Page 1 of 1

New Arduino Port of NIL  Topic is solved

Posted: Mon Jan 16, 2017 9:43 pm
by wgreiman
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.

Re: New Arduino Port of NIL

Posted: Tue Jan 17, 2017 8:41 am
by Giovanni
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