⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 ucos_ii 在microblaze平台上的移植
💻 C
字号:
/***********************************************************************************************************                                                uC/OS-II*                                          The Real-Time Kernel**                            (c) Copyright 1992-2003, Micrium, Inc., Weston, FL*                                           All Rights Reserved**                                               EXAMPLE #1*** Description:  Shows an example of how to use uCOS-II with the Xilinx MicroBlaze processor.  The example*               assumes the existence of the following devices in the FPGA:**               - MicroBlaze processor*               - Interrupt controller*               - Timer/Counter*               - UartLite**               The Timer/Counter device is set up to interrupt (rollover) at a rate of OS_TICKS_PER_SEC, *               and we use this as the OS timer tick.**********************************************************************************************************/#include <includes.h>/***********************************************************************************************************                                             CONSTANTS**********************************************************************************************************/#define  APP_TASK_START_ID               0 #define  APP_TASK_START_PRIO             0#define  APP_TASK_START_STK_SIZE       256#define  APP_TASK_CLK_ID                 1#define  APP_TASK_CLK_PRIO               1#define  APP_TASK_CLK_STK_SIZE         256/***********************************************************************************************************                                           GLOBAL VARIABLES**********************************************************************************************************/static  OS_STK   AppTaskStartStk[APP_TASK_START_STK_SIZE];  /* Start task stack                        */static  OS_STK   AppTaskClkStk[APP_TASK_CLK_STK_SIZE];      /* Clock task stack                        */

/***********************************************************************************************************                                             PROTOTYPES**********************************************************************************************************/static  void     AppTaskStart(void *p_arg);static  void     AppTaskCreate(void);static  void     AppInitIO(void);static  void     AppTaskClk(void *p_arg);/***********************************************************************************************************                                              main()* * Description: This is the 'standard' C startup entry point.  main(0 does the following:**              1) Outputs a 'sign on' message on the serial port*              2) Initialize uC/OS-II*              3) Create a single task which will create the other application tasks.*              4) Start uC/OS-II** Arguments  : None** Returns    : main() should NEVER return** Note(s)    : 1) It is assumed that interrupts are DISABLED when main() is called.  Interrupts will*                 be enabled by the first task that uC/OS-II starts.**********************************************************************************************************/int  main (void){    INT8U    err;    BSP_IntDisAll();                         /* Make sure interrupts are disabled on interrupt controller */

    OSInit();                                /* Initialize uC/OS-II                                       */    OSTaskCreateExt(AppTaskStart,                   (void *)0,                   &AppTaskStartStk[APP_TASK_START_STK_SIZE - 1],                   APP_TASK_START_PRIO,                   APP_TASK_START_ID,                   &AppTaskStartStk[0],                   APP_TASK_START_STK_SIZE,                   (void *)0,                   OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);    OSTaskNameSet(APP_TASK_START_PRIO, "App Start Task", &err);    OSTaskNameSet(OS_IDLE_PRIO, "uC/OS-II Idle Task", &err);    OSTaskNameSet(OS_STAT_PRIO, "uC/OS-II Stat Task", &err);    print("####################################################\n\r");    print("#                      Micrium                     #\n\r");    print("#          uC/OS-II, The Real-Time Kernel          #\n\r");    print("#                                                  #\n\r");    print("#                 Xilinx MicroBlaze                #\n\r");    print("####################################################\n\r");    print("\n\r");    print("\n\r");            OSStart();                               /* Start multitasking                                        */}/*$PAGE*//***********************************************************************************************************                                             AppTaskStart()* * Description: This is the first task executed by uC/OS-II following OSStart() because it has the highest *              priority of all tasks created.*              * Arguments  : p_arg        Argument passed to this task when task is created.  The argument is not used.** Returns    : None**********************************************************************************************************/static  void  AppTaskStart (void *p_arg){
    INT8U  i;

	INT32U a;
	INT32U b;
	INT32U c;
	INT32U d;
	INT32U e;
	INT32U f;
	INT32U g;
	INT32U h;
	INT32U j;
	INT32U k;
	INT32U l;

    a = 0;
	b = 1;
	c = 2;
	d = 3;
	e = 4;
	f = 5;
	g = 6;
	h = 7;
	j = 8;
	k = 9;
	l = 10;
	
	a = b + c + d + e + f + g + h + j + k + l; 
    p_arg = p_arg;                        /* Prevent compiler warning by doing something with argument */
    BSP_InitIO();                         /* Initialize the I/Os (MUST be done before other tasks      */
#if OS_TASK_STAT_EN > 0    OSStatInit();                         /* Initialize uC/OS-II's statistics                          */#endif    AppTaskCreate();                      /* Create the other application tasks                        */
	while (1) {
        for (i = 0; i < 6; i++) {         /* Display spinning wheel on LED digit #2                    */
            Disp_Icon(i, TRUE);            OSTimeDly(5);            Disp_Icon(i, FALSE);
        }
    }}/*$PAGE*//***********************************************************************************************************                                              TaskClk()* * Description: A simple task that continually sends characters out to the UART once a second.*              * Arguments  : p_arg     Argument passed to task when task is created.  Unused.** Returns    : None**********************************************************************************************************/void  AppTaskClk (void *p_arg){    INT8U  ctr;
#if OS_TASK_STAT_EN > 0    char   s[81];
#endif            p_arg = p_arg;    ctr   = 0;
#if OS_TASK_STAT_EN > 0    OS_StrCopy(s, "    CPU Usage:   %\n\r");
#endif    while (1) {#if OS_TASK_STAT_EN > 0
        s[0]  = ctr + '0';        s[15] = OSCPUUsage / 10 + '0';            /* Send the current CPU usage on the serial port     */
        s[16] = OSCPUUsage % 10 + '0';
        print(s);
		if (ctr == 9) {
            print("\n\r");
		}
#endif        Disp_7SegVal(2, ctr);                     /* Display counter value 0..9 on LED digit #2        */        if (ctr == 9) {            ctr = 0;        } else {            ctr++;        }
        OSTimeDly(OS_TICKS_PER_SEC);              /* Delay for 1 second                                */    }}/*$PAGE*//***********************************************************************************************************                                             AppTaskCreate()* * Description: This function creates all the other tasks in your application.  In this case, we only *              created ONE additional task.*              * Arguments  : None** Returns    : None**********************************************************************************************************/static  void  AppTaskCreate (void){
    INT8U  err;

    OSTaskCreateExt(AppTaskClk,                   (void *)0,                   &AppTaskClkStk[APP_TASK_CLK_STK_SIZE - 1],                   APP_TASK_CLK_PRIO,                   APP_TASK_CLK_ID,                   &AppTaskClkStk[0],                   APP_TASK_CLK_STK_SIZE,                   (void *)0,                   OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);    OSTaskNameSet(APP_TASK_CLK_PRIO, "Clock Task", &err);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -