__var __mac_temp_STAT;
__PLL0(){
//Reset, BASE_M4_CLK = IRC
__writeMemory32(0X01000800,0x4005006C,"Memory");
//OSC Enable
__writeMemory32(__readMemory32(0x40050018,"Memory")& (~(1<<0)),0x40050018,"Memory");
__delay(100);
//Set PLL 96MHz
__writeMemory32(0X00000001,0x40050044,"Memory");
__writeMemory32(0X065F2100,0x40050044,"Memory");
//wait PLL lock
do
{
__mac_temp_STAT = __readMemory32(0x40050040,"Memory");
}
while((__mac_temp_STAT & 1) == 0);
//CGU_BASE_M4_CLK = PLL1
__writeMemory32(0x09000800,0x4005006C,"Memory");
__writeMemory32(__readMemory32(0x4004312C,"Memory")&(~(1<<16)),0x4004312C,"Memory"); //CREG6 EMC_CLK_DIV = 0
__writeMemory32(__readMemory32(0x40051430,"Memory")| (1<<0),0x40051430,"Memory"); //CLK_M4_EMC_CFG Enable
do
{
__mac_temp_STAT = __readMemory32(0x40051434,"Memory"); //CCU1_CLK_M4_EMC_STAT
}
while((__mac_temp_STAT & 1) == 0);
__writeMemory32(__readMemory32(0x40051478,"Memory")| (1<<0),0x40051478,"Memory"); //CLK_M4_EMCDIV Enable
do
{
__mac_temp_STAT = __readMemory32(0x4005147C,"Memory"); //CCU1_CLK_M4_EMCDIV_STAT
}
while((__mac_temp_STAT & 1) == 0);
}
__Setup(){
//Disable EMC
__writeMemory32(0x00000000,0x40005000,"Memory");
//Configure EMC port pins
__writeMemory32(0X000000F3,0x4008609C,"Memory"); /* P1_7: D0 */
__writeMemory32(0X000000F3,0x400860A0,"Memory"); /* P1_8: D1 */
__writeMemory32(0X000000F3,0x400860A4,"Memory"); /* P1_9: D2 */
__writeMemory32(0X000000F3,0x400860A8,"Memory"); /* P1_10: D3 */
__writeMemory32(0X000000F3,0x400860AC,"Memory"); /* P1_11: D4 */
__writeMemory32(0X000000F3,0x400860B0,"Memory"); /* P1_12: D5 */
__writeMemory32(0X000000F3,0x400860B4,"Memory"); /* P1_13: D6 */
__writeMemory32(0X000000F3,0x400860B8,"Memory"); /* P1_14: D7 */
__writeMemory32(0X000000F2,0x40086290,"Memory"); /* P5_4: D8 */
__writeMemory32(0X000000F2,0x40086294,"Memory"); /* P5_5: D9 */
__writeMemory32(0X000000F2,0x40086298,"Memory"); /* P5_6: D10 */
__writeMemory32(0X000000F2,0x4008629C,"Memory"); /* P5_7: D11 */
__writeMemory32(0X000000F2,0x40086280,"Memory"); /* P5_0: D12 */
__writeMemory32(0X000000F2,0x40086284,"Memory"); /* P5_1: D13 */
__writeMemory32(0X000000F2,0x40086288,"Memory"); /* P5_2: D14 */
__writeMemory32(0X000000F2,0x4008628C,"Memory"); /* P5_3: D15 */
__writeMemory32(0X000000F2,0x40086688,"Memory"); /* PD_2: D16 */
__writeMemory32(0X000000F2,0x4008668C,"Memory"); /* PD_3: D17 */
__writeMemory32(0X000000F2,0x40086690,"Memory"); /* PD_4: D18 */
__writeMemory32(0X000000F2,0x40086694,"Memory"); /* PD_5: D19 */
__writeMemory32(0X000000F2,0x40086698,"Memory"); /* PD_6: D20 */
__writeMemory32(0X000000F2,0x4008669C,"Memory"); /* PD_7: D21 */
__writeMemory32(0X000000F2,0x400866A0,"Memory"); /* PD_8: D22 */
__writeMemory32(0X000000F2,0x400866A4,"Memory"); /* PD_9: D23 */
__writeMemory32(0X000000F3,0x40086714,"Memory"); /* PE_5: D24 */
__writeMemory32(0X000000F3,0x40086718,"Memory"); /* PE_6: D25 */
__writeMemory32(0X000000F3,0x4008671C,"Memory"); /* PE_7: D26 */
__writeMemory32(0X000000F3,0x40086720,"Memory"); /* PE_8: D27 */
__writeMemory32(0X000000F3,0x40086724,"Memory"); /* PE_9: D28 */
__writeMemory32(0X000000F3,0x40086728,"Memory"); /* PE_10: D29 */
__writeMemory32(0X000000F3,0x4008672C,"Memory"); /* PE_11: D30 */
__writeMemory32(0X000000F3,0x40086730,"Memory"); /* PE_12: D31 */
__writeMemory32(0X000000F3,0x40086124,"Memory"); /* P2_9: A0 */
__writeMemory32(0X000000F3,0x40086128,"Memory"); /* P2_10: A1 */
__writeMemory32(0X000000F3,0x4008612C,"Memory"); /* P2_11: A2 */
__writeMemory32(0X000000F3,0x40086130,"Memory"); /* P2_12: A3 */
__writeMemory32(0X000000F3,0x40086134,"Memory"); /* P2_13: A4 */
__writeMemory32(0X000000F2,0x40086080,"Memory"); /* P1_0: A5 */
__writeMemory32(0X000000F2,0x40086084,"Memory"); /* P1_1: A6 */
__writeMemory32(0X000000F2,0x40086088,"Memory"); /* P1_2: A7 */
__writeMemory32(0X000000F3,0x40086120,"Memory"); /* P2_8: A8 */
__writeMemory32(0X000000F3,0x4008611C,"Memory"); /* P2_7: A9 */
__writeMemory32(0X000000F2,0x40086118,"Memory"); /* P2_6: A10 */
__writeMemory32(0X000000F2,0x40086108,"Memory"); /* P2_2: A11 */
__writeMemory32(0X000000F2,0x40086104,"Memory"); /* P2_1: A12 */
__writeMemory32(0X000000F2,0x40086100,"Memory"); /* P2_0: A13 */
__writeMemory32(0X000000F1,0x40086320,"Memory"); /* P6_8: A14 */
// Byte enables
__writeMemory32(0x000000F3,0x40086090,"Memory"); // P1_4 BLS 0
__writeMemory32(0x000000F1,0x40086318,"Memory"); // P6_6 BLS 1
__writeMemory32(0x000000F2,0x400866B4,"Memory"); // PD_13 BLS 2
__writeMemory32(0x000000F2,0x400866A8,"Memory"); // PD_10 BLS 3
__writeMemory32(0X000000F3,0x40086324,"Memory"); /* P6_9: DYCS0 */
__writeMemory32(0X000000F3,0x40086098,"Memory"); /* P1_6: WE */
__writeMemory32(0X000000F3,0x40086310,"Memory"); /* P6_4: CAS */
__writeMemory32(0X000000F3,0x40086314,"Memory"); /* P6_5: RAS */
//Configure EMC clock-out pins
__writeMemory32(0X000000F0,0x40086C00,"Memory"); /* CLK0 */
__writeMemory32(0X000000F0,0x40086C04,"Memory"); /* CLK1 */
__writeMemory32(0X000000F0,0x40086C08,"Memory"); /* CLK2 */
__writeMemory32(0X000000F0,0x40086C0C,"Memory"); /* CLK3 */
//CKEOUT0 DQMOUT0 DQMOUT1 DQMOUT2 DQMOUT3
__writeMemory32(0X000000F3,0x4008632C,"Memory"); /* P6_11: CKEOUT0 */
__writeMemory32(0X000000F3,0x40086330,"Memory"); /* P6_12: DQMOUT0 */
__writeMemory32(0X000000F3,0x40086328,"Memory"); /* P6_10: DQMOUT1 */
__writeMemory32(0X000000F2,0x40086680,"Memory"); /* PD_0: DQMOUT2 */
__writeMemory32(0X000000F3,0x40086734,"Memory"); /* PE_13: DQMOUT3 */
__writeMemory32(0X000000F3,0x4008608C,"Memory"); // OE, SFSP1_3
__writeMemory32(0X000000F3,0x40086094,"Memory"); // CS0, SFSP1_5
__writeMemory32(0X000000F3,0x40086098,"Memory"); // WE, SFSP1_6
// enable CS0 and setup the timing
// 90ns 32-bit Flash on CS0
__writeMemory32(0x00000001,0x40005000,"Memory"); /*EMC_CONTROL (EMC Enable) */
__writeMemory32(0x00000082,0x40005200,"Memory"); // CS0: 32 bit, WE
__writeMemory32(0x00000002,0x40005208,"Memory"); // CS0: WAITOEN = 2
__writeMemory32(0x0000000B,0x4000520C,"Memory"); // CS0: WAITRD = 11
//Set EMC clock output delay
//EMCDELAYCLK (2.5.0 ns EMC clock out delay)
__writeMemory32(0x00005555,0x40086D00,"Memory");
__writeMemory32(0x00000001,0x40005000,"Memory"); /*EMC_CONTROL (EMC Enable) */
__writeMemory32(0x00000000,0x40005008,"Memory"); /*EMC_CONFIG (Little-endian, Clock Ratio 1:1) */
__writeMemory32(0X00005500,0x40005100,"Memory"); /*DYNAMICCONFIG0 */
__writeMemory32(0x00000303,0x40005104,"Memory"); /*DYNAMICRASCAS0( Latency: RAS 3, CAS 3 CCLK cyc.)*/
__writeMemory32(0x00000001,0x40005028,"Memory"); /*DYNAMICREADCONFIG (Command delayed by 1/2 CCLK) */
__writeMemory32(1,0x40005030,"Memory"); //DYNAMICRP
__writeMemory32(3,0x40005034,"Memory"); //DYNAMICRAS
__writeMemory32(6,0x40005038,"Memory"); //DYNAMICSREX
__writeMemory32(1,0x4000503C,"Memory"); //DYNAMICAPR
__writeMemory32(5,0x40005040,"Memory"); //DYNAMICDAL
__writeMemory32(1,0x40005044,"Memory"); //DYNAMICWR
__writeMemory32(5,0x40005048,"Memory"); //DYNAMICRC
__writeMemory32(5,0x4000504C,"Memory"); //DYNAMICRFC
__writeMemory32(6,0x40005050,"Memory"); //DYNAMICXSR
__writeMemory32(1,0x40005054,"Memory"); //DYNAMICRRD
__writeMemory32(2,0x40005058,"Memory"); //DYNAMICMRD
__delay(100);
__writeMemory32(0x00000183,0x40005020,"Memory"); /*DYNAMICCONTROL (Issue NOP command) */
__delay(10);
__writeMemory32(0x00000103,0x40005020,"Memory"); /*DYNAMICCONTROL (Issue PALL command) */
__delay(1);
__writeMemory32(0x00000002,0x40005024,"Memory"); /*DYNAMICREFRESH */
__delay(10);
__writeMemory32(0x0000006E,0x40005024,"Memory"); /*DYNAMICREFRESH */
__delay(10);
__writeMemory32(0x00000083,0x40005020,"Memory"); /*DYNAMICCONTROL (Issue MODE command) */
__readMemory32(0x2800C800,"Memory");
__delay(10);
__writeMemory32(0x00000003,0x40005020,"Memory"); /*DYNAMICCONTROL (Issue NORMAL command) */
//DYNAMICCONFIG0 (Enable buffer)
__writeMemory32(__readMemory32(0x40005100,"Memory") | (1 << 19),0x40005100,"Memory");
__delay(200);
}
execUserReset()
{
__message "execUserReset\n";
__Setup();
__writeMemory32(0X28000000,0x40043100,"Memory"); //Set CREG_M4MEMMAP
__message "execUserReset Finish\n";
}
execUserPreload(){
__message "execUserPreload\n";
__PLL0(); //Set PLL0
__Setup();
__message "execUserPreload Finish\n";
}