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

;********************************************************************************
;* \file Cm3RealView.scat
;* \version 6.10
;*
;* \brief
;* 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.
;*
;*  romvectors: Cypress default Interrupt service 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-2021, 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       262144
#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 CY_CHECKSUM_EXCLUDE_SIZE        AlignExpr(0, CY_FLASH_ROW_SIZE)
#define CY_APPL_NUM                     1
#define CY_APPL_MAX                     1


; Define application base address
#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE || \
     CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLEANDBOOTLOADER)

     #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 || \
     CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLEANDBOOTLOADER)

    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 - (65536 / 2)) UNINIT
    {
        * (.ramvectors)
    }

    NOINIT_DATA +0 UNINIT
    {
        * (.noinit)
    }

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

    ARM_LIB_HEAP (0x20000000 + (65536 / 2) - 0x80 - 0x0800) EMPTY 0x80
    {
    }

    ARM_LIB_STACK (0x20000000 + (65536 / 2)) EMPTY -0x0800
    {
    }
}


/*******************************************************************************
* Bootloader Metadata Section. See cm0gcc.ld on placement details.
*******************************************************************************/
#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_BOOTLOADER || \
     CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_MULTIAPPBOOTLOADER || \
     CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LAUNCHER)

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

#endif


/*******************************************************************************
* Bootloadable Metadata Section. See cm0gcc.ld on placement details.
*******************************************************************************/
#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE || \
     CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLEANDBOOTLOADER)

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

#endif


/*******************************************************************************
* Checksum Exclude Section. See cm0gcc.ld on placement details.
*******************************************************************************/
#if ((CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE) || (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLEANDBOOTLOADER))

    #if (0 != 0)

        #if ((CY_APPL_NUM == 1) && (CY_APPL_MAX == 2))
            #define CY_CHECKSUM_APPL2_START             (APPL1_START + AlignExpr(((CY_FLASH_SIZE - APPL1_START - 2 * CY_FLASH_ROW_SIZE) / 2 ), CY_FLASH_ROW_SIZE))
            #define CY_CHECKSUM_EXCLUDE_START           AlignExpr(CY_CHECKSUM_APPL2_START - CY_CHECKSUM_EXCLUDE_SIZE, CY_FLASH_ROW_SIZE)
        #else
            #define CY_CHECKSUM_EXCLUDE_START           AlignExpr((CY_FLASH_SIZE - CY_FLASH_ROW_SIZE * CY_APPL_MAX) - CY_CHECKSUM_EXCLUDE_SIZE, CY_FLASH_ROW_SIZE)
        #endif

        CY_CHECKSUM_EXCLUDE (CY_CHECKSUM_EXCLUDE_START)
        {
            .cy_checksum_exclude +0
            {
                * (.cy_checksum_exclude)
            }
        }

    #endif /* (0 != 0) */

#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) }
}


/*******************************************************************************
* Bootloader Metadata Section. Must be part of the image, but beyond rom memory.
*******************************************************************************/
#if ((CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE) || (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLEANDBOOTLOADER))

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

#endif
