Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Nucleo_F103RB_RTC_battery_bkup_pwr_off_okay
Fork of mbed-dev by
targets/TARGET_NORDIC/TARGET_NRF5/nordic_critical.c@177:619788de047e, 2017-11-07 (annotated)
- Committer:
- maxxir
- Date:
- Tue Nov 07 16:46:29 2017 +0000
- Revision:
- 177:619788de047e
- Parent:
- 149:156823d33999
To fix broken RTC on Nucleo_F103RB / STM32F103 BluePill etc..; Used direct RTC register manipulation for STM32F1xx; rtc_read() && rtc_write() (native rtc_init() - works good); also added stub for non-working on STM32F1xx rtc_read_subseconds().
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /* |
<> | 149:156823d33999 | 2 | * Copyright (c) 2015-2016, ARM Limited, All Rights Reserved |
<> | 149:156823d33999 | 3 | * SPDX-License-Identifier: Apache-2.0 |
<> | 149:156823d33999 | 4 | * |
<> | 149:156823d33999 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
<> | 149:156823d33999 | 6 | * not use this file except in compliance with the License. |
<> | 149:156823d33999 | 7 | * You may obtain a copy of the License at |
<> | 149:156823d33999 | 8 | * |
<> | 149:156823d33999 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 149:156823d33999 | 10 | * |
<> | 149:156823d33999 | 11 | * Unless required by applicable law or agreed to in writing, software |
<> | 149:156823d33999 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
<> | 149:156823d33999 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 149:156823d33999 | 14 | * See the License for the specific language governing permissions and |
<> | 149:156823d33999 | 15 | * limitations under the License. |
<> | 149:156823d33999 | 16 | */ |
<> | 149:156823d33999 | 17 | |
<> | 149:156823d33999 | 18 | #include <stdint.h> // uint32_t, UINT32_MAX |
<> | 149:156823d33999 | 19 | #include <assert.h> // uint32_t, UINT32_MAX |
<> | 149:156823d33999 | 20 | #include "cmsis.h" |
<> | 149:156823d33999 | 21 | #include "nrf_soc.h" |
<> | 149:156823d33999 | 22 | #include "nrf_sdm.h" |
<> | 149:156823d33999 | 23 | #include "nrf_nvic.h" |
<> | 149:156823d33999 | 24 | |
<> | 149:156823d33999 | 25 | static uint8_t _sd_state = 0; |
<> | 149:156823d33999 | 26 | static volatile uint32_t _entry_count = 0; |
<> | 149:156823d33999 | 27 | |
<> | 149:156823d33999 | 28 | void core_util_critical_section_enter() |
<> | 149:156823d33999 | 29 | { |
<> | 149:156823d33999 | 30 | // if a critical section has already been entered, just update the counter |
<> | 149:156823d33999 | 31 | if (_entry_count) { |
<> | 149:156823d33999 | 32 | ++_entry_count; |
<> | 149:156823d33999 | 33 | return; |
<> | 149:156823d33999 | 34 | } |
<> | 149:156823d33999 | 35 | |
<> | 149:156823d33999 | 36 | // in this path, a critical section has never been entered |
<> | 149:156823d33999 | 37 | // routine of SD V11 work even if the softdevice is not active |
<> | 149:156823d33999 | 38 | sd_nvic_critical_region_enter(&_sd_state); |
<> | 149:156823d33999 | 39 | |
<> | 149:156823d33999 | 40 | assert(_entry_count == 0); // entry count should always be equal to 0 at this point |
<> | 149:156823d33999 | 41 | ++_entry_count; |
<> | 149:156823d33999 | 42 | } |
<> | 149:156823d33999 | 43 | |
<> | 149:156823d33999 | 44 | void core_util_critical_section_exit() |
<> | 149:156823d33999 | 45 | { |
<> | 149:156823d33999 | 46 | assert(_entry_count > 0); |
<> | 149:156823d33999 | 47 | --_entry_count; |
<> | 149:156823d33999 | 48 | |
<> | 149:156823d33999 | 49 | // If their is other segments which have entered the critical section, just leave |
<> | 149:156823d33999 | 50 | if (_entry_count) { |
<> | 149:156823d33999 | 51 | return; |
<> | 149:156823d33999 | 52 | } |
<> | 149:156823d33999 | 53 | |
<> | 149:156823d33999 | 54 | // This is the last segment of the critical section, state should be restored as before entering |
<> | 149:156823d33999 | 55 | // the critical section |
<> | 149:156823d33999 | 56 | sd_nvic_critical_region_exit(_sd_state); |
<> | 149:156823d33999 | 57 | } |