1 /* 2 * Copyright (c) 2017 Intel Corporation. 3 * Copyright (c) 2018 Nordic Semiconductor ASA. 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 #include <zephyr/kernel.h> 9 10 /* Value of 0 will cause the IP stack to select next free port */ 11 #define MY_PORT 0 12 13 #define PEER_PORT 4242 14 15 /* Turn off the progress printing so that shell can be used. 16 * Set to true if you want to see progress output. 17 */ 18 #define PRINT_PROGRESS false 19 20 #if defined(CONFIG_USERSPACE) 21 #include <zephyr/app_memory/app_memdomain.h> 22 extern struct k_mem_partition app_partition; 23 extern struct k_mem_domain app_domain; 24 #define APP_BMEM K_APP_BMEM(app_partition) 25 #define APP_DMEM K_APP_DMEM(app_partition) 26 #else 27 #define APP_BMEM 28 #define APP_DMEM 29 #endif 30 31 #if defined(CONFIG_NET_TC_THREAD_PREEMPTIVE) 32 #define THREAD_PRIORITY K_PRIO_PREEMPT(8) 33 #else 34 #define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1) 35 #endif 36 37 #define UDP_STACK_SIZE 2048 38 39 struct udp_control { 40 struct k_poll_signal tx_signal; 41 struct k_timer tx_timer; 42 struct k_timer rx_timer; 43 }; 44 45 struct sample_data { 46 const char *proto; 47 48 struct { 49 int sock; 50 uint32_t expecting; 51 uint32_t counter; 52 uint32_t mtu; 53 struct udp_control *ctrl; 54 } udp; 55 56 struct { 57 int sock; 58 uint32_t expecting; 59 uint32_t received; 60 uint32_t counter; 61 } tcp; 62 }; 63 64 struct configs { 65 struct sample_data ipv4; 66 struct sample_data ipv6; 67 }; 68 69 #if !defined(CONFIG_NET_CONFIG_PEER_IPV4_ADDR) 70 #define CONFIG_NET_CONFIG_PEER_IPV4_ADDR "" 71 #endif 72 73 #if !defined(CONFIG_NET_CONFIG_PEER_IPV6_ADDR) 74 #define CONFIG_NET_CONFIG_PEER_IPV6_ADDR "" 75 #endif 76 77 extern const char lorem_ipsum[]; 78 extern const int ipsum_len; 79 extern struct configs conf; 80 81 #if defined(CONFIG_NET_UDP) 82 /* init_udp initializes kernel objects, hence it has to be called from 83 * supervisor thread. 84 */ 85 void init_udp(void); 86 int start_udp(void); 87 int process_udp(void); 88 void stop_udp(void); 89 #else init_udp(void)90static inline void init_udp(void) { } start_udp(void)91static inline int start_udp(void) { return 0; } process_udp(void)92static inline int process_udp(void) { return 0; } stop_udp(void)93static inline void stop_udp(void) { } 94 #endif /* defined(CONFIG_NET_UDP) */ 95 96 int start_tcp(void); 97 int process_tcp(void); 98 void stop_tcp(void); 99 100 #if defined(CONFIG_NET_VLAN) 101 int init_vlan(void); 102 #else init_vlan(void)103static inline int init_vlan(void) 104 { 105 return 0; 106 } 107 #endif 108