void console_thread_func( uint32_t arg ) { wiced_result_t result; uint8_t received_character; UNUSED_PARAMETER(result); /* turn off buffers, so IO occurs immediately */ setvbuf( stdin, NULL, _IONBF, 0 ); setvbuf( stdout, NULL, _IONBF, 0 ); setvbuf( stderr, NULL, _IONBF, 0 ); for(;;) { result = wiced_uart_receive_bytes( cons.uart, &received_character, 1, 1000 ); if( result == WICED_SUCCESS ) { console_process_char( received_character ); } else { if( cons.quit == WICED_TRUE ) { wiced_rtos_set_semaphore(&cons.console_quit_semaphore); break; } } } }
int rwl_read_serial_port(void* hndle, char* read_buf, unsigned int data_size, unsigned int *numread) { wiced_result_t result; wiced_uart_t uart = *((wiced_uart_t*) hndle); wiced_assert( "invalid argument", uart < WICED_UART_MAX ); if ( data_size == 0 ) { return SUCCESS; } result = wiced_uart_receive_bytes( uart, read_buf, data_size, WICED_NEVER_TIMEOUT ); *numread = data_size; return ( result==WICED_SUCCESS )? SUCCESS : SERIAL_PORT_ERR; }
/* 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 ); } } } }
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; }
static void tcp_server_thread_main(uint32_t arg) { wiced_result_t result; // 5 Connections maximum at a time platform_dct_security_t* dct_security = NULL; wiced_tls_identity_t tls_identity; #if 0 wiced_tcp_server_start(&tcp_server,INTERFACE,TCP_SERVER_LISTEN_PORT,5, client_connected_callback, received_data_callback, client_disconnected_callback, NULL ); /* Lock the DCT to allow us to access the certificate and key */ WPRINT_APP_INFO(( "Read the certificate Key from DCT\n" )); result = wiced_dct_read_lock( (void**) &dct_security, WICED_FALSE, DCT_SECURITY_SECTION, 0, sizeof( *dct_security ) ); if ( result != WICED_SUCCESS ) { WPRINT_APP_INFO(("Unable to lock DCT to read certificate\n")); return; } /* Setup TLS identity */ result = wiced_tls_init_identity( &tls_identity, dct_security->private_key, strlen( dct_security->private_key ), (uint8_t*) dct_security->certificate, strlen( dct_security->certificate ) ); if ( result != WICED_SUCCESS ) { WPRINT_APP_INFO(( "Unable to initialize TLS identity. Error = [%d]\n", result )); return; } else WPRINT_APP_INFO(("Init identity succeeded\n")); result = wiced_tcp_server_enable_tls (&tcp_server, &tls_identity); if(result != WICED_SUCCESS) { WPRINT_APP_INFO(( "Failed to enable TLS. Error = [%d]\n", result )); return; } else WPRINT_APP_INFO(("Enable TLS succeeded\n")); #endif WPRINT_APP_INFO(("IP\t\tPort\tC\tDEVICE\tREGID\tVALUE\tDBSIZE\n")); WPRINT_APP_INFO(("----------------------------------------------------------------------\n")); char receiveChar; uint32_t expected_data_size=1; while(1) { wiced_uart_receive_bytes( STDIO_UART, &receiveChar, &expected_data_size, WICED_NEVER_TIMEOUT ); switch(receiveChar) { case 'p': printStatus(); break; case '?': WPRINT_APP_INFO(("p: print status of server sockets\n")); break; } } }