void setup(void){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/gatt_browser.pklg", HCI_DUMP_PACKETLOGGER); // init HCI remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; bt_control_t * control = NULL; #ifndef HAVE_UART_CC2564 hci_transport_t * transport = hci_transport_usb_instance(); #else hci_transport_t * transport = hci_transport_h4_instance(); control = bt_control_cc256x_instance(); // config.device_name = "/dev/tty.usbserial-A600eIDu"; // 5438 config.device_name = "/dev/tty.usbserial-A800cGd0"; // 5529 config.baudrate_init = 115200; config.baudrate_main = 0; config.flowcontrol = 1; #endif hci_init(transport, &config, control, remote_db); l2cap_init(); l2cap_register_packet_handler(&handle_hci_event); gatt_client_init(); gatt_client_register_packet_handler(&handle_gatt_client_event); sm_init(); sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT); }
void bt_init ( void ) { sys_init(); mem_init(); memp_init(); pbuf_init(); UART2PrintString("mem mgmt initialized\r\n"); lwbt_memp_init(); phybusif_init(""); cb = malloc(sizeof(struct phybusif_cb)); phybusif_reset(cb); if(hci_init() != ERR_OK) { UART2PrintString("HCI initialization failed!\r\n"); return; } l2cap_init(); sdp_init(); rfcomm_init(); UART2PrintString("Bluetooth initialized.\r\n"); bt_spp_start(); UART2PrintString("Applications started.\r\n"); }
void setup(void){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // init HCI hci_transport_t * transport = hci_transport_usb_instance(); hci_uart_config_t * config = NULL; bt_control_t * control = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); hci_discoverable_control(1); l2cap_init(); l2cap_register_packet_handler(packet_handler); rfcomm_init(); rfcomm_register_packet_handler(packet_handler); rfcomm_register_service_internal(NULL, RFCOMM_SERVER_CHANNEL, 100); // reserved channel, mtu=100 // init SDP, create record for SPP and register with SDP sdp_init(); memset(spp_service_buffer, 0, sizeof(spp_service_buffer)); // service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer; // sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, RFCOMM_SERVER_CHANNEL, "SPP Counter"); // printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); // sdp_register_service_internal(NULL, service_record_item); sdp_create_spp_service( spp_service_buffer, RFCOMM_SERVER_CHANNEL, "SPP Counter"); printf("SDP service record size: %u\n\r", de_get_len(spp_service_buffer)); sdp_register_service_internal(NULL, spp_service_buffer); }
static int bt_init(void) { #if NOT_USED_FOR_NOW struct bt_driver *drv = bt_dev.drv; #endif int err = 0; #if NOT_USED_FOR_NOW err = drv->open(); if (err) { BT_ERR("HCI driver open failed (%d)", err); return err; } err = hci_init(); #endif if (!err) { err = bt_conn_init(); } scan_dev_found_cb = NULL; if (!err) { atomic_set_bit(bt_dev.flags, BT_DEV_READY); #if 0 bt_le_scan_update(false); #endif } return err; }
// main int main(void) { /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // init HCI hci_transport_t * transport = hci_transport_usb_instance(); bt_control_t * control = NULL; hci_uart_config_t * config = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // set up l2cap_le l2cap_init(); l2cap_register_fixed_channel(att_packet_handler, L2CAP_CID_ATTRIBUTE_PROTOCOL); l2cap_register_packet_handler(packet_handler); // set up ATT att_set_db(profile_data); att_set_write_callback(att_write_callback); att_dump_attributes(); att_connection.mtu = 27; printf("Run...\n\r"); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
void bluetooth_task(intptr_t unused) { #if defined(DEBUG) syslog(LOG_DEBUG, "[bluetooth] Start main task."); #endif run_loop_init(RUN_LOOP_EMBEDDED); // Initialize HCI bt_control_t *control = bt_control_cc256x_instance(); hci_transport_t *transport = hci_transport_h4_dma_instance(); hci_uart_config_t *config = hci_uart_config_cc256x_instance(); const remote_device_db_t *db = &remote_device_db_memory; hci_init(transport, config, control, db); // Initialize SPP (Serial Port Profile) bluetooth_spp_initialize(); // Power on bt_control_cc256x_enable_ehcill(false); hci_power_control(HCI_POWER_ON); run_loop_execute(); #if 0 // Code for debugging while(1) { // bluetooth_uart_isr(); embedded_execute_once(); // if(rx_size > 0 && (UART2.IIR_FCR & 0x4)) // TODO: dirty hack // AINTC.SISR = UART2_INT; tslp_tsk(1); // TODO: Use interrupt instead of sleeping. -- ertl-liyixiao } #endif }
int main(void) { clock_setup(); gpio_setup(); hal_tick_init(); debug_usart_setup(); bluetooth_setup(); // start with BTstack init - especially configure HCI Transport btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, (void*) &hci_uart_config_cc256x, control, remote_db); // enable eHCILL bt_control_cc256x_enable_ehcill(1); // hand over to btstack embedded code btstack_main(); // go run_loop_execute(); return 0; }
int main(int argc, const char * argv[]){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // pick serial port hci_uart_config_cc256x.device_name = "/dev/tty.usbserial-AD025KU2"; // init HCI hci_transport_t * transport = hci_transport_h4_instance(); bt_control_t * control = bt_control_stlc2500d_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; hci_init(transport, (void*) &hci_uart_config_cc256x, control, remote_db); // handle CTRL-c signal(SIGINT, sigint_handler); // setup app btstack_main(argc, argv); // go run_loop_execute(); return 0; }
int main(int argc, const char * argv[]){ /// GET STARTED with BTstack /// btstack_memory_init(); btstack_run_loop_init(btstack_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); // init HCI hci_init(hci_transport_usb_instance(), NULL); hci_set_link_key_db(btstack_link_key_db_fs_instance()); // inform about BTstack state hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // handle CTRL-c signal(SIGINT, sigint_handler); // setup app btstack_main(argc, argv); // go btstack_run_loop_execute(); return 0; }
static void BTAttached() { btstack_memory_init(); // init HCI hci_transport_t * transport = hci_transport_mchpusb_instance(bt_buf, bt_buf_size); bt_control_t * control = NULL; hci_uart_config_t * config = NULL; const remote_device_db_t * remote_db = &remote_device_db_memory; hci_init(transport, config, control, remote_db); // init L2CAP l2cap_init(); l2cap_register_packet_handler(PacketHandler); // init RFCOMM rfcomm_init(); rfcomm_register_packet_handler(PacketHandler); rfcomm_register_service_internal(NULL, rfcomm_channel_nr, 100); // reserved channel, mtu=100 // init SDP, create record for SPP and register with SDP sdp_init(); memset(spp_service_buffer, 0, sizeof (spp_service_buffer)); service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer; sdp_create_spp_service((uint8_t*) & service_record_item->service_record, 1, "IOIO-App"); log_printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof (service_record_item_t) + de_get_len((uint8_t*) & service_record_item->service_record))); sdp_register_service_internal(NULL, service_record_item); hci_power_control(HCI_POWER_ON); client_callback = DummyCallback; }
int main(int argc, const char * argv[]){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // init HCI hci_transport_t * transport = hci_transport_usb_instance(); hci_uart_config_t * config = NULL; bt_control_t * control = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; hci_init(transport, config, control, remote_db); // handle CTRL-c signal(SIGINT, sigint_handler); // setup app btstack_main(argc, argv); // go run_loop_execute(); return 0; }
void setup(void){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // init HCI hci_transport_t * transport = hci_transport_usb_instance(); hci_uart_config_t * config = NULL; bt_control_t * control = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // set up l2cap_le l2cap_init(); l2cap_register_fixed_channel(att_packet_handler, L2CAP_CID_ATTRIBUTE_PROTOCOL); l2cap_register_fixed_channel(sm_packet_handler, L2CAP_CID_SECURITY_MANAGER_PROTOCOL); l2cap_register_packet_handler(packet_handler); // set up ATT att_set_db(profile_data); att_set_write_callback(att_write_callback); att_dump_attributes(); att_connection.mtu = 27; }
// main int app_main(void){ printf("BTstack: setup\n"); // enable packet logger hci_dump_open(NULL, HCI_DUMP_STDOUT); /// GET STARTED with BTstack /// btstack_memory_init(); btstack_run_loop_init(btstack_run_loop_freertos_get_instance()); // init HCI hci_init(transport_get_instance(), NULL); // setup TLV ESP32 implementation const btstack_tlv_t * btstack_tlv_impl = btstack_tlv_esp32_get_instance(); // setup Link Key DB using TLV const btstack_link_key_db_t * btstack_link_key_db = btstack_link_key_db_tlv_get_instance(btstack_tlv_impl, NULL); hci_set_link_key_db(btstack_link_key_db); // setup LE Device DB using TLV le_device_db_tlv_configure(btstack_tlv_impl, NULL); // inform about BTstack state hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); btstack_main(0, NULL); printf("BTstack: execute run loop\n"); btstack_run_loop_execute(); return 0; }
static void btstack_setup(void){ /// GET STARTED with BTstack /// btstack_memory_init(); btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), &config); hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_cc256x_instance()); // inform about BTstack state hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); }
int main(void){ // stop watchdog timer WDTCTL = WDTPW + WDTHOLD; //Initialize clock and peripherals halBoardInit(); halBoardStartXT1(); halBoardSetSystemClock(SYSCLK_16MHZ); // Debug UART halUsbInit(); // show off doLCD(); // init LEDs LED_PORT_OUT |= LED_1 | LED_2; LED_PORT_DIR |= LED_1 | LED_2; /// GET STARTED /// btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); // init L2CAP l2cap_init(); l2cap_register_packet_handler(packet_handler); // ready - enable irq used in h4 task __enable_interrupt(); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); return 0; }
void BTSTACK_Initialize ( void ) { printf("\n\nBTstack_Initialize()\n"); btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); hci_dump_open(NULL, HCI_DUMP_STDOUT); hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_csr_instance(); hci_init(transport, (void*) &hci_uart_config_csr, control, NULL); // hci_power_control(HCI_POWER_ON); btstack_main(0, NULL); }
int main(int argc, const char * argv[]){ /// GET STARTED with BTstack /// btstack_memory_init(); btstack_run_loop_init(btstack_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); // pick serial port // config.device_name = "/dev/tty.usbserial-A900K2WS"; // DFROBOT // config.device_name = "/dev/tty.usbserial-A50285BI"; // BOOST-CC2564MODA New // config.device_name = "/dev/tty.usbserial-A9OVNX5P"; // RedBear IoT pHAT breakout board config.device_name = "/dev/tty.usbserial-A900K0VK"; // CSR8811 breakout board // init HCI const btstack_uart_block_t * uart_driver = btstack_uart_block_posix_instance(); const hci_transport_t * transport = hci_transport_h5_instance(uart_driver); const btstack_link_key_db_t * link_key_db = btstack_link_key_db_fs_instance(); hci_init(transport, (void*) &config); hci_set_link_key_db(link_key_db); // enable BCSP mode for CSR chipsets - auto detect might not work // hci_transport_h5_enable_bcsp_mode(); // set BD_ADDR for CSR without Flash/unique address // bd_addr_t own_address = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; // btstack_chipset_csr_set_bd_addr(own_address); // enable auto-sleep mode // hci_transport_h5_set_auto_sleep(300); // register for HCI events hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // handle CTRL-c signal(SIGINT, sigint_handler); // setup app btstack_main(argc, argv); // go btstack_run_loop_execute(); return 0; }
void setup(void){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // init HCI hci_transport_t * transport = hci_transport_usb_instance(); hci_uart_config_t * config = NULL; bt_control_t * control = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); hci_register_packet_handler(packet_handler); }
void setup(void){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // init HCI #ifdef HAVE_UART_CSR hci_transport_t * transport = hci_transport_h4_instance(); hci_uart_config_t * config = &hci_uart_config; bt_control_t * control = bt_control_csr_instance(); #elif defined(HAVE_UART_CC256x) hci_transport_t * transport = hci_transport_h4_instance(); hci_uart_config_t * config = &hci_uart_config; bt_control_t * control = bt_control_cc256x_instance(); #else hci_transport_t * transport = hci_transport_usb_instance(); hci_uart_config_t * config = NULL; bt_control_t * control = NULL; #endif remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // set up l2cap_le l2cap_init(); // setup central device db central_device_db_init(); // setup SM: Display only sm_init(); sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY); sm_set_authentication_requirements( SM_AUTHREQ_BONDING | SM_AUTHREQ_MITM_PROTECTION); // setup ATT server att_server_init(profile_data, att_read_callback, att_write_callback); att_write_queue_init(); att_attributes_init(); att_server_register_packet_handler(app_packet_handler); att_dump_attributes(); }
void BTSTACK_Initialize ( void ) { printf("\n\nBTstack_Initialize()\n"); btstack_memory_init(); btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); hci_dump_open(NULL, HCI_DUMP_STDOUT); const hci_transport_t * transport = hci_transport_h4_instance(); hci_init(transport, &config); hci_set_chipset(btstack_chipset_csr_instance()); // inform about BTstack state hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); btstack_main(0, NULL); }
static void btstack_setup(){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); // init L2CAP l2cap_init(); l2cap_register_packet_handler(packet_handler); }
static void btstack_setup(){ /// GET STARTED /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); hci_dump_open("/tmp/hci_dump_sdp_rfcomm_query.pklg", HCI_DUMP_PACKETLOGGER); hci_transport_t * transport = hci_transport_usb_instance(); hci_uart_config_t * config = NULL; bt_control_t * control = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); printf("Client HCI init done\r\n"); // init L2CAP l2cap_init(); l2cap_register_packet_handler(packet_handler); // turn on! hci_power_control(HCI_POWER_ON); }
int main(int argc, const char * argv[]){ /// GET STARTED with BTstack /// btstack_memory_init(); btstack_run_loop_init(btstack_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); // pick serial port config.device_name = "/dev/tty.usbserial-A900K0VK"; // init HCI const btstack_uart_block_t * uart_driver = btstack_uart_block_posix_instance(); const hci_transport_t * transport = hci_transport_h4_instance(uart_driver); const btstack_link_key_db_t * link_key_db = btstack_link_key_db_fs_instance(); hci_init(transport, (void*) &config); hci_set_link_key_db(link_key_db); // inform about BTstack state hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); // setup dynamic chipset driver setup hci_set_local_version_information_callback(&local_version_information_callback); // handle CTRL-c signal(SIGINT, sigint_handler); // setup app btstack_main(argc, argv); // go btstack_run_loop_execute(); return 0; }
static void btstack_setup(){ printf("Starting up..\n"); /// GET STARTED /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); hci_transport_t * transport = hci_transport_usb_instance(); hci_uart_config_t * config = NULL; bt_control_t * control = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); hci_set_class_of_device(0x200404); hci_discoverable_control(1); l2cap_init(); l2cap_register_packet_handler(&packet_handler2); l2cap_register_service_internal(NULL, packet_handler, PSM_SDP, 100, LEVEL_0); // turn on! hci_power_control(HCI_POWER_ON); }
void btstack_libusb_device_base::init() { /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); hci_dump_open( nullptr, HCI_DUMP_STDOUT ); // init HCI hci_init( hci_transport_usb_instance(), nullptr, nullptr, nullptr ); // handle CTRL-c signal(SIGINT, sigint_handler); // setup app hci_register_packet_handler( &btstack_libusb_device_base::btstack_packet_handler ); hci_connectable_control(0); // no services yet // turn on! hci_power_control(HCI_POWER_ON); // go run_loop_execute(); }
int main (int argc, char * const * argv){ static int tcp_flag = 0; while (1) { static struct option long_options[] = { { "tcp", no_argument, &tcp_flag, 1 }, { "help", no_argument, 0, 0 }, { 0,0,0,0 } // This is a filler for -1 }; int c; int option_index = -1; c = getopt_long(argc, argv, "h", long_options, &option_index); if (c == -1) break; // no more option // treat long parameter first if (option_index == -1) { switch (c) { case '?': case 'h': usage(argv[0]); return 0; break; } } else { switch (option_index) { case 1: usage(argv[0]); return 0; break; } } } // make stdout unbuffered setbuf(stdout, NULL); log_error("BTdaemon started\n"); // handle CTRL-c signal(SIGINT, daemon_sigint_handler); // handle SIGTERM - suggested for launchd signal(SIGTERM, daemon_sigint_handler); // handle SIGPIPE struct sigaction act; act.sa_handler = SIG_IGN; sigemptyset (&act.sa_mask); act.sa_flags = 0; sigaction (SIGPIPE, &act, NULL); bt_control_t * control = NULL; #ifdef HAVE_TRANSPORT_H4 config.device_name = UART_DEVICE; config.baudrate_init = UART_SPEED; config.baudrate_main = 0; config.flowcontrol = 1; #if defined(USE_BLUETOOL) && defined(USE_POWERMANAGEMENT) if (bt_control_iphone_power_management_supported()){ // use default (max) UART baudrate over netraph interface config.baudrate_init = 0; transport = hci_transport_h4_iphone_instance(); } else { transport = hci_transport_h4_instance(); } #else transport = hci_transport_h4_instance(); #endif #endif #ifdef HAVE_TRANSPORT_USB transport = hci_transport_usb_instance(); #endif #ifdef USE_BLUETOOL control = &bt_control_iphone; #endif #if defined(USE_BLUETOOL) && defined(USE_POWERMANAGEMENT) if (bt_control_iphone_power_management_supported()){ hci_transport_h4_iphone_set_enforce_wake_device("/dev/btwake"); } #endif #ifdef USE_SPRINGBOARD bluetooth_status_handler = platform_iphone_status_handler; platform_iphone_register_window_manager_restart(update_ui_status); platform_iphone_register_preferences_changed(preferences_changed_callback); #endif #ifdef REMOTE_DEVICE_DB remote_device_db = &REMOTE_DEVICE_DB; #endif run_loop_init(RUN_LOOP_POSIX); // init power management notifications if (control && control->register_for_power_notifications){ control->register_for_power_notifications(power_notification_callback); } // logging loggingEnabled = 0; int newLoggingEnabled = 1; #ifdef USE_BLUETOOL // iPhone has toggle in Preferences.app newLoggingEnabled = platform_iphone_logging_enabled(); #endif daemon_set_logging_enabled(newLoggingEnabled); // init HCI hci_init(transport, &config, control, remote_device_db); #ifdef USE_BLUETOOL // iPhone doesn't use SSP yet as there's no UI for it yet and auto accept is not an option hci_ssp_set_enable(0); #endif // init L2CAP l2cap_init(); l2cap_register_packet_handler(daemon_packet_handler); timeout.process = daemon_no_connections_timeout; #ifdef HAVE_RFCOMM log_info("config.h: HAVE_RFCOMM\n"); rfcomm_init(); rfcomm_register_packet_handler(daemon_packet_handler); #endif #ifdef HAVE_SDP sdp_init(); sdp_register_packet_handler(daemon_packet_handler); #endif #ifdef USE_LAUNCHD socket_connection_create_launchd(); #else // create server if (tcp_flag) { socket_connection_create_tcp(BTSTACK_PORT); } else { socket_connection_create_unix(BTSTACK_UNIX); } #endif socket_connection_register_packet_callback(daemon_client_handler); #ifdef USE_BLUETOOL // notify daemons notify_post("ch.ringwald.btstack.started"); // spawn thread to have BTstack run loop on new thread, while main thread is used to keep CFRunLoop pthread_t run_loop; pthread_create(&run_loop, NULL, &run_loop_thread, NULL); // needed to receive notifications CFRunLoopRun(); #endif // go! run_loop_execute(); return 0; }
/*-----------------------------------------------------------------------------------*/ int main(int argc, char **argv) { struct phybusif_cb *cb; struct timeval tcptv, bttv, now; struct timezone tz; u8_t btiptmr = 0; #ifdef PERF perf_init("/tmp/minimal.perf"); #endif /* PERF */ #ifdef STATS stats_init(); #endif /* STATS */ mem_init(); memp_init(); pbuf_init(); netif_init(); ip_init(); //udp_init(); tcp_init(); printf("TCP/IP initialized.\n"); lwbt_memp_init(); phybusif_init(); if(hci_init() != ERR_OK) { printf("HCI initialization failed!"); exit(-1); } l2cap_init(); sdp_init(); rfcomm_init(); ppp_init(); printf("Bluetooth initialized.\n"); //echo_init(); httpd_init(); printf("Applications started.\n"); cb = malloc(sizeof(struct phybusif_cb)); phybusif_reset(cb); gettimeofday(&bttv, &tz); /* Initialize Bluetooth timer (1s) */ gettimeofday(&tcptv, &tz); /* Initialize TCP timer (TCP_TMR_INTERVAL) */ /* Host controller initialization for DTs according to LAN access point (LAP) and dial up networking (DUN) profile */ bt_ip_start(NULL); while(1) { phybusif_input(cb); /* Check for input */ gettimeofday(&now, &tz); /* Get current time */ /* Check if TCP timer should be called */ if((now.tv_sec - tcptv.tv_sec) * 1000000 + (now.tv_usec - tcptv.tv_usec) >= TCP_TMR_INTERVAL * 1000) { gettimeofday(&tcptv, &tz); /* Reset TCP timer */ tcp_tmr(); } /* Check if Bluetooth and NAT timers should be called */ if((now.tv_sec - bttv.tv_sec) * 1000000 + (now.tv_usec - bttv.tv_usec) >= 1000000) { gettimeofday(&bttv, &tz); /* Restart Bluetooth timer */ l2cap_tmr(); rfcomm_tmr(); ppp_tmr(); nat_tmr(); if(++btiptmr == 240) { /* Akes server special */ bt_ip_tmr(); btiptmr = 0; } } } return 0; }
// main int main(void) { // stop watchdog timer WDTCTL = WDTPW + WDTHOLD; //Initialize clock and peripherals halBoardInit(); halBoardStartXT1(); halBoardSetSystemClock(SYSCLK_16MHZ); // init debug UART halUsbInit(); // init LEDs LED_PORT_OUT |= LED_1 | LED_2; LED_PORT_DIR |= LED_1 | LED_2; /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); // init L2CAP l2cap_init(); l2cap_register_packet_handler(packet_handler); // init RFCOMM rfcomm_init(); rfcomm_register_packet_handler(packet_handler); rfcomm_register_service_with_initial_credits_internal(NULL, rfcomm_channel_nr, 100, 1); // reserved channel, mtu=100, 1 credit // init SDP, create record for SPP and register with SDP sdp_init(); memset(spp_service_buffer, 0, sizeof(spp_service_buffer)); service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer; sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, 1, "SPP Counter"); printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); sdp_register_service_internal(NULL, service_record_item); // set one-shot timer timer_source_t heartbeat; heartbeat.process = &heartbeat_handler; run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); run_loop_add_timer(&heartbeat); puts("SPP FlowControl Demo: simulates processing on received data...\n\r"); // ready - enable irq used in h4 task __enable_interrupt(); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
// main int main ( void ) { // Initialize the processor and peripherals. // Init Clock // CPU 32MHz // Peripheral 8MHz CLKDIV = 0x0000; unsigned int pll_startup_counter = 600; CLKDIVbits.PLLEN = 1; while(pll_startup_counter--); // Configure U2RX - put on pin 17 (RP8) RPINR19bits.U2RXR = 8; // Configure U2TX - put on pin 16 (RP7) RPOR3bits.RP7R = 5; // Analog IN Disable AD1PCFG = 0xffff; EnablePullUpCN12; // Port output setup mPORTBOutputConfig(0x8000); // Init UART UART2Init(); // Init USB if ( USBHostInit(0) != TRUE ) { UART2PrintString( "ERR USBHostInit\r\n" ); while (1); } /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // init HCI hci_transport_t * transport = hci_transport_usb_instance(); bt_control_t * control = NULL; hci_uart_config_t * config = NULL; remote_device_db_t * remote_db = NULL;//(remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // init L2CAP l2cap_init(); l2cap_register_packet_handler(bt_packet_handler); // init RFCOMM rfcomm_init(); rfcomm_register_packet_handler(bt_packet_handler); rfcomm_register_service_internal(NULL, rfcomm_channel_nr, 100); // reserved channel, mtu=100 // init SDP, create record for SPP and register with SDP sdp_init(); memset(spp_service_buffer, 0, sizeof(spp_service_buffer)); service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer; sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, 1, "SPP"); // printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); sdp_register_service_internal(NULL, service_record_item); // usbhost data_source_t usbhost; usbhost.process = &usbhost_process; run_loop_add_data_source(&usbhost); data_source_t swtask; swtask.process = &sw_process; run_loop_add_data_source(&swtask); // go! run_loop_execute(); return 0; } // main
/*-----------------------------------------------------------------------------------*/ void maintask(void) { struct phybusif_cb *cb; CLKBLK ks_clk *tmr; u8_t bt_timer = 0; u16_t http_timer = 0; u16_t dma0bsz = TCR0+1; /* DMA 0 Buf size */ u8_t bt_ip_timer = 0; mem_init(); memp_init(); pbuf_init(); netif_init(); ip_init(); tcp_init(); sio_print("TCP/IP initialized.\n"); lwbt_memp_init(); phybusif_init(); if(hci_init() != ERR_OK) { sio_print("HCI initialization failed!"); } l2cap_init(); sdp_init(); rfcomm_init(); ppp_init(); sio_print("Bluetooth initialized.\n"); httpd_init(); sio_print("Applications started.\n"); cb = mem_malloc(sizeof(struct phybusif_cb)); cb->dmabuf = get_dm0ichars(); phybusif_reset(cb); tmr = KS_alloc_timer(); if(tmr == 0) { sio_print("tmr==0!\n"); } KS_start_timer(tmr, (TICKS)0, (TICKS)100/CLKTICK, TIMERSEM); /* TCP timer ticks every 100ms */ /* Reset Bluetooth module */ PD7.0 = 1; /* Enable output */ sio_print("Reseting BT module\n"); P7.0 = 1; /* Stop reset */ KS_delay(SELFTASK,(TICKS)4000/CLKTICK); /* Wait for bluetooth module to init */ /* Control application initialisation */ bt_ip_start(); while(1) { dma_input(cb, dma0bsz); /* Check for input */ /* Handle timers */ if(KS_inqsema(TIMERSEM) == SEMA_DONE) { KS_wait(TIMERSEM); tcp_tmr(); ++bt_timer; if(bt_timer == 10) { l2cap_tmr(); rfcomm_tmr(); ppp_tmr(); bt_timer = 0; ++bt_ip_timer; if(bt_ip_timer == 240) { bt_ip_tmr(); bt_ip_timer = 0; } } } } }