nrf5/sdk: Fixing unaligned access issues for nrf51 (cortex-m0) in bluetooth le driver
This commit is contained in:
parent
44c9888511
commit
e60fa9b3e1
|
@ -287,7 +287,8 @@ bool ble_drv_service_add(ubluepy_service_obj_t * p_service_obj) {
|
|||
|
||||
ble_uuid_t uuid;
|
||||
uuid.type = p_service_obj->p_uuid->uuid_vs_idx;
|
||||
uuid.uuid = (uint16_t)(*(uint16_t *)&p_service_obj->p_uuid->value[0]);
|
||||
uuid.uuid = p_service_obj->p_uuid->value[0];
|
||||
uuid.uuid += p_service_obj->p_uuid->value[1] << 8;
|
||||
|
||||
if (sd_ble_gatts_service_add(p_service_obj->type,
|
||||
&uuid,
|
||||
|
@ -296,11 +297,14 @@ bool ble_drv_service_add(ubluepy_service_obj_t * p_service_obj) {
|
|||
"Can not add Service."));
|
||||
}
|
||||
} else if (p_service_obj->p_uuid->type == BLE_UUID_TYPE_BLE) {
|
||||
printf("adding service\n");
|
||||
|
||||
ble_uuid_t uuid;
|
||||
uuid.type = p_service_obj->p_uuid->type;
|
||||
uuid.uuid = (uint16_t)(*(uint16_t *)&p_service_obj->p_uuid->value[0]);
|
||||
uuid.uuid = p_service_obj->p_uuid->value[0];
|
||||
uuid.uuid += p_service_obj->p_uuid->value[1] << 8;
|
||||
|
||||
printf("adding service\n");
|
||||
if (sd_ble_gatts_service_add(p_service_obj->type,
|
||||
&uuid,
|
||||
&p_service_obj->handle) != 0) {
|
||||
|
@ -348,7 +352,8 @@ bool ble_drv_characteristic_add(ubluepy_characteristic_obj_t * p_char_obj) {
|
|||
}
|
||||
|
||||
uuid.type = p_char_obj->p_uuid->type;
|
||||
uuid.uuid = (uint16_t)(*(uint16_t *)&p_char_obj->p_uuid->value[0]);
|
||||
uuid.uuid = p_char_obj->p_uuid->value[0];
|
||||
uuid.uuid += p_char_obj->p_uuid->value[1] << 8;
|
||||
|
||||
memset(&attr_md, 0, sizeof(attr_md));
|
||||
|
||||
|
@ -459,8 +464,8 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
|
|||
|
||||
ble_uuid_t uuid;
|
||||
uuid.type = p_service->p_uuid->type;
|
||||
uuid.uuid = (uint16_t)(*(uint16_t *)&p_service->p_uuid->value[0]);
|
||||
|
||||
uuid.uuid = p_service->p_uuid->value[0];
|
||||
uuid.uuid += p_service->p_uuid->value[1] << 8;
|
||||
// calculate total size of uuids
|
||||
if (sd_ble_uuid_encode(&uuid, &encoded_size, NULL) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
|
||||
|
@ -481,9 +486,10 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
|
|||
|
||||
uuid_total_size += encoded_size; // size of entry
|
||||
byte_pos += encoded_size; // relative to adv data packet
|
||||
BLE_DRIVER_LOG("ADV: uuid size: %u, type: %u, uuid: %u, vs_idx: %u\n",
|
||||
BLE_DRIVER_LOG("ADV: uuid size: %u, type: %u, uuid: %x%x, vs_idx: %u\n",
|
||||
encoded_size, p_service->p_uuid->type,
|
||||
(uint16_t)(*(uint16_t *)&p_service->p_uuid->value[0]),
|
||||
p_service->p_uuid->value[1],
|
||||
p_service->p_uuid->value[0],
|
||||
p_service->p_uuid->uuid_vs_idx);
|
||||
}
|
||||
|
||||
|
@ -507,7 +513,8 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
|
|||
|
||||
ble_uuid_t uuid;
|
||||
uuid.type = p_service->p_uuid->uuid_vs_idx;
|
||||
uuid.uuid = (uint16_t)(*(uint16_t *)&p_service->p_uuid->value[0]);
|
||||
uuid.uuid = p_service->p_uuid->value[0];
|
||||
uuid.uuid += p_service->p_uuid->value[1] << 8;
|
||||
|
||||
// calculate total size of uuids
|
||||
if (sd_ble_uuid_encode(&uuid, &encoded_size, NULL) != 0) {
|
||||
|
@ -529,9 +536,10 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
|
|||
|
||||
uuid_total_size += encoded_size; // size of entry
|
||||
byte_pos += encoded_size; // relative to adv data packet
|
||||
BLE_DRIVER_LOG("ADV: uuid size: %u, type: %u, uuid: %u, vs_idx: %u\n",
|
||||
BLE_DRIVER_LOG("ADV: uuid size: %u, type: %x%x, uuid: %u, vs_idx: %u\n",
|
||||
encoded_size, p_service->p_uuid->type,
|
||||
(uint16_t)(*(uint16_t *)&p_service->p_uuid->value[0]),
|
||||
p_service->p_uuid->value[1],
|
||||
p_service->p_uuid->value[0],
|
||||
p_service->p_uuid->uuid_vs_idx);
|
||||
}
|
||||
|
||||
|
@ -556,10 +564,14 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
|
|||
m_adv_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS); // approx 8 ms
|
||||
m_adv_params.timeout = 0; // infinite advertisment
|
||||
|
||||
if (m_adv_in_progress && sd_ble_gap_adv_stop() != 0) {
|
||||
#if (BLUETOOTH_SD == 132)
|
||||
if (m_adv_in_progress == true) {
|
||||
if (sd_ble_gap_adv_stop() != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
|
||||
"Can not stop advertisment."));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
m_adv_in_progress = false;
|
||||
uint32_t err_code = sd_ble_gap_adv_start(&m_adv_params);
|
||||
|
|
Loading…
Reference in New Issue