#ifndef	__BAT32G135__H
#define __BAT32G135__H

#define FMC_FLPROT          *(unsigned int *)(0x40020000UL + 0x20)
#define FMC_FLOPMD1         *(unsigned int *)(0x40020000UL + 0x04)
#define FMC_FLOPMD2         *(unsigned int *)(0x40020000UL + 0x08)
#define FMC_FLSTS           *(unsigned int *)(0x40020000UL + 0x00)
#define FMC_FLERMD          *(unsigned int *)(0x40020000UL + 0x0c)
#define FMC_FLSTS_OVF_Msk   0x01
#define SCB_VTOR           *(unsigned int *)(0xE000E000UL + 0x0D00UL + 0x08)

#define system_init()
    
#define flash_program()    do{                  \
    unsigned int i;                             \
    FMC_FLPROT = 0xF1;                          \
    for(i=0; i<FlashParameter.size; i++)        \
    {                                           \
        FMC_FLOPMD1 = 0xAA;                     \
        FMC_FLOPMD2 = 0x55;                     \
        *(unsigned char *)(FlashParameter.addr + i) = FlashParameter.data[i]; \
        while((FMC_FLSTS & FMC_FLSTS_OVF_Msk) == 0);    \
        FMC_FLSTS |= FMC_FLSTS_OVF_Msk;         \
    }                                           \
    FMC_FLPROT = 0x00;                          \
    FlashParameter.status = 0;                  \
}while(0)

#define flash_erasepage()   do{ \
    FMC_FLERMD = 0x10;          \
    FMC_FLPROT = 0xF1;          \
    FMC_FLOPMD1 = 0x55;         \
    FMC_FLOPMD2 = 0xAA;         \
    *(unsigned int *) FlashParameter.addr = 0xFFFFFFFF;  \
    while((FMC_FLSTS & FMC_FLSTS_OVF_Msk) == 0);        \
    FMC_FLSTS |= FMC_FLSTS_OVF_Msk;                     \
    FMC_FLERMD = 0x00;                                  \
    FMC_FLPROT = 0x00;                                  \
    FlashParameter.status = 0;                          \
}while(0)

#define flash_erasechip()   do{ \
    FMC_FLERMD = 0x08;          \
    FMC_FLPROT = 0xF1;          \
    FMC_FLOPMD1 = 0x55;         \
    FMC_FLOPMD2 = 0xAA;         \
    *(unsigned char *) FlashParameter.addr = 0xff;  \
    while((FMC_FLSTS & FMC_FLSTS_OVF_Msk) == 0);    \
    FMC_FLSTS |= FMC_FLSTS_OVF_Msk;                 \
    FMC_FLPROT = 0x00;                              \
    FlashParameter.status = 0;                      \
}while(0)

#endif
