Пример #1
0
wiced_result_t command_console_init( wiced_uart_t uart, uint32_t line_len, char* buffer, uint32_t history_len, char* history_buffer_ptr, const char* delimiter_string )
{
    wiced_result_t result;
    UNUSED_PARAMETER(result);

    cons.uart = uart;

    cons.command_table_count = 0;
    cons.console_line_len   = line_len;
    cons.console_buffer = buffer;

    cons.console_buffer[0] = 0;
    cons.console_cursor_position = 0;
    cons.console_current_line = 0;
    cons.console_in_esc_seq = WICED_FALSE;
    cons.console_esc_seq_last_char = ' ';

    cons.history_buffer = history_buffer_ptr;
    cons.history_length = history_len;
    cons.history_num_lines = 0;
    cons.history_newest_line = 0;
    cons.quit = WICED_FALSE;
    cons.console_delimit_string = delimiter_string;
    cons.console_prompt_string = "> ";

    cons.console_thread_is_running = WICED_FALSE;

    console_add_cmd_table( commands );


    if( uart != STDIO_UART )
    {
        /* Init uart the same as stdio uart configuration */
        ring_buffer_init( (wiced_ring_buffer_t*) &cons.console_rx_ring_buffer, (uint8_t*) console_rx_ring_data, sizeof(console_rx_ring_data) );
        result = wiced_uart_init(uart, &uart_console_config, &cons.console_rx_ring_buffer);
    }

    wiced_rtos_init_semaphore(&cons.console_quit_semaphore);

    send_str(cons.console_prompt_string);

    /* create a console thread */
    result = wiced_rtos_create_thread( &cons.console_thread, WICED_DEFAULT_LIBRARY_PRIORITY, "console", console_thread_func, CONSOLE_THREAD_STACK_SIZE, NULL);

    return result;

}
/* Main application */
void application_start( )
{
	char    receiveChar;
    uint32_t expected_data_size = 1;

	wiced_init();	/* Initialize the WICED device */

    /* Configure and start the UART. */
    /* Note that WICED_DISABLE_STDIO must be defined in the make file for this to work */
	#define RX_BUFFER_SIZE (5)
	wiced_ring_buffer_t rx_buffer;
    uint8_t             rx_data[RX_BUFFER_SIZE];
	ring_buffer_init(&rx_buffer, rx_data, RX_BUFFER_SIZE ); /* Initialize ring buffer to hold receive data */
    wiced_uart_config_t uart_config =
    {
        .baud_rate    = 9600,
        .data_width   = DATA_WIDTH_8BIT,
        .parity       = NO_PARITY,
        .stop_bits    = STOP_BITS_1,
        .flow_control = FLOW_CONTROL_DISABLED,
    };
    wiced_uart_init( STDIO_UART, &uart_config, &rx_buffer); /* Setup UART */

    while ( 1 )
    {
        if ( wiced_uart_receive_bytes( STDIO_UART, &receiveChar, &expected_data_size, WICED_NEVER_TIMEOUT ) == WICED_SUCCESS )
        {
            /* If we get here then a character has been received */
        	if(receiveChar == '0') /* LED OFF for the shield (LED ON if using the baseboard by itself) */
        	{
        		wiced_gpio_output_low( WICED_LED1 );
        	}
        	if(receiveChar == '1') /* LED ON for the shield (LED OFF if using the baseboard by itself) */
        	{
        		wiced_gpio_output_high( WICED_LED1 );
        	}
        }

    }
}
Пример #3
0
wiced_result_t wiced_wlu_server_serial_start( wiced_uart_t uart_id )
{
    wiced_assert("wlu_server already started",
            (wlu_server.started == WICED_FALSE));

    wlu_server.started = WICED_TRUE;
    wlu_server.uart_id = uart_id;

    WWD_WLAN_KEEP_AWAKE( );

    if ( uart_id != STDIO_UART )
    {
        static const platform_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_DISABLED,
        };

        WICED_VERIFY( wiced_uart_init( uart_id, &uart_config, NULL ) );
    }
    /* Start wlu server thread */
    wiced_rtos_create_thread(&wlu_server.thread, WLU_SERVER_THREAD_PRIORITY, "wlu_server", wlu_server_thread, WLU_SERVER_STACK_SIZE, &wlu_server);
    return WICED_SUCCESS;
}

