📄 test.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 2000, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* V2.00
*
* EXAMPLE #1
*********************************************************************************************************
*/
#include "includes.h"
#include <stdlib.h>
#include <stdio.h>
#include "vectors24.h"
#include "F91eval.h"
#include "vtColor.h"
extern void prt_1_isr(void);
void hw_init(void)
//Initialize hardware
{
// init_gpio();
init_default_vectors();
set_vector(INT_VEC_PRT2,OSTickISR);
set_vector(INT_VEC_PRT1,prt_1_isr);
asm(" DI"); /* because the above routines all did EI */
}
extern unsigned int ms_ticks;
INT16U ms_count(void)
{
return (unsigned int) (ms_ticks / 100);
}
/*$PAGE*/
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define TASK_STK_SIZE 512 /* Size of each task's stacks (# of WORDs) */
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK Task1Stk[TASK_STK_SIZE]; /* Tasks stacks */
OS_STK Task2Stk[TASK_STK_SIZE];
OS_STK Task3Stk[TASK_STK_SIZE];
OS_STK Task4Stk[TASK_STK_SIZE];
OS_STK Task5Stk[TASK_STK_SIZE];
OS_STK TaskStartStk[TASK_STK_SIZE];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void Task1(void *data); /* Function prototypes of tasks */
void Task2(void *data);
void Task3(void *data);
void Task4(void *data);
void Task5(void *data);
void TaskStart(void *data); /* Function prototypes of Startup task */
extern void init_tick_timer(void);
extern void init_ms_timer(void);
extern void tick_timer_start(void);
extern void ms_timer_start(void);
/*$PAGE*/
/*
*********************************************************************************************************
* MAIN
*********************************************************************************************************
*/
void main (void)
{
hw_init(); //Hardware and on-chip setup
ms_ticks=0;//0x7AAAAA;
init_console_UART();
OSInit(); /* Initialize uC/OS-II */
init_tick_timer();
init_ms_timer(); //************************************
OSTaskCreate(TaskStart, (void *)0x1234, &TaskStartStk[TASK_STK_SIZE - 1], 0);
OSStart(); /* Start multitasking */
}
/*$PAGE*/
/*
*********************************************************************************************************
* STARTUP TASK
*********************************************************************************************************
*/
void TaskStart (void *data)
{
INT8U i;
INT8U result;
printf("\n initializing...\n");
data = data; /* Prevent compiler warning */
putch('U');
ms_timer_start(); //*****************************
tick_timer_start();
asm(" EI");
putch('X');
//OSStatInit(); /* Initialize uC/OS-II's statistics */
result=OSTaskCreate(Task1, (void *)0x1111, &Task1Stk[TASK_STK_SIZE - 1], 10);
if (result != OS_NO_ERR) printf("Error %d creating Task 1\n",result);
result=OSTaskCreate(Task2, (void *)0x2222, &Task2Stk[TASK_STK_SIZE - 1], 11);
if (result != OS_NO_ERR) printf("Error %d creating Task 2\n",result);
result=OSTaskCreate(Task3, (void *)0x3333, &Task3Stk[TASK_STK_SIZE - 1], 12);
if (result != OS_NO_ERR) printf("Error %d creating Task 3\n",result);
result=OSTaskCreate(Task4, (void *)0x4444, &Task4Stk[TASK_STK_SIZE - 1], 13);
if (result != OS_NO_ERR) printf("Error %d creating Task 4\n",result);
result=OSTaskCreate(Task5, (void *)0x5555, &Task5Stk[TASK_STK_SIZE - 1], 14);
if (result != OS_NO_ERR) printf("Error %d creating Task 5\n",result);
for (;;) {
OSTimeDly(1);
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASKS
*********************************************************************************************************
*/
void Task1 (void *data)
{
for (;;) {
OSTimeDly(10);
putch('1');
}
}
void Task2 (void *data)
{
for (;;) {
OSTimeDly(22);
putch('2');
}
}
void Task3 (void *data)
{
for (;;) {
OSTimeDly(34);
putch('3');
OS_ENTER_CRITICAL
//printf("[%d]",ms_current);
printf("[%d]",ms_count());
OS_EXIT_CRITICAL
}
}
void Task4 (void *data)
{
for (;;) {
OSTimeDly(47);
putch('4');
}
}
void Task5 (void *data)
{
for (;;) {
OSTimeDly(60);
putch('5');
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -