?? ext1.c
字號(hào):
/****************************************************************************************
*
* uCOS-II EXAMPLE1 的GBA版本
* PORT by 李強(qiáng)
*
* 如果你看到顯示太密集 不是我的錯(cuò) ADS的隨機(jī)數(shù)產(chǎn)生的就是這樣di…
* 我的隨機(jī)數(shù)種子是用的OSTime(每tick自動(dòng)加1) 但是產(chǎn)生的隨機(jī)數(shù)也還是很明顯的規(guī)律了
* 如果誰有好的解決 也請(qǐng)告訴我 多謝 mail: mail2li@163.com
*
****************************************************************************************/
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* EXAMPLE #1
*
* Port to GBA by LQ[mail2li in C51BBS] (mail2li@163.com)
*
*********************************************************************************************************
*/
#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]; /* Parameters to pass to each task */
OS_EVENT *RandomSem;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void Task(void *data); /* Function prototypes of tasks */
void TaskStart(void *data); /* Function prototypes of Startup task */
static void TaskStartCreateTasks(void);
static void TaskStartDispInit(void);
static void TaskStartDisp(void);
/***************************************************************************************
*
* 以下為原PC函數(shù)在GBA上的實(shí)現(xiàn)
*
* 作者: 李強(qiáng)
*
****************************************************************************************/
/*
*********************************************************************************************************
* PC_DispStr & PC_DispChar Port to GBA screen
*********************************************************************************************************
*/
void PC_DispStr(u16 x,
u16 y,
char* str,
u16 fg_colr,
u16 bg_colr)
{
u16 old_x = wherex,
old_y = wherey,
old_fg = whichFG,
old_bg = whichBG;
setxy(x*ASC_FONT_W,y*ASC_FONT_H);
SetColor(fg_colr,bg_colr);
printLCD(str);
setxy(old_x,old_y);
SetColor(old_fg,old_bg);
}
void PC_DispChar(u16 x,
u16 y,
char ch,
u16 fg_colr,
u16 bg_colr)
{
u16 old_x = wherex,
old_y = wherey,
old_fg = whichFG,
old_bg = whichBG;
setxy(x*ASC_FONT_W,y*ASC_FONT_H);
SetColor(fg_colr,bg_colr);
lcdputc(ch);
setxy(old_x,old_y);
SetColor(old_fg,old_bg);
}
void InitTickTimer(void) // 初始化tick定時(shí)器 因?yàn)楸容^重要不放在初始化AGB中
{
REG_IME = 0;
setb(REG_IE,INT_TIM3);
REG_TM3CNT = 0x00C1;
REG_TM3D = 0x10000 - (GBA_FOSC/64)/OS_TICKS_PER_SEC;
REG_IME = 1;
}
// 產(chǎn)生一個(gè)隨機(jī)數(shù)(范圍在0~bound)
u16 random(s16 bound)
{
u16 re;
// srand(OSTime);
srand(REG_TM3D);
re = (u64)rand()*bound/RAND_MAX;
return re;
}
/*
*********************************************************************************************************
* MAIN
*********************************************************************************************************
*/
void main (void)
{
lcdinit();
SetColor(COLOR_WHITE,COLOR_BLACK);
OSInit(); /* Initialize uC/OS-II */
RandomSem = OSSemCreate(1); /* Random number semaphore */
OSTaskCreate(TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE - 1], 0);
OSStart(); /* Start multitasking */
}
/*
*********************************************************************************************************
* STARTUP TASK
*********************************************************************************************************
*/
void TaskStart (void *pdata)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
// char s[100];
INT16S key;
pdata = pdata; /* Prevent compiler warning */
TaskStartDispInit(); /* Initialize the display */
OS_ENTER_CRITICAL();
InitTickTimer();
OS_EXIT_CRITICAL();
OSStatInit(); /* Initialize uC/OS-II's statistics */
TaskStartCreateTasks(); /* Create all the application tasks */
while(1)
{
TaskStartDisp(); /* Update the display */
OSCtxSwCtr = 0; /* Clear context switch counter */
OSTimeDlyHMSM(0, 0, 1, 0); /* Wait one second */
}
}
/*
*********************************************************************************************************
* INITIALIZE THE DISPLAY
*********************************************************************************************************
*/
static void TaskStartDispInit (void)
{
/* 11111111112222222222*/
/*012345678901234567890123456789*/
PC_DispStr( 0, 0, " uC/OS-II Real-Time Kernel ", COLOR_WHITE , COLOR_RED);
PC_DispStr( 0, 1, " Vx.yy in GBA EXAMPLE #1 ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 2, " ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 3, " ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 4, " ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 5, " ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 6, " ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 7, " ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 8, " ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 9, " ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 10, " ", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 11, "#Tasks : CPU Usage: %%", COLOR_BLACK , COLOR_GRAY);
PC_DispStr( 0, 12, "#switch/s: OSTime: ", COLOR_BLACK , COLOR_GRAY);
/*012345678901234567890123456789*/
/* 11111111112222222222*/
}
/*
*********************************************************************************************************
* UPDATE THE DISPLAY
*********************************************************************************************************
*/
static void TaskStartDisp (void)
{
char s[32];
sprintf(s, "%5d", OSTaskCtr); /* Display #tasks running */
PC_DispStr(10, 11, s, COLOR_YELLOW , COLOR_BLUE);
#if OS_TASK_STAT_EN > 0
sprintf(s, "%3d", OSCPUUsage); /* Display CPU usage in % */
PC_DispStr(26, 11, s, COLOR_YELLOW , COLOR_BLUE);
#endif
sprintf(s, "%5d", OSCtxSwCtr); /* Display #context switches per second */
PC_DispStr(10, 12, s, COLOR_YELLOW , COLOR_BLUE);
sprintf(s, "%7ld", OSTime); /* Display #context switches per second */
PC_DispStr(23, 12, s, COLOR_YELLOW , COLOR_BLUE);
sprintf(s, "V%1d.%02d", OSVersion()/100, OSVersion()%100); /* Display uC/OS-II's version number*/
PC_DispStr(4, 1, s, COLOR_BLACK , COLOR_GRAY);
}
/*
*********************************************************************************************************
* CREATE TASKS
*********************************************************************************************************
*/
static void TaskStartCreateTasks (void)
{
INT8U i;
for (i = 0; i < N_TASKS; i++) { /* Create N_TASKS identical tasks */
TaskData[i] = '0' + i; /* Each task will display its own letter */
OSTaskCreate(Task, (void *)&TaskData[i], &TaskStk[i][TASK_STK_SIZE - 1], i + 1);
}
}
/*
*********************************************************************************************************
* TASKS
*********************************************************************************************************
*/
void Task (void *pdata)
{
INT8U x;
INT8U y;
INT8U err;
while(1)
{
OSSemPend(RandomSem, 0, &err); /* Acquire semaphore to perform random numbers */
x = random(30); /* Find X position where task number will appear */
y = random(8); /* Find Y position where task number will appear */
OSSemPost(RandomSem); /* Release semaphore */
/* Display the task number on the screen */
PC_DispChar(x, y + 2, *(char *)pdata, COLOR_BLACK , COLOR_GRAY);
OSTimeDly(1); /* Delay 1 clock tick */
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -