/*
* TEMPLATE : master slave sync
* ----------------------------
* task2masterslaverandom illustrates the synchronization by use of
* a standard semaphore. 
* task1 issues a signal (kick) to semaphore pSem1 every loop
* task1 sleeps in the loop based on a random scheme
* task2 wait on the kick - but will wait no more than 10 ticks
* Jens
*/
#include <snot.h>

struct k_t *pTask1, *pTask2, *pSem1;

char stak1[200];
char stak2[200];

void task1()
{
  while (1) {
    k_signal(pSem1);
    k_sleep(random(10,30)); // sleep 10-30 ticks
  }
}

void task2()
{ 
  while(1) {
    // wait for kick but only up to 10 ticks
    if (0 == k_wait(pSem1,10)) {
      Serial.println("got kick");
    }
    else {
      Serial.println("timeout");
    }
  }
}

void setup()
{
  Serial.begin(9600);
  
  k_init(2,2,0);

  pTask1 = k_crt_task(task1,10,stak1,200);
  pTask2 = k_crt_task(task2,10,stak2,200);

  pSem1 = k_crt_sem(0,10);
 

  k_start(100); // 100 milli sec tick speed
  // returning from k_start means SNOT  couldnt start
}

void loop() {/* not used */
}



