📄 test.c
字号:
/**************************************************************************
* *
* PROJECT : ARM port for UCOS-II *
* *
* MODULE : EX1.c *
* *
* AUTHOR : Michael Anburaj *
* URL : http://geocities.com/michaelanburaj/ *
* EMAIL: michaelanburaj@hotmail.com *
* *
* PROCESSOR : Any processor *
* *
* IDE : Any IDE *
* *
* DESCRIPTION : *
* This is a sample code to test UCOS-II. *
* *
**************************************************************************/
#include "includes.h"
#include "Rtl8019.h"
#include "skbuff.h"
/*#include "eth.h"
#include "arp.h"
#include "ip.h"
#include "udp.h"*/
//extern void tftp_main(unsigned long ip, unsigned long addr, int method);
//struct __FILE { int handle; /* Add whatever you need here */};
//FILE __stdout;
/* ********************************************************************* */
/* Global definitions */
/* ********************************************************************* */
/* File local definitions */
extern int FRMWRK_vStartTicker(U32);
#define TASK_STK_SIZE 4096 /* Size of each task's stacks (# of WORDs) */
#define NO_TASKS 10 /* Number of identical tasks */
#define DFT_DOWNLOAD_ADDR 0xc058000
unsigned long IP_ADDRESS = 0xc0a80064;//0xc0a80064 0xac128664
OS_STK TaskStk[NO_TASKS][TASK_STK_SIZE]; /* Tasks stacks */
OS_STK TaskStartStk[TASK_STK_SIZE];
char TaskData[NO_TASKS]; /* Parameters to pass to each task */
OS_EVENT *RandomSem;
int SemGet=0;
int packet_count=0;
extern int rd_p,wr_p;
extern int total_packet;
extern struct sk_buff skbuff[BUFF_LEN];
extern U8 bnry;
extern U8 curr;
U8 bnry_temp;
/* ********************************************************************* */
/* Local functions */
void RandomSemGet(void)
{
unsigned char err;
OSSemPend(RandomSem, 0, &err);
}
void tick_hook(void)
{
rI_ISPC = (unsigned int)1 << 13;
}
void rtl_hook(void)
{
int result;
rI_ISPC = (unsigned int)1 << 24;
SetRegPage(0);
if((*((volatile unsigned char *)(ISR))&1)){ //接收成功
//packet_count++;
//Uart_Printf("中断接收到%x个包\n",packet_count);
//Uart_Printf("接收到数据包,产生中断\n");
//Uart_Printf("total_packet1-->%x!中断\n",total_packet);
//Uart_Printf("isr---->%x\n", *((volatile unsigned char *)(ISR)));
//Uart_Printf("RandomSem->OSEventCnt---->%x\n", RandomSem->OSEventCnt);
//rINTMSK=~(BIT_GLOBAL|BIT_TIMER0); //start timer INT
//rI_ISPC=BIT_TIMER0;
leave:
if(((wr_p + 1)%BUFF_LEN != rd_p)&&total_packet!=BUFF_LEN)
{
if((wr_p==rd_p)&&(total_packet==0))
{
//Uart_Printf("total_packet==0!\n");
skb_headerinit(&skbuff[wr_p]);
result = s3c44b0_eth_rcv(skbuff[wr_p].data,&(skbuff[wr_p].len));
}
else
{
//Uart_Printf("total_packet!=0!\n");
skb_headerinit(&skbuff[wr_p+1]);
result = s3c44b0_eth_rcv(skbuff[wr_p+1].data,&(skbuff[wr_p+1].len));
if(result==0)
{
wr_p = (wr_p + 1)%BUFF_LEN;
}
}
//Uart_Printf("result-->%x!\n",result);
//Uart_Printf("得到result××××!\n");
if(result==0)
{
total_packet = total_packet+1;
}
bnry_temp = bnry+1;
if(bnry_temp==0x80)
bnry_temp=0x4c;
if(bnry_temp!=curr)
goto leave;
}
else
{
//Uart_Printf("缓冲区已满!\n");
}
//Uart_Printf("total_packet2-->%x!中断\n",total_packet);
//Uart_Printf("rd_p-->%x!\n",rd_p);
//Uart_Printf("wr_p-->%x!\n",wr_p);
//Uart_Printf("RandomSem->OSEventCnt-->%x!\n",RandomSem->OSEventCnt);
//Uart_Printf("SemGet-->%x!\n",SemGet);
//if((RandomSem->OSEventCnt==0)&&(SemGet==0))
//{
//Uart_Printf("1!\n",wr_p);
//Uart_Printf("释放信号量!\n");
OSSemPost(RandomSem);
//SemGet=1;
//}
//Uart_Printf("RandomSem->OSEventCnt---->%x\n", RandomSem->OSEventCnt);
//Uart_Printf("释放信号量后中断服务程序还在运行!\n");
}
//*((volatile unsigned char *)(ISR)) = (unsigned char)(0xff);
//Uart_Printf("----isr置位后%x\n", *((volatile unsigned char *)(ISR)));
//outportb(ISR, 0xff);
}
//int fputc(int ch, FILE *f)
//{
/* Place your implementation of fputc here */
/* e.g. write a character to a UART, or to the */
/* debugger console with SWI WriteC */
// char tempch = ch;
// Uart_SendByte(tempch);
// return ch;
//}
void rtl8019_print(void)
{
//rPCONG = rPCONG &(~ ( 0x3<<2 ));
//Uart_Printf("rtl8019_isr is still running.......\n");
//while( (rPDATG&0x0002) != 0x0002 ) ;
//Delay( 50 ) ;
//rPCONG = rPCONG | ( 0x3<<2 );
}
void printa(void)
{
Uart_Printf("aaaaaaaaaaa\n");
}
void printb(void)
{
Uart_Printf("bbbbbbbbbbb\n");
}
void printc(void)
{
Uart_Printf("ccccccccccc\n");
}
void demo_printf(void)
{
Uart_Printf("Hello World\n");
}
void demo_sprintf(void)
{
int x;
char buf[20];
for (x=1; x<=5; x++)
{
sprintf(buf, "Hello Again %d\n", x);
printf("%s", buf);
}
}
void Task (void *data)
{
U8 err;
while(1)
{
//OSSemPend(RandomSem, 0, &err); /* Acquire semaphore to perform random numbers */
//OSSemPost(RandomSem); /* Release semaphore */
Uart_SendByte(*(char *)data); /* Display the task number on the screen */
demo_printf();
OSTimeDlyHMSM(0, 0, 2, 0);
}
}
void TaskStart (void *data)
{
U8 i;
char key;
data = data; /* Prevent compiler warning */
Uart_Printf("uC/OS-II, The Real-Time Kernel ARM Ported version\n");
Uart_Printf("Jean J. Labrosse/ (Ported by) Michael Anburaj\n");
//Uart_Printf("EXAMPLE #1\n");
Uart_Printf("Determining CPU's capacity ...\n");
FRMWRK_vStartTicker(OS_TICKS_PER_SEC); /* The Tick timer is started much earlier */
Uart_Printf("Tftp Start ...\n");
//Uart_Printf("FRMWRK_vStartTicker FRMWRK_vStartTicker\n");
//OSStatInit(); /* Initialize uC/OS-II's statistics */
//for (i = 0; i < NO_TASKS; i++)
//{ /* Create NO_TASKS identical tasks */
// TaskData[i] = '0' + i; /* Each task will display its own letter */
// Uart_Printf("#%d",i);
// OSTaskCreate(Task, (void *)&TaskData[i], (void *)&TaskStk[i][TASK_STK_SIZE - 1], i + 1);
//}
//Uart_Printf("\n# Parameter1: No. Tasks\n");
//Uart_Printf("# Parameter2: CPU Usage in %%\n");
//Uart_Printf("# Parameter3: No. Task switches/sec\n");
//Uart_Printf("<-PRESS 'ESC' TO QUIT->\n");
//while(1)
//{
//Uart_Printf("while\n");
//Uart_Printf(" %d", OSTaskCtr); /* Display #tasks running */
//Uart_Printf(" %d", OSCPUUsage); /* Display CPU usage in % */
//Uart_Printf(" %d\n", OSCtxSwCtr); /* Display #context switches per second */
//OSCtxSwCtr = 0;
tftp_main(IP_ADDRESS, DFT_DOWNLOAD_ADDR, 1);
//net_handle();
//OSTimeDly(5);
//OSTimeDlyHMSM(0, 0, 5, 0); /* Wait one second */
//}
}
/* ********************************************************************* */
/* Global functions */
void APP_vMain (void)
{
OSInit(); /* Initialize uC/OS-II */
RandomSem = OSSemCreate(0); /* Random number semaphore */
OSTaskCreate(TaskStart, (void *)0, (void *)&TaskStartStk[TASK_STK_SIZE - 1], 0);
//FRMWRK_vStartTicker(OS_TICKS_PER_SEC);/* os_cfg.h */
OSStart(); /* Start multitasking */
}
/* ********************************************************************* */
static void Timer5Interrupt()
{
rI_ISPC=BIT_TIMER5; // Clear pending bit -- Watchdog timer
OSTimeTick();
}
void C_IRQHandler(void)
{
U32 temp,i;
temp=rI_ISPR;
if(temp==0) return;
for(i=0;i<26;i++){
if(temp&0x1==1){
break;
}
else{
temp=temp>>1;
}
}
if(i==26){
return;
}
temp=i<<2;
((void(*)(void))(*((U32 *)(_ISR_STARTADDRESS+0x20+temp))))();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -