# -----------------------------------------------------------------------------
# Top Level Initialization procedure
#
# Warning:  Do not modify this file, it may lead to unexpected
#           simulation failures in your Microcontroller Subsystem.
#
# -----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# Registers   Range
# -----------------------------------------------------------------------------
# MDDR         0x40020000 - 0x40020FFF (starts at 0x40020800)
# FDDR         0x40021000 - 0x40021FFF
# Internal     0x40022000 - 0x40023FFF
# (Unused)     0x40024000 - 0x40027FFF
# SERDESIF_0   0x40028000 - 0x4002BFFF
# SERDESIF_1   0x4002C000 - 0x4002FFFF
# SERDESIF_2   0x40030000 - 0x40033FFF
# SERDESIF_3   0x40034000 - 0x40037FFF
# -----------------------------------------------------------------------------

# Initialization memory map
memmap MDDR     0x40020800;
memmap FDDR     0x40021000;
memmap SERDESIF_0 0x40028000;
memmap SERDESIF_1 0x4002C000;
memmap SERDESIF_2 0x40030000;
memmap SERDESIF_3 0x40034000;

# CoreSF2Config memory map
memmap CORE_CONFIG_INTERNAL_REGISTERS 0x40022000;
constant INIT_DONE 0x4

#ifdef USE_MDDR
include "MDDR_init.bfm"
#endif
#ifdef USE_FDDR
include "FDDR_init.bfm"
#endif
#ifdef USE_SERDESIF_0
include "SERDESIF_0_init.bfm"
#endif
#ifdef USE_SERDESIF_1
include "SERDESIF_1_init.bfm"
#endif
#ifdef USE_SERDESIF_2
include "SERDESIF_2_init.bfm"
#endif
#ifdef USE_SERDESIF_3
include "SERDESIF_3_init.bfm"
#endif

procedure init;

int x;
int loop_stay;

print "Start Initialization";

print "Start Register Configuration";

#ifdef USE_MDDR
call MDDR_init;
#endif
#ifdef USE_FDDR
call FDDR_init;
#endif
#ifdef USE_SERDESIF_0
call SERDESIF_0_init;
#endif
#ifdef USE_SERDESIF_1
call SERDESIF_1_init;
#endif
#ifdef USE_SERDESIF_2
call SERDESIF_2_init;
#endif
#ifdef USE_SERDESIF_3
call SERDESIF_3_init;
#endif

write w CORE_CONFIG_INTERNAL_REGISTERS 0x000 0x1;
print "End Register Configuration";

print "Start Reset Sequencing";
set loop_stay 1
while loop_stay
  readstore b CORE_CONFIG_INTERNAL_REGISTERS INIT_DONE x // read status
  set x x & 0x01
  set loop_stay x == 0
endwhile
print "End Reset Sequencing";

print "End Initialization";

return

