1 /* 2 * Copyright (c) 2020 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief Zperf sample. 10 */ 11 #include <zephyr/usb/usb_device.h> 12 #include <zephyr/usb/usbd.h> 13 #include <zephyr/net/net_config.h> 14 15 LOG_MODULE_REGISTER(zperf, CONFIG_NET_ZPERF_LOG_LEVEL); 16 17 #ifdef CONFIG_NET_LOOPBACK_SIMULATE_PACKET_DROP 18 #include <zephyr/net/loopback.h> 19 #endif 20 21 #if defined(CONFIG_USB_DEVICE_STACK_NEXT) 22 #include <sample_usbd.h> 23 24 static struct usbd_context *sample_usbd; 25 enable_usb_device_next(void)26static int enable_usb_device_next(void) 27 { 28 int err; 29 30 sample_usbd = sample_usbd_init_device(NULL); 31 if (sample_usbd == NULL) { 32 return -ENODEV; 33 } 34 35 err = usbd_enable(sample_usbd); 36 if (err) { 37 return err; 38 } 39 40 return 0; 41 } 42 #endif /* CONFIG_USB_DEVICE_STACK_NEXT */ 43 main(void)44int main(void) 45 { 46 #if defined(CONFIG_USB_DEVICE_STACK) 47 int ret; 48 49 ret = usb_enable(NULL); 50 if (ret != 0) { 51 printk("usb enable error %d\n", ret); 52 } 53 54 (void)net_config_init_app(NULL, "Initializing network"); 55 #endif /* CONFIG_USB_DEVICE_STACK */ 56 57 #if defined(CONFIG_USB_DEVICE_STACK_NEXT) 58 if (enable_usb_device_next()) { 59 return 0; 60 } 61 62 (void)net_config_init_app(NULL, "Initializing network"); 63 #endif /* CONFIG_USB_DEVICE_STACK_NEXT */ 64 65 #ifdef CONFIG_NET_LOOPBACK_SIMULATE_PACKET_DROP 66 loopback_set_packet_drop_ratio(1); 67 #endif 68 69 #if defined(CONFIG_NET_DHCPV4) && !defined(CONFIG_NET_CONFIG_SETTINGS) 70 net_dhcpv4_start(net_if_get_default()); 71 #endif 72 return 0; 73 } 74