Various improvements (#461)
* **New Features** * Time and delay utilities added (ticks, ms, µs); SD card now uses an expansion-header CS pin; HTTP downloads warn when run on the GUI task and yield to avoid blocking. * **Bug Fixes / Reliability** * Many hard-crash paths converted to guarded checks to reduce abrupt termination and improve stability. * **Tests** * Unit tests added to validate time and delay accuracy. * **Chores** * License header and build/macro updates.
This commit is contained in:
committed by
GitHub
parent
619b5aa53b
commit
e6abd496f9
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "Time.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <rom/ets_sys.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <Tactility/Check.h>
|
||||
#include "Tactility/FreeRTOS/FreeRTOS.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Delay the current task for the specified amount of ticks
|
||||
* @warning Does not work in ISR context
|
||||
*/
|
||||
static inline void delay_ticks(TickType_t ticks) {
|
||||
check(xPortInIsrContext() == pdFALSE);
|
||||
if (ticks == 0U) {
|
||||
taskYIELD();
|
||||
} else {
|
||||
vTaskDelay(ticks);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay the current task for the specified amount of milliseconds
|
||||
* @warning Does not work in ISR context
|
||||
*/
|
||||
static inline void delay_millis(uint32_t milliSeconds) {
|
||||
delay_ticks(millis_to_ticks(milliSeconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stall the currently active CPU core for the specified amount of microseconds.
|
||||
* This does not allow other tasks to run on the stalled CPU core.
|
||||
*/
|
||||
static inline void delay_micros(uint32_t microseconds) {
|
||||
#ifdef ESP_PLATFORM
|
||||
ets_delay_us(microseconds);
|
||||
#else
|
||||
usleep(microseconds);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user