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

📄 example_dps2812m_flash.c.bak

📁 TMS320F2812驱动flash程序
💻 BAK
字号:
/* =================================================================================
File name:       	Example_DPS2812M_EXTRAM.c                   
                    
Originator:				SEED R&D Group
		
Description: 
                  Example Program That Executes From XINTF (assumes MPNMC = 1)
                  As supplied, this project is configured for "boot from XINTF Zone 7" 
                  operation. 
  
                  XMP/MCn pin = 1
  
                  Map the region for XINTF Zone 7 as RAM in Code Composer
                 (Refer to the F2812.gel file supplied with CCS Studio) 
                 
                 This example configures CPU Timer0 and increments
                 a counter each time the timer asserts an interrupt.
 
                 Watch Variables:
                  CpuTimer0.InterruptCount
                  BackGroundCounter
=====================================================================================
 History:
-------------------------------------------------------------------------------------
 10-20-2005		Release	Rev 1.0         Jijunhui                                          
------------------------------------------------------------------------------*/

// Step 0: Include required header files:
//         DSP281x_Device.h: device specific definitions #include statements for
//         all of the peripheral .h definition files.

#include "DSP281x_Device.h"     // DSP281x Headerfile Include File
#include "DSP281x_Examples.h"   // DSP281x Examples Include File
#include "Examples_DPS2812M_FLASH.h"


void main(void)
{
	Uint32 LoopVar;
    //-----------------------------------------------------------------------
    // Step 1 to Step 5 should be followed in all designs:
    //
    // Step 1: Disable and clear all CPU interrupts:
       DINT;
       IER = 0x0000;
       IFR = 0x0000;

    // Step 2. Initialize System Control registers, PLL, WatchDog, Clocks to default state:
    //         This function is found in the DSP281x_SysCtrl.c file.
    InitSysCtrl();

    // Step 3. Select GPIO for the device or for the specific application:
    //         This function is found in the DSP281x_Gpio.c file.
    // InitGpio();  // Not required for this example

    // Step 4. Initialize PIE to known state (control registers and vector table):
    //         The PIE vector table is initialized with pointers to shell Interrupt 
    //         Service Routines (ISR). The shell routines are found in DSP281x_DefaultIsr.c.
    //         Insert user specific ISR code in the appropriate shell ISR routine in 
    //         the DSP281x_DefaultIsr.c file.
    //
    //         Initialize Pie Control Registers To Default State:
    //         This function is found in the DSP281x_PieCtrl.c file.
    InitXintf();

    ERTM;										// Enable Global realtime debug DBGM

    for(LoopVar = 0; LoopVar < SRAM_LENGTH; LoopVar++)
	{
		sram_data[LoopVar] = LoopVar;
	}
	for(LoopVar = 0;  LoopVar < SRAM_LENGTH; LoopVar++)
	{
		if(sram_data[LoopVar] != LoopVar)
		{
			good_flag = 0;
			break;
		}
		good_flag = 1;
	}
	if(good_flag == 1)
	{
		for(;;);
	}
	else
	{
		for(;;);
	}
} 	

/*********************************************************************
	函数名:	unsigned int flash_erase(unsigned long addr,unsigned int type)
	目的:		FLASH擦除
	输入:		addr:	需要擦除FLASH的首地址
			type:	擦除类型
			0x50	块擦除
			0x30	段擦除
			0x10	芯片擦除
	输出:		判断擦除是否成功
			1	成功
			0	失败
*********************************************************************/

unsigned int flash_erase(unsigned long addr,unsigned int type)
{
	unsigned long i,j;
	*FLASH_5555 = FLASH_UL1;	//first
	*FLASH_2AAA = FLASH_UL2;	//second
	*FLASH_5555 = FLASH_UL3;	//third
	*FLASH_5555 = FLASH_UL4;
	*FLASH_2AAA = FLASH_UL5;
	switch(type)
	{
		case 0x50:		//block erase
			*(unsigned int *)addr = type;
			while((*(unsigned int *)addr & 0x80) != 0x80);
			for(i = 0; i < BLOCK_SIZE; i++)
			{
				if(*(unsigned int *)(addr + i) != 0xffff)
				{
					j = 0;
					break;
				}
			}
			j = 1;
			break;
		
		case 0x30:		//sector erase
			*(unsigned int *)addr = type;
			while((*(unsigned int *)addr & 0x80) != 0x80);
			for(i = 0; i < SECTOR_SIZE; i++)
			{
				if(*(unsigned int *)(addr + i) != 0xffff)
				{
					j = 0;
					break;
				}
			}
			j = 1;
			break;
			
		case 0x10:		//chip erase
			*FLASH_5555 = type;
			while((*FLASH_5555 & 0x80) != 0x80);
			for(i = 0; i < CHIP_SIZE; i++)
			{
				if(*(unsigned int *)(addr + i) != 0xffff)
				{
					j = 0;
					break;
				}
			}
			j = 1;
			break;
		
		default:
			break;
	}
	return (j);
}

/*********************************************************************
	函数名:	void flash_writes(unsigned long addr,unsigned int data)
	目的:		FLASH写
	输入:		addr:	需要写FLASH的地址
			data:	写入FLASH的数据
	输出:		无
*********************************************************************/

void flash_writes(unsigned long addr,unsigned int data)
{
	*FLASH_5555 = FLASH_UL1;
	*FLASH_2AAA = FLASH_UL2;
	*FLASH_5555 = FLASH_PROGRAM;
	*(unsigned int *)addr = data;
	while(*(unsigned int *)addr != data);
}

/*********************************************************************
	函数名:	void flash_writem(unsigned long addr,unsigned int *ptr,unsigned long length)
	目的:		FLASH连续写
	输入:		addr:	需要写FLASH的首地址
			ptr:	写入FLASH的数据指针
			length:	写入FLASH的数据长度
	输出:		无
*********************************************************************/

void flash_writem(unsigned long addr,unsigned int *ptr,unsigned long length)
{
	unsigned long i;
	for(i  = 0; i < length; i++)
	{
		flash_writes(addr+i,*(ptr+i));
	}
}

/*********************************************************************
	函数名:	unsigned int flash_reads(unsigned long addr)
	目的:		FLASH读
	输入:		addr:	需要读FLASH的首地址
	输出:		从FLASH读出的数据
*********************************************************************/

unsigned int flash_reads(unsigned long addr)
{
	return (*(unsigned int *)addr);
}

/*********************************************************************
	函数名:	void flash_readm(unsigned long addr,unsigned int *ptr,unsigned long length)
	目的:		FLASH连续读
	输入:		addr:	需要读FLASH的首地址
			ptr:	读FLASH的数据指针
			length:	读FLASH的数据长度
	输出:		无
*********************************************************************/

void flash_readm(unsigned long addr,unsigned int *ptr,unsigned long length)
{
	unsigned long i;
	for(i = 0; i < length; i++)
	{
		*(ptr + i) = flash_reads(addr+i);
	}
}

⌨️ 快捷键说明

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