Skip to content

Commit c536392

Browse files
committed
TARGET_NRF5 - Add critical section enter/exit overrides for NRF5 targets.
This change takes advantage of the reworked primitives of SDK v11.
1 parent 1aa76b7 commit c536392

File tree

1 file changed

+57
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)