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.

191 lines
5.7 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
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(void) {
  64. uint8_t speed;
  65. uint8_t buf[30];
  66. printf("lwIP Init Successed\r\n");
  67. if (g_lwipdev.dhcpstatus == 2) {
  68. sprintf((char*)buf, "DHCP IP:%d.%d.%d.%d", g_lwipdev.ip[0], g_lwipdev.ip[1], g_lwipdev.ip[2],
  69. g_lwipdev.ip[3]); /* 显示动态IP地址 */
  70. } else {
  71. sprintf((char*)buf, "Static IP:%d.%d.%d.%d", g_lwipdev.ip[0], g_lwipdev.ip[1], g_lwipdev.ip[2],
  72. g_lwipdev.ip[3]); /* 打印静态IP地址 */
  73. }
  74. printf("%s\r\n", (char*)buf);
  75. speed = ethernet_chip_get_speed(); /* 得到网速 */
  76. if (speed) {
  77. printf("Ethernet Speed:100M\r\n");
  78. } else {
  79. printf("Ethernet Speed:10M\r\n");
  80. }
  81. }
  82. /**
  83. * @breif freertos_demo
  84. * @param
  85. * @retval
  86. */
  87. void freertos_demo(void) {
  88. /* start_task任务 */
  89. xTaskCreate((TaskFunction_t)start_task, //
  90. (const char*)"start_task", //
  91. (uint16_t)START_STK_SIZE, //
  92. (void*)NULL, //
  93. (UBaseType_t)START_TASK_PRIO, //
  94. (TaskHandle_t*)&StartTask_Handler); //
  95. vTaskStartScheduler(); /* 开启任务调度 */
  96. }
  97. /**
  98. * @brief start_task
  99. * @param pvParameters : ()
  100. * @retval
  101. */
  102. void start_task(void* pvParameters) {
  103. pvParameters = pvParameters;
  104. g_lwipdev.lwip_display_fn = lwip_test_ui;
  105. while (lwip_comm_init() != 0) {
  106. printf("lwIP Init failed!!\r\n");
  107. delay_ms(500);
  108. printf("Retrying... \r\n");
  109. delay_ms(500);
  110. LED1_TOGGLE();
  111. }
  112. while (!ethernet_read_phy(PHY_SR)) /* 检查MCU与PHY芯片是否通信成功 */
  113. {
  114. /* MCU与PHY芯片通信失败,请检查电路或者源码!!!! */
  115. printf("MCU and PHY chip communication failed, please check the circuit or source code\r\n");
  116. }
  117. while ((g_lwipdev.dhcpstatus != 2) && (g_lwipdev.dhcpstatus != 0XFF)) /* 等待DHCP获取成功/超时溢出 */
  118. {
  119. vTaskDelay(5);
  120. }
  121. taskENTER_CRITICAL(); /* 进入临界区 */
  122. /* 创建lwIP任务 */
  123. xTaskCreate((TaskFunction_t)lwip_demo_task, //
  124. (const char*)"lwip_demo_task", //
  125. (uint16_t)LWIP_DMEO_STK_SIZE, //
  126. (void*)NULL, //
  127. (UBaseType_t)LWIP_DMEO_TASK_PRIO, //
  128. (TaskHandle_t*)&LWIP_Task_Handler); //
  129. /* LED测试任务 */
  130. xTaskCreate((TaskFunction_t)led_task, //
  131. (const char*)"led_task", //
  132. (uint16_t)LED_STK_SIZE, //
  133. (void*)NULL, //
  134. (UBaseType_t)LED_TASK_PRIO, //
  135. (TaskHandle_t*)&LEDTask_Handler); //
  136. vTaskDelete(StartTask_Handler); /* 删除开始任务 */
  137. taskEXIT_CRITICAL(); /* 退出临界区 */
  138. }
  139. /**
  140. * @brief lwIP运行例程
  141. * @param pvParameters : ()
  142. * @retval
  143. */
  144. void lwip_demo_task(void* pvParameters) {
  145. pvParameters = pvParameters;
  146. lwip_demo(); /* lwip测试代码 */
  147. while (1) {
  148. vTaskDelay(5);
  149. }
  150. }
  151. /**
  152. * @brief
  153. * @param pvParameters : ()
  154. * @retval
  155. */
  156. void led_task(void* pvParameters) {
  157. pvParameters = pvParameters;
  158. while (1) {
  159. LED1_TOGGLE();
  160. vTaskDelay(100);
  161. }
  162. }