source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/hal/mbed_critical_section_api.c@ 374

Last change on this file since 374 was 374, checked in by coas-nagasima, 5 years ago

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

  • Property charset set to UTF-8
  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 1.7 KB
Line 
1/* mbed Microcontroller Library
2 * Copyright (c) 2017 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "cmsis.h"
17#include "hal/critical_section_api.h"
18#include "platform/mbed_assert.h"
19#include "platform/mbed_toolchain.h"
20
21#include <stdbool.h>
22
23static volatile bool critical_interrupts_enabled = false;
24static volatile bool state_saved = false;
25
26static bool are_interrupts_enabled(void)
27{
28#if defined(__CORTEX_A9)
29 return ((__get_CPSR() & 0x80) == 0);
30#else
31 return ((__get_PRIMASK() & 0x1) == 0);
32#endif
33}
34
35
36MBED_WEAK void hal_critical_section_enter(void)
37{
38 const bool interrupt_state = are_interrupts_enabled();
39
40 __disable_irq();
41
42 if (state_saved == true) {
43 return;
44 }
45
46 critical_interrupts_enabled = interrupt_state;
47 state_saved = true;
48}
49
50MBED_WEAK void hal_critical_section_exit(void)
51{
52 // Interrupts must be disabled on invoking an exit from a critical section
53 MBED_ASSERT(!are_interrupts_enabled());
54 state_saved = false;
55
56 // Restore the IRQs to their state prior to entering the critical section
57 if (critical_interrupts_enabled == true) {
58 __enable_irq();
59 }
60}
61
62MBED_WEAK bool hal_in_critical_section(void)
63{
64 return (state_saved == true);
65}
Note: See TracBrowser for help on using the repository browser.