#! armcc -E
; The first line specifies a preprocessor command that the linker invokes 
; to pass a scatter file through a C preprocessor.

;********************************************************************************
;* File Name: Cm3RealView.scat
;* Version 4.0
;*
;*  Description:
;*  This Linker Descriptor file describes the memory layout of the PSoC5
;*  device. The memory layout of the final binary and hex images as well as
;*  the placement in PSoC5 memory is described.
;*
;*
;*  Note:
;*
;*  romvectors: Cypress default Interrupt sevice routine vector table.
;*
;*      This is the ISR vector table at bootup. Used only for the reset vector.
;*
;*
;*  ramvectors: Cypress ram interrupt service routine vector table.
;*
;*      This is the ISR vector table used by the application.
;*
;*
;********************************************************************************
;* Copyright 2008-2013, Cypress Semiconductor Corporation.  All rights reserved.
;* You may use this file only in accordance with the license, terms, conditions,
;* disclaimers, and limitations in the end user license agreement accompanying
;* the software package with which this file was provided.
;********************************************************************************/
#include "cyfitter.h"

#define CY_FLASH_SIZE       131072
#define CY_APPL_ORIGIN      0
#define CY_FLASH_ROW_SIZE   256
#define CY_ECC_ROW_SIZE     32
#define CY_EE_SIZE          2048
#define CY_METADATA_SIZE    64


; Define application base address
#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)
    #define CY_APPL_NUM     1
    #define CY_APPL_MAX     1
    #define CY_EE_IN_BTLDR  

    #if CY_APPL_ORIGIN
        #define APPL1_START     CY_APPL_ORIGIN
    #else
        #define APPL1_START     AlignExpr(ImageLimit(CYBOOTLOADER), CY_FLASH_ROW_SIZE)
    #endif

    #define APPL_START      (APPL1_START + AlignExpr(((CY_FLASH_SIZE - APPL1_START - 2 * CY_FLASH_ROW_SIZE) / 2 ) * (CY_APPL_NUM - 1), CY_FLASH_ROW_SIZE))
    #define ECC_OFFSET      ((APPL_START / CY_FLASH_ROW_SIZE) * CY_ECC_ROW_SIZE)
    #define EE_OFFSET       (CY_EE_IN_BTLDR ? 0 : (CY_EE_SIZE / CY_APPL_MAX) * (CY_APPL_NUM - 1))
    #define EE_SIZE         (CY_EE_IN_BTLDR ? CY_EE_SIZE : (CY_EE_SIZE / CY_APPL_MAX))

#else

    #define APPL_START      0
    #define ECC_OFFSET      0
    #define EE_OFFSET       0
    #define EE_SIZE         CY_EE_SIZE

#endif


; Place Bootloader at the beginning of Flash
#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)

    CYBOOTLOADER 0
    {
        .cybootloader +0
        {
            * (.cybootloader)
        }
    }

    #if CY_APPL_ORIGIN
        ScatterAssert(APPL_START > LoadLimit(CYBOOTLOADER))
    #endif

#endif


APPLICATION APPL_START (CY_FLASH_SIZE - APPL_START)
{
    VECTORS +0
    {
        * (.romvectors)
    }

    CODE +0
    {
        * (+RO)
    }

    ISRVECTORS (0x20000000 - (32768 / 2)) UNINIT
    {
        * (.ramvectors)
    }

    NOINIT_DATA +0 UNINIT
    {
        * (.noinit)
    }

    DATA +0
    {
        .ANY (+RW, +ZI)
    }

    ARM_LIB_HEAP (0x20000000 + (32768 / 2) - 0x0800 - 0x2000) EMPTY 0x0800
    {
    }

    ARM_LIB_STACK (0x20000000 + (32768 / 2)) EMPTY -0x2000
    {
    }
}


#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_BOOTLOADER || CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_MULTIAPPBOOTLOADER)

    CYLOADERMETA (CY_FLASH_SIZE - CY_METADATA_SIZE)
    {
        .cyloadermeta +0 { * (.cyloadermeta) }
    }

#else

    #if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)

        CYLOADABLEMETA (CY_FLASH_SIZE - CY_FLASH_ROW_SIZE * (CY_APPL_NUM - 1) - CY_METADATA_SIZE)
        {
            .cyloadablemeta +0 { * (.cyloadablemeta) }
        }
    
    #endif

#endif

#if (CYDEV_ECC_ENABLE == 0)

    CYCONFIGECC (0x80000000 + ECC_OFFSET)
    {
        .cyconfigecc +0 { * (.cyconfigecc) }
    }

#endif

CYCUSTNVL 0x90000000
{
    .cycustnvl +0 { * (.cycustnvl) }
}

CYWOLATCH 0x90100000
{
    .cywolatch +0 { * (.cywolatch) }
}

#if defined(CYDEV_ALLOCATE_EEPROM)

    CYEEPROM 0x90200000 + EE_OFFSET (EE_SIZE)
    {
        .cyeeprom +0 { * (.cyeeprom) }
    }

#endif

CYFLASHPROTECT 0x90400000
{
    .cyflashprotect +0 { * (.cyflashprotect) }
}

CYMETA 0x90500000
{
    .cymeta +0 { * (.cymeta) }
}

#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)

    CYLOADERMETA +0
    {
        .cyloadermeta +0 { * (.cyloadermeta) }
    }

#endif
