/******************************************************************************
 * @file     main.c
 * @brief    Main program body
 * @version  V1.8.0
 * @date     31-Dec-2021
 *
 * @note
 * Copyright (C) 2021 Spintrol Limited Corporation. All rights reserved.
 *
 * @attention
 * THIS SOFTWARE JUST PROVIDES CUSTOMERS WITH CODING INFORMATION REGARDING
 * THEIR PRODUCTS, WHICH AIMS AT SAVING TIME FOR THEM. SPINTROL SHALL NOT BE
 * LIABLE FOR THE USE OF THE SOFTWARE. SPINTROL DOES NOT GUARANTEE THE
 * CORRECTNESS OF THIS SOFTWARE AND RESERVES THE RIGHT TO MODIFY THE SOFTWARE
 * WITHOUT NOTIFICATION.
 *
 ******************************************************************************/

#include"spc1168.h"
#include<stdio.h>


#define                         OffsetADDRInFlash                      0x10000
#define                         FlashBaseADDR                          0x10000000
#define                         OperationADDR                          FlashBaseADDR + OffsetADDRInFlash


 /*************************************************************************************************************************
 *
 * @brief      This demo will show how to put all data (include process text code and parameter/excption vector table, ect.)
 *						 This demo may be usefull when you want to wrote/erase flash, which may be break-in by interrupt.
 *
 *************************************************************************************************************************/
 
 #pragma arm section code = "RAMCODE"

#define TimerPeridCount         1 //1ms
#define NVIC_VectorTable_RAM    0x20000000

static uint32_t count = 0;

int main()
{
  FLASH_WALLOW();
  FLASH_SetTiming(200000000);

  CLOCK_InitWithRCO(CLOCK_HCLK_200MHZ);

  Delay_Init();

  /*
   * Init the UART
   *
   * 1.Set the GPIO34/35 as UART FUNC
   *
   * 2.Enable the UART CLK
   *
   * 3.Set the rest para
   */
  GPIO_SetPinChannel(GPIO_34,GPIO34_UART_TXD);
  GPIO_SetPinChannel(GPIO_35,GPIO35_UART_RXD);
  CLOCK_EnableModule(UART_MODULE);
  UART_Init(UART,38400);
	
	//Set exception vector table
  SCB->VTOR = NVIC_VectorTable_RAM;
	printf("Exception vector table Addr is : %x\n",SCB->VTOR);
	
  /* Init TIMWE1 */
  TIMER_Init(TIMER1,TimerPeridCount);

  /* Open Global INT for TIMER1 */
  NVIC_EnableIRQ(TIMER1_IRQn);
	
	while(1)
	{
		printf("erase % d\n",count);
		FLASH_EraseSector(OperationADDR);
		count++;
	}
}

void TIMER1_IRQHandler()
{
  /* Clear the INT */
  TIMER_ClearInt(TIMER1);
}
#pragma arm section


