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

📄 test.c

📁 移植成功到ARM7的UCOS-II操作系统
💻 C
字号:
/**************************************************************************
*                                                                         *
*   PROJECT     : ARM port for UCOS-II                                    *
*                                                                         *
*   MODULE      : EX1.c                                                   *
*                                                                         *
*   AUTHOR      : Michael Anburaj                                         *
*                 URL  : http://geocities.com/michaelanburaj/             *
*                 EMAIL: michaelanburaj@hotmail.com                       *
*                                                                         *
*   PROCESSOR   : Any processor                                           *
*                                                                         *
*   IDE         : Any IDE                                                 *
*                                                                         *
*   DESCRIPTION :                                                         *
*   This is a sample code to test UCOS-II.                                *
*                                                                         *
**************************************************************************/


#include "includes.h"

struct __FILE { int handle;   /* Add whatever you need here */};
FILE __stdout;
/* ********************************************************************* */
/* Global definitions */


/* ********************************************************************* */
/* File local definitions */

#define  TASK_STK_SIZE 1024                      /* Size of each task's stacks (# of WORDs) */
#define  NO_TASKS           3                  /* Number of identical tasks */

OS_STK   TaskStk[NO_TASKS][TASK_STK_SIZE];      /* Tasks stacks */
OS_STK   TaskStartStk[TASK_STK_SIZE];
char     TaskData[NO_TASKS];                    /* Parameters to pass to each task */
OS_EVENT *RandomSem;

extern void FRMWRK_vStartTicker(U32 wTicksPerSec);
/* ********************************************************************* */
/* Local functions */


int fputc(int ch, FILE *f)
{
    /* Place your implementation of fputc here     */
    /* e.g. write a character to a UART, or to the */
    /* debugger console with SWI WriteC            */

    char tempch = ch;
    Uart_SendByte(tempch);
    return ch;
}

void demo_printf(void)
{
  Uart_Printf("Hello World\n");
}

void demo_sprintf(void)
{
  int x;
  char buf[20];

  for (x=1; x<=5; x++)
  {
    sprintf(buf, "Hello Again %d\n", x);
    printf("%s", buf);
  }
}


void Task (void *data)
{
        U8 err;

        while(1)
        {
                OSSemPend(RandomSem, 0, &err);  /* Acquire semaphore to perform random numbers */
                OSSemPost(RandomSem);           /* Release semaphore */
                //Uart_SendByte(*(char *)data); /* Display the task number on the screen */
                demo_printf();
                OSTimeDly(5);                   /* Delay 5 clock tick */
        }
}

void TaskStart (void *data)
{
        U8 i;
       
        data = data;                            /* Prevent compiler warning */

        Uart_Printf("uC/OS-II, The Real-Time Kernel ARM Ported version\n");
        Uart_Printf("Jean J. Labrosse/ (Ported by) Michael Anburaj\n");
        Uart_Printf("EXAMPLE #1\n");

        Uart_Printf("Determining  CPU's capacity ...\n");

        FRMWRK_vStartTicker(OS_TICKS_PER_SEC);  /* The Tick timer is started much earlier */

        OSStatInit();                           /* Initialize uC/OS-II's statistics */

        for (i = 0; i < NO_TASKS; i++)
        {                                       /* Create NO_TASKS identical tasks */
                TaskData[i] = '0' + i;          /* Each task will display its own letter */
                Uart_Printf("#%d",i);
                OSTaskCreate(Task, (void *)&TaskData[i], (void *)&TaskStk[i][TASK_STK_SIZE - 1], i + 1);
        }

        Uart_Printf("\n# Parameter1: No. Tasks\n");
        Uart_Printf("# Parameter2: CPU Usage in %%\n");
        Uart_Printf("# Parameter3: No. Task switches/sec\n");
        Uart_Printf("<-PRESS 'ESC' TO QUIT->\n");
        while(1)
        {
          OSTimeDly(65535);
        }
}


/* ********************************************************************* */
/* Global functions */

void Task1(void* data)
{
    //Start timer0 as system timer
    
    Uart_Printf("in task1 before starting timer");
    
	for (;;) {

		/* print task's id */
		
		Uart_Printf("I am task1\n");
		OSTimeDly(1000);

    }
}

void Task2(void* data)
{
    
	for (;;) {

		/* print task's id */
		
		Uart_Printf("I am task2\n");
		OSTimeDly(2000);

    }
}

void Task3(void* data)
{
    
	for (;;) {

		/* print task's id */
		
		Uart_Printf("I am task3\n");
		OSTimeDly(4000);

    }
}



void APP_vMain (void)
{
        OSInit();                               /* Initialize uC/OS-II                                      */
        RandomSem = OSSemCreate(1);             /* Random number semaphore                              */
 OSTaskCreate(TaskStart, (void *)0, (void *)&TaskStartStk[TASK_STK_SIZE - 1], 0);
 OSTaskCreate(Task1, (void *)0, (void *)&TaskStk[0][TASK_STK_SIZE - 1], 1);  
 OSTaskCreate(Task2, (void *)0, (void *)&TaskStk[1][TASK_STK_SIZE - 1], 2);
 OSTaskCreate(Task3, (void *)0, (void *)&TaskStk[2][TASK_STK_SIZE - 1], 3);     
        //FRMWRK_vStartTicker(OS_TICKS_PER_SEC);  /* os_cfg.h */
        OSStart();                              /* Start multitasking                                       */
}


/* ********************************************************************* */

⌨️ 快捷键说明

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