⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imgdl.c

📁 (1)本人基于MPC860的vxworks bsp的程序 (2)实现了FEC 100M和 SCC 10M的网口功能 (3)实现了nor flash的TFFS文件系统 (4)实现了系统的自检 (
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "vxworks.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "ioLib.h"
#include "tftpLib.h"
#include "ftpLib.h"



/*
#include "common.h"
*/

#define BUFFERSIZE 1024
#define BOOTROMSTART 0x20000000
#define ADDRTEST 0x10000
#define ADDRESSSTART 0x10000
#define GWM7040

#define ROM_BASE_ADRS  0x20000000

#define MAC_ADDR_START (ROM_BASE_ADRS+0x7F0000)

#define INTER_NAME "cpm0"

typedef unsigned char Uint8T;
typedef unsigned long Uint32T;
typedef unsigned short Uint16T;
typedef volatile unsigned short vUint16T;

/*
extern  void _ds2155E1Init(int span);

extern void ds21455IntsDeal(void);
*/
extern int zl50114DeviceLiuInit();
extern int ds21455DeviceInit();

extern int  ConfigGetKey(void *CFG_file, void *section, void *key, void *buf);


/*extern  void _ds2155E1Init(int span);*/
#if 0
extern int liuExampleE1(int deviceMode,int streamNum,int PacketSize,int QueueSize,int BufferSize);
extern int wanExampleE1(void);
extern int example1(void);
extern int example2(void);
/*
extern int lld_test(void);
*/
extern int dmaExample(void);
extern int lanlanExample(void);
extern const char * zl5011xGetErrString2(int status);

extern void Setuplanlan();
#endif



/*
extern int liuInitExample();
extern int ds21455InitExample();
*/
static void netw (char *adrs,char * name,int size);
static int optionIsDown(Uint32T addr);
static int optionIsDownW(Uint32T addr,Uint16T data);
static int flashdlWrite(Uint32T addr,Uint16T data);
static int flashGetSectorRange(int size,int * low,int * high);
static int flashEarseSectorRange(Uint32T addr,int low,int high);
static int flashdlCpy(Uint32T src,Uint32T dest,int size);
static int flashdlEarseSector(Uint32T baseadr,int sector);


char ttmp[20];

#define IIIR 0x40000000
void LedinitPortB()
{
	*(vUint16T *)(IIIR+0xABA)|=0x000F;

	*(vUint16T *)(IIIR+0xAC6)&=(0xFFF0);
	return;
}

void LedActivePortB(int span,int active)
{
	if(active == 1)
		*(vUint16T *)(IIIR+0xAC6)|=(0x0001<<span);
	else
		*(vUint16T *)(IIIR+0xAC6)&=(~(0x0001<<span));
	return;
}

void LedinitPortC()
{
	*(vUint16T *)(IIIR+0x960)|=0x0200;

	*(vUint16T *)(IIIR+0x966)|=(0x0200);

	return;
}

void LedActivePortC(int active)
{
	if(active == 1)
		*(vUint16T *)(IIIR+0x966)|=(0x0008);
	else
		*(vUint16T *)(IIIR+0x966)&=(~(0x0008));
	return;
}

void LedInitAll()
{
	LedinitPortB();
	LedinitPortC();
}

void LedActiveAll(int i)
{
	LedActivePortC(i);
	LedActivePortB(0,i);
	LedActivePortB(1,i);
	LedActivePortB(2,i);
	LedActivePortB(3,i);
}

void LedError()
{
	int i=0;
	while(1)
	{
		if(i==0)
			i=1;
		else
			i=0;
		taskDelay(30);
		LedActiveAll(i);
	}

}


void LedActiveSingle()
{
	LedActivePortB(0,1);
	taskDelay(30);
	LedActivePortB(0,0);
	LedActivePortB(1,1);
	taskDelay(30);
	LedActivePortB(1,0);
	LedActivePortB(2,1);
	taskDelay(30);
	LedActivePortB(2,0);
	LedActivePortB(3,1);
	taskDelay(30);
	LedActivePortB(3,0);
	LedActivePortC(1);
	taskDelay(30);
	LedActivePortC(0);
}

static int tftpDownLoadFile( char* host, char* fileName,char * newname)
{
     int  dataFd, total = 0;
     int  errorFd;
     int  num=0;
     int tmp,last=0;
     int * buffhead;
     FILE * fp;
     char buf [1024];
     int status;
	 
    printf("Get file %s from %s\r\nPlease wait ...\r\n",fileName,host); 
     if ((status=tftpXfer (host, 0, fileName, "get", "binary", &dataFd, &errorFd) ) == ERROR)
     {
         printf("Can not establish link to host %s\r\n",host);
         return (ERROR);
      }
	printf("The result of status is %d\r\n",status);
     if((fp = fopen(newname, "w")) == NULL) 
     {
		printf("ERROR Create file for UPLOAD!\r\n");
		return ERROR;
     }
     while ((num = read (dataFd, buf, sizeof (buf))) > 0)
     {
     	if(fwrite(buf,1,num,fp)<num)
	{
		printf("write file error!\r\n");
		return ERROR;
	}
     }
     close (dataFd);
     fclose(fp);
    
    printf("File Transfered Successfully!\r\n " );
     close (errorFd);
     return OK;
}


static int tftpGetFile( char* host, char* fileName, void * buff ,int * maxSize)
{
     int  dataFd, total = 0;
     int  errorFd;
     int  num=0;
     int tmp,last=0;
     int * buffhead;
     char buf [BUFFERSIZE];
    printf("Get file from %s,maxsize=%d\r\nPlease wait ...\r\n",host,*maxSize); 
    buffhead=buff;
     if (tftpXfer (host, 0, fileName, "get", "binary", &dataFd, &errorFd) == ERROR)
     {
         printf("Can not establish link to host %s\r\n",host);
         return (ERROR);
      }
     while ((num = read (dataFd, buf, sizeof (buf))) > 0)
     {
	last=total;
	total += num;
	 if(total>*maxSize)
	 {
		tmp=total-*maxSize;
		num=num-tmp;
		total=total-tmp;
		printf("over flow!total=%d,maxSize=%d,num=%d\r\n",total,*maxSize,num);
		memcpy(buff+last,buf,num);
		break;
	 }
        memcpy(buff+last, buf, num);
	 if(total%10240==0)
	 	printf(".");

     }
     *maxSize=total;
     close (dataFd);
     printf("\r\n");
     if( total >0 )
         printf("File Transfered Successfully!\r\nSave %d to %08x\r\n ",total,(Uint32T)buffhead);
     else
     {
     	printf("File Transfered Failed!\r\n ");
	return ERROR;
     }
     close (errorFd);
     return OK;
}

static int writeflash(Uint32T src,Uint32T addr,int size)
 {
	return flashdlCpy(src, addr, size);
 }

static int MAC2Flash(Uint8T mac[12])
{
	Uint16T tmp[6];
	int i;
	for(i=0;i<6;i++)
		tmp[i]=*(Uint16T *)(mac+2*i);
	printf("the mac address you wang write is:\r\n");
	for(i=0;i<6;i++)
		printf("%04x ",tmp[i]);
	printf("\r\n");

	/*****Earse flash sector for write mac address*****/

	*((vUint16T *)ROM_BASE_ADRS+0x555) = 0xAA;
	*((vUint16T *)ROM_BASE_ADRS+0x2AA) = 0x55;
	*((vUint16T *)ROM_BASE_ADRS+0x555) = 0x80;
	*((vUint16T *)ROM_BASE_ADRS+0x555) = 0xAA;
	*((vUint16T *)ROM_BASE_ADRS+0x2AA) = 0x55;
	*((vUint16T *)(MAC_ADDR_START)) = 0x30;

	/*********flash Earse for MAC write complete******/
	taskDelay(sysClkRateGet()*3);

	/*********write MAC Addr to Flash***************/
	for(i=0;i<6;i++)
	{
		*((vUint16T *)ROM_BASE_ADRS + 0x555) = 0xAA;
		*((vUint16T *)ROM_BASE_ADRS + 0x2AA) = 0x55;
		*((vUint16T *)ROM_BASE_ADRS + 0x555) = 0xA0;	
		*((vUint16T *)(MAC_ADDR_START+2*i)) = tmp[i];
		taskDelay(2);
		tmp[i] = *((vUint16T *)(MAC_ADDR_START+2*i));
	}
	printf("MAC address wirte complete!\r\n");
	return OK;

}

int StrtoHex1(char buf[],Uint8T * tmp)
{
	int status=OK;
	int i;
	memset(tmp,0,6);
	if(buf == NULL)
	{
		printf("buf is NULL!\r\n");
		memset(tmp,0xff,6);
		status=ERROR;
		return status;
	}
	if(strlen(buf)!=12)
	{
		printf("Invalid length!\r\n");
		memset(tmp,0xff,6);
		status=ERROR;
		return status;
	}
	for(i=0;i<12;i++)
	{
		if(buf[i]>='a' && buf[i]<='z')
			tmp[i/2]=((tmp[i/2]<<((i%2)*4)) | (buf[i]-'a'+10));
		else
		if(buf[i]>='0' && buf[i]<='9')
			tmp[i/2]=((tmp[i/2]<<((i%2)*4)) | (buf[i]-'0'));
		else 
		if(buf[i]>='A' && buf[i]<='Z')
			tmp[i/2]=((tmp[i/2]<<((i%2)*4)) | (buf[i]-'A'+10));
		else
		{
			printf("Invalid Data at %d\r\n",i+1);
			memset(tmp,0xff,sizeof(int)*6);
			status=ERROR;
			return status;
		}
		/*printf("buf[%d]=%c,tmp[%d]=%02x\r\n",i,buf[i],i/2,tmp[i/2]);*/
	}
	
		return status;
}


void SetMacAddress()
{
	char tmp[20];
	Uint8T mac[12];
	Uint16T old[6];
	int i;
	for(i=0;i<6;i++)
		old[i]=*(vUint16T *)(MAC_ADDR_START+2*i);
	while(1)
	{
		memset(tmp,0,sizeof(tmp));
		printf("The MAC addr of lan is[%04x%04x%04x]:",old[0],old[1],old[2]);
		scanf("%s",tmp);
		if(StrtoHex1(tmp,mac)==OK)
			break;
		else
			continue;
	}

	while(1)
	{
		memset(tmp,0,sizeof(tmp));
		printf("The MAC addr of UpLink is[%04x%04x%04x]:",old[3],old[4],old[5]);
		scanf("%s",tmp);
		if(StrtoHex1(tmp,(mac+6))==OK)
			break;
		else
			continue;
	}
	MAC2Flash(mac);

}

#if 0
int GetStreamNum(void)
{
	int streamNum=0;
	while(1)
	{
		printf("How many stream you want use(1,2,3,4):");
		scanf("%d",&streamNum);
		if(streamNum<1 || streamNum>4)
			printf("Invalid stream number!\r\n");
		else
			break;
	}
	return streamNum;
}



void test2(int mode,int par[4])
{
	switch(mode)
	{
		case 0:
     			printf("resule is %s\r\n",zl5011xGetErrString2(liuExampleE1(0,par[0],par[1],par[2],par[3])));
			break;

		case 1:
			printf("resule is %s\r\n",zl5011xGetErrString2(liuExampleE1(1,par[0],par[1],par[2],par[3])));
       		break;

		case 3:
			printf("resule is %s\r\n",zl5011xGetErrString2(liuExampleE1(2,par[0],par[1],par[2],par[3])));
       		break;

		case 2:
	   	       printf("resule is %s\r\n",zl5011xGetErrString2(wanExampleE1()));
			break;

		default:
			printf("undefined value\r\n");
	}
	
	printf("ZL50114 Complete!\r\n");

}

void test1()
{
/*
Ledinit();
	_ds2155E1Init(0);
*/

       example1();
       example2();
     
/*taskSpawn ("tTest1", 120, 8,
		20000, (FUNCPTR) test2,
		0,0,0,0,0,0,0,0,0,0);
	 printf("task2 OK\r\n");
*/
	printf("ZL50114 Complete!\r\n");
}

void test3(int span)
{
	_ds2155E1Init(span);

}

void test5()
{
	while(1)
	{
		ds21455IntsDeal();
		taskDelay(sysClkRateGet());
	}

}

void test4()
{
	taskSpawn ("tTest", 120, 8,
		20000, (FUNCPTR) test5,
		0,0,0,0,0,0,0,0,0,0);
	 printf("Interrupt  OK\r\n");

}

int QueueSize(int n)
{
	int i=0;
	int result=1;
	
	if(n<0)
		return -1;
	for(i=0;i<n;i++)
		result=result*2;
	return result;

}


int * GetPar(int par[])
{

	char ch;
	double tmp;
	{
		while(1)
		{
			printf("How many Stream you want to use[1-4]:");
			scanf("%d",par);
			getchar();
			if((*par)<1 || (*par)>4)
				printf("Invalid Stream Number!\r\n");
			else
				break;
		}

		while(1)
		{
			printf("The packet size you want is(n*32)[1-46]:");
			scanf("%d",(par+1));
			if((*(par+1))<1 || (*(par+1))>46)
				printf("Invalid packet size(32-1500)!\r\n");
			else
				break;
		}

		while(1)
		{
			printf("The Queue size you want is(2^n)[1-7]:");
			scanf("%d",(par+2));
			if((*(par+2))<1 || (*(par+2))>7)
				printf("Invalid Queue size(2-128)!\r\n");
			else
				break;
		}

		
		while(1)
		{
			printf("The Jitter Buffer Size you want is(125*n)[1-1600]:");
			scanf("%d",(par+3));
			if((*(par+3))<1 || (*(par+3))>1600)
				printf("Invalid Jitter Buffer Size(125-2000000)!\r\n");
			else
				break;
		}

	}
	printf("Stream Number = %d\r\n",*par);
	printf("Packet Size = %d\r\n",(*(par+1))*32);
	printf("Queue Size = %d\r\n",QueueSize(*(par+2))); 

	printf("Jitter Buffer Size = %d %c s\r\n",125*(*(par+3)),230);
/*
		*(par)=4;
		*(par+1)=20;
		*(par+2)=7;
*/	

	return par;
}

void lanlanTest()
{
Setuplanlan();
}
#endif

int testa()
{
	FILE *fp;
	fp=fopen("/agent/GWM7040.bin","r");
	if(fp!=NULL)
		printf("OK\r\n");
	fclose(fp);
	return 0;
}

#if 0

int str2SubNet(char * buf,Uint32T *NetMask)
{
	int status = OK;
	int m[4];

	sscanf(buf,"%d.%d.%d.%d",m,m+1,m+2,m+3);
	*NetMask = (m[0]<<24)|(m[1]<<16)|(m[2]<<8)|m[3];
	return status;

}

int sysSetInterfaceIpSubnet()
{
	int status = OK;
	char section[20],key[20];
	Uint32T NetMask;
	memset(key,0,sizeof(key));
	status = ConfigGetKey("/agent/GWM7040.BIN","TDMoIP","GWM7040_MANA_IP_ADDR",key);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -