11typedef uint8_t osal_semaphore_def_t;
12typedef uint8_t osal_mutex_def_t;
14typedef FuriSemaphore* osal_semaphore_t;
15typedef FuriMutex* osal_mutex_t;
16typedef FuriMessageQueue* osal_queue_t;
23#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
24 osal_queue_def_t _name = {.depth = _depth, .item_sz = sizeof(_type)}
26FURI_ALWAYS_INLINE
static inline uint32_t _osal_ms2tick(uint32_t msec) {
27 if(msec == OSAL_TIMEOUT_WAIT_FOREVER) {
28 return FuriWaitForever;
34 uint32_t ticks = furi_ms_to_ticks(msec);
44FURI_ALWAYS_INLINE
static inline uint32_t osal_time_millis(
void) {
45 return furi_get_tick();
48FURI_ALWAYS_INLINE
static inline void osal_task_delay(uint32_t msec) {
52#define OSAL_SPINLOCK_DEF(_name, _int_set) osal_spinlock_t _name
54typedef UBaseType_t osal_spinlock_t;
56FURI_ALWAYS_INLINE
static inline void osal_spin_init(osal_spinlock_t* ctx) {
60FURI_ALWAYS_INLINE
static inline void osal_spin_lock(osal_spinlock_t* ctx,
bool in_isr) {
69FURI_ALWAYS_INLINE
static inline void osal_spin_unlock(osal_spinlock_t* ctx,
bool in_isr) {
78FURI_ALWAYS_INLINE
static inline osal_semaphore_t
79 osal_semaphore_create(osal_semaphore_def_t* semdef) {
81 return furi_semaphore_alloc(1, 0);
84FURI_ALWAYS_INLINE
static inline bool osal_semaphore_delete(osal_semaphore_t semd_hdl) {
85 furi_semaphore_free(semd_hdl);
89FURI_ALWAYS_INLINE
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl,
bool in_isr) {
91 FuriStatus stat = furi_semaphore_release(sem_hdl);
92 return (stat == FuriStatusOk);
95FURI_ALWAYS_INLINE
static inline bool
96 osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) {
97 FuriStatus stat = furi_semaphore_acquire(sem_hdl, _osal_ms2tick(msec));
98 return (stat == FuriStatusOk);
101FURI_ALWAYS_INLINE
static inline void osal_semaphore_reset(osal_semaphore_t
const sem_hdl) {
102 furi_semaphore_acquire(sem_hdl, 0);
105FURI_ALWAYS_INLINE
static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) {
107 return furi_mutex_alloc(FuriMutexTypeNormal);
110FURI_ALWAYS_INLINE
static inline bool osal_mutex_delete(osal_mutex_t mutex_hdl) {
111 furi_mutex_free(mutex_hdl);
115FURI_ALWAYS_INLINE
static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec) {
116 FuriStatus stat = furi_mutex_acquire(mutex_hdl, _osal_ms2tick(msec));
117 return (stat == FuriStatusOk);
120FURI_ALWAYS_INLINE
static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) {
121 FuriStatus stat = furi_mutex_release(mutex_hdl);
122 return (stat == FuriStatusOk);
125FURI_ALWAYS_INLINE
static inline osal_queue_t osal_queue_create(
osal_queue_def_t* qdef) {
126 return furi_message_queue_alloc(qdef->depth, qdef->item_sz);
129FURI_ALWAYS_INLINE
static inline bool osal_queue_delete(osal_queue_t qhdl) {
130 furi_message_queue_free(qhdl);
134FURI_ALWAYS_INLINE
static inline bool
135 osal_queue_receive(osal_queue_t qhdl,
void* data, uint32_t msec) {
136 FuriStatus stat = furi_message_queue_get(qhdl, data, _osal_ms2tick(msec));
137 return (stat == FuriStatusOk);
140FURI_ALWAYS_INLINE
static inline bool
141 osal_queue_send(osal_queue_t qhdl,
void const* data,
bool in_isr) {
143 FuriStatus stat = furi_message_queue_put(qhdl, data, in_isr ? 0 : FuriWaitForever);
144 return (stat == FuriStatusOk);
147FURI_ALWAYS_INLINE
static inline bool osal_queue_empty(osal_queue_t qhdl) {
148 return (furi_message_queue_get_count(qhdl) == 0);
Definition tusb_os_custom.h:18