forked from espressif/esp-idf
Merge branch 'refactor/freertos_port_files' into 'master'
FreeRTOS: Tidy up existing port files Closes IDF-3919 See merge request espressif/esp-idf!15199
This commit is contained in:
@@ -90,7 +90,6 @@
|
|||||||
#define portNUM_PROCESSORS 1
|
#define portNUM_PROCESSORS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define configASSERT_2 0
|
|
||||||
#define portUSING_MPU_WRAPPERS 0
|
#define portUSING_MPU_WRAPPERS 0
|
||||||
#define configUSE_MUTEX 1
|
#define configUSE_MUTEX 1
|
||||||
|
|
||||||
@@ -206,7 +205,6 @@
|
|||||||
#define configGENERATE_RUN_TIME_STATS 1 /* Used by vTaskGetRunTimeStats() */
|
#define configGENERATE_RUN_TIME_STATS 1 /* Used by vTaskGetRunTimeStats() */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define configUSE_TRACE_FACILITY_2 0
|
|
||||||
#define configBENCHMARK 0
|
#define configBENCHMARK 0
|
||||||
#define configUSE_16_BIT_TICKS 0
|
#define configUSE_16_BIT_TICKS 0
|
||||||
#define configIDLE_SHOULD_YIELD 0
|
#define configIDLE_SHOULD_YIELD 0
|
||||||
|
@@ -1,16 +1,8 @@
|
|||||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
/*
|
||||||
//
|
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
*
|
||||||
// you may not use this file except in compliance with the License.
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
// You may obtain a copy of the License at
|
*/
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
@@ -22,8 +14,9 @@
|
|||||||
#include "esp_task_wdt.h"
|
#include "esp_task_wdt.h"
|
||||||
#include "esp_task.h"
|
#include "esp_task.h"
|
||||||
#include "esp_private/crosscore_int.h"
|
#include "esp_private/crosscore_int.h"
|
||||||
#include "esp_private/startup_internal.h"
|
#include "esp_private/startup_internal.h" /* Required by g_spiram_ok. [refactor-todo] for g_spiram_ok */
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
#include "soc/soc_memory_types.h"
|
||||||
#include "soc/dport_access.h"
|
#include "soc/dport_access.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
@@ -136,3 +129,19 @@ static void main_task(void* args)
|
|||||||
app_main();
|
app_main();
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------- Heap Related -----------------------
|
||||||
|
|
||||||
|
bool xPortCheckValidTCBMem(const void *ptr)
|
||||||
|
{
|
||||||
|
return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool xPortcheckValidStackMem(const void *ptr)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
|
||||||
|
return esp_ptr_byte_accessible(ptr);
|
||||||
|
#else
|
||||||
|
return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@@ -24,46 +24,47 @@
|
|||||||
*
|
*
|
||||||
* 1 tab == 4 spaces!
|
* 1 tab == 4 spaces!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PORTMACRO_H
|
#ifndef PORTMACRO_H
|
||||||
#define PORTMACRO_H
|
#define PORTMACRO_H
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLER__
|
||||||
|
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "soc/spinlock.h"
|
||||||
|
#include "soc/interrupt_core0_reg.h"
|
||||||
|
#include "soc/cpu.h"
|
||||||
|
#include "esp_attr.h"
|
||||||
|
#include "esp_rom_sys.h"
|
||||||
|
#include "esp_timer.h" /* required for FreeRTOS run time stats */
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
|
#include "esp_system.h" /* required by esp_get_...() functions in portable.h. [refactor-todo] Update portable.h */
|
||||||
|
#include "esp_newlib.h"
|
||||||
|
#include "portbenchmark.h"
|
||||||
|
|
||||||
|
/* [refactor-todo] These includes are not directly used in this file. They are kept into to prevent a breaking change. Remove these. */
|
||||||
|
#include <limits.h>
|
||||||
|
#ifdef CONFIG_LEGACY_INCLUDE_COMMON_HEADERS
|
||||||
|
#include "soc/soc_memory_layout.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __ASSEMBLER__
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include "esp_timer.h" /* required for FreeRTOS run time stats */
|
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
/* --------------------------------------------------- Port Types ------------------------------------------------------
|
||||||
#include "esp_attr.h"
|
* - Port specific types.
|
||||||
#include "esp_heap_caps.h"
|
* - The settings in this file configure FreeRTOS correctly for the given hardware and compiler.
|
||||||
#ifdef CONFIG_LEGACY_INCLUDE_COMMON_HEADERS
|
* - These settings should not be altered.
|
||||||
#include "soc/soc_memory_layout.h"
|
* - The port types must come first as they are used further down in this file
|
||||||
#endif
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
#include "soc/spinlock.h"
|
|
||||||
#include "soc/interrupt_core0_reg.h"
|
|
||||||
#include "esp_rom_sys.h"
|
|
||||||
#include "soc/cpu.h"
|
|
||||||
#include "esp_system.h"
|
|
||||||
#include "esp_newlib.h"
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------
|
|
||||||
* Port specific definitions.
|
|
||||||
*
|
|
||||||
* The settings in this file configure FreeRTOS correctly for the
|
|
||||||
* given hardware and compiler.
|
|
||||||
*
|
|
||||||
* These settings should not be altered.
|
|
||||||
*-----------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Type definitions. */
|
|
||||||
#define portCHAR uint8_t
|
#define portCHAR uint8_t
|
||||||
#define portFLOAT float
|
#define portFLOAT float
|
||||||
#define portDOUBLE double
|
#define portDOUBLE double
|
||||||
@@ -71,110 +72,115 @@ extern "C" {
|
|||||||
#define portSHORT int16_t
|
#define portSHORT int16_t
|
||||||
#define portSTACK_TYPE uint8_t
|
#define portSTACK_TYPE uint8_t
|
||||||
#define portBASE_TYPE int
|
#define portBASE_TYPE int
|
||||||
// interrupt module will mask interrupt with priority less than threshold
|
|
||||||
#define RVHAL_EXCM_LEVEL 4
|
|
||||||
|
|
||||||
typedef portSTACK_TYPE StackType_t;
|
typedef portSTACK_TYPE StackType_t;
|
||||||
typedef portBASE_TYPE BaseType_t;
|
typedef portBASE_TYPE BaseType_t;
|
||||||
typedef unsigned portBASE_TYPE UBaseType_t;
|
typedef unsigned portBASE_TYPE UBaseType_t;
|
||||||
|
|
||||||
#if( configUSE_16_BIT_TICKS == 1 )
|
#if (configUSE_16_BIT_TICKS == 1)
|
||||||
typedef uint16_t TickType_t;
|
typedef uint16_t TickType_t;
|
||||||
#define portMAX_DELAY ( TickType_t ) 0xffff
|
#define portMAX_DELAY (TickType_t) 0xffff
|
||||||
#else
|
#else
|
||||||
typedef uint32_t TickType_t;
|
typedef uint32_t TickType_t;
|
||||||
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
|
#define portMAX_DELAY (TickType_t) 0xffffffffUL
|
||||||
#endif
|
#endif
|
||||||
/*------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Architecture specifics. */
|
/* Task function macros as described on the FreeRTOS.org WEB site. */
|
||||||
#define portSTACK_GROWTH ( -1 )
|
#define portTASK_FUNCTION_PROTO(vFunction, pvParameters) void vFunction(void *pvParameters)
|
||||||
#define portTICK_PERIOD_MS ( ( TickType_t ) (1000 / configTICK_RATE_HZ) )
|
#define portTASK_FUNCTION(vFunction, pvParameters) void vFunction(void *pvParameters)
|
||||||
#define portBYTE_ALIGNMENT 16
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
#include "portbenchmark.h"
|
|
||||||
|
|
||||||
static inline BaseType_t IRAM_ATTR xPortGetCoreID(void) {
|
// interrupt module will mask interrupt with priority less than threshold
|
||||||
return cpu_hal_get_core_id();
|
#define RVHAL_EXCM_LEVEL 4
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline bool IRAM_ATTR xPortCanYield(void)
|
|
||||||
{
|
|
||||||
uint32_t threshold = REG_READ(INTERRUPT_CORE0_CPU_INT_THRESH_REG);
|
|
||||||
/* when enter critical code, freertos will mask threshold to RVHAL_EXCM_LEVEL
|
|
||||||
* and exit critical code, will recover threshold value (1). so threshold <= 1
|
|
||||||
* means not in critical code
|
|
||||||
*/
|
|
||||||
return (threshold <= 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set)
|
/* ----------------------------------------------- Port Configurations -------------------------------------------------
|
||||||
{
|
* - Configurations values supplied by each port
|
||||||
#if defined(CONFIG_SPIRAM)
|
* - Required by FreeRTOS
|
||||||
compare_and_set_extram(addr, compare, set);
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set) {
|
|
||||||
compare_and_set_native(addr, compare, set);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define portCRITICAL_NESTING_IN_TCB 0
|
#define portCRITICAL_NESTING_IN_TCB 0
|
||||||
|
#define portSTACK_GROWTH (-1)
|
||||||
|
#define portTICK_PERIOD_MS ((TickType_t) (1000 / configTICK_RATE_HZ))
|
||||||
|
#define portBYTE_ALIGNMENT 16
|
||||||
|
#define portNOP() __asm volatile (" nop ")
|
||||||
|
|
||||||
/*
|
|
||||||
* Send an interrupt to another core in order to make the task running
|
|
||||||
* on it yield for a higher-priority task.
|
|
||||||
*/
|
|
||||||
void vPortYieldOtherCore( BaseType_t coreid);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Callback to set a watchpoint on the end of the stack. Called every context switch to change the stack
|
|
||||||
watchpoint around.
|
|
||||||
*/
|
|
||||||
void vPortSetStackWatchpoint( void* pxStackStart );
|
|
||||||
|
|
||||||
/*
|
/* ---------------------------------------------- Forward Declarations -------------------------------------------------
|
||||||
* Returns true if the current core is in ISR context; low prio ISR, med prio ISR or timer tick ISR. High prio ISRs
|
* - Forward declarations of all the port functions and macros need to implement the FreeRTOS porting interface
|
||||||
* aren't detected here, but they normally cannot call C code, so that should not be an issue anyway.
|
* - These must come before definition/declaration of the FreeRTOS porting interface
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
// --------------------- Interrupts ------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the current core is in an ISR context
|
||||||
|
*
|
||||||
|
* - ISR context consist of Low/Mid priority ISR, or time tick ISR
|
||||||
|
* - High priority ISRs aren't detected here, but they normally cannot call C code, so that should not be an issue anyway.
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] Check if this should be inlined
|
||||||
|
* @return
|
||||||
|
* - pdTRUE if in ISR
|
||||||
|
* - pdFALSE otherwise
|
||||||
*/
|
*/
|
||||||
BaseType_t xPortInIsrContext(void);
|
BaseType_t xPortInIsrContext(void);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* This function will be called in High prio ISRs. Returns true if the current core was in ISR context
|
* @brief Check if in ISR context from High priority ISRs
|
||||||
* before calling into high prio ISR context.
|
*
|
||||||
|
* - Called from High priority ISR
|
||||||
|
* - Checks if the previous context (before high priority interrupt) was in ISR context (meaning low/med priority)
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] Check if this should be inlined
|
||||||
|
* @return
|
||||||
|
* - pdTRUE if in previous in ISR context
|
||||||
|
* - pdFALSE otherwise
|
||||||
*/
|
*/
|
||||||
BaseType_t xPortInterruptedFromISRContext(void);
|
BaseType_t xPortInterruptedFromISRContext(void);
|
||||||
|
|
||||||
/* "mux" data structure (spinlock) */
|
/**
|
||||||
|
* @brief Disable interrupts in a nested manner
|
||||||
|
*
|
||||||
|
* - Cleaner solution allows nested interrupts disabling and restoring via local registers or stack.
|
||||||
|
* - They can be called from interrupts too.
|
||||||
|
* - WARNING Only applies to current CPU.
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] Define this as portSET_INTERRUPT_MASK_FROM_ISR() instead
|
||||||
|
* @return unsigned Previous interrupt state
|
||||||
|
*/
|
||||||
|
static inline unsigned portENTER_CRITICAL_NESTED(void);
|
||||||
|
|
||||||
|
/* ---------------------- Spinlocks ------------------------
|
||||||
|
- Spinlocks added to match API with SMP FreeRTOS. Single core RISC-V does not need spin locks
|
||||||
|
- Because single core does not have a primitive spinlock data type, we have to implement one here
|
||||||
|
* @note [refactor-todo] Refactor critical section API so that this is no longer required
|
||||||
|
* ------------------------------------------------------ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Spinlock object
|
||||||
|
* Owner:
|
||||||
|
* - Set to 0 if uninitialized
|
||||||
|
* - Set to portMUX_FREE_VAL when free
|
||||||
|
* - Set to CORE_ID_REGVAL_PRO or CORE_ID_REGVAL_AP when locked
|
||||||
|
* - Any other value indicates corruption
|
||||||
|
* Count:
|
||||||
|
* - 0 if unlocked
|
||||||
|
* - Recursive count if locked
|
||||||
|
*
|
||||||
|
* @note Not a true spinlock as single core RISC-V does not have atomic compare and set instruction
|
||||||
|
* @note Keep portMUX_INITIALIZER_UNLOCKED in sync with this struct
|
||||||
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* owner field values:
|
|
||||||
* 0 - Uninitialized (invalid)
|
|
||||||
* portMUX_FREE_VAL - Mux is free, can be locked by either CPU
|
|
||||||
* CORE_ID_REGVAL_PRO / CORE_ID_REGVAL_APP - Mux is locked to the particular core
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Any value other than portMUX_FREE_VAL, CORE_ID_REGVAL_PRO, CORE_ID_REGVAL_APP indicates corruption
|
|
||||||
*/
|
|
||||||
uint32_t owner;
|
uint32_t owner;
|
||||||
/* count field:
|
|
||||||
* If mux is unlocked, count should be zero.
|
|
||||||
* If mux is locked, count is non-zero & represents the number of recursive locks on the mux.
|
|
||||||
*/
|
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
const char *lastLockedFn;
|
const char *lastLockedFn;
|
||||||
int lastLockedLine;
|
int lastLockedLine;
|
||||||
#endif
|
#endif
|
||||||
} portMUX_TYPE;
|
} portMUX_TYPE;
|
||||||
|
/**< Spinlock initializer */
|
||||||
#define portMUX_FREE_VAL SPINLOCK_FREE
|
|
||||||
|
|
||||||
/* Special constants for vPortCPUAcquireMutexTimeout() */
|
|
||||||
#define portMUX_NO_TIMEOUT SPINLOCK_WAIT_FOREVER /* When passed for 'timeout_cycles', spin forever if necessary */
|
|
||||||
#define portMUX_TRY_LOCK SPINLOCK_NO_WAIT /* Try to acquire the spinlock a single time only */
|
|
||||||
|
|
||||||
// Keep this in sync with the portMUX_TYPE struct definition please.
|
|
||||||
#ifndef CONFIG_FREERTOS_PORTMUX_DEBUG
|
#ifndef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
#define portMUX_INITIALIZER_UNLOCKED { \
|
#define portMUX_INITIALIZER_UNLOCKED { \
|
||||||
.owner = portMUX_FREE_VAL, \
|
.owner = portMUX_FREE_VAL, \
|
||||||
@@ -187,15 +193,251 @@ typedef struct {
|
|||||||
.lastLockedFn = "(never locked)", \
|
.lastLockedFn = "(never locked)", \
|
||||||
.lastLockedLine = -1 \
|
.lastLockedLine = -1 \
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* CONFIG_FREERTOS_PORTMUX_DEBUG */
|
||||||
|
#define portMUX_FREE_VAL SPINLOCK_FREE /**< Spinlock is free. [refactor-todo] check if this is still required */
|
||||||
|
#define portMUX_NO_TIMEOUT SPINLOCK_WAIT_FOREVER /**< When passed for 'timeout_cycles', spin forever if necessary. [refactor-todo] check if this is still required */
|
||||||
|
#define portMUX_TRY_LOCK SPINLOCK_NO_WAIT /**< Try to acquire the spinlock a single time only. [refactor-todo] check if this is still required */
|
||||||
|
|
||||||
/* Scheduler utilities. */
|
/**
|
||||||
extern void vPortYield( void );
|
* @brief Initialize a spinlock
|
||||||
extern void vPortYieldFromISR( void );
|
*
|
||||||
|
* - Initializes a spinlock that is used by FreeRTOS SMP critical sections
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] We can make this inline or consider making it a macro
|
||||||
|
* @param[in] mux Spinlock
|
||||||
|
*/
|
||||||
|
void vPortCPUInitializeMutex(portMUX_TYPE *mux);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Acquire a spinlock
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] check if we still need this
|
||||||
|
* @note [refactor-todo] Check if this should be inlined
|
||||||
|
* @param[in] mux Spinlock
|
||||||
|
*/
|
||||||
|
void vPortCPUAcquireMutex(portMUX_TYPE *mux);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Acquire a spinlock but with a specified timeout
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] Check if we still need this
|
||||||
|
* @note [refactor-todo] Check if this should be inlined
|
||||||
|
* @note [refactor-todo] Check if this function should be renamed (due to bool return type)
|
||||||
|
* @param[in] mux Spinlock
|
||||||
|
* @param[in] timeout Timeout in number of CPU cycles
|
||||||
|
* @return true Spinlock acquired
|
||||||
|
* @return false Timed out
|
||||||
|
*/
|
||||||
|
bool vPortCPUAcquireMutexTimeout(portMUX_TYPE *mux, int timeout_cycles);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Release a spinlock
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] check if we still need this
|
||||||
|
* @note [refactor-todo] Check if this should be inlined
|
||||||
|
* @param[in] mux Spinlock
|
||||||
|
*/
|
||||||
|
void vPortCPUReleaseMutex(portMUX_TYPE *mux);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Wrapper for atomic compare-and-set instruction
|
||||||
|
*
|
||||||
|
* @note Isn't a real atomic CAS.
|
||||||
|
* @note [refactor-todo] check if we still need this
|
||||||
|
* @note [refactor-todo] Check if this function should be renamed (due to void return type)
|
||||||
|
*
|
||||||
|
* @param[inout] addr Pointer to target address
|
||||||
|
* @param[in] compare Compare value
|
||||||
|
* @param[inout] set Pointer to set value
|
||||||
|
*/
|
||||||
|
static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Wrapper for atomic compare-and-set instruction in external RAM
|
||||||
|
*
|
||||||
|
* @note Isn't a real atomic CAS.
|
||||||
|
* @note [refactor-todo] check if we still need this
|
||||||
|
* @note [refactor-todo] Check if this function should be renamed (due to void return type)
|
||||||
|
*
|
||||||
|
* @param[inout] addr Pointer to target address
|
||||||
|
* @param[in] compare Compare value
|
||||||
|
* @param[inout] set Pointer to set value
|
||||||
|
*/
|
||||||
|
static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set);
|
||||||
|
|
||||||
|
// ------------------ Critical Sections --------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enter a critical section
|
||||||
|
*
|
||||||
|
* - Simply disable interrupts
|
||||||
|
* - Can be nested
|
||||||
|
*/
|
||||||
|
void vPortEnterCritical(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Exit a critical section
|
||||||
|
*
|
||||||
|
* - Reenables interrupts
|
||||||
|
* - Can be nested
|
||||||
|
*/
|
||||||
|
void vPortExitCritical(void);
|
||||||
|
|
||||||
|
// ---------------------- Yielding -------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set interrupt mask and return current interrupt enable register
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] Check if this function should be renamed (due to int return type)
|
||||||
|
* @return int Current interrupt enable register before set
|
||||||
|
*/
|
||||||
|
int vPortSetInterruptMask(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clear current interrupt mask and set given mask
|
||||||
|
*
|
||||||
|
* @param mask Interrupt mask
|
||||||
|
*/
|
||||||
|
void vPortClearInterruptMask(int mask);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Perform a context switch from a task
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] The rest of ESP-IDF should call taskYield() instead
|
||||||
|
*/
|
||||||
|
void vPortYield(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Perform a context switch from an ISR
|
||||||
|
*/
|
||||||
|
void vPortYieldFromISR(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Yields the other core
|
||||||
|
*
|
||||||
|
* @note Added to be compatible with SMP API
|
||||||
|
* @note [refactor-todo] Put this into private macros as its only called from task.c and is not public API
|
||||||
|
* @param coreid ID of core to yield
|
||||||
|
*/
|
||||||
|
void vPortYieldOtherCore(BaseType_t coreid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the current core can yield
|
||||||
|
*
|
||||||
|
* - A core cannot yield if its in an ISR or in a critical section
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] See if this can be separated from port macro
|
||||||
|
* @note [refactor-todo] Check if this function should be renamed (due to bool return type)
|
||||||
|
* @return true Core can yield
|
||||||
|
* @return false Core cannot yield
|
||||||
|
*/
|
||||||
|
static inline bool IRAM_ATTR xPortCanYield(void);
|
||||||
|
|
||||||
|
// ------------------- Hook Functions ----------------------
|
||||||
|
|
||||||
|
extern void esp_vApplicationIdleHook(void);
|
||||||
|
extern void esp_vApplicationTickHook(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Hook function called on entry to tickless idle
|
||||||
|
*
|
||||||
|
* - Implemented in pm_impl.c
|
||||||
|
*
|
||||||
|
* @param xExpectedIdleTime Expected idle time
|
||||||
|
*/
|
||||||
|
void vApplicationSleep(TickType_t xExpectedIdleTime);
|
||||||
|
|
||||||
|
// ----------------------- System --------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the tick rate per second
|
||||||
|
*
|
||||||
|
* @note [refactor-todo] make this inline
|
||||||
|
* @note [refactor-todo] Check if this function should be renamed (due to uint return type)
|
||||||
|
* @return uint32_t Tick rate in Hz
|
||||||
|
*/
|
||||||
|
uint32_t xPortGetTickRateHz(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set a watchpoint to watch the last 32 bytes of the stack
|
||||||
|
*
|
||||||
|
* Callback to set a watchpoint on the end of the stack. Called every context switch to change the stack watchpoint
|
||||||
|
* around.
|
||||||
|
*
|
||||||
|
* @param pxStackStart Pointer to the start of the stack
|
||||||
|
*/
|
||||||
|
void vPortSetStackWatchpoint(void *pxStackStart);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the current core's ID
|
||||||
|
*
|
||||||
|
* @note Added to be compatible with SMP API
|
||||||
|
* @note [refactor-todo] IDF should call a FreeRTOS like macro instead of port function directly
|
||||||
|
* @return BaseType_t Core ID
|
||||||
|
*/
|
||||||
|
static inline BaseType_t IRAM_ATTR xPortGetCoreID(void)
|
||||||
|
{
|
||||||
|
return cpu_hal_get_core_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------- FreeRTOS Porting Interface ----------------------------------------------
|
||||||
|
* - Contains all the mappings of the macros required by FreeRTOS
|
||||||
|
* - Most come after forward declare as porting macros map to declared functions
|
||||||
|
* - Maps to forward declared functions
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
// ----------------------- Memory --------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Task memory allocation macros
|
||||||
|
*
|
||||||
|
* @note Because the ROM routines don't necessarily handle a stack in external RAM correctly, we force the stack
|
||||||
|
* memory to always be internal.
|
||||||
|
* @note [refactor-todo] Update portable.h to match v10.4.3 to use new malloc prototypes
|
||||||
|
*/
|
||||||
|
#define portTcbMemoryCaps (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)
|
||||||
|
#define portStackMemoryCaps (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)
|
||||||
|
#define pvPortMallocTcbMem(size) pvPortMalloc(size)
|
||||||
|
#define pvPortMallocStackMem(size) pvPortMalloc(size)
|
||||||
|
|
||||||
|
// --------------------- Interrupts ------------------------
|
||||||
|
|
||||||
|
#define portEXIT_CRITICAL_NESTED(state) do { portCLEAR_INTERRUPT_MASK_FROM_ISR(state);} while(0);
|
||||||
|
#define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK_FROM_ISR()
|
||||||
|
#define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK_FROM_ISR(1)
|
||||||
|
#define portSET_INTERRUPT_MASK_FROM_ISR() vPortSetInterruptMask()
|
||||||
|
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedStatusValue) vPortClearInterruptMask(uxSavedStatusValue)
|
||||||
|
|
||||||
|
// ------------------ Critical Sections --------------------
|
||||||
|
|
||||||
|
#define portENTER_CRITICAL(mux) {(void)mux; vPortEnterCritical();}
|
||||||
|
#define portEXIT_CRITICAL(mux) {(void)mux; vPortExitCritical();}
|
||||||
|
//In single-core RISC-V, we can use the same critical section API
|
||||||
|
#define portENTER_CRITICAL_ISR(mux) portENTER_CRITICAL(mux)
|
||||||
|
#define portEXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL(mux)
|
||||||
|
/* [refactor-todo] on RISC-V, both ISR and non-ISR cases result in the same call. We can redefine this macro */
|
||||||
|
#define portENTER_CRITICAL_SAFE(mux) ({ \
|
||||||
|
if (xPortInIsrContext()) { \
|
||||||
|
portENTER_CRITICAL_ISR(mux); \
|
||||||
|
} else { \
|
||||||
|
portENTER_CRITICAL(mux); \
|
||||||
|
} \
|
||||||
|
})
|
||||||
|
#define portEXIT_CRITICAL_SAFE(mux) ({ \
|
||||||
|
if (xPortInIsrContext()) { \
|
||||||
|
portEXIT_CRITICAL_ISR(mux); \
|
||||||
|
} else { \
|
||||||
|
portEXIT_CRITICAL(mux); \
|
||||||
|
} \
|
||||||
|
})
|
||||||
|
|
||||||
|
// ---------------------- Yielding -------------------------
|
||||||
|
|
||||||
#define portYIELD() vPortYield()
|
#define portYIELD() vPortYield()
|
||||||
#define portYIELD_FROM_ISR() vPortYieldFromISR()
|
#define portYIELD_FROM_ISR() vPortYieldFromISR()
|
||||||
|
#define portEND_SWITCHING_ISR(xSwitchRequired) if(xSwitchRequired) vPortYield()
|
||||||
/* Yielding within an API call (when interrupts are off), means the yield should be delayed
|
/* Yielding within an API call (when interrupts are off), means the yield should be delayed
|
||||||
until interrupts are re-enabled.
|
until interrupts are re-enabled.
|
||||||
To do this, we use the "cross-core" interrupt as a trigger to yield on this core when interrupts are re-enabled.This
|
To do this, we use the "cross-core" interrupt as a trigger to yield on this core when interrupts are re-enabled.This
|
||||||
@@ -203,112 +445,104 @@ extern void vPortYieldFromISR( void );
|
|||||||
happening on the same CPU.
|
happening on the same CPU.
|
||||||
*/
|
*/
|
||||||
#define portYIELD_WITHIN_API() portYIELD()
|
#define portYIELD_WITHIN_API() portYIELD()
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Critical section management. */
|
// ------------------- Hook Functions ----------------------
|
||||||
extern int vPortSetInterruptMask(void);
|
|
||||||
extern void vPortClearInterruptMask( int );
|
|
||||||
|
|
||||||
void vPortCPUInitializeMutex(portMUX_TYPE *mux);
|
|
||||||
void vPortCPUAcquireMutex(portMUX_TYPE *mux);
|
|
||||||
bool vPortCPUAcquireMutexTimeout(portMUX_TYPE *mux, int timeout_cycles);
|
|
||||||
void vPortCPUReleaseMutex(portMUX_TYPE *mux);
|
|
||||||
|
|
||||||
extern void vPortEnterCritical( void );
|
|
||||||
extern void vPortExitCritical( void );
|
|
||||||
|
|
||||||
#define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK_FROM_ISR()
|
|
||||||
#define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK_FROM_ISR(1)
|
|
||||||
|
|
||||||
#define portENTER_CRITICAL(mux) {(void)mux; vPortEnterCritical();}
|
|
||||||
#define portEXIT_CRITICAL(mux) {(void)mux; vPortExitCritical();}
|
|
||||||
|
|
||||||
#define portENTER_CRITICAL_ISR(mux) portENTER_CRITICAL(mux)
|
|
||||||
#define portEXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL(mux)
|
|
||||||
|
|
||||||
#define portENTER_CRITICAL_SAFE(mux) do { \
|
|
||||||
if (xPortInIsrContext()) { \
|
|
||||||
portENTER_CRITICAL_ISR(mux); \
|
|
||||||
} else { \
|
|
||||||
portENTER_CRITICAL(mux); \
|
|
||||||
} \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
#define portEXIT_CRITICAL_SAFE(mux) do { \
|
|
||||||
if (xPortInIsrContext()) { \
|
|
||||||
portEXIT_CRITICAL_ISR(mux); \
|
|
||||||
} else { \
|
|
||||||
portEXIT_CRITICAL(mux); \
|
|
||||||
} \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
/*------------------------------------------------------------*/
|
|
||||||
#define portSET_INTERRUPT_MASK_FROM_ISR() vPortSetInterruptMask()
|
|
||||||
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) vPortClearInterruptMask( uxSavedStatusValue )
|
|
||||||
#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) vPortYield()
|
|
||||||
|
|
||||||
// Cleaner solution allows nested interrupts disabling and restoring via local registers or stack.
|
|
||||||
// They can be called from interrupts too.
|
|
||||||
static inline unsigned portENTER_CRITICAL_NESTED(void) {
|
|
||||||
unsigned state = portSET_INTERRUPT_MASK_FROM_ISR();
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define portEXIT_CRITICAL_NESTED(state) do { portCLEAR_INTERRUPT_MASK_FROM_ISR( state );} while(0);
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
//Because the ROM routines don't necessarily handle a stack in external RAM correctly, we force
|
|
||||||
//the stack memory to always be internal.
|
|
||||||
#define portTcbMemoryCaps (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)
|
|
||||||
#define portStackMemoryCaps (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)
|
|
||||||
|
|
||||||
#define pvPortMallocTcbMem(size) pvPortMalloc(size)
|
|
||||||
#define pvPortMallocStackMem(size) pvPortMalloc(size)
|
|
||||||
|
|
||||||
/* Fine resolution time */
|
|
||||||
#define portGET_RUN_TIME_COUNTER_VALUE() 0
|
|
||||||
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
|
|
||||||
|
|
||||||
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
|
|
||||||
/* Coarse resolution time (us) */
|
|
||||||
#define portALT_GET_RUN_TIME_COUNTER_VALUE(x) do {x = (uint32_t)esp_timer_get_time();} while(0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern void esp_vApplicationIdleHook( void );
|
|
||||||
extern void esp_vApplicationTickHook( void );
|
|
||||||
|
|
||||||
#ifndef CONFIG_FREERTOS_LEGACY_HOOKS
|
#ifndef CONFIG_FREERTOS_LEGACY_HOOKS
|
||||||
#define vApplicationIdleHook esp_vApplicationIdleHook
|
#define vApplicationIdleHook esp_vApplicationIdleHook
|
||||||
#define vApplicationTickHook esp_vApplicationTickHook
|
#define vApplicationTickHook esp_vApplicationTickHook
|
||||||
#endif /* !CONFIG_FREERTOS_LEGACY_HOOKS */
|
#endif /* !CONFIG_FREERTOS_LEGACY_HOOKS */
|
||||||
|
#define portSUPPRESS_TICKS_AND_SLEEP(idleTime) vApplicationSleep(idleTime)
|
||||||
|
|
||||||
/* Task function macros as described on the FreeRTOS.org WEB site. */
|
// ------------------- Run Time Stats ----------------------
|
||||||
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
|
|
||||||
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
|
|
||||||
|
|
||||||
void vApplicationSleep( TickType_t xExpectedIdleTime );
|
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
|
||||||
#define portSUPPRESS_TICKS_AND_SLEEP( idleTime ) vApplicationSleep( idleTime )
|
#define portGET_RUN_TIME_COUNTER_VALUE() 0
|
||||||
|
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
|
||||||
#define portNOP() __asm volatile ( " nop " )
|
/* Coarse resolution time (us) */
|
||||||
|
#define portALT_GET_RUN_TIME_COUNTER_VALUE(x) do {x = (uint32_t)esp_timer_get_time();} while(0)
|
||||||
#define portVALID_TCB_MEM(ptr) esp_ptr_byte_accessible(ptr)
|
|
||||||
#define portVALID_STACK_MEM(ptr) esp_ptr_byte_accessible(ptr)
|
|
||||||
|
|
||||||
/* Get tick rate per second */
|
|
||||||
uint32_t xPortGetTickRateHz(void);
|
|
||||||
|
|
||||||
// configASSERT_2 if requested
|
|
||||||
#if configASSERT_2
|
|
||||||
#include <stdio.h>
|
|
||||||
void exit(int);
|
|
||||||
#define configASSERT( x ) if (!(x)) { porttracePrint(-1); printf("\nAssertion failed in %s:%d\n", __FILE__, __LINE__); exit(-1); }
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif //__ASSEMBLER__
|
|
||||||
|
/* --------------------------------------------- Inline Implementations ------------------------------------------------
|
||||||
|
* - Implementation of inline functions of the forward declares
|
||||||
|
* - Should come after forward declare and FreeRTOS Porting interface, as implementation may use both.
|
||||||
|
* - For implementation of non-inlined functions, see port.c, port_common.c, or other assembly files
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
// --------------------- Interrupts ------------------------
|
||||||
|
|
||||||
|
static inline unsigned portENTER_CRITICAL_NESTED(void)
|
||||||
|
{
|
||||||
|
unsigned state = portSET_INTERRUPT_MASK_FROM_ISR();
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------- Spinlocks ------------------------
|
||||||
|
|
||||||
|
static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set)
|
||||||
|
{
|
||||||
|
compare_and_set_native(addr, compare, set);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set)
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_SPIRAM)
|
||||||
|
compare_and_set_extram(addr, compare, set);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------- Yielding -------------------------
|
||||||
|
|
||||||
|
static inline bool IRAM_ATTR xPortCanYield(void)
|
||||||
|
{
|
||||||
|
uint32_t threshold = REG_READ(INTERRUPT_CORE0_CPU_INT_THRESH_REG);
|
||||||
|
/* when enter critical code, FreeRTOS will mask threshold to RVHAL_EXCM_LEVEL
|
||||||
|
* and exit critical code, will recover threshold value (1). so threshold <= 1
|
||||||
|
* means not in critical code
|
||||||
|
*/
|
||||||
|
return (threshold <= 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------ Misc ---------------------------------------------------------
|
||||||
|
* - Miscellaneous porting macros
|
||||||
|
* - These are not port of the FreeRTOS porting interface, but are used by other FreeRTOS dependent components
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
// -------------------- Heap Related -----------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if a given piece of memory can be used to store a task's TCB
|
||||||
|
*
|
||||||
|
* - Defined in port_common.c
|
||||||
|
*
|
||||||
|
* @param ptr Pointer to memory
|
||||||
|
* @return true Memory can be used to store a TCB
|
||||||
|
* @return false Otherwise
|
||||||
|
*/
|
||||||
|
bool xPortCheckValidTCBMem(const void *ptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if a given piece of memory can be used to store a task's stack
|
||||||
|
*
|
||||||
|
* - Defined in port_common.c
|
||||||
|
*
|
||||||
|
* @param ptr Pointer to memory
|
||||||
|
* @return true Memory can be used to store a task stack
|
||||||
|
* @return false Otherwise
|
||||||
|
*/
|
||||||
|
bool xPortcheckValidStackMem(const void *ptr);
|
||||||
|
|
||||||
|
#define portVALID_TCB_MEM(ptr) xPortCheckValidTCBMem(ptr)
|
||||||
|
#define portVALID_STACK_MEM(ptr) xPortcheckValidStackMem(ptr)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif //__ASSEMBLER__
|
||||||
|
|
||||||
#endif /* PORTMACRO_H */
|
#endif /* PORTMACRO_H */
|
||||||
|
@@ -74,31 +74,35 @@
|
|||||||
* Implementation of functions defined in portable.h for the RISC-V port.
|
* Implementation of functions defined in portable.h for the RISC-V port.
|
||||||
*----------------------------------------------------------------------*/
|
*----------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "FreeRTOS.h"
|
|
||||||
#include "task.h"
|
|
||||||
#include "portmacro.h"
|
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
#include <string.h>
|
||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
#include "soc/periph_defs.h"
|
#include "soc/periph_defs.h"
|
||||||
#include "soc/system_reg.h"
|
#include "soc/system_reg.h"
|
||||||
#include "hal/systimer_hal.h"
|
#include "hal/systimer_hal.h"
|
||||||
#include "hal/systimer_ll.h"
|
#include "hal/systimer_ll.h"
|
||||||
|
|
||||||
#include "riscv/rvruntime-frames.h"
|
#include "riscv/rvruntime-frames.h"
|
||||||
#include "riscv/riscv_interrupts.h"
|
#include "riscv/riscv_interrupts.h"
|
||||||
#include "riscv/interrupt.h"
|
#include "riscv/interrupt.h"
|
||||||
|
#include "esp_private/crosscore_int.h"
|
||||||
#include "port_systick.h"
|
#include "esp_private/pm_trace.h"
|
||||||
|
#include "esp_attr.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
#include "esp_intr_alloc.h"
|
#include "esp_intr_alloc.h"
|
||||||
#include "esp_private/crosscore_int.h"
|
|
||||||
#include "esp_attr.h"
|
|
||||||
#include "esp_debug_helpers.h"
|
#include "esp_debug_helpers.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_private/pm_trace.h"
|
#include "FreeRTOS.h" /* This pulls in portmacro.h */
|
||||||
|
#include "task.h"
|
||||||
|
#include "portmacro.h"
|
||||||
|
#include "port_systick.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------------------------------- Variables ------------------------------------------------------
|
||||||
|
*
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
static const char *TAG = "cpu_start"; // [refactor-todo]: might be appropriate to change in the future, but
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A variable is used to keep track of the critical section nesting.
|
* @brief A variable is used to keep track of the critical section nesting.
|
||||||
@@ -114,33 +118,43 @@ BaseType_t xPortSwitchFlag = 0;
|
|||||||
__attribute__((aligned(16))) static StackType_t xIsrStack[configISR_STACK_SIZE];
|
__attribute__((aligned(16))) static StackType_t xIsrStack[configISR_STACK_SIZE];
|
||||||
StackType_t *xIsrStackTop = &xIsrStack[0] + (configISR_STACK_SIZE & (~((portPOINTER_SIZE_TYPE)portBYTE_ALIGNMENT_MASK)));
|
StackType_t *xIsrStackTop = &xIsrStack[0] + (configISR_STACK_SIZE & (~((portPOINTER_SIZE_TYPE)portBYTE_ALIGNMENT_MASK)));
|
||||||
|
|
||||||
static const char *TAG = "cpu_start"; // [refactor-todo]: might be appropriate to change in the future, but
|
|
||||||
|
|
||||||
static void prvTaskExitError(void);
|
|
||||||
|
/* ------------------------------------------------ FreeRTOS Portable --------------------------------------------------
|
||||||
|
* - Provides implementation for functions required by FreeRTOS
|
||||||
|
* - Declared in portable.h
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
// ----------------- Scheduler Start/End -------------------
|
||||||
|
|
||||||
extern void esprv_intc_int_set_threshold(int); // FIXME, this function is in ROM only
|
extern void esprv_intc_int_set_threshold(int); // FIXME, this function is in ROM only
|
||||||
|
BaseType_t xPortStartScheduler(void)
|
||||||
void vPortEnterCritical(void)
|
|
||||||
{
|
{
|
||||||
BaseType_t state = portENTER_CRITICAL_NESTED();
|
uxInterruptNesting = 0;
|
||||||
uxCriticalNesting++;
|
uxCriticalNesting = 0;
|
||||||
|
uxSchedulerRunning = 0;
|
||||||
|
|
||||||
if (uxCriticalNesting == 1) {
|
/* Setup the hardware to generate the tick. */
|
||||||
uxSavedInterruptState = state;
|
vPortSetupTimer();
|
||||||
}
|
|
||||||
|
esprv_intc_int_set_threshold(1); /* set global INTC masking level */
|
||||||
|
riscv_global_interrupts_enable();
|
||||||
|
|
||||||
|
vPortYield();
|
||||||
|
|
||||||
|
/*Should not get here*/
|
||||||
|
return pdFALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vPortExitCritical(void)
|
void vPortEndScheduler(void)
|
||||||
{
|
{
|
||||||
if (uxCriticalNesting > 0) {
|
/* very unlikely this function will be called, so just trap here */
|
||||||
uxCriticalNesting--;
|
abort();
|
||||||
if (uxCriticalNesting == 0) {
|
|
||||||
portEXIT_CRITICAL_NESTED(uxSavedInterruptState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void prvTaskExitError(void)
|
// ------------------------ Stack --------------------------
|
||||||
|
|
||||||
|
static void prvTaskExitError(void)
|
||||||
{
|
{
|
||||||
/* A function that implements a task must not exit or attempt to return to
|
/* A function that implements a task must not exit or attempt to return to
|
||||||
its caller as there is nothing to return to. If a task wants to exit it
|
its caller as there is nothing to return to. If a task wants to exit it
|
||||||
@@ -153,57 +167,11 @@ void prvTaskExitError(void)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear current interrupt mask and set given mask */
|
|
||||||
void vPortClearInterruptMask(int mask)
|
|
||||||
{
|
|
||||||
REG_WRITE(INTERRUPT_CORE0_CPU_INT_THRESH_REG, mask);
|
|
||||||
/**
|
|
||||||
* The delay between the moment we unmask the interrupt threshold register
|
|
||||||
* and the moment the potential requested interrupt is triggered is not
|
|
||||||
* null: up to three machine cycles/instructions can be executed.
|
|
||||||
*
|
|
||||||
* When compilation size optimization is enabled, this function and its
|
|
||||||
* callers returning void will have NO epilogue, thus the instruction
|
|
||||||
* following these calls will be executed.
|
|
||||||
*
|
|
||||||
* If the requested interrupt is a context switch to a higher priority
|
|
||||||
* task then the one currently running, we MUST NOT execute any instruction
|
|
||||||
* before the interrupt effectively happens.
|
|
||||||
* In order to prevent this, force this routine to have a 3-instruction
|
|
||||||
* delay before exiting.
|
|
||||||
*/
|
|
||||||
asm volatile ( "nop" );
|
|
||||||
asm volatile ( "nop" );
|
|
||||||
asm volatile ( "nop" );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set interrupt mask and return current interrupt enable register */
|
|
||||||
int vPortSetInterruptMask(void)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
unsigned old_mstatus = RV_CLEAR_CSR(mstatus, MSTATUS_MIE);
|
|
||||||
ret = REG_READ(INTERRUPT_CORE0_CPU_INT_THRESH_REG);
|
|
||||||
REG_WRITE(INTERRUPT_CORE0_CPU_INT_THRESH_REG, RVHAL_EXCM_LEVEL);
|
|
||||||
RV_SET_CSR(mstatus, old_mstatus & MSTATUS_MIE);
|
|
||||||
/**
|
|
||||||
* In theory, this function should not return immediately as there is a
|
|
||||||
* delay between the moment we mask the interrupt threshold register and
|
|
||||||
* the moment a potential lower-priority interrupt is triggered (as said
|
|
||||||
* above), it should have a delay of 2 machine cycles/instructions.
|
|
||||||
*
|
|
||||||
* However, in practice, this function has an epilogue of one instruction,
|
|
||||||
* thus the instruction masking the interrupt threshold register is
|
|
||||||
* followed by two instructions: `ret` and `csrrs` (RV_SET_CSR).
|
|
||||||
* That's why we don't need any additional nop instructions here.
|
|
||||||
*/
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters)
|
StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters)
|
||||||
{
|
{
|
||||||
extern uint32_t __global_pointer$;
|
extern uint32_t __global_pointer$;
|
||||||
uint8_t* task_thread_local_start;
|
uint8_t *task_thread_local_start;
|
||||||
uint8_t* threadptr;
|
uint8_t *threadptr;
|
||||||
extern char _thread_local_start, _thread_local_end, _flash_rodata_start;
|
extern char _thread_local_start, _thread_local_end, _flash_rodata_start;
|
||||||
|
|
||||||
/* Byte pointer, so that subsequent calculations don't depend on sizeof(StackType_t). */
|
/* Byte pointer, so that subsequent calculations don't depend on sizeof(StackType_t). */
|
||||||
@@ -271,78 +239,13 @@ StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxC
|
|||||||
return (StackType_t *)frame;
|
return (StackType_t *)frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseType_t xPortStartScheduler(void)
|
|
||||||
{
|
|
||||||
uxInterruptNesting = 0;
|
|
||||||
uxCriticalNesting = 0;
|
|
||||||
uxSchedulerRunning = 0;
|
|
||||||
|
|
||||||
/* Setup the hardware to generate the tick. */
|
|
||||||
vPortSetupTimer();
|
|
||||||
|
|
||||||
esprv_intc_int_set_threshold(1); /* set global INTC masking level */
|
/* ---------------------------------------------- Port Implementations -------------------------------------------------
|
||||||
riscv_global_interrupts_enable();
|
*
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
vPortYield();
|
// --------------------- Interrupts ------------------------
|
||||||
|
|
||||||
/*Should not get here*/
|
|
||||||
return pdFALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void vPortEndScheduler(void)
|
|
||||||
{
|
|
||||||
/* very unlikely this function will be called, so just trap here */
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
void vPortYieldOtherCore(BaseType_t coreid)
|
|
||||||
{
|
|
||||||
esp_crosscore_int_send_yield(coreid);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vPortYieldFromISR( void )
|
|
||||||
{
|
|
||||||
traceISR_EXIT_TO_SCHEDULER();
|
|
||||||
uxSchedulerRunning = 1;
|
|
||||||
xPortSwitchFlag = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void vPortYield(void)
|
|
||||||
{
|
|
||||||
if (uxInterruptNesting) {
|
|
||||||
vPortYieldFromISR();
|
|
||||||
} else {
|
|
||||||
|
|
||||||
esp_crosscore_int_send_yield(0);
|
|
||||||
/* There are 3-4 instructions of latency between triggering the software
|
|
||||||
interrupt and the CPU interrupt happening. Make sure it happened before
|
|
||||||
we return, otherwise vTaskDelay() may return and execute 1-2
|
|
||||||
instructions before the delay actually happens.
|
|
||||||
|
|
||||||
(We could use the WFI instruction here, but there is a chance that
|
|
||||||
the interrupt will happen while evaluating the other two conditions
|
|
||||||
for an instant yield, and if that happens then the WFI would be
|
|
||||||
waiting for the next interrupt to occur...)
|
|
||||||
*/
|
|
||||||
while (uxSchedulerRunning && uxCriticalNesting == 0 && REG_READ(SYSTEM_CPU_INTR_FROM_CPU_0_REG) != 0) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#define STACK_WATCH_AREA_SIZE 32
|
|
||||||
#define STACK_WATCH_POINT_NUMBER (SOC_CPU_WATCHPOINTS_NUM - 1)
|
|
||||||
|
|
||||||
void vPortSetStackWatchpoint(void *pxStackStart)
|
|
||||||
{
|
|
||||||
uint32_t addr = (uint32_t)pxStackStart;
|
|
||||||
addr = (addr + (STACK_WATCH_AREA_SIZE - 1)) & (~(STACK_WATCH_AREA_SIZE - 1));
|
|
||||||
esp_cpu_set_watchpoint(STACK_WATCH_POINT_NUMBER, (char *)addr, STACK_WATCH_AREA_SIZE, ESP_WATCHPOINT_STORE);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t xPortGetTickRateHz(void)
|
|
||||||
{
|
|
||||||
return (uint32_t)configTICK_RATE_HZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseType_t xPortInIsrContext(void)
|
BaseType_t xPortInIsrContext(void)
|
||||||
{
|
{
|
||||||
@@ -355,6 +258,7 @@ BaseType_t IRAM_ATTR xPortInterruptedFromISRContext(void)
|
|||||||
return uxInterruptNesting;
|
return uxInterruptNesting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------- Spinlocks ------------------------
|
||||||
|
|
||||||
void vPortCPUInitializeMutex(portMUX_TYPE *mux)
|
void vPortCPUInitializeMutex(portMUX_TYPE *mux)
|
||||||
{
|
{
|
||||||
@@ -378,6 +282,109 @@ void vPortCPUReleaseMutex(portMUX_TYPE *mux)
|
|||||||
(void)mux; //TODO: IDF-2393
|
(void)mux; //TODO: IDF-2393
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------ Critical Sections --------------------
|
||||||
|
|
||||||
|
void vPortEnterCritical(void)
|
||||||
|
{
|
||||||
|
BaseType_t state = portENTER_CRITICAL_NESTED();
|
||||||
|
uxCriticalNesting++;
|
||||||
|
|
||||||
|
if (uxCriticalNesting == 1) {
|
||||||
|
uxSavedInterruptState = state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void vPortExitCritical(void)
|
||||||
|
{
|
||||||
|
if (uxCriticalNesting > 0) {
|
||||||
|
uxCriticalNesting--;
|
||||||
|
if (uxCriticalNesting == 0) {
|
||||||
|
portEXIT_CRITICAL_NESTED(uxSavedInterruptState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------- Yielding -------------------------
|
||||||
|
|
||||||
|
int vPortSetInterruptMask(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
unsigned old_mstatus = RV_CLEAR_CSR(mstatus, MSTATUS_MIE);
|
||||||
|
ret = REG_READ(INTERRUPT_CORE0_CPU_INT_THRESH_REG);
|
||||||
|
REG_WRITE(INTERRUPT_CORE0_CPU_INT_THRESH_REG, RVHAL_EXCM_LEVEL);
|
||||||
|
RV_SET_CSR(mstatus, old_mstatus & MSTATUS_MIE);
|
||||||
|
/**
|
||||||
|
* In theory, this function should not return immediately as there is a
|
||||||
|
* delay between the moment we mask the interrupt threshold register and
|
||||||
|
* the moment a potential lower-priority interrupt is triggered (as said
|
||||||
|
* above), it should have a delay of 2 machine cycles/instructions.
|
||||||
|
*
|
||||||
|
* However, in practice, this function has an epilogue of one instruction,
|
||||||
|
* thus the instruction masking the interrupt threshold register is
|
||||||
|
* followed by two instructions: `ret` and `csrrs` (RV_SET_CSR).
|
||||||
|
* That's why we don't need any additional nop instructions here.
|
||||||
|
*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vPortClearInterruptMask(int mask)
|
||||||
|
{
|
||||||
|
REG_WRITE(INTERRUPT_CORE0_CPU_INT_THRESH_REG, mask);
|
||||||
|
/**
|
||||||
|
* The delay between the moment we unmask the interrupt threshold register
|
||||||
|
* and the moment the potential requested interrupt is triggered is not
|
||||||
|
* null: up to three machine cycles/instructions can be executed.
|
||||||
|
*
|
||||||
|
* When compilation size optimization is enabled, this function and its
|
||||||
|
* callers returning void will have NO epilogue, thus the instruction
|
||||||
|
* following these calls will be executed.
|
||||||
|
*
|
||||||
|
* If the requested interrupt is a context switch to a higher priority
|
||||||
|
* task then the one currently running, we MUST NOT execute any instruction
|
||||||
|
* before the interrupt effectively happens.
|
||||||
|
* In order to prevent this, force this routine to have a 3-instruction
|
||||||
|
* delay before exiting.
|
||||||
|
*/
|
||||||
|
asm volatile ( "nop" );
|
||||||
|
asm volatile ( "nop" );
|
||||||
|
asm volatile ( "nop" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void vPortYield(void)
|
||||||
|
{
|
||||||
|
if (uxInterruptNesting) {
|
||||||
|
vPortYieldFromISR();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
esp_crosscore_int_send_yield(0);
|
||||||
|
/* There are 3-4 instructions of latency between triggering the software
|
||||||
|
interrupt and the CPU interrupt happening. Make sure it happened before
|
||||||
|
we return, otherwise vTaskDelay() may return and execute 1-2
|
||||||
|
instructions before the delay actually happens.
|
||||||
|
|
||||||
|
(We could use the WFI instruction here, but there is a chance that
|
||||||
|
the interrupt will happen while evaluating the other two conditions
|
||||||
|
for an instant yield, and if that happens then the WFI would be
|
||||||
|
waiting for the next interrupt to occur...)
|
||||||
|
*/
|
||||||
|
while (uxSchedulerRunning && uxCriticalNesting == 0 && REG_READ(SYSTEM_CPU_INTR_FROM_CPU_0_REG) != 0) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void vPortYieldFromISR( void )
|
||||||
|
{
|
||||||
|
traceISR_EXIT_TO_SCHEDULER();
|
||||||
|
uxSchedulerRunning = 1;
|
||||||
|
xPortSwitchFlag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vPortYieldOtherCore(BaseType_t coreid)
|
||||||
|
{
|
||||||
|
esp_crosscore_int_send_yield(coreid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------- Hook Functions ----------------------
|
||||||
|
|
||||||
void __attribute__((weak)) vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
|
void __attribute__((weak)) vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
|
||||||
{
|
{
|
||||||
#define ERR_STR1 "***ERROR*** A stack overflow in task "
|
#define ERR_STR1 "***ERROR*** A stack overflow in task "
|
||||||
@@ -393,6 +400,32 @@ void __attribute__((weak)) vApplicationStackOverflowHook(TaskHandle_t xTask, cha
|
|||||||
esp_system_abort(buf);
|
esp_system_abort(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------- System --------------------------
|
||||||
|
|
||||||
|
uint32_t xPortGetTickRateHz(void)
|
||||||
|
{
|
||||||
|
return (uint32_t)configTICK_RATE_HZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define STACK_WATCH_AREA_SIZE 32
|
||||||
|
#define STACK_WATCH_POINT_NUMBER (SOC_CPU_WATCHPOINTS_NUM - 1)
|
||||||
|
|
||||||
|
void vPortSetStackWatchpoint(void *pxStackStart)
|
||||||
|
{
|
||||||
|
uint32_t addr = (uint32_t)pxStackStart;
|
||||||
|
addr = (addr + (STACK_WATCH_AREA_SIZE - 1)) & (~(STACK_WATCH_AREA_SIZE - 1));
|
||||||
|
esp_cpu_set_watchpoint(STACK_WATCH_POINT_NUMBER, (char *)addr, STACK_WATCH_AREA_SIZE, ESP_WATCHPOINT_STORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------------------------- Misc Implementations -------------------------------------------------
|
||||||
|
*
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
// --------------------- App Start-up ----------------------
|
||||||
|
|
||||||
|
/* [refactor-todo]: See if we can include this through a header */
|
||||||
extern void esp_startup_start_app_common(void);
|
extern void esp_startup_start_app_common(void);
|
||||||
|
|
||||||
void esp_startup_start_app(void)
|
void esp_startup_start_app(void)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
|
|
||||||
All rights reserved
|
|
||||||
|
|
||||||
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
|
||||||
|
|
||||||
***************************************************************************
|
|
||||||
* *
|
|
||||||
* FreeRTOS provides completely free yet professionally developed, *
|
|
||||||
* robust, strictly quality controlled, supported, and cross *
|
|
||||||
* platform software that has become a de facto standard. *
|
|
||||||
* *
|
|
||||||
* Help yourself get started quickly and support the FreeRTOS *
|
|
||||||
* project by purchasing a FreeRTOS tutorial book, reference *
|
|
||||||
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
|
||||||
* *
|
|
||||||
* Thank you! *
|
|
||||||
* *
|
|
||||||
***************************************************************************
|
|
||||||
|
|
||||||
This file is part of the FreeRTOS distribution.
|
|
||||||
|
|
||||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
|
||||||
the terms of the GNU General Public License (version 2) as published by the
|
|
||||||
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
|
||||||
|
|
||||||
>>! NOTE: The modification to the GPL is included to allow you to !<<
|
|
||||||
>>! distribute a combined work that includes FreeRTOS without being !<<
|
|
||||||
>>! obliged to provide the source code for proprietary components !<<
|
|
||||||
>>! outside of the FreeRTOS kernel. !<<
|
|
||||||
|
|
||||||
FreeRTOS 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. Full license text is available from the following
|
|
||||||
link: http://www.freertos.org/a00114.html
|
|
||||||
|
|
||||||
1 tab == 4 spaces!
|
|
||||||
|
|
||||||
***************************************************************************
|
|
||||||
* *
|
|
||||||
* Having a problem? Start by reading the FAQ "My application does *
|
|
||||||
* not run, what could be wrong?" *
|
|
||||||
* *
|
|
||||||
* http://www.FreeRTOS.org/FAQHelp.html *
|
|
||||||
* *
|
|
||||||
***************************************************************************
|
|
||||||
|
|
||||||
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
|
||||||
license and Real Time Engineers Ltd. contact details.
|
|
||||||
|
|
||||||
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
|
||||||
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
|
||||||
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
|
||||||
|
|
||||||
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
|
||||||
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
|
||||||
licenses offer ticketed support, indemnification and middleware.
|
|
||||||
|
|
||||||
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
|
||||||
engineered and independently SIL3 certified version for use in safety and
|
|
||||||
mission critical applications that require provable dependability.
|
|
||||||
|
|
||||||
1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* This header holds the macros for porting which should only be used inside FreeRTOS */
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "soc/soc_memory_layout.h"
|
|
||||||
|
|
||||||
//xTaskCreateStatic uses these functions to check incoming memory.
|
|
||||||
#define portVALID_TCB_MEM(ptr) (esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr))
|
|
||||||
#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
|
|
||||||
#define portVALID_STACK_MEM(ptr) esp_ptr_byte_accessible(ptr)
|
|
||||||
#else
|
|
||||||
#define portVALID_STACK_MEM(ptr) (esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr))
|
|
||||||
#endif
|
|
@@ -1,153 +1,124 @@
|
|||||||
/*
|
/*
|
||||||
FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
|
* FreeRTOS Kernel V10.4.3
|
||||||
All rights reserved
|
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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. If you wish to use our Amazon
|
||||||
|
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
|
||||||
|
*
|
||||||
|
* 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://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
|
* 1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
/*
|
||||||
|
* Copyright (c) 2015-2019 Cadence Design Systems, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
This file is part of the FreeRTOS distribution.
|
#include "sdkconfig.h"
|
||||||
|
#include <stdint.h>
|
||||||
FreeRTOS is free software; you can redistribute it and/or modify it under
|
|
||||||
the terms of the GNU General Public License (version 2) as published by the
|
|
||||||
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
|
||||||
|
|
||||||
***************************************************************************
|
|
||||||
>>! NOTE: The modification to the GPL is included to allow you to !<<
|
|
||||||
>>! distribute a combined work that includes FreeRTOS without being !<<
|
|
||||||
>>! obliged to provide the source code for proprietary components !<<
|
|
||||||
>>! outside of the FreeRTOS kernel. !<<
|
|
||||||
***************************************************************************
|
|
||||||
|
|
||||||
FreeRTOS 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. Full license text is available on the following
|
|
||||||
link: http://www.freertos.org/a00114.html
|
|
||||||
|
|
||||||
***************************************************************************
|
|
||||||
* *
|
|
||||||
* FreeRTOS provides completely free yet professionally developed, *
|
|
||||||
* robust, strictly quality controlled, supported, and cross *
|
|
||||||
* platform software that is more than just the market leader, it *
|
|
||||||
* is the industry's de facto standard. *
|
|
||||||
* *
|
|
||||||
* Help yourself get started quickly while simultaneously helping *
|
|
||||||
* to support the FreeRTOS project by purchasing a FreeRTOS *
|
|
||||||
* tutorial book, reference manual, or both: *
|
|
||||||
* http://www.FreeRTOS.org/Documentation *
|
|
||||||
* *
|
|
||||||
***************************************************************************
|
|
||||||
|
|
||||||
http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
|
|
||||||
the FAQ page "My application does not run, what could be wrong?". Have you
|
|
||||||
defined configASSERT()?
|
|
||||||
|
|
||||||
http://www.FreeRTOS.org/support - In return for receiving this top quality
|
|
||||||
embedded software for free we request you assist our global community by
|
|
||||||
participating in the support forum.
|
|
||||||
|
|
||||||
http://www.FreeRTOS.org/training - Investing in training allows your team to
|
|
||||||
be as productive as possible as early as possible. Now you can receive
|
|
||||||
FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
|
|
||||||
Ltd, and the world's leading authority on the world's leading RTOS.
|
|
||||||
|
|
||||||
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
|
||||||
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
|
||||||
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
|
||||||
|
|
||||||
http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
|
|
||||||
Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
|
|
||||||
|
|
||||||
http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
|
|
||||||
Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
|
|
||||||
licenses offer ticketed support, indemnification and commercial middleware.
|
|
||||||
|
|
||||||
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
|
||||||
engineered and independently SIL3 certified version for use in safety and
|
|
||||||
mission critical applications that require provable dependability.
|
|
||||||
|
|
||||||
1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
// Copyright (c) 2003-2015 Cadence Design Systems, Inc.
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <xtensa/config/core.h>
|
#include <xtensa/config/core.h>
|
||||||
|
#include <xtensa/xtensa_context.h>
|
||||||
#include "xtensa_rtos.h"
|
|
||||||
|
|
||||||
#include "soc/cpu.h"
|
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
|
||||||
#include "task.h"
|
|
||||||
|
|
||||||
#include "esp_debug_helpers.h"
|
|
||||||
#include "esp_heap_caps.h"
|
|
||||||
#include "esp_heap_caps_init.h"
|
|
||||||
#include "esp_private/crosscore_int.h"
|
|
||||||
|
|
||||||
#include "esp_intr_alloc.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "sdkconfig.h"
|
|
||||||
|
|
||||||
#include "esp_task_wdt.h"
|
|
||||||
#include "esp_task.h"
|
|
||||||
|
|
||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
#include "soc/efuse_reg.h"
|
#include "esp_private/crosscore_int.h"
|
||||||
#include "soc/dport_access.h"
|
#include "esp_system.h"
|
||||||
#include "soc/dport_reg.h"
|
#include "esp_log.h"
|
||||||
#include "esp_int_wdt.h"
|
#include "esp_int_wdt.h"
|
||||||
|
#include "esp_app_trace.h" /* Required for esp_apptrace_init. [refactor-todo] */
|
||||||
|
#include "FreeRTOS.h" /* This pulls in portmacro.h */
|
||||||
#include "sdkconfig.h"
|
#include "task.h" /* Required for TaskHandle_t, tskNO_AFFINITY, and vTaskStartScheduler */
|
||||||
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32
|
|
||||||
#include "esp32/spiram.h"
|
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
|
||||||
#include "esp32s2/spiram.h"
|
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
|
||||||
#include "esp32s3/spiram.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "port_systick.h"
|
#include "port_systick.h"
|
||||||
#include "esp_private/startup_internal.h" // [refactor-todo] for g_spiram_ok
|
|
||||||
#include "esp_app_trace.h" // [refactor-todo] for esp_app_trace_init
|
|
||||||
|
|
||||||
/* Defined in xtensa_context.S */
|
|
||||||
extern void _xt_coproc_init(void);
|
|
||||||
|
|
||||||
static const char* TAG = "cpu_start"; // [refactor-todo]: might be appropriate to change in the future, but
|
|
||||||
// for now maintain the same log output
|
|
||||||
|
|
||||||
_Static_assert(tskNO_AFFINITY == CONFIG_FREERTOS_NO_AFFINITY, "incorrect tskNO_AFFINITY value");
|
_Static_assert(tskNO_AFFINITY == CONFIG_FREERTOS_NO_AFFINITY, "incorrect tskNO_AFFINITY value");
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
/* ---------------------------------------------------- Variables ------------------------------------------------------
|
||||||
|
*
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
static const char *TAG = "cpu_start"; /* [refactor-todo]: might be appropriate to change in the future, but for now maintain the same log output */
|
||||||
extern volatile int port_xSchedulerRunning[portNUM_PROCESSORS];
|
extern volatile int port_xSchedulerRunning[portNUM_PROCESSORS];
|
||||||
unsigned port_interruptNesting[portNUM_PROCESSORS] = {0}; // Interrupt nesting level. Increased/decreased in portasm.c, _frxt_int_enter/_frxt_int_exit
|
unsigned port_interruptNesting[portNUM_PROCESSORS] = {0}; // Interrupt nesting level. Increased/decreased in portasm.c, _frxt_int_enter/_frxt_int_exit
|
||||||
BaseType_t port_uxCriticalNesting[portNUM_PROCESSORS] = {0};
|
BaseType_t port_uxCriticalNesting[portNUM_PROCESSORS] = {0};
|
||||||
BaseType_t port_uxOldInterruptState[portNUM_PROCESSORS] = {0};
|
BaseType_t port_uxOldInterruptState[portNUM_PROCESSORS] = {0};
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------ FreeRTOS Portable --------------------------------------------------
|
||||||
|
* - Provides implementation for functions required by FreeRTOS
|
||||||
|
* - Declared in portable.h
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
// ----------------- Scheduler Start/End -------------------
|
||||||
|
|
||||||
|
/* Defined in xtensa_context.S */
|
||||||
|
extern void _xt_coproc_init(void);
|
||||||
|
|
||||||
|
BaseType_t xPortStartScheduler( void )
|
||||||
|
{
|
||||||
|
// Interrupts are disabled at this point and stack contains PS with enabled interrupts when task context is restored
|
||||||
|
|
||||||
|
#if XCHAL_CP_NUM > 0
|
||||||
|
/* Initialize co-processor management for tasks. Leave CPENABLE alone. */
|
||||||
|
_xt_coproc_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Setup the hardware to generate the tick. */
|
||||||
|
vPortSetupTimer();
|
||||||
|
|
||||||
|
port_xSchedulerRunning[xPortGetCoreID()] = 1;
|
||||||
|
|
||||||
|
// Cannot be directly called from C; never returns
|
||||||
|
__asm__ volatile ("call0 _frxt_dispatch\n");
|
||||||
|
|
||||||
|
/* Should not get here. */
|
||||||
|
return pdTRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vPortEndScheduler( void )
|
||||||
|
{
|
||||||
|
/* It is unlikely that the Xtensa port will get stopped. If required simply
|
||||||
|
disable the tick interrupt here. */
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------ Stack --------------------------
|
||||||
|
|
||||||
// User exception dispatcher when exiting
|
// User exception dispatcher when exiting
|
||||||
void _xt_user_exit(void);
|
void _xt_user_exit(void);
|
||||||
@@ -158,15 +129,12 @@ static void vPortTaskWrapper(TaskFunction_t pxCode, void *pvParameters)
|
|||||||
{
|
{
|
||||||
pxCode(pvParameters);
|
pxCode(pvParameters);
|
||||||
//FreeRTOS tasks should not return. Log the task name and abort.
|
//FreeRTOS tasks should not return. Log the task name and abort.
|
||||||
char * pcTaskName = pcTaskGetTaskName(NULL);
|
char *pcTaskName = pcTaskGetTaskName(NULL);
|
||||||
ESP_LOGE("FreeRTOS", "FreeRTOS Task \"%s\" should not return, Aborting now!", pcTaskName);
|
ESP_LOGE("FreeRTOS", "FreeRTOS Task \"%s\" should not return, Aborting now!", pcTaskName);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Stack initialization
|
|
||||||
*/
|
|
||||||
#if portUSING_MPU_WRAPPERS
|
#if portUSING_MPU_WRAPPERS
|
||||||
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged )
|
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged )
|
||||||
#else
|
#else
|
||||||
@@ -175,9 +143,9 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
|
|||||||
{
|
{
|
||||||
StackType_t *sp, *tp;
|
StackType_t *sp, *tp;
|
||||||
XtExcFrame *frame;
|
XtExcFrame *frame;
|
||||||
#if XCHAL_CP_NUM > 0
|
#if XCHAL_CP_NUM > 0
|
||||||
uint32_t *p;
|
uint32_t *p;
|
||||||
#endif
|
#endif
|
||||||
uint32_t *threadptr;
|
uint32_t *threadptr;
|
||||||
void *task_thread_local_start;
|
void *task_thread_local_start;
|
||||||
extern int _thread_local_start, _thread_local_end, _flash_rodata_start, _flash_rodata_align;
|
extern int _thread_local_start, _thread_local_end, _flash_rodata_start, _flash_rodata_align;
|
||||||
@@ -198,46 +166,47 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
|
|||||||
sp = (StackType_t *) (((UBaseType_t)pxTopOfStack - XT_CP_SIZE - thread_local_sz - XT_STK_FRMSZ) & ~0xf);
|
sp = (StackType_t *) (((UBaseType_t)pxTopOfStack - XT_CP_SIZE - thread_local_sz - XT_STK_FRMSZ) & ~0xf);
|
||||||
|
|
||||||
/* Clear the entire frame (do not use memset() because we don't depend on C library) */
|
/* Clear the entire frame (do not use memset() because we don't depend on C library) */
|
||||||
for (tp = sp; tp <= pxTopOfStack; ++tp)
|
for (tp = sp; tp <= pxTopOfStack; ++tp) {
|
||||||
*tp = 0;
|
*tp = 0;
|
||||||
|
}
|
||||||
|
|
||||||
frame = (XtExcFrame *) sp;
|
frame = (XtExcFrame *) sp;
|
||||||
|
|
||||||
/* Explicitly initialize certain saved registers */
|
/* Explicitly initialize certain saved registers */
|
||||||
#if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
|
#if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
|
||||||
frame->pc = (UBaseType_t) vPortTaskWrapper; /* task wrapper */
|
frame->pc = (UBaseType_t) vPortTaskWrapper; /* task wrapper */
|
||||||
#else
|
#else
|
||||||
frame->pc = (UBaseType_t) pxCode; /* task entrypoint */
|
frame->pc = (UBaseType_t) pxCode; /* task entrypoint */
|
||||||
#endif
|
#endif
|
||||||
frame->a0 = 0; /* to terminate GDB backtrace */
|
frame->a0 = 0; /* to terminate GDB backtrace */
|
||||||
frame->a1 = (UBaseType_t) sp + XT_STK_FRMSZ; /* physical top of stack frame */
|
frame->a1 = (UBaseType_t) sp + XT_STK_FRMSZ; /* physical top of stack frame */
|
||||||
frame->exit = (UBaseType_t) _xt_user_exit; /* user exception exit dispatcher */
|
frame->exit = (UBaseType_t) _xt_user_exit; /* user exception exit dispatcher */
|
||||||
|
|
||||||
/* Set initial PS to int level 0, EXCM disabled ('rfe' will enable), user mode. */
|
/* Set initial PS to int level 0, EXCM disabled ('rfe' will enable), user mode. */
|
||||||
/* Also set entry point argument parameter. */
|
/* Also set entry point argument parameter. */
|
||||||
#ifdef __XTENSA_CALL0_ABI__
|
#ifdef __XTENSA_CALL0_ABI__
|
||||||
#if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
|
#if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
|
||||||
frame->a2 = (UBaseType_t) pxCode;
|
frame->a2 = (UBaseType_t) pxCode;
|
||||||
frame->a3 = (UBaseType_t) pvParameters;
|
frame->a3 = (UBaseType_t) pvParameters;
|
||||||
#else
|
#else
|
||||||
frame->a2 = (UBaseType_t) pvParameters;
|
frame->a2 = (UBaseType_t) pvParameters;
|
||||||
#endif
|
#endif
|
||||||
frame->ps = PS_UM | PS_EXCM;
|
frame->ps = PS_UM | PS_EXCM;
|
||||||
#else
|
#else /* __XTENSA_CALL0_ABI__ */
|
||||||
/* + for windowed ABI also set WOE and CALLINC (pretend task was 'call4'd). */
|
/* + for windowed ABI also set WOE and CALLINC (pretend task was 'call4'd). */
|
||||||
#if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
|
#if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
|
||||||
frame->a6 = (UBaseType_t) pxCode;
|
frame->a6 = (UBaseType_t) pxCode;
|
||||||
frame->a7 = (UBaseType_t) pvParameters;
|
frame->a7 = (UBaseType_t) pvParameters;
|
||||||
#else
|
#else
|
||||||
frame->a6 = (UBaseType_t) pvParameters;
|
frame->a6 = (UBaseType_t) pvParameters;
|
||||||
#endif
|
#endif
|
||||||
frame->ps = PS_UM | PS_EXCM | PS_WOE | PS_CALLINC(1);
|
frame->ps = PS_UM | PS_EXCM | PS_WOE | PS_CALLINC(1);
|
||||||
#endif
|
#endif /* __XTENSA_CALL0_ABI__ */
|
||||||
|
|
||||||
#ifdef XT_USE_SWPRI
|
#ifdef XT_USE_SWPRI
|
||||||
/* Set the initial virtual priority mask value to all 1's. */
|
/* Set the initial virtual priority mask value to all 1's. */
|
||||||
frame->vpri = 0xFFFFFFFF;
|
frame->vpri = 0xFFFFFFFF;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Init threadptr register and set up TLS run-time area.
|
/* Init threadptr register and set up TLS run-time area.
|
||||||
* The diagram in port/riscv/port.c illustrates the calculations below.
|
* The diagram in port/riscv/port.c illustrates the calculations below.
|
||||||
@@ -259,7 +228,7 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
|
|||||||
const uint32_t base = (tcb_size + tls_section_alignment - 1) & (~(tls_section_alignment - 1));
|
const uint32_t base = (tcb_size + tls_section_alignment - 1) & (~(tls_section_alignment - 1));
|
||||||
*threadptr = (uint32_t)task_thread_local_start - ((uint32_t)&_thread_local_start - (uint32_t)&_flash_rodata_start) - base;
|
*threadptr = (uint32_t)task_thread_local_start - ((uint32_t)&_thread_local_start - (uint32_t)&_flash_rodata_start) - base;
|
||||||
|
|
||||||
#if XCHAL_CP_NUM > 0
|
#if XCHAL_CP_NUM > 0
|
||||||
/* Init the coprocessor save area (see xtensa_context.h) */
|
/* Init the coprocessor save area (see xtensa_context.h) */
|
||||||
/* No access to TCB here, so derive indirectly. Stack growth is top to bottom.
|
/* No access to TCB here, so derive indirectly. Stack growth is top to bottom.
|
||||||
* //p = (uint32_t *) xMPUSettings->coproc_area;
|
* //p = (uint32_t *) xMPUSettings->coproc_area;
|
||||||
@@ -269,146 +238,40 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
|
|||||||
p[0] = 0;
|
p[0] = 0;
|
||||||
p[1] = 0;
|
p[1] = 0;
|
||||||
p[2] = (((uint32_t) p) + 12 + XCHAL_TOTAL_SA_ALIGN - 1) & -XCHAL_TOTAL_SA_ALIGN;
|
p[2] = (((uint32_t) p) + 12 + XCHAL_TOTAL_SA_ALIGN - 1) & -XCHAL_TOTAL_SA_ALIGN;
|
||||||
#endif
|
#endif /* XCHAL_CP_NUM */
|
||||||
|
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
void vPortEndScheduler( void )
|
|
||||||
{
|
|
||||||
/* It is unlikely that the Xtensa port will get stopped. If required simply
|
|
||||||
disable the tick interrupt here. */
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
BaseType_t xPortStartScheduler( void )
|
|
||||||
{
|
|
||||||
// Interrupts are disabled at this point and stack contains PS with enabled interrupts when task context is restored
|
|
||||||
|
|
||||||
#if XCHAL_CP_NUM > 0
|
|
||||||
/* Initialize co-processor management for tasks. Leave CPENABLE alone. */
|
|
||||||
_xt_coproc_init();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Setup the hardware to generate the tick. */
|
|
||||||
vPortSetupTimer();
|
|
||||||
|
|
||||||
port_xSchedulerRunning[xPortGetCoreID()] = 1;
|
|
||||||
|
|
||||||
// Cannot be directly called from C; never returns
|
|
||||||
__asm__ volatile ("call0 _frxt_dispatch\n");
|
|
||||||
|
|
||||||
/* Should not get here. */
|
|
||||||
return pdTRUE;
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
void vPortYieldOtherCore( BaseType_t coreid ) {
|
|
||||||
esp_crosscore_int_send_yield( coreid );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Used to set coprocessor area in stack. Current hack is to reuse MPU pointer for coprocessor area.
|
|
||||||
*/
|
|
||||||
#if portUSING_MPU_WRAPPERS
|
|
||||||
void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint32_t usStackDepth )
|
|
||||||
{
|
|
||||||
#if XCHAL_CP_NUM > 0
|
|
||||||
xMPUSettings->coproc_area = ( StackType_t * ) ( ( uint32_t ) ( pxBottomOfStack + usStackDepth - 1 ));
|
|
||||||
xMPUSettings->coproc_area = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) xMPUSettings->coproc_area ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
|
|
||||||
xMPUSettings->coproc_area = ( StackType_t * ) ( ( ( uint32_t ) xMPUSettings->coproc_area - XT_CP_SIZE ) & ~0xf );
|
|
||||||
|
|
||||||
|
|
||||||
/* NOTE: we cannot initialize the coprocessor save area here because FreeRTOS is going to
|
/* ---------------------------------------------- Port Implementations -------------------------------------------------
|
||||||
* clear the stack area after we return. This is done in pxPortInitialiseStack().
|
*
|
||||||
*/
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void vPortReleaseTaskMPUSettings( xMPU_SETTINGS *xMPUSettings )
|
// --------------------- Interrupts ------------------------
|
||||||
{
|
|
||||||
/* If task has live floating point registers somewhere, release them */
|
|
||||||
_xt_coproc_release( xMPUSettings->coproc_area );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns true if the current core is in ISR context; low prio ISR, med prio ISR or timer tick ISR. High prio ISRs
|
|
||||||
* aren't detected here, but they normally cannot call C code, so that should not be an issue anyway.
|
|
||||||
*/
|
|
||||||
BaseType_t xPortInIsrContext(void)
|
BaseType_t xPortInIsrContext(void)
|
||||||
{
|
{
|
||||||
unsigned int irqStatus;
|
unsigned int irqStatus;
|
||||||
BaseType_t ret;
|
BaseType_t ret;
|
||||||
irqStatus=portENTER_CRITICAL_NESTED();
|
irqStatus = portENTER_CRITICAL_NESTED();
|
||||||
ret=(port_interruptNesting[xPortGetCoreID()] != 0);
|
ret = (port_interruptNesting[xPortGetCoreID()] != 0);
|
||||||
portEXIT_CRITICAL_NESTED(irqStatus);
|
portEXIT_CRITICAL_NESTED(irqStatus);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* This function will be called in High prio ISRs. Returns true if the current core was in ISR context
|
|
||||||
* before calling into high prio ISR context.
|
|
||||||
*/
|
|
||||||
BaseType_t IRAM_ATTR xPortInterruptedFromISRContext(void)
|
|
||||||
{
|
|
||||||
return (port_interruptNesting[xPortGetCoreID()] != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IRAM_ATTR vPortEvaluateYieldFromISR(int argc, ...)
|
|
||||||
{
|
|
||||||
BaseType_t xYield;
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, argc);
|
|
||||||
|
|
||||||
if(argc) {
|
|
||||||
xYield = (BaseType_t)va_arg(ap, int);
|
|
||||||
va_end(ap);
|
|
||||||
} else {
|
|
||||||
//it is a empty parameter vPortYieldFromISR macro call:
|
|
||||||
va_end(ap);
|
|
||||||
traceISR_EXIT_TO_SCHEDULER();
|
|
||||||
_frxt_setup_switch();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Yield exists, so need evaluate it first then switch:
|
|
||||||
if(xYield == pdTRUE) {
|
|
||||||
traceISR_EXIT_TO_SCHEDULER();
|
|
||||||
_frxt_setup_switch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void vPortAssertIfInISR(void)
|
void vPortAssertIfInISR(void)
|
||||||
{
|
{
|
||||||
configASSERT(xPortInIsrContext());
|
configASSERT(xPortInIsrContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STACK_WATCH_AREA_SIZE 32
|
BaseType_t IRAM_ATTR xPortInterruptedFromISRContext(void)
|
||||||
#define STACK_WATCH_POINT_NUMBER (SOC_CPU_WATCHPOINTS_NUM - 1)
|
{
|
||||||
|
return (port_interruptNesting[xPortGetCoreID()] != 0);
|
||||||
void vPortSetStackWatchpoint( void* pxStackStart ) {
|
|
||||||
//Set watchpoint 1 to watch the last 32 bytes of the stack.
|
|
||||||
//Unfortunately, the Xtensa watchpoints can't set a watchpoint on a random [base - base+n] region because
|
|
||||||
//the size works by masking off the lowest address bits. For that reason, we futz a bit and watch the lowest 32
|
|
||||||
//bytes of the stack we can actually watch. In general, this can cause the watchpoint to be triggered at most
|
|
||||||
//28 bytes early. The value 32 is chosen because it's larger than the stack canary, which in FreeRTOS is 20 bytes.
|
|
||||||
//This way, we make sure we trigger before/when the stack canary is corrupted, not after.
|
|
||||||
int addr=(int)pxStackStart;
|
|
||||||
addr=(addr+31)&(~31);
|
|
||||||
esp_cpu_set_watchpoint(STACK_WATCH_POINT_NUMBER, (char*)addr, 32, ESP_WATCHPOINT_STORE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t xPortGetTickRateHz(void) {
|
// ------------------ Critical Sections --------------------
|
||||||
return (uint32_t)configTICK_RATE_HZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void __attribute__((optimize("-O3"))) vPortEnterCritical(portMUX_TYPE *mux)
|
void __attribute__((optimize("-O3"))) vPortEnterCritical(portMUX_TYPE *mux)
|
||||||
{
|
{
|
||||||
@@ -424,8 +287,7 @@ void __attribute__((optimize("-O3"))) vPortEnterCritical(portMUX_TYPE *mux)
|
|||||||
BaseType_t newNesting = port_uxCriticalNesting[coreID] + 1;
|
BaseType_t newNesting = port_uxCriticalNesting[coreID] + 1;
|
||||||
port_uxCriticalNesting[coreID] = newNesting;
|
port_uxCriticalNesting[coreID] = newNesting;
|
||||||
|
|
||||||
if( newNesting == 1 )
|
if ( newNesting == 1 ) {
|
||||||
{
|
|
||||||
//This is the first time we get called. Save original interrupt level.
|
//This is the first time we get called. Save original interrupt level.
|
||||||
port_uxOldInterruptState[coreID] = oldInterruptLevel;
|
port_uxOldInterruptState[coreID] = oldInterruptLevel;
|
||||||
}
|
}
|
||||||
@@ -437,33 +299,123 @@ void __attribute__((optimize("-O3"))) vPortExitCritical(portMUX_TYPE *mux)
|
|||||||
BaseType_t coreID = xPortGetCoreID();
|
BaseType_t coreID = xPortGetCoreID();
|
||||||
BaseType_t nesting = port_uxCriticalNesting[coreID];
|
BaseType_t nesting = port_uxCriticalNesting[coreID];
|
||||||
|
|
||||||
if(nesting > 0)
|
if (nesting > 0) {
|
||||||
{
|
|
||||||
nesting--;
|
nesting--;
|
||||||
port_uxCriticalNesting[coreID] = nesting;
|
port_uxCriticalNesting[coreID] = nesting;
|
||||||
|
|
||||||
if( nesting == 0 )
|
if ( nesting == 0 ) {
|
||||||
{
|
|
||||||
portEXIT_CRITICAL_NESTED(port_uxOldInterruptState[coreID]);
|
portEXIT_CRITICAL_NESTED(port_uxOldInterruptState[coreID]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------- Yielding -------------------------
|
||||||
|
|
||||||
|
void vPortYieldOtherCore( BaseType_t coreid )
|
||||||
|
{
|
||||||
|
esp_crosscore_int_send_yield( coreid );
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void _frxt_setup_switch( void ); //Defined in portasm.S
|
||||||
|
|
||||||
|
void IRAM_ATTR vPortEvaluateYieldFromISR(int argc, ...)
|
||||||
|
{
|
||||||
|
BaseType_t xYield;
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, argc);
|
||||||
|
|
||||||
|
if (argc) {
|
||||||
|
xYield = (BaseType_t)va_arg(ap, int);
|
||||||
|
va_end(ap);
|
||||||
|
} else {
|
||||||
|
//it is a empty parameter vPortYieldFromISR macro call:
|
||||||
|
va_end(ap);
|
||||||
|
traceISR_EXIT_TO_SCHEDULER();
|
||||||
|
_frxt_setup_switch();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Yield exists, so need evaluate it first then switch:
|
||||||
|
if (xYield == pdTRUE) {
|
||||||
|
traceISR_EXIT_TO_SCHEDULER();
|
||||||
|
_frxt_setup_switch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------- Hook Functions ----------------------
|
||||||
|
|
||||||
void __attribute__((weak)) vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
|
void __attribute__((weak)) vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
|
||||||
{
|
{
|
||||||
#define ERR_STR1 "***ERROR*** A stack overflow in task "
|
#define ERR_STR1 "***ERROR*** A stack overflow in task "
|
||||||
#define ERR_STR2 " has been detected."
|
#define ERR_STR2 " has been detected."
|
||||||
const char *str[] = {ERR_STR1, pcTaskName, ERR_STR2};
|
const char *str[] = {ERR_STR1, pcTaskName, ERR_STR2};
|
||||||
|
|
||||||
char buf[sizeof(ERR_STR1) + CONFIG_FREERTOS_MAX_TASK_NAME_LEN + sizeof(ERR_STR2) + 1 /* null char */] = { 0 };
|
char buf[sizeof(ERR_STR1) + CONFIG_FREERTOS_MAX_TASK_NAME_LEN + sizeof(ERR_STR2) + 1 /* null char */] = { 0 };
|
||||||
|
|
||||||
char *dest = buf;
|
char *dest = buf;
|
||||||
for (size_t i = 0 ; i < sizeof(str)/ sizeof(str[0]); i++) {
|
for (size_t i = 0 ; i < sizeof(str) / sizeof(str[0]); i++) {
|
||||||
dest = strcat(dest, str[i]);
|
dest = strcat(dest, str[i]);
|
||||||
}
|
}
|
||||||
esp_system_abort(buf);
|
esp_system_abort(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------- System --------------------------
|
||||||
|
|
||||||
|
uint32_t xPortGetTickRateHz(void)
|
||||||
|
{
|
||||||
|
return (uint32_t)configTICK_RATE_HZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define STACK_WATCH_AREA_SIZE 32
|
||||||
|
#define STACK_WATCH_POINT_NUMBER (SOC_CPU_WATCHPOINTS_NUM - 1)
|
||||||
|
|
||||||
|
void vPortSetStackWatchpoint( void *pxStackStart )
|
||||||
|
{
|
||||||
|
//Set watchpoint 1 to watch the last 32 bytes of the stack.
|
||||||
|
//Unfortunately, the Xtensa watchpoints can't set a watchpoint on a random [base - base+n] region because
|
||||||
|
//the size works by masking off the lowest address bits. For that reason, we futz a bit and watch the lowest 32
|
||||||
|
//bytes of the stack we can actually watch. In general, this can cause the watchpoint to be triggered at most
|
||||||
|
//28 bytes early. The value 32 is chosen because it's larger than the stack canary, which in FreeRTOS is 20 bytes.
|
||||||
|
//This way, we make sure we trigger before/when the stack canary is corrupted, not after.
|
||||||
|
int addr = (int)pxStackStart;
|
||||||
|
addr = (addr + 31) & (~31);
|
||||||
|
esp_cpu_set_watchpoint(STACK_WATCH_POINT_NUMBER, (char *)addr, 32, ESP_WATCHPOINT_STORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------- Misc Implementations -------------------------------------------------
|
||||||
|
*
|
||||||
|
* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
// -------------------- Co-Processor -----------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Used to set coprocessor area in stack. Current hack is to reuse MPU pointer for coprocessor area.
|
||||||
|
*/
|
||||||
|
#if portUSING_MPU_WRAPPERS
|
||||||
|
void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION *const xRegions, StackType_t *pxBottomOfStack, uint32_t usStackDepth )
|
||||||
|
{
|
||||||
|
#if XCHAL_CP_NUM > 0
|
||||||
|
xMPUSettings->coproc_area = ( StackType_t * ) ( ( uint32_t ) ( pxBottomOfStack + usStackDepth - 1 ));
|
||||||
|
xMPUSettings->coproc_area = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) xMPUSettings->coproc_area ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
|
||||||
|
xMPUSettings->coproc_area = ( StackType_t * ) ( ( ( uint32_t ) xMPUSettings->coproc_area - XT_CP_SIZE ) & ~0xf );
|
||||||
|
|
||||||
|
|
||||||
|
/* NOTE: we cannot initialize the coprocessor save area here because FreeRTOS is going to
|
||||||
|
* clear the stack area after we return. This is done in pxPortInitialiseStack().
|
||||||
|
*/
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void vPortReleaseTaskMPUSettings( xMPU_SETTINGS *xMPUSettings )
|
||||||
|
{
|
||||||
|
/* If task has live floating point registers somewhere, release them */
|
||||||
|
_xt_coproc_release( xMPUSettings->coproc_area );
|
||||||
|
}
|
||||||
|
#endif /* portUSING_MPU_WRAPPERS */
|
||||||
|
|
||||||
|
// --------------------- App Start-up ----------------------
|
||||||
|
|
||||||
#if !CONFIG_FREERTOS_UNICORE
|
#if !CONFIG_FREERTOS_UNICORE
|
||||||
void esp_startup_start_app_other_cores(void)
|
void esp_startup_start_app_other_cores(void)
|
||||||
{
|
{
|
||||||
|
@@ -1382,10 +1382,10 @@ components/freertos/croutine.c
|
|||||||
components/freertos/esp_additions/task_snapshot.c
|
components/freertos/esp_additions/task_snapshot.c
|
||||||
components/freertos/event_groups.c
|
components/freertos/event_groups.c
|
||||||
components/freertos/freertos_v8_compat.c
|
components/freertos/freertos_v8_compat.c
|
||||||
|
components/freertos/include/esp_additions/freertos/FreeRTOSConfig.h
|
||||||
components/freertos/include/esp_additions/freertos/task_snapshot.h
|
components/freertos/include/esp_additions/freertos/task_snapshot.h
|
||||||
components/freertos/include/esp_additions/freertos_tasks_c_additions.h
|
components/freertos/include/esp_additions/freertos_tasks_c_additions.h
|
||||||
components/freertos/include/freertos/FreeRTOS.h
|
components/freertos/include/freertos/FreeRTOS.h
|
||||||
components/freertos/include/freertos/FreeRTOSConfig.h
|
|
||||||
components/freertos/include/freertos/StackMacros.h
|
components/freertos/include/freertos/StackMacros.h
|
||||||
components/freertos/include/freertos/atomic.h
|
components/freertos/include/freertos/atomic.h
|
||||||
components/freertos/include/freertos/croutine.h
|
components/freertos/include/freertos/croutine.h
|
||||||
@@ -1404,14 +1404,13 @@ components/freertos/include/freertos/stream_buffer.h
|
|||||||
components/freertos/include/freertos/task.h
|
components/freertos/include/freertos/task.h
|
||||||
components/freertos/include/freertos/timers.h
|
components/freertos/include/freertos/timers.h
|
||||||
components/freertos/list.c
|
components/freertos/list.c
|
||||||
components/freertos/port/linux/include/freertos/FreeRTOSConfig.h
|
components/freertos/port/linux/include/freertos/FreeRTOSConfig_arch.h
|
||||||
components/freertos/port/linux/include/freertos/portmacro.h
|
components/freertos/port/linux/include/freertos/portmacro.h
|
||||||
components/freertos/port/port_common.c
|
components/freertos/port/riscv/include/freertos/FreeRTOSConfig_arch.h
|
||||||
components/freertos/port/riscv/include/freertos/FreeRTOSConfig.h
|
|
||||||
components/freertos/port/riscv/include/freertos/portbenchmark.h
|
components/freertos/port/riscv/include/freertos/portbenchmark.h
|
||||||
components/freertos/port/riscv/include/freertos/portmacro.h
|
components/freertos/port/riscv/include/freertos/portmacro.h
|
||||||
components/freertos/port/riscv/port.c
|
components/freertos/port/riscv/port.c
|
||||||
components/freertos/port/xtensa/include/freertos/FreeRTOSConfig.h
|
components/freertos/port/xtensa/include/freertos/FreeRTOSConfig_arch.h
|
||||||
components/freertos/port/xtensa/include/freertos/portbenchmark.h
|
components/freertos/port/xtensa/include/freertos/portbenchmark.h
|
||||||
components/freertos/port/xtensa/include/freertos/portmacro.h
|
components/freertos/port/xtensa/include/freertos/portmacro.h
|
||||||
components/freertos/port/xtensa/include/freertos/portmacro_priv.h
|
components/freertos/port/xtensa/include/freertos/portmacro_priv.h
|
||||||
|
Reference in New Issue
Block a user