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
191 lines
5.7 KiB
/**
|
|
****************************************************************************************************
|
|
* @file freertos_demo.c
|
|
* @author 正点原子团队(ALIENTEK)
|
|
* @version V1.0
|
|
* @date 2022-01-11
|
|
* @brief lwIP SOCKET UDP广播 实验
|
|
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
|
|
****************************************************************************************************
|
|
* @attention
|
|
*
|
|
* 实验平台:正点原子 探索者 F407开发板
|
|
* 在线视频:www.yuanzige.com
|
|
* 技术论坛:www.openedv.com
|
|
* 公司网址:www.alientek.com
|
|
* 购买地址:openedv.taobao.com
|
|
*
|
|
****************************************************************************************************
|
|
*/
|
|
|
|
#include "freertos_demo.h"
|
|
|
|
#include "./BSP/KEY/key.h"
|
|
#include "./BSP/LED/led.h"
|
|
#include "./SYSTEM/delay/delay.h"
|
|
#include "./SYSTEM/usart/usart.h"
|
|
#include "FreeRTOS.h"
|
|
#include "lwip_comm.h"
|
|
#include "lwip_demo.h"
|
|
#include "lwipopts.h"
|
|
#include "queue.h"
|
|
#include "stdio.h"
|
|
#include "string.h"
|
|
#include "task.h"
|
|
|
|
/******************************************************************************************************/
|
|
/*FreeRTOS配置*/
|
|
|
|
/* START_TASK 任务 配置
|
|
* 包括: 任务句柄 任务优先级 堆栈大小 创建任务
|
|
*/
|
|
#define START_TASK_PRIO 5 /* 任务优先级 */
|
|
#define START_STK_SIZE 128 /* 任务堆栈大小 */
|
|
TaskHandle_t StartTask_Handler; /* 任务句柄 */
|
|
void start_task(void* pvParameters); /* 任务函数 */
|
|
|
|
/* LWIP_DEMO 任务 配置
|
|
* 包括: 任务句柄 任务优先级 堆栈大小 创建任务
|
|
*/
|
|
#define LWIP_DMEO_TASK_PRIO 11 /* 任务优先级 */
|
|
#define LWIP_DMEO_STK_SIZE 1024 /* 任务堆栈大小 */
|
|
TaskHandle_t LWIP_Task_Handler; /* 任务句柄 */
|
|
void lwip_demo_task(void* pvParameters); /* 任务函数 */
|
|
|
|
/* LED_TASK 任务 配置
|
|
* 包括: 任务句柄 任务优先级 堆栈大小 创建任务
|
|
*/
|
|
#define LED_TASK_PRIO 10 /* 任务优先级 */
|
|
#define LED_STK_SIZE 128 /* 任务堆栈大小 */
|
|
TaskHandle_t LEDTask_Handler; /* 任务句柄 */
|
|
void led_task(void* pvParameters); /* 任务函数 */
|
|
|
|
/******************************************************************************************************/
|
|
|
|
/**
|
|
* @breif 加载UI
|
|
* @param mode : bit0:0,不加载;1,加载前半部分UI
|
|
* bit1:0,不加载;1,加载后半部分UI
|
|
* @retval 无
|
|
*/
|
|
void lwip_test_ui(void) {
|
|
uint8_t speed;
|
|
uint8_t buf[30];
|
|
|
|
printf("lwIP Init Successed\r\n");
|
|
|
|
if (g_lwipdev.dhcpstatus == 2) {
|
|
sprintf((char*)buf, "DHCP IP:%d.%d.%d.%d", g_lwipdev.ip[0], g_lwipdev.ip[1], g_lwipdev.ip[2],
|
|
g_lwipdev.ip[3]); /* 显示动态IP地址 */
|
|
} else {
|
|
sprintf((char*)buf, "Static IP:%d.%d.%d.%d", g_lwipdev.ip[0], g_lwipdev.ip[1], g_lwipdev.ip[2],
|
|
g_lwipdev.ip[3]); /* 打印静态IP地址 */
|
|
}
|
|
|
|
printf("%s\r\n", (char*)buf);
|
|
|
|
speed = ethernet_chip_get_speed(); /* 得到网速 */
|
|
|
|
if (speed) {
|
|
printf("Ethernet Speed:100M\r\n");
|
|
} else {
|
|
printf("Ethernet Speed:10M\r\n");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @breif freertos_demo
|
|
* @param 无
|
|
* @retval 无
|
|
*/
|
|
void freertos_demo(void) {
|
|
/* start_task任务 */
|
|
xTaskCreate((TaskFunction_t)start_task, //
|
|
(const char*)"start_task", //
|
|
(uint16_t)START_STK_SIZE, //
|
|
(void*)NULL, //
|
|
(UBaseType_t)START_TASK_PRIO, //
|
|
(TaskHandle_t*)&StartTask_Handler); //
|
|
|
|
vTaskStartScheduler(); /* 开启任务调度 */
|
|
}
|
|
|
|
/**
|
|
* @brief start_task
|
|
* @param pvParameters : 传入参数(未用到)
|
|
* @retval 无
|
|
*/
|
|
void start_task(void* pvParameters) {
|
|
pvParameters = pvParameters;
|
|
|
|
g_lwipdev.lwip_display_fn = lwip_test_ui;
|
|
|
|
while (lwip_comm_init() != 0) {
|
|
printf("lwIP Init failed!!\r\n");
|
|
delay_ms(500);
|
|
printf("Retrying... \r\n");
|
|
delay_ms(500);
|
|
LED1_TOGGLE();
|
|
}
|
|
|
|
while (!ethernet_read_phy(PHY_SR)) /* 检查MCU与PHY芯片是否通信成功 */
|
|
{
|
|
/* MCU与PHY芯片通信失败,请检查电路或者源码!!!! */
|
|
printf("MCU and PHY chip communication failed, please check the circuit or source code\r\n");
|
|
}
|
|
|
|
while ((g_lwipdev.dhcpstatus != 2) && (g_lwipdev.dhcpstatus != 0XFF)) /* 等待DHCP获取成功/超时溢出 */
|
|
{
|
|
vTaskDelay(5);
|
|
}
|
|
|
|
taskENTER_CRITICAL(); /* 进入临界区 */
|
|
|
|
/* 创建lwIP任务 */
|
|
xTaskCreate((TaskFunction_t)lwip_demo_task, //
|
|
(const char*)"lwip_demo_task", //
|
|
(uint16_t)LWIP_DMEO_STK_SIZE, //
|
|
(void*)NULL, //
|
|
(UBaseType_t)LWIP_DMEO_TASK_PRIO, //
|
|
(TaskHandle_t*)&LWIP_Task_Handler); //
|
|
|
|
/* LED测试任务 */
|
|
xTaskCreate((TaskFunction_t)led_task, //
|
|
(const char*)"led_task", //
|
|
(uint16_t)LED_STK_SIZE, //
|
|
(void*)NULL, //
|
|
(UBaseType_t)LED_TASK_PRIO, //
|
|
(TaskHandle_t*)&LEDTask_Handler); //
|
|
|
|
vTaskDelete(StartTask_Handler); /* 删除开始任务 */
|
|
taskEXIT_CRITICAL(); /* 退出临界区 */
|
|
}
|
|
|
|
/**
|
|
* @brief lwIP运行例程
|
|
* @param pvParameters : 传入参数(未用到)
|
|
* @retval 无
|
|
*/
|
|
void lwip_demo_task(void* pvParameters) {
|
|
pvParameters = pvParameters;
|
|
|
|
lwip_demo(); /* lwip测试代码 */
|
|
|
|
while (1) {
|
|
vTaskDelay(5);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief 系统再运行
|
|
* @param pvParameters : 传入参数(未用到)
|
|
* @retval 无
|
|
*/
|
|
void led_task(void* pvParameters) {
|
|
pvParameters = pvParameters;
|
|
|
|
while (1) {
|
|
LED1_TOGGLE();
|
|
vTaskDelay(100);
|
|
}
|
|
}
|