mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-18 19:01:47 +03:00
2dea6969fe
* Furi_hal_speaker: multiple resource usage * Furi_hal_speaker: fix multiple resource usage * Furi_hal_speaker: fix music_player_worker * Furi_hal_speaker: fix mutex release queue handling * SubGhz: add furi_hal_subghz_set_debug_pin * SubGhz: add sound SubGhz Read, SubGhz Read RAW * furi_hal_speaker: add __attribute__((warn_unused_result)) for furi_hal_speaker_acquire() * Furi_hal_speaker: fix review comments * SubGhz: cleanup naming and locking timings * SubGhz,FuriHal: fix speaker deinit logic and subghz speaker release sequence * FuriHal: crash on speaker acquire/release from IRQ * Furi, FuriHal: FURI_WARN_UNUSED and documentation update * Bump api symbols version: fix broken speaker Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
82 lines
2.3 KiB
C
82 lines
2.3 KiB
C
#pragma once
|
|
|
|
#include "core_defines.h"
|
|
#include <stdbool.h>
|
|
#include <FreeRTOS.h>
|
|
#include <task.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <cmsis_compiler.h>
|
|
|
|
#ifndef FURI_WARN_UNUSED
|
|
#define FURI_WARN_UNUSED __attribute__((warn_unused_result))
|
|
#endif
|
|
|
|
#ifndef FURI_IS_IRQ_MASKED
|
|
#define FURI_IS_IRQ_MASKED() (__get_PRIMASK() != 0U)
|
|
#endif
|
|
|
|
#ifndef FURI_IS_IRQ_MODE
|
|
#define FURI_IS_IRQ_MODE() (__get_IPSR() != 0U)
|
|
#endif
|
|
|
|
#ifndef FURI_IS_ISR
|
|
#define FURI_IS_ISR() (FURI_IS_IRQ_MODE() || FURI_IS_IRQ_MASKED())
|
|
#endif
|
|
|
|
#ifndef FURI_CRITICAL_ENTER
|
|
#define FURI_CRITICAL_ENTER() \
|
|
uint32_t __isrm = 0; \
|
|
bool __from_isr = FURI_IS_ISR(); \
|
|
bool __kernel_running = (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING); \
|
|
if(__from_isr) { \
|
|
__isrm = taskENTER_CRITICAL_FROM_ISR(); \
|
|
} else if(__kernel_running) { \
|
|
taskENTER_CRITICAL(); \
|
|
} else { \
|
|
__disable_irq(); \
|
|
}
|
|
#endif
|
|
|
|
#ifndef FURI_CRITICAL_EXIT
|
|
#define FURI_CRITICAL_EXIT() \
|
|
if(__from_isr) { \
|
|
taskEXIT_CRITICAL_FROM_ISR(__isrm); \
|
|
} else if(__kernel_running) { \
|
|
taskEXIT_CRITICAL(); \
|
|
} else { \
|
|
__enable_irq(); \
|
|
}
|
|
#endif
|
|
|
|
static inline bool furi_is_irq_context() {
|
|
bool irq = false;
|
|
BaseType_t state;
|
|
|
|
if(FURI_IS_IRQ_MODE()) {
|
|
/* Called from interrupt context */
|
|
irq = true;
|
|
} else {
|
|
/* Get FreeRTOS scheduler state */
|
|
state = xTaskGetSchedulerState();
|
|
|
|
if(state != taskSCHEDULER_NOT_STARTED) {
|
|
/* Scheduler was started */
|
|
if(FURI_IS_IRQ_MASKED()) {
|
|
/* Interrupts are masked */
|
|
irq = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Return context, 0: thread context, 1: IRQ context */
|
|
return (irq);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|