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

📄 app.c

📁 ucosII 修改移植到 freescale MCF51JM128
💻 C
字号:
/*
*********************************************************************************************************
*                                               uC/OS-II
*                                         The Real-Time Kernel
*
*                                           Sample code
*
* File : app.c
* By   : Eric Shufro
*********************************************************************************************************
*/

#include <includes.h>

/*
*********************************************************************************************************
*                                            CONSTANTS
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            PROTOTYPES
*********************************************************************************************************
*/

static  void  AppStartTask(void *p_arg);
static  void  AccelerometerTask(void *p_arg);
static  void  AppTaskCreate(void);

#if (uC_PROBE_OS_PLUGIN > 0) || (uC_PROBE_COM_MODULE > 0)
extern  void  AppProbeInit(void);
#endif

/*
*********************************************************************************************************
*                                            VARIABLES
*********************************************************************************************************
*/

OS_STK      AppStartTaskStk[APP_TASK_START_STK_SIZE];    
OS_STK      AccelerometerTaskStk[ACCELEROMETER_TASK_STK_SIZE];  

CPU_INT16U  Ax;                                                         /* Define globals for storing the accelerometer data.       */
CPU_INT16U  Ay;                                                         /* Globals are used since they are visable to uC/Probe.     */
CPU_INT16U  Az;

/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the 'C' code entry point for the uC/OS-II based application
*
* Arguments   : None
*
* Returns     : None.
*
* Callers     : _Startup. See Start08.c
*
* Notes       : 1) This function never returns
*********************************************************************************************************
*/
    extern void LED_Init(void);
void  main (void)
{
    CPU_INT08U  err;


    OSInit();                                                           /* Initialize "uC/OS-II, The Real-Time Kernel"              */

    OSTaskCreateExt(AppStartTask,                                       /* At least 1 task must be created before calling OSStart() */
                    (void *)0, 
                    (OS_STK *)&AppStartTaskStk[APP_TASK_START_STK_SIZE - 1], 
                     APP_TASK_START_PRIO, 
                     APP_TASK_START_PRIO,
                    (OS_STK *)&AppStartTaskStk[0],
                     APP_TASK_START_STK_SIZE,
                    (void *)0,
                     OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 15
    OSTaskNameSet(APP_TASK_START_PRIO, (unsigned char *)"Startup Task", &err);
#endif

    OSStart();                                                          /* Start multitasking (i.e. give control to uC/OS-II)       */
}                                                                       /* This function call never returns                         */

/*
*********************************************************************************************************
*                                            STARTUP TASK
*
* Description : This is an example of a uC/OS-II startup task. 
*
* Arguments   : p_arg   is the argument passed to 'AppStartTask()' by 'OSTaskCreateExt()'.
*
* 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.
*               2) Interrupts are enabled once the task start because the I-bit of the CCR register was
*                  set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/

static  void  AppStartTask (void *p_arg)
{
    CPU_INT08U  i;
    CPU_INT08U  j;
    
       
   (void)p_arg;

    BSP_Init();                                                         /* Initialize the BSP such as the OS Ticker and PLL         */

#if OS_TASK_STAT_EN > 0
    OSStatInit();                                                       /* Start stats task                                         */
#endif

#if (uC_PROBE_OS_PLUGIN > 0) || (uC_PROBE_COM_MODULE > 0)
    AppProbeInit();                                                     /* Initialize uC/Probe modules                              */
#endif

    AppTaskCreate();                                                    /* Create additional applicaiton tasks                      */           
                                                                            
    LED_Off(0);                                                         /* Ensure all LEDs are off                                  */
           
    while (DEF_TRUE) {                                                  /* Task body, always written as an infinite loop            */
        for (j = 0; j < 4; j++) {                                       /* Demo task utilizing only the first 4 LEDs                */
            for (i = 1; i <= 4; i++) {
                LED_On(i);
                OSTimeDlyHMSM(0, 0, 0, 25);
                LED_Off(i);
                OSTimeDlyHMSM(0, 0, 0, 25);
            }

            for (i = 3; i >= 2; i--) {
                LED_On(i);
                OSTimeDlyHMSM(0, 0, 0, 25);
                LED_Off(i);
                OSTimeDlyHMSM(0, 0, 0, 25);
            }
        }

        for (i = 0; i < 4; i++) {
            LED_On(1);
            LED_On(2);
            LED_On(3);
            LED_On(4);
            OSTimeDlyHMSM(0, 0, 0, 50);
            LED_Off(1);
            LED_Off(2);
            LED_Off(3);
            LED_Off(4);                        
            OSTimeDlyHMSM(0, 0, 0, 50);
        }
        

    }
}
 
/*
*********************************************************************************************************
*                                            ACCELEROMETER TASK
*
* Description : This task handles data from the analog output accelerometer
*
* Arguments   : p_arg   is the argument passed to 'AppStartTask()' by 'OSTaskCreateExt()'.
*
* 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.
*               2) Axis data is stored in global variables to in order to make it accessible
*                  by uC/Probe.
*********************************************************************************************************
*/

static  void  AccelerometerTask (void *p_arg)
{
   (void)p_arg;
   
    Accelerometer_Init();                                               /* Initialize the ADC port                                  */
    
    while (DEF_TRUE) {
        Ax  =   Accelerometer_Rd(ATC_RD_X);                             /* Read the 3 ADC channel values. This function call blocks */    
        Ay  =   Accelerometer_Rd(ATC_RD_Y);                             /* until the conversion is completed                        */              
        Az  =   Accelerometer_Rd(ATC_RD_Z);                
        OSTimeDlyHMSM(0, 0, 0, 10);                                     /* Delay the task for a short while                         */     
    }   
}
 
/*
*********************************************************************************************************
*                              CREATE ADDITIONAL APPLICATION TASKS
*********************************************************************************************************
*/

static  void  AppTaskCreate (void)
{
    CPU_INT08U  err;
    
    
    OSTaskCreateExt(AccelerometerTask,                                  /* Create a task for handling accelerometer data            */
                    (void *)0, 
                    (OS_STK *)&AccelerometerTaskStk[ACCELEROMETER_TASK_STK_SIZE - 1], 
                     ACCELEROMETER_TASK_PRIO, 
                     ACCELEROMETER_TASK_PRIO,
                    (OS_STK *)&AccelerometerTaskStk[0],
                     ACCELEROMETER_TASK_STK_SIZE,
                    (void *)0,
                     OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 20
    OSTaskNameSet(ACCELEROMETER_TASK_PRIO, (unsigned char *)"Accelerometer Task", &err);
#endif
}


⌨️ 快捷键说明

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