Skip to content

Commit 8c288f5

Browse files
put example netx app in examples folder
1 parent 84701fd commit 8c288f5

3 files changed

Lines changed: 162 additions & 133 deletions

File tree

.github/workflows/threadx.yml

Lines changed: 1 addition & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -113,142 +113,10 @@ jobs:
113113
make
114114
sudo make install
115115
116-
- name: Create ThreadX NetX test app source file
117-
working-directory: ./wolfmqtt
118-
run: |
119-
cat > examples/threadx_netx_test.c <<'EOF'
120-
/* threadx_netx_test.c
121-
* Minimal ThreadX/NetX test app using NetConnect logic from mqttnet.c
122-
*/
123-
124-
#include <stdio.h>
125-
#include "tx_api.h"
126-
#include "nx_api.h"
127-
#include "nxd_dns.h"
128-
#include "wolfmqtt/mqtt_client.h"
129-
#include "examples/mqttnet.h"
130-
#include "examples/mqttexample.h"
131-
132-
#define DEMO_STACK_SIZE 40000
133-
#define DEMO_IP_ADDRESS IP_ADDRESS(192,168,1,100)
134-
#define DEMO_NET_MASK 0xFFFFFF00
135-
#define DEMO_GATEWAY_ADDRESS IP_ADDRESS(192,168,1,1)
136-
#define DEMO_DNS_SERVER IP_ADDRESS(8,8,8,8)
137-
#define DEMO_HOSTNAME "test.mosquitto.org"
138-
#define DEMO_PORT 1883
139-
#define DEMO_TIMEOUT_MS 5000
140-
141-
/* ThreadX/NetX objects */
142-
TX_THREAD demo_thread;
143-
ULONG demo_thread_stack[DEMO_STACK_SIZE / sizeof(ULONG)];
144-
NX_PACKET_POOL pool_0;
145-
NX_IP ip_0;
146-
NX_DNS dns_0;
147-
void *first_unused_memory;
148-
149-
/* Forward declaration */
150-
void demo_thread_entry(ULONG thread_input);
151-
void nx_driver_placeholder(NX_IP_DRIVER *driver_req);
152-
153-
#ifdef __linux__
154-
int main(int argc, char** argv)
155-
{
156-
tx_kernel_enter();
157-
return 0;
158-
}
159-
#endif
160-
161-
void tx_application_define(void *memory_ptr)
162-
{
163-
first_unused_memory = memory_ptr;
164-
165-
/* Create the main demo thread. */
166-
tx_thread_create(&demo_thread, "Demo Thread", demo_thread_entry, 0,
167-
demo_thread_stack, DEMO_STACK_SIZE,
168-
1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
169-
}
170-
171-
void demo_thread_entry(ULONG thread_input)
172-
{
173-
UINT status;
174-
NXD_ADDRESS dns_server;
175-
MQTTCtx mqttCtx;
176-
MqttNet net;
177-
SocketContext *sockCtx;
178-
int rc;
179-
180-
/* Initialize NetX system */
181-
nx_system_initialize();
182-
183-
/* Create a packet pool. */
184-
status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool",
185-
1536, (UCHAR*)first_unused_memory, 16*1536);
186-
if (status != NX_SUCCESS) {
187-
printf("Packet pool create failed: %u\n", status);
188-
return;
189-
}
190-
191-
/* Create an IP instance. */
192-
status = nx_ip_create(&ip_0, "NetX IP Instance",
193-
DEMO_IP_ADDRESS, DEMO_NET_MASK,
194-
&pool_0, nx_driver_placeholder,
195-
(UCHAR*)first_unused_memory + 16*1536, 2048, 1);
196-
if (status != NX_SUCCESS) {
197-
printf("IP create failed: %u\n", status);
198-
return;
199-
}
200-
201-
/* Enable ARP, ICMP, TCP, UDP */
202-
nx_arp_enable(&ip_0, (UCHAR*)first_unused_memory + 16*1536 + 2048, 1024);
203-
nx_icmp_enable(&ip_0);
204-
nx_tcp_enable(&ip_0);
205-
nx_udp_enable(&ip_0);
206-
207-
/* Create DNS instance */
208-
status = nx_dns_create(&dns_0, &ip_0, (UCHAR*)"DNS Client");
209-
if (status != NX_SUCCESS) {
210-
printf("DNS create failed: %u\n", status);
211-
return;
212-
}
213-
dns_server.nxd_ip_version = NX_IP_VERSION_V4;
214-
dns_server.nxd_ip_address.v4 = DEMO_DNS_SERVER;
215-
nxd_dns_server_add(&dns_0, &dns_server);
216-
217-
/* Initialize MQTT context and network */
218-
mqtt_init_ctx(&mqttCtx);
219-
MqttClientNet_Init(&net, &mqttCtx);
220-
sockCtx = (SocketContext*)net.context;
221-
sockCtx->ipPtr = &ip_0;
222-
sockCtx->dnsPtr = &dns_0;
223-
224-
/* Use NetConnect to connect to the MQTT broker */
225-
rc = net.connect(sockCtx, DEMO_HOSTNAME, DEMO_PORT, DEMO_TIMEOUT_MS);
226-
if (rc == 0) {
227-
printf("NetConnect succeeded!\n");
228-
net.disconnect(sockCtx);
229-
} else {
230-
printf("NetConnect failed: %d\n", rc);
231-
}
232-
233-
/* Cleanup (not strictly necessary in a demo) */
234-
nx_dns_delete(&dns_0);
235-
nx_ip_delete(&ip_0);
236-
nx_packet_pool_delete(&pool_0);
237-
/* Thread exits */
238-
tx_thread_terminate(&demo_thread);
239-
}
240-
241-
/* Placeholder driver for demo purposes */
242-
void nx_driver_placeholder(NX_IP_DRIVER *driver_req)
243-
{
244-
NX_PARAMETER_NOT_USED(driver_req);
245-
}
246-
EOF
247-
248116
- name: Compile ThreadX NetX test app
249117
working-directory: ./wolfmqtt
250118
run: |
251-
gcc -o threadx_netx_test examples/threadx_netx_test.c examples/mqttnet.c examples/mqttexample.c -I. -I${{ github.workspace }}/netxduo_src/common/inc -I${{ github.workspace }}/netxduo_src/ports/linux/gnu/inc -I${{ github.workspace }}/netxduo_src/test/cmake/netxduo64/build/libs/inc -I${{ github.workspace }}/netxduo_src/test/cmake/netxduo64/build/libs/threadx -L${{ github.workspace }}/netxduo_src/test/cmake/netxduo64/build/default_build_coverage/netxduo -L${{ github.workspace }}/netxduo_src/test/cmake/netxduo64/build/libs/threadx -lnetxduo -lthreadx -lwolfssl -lwolfmqtt
119+
gcc -DHAVE_NETX -o threadx_netx examples/threadx/threadx_netx.c examples/mqttnet.c examples/mqttexample.c -I. -I${{ github.workspace }}/netxduo_src/common/inc -I${{ github.workspace }}/netxduo_src/ports/linux/gnu/inc -I${{ github.workspace }}/netxduo_src/test/cmake/netxduo64/build/libs/inc -I${{ github.workspace }}/netxduo_src/test/cmake/netxduo64/build/libs/threadx -L${{ github.workspace }}/netxduo_src/test/cmake/netxduo64/build/default_build_coverage/netxduo -L${{ github.workspace }}/netxduo_src/test/cmake/netxduo64/build/libs/threadx -lnetxduo -lthreadx -lwolfssl -lwolfmqtt
252120
253121
# capture logs on failure
254122
- name: Show logs on failure

