Merge branch 'feature/c++'
This commit is contained in:
commit
8b90dbd9e5
29 changed files with 801 additions and 14 deletions
|
@ -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();
|
||||
|
||||
|
|
25
common.mk
25
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 -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)
|
||||
CFLAGS += -g -O0
|
||||
C_CXX_FLAGS += -g -O0
|
||||
LDFLAGS += -g -O0
|
||||
else
|
||||
CFLAGS += -g -O2
|
||||
C_CXX_FLAGS += -g -O2
|
||||
LDFLAGS += -g -O2
|
||||
endif
|
||||
|
||||
|
@ -216,19 +221,23 @@ $(1)_ROOT ?= $$($(1)_DEFAULT_ROOT)
|
|||
$(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)) \
|
||||
$$(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))
|
||||
|
||||
### 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)
|
||||
|
@ -237,6 +246,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 $$@)
|
||||
|
|
25
core/cplusplus_operators.cpp
Normal file
25
core/cplusplus_operators.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* Part of esp-open-rtos
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef _COMMON_MACROS_H
|
||||
#define _COMMON_MACROS_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#define UNUSED __attributed((unused))
|
||||
|
||||
#ifndef BIT
|
||||
|
@ -45,7 +47,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.
|
||||
*/
|
||||
#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))
|
||||
|
||||
|
|
|
@ -122,7 +122,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
|
||||
|
|
|
@ -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)();
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
5
examples/cpp_01_tasks/Makefile
Normal file
5
examples/cpp_01_tasks/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Simple makefile for simple example
|
||||
PROGRAM=cpp_01_tasks
|
||||
OTA=0
|
||||
EXTRA_COMPONENTS=extras/cpp_support
|
||||
include ../../common.mk
|
106
examples/cpp_01_tasks/main.cpp
Normal file
106
examples/cpp_01_tasks/main.cpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#include "task.hpp"
|
||||
#include "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<uint32_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<uint32_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 %u\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<uint32_t> MyQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
extern "C" void user_init(void)
|
||||
{
|
||||
sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
|
||||
|
||||
MyQueue.queue_create(10);
|
||||
|
||||
task_1.queue = MyQueue;
|
||||
task_2.queue = MyQueue;
|
||||
|
||||
task_1.task_create("tsk1");
|
||||
task_2.task_create("tsk2");
|
||||
}
|
3
examples/simple_cplusplus/Makefile
Normal file
3
examples/simple_cplusplus/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Simple makefile for simple example
|
||||
PROGRAM=simple
|
||||
include ../../common.mk
|
64
examples/simple_cplusplus/simple.cpp
Normal file
64
examples/simple_cplusplus/simple.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* 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 %d\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);
|
||||
Counter *new_counter = new Counter(24);
|
||||
while(1) {
|
||||
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 %d static counter %d newly allocated counter %d\r\n", local_counter.getCount(),
|
||||
static_counter.getCount(), new_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);
|
||||
}
|
8
extras/cpp_support/component.mk
Normal file
8
extras/cpp_support/component.mk
Normal file
|
@ -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))
|
102
extras/cpp_support/include/countdown.hpp
Normal file
102
extras/cpp_support/include/countdown.hpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* 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_TIMER_HPP
|
||||
#define 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
|
113
extras/cpp_support/include/mutex.hpp
Normal file
113
extras/cpp_support/include/mutex.hpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* 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_MUTEX_HPP
|
||||
#define 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 = 0;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
inline int mutex_create()
|
||||
{
|
||||
mutex = xSemaphoreCreateMutex();
|
||||
|
||||
if(mutex == NULL) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
inline void mutex_destroy()
|
||||
{
|
||||
vQueueDelete(mutex);
|
||||
mutex = 0;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @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 /* ESP_OPEN_RTOS_MUTEX_HPP */
|
||||
|
124
extras/cpp_support/include/queue.hpp
Normal file
124
extras/cpp_support/include/queue.hpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* 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_QUEUE_HPP
|
||||
#define ESP_OPEN_RTOS_QUEUE_HPP
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
|
||||
namespace esp_open_rtos {
|
||||
namespace thread {
|
||||
|
||||
/******************************************************************************************************************
|
||||
* class queue_t
|
||||
*
|
||||
*/
|
||||
template<class Data>
|
||||
class queue_t
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*
|
||||
*/
|
||||
inline queue_t()
|
||||
{
|
||||
queue = 0;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param uxQueueLength
|
||||
* @param uxItemSize
|
||||
* @return
|
||||
*/
|
||||
inline int queue_create(unsigned portBASE_TYPE uxQueueLength)
|
||||
{
|
||||
queue = xQueueCreate(uxQueueLength, sizeof(Data));
|
||||
|
||||
if(queue == NULL) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
inline void queue_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 /* ESP_OPEN_RTOS_QUEUE_HPP */
|
||||
|
106
extras/cpp_support/include/task.hpp
Normal file
106
extras/cpp_support/include/task.hpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* 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_TASK_HPP
|
||||
#define 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 /* ESP_OPEN_RTOS_TASK_HPP */
|
||||
|
3
extras/thread/component.mk
Normal file
3
extras/thread/component.mk
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Component makefile for extras/thread
|
||||
|
||||
INC_DIRS += $(ROOT)extras
|
3
extras/timer/component.mk
Normal file
3
extras/timer/component.mk
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Component makefile for extras/timer
|
||||
|
||||
INC_DIRS += $(ROOT)extras
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
#include <lwip/ip_addr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
NULL_MODE = 0,
|
||||
STATION_MODE,
|
||||
|
@ -67,7 +71,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
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
#define SDK_PRIVATE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.*)))
|
||||
|
|
Loading…
Reference in a new issue