📄 main.c.bak
字号:
/* Include necessary Nucleus PLUS files. */
#include "..\NUCLEUS\nucleus.h"
#include "..\NUCLEUS\mcf5307.h"
#include "main.h"
#include "..\io\time.h"
#include "..\file32\pcdisk.h"
#include "string.h"
#define MaxNumberOfTask 40
#define SizeEachTime 1024*128
extern MCF5307_IMM *imm;
extern struct time Time;
NU_TASK Task_1;
NU_TASK Task_2;
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;
MCF5307_IMM *imm;
/* Define prototypes for function references. */
void task_1(UNSIGNED argc, VOID *argv);
void task_2(UNSIGNED argc, VOID *argv);
void ShowTask(void);
void SystemInit(void);
extern void InitMbus(void);
extern void TestMbus(void);
extern STATUS file_init(VOID);
//extern INT NU_Become_File_User(VOID);
/* Define the Application_Initialize routine that determines the initial
Nucleus PLUS application environment. */
void Application_Initialize(void *first_available_memory)
{
VOID *pointer;
/* Create a system memory pool that will be used to allocate task stacks,
queue areas, etc. */
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, 4096, NU_NO_SUSPEND);
NU_Create_Task(&Task_1, "SysInit", task_1, 0, NU_NULL, pointer, 1024, 1, 20,
NU_PREEMPT, NU_NO_START);
/* Create UART task */
NU_Allocate_Memory(&System_Memory, &pointer, 4096, NU_NO_SUSPEND);
NU_Create_Task(&Task_2, "DbgTask", task_2, 0, NU_NULL, pointer, 1024, 1, 20,
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");
//NUFP_Initialize();
}
/* 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;
unsigned char result;
unsigned long KeyNumber;
NU_Sleep(200);
Time.Second=0x01;
Time.Minute=0x01;
Time.Hour=0x01;
Time.Date=0x01;
Time.Day=0x01;
Time.Month=0x01;
Time.Year=0x04;
result=SetRTC8563(&Time);
if(result!=0x00)
Printf("Set RTC PCF8563 Success!\r\n");
else
Printf("Set RTC PCF8563 Fail!\r\n");
/*
while(1)
{
NU_Sleep(100);
GetRTC8563(&Time);
sprintf(Buf,"Oh , Time is: %02x-%02x-%02x %02x:%02x:%02x\r\n",Time.Year,Time.Month,Time.Date,Time.Hour,Time.Minute,Time.Second);
Printf(Buf);
}
*/
}
void task_2(UNSIGNED argc, VOID *argv)
{
unsigned long KeyNumber;
STATUS Sta;
INT FileP;
char pwd[10];
char *Buf;
char *BBuf;
unsigned long ReadLength,ImageSize,LeftSize,times,i;
PC_FILE *pfile;
BBuf=(char *)0x00001000; //load image from harddisk to ram 0x00001000
SystemInit();
Printf("\r\n");
Printf("--------------------\r\n");
Printf("Coldfire Flash Writer V1.0...\r\n");
Printf("By coldfire_arm@yahoo.com.cn, Tao Huibin\r\n");
Printf("System Initialize OK, Ready to Write image...\r\n");
GetRTC8563(&Time);
sprintf(Buf,"Time starting is: %02x-%02x-%02x %02x:%02x:%02x\r\n",Time.Year,Time.Month,Time.Date,Time.Hour,Time.Minute,Time.Second);
Printf(Buf);
//Flash_Test();
GetRTC8563(&Time);
sprintf(Buf,"Time ending is : %02x-%02x-%02x %02x:%02x:%02x\r\n",Time.Year,Time.Month,Time.Date,Time.Hour,Time.Minute,Time.Second);
Printf(Buf);
GetRTC8563(&Time);
sprintf(Buf,"Time starting is: %02x-%02x-%02x %02x:%02x:%02x\r\n",Time.Year,Time.Month,Time.Date,Time.Hour,Time.Minute,Time.Second);
Printf(Buf);
Sta=file_init();
//Sta=NU_Become_File_User();
Sta=pc_memory_init();
Sta=NU_Open_Disk("c:");
if(Sta ==NU_SUCCESS) Printf( "Open disk successed.\n");
//read a file named xq.txt and print the content in this file;
FileP=NU_Open("C:\\xq.txt",PO_RDONLY, PS_IREAD);
if(FileP >=0)
{
Sta = NU_Read(FileP,Buf,200);
}
NU_Close(FileP);
Sta = NU_Close_Disk("c:");
for(i=0;i<=2;i++)
{
Printf(Buf);
}
//creat a file named haibao.txt,and write a string in the file;
FileP=NU_Open("C:\\haibao.txt",PO_CREAT|PO_RDWR,PS_IWRITE);
if(FileP >=0)
{
Printf("Creat file haiboa.txt succeed\n");
Buf="haibao shi wo";
Sta =NU_Write(FileP,Buf,200);
if(Sta>=0)Printf("Write file succed\n");
}
NU_Close(FileP);
Sta = NU_Close_Disk("c:");
}
void ShowTask(void)
{
/*
unsigned long TaskNumber,i;
NU_TASK *Pointer_Array[MaxNumberOfTask];
char Buf[20];
char Buf1[20];
char DebugBuffer[100];
struct TaskInfo
{
char Name[9];
DATA_ELEMENT task_status;
UNSIGNED scheduled_count;
OPTION priority;
OPTION preempt;
UNSIGNED time_slice;
VOID *stack_base;
UNSIGNED stack_size;
UNSIGNED minimum_stack;
};
struct TaskInfo Info;
Printf("\r\n\r\nName Status sch._count Pri. Pre. Slice S._base S._size Min._stack \r\n");
TaskNumber = NU_Task_Pointers(&Pointer_Array[0],MaxNumberOfTask);
for(i=0;i<TaskNumber;i++)
{
Info.Name[8]=0x00;
NU_Task_Information(Pointer_Array[i],
(Info.Name),
&(Info.task_status),
&(Info.scheduled_count),
&(Info.priority),
&(Info.preempt),
&(Info.time_slice),
&(Info.stack_base),
&(Info.stack_size),
&(Info.minimum_stack)
);
switch(Info.task_status)
{
case(NU_READY): sprintf(Buf,"READY");break;
case(NU_PURE_SUSPEND): sprintf(Buf,"PURE_S");break;
case(NU_FINISHED): sprintf(Buf,"FINISHED");break;
case(NU_TERMINATED): sprintf(Buf,"TERMINATED");break;
case(NU_SLEEP_SUSPEND): sprintf(Buf,"SLEEP_S");break;
case(NU_MAILBOX_SUSPEND): sprintf(Buf,"MAILBOX_S");break;
case(NU_QUEUE_SUSPEND): sprintf(Buf,"QUEUE_S");break;
case(NU_PIPE_SUSPEND): sprintf(Buf,"PIPE_S");break;
case(NU_EVENT_SUSPEND): sprintf(Buf,"EVENT_S");break;
case(NU_SEMAPHORE_SUSPEND): sprintf(Buf,"SEMAPHORE_S");break;
case(NU_MEMORY_SUSPEND): sprintf(Buf,"MEMORY_S");break;
case(NU_PARTITION_SUSPEND): sprintf(Buf,"PARTITION_S");break;
case(NU_DRIVER_SUSPEND): sprintf(Buf,"DRIVER_S");break;
default:sprintf(Buf,"UNKNOWN");
}
switch(Info.preempt)
{
case(NU_NO_PREEMPT): sprintf(Buf1,"No");break;
case(NU_PREEMPT): sprintf(Buf1,"Yes");break;
default:sprintf(Buf1,"UNKNOWN");
}
sprintf(DebugBuffer,"%-8s%-11s%11ld %3d %-3s %5ld 0x%08lX 0x%08lX 0x%08lX\r\n",
Info.Name,
Buf,
Info.scheduled_count,
Info.priority,
Buf1,
Info.time_slice,
Info.stack_base,
Info.stack_size,
Info.minimum_stack
);
Printf(DebugBuffer);
}
*/
}
void SystemInit()
{
imm= (MCF5307_IMM *)0x10000000;
Uart1_ReInit(imm);
InitMbus();
imm->sim.AVCR=0xd4; //enable ext. int. auto vect.
imm->sim.IRQPAR=0xe0; // ext. IRQ 5-3-1 mapped to IRQ 4/6/2
imm->sim.IMR=(0x0000
|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
|MCF5307_SIM_IMR_EINT1
);
cpu_cache_disable();
EnableCache();
asm(" move.w #0x2000,SR ");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -