forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 3
/
nrfx_glue.h
152 lines (129 loc) · 4.59 KB
/
nrfx_glue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Glenn Ruben Bakke
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef NRFX_GLUE_H
#define NRFX_GLUE_H
#include "py/mpconfig.h"
#include "py/misc.h"
#include <soc/nrfx_irqs.h>
#ifndef ARRAY_SIZE
#define ARRAY_SIZE MP_ARRAY_SIZE
#endif
#define NRFX_STATIC_ASSERT(expression)
#define NRFX_ASSERT(expression) do { bool res = expression; (void)res; } while (0)
void mp_hal_delay_us(mp_uint_t us);
#define NRFX_DELAY_US mp_hal_delay_us
#if BLUETOOTH_SD
#if NRF51
#include "nrf_soc.h"
#else
#include "nrf_nvic.h"
#endif
#include "ble_drv.h"
#if (BLUETOOTH_SD == 110)
#define NRFX_IRQ_ENABLE(irq_number) \
do { \
if (ble_drv_stack_enabled() == 1) \
{ \
sd_nvic_EnableIRQ(irq_number); \
} else { \
NVIC_EnableIRQ(irq_number); \
} \
} while (0)
#else
#define NRFX_IRQ_ENABLE(irq_number) sd_nvic_EnableIRQ(irq_number)
#endif
#if (BLUETOOTH_SD == 110)
#define NRFX_IRQ_DISABLE(irq_number) \
do { \
if (ble_drv_stack_enabled() == 1) \
{ \
sd_nvic_DisableIRQ(irq_number); \
} else { \
NVIC_DisableIRQ(irq_number); \
} \
} while (0)
#else
#define NRFX_IRQ_DISABLE(irq_number) sd_nvic_DisableIRQ(irq_number)
#endif
#if (BLUETOOTH_SD == 110)
#define NRFX_IRQ_PRIORITY_SET(irq_number, priority) \
do { \
if (ble_drv_stack_enabled() == 1) \
{ \
sd_nvic_SetPriority(irq_number, priority); \
} else { \
NVIC_SetPriority(irq_number, priority); \
} \
} while (0)
#else
#define NRFX_IRQ_PRIORITY_SET(irq_number, priority) sd_nvic_SetPriority(irq_number, priority)
#endif
#if (BLUETOOTH_SD == 110)
#define NRFX_IRQ_PENDING_SET(irq_number) \
do { \
if (ble_drv_stack_enabled() == 1) \
{ \
sd_nvic_SetPendingIRQ(irq_number); \
} else { \
NVIC_SetPendingIRQ(irq_number); \
} \
} while (0)
#else
#define NRFX_IRQ_PENDING_SET(irq_number) sd_nvic_SetPendingIRQ(irq_number)
#endif
#if (BLUETOOTH_SD == 110)
#define NRFX_IRQ_PENDING_CLEAR(irq_number) \
do { \
if (ble_drv_stack_enabled() == 1) \
{ \
sd_nvic_ClearPendingIRQ(irq_number); \
} else { \
NVIC_ClearPendingIRQ(irq_number)(irq_number); \
} \
} while (0)
#else
#define NRFX_IRQ_PENDING_CLEAR(irq_number) sd_nvic_ClearPendingIRQ(irq_number)
#endif
#define NRFX_CRITICAL_SECTION_ENTER() \
{ \
uint8_t _is_nested_critical_region; \
sd_nvic_critical_region_enter(&_is_nested_critical_region);
#define NRFX_CRITICAL_SECTION_EXIT() \
sd_nvic_critical_region_exit(_is_nested_critical_region); \
}
#else // BLUETOOTH_SD
#define NRFX_IRQ_ENABLE(irq_number) NVIC_EnableIRQ(irq_number)
#define NRFX_IRQ_DISABLE(irq_number) NVIC_DisableIRQ(irq_number)
#define NRFX_IRQ_PRIORITY_SET(irq_number, priority) NVIC_SetPriority(irq_number, priority)
#define NRFX_IRQ_PENDING_SET(irq_number) NVIC_SetPendingIRQ(irq_number)
#define NRFX_IRQ_PENDING_CLEAR(irq_number) NVIC_ClearPendingIRQ(irq_number)
// Source:
// https://devzone.nordicsemi.com/f/nordic-q-a/8572/disable-interrupts-and-enable-interrupts-if-they-where-enabled/31347#31347
#define NRFX_CRITICAL_SECTION_ENTER() { int _old_primask = __get_PRIMASK(); __disable_irq();
#define NRFX_CRITICAL_SECTION_EXIT() __set_PRIMASK(_old_primask); }
#endif // !BLUETOOTH_SD
#define NRFX_IRQ_IS_ENABLED(irq_number) (0 != (NVIC->ISER[irq_number / 32] & (1UL << (irq_number % 32))))
#endif // NRFX_GLUE_H