#include <stdio.h>
#include "OB90A64M1.h"
#include "gpio.h"
#include "uart.h"
#include "fmc.h"

int main(void)
{
    uint32_t nLoop, nData;
    uint32_t  WBuff[100];
    
    SystemCoreClockUpdate();
    GPIO_SetPinMFType(OB_GPIO2, GPIO_PIN0, GPIO_MF_UART1_RX);
    GPIO_SetPinMFType(OB_GPIO2, GPIO_PIN1, GPIO_MF_UART1_TX);
    UART_Open(OB_UART1, 19200);

    printf(" FMC IAP Sample Code \n\r");
    //---------------------------------------------------------
    nData = FMC_GetBootSource();
    if (nData == 0x00)
        printf(" This chip is currently booting from APROM \n\r");
    else
        printf(" This chip is currently booting from LDROM \n\r");

    //---------------------Get Company ID------------------------------------
    nData = FMC_ReadCompanyID(0);
    printf(" SYNCMOS ID = %08X", nData);
    nData = FMC_ReadCompanyID(1);
    printf(",%08X\n\r", nData);

    //------------PAGE ERASE------------------------------------
    FMC_PageErase(0x4000);
    
    //----------------PROGRAM--------------------------------
    WBuff[0] = 0x55667788;
    for (nLoop = 0x00; nLoop < 512; nLoop = nLoop + 4)
    {
       
        FMC_Write( (0x4000 + nLoop), 4, WBuff);
        WBuff[0] = WBuff[0] + 8;
    }
    
    //----------------READ----------------------------------
    for (nLoop = 0x00; nLoop < 512; nLoop = nLoop + 4)
    {
        FMC_Read( (0x4000 + nLoop), 4, WBuff);
        printf(" Address = 0x%08x", (0x4000 + nLoop));
        printf(" , Data= 0x%08x\n\r", nData);
    }
  
		while(1);
}
