Skip to content

Commit

Permalink
Merge branch 'feature/amazon_freertos_compat_v2' into 'master'
Browse files Browse the repository at this point in the history
Changes for Amazon Freertos compatibility

See merge request idf/esp-idf!2123
  • Loading branch information
igrr committed Apr 20, 2018
2 parents 6fd25b4 + 441b4a9 commit 22fbcd2
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 28 deletions.
12 changes: 6 additions & 6 deletions components/driver/spi_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ bool IRAM_ATTR spicommon_dmaworkaround_req_reset(int dmachan, dmaworkaround_cb_t
{
int otherchan = (dmachan == 1) ? 2 : 1;
bool ret;
portENTER_CRITICAL(&dmaworkaround_mux);
portENTER_CRITICAL_ISR(&dmaworkaround_mux);
if (dmaworkaround_channels_busy[otherchan-1]) {
//Other channel is busy. Call back when it's done.
dmaworkaround_cb = cb;
Expand All @@ -450,7 +450,7 @@ bool IRAM_ATTR spicommon_dmaworkaround_req_reset(int dmachan, dmaworkaround_cb_t
periph_module_reset( PERIPH_SPI_DMA_MODULE );
ret = true;
}
portEXIT_CRITICAL(&dmaworkaround_mux);
portEXIT_CRITICAL_ISR(&dmaworkaround_mux);
return ret;
}

Expand All @@ -461,7 +461,7 @@ bool IRAM_ATTR spicommon_dmaworkaround_reset_in_progress()

void IRAM_ATTR spicommon_dmaworkaround_idle(int dmachan)
{
portENTER_CRITICAL(&dmaworkaround_mux);
portENTER_CRITICAL_ISR(&dmaworkaround_mux);
dmaworkaround_channels_busy[dmachan-1] = 0;
if (dmaworkaround_waiting_for_chan == dmachan) {
//Reset DMA
Expand All @@ -471,14 +471,14 @@ void IRAM_ATTR spicommon_dmaworkaround_idle(int dmachan)
dmaworkaround_cb(dmaworkaround_cb_arg);

}
portEXIT_CRITICAL(&dmaworkaround_mux);
portEXIT_CRITICAL_ISR(&dmaworkaround_mux);
}

void IRAM_ATTR spicommon_dmaworkaround_transfer_active(int dmachan)
{
portENTER_CRITICAL(&dmaworkaround_mux);
portENTER_CRITICAL_ISR(&dmaworkaround_mux);
dmaworkaround_channels_busy[dmachan-1] = 1;
portEXIT_CRITICAL(&dmaworkaround_mux);
portEXIT_CRITICAL_ISR(&dmaworkaround_mux);
}


3 changes: 1 addition & 2 deletions components/esp32/cpu_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
#include "freertos/queue.h"
#include "freertos/portmacro.h"

#include "tcpip_adapter.h"

#include "esp_heap_caps_init.h"
#include "sdkconfig.h"
#include "esp_system.h"
Expand All @@ -55,6 +53,7 @@
#include "esp_newlib.h"
#include "esp_brownout.h"
#include "esp_int_wdt.h"
#include "esp_task.h"
#include "esp_task_wdt.h"
#include "esp_phy_init.h"
#include "esp_cache_err_int.h"
Expand Down
4 changes: 2 additions & 2 deletions components/esp32/crosscore_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ static void IRAM_ATTR esp_crosscore_isr(void *arg) {
DPORT_WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_1_REG, 0);
}
//Grab the reason and clear it.
portENTER_CRITICAL(&reason_spinlock);
portENTER_CRITICAL_ISR(&reason_spinlock);
my_reason_val=*my_reason;
*my_reason=0;
portEXIT_CRITICAL(&reason_spinlock);
portEXIT_CRITICAL_ISR(&reason_spinlock);

//Check what we need to do.
if (my_reason_val & REASON_YIELD) {
Expand Down
10 changes: 5 additions & 5 deletions components/esp32/esp_timer_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp)

static void IRAM_ATTR timer_alarm_isr(void *arg)
{
portENTER_CRITICAL(&s_time_update_lock);
portENTER_CRITICAL_ISR(&s_time_update_lock);
// Timekeeping: adjust s_time_base_us if counter has passed ALARM_OVERFLOW_VAL
if (timer_overflow_happened()) {
timer_count_reload();
Expand All @@ -256,17 +256,17 @@ static void IRAM_ATTR timer_alarm_isr(void *arg)
// Set alarm to the next overflow moment. Later, upper layer function may
// call esp_timer_impl_set_alarm to change this to an earlier value.
REG_WRITE(FRC_TIMER_ALARM_REG(1), ALARM_OVERFLOW_VAL);
portEXIT_CRITICAL(&s_time_update_lock);
portEXIT_CRITICAL_ISR(&s_time_update_lock);
// Call the upper layer handler
(*s_alarm_handler)(arg);
}

void IRAM_ATTR esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us)
{
portENTER_CRITICAL(&s_time_update_lock);
portENTER_CRITICAL_ISR(&s_time_update_lock);
/* Bail out if the timer is not initialized yet */
if (s_timer_interrupt_handle == NULL) {
portEXIT_CRITICAL(&s_time_update_lock);
portEXIT_CRITICAL_ISR(&s_time_update_lock);
return;
}

Expand Down Expand Up @@ -308,7 +308,7 @@ void IRAM_ATTR esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us)
s_timer_ticks_per_us = new_ticks_per_us;
s_timer_us_per_overflow = ALARM_OVERFLOW_VAL / new_ticks_per_us;

portEXIT_CRITICAL(&s_time_update_lock);
portEXIT_CRITICAL_ISR(&s_time_update_lock);
}

esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler)
Expand Down
5 changes: 4 additions & 1 deletion components/freertos/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -3878,6 +3878,10 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask )

static void prvDeleteTCB( TCB_t *pxTCB )
{
/* This call is required for any port specific cleanup related to task.
It must be above the vPortFree() calls. */
portCLEAN_UP_TCB( pxTCB );

/* Free up the memory allocated by the scheduler for the task. It is up
to the task to free any memory allocated at the application level. */
#if ( configUSE_NEWLIB_REENTRANT == 1 )
Expand Down Expand Up @@ -3920,7 +3924,6 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
/* Neither the stack nor the TCB were allocated dynamically, so
nothing needs to be freed. */
configASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB )
portCLEAN_UP_TCB( pxTCB );
mtCOVERAGE_TEST_MARKER();
}
}
Expand Down
16 changes: 8 additions & 8 deletions components/heap/heap_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ esp_err_t heap_trace_start(heap_trace_mode_t mode_param)
if (buffer == NULL || total_records == 0) {
return ESP_ERR_INVALID_STATE;
}
taskENTER_CRITICAL(&trace_mux);
portENTER_CRITICAL(&trace_mux);

tracing = false;
mode = mode_param;
Expand All @@ -87,7 +87,7 @@ esp_err_t heap_trace_start(heap_trace_mode_t mode_param)
has_overflowed = false;
heap_trace_resume();

taskEXIT_CRITICAL(&trace_mux);
portEXIT_CRITICAL(&trace_mux);
return ESP_OK;
}

Expand Down Expand Up @@ -128,13 +128,13 @@ esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record)
}
esp_err_t result = ESP_OK;

taskENTER_CRITICAL(&trace_mux);
portENTER_CRITICAL(&trace_mux);
if (index >= count) {
result = ESP_ERR_INVALID_ARG; /* out of range for 'count' */
} else {
memcpy(record, &buffer[index], sizeof(heap_trace_record_t));
}
taskEXIT_CRITICAL(&trace_mux);
portEXIT_CRITICAL(&trace_mux);
return result;
}

Expand Down Expand Up @@ -192,7 +192,7 @@ void heap_trace_dump(void)
/* Add a new allocation to the heap trace records */
static IRAM_ATTR void record_allocation(const heap_trace_record_t *record)
{
taskENTER_CRITICAL(&trace_mux);
portENTER_CRITICAL(&trace_mux);
if (tracing) {
if (count == total_records) {
has_overflowed = true;
Expand All @@ -211,7 +211,7 @@ static IRAM_ATTR void record_allocation(const heap_trace_record_t *record)
count++;
total_allocations++;
}
taskEXIT_CRITICAL(&trace_mux);
portEXIT_CRITICAL(&trace_mux);
}

// remove a record, used when freeing
Expand All @@ -224,7 +224,7 @@ static void remove_record(int index);
*/
static IRAM_ATTR void record_free(void *p, void **callers)
{
taskENTER_CRITICAL(&trace_mux);
portENTER_CRITICAL(&trace_mux);
if (tracing && count > 0) {
total_frees++;
/* search backwards for the allocation record matching this free */
Expand All @@ -244,7 +244,7 @@ static IRAM_ATTR void record_free(void *p, void **callers)
}
}
}
taskEXIT_CRITICAL(&trace_mux);
portEXIT_CRITICAL(&trace_mux);
}

/* remove the entry at 'index' from the ringbuffer of saved records */
Expand Down
5 changes: 2 additions & 3 deletions components/heap/multi_heap_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@
#ifdef ESP_PLATFORM

