#include <krnl.h>
// CPU needs code, data and stak
//            ++    ++       |--- supplied by you

char s1[100], s2[100], s3[100];
struct k_t  *pT1, *pT2, *pT3;

volatile int loopCnt = 0, temp = 0,isrTick=0;

void AD()
{
}
void DA()
{
}
void controlAlg()
{
}

void task1()  // might be high priority duty
{
  while (1) {
    loopCnt++;
    k_sleep(10);
    AD();

    if (10 * (loopCnt / 10) == loopCnt) {
      temp += 2;
      if (100 < temp)
        temp = 0;
    }
    controlAlg();
    DA();
  }
}

void task2()
{
  while (1) {
  }
}

void task3()
{
  while (1) {
    k_sleep(100);
    Serial.print("status ");
    Serial.print(temp);
    Serial.print(" ");
    Serial.print(loopCnt);
    Serial.print(" noOfInterrupts ");
    Serial.println(isrTick);
  }
}

void anInterruptRoutine()
{
  isrTick++;
}

void setup() {
  // put your setup code here, to run once:

  int err;
  // put your main code here, to run repeatedly:

  // initialization part
  Serial.begin(9600);
  pinMode(2,OUTPUT);
  digitalWrite(2, HIGH);
  
  attachInterrupt(0,anInterruptRoutine, FALLING);
  
  k_init(3, 0, 0);
  pT1 = k_crt_task(task1,  8, s1, 100);
  pT2 = k_crt_task(task2, 10, s2, 100);
  pT3 = k_crt_task(task3, 10, s3, 100);

  err = k_start(10);  // tick speed equals 10 milliseconds
  Serial.print("en error ocurred ");
  Serial.println(err);
}

void loop() {} // always empty but needed bq of compiler

