From 78baa15460d93ffbe07b9540859ad73506905473 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 23 Dec 2015 16:04:05 +0100 Subject: [PATCH] wiced: add files for LE peripheral --- port/wiced/main.c | 160 +------------------------------------------- port/wiced/wiced.mk | 8 ++- 2 files changed, 9 insertions(+), 159 deletions(-) diff --git a/port/wiced/main.c b/port/wiced/main.c index e5d0c5d5e..2da5fc61d 100644 --- a/port/wiced/main.c +++ b/port/wiced/main.c @@ -37,165 +37,9 @@ #include "wiced.h" #include "platform_bluetooth.h" +#include "bt_control_bcm.h" #include "btstack.h" - -#if 0 -static void dummy_handler(void); - -// handlers -static void (*rx_done_handler)(void) = dummy_handler; -static void (*tx_done_handler)(void) = dummy_handler; -static void (*cts_irq_handler)(void) = dummy_handler; -static int hal_uart_needed_during_sleep = 1; - -// static wiced_worker_thread_t tick_worker; - -// worker thread to do blocking write -static wiced_worker_thread_t rx_worker; -static uint8_t * rx_worker_data_buffer; -static uint16_t rx_worker_data_size; - -// worker thread to do blocking read -static wiced_worker_thread_t tx_worker; -static const uint8_t * tx_worker_data_buffer; -static uint16_t tx_worker_data_size; - -static void dummy_handler(void){}; - -void hal_uart_dma_init(void){ - - wiced_uart_config_t uart_config = - { - .baud_rate = 115200, - .data_width = DATA_WIDTH_8BIT, - .parity = NO_PARITY, - .stop_bits = STOP_BITS_1, - .flow_control = FLOW_CONTROL_CTS_RTS, - }; - - // test RTS first - platform_gpio_init( wiced_bt_control_pins[WICED_BT_PIN_UART_RTS], OUTPUT_PUSH_PULL); - platform_gpio_init( wiced_bt_control_pins[WICED_BT_PIN_UART_TX], OUTPUT_PUSH_PULL); - while (1) { - platform_gpio_output_low( wiced_bt_control_pins[WICED_BT_PIN_UART_RTS]); - platform_gpio_output_low( wiced_bt_control_pins[WICED_BT_PIN_UART_TX]); - platform_gpio_output_high(wiced_bt_control_pins[WICED_BT_PIN_UART_RTS]); - platform_gpio_output_high(wiced_bt_control_pins[WICED_BT_PIN_UART_TX]); - } - - // configure HOST and DEVICE WAKE PINs - platform_gpio_init( wiced_bt_control_pins[WICED_BT_PIN_HOST_WAKE], INPUT_HIGH_IMPEDANCE); - platform_gpio_init( wiced_bt_control_pins[WICED_BT_PIN_DEVICE_WAKE], OUTPUT_PUSH_PULL); - platform_gpio_output_low( wiced_bt_control_pins[WICED_BT_PIN_DEVICE_WAKE]); - wiced_rtos_delay_milliseconds( 100 ); - - // power cycle Bluetooth - platform_gpio_init( wiced_bt_control_pins[ WICED_BT_PIN_POWER ], OUTPUT_PUSH_PULL ); - platform_gpio_output_low( wiced_bt_control_pins[ WICED_BT_PIN_POWER ] ); - wiced_rtos_delay_milliseconds( 100 ); - platform_gpio_output_high( wiced_bt_control_pins[ WICED_BT_PIN_POWER ] ); - - wiced_rtos_delay_milliseconds( 500 ); - - // init UART - platform_uart_init( wiced_bt_uart_driver, wiced_bt_uart_peripheral, &uart_config, NULL ); - - // create worker threads for rx/tx - wiced_rtos_create_worker_thread(&tx_worker, WICED_NETWORK_WORKER_PRIORITY, 1000, 1); - wiced_rtos_create_worker_thread(&rx_worker, WICED_NETWORK_WORKER_PRIORITY, 1000, 5); -} - -void hal_uart_dma_set_sleep(uint8_t sleep){ - hal_uart_needed_during_sleep = !sleep; -} - -void hal_uart_dma_set_block_received( void (*the_block_handler)(void)){ - rx_done_handler = the_block_handler; -} - -void hal_uart_dma_set_block_sent( void (*the_block_handler)(void)){ - tx_done_handler = the_block_handler; -} - -void hal_uart_dma_set_csr_irq_handler( void (*the_irq_handler)(void)){ - cts_irq_handler = the_irq_handler; -} - -int hal_uart_dma_set_baud(uint32_t baud){ - return 0; -} - -static wiced_result_t tx_worker_task(void * arg){ - // printf("tx_worker_task len %u\n", tx_worker_data_size); - platform_uart_transmit_bytes(wiced_bt_uart_driver, tx_worker_data_buffer, tx_worker_data_size); - // printf("tx_worker_task done\n"); - tx_done_handler(); - return WICED_SUCCESS; -} - -static wiced_result_t rx_worker_task(void * arg){ - // printf("rx_worker_task len %u\n", rx_worker_data_size); - // printf("/%u\\\n", rx_worker_data_size); - platform_uart_receive_bytes(wiced_bt_uart_driver, rx_worker_data_buffer, rx_worker_data_size, WICED_NEVER_TIMEOUT); - // printf("rx_worker_task done\n"); - rx_done_handler(); - return WICED_SUCCESS; -} - -void hal_uart_dma_send_block(const uint8_t *data, uint16_t size){ - // printf("hal_uart_dma_send_block len %u\n", size); - tx_worker_data_buffer = data; - tx_worker_data_size = size; -#if 0 - wiced_rtos_send_asynchronous_event(&tx_worker, &tx_worker_task, NULL); - printf("hal_uart_dma_send_block B\n"); - wiced_rtos_delay_milliseconds(100); -#endif - platform_uart_transmit_bytes(wiced_bt_uart_driver, tx_worker_data_buffer, tx_worker_data_size); - // printf("hal_uart_dma_send_block done\n"); - tx_done_handler(); - } - -void hal_uart_dma_receive_block(uint8_t *data, uint16_t size){ - // printf("hal_uart_dma_receive_block len %u\n", size); - rx_worker_data_buffer = data; - rx_worker_data_size = size; - - if ( wiced_rtos_is_current_thread( &rx_worker.thread ) == WICED_SUCCESS ){ - // re-entrant call .. don't post to queue, just call it directlyh - // printf("/%u\\\n", rx_worker_data_size); - rx_worker_task(NULL); - } else { - // printf("\\%u/\n", rx_worker_data_size); - wiced_rtos_send_asynchronous_event(&rx_worker, &rx_worker_task, NULL); - wiced_rtos_delay_milliseconds(100); - } - // printf("hal_uart_dma_receive_block done\n"); -} -#endif -#if 0 - while (1) { - // send HCI Reset - uint8_t hci_reset[] = { 0x01, 0x03, 0x0c, 0x00}; - wiced_result_t res; - res = platform_uart_transmit_bytes(wiced_bt_uart_driver, hci_reset, sizeof(hci_reset) ); - printf("Send reset.. res %u\n", res); - - // receive event - uint8_t buffer[6]; - res = platform_uart_receive_bytes(wiced_bt_uart_driver, buffer, 6, 5000); - int i; - for (i=0;i