Furi: core refactoring and CMSIS removal part 2 (#1410)

* Furi: rename and move core
* Furi: drop CMSIS_OS header and unused api, partially refactor and cleanup the rest
* Furi: CMSIS_OS drop and refactoring.
* Furi: refactoring, remove cmsis legacy
* Furi: fix incorrect assert on queue deallocation, cleanup timer
* Furi: improve delay api, get rid of floats
* hal: dropped furi_hal_crc
* Furi: move DWT based delay to cortex HAL
* Furi: update core documentation

Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
あく
2022-07-20 13:56:33 +03:00
committed by GitHub
parent f9c2287ea7
commit e3c7201a20
264 changed files with 2569 additions and 3883 deletions

View File

@@ -27,12 +27,12 @@ typedef struct {
GapConfig* config;
GapConnectionParams connection_params;
GapState state;
osMutexId_t state_mutex;
FuriMutex* state_mutex;
GapEventCallback on_event_cb;
void* context;
osTimerId_t advertise_timer;
FuriTimer* advertise_timer;
FuriThread* thread;
osMessageQueueId_t command_queue;
FuriMessageQueue* command_queue;
bool enable_adv;
} Gap;
@@ -94,7 +94,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) {
event_pckt = (hci_event_pckt*)((hci_uart_pckt*)pckt)->data;
if(gap) {
osMutexAcquire(gap->state_mutex, osWaitForever);
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
}
switch(event_pckt->evt) {
case EVT_DISCONN_COMPLETE: {
@@ -152,7 +152,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) {
gap->connection_params.supervisor_timeout = event->Supervision_Timeout;
// Stop advertising as connection completed
osTimerStop(gap->advertise_timer);
furi_timer_stop(gap->advertise_timer);
// Update connection status and handle
gap->state = GapStateConnected;
@@ -268,7 +268,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) {
break;
}
if(gap) {
osMutexRelease(gap->state_mutex);
furi_mutex_release(gap->state_mutex);
}
return SVCCTL_UserEvtFlowEnable;
}
@@ -382,7 +382,7 @@ static void gap_advertise_start(GapState new_state) {
max_interval = 0x0fa0; // 2.5 s
}
// Stop advertising timer
osTimerStop(gap->advertise_timer);
furi_timer_stop(gap->advertise_timer);
if((new_state == GapStateAdvLowPower) &&
((gap->state == GapStateAdvFast) || (gap->state == GapStateAdvLowPower))) {
@@ -413,7 +413,7 @@ static void gap_advertise_start(GapState new_state) {
gap->state = new_state;
GapEvent event = {.type = GapEventTypeStartAdvertising};
gap->on_event_cb(event, gap->context);
osTimerStart(gap->advertise_timer, INITIAL_ADV_TIMEOUT);
furi_timer_start(gap->advertise_timer, INITIAL_ADV_TIMEOUT);
}
static void gap_advertise_stop() {
@@ -429,7 +429,7 @@ static void gap_advertise_stop() {
}
}
// Stop advertising
osTimerStop(gap->advertise_timer);
furi_timer_stop(gap->advertise_timer);
ret = aci_gap_set_non_discoverable();
if(ret != BLE_STATUS_SUCCESS) {
FURI_LOG_E(TAG, "set_non_discoverable failed %d", ret);
@@ -443,32 +443,32 @@ static void gap_advertise_stop() {
}
void gap_start_advertising() {
osMutexAcquire(gap->state_mutex, osWaitForever);
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
if(gap->state == GapStateIdle) {
gap->state = GapStateStartingAdv;
FURI_LOG_I(TAG, "Start advertising");
gap->enable_adv = true;
GapCommand command = GapCommandAdvFast;
furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK);
furi_check(furi_message_queue_put(gap->command_queue, &command, 0) == FuriStatusOk);
}
osMutexRelease(gap->state_mutex);
furi_mutex_release(gap->state_mutex);
}
void gap_stop_advertising() {
osMutexAcquire(gap->state_mutex, osWaitForever);
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
if(gap->state > GapStateIdle) {
FURI_LOG_I(TAG, "Stop advertising");
gap->enable_adv = false;
GapCommand command = GapCommandAdvStop;
furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK);
furi_check(furi_message_queue_put(gap->command_queue, &command, 0) == FuriStatusOk);
}
osMutexRelease(gap->state_mutex);
furi_mutex_release(gap->state_mutex);
}
static void gap_advetise_timer_callback(void* context) {
UNUSED(context);
GapCommand command = GapCommandAdvLowPower;
furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK);
furi_check(furi_message_queue_put(gap->command_queue, &command, 0) == FuriStatusOk);
}
bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
@@ -480,14 +480,14 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
gap->config = config;
srand(DWT->CYCCNT);
// Create advertising timer
gap->advertise_timer = osTimerNew(gap_advetise_timer_callback, osTimerOnce, NULL, NULL);
gap->advertise_timer = furi_timer_alloc(gap_advetise_timer_callback, FuriTimerTypeOnce, NULL);
// Initialization of GATT & GAP layer
gap->service.adv_name = config->adv_name;
gap_init_svc(gap);
// Initialization of the BLE Services
SVCCTL_Init();
// Initialization of the GAP state
gap->state_mutex = osMutexNew(NULL);
gap->state_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
gap->state = GapStateIdle;
gap->service.connection_handle = 0xFFFF;
gap->enable_adv = true;
@@ -501,7 +501,7 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
furi_thread_start(gap->thread);
// Command queue allocation
gap->command_queue = osMessageQueueNew(8, sizeof(GapCommand), NULL);
gap->command_queue = furi_message_queue_alloc(8, sizeof(GapCommand));
uint8_t adv_service_uid[2];
gap->service.adv_svc_uuid_len = 1;
@@ -518,9 +518,9 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
GapState gap_get_state() {
GapState state;
if(gap) {
osMutexAcquire(gap->state_mutex, osWaitForever);
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
state = gap->state;
osMutexRelease(gap->state_mutex);
furi_mutex_release(gap->state_mutex);
} else {
state = GapStateUninitialized;
}
@@ -529,19 +529,19 @@ GapState gap_get_state() {
void gap_thread_stop() {
if(gap) {
osMutexAcquire(gap->state_mutex, osWaitForever);
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
gap->enable_adv = false;
GapCommand command = GapCommandKillThread;
osMessageQueuePut(gap->command_queue, &command, 0, osWaitForever);
osMutexRelease(gap->state_mutex);
furi_message_queue_put(gap->command_queue, &command, FuriWaitForever);
furi_mutex_release(gap->state_mutex);
furi_thread_join(gap->thread);
furi_thread_free(gap->thread);
// Free resources
osMutexDelete(gap->state_mutex);
osMessageQueueDelete(gap->command_queue);
osTimerStop(gap->advertise_timer);
while(xTimerIsTimerActive(gap->advertise_timer) == pdTRUE) osDelay(1);
furi_check(osTimerDelete(gap->advertise_timer) == osOK);
furi_mutex_free(gap->state_mutex);
furi_message_queue_free(gap->command_queue);
furi_timer_stop(gap->advertise_timer);
while(xTimerIsTimerActive(gap->advertise_timer) == pdTRUE) furi_delay_tick(1);
furi_timer_free(gap->advertise_timer);
free(gap);
gap = NULL;
}
@@ -551,12 +551,12 @@ static int32_t gap_app(void* context) {
UNUSED(context);
GapCommand command;
while(1) {
osStatus_t status = osMessageQueueGet(gap->command_queue, &command, NULL, osWaitForever);
if(status != osOK) {
FuriStatus status = furi_message_queue_get(gap->command_queue, &command, FuriWaitForever);
if(status != FuriStatusOk) {
FURI_LOG_E(TAG, "Message queue get error: %d", status);
continue;
}
osMutexAcquire(gap->state_mutex, osWaitForever);
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
if(command == GapCommandKillThread) {
break;
}
@@ -567,7 +567,7 @@ static int32_t gap_app(void* context) {
} else if(command == GapCommandAdvStop) {
gap_advertise_stop();
}
osMutexRelease(gap->state_mutex);
furi_mutex_release(gap->state_mutex);
}
return 0;