[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:
あく
2022-06-20 17:54:48 +03:00
committed by GitHub
parent 7618c8ba6f
commit 839e52ac32
61 changed files with 1467 additions and 2784 deletions

View File

@@ -20,7 +20,7 @@ extern uint32_t SystemCoreClock;
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ (SystemCoreClock)
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES (56)
#define configMAX_PRIORITIES (32)
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
/* Heap size determined automatically by linker */
@@ -35,7 +35,7 @@ extern uint32_t SystemCoreClock;
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 2
#define configRECORD_STACK_HIGH_ADDRESS 1
#define configUSE_NEWLIB_REENTRANT 0
@@ -89,6 +89,9 @@ to exclude the API function. */
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 2
#define CMSIS_TASK_NOTIFY_INDEX 1
extern __attribute__((__noreturn__)) void furi_thread_catch();
#define configTASK_RETURN_ADDRESS (furi_thread_catch + 2)
/*
* The CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used
* by the application thus the correct define need to be enabled below

View File

@@ -7,19 +7,16 @@
#define TAG "Main"
static const osThreadAttr_t init_thread_attr = {
.name = "Init",
.stack_size = 4096,
};
int32_t init_task(void* context) {
UNUSED(context);
void init_task() {
// Flipper FURI HAL
furi_hal_init();
// Init flipper
flipper_init();
osThreadExit();
return 0;
}
int main() {
@@ -29,8 +26,13 @@ int main() {
// Flipper critical FURI HAL
furi_hal_init_early();
FuriThread* main_thread = furi_thread_alloc();
furi_thread_set_name(main_thread, "Init");
furi_thread_set_stack_size(main_thread, 4096);
furi_thread_set_callback(main_thread, init_task);
#ifdef FURI_RAM_EXEC
osThreadNew(init_task, NULL, &init_thread_attr);
furi_thread_start(main_thread);
#else
furi_hal_light_sequence("RGB");
@@ -52,7 +54,7 @@ int main() {
furi_hal_power_reset();
} else {
furi_hal_light_sequence("rgb G");
osThreadNew(init_task, NULL, &init_thread_attr);
furi_thread_start(main_thread);
}
#endif

View File

@@ -6,6 +6,7 @@
#include "gap.h"
#include <furi_hal.h>
#include <furi.h>
#define TAG "Bt"
@@ -106,9 +107,9 @@ void ble_app_get_key_storage_buff(uint8_t** addr, uint16_t* size) {
void ble_app_thread_stop() {
if(ble_app) {
osThreadId_t thread_id = furi_thread_get_thread_id(ble_app->thread);
FuriThreadId thread_id = furi_thread_get_id(ble_app->thread);
furi_assert(thread_id);
osThreadFlagsSet(thread_id, BLE_APP_FLAG_KILL_THREAD);
furi_thread_flags_set(thread_id, BLE_APP_FLAG_KILL_THREAD);
furi_thread_join(ble_app->thread);
furi_thread_free(ble_app->thread);
// Free resources
@@ -125,7 +126,7 @@ static int32_t ble_app_hci_thread(void* arg) {
uint32_t flags = 0;
while(1) {
flags = osThreadFlagsWait(BLE_APP_FLAG_ALL, osFlagsWaitAny, osWaitForever);
flags = furi_thread_flags_wait(BLE_APP_FLAG_ALL, osFlagsWaitAny, osWaitForever);
if(flags & BLE_APP_FLAG_KILL_THREAD) {
break;
}
@@ -141,9 +142,9 @@ static int32_t ble_app_hci_thread(void* arg) {
void hci_notify_asynch_evt(void* pdata) {
UNUSED(pdata);
if(ble_app) {
osThreadId_t thread_id = furi_thread_get_thread_id(ble_app->thread);
FuriThreadId thread_id = furi_thread_get_id(ble_app->thread);
furi_assert(thread_id);
osThreadFlagsSet(thread_id, BLE_APP_FLAG_HCI_EVENT);
furi_thread_flags_set(thread_id, BLE_APP_FLAG_HCI_EVENT);
}
}

View File

@@ -333,9 +333,9 @@ static void ble_glue_clear_shared_memory() {
void ble_glue_thread_stop() {
if(ble_glue) {
osThreadId_t thread_id = furi_thread_get_thread_id(ble_glue->thread);
FuriThreadId thread_id = furi_thread_get_id(ble_glue->thread);
furi_assert(thread_id);
osThreadFlagsSet(thread_id, BLE_GLUE_FLAG_KILL_THREAD);
furi_thread_flags_set(thread_id, BLE_GLUE_FLAG_KILL_THREAD);
furi_thread_join(ble_glue->thread);
furi_thread_free(ble_glue->thread);
// Free resources
@@ -353,7 +353,7 @@ static int32_t ble_glue_shci_thread(void* context) {
uint32_t flags = 0;
while(true) {
flags = osThreadFlagsWait(BLE_GLUE_FLAG_ALL, osFlagsWaitAny, osWaitForever);
flags = furi_thread_flags_wait(BLE_GLUE_FLAG_ALL, osFlagsWaitAny, osWaitForever);
if(flags & BLE_GLUE_FLAG_SHCI_EVENT) {
shci_user_evt_proc();
}
@@ -368,9 +368,9 @@ static int32_t ble_glue_shci_thread(void* context) {
void shci_notify_asynch_evt(void* pdata) {
UNUSED(pdata);
if(ble_glue) {
osThreadId_t thread_id = furi_thread_get_thread_id(ble_glue->thread);
FuriThreadId thread_id = furi_thread_get_id(ble_glue->thread);
furi_assert(thread_id);
osThreadFlagsSet(thread_id, BLE_GLUE_FLAG_SHCI_EVENT);
furi_thread_flags_set(thread_id, BLE_GLUE_FLAG_SHCI_EVENT);
}
}

View File

@@ -322,7 +322,7 @@ void furi_hal_bt_set_key_storage_change_callback(
void furi_hal_bt_nvm_sram_sem_acquire() {
while(LL_HSEM_1StepLock(HSEM, CFG_HW_BLE_NVM_SRAM_SEMID)) {
osThreadYield();
furi_thread_yield();
}
}

View File

@@ -34,7 +34,7 @@ void furi_hal_crc_init(bool synchronize) {
void furi_hal_crc_reset() {
furi_check(hal_crc_control.state == CRC_State_Ready);
if(hal_crc_control.mtx) {
furi_check(osMutexGetOwner(hal_crc_control.mtx) == osThreadGetId());
furi_check(osMutexGetOwner(hal_crc_control.mtx) == furi_thread_get_current_id());
osMutexRelease(hal_crc_control.mtx);
}
LL_CRC_ResetCRCCalculationUnit(CRC);

View File

@@ -112,7 +112,7 @@ static void furi_hal_flash_lock(void) {
static void furi_hal_flash_begin_with_core2(bool erase_flag) {
// Take flash controller ownership
while(LL_HSEM_1StepLock(HSEM, CFG_HW_FLASH_SEMID) != 0) {
osThreadYield();
furi_thread_yield();
}
// Unlock flash operation
@@ -128,7 +128,7 @@ static void furi_hal_flash_begin_with_core2(bool erase_flag) {
while(true) {
// Wait till flash controller become usable
while(LL_FLASH_IsActiveFlag_OperationSuspended()) {
osThreadYield();
furi_thread_yield();
};
// Just a little more love
@@ -137,14 +137,14 @@ static void furi_hal_flash_begin_with_core2(bool erase_flag) {
// Actually we already have mutex for it, but specification is specification
if(LL_HSEM_IsSemaphoreLocked(HSEM, CFG_HW_BLOCK_FLASH_REQ_BY_CPU1_SEMID)) {
taskEXIT_CRITICAL();
osThreadYield();
furi_thread_yield();
continue;
}
// Take sempahopre and prevent core2 from anything funky
if(LL_HSEM_1StepLock(HSEM, CFG_HW_BLOCK_FLASH_REQ_BY_CPU2_SEMID) != 0) {
taskEXIT_CRITICAL();
osThreadYield();
furi_thread_yield();
continue;
}
@@ -173,7 +173,7 @@ static void furi_hal_flash_end_with_core2(bool erase_flag) {
// Doesn't make much sense, does it?
while(READ_BIT(FLASH->SR, FLASH_SR_BSY)) {
osThreadYield();
furi_thread_yield();
}
// Erase activity over, core2 can continue
@@ -498,7 +498,7 @@ bool furi_hal_flash_ob_set_word(size_t word_idx, const uint32_t value) {
/* 3. Check that no Flash memory operation is on going by checking the BSY && PESD */
furi_check(furi_hal_flash_wait_last_operation(FURI_HAL_FLASH_TIMEOUT));
while(LL_FLASH_IsActiveFlag_OperationSuspended()) {
osThreadYield();
furi_thread_yield();
};
/* 4. Set the Options start bit OPTSTRT */

View File

@@ -179,7 +179,7 @@ bool furi_hal_nfc_activate_nfca(uint32_t timeout, uint32_t* cuid) {
FURI_LOG_T(TAG, "Timeout");
return false;
}
osThreadYield();
furi_thread_yield();
}
rfalNfcGetDevicesFound(&dev_list, &dev_cnt);
// Take first device and set cuid
@@ -397,14 +397,14 @@ static bool furi_hal_nfc_transparent_tx_rx(FuriHalNfcTxRxContext* tx_rx, uint16_
}
// Manually wait for interrupt
furi_hal_gpio_init(&gpio_rfid_pull, GpioModeInput, GpioPullDown, GpioSpeedVeryHigh);
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeInput, GpioPullDown, GpioSpeedVeryHigh);
st25r3916ClearAndEnableInterrupts(ST25R3916_IRQ_MASK_RXE);
uint32_t irq = 0;
uint8_t rxe = 0;
uint32_t start = DWT->CYCCNT;
while(true) {
if(furi_hal_gpio_read(&gpio_rfid_pull) == true) {
if(furi_hal_gpio_read(&gpio_nfc_irq_rfid_pull) == true) {
st25r3916ReadRegister(ST25R3916_REG_IRQ_MAIN, &rxe);
if(rxe & (1 << 4)) {
irq = 1;

View File

@@ -42,7 +42,7 @@ const GpioPin gpio_ext_pa4 = {.port = GPIOA, .pin = LL_GPIO_PIN_4};
const GpioPin gpio_ext_pa6 = {.port = GPIOA, .pin = LL_GPIO_PIN_6};
const GpioPin gpio_ext_pa7 = {.port = GPIOA, .pin = LL_GPIO_PIN_7};
const GpioPin gpio_rfid_pull = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pin};
const GpioPin gpio_nfc_irq_rfid_pull = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pin};
const GpioPin gpio_rfid_carrier_out = {.port = RFID_OUT_GPIO_Port, .pin = RFID_OUT_Pin};
const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin};
const GpioPin gpio_rfid_carrier = {.port = RFID_CARRIER_GPIO_Port, .pin = RFID_CARRIER_Pin};
@@ -138,7 +138,7 @@ void furi_hal_resources_init() {
furi_hal_gpio_init(&ibutton_gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_rfid_pull, GpioModeInterruptRise, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeInterruptRise, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_rf_sw_0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);

View File

@@ -77,7 +77,7 @@ extern const GpioPin gpio_ext_pa4;
extern const GpioPin gpio_ext_pa6;
extern const GpioPin gpio_ext_pa7;
extern const GpioPin gpio_rfid_pull;
extern const GpioPin gpio_nfc_irq_rfid_pull;
extern const GpioPin gpio_rfid_carrier_out;
extern const GpioPin gpio_rfid_data_in;
extern const GpioPin gpio_rfid_carrier;

View File

@@ -69,8 +69,8 @@ void furi_hal_rfid_pins_reset() {
furi_hal_gpio_write(&gpio_rfid_carrier_out, false);
// from both sides
furi_hal_gpio_init(&gpio_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_rfid_pull, true);
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_nfc_irq_rfid_pull, true);
furi_hal_gpio_init_simple(&gpio_rfid_carrier, GpioModeAnalog);
@@ -84,7 +84,11 @@ void furi_hal_rfid_pins_emulate() {
// pull pin to timer out
furi_hal_gpio_init_ex(
&gpio_rfid_pull, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
&gpio_nfc_irq_rfid_pull,
GpioModeAltFunctionPushPull,
GpioPullNo,
GpioSpeedLow,
GpioAltFn1TIM2);
// pull rfid antenna from carrier side
furi_hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
@@ -100,8 +104,8 @@ void furi_hal_rfid_pins_read() {
furi_hal_ibutton_pin_low();
// dont pull rfid antenna
furi_hal_gpio_init(&gpio_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_rfid_pull, false);
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_nfc_irq_rfid_pull, false);
// carrier pin to timer out
furi_hal_gpio_init_ex(
@@ -116,11 +120,11 @@ void furi_hal_rfid_pins_read() {
}
void furi_hal_rfid_pin_pull_release() {
furi_hal_gpio_write(&gpio_rfid_pull, true);
furi_hal_gpio_write(&gpio_nfc_irq_rfid_pull, true);
}
void furi_hal_rfid_pin_pull_pulldown() {
furi_hal_gpio_write(&gpio_rfid_pull, false);
furi_hal_gpio_write(&gpio_nfc_irq_rfid_pull, false);
}
void furi_hal_rfid_tim_read(float freq, float duty_cycle) {

View File

@@ -101,7 +101,7 @@ bool furi_hal_usb_set_config(FuriHalUsbInterface* new_if, void* ctx) {
return true;
}
furi_assert(usb.thread);
osThreadFlagsSet(furi_thread_get_thread_id(usb.thread), EventModeChange);
furi_thread_flags_set(furi_thread_get_id(usb.thread), EventModeChange);
return true;
}
@@ -125,17 +125,17 @@ bool furi_hal_usb_is_locked() {
void furi_hal_usb_disable() {
furi_assert(usb.thread);
osThreadFlagsSet(furi_thread_get_thread_id(usb.thread), EventDisable);
furi_thread_flags_set(furi_thread_get_id(usb.thread), EventDisable);
}
void furi_hal_usb_enable() {
furi_assert(usb.thread);
osThreadFlagsSet(furi_thread_get_thread_id(usb.thread), EventEnable);
furi_thread_flags_set(furi_thread_get_id(usb.thread), EventEnable);
}
void furi_hal_usb_reinit() {
furi_assert(usb.thread);
osThreadFlagsSet(furi_thread_get_thread_id(usb.thread), EventReinit);
furi_thread_flags_set(furi_thread_get_id(usb.thread), EventReinit);
}
/* Get device / configuration descriptors */
@@ -148,7 +148,7 @@ static usbd_respond usb_descriptor_get(usbd_ctlreq* req, void** address, uint16_
switch(dtype) {
case USB_DTYPE_DEVICE:
osThreadFlagsSet(furi_thread_get_thread_id(usb.thread), EventRequest);
furi_thread_flags_set(furi_thread_get_id(usb.thread), EventRequest);
if(usb.callback != NULL) {
usb.callback(FuriHalUsbStateEventDescriptorRequest, usb.cb_ctx);
}
@@ -192,7 +192,7 @@ static void reset_evt(usbd_device* dev, uint8_t event, uint8_t ep) {
UNUSED(dev);
UNUSED(event);
UNUSED(ep);
osThreadFlagsSet(furi_thread_get_thread_id(usb.thread), EventReset);
furi_thread_flags_set(furi_thread_get_id(usb.thread), EventReset);
if(usb.callback != NULL) {
usb.callback(FuriHalUsbStateEventReset, usb.cb_ctx);
}
@@ -236,11 +236,11 @@ static int32_t furi_hal_usb_thread(void* context) {
FuriHalUsbInterface* if_ctx_new = NULL;
if(usb.if_next != NULL) {
osThreadFlagsSet(furi_thread_get_thread_id(usb.thread), EventModeChange);
furi_thread_flags_set(furi_thread_get_id(usb.thread), EventModeChange);
}
while(true) {
uint32_t flags = osThreadFlagsWait(USB_SRV_ALL_EVENTS, osFlagsWaitAny, 500);
uint32_t flags = furi_thread_flags_wait(USB_SRV_ALL_EVENTS, osFlagsWaitAny, 500);
if((flags & osFlagsError) == 0) {
if(flags & EventModeChange) {
if(usb.if_next != usb.if_cur) {