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

📄 app.c

📁 在IAR EWARM开发环境下的ucos_2操作系统在LPC2200上的应用
💻 C
字号:
/*
*********************************************************************************************************
*                                              EXAMPLE CODE
*
*                          (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               Knowledge of the source code may NOT be used to develop a similar product.
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                             EXAMPLE CODE
*
*                                              NXP LPC2103
*                                                on the
*                                     IAR LPC2103-01-SK Evaluation Board
*
* Filename      : app.c
* Version       : V1.00
* Programmer(s) : FT
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/

#include <includes.h>

/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/

                                                                /* ----------------- APPLICATION GLOBALS ------------------ */
static  OS_STK       App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE];

#define  TASK_STK_SIZE                  200      /* Size of each task's stacks (# of WORDs)            */

OS_STK Task1Stk[TASK_STK_SIZE];

char *msgbuf1="\rBlock1 allocated.\n";
char *msgbuf2="\rBlock2 allocated.\n";

OS_MEM *PartitionPtr;
INT8U Partition[4][32];
OS_MEM_DATA MemInfo;

void Task1(void *pdata);

/*
*********************************************************************************************************
*                                         LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

static  void  App_TaskStart               (void        *p_arg);

/*
*********************************************************************************************************
*                                                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.
*
* Argument(s) : none
*
* Return(s)   : none
*********************************************************************************************************
*/

int  main (void)
{
    CPU_INT08U  err;
    BSP_IntDisAll();                                            /* Disable all interrupts until we are ready to accept them */
    OSInit();                                                   /* Initialize "uC/OS-II, The Real-Time Kernel"              */ 


    PartitionPtr=OSMemCreate(Partition,4,32,&err);
    OSTaskCreate(Task1, (void *)0, &Task1Stk[TASK_STK_SIZE - 1], 5);

    OSTaskCreateExt((void (*)(void *)) App_TaskStart,           /* Create the start task                                    */
                    (void           *) 0,
                    (OS_STK         *)&App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE - 1],
                    (INT8U           ) APP_CFG_TASK_START_PRIO,
                    (INT16U          ) APP_CFG_TASK_START_PRIO,
                    (OS_STK         *)&App_TaskStartStk[0],
                    (INT32U          ) APP_CFG_TASK_START_STK_SIZE,
                    (void           *) 0,
                    (INT16U          )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));

#if (OS_TASK_NAME_SIZE > 5)
    OSTaskNameSet(APP_CFG_TASK_START_PRIO, "Start", &err);
    OSTaskNameSet(5, "Task1", &err);   
#endif

    OSStart();                                                  /* Start multitasking (i.e. give control to uC/OS-II)       */
}


/*
*********************************************************************************************************
*                                          AppTaskStart()
*
* Description : The startup task.  The uC/OS-II ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (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 starts because the I-bit of the CCR register was
*                   set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/

static  void  App_TaskStart (void *p_arg)
{
    CPU_INT08U  i;

    (void)p_arg;

    BSP_Init();                                                 /* Initialize BSP functions                                 */

#if (OS_TASK_STAT_EN > 0)
    OSStatInit();                                               /* Determine CPU capacity                                   */
#endif
        
    BSP_LED_Off(0);                                             /* Turn OFF all the LEDs                                    */
    
    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */
        for (i = 1; i <= 16; i++) {
             BSP_LED_Off(i - 1);
             OSTimeDlyHMSM(0, 0, 0, 50);
             BSP_LED_On(i);
             OSTimeDlyHMSM(0, 0, 0, 50);
        }
    }
}
                   
void Task1(void *pdata)
{
  INT8U err;
  INT8U flag;
  INT8U *pblock1;
  INT8U *pblock2;

  for(;;)
 {
   pblock1=OSMemGet(PartitionPtr,&err);
   pblock2=OSMemGet(PartitionPtr,&err);
   memcpy((char *)pblock1,msgbuf1,32);
   memcpy((char *)pblock2,msgbuf2,32);
   puts((char *)pblock1);
   puts((char *)pblock2);
   flag=OSMemQuery(PartitionPtr,&MemInfo);
   printf("\rThe block size is %d\n",MemInfo.OSBlkSize);
   printf("\rThe number of block  is %d\n",MemInfo.OSNBlks);
   printf("\rThe number of free block  is %d\n",MemInfo.OSNFree);
   printf("\rThe block in use is %d\n",MemInfo.OSNUsed);
   OSMemPut(PartitionPtr,pblock1);
   OSMemPut(PartitionPtr,pblock2);
   flag=OSMemQuery(PartitionPtr,&MemInfo);
   printf("\rThe block size is %d\n",MemInfo.OSBlkSize);
   printf("\rThe number of block  is %d\n",MemInfo.OSNBlks);
   printf("\rThe number of free block  is %d\n",MemInfo.OSNFree);
   printf("\rThe block in use is %d\n",MemInfo.OSNUsed);
   OSTimeDly(64);
 }
}
                   

⌨️ 快捷键说明

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