AT32F407+freertos+lwip example
/**
******************************************************************************
* File : ETH/Telent/main.c
* Version: V1.1.9
* Date : 2020-05-29
* Brief : ethernet function test.
******************************************************************************
*/
/* Includes -----------------------------------------------------------------*/
#include "at32_board.h"
#include "main.h"
#include "eth_config.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "arch/sys_arch.h"
#include "api.h"
#include "apps/httpd.h"
/** @addtogroup AT32F407_StdPeriph_Examples
* @{
*/
/** @addtogroup ETH_Telnet
* @{
*/
/* Gloable variables ---------------------------------------------------------*/
__IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
uint32_t timingdelay;
/* task1 priority */
#define Task1_PRIO 3
/* task1 stack size*/
#define Task1_STK_SIZE 256
/* task1 handler */
TaskHandle_t Task1_Handler;
/* task1 function */
void task1(void *pvParameters);
/* task2 Priority */
#define Task2_PRIO 3
/* task2 stack size*/
#define Task2_STK_SIZE 256
/* task2 handler */
TaskHandle_t Task2_Handler;
/* task2 function */
void task2(void *pvParameters);
#if LWIP_DHCP
/* task3 Priority */
#define Task3_PRIO 4
/* task3 stack size*/
#define Task3_STK_SIZE 256
/* task3 handler */
TaskHandle_t Task3_Handler;
/* task3 function */
void task3(void *pvParameters);
#endif
/* Gloable functions ---------------------------------------------------------*/
/**
* @brief Main Function.
* @param None
* @retval None
*/
int main(void)
{
/* --------BSP Init ------------------------------------------------*/
AT32_Board_Init();
UART_Print_Init(115200);
/* Setup AT32 system (clocks, Ethernet, GPIO, NVIC)*/
/* 进入临界区保护 */
taskENTER_CRITICAL();
/* Initilaize LwIP satck, IP configuration and MAC configuration*/
/* 创建task1 */
xTaskCreate((TaskFunction_t )task1,
(const char* )"task1",
(uint16_t )Task1_STK_SIZE,
(void* )NULL,
(UBaseType_t )Task1_PRIO,
(TaskHandle_t* )&Task1_Handler);
/* 创建task2 */
xTaskCreate((TaskFunction_t )task2,
(const char* )"task2",
(uint16_t )Task2_STK_SIZE,
(void* )NULL,
(UBaseType_t )Task2_PRIO,
(TaskHandle_t* )&Task2_Handler);
#if LWIP_DHCP
xTaskCreate((TaskFunction_t )task3,
(const char* )"task3",
(uint16_t )Task3_STK_SIZE,
(void* )NULL,
(UBaseType_t )Task3_PRIO,
(TaskHandle_t* )&Task3_Handler);
#endif
/* 退出临界区保护 */
taskEXIT_CRITICAL();
/* 开启任务调度器 */
vTaskStartScheduler();
while(1);
}
/* task1 */
void task1(void *pvParameters)
{
if(System_Setup() == ETH_DRIVER_FAIL) {
while(1);
}
LwIP_Init();
httpd_init();
while(1)
{
printf("This is task1!\r\n");
vTaskDelay(500);
#if LWIP_DHCP
/* Necessary */
dhcp_fine_tmr();
printf("0x%08x\n\r", netif.ip_addr.addr);
#endif
}
}
/* task2???? */
void task2(void *pvParameters)
{
while(1)
{
printf("This is task2!\r\n");
vTaskDelay(1100);
}
}
#if LWIP_DHCP
void task3(void *pvParameters)
{
int i;
while(1)
{
printf("This is task3!\r\n");
/* Necessary */
for(i=0;j<60;i++)
vTaskDelay(1000);
dhcp_coarse_tmr();
printf("dhcp_coarse_tmr() call!\r\n");
vTaskDelay(1000);
}
}
#endif
/**
* @brief Inserts a delay time.
* @param nCount: number of 10ms periods to wait for.
* @retval None
*/
void Delay(uint32_t nCount)
{
/* Capture the current local time */
timingdelay = LocalTime + nCount;
/* wait until the desired delay finish */
while(timingdelay > LocalTime)
{
}
}
/**
* @brief Updates the system local time
* @param None
* @retval None
*/
void Time_Update(void)
{
LocalTime += SYSTEMTICK_PERIOD_MS;
}
/**
* @brief Handles the periodic tasks of the system
* @param None
* @retval None
*/
void System_Periodic_Handle(void)
{
/* LwIP periodic services are done here */
LwIP_Periodic_Handle(LocalTime);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{}
}
#endif
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2019 ArteryTek *****END OF FILE****/
|