Merge branch 'develop'

This commit is contained in:
Matthias Ringwald 2016-08-23 10:03:23 +02:00
commit b05d5f46fb
5 changed files with 88 additions and 15 deletions

View File

@ -19,9 +19,9 @@ that is necessary to setup BTstack. From the point when the run loop
is executed, the application runs as a finite
state machine, which processes events received from BTstack. BTstack
groups events logically and provides them via packet handlers.
We provide their overview here, and finally, for the case that there is a need to inspect the data exchanged
We provide their overview here. For the case that there is a need to inspect the data exchanged
between BTstack and the Bluetooth chipset, we describe how to configure
packet logging mechanism.
packet logging mechanism. Finally, we provide an overview on power management in Bluetooth in general and how to save energy in BTstack.
## Configuration in btstack_config.h {#sec:btstackConfigHowTo}
@ -477,3 +477,49 @@ In addition to the HCI packets, you can also enable BTstack's debug information
to the btstack_config.h and recompiling your application.
## Bluetooth Power Control {#sec:powerControl}
In most BTstack examples, the device is set to be discoverable and connectable. In this mode, even when there's no active connection, the Bluetooth Controller will periodicaly activate its receiver in order to listen for inquiries or connecting requests from another device.
The ability to be discoverable requires more energy than the ability to be connected. Being discoverable also announces the device to anybody in the area. Therefore, it is a good idea to pause listening for inquiries when not needed. Other devices that have your Bluetooth address can still connect to your device.
To enable/disable discoverabilty, you can call:
/**
* @brief Allows to control if device is discoverable. OFF by default.
*/
void gap_discoverable_control(uint8_t enable);
If you don't need to become connected from other devices for a longer period of time, you can also disable the listening to connection requests.
To enable/disable connectability, you can call:
/**
* @brief Override page scan mode. Page scan mode enabled by l2cap when services are registered
* @note Might be used to reduce power consumption while Bluetooth module stays powered but no (new)
* connections are expected
*/
void gap_connectable_control(uint8_t enable);
For Bluetooth Low Energy, the radio is periodically used to broadcast advertisements that are used for both discovery and connection establishment.
To enable/disable advertisements, you can call:
/**
* @brief Enable/Disable Advertisements. OFF by default.
* @param enabled
*/
void gap_advertisements_enable(int enabled);
If a Bluetooth Controller is neither discoverable nor conectable, it does not need to periodically turn on its radio and it only needs to respond to commands from the Host. In this case, the Bluetooth Controller is free to enter some kind of deep sleep where the power consumption is minimal.
Finally, if that's not sufficient for your application, you could request BTstack to shutdown the Bluetooth Controller. For this, the "on" and "off" functions in the btstack_control_t struct must be implemented. To shutdown the Bluetooth Controller, you can call:
/**
* @brief Requests the change of BTstack power mode.
*/
int hci_power_control(HCI_POWER_MODE mode);
with mode set to *HCI_POWER_OFF*. When needed later, Bluetooth can be started again via by calling it with mode *HCI_POWER_ON*, as seen in all examples.

View File

