| 
									
										
										
										
											2020-01-06 17:01:53 -03:00
										 |  |  | // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Licensed under the Apache License, Version 2.0 (the "License");
 | 
					
						
							|  |  |  | // you may not use this file except in compliance with the License.
 | 
					
						
							|  |  |  | // 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.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 13:52:27 -03:00
										 |  |  | #include <esp_expression_with_stack.h>
 | 
					
						
							|  |  |  | #include <freertos/xtensa_rtos.h>
 | 
					
						
							|  |  |  | #include <freertos/xtensa_context.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-01-06 17:01:53 -03:00
										 |  |  | #if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
 | 
					
						
							| 
									
										
										
										
											2020-02-10 12:03:24 -03:00
										 |  |  |     esp_clear_watchpoint(1); | 
					
						
							| 
									
										
										
										
											2020-02-06 16:24:39 -03:00
										 |  |  |     uint32_t watchpoint_place = ((uint32_t)stack + 32) & 0x1f ; | 
					
						
							| 
									
										
										
										
											2020-01-06 17:01:53 -03:00
										 |  |  | #endif    
 | 
					
						
							| 
									
										
										
										
											2019-11-27 13:52:27 -03:00
										 |  |  |     StackType_t *top_of_stack =  (StackType_t *)&stack[0] +                   | 
					
						
							| 
									
										
										
										
											2019-12-20 13:23:47 -03:00
										 |  |  |             ((stack_size * sizeof(StackType_t)) / sizeof(StackType_t)); | 
					
						
							| 
									
										
										
										
											2019-11-27 13:52:27 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //Align stack to a 16byte boundary, as required by CPU specific:
 | 
					
						
							| 
									
										
										
										
											2019-12-04 11:25:02 -03:00
										 |  |  |     top_of_stack =  (StackType_t *)(((UBaseType_t)(top_of_stack - 31) - | 
					
						
							| 
									
										
										
										
											2019-11-27 13:52:27 -03:00
										 |  |  |                                     ALIGNUP(0x10, sizeof(XtSolFrame) )) &  | 
					
						
							|  |  |  |                                     ~0xf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //Fake stack frame to do not break the backtrace
 | 
					
						
							|  |  |  |     XtSolFrame *frame = (XtSolFrame *)top_of_stack; | 
					
						
							|  |  |  |     frame->a0 = 0; | 
					
						
							|  |  |  |     frame->a1 = (UBaseType_t)top_of_stack; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-06 17:01:53 -03:00
										 |  |  | #if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
 | 
					
						
							| 
									
										
										
										
											2020-02-10 12:03:24 -03:00
										 |  |  |     esp_set_watchpoint(1, (uint8_t *)watchpoint_place, 32, ESP_WATCHPOINT_STORE);     | 
					
						
							| 
									
										
										
										
											2020-01-06 17:01:53 -03:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 13:52:27 -03:00
										 |  |  |     return top_of_stack;            | 
					
						
							|  |  |  | } |