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

📄 download.c

📁 44b0x开发板源代码
💻 C
字号:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "..\inc\option.h"
#include "..\inc\def.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\flash.h"
#include "..\inc\download.h"
#include "..\inc\file.h"
#include "..\inc\usb.h"
extern U8 tx_buf[16*1024];
extern U8 Page_Buf[528];
extern unsigned char *downPt;
extern unsigned int fileSize;
static void (*run)(void)=(void (*)(void))DOWNLOAD_ADDRESS;
U8 DEMO1_CODE[]     ={'D','E','M','O','1',' ',' ',' ','B','I','N'};
U8 DEMO2_CODE[]     ={'D','E','M','O','2',' ',' ',' ','B','I','N'};
U8 DEMO3_CODE[]     ={'D','E','M','O','3',' ',' ',' ','B','I','N'};
U8 SYSTEM_CODE[]     ={'S','Y','S','T','E','M',' ',' ','B','I','N'};
U8 CHINESE_LIB_NAME[]={'H','Z','K','1','6',' ',' ',' ','D','A','T'};
U8 CHINESE_LIB[8704][32];	//8704*32=272KB=17 BLOCK


void LOAD_DEMO1_CODE(void)
{
	U32 i,POINTER,root_location;
	root_location=find_file(DEMO1_CODE);
	
	//get the file first cluster//
	current_block=root_buf[root_location][27]*256+root_buf[root_location][26];
	
	if(root_location==FILE_NO_FOUND)
		Uart_Printf("\nDEMO1.BIN no found!");
	else
	{
		Uart_Printf("\n%d",current_block);
		Uart_Printf("\nLoading DEMO1.BIN...");
		while(1)
		{
			read_file(tx_buf);
			for(i=0;i<BLOCK_SIZE;i++)
			{
				*((unsigned char *)(DOWNLOAD_ADDRESS+POINTER))=tx_buf[i];
				POINTER++;
			}
		current_block=Page_Buf[512+14]*256+Page_Buf[512+15];
		if(current_block==LAST_BLOCK)
			break;	
		}
		Uart_Printf("\nDEMO1.BIN loading finished!");
		//disable usb//
		write_usb(0x00,0x01);	//写 0x01 到 MCNTRL//
		//INTOC(1-0)=00	:禁止中断输出      //
		//NAT=0			:禁止被USB总线检测 //
		//VEG=0			:禁止内部3.3V稳压  //
		//SRST=1		:进行软件复位      //
		run();
	}
}
void LOAD_DEMO2_CODE(void)
{
	U32 i,POINTER,root_location;
	root_location=find_file(DEMO2_CODE);
	
	//get the file first cluster//
	current_block=root_buf[root_location][27]*256+root_buf[root_location][26];
	
	if(root_location==FILE_NO_FOUND)
		Uart_Printf("\nDEMO2.BIN no found!");
	else
	{
		Uart_Printf("\n%d",current_block);
		Uart_Printf("\nLoading DEMO2.BIN...");
		while(1)
		{
			read_file(tx_buf);
			for(i=0;i<BLOCK_SIZE;i++)
			{
				*((unsigned char *)(DOWNLOAD_ADDRESS+POINTER))=tx_buf[i];
				POINTER++;
			}
		current_block=Page_Buf[512+14]*256+Page_Buf[512+15];
		if(current_block==LAST_BLOCK)
			break;	
		}
		Uart_Printf("\nDEMO2.BIN loading finished!");
		//disable usb//
		write_usb(0x00,0x01);	//写 0x01 到 MCNTRL//
		//INTOC(1-0)=00	:禁止中断输出      //
		//NAT=0			:禁止被USB总线检测 //
		//VEG=0			:禁止内部3.3V稳压  //
		//SRST=1		:进行软件复位      //
		run();
	}
}
void LOAD_DEMO3_CODE(void)
{
	U32 i,POINTER,root_location;
	root_location=find_file(DEMO3_CODE);
	
	//get the file first cluster//
	current_block=root_buf[root_location][27]*256+root_buf[root_location][26];
	
	if(root_location==FILE_NO_FOUND)
		Uart_Printf("\nDEMO3.BIN no found!");
	else
	{
		Uart_Printf("\n%d",current_block);
		Uart_Printf("\nLoading DEMO3.BIN...");
		while(1)
		{
			read_file(tx_buf);
			for(i=0;i<BLOCK_SIZE;i++)
			{
				*((unsigned char *)(DOWNLOAD_ADDRESS+POINTER))=tx_buf[i];
				POINTER++;
			}
		current_block=Page_Buf[512+14]*256+Page_Buf[512+15];
		if(current_block==LAST_BLOCK)
			break;	
		}
		Uart_Printf("\nDEMO3.BIN loading finished!");
		//disable usb//
		write_usb(0x00,0x01);	//写 0x01 到 MCNTRL//
		//INTOC(1-0)=00	:禁止中断输出      //
		//NAT=0			:禁止被USB总线检测 //
		//VEG=0			:禁止内部3.3V稳压  //
		//SRST=1		:进行软件复位      //
		run();
	}
}
void LOAD_SYSTEM_CODE(void)
{
	U32 i,POINTER,root_location;
	root_location=find_file(SYSTEM_CODE);
	
	//get the file first cluster//
	current_block=root_buf[root_location][27]*256+root_buf[root_location][26];
	
	if(root_location==FILE_NO_FOUND)
		Uart_Printf("\nSYSTEM.BIN no found!");
	else
	{
		Uart_Printf("\n%d",current_block);
		Uart_Printf("\nLoading SYSTEM.BIN...");
		while(1)
		{
			read_file(tx_buf);
			for(i=0;i<BLOCK_SIZE;i++)
			{
				*((unsigned char *)(DOWNLOAD_ADDRESS+POINTER))=tx_buf[i];
				POINTER++;
			}
		current_block=Page_Buf[512+14]*256+Page_Buf[512+15];
		if(current_block==LAST_BLOCK)
			break;	
		}
		Uart_Printf("\nSYSTEM.BIN loading finished!");
		//disable usb//
		write_usb(0x00,0x01);	//写 0x01 到 MCNTRL//
		//INTOC(1-0)=00	:禁止中断输出      //
		//NAT=0			:禁止被USB总线检测 //
		//VEG=0			:禁止内部3.3V稳压  //
		//SRST=1		:进行软件复位      //
		run();
	}
}
void LOAD_HZK(void)
{
	U32 i,POINTER,root_location;
	root_location=find_file(CHINESE_LIB_NAME);
	
	//get the file first cluster//
	current_block=root_buf[root_location][27]*256+root_buf[root_location][26];
	
	if(root_location==FILE_NO_FOUND)
		Uart_Printf("\nHZK is not found!");
	else
	{
		Uart_Printf("\nHZK's first Block/Cluster is at %d",current_block);
		Uart_Printf("\n   Loading HZK,please wait...");
		while(1)
		{
			read_file(tx_buf);
			for(i=0;i<BLOCK_SIZE;i++)
			{
				CHINESE_LIB[POINTER/32][POINTER%32]=tx_buf[i];
				POINTER++;
			}
		current_block=Page_Buf[512+14]*256+Page_Buf[512+15];
		if(current_block==65535)
			break;	
		}
		Uart_Printf("\nHZK loading finished!");
	}
}

⌨️ 快捷键说明

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