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()); }
23void delay(uint32_t ms) { ::k_msleep(ms); }
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);
66 auto *mutex =
new k_mutex();
67 this->handle_ = mutex;
70Mutex::~Mutex() {
delete static_cast<k_mutex *
>(this->handle_); }
71void Mutex::lock() { k_mutex_lock(
static_cast<k_mutex *
>(this->handle_), K_FOREVER); }
72bool Mutex::try_lock() {
return k_mutex_lock(
static_cast<k_mutex *
>(this->handle_), K_NO_WAIT) == 0; }
73void Mutex::unlock() { k_mutex_unlock(
static_cast<k_mutex *
>(this->handle_)); }
84 sys_rand_get(data,
len);
90 mac[0] = ((NRF_FICR->DEVICEADDR[1] & 0xFFFF) >> 8) | 0xC0;
91 mac[1] = NRF_FICR->DEVICEADDR[1] & 0xFFFF;
92 mac[2] = NRF_FICR->DEVICEADDR[0] >> 24;
93 mac[3] = NRF_FICR->DEVICEADDR[0] >> 16;
94 mac[4] = NRF_FICR->DEVICEADDR[0] >> 8;
95 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 number of random bytes.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
uint32_t arch_get_cpu_freq_hz()
uint32_t IRAM_ATTR HOT micros()
uint32_t random_uint32()
Return a random 32-bit unsigned integer.
uint16_t progmem_read_uint16(const uint16_t *addr)
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()
uint8_t progmem_read_byte(const uint8_t *addr)