Skip to content

Commit

Permalink
Merge branch 'feature/btdm_controller' into 'master'
Browse files Browse the repository at this point in the history
BT support

Initial version of BT support.

BT and WiFi are mutually exclusive at this point, so we have a new option to select which stack is used.
Precompiled BT libraries are added as a submodule.


See merge request !109
  • Loading branch information
wujiangang committed Sep 23, 2016
2 parents 28be72d + 6bb5a93 commit 4480ab6
Show file tree
Hide file tree
Showing 15 changed files with 529 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "components/esptool_py/esptool"]
path = components/esptool_py/esptool
url = https://github.com/themadinventor/esptool.git
[submodule "components/bt/lib"]
path = components/bt/lib
url = https://github.com/espressif/esp32-bt-lib.git
32 changes: 0 additions & 32 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,6 @@ config PYTHON
help
The executable name/path that is used to run python. On some systems Python 2.x
may need to be invoked as python2.

config MEMMAP_BT
bool "Reserve space for Bluetooth stack"
default "n"
help
The Bluetooth stack uses memory that cannot be used as generic memory anymore. This
reserves the space for that within the memory map of the compiled binary.

config MEMMAP_SMP
bool "Reserve memory for two cores"
default "y"
help
The ESP32 contains two cores. If you plan to only use one, you can disable this item
to save some memory. (ToDo: Make this automatically depend on unicore support)

config MEMMAP_TRACEMEM
bool "Use TRAX tracing feature"
default "n"
help
The ESP32 contains a feature which allows you to trace the execution path the processor
has taken through the program. This is stored in a chunk of 32K (16K for single-processor)
of memory that can't be used for general purposes anymore. Disable this if you do not know
what this is.

config MEMMAP_SPISRAM
bool "Use external SPI SRAM chip as main memory"
default "n"
help
The ESP32 can control an external SPI SRAM chip, adding the memory it contains to the
main memory map. Enable this if you have this hardware and want to use it in the same
way as on-chip RAM.

endmenu

source "$COMPONENT_KCONFIGS_PROJBUILD"
Expand Down
26 changes: 13 additions & 13 deletions components/bt/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ visible if MEMMAP_BT


config BT_ENABLED
bool "Enable low-level BT stack"
depends on MEMMAP_BT
bool
depends on ESP32_ENABLE_STACK_BT
help
This compiles in the low-level BT stack.

config BT_BTLE
bool "Enable BTLE"
depends on BT_ENABLED
help
This compiles BTLE support

config BT_BT
bool "Enable classic BT"
depends on BT_ENABLED
help
This enables classic BT support
#config BT_BTLE
# bool "Enable BTLE"
# depends on BT_ENABLED
# help
# This compiles BTLE support
#
#config BT_BT
# bool "Enable classic BT"
# depends on BT_ENABLED
# help
# This enables classic BT support

endmenu
121 changes: 121 additions & 0 deletions components/bt/bt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/xtensa_api.h"
#include "freertos/portmacro.h"
#include "esp_types.h"
#include "esp_system.h"
#include "esp_task.h"
#include "esp_intr.h"
#include "esp_attr.h"
#include "bt.h"

#if CONFIG_BT_ENABLED

/* not for user call, so don't put to include file */
extern void btdm_osi_funcs_register(void *osi_funcs);
extern void btdm_controller_init(void);


static bt_app_startup_cb_t app_startup_cb;
static void *app_startup_ctx;

#define BT_DEBUG(...)
#define BT_API_CALL_CHECK(info, api_call, ret) \
do{\
esp_err_t __err = (api_call);\
if ((ret) != __err) {\
BT_DEBUG("%s %d %s ret=%d\n", __FUNCTION__, __LINE__, (info), __err);\
return __err;\
}\
} while(0)

struct osi_funcs_t {
xt_handler (*_set_isr)(int n, xt_handler f, void *arg);
void (*_ints_on)(unsigned int mask);
void (*_interrupt_disable)(void);
void (*_interrupt_restore)(void);
void (*_task_yield)(void);
void *(*_semphr_create)(uint32_t max, uint32_t init);
void *(*_semphr_give_from_isr)(void *semphr, void *hptw);
void *(*_semphr_take)(void *semphr, uint32_t block_time);
esp_err_t (* _read_efuse_mac)(uint8_t mac[6]);
};

