arduino-pico/cores/rp2040/delay.cpp
Earle F. Philhower, III bda630e419
Add FreeRTOS support thanks to @hfellner (#533)
Using all the work from @hfellner and others, add FreeRTOS
SMP support.

Allow idling cores through the FreeRTOS FIFO queue to
allow for file system and EEPROM support.

Make delay a weak function so FreeRTOS can override.

Add cycle count support under FreeRTOS using a PIO SM.

Use a task-based approach for handling the USB periodic work
instead of the IRQ-based one in the main core.

Set 8 prio levels so it fits in 3 bits nicely (0..7).
2022-04-24 20:59:57 -07:00

65 lines
1.6 KiB
C++

/*
delay() for the Raspberry Pi Pico RP2040
Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <pico.h>
#include <pico/time.h>
#ifdef USE_TINYUSB
#include "Adafruit_TinyUSB_API.h"
#endif
extern "C" void delay(unsigned long ms) __attribute__((weak));
extern "C" void yield() __attribute__((weak));
extern "C"
{
void delay(unsigned long ms) {
if (!ms) {
return;
}
sleep_ms(ms);
}
void delayMicroseconds(unsigned int usec) {
if (!usec) {
return;
}
sleep_us(usec);
}
void yield() {
#ifdef USE_TINYUSB
TinyUSB_Device_Task();
TinyUSB_Device_FlushCDC();
#endif
}
uint32_t millis() {
return to_ms_since_boot(get_absolute_time());
}
uint32_t micros() {
return to_us_since_boot(get_absolute_time());
}
} // extern C