[FL-1816] Fix ble radio stack is alive check (#707)
* bt: fix bt_is_alive return, add bt_is_active * bt: fix bt_is_alive return * Cli: show heap usage in ps. * FuriHal: strict sequence for flash operations * Scripts: add stress test * Core: proper heap calculation. Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -24,7 +24,7 @@ void furi_hal_bt_start_advertising() {
|
||||
}
|
||||
|
||||
void furi_hal_bt_stop_advertising() {
|
||||
if(furi_hal_bt_is_alive()) {
|
||||
if(furi_hal_bt_is_active()) {
|
||||
gap_stop_advertising();
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,11 @@ void furi_hal_bt_dump_state(string_t buffer) {
|
||||
}
|
||||
|
||||
bool furi_hal_bt_is_alive() {
|
||||
BleGlueStatus status = APPE_Status();
|
||||
return (status == BleGlueStatusBroken) || (status == BleGlueStatusStarted);
|
||||
}
|
||||
|
||||
bool furi_hal_bt_is_active() {
|
||||
return gap_get_state() > GapStateIdle;
|
||||
}
|
||||
|
||||
@@ -67,7 +72,7 @@ bool furi_hal_bt_wait_startup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool furi_hal_bt_lock_flash() {
|
||||
bool furi_hal_bt_lock_flash(bool erase_flag) {
|
||||
if (!furi_hal_bt_wait_startup()) {
|
||||
return false;
|
||||
}
|
||||
@@ -75,18 +80,25 @@ bool furi_hal_bt_lock_flash() {
|
||||
while (HAL_HSEM_FastTake(CFG_HW_FLASH_SEMID) != HAL_OK) {
|
||||
osDelay(1);
|
||||
}
|
||||
|
||||
SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_ON);
|
||||
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
while(LL_FLASH_IsOperationSuspended()) {};
|
||||
if(erase_flag) SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_ON);
|
||||
|
||||
while(LL_FLASH_IsActiveFlag_OperationSuspended()) {};
|
||||
|
||||
__disable_irq();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void furi_hal_bt_unlock_flash() {
|
||||
SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
|
||||
void furi_hal_bt_unlock_flash(bool erase_flag) {
|
||||
__enable_irq();
|
||||
|
||||
if(erase_flag) SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
|
||||
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
HAL_HSEM_Release(CFG_HW_FLASH_SEMID, HSEM_CPU1_COREID);
|
||||
}
|
||||
|
||||
|
@@ -57,7 +57,7 @@ size_t furi_hal_flash_get_free_page_count() {
|
||||
}
|
||||
|
||||
bool furi_hal_flash_erase(uint8_t page, uint8_t count) {
|
||||
if (!furi_hal_bt_lock_flash()) {
|
||||
if (!furi_hal_bt_lock_flash(true)) {
|
||||
return false;
|
||||
}
|
||||
FLASH_EraseInitTypeDef erase;
|
||||
@@ -66,24 +66,24 @@ bool furi_hal_flash_erase(uint8_t page, uint8_t count) {
|
||||
erase.NbPages = count;
|
||||
uint32_t error;
|
||||
HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&erase, &error);
|
||||
furi_hal_bt_unlock_flash();
|
||||
furi_hal_bt_unlock_flash(true);
|
||||
return status == HAL_OK;
|
||||
}
|
||||
|
||||
bool furi_hal_flash_write_dword(size_t address, uint64_t data) {
|
||||
if (!furi_hal_bt_lock_flash()) {
|
||||
if (!furi_hal_bt_lock_flash(false)) {
|
||||
return false;
|
||||
}
|
||||
HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data);
|
||||
furi_hal_bt_unlock_flash();
|
||||
furi_hal_bt_unlock_flash(false);
|
||||
return status == HAL_OK;
|
||||
}
|
||||
|
||||
bool furi_hal_flash_write_dword_from(size_t address, size_t source_address) {
|
||||
if (!furi_hal_bt_lock_flash()) {
|
||||
if (!furi_hal_bt_lock_flash(false)) {
|
||||
return false;
|
||||
}
|
||||
HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST, address, source_address);
|
||||
furi_hal_bt_unlock_flash();
|
||||
furi_hal_bt_unlock_flash(false);
|
||||
return status == HAL_OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user