#! armcc -E -I .\,.\src\config,.\sdk\common_project_files\ --cpu Cortex-M0

#include "da1458x_config_basic.h"
#include "da1458x_config_advanced.h"
#include "da1458x_scatter_config.h"

; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
;
; This scatter file is set up for EM_MAP == 23!
; If an application uses a different memory layout then it must
; use a customized scatter file.
;**************************************************************

LR_IROM1 0x20000000 0x160 {                     ; load region size_region
    ER_IROM1 0x20000000 0x160 {                 ; load address = execution address
        *.o (RESET, +First)
    }
}

LR_IROM2 0x20000160 0x160 {
    ER_IROM2 0x20000160 0x160  {
       * (jump_table_mem_area)
    }
}

LR_IROM3 0x200002C0 0x80 {
    ER_IROM3 0x200002C0 0x80 {
        * (timeout_table_area)
    }
}

LR_IROM4 0x20000340 0x100 {
    ER_IROM4 0x20000340 0x100 {
        * (nvds_data_storage_area)
    }
}

LR_IROM5 0x20000440 0x93c0 {
    // 0x20005800 0x22C0
    ER_IROM5 0x20000440 0x53C0 {
       *(InRoot$$Sections)                      ; All library sections that must be in a
                                                ; root region, for example, __main.o,
                                                ; __scatter*.o, __dc*.o, and * Region$$Table
        boot_vectors.o (+RO)
        system_ARMCM0.o (+RO)
        ;*armlib* (+RO)
        .ANY (+RO)
        .ANY (+RW)
    }

    ;ER_OTA_SPACE 0x20005800 0x22C0 {
        ;user_periph_setup.o (+RO, +RW, +ZI)
    ;}

    ; *********************************************************************************************
    ; * END OF OTP - ANYTHING BELOW THIS POINT IS NOT WRITTEN WHEN THE CODE IS BURNED TO THE OTP! *
    ; *********************************************************************************************
#if (ZI_AT_8000 > 0)
    RW_IRAM50 0x20008000 ZI_AT_8000 {           ; ZI
    #if (USE_MEMORY_MAP == EXT_SLEEP_SETUP)
        .ANY (retention_mem_area0)              ; application data
    #endif

        .ANY (+ZI)
    }
#endif

    ;
    ; not retained HEAP
    ;
    RW_IRAM51 (0x20009000 - NON_RET_HEAP_SIZE) UNINIT NON_RET_HEAP_SIZE {
        jump_table.o (heap_mem_area_not_ret)
    }

    RW_IRAM52 0x20009000 EMPTY 0x20 {}          ; reserved for ROM code

    RW_IRAM53 0x20009020 0x1e0 {                ; Remaining area above 0x20009020 is set as ZI
        .ANY (+ZI)
    }

    RW_IRAM54 0x20009200 UNINIT 0x600 {         ; Stack
        .ANY (STACK)
    }

}

#if (BLE_CONNECTION_MAX_USER > 4)
LR_RETENTION_RAM1 0x000800e8 0x16c {
    ZI_RET1 0x00800e8 UNINIT 0x16c {
    #if (USE_MEMORY_MAP != EXT_SLEEP_SETUP)
        ; use
        * (retention_mem_area1)                 ; application data (up to 364 bytes!)
        ; or specify explicitly each object that has data to be placed in here
        ; app.o (retention_mem_area0)
        ; arch_main.o (retention_mem_area0)
        ; etc.
        ;
        ; execution region's size restrictions do apply!
    #else
        .ANY (retention_mem_area0)              ; application data (up to 364 bytes!)
    #endif
    }
}
#endif

#if (USE_MEMORY_MAP != EXT_SLEEP_SETUP)
LR_RETENTION_RAM0 0x00080768 (RETRAM_LEN + EXCHANGE_MEMORY_SIZE) {
    ;------------------------------------------------------------------------------------------
    ; if Deep Sleep is not used then ER_RET0 should occupy the whole memory space
    ; (length = 0x2898)
    ;------------------------------------------------------------------------------------------

    ; Deep Sleep mode
    ; RetRAM : 0x80000 - 0x82000
    ZI_RET00 0x00080768 UNINIT RETRAM_LEN {     ; 0x80768 is the last address used by the ROM code
    #if (BLE_CONNECTION_MAX_USER > 4)
        arch_system.o (cs_area)
    #endif
        * (retention_mem_area0)                 ; application data
        jump_table.o (heap_env_area)
        jump_table.o (heap_db_area)
        jump_table.o (heap_msg_area)
        ; SPOTAR
#if defined(SPOTAR_PATCH_AREA) && (SPOTAR_PATCH_AREA == 0)
        app_spotar.o (spotar_patch_area)        ; Placed in the RetRAM when SPOTAR_PATCH_SYSRAM is 0
#endif
    }

    ZI_RET01 EXCHANGE_MEMORY_BASE EXCHANGE_MEMORY_SIZE {
        arch_main.o (BLE_exchange_memory)
    }
}

LR_RETENTION_RAM2 0x00082000 ExtRETRAM_LEN {
    ZI_RET20 0x00082000 UNINIT ExtRETRAM_LEN {
#if defined(SPOTAR_PATCH_AREA) && (SPOTAR_PATCH_AREA == 1)
        app_spotar.o (spotar_patch_area)        ; Placed in the SysRAM when SPOTAR_PATCH_SYSRAM is 1
#endif
        .ANY (+ZI)
    }
}

#else
LR_RETENTION_RAM2 0x00080768 0x2898 {
    ; Extended Sleep mode
    ; Extended RetRAM : 0x80000 - 0x83000
    ZI_RET20 0x00080768 UNINIT 0x22b8  {         ; 0x80768 is the last address used by the ROM code
    #if (BLE_CONNECTION_MAX_USER > 4)
        arch_system.o (cs_area)
    #endif
        jump_table.o (heap_env_area)
        jump_table.o (heap_db_area)
        jump_table.o (heap_msg_area)
        .ANY (retention_mem_area0)              ; application data
        .ANY (+ZI)
#if defined(SPOTAR_PATCH_AREA) && (SPOTAR_PATCH_AREA == 1)
        app_spotar.o (spotar_patch_area)        ; Placed in the SysRAM when SPOTAR_PATCH_SYSRAM is 1
#endif
    }

    ZI_RET21 EXCHANGE_MEMORY_BASE EXCHANGE_MEMORY_SIZE {
        arch_main.o (BLE_exchange_memory)
    }
}
#endif

;LR_GUARD_RAM 0x50000000 0x0 {
    ;RW_GRAM0 0x50000000 0x0 {                   ; Make sure that nothing has been placed in here!
        ;*.o (exchange_mem_case1)
    ;}
;}

