Mouse code for the MacroRat
mbed-dev/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/nordic_critical.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /* |
sahilmgandhi | 18:6a4db94011d3 | 2 | * Copyright (c) 2015-2016, ARM Limited, All Rights Reserved |
sahilmgandhi | 18:6a4db94011d3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * |
sahilmgandhi | 18:6a4db94011d3 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
sahilmgandhi | 18:6a4db94011d3 | 6 | * not use this file except in compliance with the License. |
sahilmgandhi | 18:6a4db94011d3 | 7 | * You may obtain a copy of the License at |
sahilmgandhi | 18:6a4db94011d3 | 8 | * |
sahilmgandhi | 18:6a4db94011d3 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
sahilmgandhi | 18:6a4db94011d3 | 10 | * |
sahilmgandhi | 18:6a4db94011d3 | 11 | * Unless required by applicable law or agreed to in writing, software |
sahilmgandhi | 18:6a4db94011d3 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
sahilmgandhi | 18:6a4db94011d3 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sahilmgandhi | 18:6a4db94011d3 | 14 | * See the License for the specific language governing permissions and |
sahilmgandhi | 18:6a4db94011d3 | 15 | * limitations under the License. |
sahilmgandhi | 18:6a4db94011d3 | 16 | */ |
sahilmgandhi | 18:6a4db94011d3 | 17 | |
sahilmgandhi | 18:6a4db94011d3 | 18 | #include <stdint.h> // uint32_t, UINT32_MAX |
sahilmgandhi | 18:6a4db94011d3 | 19 | #include <assert.h> // uint32_t, UINT32_MAX |
sahilmgandhi | 18:6a4db94011d3 | 20 | #include "cmsis.h" |
sahilmgandhi | 18:6a4db94011d3 | 21 | #include "nrf_soc.h" |
sahilmgandhi | 18:6a4db94011d3 | 22 | #include "nrf_sdm.h" |
sahilmgandhi | 18:6a4db94011d3 | 23 | #include "nrf_nvic.h" |
sahilmgandhi | 18:6a4db94011d3 | 24 | |
sahilmgandhi | 18:6a4db94011d3 | 25 | static uint8_t _sd_state = 0; |
sahilmgandhi | 18:6a4db94011d3 | 26 | static volatile uint32_t _entry_count = 0; |
sahilmgandhi | 18:6a4db94011d3 | 27 | |
sahilmgandhi | 18:6a4db94011d3 | 28 | void core_util_critical_section_enter() |
sahilmgandhi | 18:6a4db94011d3 | 29 | { |
sahilmgandhi | 18:6a4db94011d3 | 30 | // if a critical section has already been entered, just update the counter |
sahilmgandhi | 18:6a4db94011d3 | 31 | if (_entry_count) |
sahilmgandhi | 18:6a4db94011d3 | 32 | { |
sahilmgandhi | 18:6a4db94011d3 | 33 | ++_entry_count; |
sahilmgandhi | 18:6a4db94011d3 | 34 | return; |
sahilmgandhi | 18:6a4db94011d3 | 35 | } |
sahilmgandhi | 18:6a4db94011d3 | 36 | |
sahilmgandhi | 18:6a4db94011d3 | 37 | // in this path, a critical section has never been entered |
sahilmgandhi | 18:6a4db94011d3 | 38 | // routine of SD V11 work even if the softdevice is not active |
sahilmgandhi | 18:6a4db94011d3 | 39 | sd_nvic_critical_region_enter(&_sd_state); |
sahilmgandhi | 18:6a4db94011d3 | 40 | |
sahilmgandhi | 18:6a4db94011d3 | 41 | assert(_entry_count == 0); // entry count should always be equal to 0 at this point |
sahilmgandhi | 18:6a4db94011d3 | 42 | ++_entry_count; |
sahilmgandhi | 18:6a4db94011d3 | 43 | } |
sahilmgandhi | 18:6a4db94011d3 | 44 | |
sahilmgandhi | 18:6a4db94011d3 | 45 | void core_util_critical_section_exit() |
sahilmgandhi | 18:6a4db94011d3 | 46 | { |
sahilmgandhi | 18:6a4db94011d3 | 47 | assert(_entry_count > 0); |
sahilmgandhi | 18:6a4db94011d3 | 48 | --_entry_count; |
sahilmgandhi | 18:6a4db94011d3 | 49 | |
sahilmgandhi | 18:6a4db94011d3 | 50 | // If their is other segments which have entered the critical section, just leave |
sahilmgandhi | 18:6a4db94011d3 | 51 | if (_entry_count) |
sahilmgandhi | 18:6a4db94011d3 | 52 | { |
sahilmgandhi | 18:6a4db94011d3 | 53 | return; |
sahilmgandhi | 18:6a4db94011d3 | 54 | } |
sahilmgandhi | 18:6a4db94011d3 | 55 | |
sahilmgandhi | 18:6a4db94011d3 | 56 | // This is the last segment of the critical section, state should be restored as before entering |
sahilmgandhi | 18:6a4db94011d3 | 57 | // the critical section |
sahilmgandhi | 18:6a4db94011d3 | 58 | sd_nvic_critical_region_exit(_sd_state); |
sahilmgandhi | 18:6a4db94011d3 | 59 | } |