#include <mbed.h>
#include "rtos.h"
using namespace mbed;
using namespace rtos;
Thread t1;
Thread t2;
Thread t3;
Thread t4;
#define MASTER_FLAG (1UL << 0)
#define SLAVE1_FLAG (1UL << 1)
#define SLAVE2_FLAG (1UL << 2)
EventFlags flags;
void setup() {
// put your setup code here, to run once:
Serial1.begin(115200);
Serial1.println("Hello, Raspberry Pi Pico!");
t1.start(Master);
t2.start(Slave1);
t3.start(Slave2);
pinMode(1, OUTPUT);
t4.start(Task4);
}
#define DELAY 500
unsigned long runTime=millis()+DELAY;
void loop() {
// put your main code here, to run repeatedly:
delay(1); // this speeds up the simulation
if (runTime<=millis())
{
runTime+=DELAY;
flags.set(MASTER_FLAG);
}
}
unsigned count=0;
void Master()
{
while(1)
{
//Thread::wait(500);
flags.wait_any(MASTER_FLAG);
flags.set(SLAVE1_FLAG | SLAVE2_FLAG);
Serial1.print("\nMaster Thread - ");
Serial1.println(++count);
digitalWrite(1,!digitalRead(1));
}
}
void Slave1()
{
while(1)
{
flags.wait_any(SLAVE1_FLAG);
Serial1.print("Slave1 thread - ");
Serial1.println(++count);
}
}
void Slave2()
{
while (1)
{
flags.wait_any(SLAVE2_FLAG);
Serial1.print("Slave2 thread - ");
Serial1.println(++count);
}
}
void Task4()
{
while(1)
{
delay(207);
Serial1.println("Task4");
}
}