📄 main.c
字号:
#include "../../ucos-ii/includes.h" /* uC/OS interface */
#include "../uhal/s3c4510b.h"
//task stack size
#ifdef SEMIHOSTED
#define TASK_STACK_SIZE (64+SEMIHOSTED_STACK_NEEDS)
#else
#define TASK_STACK_SIZE 10*1024
#endif
//Task definition
/* allocate memory for tasks' stacks */
#define STACKSIZE 128
//#define DATABUFFSIZE 32
#define HALFOFSIZE 16
/* Global Variable */
unsigned int Stack1[STACKSIZE];
unsigned int Stack2[STACKSIZE];
unsigned int Stack3[STACKSIZE];
unsigned int StackMain[STACKSIZE];
unsigned int StackUART0Tx[STACKSIZE];
OS_EVENT *hMyMbox = 0;
//
int ByteCnt = 0;
char DataBuff[DATABUFFSIZE];
char *pRx = &DataBuff[0];
char exFlag = 0;
void Uart0Tx(void *Id)
{
char *pTx = 0;
// int TxByteCnt = 0;
int i=0;
INT8U pError = 0;
while(1)
{
//debug
/* while(!(UARTSTAT0&0x40));
UARTTXH0 = 0x55;
OSTimeDly(200);
*/
//Get Msg
pTx = (char*)OSMboxPend(hMyMbox,0,&pError);
if(pTx != 0)
{//Tx Data
for(i=0;i<HALFOFSIZE;i++)
{
while(!(UARTSTAT0&0x40));
UARTTXH0 = *(pTx+i);
}
}
}
}
void Task1(void *Id)
{
while(1)
{
IOPDATA = (IOPDATA)^0x0001;
OSTimeDly(50);
}
}
void Task2(void *Id)
{
int i;
while(1)
{
for(i=0; i<16; i++)
{
IOPDATA = (IOPDATA)^0x0002;
OSTimeDly(50);
}
}
}
void Task3(void *Id)
{
int i=0;
while(1)
{
for (i = 16; --i >= 0; )
{
Set8Led(i); //display number 'i' on the 7 segments LED
OSTimeDly(100);
}
if( i == 0)
i = 16;
}
}
void TaskStart (void *i)
{
char Id1 = '1';
char Id2 = '2';
char Id3 = '3';
uHALr_InitTimers(); // enable timer counter interrupt
/*
* create the tasks in uC/OS and assign decreasing
* priority to them
*/
OSTaskCreate(Uart0Tx, (void *)0, &StackUART0Tx[STACKSIZE - 1], 2);
OSTaskCreate(Task1, (void *)0, &Stack1[STACKSIZE - 1], 4);
OSTaskCreate(Task2, (void *)0, &Stack2[STACKSIZE - 1], 5);
OSTaskCreate(Task3, (void *)0, &Stack3[STACKSIZE - 1], 6);
// Delete current task
OSTaskDel(OS_PRIO_SELF);
}
int Main(void)//int argc, char **argv
{
char Id4 = '4';
ARMTargetInit();
/* needed by uC/OS */
OSInit();
OSTimeSet(0);
hMyMbox = OSMboxCreate((void *)0);
if(hMyMbox == (void*)0)
return;
/* create the start task */
OSTaskCreate(TaskStart,(void *)0, &StackMain[STACKSIZE - 1], 0);
ARMTargetStart();
/* start the operating system */
OSStart();
return(0);
//* End
}
void UART0RxIsr(void)
{
*(pRx+ByteCnt) = UARTRXB0;
ByteCnt++;
if(ByteCnt>=HALFOFSIZE)
{
ByteCnt = 0;
if(exFlag == 0)
{
exFlag = 1;
OSMboxPost(hMyMbox, pRx);
pRx = &DataBuff[HALFOFSIZE];
}
else
{
exFlag = 0;
OSMboxPost(hMyMbox, pRx);
pRx = &DataBuff[0];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -