[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

@@ -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) {