diff --git a/axtls/include/version.h b/axtls/include/version.h index 43c7194..8fee21b 100644 --- a/axtls/include/version.h +++ b/axtls/include/version.h @@ -5,6 +5,6 @@ #ifndef _VERSION_H -#define AXTLS_VERSION "esp-open-rtos axTLS "GITSHORTREV +#define AXTLS_VERSION "esp-open-rtos axTLS " GITSHORTREV #endif diff --git a/common.mk b/common.mk index 323d13d..199dd0a 100644 --- a/common.mk +++ b/common.mk @@ -94,14 +94,19 @@ OWN_LIBC ?= 1 # Note: you will need a recent esp ENTRY_SYMBOL ?= call_user_start -CFLAGS = -Wall -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -std=gnu99 $(CPPFLAGS) +# Common flags for both C & C++_ +C_CXX_FLAGS = -Wall -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals $(CPPFLAGS) +# Flags for C only +CFLAGS = $(C_CXX_FLAGS) -std=gnu99 +# Flags for C++ only +CXXFLAGS = $(C_CXX_FLAGS) -fno-exceptions LDFLAGS = -nostdlib -Wl,--no-check-sections -Wl,-L$(BUILD_DIR)sdklib -Wl,-L$(ROOT)lib -u $(ENTRY_SYMBOL) -Wl,-static -Wl,-Map=build/${PROGRAM}.map $(EXTRA_LDFLAGS) ifeq ($(FLAVOR),debug) - CFLAGS += -g -O0 + C_CXX_FLAGS += -g -O0 LDFLAGS += -g -O0 else - CFLAGS += -g -O2 + C_CXX_FLAGS += -g -O2 LDFLAGS += -g -O2 endif @@ -138,8 +143,8 @@ endif LINKER_SCRIPTS_PROCESSED = $(addprefix $(LD_DIR),$(LINKER_SCRIPTS)) # derive various parts of compiler/linker arguments -SDK_LIB_ARGS = $(addprefix -l,$(SDK_LIBS)) -LIB_ARGS = $(addprefix -l,$(LIBS)) +SDK_LIB_ARGS = $(addprefix -l,$(SDK_LIBS)) +LIB_ARGS = $(addprefix -l,$(LIBS)) PROGRAM_OUT = $(BUILD_DIR)$(PROGRAM).out LDFLAGS += $(addprefix -T,$(LINKER_SCRIPTS_PROCESSED)) @@ -229,7 +234,9 @@ $(1)_MAKEFILE ?= $(lastword $(MAKEFILE_LIST)) ### determine compiler arguments ### $(1)_CFLAGS ?= $(CFLAGS) +$(1)_CXXFLAGS ?= $(CXXFLAGS) $(1)_CC_ARGS = $(Q) $(CC) $$(addprefix -I,$$(INC_DIRS)) $$(addprefix -I,$$($(1)_INC_DIR)) $$($(1)_CFLAGS) +$(1)_CXX_ARGS = $(Q) $(C++) $$(addprefix -I,$$(INC_DIRS)) $$(addprefix -I,$$($(1)_INC_DIR)) $$($(1)_CXXFLAGS) $(1)_AR = $(call lc,$(BUILD_DIR)$(1).a) $$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.c $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR) diff --git a/core/include/common_macros.h b/core/include/common_macros.h index fa13ff9..3afd593 100644 --- a/core/include/common_macros.h +++ b/core/include/common_macros.h @@ -26,7 +26,11 @@ Important to note: IROM flash can only be accessed via 32-bit word aligned reads. It's up to the user of this attribute to ensure this. */ -#define IROM __attribute__((section(".irom0.literal"))) const +#ifdef __cplusplus + #define IROM __attribute__((section(".irom0.literal"))) +#else + #define IROM __attribute__((section(".irom0.literal"))) const +#endif #define INLINED inline static __attribute__((always_inline)) __attribute__((unused)) diff --git a/include/espressif/esp8266/esp8266.h b/include/espressif/esp8266/esp8266.h index 2d8b21b..4bf1a7a 100644 --- a/include/espressif/esp8266/esp8266.h +++ b/include/espressif/esp8266/esp8266.h @@ -6,6 +6,10 @@ #ifndef __ESP8266_H__ #define __ESP8266_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include "ets_sys.h" #include "eagle_soc.h" #include "gpio_register.h" @@ -14,5 +18,9 @@ #include "timer_register.h" #include "uart_register.h" +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/espressif/esp_misc.h b/include/espressif/esp_misc.h index d8ce65e..6490fa5 100644 --- a/include/espressif/esp_misc.h +++ b/include/espressif/esp_misc.h @@ -8,6 +8,10 @@ #include "lwip/ip_addr.h" +#ifdef __cplusplus +extern "C" { +#endif + #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" @@ -23,4 +27,8 @@ void sdk_os_delay_us(uint16_t us); void sdk_os_install_putc1(void (*p)(char c)); void sdk_os_putc(char c); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/espressif/esp_softap.h b/include/espressif/esp_softap.h index 44f06cc..8a81aef 100644 --- a/include/espressif/esp_softap.h +++ b/include/espressif/esp_softap.h @@ -6,6 +6,10 @@ #ifndef __ESP_SOFTAP_H__ #define __ESP_SOFTAP_H__ +#ifdef __cplusplus +extern "C" { +#endif + struct sdk_softap_config { uint8_t ssid[32]; uint8_t password[64]; @@ -20,4 +24,8 @@ struct sdk_softap_config { bool sdk_wifi_softap_get_config(struct sdk_softap_config *config); bool sdk_wifi_softap_set_config(struct sdk_softap_config *config); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/espressif/esp_sta.h b/include/espressif/esp_sta.h index 8b9059a..0c94a6c 100644 --- a/include/espressif/esp_sta.h +++ b/include/espressif/esp_sta.h @@ -10,6 +10,10 @@ #include "queue.h" +#ifdef __cplusplus +extern "C" { +#endif + struct sdk_station_config { uint8_t ssid[32]; uint8_t password[64]; @@ -68,4 +72,8 @@ enum { uint8_t sdk_wifi_station_get_connect_status(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/espressif/esp_system.h b/include/espressif/esp_system.h index 93eea64..e37263e 100644 --- a/include/espressif/esp_system.h +++ b/include/espressif/esp_system.h @@ -6,6 +6,10 @@ #ifndef __ESP_SYSTEM_H__ #define __ESP_SYSTEM_H__ +#ifdef __cplusplus +extern "C" { +#endif + enum sdk_rst_reason { DEFAULT_RST = 0, WDT_RST = 1, @@ -54,4 +58,8 @@ bool sdk_system_rtc_mem_write(uint8_t dst, const void *src, uint16_t n); void sdk_system_uart_swap(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/espressif/esp_timer.h b/include/espressif/esp_timer.h index 6f05547..0ceb131 100644 --- a/include/espressif/esp_timer.h +++ b/include/espressif/esp_timer.h @@ -6,6 +6,10 @@ #ifndef __ESP_TIMER_H__ #define __ESP_TIMER_H__ +#ifdef __cplusplus +extern "C" { +#endif + /* timer related */ typedef void sdk_os_timer_func_t(void *timer_arg); @@ -19,4 +23,8 @@ typedef struct _os_timer_t { void *timer_arg; } sdk_os_timer_t; +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/espressif/esp_wifi.h b/include/espressif/esp_wifi.h index e2274f1..c966f3d 100644 --- a/include/espressif/esp_wifi.h +++ b/include/espressif/esp_wifi.h @@ -9,6 +9,10 @@ #ifndef __ESP_WIFI_H__ #define __ESP_WIFI_H__ +#ifdef __cplusplus +extern "C" { +#endif + enum { NULL_MODE = 0, STATION_MODE, @@ -63,7 +67,11 @@ enum sdk_phy_mode { PHY_MODE_11N = 3 }; -enum phy_mode sdk_wifi_get_phy_mode(void); +enum sdk_phy_mode sdk_wifi_get_phy_mode(void); bool sdk_wifi_set_phy_mode(enum sdk_phy_mode mode); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/espressif/sdk_private.h b/include/espressif/sdk_private.h index 4340999..fa643a7 100644 --- a/include/espressif/sdk_private.h +++ b/include/espressif/sdk_private.h @@ -15,6 +15,11 @@ #define SDK_PRIVATE_H #include + +#ifdef __cplusplus +extern "C" { +#endif + struct ip_addr; /********************************************* @@ -49,4 +54,8 @@ void sdk_system_station_got_ip_set(struct ip_addr *ip_addr, struct ip_addr *sn_m */ void sdk_system_pp_recycle_rx_pkt(void *eb); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/espressif/spi_flash.h b/include/espressif/spi_flash.h index 1805cc7..224bce4 100644 --- a/include/espressif/spi_flash.h +++ b/include/espressif/spi_flash.h @@ -6,6 +6,10 @@ #ifndef __SPI_FLASH_H__ #define __SPI_FLASH_H__ +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { SPI_FLASH_RESULT_OK, SPI_FLASH_RESULT_ERR, @@ -21,6 +25,7 @@ sdk_SpiFlashOpResult sdk_spi_flash_erase_sector(uint16_t sec); sdk_SpiFlashOpResult sdk_spi_flash_write(uint32_t des_addr, uint32_t *src_addr, uint32_t size); sdk_SpiFlashOpResult sdk_spi_flash_read(uint32_t src_addr, uint32_t *des_addr, uint32_t size); + /* SDK uses this structure internally to account for flash size. chip_size field is initialised during startup from the flash size @@ -42,4 +47,9 @@ typedef struct { extern sdk_flashchip_t sdk_flashchip; + +#ifdef __cplusplus +} +#endif + #endif diff --git a/ld/eagle.app.v6.ld b/ld/eagle.app.v6.ld index ae5c23b..1c45f1d 100644 --- a/ld/eagle.app.v6.ld +++ b/ld/eagle.app.v6.ld @@ -166,11 +166,14 @@ SECTIONS *(.gnu.linkonce.e.*) *(.gnu.version_r) *(.eh_frame) + . = (. + 3) & ~ 3; /* C++ constructor and destructor tables, properly ordered: */ + __init_array_start = ABSOLUTE(.); KEEP (*crtbegin.o(.ctors)) KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) + __init_array_end = ABSOLUTE(.); KEEP (*crtbegin.o(.dtors)) KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) KEEP (*(SORT(.dtors.*)))