From da6b5f74bb066a23a9dcb4cf030cfa4ffc9e5c72 Mon Sep 17 00:00:00 2001 From: Michael Jacobsen Date: Thu, 30 Jul 2015 19:34:13 +0200 Subject: [PATCH 01/18] Mostly updated header files for use in C++ --- axtls/include/version.h | 2 +- common.mk | 17 ++++++++++++----- core/include/common_macros.h | 6 +++++- include/espressif/esp8266/esp8266.h | 8 ++++++++ include/espressif/esp_misc.h | 8 ++++++++ include/espressif/esp_softap.h | 8 ++++++++ include/espressif/esp_sta.h | 8 ++++++++ include/espressif/esp_system.h | 8 ++++++++ include/espressif/esp_timer.h | 8 ++++++++ include/espressif/esp_wifi.h | 10 +++++++++- include/espressif/sdk_private.h | 9 +++++++++ include/espressif/spi_flash.h | 10 ++++++++++ ld/eagle.app.v6.ld | 3 +++ 13 files changed, 97 insertions(+), 8 deletions(-) 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.*))) From 424dc0f3b0bed8e963c2a592517b4c2eb53633cf Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Mon, 10 Aug 2015 15:51:57 +1000 Subject: [PATCH 02/18] Add C++ support to Makefile, and proof-of-concept simple.cpp example This is a work in progress based on @mikejac's work. Missing: * No 'new' operator. * I don't think STL is currently supported. --- FreeRTOS/Source/portable/esp8266/port.c | 11 ++++++ common.mk | 14 +++++-- core/sdk_compat.c | 15 +++++++ examples/simple_cplusplus/Makefile | 3 ++ examples/simple_cplusplus/simple.cpp | 52 +++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 examples/simple_cplusplus/Makefile create mode 100644 examples/simple_cplusplus/simple.cpp diff --git a/FreeRTOS/Source/portable/esp8266/port.c b/FreeRTOS/Source/portable/esp8266/port.c index 1632fe1..71c6658 100644 --- a/FreeRTOS/Source/portable/esp8266/port.c +++ b/FreeRTOS/Source/portable/esp8266/port.c @@ -178,6 +178,9 @@ void xPortSysTickHandle (void) //OpenNMI(); } +static bool sdk_compat_initialised; +void sdk_compat_initialise(void); + /* * See header file for description. */ @@ -186,6 +189,14 @@ portBASE_TYPE xPortStartScheduler( void ) _xt_isr_attach(INUM_SOFT, SV_ISR); _xt_isr_unmask(BIT(INUM_SOFT)); + /* ENORMOUS HACK: Call the sdk_compat_initialise() function. + This can be removed happily once we have open source startup code. + */ + if(!sdk_compat_initialised) { + sdk_compat_initialised = true; + sdk_compat_initialise(); + } + /* Initialize system tick timer interrupt and schedule the first tick. */ sdk__xt_tick_timer_init(); diff --git a/common.mk b/common.mk index 199dd0a..4a2bd5b 100644 --- a/common.mk +++ b/common.mk @@ -221,13 +221,15 @@ COMPONENT_ARS = define component_compile_rules $(1)_OBJ_DIR = $(call lc,$(BUILD_DIR)$(1)/) ### determine source files and object files ### -$(1)_SRC_FILES ?= $$(foreach sdir,$$($(1)_SRC_DIR), \ - $$(wildcard $$(sdir)/*.c) $$(wildcard $$(sdir)/*.S)) \ +$(1)_SRC_FILES ?= $$(foreach sdir,$$($(1)_SRC_DIR), \ + $$(wildcard $$(sdir)/*.c) $$(wildcard $$(sdir)/*.S) \ + $$(wildcard $$(sdir)/*.cpp)) \ $$($(1)_EXTRA_SRC_FILES) $(1)_REAL_SRC_FILES = $$(foreach sfile,$$($(1)_SRC_FILES),$$(realpath $$(sfile))) $(1)_REAL_ROOT = $$(realpath $$($(1)_ROOT)) # patsubst here substitutes real component root path for the relative OBJ_DIR path, making things short again -$(1)_OBJ_FILES_C = $$(patsubst $$($(1)_REAL_ROOT)%.c,$$($(1)_OBJ_DIR)%.o,$$($(1)_REAL_SRC_FILES)) +$(1)_OBJ_FILES_CXX = $$(patsubst $$($(1)_REAL_ROOT)%.cpp,$$($(1)_OBJ_DIR)%.o,$$($(1)_REAL_SRC_FILES)) +$(1)_OBJ_FILES_C = $$(patsubst $$($(1)_REAL_ROOT)%.c,$$($(1)_OBJ_DIR)%.o,$$($(1)_OBJ_FILES_CXX)) $(1)_OBJ_FILES = $$(patsubst $$($(1)_REAL_ROOT)%.S,$$($(1)_OBJ_DIR)%.o,$$($(1)_OBJ_FILES_C)) # the last included makefile is our component's component.mk makefile (rebuild the component if it changes) $(1)_MAKEFILE ?= $(lastword $(MAKEFILE_LIST)) @@ -245,6 +247,12 @@ $$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.c $$($(1)_MAKEFILE) $(wildcard $(ROOT)* $$($(1)_CC_ARGS) -c $$< -o $$@ $$($(1)_CC_ARGS) -MM -MT $$@ -MF $$(@:.o=.d) $$< +$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.cpp $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR) + $(vecho) "C++ $$<" + $(Q) mkdir -p $$(dir $$@) + $$($(1)_CXX_ARGS) -c $$< -o $$@ + $$($(1)_CXX_ARGS) -MM -MT $$@ -MF $$(@:.o=.d) $$< + $$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.S $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR) $(vecho) "AS $$<" $(Q) mkdir -p $$(dir $$@) diff --git a/core/sdk_compat.c b/core/sdk_compat.c index d141708..b6bb6b3 100644 --- a/core/sdk_compat.c +++ b/core/sdk_compat.c @@ -14,3 +14,18 @@ void IRAM *zalloc(size_t nbytes) { return calloc(1, nbytes); } + +extern void (*__init_array_start)(void); +extern void (*__init_array_end)(void); + +/* Do things which should be done as part of the startup code, but aren't. + + Can be replaced with _start() once we have open source startup code. +*/ +void sdk_compat_initialise() +{ + /* Call C++ constructors or C functions marked with __attribute__((constructor)) */ + void (**p)(void); + for ( p = &__init_array_start; p != &__init_array_end; ++p) + (*p)(); +} diff --git a/examples/simple_cplusplus/Makefile b/examples/simple_cplusplus/Makefile new file mode 100644 index 0000000..717b163 --- /dev/null +++ b/examples/simple_cplusplus/Makefile @@ -0,0 +1,3 @@ +# Simple makefile for simple example +PROGRAM=simple +include ../../common.mk diff --git a/examples/simple_cplusplus/simple.cpp b/examples/simple_cplusplus/simple.cpp new file mode 100644 index 0000000..dada441 --- /dev/null +++ b/examples/simple_cplusplus/simple.cpp @@ -0,0 +1,52 @@ +/* A very basic C++ example, really just proof of concept for C++ + + This sample code is in the public domain. + */ +#include "espressif/esp_common.h" +#include "espressif/sdk_private.h" +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" + +class Counter +{ +private: + uint32_t _count; +public: + Counter(uint32_t initial_count) + { + this->_count = initial_count; + printf("Counter initialised with count %ld\r\n", initial_count); + } + + void Increment() + { + _count++; + } + + uint32_t getCount() + { + return _count; + } +}; + +static Counter static_counter(99); + +void task1(void *pvParameters) +{ + Counter local_counter = Counter(12); + while(1) { + Counter &counter = rand() % 2 ? static_counter : local_counter; + counter.Increment(); + printf("local counter %ld static counter %ld\r\n", local_counter.getCount(), + static_counter.getCount()); + vTaskDelay(100); + } +} + +extern "C" void user_init(void) +{ + sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); + printf("SDK version:%s\n", sdk_system_get_sdk_version()); + xTaskCreate(task1, (signed char *)"tsk1", 256, NULL, 2, NULL); +} From 7d480876fa81e7a0920a00d415e3e1fa92fc801b Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 13 Aug 2015 08:32:34 +1000 Subject: [PATCH 03/18] Add basic C++ new/delete operators, as contributed by @mikejac in #24 --- core/cplusplus_operators.cpp | 25 +++++++++++++++++++++++++ examples/simple_cplusplus/simple.cpp | 20 ++++++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 core/cplusplus_operators.cpp diff --git a/core/cplusplus_operators.cpp b/core/cplusplus_operators.cpp new file mode 100644 index 0000000..86f4477 --- /dev/null +++ b/core/cplusplus_operators.cpp @@ -0,0 +1,25 @@ +/* Part of esp-open-rtos + * BSD Licensed as described in the file LICENSE + */ +#include +#include + +void *operator new(size_t size) +{ + return malloc(size); +} + +void *operator new[](size_t size) +{ + return malloc(size); +} + +void operator delete(void * ptr) +{ + free(ptr); +} + +void operator delete[](void * ptr) +{ + free(ptr); +} diff --git a/examples/simple_cplusplus/simple.cpp b/examples/simple_cplusplus/simple.cpp index dada441..8d964fa 100644 --- a/examples/simple_cplusplus/simple.cpp +++ b/examples/simple_cplusplus/simple.cpp @@ -35,11 +35,23 @@ static Counter static_counter(99); void task1(void *pvParameters) { Counter local_counter = Counter(12); + Counter *new_counter = new Counter(24); while(1) { - Counter &counter = rand() % 2 ? static_counter : local_counter; - counter.Increment(); - printf("local counter %ld static counter %ld\r\n", local_counter.getCount(), - static_counter.getCount()); + Counter *counter = NULL; + switch(rand() % 3) { + case 0: + counter = &local_counter; + break; + case 1: + counter = &static_counter; + break; + default: + counter = new_counter; + break; + } + counter->Increment(); + printf("local counter %ld static counter %ld newly allocated counter %ld\r\n", local_counter.getCount(), + static_counter.getCount(), new_counter->getCount()); vTaskDelay(100); } } From 1282e11c088254a8ab3cfa4b179a35392748d27c Mon Sep 17 00:00:00 2001 From: Michael Jacobsen Date: Wed, 19 Aug 2015 08:38:15 +0200 Subject: [PATCH 04/18] Added C++ base components and example --- common.mk | 4 +- examples/cpp_01_tasks/Makefile | 3 + examples/cpp_01_tasks/main.cpp | 100 +++++++++++++++++++++++++++ extras/cplusplus/component.mk | 3 + extras/cplusplus/cplusplus.hpp | 68 +++++++++++++++++++ extras/thread/component.mk | 3 + extras/thread/mutex.hpp | 90 +++++++++++++++++++++++++ extras/thread/queue.hpp | 120 +++++++++++++++++++++++++++++++++ extras/thread/task.hpp | 99 +++++++++++++++++++++++++++ extras/timer/component.mk | 3 + extras/timer/countdown.hpp | 95 ++++++++++++++++++++++++++ 11 files changed, 586 insertions(+), 2 deletions(-) create mode 100644 examples/cpp_01_tasks/Makefile create mode 100644 examples/cpp_01_tasks/main.cpp create mode 100644 extras/cplusplus/component.mk create mode 100644 extras/cplusplus/cplusplus.hpp create mode 100644 extras/thread/component.mk create mode 100644 extras/thread/mutex.hpp create mode 100644 extras/thread/queue.hpp create mode 100644 extras/thread/task.hpp create mode 100644 extras/timer/component.mk create mode 100644 extras/timer/countdown.hpp diff --git a/common.mk b/common.mk index 4a2bd5b..a73092c 100644 --- a/common.mk +++ b/common.mk @@ -99,7 +99,7 @@ C_CXX_FLAGS = -Wall -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-lit # Flags for C only CFLAGS = $(C_CXX_FLAGS) -std=gnu99 # Flags for C++ only -CXXFLAGS = $(C_CXX_FLAGS) -fno-exceptions +CXXFLAGS = $(C_CXX_FLAGS) -fno-exceptions -fno-rtti 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) @@ -177,7 +177,7 @@ IMGTOOL_ARGS=-$(IMGTOOL_FLASH_SIZE) -$(FLASH_MODE) -$(FLASH_SPEED) # Placing $(PROGRAM_DIR) and $(PROGRAM_DIR)include first allows # programs to have their own copies of header config files for components # , which is useful for overriding things. -INC_DIRS = $(PROGRAM_DIR) $(PROGRAM_DIR)include $(ROOT)include +INC_DIRS = $(PROGRAM_DIR) $(PROGRAM_DIR)include $(ROOT)include $(ROOT)extras ifeq ($(OWN_LIBC),1) INC_DIRS += $(ROOT)libc/xtensa-lx106-elf/include diff --git a/examples/cpp_01_tasks/Makefile b/examples/cpp_01_tasks/Makefile new file mode 100644 index 0000000..458932f --- /dev/null +++ b/examples/cpp_01_tasks/Makefile @@ -0,0 +1,3 @@ +# Simple makefile for simple example +PROGRAM=cpp_01_tasks +include ../../common.mk diff --git a/examples/cpp_01_tasks/main.cpp b/examples/cpp_01_tasks/main.cpp new file mode 100644 index 0000000..133d1c5 --- /dev/null +++ b/examples/cpp_01_tasks/main.cpp @@ -0,0 +1,100 @@ +/* + * ESP8266 FreeRTOS Firmware + * Copyright (C) 2015 Michael Jacobsen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * https://github.com/SuperHouse/esp-open-rtos + * + */ + +#include "cplusplus/cplusplus.hpp" +#include "thread/task.hpp" +#include "thread/queue.hpp" + +#include "espressif/esp_common.h" + +/****************************************************************************************************************** + * task_1_t + * + */ +class task_1_t: public esp_open_rtos::thread::task_t +{ +public: + esp_open_rtos::thread::queue_t queue; + +private: + void task() + { + printf("task_1_t::task(): start\n"); + + uint32_t count = 0; + + while(true) { + sleep(1000); + queue.post(count); + count++; + } + } +}; +/****************************************************************************************************************** + * task_2_t + * + */ +class task_2_t: public esp_open_rtos::thread::task_t +{ +public: + esp_open_rtos::thread::queue_t queue; + +private: + void task() + { + printf("task_2_t::task(): start\n"); + + while(true) { + uint32_t count; + + if(queue.receive(count, 1500) == 0) { + printf("task_2_t::task(): got %lu\n", count); + } + else { + printf("task_2_t::task(): no msg\n"); + } + } + } +}; +/****************************************************************************************************************** + * globals + * + */ +task_1_t task_1; +task_2_t task_2; + +esp_open_rtos::thread::queue_t MyQueue; + +/** + * + */ +extern "C" void user_init(void) +{ + sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); + + MyQueue.create(10); + + task_1.queue = MyQueue; + task_2.queue = MyQueue; + + task_1.task_create("tsk1"); + task_2.task_create("tsk2"); +} \ No newline at end of file diff --git a/extras/cplusplus/component.mk b/extras/cplusplus/component.mk new file mode 100644 index 0000000..3f5673d --- /dev/null +++ b/extras/cplusplus/component.mk @@ -0,0 +1,3 @@ +# Component makefile for extras/cplusplus + +INC_DIRS += $(ROOT)extras diff --git a/extras/cplusplus/cplusplus.hpp b/extras/cplusplus/cplusplus.hpp new file mode 100644 index 0000000..cc58031 --- /dev/null +++ b/extras/cplusplus/cplusplus.hpp @@ -0,0 +1,68 @@ +/* + * ESP8266 FreeRTOS Firmware + * Copyright (C) 2015 Michael Jacobsen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * https://github.com/SuperHouse/esp-open-rtos + * + */ + +#ifndef COM_THOLUSI_ESP_OPEN_RTOS_CPLUSPLUS_HPP +#define COM_THOLUSI_ESP_OPEN_RTOS_CPLUSPLUS_HPP + +#include + +/****************************************************************************************************************** + * C++ new and delete operators + * + */ + +/** + * + * @param size + * @return + */ +inline void *operator new(size_t size) +{ + return malloc(size); +} +/** + * + * @param size + * @return + */ +inline void *operator new[](size_t size) +{ + return malloc(size); +} +/** + * + * @param ptr + */ +inline void operator delete(void * ptr) +{ + free(ptr); +} +/** + * + * @param ptr + */ +inline void operator delete[](void * ptr) +{ + free(ptr); +} + +#endif /* COM_THOLUSI_ESP_OPEN_RTOS_CPLUSPLUS_HPP */ + diff --git a/extras/thread/component.mk b/extras/thread/component.mk new file mode 100644 index 0000000..46193ef --- /dev/null +++ b/extras/thread/component.mk @@ -0,0 +1,3 @@ +# Component makefile for extras/thread + +INC_DIRS += $(ROOT)extras diff --git a/extras/thread/mutex.hpp b/extras/thread/mutex.hpp new file mode 100644 index 0000000..d3db1da --- /dev/null +++ b/extras/thread/mutex.hpp @@ -0,0 +1,90 @@ +/* + * ESP8266 FreeRTOS Firmware + * Copyright (C) 2015 Michael Jacobsen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * https://github.com/SuperHouse/esp-open-rtos + * + */ + +#ifndef COM_THOLUSI_ESP_OPEN_RTOS_MUTEX_HPP +#define COM_THOLUSI_ESP_OPEN_RTOS_MUTEX_HPP + +#include "semphr.h" + +namespace esp_open_rtos { +namespace thread { + +/****************************************************************************************************************** + * class mutex_t + * + */ +class mutex_t +{ +public: + /** + * + */ + inline mutex_t() + { + mutex = xSemaphoreCreateMutex(); + } + /** + * + */ + inline ~mutex_t() + { + vQueueDelete(mutex); + } + /** + * + * @return + */ + inline int lock() + { + return (xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE) ? 0 : -1; + } + /** + * + * @param ms + * @return + */ + inline int try_lock(unsigned long ms) + { + return (xSemaphoreTake(mutex, ms / portTICK_RATE_MS) == pdTRUE) ? 0 : -1; + } + /** + * + * @return + */ + inline int unlock() + { + return (xSemaphoreGive(mutex) == pdTRUE) ? 0 : -1; + } + +private: + xSemaphoreHandle mutex; + + // Disable copy construction and assignment. + mutex_t (const mutex_t&); + const mutex_t &operator = (const mutex_t&); +}; + +} //namespace thread { +} //namespace esp_open_rtos { + + +#endif /* COM_THOLUSI_ESP_OPEN_RTOS_MUTEX_HPP */ + diff --git a/extras/thread/queue.hpp b/extras/thread/queue.hpp new file mode 100644 index 0000000..fd14166 --- /dev/null +++ b/extras/thread/queue.hpp @@ -0,0 +1,120 @@ +/* + * ESP8266 FreeRTOS Firmware + * Copyright (C) 2015 Michael Jacobsen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * https://github.com/SuperHouse/esp-open-rtos + * + */ + +#ifndef COM_THOLUSI_ESP_OPEN_RTOS_QUEUE_HPP +#define COM_THOLUSI_ESP_OPEN_RTOS_QUEUE_HPP + +#include "FreeRTOS.h" +#include "queue.h" + +namespace esp_open_rtos { +namespace thread { + +/****************************************************************************************************************** + * class queue_t + * + */ +template +class queue_t +{ +public: + /** + * + */ + inline queue_t() + { + queue = 0; + } + /** + * + * @param uxQueueLength + * @param uxItemSize + * @return + */ + inline int create(unsigned portBASE_TYPE uxQueueLength) + { + queue = xQueueCreate(uxQueueLength, sizeof(Data)); + + if(queue == NULL) { + return -1; + } + else { + return 0; + } + } + /** + * + * @param data + * @param ms + * @return + */ + inline void destroy() + { + vQueueDelete(queue); + queue = 0; + } + /** + * + * @param data + * @param ms + * @return + */ + inline int post(const Data& data, unsigned long ms = 0) + { + return (xQueueSend(queue, &data, ms / portTICK_RATE_MS) == pdTRUE) ? 0 : -1; + } + /** + * + * @param data + * @param ms + * @return + */ + inline int receive(Data& data, unsigned long ms = 0) + { + return (xQueueReceive(queue, &data, ms / portTICK_RATE_MS) == pdTRUE) ? 0 : -1; + } + /** + * + * @param other + * @return + */ + const queue_t &operator = (const queue_t& other) + { + if(this != &other) { // protect against invalid self-assignment + queue = other.queue; + } + + return *this; + } + +private: + xQueueHandle queue; + + // Disable copy construction. + queue_t (const queue_t&); +}; + +} //namespace thread { +} //namespace esp_open_rtos { + + +#endif /* COM_THOLUSI_ESP_OPEN_RTOS_QUEUE_HPP */ + diff --git a/extras/thread/task.hpp b/extras/thread/task.hpp new file mode 100644 index 0000000..dc527f0 --- /dev/null +++ b/extras/thread/task.hpp @@ -0,0 +1,99 @@ +/* + * ESP8266 FreeRTOS Firmware + * Copyright (C) 2015 Michael Jacobsen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * https://github.com/SuperHouse/esp-open-rtos + * + */ + +#ifndef COM_THOLUSI_ESP_OPEN_RTOS_TASK_HPP +#define COM_THOLUSI_ESP_OPEN_RTOS_TASK_HPP + +#include "FreeRTOS.h" +#include "task.h" + +namespace esp_open_rtos { +namespace thread { + +/****************************************************************************************************************** + * task_t + * + */ +class task_t +{ +public: + /** + * + */ + task_t() + {} + /** + * + * @param pcName + * @param usStackDepth + * @param uxPriority + * @return + */ + int task_create(const char* const pcName, unsigned short usStackDepth = 256, unsigned portBASE_TYPE uxPriority = 2) + { + return xTaskCreate(task_t::_task, (signed char *)pcName, usStackDepth, this, uxPriority, NULL); + } + +protected: + /** + * + * @param ms + */ + void sleep(unsigned long ms) + { + vTaskDelay(ms / portTICK_RATE_MS); + } + /** + * + * @return + */ + inline unsigned long millis() + { + return xTaskGetTickCount() * portTICK_RATE_MS; + } + +private: + /** + * + */ + virtual void task() = 0; + /** + * + * @param pvParameters + */ + static void _task(void* pvParameters) + { + if(pvParameters != 0) { + ((task_t*)(pvParameters))->task(); + } + } + + // no copy and no = operator + task_t(const task_t&); + task_t &operator=(const task_t&); +}; + +} //namespace thread { +} //namespace esp_open_rtos { + + +#endif /* COM_THOLUSI_ESP_OPEN_RTOS_TASK_HPP */ + diff --git a/extras/timer/component.mk b/extras/timer/component.mk new file mode 100644 index 0000000..255ebae --- /dev/null +++ b/extras/timer/component.mk @@ -0,0 +1,3 @@ +# Component makefile for extras/timer + +INC_DIRS += $(ROOT)extras diff --git a/extras/timer/countdown.hpp b/extras/timer/countdown.hpp new file mode 100644 index 0000000..ff1a2bf --- /dev/null +++ b/extras/timer/countdown.hpp @@ -0,0 +1,95 @@ +/* + * ESP8266 FreeRTOS Firmware + * Copyright (C) 2015 Michael Jacobsen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * https://github.com/SuperHouse/esp-open-rtos + * + */ + +#ifndef COM_THOLUSI_ESP_OPEN_RTOS_TIMER_HPP +#define COM_THOLUSI_ESP_OPEN_RTOS_TIMER_HPP + +#include "FreeRTOS.h" +#include "task.h" + +namespace esp_open_rtos { +namespace timer { + +#define __millis() (xTaskGetTickCount() * portTICK_RATE_MS) + +/****************************************************************************************************************** + * countdown_t + * + */ +class countdown_t +{ +public: + /** + * + */ + countdown_t() + { + interval_end_ms = 0L; + } + /** + * + * @param ms + */ + countdown_t(int ms) + { + countdown_ms(ms); + } + /** + * + * @return + */ + bool expired() + { + return (interval_end_ms > 0L) && (__millis() >= interval_end_ms); + } + /** + * + * @param ms + */ + void countdown_ms(unsigned long ms) + { + interval_end_ms = __millis() + ms; + } + /** + * + * @param seconds + */ + void countdown(int seconds) + { + countdown_ms((unsigned long)seconds * 1000L); + } + /** + * + * @return + */ + int left_ms() + { + return interval_end_ms - __millis(); + } + +private: + portTickType interval_end_ms; +}; + +} // namespace timer { +} // namespace esp_open_rtos { + +#endif From 4f7d1c2393d10d5b068c8450def03471d9e4046c Mon Sep 17 00:00:00 2001 From: Michael Jacobsen Date: Wed, 19 Aug 2015 08:44:41 +0200 Subject: [PATCH 05/18] Header files adjustments --- extras/cplusplus/cplusplus.hpp | 6 +++--- extras/thread/mutex.hpp | 6 +++--- extras/thread/queue.hpp | 6 +++--- extras/thread/task.hpp | 6 +++--- extras/timer/countdown.hpp | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/extras/cplusplus/cplusplus.hpp b/extras/cplusplus/cplusplus.hpp index cc58031..a78e146 100644 --- a/extras/cplusplus/cplusplus.hpp +++ b/extras/cplusplus/cplusplus.hpp @@ -19,8 +19,8 @@ * */ -#ifndef COM_THOLUSI_ESP_OPEN_RTOS_CPLUSPLUS_HPP -#define COM_THOLUSI_ESP_OPEN_RTOS_CPLUSPLUS_HPP +#ifndef ESP_OPEN_RTOS_CPLUSPLUS_HPP +#define ESP_OPEN_RTOS_CPLUSPLUS_HPP #include @@ -64,5 +64,5 @@ inline void operator delete[](void * ptr) free(ptr); } -#endif /* COM_THOLUSI_ESP_OPEN_RTOS_CPLUSPLUS_HPP */ +#endif /* ESP_OPEN_RTOS_CPLUSPLUS_HPP */ diff --git a/extras/thread/mutex.hpp b/extras/thread/mutex.hpp index d3db1da..b4e56a4 100644 --- a/extras/thread/mutex.hpp +++ b/extras/thread/mutex.hpp @@ -19,8 +19,8 @@ * */ -#ifndef COM_THOLUSI_ESP_OPEN_RTOS_MUTEX_HPP -#define COM_THOLUSI_ESP_OPEN_RTOS_MUTEX_HPP +#ifndef ESP_OPEN_RTOS_MUTEX_HPP +#define ESP_OPEN_RTOS_MUTEX_HPP #include "semphr.h" @@ -86,5 +86,5 @@ private: } //namespace esp_open_rtos { -#endif /* COM_THOLUSI_ESP_OPEN_RTOS_MUTEX_HPP */ +#endif /* ESP_OPEN_RTOS_MUTEX_HPP */ diff --git a/extras/thread/queue.hpp b/extras/thread/queue.hpp index fd14166..e02bec6 100644 --- a/extras/thread/queue.hpp +++ b/extras/thread/queue.hpp @@ -19,8 +19,8 @@ * */ -#ifndef COM_THOLUSI_ESP_OPEN_RTOS_QUEUE_HPP -#define COM_THOLUSI_ESP_OPEN_RTOS_QUEUE_HPP +#ifndef ESP_OPEN_RTOS_QUEUE_HPP +#define ESP_OPEN_RTOS_QUEUE_HPP #include "FreeRTOS.h" #include "queue.h" @@ -116,5 +116,5 @@ private: } //namespace esp_open_rtos { -#endif /* COM_THOLUSI_ESP_OPEN_RTOS_QUEUE_HPP */ +#endif /* ESP_OPEN_RTOS_QUEUE_HPP */ diff --git a/extras/thread/task.hpp b/extras/thread/task.hpp index dc527f0..a8a5c5b 100644 --- a/extras/thread/task.hpp +++ b/extras/thread/task.hpp @@ -19,8 +19,8 @@ * */ -#ifndef COM_THOLUSI_ESP_OPEN_RTOS_TASK_HPP -#define COM_THOLUSI_ESP_OPEN_RTOS_TASK_HPP +#ifndef ESP_OPEN_RTOS_TASK_HPP +#define ESP_OPEN_RTOS_TASK_HPP #include "FreeRTOS.h" #include "task.h" @@ -95,5 +95,5 @@ private: } //namespace esp_open_rtos { -#endif /* COM_THOLUSI_ESP_OPEN_RTOS_TASK_HPP */ +#endif /* ESP_OPEN_RTOS_TASK_HPP */ diff --git a/extras/timer/countdown.hpp b/extras/timer/countdown.hpp index ff1a2bf..71dd55c 100644 --- a/extras/timer/countdown.hpp +++ b/extras/timer/countdown.hpp @@ -19,8 +19,8 @@ * */ -#ifndef COM_THOLUSI_ESP_OPEN_RTOS_TIMER_HPP -#define COM_THOLUSI_ESP_OPEN_RTOS_TIMER_HPP +#ifndef ESP_OPEN_RTOS_TIMER_HPP +#define ESP_OPEN_RTOS_TIMER_HPP #include "FreeRTOS.h" #include "task.h" From 6bc95994b70d3b2d1ddd9a657366cda7af4f0c6a Mon Sep 17 00:00:00 2001 From: Michael Jacobsen Date: Thu, 20 Aug 2015 10:04:59 +0200 Subject: [PATCH 06/18] Updated license --- examples/cpp_01_tasks/main.cpp | 31 +++++++++++++++++++------------ extras/cplusplus/cplusplus.hpp | 33 ++++++++++++++++++++------------- extras/thread/mutex.hpp | 31 +++++++++++++++++++------------ extras/thread/queue.hpp | 31 +++++++++++++++++++------------ extras/thread/task.hpp | 31 +++++++++++++++++++------------ extras/timer/countdown.hpp | 31 +++++++++++++++++++------------ 6 files changed, 115 insertions(+), 73 deletions(-) diff --git a/examples/cpp_01_tasks/main.cpp b/examples/cpp_01_tasks/main.cpp index 133d1c5..0b9fe1f 100644 --- a/examples/cpp_01_tasks/main.cpp +++ b/examples/cpp_01_tasks/main.cpp @@ -1,20 +1,27 @@ /* + * The MIT License (MIT) + * * ESP8266 FreeRTOS Firmware - * Copyright (C) 2015 Michael Jacobsen + * Copyright (c) 2015 Michael Jacobsen (github.com/mikejac) * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * * https://github.com/SuperHouse/esp-open-rtos * */ diff --git a/extras/cplusplus/cplusplus.hpp b/extras/cplusplus/cplusplus.hpp index a78e146..bf006a8 100644 --- a/extras/cplusplus/cplusplus.hpp +++ b/extras/cplusplus/cplusplus.hpp @@ -1,24 +1,31 @@ /* + * The MIT License (MIT) + * * ESP8266 FreeRTOS Firmware - * Copyright (C) 2015 Michael Jacobsen + * Copyright (c) 2015 Michael Jacobsen (github.com/mikejac) * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * * https://github.com/SuperHouse/esp-open-rtos * */ - + #ifndef ESP_OPEN_RTOS_CPLUSPLUS_HPP #define ESP_OPEN_RTOS_CPLUSPLUS_HPP diff --git a/extras/thread/mutex.hpp b/extras/thread/mutex.hpp index b4e56a4..714c585 100644 --- a/extras/thread/mutex.hpp +++ b/extras/thread/mutex.hpp @@ -1,20 +1,27 @@ /* + * The MIT License (MIT) + * * ESP8266 FreeRTOS Firmware - * Copyright (C) 2015 Michael Jacobsen + * Copyright (c) 2015 Michael Jacobsen (github.com/mikejac) * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * * https://github.com/SuperHouse/esp-open-rtos * */ diff --git a/extras/thread/queue.hpp b/extras/thread/queue.hpp index e02bec6..a24f302 100644 --- a/extras/thread/queue.hpp +++ b/extras/thread/queue.hpp @@ -1,20 +1,27 @@ /* + * The MIT License (MIT) + * * ESP8266 FreeRTOS Firmware - * Copyright (C) 2015 Michael Jacobsen + * Copyright (c) 2015 Michael Jacobsen (github.com/mikejac) * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * * https://github.com/SuperHouse/esp-open-rtos * */ diff --git a/extras/thread/task.hpp b/extras/thread/task.hpp index a8a5c5b..cb1cb45 100644 --- a/extras/thread/task.hpp +++ b/extras/thread/task.hpp @@ -1,20 +1,27 @@ /* + * The MIT License (MIT) + * * ESP8266 FreeRTOS Firmware - * Copyright (C) 2015 Michael Jacobsen + * Copyright (c) 2015 Michael Jacobsen (github.com/mikejac) * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * * https://github.com/SuperHouse/esp-open-rtos * */ diff --git a/extras/timer/countdown.hpp b/extras/timer/countdown.hpp index 71dd55c..87c8f3f 100644 --- a/extras/timer/countdown.hpp +++ b/extras/timer/countdown.hpp @@ -1,20 +1,27 @@ /* + * The MIT License (MIT) + * * ESP8266 FreeRTOS Firmware - * Copyright (C) 2015 Michael Jacobsen + * Copyright (c) 2015 Michael Jacobsen (github.com/mikejac) * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * * https://github.com/SuperHouse/esp-open-rtos * */ From 94a953d3e34bb2c9afcc5b7e42ccd4eef3098860 Mon Sep 17 00:00:00 2001 From: Michael Jacobsen Date: Fri, 21 Aug 2015 08:30:52 +0200 Subject: [PATCH 07/18] Header files re-arrangement --- common.mk | 2 +- examples/cpp_01_tasks/Makefile | 2 ++ examples/cpp_01_tasks/main.cpp | 6 +++--- extras/cpp_support/component.mk | 8 ++++++++ extras/{timer => cpp_support/include}/countdown.hpp | 0 extras/{cplusplus => cpp_support/include}/cplusplus.hpp | 0 extras/{thread => cpp_support/include}/mutex.hpp | 0 extras/{thread => cpp_support/include}/queue.hpp | 0 extras/{thread => cpp_support/include}/task.hpp | 0 9 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 extras/cpp_support/component.mk rename extras/{timer => cpp_support/include}/countdown.hpp (100%) rename extras/{cplusplus => cpp_support/include}/cplusplus.hpp (100%) rename extras/{thread => cpp_support/include}/mutex.hpp (100%) rename extras/{thread => cpp_support/include}/queue.hpp (100%) rename extras/{thread => cpp_support/include}/task.hpp (100%) diff --git a/common.mk b/common.mk index a73092c..342bae2 100644 --- a/common.mk +++ b/common.mk @@ -177,7 +177,7 @@ IMGTOOL_ARGS=-$(IMGTOOL_FLASH_SIZE) -$(FLASH_MODE) -$(FLASH_SPEED) # Placing $(PROGRAM_DIR) and $(PROGRAM_DIR)include first allows # programs to have their own copies of header config files for components # , which is useful for overriding things. -INC_DIRS = $(PROGRAM_DIR) $(PROGRAM_DIR)include $(ROOT)include $(ROOT)extras +INC_DIRS = $(PROGRAM_DIR) $(PROGRAM_DIR)include $(ROOT)include ifeq ($(OWN_LIBC),1) INC_DIRS += $(ROOT)libc/xtensa-lx106-elf/include diff --git a/examples/cpp_01_tasks/Makefile b/examples/cpp_01_tasks/Makefile index 458932f..f9254cf 100644 --- a/examples/cpp_01_tasks/Makefile +++ b/examples/cpp_01_tasks/Makefile @@ -1,3 +1,5 @@ # Simple makefile for simple example PROGRAM=cpp_01_tasks +OTA=0 +EXTRA_COMPONENTS=extras/cpp_support include ../../common.mk diff --git a/examples/cpp_01_tasks/main.cpp b/examples/cpp_01_tasks/main.cpp index 0b9fe1f..219be74 100644 --- a/examples/cpp_01_tasks/main.cpp +++ b/examples/cpp_01_tasks/main.cpp @@ -26,9 +26,9 @@ * */ -#include "cplusplus/cplusplus.hpp" -#include "thread/task.hpp" -#include "thread/queue.hpp" +#include "cplusplus.hpp" +#include "task.hpp" +#include "queue.hpp" #include "espressif/esp_common.h" diff --git a/extras/cpp_support/component.mk b/extras/cpp_support/component.mk new file mode 100644 index 0000000..6bc4ada --- /dev/null +++ b/extras/cpp_support/component.mk @@ -0,0 +1,8 @@ +# Component makefile for extras/cpp_support +INC_DIRS += $(ROOT)extras/cpp_support/include + +# args for passing into compile rule generation +# extras/mqtt-client_INC_DIR = $(ROOT)extras/mqtt-client +# extras/mqtt-client_SRC_DIR = $(ROOT)extras/mqtt-client + +# $(eval $(call component_compile_rules,extras/mqtt-client)) diff --git a/extras/timer/countdown.hpp b/extras/cpp_support/include/countdown.hpp similarity index 100% rename from extras/timer/countdown.hpp rename to extras/cpp_support/include/countdown.hpp diff --git a/extras/cplusplus/cplusplus.hpp b/extras/cpp_support/include/cplusplus.hpp similarity index 100% rename from extras/cplusplus/cplusplus.hpp rename to extras/cpp_support/include/cplusplus.hpp diff --git a/extras/thread/mutex.hpp b/extras/cpp_support/include/mutex.hpp similarity index 100% rename from extras/thread/mutex.hpp rename to extras/cpp_support/include/mutex.hpp diff --git a/extras/thread/queue.hpp b/extras/cpp_support/include/queue.hpp similarity index 100% rename from extras/thread/queue.hpp rename to extras/cpp_support/include/queue.hpp diff --git a/extras/thread/task.hpp b/extras/cpp_support/include/task.hpp similarity index 100% rename from extras/thread/task.hpp rename to extras/cpp_support/include/task.hpp From 5c1ce0a508971179f457ab9c0f4b67609282a9d8 Mon Sep 17 00:00:00 2001 From: Michael Jacobsen Date: Sun, 23 Aug 2015 10:21:42 +0200 Subject: [PATCH 08/18] Header files adjustment (MQTT changes split from original commit - @projectgus.) --- examples/cpp_01_tasks/main.cpp | 4 ++-- extras/cpp_support/include/mutex.hpp | 20 ++++++++++++++++++-- extras/cpp_support/include/queue.hpp | 7 ++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/examples/cpp_01_tasks/main.cpp b/examples/cpp_01_tasks/main.cpp index 219be74..1295327 100644 --- a/examples/cpp_01_tasks/main.cpp +++ b/examples/cpp_01_tasks/main.cpp @@ -95,9 +95,9 @@ esp_open_rtos::thread::queue_t MyQueue; */ extern "C" void user_init(void) { - sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); + sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); - MyQueue.create(10); + MyQueue.queue_create(10); task_1.queue = MyQueue; task_2.queue = MyQueue; diff --git a/extras/cpp_support/include/mutex.hpp b/extras/cpp_support/include/mutex.hpp index 714c585..aaf29db 100644 --- a/extras/cpp_support/include/mutex.hpp +++ b/extras/cpp_support/include/mutex.hpp @@ -46,14 +46,30 @@ public: */ inline mutex_t() { - mutex = xSemaphoreCreateMutex(); + mutex = 0; + } + /** + * + * @return + */ + inline int mutex_create() + { + mutex = xSemaphoreCreateMutex(); + + if(mutex == NULL) { + return -1; + } + else { + return 0; + } } /** * */ - inline ~mutex_t() + inline void mutex_destroy() { vQueueDelete(mutex); + mutex = 0; } /** * diff --git a/extras/cpp_support/include/queue.hpp b/extras/cpp_support/include/queue.hpp index a24f302..047ce29 100644 --- a/extras/cpp_support/include/queue.hpp +++ b/extras/cpp_support/include/queue.hpp @@ -56,7 +56,7 @@ public: * @param uxItemSize * @return */ - inline int create(unsigned portBASE_TYPE uxQueueLength) + inline int queue_create(unsigned portBASE_TYPE uxQueueLength) { queue = xQueueCreate(uxQueueLength, sizeof(Data)); @@ -69,11 +69,8 @@ public: } /** * - * @param data - * @param ms - * @return */ - inline void destroy() + inline void queue_destroy() { vQueueDelete(queue); queue = 0; From e9b1df5cb5615dcaba9bcf0a36b1343b20a3cba4 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 26 Aug 2015 10:36:40 +1000 Subject: [PATCH 09/18] Post-merge cleanup of extras/cpp_support --- core/cplusplus_operators.cpp | 25 ------------------- examples/cpp_01_tasks/main.cpp | 4 +-- extras/cplusplus/component.mk | 3 --- .../{cplusplus.hpp => cpp_operators.hpp} | 0 4 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 core/cplusplus_operators.cpp delete mode 100644 extras/cplusplus/component.mk rename extras/cpp_support/include/{cplusplus.hpp => cpp_operators.hpp} (100%) diff --git a/core/cplusplus_operators.cpp b/core/cplusplus_operators.cpp deleted file mode 100644 index 86f4477..0000000 --- a/core/cplusplus_operators.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* Part of esp-open-rtos - * BSD Licensed as described in the file LICENSE - */ -#include -#include - -void *operator new(size_t size) -{ - return malloc(size); -} - -void *operator new[](size_t size) -{ - return malloc(size); -} - -void operator delete(void * ptr) -{ - free(ptr); -} - -void operator delete[](void * ptr) -{ - free(ptr); -} diff --git a/examples/cpp_01_tasks/main.cpp b/examples/cpp_01_tasks/main.cpp index 1295327..cf751d6 100644 --- a/examples/cpp_01_tasks/main.cpp +++ b/examples/cpp_01_tasks/main.cpp @@ -26,7 +26,7 @@ * */ -#include "cplusplus.hpp" +#include "cpp_operators.hpp" #include "task.hpp" #include "queue.hpp" @@ -104,4 +104,4 @@ extern "C" void user_init(void) task_1.task_create("tsk1"); task_2.task_create("tsk2"); -} \ No newline at end of file +} diff --git a/extras/cplusplus/component.mk b/extras/cplusplus/component.mk deleted file mode 100644 index 3f5673d..0000000 --- a/extras/cplusplus/component.mk +++ /dev/null @@ -1,3 +0,0 @@ -# Component makefile for extras/cplusplus - -INC_DIRS += $(ROOT)extras diff --git a/extras/cpp_support/include/cplusplus.hpp b/extras/cpp_support/include/cpp_operators.hpp similarity index 100% rename from extras/cpp_support/include/cplusplus.hpp rename to extras/cpp_support/include/cpp_operators.hpp From c565e2b90d091ec80ef4620dd668407e951edea6 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 26 Aug 2015 10:49:00 +1000 Subject: [PATCH 10/18] gpio.h: Explicit cast to enum type (needed for g++) --- core/include/esp/gpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/include/esp/gpio.h b/core/include/esp/gpio.h index 1f1ce14..679fff2 100644 --- a/core/include/esp/gpio.h +++ b/core/include/esp/gpio.h @@ -124,7 +124,7 @@ INLINED void gpio_set_interrupt(const uint8_t gpio_num, const gpio_inttype_t int /* Return the interrupt type set for a pin */ INLINED gpio_inttype_t gpio_get_interrupt(const uint8_t gpio_num) { - return FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[gpio_num]); + return (gpio_inttype_t)FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[gpio_num]); } #endif From 43ecec547062b09e70339476388ce01f6e97c827 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 26 Aug 2015 11:07:06 +1000 Subject: [PATCH 11/18] Move c++ operators back to link-time resolutions, part of 'core' This reverts commit e9b1df5cb5615dcaba9bcf0a36b1343b20a3cba4. --- core/cplusplus_operators.cpp | 25 +++++++ examples/cpp_01_tasks/main.cpp | 3 +- extras/cplusplus/component.mk | 3 + extras/cpp_support/include/cpp_operators.hpp | 75 -------------------- 4 files changed, 29 insertions(+), 77 deletions(-) create mode 100644 core/cplusplus_operators.cpp create mode 100644 extras/cplusplus/component.mk delete mode 100644 extras/cpp_support/include/cpp_operators.hpp diff --git a/core/cplusplus_operators.cpp b/core/cplusplus_operators.cpp new file mode 100644 index 0000000..86f4477 --- /dev/null +++ b/core/cplusplus_operators.cpp @@ -0,0 +1,25 @@ +/* Part of esp-open-rtos + * BSD Licensed as described in the file LICENSE + */ +#include +#include + +void *operator new(size_t size) +{ + return malloc(size); +} + +void *operator new[](size_t size) +{ + return malloc(size); +} + +void operator delete(void * ptr) +{ + free(ptr); +} + +void operator delete[](void * ptr) +{ + free(ptr); +} diff --git a/examples/cpp_01_tasks/main.cpp b/examples/cpp_01_tasks/main.cpp index cf751d6..160a0c8 100644 --- a/examples/cpp_01_tasks/main.cpp +++ b/examples/cpp_01_tasks/main.cpp @@ -26,7 +26,6 @@ * */ -#include "cpp_operators.hpp" #include "task.hpp" #include "queue.hpp" @@ -104,4 +103,4 @@ extern "C" void user_init(void) task_1.task_create("tsk1"); task_2.task_create("tsk2"); -} +} \ No newline at end of file diff --git a/extras/cplusplus/component.mk b/extras/cplusplus/component.mk new file mode 100644 index 0000000..3f5673d --- /dev/null +++ b/extras/cplusplus/component.mk @@ -0,0 +1,3 @@ +# Component makefile for extras/cplusplus + +INC_DIRS += $(ROOT)extras diff --git a/extras/cpp_support/include/cpp_operators.hpp b/extras/cpp_support/include/cpp_operators.hpp deleted file mode 100644 index bf006a8..0000000 --- a/extras/cpp_support/include/cpp_operators.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * The MIT License (MIT) - * - * ESP8266 FreeRTOS Firmware - * Copyright (c) 2015 Michael Jacobsen (github.com/mikejac) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * https://github.com/SuperHouse/esp-open-rtos - * - */ - -#ifndef ESP_OPEN_RTOS_CPLUSPLUS_HPP -#define ESP_OPEN_RTOS_CPLUSPLUS_HPP - -#include - -/****************************************************************************************************************** - * C++ new and delete operators - * - */ - -/** - * - * @param size - * @return - */ -inline void *operator new(size_t size) -{ - return malloc(size); -} -/** - * - * @param size - * @return - */ -inline void *operator new[](size_t size) -{ - return malloc(size); -} -/** - * - * @param ptr - */ -inline void operator delete(void * ptr) -{ - free(ptr); -} -/** - * - * @param ptr - */ -inline void operator delete[](void * ptr) -{ - free(ptr); -} - -#endif /* ESP_OPEN_RTOS_CPLUSPLUS_HPP */ - From c824bcf74a1781df0225cb811fc27fe7b2f99beb Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 26 Aug 2015 11:11:31 +1000 Subject: [PATCH 12/18] common_macros: Include sys/cdefs.h, defines _Static_assert among others --- core/include/common_macros.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/include/common_macros.h b/core/include/common_macros.h index 2b4d73b..7ef2e60 100644 --- a/core/include/common_macros.h +++ b/core/include/common_macros.h @@ -10,6 +10,8 @@ #ifndef _COMMON_MACROS_H #define _COMMON_MACROS_H +#include + #define UNUSED __attributed((unused)) #ifndef BIT From 778b94cf404b7ed52272a6023da18f426cd57408 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 26 Aug 2015 11:14:34 +1000 Subject: [PATCH 13/18] examples/Makefile: Use MAKE to properly invoke make recursively --- examples/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Makefile b/examples/Makefile index 0436a13..2f816e5 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -22,10 +22,10 @@ build-examples: $(EXAMPLES_BUILD) rebuild-examples: $(EXAMPLES_REBUILD) %.dummybuild: - make -C $(dir $@) + $(MAKE) -C $(dir $@) %.dummyrebuild: - make -C $(dir $@) rebuild + $(MAKE) -C $(dir $@) rebuild .PHONY: warning rebuild-examples build-examples .NOTPARALLEL: From 18d1bb21f796d9a92362a7310105c2dc88030996 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 26 Aug 2015 11:16:58 +1000 Subject: [PATCH 14/18] Remove stray extras/cplusplus --- extras/cplusplus/component.mk | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 extras/cplusplus/component.mk diff --git a/extras/cplusplus/component.mk b/extras/cplusplus/component.mk deleted file mode 100644 index 3f5673d..0000000 --- a/extras/cplusplus/component.mk +++ /dev/null @@ -1,3 +0,0 @@ -# Component makefile for extras/cplusplus - -INC_DIRS += $(ROOT)extras From 91d897dbbe7793727c33a4b5a9cec0f89ff35819 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Sat, 12 Sep 2015 15:23:42 +1000 Subject: [PATCH 15/18] iomux: Fix setting of invalid bits when masking in iomux fields Fixes regression from 2a939e97 Part of issue #45 --- core/include/esp/iomux_regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/include/esp/iomux_regs.h b/core/include/esp/iomux_regs.h index 4ea3be2..2600da9 100644 --- a/core/include/esp/iomux_regs.h +++ b/core/include/esp/iomux_regs.h @@ -45,7 +45,7 @@ _Static_assert(sizeof(struct IOMUX_REGS) == 0x44, "IOMUX_REGS is the wrong size" #define IOMUX_PIN_FUNC_MASK 0x00001030 /* WARNING: Macro evaluates argument twice */ -#define IOMUX_FUNC(val) (VAL2FIELD(IOMUX_PIN_FUNC_LOW, val) | VAL2FIELD(IOMUX_PIN_FUNC_HIGH, val)) +#define IOMUX_FUNC(val) (VAL2FIELD_M(IOMUX_PIN_FUNC_LOW, val) | VAL2FIELD_M(IOMUX_PIN_FUNC_HIGH, val)) /* WARNING: Macro evaluates argument twice */ #define IOMUX_FUNC_VALUE(regbits) (FIELD2VAL(IOMUX_PIN_FUNC_LOW, regbits) | FIELD2VAL(IOMUX_PIN_FUNC_HIGH, regbits)) From c45e84d61d2d3f784b0fae4d4612dc2a13ff714e Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Sat, 12 Sep 2015 16:20:05 +1000 Subject: [PATCH 16/18] Rename GPIO_CONF_PUSH_PULL to GPIO_CONF_OPEN_DRAIN Seems I got the functionality of this bit inverted when initially testing. In testing it also seems open drain mode is ignored on some pins, which still source current. Needs more investigation though (may be pullups internal to the ESP modules or set by default in software.) Relates to #45 --- core/include/esp/gpio.h | 10 ++++------ core/include/esp/gpio_regs.h | 15 ++++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/include/esp/gpio.h b/core/include/esp/gpio.h index 1f1ce14..456625a 100644 --- a/core/include/esp/gpio.h +++ b/core/include/esp/gpio.h @@ -27,28 +27,26 @@ typedef enum { INLINED void gpio_enable(const uint8_t gpio_num, const gpio_direction_t direction) { uint32_t iomux_flags; - uint32_t ctrl_val; switch(direction) { case GPIO_INPUT: iomux_flags = 0; - ctrl_val = 0; break; case GPIO_OUTPUT: iomux_flags = IOMUX_PIN_OUTPUT_ENABLE; - ctrl_val = GPIO_CONF_PUSH_PULL; break; case GPIO_OUT_OPEN_DRAIN: iomux_flags = IOMUX_PIN_OUTPUT_ENABLE; - ctrl_val = 0; break; case GPIO_INPUT_PULLUP: iomux_flags = IOMUX_PIN_PULLUP; - ctrl_val = 0; break; } iomux_set_gpio_function(gpio_num, iomux_flags); - GPIO.CONF[gpio_num] = (GPIO.CONF[gpio_num] & FIELD_MASK(GPIO_CONF_INTTYPE)) | ctrl_val; + if(direction == GPIO_OUT_OPEN_DRAIN) + GPIO.CONF[gpio_num] |= GPIO_CONF_OPEN_DRAIN; + else + GPIO.CONF[gpio_num] &= ~GPIO_CONF_OPEN_DRAIN; if (iomux_flags & IOMUX_PIN_OUTPUT_ENABLE) GPIO.ENABLE_OUT_SET = BIT(gpio_num); else diff --git a/core/include/esp/gpio_regs.h b/core/include/esp/gpio_regs.h index 3d91efb..815e7c1 100644 --- a/core/include/esp/gpio_regs.h +++ b/core/include/esp/gpio_regs.h @@ -76,10 +76,15 @@ _Static_assert(sizeof(struct GPIO_REGS) == 0x74, "GPIO_REGS is the wrong size"); * Under what conditions this GPIO input should generate an interrupt. * (see gpio_inttype_t enum below for values) * - * GPIO_CONF_PUSH_PULL (boolean) - * When set, a high output state will pull the pin up to +Vcc (3.3V). When - * cleared, output functions in "open drain" mode (low state will pull down - * to ground, but high state allows output to "float"). + * GPIO_CONF_OPEN_DRAIN (boolean) + * If this bit is set, the pin is in "open drain" mode - a high output state + * will leave the pin floating but not source any current. If bit is cleared, + * the pin is in push/pull mode so a high output state will drive the pin up + * to +Vcc (3.3V). In either case, a low output state will pull the pin down + * to ground. + * + * GPIO_CONF_OPEN_DRAIN does not appear to work on all pins. + * * * GPIO_CONF_SOURCE_PWM (boolean) * When set, GPIO pin output will be connected to the sigma-delta PWM @@ -93,7 +98,7 @@ _Static_assert(sizeof(struct GPIO_REGS) == 0x74, "GPIO_REGS is the wrong size"); #define GPIO_CONF_WAKEUP_ENABLE BIT(10) #define GPIO_CONF_INTTYPE_M 0x00000007 #define GPIO_CONF_INTTYPE_S 7 -#define GPIO_CONF_PUSH_PULL BIT(2) +#define GPIO_CONF_OPEN_DRAIN BIT(2) #define GPIO_CONF_SOURCE_PWM BIT(0) /* Valid values for the GPIO_CONF_INTTYPE field */ From 347f9d3a853605b5cae28d57f040b41932bdb1d2 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Sat, 12 Sep 2015 16:28:11 +1000 Subject: [PATCH 17/18] Rename main.cpp in tasks example --- examples/cpp_01_tasks/{main.cpp => cpp_tasks.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/cpp_01_tasks/{main.cpp => cpp_tasks.cpp} (100%) diff --git a/examples/cpp_01_tasks/main.cpp b/examples/cpp_01_tasks/cpp_tasks.cpp similarity index 100% rename from examples/cpp_01_tasks/main.cpp rename to examples/cpp_01_tasks/cpp_tasks.cpp From cceb9de300affe5b4092951a9d252df05a28d870 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 18 Sep 2015 17:59:47 +1000 Subject: [PATCH 18/18] bmp180 i2c: Fix typo temperatue->temperature. Closes #47 --- examples/bmp180_i2c/bmp180_i2c.c | 6 +++--- extras/bmp180/bmp180.c | 8 ++++---- extras/bmp180/bmp180.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/bmp180_i2c/bmp180_i2c.c b/examples/bmp180_i2c/bmp180_i2c.c index 15c0508..578db67 100644 --- a/examples/bmp180_i2c/bmp180_i2c.c +++ b/examples/bmp180_i2c/bmp180_i2c.c @@ -30,13 +30,13 @@ static xQueueHandle mainqueue; static xTimerHandle timerHandle; // Own BMP180 User Inform Implementation -bool bmp180_i2c_informUser(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperatue, bmp180_press_t pressure) +bool bmp180_i2c_informUser(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure) { my_event_t ev; ev.event_type = MY_EVT_BMP180; ev.bmp180_data.cmd = cmd; - ev.bmp180_data.temperatue = temperatue; + ev.bmp180_data.temperature = temperature; ev.bmp180_data.pressure = pressure; return (xQueueSend(*resultQueue, &ev, 0) == pdTRUE); @@ -74,7 +74,7 @@ void bmp180_task(void *pvParameters) break; case MY_EVT_BMP180: printf("%s: Received BMP180 Event temp:=%d.%d°C press=%d.%02dhPa\n", __FUNCTION__, \ - (int32_t)ev.bmp180_data.temperatue, abs((int32_t)(ev.bmp180_data.temperatue*10)%10), \ + (int32_t)ev.bmp180_data.temperature, abs((int32_t)(ev.bmp180_data.temperature*10)%10), \ ev.bmp180_data.pressure/100, ev.bmp180_data.pressure%100 ); break; default: diff --git a/extras/bmp180/bmp180.c b/extras/bmp180/bmp180.c index 66203b0..7291236 100644 --- a/extras/bmp180/bmp180.c +++ b/extras/bmp180/bmp180.c @@ -75,10 +75,10 @@ static int16_t MD; // Forward declarations // static void bmp180_meassure(const bmp180_command_t* command); -static bool bmp180_informUser_Impl(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperatue, bmp180_press_t pressure); +static bool bmp180_informUser_Impl(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure); // Set default implementation .. User gets result as bmp180_result_t event -bool (*bmp180_informUser)(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperatue, bmp180_press_t pressure) = bmp180_informUser_Impl; +bool (*bmp180_informUser)(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure) = bmp180_informUser_Impl; // I2C Driver Task static void bmp180_driver_task(void *pvParameters) @@ -279,12 +279,12 @@ static void bmp180_meassure(const bmp180_command_t* command) } // Default user inform implementation -static bool bmp180_informUser_Impl(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperatue, bmp180_press_t pressure) +static bool bmp180_informUser_Impl(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure) { bmp180_result_t result; result.cmd = cmd; - result.temperatue = temperatue; + result.temperature = temperature; result.pressure = pressure; return (xQueueSend(*resultQueue, &result, 0) == pdTRUE); diff --git a/extras/bmp180/bmp180.h b/extras/bmp180/bmp180.h index 73709ff..b675130 100644 --- a/extras/bmp180/bmp180.h +++ b/extras/bmp180/bmp180.h @@ -33,7 +33,7 @@ typedef uint32_t bmp180_press_t; typedef struct { uint8_t cmd; - bmp180_temp_t temperatue; + bmp180_temp_t temperature; bmp180_press_t pressure; } bmp180_result_t; @@ -50,6 +50,6 @@ void bmp180_trigger_temperature_measurement(const xQueueHandle* resultQueue); void bmp180_trigger_pressure_measurement(const xQueueHandle* resultQueue); // Give the user the chance to create it's own handler -extern bool (*bmp180_informUser)(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperatue, bmp180_press_t pressure); +extern bool (*bmp180_informUser)(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure); #endif /* DRIVER_BMP180_H_ */