/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#ifndef INCLUDE_ECXX_PLATFORM_SPECIFIC_CONFIG_H
#error "this file cannot be included directly"
#endif
#undef INCLUDE_ECXX_PLATFORM_SPECIFIC_CONFIG_H


#ifndef ECXX_PLATFORM_NODEMCU_CONFIG_H
#define ECXX_PLATFORM_NODEMCU_CONFIG_H


//
// Platform-specific's instruction-caching macros
//

// Inform that the platform-specific's instruction-caching macros have been defined here
#define ECXX_ICACHE_FMACROS_DEFINED

#undef ICACHE_FLASH_ATTR
#define ICACHE_FLASH_ATTR __attribute__ ( ( section(                                                \
    "\".irom0.text." __FILE__ "." __ECXX_STRINGIFY(__LINE__) "." __ECXX_STRINGIFY(__COUNTER__) "\"" \
) ) )

#undef ICACHE_RAM_ATTR
#define ICACHE_RAM_ATTR   __attribute__ ( ( section(                                                \
    "\".iram.text."  __FILE__ "." __ECXX_STRINGIFY(__LINE__) "." __ECXX_STRINGIFY(__COUNTER__) "\"" \
) ) )


//
// Available RAM size
//
// https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map
#define RAM_SIZE    (0x3FFFC000UL - 0x3FFE8000UL)
#define RAM_SIZE_KB (RAM_SIZE / 1024)


//
// Platform-specific's program-memory macros
//

// Inform that the platform-specific's program-memory macros have been defined here
#define ECXX_PROGMEM_FMACROS_NEAR_DEFINED
#define ECXX_PROGMEM_FMACROS_FAR_DEFINED

// Attribute to put constants in program memory
#undef PROGMEM
#define PROGMEM __attribute__ ( ( section (                                                        \
    "\".irom.text." __FILE__ "." __ECXX_STRINGIFY(__LINE__) "." __ECXX_STRINGIFY(__COUNTER__) "\"" \
) ) )

#undef PROGMEM_FAR
#define PROGMEM_FAR PROGMEM

// Attribute to put strings in program memory
#define PROGMEM_STR __attribute__( ( section (                                                                               \
    "\".irom0.pstr." __FILE__ "." __ECXX_STRINGIFY(__LINE__) "." __ECXX_STRINGIFY(__COUNTER__) "\", \"aSM\", @progbits, 1 #" \
) ) )

// Macro to put inline string literals in program memory (normal)
// WARNING : Do not change the alignment!
#define PGM_STR(STR) ( __extension__ ( {                                   \
    static const char __C[] __attribute__((aligned(4))) PROGMEM_STR = STR; \
    eCxx::PGM_PTR(&__C[0]);                                                \
} ) )

// Macro to put inline string literals in program memory (far)
// WARNING : Do not change the alignment!
#define PGM_STR_FAR(STR) ( __extension__ ( {                               \
    static const char __C[] __attribute__((aligned(4))) PROGMEM_STR = STR; \
    eCxx::PGM_PTR_FAR(&__C[0]);                                            \
} ) )


#endif
