NS.One RTOS Blink LED dan Serial

Berikut adalah sebuah contoh aplikasi NS.One RTOS, dimana blink LED dan pengiriman data melalui serial, ditangani oleh dua thread yang berbeda.

#include <ChibiOS_AVR.h>

static WORKING_AREA(waThread1, 16);

static msg_t Thread1(void *arg) {

  pinMode(30, OUTPUT);
  while (1) {
    digitalWrite(30, HIGH);
    chThdSleepMilliseconds(250);
    digitalWrite(30, LOW);
    chThdSleepMilliseconds(250);
  }
  return 0;
}

static WORKING_AREA(waThread2, 64);
static msg_t Thread2(void *arg) {

  while (1) {
    chThdSleepMilliseconds(1000);
    Serial.println(F("Hello"));
  }
}

void setup() {

  Serial.begin(9600);
  chBegin(mainThread);
  while(1) {}
}

void mainThread() {

  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 2, Thread1, NULL);
  chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO + 1, Thread2, NULL);

  while (1) {
  }
}

void loop() {
 // not used
}