@ -141,6 +141,8 @@ static void local_version_information_callback(uint8_t * packet){
hci_set_chipset(btstack_chipset_cc256x_instance());
#ifdef ENABLE_EHCILL
printf("eHCILL enabled.\n");
#else
printf("eHCILL disable.\n");
#endif
break;
case COMPANY_ID_BROADCOM_CORPORATION:

View File

@ -178,11 +178,15 @@ static wiced_result_t h4_rx_worker_receive_packet(void * arg){
// executed on tx worker thread
static wiced_result_t h4_tx_worker_send_packet(void * arg){
#ifdef WICED_BT_UART_MANUAL_CTS_RTS
int cts_was_raised = 0;
while (platform_gpio_input_get(wiced_bt_uart_pins[WICED_BT_PIN_UART_CTS]) == WICED_TRUE){
printf(".");
wiced_rtos_delay_milliseconds(10);
wiced_rtos_delay_milliseconds(100);
cts_was_raised = 1;
}
if (cts_was_raised){
printf("\n");
}
printf("\n");
#endif
// blocking send
platform_uart_transmit_bytes(wiced_bt_uart_driver, tx_worker_data_buffer, tx_worker_data_size);
@ -193,7 +197,7 @@ static wiced_result_t h4_tx_worker_send_packet(void * arg){
static int h4_set_baudrate(uint32_t baudrate){
#ifdef _STM32F205RGT6_
#if defined(_STM32F205RGT6_) || defined(STM32F40_41xxx)
// directly use STM peripheral functions to change baud rate dynamically
@ -270,6 +274,13 @@ static int h4_open(void){
platform_gpio_init(wiced_bt_control_pins[WICED_BT_PIN_HOST_WAKE], INPUT_HIGH_IMPEDANCE);
platform_gpio_init(wiced_bt_control_pins[WICED_BT_PIN_DEVICE_WAKE], OUTPUT_PUSH_PULL);
platform_gpio_output_low(wiced_bt_control_pins[WICED_BT_PIN_DEVICE_WAKE]);
/* Configure Reg Enable pin to output. Set to HIGH */
if (wiced_bt_control_pins[ WICED_BT_PIN_POWER ]){
platform_gpio_init( wiced_bt_control_pins[ WICED_BT_PIN_POWER ], OUTPUT_OPEN_DRAIN_PULL_UP );
platform_gpio_output_high( wiced_bt_control_pins[ WICED_BT_PIN_POWER ] );
}
wiced_rtos_delay_milliseconds( 100 );
// -- init UART
@ -291,12 +302,23 @@ static int h4_open(void){
#endif
platform_uart_init( wiced_bt_uart_driver, wiced_bt_uart_peripheral, &uart_config, ring_buffer );
// reset Bluetooth
platform_gpio_init( wiced_bt_control_pins[ WICED_BT_PIN_POWER ], OUTPUT_PUSH_PULL );
platform_gpio_output_low( wiced_bt_control_pins[ WICED_BT_PIN_POWER ] );
wiced_rtos_delay_milliseconds( 100 );
platform_gpio_output_high( wiced_bt_control_pins[ WICED_BT_PIN_POWER ] );
// Reset Bluetooth via RESET line. Fallback to toggling POWER otherwise
if ( wiced_bt_control_pins[ WICED_BT_PIN_RESET ]){
platform_gpio_init( wiced_bt_control_pins[ WICED_BT_PIN_RESET ], OUTPUT_PUSH_PULL );
platform_gpio_output_high( wiced_bt_control_pins[ WICED_BT_PIN_RESET ] );
platform_gpio_output_low( wiced_bt_control_pins[ WICED_BT_PIN_RESET ] );
wiced_rtos_delay_milliseconds( 100 );
platform_gpio_output_high( wiced_bt_control_pins[ WICED_BT_PIN_RESET ] );
}
else if ( wiced_bt_control_pins[ WICED_BT_PIN_POWER ]){
platform_gpio_output_low( wiced_bt_control_pins[ WICED_BT_PIN_POWER ] );
wiced_rtos_delay_milliseconds( 100 );
platform_gpio_output_high( wiced_bt_control_pins[ WICED_BT_PIN_POWER ] );
}
// wait for Bluetooth to start up
wiced_rtos_delay_milliseconds( 500 );
// create worker threads for rx/tx. only single request is posted to their queues

View File

@ -43,7 +43,7 @@
#include "platform_bluetooth.h"
#include "wiced.h"
#include "platform/wwd_platform_interface.h"
// see generated_mac_address.txt - "macaddr=02:0A:F7:3d:76:be"
static const char * wifi_mac_address = NVRAM_GENERATED_MAC_ADDRESS;
@ -53,7 +53,7 @@ static btstack_packet_callback_registration_t hci_event_callback_registration;
static const hci_transport_config_uart_t hci_transport_config_uart = {
HCI_TRANSPORT_CONFIG_UART,
115200,
0, // 3000000,
0,
1,
NULL,
};
@ -69,8 +69,11 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
void application_start(void){
/* Initialise the WICED device */
wiced_init();
/* Initialise the WICED device without WLAN */
wiced_core_init();
/* 32 kHz clock also needed for Bluetooth */
host_platform_init_wlan_powersave_clock();
printf("BTstack on WICED\n");

View File

@ -248,7 +248,7 @@ void gap_advertisements_set_params(uint16_t adv_int_min, uint16_t adv_int_max, u
uint8_t direct_address_typ, bd_addr_t direct_address, uint8_t channel_map, uint8_t filter_policy);
/**
* @brief Enable/Disable Advertisements
* @brief Enable/Disable Advertisements. OFF by default.
* @param enabled
*/
void gap_advertisements_enable(int enabled);