1 // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #pragma once
15 
16 #include <stdbool.h>
17 #include "freertos/FreeRTOS.h"
18 #include "freertos/semphr.h"
19 #include "freertos/task.h"
20 #include "esp_debug_helpers.h"
21 #include "esp_log.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef void (*shared_stack_function)(void);
28 
29 #define ESP_EXECUTE_EXPRESSION_WITH_STACK(lock, stack, stack_size, expression) \
30     esp_execute_shared_stack_function(lock, stack, stack_size, expression)
31 
32 /**
33  * @brief Calls user defined shared stack space function
34  * @param lock Mutex object to protect in case of shared stack
35  * @param stack Pointer to user alocated stack
36  * @param stack_size Size of current stack in bytes
37  * @param function pointer to the shared stack function to be executed
38  * @note  if either lock, stack or stack size is invalid, the expression will
39  *          be called using the current stack.
40  */
41 void esp_execute_shared_stack_function(SemaphoreHandle_t lock,
42                                       void *stack,
43                                       size_t stack_size,
44                                       shared_stack_function function);
45 
46 
47 #ifdef __cplusplus
48 }
49 #endif
50