/*******************************************************************************
* Copyright (C) 2019 China Micro Semiconductor Limited Company. All Rights Reserved.
*
* This software is owned and published by:
* CMS LLC, No 2609-10, Taurus Plaza, TaoyuanRoad, NanshanDistrict, Shenzhen, China.
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with CMS
* components. This software is licensed by CMS to be adapted only
* for use in systems utilizing CMS components. CMS shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. CMS is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/

/****************************************************************************/
/** \file main.c
**
**	History:
**	
*****************************************************************************/
/****************************************************************************/
/*	include files
*****************************************************************************/
#include "CMS32F035x.h"

/****************************************************************************/
/*	Local pre-processor symbols/macros('#define')
*****************************************************************************/

/****************************************************************************/
/*	Global variable definitions(declared in header file with 'extern')
*****************************************************************************/

/****************************************************************************/
/*	Local type definitions('typedef')
*****************************************************************************/

/****************************************************************************/
/*	Local variable  definitions('static')
*****************************************************************************/
uint32_t  APROM_DataTab[20] ={0};
uint32_t  APROM_StartAddr = 0xFC00;		
uint32_t  APROM_StopAddr = 0xFFFFF;

uint32_t  DATA_DataTab[20] ={0};
uint32_t  DATA_StartAddr = 0x1C000000;		
uint32_t  DATA_StopAddr = 0x1C0003FF;

uint32_t  DataBuf[20] ={0};
uint16_t  CRCResult=0;

/****************************************************************************/
/*	Local function prototypes('static')
*****************************************************************************/



/****************************************************************************/
/*	Function implementation - global ('extern') and local('static')
*****************************************************************************/

/*****************************************************************************
 ** \brief	 main
 **
 ** \param [in]  none   
 **
 ** \return 0
*****************************************************************************/
int main(void)
{		
	uint32_t  Count;
	
 	SYS_DisableIOCFGProtect();			/*关闭IOCONFIG写保护*/
	SYS_DisableGPIO0Protect();			/*关闭GPIO0的相关寄存器写保护*/
	SYS_DisableGPIO1Protect();			/*关闭GPIO1的相关寄存器写保护*/
	SYS_DisableGPIO2Protect();			/*关闭GPIO2的相关寄存器写保护*/
	SYS_DisableGPIO3Protect();			/*关闭GPIO3的相关寄存器写保护*/
	SYS_DisableGPIO4Protect();			/*关闭GPIO4的相关寄存器写保护*/
	SYS_DisableGPIO5Protect();			/*关闭GPIO5的相关寄存器写保护*/	
	
	SYS_ConfigHSI(SYS_CLK_HSI_48M);		/*设置内部高速时钟为48Mhz*/
	SYS_EnableHSI();					/*开启高速时钟*/
	SYS_ConfigAHBClock(SYS_CLK_SEL_HSI,SYS_CLK_DIV_1);	/*设置AHB时钟为高速时钟的1分频*/
	SYS_ConfigAPBClock(AHB_CLK_DIV_1);					/*设置APB时钟为AHB时钟的1分频*/
	SystemCoreClockUpdate();						/*刷新SystemCoreCLk、SystemAPBClock变量值*/
		

	Count =0;	
	for(Count=0; Count<20;Count++)
	{
		APROM_DataTab[Count] = Count+1;	
	}
		
	/*APROM 擦除*/
	FMC_ErasePage(APROM_StartAddr);
	/*APROM 写*/	
	for(Count=0; Count<20;Count++)
	{
		FMC_Write(APROM_StartAddr + Count*4 , APROM_DataTab[Count]);	
	}	
	/*APROM 读*/		
	for(Count=0; Count<20;Count++)
	{
		DATA_DataTab[Count] = FMC_Read(APROM_StartAddr + Count*4);	
	}	
	
	/*DATA 擦除*/
	FMC_ErasePage(DATA_StartAddr);	
	
	/*DATA 写*/
	for(Count=0; Count<20;Count++)
	{
		FMC_Write(DATA_StartAddr + Count*4 , DATA_DataTab[Count]);	
	}	
	
	/*DATA 读*/
	for(Count=0; Count<20;Count++)
	{
		DataBuf[Count] = FMC_Read(DATA_StartAddr + Count*4);		
	}	
		
	/*CRC校验（只适用于APROM区）*/		
	CRCResult = FMC_CRC(APROM_StartAddr, APROM_StartAddr);
	
	
	while(1)
	{	
		;
	}	
	
}
















