Skip to content

Commit

Permalink
Furi: smaller critical enter and critical exit macro (#2716)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Jun 6, 2023
1 parent e4a2e9a commit 3e1f209
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
4 changes: 3 additions & 1 deletion firmware/targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -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,,
Expand Down Expand Up @@ -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*"
Expand Down
4 changes: 3 additions & 1 deletion firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -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,,
Expand Down Expand Up @@ -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*"
Expand Down
31 changes: 12 additions & 19 deletions furi/core/common_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions furi/core/critical.c
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 3e1f209

Please sign in to comment.