run_loop: pass in run_loop_X_get_instance() to run_loop_init(). Various other fixes

This commit is contained in:
Matthias Ringwald 2016-01-06 17:31:20 +01:00
parent 3e39f9f6b5
commit a484130c09
55 changed files with 309 additions and 153 deletions

View File

@ -19,7 +19,7 @@ embedded system with a Bluetooth chipset connected via UART.
btstack_memory_init();
// select embedded run loop
run_loop_init(RUN_LOOP_EMBEDDED);
run_loop_init(run_loop_embedded_get_instance());
// use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
hci_dump_open(NULL, HCI_DUMP_STDOUT);

View File

@ -98,7 +98,7 @@ embedded systems:
<!-- -->
run_loop_init(RUN_LOOP_EMBEDDED);
run_loop_init(run_loop_embedded_get_instance());
The Run loop API is provided [here](appendix/apis/#sec:runLoopAPIAppendix). To
enable the use of timers, make sure that you defined HAVE_TICK in the

View File

@ -47,6 +47,7 @@
#include <string.h>
#include "btstack_client.h"
#include "run_loop_posix.h"
#define MAX_DEVICES 10
struct device {
@ -235,7 +236,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
int main (int argc, const char * argv[]){
// start stack
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
int err = bt_open();
if (err) {
printf("Failed to open connection to BTdaemon\n");

View File

@ -47,6 +47,7 @@
#include <string.h>
#include "btstack_client.h"
#include "run_loop_posix.h"
#include "hci_cmds.h"
#include "classic/sdp_util.h"
@ -196,7 +197,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
}
int main (int argc, const char * argv[]){
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
int err = bt_open();
if (err) {
printf("Failed to open connection to BTdaemon\n");

View File

@ -47,6 +47,7 @@
#include <string.h>
#include "btstack_client.h"
#include "run_loop_posix.h"
#include "hci_cmds.h"
#define PSM_TEST 0xdead
@ -200,7 +201,7 @@ int main (int argc, const char * argv[]){
}
}
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
int err = bt_open();
if (err) {
printf("Failed to open connection to BTdaemon\n");

View File

@ -45,6 +45,7 @@
#include <string.h>
#include "btstack_client.h"
#include "run_loop_posix.h"
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
@ -79,7 +80,7 @@ int main (int argc, const char * argv[]){
printf("le_scan started\n");
printf("- connecting to BTstack Daemon\n");
// start stack
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
int err = bt_open();
if (err) {
printf("-> Failed to open connection to BTstack Daemon\n");

View File

@ -54,6 +54,7 @@
#include <sys/stat.h>
#include "btstack_client.h"
#include "run_loop_posix.h"
#include "classic/sdp_util.h"
// input from command line arguments
@ -162,7 +163,7 @@ int main (int argc, const char * argv[]){
arg++;
}
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
int err = bt_open();
if (err) {
fprintf(stderr,"Failed to open connection to BTdaemon, err %d\n",err);

View File

@ -50,6 +50,7 @@
#include <sys/stat.h>
#include "btstack_client.h"
#include "run_loop_posix.h"
#include "classic/sdp_util.h"
// input from command line arguments
@ -150,7 +151,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
int main (int argc, const char * argv[]){
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
int err = bt_open();
if (err) {
fprintf(stderr,"Failed to open connection to BTdaemon, err %d\n",err);

View File

@ -50,6 +50,7 @@
#include <sys/stat.h>
#include "btstack_client.h"
#include "run_loop_posix.h"
#include "classic/sdp_util.h"
#define NUM_ROWS 25
@ -176,7 +177,7 @@ int main (int argc, const char * argv[]){
create_test_data();
printf("created test data: \n%s\n", test_data);
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
int err = bt_open();
if (err) {
fprintf(stderr,"Failed to open connection to BTdaemon, err %d\n",err);

View File

@ -47,6 +47,8 @@
#include <string.h>
#include "btstack_client.h"
#include "run_loop.h"
#include "run_loop_posix.h"
#include "hci_cmds.h"
// bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard
@ -98,7 +100,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
}
int main (int argc, const char * argv[]){
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
int err = bt_open();
if (err) {
printf("Failed to open connection to BTdaemon\n");

View File

@ -10,7 +10,7 @@ CFLAGS += -I${BTSTACK_ROOT}/src
CORE += \
btstack_memory.c \
linked_list.c \
bk_linked_list.c \
memory_pool.c \
run_loop.c \

View File

@ -0,0 +1,63 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
/*
* run_loop_cocoa.h
* Functionality special to the CoreFoundation run loop
*/
#ifndef __RUN_LOOP_COCOA_H
#define __RUN_LOOP_COCOA_H
#include "run_loop.h"
#if defined __cplusplus
extern "C" {
#endif
/**
* Provide run_loop_cocoa instance
*/
const run_loop_t * run_loop_cocoa_get_instance(void){
/* API_END */
#if defined __cplusplus
}
#endif
#endif // __RUN_LOOP_COCOA_H

View File

@ -51,6 +51,7 @@
#include <stdlib.h>
static struct timeval init_tv;
static const run_loop_t run_loop_cocoa;
static void theCFRunLoopTimerCallBack (CFRunLoopTimerRef timer,void *info){
timer_source_t * ts = (timer_source_t*)info;
@ -173,7 +174,14 @@ void run_loop_cocoa_dump_timer(void){
return;
}
run_loop_t run_loop_cocoa = {
/**
* Provide run_loop_embedded instance
*/
const run_loop_t * run_loop_cocoa_get_instance(void){
return &run_loop_cocoa;
}
static const run_loop_t run_loop_cocoa = {
&run_loop_cocoa_init,
&run_loop_cocoa_add_data_source,
&run_loop_cocoa_remove_data_source,

View File

@ -58,6 +58,7 @@
#include "btstack.h"
#include "bk_linked_list.h"
#include "run_loop.h"
#include "run_loop_posix.h"
#include "hci_cmds.h"
#include "version.h"
@ -1985,7 +1986,7 @@ int main (int argc, char * const * argv){
remote_device_db = &REMOTE_DEVICE_DB;
#endif
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
// init power management notifications
if (control && control->register_for_power_notifications){

View File

@ -76,6 +76,8 @@
#define TIMER_SUPPORT
#endif
static const run_loop_t run_loop_embedded;
// the run loop
static bk_linked_list_t data_sources;
@ -243,7 +245,6 @@ void run_loop_embedded_trigger(void){
}
static void run_loop_embedded_init(void){
data_sources = NULL;
#ifdef TIMER_SUPPORT
@ -257,7 +258,14 @@ static void run_loop_embedded_init(void){
#endif
}
const run_loop_t run_loop_embedded = {
/**
* Provide run_loop_embedded instance
*/
const run_loop_t * run_loop_embedded_get_instance(void){
return &run_loop_embedded;
}
static const run_loop_t run_loop_embedded = {
&run_loop_embedded_init,
&run_loop_embedded_add_data_source,
&run_loop_embedded_remove_data_source,

View File

@ -55,6 +55,10 @@
extern "C" {
#endif
/**
* Provide run_loop_embedded instance
*/
const run_loop_t * run_loop_embedded_get_instance(void);
// hack to fix HCI timer handling
#ifdef HAVE_TICK

View File

@ -42,10 +42,10 @@
*/
#include "run_loop.h"
#include "run_loop_private.h"
#include "run_loop_posix.h"
#include "bk_linked_list.h"
#include "debug.h"
#include "run_loop_private.h"
#ifdef _WIN32
#include "Winsock2.h"
@ -263,7 +263,8 @@ static uint32_t run_loop_posix_get_time_ms(void){
+ (current_tv.tv_usec - init_tv.tv_usec) / 1000;
}
run_loop_t run_loop_posix = {
static const run_loop_t run_loop_posix = {
&run_loop_posix_init,
&run_loop_posix_add_data_source,
&run_loop_posix_remove_data_source,
@ -274,3 +275,11 @@ run_loop_t run_loop_posix = {
&run_loop_posix_dump_timer,
&run_loop_posix_get_time_ms,
};
/**
* Provide run_loop_posix instance
*/
const run_loop_t * run_loop_posix_get_instance(void){
return &run_loop_posix;
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
/*
* run_loop_posix.h
* Functionality special to the POSIX run loop
*/
#ifndef __RUN_LOOP_POSIX_H
#define __RUN_LOOP_POSIX_H
#include "run_loop.h"
#if defined __cplusplus
extern "C" {
#endif
/**
* Provide run_loop_posix instance
*/
const run_loop_t * run_loop_posix_get_instance(void);
/* API_END */
#if defined __cplusplus
}
#endif
#endif // __RUN_LOOP_POSIX_H

View File

@ -749,7 +749,7 @@ void BTstackManager::setup(void){
printf("BTstackManager::setup()\n");
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
run_loop_init(run_loop_embedded_get_instance());
hci_transport_t * transport = hci_transport_h4_dma_instance();
bt_control_t * control = bt_control_em9301_instance();

View File

@ -9,7 +9,7 @@ VERSION=`sed -n -e 's/^.*BTSTACK_VERSION \"\(.*\)\"/\1/p' ${BTSTACK_ROOT}/src/ve
BTSTACK_PACKAGE=/tmp/btstack
ARCHIVE=btstack-arduino-${VERSION}.zip
SRC_FILES = btstack_memory.c linked_list.c memory_pool.c run_loop.c
SRC_FILES = btstack_memory.c bk_linked_list.c memory_pool.c run_loop.c
SRC_FILES += hci_dump.c hci.c hci_cmds.c utils.c l2cap.c
BLE_FILES = ad_parser.c att.c att_server.c att_dispatch.c att_db_util.c le_device_db_memory.c gatt_client.c
BLE_FILES += sm.c ancs_client_lib.h ancs_client_lib.c

View File

@ -4,6 +4,7 @@ CC = @CC@
LDFLAGS = @LDFLAGS@ -lBTstack -L../src
CFLAGS = @CFLAGS@ \
-I$(BTSTACK_ROOT)/platform/daemon/src \
-I$(BTSTACK_ROOT)/platform/posix/src \
-I$(BTSTACK_ROOT)/src \
-I..
prefix = @prefix@

View File

@ -5,7 +5,8 @@ prefix = @prefix@
CC = @CC@
LDFLAGS = @LDFLAGS@
CFLAGS = @CFLAGS@ \
-I $(BTSTACK_ROOT)/platform/src/daemon \
-I $(BTSTACK_ROOT)/platform/daemon/src \
-I $(BTSTACK_ROOT)/platform/posix/src \
-I $(BTSTACK_ROOT)/src \
-I..
BTSTACK_LIB_LDFLAGS = @BTSTACK_LIB_LDFLAGS@
@ -29,7 +30,7 @@ libBTstack_SOURCES = \
socket_connection.c \
hci_cmds.c \
daemon_cmds.c \
linked_list.c \
bk_linked_list.c \
run_loop.c \
sdp_util.c \
utils.c \

View File

@ -34,20 +34,20 @@ CFLAGS += \
LDFLAGS = -mmcu=msp430f5438a
CORE = \
hal_tick.c \
hal_cpu.c \
bk_linked_list.c \
btstack_memory.c \
hal_board.c \
hal_compat.c \
hal_cpu.c \
hal_led.c \
hal_tick.c \
hal_usb.c \
hci_dump.c \
btstack_memory.c \
linked_list.c \
main.c \
memory_pool.c \
run_loop.c \
run_loop_embedded.c \
utils.c \
main.c \
COMMON = \
hal_uart_dma.c \

View File

@ -87,7 +87,7 @@ int main(void)
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
run_loop_init(run_loop_embedded_get_instance());
// init HCI
hci_transport_t * transport = hci_transport_h4_dma_instance();

View File

@ -46,6 +46,7 @@
#include "btstack_client.h"
#include "run_loop.h"
#include "run_loop_cocoa.h"
#include "hci_cmds.h"
void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
@ -70,7 +71,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
[window makeKeyAndVisible];
// start Bluetooth
run_loop_init(RUN_LOOP_COCOA);
run_loop_init(run_loop_cocoa_get_instance());
int res = bt_open();
if (res){

View File

@ -32,6 +32,8 @@
#import <BTstack/BTstackManager.h>
#import "btstack.h"
#import "run_loop.h"
#import "run_loop_cocoa.h"
#import <btstack/BTDevice.h>
#define INQUIRY_INTERVAL 3
@ -69,7 +71,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
[self setListeners:[[NSMutableSet alloc] init]];
// Use Cocoa run loop
run_loop_init(RUN_LOOP_COCOA);
run_loop_init(run_loop_cocoa_get_instance());
// our packet handler
bt_register_packet_handler(packet_handler);

View File

@ -30,6 +30,8 @@
*/
#import "BluetoothController.h"
#include "run_loop.h"
#include "run_loop_cocoa.h"
#pragma mark callback handler
static void btstackStoppedCallback(CFNotificationCenterRef center,
@ -83,7 +85,7 @@ static BluetoothController* sharedInstance = nil;
CFNotificationSuspensionBehaviorDrop); // suspension behavior
// set up libBTstack
run_loop_init(RUN_LOOP_COCOA);
run_loop_init(run_loop_cocoa_get_instance());
bt_register_packet_handler(bt_packet_handler);
return self;

View File

@ -17,10 +17,10 @@ VPATH += $(BTSTACK_ROOT)/src \
LIBRARY_NAME = libBTstack
libBTstack_FILES = \
bk_linked_list.c \
daemon_cmds.c \
hci_cmds.c \
hci_dump.c \
linked_list.c \
run_loop.c \
sdp_util.c \
utils.c \

View File

@ -50,6 +50,7 @@
#include "btstack-config.h"
#include "run_loop.h"
#include "run_loop_posix.h"
#include "hal_led.h"
#include "debug.h"
@ -84,7 +85,7 @@ int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
// use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);

View File

@ -34,20 +34,20 @@ CFLAGS += \
LDFLAGS = -mmcu=msp430f5438a
CORE = \
hal_tick.c \
hal_cpu.c \
bk_linked_list.c \
btstack_memory.c \
hal_board.c \
hal_led.c \
hal_compat.c \
hal_cpu.c \
hal_led.c \
hal_tick.c \
hal_usb.c \
hci_dump.c \
btstack_memory.c \
linked_list.c \
main.c \
memory_pool.c \
run_loop.c \
run_loop_embedded.c \
utils.c \
main.c \
COMMON = \
hal_uart_dma.c \

View File

@ -364,7 +364,7 @@ int main(void){
/// GET STARTED ///
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
run_loop_init(run_loop_embedded_get_instance());
// init HCI
hci_transport_t * transport = hci_transport_h4_dma_instance();

View File

@ -87,7 +87,7 @@ static void hw_setup(void){
static void btstack_setup(void){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
run_loop_init(run_loop_embedded_get_instance());
// init HCI
hci_transport_t * transport = hci_transport_h4_dma_instance();

View File

@ -94,7 +94,7 @@ static void btstack_setup(void){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
run_loop_init(run_loop_embedded_get_instance());
// init HCI
hci_transport_t * transport = hci_transport_h4_dma_instance();

View File

@ -35,7 +35,7 @@
</logicalFolder>
<logicalFolder name="src" displayName="src" projectFiles="true">
<itemPath>../../../src/hci_cmds.h</itemPath>
<itemPath>../../../src/linked_list.h</itemPath>
<itemPath>../../../src/bk_linked_list.h</itemPath>
<itemPath>../../../src/memory_pool.h</itemPath>
<itemPath>../../../src/run_loop.h</itemPath>
<itemPath>../../../src/utils.h</itemPath>
@ -127,7 +127,7 @@
<itemPath>../../../src/hci_transport_h4_dma.c</itemPath>
<itemPath>../../../src/l2cap.c</itemPath>
<itemPath>../../../src/l2cap_signaling.c</itemPath>
<itemPath>../../../src/linked_list.c</itemPath>
<itemPath>../../../src/bk_linked_list.c</itemPath>
<itemPath>../../../src/memory_pool.c</itemPath>
<itemPath>../../../src/classic/remote_device_db_memory.c</itemPath>
<itemPath>../../../src/classic/rfcomm.c</itemPath>

View File

@ -219,7 +219,7 @@ void BTSTACK_Initialize ( void )
printf("\n\nBTstack_Initialize()\n");
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
run_loop_init(run_loop_embedded_get_instance());
hci_dump_open(NULL, HCI_DUMP_STDOUT);

View File

@ -90,7 +90,7 @@ int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
// use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);

View File

@ -87,7 +87,7 @@ int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
// use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);

View File

@ -90,7 +90,7 @@ int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
// use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);

View File

@ -90,7 +90,7 @@ int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
// use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);

View File

@ -18,7 +18,7 @@ VPATH += $(BTSTACK_ROOT)/chipset/cc256x
CORE = \
main.c \
btstack_memory.c \
linked_list.c \
bk_linked_list.c \
memory_pool.c \
run_loop.c \
run_loop_embedded.c

View File

@ -49,6 +49,7 @@
#include <unistd.h>
#include "run_loop.h"
#include "run_loop_embedded.h"
#include "hci.h"
#include "bt_control_cc256x.h"
#include "btstack_memory.h"
@ -419,7 +420,7 @@ int main(void)
// start with BTstack init - especially configure HCI Transport
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
run_loop_init(run_loop_embedded_get_instance());
// init HCI
hci_transport_t * transport = hci_transport_h4_dma_instance();

View File

@ -35,12 +35,16 @@
*
*/
#include "wiced.h"
#include "platform_bluetooth.h"
#include "bt_control_bcm.h"
#include "btstack.h"
#include "run_loop_wiced.h"
#include "generated_mac_address.txt"
#include "platform_bluetooth.h"
#include "wiced.h"
// see generated_mac_address.txt - "macaddr=02:0A:F7:3d:76:be"
static const char * wifi_mac_address = NVRAM_GENERATED_MAC_ADDRESS;
@ -81,7 +85,7 @@ void application_start(void){
// start with BTstack init - especially configure HCI Transport
btstack_memory_init();
run_loop_init(RUN_LOOP_WICED);
run_loop_init(run_loop_wiced_get_instance());
// enable full log output while porting
// hci_dump_open(NULL, HCI_DUMP_STDOUT);

View File

@ -57,6 +57,8 @@ typedef struct function_call {
void * arg;
} function_call_t;
static const run_loop_t run_loop_wiced;
static wiced_queue_t run_loop_queue;
// the run loop
@ -171,7 +173,14 @@ static void run_loop_wiced_run_loop_init(void){
wiced_rtos_init_queue(&run_loop_queue, "BTstack Run Loop", sizeof(function_call_t), 5);
}
const run_loop_t run_loop_wiced = {
/**
* @brief Provide run_loop_posix instance for use with run_loop_init
*/
const run_loop_t * run_loop_wiced_get_instance(void){
return &run_loop_wiced;
}
static const run_loop_t run_loop_wiced = {
&run_loop_wiced_run_loop_init,
&run_loop_wiced_add_data_source,
&run_loop_wiced_remove_data_source,

View File

@ -48,6 +48,11 @@
#include "run_loop.h"
#include "wiced.h"
/**
* @brief Provide run_loop_posix instance for use with run_loop_init
*/
const run_loop_t * run_loop_wiced_get_instance(void);
/*
* @brief Execute code on BTstack run loop. Can be used to control BTstack from a different thread
*/

View File

@ -47,6 +47,10 @@
#include "hci.h"
#include "gap.h"
#ifdef HAVE_TICK
#include "run_loop_embedded.h"
#endif
#ifdef HAVE_BLE
#include "gap.h"
#endif
@ -203,7 +207,7 @@ static void hci_connection_timeout_handler(timer_source_t *timer){
}
#endif
#ifdef HAVE_TICK
if (run_loop_embedded_ticks_for_ms() > connection->timestamp + run_loop_embedded_ticks_for_ms(HCI_CONNECTION_TIMEOUT_MS)){
if (run_loop_embedded_get_ticks() > connection->timestamp + run_loop_embedded_ticks_for_ms(HCI_CONNECTION_TIMEOUT_MS)){
// connections might be timed out
hci_emit_l2cap_check_timeout(connection);
}

View File

@ -51,30 +51,20 @@
#include "debug.h"
#include "btstack-config.h"
static run_loop_t * the_run_loop = NULL;
static const run_loop_t * the_run_loop = NULL;
extern const run_loop_t run_loop_embedded;
#ifdef USE_POSIX_RUN_LOOP
extern run_loop_t run_loop_posix;
#endif
#ifdef USE_COCOA_RUN_LOOP
extern run_loop_t run_loop_cocoa;
#endif
#ifdef HAVE_WICED
extern run_loop_t run_loop_wiced;
#endif
// assert run loop initialized
static void run_loop_assert(void){
#ifndef EMBEDDED
if (!the_run_loop){
log_error("ERROR: run_loop function called before run_loop_init!");
#ifdef EMBEDDED
exit(10);
}
#else
while(1);
#endif
}
}
@ -147,43 +137,16 @@ void run_loop_execute(void){
}
// init must be called before any other run_loop call
void run_loop_init(RUN_LOOP_TYPE type){
#ifndef EMBEDDED
void run_loop_init(const run_loop_t * run_loop){
if (the_run_loop){
log_error("ERROR: run loop initialized twice!");
exit(10);
}
#endif
switch (type) {
#ifdef EMBEDDED
#ifdef HAVE_WICED
case RUN_LOOP_WICED:
the_run_loop = &run_loop_wiced;
break;
while(1);
#else
case RUN_LOOP_EMBEDDED:
the_run_loop = &run_loop_embedded;
break;
exit(10);
#endif
#endif
#ifdef USE_POSIX_RUN_LOOP
case RUN_LOOP_POSIX:
the_run_loop = &run_loop_posix;
break;
#endif
#ifdef USE_COCOA_RUN_LOOP
case RUN_LOOP_COCOA:
the_run_loop = &run_loop_cocoa;
break;
#endif
default:
#ifndef EMBEDDED
log_error("ERROR: invalid run loop type %u selected!", type);
exit(10);
#endif
break;
}
the_run_loop = run_loop;
the_run_loop->init();
}

View File

@ -58,13 +58,6 @@
extern "C" {
#endif
typedef enum {
RUN_LOOP_POSIX = 1,
RUN_LOOP_COCOA,
RUN_LOOP_EMBEDDED,
RUN_LOOP_WICED,
} RUN_LOOP_TYPE;
typedef struct data_source {
linked_item_t item;
int fd; // <-- file descriptor to watch or 0
@ -84,6 +77,15 @@ typedef struct timer {
/* API_START */
typedef struct run_loop run_loop_t;
/**
* @brief Init main run loop. Must be called before any other run loop call.
*
* Use run_loop_$(RUN_LOOP_TYPE)_get_instance() from run_loop_$(RUN_LOOP_TYPE).h to get instance
*/
void run_loop_init(const run_loop_t * run_loop);
/**
* @brief Set timer based on current time in milliseconds.
*/
@ -106,11 +108,6 @@ int run_loop_remove_timer(timer_source_t *timer);
*/
uint32_t run_loop_get_time_ms(void);
/**
* @brief Init must be called before any other run_loop call. Use RUN_LOOP_EMBEDDED for embedded devices.
*/
void run_loop_init(RUN_LOOP_TYPE type);
/**
* @brief Set data source callback.
*/

View File

@ -58,7 +58,7 @@ extern "C" {
void run_loop_timer_dump(void);
// internal use only
typedef struct {
struct run_loop {
void (*init)(void);
void (*add_data_source)(data_source_t *dataSource);
int (*remove_data_source)(data_source_t *dataSource);
@ -68,7 +68,7 @@ typedef struct {
void (*execute)(void);
void (*dump_timer)(void);
uint32_t (*get_time_ms)(void);
} run_loop_t;
};
#if defined __cplusplus
}

View File

@ -12,16 +12,16 @@ VPATH += ${BTSTACK_ROOT}/src
VPATH += ${BTSTACK_ROOT}/platform/posix/src
COMMON = \
utils.c \
ad_parser.c \
bk_linked_list.c \
btstack_memory.c \
memory_pool.c \
linked_list.c \
run_loop.c \
run_loop_posix.c \
hci.c \
hci_cmds.c \
hci_dump.c \
hci.c \
ad_parser.c \
memory_pool.c \
run_loop.c \
run_loop_posix.c \
utils.c \
COMMON_OBJ = $(COMMON:.c=.o)

View File

@ -12,18 +12,18 @@ VPATH += ${BTSTACK_ROOT}/src/ble
VPATH += ${BTSTACK_ROOT}/platform/posix/src
COMMON = \
utils.c \
ad_parser.c \
att.c \
att_dispatch.c \
bk_linked_list.c \
btstack_memory.c \
memory_pool.c \
linked_list.c \
gatt_client.c \
hci_cmds.c \
hci_dump.c \
att_dispatch.c \
att.c \
ad_parser.c \
gatt_client.c \
le_device_db_memory.c \
memory_pool.c \
mock.c
utils.c \
COMMON_OBJ = $(COMMON:.c=.o)

View File

@ -8,38 +8,38 @@ CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest
include ${BTSTACK_ROOT}/example/embedded/Makefile.inc
COMMON = \
sdp.c \
sdp_query_rfcomm.c \
bk_linked_list.c \
btstack_memory.c \
linked_list.c \
memory_pool.c \
run_loop.c \
run_loop_posix.c \
hci.c \
hci_cmds.c \
hci_dump.c \
l2cap.c \
l2cap_signaling.c \
rfcomm.c \
memory_pool.c \
remote_device_db_memory.c \
sdp_util.c \
utils.c \
rfcomm.c \
run_loop.c \
run_loop_posix.c \
sdp_client.c \
sdp_parser.c \
sdp_query_util.c \
sdp_query_rfcomm.c \
sdp.c \
sdp_util.c \
utils.c \
MOCK = \
btstack_memory.c \
linked_list.c \
memory_pool.c \
remote_device_db_memory.c \
hci_cmds.c \
hci_dump.c \
sdp_util.c \
utils.c \
mock.c \
test_sequences.c \
bk_linked_list.c \
btstack_memory.c \
hci_cmds.c \
hci_dump.c \
memory_pool.c \
remote_device_db_memory.c \
sdp_util.c \
utils.c \
COMMON_OBJ = $(COMMON:.c=.o)
MOCK_OBJ = $(MOCK:.c=.o)

View File

@ -13,7 +13,7 @@ VPATH += ${BTSTACK_ROOT}/src
VPATH += ${BTSTACK_ROOT}/platform/posix/src
COMMON = \
linked_list.c \
bk_linked_list.c \
COMMON_OBJ = $(COMMON:.c=.o)

View File

@ -28,7 +28,7 @@ MEMORY = \
btstack_memory.c \
hci_dump.c \
remote_device_db_memory.c \
linked_list.c
bk_linked_list.c
FS_OBJ = $(FS:.c=.o)
MEMORY_OBJ = $(MEMORY:.c=.o)

View File

@ -15,15 +15,15 @@ COMMON = \
utils.c \
btstack_memory.c \
memory_pool.c \
linked_list.c \
bk_linked_list.c \
run_loop.c \
run_loop_posix.c \
hci_cmds.c \
hci_dump.c \
sm.c \
le_device_db_memory.c \
rijndael.c \
mock.c
rijndael.c \
mock.c \
COMMON_OBJ = $(COMMON:.c=.o)

View File

@ -175,7 +175,7 @@ void CHECK_EQUAL_ARRAY(uint8_t * expected, uint8_t * actual, int size){
TEST_GROUP(SecurityManager){
void setup(void){
btstack_memory_init();
run_loop_init(RUN_LOOP_POSIX);
run_loop_init(run_loop_posix_get_instance());
sm_init();
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
sm_set_authentication_requirements( SM_AUTHREQ_BONDING );