Continued working on BLE rf modem sleep feature : issue when trying to wake rf modem up before sending data by writing to a characteristic
This commit is contained in:
parent
13e7553d09
commit
54a22beaf7
@ -117,16 +117,31 @@ bool is_ble_modem_on(void)
|
|||||||
|
|
||||||
bool ble_modem_sleep(void)
|
bool ble_modem_sleep(void)
|
||||||
{
|
{
|
||||||
bool status = tls_bt_ctrl_sleep(true);
|
tls_bt_status_t status = tls_bt_ctrl_sleep(true);
|
||||||
if(status)_ble_modem_is_sleeping = true;
|
if(status == TLS_BT_STATUS_SUCCESS)
|
||||||
return status;
|
{
|
||||||
|
_ble_modem_is_sleeping = true;
|
||||||
|
TLS_BT_APPL_TRACE_DEBUG("ble modem sleeping"NEW_LINE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ble_modem_wake(void)
|
bool ble_modem_wake(void)
|
||||||
{
|
{
|
||||||
bool status = tls_bt_ctrl_sleep(false);
|
tls_bt_status_t status = tls_bt_ctrl_sleep(false);
|
||||||
if(status)_ble_modem_is_sleeping = false;
|
if(status == TLS_BT_STATUS_SUCCESS)
|
||||||
return status;
|
{
|
||||||
|
if(tls_bt_ctrl_wakeup() == TLS_BT_STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
_ble_modem_is_sleeping = false;
|
||||||
|
TLS_BT_APPL_TRACE_DEBUG("ble modem awaken"NEW_LINE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ble_modem_is_sleeping(void)
|
bool ble_modem_is_sleeping(void)
|
||||||
|
@ -389,8 +389,6 @@ bool ble_service_send_nus_data(const uint8_t *data, uint16_t length)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ble_modem_is_sleeping())ble_modem_wake();
|
|
||||||
|
|
||||||
notification_data.transfer_in_progress = true;
|
notification_data.transfer_in_progress = true;
|
||||||
notification_data.data = data;
|
notification_data.data = data;
|
||||||
notification_data.length = length;
|
notification_data.length = length;
|
||||||
@ -511,6 +509,8 @@ static bool ble_service_advertise(bool enable)
|
|||||||
|
|
||||||
if(enable)
|
if(enable)
|
||||||
{
|
{
|
||||||
|
if(!ble_modem_is_sleeping())ble_modem_sleep();
|
||||||
|
|
||||||
struct ble_hs_adv_fields advertisement_fields = {0};
|
struct ble_hs_adv_fields advertisement_fields = {0};
|
||||||
uint8_t own_addr_type = BLE_OWN_ADDR_RANDOM;
|
uint8_t own_addr_type = BLE_OWN_ADDR_RANDOM;
|
||||||
|
|
||||||
@ -765,7 +765,6 @@ static int ble_gap_event_cb(struct ble_gap_event *event, void *arg)
|
|||||||
TLS_BT_APPL_TRACE_VERBOSE("last data chunk sent, end of the transfer"NEW_LINE);
|
TLS_BT_APPL_TRACE_VERBOSE("last data chunk sent, end of the transfer"NEW_LINE);
|
||||||
// All data have been sent, end of the transfer
|
// All data have been sent, end of the transfer
|
||||||
reset_data_being_sent(¬ification_data);
|
reset_data_being_sent(¬ification_data);
|
||||||
if(!ble_modem_is_sleeping())ble_modem_sleep();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Indication
|
else // Indication
|
||||||
@ -945,6 +944,7 @@ static int gatt_nus_char_access_cb(uint16_t conn_handle, uint16_t attr_handle, s
|
|||||||
{
|
{
|
||||||
case BLE_GATT_ACCESS_OP_WRITE_CHR:
|
case BLE_GATT_ACCESS_OP_WRITE_CHR:
|
||||||
{
|
{
|
||||||
|
if(ble_modem_is_sleeping())ble_modem_wake();
|
||||||
struct os_mbuf *om_buf = ctxt->om;
|
struct os_mbuf *om_buf = ctxt->om;
|
||||||
while(om_buf)
|
while(om_buf)
|
||||||
{
|
{
|
||||||
|
@ -183,7 +183,6 @@ static void nus_data_rx_cb(const uint8_t *data, uint16_t length)
|
|||||||
gadget_bridge_parser_code_e code;
|
gadget_bridge_parser_code_e code;
|
||||||
while((code = gadget_bridge_parser_run()) == GADGET_BRIDGE_PARSER_CODE_PARSING);
|
while((code = gadget_bridge_parser_run()) == GADGET_BRIDGE_PARSER_CODE_PARSING);
|
||||||
shell_printf("Gadget bridge parser code : %s"NEW_LINE, gadget_bridge_parser_code_2_str(code));
|
shell_printf("Gadget bridge parser code : %s"NEW_LINE, gadget_bridge_parser_code_2_str(code));
|
||||||
//ble_modem_wake();
|
|
||||||
//shell_puts("#"NEW_LINE);
|
//shell_puts("#"NEW_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,6 +662,15 @@ void tls_bt_controller_sleep_exit_cb(void)
|
|||||||
//shell_printf("BT CTRL wakeup"NEW_LINE);
|
//shell_printf("BT CTRL wakeup"NEW_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void demo_timer_irq(void *arg)
|
||||||
|
{
|
||||||
|
bool *sleeping = arg;
|
||||||
|
if(*sleeping)
|
||||||
|
ble_modem_sleep();
|
||||||
|
else
|
||||||
|
ble_modem_wake();
|
||||||
|
}
|
||||||
|
|
||||||
int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||||
{
|
{
|
||||||
if(argc > 1)
|
if(argc > 1)
|
||||||
@ -681,6 +689,7 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
ble_service_register_nus_data_rx_cb(&(nus_data_rx_cb));
|
ble_service_register_nus_data_rx_cb(&(nus_data_rx_cb));
|
||||||
ble_service_set_pairing_passkey(123456);
|
ble_service_set_pairing_passkey(123456);
|
||||||
|
|
||||||
|
if(!ble_modem_is_sleeping())ble_modem_sleep();
|
||||||
tls_bt_register_sleep_callback(tls_bt_controller_sleep_enter_cb, tls_bt_controller_sleep_exit_cb);
|
tls_bt_register_sleep_callback(tls_bt_controller_sleep_enter_cb, tls_bt_controller_sleep_exit_cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -737,7 +746,7 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
|
|
||||||
to_return = gadget_bridge_send_toast(toast_type, argv[4]);
|
to_return = gadget_bridge_send_toast(toast_type, argv[4]);
|
||||||
}
|
}
|
||||||
if(strcmp(argv[2], "ver") == 0 && argc == 5)
|
else if(strcmp(argv[2], "ver") == 0 && argc == 5)
|
||||||
{
|
{
|
||||||
to_return = gadget_bridge_send_firmware_version(argv[3], argv[4]);
|
to_return = gadget_bridge_send_firmware_version(argv[3], argv[4]);
|
||||||
}
|
}
|
||||||
@ -862,9 +871,23 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
{
|
{
|
||||||
if(argc == 3)
|
if(argc == 3)
|
||||||
{
|
{
|
||||||
bool sleeping = strtoul(argv[2], NULL, 10);
|
static bool sleeping;
|
||||||
bool status = sleeping ? ble_modem_sleep() : ble_modem_wake();
|
sleeping = strtoul(argv[2], NULL, 10);
|
||||||
shell_printf("BLE modem set to sleeping : %d"NEW_LINE, status);
|
|
||||||
|
static uint8_t timer_id = WM_TIMER_ID_INVALID;
|
||||||
|
if(timer_id == WM_TIMER_ID_INVALID)
|
||||||
|
{
|
||||||
|
struct tls_timer_cfg timer_cfg;
|
||||||
|
|
||||||
|
timer_cfg.unit = TLS_TIMER_UNIT_MS;
|
||||||
|
timer_cfg.timeout = 2000;
|
||||||
|
timer_cfg.is_repeat = 0;
|
||||||
|
timer_cfg.callback = (tls_timer_irq_callback)demo_timer_irq;
|
||||||
|
timer_cfg.arg = &sleeping;
|
||||||
|
timer_id = tls_timer_create(&timer_cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_timer_start(timer_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(strcmp(argv[1], "ble_modem_wake") == 0)
|
else if(strcmp(argv[1], "ble_modem_wake") == 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user