xref: /btstack/port/renesas-tb-s1ja-cc256x/template/btstack_example/src/hal_entry.c (revision d39264f239eb026fd486651e238a9ef65f8504ab)
13b5c872aSMatthias Ringwald /*
23b5c872aSMatthias Ringwald  * Copyright (C) 2019 BlueKitchen GmbH
33b5c872aSMatthias Ringwald  *
43b5c872aSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
53b5c872aSMatthias Ringwald  * modification, are permitted provided that the following conditions
63b5c872aSMatthias Ringwald  * are met:
73b5c872aSMatthias Ringwald  *
83b5c872aSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
93b5c872aSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
103b5c872aSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
113b5c872aSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
123b5c872aSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
133b5c872aSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
143b5c872aSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
153b5c872aSMatthias Ringwald  *    from this software without specific prior written permission.
163b5c872aSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
173b5c872aSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
183b5c872aSMatthias Ringwald  *    monetary gain.
193b5c872aSMatthias Ringwald  *
203b5c872aSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
213b5c872aSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
223b5c872aSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
253b5c872aSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
263b5c872aSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
273b5c872aSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
283b5c872aSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
293b5c872aSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
303b5c872aSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313b5c872aSMatthias Ringwald  * SUCH DAMAGE.
323b5c872aSMatthias Ringwald  *
333b5c872aSMatthias Ringwald  * Please inquire about commercial licensing options at
343b5c872aSMatthias Ringwald  * [email protected]
353b5c872aSMatthias Ringwald  *
363b5c872aSMatthias Ringwald  */
373b5c872aSMatthias Ringwald 
383b5c872aSMatthias Ringwald #define BTSTACK_FILE__ "hal_entry.c"
393b5c872aSMatthias Ringwald 
403b5c872aSMatthias Ringwald #include "../src/synergy_gen/hal_data.h"
413b5c872aSMatthias Ringwald 
423b5c872aSMatthias Ringwald // hal_time_ms.h implementation
433b5c872aSMatthias Ringwald #include "hal_time_ms.h"
443b5c872aSMatthias Ringwald 
453b5c872aSMatthias Ringwald volatile uint32_t time_ms;
463b5c872aSMatthias Ringwald 
timer_1ms(timer_callback_args_t * p_args)473b5c872aSMatthias Ringwald void timer_1ms(timer_callback_args_t *p_args){
483b5c872aSMatthias Ringwald     (void) p_args;
493b5c872aSMatthias Ringwald     time_ms++;
503b5c872aSMatthias Ringwald }
513b5c872aSMatthias Ringwald 
hal_time_ms(void)523b5c872aSMatthias Ringwald uint32_t hal_time_ms(void){
533b5c872aSMatthias Ringwald     return time_ms;
543b5c872aSMatthias Ringwald }
553b5c872aSMatthias Ringwald 
563b5c872aSMatthias Ringwald // hal_cpu.h implementation
573b5c872aSMatthias Ringwald #include "hal_cpu.h"
583b5c872aSMatthias Ringwald 
hal_cpu_disable_irqs(void)593b5c872aSMatthias Ringwald void hal_cpu_disable_irqs(void){
603b5c872aSMatthias Ringwald     __disable_irq();
613b5c872aSMatthias Ringwald }
623b5c872aSMatthias Ringwald 
hal_cpu_enable_irqs(void)633b5c872aSMatthias Ringwald void hal_cpu_enable_irqs(void){
643b5c872aSMatthias Ringwald     __enable_irq();
653b5c872aSMatthias Ringwald }
663b5c872aSMatthias Ringwald 
hal_cpu_enable_irqs_and_sleep(void)673b5c872aSMatthias Ringwald void hal_cpu_enable_irqs_and_sleep(void){
683b5c872aSMatthias Ringwald     __enable_irq();
693b5c872aSMatthias Ringwald     __asm__("wfe"); // go to sleep if event flag isn't set. if set, just clear it. IRQs set event flag
703b5c872aSMatthias Ringwald }
713b5c872aSMatthias Ringwald 
723b5c872aSMatthias Ringwald // hal_uart_dma.h implementation
733b5c872aSMatthias Ringwald #include "hal_uart_dma.h"
743b5c872aSMatthias Ringwald #include "btstack_debug.h"
753b5c872aSMatthias Ringwald #include "btstack_ring_buffer.h"
763b5c872aSMatthias Ringwald #include "btstack_util.h"
773b5c872aSMatthias Ringwald 
783b5c872aSMatthias Ringwald #define nShutdown_pin IOPORT_PORT_01_PIN_12
793b5c872aSMatthias Ringwald #define rts_pin       IOPORT_PORT_03_PIN_03
803b5c872aSMatthias Ringwald 
813b5c872aSMatthias Ringwald // handlers
823b5c872aSMatthias Ringwald static void (*rx_done_handler)(void);
833b5c872aSMatthias Ringwald static void (*tx_done_handler)(void);
843b5c872aSMatthias Ringwald static void (*cts_irq_handler)(void);
853b5c872aSMatthias Ringwald 
863b5c872aSMatthias Ringwald // ringbuffer to deal with eager fifo
873b5c872aSMatthias Ringwald static uint8_t rx_ring_buffer_storage[64];
883b5c872aSMatthias Ringwald static btstack_ring_buffer_t rx_ring_buffer;
893b5c872aSMatthias Ringwald 
903b5c872aSMatthias Ringwald static volatile uint8_t * rx_buffer;
913b5c872aSMatthias Ringwald static volatile uint16_t rx_len;
923b5c872aSMatthias Ringwald 
hal_uart_dma_set_sleep(uint8_t sleep)933b5c872aSMatthias Ringwald void hal_uart_dma_set_sleep(uint8_t sleep){
943b5c872aSMatthias Ringwald     // TODO: configure RTS as GPIO and raise
953b5c872aSMatthias Ringwald     (void) sleep;
963b5c872aSMatthias Ringwald }
973b5c872aSMatthias Ringwald 
nShutdown_low(void)983b5c872aSMatthias Ringwald static void nShutdown_low(void){
993b5c872aSMatthias Ringwald     g_ioport.p_api->pinWrite(nShutdown_pin, IOPORT_LEVEL_LOW);
1003b5c872aSMatthias Ringwald }
1013b5c872aSMatthias Ringwald 
nShutdown_high(void)1023b5c872aSMatthias Ringwald static void nShutdown_high(void){
1033b5c872aSMatthias Ringwald     g_ioport.p_api->pinWrite(nShutdown_pin, IOPORT_LEVEL_HIGH);
1043b5c872aSMatthias Ringwald }
1053b5c872aSMatthias Ringwald 
1063b5c872aSMatthias Ringwald // reset Bluetooth using n_shutdown
bluetooth_power_cycle(void)1073b5c872aSMatthias Ringwald static void bluetooth_power_cycle(void){
1083b5c872aSMatthias Ringwald     nShutdown_low();
1093b5c872aSMatthias Ringwald     R_BSP_SoftwareDelay( 250, BSP_DELAY_UNITS_MILLISECONDS);
1103b5c872aSMatthias Ringwald     nShutdown_high();
1113b5c872aSMatthias Ringwald     R_BSP_SoftwareDelay( 250, BSP_DELAY_UNITS_MILLISECONDS);
1123b5c872aSMatthias Ringwald }
1133b5c872aSMatthias Ringwald 
user_uart_callback(uart_callback_args_t * p_args)1143b5c872aSMatthias Ringwald void user_uart_callback(uart_callback_args_t *p_args){
1153b5c872aSMatthias Ringwald     switch (p_args->event){
1163b5c872aSMatthias Ringwald         case UART_EVENT_TX_DATA_EMPTY:
1173b5c872aSMatthias Ringwald             (*tx_done_handler)();
1183b5c872aSMatthias Ringwald             break;
1193b5c872aSMatthias Ringwald         case UART_EVENT_RX_CHAR:
1203b5c872aSMatthias Ringwald             if (rx_len > 0){
1213b5c872aSMatthias Ringwald                 *rx_buffer++ = (uint8_t) p_args->data;
1223b5c872aSMatthias Ringwald                 rx_len--;
1233b5c872aSMatthias Ringwald                 if (rx_len == 0) {
1243b5c872aSMatthias Ringwald                     g_ioport.p_api->pinWrite(rts_pin, IOPORT_LEVEL_HIGH);
1253b5c872aSMatthias Ringwald                     (*rx_done_handler)();
1263b5c872aSMatthias Ringwald                 }
1273b5c872aSMatthias Ringwald             } else {
1283b5c872aSMatthias Ringwald                 // store in ring buffer
1293b5c872aSMatthias Ringwald                 uint8_t data = (uint8_t) p_args->data;
1303b5c872aSMatthias Ringwald                 btstack_ring_buffer_write(&rx_ring_buffer, &data, 1);
1313b5c872aSMatthias Ringwald             }
1323b5c872aSMatthias Ringwald             break;
1333b5c872aSMatthias Ringwald         case UART_EVENT_ERR_RXBUF_OVERFLOW:
1343b5c872aSMatthias Ringwald             log_info("UART_EVENT_ERR_RXBUF_OVERFLOW");
1353b5c872aSMatthias Ringwald             break;
1363b5c872aSMatthias Ringwald         default:
1373b5c872aSMatthias Ringwald             break;
1383b5c872aSMatthias Ringwald     }
1393b5c872aSMatthias Ringwald }
1403b5c872aSMatthias Ringwald 
hal_uart_dma_init(void)1413b5c872aSMatthias Ringwald void hal_uart_dma_init(void){
1423b5c872aSMatthias Ringwald     bluetooth_power_cycle();
1433b5c872aSMatthias Ringwald     btstack_ring_buffer_init(&rx_ring_buffer, rx_ring_buffer_storage, sizeof(rx_ring_buffer_storage));
1443b5c872aSMatthias Ringwald }
1453b5c872aSMatthias Ringwald 
hal_uart_dma_set_block_received(void (* the_block_handler)(void))1463b5c872aSMatthias Ringwald void hal_uart_dma_set_block_received( void (*the_block_handler)(void)){
1473b5c872aSMatthias Ringwald     rx_done_handler = the_block_handler;
1483b5c872aSMatthias Ringwald }
1493b5c872aSMatthias Ringwald 
hal_uart_dma_set_block_sent(void (* the_block_handler)(void))1503b5c872aSMatthias Ringwald void hal_uart_dma_set_block_sent( void (*the_block_handler)(void)){
1513b5c872aSMatthias Ringwald     tx_done_handler = the_block_handler;
1523b5c872aSMatthias Ringwald }
1533b5c872aSMatthias Ringwald 
hal_uart_dma_set_csr_irq_handler(void (* the_irq_handler)(void))1543b5c872aSMatthias Ringwald void hal_uart_dma_set_csr_irq_handler( void (*the_irq_handler)(void)){
1553b5c872aSMatthias Ringwald     // TODO: configure CTS GPIO as edge falling edge trigger
1563b5c872aSMatthias Ringwald     cts_irq_handler = the_irq_handler;
1573b5c872aSMatthias Ringwald }
1583b5c872aSMatthias Ringwald 
hal_uart_dma_set_baud(uint32_t baud)1593b5c872aSMatthias Ringwald int  hal_uart_dma_set_baud(uint32_t baud){
1603b5c872aSMatthias Ringwald     ssp_err_t error = g_uart0.p_api->baudSet(g_uart0.p_ctrl, baud);
1613b5c872aSMatthias Ringwald     if (error != SSP_SUCCESS){
1623b5c872aSMatthias Ringwald         log_error("hal_uart_dma_set_baud error 0x%x", error);
1633b5c872aSMatthias Ringwald     }
1643b5c872aSMatthias Ringwald     return 0;
1653b5c872aSMatthias Ringwald }
1663b5c872aSMatthias Ringwald 
hal_uart_dma_send_block(const uint8_t * data,uint16_t size)1673b5c872aSMatthias Ringwald void hal_uart_dma_send_block(const uint8_t *data, uint16_t size){
1683b5c872aSMatthias Ringwald     g_uart0.p_api->write(g_uart0.p_ctrl, data, size);
1693b5c872aSMatthias Ringwald }
1703b5c872aSMatthias Ringwald 
hal_uart_dma_receive_block(uint8_t * data,uint16_t size)1713b5c872aSMatthias Ringwald void hal_uart_dma_receive_block(uint8_t *data, uint16_t size){
1723b5c872aSMatthias Ringwald     // fill from  ring buffer
1733b5c872aSMatthias Ringwald     uint32_t number_of_bytes_read = 0;
1743b5c872aSMatthias Ringwald     btstack_ring_buffer_read(&rx_ring_buffer, data, size, &number_of_bytes_read);
1753b5c872aSMatthias Ringwald     size -= number_of_bytes_read;
1763b5c872aSMatthias Ringwald     data += number_of_bytes_read;
1773b5c872aSMatthias Ringwald     if (size == 0){
1783b5c872aSMatthias Ringwald         (*rx_done_handler)();
1793b5c872aSMatthias Ringwald         return;
1803b5c872aSMatthias Ringwald     }
1813b5c872aSMatthias Ringwald 
1823b5c872aSMatthias Ringwald     // Clear RTS and read from UART
1833b5c872aSMatthias Ringwald     rx_buffer = data;
1843b5c872aSMatthias Ringwald     rx_len = size;
1853b5c872aSMatthias Ringwald     g_ioport.p_api->pinWrite(rts_pin, IOPORT_LEVEL_LOW);
1863b5c872aSMatthias Ringwald }
1873b5c872aSMatthias Ringwald 
1883b5c872aSMatthias Ringwald // actual port
1893b5c872aSMatthias Ringwald 
1903b5c872aSMatthias Ringwald #include "bluetooth.h"
1913b5c872aSMatthias Ringwald #include "bluetooth_company_id.h"
1923b5c872aSMatthias Ringwald #include "btstack_chipset_cc256x.h"
1933b5c872aSMatthias Ringwald #include "btstack_defines.h"
1943b5c872aSMatthias Ringwald #include "btstack_event.h"
1953b5c872aSMatthias Ringwald #include "btstack_run_loop_embedded.h"
1963b5c872aSMatthias Ringwald #include "btstack_tlv.h"
1973b5c872aSMatthias Ringwald #include "btstack_tlv_flash_bank.h"
1983b5c872aSMatthias Ringwald #include "hci.h"
1993b5c872aSMatthias Ringwald #include "hci_cmd.h"
2003b5c872aSMatthias Ringwald #include "hci_dump.h"
201057ebb45SMatthias Ringwald #include "hci_dump_embedded_stdout.h"
2023b5c872aSMatthias Ringwald #include "hci_transport.h"
203c8dfe071SMatthias Ringwald #include "hci_transport_h4.h"
2043b5c872aSMatthias Ringwald #include "btstack_memory.h"
2053b5c872aSMatthias Ringwald #include "ble/le_device_db_tlv.h"
2063b5c872aSMatthias Ringwald #include "classic/btstack_link_key_db_tlv.h"
207f0e5893eSMatthias Ringwald #include "hal_flash_bank_synergy.h"
2083b5c872aSMatthias Ringwald 
packet_handler(uint8_t packet_type,uint16_t channel,uint8_t * packet,uint16_t size)2093b5c872aSMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
2103b5c872aSMatthias Ringwald     UNUSED(size);
2113b5c872aSMatthias Ringwald     UNUSED(channel);
2123b5c872aSMatthias Ringwald     bd_addr_t local_addr;
2133b5c872aSMatthias Ringwald     if (packet_type != HCI_EVENT_PACKET) return;
2143b5c872aSMatthias Ringwald     switch(hci_event_packet_get_type(packet)){
2153b5c872aSMatthias Ringwald         case BTSTACK_EVENT_STATE:
2163b5c872aSMatthias Ringwald             if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return;
2173b5c872aSMatthias Ringwald             gap_local_bd_addr(local_addr);
2183b5c872aSMatthias Ringwald             printf("BTstack up and running on %s.\n", bd_addr_to_str(local_addr));
2193b5c872aSMatthias Ringwald             break;
2203b5c872aSMatthias Ringwald         case HCI_EVENT_COMMAND_COMPLETE:
221*d39264f2SMatthias Ringwald             if (hci_event_command_complete_get_command_opcode(packet) == HCI_OPCODE_HCI_READ_LOCAL_VERSION_INFORMATION){
2223b5c872aSMatthias Ringwald                 uint16_t manufacturer   = little_endian_read_16(packet, 10);
2233b5c872aSMatthias Ringwald                 uint16_t lmp_subversion = little_endian_read_16(packet, 12);
2243b5c872aSMatthias Ringwald                 // assert manufacturer is TI
2253b5c872aSMatthias Ringwald                 if (manufacturer != BLUETOOTH_COMPANY_ID_TEXAS_INSTRUMENTS_INC){
2263b5c872aSMatthias Ringwald                     printf("ERROR: Expected Bluetooth Chipset from TI but got manufacturer 0x%04x\n", manufacturer);
2273b5c872aSMatthias Ringwald                     break;
2283b5c872aSMatthias Ringwald                 }
2293b5c872aSMatthias Ringwald                 // assert correct init script is used based on expected lmp_subversion
2303b5c872aSMatthias Ringwald                 if (lmp_subversion != btstack_chipset_cc256x_lmp_subversion()){
2313b5c872aSMatthias Ringwald                     printf("Error: LMP Subversion does not match initscript! ");
2323b5c872aSMatthias Ringwald                     printf("Your initscripts is for %s chipset\n", btstack_chipset_cc256x_lmp_subversion() < lmp_subversion ? "an older" : "a newer");
2333b5c872aSMatthias Ringwald                     printf("Please update Makefile to include the appropriate bluetooth_init_cc256???.c file\n");
2343b5c872aSMatthias Ringwald                     break;
2353b5c872aSMatthias Ringwald                 }
2363b5c872aSMatthias Ringwald             }
2373b5c872aSMatthias Ringwald             break;
2383b5c872aSMatthias Ringwald         default:
2393b5c872aSMatthias Ringwald             break;
2403b5c872aSMatthias Ringwald     }
2413b5c872aSMatthias Ringwald }
2423b5c872aSMatthias Ringwald 
2433b5c872aSMatthias Ringwald // port.c
2443b5c872aSMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration;
2453b5c872aSMatthias Ringwald static btstack_tlv_flash_bank_t btstack_tlv_flash_bank_context;
2463b5c872aSMatthias Ringwald 
247f0e5893eSMatthias Ringwald static hal_flash_bank_synergy_t  hal_flash_bank_context;
248f0e5893eSMatthias Ringwald #define HAL_FLASH_BANK_SIZE     ( 10224 )
249f0e5893eSMatthias Ringwald #define HAL_FLASH_BANK_0_ADDR   ( 0x40100000 )
250f0e5893eSMatthias Ringwald #define HAL_FLASH_BANK_1_ADDR   ( 0x40100400 )
251f0e5893eSMatthias Ringwald 
2523b5c872aSMatthias Ringwald static const hci_transport_config_uart_t config = {
2533b5c872aSMatthias Ringwald     HCI_TRANSPORT_CONFIG_UART,
2543b5c872aSMatthias Ringwald     115200,
25571174eb4SMatthias Ringwald     2000000,
2563b5c872aSMatthias Ringwald     1,
2573b5c872aSMatthias Ringwald     NULL
2583b5c872aSMatthias Ringwald };
2593b5c872aSMatthias Ringwald 
2603b5c872aSMatthias Ringwald int btstack_main(int argc, const char * argv[]);
hal_entry(void)2613b5c872aSMatthias Ringwald void hal_entry(void) {
2623b5c872aSMatthias Ringwald 
2633b5c872aSMatthias Ringwald     // init hal
2643b5c872aSMatthias Ringwald     g_hal_init();
2653b5c872aSMatthias Ringwald 
266f0e5893eSMatthias Ringwald     // open uart, timer, flash
2673b5c872aSMatthias Ringwald     g_uart0.p_api->open(g_uart0.p_ctrl, g_uart0.p_cfg);
2683b5c872aSMatthias Ringwald     g_timer0.p_api->open(g_timer0.p_ctrl, g_timer0.p_cfg);
269f0e5893eSMatthias Ringwald     g_flash0.p_api->open(g_flash0.p_ctrl, g_flash0.p_cfg);
2703b5c872aSMatthias Ringwald 
2713b5c872aSMatthias Ringwald     // start with BTstack init - especially configure HCI Transport
2723b5c872aSMatthias Ringwald     btstack_memory_init();
2733b5c872aSMatthias Ringwald     btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
2743b5c872aSMatthias Ringwald 
2753035e4e5SMatthias Ringwald     // enable HCI logging
276057ebb45SMatthias Ringwald     // hci_dump_init(hci_dump_embedded_stdout_get_instance());
2773b5c872aSMatthias Ringwald 
2783b5c872aSMatthias Ringwald     // init HCI
2793b5c872aSMatthias Ringwald     hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), (void*) &config);
2803b5c872aSMatthias Ringwald     hci_set_chipset(btstack_chipset_cc256x_instance());
2813b5c872aSMatthias Ringwald 
2823b5c872aSMatthias Ringwald     // setup TLV Flash Sector implementation
283f0e5893eSMatthias Ringwald     const hal_flash_bank_t * hal_flash_bank_impl = hal_flash_bank_synergy_init_instance(
2843b5c872aSMatthias Ringwald             &hal_flash_bank_context,
2853b5c872aSMatthias Ringwald             HAL_FLASH_BANK_SIZE,
2863b5c872aSMatthias Ringwald             HAL_FLASH_BANK_0_ADDR,
2873b5c872aSMatthias Ringwald             HAL_FLASH_BANK_1_ADDR);
2883b5c872aSMatthias Ringwald 
2893b5c872aSMatthias Ringwald     const btstack_tlv_t * btstack_tlv_impl = btstack_tlv_flash_bank_init_instance(
2903b5c872aSMatthias Ringwald             &btstack_tlv_flash_bank_context,
2913b5c872aSMatthias Ringwald             hal_flash_bank_impl,
2923b5c872aSMatthias Ringwald             &hal_flash_bank_context);
2933b5c872aSMatthias Ringwald 
2943b5c872aSMatthias Ringwald     // setup global tlv
2953b5c872aSMatthias Ringwald     btstack_tlv_set_instance(btstack_tlv_impl, &btstack_tlv_flash_bank_context);
2963b5c872aSMatthias Ringwald 
2973b5c872aSMatthias Ringwald     // setup Link Key DB using TLV
2983b5c872aSMatthias Ringwald     const btstack_link_key_db_t * btstack_link_key_db = btstack_link_key_db_tlv_get_instance(btstack_tlv_impl, &btstack_tlv_flash_bank_context);
2993b5c872aSMatthias Ringwald     hci_set_link_key_db(btstack_link_key_db);
3003b5c872aSMatthias Ringwald 
3013b5c872aSMatthias Ringwald     // setup LE Device DB using TLV
3023b5c872aSMatthias Ringwald     le_device_db_tlv_configure(btstack_tlv_impl, &btstack_tlv_flash_bank_context);
3033b5c872aSMatthias Ringwald 
3043b5c872aSMatthias Ringwald #ifdef HAVE_HAL_AUDIO
3053b5c872aSMatthias Ringwald     // setup audio
3063b5c872aSMatthias Ringwald     btstack_audio_sink_set_instance(btstack_audio_embedded_sink_get_instance());
3073b5c872aSMatthias Ringwald     btstack_audio_source_set_instance(btstack_audio_embedded_source_get_instance());
3083b5c872aSMatthias Ringwald #endif
3093b5c872aSMatthias Ringwald 
3103b5c872aSMatthias Ringwald     // inform about BTstack state
3113b5c872aSMatthias Ringwald     hci_event_callback_registration.callback = &packet_handler;
3123b5c872aSMatthias Ringwald     hci_add_event_handler(&hci_event_callback_registration);
3133b5c872aSMatthias Ringwald 
3143b5c872aSMatthias Ringwald     // hand over to btstack embedded code
3153b5c872aSMatthias Ringwald     btstack_main(0, NULL);
3163b5c872aSMatthias Ringwald 
3173b5c872aSMatthias Ringwald     // go
3183b5c872aSMatthias Ringwald     btstack_run_loop_execute();
3193b5c872aSMatthias Ringwald }
320