1313#include <rtthread.h>
1414#include <rtdevice.h>
1515#include <board.h>
16-
16+ #ifdef BSP_USING_WLAN
17+ #include "gd32vw55x_platform.h"
18+ #include "wrapper_os.h"
19+ #include "wifi_management.h"
20+ #include "wifi_init.h"
21+ #include "user_setting.h"
22+ #include "util.h"
23+ #endif /* BSP_USING_WLAN */
1724/* LED1 ~ LED3 pin: PA4 PA5 PA6 */
1825#define LED1_PIN GET_PIN(A, 4)
1926
20- int main (void )
27+
28+ #ifdef RT_USING_WIFI
29+ #define START_TASK_STACK_SIZE 512
30+ #define START_TASK_PRIO 4
31+
32+ static void application_init (void )
2133{
22- rt_kprintf ("Hello GD32VW553H\n" );
23- /* set LED1 pin mode to output */
24- rt_pin_mode (LED1_PIN , PIN_MODE_OUTPUT );
34+ util_init ();
35+
36+ user_setting_init ();
37+
38+ if (wifi_init ()) {
39+ rt_kprintf ("wifi init failed\r\n" );
40+ } else {
41+ // rt_kprintf("wifi init success\r\n");
42+ }
43+ }
44+
45+ static rt_sem_t init_done_sem = RT_NULL ;
46+
47+ static void start_task (void * param )
48+ {
49+ (void )param ;
50+
51+ application_init ();
52+ // rt_kprintf("Start task completed, exiting.\n");
53+
54+ /* Note: In RT-Thread, task should exit by returning, not by calling sys_task_delete(NULL).
55+ * When the task function returns, RT-Thread will automatically clean up the task.
56+ */
57+
58+ rt_sem_release (init_done_sem );
59+ }
60+
61+ #endif /* RT_USING_WIFI */
62+
63+ /* LED blink thread */
64+ static void led_thread_entry (void * param )
65+ {
66+ (void )param ;
2567
2668 while (1 )
2769 {
@@ -30,6 +72,63 @@ int main(void)
3072 rt_pin_write (LED1_PIN , PIN_LOW );
3173 rt_thread_mdelay (500 );
3274 }
75+ }
76+
77+ int main (void )
78+ {
79+ rt_thread_t led_thread ;
80+
81+ rt_kprintf ("Hello GD32VW553H\n" );
82+ /* set LED1 pin mode to output */
83+ rt_pin_mode (LED1_PIN , PIN_MODE_OUTPUT );
84+
85+ #ifdef RT_USING_WIFI
86+ /* Create semaphore for synchronization */
87+ init_done_sem = rt_sem_create ("init_done" , 0 , RT_IPC_FLAG_PRIO );
88+ if (init_done_sem == RT_NULL ) {
89+ rt_kprintf ("Failed to create semaphore\n" );
90+ return - RT_ERROR ;
91+ }
92+
93+ if (sys_task_create_dynamic ((const uint8_t * )"start_task" ,
94+ START_TASK_STACK_SIZE , OS_TASK_PRIORITY (START_TASK_PRIO ), start_task , NULL ) == NULL ) {
95+ rt_kprintf ("Create start task failed\r\n" );
96+ return - RT_ERROR ;
97+ }
98+
99+ // rt_kprintf("Waiting for initialization to complete...\n");
100+ /* Wait for initialization task to complete */
101+ rt_sem_take (init_done_sem , RT_WAITING_FOREVER );
102+ // rt_kprintf("Initialization completed, continuing...\n");
103+
104+ /* Clean up semaphore */
105+ rt_sem_delete (init_done_sem );
106+ init_done_sem = RT_NULL ;
107+
108+ /* set wifi work mode */
109+ rt_wlan_set_mode (RT_WLAN_DEVICE_STA_NAME , RT_WLAN_STATION );
110+ rt_wlan_set_mode (RT_WLAN_DEVICE_AP_NAME , RT_WLAN_AP );
111+ #ifdef RT_USING_NETDEV
112+ rt_thread_mdelay (1000 );
113+ extern int wifi_netdev_register (void );
114+ wifi_netdev_register ();
115+ #endif /* RT_USING_NETDEV */
116+ #endif /* RT_USING_WIFI */
117+
118+ /* Create LED blink thread */
119+ led_thread = rt_thread_create ("led" ,
120+ led_thread_entry ,
121+ RT_NULL ,
122+ 1024 ,
123+ 25 , /* Lower priority to not block shell */
124+ 10 );
125+ if (led_thread != RT_NULL ) {
126+ rt_thread_startup (led_thread );
127+ rt_kprintf ("LED thread started\n" );
128+ } else {
129+ rt_kprintf ("Failed to create LED thread\n" );
130+ }
33131
132+ /* Return from main to allow shell to work properly */
34133 return RT_EOK ;
35134}
0 commit comments