2021-05-18 13:51:00 +03:00
|
|
|
#pragma once
|
|
|
|
|
2022-08-22 20:06:17 +03:00
|
|
|
#include "core_defines.h"
|
2022-03-29 20:37:23 +03:00
|
|
|
#include <stdbool.h>
|
2022-07-20 13:56:33 +03:00
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <task.h>
|
2022-03-29 20:37:23 +03:00
|
|
|
|
2022-03-30 18:23:40 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <cmsis_compiler.h>
|
|
|
|
|
2022-12-17 01:20:10 +03:00
|
|
|
#ifndef FURI_WARN_UNUSED
|
|
|
|
#define FURI_WARN_UNUSED __attribute__((warn_unused_result))
|
|
|
|
#endif
|
|
|
|
|
2022-03-29 20:37:23 +03:00
|
|
|
#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
|
2022-04-13 23:50:25 +03:00
|
|
|
#define FURI_IS_ISR() (FURI_IS_IRQ_MODE() || FURI_IS_IRQ_MASKED())
|
2022-03-29 20:37:23 +03:00
|
|
|
#endif
|
|
|
|
|
2021-12-01 01:07:17 +03:00
|
|
|
#ifndef FURI_CRITICAL_ENTER
|
2022-07-20 13:56:33 +03:00
|
|
|
#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(); \
|
2022-03-29 20:37:23 +03:00
|
|
|
}
|
2021-12-01 01:07:17 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef FURI_CRITICAL_EXIT
|
2022-03-29 20:37:23 +03:00
|
|
|
#define FURI_CRITICAL_EXIT() \
|
|
|
|
if(__from_isr) { \
|
|
|
|
taskEXIT_CRITICAL_FROM_ISR(__isrm); \
|
2022-04-13 23:50:25 +03:00
|
|
|
} else if(__kernel_running) { \
|
2022-03-29 20:37:23 +03:00
|
|
|
taskEXIT_CRITICAL(); \
|
2022-04-13 23:50:25 +03:00
|
|
|
} else { \
|
|
|
|
__enable_irq(); \
|
2022-03-29 20:37:23 +03:00
|
|
|
}
|
2022-01-03 00:39:56 +03:00
|
|
|
#endif
|
2022-03-30 18:23:40 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|