[FL-1991] Rewrite flash driver (#813)
* Toolbox: fix null pointer dereference in manchester decoder. * FuriHal: use MPU to protect from null pointer dereference, replace flash driver with our own implementation.
This commit is contained in:
@@ -12,6 +12,16 @@ void furi_hal_bt_init() {
|
||||
furi_hal_bt_core2_mtx = osMutexNew(NULL);
|
||||
}
|
||||
|
||||
void furi_hal_bt_lock_core2() {
|
||||
furi_assert(furi_hal_bt_core2_mtx);
|
||||
furi_check(osMutexAcquire(furi_hal_bt_core2_mtx, osWaitForever) == osOK);
|
||||
}
|
||||
|
||||
void furi_hal_bt_unlock_core2() {
|
||||
furi_assert(furi_hal_bt_core2_mtx);
|
||||
furi_check(osMutexRelease(furi_hal_bt_core2_mtx) == osOK);
|
||||
}
|
||||
|
||||
static bool furi_hal_bt_wait_startup() {
|
||||
uint16_t counter = 0;
|
||||
while (!(ble_glue_get_status() == BleGlueStatusStarted || ble_glue_get_status() == BleGlueStatusBleStackMissing)) {
|
||||
@@ -130,91 +140,6 @@ bool furi_hal_bt_is_active() {
|
||||
return gap_get_state() > GapStateIdle;
|
||||
}
|
||||
|
||||
static void furi_hal_bt_lock_flash_core2(bool erase_flag) {
|
||||
// Take flash controller ownership
|
||||
while (HAL_HSEM_FastTake(CFG_HW_FLASH_SEMID) != HAL_OK) {
|
||||
taskYIELD();
|
||||
}
|
||||
|
||||
// Unlock flash operation
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
// Erase activity notification
|
||||
if(erase_flag) SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_ON);
|
||||
|
||||
while(true) {
|
||||
// Wait till flash controller become usable
|
||||
while(LL_FLASH_IsActiveFlag_OperationSuspended()) {
|
||||
taskYIELD();
|
||||
};
|
||||
|
||||
// Just a little more love
|
||||
taskENTER_CRITICAL();
|
||||
|
||||
// Actually we already have mutex for it, but specification is specification
|
||||
if (HAL_HSEM_IsSemTaken(CFG_HW_BLOCK_FLASH_REQ_BY_CPU1_SEMID)) {
|
||||
taskEXIT_CRITICAL();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Take sempahopre and prevent core2 from anyting funky
|
||||
if (HAL_HSEM_FastTake(CFG_HW_BLOCK_FLASH_REQ_BY_CPU2_SEMID) != HAL_OK) {
|
||||
taskEXIT_CRITICAL();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void furi_hal_bt_lock_flash(bool erase_flag) {
|
||||
// Acquire dangerous ops mutex
|
||||
osMutexAcquire(furi_hal_bt_core2_mtx, osWaitForever);
|
||||
|
||||
// If Core2 is running use IPC locking
|
||||
BleGlueStatus status = ble_glue_get_status();
|
||||
if(status == BleGlueStatusStarted || status == BleGlueStatusBleStackMissing) {
|
||||
furi_hal_bt_lock_flash_core2(erase_flag);
|
||||
} else {
|
||||
HAL_FLASH_Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
static void furi_hal_bt_unlock_flash_core2(bool erase_flag) {
|
||||
// Funky ops are ok at this point
|
||||
HAL_HSEM_Release(CFG_HW_BLOCK_FLASH_REQ_BY_CPU2_SEMID, 0);
|
||||
|
||||
// Task switching is ok
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
// Doesn't make much sense, does it?
|
||||
while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) {
|
||||
taskYIELD();
|
||||
}
|
||||
|
||||
// Erase activity over, core2 can continue
|
||||
if(erase_flag) SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
|
||||
|
||||
// Lock flash controller
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
// Release flash controller ownership
|
||||
HAL_HSEM_Release(CFG_HW_FLASH_SEMID, 0);
|
||||
}
|
||||
|
||||
void furi_hal_bt_unlock_flash(bool erase_flag) {
|
||||
// If Core2 is running use IPC locking
|
||||
BleGlueStatus status = ble_glue_get_status();
|
||||
if(status == BleGlueStatusStarted || status == BleGlueStatusBleStackMissing) {
|
||||
furi_hal_bt_unlock_flash_core2(erase_flag);
|
||||
} else {
|
||||
HAL_FLASH_Lock();
|
||||
}
|
||||
|
||||
// Release dangerous ops mutex
|
||||
osMutexRelease(furi_hal_bt_core2_mtx);
|
||||
}
|
||||
|
||||
void furi_hal_bt_start_tone_tx(uint8_t channel, uint8_t power) {
|
||||
aci_hal_set_tx_power_level(0, power);
|
||||
aci_hal_tone_start(channel, 0);
|
||||
|
||||
Reference in New Issue
Block a user