static portMUX_TYPE global_int_mux = portMUX_INITIALIZER_UNLOCKED;

static void IRAM_ATTR interrupt_disable(void)
{
portENTER_CRITICAL(&global_int_mux);
}

static void IRAM_ATTR interrupt_restore(void)
{
portEXIT_CRITICAL(&global_int_mux);
}

static void * IRAM_ATTR semphr_take_wrapper(void *semphr, uint32_t block_time)
{
return (void *)xSemaphoreTake(semphr, block_time);
}

static struct osi_funcs_t osi_funcs = {
._set_isr = xt_set_interrupt_handler,
._ints_on = xt_ints_on,
._interrupt_disable = interrupt_disable,
._interrupt_restore = interrupt_restore,
._task_yield = vPortYield,
._semphr_create = xQueueCreateCountingSemaphore,
._semphr_give_from_isr = (void *)xQueueGiveFromISR,
._semphr_take = semphr_take_wrapper,
._read_efuse_mac = system_efuse_read_mac,
};

static void bt_controller_task(void *pvParam)
{
btdm_osi_funcs_register(&osi_funcs);
btdm_controller_init();
}


static void bt_init_task(void *pvParameters)
{
xTaskCreatePinnedToCore(bt_controller_task, "btControllerTask", ESP_TASK_BT_CONTROLLER_STACK, NULL, ESP_TASK_BT_CONTROLLER_PRIO, NULL, 0);

if (app_startup_cb) {
app_startup_cb(app_startup_ctx);
}

vTaskDelete(NULL);
}


esp_err_t esp_bt_startup(bt_app_startup_cb_t cb, void *ctx)
{
app_startup_cb = cb;
app_startup_ctx = ctx;

xTaskCreatePinnedToCore(bt_init_task, "btInitTask", ESP_TASK_BT_INIT_STACK, NULL, ESP_TASK_BT_INIT_PRIO, NULL, 0);

return ESP_OK;
}
#endif
25 changes: 25 additions & 0 deletions components/bt/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Component Makefile
#

#COMPONENT_ADD_INCLUDEDIRS :=

CURRENT_DIR=$(IDF_PATH)/components/bt

COMPONENT_ADD_INCLUDEDIRS := ./include

CFLAGS += -Wno-error=unused-label -Wno-error=return-type -Wno-error=missing-braces -Wno-error=pointer-sign -Wno-error=parentheses

LIBS := btdm_app

COMPONENT_ADD_LDFLAGS := -lbt -L$(abspath lib) \
$(addprefix -l,$(LIBS)) \
$(LINKER_SCRIPTS)


ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
$(COMPONENT_LIBRARY): $(ALL_LIB_FILES)

COMPONENT_SRCDIRS := ./

include $(IDF_PATH)/make/component_common.mk
66 changes: 66 additions & 0 deletions components/bt/include/bt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef __BT_H__
#define __BT_H__

#include "freertos/FreeRTOS.h"
#include "esp_err.h"

#ifdef __cplusplus
extern "C" {
#endif


typedef void (* bt_app_startup_cb_t)(void *param);

esp_err_t esp_bt_startup(bt_app_startup_cb_t cb, void *ctx);

/* @breif: vhci_host_callback
* used for vhci call host function to notify what host need to do
*
* notify_host_send_available: notify host can send packet to controller
* notify_host_recv: notify host that controller has packet send to host
*/
typedef struct vhci_host_callback {

void (*notify_host_send_available)(void);
int (*notify_host_recv)(uint8_t *data, uint16_t len);
} vhci_host_callback_t;

/* @breif: API_vhci_host_check_send_available
* used for check actively if the host can send packet to controller or not.
* return true for ready to send, false means cannot send packet
*/
bool API_vhci_host_check_send_available(void);

/* @breif: API_vhci_host_send_packet
* host send packet to controller
* param data is the packet point, the param len is the packet length
* return void
*/
void API_vhci_host_send_packet(uint8_t *data, uint16_t len);

/* @breif: API_vhci_host_register_callback
* register the vhci referece callback, the call back
* struct defined by vhci_host_callback structure.
* param is the vhci_host_callback type variable
*/
void API_vhci_host_register_callback(const vhci_host_callback_t *callback);

#ifdef __cplusplus
}
#endif