examples/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ DISTCLEANFILES+= examples/websocket/.libs/websocket_client
210210
endif
211211

212212
EXTRA_DIST+= examples/mqttuart.c \
213+
examples/threadx/threadx_netx.c \
213214
examples/publish.dat \
214215
examples/mqttclient/mqttclient.vcxproj \
215216
examples/nbclient/nbclient.vcxproj \

examples/threadx/threadx_netx.c

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/* threadx_netx.c
2+
*
3+
* Copyright (C) 2006-2025 wolfSSL Inc.
4+
*
5+
* This file is part of wolfMQTT.
6+
*
7+
* wolfMQTT is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfMQTT is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
22+
/* Include the autoconf generated config.h */
23+
#ifdef HAVE_CONFIG_H
24+
#include <config.h>
25+
#endif
26+
27+
28+
/* This is a start to an example use with ThreadX. It currently is being used
29+
* to confirm that compiling with all necessary NetX ThreadX API's succeds */
30+
31+
#ifdef HAVE_NETX
32+
33+
#include <stdio.h>
34+
#include "tx_api.h"
35+
#include "nx_api.h"
36+
#include "nxd_dns.h"
37+
38+
#include "wolfmqtt/mqtt_client.h"
39+
#include "examples/mqttnet.h"
40+
#include "examples/mqttexample.h"
41+
42+
#define DEMO_STACK_SIZE 40000
43+
#define DEMO_IP_ADDRESS IP_ADDRESS(192,168,1,129)
44+
#define DEMO_NET_MASK 0xFFFFFF00
45+
#define DEMO_GATEWAY_ADDRESS IP_ADDRESS(192,168,1,1)
46+
#define DEMO_DNS_SERVER IP_ADDRESS(8,8,8,8)
47+
#define DEMO_HOSTNAME "test.mosquitto.org"
48+
#define DEMO_PORT 1883
49+
#define DEMO_TIMEOUT_MS 5000
50+
51+
/* ThreadX/NetX objects */
52+
TX_THREAD demo_thread;
53+
ULONG demo_thread_stack[DEMO_STACK_SIZE / sizeof(ULONG)];
54+
NX_PACKET_POOL pool_0;
55+
NX_IP ip_0;
56+
NX_DNS dns_0;
57+
void *first_unused_memory;
58+
59+
/* Forward declaration */
60+
void demo_thread_entry(ULONG thread_input);
61+
void nx_driver_placeholder(NX_IP_DRIVER *driver_req);
62+
63+
#ifdef __linux__
64+
int main(int argc, char** argv)
65+
{
66+
tx_kernel_enter();
67+
return 0;
68+
}
69+
#endif
70+
71+
void tx_application_define(void *memory_ptr)
72+
{
73+
first_unused_memory = memory_ptr;
74+
75+
/* Create the main demo thread. */
76+
tx_thread_create(&demo_thread, "Demo Thread", demo_thread_entry, 0,
77+
demo_thread_stack, DEMO_STACK_SIZE, 1, 1,
78+
TX_NO_TIME_SLICE, TX_AUTO_START);
79+
}
80+
81+
void demo_thread_entry(ULONG thread_input)
82+
{
83+
UINT status;
84+
NXD_ADDRESS dns_server;
85+
MQTTCtx mqttCtx;
86+
MqttNet net;
87+
SocketContext *sockCtx;
88+
int rc;
89+
UCHAR* pointer = (UCHAR*)first_unused_memory;
90+
91+
/* Initialize NetX system */
92+
nx_system_initialize();
93+
94+
/* Create a packet pool. */
95+
status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool",
96+
1536, pointer, 16*1536);
97+
if (status != NX_SUCCESS) {
98+
printf("Packet pool create failed: %u\n", status);
99+
return;
100+
}
101+
pointer += 16*1536;
102+
103+
/* Create an IP instance. */
104+
status = nx_ip_create(&ip_0, "NetX IP Instance",
105+
DEMO_IP_ADDRESS, DEMO_NET_MASK,
106+
&pool_0, nx_driver_placeholder,
107+
pointer, 2048, 1);
108+
if (status != NX_SUCCESS) {
109+
printf("IP create failed: %u\n", status);
110+
return;
111+
}
112+
pointer += 2048;
113+
114+
/* Enable ARP, ICMP, TCP, UDP */
115+
nx_arp_enable(&ip_0, pointer, 1024);
116+
pointer += 1024;
117+
nx_icmp_enable(&ip_0);
118+
nx_tcp_enable(&ip_0);
119+
nx_udp_enable(&ip_0);
120+
121+
/* Create DNS instance */
122+
status = nx_dns_create(&dns_0, &ip_0, (UCHAR*)"DNS Client");
123+
if (status != NX_SUCCESS) {
124+
printf("DNS create failed: %u\n", status);
125+
return;
126+
}
127+
dns_server.nxd_ip_version = NX_IP_VERSION_V4;
128+
dns_server.nxd_ip_address.v4 = DEMO_DNS_SERVER;
129+
nxd_dns_server_add(&dns_0, &dns_server);
130+
131+
/* Initialize MQTT context and network */
132+
mqtt_init_ctx(&mqttCtx);
133+
MqttClientNet_Init(&net, &mqttCtx);
134+
sockCtx = (SocketContext*)net.context;
135+
sockCtx->ipPtr = &ip_0;
136+
sockCtx->dnsPtr = &dns_0;
137+
138+
/* Use NetConnect to connect to the MQTT broker */
139+
rc = net.connect(sockCtx, DEMO_HOSTNAME, DEMO_PORT, DEMO_TIMEOUT_MS);
140+
if (rc == 0) {
141+
printf("NetConnect succeeded!\n");
142+
net.disconnect(sockCtx);
143+
} else {
144+
printf("NetConnect failed: %d\n", rc);
145+
}
146+
147+
/* Cleanup (not strictly necessary in a demo) */
148+
nx_dns_delete(&dns_0);
149+
nx_ip_delete(&ip_0);
150+
nx_packet_pool_delete(&pool_0);
151+
/* Thread exits */
152+
tx_thread_terminate(&demo_thread);
153+
}
154+
155+
/* Placeholder driver for demo purposes */
156+
void nx_driver_placeholder(NX_IP_DRIVER *driver_req)
157+
{
158+
NX_PARAMETER_NOT_USED(driver_req);
159+
}
160+
#endif /* HAVE_NETX */

0 commit comments

Comments
 (0)