?? ex1.c
字號:
/*
* uC/OS-II
* The Real-Time Kernel
*
* Linux Port
*
* File : $Source: /proj/cvs-gfa/Micrium/Software/linux-test/ex1.c,v $
* By : (c) George Fankhauser, Sensaco Consulting GmbH,
* Switzerland, http://www.sensaco.com
* Version : $Revision: 1.1.1.1 $
*
* Changed by : $Author: gfa $
* $Date: 2003/11/20 10:19:14 $
*
* $Log: ex1.c,v $ * Revision 1.1.1.1 2003/11/20 10:19:14 gfa * check in ucos II for linux *
*/
/** \file
* This is the basic test program based on example #1 from the book MicroC/OS-II by J.J. Labrosse.
*
*
*/
#include "includes.h"
#include <stdio.h>
/** the ugly output stuff */
#include "term_display.h"
#define TASK_STK_SIZE OS_TASK_DEF_STK_SIZE /* Size of each task's stacks (# of bytes) */
#define N_TASKS 7 /* Number of identical tasks */
OS_STK TaskStk[N_TASKS][TASK_STK_SIZE]; /* Stacks for subtasks */
OS_STK TaskStartStk[TASK_STK_SIZE]; /* Stack for first task */
char TaskData[N_TASKS]; /* Parameters to pass to each task */
void subTask(void *data); /* Function prototypes of tasks */
void myTask(void *data); /* Function prototypes of Startup task */
void PutChar(char c); /* Write a character to the UART */
void PutString(const char *s); /* Write a null-terminated string to the UART */
void SPrintDec(char *, INT16U, INT8U); /* Output an INT16U to a string (right adjust) */
void PutDec (INT8U x); /* Display an INT8U without leading zeros */
void PC_Attribute (INT8U fgcolor, INT8U bgcolor); /* Set attributes on PC_ terminal */
void PC_DispClrScr(void); /* Clear PC_ terminal */
void PC_DispChar(INT8U, INT8U, char, INT8U, INT8U); /* Display a character on PC_ terminal */
void PC_DispStr(INT8U, INT8U, char *, INT8U, INT8U); /* Display a string on PC_ terminal */
INT8U random(INT8U n); /* Simple random generator (found in K&R) */
int main (void)
{
OSInit();
RandomSem = OSSemCreate(1); /* Random number semaphore */
DispStrSem = OSSemCreate(1); /* Display string semaphore */
OSTaskCreate(myTask, (void *)0, (void *)&TaskStartStk[TASK_STK_SIZE - 1], 0);
RndNext = 1; /* set random generator seed to 1 */
OSStart(); /* Start multitasking */
return 0;
}
/** myTask
* this is the highest priority task in this example
*
* Example taken from the Book
*/
void myTask(void *data)
{
INT8U i;
char s[10];
static int x = 0;
data = data;
linuxInitInt(); /* Initialize the Linux timer */
PC_DispClrScr();
PC_DispStr(26, 1, "uC/OS-II, The Real-Time Kernel", COLOR_WHITE, COLOR_RED);
PC_DispStr(33, 2, "Jean J. Labrosse", COLOR_WHITE, COLOR_BLACK);
PC_DispStr(25, 3, "Linux port by George Fankhauser", COLOR_WHITE, COLOR_BLACK);
PC_DispStr(18, 4, "Sensaco Consulting GmbH, http://www.sensaco.com", COLOR_WHITE,COLOR_BLACK);
PC_DispStr(1, 23, "Determining CPU's capacity ...", COLOR_WHITE, COLOR_BLACK);
OSStatInit(); /* Initialize uC/OS-II's statistics */
for (i = 0; i < N_TASKS; i++) { /* Create N_TASKS identical tasks */
TaskData[i] = '0' + i; /* Each task will display its own letter */
OSTaskCreate(subTask, (void *)&TaskData[i], (void *)&TaskStk[i][TASK_STK_SIZE - 1], i + 1 /* prio */);
}
PC_DispStr(1, 23, "#Tasks : xxxxx CPU Usage: xxx %", COLOR_WHITE, COLOR_BLACK);
PC_DispStr(1, 24, "#Task switch/sec: xxxxx Task Sw.: xxxxx", COLOR_WHITE, COLOR_BLACK);
for (;;) {
SPrintDec(s, (INT16U)OSTaskCtr, 5); /* Display #tasks running */
PC_DispStr(19, 23, s, COLOR_WHITE, COLOR_BLUE);
SPrintDec(s, (INT16U)OSCPUUsage, 3); /* Display CPU usage in % */
PC_DispStr(37, 23, s, COLOR_WHITE, COLOR_BLUE);
x += OSCtxSwCtr;
SPrintDec(s, (INT16U)x, 6); /* # switches */
PC_DispStr(37, 24, s, COLOR_WHITE, COLOR_BLUE);
#define UPDATE_F 4
SPrintDec(s, (INT16U)OSCtxSwCtr * UPDATE_F, 5); /* Display #context switches per second */
PC_DispStr(19, 24, s, COLOR_WHITE, COLOR_BLUE);
OSCtxSwCtr = 0;
OSTimeDlyHMSM(0, 0, 0, 1000/UPDATE_F); /* Wait 1/UPDATES second */
}
}
/**
*/
void subTask (void *data)
{
INT8U x;
INT8U y;
INT8U err;
for (;;) {
OSSemPend(RandomSem, 0, &err); /* Acquire semaphore to perform random numbers */
x = random(80); /* Find X position where task number will appear */
y = random(15); /* Find Y position where task number will appear */
OSSemPost(RandomSem); /* Release semaphore */
/* Display the task number on the screen */
PC_DispChar(x + 1, y + 6, *(char *)data, COLOR_BLACK,
*(char *)data - '0' + 1);
OSTimeDly(1); /* Delay 1 clock tick, gibes lower prio threafds a chance to run */
}
}
void OSTaskSwHook() {}
void OSTaskStatHook() {}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -