nrf_soc.h 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /*
  2. * Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form, except as embedded into a Nordic
  12. * Semiconductor ASA integrated circuit in a product or a software update for
  13. * such product, must reproduce the above copyright notice, this list of
  14. * conditions and the following disclaimer in the documentation and/or other
  15. * materials provided with the distribution.
  16. *
  17. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * 4. This software, with or without modification, must only be used with a
  22. * Nordic Semiconductor ASA integrated circuit.
  23. *
  24. * 5. Any software provided in binary form under this license must not be reverse
  25. * engineered, decompiled, modified and/or disassembled.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  28. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  33. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  36. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. /**
  39. * @defgroup nrf_soc_api SoC Library API
  40. * @{
  41. *
  42. * @brief APIs for the SoC library.
  43. *
  44. */
  45. #ifndef NRF_SOC_H__
  46. #define NRF_SOC_H__
  47. #include <stdint.h>
  48. #include "nrf.h"
  49. #include "nrf_svc.h"
  50. #include "nrf_error.h"
  51. #include "nrf_error_soc.h"
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /**@addtogroup NRF_SOC_DEFINES Defines
  56. * @{ */
  57. /**@brief The number of the lowest SVC number reserved for the SoC library. */
  58. #define SOC_SVC_BASE (0x20) /**< Base value for SVCs that are available when the SoftDevice is disabled. */
  59. #define SOC_SVC_BASE_NOT_AVAILABLE (0x2C) /**< Base value for SVCs that are not available when the SoftDevice is disabled. */
  60. /**@brief Guaranteed time for application to process radio inactive notification. */
  61. #define NRF_RADIO_NOTIFICATION_INACTIVE_GUARANTEED_TIME_US (62)
  62. /**@brief The minimum allowed timeslot extension time. */
  63. #define NRF_RADIO_MINIMUM_TIMESLOT_LENGTH_EXTENSION_TIME_US (200)
  64. /**@brief The maximum processing time to handle a timeslot extension. */
  65. #define NRF_RADIO_MAX_EXTENSION_PROCESSING_TIME_US (20)
  66. /**@brief The latest time before the end of a timeslot the timeslot can be extended. */
  67. #define NRF_RADIO_MIN_EXTENSION_MARGIN_US (82)
  68. #define SOC_ECB_KEY_LENGTH (16) /**< ECB key length. */
  69. #define SOC_ECB_CLEARTEXT_LENGTH (16) /**< ECB cleartext length. */
  70. #define SOC_ECB_CIPHERTEXT_LENGTH (SOC_ECB_CLEARTEXT_LENGTH) /**< ECB ciphertext length. */
  71. #define SD_EVT_IRQn (SWI2_IRQn) /**< SoftDevice Event IRQ number. Used for both protocol events and SoC events. */
  72. #define SD_EVT_IRQHandler (SWI2_IRQHandler) /**< SoftDevice Event IRQ handler. Used for both protocol events and SoC events.
  73. The default interrupt priority for this handler is set to 6 */
  74. #define RADIO_NOTIFICATION_IRQn (SWI1_IRQn) /**< The radio notification IRQ number. */
  75. #define RADIO_NOTIFICATION_IRQHandler (SWI1_IRQHandler) /**< The radio notification IRQ handler.
  76. The default interrupt priority for this handler is set to 6 */
  77. #define NRF_RADIO_LENGTH_MIN_US (100) /**< The shortest allowed radio timeslot, in microseconds. */
  78. #define NRF_RADIO_LENGTH_MAX_US (100000) /**< The longest allowed radio timeslot, in microseconds. */
  79. #define NRF_RADIO_DISTANCE_MAX_US (128000000UL - 1UL) /**< The longest timeslot distance, in microseconds, allowed for the distance parameter (see @ref nrf_radio_request_normal_t) in the request. */
  80. #define NRF_RADIO_EARLIEST_TIMEOUT_MAX_US (128000000UL - 1UL) /**< The longest timeout, in microseconds, allowed when requesting the earliest possible timeslot. */
  81. #define NRF_RADIO_START_JITTER_US (2) /**< The maximum jitter in @ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START relative to the requested start time. */
  82. /**@brief Mask of PPI channels reserved by the SoftDevice when the SoftDevice is disabled. */
  83. #define NRF_SOC_SD_PPI_CHANNELS_SD_DISABLED_MSK ((uint32_t)(0))
  84. /**@brief Mask of PPI channels reserved by the SoftDevice when the SoftDevice is enabled. */
  85. #define NRF_SOC_SD_PPI_CHANNELS_SD_ENABLED_MSK ((uint32_t)( \
  86. (1U << 17) \
  87. | (1U << 18) \
  88. | (1U << 19) \
  89. | (1U << 20) \
  90. | (1U << 21) \
  91. | (1U << 22) \
  92. | (1U << 23) \
  93. | (1U << 24) \
  94. | (1U << 25) \
  95. | (1U << 26) \
  96. | (1U << 27) \
  97. | (1U << 28) \
  98. | (1U << 29) \
  99. | (1U << 30) \
  100. | (1U << 31) \
  101. ))
  102. /**@brief Mask of PPI groups reserved by the SoftDevice when the SoftDevice is disabled. */
  103. #define NRF_SOC_SD_PPI_GROUPS_SD_DISABLED_MSK ((uint32_t)(0))
  104. /**@brief Mask of PPI groups reserved by the SoftDevice when the SoftDevice is enabled. */
  105. #define NRF_SOC_SD_PPI_GROUPS_SD_ENABLED_MSK ((uint32_t)( \
  106. (1U << 4) \
  107. | (1U << 5) \
  108. ))
  109. /**@} */
  110. /**@addtogroup NRF_SOC_ENUMS Enumerations
  111. * @{ */
  112. /**@brief The SVC numbers used by the SVC functions in the SoC library. */
  113. enum NRF_SOC_SVCS
  114. {
  115. SD_PPI_CHANNEL_ENABLE_GET = SOC_SVC_BASE,
  116. SD_PPI_CHANNEL_ENABLE_SET = SOC_SVC_BASE + 1,
  117. SD_PPI_CHANNEL_ENABLE_CLR = SOC_SVC_BASE + 2,
  118. SD_PPI_CHANNEL_ASSIGN = SOC_SVC_BASE + 3,
  119. SD_PPI_GROUP_TASK_ENABLE = SOC_SVC_BASE + 4,
  120. SD_PPI_GROUP_TASK_DISABLE = SOC_SVC_BASE + 5,
  121. SD_PPI_GROUP_ASSIGN = SOC_SVC_BASE + 6,
  122. SD_PPI_GROUP_GET = SOC_SVC_BASE + 7,
  123. SD_FLASH_PAGE_ERASE = SOC_SVC_BASE + 8,
  124. SD_FLASH_WRITE = SOC_SVC_BASE + 9,
  125. SD_FLASH_PROTECT = SOC_SVC_BASE + 10,
  126. SD_PROTECTED_REGISTER_WRITE = SOC_SVC_BASE + 11,
  127. SD_MUTEX_NEW = SOC_SVC_BASE_NOT_AVAILABLE,
  128. SD_MUTEX_ACQUIRE = SOC_SVC_BASE_NOT_AVAILABLE + 1,
  129. SD_MUTEX_RELEASE = SOC_SVC_BASE_NOT_AVAILABLE + 2,
  130. SD_RAND_APPLICATION_POOL_CAPACITY_GET = SOC_SVC_BASE_NOT_AVAILABLE + 3,
  131. SD_RAND_APPLICATION_BYTES_AVAILABLE_GET = SOC_SVC_BASE_NOT_AVAILABLE + 4,
  132. SD_RAND_APPLICATION_VECTOR_GET = SOC_SVC_BASE_NOT_AVAILABLE + 5,
  133. SD_POWER_MODE_SET = SOC_SVC_BASE_NOT_AVAILABLE + 6,
  134. SD_POWER_SYSTEM_OFF = SOC_SVC_BASE_NOT_AVAILABLE + 7,
  135. SD_POWER_RESET_REASON_GET = SOC_SVC_BASE_NOT_AVAILABLE + 8,
  136. SD_POWER_RESET_REASON_CLR = SOC_SVC_BASE_NOT_AVAILABLE + 9,
  137. SD_POWER_POF_ENABLE = SOC_SVC_BASE_NOT_AVAILABLE + 10,
  138. SD_POWER_POF_THRESHOLD_SET = SOC_SVC_BASE_NOT_AVAILABLE + 11,
  139. SD_POWER_RAM_POWER_SET = SOC_SVC_BASE_NOT_AVAILABLE + 13,
  140. SD_POWER_RAM_POWER_CLR = SOC_SVC_BASE_NOT_AVAILABLE + 14,
  141. SD_POWER_RAM_POWER_GET = SOC_SVC_BASE_NOT_AVAILABLE + 15,
  142. SD_POWER_GPREGRET_SET = SOC_SVC_BASE_NOT_AVAILABLE + 16,
  143. SD_POWER_GPREGRET_CLR = SOC_SVC_BASE_NOT_AVAILABLE + 17,
  144. SD_POWER_GPREGRET_GET = SOC_SVC_BASE_NOT_AVAILABLE + 18,
  145. SD_POWER_DCDC_MODE_SET = SOC_SVC_BASE_NOT_AVAILABLE + 19,
  146. SD_APP_EVT_WAIT = SOC_SVC_BASE_NOT_AVAILABLE + 21,
  147. SD_CLOCK_HFCLK_REQUEST = SOC_SVC_BASE_NOT_AVAILABLE + 22,
  148. SD_CLOCK_HFCLK_RELEASE = SOC_SVC_BASE_NOT_AVAILABLE + 23,
  149. SD_CLOCK_HFCLK_IS_RUNNING = SOC_SVC_BASE_NOT_AVAILABLE + 24,
  150. SD_RADIO_NOTIFICATION_CFG_SET = SOC_SVC_BASE_NOT_AVAILABLE + 25,
  151. SD_ECB_BLOCK_ENCRYPT = SOC_SVC_BASE_NOT_AVAILABLE + 26,
  152. SD_ECB_BLOCKS_ENCRYPT = SOC_SVC_BASE_NOT_AVAILABLE + 27,
  153. SD_RADIO_SESSION_OPEN = SOC_SVC_BASE_NOT_AVAILABLE + 28,
  154. SD_RADIO_SESSION_CLOSE = SOC_SVC_BASE_NOT_AVAILABLE + 29,
  155. SD_RADIO_REQUEST = SOC_SVC_BASE_NOT_AVAILABLE + 30,
  156. SD_EVT_GET = SOC_SVC_BASE_NOT_AVAILABLE + 31,
  157. SD_TEMP_GET = SOC_SVC_BASE_NOT_AVAILABLE + 32,
  158. SVC_SOC_LAST = SOC_SVC_BASE_NOT_AVAILABLE + 37
  159. };
  160. /**@brief Possible values of a ::nrf_mutex_t. */
  161. enum NRF_MUTEX_VALUES
  162. {
  163. NRF_MUTEX_FREE,
  164. NRF_MUTEX_TAKEN
  165. };
  166. /**@brief Power modes. */
  167. enum NRF_POWER_MODES
  168. {
  169. NRF_POWER_MODE_CONSTLAT, /**< Constant latency mode. See power management in the reference manual. */
  170. NRF_POWER_MODE_LOWPWR /**< Low power mode. See power management in the reference manual. */
  171. };
  172. /**@brief Power failure thresholds */
  173. enum NRF_POWER_THRESHOLDS
  174. {
  175. NRF_POWER_THRESHOLD_V17 = 4UL, /**< 1.7 Volts power failure threshold. */
  176. NRF_POWER_THRESHOLD_V18, /**< 1.8 Volts power failure threshold. */
  177. NRF_POWER_THRESHOLD_V19, /**< 1.9 Volts power failure threshold. */
  178. NRF_POWER_THRESHOLD_V20, /**< 2.0 Volts power failure threshold. */
  179. NRF_POWER_THRESHOLD_V21, /**< 2.1 Volts power failure threshold. */
  180. NRF_POWER_THRESHOLD_V22, /**< 2.2 Volts power failure threshold. */
  181. NRF_POWER_THRESHOLD_V23, /**< 2.3 Volts power failure threshold. */
  182. NRF_POWER_THRESHOLD_V24, /**< 2.4 Volts power failure threshold. */
  183. NRF_POWER_THRESHOLD_V25, /**< 2.5 Volts power failure threshold. */
  184. NRF_POWER_THRESHOLD_V26, /**< 2.6 Volts power failure threshold. */
  185. NRF_POWER_THRESHOLD_V27, /**< 2.7 Volts power failure threshold. */
  186. NRF_POWER_THRESHOLD_V28 /**< 2.8 Volts power failure threshold. */
  187. };
  188. /**@brief DC/DC converter modes. */
  189. enum NRF_POWER_DCDC_MODES
  190. {
  191. NRF_POWER_DCDC_DISABLE, /**< The DCDC is disabled. */
  192. NRF_POWER_DCDC_ENABLE /**< The DCDC is enabled. */
  193. };
  194. /**@brief Radio notification distances. */
  195. enum NRF_RADIO_NOTIFICATION_DISTANCES
  196. {
  197. NRF_RADIO_NOTIFICATION_DISTANCE_NONE = 0, /**< The event does not have a notification. */
  198. NRF_RADIO_NOTIFICATION_DISTANCE_800US, /**< The distance from the active notification to start of radio activity. */
  199. NRF_RADIO_NOTIFICATION_DISTANCE_1740US, /**< The distance from the active notification to start of radio activity. */
  200. NRF_RADIO_NOTIFICATION_DISTANCE_2680US, /**< The distance from the active notification to start of radio activity. */
  201. NRF_RADIO_NOTIFICATION_DISTANCE_3620US, /**< The distance from the active notification to start of radio activity. */
  202. NRF_RADIO_NOTIFICATION_DISTANCE_4560US, /**< The distance from the active notification to start of radio activity. */
  203. NRF_RADIO_NOTIFICATION_DISTANCE_5500US /**< The distance from the active notification to start of radio activity. */
  204. };
  205. /**@brief Radio notification types. */
  206. enum NRF_RADIO_NOTIFICATION_TYPES
  207. {
  208. NRF_RADIO_NOTIFICATION_TYPE_NONE = 0, /**< The event does not have a radio notification signal. */
  209. NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE, /**< Using interrupt for notification when the radio will be enabled. */
  210. NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE, /**< Using interrupt for notification when the radio has been disabled. */
  211. NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, /**< Using interrupt for notification both when the radio will be enabled and disabled. */
  212. };
  213. /**@brief The Radio signal callback types. */
  214. enum NRF_RADIO_CALLBACK_SIGNAL_TYPE
  215. {
  216. NRF_RADIO_CALLBACK_SIGNAL_TYPE_START, /**< This signal indicates the start of the radio timeslot. */
  217. NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0, /**< This signal indicates the NRF_TIMER0 interrupt. */
  218. NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO, /**< This signal indicates the NRF_RADIO interrupt. */
  219. NRF_RADIO_CALLBACK_SIGNAL_TYPE_EXTEND_FAILED, /**< This signal indicates extend action failed. */
  220. NRF_RADIO_CALLBACK_SIGNAL_TYPE_EXTEND_SUCCEEDED /**< This signal indicates extend action succeeded. */
  221. };
  222. /**@brief The actions requested by the signal callback.
  223. *
  224. * This code gives the SOC instructions about what action to take when the signal callback has
  225. * returned.
  226. */
  227. enum NRF_RADIO_SIGNAL_CALLBACK_ACTION
  228. {
  229. NRF_RADIO_SIGNAL_CALLBACK_ACTION_NONE, /**< Return without action. */
  230. NRF_RADIO_SIGNAL_CALLBACK_ACTION_EXTEND, /**< Request an extension of the current
  231. timeslot. Maximum execution time for this action:
  232. @ref NRF_RADIO_MAX_EXTENSION_PROCESSING_TIME_US.
  233. This action must be started at least
  234. @ref NRF_RADIO_MIN_EXTENSION_MARGIN_US before
  235. the end of the timeslot. */
  236. NRF_RADIO_SIGNAL_CALLBACK_ACTION_END, /**< End the current radio timeslot. */
  237. NRF_RADIO_SIGNAL_CALLBACK_ACTION_REQUEST_AND_END /**< Request a new radio timeslot and end the current timeslot. */
  238. };
  239. /**@brief Radio timeslot high frequency clock source configuration. */
  240. enum NRF_RADIO_HFCLK_CFG
  241. {
  242. NRF_RADIO_HFCLK_CFG_XTAL_GUARANTEED, /**< The SoftDevice will guarantee that the high frequency clock source is the
  243. external crystal for the whole duration of the timeslot. This should be the
  244. preferred option for events that use the radio or require high timing accuracy.
  245. @note The SoftDevice will automatically turn on and off the external crystal,
  246. at the beginning and end of the timeslot, respectively. The crystal may also
  247. intentionally be left running after the timeslot, in cases where it is needed
  248. by the SoftDevice shortly after the end of the timeslot. */
  249. NRF_RADIO_HFCLK_CFG_NO_GUARANTEE /**< This configuration allows for earlier and tighter scheduling of timeslots.
  250. The RC oscillator may be the clock source in part or for the whole duration of the timeslot.
  251. The RC oscillator's accuracy must therefore be taken into consideration.
  252. @note If the application will use the radio peripheral in timeslots with this configuration,
  253. it must make sure that the crystal is running and stable before starting the radio. */
  254. };
  255. /**@brief Radio timeslot priorities. */
  256. enum NRF_RADIO_PRIORITY
  257. {
  258. NRF_RADIO_PRIORITY_HIGH, /**< High (equal priority as the normal connection priority of the SoftDevice stack(s)). */
  259. NRF_RADIO_PRIORITY_NORMAL, /**< Normal (equal priority as the priority of secondary activities of the SoftDevice stack(s)). */
  260. };
  261. /**@brief Radio timeslot request type. */
  262. enum NRF_RADIO_REQUEST_TYPE
  263. {
  264. NRF_RADIO_REQ_TYPE_EARLIEST, /**< Request radio timeslot as early as possible. This should always be used for the first request in a session. */
  265. NRF_RADIO_REQ_TYPE_NORMAL /**< Normal radio timeslot request. */
  266. };
  267. /**@brief SoC Events. */
  268. enum NRF_SOC_EVTS
  269. {
  270. NRF_EVT_HFCLKSTARTED, /**< Event indicating that the HFCLK has started. */
  271. NRF_EVT_POWER_FAILURE_WARNING, /**< Event indicating that a power failure warning has occurred. */
  272. NRF_EVT_FLASH_OPERATION_SUCCESS, /**< Event indicating that the ongoing flash operation has completed successfully. */
  273. NRF_EVT_FLASH_OPERATION_ERROR, /**< Event indicating that the ongoing flash operation has timed out with an error. */
  274. NRF_EVT_RADIO_BLOCKED, /**< Event indicating that a radio timeslot was blocked. */
  275. NRF_EVT_RADIO_CANCELED, /**< Event indicating that a radio timeslot was canceled by SoftDevice. */
  276. NRF_EVT_RADIO_SIGNAL_CALLBACK_INVALID_RETURN, /**< Event indicating that a radio timeslot signal callback handler return was invalid. */
  277. NRF_EVT_RADIO_SESSION_IDLE, /**< Event indicating that a radio timeslot session is idle. */
  278. NRF_EVT_RADIO_SESSION_CLOSED, /**< Event indicating that a radio timeslot session is closed. */
  279. NRF_EVT_NUMBER_OF_EVTS
  280. };
  281. /**@} */
  282. /**@addtogroup NRF_SOC_STRUCTURES Structures
  283. * @{ */
  284. /**@brief Represents a mutex for use with the nrf_mutex functions.
  285. * @note Accessing the value directly is not safe, use the mutex functions!
  286. */
  287. typedef volatile uint8_t nrf_mutex_t;
  288. /**@brief Parameters for a request for a timeslot as early as possible. */
  289. typedef struct
  290. {
  291. uint8_t hfclk; /**< High frequency clock source, see @ref NRF_RADIO_HFCLK_CFG. */
  292. uint8_t priority; /**< The radio timeslot priority, see @ref NRF_RADIO_PRIORITY. */
  293. uint32_t length_us; /**< The radio timeslot length (in the range 100 to 100,000] microseconds). */
  294. uint32_t timeout_us; /**< Longest acceptable delay until the start of the requested timeslot (up to @ref NRF_RADIO_EARLIEST_TIMEOUT_MAX_US microseconds). */
  295. } nrf_radio_request_earliest_t;
  296. /**@brief Parameters for a normal radio timeslot request. */
  297. typedef struct
  298. {
  299. uint8_t hfclk; /**< High frequency clock source, see @ref NRF_RADIO_HFCLK_CFG. */
  300. uint8_t priority; /**< The radio timeslot priority, see @ref NRF_RADIO_PRIORITY. */
  301. uint32_t distance_us; /**< Distance from the start of the previous radio timeslot (up to @ref NRF_RADIO_DISTANCE_MAX_US microseconds). */
  302. uint32_t length_us; /**< The radio timeslot length (in the range [100..100,000] microseconds). */
  303. } nrf_radio_request_normal_t;
  304. /**@brief Radio timeslot request parameters. */
  305. typedef struct
  306. {
  307. uint8_t request_type; /**< Type of request, see @ref NRF_RADIO_REQUEST_TYPE. */
  308. union
  309. {
  310. nrf_radio_request_earliest_t earliest; /**< Parameters for requesting a radio timeslot as early as possible. */
  311. nrf_radio_request_normal_t normal; /**< Parameters for requesting a normal radio timeslot. */
  312. } params; /**< Parameter union. */
  313. } nrf_radio_request_t;
  314. /**@brief Return parameters of the radio timeslot signal callback. */
  315. typedef struct
  316. {
  317. uint8_t callback_action; /**< The action requested by the application when returning from the signal callback, see @ref NRF_RADIO_SIGNAL_CALLBACK_ACTION. */
  318. union
  319. {
  320. struct
  321. {
  322. nrf_radio_request_t * p_next; /**< The request parameters for the next radio timeslot. */
  323. } request; /**< Additional parameters for return_code @ref NRF_RADIO_SIGNAL_CALLBACK_ACTION_REQUEST_AND_END. */
  324. struct
  325. {
  326. uint32_t length_us; /**< Requested extension of the radio timeslot duration (microseconds) (for minimum time see @ref NRF_RADIO_MINIMUM_TIMESLOT_LENGTH_EXTENSION_TIME_US). */
  327. } extend; /**< Additional parameters for return_code @ref NRF_RADIO_SIGNAL_CALLBACK_ACTION_EXTEND. */
  328. } params; /**< Parameter union. */
  329. } nrf_radio_signal_callback_return_param_t;
  330. /**@brief The radio timeslot signal callback type.
  331. *
  332. * @note In case of invalid return parameters, the radio timeslot will automatically end
  333. * immediately after returning from the signal callback and the
  334. * @ref NRF_EVT_RADIO_SIGNAL_CALLBACK_INVALID_RETURN event will be sent.
  335. * @note The returned struct pointer must remain valid after the signal callback
  336. * function returns. For instance, this means that it must not point to a stack variable.
  337. *
  338. * @param[in] signal_type Type of signal, see @ref NRF_RADIO_CALLBACK_SIGNAL_TYPE.
  339. *
  340. * @return Pointer to structure containing action requested by the application.
  341. */
  342. typedef nrf_radio_signal_callback_return_param_t * (*nrf_radio_signal_callback_t) (uint8_t signal_type);
  343. /**@brief AES ECB parameter typedefs */
  344. typedef uint8_t soc_ecb_key_t[SOC_ECB_KEY_LENGTH]; /**< Encryption key type. */
  345. typedef uint8_t soc_ecb_cleartext_t[SOC_ECB_CLEARTEXT_LENGTH]; /**< Cleartext data type. */
  346. typedef uint8_t soc_ecb_ciphertext_t[SOC_ECB_CIPHERTEXT_LENGTH]; /**< Ciphertext data type. */
  347. /**@brief AES ECB data structure */
  348. typedef struct
  349. {
  350. soc_ecb_key_t key; /**< Encryption key. */
  351. soc_ecb_cleartext_t cleartext; /**< Cleartext data. */
  352. soc_ecb_ciphertext_t ciphertext; /**< Ciphertext data. */
  353. } nrf_ecb_hal_data_t;
  354. /**@brief AES ECB block. Used to provide multiple blocks in a single call
  355. to @ref sd_ecb_blocks_encrypt.*/
  356. typedef struct
  357. {
  358. soc_ecb_key_t const * p_key; /**< Pointer to the Encryption key. */
  359. soc_ecb_cleartext_t const * p_cleartext; /**< Pointer to the Cleartext data. */
  360. soc_ecb_ciphertext_t * p_ciphertext; /**< Pointer to the Ciphertext data. */
  361. } nrf_ecb_hal_data_block_t;
  362. /**@} */
  363. /**@addtogroup NRF_SOC_FUNCTIONS Functions
  364. * @{ */
  365. /**@brief Initialize a mutex.
  366. *
  367. * @param[in] p_mutex Pointer to the mutex to initialize.
  368. *
  369. * @retval ::NRF_SUCCESS
  370. */
  371. SVCALL(SD_MUTEX_NEW, uint32_t, sd_mutex_new(nrf_mutex_t * p_mutex));
  372. /**@brief Attempt to acquire a mutex.
  373. *
  374. * @param[in] p_mutex Pointer to the mutex to acquire.
  375. *
  376. * @retval ::NRF_SUCCESS The mutex was successfully acquired.
  377. * @retval ::NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN The mutex could not be acquired.
  378. */
  379. SVCALL(SD_MUTEX_ACQUIRE, uint32_t, sd_mutex_acquire(nrf_mutex_t * p_mutex));
  380. /**@brief Release a mutex.
  381. *
  382. * @param[in] p_mutex Pointer to the mutex to release.
  383. *
  384. * @retval ::NRF_SUCCESS
  385. */
  386. SVCALL(SD_MUTEX_RELEASE, uint32_t, sd_mutex_release(nrf_mutex_t * p_mutex));
  387. /**@brief Query the capacity of the application random pool.
  388. *
  389. * @param[out] p_pool_capacity The capacity of the pool.
  390. *
  391. * @retval ::NRF_SUCCESS
  392. */
  393. SVCALL(SD_RAND_APPLICATION_POOL_CAPACITY_GET, uint32_t, sd_rand_application_pool_capacity_get(uint8_t * p_pool_capacity));
  394. /**@brief Get number of random bytes available to the application.
  395. *
  396. * @param[out] p_bytes_available The number of bytes currently available in the pool.
  397. *
  398. * @retval ::NRF_SUCCESS
  399. */
  400. SVCALL(SD_RAND_APPLICATION_BYTES_AVAILABLE_GET, uint32_t, sd_rand_application_bytes_available_get(uint8_t * p_bytes_available));
  401. /**@brief Get random bytes from the application pool.
  402. *
  403. * @param[out] p_buff Pointer to unit8_t buffer for storing the bytes.
  404. * @param[in] length Number of bytes to take from pool and place in p_buff.
  405. *
  406. * @retval ::NRF_SUCCESS The requested bytes were written to p_buff.
  407. * @retval ::NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES No bytes were written to the buffer, because there were not enough bytes available.
  408. */
  409. SVCALL(SD_RAND_APPLICATION_VECTOR_GET, uint32_t, sd_rand_application_vector_get(uint8_t * p_buff, uint8_t length));
  410. /**@brief Gets the reset reason register.
  411. *
  412. * @param[out] p_reset_reason Contents of the NRF_POWER->RESETREAS register.
  413. *
  414. * @retval ::NRF_SUCCESS
  415. */
  416. SVCALL(SD_POWER_RESET_REASON_GET, uint32_t, sd_power_reset_reason_get(uint32_t * p_reset_reason));
  417. /**@brief Clears the bits of the reset reason register.
  418. *
  419. * @param[in] reset_reason_clr_msk Contains the bits to clear from the reset reason register.
  420. *
  421. * @retval ::NRF_SUCCESS
  422. */
  423. SVCALL(SD_POWER_RESET_REASON_CLR, uint32_t, sd_power_reset_reason_clr(uint32_t reset_reason_clr_msk));
  424. /**@brief Sets the power mode when in CPU sleep.
  425. *
  426. * @param[in] power_mode The power mode to use when in CPU sleep, see @ref NRF_POWER_MODES. @sa sd_app_evt_wait
  427. *
  428. * @retval ::NRF_SUCCESS The power mode was set.
  429. * @retval ::NRF_ERROR_SOC_POWER_MODE_UNKNOWN The power mode was unknown.
  430. */
  431. SVCALL(SD_POWER_MODE_SET, uint32_t, sd_power_mode_set(uint8_t power_mode));
  432. /**@brief Puts the chip in System OFF mode.
  433. *
  434. * @retval ::NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN
  435. */
  436. SVCALL(SD_POWER_SYSTEM_OFF, uint32_t, sd_power_system_off(void));
  437. /**@brief Enables or disables the power-fail comparator.
  438. *
  439. * Enabling this will give a SoftDevice event (NRF_EVT_POWER_FAILURE_WARNING) when the power failure warning occurs.
  440. * The event can be retrieved with sd_evt_get();
  441. *
  442. * @param[in] pof_enable True if the power-fail comparator should be enabled, false if it should be disabled.
  443. *
  444. * @retval ::NRF_SUCCESS
  445. */
  446. SVCALL(SD_POWER_POF_ENABLE, uint32_t, sd_power_pof_enable(uint8_t pof_enable));
  447. /**@brief Sets the power failure comparator threshold value.
  448. *
  449. *
  450. * @param[in] threshold The power-fail threshold value to use, see @ref NRF_POWER_THRESHOLDS.
  451. *
  452. * @retval ::NRF_SUCCESS The power failure threshold was set.
  453. * @retval ::NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN The power failure threshold is unknown.
  454. */
  455. SVCALL(SD_POWER_POF_THRESHOLD_SET, uint32_t, sd_power_pof_threshold_set(uint8_t threshold));
  456. /**@brief Writes the NRF_POWER->RAM[index].POWERSET register.
  457. *
  458. * @param[in] index Contains the index in the NRF_POWER->RAM[index].POWERSET register to write to.
  459. * @param[in] ram_powerset Contains the word to write to the NRF_POWER->RAM[index].POWERSET register.
  460. *
  461. * @retval ::NRF_SUCCESS
  462. */
  463. SVCALL(SD_POWER_RAM_POWER_SET, uint32_t, sd_power_ram_power_set(uint8_t index, uint32_t ram_powerset));
  464. /**@brief Writes the NRF_POWER->RAM[index].POWERCLR register.
  465. *
  466. * @param[in] index Contains the index in the NRF_POWER->RAM[index].POWERCLR register to write to.
  467. * @param[in] ram_powerclr Contains the word to write to the NRF_POWER->RAM[index].POWERCLR register.
  468. *
  469. * @retval ::NRF_SUCCESS
  470. */
  471. SVCALL(SD_POWER_RAM_POWER_CLR, uint32_t, sd_power_ram_power_clr(uint8_t index, uint32_t ram_powerclr));
  472. /**@brief Get contents of NRF_POWER->RAM[index].POWER register, indicates power status of RAM[index] blocks.
  473. *
  474. * @param[in] index Contains the index in the NRF_POWER->RAM[index].POWER register to read from.
  475. * @param[out] p_ram_power Content of NRF_POWER->RAM[index].POWER register.
  476. *
  477. * @retval ::NRF_SUCCESS
  478. */
  479. SVCALL(SD_POWER_RAM_POWER_GET, uint32_t, sd_power_ram_power_get(uint8_t index, uint32_t * p_ram_power));
  480. /**@brief Set bits in the general purpose retention registers (NRF_POWER->GPREGRET*).
  481. *
  482. * @param[in] gpregret_id 0 for GPREGRET, 1 for GPREGRET2.
  483. * @param[in] gpregret_msk Bits to be set in the GPREGRET register.
  484. *
  485. * @retval ::NRF_SUCCESS
  486. */
  487. SVCALL(SD_POWER_GPREGRET_SET, uint32_t, sd_power_gpregret_set(uint32_t gpregret_id, uint32_t gpregret_msk));
  488. /**@brief Clear bits in the general purpose retention registers (NRF_POWER->GPREGRET*).
  489. *
  490. * @param[in] gpregret_id 0 for GPREGRET, 1 for GPREGRET2.
  491. * @param[in] gpregret_msk Bits to be clear in the GPREGRET register.
  492. *
  493. * @retval ::NRF_SUCCESS
  494. */
  495. SVCALL(SD_POWER_GPREGRET_CLR, uint32_t, sd_power_gpregret_clr(uint32_t gpregret_id, uint32_t gpregret_msk));
  496. /**@brief Get contents of the general purpose retention registers (NRF_POWER->GPREGRET*).
  497. *
  498. * @param[in] gpregret_id 0 for GPREGRET, 1 for GPREGRET2.
  499. * @param[out] p_gpregret Contents of the GPREGRET register.
  500. *
  501. * @retval ::NRF_SUCCESS
  502. */
  503. SVCALL(SD_POWER_GPREGRET_GET, uint32_t, sd_power_gpregret_get(uint32_t gpregret_id, uint32_t *p_gpregret));
  504. /**@brief Enable or disable the DC/DC regulator.
  505. *
  506. * @param[in] dcdc_mode The mode of the DCDC, see @ref NRF_POWER_DCDC_MODES.
  507. *
  508. * @retval ::NRF_SUCCESS
  509. * @retval ::NRF_ERROR_INVALID_PARAM The DCDC mode is invalid.
  510. */
  511. SVCALL(SD_POWER_DCDC_MODE_SET, uint32_t, sd_power_dcdc_mode_set(uint8_t dcdc_mode));
  512. /**@brief Request the high frequency crystal oscillator.
  513. *
  514. * Will start the high frequency crystal oscillator, the startup time of the crystal varies
  515. * and the ::sd_clock_hfclk_is_running function can be polled to check if it has started.
  516. *
  517. * @see sd_clock_hfclk_is_running
  518. * @see sd_clock_hfclk_release
  519. *
  520. * @retval ::NRF_SUCCESS
  521. */
  522. SVCALL(SD_CLOCK_HFCLK_REQUEST, uint32_t, sd_clock_hfclk_request(void));
  523. /**@brief Releases the high frequency crystal oscillator.
  524. *
  525. * Will stop the high frequency crystal oscillator, this happens immediately.
  526. *
  527. * @see sd_clock_hfclk_is_running
  528. * @see sd_clock_hfclk_request
  529. *
  530. * @retval ::NRF_SUCCESS
  531. */
  532. SVCALL(SD_CLOCK_HFCLK_RELEASE, uint32_t, sd_clock_hfclk_release(void));
  533. /**@brief Checks if the high frequency crystal oscillator is running.
  534. *
  535. * @see sd_clock_hfclk_request
  536. * @see sd_clock_hfclk_release
  537. *
  538. * @param[out] p_is_running 1 if the external crystal oscillator is running, 0 if not.
  539. *
  540. * @retval ::NRF_SUCCESS
  541. */
  542. SVCALL(SD_CLOCK_HFCLK_IS_RUNNING, uint32_t, sd_clock_hfclk_is_running(uint32_t * p_is_running));
  543. /**@brief Waits for an application event.
  544. *
  545. * An application event is either an application interrupt or a pended interrupt when the interrupt
  546. * is disabled.
  547. *
  548. * When the application waits for an application event by calling this function, an interrupt that
  549. * is enabled will be taken immediately on pending since this function will wait in thread mode,
  550. * then the execution will return in the application's main thread.
  551. *
  552. * In order to wake up from disabled interrupts, the SEVONPEND flag has to be set in the Cortex-M
  553. * MCU's System Control Register (SCR), CMSIS_SCB. In that case, when a disabled interrupt gets
  554. * pended, this function will return to the application's main thread.
  555. *
  556. * @note The application must ensure that the pended flag is cleared using ::sd_nvic_ClearPendingIRQ
  557. * in order to sleep using this function. This is only necessary for disabled interrupts, as
  558. * the interrupt handler will clear the pending flag automatically for enabled interrupts.
  559. *
  560. * @note If an application interrupt has happened since the last time sd_app_evt_wait was
  561. * called this function will return immediately and not go to sleep. This is to avoid race
  562. * conditions that can occur when a flag is updated in the interrupt handler and processed
  563. * in the main loop.
  564. *
  565. * @post An application interrupt has happened or a interrupt pending flag is set.
  566. *
  567. * @retval ::NRF_SUCCESS
  568. */
  569. SVCALL(SD_APP_EVT_WAIT, uint32_t, sd_app_evt_wait(void));
  570. /**@brief Get PPI channel enable register contents.
  571. *
  572. * @param[out] p_channel_enable The contents of the PPI CHEN register.
  573. *
  574. * @retval ::NRF_SUCCESS
  575. */
  576. SVCALL(SD_PPI_CHANNEL_ENABLE_GET, uint32_t, sd_ppi_channel_enable_get(uint32_t * p_channel_enable));
  577. /**@brief Set PPI channel enable register.
  578. *
  579. * @param[in] channel_enable_set_msk Mask containing the bits to set in the PPI CHEN register.
  580. *
  581. * @retval ::NRF_SUCCESS
  582. */
  583. SVCALL(SD_PPI_CHANNEL_ENABLE_SET, uint32_t, sd_ppi_channel_enable_set(uint32_t channel_enable_set_msk));
  584. /**@brief Clear PPI channel enable register.
  585. *
  586. * @param[in] channel_enable_clr_msk Mask containing the bits to clear in the PPI CHEN register.
  587. *
  588. * @retval ::NRF_SUCCESS
  589. */
  590. SVCALL(SD_PPI_CHANNEL_ENABLE_CLR, uint32_t, sd_ppi_channel_enable_clr(uint32_t channel_enable_clr_msk));
  591. /**@brief Assign endpoints to a PPI channel.
  592. *
  593. * @param[in] channel_num Number of the PPI channel to assign.
  594. * @param[in] evt_endpoint Event endpoint of the PPI channel.
  595. * @param[in] task_endpoint Task endpoint of the PPI channel.
  596. *
  597. * @retval ::NRF_ERROR_SOC_PPI_INVALID_CHANNEL The channel number is invalid.
  598. * @retval ::NRF_SUCCESS
  599. */
  600. SVCALL(SD_PPI_CHANNEL_ASSIGN, uint32_t, sd_ppi_channel_assign(uint8_t channel_num, const volatile void * evt_endpoint, const volatile void * task_endpoint));
  601. /**@brief Task to enable a channel group.
  602. *
  603. * @param[in] group_num Number of the channel group.
  604. *
  605. * @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid
  606. * @retval ::NRF_SUCCESS
  607. */
  608. SVCALL(SD_PPI_GROUP_TASK_ENABLE, uint32_t, sd_ppi_group_task_enable(uint8_t group_num));
  609. /**@brief Task to disable a channel group.
  610. *
  611. * @param[in] group_num Number of the PPI group.
  612. *
  613. * @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid.
  614. * @retval ::NRF_SUCCESS
  615. */
  616. SVCALL(SD_PPI_GROUP_TASK_DISABLE, uint32_t, sd_ppi_group_task_disable(uint8_t group_num));
  617. /**@brief Assign PPI channels to a channel group.
  618. *
  619. * @param[in] group_num Number of the channel group.
  620. * @param[in] channel_msk Mask of the channels to assign to the group.
  621. *
  622. * @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid.
  623. * @retval ::NRF_SUCCESS
  624. */
  625. SVCALL(SD_PPI_GROUP_ASSIGN, uint32_t, sd_ppi_group_assign(uint8_t group_num, uint32_t channel_msk));
  626. /**@brief Gets the PPI channels of a channel group.
  627. *
  628. * @param[in] group_num Number of the channel group.
  629. * @param[out] p_channel_msk Mask of the channels assigned to the group.
  630. *
  631. * @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid.
  632. * @retval ::NRF_SUCCESS
  633. */
  634. SVCALL(SD_PPI_GROUP_GET, uint32_t, sd_ppi_group_get(uint8_t group_num, uint32_t * p_channel_msk));
  635. /**@brief Configures the Radio Notification signal.
  636. *
  637. * @note
  638. * - The notification signal latency depends on the interrupt priority settings of SWI used
  639. * for notification signal.
  640. * - To ensure that the radio notification signal behaves in a consistent way, the radio
  641. * notifications must be configured when there is no protocol stack or other SoftDevice
  642. * activity in progress. It is recommended that the radio notification signal is
  643. * configured directly after the SoftDevice has been enabled.
  644. * - In the period between the ACTIVE signal and the start of the Radio Event, the SoftDevice
  645. * will interrupt the application to do Radio Event preparation.
  646. * - Using the Radio Notification feature may limit the bandwidth, as the SoftDevice may have
  647. * to shorten the connection events to have time for the Radio Notification signals.
  648. *
  649. * @param[in] type Type of notification signal, see @ref NRF_RADIO_NOTIFICATION_TYPES.
  650. * @ref NRF_RADIO_NOTIFICATION_TYPE_NONE shall be used to turn off radio
  651. * notification. Using @ref NRF_RADIO_NOTIFICATION_DISTANCE_NONE is
  652. * recommended (but not required) to be used with
  653. * @ref NRF_RADIO_NOTIFICATION_TYPE_NONE.
  654. *
  655. * @param[in] distance Distance between the notification signal and start of radio activity, see @ref NRF_RADIO_NOTIFICATION_DISTANCES.
  656. * This parameter is ignored when @ref NRF_RADIO_NOTIFICATION_TYPE_NONE or
  657. * @ref NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE is used.
  658. *
  659. * @retval ::NRF_ERROR_INVALID_PARAM The group number is invalid.
  660. * @retval ::NRF_ERROR_INVALID_STATE A protocol stack or other SoftDevice is running. Stop all
  661. * running activities and retry.
  662. * @retval ::NRF_SUCCESS
  663. */
  664. SVCALL(SD_RADIO_NOTIFICATION_CFG_SET, uint32_t, sd_radio_notification_cfg_set(uint8_t type, uint8_t distance));
  665. /**@brief Encrypts a block according to the specified parameters.
  666. *
  667. * 128-bit AES encryption.
  668. *
  669. * @note:
  670. * - The application may set the SEVONPEND bit in the SCR to 1 to make the SoftDevice sleep while
  671. * the ECB is running. The SEVONPEND bit should only be cleared (set to 0) from application
  672. * main or low interrupt level.
  673. *
  674. * @param[in, out] p_ecb_data Pointer to the ECB parameters' struct (two input
  675. * parameters and one output parameter).
  676. *
  677. * @retval ::NRF_SUCCESS
  678. */
  679. SVCALL(SD_ECB_BLOCK_ENCRYPT, uint32_t, sd_ecb_block_encrypt(nrf_ecb_hal_data_t * p_ecb_data));
  680. /**@brief Encrypts multiple data blocks provided as an array of data block structures.
  681. *
  682. * @details: Performs 128-bit AES encryption on multiple data blocks
  683. *
  684. * @note:
  685. * - The application may set the SEVONPEND bit in the SCR to 1 to make the SoftDevice sleep while
  686. * the ECB is running. The SEVONPEND bit should only be cleared (set to 0) from application
  687. * main or low interrupt level.
  688. *
  689. * @param[in] block_count Count of blocks in the p_data_blocks array.
  690. * @param[in,out] p_data_blocks Pointer to the first entry in a contiguous array of
  691. * @ref nrf_ecb_hal_data_block_t structures.
  692. *
  693. * @retval ::NRF_SUCCESS
  694. */
  695. SVCALL(SD_ECB_BLOCKS_ENCRYPT, uint32_t, sd_ecb_blocks_encrypt(uint8_t block_count, nrf_ecb_hal_data_block_t * p_data_blocks));
  696. /**@brief Gets any pending events generated by the SoC API.
  697. *
  698. * The application should keep calling this function to get events, until ::NRF_ERROR_NOT_FOUND is returned.
  699. *
  700. * @param[out] p_evt_id Set to one of the values in @ref NRF_SOC_EVTS, if any events are pending.
  701. *
  702. * @retval ::NRF_SUCCESS An event was pending. The event id is written in the p_evt_id parameter.
  703. * @retval ::NRF_ERROR_NOT_FOUND No pending events.
  704. */
  705. SVCALL(SD_EVT_GET, uint32_t, sd_evt_get(uint32_t * p_evt_id));
  706. /**@brief Get the temperature measured on the chip
  707. *
  708. * This function will block until the temperature measurement is done.
  709. * It takes around 50 us from call to return.
  710. *
  711. * @param[out] p_temp Result of temperature measurement. Die temperature in 0.25 degrees Celsius.
  712. *
  713. * @retval ::NRF_SUCCESS A temperature measurement was done, and the temperature was written to temp
  714. */
  715. SVCALL(SD_TEMP_GET, uint32_t, sd_temp_get(int32_t * p_temp));
  716. /**@brief Flash Write
  717. *
  718. * Commands to write a buffer to flash
  719. *
  720. * If the SoftDevice is enabled:
  721. * This call initiates the flash access command, and its completion will be communicated to the
  722. * application with exactly one of the following events:
  723. * - @ref NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
  724. * - @ref NRF_EVT_FLASH_OPERATION_ERROR - The command could not be started.
  725. *
  726. * If the SoftDevice is not enabled no event will be generated, and this call will return @ref NRF_SUCCESS when the
  727. * write has been completed
  728. *
  729. * @note
  730. * - This call takes control over the radio and the CPU during flash erase and write to make sure that
  731. * they will not interfere with the flash access. This means that all interrupts will be blocked
  732. * for a predictable time (depending on the NVMC specification in the device's Product Specification
  733. * and the command parameters).
  734. * - The data in the p_src buffer should not be modified before the @ref NRF_EVT_FLASH_OPERATION_SUCCESS
  735. * or the @ref NRF_EVT_FLASH_OPERATION_ERROR have been received if the SoftDevice is enabled.
  736. * - This call will make the SoftDevice trigger a hardfault when the page is written, if it is
  737. * protected.
  738. *
  739. *
  740. * @param[in] p_dst Pointer to start of flash location to be written.
  741. * @param[in] p_src Pointer to buffer with data to be written.
  742. * @param[in] size Number of 32-bit words to write. Maximum size is the number of words in one
  743. * flash page. See the device's Product Specification for details.
  744. *
  745. * @retval ::NRF_ERROR_INVALID_ADDR Tried to write to a non existing flash address, or p_dst or p_src was unaligned.
  746. * @retval ::NRF_ERROR_BUSY The previous command has not yet completed.
  747. * @retval ::NRF_ERROR_INVALID_LENGTH Size was 0, or higher than the maximum allowed size.
  748. * @retval ::NRF_ERROR_FORBIDDEN Tried to write to an address outside the application flash area.
  749. * @retval ::NRF_SUCCESS The command was accepted.
  750. */
  751. SVCALL(SD_FLASH_WRITE, uint32_t, sd_flash_write(uint32_t * p_dst, uint32_t const * p_src, uint32_t size));
  752. /**@brief Flash Erase page
  753. *
  754. * Commands to erase a flash page
  755. * If the SoftDevice is enabled:
  756. * This call initiates the flash access command, and its completion will be communicated to the
  757. * application with exactly one of the following events:
  758. * - @ref NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
  759. * - @ref NRF_EVT_FLASH_OPERATION_ERROR - The command could not be started.
  760. *
  761. * If the SoftDevice is not enabled no event will be generated, and this call will return @ref NRF_SUCCESS when the
  762. * erase has been completed
  763. *
  764. * @note
  765. * - This call takes control over the radio and the CPU during flash erase and write to make sure that
  766. * they will not interfere with the flash access. This means that all interrupts will be blocked
  767. * for a predictable time (depending on the NVMC specification in the device's Product Specification
  768. * and the command parameters).
  769. * - This call will make the SoftDevice trigger a hardfault when the page is erased, if it is
  770. * protected.
  771. *
  772. *
  773. * @param[in] page_number Page number of the page to erase
  774. *
  775. * @retval ::NRF_ERROR_INTERNAL If a new session could not be opened due to an internal error.
  776. * @retval ::NRF_ERROR_INVALID_ADDR Tried to erase to a non existing flash page.
  777. * @retval ::NRF_ERROR_BUSY The previous command has not yet completed.
  778. * @retval ::NRF_ERROR_FORBIDDEN Tried to erase a page outside the application flash area.
  779. * @retval ::NRF_SUCCESS The command was accepted.
  780. */
  781. SVCALL(SD_FLASH_PAGE_ERASE, uint32_t, sd_flash_page_erase(uint32_t page_number));
  782. /**@brief Flash Protection set
  783. *
  784. * Commands to set the flash protection configuration registers.
  785. This sets the CONFIGx registers of the BPROT peripheral.
  786. *
  787. * @note Not all parameters are valid for all products. Some bits in each parameter may not be
  788. * valid for your product. Please refer your Product Specification for more details.
  789. *
  790. * @note To read the values read them directly. They are only write-protected.
  791. *
  792. * @note It is possible to use @ref sd_protected_register_write instead of this function.
  793. *
  794. * @param[in] block_cfg0 Value to be written to the configuration register.
  795. * @param[in] block_cfg1 Value to be written to the configuration register.
  796. * @param[in] block_cfg2 Value to be written to the configuration register.
  797. * @param[in] block_cfg3 Value to be written to the configuration register.
  798. *
  799. * @retval ::NRF_ERROR_NOT_SUPPORTED Non-zero value supplied to one or more of the unsupported parameters.
  800. * @retval ::NRF_SUCCESS Values successfully written to configuration registers.
  801. */
  802. SVCALL(SD_FLASH_PROTECT, uint32_t, sd_flash_protect(uint32_t block_cfg0, uint32_t block_cfg1, uint32_t block_cfg2, uint32_t block_cfg3));
  803. /**@brief Opens a session for radio timeslot requests.
  804. *
  805. * @note Only one session can be open at a time.
  806. * @note p_radio_signal_callback(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START) will be called when the radio timeslot
  807. * starts. From this point the NRF_RADIO and NRF_TIMER0 peripherals can be freely accessed
  808. * by the application.
  809. * @note p_radio_signal_callback(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0) is called whenever the NRF_TIMER0
  810. * interrupt occurs.
  811. * @note p_radio_signal_callback(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO) is called whenever the NRF_RADIO
  812. * interrupt occurs.
  813. * @note p_radio_signal_callback() will be called at ARM interrupt priority level 0. This
  814. * implies that none of the sd_* API calls can be used from p_radio_signal_callback().
  815. *
  816. * @param[in] p_radio_signal_callback The signal callback.
  817. *
  818. * @retval ::NRF_ERROR_INVALID_ADDR p_radio_signal_callback is an invalid function pointer.
  819. * @retval ::NRF_ERROR_BUSY If session cannot be opened.
  820. * @retval ::NRF_ERROR_INTERNAL If a new session could not be opened due to an internal error.
  821. * @retval ::NRF_SUCCESS Otherwise.
  822. */
  823. SVCALL(SD_RADIO_SESSION_OPEN, uint32_t, sd_radio_session_open(nrf_radio_signal_callback_t p_radio_signal_callback));
  824. /**@brief Closes a session for radio timeslot requests.
  825. *
  826. * @note Any current radio timeslot will be finished before the session is closed.
  827. * @note If a radio timeslot is scheduled when the session is closed, it will be canceled.
  828. * @note The application cannot consider the session closed until the @ref NRF_EVT_RADIO_SESSION_CLOSED
  829. * event is received.
  830. *
  831. * @retval ::NRF_ERROR_FORBIDDEN If session not opened.
  832. * @retval ::NRF_ERROR_BUSY If session is currently being closed.
  833. * @retval ::NRF_SUCCESS Otherwise.
  834. */
  835. SVCALL(SD_RADIO_SESSION_CLOSE, uint32_t, sd_radio_session_close(void));
  836. /**@brief Requests a radio timeslot.
  837. *
  838. * @note The request type is determined by p_request->request_type, and can be one of @ref NRF_RADIO_REQ_TYPE_EARLIEST
  839. * and @ref NRF_RADIO_REQ_TYPE_NORMAL. The first request in a session must always be of type @ref NRF_RADIO_REQ_TYPE_EARLIEST.
  840. * @note For a normal request (@ref NRF_RADIO_REQ_TYPE_NORMAL), the start time of a radio timeslot is specified by
  841. * p_request->distance_us and is given relative to the start of the previous timeslot.
  842. * @note A too small p_request->distance_us will lead to a @ref NRF_EVT_RADIO_BLOCKED event.
  843. * @note Timeslots scheduled too close will lead to a @ref NRF_EVT_RADIO_BLOCKED event.
  844. * @note See the SoftDevice Specification for more on radio timeslot scheduling, distances and lengths.
  845. * @note If an opportunity for the first radio timeslot is not found before 100 ms after the call to this
  846. * function, it is not scheduled, and instead a @ref NRF_EVT_RADIO_BLOCKED event is sent.
  847. * The application may then try to schedule the first radio timeslot again.
  848. * @note Successful requests will result in nrf_radio_signal_callback_t(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START).
  849. * Unsuccessful requests will result in a @ref NRF_EVT_RADIO_BLOCKED event, see @ref NRF_SOC_EVTS.
  850. * @note The jitter in the start time of the radio timeslots is +/- @ref NRF_RADIO_START_JITTER_US us.
  851. * @note The nrf_radio_signal_callback_t(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START) call has a latency relative to the
  852. * specified radio timeslot start, but this does not affect the actual start time of the timeslot.
  853. * @note NRF_TIMER0 is reset at the start of the radio timeslot, and is clocked at 1MHz from the high frequency
  854. * (16 MHz) clock source. If p_request->hfclk_force_xtal is true, the high frequency clock is
  855. * guaranteed to be clocked from the external crystal.
  856. * @note The SoftDevice will neither access the NRF_RADIO peripheral nor the NRF_TIMER0 peripheral
  857. * during the radio timeslot.
  858. *
  859. * @param[in] p_request Pointer to the request parameters.
  860. *
  861. * @retval ::NRF_ERROR_FORBIDDEN Either:
  862. * - The session is not open.
  863. * - The session is not IDLE.
  864. * - This is the first request and its type is not @ref NRF_RADIO_REQ_TYPE_EARLIEST.
  865. * - The request type was set to @ref NRF_RADIO_REQ_TYPE_NORMAL after a
  866. * @ref NRF_RADIO_REQ_TYPE_EARLIEST request was blocked.
  867. * @retval ::NRF_ERROR_INVALID_ADDR If the p_request pointer is invalid.
  868. * @retval ::NRF_ERROR_INVALID_PARAM If the parameters of p_request are not valid.
  869. * @retval ::NRF_SUCCESS Otherwise.
  870. */
  871. SVCALL(SD_RADIO_REQUEST, uint32_t, sd_radio_request(nrf_radio_request_t const * p_request));
  872. /**@brief Write register protected by the SoftDevice
  873. *
  874. * This function writes to a register that is write-protected by the SoftDevice. Please refer to your
  875. * SoftDevice Specification for more details about which registers that are protected by SoftDevice.
  876. * This function can write to the following protected peripheral:
  877. * - BPROT
  878. *
  879. * @note Protected registers may be read directly.
  880. * @note Register that are write-once will return @ref NRF_SUCCESS on second set, even the value in
  881. * the register has not changed. See the Product Specification for more details about register
  882. * properties.
  883. *
  884. * @param[in] p_register Pointer to register to be written.
  885. * @param[in] value Value to be written to the register.
  886. *
  887. * @retval ::NRF_ERROR_INVALID_ADDR This function can not write to the reguested register.
  888. * @retval ::NRF_SUCCESS Value successfully written to register.
  889. *
  890. */
  891. SVCALL(SD_PROTECTED_REGISTER_WRITE, uint32_t, sd_protected_register_write(volatile uint32_t * p_register, uint32_t value));
  892. /**@} */
  893. #ifdef __cplusplus
  894. }
  895. #endif
  896. #endif // NRF_SOC_H__
  897. /**@} */