📄 mytask.c
字号:
// MyTask.c
#include "includes.h"
#define TASK_STK_SIZE 1024 // task stack size
#define N_TASKS 2 // number of tasks
OS_STK TaskStk[N_TASKS][TASK_STK_SIZE/sizeof(OS_STK)]; // Tasks stacks
// Prototypes
void Task(void * pParam);
void Sleep(INT16U uSec);
void ClearScreen();
void OnScreen(int x, int y, char * pszText, int nColor);
// Application entry point, invoked from Entry.obj assembled from entry.S
int main()
{
int LineNo10 = 10;
int LineNo11 = 11;
// Set the top of stack.
__asm__ __volatile__("movl $0xa0000, %esp\n");
// Display a banner.
ClearScreen();
OnScreen(0, 0, "Welcome to Micro-C/OS-II on x86 in protected mode!", 14);
// Initialize uC/OS.
OSCpuInit();
OSInit();
// Create two tasks.
OSTaskCreate(Task, &LineNo10, &TaskStk[0][TASK_STK_SIZE], 0);
OSTaskCreate(Task, &LineNo11, &TaskStk[1][TASK_STK_SIZE], 1);
// Start multitasking.
OSStart();
return 0;
/* NEVER EXECUTED */
}
// Display a line of characters at the line specified by the parameter,
// assuming a color 80x25 video adapter.
//
// This function never returns.
void Task(void * pParam)
{
int LineNo = *(int *) pParam;
char * LineAddr = (char *) 0xb8000 + LineNo * 160;
char * p;
int i;
while (1)
{
p = LineAddr;
for (i = 0; i < 80; i++)
{
*p++ = (char) LineNo;
*p++ = 12;
}
Sleep(1);
p = LineAddr;
for (i = 0; i < 80; i++)
{
*p++ = ' ';
*p++ = 14;
}
Sleep(1);
}
}
// Sleeps for the specified delay (in seconds).
// Since the 8254 is not set in this implementation,
// sleeping one second means sleeping 18 clock ticks.
void Sleep(INT16U uSec)
{
OSTimeDly((INT16U) (18 * uSec));
}
// Clears the screen.
void ClearScreen()
{
int x,y;
char * pScreen = (char *) 0xb8000;
for (y = 0; y < 25; y++)
for (x = 0; x < 80; x++)
{
*pScreen++ = ' ';
*pScreen++ = 7;
}
}
// Displays a string on the screen, assuming a 80x25 color adapter.
void OnScreen(int x, int y, char * pszText, int nColor)
{
char * pScreen = (char *) (0xb8000 + y * 160 + x * 2);
while (*pszText)
{
*pScreen++ = *pszText++;
*pScreen++ = nColor;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -