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:
Sergey Gavrilov 2023-06-06 12:00:43 -07:00 committed by GitHub
parent e4a2e9a920
commit 3e1f209d64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 21 deletions

View 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,,
@ -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 entry status name type params
2 Version + 28.3 28.4
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
288 Function - __eprintf void const char*, const char*, unsigned int, const char*
289 Function + __errno int*
290 Function + __furi_crash void
291 Function + __furi_critical_enter __FuriCriticalInfo
292 Function + __furi_critical_exit void __FuriCriticalInfo
293 Function + __furi_halt void
294 Function - __getdelim ssize_t char**, size_t*, int, FILE*
295 Function - __getline ssize_t char**, size_t*, FILE*

View 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*"

1 entry status name type params
2 Version + 28.3 28.4
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
323 Function - __fpclassifyd int double
324 Function - __fpclassifyf int float
325 Function + __furi_crash void
326 Function + __furi_critical_enter __FuriCriticalInfo
327 Function + __furi_critical_exit void __FuriCriticalInfo
328 Function + __furi_halt void
329 Function - __getdelim ssize_t char**, size_t*, int, FILE*
330 Function - __getline ssize_t char**, size_t*, FILE*

View 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
View 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();
}
}