📄 demo.c
字号:
/* Include necessary Nucleus PLUS files. */
#include "..\NUCLEUS\nucleus.h"
#include "..\NUCLEUS\mcf5307.h"
#include "..\net\sockdefs.h"
#include "..\net\socketd.h"
/***************** used in debug module */
#include "string.h"
extern unsigned char RxData[4096];
extern unsigned char TxData[4096];
char DebugBuffer[4096];
#define MaxNumberOfTask 40
//net
//extern void ShowNet(unsigned char *KeyBuf);
//extern void TransNet(void);
extern MCF5307_IMM *imm;
extern int MySocketNumber;
extern next_socket_no;
extern struct time
{ unsigned char Year;
unsigned char Month;
unsigned char Date;
unsigned char Hour;
unsigned char Minute;
unsigned char Second;
}Time;
/****************************************/
/* Define Application data structures. */
NU_TASK Task_1;
NU_TASK Task_2;
NU_TASK Task_3;
NU_TASK Task_4;
NU_TASK CpuTime;
NU_QUEUE Queue_0;
NU_SEMAPHORE Semaphore_0;
NU_SEMAPHORE Semaphore_1;
NU_SEMAPHORE Semaphore_2;
NU_SEMAPHORE Semaphore_3;
NU_EVENT_GROUP Event_Group_0;
NU_MEMORY_POOL System_Memory;
/* Allocate global counters. */
UNSIGNED Task_Time;
UNSIGNED Task_2_messages_received;
UNSIGNED Task_2_invalid_messages;
UNSIGNED Task_1_messages_sent;
NU_TASK *Who_has_the_resource;
UNSIGNED Event_Detections;
/* Define prototypes for function references. */
void task_1(UNSIGNED argc, VOID *argv);
void task_2(UNSIGNED argc, VOID *argv);
void task_4(UNSIGNED argc, VOID *argv);
void task_debug(UNSIGNED argc, VOID *argv);
void p_CpuTime(UNSIGNED argc, VOID *argv);
void p_CpuAddTime(UNSIGNED argc, VOID *argv);
void Test_Printer();
void ShowTask(void);
unsigned char TCPBuf[4096];
unsigned char ServerBuf[4096];
unsigned int CpuSpeed;
unsigned int MaxSpeed;
unsigned int CurrentSpeed;
short CpuUsage;
unsigned char Testx; /*add by sunsir*/
unsigned char Testy;
void expiration_routine(UNSIGNED id);
unsigned int TestCount = 0;
/**********************8*/
//unsigned char LocalIp[4]={192,168,0,11};
unsigned char LocalIp[4]={219,245,153,25};
/* Define the Application_Initialize routine that determines the initial
Nucleus PLUS application environment. */
void Application_Initialize(void *first_available_memory)
{
VOID *pointer;
SystemInit();
// InitNet();
/*
STATUS NU_Create_Task(NU_TASK *task, CHAR *name, VOID
(*task_entry)(UNSIGNED, VOID *),
UNSIGNED argc, VOID *argv,
VOID *stack_address, UNSIGNED stack_size,
OPTION priority, UNSIGNED time_slice,
OPTION preempt, OPTION auto_start)
*/
/* Create a system memory pool that will be used to allocate task stacks,
queue areas, etc. */
//Printf("\r\nClient Socket close bad!\r\n");
NU_Create_Memory_Pool(&System_Memory, "SYSMEM",
first_available_memory, 500*2048, 50, NU_FIFO);
/* Create each task in the system. */
/* Create task 1. */
NU_Allocate_Memory(&System_Memory, &pointer, 1024, NU_NO_SUSPEND);
NU_Create_Task(&Task_1, "NetInit", task_1, 0, NU_NULL, pointer, 1024, 1, 20,
NU_PREEMPT, NU_NO_START);
/* Create task 2. */
NU_Allocate_Memory(&System_Memory, &pointer, 1024, NU_NO_SUSPEND);
NU_Create_Task(&Task_2, "FtpData", task_2, 0, NU_NULL, pointer, 1024, 7, 3,
NU_PREEMPT, NU_NO_START);
/* Create UART task */
NU_Allocate_Memory(&System_Memory, &pointer, 1024, NU_NO_SUSPEND);
NU_Create_Task(&Task_3, "DbgTask", task_debug, 0, NU_NULL, pointer, 1024, 7, 3,
NU_PREEMPT, NU_NO_START);
/* Create CpuTime task */
NU_Allocate_Memory(&System_Memory, &pointer, 1024, NU_NO_SUSPEND);
NU_Create_Task(&CpuTime, "CpuTime", p_CpuTime, 0, NU_NULL, pointer, 1024, 255, 3,
NU_PREEMPT, NU_START);
/* Create communication queue. */
NU_Allocate_Memory(&System_Memory, &pointer, 100*sizeof(UNSIGNED),
NU_NO_SUSPEND);
NU_Create_Queue(&Queue_0, "QUEUE 0", pointer, 100, NU_FIXED_SIZE, 1,
NU_FIFO);
/************ Create synchronization semaphore. used in debug module ************/
//Semaphore_0 indicate uart trans! ok!
NU_Create_Semaphore(&Semaphore_0, "SEM 0", 1, NU_FIFO);
NU_Reset_Semaphore(&Semaphore_0,0);
//Semaphore_1 indicate uart is busy
NU_Create_Semaphore(&Semaphore_1, "SEM 1", 1, NU_FIFO);
NU_Reset_Semaphore(&Semaphore_0,1);
//Semaphore_2 indicate tcp receive task is ready?
NU_Create_Semaphore(&Semaphore_2, "SEM 2", 1, NU_FIFO);
NU_Reset_Semaphore(&Semaphore_2,0);
//Semaphore_3 indicate uart receive ok !
NU_Create_Semaphore(&Semaphore_3, "SEM 3", 1, NU_FIFO);
NU_Reset_Semaphore(&Semaphore_3,0);
/********************************************************************************/
/* Create event flag group. */
NU_Create_Event_Group(&Event_Group_0, "EVGROUP0");
}
/* Define the system timer task. More complicated systems might use a
routine like this to perform periodic message sending and other time
oriented functions. */
void task_1(UNSIGNED argc, VOID *argv)
{
void *pointer;
sint status;
unsigned char sta;
// NU_Init_Net(int8 * ip_address, int16 irq, uint32 ram_addr,uint32 io_addr);
// InitMbus();
// sta = SetRTC();
// while(1)
// {
// sta = ReadRTC();
// }
//sta = Write_E2rom(0x00,0x55);
//sta = Read_E2rom(0x00);
//sta = TestE2rom();
// Test_Printer();
status = NU_Init_Net(LocalIp, 0x1A, 0x30400200,0x30400200);//0x44000200, 0x44000200);//0x30400200
// Test_Printer();
if(status == -1)
while(1);
imm->sim.IMR=(0
|MCF5307_SIM_IMR_DMA3
|MCF5307_SIM_IMR_DMA2
|MCF5307_SIM_IMR_DMA1
|MCF5307_SIM_IMR_DMA0
|MCF5307_SIM_IMR_UART2
// |MCF5307_SIM_IMR_UART1
|MCF5307_SIM_IMR_MBUS
|MCF5307_SIM_IMR_TIMER2
// |MCF5307_SIM_IMR_TIMER1
|MCF5307_SIM_IMR_SWT
|MCF5307_SIM_IMR_EINT7
|MCF5307_SIM_IMR_EINT6
|MCF5307_SIM_IMR_EINT5
|MCF5307_SIM_IMR_EINT4
|MCF5307_SIM_IMR_EINT3
// |MCF5307_SIM_IMR_EINT2 //enable net card
|MCF5307_SIM_IMR_EINT1
);
/* Create server task */
NU_Allocate_Memory(&System_Memory, &pointer, 1024, NU_NO_SUSPEND);
NU_Create_Task(&Task_4, "TcpSer.", task_4, 0, NU_NULL, pointer, 1024, 7, 3,
NU_PREEMPT, NU_START);
}
/* Define the queue sending task. Note that the only things that cause
this task to suspend are queue full conditions and the time slice
specified in the configuration file. */
/* Define the task that waits for the event to be set by task 1. */
// It's a dead loop. ftp client , try to link a ftp server at 192.168.1.89 (TAOHUIBIN) on port 21
// it display information from server and display it;
void task_2(UNSIGNED argc, VOID *argv)
{
int Count=1;
NU_Obtain_Semaphore(&Semaphore_2,NU_SUSPEND);
while(Count>0)
{
NU_fcntl(MySocketNumber, NU_SETFLAG, NU_BLOCK, 0); //set block flag
Count=NU_Recv(MySocketNumber,TCPBuf,1500,0); //to get data
NU_fcntl(MySocketNumber, NU_SETFLAG, NU_FALSE, 0); //clear block flag
if(Count>0)
{
TCPBuf[Count]=0x00;
Printf("\r\n Replay of FTP is:\r\n");
Printf(TCPBuf);
Printf(">");
}
if(Count==NU_NOT_CONNECTED)
Printf("\r\n no connection\r\n");
Printf(">");
}
}
//tcp server
//Listen at 192.168.1.117 on port 23
void task_4(UNSIGNED argc, VOID *argv)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -