/******************************************************************/
/* Code Composer Studio supports five reserved GEL functions that */
/* automatically get executed if they are defined. They are:      */
/*                                                                */
/* StartUp()              - Executed whenever CCS is invoked      */
/* OnReset()              - Executed after Debug->Reset CPU       */
/* OnRestart()            - Executed after Debug->Restart         */
/* OnPreFileLoaded()      - Executed before File->Load Program    */
/* OnFileLoaded()         - Executed after File->Load Program     */
/*                                                                */
/******************************************************************/

StartUp()
{
    /* Initialize F2812 memory map */
    GEL_Reset();
    F2812_Memory_Map();
    /* Enable_DFT(); */
    GEL_TextOut("Gel StartUp Complete.\n");
}

OnReset(int nErrorCode)
{
    Enable_DFT();
}

/* commented out to avoid execution
OnRestart(int nErrorCode)
{
}

OnPreFileLoaded()
{
}

OnFileLoaded(int nErrorCode, int bSymbolsOnly)
{
}
*/

menuitem "Initialize Memory Map";

/*------------------- F2812 Memory Map, MPNMC=0 --------------------*/
/*                                                                  */
/*   Note: M0M1MAP and VMAP signals tied high on F2812 core         */
/*                                                                  */
/*   0x000000 - 0x0007ff   M0/M1 SARAM             (Prog and Data)  */
/*   0x000800 - 0x000fff   Peripheral Frame0 (PF0) (Data only)      */
/*   0x002000 - 0x003fff   XINTF ZONE 0            (Prog and Data)  */
/*   0x004000 - 0x005fff   XINTF ZONE 1            (Prog and Data)  */
/*   0x006000 - 0x006fff   Peripheral Frame1 (PF1) (Data only)      */
/*   0x007000 - 0x007fff   Peripheral Frame2 (PF2) (Data only)      */
/*   0x008000 - 0x009fff   L0/L1 SARAM             (Prog and Data)  */
/*   0x080000 - 0x0fffff   XINTF ZONE 2            (Prog and Data)  */
/*   0x100000 - 0x17ffff   XINTF ZONE 6            (Prog and Data)  */
/*   0x3d7800 - 0x3d7fff   OTP                     (Prog and Data)  */
/*   0x3d8000 - 0x3f7fff   FLASH                   (Prog and Data)  */
/*   0x3f8000 - 0x3f9fff   H0 SARAM                (Prog and Data)  */
/*   0x3fc000 - 0x3fffff   XINTF ZONE 7 (MPNMC=1)  (Prog and Data)  */
/*   0x3ff000 - 0x3fffff   BOOT ROM     (MPNMC=0)  (Prog and Data)  */
/*------------------------------------------------------------------*/
hotmenu F2812_Memory_Map()
{
    GEL_MapReset();
    GEL_MapOn();

    /* Program memory maps */
    GEL_MapAdd(0x0,0,0x800,1,1);                  /* M0/M1 SARAM  */
    GEL_MapAdd(0x2000,0,0x2000,1,1);              /* XINTF ZONE 0 */
    GEL_MapAdd(0x4000,0,0x2000,1,1);              /* XINTF ZONE 1 */
    GEL_MapAdd(0x8000,0,0x2000,1,1);              /* L0/L1 SARAM  */
    GEL_MapAdd(0x80000,0,0x80000,1,1);            /* XINTF ZONE 2 */
    GEL_MapAdd(0x100000,0,0x80000,1,1);           /* XINTF ZONE 6 */
    GEL_MapAdd(0x3d7800,0,0x800,1,0);             /* OTP          */
    GEL_MapAdd(0x3d8000,0,0x20000,1,0);           /* FLASH        */
    GEL_MapAdd(0x3f8000,0,0x2000,1,1);            /* H0 SARAM     */

    /* Data memory maps */
    GEL_MapAdd(0x0,1,0x800,1,1);                  /* M0/M1 SARAM  */
    GEL_MapAdd(0x800,1,0x800,1,1);                /* PF0          */
    GEL_MapAdd(0x2000,1,0x2000,1,1);              /* XINTF ZONE 0 */
    GEL_MapAdd(0x4000,1,0x2000,1,1);              /* XINTF ZONE 1 */
    GEL_MapAdd(0x6000,1,0x1000,1,1);              /* PF1          */
    GEL_MapAddStr(0x7000,1,0x1000,"R|W|AS2",0);   /* PF2          */
    GEL_MapAdd(0x8000,1,0x2000,1,1);              /* L0/L1 SARAM  */
    GEL_MapAdd(0x80000,1,0x80000,1,1);            /* XINTF ZONE 2 */
    GEL_MapAdd(0x100000,1,0x80000,1,1);           /* XINTF ZONE 6 */
    GEL_MapAdd(0x3d7800,1,0x800,1,0);             /* OTP          */
    GEL_MapAdd(0x3d8000,0,0x20000,1,1);           /* FLASH        */
    GEL_MapAdd(0x3f8000,1,0x2000,1,1);            /* H0 SARAM     */

    /* Uncomment the map that corresponds to the MPNMC value.     */
    F2812_Boot_ROM_Map();
    /* F2812_XINTF_Zone7_Map(); */
}

