Esempio n. 1
0
/**
 * Event loop for the main bleprph task.
 */
static void
bleprph_task_handler(void *unused)
{
    struct os_event *ev;
    struct os_callout_func *cf;
    int rc;

    rc = ble_hs_start();
    assert(rc == 0);

    /* Begin advertising. */
    bleprph_advertise();

    while (1) {
        ev = os_eventq_get(&bleprph_evq);
        switch (ev->ev_type) {
        case OS_EVENT_T_TIMER:
            cf = (struct os_callout_func *)ev;
            assert(cf->cf_func);
            cf->cf_func(CF_ARG(cf));
            break;
        default:
            assert(0);
            break;
        }
    }
}
Esempio n. 2
0
/**
 * BLE test task
 *
 * @param arg
 */
void
prphtest_task_handler(void *arg)
{
    struct ble_hs_adv_fields fields;
    struct os_callout_func *cf;
    struct os_event *ev;
    int rc;

    /* We are initialized */
    console_printf("ADVERTISER\n");

    /* Initialize eventq */
    os_eventq_init(&g_prphtest_evq);

    /* Init prphtest variables */
    g_prphtest_state = 0;
    g_next_os_time = os_time_get();

    ble_gap_conn_set_cb(prphtest_on_connect, NULL);

    prphtest_register_attrs();

    memset(&fields, 0, sizeof fields);
    fields.name = (uint8_t *)"nimble";
    fields.name_len = 6;
    fields.name_is_complete = 1;
    rc = ble_gap_conn_set_adv_fields(&fields);
    assert(rc == 0);

    rc = ble_gap_conn_advertise(BLE_GAP_DISC_MODE_NON, BLE_GAP_CONN_MODE_UND,
                                NULL, 0);
    assert(rc == 0);

    while (1) {
        ev = os_eventq_get(&g_prphtest_evq);
        switch (ev->ev_type) {
        case OS_EVENT_T_TIMER:
            cf = (struct os_callout_func *)ev;
            assert(cf->cf_func);
            cf->cf_func(cf->cf_arg);
            break;
        default:
            assert(0);
            break;
        }
    }
}
Esempio n. 3
0
static void
ble_hs_event_handle(void *unused)
{
    struct os_callout_func *cf;
    struct os_event *ev;
    os_sr_t sr;

    while (1) {
        OS_ENTER_CRITICAL(sr);
        ev = STAILQ_FIRST(&ble_hs_evq.evq_list);
        OS_EXIT_CRITICAL(sr);

        if (ev == NULL) {
            break;
        }

        ev = os_eventq_get(&ble_hs_evq);
        switch (ev->ev_type) {
        case OS_EVENT_T_TIMER:
            cf = (struct os_callout_func *)ev;
            assert(cf->cf_func);
            cf->cf_func(ev->ev_arg);
            break;

        case BLE_HOST_HCI_EVENT_CTLR_EVENT:
            /* Process HCI event from controller */
            host_hci_os_event_proc(ev);
            break;

        case OS_EVENT_T_MQUEUE_DATA:
            ble_hs_process_tx_data_queue();
            ble_hs_process_rx_data_queue();
            break;

        default:
            BLE_HS_DBG_ASSERT(0);
            break;
        }
    }
}
Esempio n. 4
0
/**
 * BLE test task 
 * 
 * @param arg 
 */
void
bletest_task_handler(void *arg)
{
    int rc;
    uint64_t event_mask;
    struct os_event *ev;
    struct os_callout_func *cf;

    /* Set LED blink rate */
    g_bletest_led_rate = OS_TICKS_PER_SEC / 20;

    /* Wait one second before starting test task */
    os_time_delay(OS_TICKS_PER_SEC);

    /* Initialize eventq */
    os_eventq_init(&g_bletest_evq);

    /* Initialize the host timer */
    os_callout_func_init(&g_bletest_timer, &g_bletest_evq, bletest_timer_cb,
                         NULL);

    /* Send the reset command first */
    rc = host_hci_cmd_send(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET,
                           0, NULL);
    assert(rc == 0);
    host_hci_outstanding_opcode = 0;

#if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER)
    /* Initialize the advertiser */
    console_printf("Starting BLE test task as advertiser\n");
    bletest_init_advertising();
#endif

#if (BLETEST_CFG_ROLE == BLETEST_ROLE_SCANNER)
    /* Initialize the scanner */
    console_printf("Starting BLE test task as scanner\n");
    bletest_init_scanner();
#endif

#if (BLETEST_CFG_ROLE == BLETEST_ROLE_INITIATOR)
    /* Initialize the scanner */
    console_printf("Starting BLE test task as initiator\n");
    bletest_init_initiator();
#endif

    /* Set the event mask we want to display */
    event_mask = 0x7FF;
    rc = host_hci_cmd_le_set_event_mask(event_mask);
    assert(rc == 0);
    host_hci_outstanding_opcode = 0;

    /* Turn on all events */
    event_mask = 0xffffffffffffffff;
    rc = host_hci_cmd_set_event_mask(event_mask);
    assert(rc == 0);
    host_hci_outstanding_opcode = 0;

    /* Turn on all events */
    rc = host_hci_cmd_rd_local_version();
    assert(rc == 0);
    host_hci_outstanding_opcode = 0;

    /* Wait some time before starting */
    os_time_delay(OS_TICKS_PER_SEC);

    /* Init bletest variables */
    g_bletest_state = 0;
    g_next_os_time = os_time_get();

    /* Begin advertising if we are an advertiser */
#if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER)
    rc = host_hci_cmd_le_set_adv_enable(1);
    assert(rc == 0);
    host_hci_outstanding_opcode = 0;
#endif

    bletest_timer_cb(NULL);

    while (1) {
        ev = os_eventq_get(&g_bletest_evq);
        switch (ev->ev_type) {
        case OS_EVENT_T_TIMER:
            cf = (struct os_callout_func *)ev;
            assert(cf->cf_func);
            cf->cf_func(cf->cf_arg);
            break;
        default:
            assert(0);
            break;
        }
    }
}