nrf_soc.h 50 KB

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