#endif /* __BT_H__ */
1 change: 1 addition & 0 deletions components/bt/lib
Submodule lib added at 6c9a6d
56 changes: 54 additions & 2 deletions components/esp32/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,65 @@ config ESP32_DEFAULT_CPU_FREQ_MHZ
default 160 if ESP32_DEFAULT_CPU_FREQ_160
default 240 if ESP32_DEFAULT_CPU_FREQ_240

choice ESP32_WIFI_OR_BT
prompt "Select stack to enable (WiFi or BT)"
default ESP32_ENABLE_WIFI
help
Temporarily, WiFi and BT stacks can not be used at the same time.
Select which stack to enable.

config ESP32_ENABLE_STACK_WIFI
bool "WiFi"
select WIFI_ENABLED if ESP32_ENABLE_STACK_WIFI
config ESP32_ENABLE_STACK_BT
bool "BT"
select MEMMAP_BT if ESP32_ENABLE_STACK_BT
select BT_ENABLED if ESP32_ENABLE_STACK_BT
config ESP32_ENABLE_STACK_NONE
bool "None"
endchoice

config MEMMAP_BT
bool
depends on ESP32_ENABLE_STACK_BT
help
The Bluetooth stack uses memory that cannot be used as generic memory anymore. This
reserves the space for that within the memory map of the compiled binary.
This option is required to enable BT stack.
Temporarily, this option is not compatible with WiFi stack.

config MEMMAP_SMP
bool "Reserve memory for two cores"
default "y"
help
The ESP32 contains two cores. If you plan to only use one, you can disable this item
to save some memory. (ToDo: Make this automatically depend on unicore support)

config MEMMAP_TRACEMEM
bool "Use TRAX tracing feature"
default "n"
help
The ESP32 contains a feature which allows you to trace the execution path the processor
has taken through the program. This is stored in a chunk of 32K (16K for single-processor)
of memory that can't be used for general purposes anymore. Disable this if you do not know
what this is.

config MEMMAP_SPISRAM
bool "Use external SPI SRAM chip as main memory"
default "n"
help
The ESP32 can control an external SPI SRAM chip, adding the memory it contains to the
main memory map. Enable this if you have this hardware and want to use it in the same
way as on-chip RAM.

config WIFI_ENABLED
bool "Enable low-level WiFi stack"
bool
default "y"
depends on ESP32_ENABLE_STACK_WIFI
help
This compiles in the low-level WiFi stack.

Temporarily, this option requires that FreeRTOS runs in single core mode.
Temporarily, this option is not compatible with BT stack.

config WIFI_AUTO_STARTUP
bool "Start WiFi with system startup"
Expand Down
8 changes: 7 additions & 1 deletion components/esp32/cpu_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ static void IRAM_ATTR call_user_start_cpu1();
static void IRAM_ATTR user_start_cpu1(void);
extern void ets_setup_syscalls(void);
extern esp_err_t app_main(void *ctx);
#if CONFIG_BT_ENABLED
extern void bt_app_main(void *param);
#endif

extern int _bss_start;
extern int _bss_end;
Expand Down Expand Up @@ -161,7 +164,10 @@ void user_start_cpu0(void)

#if CONFIG_WIFI_ENABLED && CONFIG_WIFI_AUTO_STARTUP
#include "esp_wifi.h"
esp_wifi_startup(app_main, NULL);
esp_wifi_startup(app_main, NULL);
#elif CONFIG_BT_ENABLED
#include "bt.h"
esp_bt_startup(bt_app_main, NULL);
#else
app_main(NULL);
#endif
Expand Down

0 comments on commit 4480ab6

Please sign in to comment.