void demo_task_3(void *arg) { #ifndef CONFIG_AOS_CLI // int count = 0; #endif soc_init(); // bsp_board_leds_init(); while (1) { #ifndef CONFIG_AOS_CLI //printf("hello world! count %d\n", count++); #endif bsp_board_led_on(0); bsp_board_led_invert(1); // nrf_delay_ms(500); // //sleep 1 second krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND); } }
/**@brief AMT Client Handler. */ void amtc_evt_handler(nrf_ble_amtc_t * p_amt_c, nrf_ble_amtc_evt_t * p_evt) { uint32_t err_code; switch (p_evt->evt_type) { case NRF_BLE_AMT_C_EVT_DISCOVERY_COMPLETE: { NRF_LOG_INFO("AMT service discovered on peer.\r\n"); err_code = nrf_ble_amtc_handles_assign(p_amt_c , p_evt->conn_handle, &p_evt->params.peer_db); APP_ERROR_CHECK(err_code); // Enable notifications. err_code = nrf_ble_amtc_notif_enable(p_amt_c); APP_ERROR_CHECK(err_code); } break; case NRF_BLE_AMT_C_EVT_NOTIFICATION: { static uint32_t bytes_cnt = 0; static uint32_t kbytes_cnt = 0; if (p_evt->params.hvx.bytes_sent == 0) { bytes_cnt = 0; kbytes_cnt = 0; } bytes_cnt += p_evt->params.hvx.notif_len; if (bytes_cnt > 1024) { bsp_board_led_invert(LED_PROGRESS); bytes_cnt -= 1024; kbytes_cnt++; NRF_LOG_INFO("Received %u kbytes\r\n", kbytes_cnt); nrf_ble_amts_rbc_set(&m_amts, p_evt->params.hvx.bytes_rcvd); } if (p_evt->params.hvx.bytes_rcvd >= AMT_BYTE_TRANSFER_CNT) { bsp_board_led_off(LED_PROGRESS); bytes_cnt = 0; kbytes_cnt = 0; NRF_LOG_INFO("Transfer complete, received %u bytes of ATT payload.\r\n", p_evt->params.hvx.bytes_rcvd); nrf_ble_amts_rbc_set(&m_amts, p_evt->params.hvx.bytes_rcvd); } } break; case NRF_BLE_AMT_C_EVT_RBC_READ_RSP: { NRF_LOG_INFO("Peer received %u bytes of ATT payload.\r\n", (p_evt->params.rcv_bytes_cnt)); test_terminate(); } break; default: break; } }
/**@brief AMT Service Handler. */ static void amts_evt_handler(nrf_ble_amts_evt_t evt) { ret_code_t err_code; switch (evt.evt_type) { case SERVICE_EVT_NOTIF_ENABLED: { NRF_LOG_INFO("Notifications enabled.\r\n"); bsp_board_led_on(LED_READY); m_notif_enabled = true; if (m_board_role != BOARD_TESTER) { return; } if (m_gap_role == BLE_GAP_ROLE_PERIPH) { m_conn_interval_configured = false; m_conn_param.min_conn_interval = m_test_params.conn_interval; m_conn_param.max_conn_interval = m_test_params.conn_interval + 1; err_code = ble_conn_params_change_conn_params(&m_conn_param); if (err_code != NRF_SUCCESS) { NRF_LOG_ERROR("ble_conn_params_change_conn_params() failed: 0x%x.\r\n", err_code); } } if (m_gap_role == BLE_GAP_ROLE_CENTRAL) { m_conn_interval_configured = true; m_conn_param.min_conn_interval = m_test_params.conn_interval; m_conn_param.max_conn_interval = m_test_params.conn_interval; err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_conn_param); if (err_code != NRF_SUCCESS) { NRF_LOG_ERROR("sd_ble_gap_conn_param_update() failed: 0x%x.\r\n", err_code); } } } break; case SERVICE_EVT_NOTIF_DISABLED: { NRF_LOG_INFO("Notifications disabled.\r\n"); bsp_board_led_off(LED_READY); } break; case SERVICE_EVT_TRANSFER_1KB: { NRF_LOG_INFO("Sent %u KBytes\r\n", (evt.bytes_transfered_cnt / 1024)); bsp_board_led_invert(LED_PROGRESS); } break; case SERVICE_EVT_TRANSFER_FINISHED: { // Stop counter as soon as possible. counter_stop(); bsp_board_led_off(LED_PROGRESS); bsp_board_led_on(LED_FINISHED); uint32_t time_ms = counter_get(); uint32_t bit_count = (evt.bytes_transfered_cnt * 8); float throughput = (((float)(bit_count * 100) / time_ms) / 1024); NRF_LOG_INFO("Done.\r\n\r\n"); NRF_LOG_INFO("=============================\r\n"); NRF_LOG_INFO("Time: %u.%.2u seconds elapsed.\r\n", (counter_get() / 100), (counter_get() % 100)); NRF_LOG_INFO("Throughput: " NRF_LOG_FLOAT_MARKER " Kbits/s.\r\n", NRF_LOG_FLOAT(throughput)); NRF_LOG_INFO("=============================\r\n"); NRF_LOG_INFO("Sent %u bytes of ATT payload.\r\n", evt.bytes_transfered_cnt); NRF_LOG_INFO("Retrieving amount of bytes received from peer...\r\n"); err_code = nrf_ble_amtc_rcb_read(&m_amtc); if (err_code != NRF_SUCCESS) { NRF_LOG_ERROR("nrf_ble_amtc_rcb_read() failed: 0x%x.\r\n", err_code); test_terminate(); } } break; } }
/**@brief Handle events from alert timer. * * @param[in] p_context parameter registered in timer start function. */ static void alert_timer_handler(void * p_context) { UNUSED_PARAMETER(p_context); bsp_board_led_invert(BSP_LED_ALERT); }
/**@brief Configure leds to indicate required state. * @param[in] indicate State to be indicated. */ static uint32_t bsp_led_indication(bsp_indication_t indicate) { uint32_t err_code = NRF_SUCCESS; uint32_t next_delay = 0; if (m_leds_clear) { m_leds_clear = false; leds_off(); } switch (indicate) { case BSP_INDICATE_IDLE: leds_off(); err_code = app_timer_stop(m_bsp_leds_tmr); m_stable_state = indicate; break; case BSP_INDICATE_SCANNING: case BSP_INDICATE_ADVERTISING: // in advertising blink LED_0 if (bsp_board_led_state_get(BSP_LED_INDICATE_INDICATE_ADVERTISING)) { bsp_board_led_off(BSP_LED_INDICATE_INDICATE_ADVERTISING); next_delay = indicate == BSP_INDICATE_ADVERTISING ? ADVERTISING_LED_OFF_INTERVAL : ADVERTISING_SLOW_LED_OFF_INTERVAL; } else { bsp_board_led_on(BSP_LED_INDICATE_INDICATE_ADVERTISING); next_delay = indicate == BSP_INDICATE_ADVERTISING ? ADVERTISING_LED_ON_INTERVAL : ADVERTISING_SLOW_LED_ON_INTERVAL; } m_stable_state = indicate; err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(next_delay), NULL); break; case BSP_INDICATE_ADVERTISING_WHITELIST: // in advertising quickly blink LED_0 if (bsp_board_led_state_get(BSP_LED_INDICATE_ADVERTISING_WHITELIST)) { bsp_board_led_off(BSP_LED_INDICATE_ADVERTISING_WHITELIST); next_delay = indicate == BSP_INDICATE_ADVERTISING_WHITELIST ? ADVERTISING_WHITELIST_LED_OFF_INTERVAL : ADVERTISING_SLOW_LED_OFF_INTERVAL; } else { bsp_board_led_on(BSP_LED_INDICATE_ADVERTISING_WHITELIST); next_delay = indicate == BSP_INDICATE_ADVERTISING_WHITELIST ? ADVERTISING_WHITELIST_LED_ON_INTERVAL : ADVERTISING_SLOW_LED_ON_INTERVAL; } m_stable_state = indicate; err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(next_delay), NULL); break; case BSP_INDICATE_ADVERTISING_SLOW: // in advertising slowly blink LED_0 if (bsp_board_led_state_get(BSP_LED_INDICATE_ADVERTISING_SLOW)) { bsp_board_led_off(BSP_LED_INDICATE_ADVERTISING_SLOW); next_delay = indicate == BSP_INDICATE_ADVERTISING_SLOW ? ADVERTISING_SLOW_LED_OFF_INTERVAL : ADVERTISING_SLOW_LED_OFF_INTERVAL; } else { bsp_board_led_on(BSP_LED_INDICATE_ADVERTISING_SLOW); next_delay = indicate == BSP_INDICATE_ADVERTISING_SLOW ? ADVERTISING_SLOW_LED_ON_INTERVAL : ADVERTISING_SLOW_LED_ON_INTERVAL; } m_stable_state = indicate; err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(next_delay), NULL); break; case BSP_INDICATE_ADVERTISING_DIRECTED: // in advertising very quickly blink LED_0 if (bsp_board_led_state_get(BSP_LED_INDICATE_ADVERTISING_DIRECTED)) { bsp_board_led_off(BSP_LED_INDICATE_ADVERTISING_DIRECTED); next_delay = indicate == BSP_INDICATE_ADVERTISING_DIRECTED ? ADVERTISING_DIRECTED_LED_OFF_INTERVAL : ADVERTISING_SLOW_LED_OFF_INTERVAL; } else { bsp_board_led_on(BSP_LED_INDICATE_ADVERTISING_DIRECTED); next_delay = indicate == BSP_INDICATE_ADVERTISING_DIRECTED ? ADVERTISING_DIRECTED_LED_ON_INTERVAL : ADVERTISING_SLOW_LED_ON_INTERVAL; } m_stable_state = indicate; err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(next_delay), NULL); break; case BSP_INDICATE_BONDING: // in bonding fast blink LED_0 bsp_board_led_invert(BSP_LED_INDICATE_BONDING); m_stable_state = indicate; err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(BONDING_INTERVAL), NULL); break; case BSP_INDICATE_CONNECTED: bsp_board_led_on(BSP_LED_INDICATE_CONNECTED); m_stable_state = indicate; break; case BSP_INDICATE_SENT_OK: // when sending shortly invert LED_1 m_leds_clear = true; bsp_board_led_invert(BSP_LED_INDICATE_SENT_OK); err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(SENT_OK_INTERVAL), NULL); break; case BSP_INDICATE_SEND_ERROR: // on receving error invert LED_1 for long time m_leds_clear = true; bsp_board_led_invert(BSP_LED_INDICATE_SEND_ERROR); err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(SEND_ERROR_INTERVAL), NULL); break; case BSP_INDICATE_RCV_OK: // when receving shortly invert LED_1 m_leds_clear = true; bsp_board_led_invert(BSP_LED_INDICATE_RCV_OK); err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(RCV_OK_INTERVAL), NULL); break; case BSP_INDICATE_RCV_ERROR: // on receving error invert LED_1 for long time m_leds_clear = true; bsp_board_led_invert(BSP_LED_INDICATE_RCV_ERROR); err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(RCV_ERROR_INTERVAL), NULL); break; case BSP_INDICATE_FATAL_ERROR: // on fatal error turn on all leds bsp_board_leds_on(); m_stable_state = indicate; break; case BSP_INDICATE_ALERT_0: case BSP_INDICATE_ALERT_1: case BSP_INDICATE_ALERT_2: case BSP_INDICATE_ALERT_3: case BSP_INDICATE_ALERT_OFF: err_code = app_timer_stop(m_bsp_alert_tmr); next_delay = (uint32_t)BSP_INDICATE_ALERT_OFF - (uint32_t)indicate; // a little trick to find out that if it did not fall through ALERT_OFF if (next_delay && (err_code == NRF_SUCCESS)) { if (next_delay > 1) { err_code = app_timer_start(m_bsp_alert_tmr, APP_TIMER_TICKS(((uint16_t)next_delay * ALERT_INTERVAL)), NULL); } bsp_board_led_on(BSP_LED_ALERT); m_alert_on = true; } else { bsp_board_led_off(BSP_LED_ALERT); m_alert_on = false; } break; case BSP_INDICATE_USER_STATE_OFF: leds_off(); m_stable_state = indicate; break; case BSP_INDICATE_USER_STATE_0: leds_off(); bsp_board_led_on(BSP_LED_INDICATE_USER_LED1); m_stable_state = indicate; break; case BSP_INDICATE_USER_STATE_1: leds_off(); bsp_board_led_on(BSP_LED_INDICATE_USER_LED2); m_stable_state = indicate; break; case BSP_INDICATE_USER_STATE_2: leds_off(); bsp_board_led_on(BSP_LED_INDICATE_USER_LED1); bsp_board_led_on(BSP_LED_INDICATE_USER_LED2); m_stable_state = indicate; break; case BSP_INDICATE_USER_STATE_3: case BSP_INDICATE_USER_STATE_ON: bsp_board_leds_on(); m_stable_state = indicate; break; default: break; } return err_code; }