• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "soc/compare_set.h"
15 #include "soc/spinlock.h"
16 #include "soc/soc_caps.h"
17 #if __XTENSA__ && SOC_SPIRAM_SUPPORTED
18 
19 static spinlock_t global_extram_lock = SPINLOCK_INITIALIZER;
20 
compare_and_set_extram(volatile uint32_t * addr,uint32_t compare,uint32_t * set)21 void compare_and_set_extram(volatile uint32_t *addr, uint32_t compare, uint32_t *set)
22 {
23     uint32_t intlevel, old_value;
24     __asm__ __volatile__ ("rsil %0, " XTSTR(XCHAL_EXCM_LEVEL) "\n"
25                           : "=r"(intlevel));
26 
27 	spinlock_acquire(&global_extram_lock, SPINLOCK_WAIT_FOREVER);
28 
29     old_value = *addr;
30     if (old_value == compare) {
31         *addr = *set;
32     }
33 
34 	spinlock_release(&global_extram_lock);
35 
36 	__asm__ __volatile__ ("memw \n"
37 						"wsr %0, ps\n"
38 						:: "r"(intlevel));
39 
40     *set = old_value;
41 }
42 #else // __XTENSA__ && SOC_SPIRAM_SUPPORTED
43 
compare_and_set_extram(volatile uint32_t * addr,uint32_t compare,uint32_t * set)44 void compare_and_set_extram(volatile uint32_t *addr, uint32_t compare, uint32_t *set)
45 {
46     compare_and_set_native(addr, compare, set);
47 }
48 #endif // endif
49 
50