3#include <zephyr/kernel.h>
4#include <zephyr/drivers/watchdog.h>
5#include <zephyr/sys/reboot.h>
6#include <zephyr/random/random.h>
14static int wdt_channel_id = -1;
15static const device *
const WDT = DEVICE_DT_GET(DT_ALIAS(watchdog0));
18void yield() { ::k_yield(); }
20uint64_t
millis_64() {
return static_cast<uint64_t
>(k_uptime_get()); }
21uint32_t micros() {
return k_ticks_to_us_floor32(k_uptime_ticks()); }
27 if (device_is_ready(WDT)) {
28 static wdt_timeout_cfg wdt_config{};
29 wdt_config.flags = WDT_FLAG_RESET_SOC;
32 wdt_config.window.max = 10000;
34 wdt_config.window.max = 2000;
36 wdt_channel_id = wdt_install_timeout(WDT, &wdt_config);
37 if (wdt_channel_id >= 0) {
40 options |= WDT_OPT_PAUSE_HALTED_BY_DBG;
43 options |= WDT_OPT_PAUSE_IN_SLEEP;
53 if (wdt_channel_id >= 0) {
54 wdt_feed(WDT, wdt_channel_id);
64 auto *mutex =
new k_mutex();
65 this->handle_ = mutex;
68Mutex::~Mutex() {
delete static_cast<k_mutex *
>(this->handle_); }
69void Mutex::lock() { k_mutex_lock(
static_cast<k_mutex *
>(this->handle_), K_FOREVER); }
70bool Mutex::try_lock() {
return k_mutex_lock(
static_cast<k_mutex *
>(this->handle_), K_NO_WAIT) == 0; }
71void Mutex::unlock() { k_mutex_unlock(
static_cast<k_mutex *
>(this->handle_)); }
79 sys_rand_get(data,
len);
85 mac[0] = ((NRF_FICR->DEVICEADDR[1] & 0xFFFF) >> 8) | 0xC0;
86 mac[1] = NRF_FICR->DEVICEADDR[1] & 0xFFFF;
87 mac[2] = NRF_FICR->DEVICEADDR[0] >> 24;
88 mac[3] = NRF_FICR->DEVICEADDR[0] >> 16;
89 mac[4] = NRF_FICR->DEVICEADDR[0] >> 8;
90 mac[5] = NRF_FICR->DEVICEADDR[0];
Providing packet encoding functions for exchanging data with a remote host.
uint32_t arch_get_cpu_cycle_count()
bool random_bytes(uint8_t *data, size_t len)
Generate len random bytes using the platform's secure RNG (hardware RNG or OS CSPRNG).
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
uint32_t arch_get_cpu_freq_hz()
uint32_t IRAM_ATTR HOT micros()
void get_mac_address_raw(uint8_t *mac)
Get the device MAC address as raw bytes, written into the provided byte array (6 bytes).
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()