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

📄 test.c

📁 mips下的ucos
💻 C
字号:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*
*                        (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
*                                           All Rights Reserved
*
*                                                 V2.00
*
*                                               EXAMPLE #1
*********************************************************************************************************
*/

#include "includes.h"

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

#define  TASK_STK_SIZE 	512       /* Size of each task's stacks (# of WORDs)            */
#define  N_TASKS         10       /* Number of identical tasks                          */

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

OS_STK           TaskStk[N_TASKS][TASK_STK_SIZE];     /* Tasks stacks                                  */
OS_STK           TaskStartStk[TASK_STK_SIZE];
char             TaskData[N_TASKS][80];               /* Parameters to pass to each task               */
OS_EVENT        *IOSem;

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

void   Task(void *data);                              /* Function prototypes of tasks                  */
void   TaskStart(void *data);                         /* Function prototypes of Startup task           */

/*$PAGE*/
/*
*********************************************************************************************************
*                                                MAIN
*********************************************************************************************************
*/

int main (void)
{
  printf("Start of uCos test\n");
  OSInit();                                              /* Initialize uC/OS-II                      */
  printf("OSInit done\n");

  IOSem = OSSemCreate(1); 	// IO Semaphore
  OSTaskCreate(TaskStart, (void *)0, (void *)&TaskStartStk[TASK_STK_SIZE - 1], 0);
  OSStart();                                             /* Start multitasking                       */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                              STARTUP TASK
*********************************************************************************************************
*/
void TaskStart (void *data)
{
  UBYTE  i;
  INT8U err;
  
  printf("Main task started\n");
  
  BSPInit();
  OSSemPend(IOSem, 0, &err);	// Acquire semaphore to do IO           
  printf("Timer started\n");
  OSSemPost(IOSem);       	// Release semaphore 

  OSStatInit();                                          /* Initialize uC/OS-II's statistics         */
  for (i = 0; i < N_TASKS; i++) {     
    sprintf(TaskData[i], "I am task %i", i+1);
    printf("About to create task %i\n", i);
    OSTaskCreate(Task, (void *)TaskData[i], (void *)&TaskStk[i][TASK_STK_SIZE - 1], i+1);
  }
  
  for (;;) {
    OSSemPend(IOSem, 0, &err);	// Acquire semaphore to do IO           
    printf("Task %5d  CPU Usage %3d%%\n", OSTaskCtr, OSCPUUsage);
    printf("Task switch/sec: %5d\n", OSCtxSwCtr);
    OSSemPost(IOSem);       	// Release semaphore 
    
    OSCtxSwCtr = 0;
    
    OSTimeDlyHMSM(0, 0, 1, 0);                         /* Wait one second                          */
  }
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                                  TASKS
*********************************************************************************************************
*/

long x[100];
void Task (void *data)
{
  int i,j,k;
  INT8U err;

  for (;;) {
    OSSemPend(IOSem, 0, &err);	// Acquire semaphore to do IO           
    printf ("%s\n", (char *)data);
    OSSemPost(IOSem);       	// Release semaphore 

    for (i=0; i<100; ++i)
      for (j=0; j<10; ++j)
	x[i]=i+j;

    //OSTimeDlyHMSM(0, 0, 1, 0);	/* Wait one second                          */
    OSTimeDly(1);                   /* Delay 1 clock tick                                 */
  }

}

⌨️ 快捷键说明

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