Committer:
borlanic
Date:
Thu Mar 29 07:02:09 2018 +0000
Revision:
0:380207fcb5c1
Encoder, IMU --> OK; Controller --> in bearbeitung

Who changed what in which revision?

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