游戏王对战板,目前code还是空的

Committer:
WFKnight
Date:
Thu Jun 21 13:51:43 2018 +0000
Revision:
0:9b3d4731edbb
UART, RTOS, LED

Who changed what in which revision?

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