本帖最后由 muyichuan2012 于 2021-1-5 20:25 编辑
demo中包括led toggle和串口打印两个任务
/**
******************************************************************************
* File : GPIO/LED_Toggle/main.c
* Version: V1.2.8
* Date : 2020-11-27
* Brief : Main program body
******************************************************************************
*/
#include <stdio.h>
#include "at32f4xx.h"
#include "at32_board.h"
#include <includes.h>
uint32_t task_cnt[3];
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
static OS_TCB AppTaskStartTCB;
static CPU_STK AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE];
static OS_TCB AppTask1TCB;
static CPU_STK AppTask1Stk[APP_CFG_TASK_1_STK_SIZE];
static OS_TCB AppTask2TCB;
static CPU_STK AppTask2Stk[APP_CFG_TASK_2_STK_SIZE];
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/* ----------------- APPLICATION GLOBALS -------------- */
static OS_TCB AppTaskStartTCB;
static CPU_STK AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg);
static void AppTaskCreate (void);
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary initialization.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
int main(void)
{
OS_ERR err;
// BSP_IntDisAll(); /* Disable all interrupts. */
OSInit(&err); /* Init uC/OS-III. */
OSTaskCreate((OS_TCB *)&AppTaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR )AppTaskStart,
(void *)0u,
(OS_PRIO )APP_CFG_TASK_START_PRIO,
(CPU_STK *)&AppTaskStartStk[0u],
(CPU_STK_SIZE )AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE / 10u],
(CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
(OS_MSG_QTY )0u,
(OS_TICK )0u,
(void *)0u,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
(void)&err;
return (0u);
}
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
CPU_INT32U cpu_clk_freq;
CPU_INT32U cnts;
OS_ERR err;
(void)p_arg;
BSP_Init(); /* Initialize BSP functions */
AT32_LEDn_Init(LED2); //PC2
AT32_LEDn_Init(LED3); //PC3
UART_Print_Init(115200); //PA9
CPU_Init(); /* Initialize the uC/CPU services */
cpu_clk_freq = BSP_CPU_ClkFreq(); /* Determine SysTick reference freq. */
cnts = cpu_clk_freq /* Determine nbr SysTick increments */
/ (CPU_INT32U)OSCfg_TickRate_Hz;
OS_CPU_SysTickInit(cnts); /* Init uC/OS periodic time src (SysTick). */
// Mem_Init(); /* Initialize memory managment module */
// Math_Init(); /* Initialize mathematical module */
#if OS_CFG_STAT_TASK_EN > 0u
OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
#if (APP_CFG_SERIAL_EN == DEF_ENABLED)
App_SerialInit(); /* Initialize Serial communication for application ... */
#endif
AppTaskCreate ();
while (1)
{
task_cnt[0]++;
OSTimeDly(100, OS_OPT_TIME_DLY, &err);
}
}
static void AppTask1(void *p_arg)
{
OS_ERR err;
(void)p_arg;
while(1)
{
task_cnt[1]++;
AT32_LEDn_Toggle(LED2);
OSTimeDly(500, OS_OPT_TIME_DLY, &err);
}
}
static void AppTask2(void *p_arg)
{
OS_ERR err;
(void)p_arg;
while(1)
{
task_cnt[2]++;
AT32_LEDn_Toggle(LED3);
printf("task 2\r\n");
OSTimeDly(1000, OS_OPT_TIME_DLY, &err);
}
}
static void AppTaskCreate (void)
{
OS_ERR err;
/***********************************/
OSTaskCreate((OS_TCB *)&AppTask1TCB,
(CPU_CHAR *)"App Task 1",
(OS_TASK_PTR )AppTask1,
(void *)0,
(OS_PRIO )APP_CFG_TASK_1_PRIO,
(CPU_STK *)&AppTask1Stk[0],
(CPU_STK_SIZE )APP_CFG_TASK_1_STK_SIZE / 10,
(CPU_STK_SIZE )APP_CFG_TASK_1_STK_SIZE,
(OS_MSG_QTY )1,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
/***********************************/
OSTaskCreate((OS_TCB *)&AppTask2TCB,
(CPU_CHAR *)"App Task 2",
(OS_TASK_PTR )AppTask2,
(void *)0,
(OS_PRIO )APP_CFG_TASK_2_PRIO,
(CPU_STK *)&AppTask2Stk[0],
(CPU_STK_SIZE )APP_CFG_TASK_2_STK_SIZE / 10,
(CPU_STK_SIZE )APP_CFG_TASK_2_STK_SIZE,
(OS_MSG_QTY )2,
(OS_TICK )0,
(void *)0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
}
|
共1人点赞
|