nrf_soc.h 51 KB

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