打印
[RTOS]

AT32F413/AT32F415移植到ucosIII

[复制链接]
1348|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
muyichuan2012|  楼主 | 2021-1-5 19:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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);
        
}


415_uCOSIII.rar

1.2 MB

413_uCOSIII.rar

1.2 MB

使用特权

评论回复
沙发
单片小菜| | 2021-1-8 10:13 | 只看该作者
感谢楼主的分享,不错的**,收藏叻

使用特权

评论回复
板凳
水牛_kiss| | 2021-5-12 14:09 | 只看该作者
谢谢楼主分享,收藏!

使用特权

评论回复
地板
szhyk| | 2022-11-8 14:27 | 只看该作者
感谢楼主分享!

使用特权

评论回复
5
mollylawrence| | 2022-12-3 12:04 | 只看该作者
ucosIII不如Rt-thread火了。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

150

主题

1741

帖子

24

粉丝