/** @brief Memory map for application in RAM and stored on QSPI
 * @file platform-memory-map.h
 *
 *  Created on: 9 Jun 2020
 *      Author: Nick Pelling
 */

#ifndef PLATFORM_MEMORY_MAP_H_
#define PLATFORM_MEMORY_MAP_H_

#define QSPI_FLASH_SIZE        (16 * 1024 * 1024U)  ///< 0x1000000U Total size of QSPI flash
#define QSPI_BOOTLOADER_SIZE		(256U * 1024U)	///< 0x40000U Size available for bootloader binary on QSPI flash
#define QSPI_PLATFORM_BINARY_SIZE	(512U * 1024U) 	///< 0x80000U Size available for platform binary on QSPI flash
#define QSPI_PLUGIN_BINARY_SIZE		(256U * 1024U) 	///< 0x40000U Size available for plugin binary on QSPI flash
#define QSPI_BOOTLOADER_CONFIG_SIZE	(64U  * 1024U) 	///< 0x10000U Size available for bootloader config on QSPI flash
#define QSPI_PLATFORM_CONFIG_SIZE	(64U  * 1024U) 	///< 0x10000U Size available for platform config on QSPI flash
#define QSPI_PLUGIN_CONFIG_SIZE		(64U  * 1024U) 	///< 0x10000U Size available for plugin config on QSPI flash

#define RAM_PLATFORM_SIZE			(416U * 1024U)	// 0x68000U (includes heap)
#define RAM_PLATFORM_STACK_SIZE		(16U  * 1024U)	// 0x04000U
#define RAM_PLUGIN_SIZE				(16U  * 1024U)	// 0x04000U

#define QSPI_BOOTLOADERx_BINARY	(FlexSPI_AMBA_BASE)	                                    ///< 0x60000000U 512K - The Bootloader binary must be located at the start of the FlexSPI Flash.
#define QSPI_BOOTLOADERx_CONFIG	(QSPI_BOOTLOADERx_BINARY + QSPI_BOOTLOADER_SIZE)        ///< 0x60080000U  64K - Bootloader configuration data on FlexSPI Flash.
#define QSPI_BOOTLOADERy_BINARY	(QSPI_BOOTLOADERx_CONFIG + QSPI_BOOTLOADER_CONFIG_SIZE) ///< 0x60090000U 512K - Alternative bootloader. I'm not sure that this can be used to boot from.
#define QSPI_BOOTLOADERy_CONFIG	(QSPI_BOOTLOADERy_BINARY + QSPI_BOOTLOADER_SIZE)        ///< 0x60110000U  64K - Configuration file for alterative bootloader.

#define QSPI_PLATFORMx_BINARY	(QSPI_BOOTLOADERy_CONFIG + QSPI_BOOTLOADER_CONFIG_SIZE) ///< 0x60120000U	// 512K
#define QSPI_PLATFORMx_CONFIG	(QSPI_PLATFORMx_BINARY + QSPI_PLATFORM_BINARY_SIZE)     ///< 0x601A0000U	//  64K
#define QSPI_PLATFORMy_BINARY	(QSPI_PLATFORMx_CONFIG + QSPI_PLATFORM_CONFIG_SIZE)     ///< 0x601B0000U	// 512K
#define QSPI_PLATFORMy_CONFIG	(QSPI_PLATFORMy_BINARY + QSPI_PLATFORM_BINARY_SIZE)     ///< 0x60230000U	//  64K
#define QSPI_PLATFORMz_BINARY   (QSPI_PLATFORMy_CONFIG + QSPI_PLATFORM_CONFIG_SIZE)     ///< 0x60240000U    // 512K
#define QSPI_PLATFORMz_CONFIG   (QSPI_PLATFORMz_BINARY + QSPI_PLATFORM_BINARY_SIZE)     ///< 0x602C0000U    //  64K


