AT32F425-测评报告-FreeRTOS_08
[复制链接]
本帖最后由 维尔瓦 于 2022-5-4 14:50 编辑
简述
本系列是基于雅特力-AT32F425R8T7-7开发板的测评报
例程位置:
例程功能分析:
从源码中可以看到,该例程主要创建了两个线程。
线程1: led2_task_function //让LED2翻转
线程2:led3_task_function //让LED3翻转
开启线程调度
我们在原有例程上稍加改动
在两个线程的执行函数中添加串口打印
NOTE: 注意例子中使用的是串口1
然后编译下载
插上USB-TTL连接到电脑
打开设备管理器,查看串口对应的端口
随便打开一个串口助手
可以看到板子发送上来的数据,而且板子上的LED也会闪烁,说明两个线程都在正常运行着。
那么我们可以照葫芦画瓢自己来写一个线程,感受FreeRTOS的线程创建过程
## 1. 申明线程句柄变量和线程处理函数
## 2. 初始化LED4
## 3. 创建线程
## 4. 定义线程函数实体
## 5. 观察现象
通过串口助手可以看到线程4成功创建且线程函数也在正常运行,板子上的LED4也跟着闪烁
最后贴上我的测试代码
/**
**************************************************************************
* [url=home.php?mod=space&uid=1307177]@File[/url] main.c
* [url=home.php?mod=space&uid=252314]@version[/url] v2.0.1
* [url=home.php?mod=space&uid=311857]@date[/url] 2022-02-11
* [url=home.php?mod=space&uid=159083]@brief[/url] main program
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
#include "at32f425_board.h"
#include "at32f425_clock.h"
#include "FreeRTOS.h"
#include "task.h"
/** @addtogroup UTILITIES_examples
* @{
*/
/** @addtogroup FreeRTOS_demo
* @{
*/
TaskHandle_t led2_handler;
TaskHandle_t led3_handler;
TaskHandle_t led4_handler;
/* led2 task */
void led2_task_function(void *pvParameters);
/* led3 task */
void led3_task_function(void *pvParameters);
/* led3 task */
void led4_task_function_ourself(void *pvParameters);
/**
* @brief main function.
* @param none
* @retval none
*/
int main(void)
{
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
system_clock_config();
/* init led2 and led3 */
at32_led_init(LED2);
at32_led_init(LED3);
at32_led_init(LED4);
/* init usart1 */
uart_print_init(115200);
/* enter critical */
taskENTER_CRITICAL();
/* create led2 task */
if(xTaskCreate((TaskFunction_t )led2_task_function,
(const char* )"LED2_task",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )2,
(TaskHandle_t* )&led2_handler) != pdPASS)
{
printf("LED2 task could not be created as there was insufficient heap memory remaining.\r\n");
}
else
{
printf("LED2 task was created successfully.\r\n");
}
/* create led3 task */
if(xTaskCreate((TaskFunction_t )led3_task_function,
(const char* )"LED3_task",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )2,
(TaskHandle_t* )&led3_handler) != pdPASS)
{
printf("LED3 task could not be created as there was insufficient heap memory remaining.\r\n");
}
else
{
printf("LED3 task was created successfully.\r\n");
}
/* create led4 task */
if(xTaskCreate((TaskFunction_t )led4_task_function_ourself,
(const char* )"LED4_task_ourself",
(uint16_t )512,
(void* )NULL,
(UBaseType_t )3,
(TaskHandle_t* )&led4_handler) != pdPASS)
{
printf("LED4 task could not be created as there was insufficient heap memory remaining.\r\n");
}
else
{
printf("LED4 task was created successfully.\r\n");
}
/* exit critical */
taskEXIT_CRITICAL();
/* start scheduler */
vTaskStartScheduler();
}
/* led2 task function */
void led2_task_function(void *pvParameters)
{
while(1)
{
at32_led_toggle(LED2);
printf("at32_led_toggle(LED2)\n");
vTaskDelay(1000);
}
}
/* led3 task function */
void led3_task_function(void *pvParameters)
{
while(1)
{
at32_led_toggle(LED3);
printf("at32_led_toggle(LED3)\n");
vTaskDelay(500);
}
}
/* led4 task function */
void led4_task_function_ourself(void *pvParameters)
{
while(1)
{
at32_led_toggle(LED4);
printf("at32_led_toggle(LED4)\n");
vTaskDelay(500);
}
}
/**
* @}
*/
/**
* @}
*/
|