mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-29 00:09:19 +03:00
Furi: smaller critical enter and critical exit macro (#2716)
* Furi: smaller critical enter and critical exit macro * api: bumped version --------- Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
parent
e4a2e9a920
commit
3e1f209d64
@ -1,5 +1,5 @@
|
||||
entry,status,name,type,params
|
||||
Version,+,28.3,,
|
||||
Version,+,28.4,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
Header,+,applications/services/cli/cli_vcp.h,,
|
||||
@ -288,6 +288,8 @@ Function,+,__clear_cache,void,"void*, void*"
|
||||
Function,-,__eprintf,void,"const char*, const char*, unsigned int, const char*"
|
||||
Function,+,__errno,int*,
|
||||
Function,+,__furi_crash,void,
|
||||
Function,+,__furi_critical_enter,__FuriCriticalInfo,
|
||||
Function,+,__furi_critical_exit,void,__FuriCriticalInfo
|
||||
Function,+,__furi_halt,void,
|
||||
Function,-,__getdelim,ssize_t,"char**, size_t*, int, FILE*"
|
||||
Function,-,__getline,ssize_t,"char**, size_t*, FILE*"
|
||||
|
|
@ -1,5 +1,5 @@
|
||||
entry,status,name,type,params
|
||||
Version,+,28.3,,
|
||||
Version,+,28.4,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
Header,+,applications/services/cli/cli_vcp.h,,
|
||||
@ -323,6 +323,8 @@ Function,+,__errno,int*,
|
||||
Function,-,__fpclassifyd,int,double
|
||||
Function,-,__fpclassifyf,int,float
|
||||
Function,+,__furi_crash,void,
|
||||
Function,+,__furi_critical_enter,__FuriCriticalInfo,
|
||||
Function,+,__furi_critical_exit,void,__FuriCriticalInfo
|
||||
Function,+,__furi_halt,void,
|
||||
Function,-,__getdelim,ssize_t,"char**, size_t*, int, FILE*"
|
||||
Function,-,__getline,ssize_t,"char**, size_t*, FILE*"
|
||||
|
|
@ -31,29 +31,22 @@ extern "C" {
|
||||
#define FURI_IS_ISR() (FURI_IS_IRQ_MODE() || FURI_IS_IRQ_MASKED())
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint32_t isrm;
|
||||
bool from_isr;
|
||||
bool kernel_running;
|
||||
} __FuriCriticalInfo;
|
||||
|
||||
__FuriCriticalInfo __furi_critical_enter(void);
|
||||
|
||||
void __furi_critical_exit(__FuriCriticalInfo info);
|
||||
|
||||
#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(); \
|
||||
}
|
||||
#define FURI_CRITICAL_ENTER() __FuriCriticalInfo __furi_critical_info = __furi_critical_enter();
|
||||
#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(); \
|
||||
}
|
||||
#define FURI_CRITICAL_EXIT() __furi_critical_exit(__furi_critical_info);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
29
furi/core/critical.c
Normal file
29
furi/core/critical.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include "common_defines.h"
|
||||
|
||||
__FuriCriticalInfo __furi_critical_enter(void) {
|
||||
__FuriCriticalInfo info;
|
||||
|
||||
info.isrm = 0;
|
||||
info.from_isr = FURI_IS_ISR();
|
||||
info.kernel_running = (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING);
|
||||
|
||||
if(info.from_isr) {
|
||||
info.isrm = taskENTER_CRITICAL_FROM_ISR();
|
||||
} else if(info.kernel_running) {
|
||||
taskENTER_CRITICAL();
|
||||
} else {
|
||||
__disable_irq();
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
void __furi_critical_exit(__FuriCriticalInfo info) {
|
||||
if(info.from_isr) {
|
||||
taskEXIT_CRITICAL_FROM_ISR(info.isrm);
|
||||
} else if(info.kernel_running) {
|
||||
taskEXIT_CRITICAL();
|
||||
} else {
|
||||
__enable_irq();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user