Skip to content

Commit

Permalink
Move away from semaphores
Browse files Browse the repository at this point in the history
  • Loading branch information
Astrrra committed Dec 20, 2024
1 parent 44457aa commit 33ef5c3
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 22 deletions.
1 change: 0 additions & 1 deletion targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,6 @@ Function,-,gap_init,_Bool,"GapConfig*, GapEventCallback, void*"
Function,-,gap_start_advertising,void,
Function,-,gap_stop_advertising,void,
Function,-,gap_thread_stop,void,
Function,-,gap_wait_for_tx_pool_available,void,FuriWait
Function,-,getc,int,FILE*
Function,-,getc_unlocked,int,FILE*
Function,-,getchar,int,
Expand Down
1 change: 0 additions & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,6 @@ Function,-,gap_init,_Bool,"GapConfig*, GapEventCallback, void*"
Function,-,gap_start_advertising,void,
Function,-,gap_stop_advertising,void,
Function,-,gap_thread_stop,void,
Function,-,gap_wait_for_tx_pool_available,void,FuriWait
Function,-,getc,int,FILE*
Function,-,getc_unlocked,int,FILE*
Function,-,getchar,int,
Expand Down
9 changes: 5 additions & 4 deletions targets/f7/ble_glue/furi_ble/gatt.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "gatt.h"
#include "gap.h"
#include <ble/ble.h>

#include <furi.h>
Expand Down Expand Up @@ -120,9 +119,11 @@ bool ble_gatt_characteristic_update(
if(result) {
if(result == BLE_STATUS_INSUFFICIENT_RESOURCES) {
FURI_LOG_E(TAG, "Insufficient resources for %s characteristic", char_descriptor->name);
gap_wait_for_tx_pool_available(1000); // 1 second timeout
result = aci_gatt_update_char_value(
svc_handle, char_instance->handle, 0, char_data_size, char_data);
do {
furi_delay_ms(1);
result = aci_gatt_update_char_value(
svc_handle, char_instance->handle, 0, char_data_size, char_data);
} while(result == BLE_STATUS_INSUFFICIENT_RESOURCES);
}
}

Expand Down
14 changes: 0 additions & 14 deletions targets/f7/ble_glue/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ typedef struct {
bool enable_adv;
bool is_secure;
uint8_t negotiation_round;
FuriSemaphore* tx_pool_busy;
} Gap;

typedef enum {
Expand Down Expand Up @@ -300,11 +299,6 @@ BleEventFlowStatus ble_event_app_notification(void* pckt) {
}
break;
}

case ACI_GATT_TX_POOL_AVAILABLE_VSEVT_CODE:
FURI_LOG_D(TAG, "TX pool available event");
furi_semaphore_release(gap->tx_pool_busy);
break;
}
default:
break;
Expand All @@ -315,11 +309,6 @@ BleEventFlowStatus ble_event_app_notification(void* pckt) {
return BleEventFlowEnable;
}

void gap_wait_for_tx_pool_available(FuriWait wait) {
furi_check(gap);
furi_check(furi_semaphore_acquire(gap->tx_pool_busy, wait) == FuriStatusOk);
}

static void set_advertisment_service_uid(uint8_t* uid, uint8_t uid_len) {
if(uid_len == 2) {
gap->service.adv_svc_uuid[0] = AD_TYPE_16_BIT_SERV_UUID;
Expand Down Expand Up @@ -538,7 +527,6 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {

gap = malloc(sizeof(Gap));
gap->config = config;
gap->tx_pool_busy = furi_semaphore_alloc(1, 0);
// Create advertising timer
gap->advertise_timer = furi_timer_alloc(gap_advetise_timer_callback, FuriTimerTypeOnce, NULL);
// Initialization of GATT & GAP layer
Expand Down Expand Up @@ -604,8 +592,6 @@ void gap_thread_stop(void) {
gap->command_queue = NULL;
furi_timer_free(gap->advertise_timer);
gap->advertise_timer = NULL;
furi_semaphore_free(gap->tx_pool_busy);
gap->tx_pool_busy = NULL;

ble_event_dispatcher_reset();
free(gap);
Expand Down
2 changes: 0 additions & 2 deletions targets/f7/ble_glue/gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ void gap_thread_stop(void);

void gap_emit_ble_beacon_status_event(bool active);

void gap_wait_for_tx_pool_available(FuriWait wait);

#ifdef __cplusplus
}
#endif

0 comments on commit 33ef5c3

Please sign in to comment.