#define QSPI_PLUGIN1x_BINARY	(QSPI_PLATFORMz_CONFIG + QSPI_PLATFORM_CONFIG_SIZE)     ///< 0x602D0000U	// 256K
#define QSPI_PLUGIN1x_CONFIG	(QSPI_PLUGIN1x_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60310000U	//  64K
#define QSPI_PLUGIN1y_BINARY	(QSPI_PLUGIN1x_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x60320000U	// 256K
#define QSPI_PLUGIN1y_CONFIG	(QSPI_PLUGIN1y_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60360000U	//  64K
#define QSPI_PLUGIN1z_BINARY    (QSPI_PLUGIN1y_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x60370000U    // 256K
#define QSPI_PLUGIN1z_CONFIG    (QSPI_PLUGIN1z_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x603B0000U    //  64K

#define QSPI_PLUGIN2x_BINARY	(QSPI_PLUGIN1z_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x603C0000U	// 256K
#define QSPI_PLUGIN2x_CONFIG	(QSPI_PLUGIN2x_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60400000U	//  64K
#define QSPI_PLUGIN2y_BINARY	(QSPI_PLUGIN2x_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x60410000U	// 256K
#define QSPI_PLUGIN2y_CONFIG	(QSPI_PLUGIN2y_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60450000U	//  64K
#define QSPI_PLUGIN2z_BINARY    (QSPI_PLUGIN2y_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x60460000U    // 256K
#define QSPI_PLUGIN2z_CONFIG    (QSPI_PLUGIN2z_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x604A0000U    //  64K

#define QSPI_PLUGIN3x_BINARY	(QSPI_PLUGIN2z_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x604B0000U	// 256K
#define QSPI_PLUGIN3x_CONFIG	(QSPI_PLUGIN3x_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x604F0000U	//  64K
#define QSPI_PLUGIN3y_BINARY	(QSPI_PLUGIN3x_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x60500000U	// 256K
#define QSPI_PLUGIN3y_CONFIG	(QSPI_PLUGIN3y_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60540000U	//  64K
#define QSPI_PLUGIN3z_BINARY    (QSPI_PLUGIN3y_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x60550000U    // 256K
#define QSPI_PLUGIN3z_CONFIG    (QSPI_PLUGIN3z_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60590000U    //  64K

#define QSPI_PLUGIN4x_BINARY	(QSPI_PLUGIN3z_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x605A0000U	// 256K
#define QSPI_PLUGIN4x_CONFIG	(QSPI_PLUGIN4x_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x605E0000U	//  64K
#define QSPI_PLUGIN4y_BINARY	(QSPI_PLUGIN4x_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x605F0000U	// 256K
#define QSPI_PLUGIN4y_CONFIG	(QSPI_PLUGIN4y_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60630000U	//  64K
#define QSPI_PLUGIN4z_BINARY    (QSPI_PLUGIN4y_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x60640000U    // 256K
#define QSPI_PLUGIN4z_CONFIG    (QSPI_PLUGIN4z_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60680000U    //  64K

#define QSPI_PLUGIN5x_BINARY	(QSPI_PLUGIN4z_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x60690000U	// 256K
#define QSPI_PLUGIN5x_CONFIG	(QSPI_PLUGIN5x_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x606D0000U	//  64K
#define QSPI_PLUGIN5y_BINARY	(QSPI_PLUGIN5x_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x606E0000U	// 256K
#define QSPI_PLUGIN5y_CONFIG	(QSPI_PLUGIN5y_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60720000U	//  64K
#define QSPI_PLUGIN5z_BINARY    (QSPI_PLUGIN5y_CONFIG + QSPI_PLUGIN_CONFIG_SIZE)        ///< 0x60730000U    // 256K
#define QSPI_PLUGIN5z_CONFIG    (QSPI_PLUGIN5z_BINARY + QSPI_PLUGIN_BINARY_SIZE)        ///< 0x60770000U    //  64K

#define RAM_PLATFORM			0x20200000U	// 416K (includes heap)
#define RAM_PLATFORM_STACK		0x20268000U	//  16K
#define RAM_PLUGIN1				0x2026C000U	//  16K
#define RAM_PLUGIN2				0x20270000U	//  16K
#define RAM_PLUGIN3				0x20274000U	//  16K
#define RAM_PLUGIN4				0x20278000U	//  16K
#define RAM_PLUGIN5				0x2027C000U	//  16K

#endif /* PLATFORM_MEMORY_MAP_H_ */
