[FL-2591] Furi: remove CMSIS thread api, migrate to FuriThread, remove unused CMSIS APIs (#1333)
* Furi: remove CMSIS thread api, migrate to FuriThread, remove unused CMSIS APIs * Furi: magic thread catcher validating thread completion; backtrace improver * Furi: allow furi_thread_get_current_id outside of thread context * Furi: use IRQ instead of ISR for core primitives
This commit is contained in:
@@ -3,49 +3,58 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal_spi.h>
|
||||
|
||||
static const osThreadAttr_t platform_irq_thread_attr = {
|
||||
.name = "RfalIrqDriver",
|
||||
.stack_size = 1024,
|
||||
.priority = osPriorityRealtime,
|
||||
};
|
||||
typedef struct {
|
||||
FuriThread* thread;
|
||||
volatile PlatformIrqCallback callback;
|
||||
} RfalPlatform;
|
||||
|
||||
static volatile osThreadId_t platform_irq_thread_id = NULL;
|
||||
static volatile PlatformIrqCallback platform_irq_callback = NULL;
|
||||
static const GpioPin pin = {ST25R_INT_PORT, ST25R_INT_PIN};
|
||||
static volatile RfalPlatform rfal_platform = {
|
||||
.thread = NULL,
|
||||
.callback = NULL,
|
||||
};
|
||||
|
||||
void nfc_isr(void* _ctx) {
|
||||
UNUSED(_ctx);
|
||||
if(platform_irq_callback && platformGpioIsHigh(ST25R_INT_PORT, ST25R_INT_PIN)) {
|
||||
osThreadFlagsSet(platform_irq_thread_id, 0x1);
|
||||
if(rfal_platform.callback && platformGpioIsHigh(ST25R_INT_PORT, ST25R_INT_PIN)) {
|
||||
furi_thread_flags_set(furi_thread_get_id(rfal_platform.thread), 0x1);
|
||||
}
|
||||
}
|
||||
|
||||
void platformIrqThread() {
|
||||
int32_t rfal_platform_irq_thread(void* context) {
|
||||
UNUSED(context);
|
||||
|
||||
while(1) {
|
||||
uint32_t flags = osThreadFlagsWait(0x1, osFlagsWaitAny, osWaitForever);
|
||||
uint32_t flags = furi_thread_flags_wait(0x1, osFlagsWaitAny, osWaitForever);
|
||||
if(flags & 0x1) {
|
||||
platform_irq_callback();
|
||||
rfal_platform.callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void platformEnableIrqCallback() {
|
||||
furi_hal_gpio_init(&pin, GpioModeInterruptRise, GpioPullDown, GpioSpeedLow);
|
||||
furi_hal_gpio_enable_int_callback(&pin);
|
||||
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeInterruptRise, GpioPullDown, GpioSpeedLow);
|
||||
furi_hal_gpio_enable_int_callback(&gpio_nfc_irq_rfid_pull);
|
||||
}
|
||||
|
||||
void platformDisableIrqCallback() {
|
||||
furi_hal_gpio_init(&pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_disable_int_callback(&pin);
|
||||
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_disable_int_callback(&gpio_nfc_irq_rfid_pull);
|
||||
}
|
||||
|
||||
void platformSetIrqCallback(PlatformIrqCallback callback) {
|
||||
platform_irq_callback = callback;
|
||||
platform_irq_thread_id = osThreadNew(platformIrqThread, NULL, &platform_irq_thread_attr);
|
||||
furi_hal_gpio_add_int_callback(&pin, nfc_isr, NULL);
|
||||
rfal_platform.callback = callback;
|
||||
rfal_platform.thread = furi_thread_alloc();
|
||||
|
||||
furi_thread_set_name(rfal_platform.thread, "RfalIrqDriver");
|
||||
furi_thread_set_callback(rfal_platform.thread, rfal_platform_irq_thread);
|
||||
furi_thread_set_stack_size(rfal_platform.thread, 1024);
|
||||
furi_thread_set_priority(rfal_platform.thread, FuriThreadPriorityIsr);
|
||||
furi_thread_start(rfal_platform.thread);
|
||||
|
||||
furi_hal_gpio_add_int_callback(&gpio_nfc_irq_rfid_pull, nfc_isr, NULL);
|
||||
// Disable interrupt callback as the pin is shared between 2 apps
|
||||
// It is enabled in rfalLowPowerModeStop()
|
||||
furi_hal_gpio_disable_int_callback(&pin);
|
||||
furi_hal_gpio_disable_int_callback(&gpio_nfc_irq_rfid_pull);
|
||||
}
|
||||
|
||||
bool platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t len) {
|
||||
|
Reference in New Issue
Block a user