/* Map Boot ROM if MPNMC = 0                                      */
F2812_Boot_ROM_Map()
{
    GEL_MapAdd(0x3ff000,0,0x1000,1,0);            /* BOOT ROM     */
    GEL_MapAdd(0x3ff000,1,0x1000,1,0);            /* BOOT ROM     */
}

/* Map External Interface Zone 7 if MPNMC = 1                     */
F2812_XINTF_Zone7_Map()
{
    GEL_MapAdd(0x3fc000,0,0x4000,1,1);            /* XINTF ZONE 7 */
    GEL_MapAdd(0x3fc000,1,0x4000,1,1);            /* XINTF ZONE 7 */
}

/* Enable DFT read/write for SARAM blocks */ 
Enable_DFT()
{
    *0x950 = 0x0300;    /* M0 */
    *0x951 = 0x0300;    /* M1 */
    *0x952 = 0x0300;    /* L0 */
    *0x953 = 0x0300;    /* L1 */
    *0x954 = 0x0300;    /* H0 */
}

menuitem "Watchdog";
hotmenu Disable_WD()
{
    /* Enable WD override */
    *0x7029 = *0x7029 | 0x0068;
    *0x7025 = 0x0055; 
    *0x7025 = 0x00AA;
}

menuitem "Code Security Module"
hotmenu Unlock_CSM()
{
    /* Assumes flash is erased */ 
    *0xAE0 = 0xFFFF; 
    *0xAE1 = 0xFFFF; 
    *0xAE2 = 0xFFFF; 
    *0xAE3 = 0xFFFF; 
    *0xAE4 = 0xFFFF; 
    *0xAE5 = 0xFFFF; 
    *0xAE6 = 0xFFFF; 
    *0xAE7 = 0xFFFF; 

    /* Read the password locations */                
    XAR0 = *0x3F7FF8; 
    XAR0 = *0x3F7FF9; 
    XAR0 = *0x3F7FFA; 
    XAR0 = *0x3F7FFB; 
    XAR0 = *0x3F7FFC; 
    XAR0 = *0x3F7FFD; 
    XAR0 = *0x3F7FFE; 
    XAR0 = *0x3F7FFF;    
}

menuitem "Addressing Modes";
hotmenu C27x_Mode()
{
    AMODE = 0;
    OBJMODE = 0;
}

hotmenu C28x_Mode()
{
    AMODE = 0;
    OBJMODE = 1;
}

hotmenu C2xLP_Mode()
{
    AMODE = 1;
    OBJMODE = 1;
}
