Help with Understanding Atmel Software Framework a bit more - Atmel SAMB11

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everybody,

 

I am new to Bluetooth and so when looking through the code to try and understand how to connect two microcontrollers from two different manufacturers I ran into the following function which is located in the ble_manager.c file of most Atmel SAMB11 Xplained Pro demos:

 

ble_mgr_events_callback_handler(ble_mgr_event_cb_t event_cb_type, 
                                    ble_mgr_event_t event_type,
                                    const ble_event_callback_t *ble_event_handler)

 

So this ble_event_handler is passed into this function, which contains an array of function pointers such as ble_scan_report_handler, ble_connected_state_handler, etc.  What I am having trouble seeing is how are all these functions being called when scanning and connecting to another device, is it all being handled in the background with the ble_event_task()?

MADEIT

Last Edited: Wed. Mar 1, 2017 - 10:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi mac124,

 

I just joined this forum so I might be a bit late, but I spent some time understanding this so here are some precisions.

 

If you read ble_mgr_events_callback_handler, you can see that it registers the callback to the following arrays :

(ble_manager.c:84)

const ble_event_callback_t *ble_mgr_gap_event_cb[MAX_GAP_EVENT_SUBSCRIBERS];
const ble_event_callback_t *ble_mgr_gatt_client_event_cb[MAX_GATT_CLIENT_SUBSCRIBERS];
const ble_event_callback_t *ble_mgr_gatt_server_event_cb[MAX_GATT_SERVER_SUBSCRIBERS];
const ble_event_callback_t *ble_mgr_l2cap_event_cb[MAX_L2CAP_EVENT_SUBSCRIBERS];
const ble_event_callback_t *ble_mgr_htpt_event_cb[MAX_HTPT_EVENT_SUBSCRIBERS];
const ble_event_callback_t *ble_mgr_dtm_event_cb[MAX_DTM_EVENT_SUBSCRIBERS];
const ble_event_callback_t *ble_mgr_custom_event_cb[MAX_CUSTOM_EVENT_SUBSCRIBERS];

ble_event_task() is nothing more than a call to at_ble_event_get() to get the last event from the stack (this is a blocking call) then forwarding this event to ble_event_manager(). This function "distributes" this event to the correct handler(s) (there can be multiple handlers for each event) using the arrays that I talked about above.

 

The events are grouped by types (this is the event_type parameter in ble_mgr_events_callback_handler), and each event has a code, here is the list :

/* GAP events */
AT_BLE_UNDEFINED_EVENT, 0
AT_BLE_SCAN_INFO, 1
AT_BLE_SCAN_REPORT, 2
AT_BLE_ADV_REPORT, 3 
AT_BLE_RAND_ADDR_CHANGED, 4
AT_BLE_CONNECTED, 5
AT_BLE_DISCONNECTED, 6
AT_BLE_CONN_PARAM_UPDATE_DONE, 7
AT_BLE_CONN_PARAM_UPDATE_REQUEST, 8
AT_BLE_PAIR_DONE, 9
AT_BLE_PAIR_REQUEST, 10
AT_BLE_SLAVE_SEC_REQUEST, 11
AT_BLE_PAIR_KEY_REQUEST, 12
AT_BLE_ENCRYPTION_REQUEST, 13
AT_BLE_ENCRYPTION_STATUS_CHANGED, 14
AT_BLE_RESOLV_RAND_ADDR_STATUS, 15
AT_BLE_SIGN_COUNTERS_IND, 15
AT_BLE_PEER_ATT_INFO_IND, 17
AT_BLE_CON_CHANNEL_MAP_IND, 18

/* GATT Client events */ 
AT_BLE_PRIMARY_SERVICE_FOUND, 19
AT_BLE_INCLUDED_SERVICE_FOUND, 20
AT_BLE_CHARACTERISTIC_FOUND, 21
AT_BLE_DESCRIPTOR_FOUND, 22
AT_BLE_DISCOVERY_COMPLETE, 23
AT_BLE_CHARACTERISTIC_READ_RESPONSE, 24
AT_BLE_CHARACTERISTIC_READ_BY_UUID_RESPONSE = AT_BLE_CHARACTERISTIC_READ_RESPONSE, 24
AT_BLE_CHARACTERISTIC_READ_MULTIBLE_RESPONSE, 25
AT_BLE_CHARACTERISTIC_WRITE_RESPONSE, 26
AT_BLE_NOTIFICATION_RECIEVED, 27
AT_BLE_INDICATION_RECIEVED, 28

/* GATT Server events */
AT_BLE_NOTIFICATION_CONFIRMED, 29
AT_BLE_INDICATION_CONFIRMED, 30
AT_BLE_CHARACTERISTIC_CHANGED, 31
AT_BLE_CHARACTERISTIC_CONFIGURATION_CHANGED, 32
AT_BLE_SERVICE_CHANGED_INDICATION_SENT, 33
AT_BLE_WRITE_AUTHORIZE_REQUEST, 34
AT_BLE_MTU_CHANGED_INDICATION, 35
AT_BLE_MTU_CHANGED_CMD_COMPLETE, 36
AT_BLE_CHARACTERISTIC_WRITE_CMD_CMP, 37
AT_BLE_READ_AUTHORIZE_REQUEST, 38

/* L2CAP events */
AT_BLE_LECB_CONN_REQ, 39
AT_BLE_LECB_CONNECTED, 40
AT_BLE_LECB_DISCONNECTED, 41
AT_BLE_LECB_ADD_CREDIT_IND, 42
AT_BLE_LECB_SEND_RESP, 43
AT_BLE_LECB_DATA_RECIEVED, 44


/* HTPT Health Thermometer Profile events */
AT_BLE_HTPT_CREATE_DB_CFM, 45
AT_BLE_HTPT_ERROR_IND, 46
AT_BLE_HTPT_DISABLE_IND, 47
AT_BLE_HTPT_TEMP_SEND_CFM, 48
AT_BLE_HTPT_MEAS_INTV_CHG_IND, 49
AT_BLE_HTPT_CFG_INDNTF_IND, 50

AT_BLE_HTPT_ENABLE_RSP, 51
AT_BLE_HTPT_MEAS_INTV_UPD_RSP, 52
AT_BLE_HTPT_MEAS_INTV_CHG_REQ, 53
/* DTM events */
AT_BLE_LE_TEST_STATUS, 54
AT_BLE_LE_PACKET_REPORT, 55
/* Custom user defined events */
AT_BLE_CUSTOM_EVENT, 56

AT_BLE_DEVICE_READY, 57

AT_PLATFORM_EVENT, 58

AT_BLE_EVENT_MAX 59

Hope this helps

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you that does help a lot!

MADEIT