wiced_result_t wiced_wlu_server_serial_stop( void )
{
    if ( wiced_rtos_is_current_thread( &wlu_server.thread ) != WICED_SUCCESS )
    {
        wiced_rtos_thread_force_awake( &wlu_server.thread );
        wiced_rtos_thread_join( &wlu_server.thread );
        wiced_rtos_delete_thread( &wlu_server.thread );
    }
    WWD_WLAN_LET_SLEEP( );
    wlu_server.started = WICED_FALSE;
    return WICED_SUCCESS;
}

static void wlu_server_thread( uint32_t thread_input )
{
    wiced_wlu_server_t* wlu = (wiced_wlu_server_t*) thread_input;
    int argc = 2;
    char *argv[] = { (char*)wlu->uart_id, "" };
#ifdef  RWL_SOCKET
    char *arge[] = { (char *)wlu->eth_port, "" };
#endif


    wiced_assert( "invalid argument", wlu->uart_id < WICED_UART_MAX );

    UNUSED_PARAMETER(thread_input);

#ifdef  RWL_SOCKET
    if (wlu->eth_started ==  WICED_TRUE)
#endif
    {
#ifdef  RWL_SOCKET
        remote_server_exec( argc, (wlu->eth_started ==  WICED_TRUE)?arge:argv, NULL );
#else
        remote_server_exec(argc, argv, NULL);
#endif


    }
}
Пример #4
0
wiced_result_t bt_mfgtest_start( const wiced_uart_config_t* config )
{
    wiced_result_t result;

    result = bt_firmware_download( bt_hci_firmware_image, bt_hci_firmware_size, bt_hci_firmware_version );
    if ( result != WICED_BT_SUCCESS )
    {
        WPRINT_LIB_ERROR( ( "Error downloading HCI firmware\n" ) );
        return result;
    }

    result = bt_transport_driver_init( bt_mfgtest_transport_driver_event_handler, bt_mfgtest_transport_driver_bus_read_handler );
    if ( result != WICED_BT_SUCCESS )
    {
        WPRINT_LIB_ERROR( ( "Error initialising BT transport driver\n" ) );
        return result;
    }

    /* Initialise BT transport thread */
    result = bt_transport_thread_init( bt_mfgtest_transport_thread_received_packet_handler );
    if ( result != WICED_BT_SUCCESS )
    {
        WPRINT_LIB_ERROR( ( "Error initialising BT transport thread\n" ) );
        return result;
    }

    ring_buffer_init( &pc_uart_ring_buffer, pc_uart_ring_buffer_data, BT_BUS_RX_FIFO_SIZE );

    result = wiced_uart_init( STDIO_UART, config, &pc_uart_ring_buffer );
    if ( result != WICED_SUCCESS )
    {
        WPRINT_LIB_ERROR( ( "Error initialising UART connection to PC\n" ) );
        return result;
    }

    /* Grab message from PC and pass it over to the controller */
    while ( 1 )
    {
        hci_command_header_t header;
        bt_packet_t*         packet;

        /* Read HCI header */
        wiced_uart_receive_bytes( STDIO_UART, (void*)&header, sizeof( header ), WICED_NEVER_TIMEOUT );

        /* Allocate dynamic packet */
        bt_packet_pool_dynamic_allocate_packet( &packet, sizeof( header ), header.content_length );

        /* Copy header to packet */
        memcpy( packet->packet_start, &header, sizeof( header ) );

        /* Read the remaining packet */
        wiced_uart_receive_bytes( STDIO_UART, packet->data_start, header.content_length, WICED_NEVER_TIMEOUT );

        /* Set the end of the packet */
        packet->data_end = packet->data_start + header.content_length;

        /* Send packet to the controller */
        bt_transport_driver_send_packet( packet );
    }

    return WICED_BT_SUCCESS;
}