1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 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 */ 15 /*****************************************************************************/ 16 /* File Includes */ 17 /*****************************************************************************/ 18 19 #include "ll.h" 20 21 /*****************************************************************************/ 22 /* Variables */ 23 /*****************************************************************************/ 24 25 static unsigned int critical_sect_count = 0U; 26 static unsigned int critical_ctxt_saved = 0U; 27 28 /*****************************************************************************/ 29 /* Functions */ 30 /*****************************************************************************/ 31 critical_section_start(void)32void critical_section_start(void) 33 { 34 if (__get_IPSR() == 0U) { 35 if (0U == critical_sect_count) { 36 critical_ctxt_saved = __get_PRIMASK(); 37 __disable_irq(); 38 } 39 critical_sect_count++; 40 } 41 } 42 critical_section_end(void)43void critical_section_end(void) 44 { 45 if (__get_IPSR() == 0U) { 46 critical_sect_count--; 47 if (0U == critical_sect_count) { 48 __set_PRIMASK(critical_ctxt_saved); 49 } 50 } 51 } 52