📄 test.c
字号:
/*********************************************************************************************************/
/***********************************************************************************************************/
#include <rtc.h>
#include <soc.h>
#include "includes.h"
#define TASK_STK_SIZE 256 /* Size of each task's stacks (# of WORDs) */
#define NO_TASKS 10 /* 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;
/* ********************************************************************* */
/* Local functions */
void rtc_Init(void)
{
SCU_INTMA=SCU_INTMA|0x04;
IER=IER|0x0100; // 打开对应位向CPU发送信息
ITR=ITR|0x0100; // 上升沿有效
RTCCTL=0x0004; // 0100写RTC
RTCIM=0x0034; // 00110100 1/16 上升沿
RTCCTL=0x0001; // 0001
}
void Task (void *data)
{
U8 err;
while(1)
{
OSSemPend(RandomSem, 0, &err); /* Acquire semaphore to perform random numbers */
OSSemPost(RandomSem); /* Release semaphore */
test_sendchar(*(char *)data); /* Display the task number on the screen */
printf("NO: Task is running \n ");
OSTimeDly(5); /* Delay 5 clock tick */
// OSCtxSwCtr = 0;
}
}
void TaskStart (void *data)
{
U8 i;
char key;
data = data; /* Prevent compiler warning */
printf("uC/OS-II, The Real-Time Kernel MIPS Ported version\n");
printf("Jean J. Labrosse/ (Ported by) Michael Anburaj\n");
printf("EXAMPLE #1\n");
printf("Determining CPU's capacity ...\n");
rtc_Init(); /* 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;
printf("#%d",i);
OSTaskCreate(Task, (void *)&TaskData[i], (void *)&TaskStk[i][TASK_STK_SIZE - 1], i + 1);
}
printf("\n# Parameter1: No. Tasks\n");
// printf("# Parameter2: CPU Usage in %%\n");
printf("# Parameter2: No. Task switches/sec\n");
printf("<-PRESS 'ESC' TO QUIT->\n");
while(1)
{
printf(" %d", OSTaskCtr); /* Display #tasks running */
// printf(" %d", OSCPUUsage); /* Display CPU usage in % */
printf(" %d\n", OSCtxSwCtr); /* Display #context switches per second */
// OSCtxSwCtr = 0;
rtc_Init();
if(test_getchar(&key) == TRUE)
{ /* See if key has been pressed */
if(key == 0x1B) /* Yes, see if it's the ESCAPE key */
while(1); /* Stay here for ever */
}
OSTimeDlyHMSM(0, 0, 1, 0); /* Wait one second */
}
}
/* ********************************************************************* */
/* Global functions */
int main(void)
{
printf("start main \n");
OSInit();
RandomSem = OSSemCreate(1);
printf("start OSTaskCreate \n");
OSTaskCreate(TaskStart, (void *)0, (void *)&TaskStartStk[TASK_STK_SIZE - 1], 0);
printf("finish OSTaskCreate \n");
printf("start rtc_init \n");
// rtc_Init() ;
OSStart();
/* Start multitasking */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -