#include <cmsis_os2.h>
struct Reading {
uint32_t time_ms;
uint32_t millivolts;
};
osMessageQueueId_t readings;
void blinkThread(void*) {
for (;;) {
osDelay(100);
osDelay(900);
}
}
void sampleThread(void*) {
uint32_t wake = osKernelGetTickCount();
for (;;) {
if (osMessageQueuePut(readings, &r, 0, 0) != osOK) {
Serial.println(
"Queue full: reading dropped");
}
wake += 100;
osDelayUntil(wake);
}
}
char kernel[32];
osKernelGetInfo(nullptr, kernel, sizeof(kernel));
readings = osMessageQueueNew(20, sizeof(Reading), nullptr);
osThreadAttr_t blink = {};
blink.name = "blink";
blink.stack_size = 1024;
osThreadNew(blinkThread, nullptr, &blink);
osThreadAttr_t sample = {};
sample.name = "sample";
sample.stack_size = 2048;
sample.priority = osPriorityAboveNormal;
osThreadNew(sampleThread, nullptr, &sample);
}
Reading r;
if (osMessageQueueGet(readings, &r, nullptr, osWaitForever) == osOK) {
}
}
@ OUTPUT
Definition Common.h:40
@ HIGH
Definition Common.h:32
@ LOW
Definition Common.h:31
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
uint32_t analogReadMillivolts(pin_size_t pin)
Reads an analog pin as a voltage, whatever its ADC and full scale.
void digitalWrite(pin_size_t pinNumber, PinStatus status)
Sets an output pin HIGH (3.3 V) or LOW (0 V).
void pinMode(pin_size_t pinNumber, PinMode pinMode)
Sets a pin as an input or an output.
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.
#define LED_BUILTIN
On-board LED.
Definition pins_arduino.h:63