expression_with_stack_xtensa.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include <esp_expression_with_stack.h>
  15. #include <freertos/xtensa_rtos.h>
  16. #include <freertos/xtensa_context.h>
  17. StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size)
  18. {
  19. #if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
  20. int watchpoint_place = (((int)stack + 31) & ~31);
  21. #endif
  22. StackType_t *top_of_stack = (StackType_t *)&stack[0] +
  23. ((stack_size * sizeof(StackType_t)) / sizeof(StackType_t));
  24. //Align stack to a 16byte boundary, as required by CPU specific:
  25. top_of_stack = (StackType_t *)(((UBaseType_t)(top_of_stack - 31) -
  26. ALIGNUP(0x10, sizeof(XtSolFrame) )) &
  27. ~0xf);
  28. //Fake stack frame to do not break the backtrace
  29. XtSolFrame *frame = (XtSolFrame *)top_of_stack;
  30. frame->a0 = 0;
  31. frame->a1 = (UBaseType_t)top_of_stack;
  32. #if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
  33. esp_set_watchpoint(2, (char*)watchpoint_place, 32, ESP_WATCHPOINT_STORE);
  34. #endif
  35. return top_of_stack;
  36. }