You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
6.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. /**
  2. ****************************************************************************************************
  3. * @file freertos_demo.c
  4. * @author (ALIENTEK)
  5. * @version V1.0
  6. * @date 2022-01-11
  7. * @brief lwIP SOCKET UDP广播
  8. * @license Copyright (c) 2020-2032, 广
  9. ****************************************************************************************************
  10. * @attention
  11. *
  12. * : F407开发板
  13. * 线:www.yuanzige.com
  14. * :www.openedv.com
  15. * :www.alientek.com
  16. * :openedv.taobao.com
  17. *
  18. ****************************************************************************************************
  19. */
  20. #include "freertos_demo.h"
  21. #include "./BSP/KEY/key.h"
  22. #include "./BSP/LED/led.h"
  23. #include "./SYSTEM/delay/delay.h"
  24. #include "./SYSTEM/usart/usart.h"
  25. #include "FreeRTOS.h"
  26. #include "lwip_comm.h"
  27. #include "lwip_demo.h"
  28. #include "lwipopts.h"
  29. #include "queue.h"
  30. #include "stdio.h"
  31. #include "string.h"
  32. #include "task.h"
  33. /******************************************************************************************************/
  34. /*FreeRTOS配置*/
  35. /* START_TASK 任务 配置
  36. * :
  37. */
  38. #define START_TASK_PRIO 5 /* 任务优先级 */
  39. #define START_STK_SIZE 128 /* 任务堆栈大小 */
  40. TaskHandle_t StartTask_Handler; /* 任务句柄 */
  41. void start_task(void* pvParameters); /* 任务函数 */
  42. /* LWIP_DEMO 任务 配置
  43. * :
  44. */
  45. #define LWIP_DMEO_TASK_PRIO 11 /* 任务优先级 */
  46. #define LWIP_DMEO_STK_SIZE 1024 /* 任务堆栈大小 */
  47. TaskHandle_t LWIP_Task_Handler; /* 任务句柄 */
  48. void lwip_demo_task(void* pvParameters); /* 任务函数 */
  49. /* LED_TASK 任务 配置
  50. * :
  51. */
  52. #define LED_TASK_PRIO 10 /* 任务优先级 */
  53. #define LED_STK_SIZE 128 /* 任务堆栈大小 */
  54. TaskHandle_t LEDTask_Handler; /* 任务句柄 */
  55. void led_task(void* pvParameters); /* 任务函数 */
  56. /******************************************************************************************************/
  57. /**
  58. * @breif UI
  59. * @param mode : bit0:0,;1,UI
  60. * bit1:0,;1,UI
  61. * @retval
  62. */
  63. void lwip_test_ui(uint8_t mode) {
  64. uint8_t speed;
  65. uint8_t buf[30];
  66. if (mode & 1 << 0) {
  67. printf("STM32\r\n");
  68. printf("lwIP UDPBroadcastTest\r\n");
  69. printf("ATOM@ALIENTEK\r\n");
  70. }
  71. if (mode & 1 << 1) {
  72. // lcd_fill(5, 110, lcddev.width,lcddev.height, WHITE);
  73. printf("lwIP Init Successed\r\n");
  74. if (g_lwipdev.dhcpstatus == 2) {
  75. sprintf((char*)buf, "DHCP IP:%d.%d.%d.%d", g_lwipdev.ip[0], g_lwipdev.ip[1], g_lwipdev.ip[2],
  76. g_lwipdev.ip[3]); /* 显示动态IP地址 */
  77. } else {
  78. sprintf((char*)buf, "Static IP:%d.%d.%d.%d", g_lwipdev.ip[0], g_lwipdev.ip[1], g_lwipdev.ip[2],
  79. g_lwipdev.ip[3]); /* 打印静态IP地址 */
  80. }
  81. printf("%s\r\n", (char*)buf);
  82. speed = ethernet_chip_get_speed(); /* 得到网速 */
  83. if (speed) {
  84. printf("Ethernet Speed:100M\r\n");
  85. } else {
  86. printf("Ethernet Speed:10M\r\n");
  87. }
  88. }
  89. }
  90. /**
  91. * @breif freertos_demo
  92. * @param
  93. * @retval
  94. */
  95. void freertos_demo(void) {
  96. /* start_task任务 */
  97. xTaskCreate((TaskFunction_t)start_task, //
  98. (const char*)"start_task", //
  99. (uint16_t)START_STK_SIZE, //
  100. (void*)NULL, //
  101. (UBaseType_t)START_TASK_PRIO, //
  102. (TaskHandle_t*)&StartTask_Handler); //
  103. vTaskStartScheduler(); /* 开启任务调度 */
  104. }
  105. /**
  106. * @brief start_task
  107. * @param pvParameters : ()
  108. * @retval
  109. */
  110. void start_task(void* pvParameters) {
  111. pvParameters = pvParameters;
  112. g_lwipdev.lwip_display_fn = lwip_test_ui;
  113. lwip_test_ui(1); /* 加载后前部分UI */
  114. while (lwip_comm_init() != 0) {
  115. printf("lwIP Init failed!!\r\n");
  116. delay_ms(500);
  117. printf("Retrying... \r\n");
  118. delay_ms(500);
  119. LED1_TOGGLE();
  120. }
  121. while (!ethernet_read_phy(PHY_SR)) /* 检查MCU与PHY芯片是否通信成功 */
  122. {
  123. /* MCU与PHY芯片通信失败,请检查电路或者源码!!!! */
  124. printf("MCU and PHY chip communication failed, please check the circuit or source code\r\n");
  125. }
  126. while ((g_lwipdev.dhcpstatus != 2) && (g_lwipdev.dhcpstatus != 0XFF)) /* 等待DHCP获取成功/超时溢出 */
  127. {
  128. vTaskDelay(5);
  129. }
  130. taskENTER_CRITICAL(); /* 进入临界区 */
  131. /* 创建lwIP任务 */
  132. xTaskCreate((TaskFunction_t)lwip_demo_task, //
  133. (const char*)"lwip_demo_task", //
  134. (uint16_t)LWIP_DMEO_STK_SIZE, //
  135. (void*)NULL, //
  136. (UBaseType_t)LWIP_DMEO_TASK_PRIO, //
  137. (TaskHandle_t*)&LWIP_Task_Handler); //
  138. /* LED测试任务 */
  139. xTaskCreate((TaskFunction_t)led_task, //
  140. (const char*)"led_task", //
  141. (uint16_t)LED_STK_SIZE, //
  142. (void*)NULL, //
  143. (UBaseType_t)LED_TASK_PRIO, //
  144. (TaskHandle_t*)&LEDTask_Handler); //
  145. vTaskDelete(StartTask_Handler); /* 删除开始任务 */
  146. taskEXIT_CRITICAL(); /* 退出临界区 */
  147. }
  148. /**
  149. * @brief lwIP运行例程
  150. * @param pvParameters : ()
  151. * @retval
  152. */
  153. void lwip_demo_task(void* pvParameters) {
  154. pvParameters = pvParameters;
  155. lwip_demo(); /* lwip测试代码 */
  156. while (1) {
  157. vTaskDelay(5);
  158. }
  159. }
  160. /**
  161. * @brief
  162. * @param pvParameters : ()
  163. * @retval
  164. */
  165. void led_task(void* pvParameters) {
  166. pvParameters = pvParameters;
  167. while (1) {
  168. LED1_TOGGLE();
  169. vTaskDelay(100);
  170. }
  171. }