#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <rom/ets_sys.h>
#include <assert.h>

/* Because malloc/free can happen inside an ISR context,
we need to use portmux spinlocks here not RTOS mutexes */
#define MULTI_HEAP_LOCK(PLOCK) do { \
if((PLOCK) != NULL) { \
taskENTER_CRITICAL((portMUX_TYPE *)(PLOCK)); \
portENTER_CRITICAL((portMUX_TYPE *)(PLOCK)); \
} \
} while(0)


#define MULTI_HEAP_UNLOCK(PLOCK) do { \
if ((PLOCK) != NULL) { \
taskEXIT_CRITICAL((portMUX_TYPE *)(PLOCK)); \
portEXIT_CRITICAL((portMUX_TYPE *)(PLOCK)); \
} \
} while(0)

Expand Down
5 changes: 5 additions & 0 deletions components/newlib/include/sys/reent.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,18 @@ extern const struct __sFILE_fake __sf_fake_stderr;
_NULL \
}

#ifndef ESP_PLATFORM
#define _REENT_INIT_PTR(var) \
{ memset((var), 0, sizeof(*(var))); \
(var)->_stdin = (__FILE *)&__sf_fake_stdin; \
(var)->_stdout = (__FILE *)&__sf_fake_stdout; \
(var)->_stderr = (__FILE *)&__sf_fake_stderr; \
(var)->_current_locale = "C"; \
}
#else
extern void esp_reent_init(struct _reent* reent);
#define _REENT_INIT_PTR(var) esp_reent_init(var)
#endif

/* Only built the assert() calls if we are built with debugging. */
#if DEBUG
Expand Down
4 changes: 4 additions & 0 deletions components/pthread/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ COMPONENT_SRCDIRS := .
COMPONENT_ADD_INCLUDEDIRS := include

COMPONENT_ADD_LDFLAGS := -lpthread

ifdef CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK
COMPONENT_ADD_LDFLAGS += -Wl,--wrap=vPortCleanUpTCB
endif
31 changes: 31 additions & 0 deletions components/pthread/pthread_local_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,29 @@ static void pthread_local_storage_thread_deleted_callback(int index, void *v_tls
free(tls);
}

#if defined(CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK)
/* Called from FreeRTOS task delete hook */
void pthread_local_storage_cleanup(TaskHandle_t task)
{
void *tls = pvTaskGetThreadLocalStoragePointer(task, PTHREAD_TLS_INDEX);
if (tls != NULL) {
pthread_local_storage_thread_deleted_callback(PTHREAD_TLS_INDEX, tls);
vTaskSetThreadLocalStoragePointer(task, PTHREAD_TLS_INDEX, NULL);
}
}

void __real_vPortCleanUpTCB(void *tcb);

/* If static task cleanup hook is defined then its applications responsibility to define `vPortCleanUpTCB`.
Here we are wrapping it, so that we can do pthread specific TLS cleanup and then invoke application
real specific `vPortCleanUpTCB` */
void __wrap_vPortCleanUpTCB(void *tcb)
{
pthread_local_storage_cleanup(tcb);
__real_vPortCleanUpTCB(tcb);
}
#endif

/* this function called from pthread_task_func for "early" cleanup of TLS in a pthread */
void pthread_internal_local_storage_destructor_callback()
{
Expand All @@ -151,10 +174,14 @@ void pthread_internal_local_storage_destructor_callback()
/* remove the thread-local-storage pointer to avoid the idle task cleanup
calling it again...
*/
#if defined(CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK)
vTaskSetThreadLocalStoragePointer(NULL, PTHREAD_TLS_INDEX, NULL);
#else
vTaskSetThreadLocalStoragePointerAndDelCallback(NULL,
PTHREAD_TLS_INDEX,
NULL,
NULL);
#endif
}
}

Expand Down Expand Up @@ -196,10 +223,14 @@ int pthread_setspecific(pthread_key_t key, const void *value)
if (tls == NULL) {
return ENOMEM;
}
#if defined(CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK)
vTaskSetThreadLocalStoragePointer(NULL, PTHREAD_TLS_INDEX, tls);
#else
vTaskSetThreadLocalStoragePointerAndDelCallback(NULL,
PTHREAD_TLS_INDEX,
tls,
pthread_local_storage_thread_deleted_callback);
#endif
}

value_entry_t *entry = find_value(tls, key);
Expand Down
2 changes: 2 additions & 0 deletions components/smartconfig/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#
# Component Makefile
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion components/wpa_supplicant/port/include/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "rom/ets_sys.h"
#include "lwip/mem.h"

typedef long os_time_t;

/**
Expand Down

0 comments on commit 22fbcd2

Please sign in to comment.