Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
SchedulerBenchmarkChannel.ino
Go to the documentation of this file.
1 
28 #include <Scheduler.h>
29 #include <Scheduler/Channel.h>
30 
31 // Check for SparkFun SAMD21 Breakout
32 #if defined(ARDUINO_ARCH_SAMD) && (USB_PID == 0x8D21)
33 #define Serial SerialUSB
34 #endif
35 
36 // const size_t PAYLOAD_MAX = 1;
37 const size_t PAYLOAD_MAX = 8;
38 struct msg_t {
39  uint8_t payload[PAYLOAD_MAX];
40 };
41 
43 unsigned long count = 0;
44 
45 void setup()
46 {
47  Serial.begin(57600);
48  while (!Serial);
49  Serial.println(F("SchedulerBenchmarkChannel: started"));
50  Serial.flush();
51 
54 }
55 
56 void loop()
57 {
58  unsigned long start = millis();
59  await(millis() - start >= 1000);
60  Serial.print(count);
61  Serial.print(F(" ("));
62  Serial.print(1000000.0 / count);
63  Serial.println(F(" us)"));
64  Serial.flush();
65  count = 0;
66 }
67 
68 void producer()
69 {
70  msg_t msg;
71  while (1)
72  chan.send(&msg, sizeof(msg));
73 }
74 
75 void consumer()
76 {
77  msg_t msg;
78  while (1) {
79  chan.recv(&msg, sizeof(msg));
80  count += 1;
81  }
82 }
void consumer()
int recv(void *buf, size_t size)
Definition: Channel.h:71
static bool startLoop(func_t taskLoop, size_t stackSize=DEFAULT_STACK_SIZE)
Definition: Scheduler.h:65
#define await(cond)
Definition: Scheduler.h:162
uint8_t payload[PAYLOAD_MAX]
const size_t PAYLOAD_MAX
Channel chan
int send(const void *buf, size_t size)
Definition: Channel.h:46
void producer()
unsigned long count
SchedulerClass Scheduler
Definition: Scheduler.cpp:53