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

📄 sst25vf040b.c

📁 TMS320VC5509A烧写片外串行FLASH的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	set_cs(0);				 /* enable device */	send_byte(0x9F);		 /* send JEDEC ID command (9Fh) */    temp = (temp | get_byte()) << 8;	 /* receive byte */	temp = (temp | get_byte()) << 8;		temp = (temp | get_byte()); 	 /* temp value = 0xBF258D */	set_cs(1);				/* disable device */	return temp;}/************************************************************************//* PROCEDURE:	flash_read_byte													*//*																		*/		/* This procedure reads one address of the device.  It will return the 	*//* byte read in variable byte.											*//*																		*//*																		*//*																		*//* Input:																*//*		addr:	Destination Address 000000H - 07FFFFH					*//*      																*//*																		*//* Returns:																*//*		byte															*//*																		*//************************************************************************/unsigned char flash_read_byte(unsigned long addr) {	unsigned char byte = 0;		set_cs(0);				/* enable device */	send_byte(0x03); 		/* read command */	send_byte(((addr & 0xFFFFFF) >> 16));	/* send 3 address bytes */	send_byte(((addr & 0xFFFF) >> 8));	send_byte(addr & 0xFF);	byte = get_byte();	set_cs(1);				/* disable device */    	return byte;			/* return one byte read */}/************************************************************************//* PROCEDURE:	flash_read_nbyte										*//*																		*/		/* This procedure reads multiple addresses of the device and stores		*//* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*//*																		*//* Input:																*//*		addr:		Destination Address 000000H - 07FFFFH				*//*      pd:         Point to data                                       *//*      num     	Number of bytes to read	(max = 128)					*//*																		*//* Returns:																*//*		Nothing															*//*																		*//************************************************************************/void flash_read_nbyte(unsigned long addr, unsigned char *pd, unsigned long num){	unsigned long i = 0;    	set_cs(0);					/* enable device */	send_byte(0x03); 			/* read command */	send_byte(((addr & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	send_byte(((addr & 0xFFFF) >> 8));	send_byte(addr & 0xFF);	for (i = 0; i < num; i++)		/* read until no_bytes is reached */	{		*pd = get_byte();	/* receive byte and store at address 80H - FFH */        pd++;	}	set_cs(1);					/* disable device */}/************************************************************************//* PROCEDURE:	flash_fast_read_byte									*//*																		*/		/* This procedure reads one address of the device.  It will return the 	*//* byte read in variable byte.											*//*																		*//*																		*//*																		*//* Input:																*//*		addr:	Destination Address 000000H - 07FFFFH					*//*      																*//*																		*//* Returns:																*//*		byte															*//*																		*//************************************************************************/unsigned char flash_fast_read_byte(unsigned long addr) {	unsigned char byte = 0;		set_cs(0);				/* enable device */	send_byte(0x0B); 		/* read command */	send_byte(((addr & 0xFFFFFF) >> 16));	/* send 3 address bytes */	send_byte(((addr & 0xFFFF) >> 8));	send_byte(addr & 0xFF);	send_byte(0xFF);		/*dummy byte*/	byte = get_byte();	set_cs(1);				/* disable device */    	return byte;			/* return one byte read */}/************************************************************************//* PROCEDURE:	flash_fast_read_nbyte									*//*																		*/		/* This procedure reads multiple addresses of the device and stores		*//* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*//*																		*//* Input:																*//*		addr:		Destination Address 000000H - 07FFFFH               *//*      *pd:        Piont to data                                       *//*      num:    	Number of bytes to read	(max = 128)					*//*																		*//* Returns:																*//*		Nothing															*//*																		*//************************************************************************/void flash_fast_read_nbyte(unsigned long addr, unsigned char *pd, unsigned long num){	unsigned long i = 0;    	set_cs(0);					/* enable device */	send_byte(0x0B); 			/* read command */	send_byte(((addr & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	send_byte(((addr & 0xFFFF) >> 8));	send_byte(addr & 0xFF);	send_byte(0xFF);			/*dummy byte*/	for (i = 0; i < num; i++)		/* read until no_bytes is reached */	{		*pd = get_byte();	/* receive byte and store at address 80H - FFH */        pd++;	}	set_cs(1);					/* disable device */}/************************************************************************//* PROCEDURE:	flash_write_byte										*//*																		*//* This procedure programs one address of the device.					*//* Assumption:  Address being programmed is already erased and is NOT	*//*				block protected.										*//*																		*//*																		*//*																		*//* Input:																*//*		addr:		Destination Address 000000H - 07FFFFH				*//*		byte:		byte to be programmed								*//*      																*//*																		*//* Returns:																*//*		Nothing															*//*																		*//************************************************************************/void flash_write_byte(unsigned long addr, unsigned char byte){    wait_busy();    flash_write_enable();       /* Enable write */    	set_cs(0);					/* enable device */	send_byte(0x02); 			/* send Byte Program command */	send_byte(((addr & 0xFFFFFF) >> 16));	/* send 3 address bytes */	send_byte(((addr & 0xFFFF) >> 8));	send_byte(addr & 0xFF);	send_byte(byte);			/* send byte to be programmed */	set_cs(1);					/* disable device */}/************************************************************************//* PROCEDURE:	flash_write_nword										*//*																		*//* This procedure programs consecutive addresses of 2 bytes of data into*//* the device:  1st data byte will be programmed into the initial		*//* address [A23-A1] and with A0 = 0.  The 2nd data byte will be be		*//* programmed into initial address [A23-A1] and with A0  = 1.  This		*//* is used to to start the AAI process.  It should be followed by 		*//* Auto_Add_IncB.														*//* Assumption:  Address being programmed is already erased and is NOT	*//*				block protected.										*//*																		*//*																		*//* Note: Only RDSR command can be executed once in AAI mode with SO  	*//* 	 disable to output RY/BY# status.  Use WRDI to exit AAI mode 		*//*	 unless AAI is programming the last address or last address of		*//* 	 unprotected block, which automatically exits AAI mode.				*//*																		*//* Input:																*//*		addr:		Destination Address 000000H - 07FFFFH				*//*		pword:		Point of word to be programmed   					*//*      num:		Num of pword            							*//*																		*//* Returns:																*//*		Nothing															*//*																		*//************************************************************************/void flash_write_nword(unsigned long addr, unsigned short *pword, unsigned long num){    unsigned char byte1, byte2;    wait_busy();    flash_write_enable();       /* Enable write */        byte1 = *pword & 0xff;    byte2 = *pword >> 8;    	set_cs(0);					/* enable device */	send_byte(0xAD);			/* send AAI command */	send_byte(((addr & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	send_byte(((addr & 0xFFFF) >> 8));	send_byte(addr & 0xFF);	send_byte(byte1);			/* send 1st byte to be programmed */		send_byte(byte2);			/* send 2nd byte to be programmed */	set_cs(1);					/* disable device */    *pword++;    num--;    while (num>0)    {        wait_busy_aai();        /* Wait not busy */        byte1 = *pword & 0xff;        byte2 = *pword >> 8;        set_cs(0);					/* enable device */        send_byte(0xAD);			/* send AAI command */        send_byte(byte1);			/* send 1st byte to be programmed */	        send_byte(byte2);			/* send 2nd byte to be programmed */        set_cs(1);					/* disable device */        *pword++;        num--;    }    wait_busy_aai();    set_cs(0);    send_byte(0x04);            /* Finish aai write */    set_cs(1);}/************************************************************************//* PROCEDURE: flash_chip_erase											*//*																		*//* This procedure erases the entire Chip.								*//*																		*//* Input:																*//*		None															*//*																		*//* Returns:																*//*		Nothing															*//************************************************************************/void flash_chip_erase(void){    wait_busy();    flash_write_enable();    	set_cs(0);					/* enable device */	send_byte(0x60);			/* send Chip erase command (60h or C7h) */	set_cs(1);					/* disable device */}/************************************************************************//* PROCEDURE: flash_sector_erase										*//*																		*//* This procedure Sector erases the Chip.								*//*																		*//* Input:																*//*		addr:		Destination Address 000000H - 07FFFFH				*//*																		*//* Returns:																*//*		Nothing															*//************************************************************************/void flash_sector_erase(unsigned long addr){    wait_busy();    flash_write_enable();    	set_cs(0);					/* enable device */	send_byte(0x20);			/* send Sector erase command */	send_byte(((addr & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	send_byte(((addr & 0xFFFF) >> 8));	send_byte(addr & 0xFF);	set_cs(1);					/* disable device */}/************************************************************************//* PROCEDURE: flash_block_erase_32k										*//*																		*//* This procedure block erases 32 KByte of the Chip.					*//*																		*//* Input:																*//*		addr:		Destination Address 000000H - 07FFFFH				*//*																		*//* Returns:																*//*		Nothing															*//************************************************************************/void flash_block_erase_32k(unsigned long addr){    wait_busy();    flash_write_enable();    	set_cs(0);					/* enable device */	send_byte(0x52);			/* send 32 KByte block erase command */	send_byte(((addr & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	send_byte(((addr & 0xFFFF) >> 8));	send_byte(addr & 0xFF);	set_cs(1);					/* disable device */}	/************************************************************************//* PROCEDURE: flash_block_erase_64K										*//*																		*//* This procedure block erases 64 KByte of the Chip.					*//*																		*//* Input:																*//*		addr:		Destination Address 000000H - 07FFFFH				*//*																		*//* Returns:																*//*		Nothing															*//************************************************************************/void flash_block_erase_64k(unsigned long addr){    wait_busy();    flash_write_enable();    	set_cs(0);					/* enable device */	send_byte(0xD8);			/* send 64KByte block erase command */	send_byte(((addr & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	send_byte(((addr & 0xFFFF) >> 8));	send_byte(addr & 0xFF);	set_cs(1);					/* disable device */}

⌨️ 快捷键说明

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