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

📄 flashcode.c

📁 CCS下对c6416DSP开发板EPROM的烧写程序
💻 C
字号:
/********************************************************************************/
/* flashcode.c									*/ 
/* Written by: Kyle Castille							*/
/* Updated by: Michael Haag (6/27/01)						*/	                                               
/* This program will create a dummy data buffer with an incrementing count	*/
/* in internal memory, and then program this data to the AM29LV800-90 Flash	*/
/* which is a 1M x 8/512k x 16, 90 ns Flash memory.				*/
/* 										*/
/* This program assumes that the ARDY interface is used, so no software		*/
/* checking is done to detect end of operation for erase or program		*/
/*										*/
/********************************************************************************/
#define CHIP_6416 1

#define		CE1_ADDRS	0x64000000
#define		INT_MEM		0x00000000
#define 	FLASH_ADDRS		CE1_ADDRS
#define 	SRC_ADDRS		INT_MEM
#define 	LENGTH			0x400
#define 	TRUE			1
#define 	FALSE			0
#include <stdlib.h>
#include <stdio.h>
#include <csl.h>
#include <csl_emifb.h>
#include <csl_emifbhal.h>
extern EMIFB_Config config; 
void load_source (short * source, int num_words);
void erase_flash(int * flash_addrs);
void program_flash(short * source, int * flash_addrs, int num_words);



/****************************************************************************/
/* emif_config :Routine to configure the Emif for operation with 			*/
/*		AM29LV800-90 at CE1.  This routine sets the CE1 control register	*/
/*		for a 32 bit asynchronous memory interface with the following 		*/
/*		parameters:								*/
/*		Mtype = 010 (32-bit async memory)					*/
/*		Read Setup/Strobe/Hold = 1/21/3						*/
/*		Write Setup/Strobe/Hold = 2/13/3					*/
/*											*/
/****************************************************************************/


void
main(){
	int * flash_ptr = (int *)FLASH_ADDRS;
	short * src_ptr = (short *)SRC_ADDRS;

	/* initialize the CSL library */
 	 CSL_init();

	EMIFB_config(&config);
	load_source(src_ptr, LENGTH);
	erase_flash(flash_ptr);
	program_flash(src_ptr, flash_ptr, LENGTH);
	printf("Successful erase and program!!!");
}

/****************************************************************************/
/* load_source : Routine to load the source memory with data.  This routine	*/
/*		loads an incrementing count into the source memory for  	*/
/*		demonstration purposes.					     	*/
/* Inputs:									*/
/*	source_ptr	: 	Address to be used as the source buffer		*/
/*	length   	: 	Length to be programmed				*/
/*										*/
/****************************************************************************/


EMIFB_Config config = {
	/* Create Global Control Register field */
0x00002060,
0x02a08a00,
0x02a08a00,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0x00000000
};

void load_source(short * source_ptr, int length)
{
	int i;

	for (i = 0; i < length; i ++){
		* source_ptr++ = i;
	}
}

/****************************************************************************/
/* erase_flash : Routine to erase entire FLASH memory AM29LV800 (1M x 8bit/	*/
/*		512k x 16bit)							*/
/* Inputs:									*/
/*	flash_ptr: Address of the FLASH PEROM			           	*/
/* 										*/
/****************************************************************************/
	
void erase_flash(int * flash_ptr)
{
	/* Control addresses are left shifted so that 		*/
	/*  they appear correctly on the EMIF's EA[19:2]	*/
	/* Byte address << 2 == Word Address				*/

	int * ctrl_addr1 = (int *) ((int)flash_ptr + (0x555 << 2));
	int * ctrl_addr2 = (int *) ((int)flash_ptr + (0x2aa << 2));;

	* ctrl_addr1 = 0x00aa;	/* Erase sequence writes to addr1 and addr2 	*/
	* ctrl_addr2 = 0x0055;	/*  with this data 								*/
	* ctrl_addr1 = 0x0080;
	* ctrl_addr1 = 0x00aa;
	* ctrl_addr2 = 0x0055;
	* ctrl_addr1 = 0x0010;
}

/****************************************************************************/
/* program_flash: Routine to program FLASH AM29LV800				*/
/* Inputs:									*/
/*	flash_ptr	: Address of the FLASH  				*/
/*	source_ptr	: Address of the array containing the code to program 	*/
/* 	length		: Length to be programmed				*/
/*										*/
/****************************************************************************/

void program_flash(short * source_ptr, int * flash_ptr, int length)
{
	int i;

	/* Control addresses are left shifted so that 	 	*/
	/*  they appear correctly on the EMIF's EA[19:2]	*/
	/* Byte address << 2 == Word Address		    	*/
	int * ctrl_addr1 = (int *) ((int)flash_ptr + (0x555 << 2));
	int * ctrl_addr2 = (int *) ((int)flash_ptr + (0x2aa << 2));;
		
	for (i = 0; i < length; i++){

		* ctrl_addr1 = 0x00aa;
		* ctrl_addr2 = 0x0055;
		* ctrl_addr1 = 0x00a0;

		* flash_ptr++ = * source_ptr++;
	}
}

⌨️ 快捷键说明

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