nrf_soc.h 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. /*
  2. * Copyright (c) 2015 - 2018, 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 (17)
  66. /**@brief The latest time before the end of a timeslot the timeslot can be extended. */
  67. #define NRF_RADIO_MIN_EXTENSION_MARGIN_US (79)
  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 channels available to the application when the SoftDevice is disabled. */
  103. #define NRF_SOC_APP_PPI_CHANNELS_SD_DISABLED_MSK (~NRF_SOC_SD_PPI_CHANNELS_SD_DISABLED_MSK)
  104. /**@brief Mask of PPI channels available to the application when the SoftDevice is enabled. */
  105. #define NRF_SOC_APP_PPI_CHANNELS_SD_ENABLED_MSK (~NRF_SOC_SD_PPI_CHANNELS_SD_ENABLED_MSK)
  106. /**@brief Mask of PPI groups reserved by the SoftDevice when the SoftDevice is disabled. */
  107. #define NRF_SOC_SD_PPI_GROUPS_SD_DISABLED_MSK ((uint32_t)(0))
  108. /**@brief Mask of PPI groups reserved by the SoftDevice when the SoftDevice is enabled. */
  109. #define NRF_SOC_SD_PPI_GROUPS_SD_ENABLED_MSK ((uint32_t)( \
  110. (1U << 4) \
  111. | (1U << 5) \
  112. ))
  113. /**@brief Mask of PPI groups available to the application when the SoftDevice is disabled. */
  114. #define NRF_SOC_APP_PPI_GROUPS_SD_DISABLED_MSK (~NRF_SOC_SD_PPI_GROUPS_SD_DISABLED_MSK)
  115. /**@brief Mask of PPI groups available to the application when the SoftDevice is enabled. */
  116. #define NRF_SOC_APP_PPI_GROUPS_SD_ENABLED_MSK (~NRF_SOC_SD_PPI_GROUPS_SD_ENABLED_MSK)
  117. /**@} */
  118. /**@addtogroup NRF_SOC_ENUMS Enumerations
  119. * @{ */
  120. /**@brief The SVC numbers used by the SVC functions in the SoC library. */
  121. enum NRF_SOC_SVCS
  122. {
  123. SD_PPI_CHANNEL_ENABLE_GET = SOC_SVC_BASE,
  124. SD_PPI_CHANNEL_ENABLE_SET = SOC_SVC_BASE + 1,
  125. SD_PPI_CHANNEL_ENABLE_CLR = SOC_SVC_BASE + 2,
  126. SD_PPI_CHANNEL_ASSIGN = SOC_SVC_BASE + 3,
  127. SD_PPI_GROUP_TASK_ENABLE = SOC_SVC_BASE + 4,
  128. SD_PPI_GROUP_TASK_DISABLE = SOC_SVC_BASE + 5,
  129. SD_PPI_GROUP_ASSIGN = SOC_SVC_BASE + 6,
  130. SD_PPI_GROUP_GET = SOC_SVC_BASE + 7,
  131. SD_FLASH_PAGE_ERASE = SOC_SVC_BASE + 8,
  132. SD_FLASH_WRITE = SOC_SVC_BASE + 9,
  133. SD_FLASH_PROTECT = SOC_SVC_BASE + 10,
  134. SD_PROTECTED_REGISTER_WRITE = SOC_SVC_BASE + 11,
  135. SD_MUTEX_NEW = SOC_SVC_BASE_NOT_AVAILABLE,
  136. SD_MUTEX_ACQUIRE = SOC_SVC_BASE_NOT_AVAILABLE + 1,
  137. SD_MUTEX_RELEASE = SOC_SVC_BASE_NOT_AVAILABLE + 2,
  138. SD_RAND_APPLICATION_POOL_CAPACITY_GET = SOC_SVC_BASE_NOT_AVAILABLE + 3,
  139. SD_RAND_APPLICATION_BYTES_AVAILABLE_GET = SOC_SVC_BASE_NOT_AVAILABLE + 4,
  140. SD_RAND_APPLICATION_VECTOR_GET = SOC_SVC_BASE_NOT_AVAILABLE + 5,
  141. SD_POWER_MODE_SET = SOC_SVC_BASE_NOT_AVAILABLE + 6,
  142. SD_POWER_SYSTEM_OFF = SOC_SVC_BASE_NOT_AVAILABLE + 7,
  143. SD_POWER_RESET_REASON_GET = SOC_SVC_BASE_NOT_AVAILABLE + 8,
  144. SD_POWER_RESET_REASON_CLR = SOC_SVC_BASE_NOT_AVAILABLE + 9,
  145. SD_POWER_POF_ENABLE = SOC_SVC_BASE_NOT_AVAILABLE + 10,
  146. SD_POWER_POF_THRESHOLD_SET = SOC_SVC_BASE_NOT_AVAILABLE + 11,
  147. SD_POWER_RAM_POWER_SET = SOC_SVC_BASE_NOT_AVAILABLE + 13,
  148. SD_POWER_RAM_POWER_CLR = SOC_SVC_BASE_NOT_AVAILABLE + 14,
  149. SD_POWER_RAM_POWER_GET = SOC_SVC_BASE_NOT_AVAILABLE + 15,
  150. SD_POWER_GPREGRET_SET = SOC_SVC_BASE_NOT_AVAILABLE + 16,
  151. SD_POWER_GPREGRET_CLR = SOC_SVC_BASE_NOT_AVAILABLE + 17,
  152. SD_POWER_GPREGRET_GET = SOC_SVC_BASE_NOT_AVAILABLE + 18,
  153. SD_POWER_DCDC_MODE_SET = SOC_SVC_BASE_NOT_AVAILABLE + 19,
  154. SD_APP_EVT_WAIT = SOC_SVC_BASE_NOT_AVAILABLE + 21,
  155. SD_CLOCK_HFCLK_REQUEST = SOC_SVC_BASE_NOT_AVAILABLE + 22,
  156. SD_CLOCK_HFCLK_RELEASE = SOC_SVC_BASE_NOT_AVAILABLE + 23,
  157. SD_CLOCK_HFCLK_IS_RUNNING = SOC_SVC_BASE_NOT_AVAILABLE + 24,
  158. SD_RADIO_NOTIFICATION_CFG_SET = SOC_SVC_BASE_NOT_AVAILABLE + 25,
  159. SD_ECB_BLOCK_ENCRYPT = SOC_SVC_BASE_NOT_AVAILABLE + 26,
  160. SD_ECB_BLOCKS_ENCRYPT = SOC_SVC_BASE_NOT_AVAILABLE + 27,
  161. SD_RADIO_SESSION_OPEN = SOC_SVC_BASE_NOT_AVAILABLE + 28,
  162. SD_RADIO_SESSION_CLOSE = SOC_SVC_BASE_NOT_AVAILABLE + 29,
  163. SD_RADIO_REQUEST = SOC_SVC_BASE_NOT_AVAILABLE + 30,
  164. SD_EVT_GET = SOC_SVC_BASE_NOT_AVAILABLE + 31,
  165. SD_TEMP_GET = SOC_SVC_BASE_NOT_AVAILABLE + 32,
  166. SVC_SOC_LAST = SOC_SVC_BASE_NOT_AVAILABLE + 37
  167. };
  168. /**@brief Possible values of a ::nrf_mutex_t. */
  169. enum NRF_MUTEX_VALUES
  170. {
  171. NRF_MUTEX_FREE,
  172. NRF_MUTEX_TAKEN
  173. };
  174. /**@brief Power modes. */
  175. enum NRF_POWER_MODES
  176. {
  177. NRF_POWER_MODE_CONSTLAT, /**< Constant latency mode. See power management in the reference manual. */
  178. NRF_POWER_MODE_LOWPWR /**< Low power mode. See power management in the reference manual. */
  179. };
  180. /**@brief Power failure thresholds */
  181. enum NRF_POWER_THRESHOLDS
  182. {
  183. NRF_POWER_THRESHOLD_V17 = 4UL, /**< 1.7 Volts power failure threshold. */
  184. NRF_POWER_THRESHOLD_V18, /**< 1.8 Volts power failure threshold. */
  185. NRF_POWER_THRESHOLD_V19, /**< 1.9 Volts power failure threshold. */
  186. NRF_POWER_THRESHOLD_V20, /**< 2.0 Volts power failure threshold. */
  187. NRF_POWER_THRESHOLD_V21, /**< 2.1 Volts power failure threshold. */
  188. NRF_POWER_THRESHOLD_V22, /**< 2.2 Volts power failure threshold. */
  189. NRF_POWER_THRESHOLD_V23, /**< 2.3 Volts power failure threshold. */
  190. NRF_POWER_THRESHOLD_V24, /**< 2.4 Volts power failure threshold. */
  191. NRF_POWER_THRESHOLD_V25, /**< 2.5 Volts power failure threshold. */
  192. NRF_POWER_THRESHOLD_V26, /**< 2.6 Volts power failure threshold. */
  193. NRF_POWER_THRESHOLD_V27, /**< 2.7 Volts power failure threshold. */
  194. NRF_POWER_THRESHOLD_V28 /**< 2.8 Volts power failure threshold. */
  195. };
  196. /**@brief DC/DC converter modes. */
  197. enum NRF_POWER_DCDC_MODES
  198. {
  199. NRF_POWER_DCDC_DISABLE, /**< The DCDC is disabled. */
  200. NRF_POWER_DCDC_ENABLE /**< The DCDC is enabled. */
  201. };
  202. /**@brief Radio notification distances. */
  203. enum NRF_RADIO_NOTIFICATION_DISTANCES
  204. {
  205. NRF_RADIO_NOTIFICATION_DISTANCE_NONE = 0, /**< The event does not have a notification. */
  206. NRF_RADIO_NOTIFICATION_DISTANCE_800US, /**< The distance from the active notification to start of radio activity. */
  207. NRF_RADIO_NOTIFICATION_DISTANCE_1740US, /**< The distance from the active notification to start of radio activity. */
  208. NRF_RADIO_NOTIFICATION_DISTANCE_2680US, /**< The distance from the active notification to start of radio activity. */
  209. NRF_RADIO_NOTIFICATION_DISTANCE_3620US, /**< The distance from the active notification to start of radio activity. */
  210. NRF_RADIO_NOTIFICATION_DISTANCE_4560US, /**< The distance from the active notification to start of radio activity. */
  211. NRF_RADIO_NOTIFICATION_DISTANCE_5500US /**< The distance from the active notification to start of radio activity. */
  212. };
  213. /**@brief Radio notification types. */
  214. enum NRF_RADIO_NOTIFICATION_TYPES
  215. {
  216. NRF_RADIO_NOTIFICATION_TYPE_NONE = 0, /**< The event does not have a radio notification signal. */
  217. NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE, /**< Using interrupt for notification when the radio will be enabled. */
  218. NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE, /**< Using interrupt for notification when the radio has been disabled. */
  219. NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, /**< Using interrupt for notification both when the radio will be enabled and disabled. */
  220. };
  221. /**@brief The Radio signal callback types. */
  222. enum NRF_RADIO_CALLBACK_SIGNAL_TYPE
  223. {
  224. NRF_RADIO_CALLBACK_SIGNAL_TYPE_START, /**< This signal indicates the start of the radio timeslot. */
  225. NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0, /**< This signal indicates the NRF_TIMER0 interrupt. */
  226. NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO, /**< This signal indicates the NRF_RADIO interrupt. */
  227. NRF_RADIO_CALLBACK_SIGNAL_TYPE_EXTEND_FAILED, /**< This signal indicates extend action failed. */
  228. NRF_RADIO_CALLBACK_SIGNAL_TYPE_EXTEND_SUCCEEDED /**< This signal indicates extend action succeeded. */
  229. };
  230. /**@brief The actions requested by the signal callback.
  231. *
  232. * This code gives the SOC instructions about what action to take when the signal callback has
  233. * returned.
  234. */
  235. enum NRF_RADIO_SIGNAL_CALLBACK_ACTION
  236. {
  237. NRF_RADIO_SIGNAL_CALLBACK_ACTION_NONE, /**< Return without action. */
  238. NRF_RADIO_SIGNAL_CALLBACK_ACTION_EXTEND, /**< Request an extension of the current
  239. timeslot. Maximum execution time for this action:
  240. @ref NRF_RADIO_MAX_EXTENSION_PROCESSING_TIME_US.
  241. This action must be started at least
  242. @ref NRF_RADIO_MIN_EXTENSION_MARGIN_US before
  243. the end of the timeslot. */
  244. NRF_RADIO_SIGNAL_CALLBACK_ACTION_END, /**< End the current radio timeslot. */
  245. NRF_RADIO_SIGNAL_CALLBACK_ACTION_REQUEST_AND_END /**< Request a new radio timeslot and end the current timeslot. */
  246. };
  247. /**@brief Radio timeslot high frequency clock source configuration. */
  248. enum NRF_RADIO_HFCLK_CFG
  249. {
  250. NRF_RADIO_HFCLK_CFG_XTAL_GUARANTEED, /**< The SoftDevice will guarantee that the high frequency clock source is the
  251. external crystal for the whole duration of the timeslot. This should be the
  252. preferred option for events that use the radio or require high timing accuracy.
  253. @note The SoftDevice will automatically turn on and off the external crystal,
  254. at the beginning and end of the timeslot, respectively. The crystal may also
  255. intentionally be left running after the timeslot, in cases where it is needed
  256. by the SoftDevice shortly after the end of the timeslot. */
  257. NRF_RADIO_HFCLK_CFG_NO_GUARANTEE /**< This configuration allows for earlier and tighter scheduling of timeslots.
  258. The RC oscillator may be the clock source in part or for the whole duration of the timeslot.
  259. The RC oscillator's accuracy must therefore be taken into consideration.
  260. @note If the application will use the radio peripheral in timeslots with this configuration,
  261. it must make sure that the crystal is running and stable before starting the radio. */
  262. };
  263. /**@brief Radio timeslot priorities. */
  264. enum NRF_RADIO_PRIORITY
  265. {
  266. NRF_RADIO_PRIORITY_HIGH, /**< High (equal priority as the normal connection priority of the SoftDevice stack(s)). */
  267. NRF_RADIO_PRIORITY_NORMAL, /**< Normal (equal priority as the priority of secondary activities of the SoftDevice stack(s)). */
  268. };
  269. /**@brief Radio timeslot request type. */
  270. enum NRF_RADIO_REQUEST_TYPE
  271. {
  272. NRF_RADIO_REQ_TYPE_EARLIEST, /**< Request radio timeslot as early as possible. This should always be used for the first request in a session. */
  273. NRF_RADIO_REQ_TYPE_NORMAL /**< Normal radio timeslot request. */
  274. };
  275. /**@brief SoC Events. */
  276. enum NRF_SOC_EVTS
  277. {
  278. NRF_EVT_HFCLKSTARTED, /**< Event indicating that the HFCLK has started. */
  279. NRF_EVT_POWER_FAILURE_WARNING, /**< Event indicating that a power failure warning has occurred. */
  280. NRF_EVT_FLASH_OPERATION_SUCCESS, /**< Event indicating that the ongoing flash operation has completed successfully. */
  281. NRF_EVT_FLASH_OPERATION_ERROR, /**< Event indicating that the ongoing flash operation has timed out with an error. */
  282. NRF_EVT_RADIO_BLOCKED, /**< Event indicating that a radio timeslot was blocked. */
  283. NRF_EVT_RADIO_CANCELED, /**< Event indicating that a radio timeslot was canceled by SoftDevice. */
  284. NRF_EVT_RADIO_SIGNAL_CALLBACK_INVALID_RETURN, /**< Event indicating that a radio timeslot signal callback handler return was invalid. */
  285. NRF_EVT_RADIO_SESSION_IDLE, /**< Event indicating that a radio timeslot session is idle. */
  286. NRF_EVT_RADIO_SESSION_CLOSED, /**< Event indicating that a radio timeslot session is closed. */
  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 Sets the power failure comparator threshold value.
  456. *
  457. *
  458. * @param[in] threshold The power-fail threshold value to use, see @ref NRF_POWER_THRESHOLDS.
  459. *
  460. * @retval ::NRF_SUCCESS The power failure threshold was set.
  461. * @retval ::NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN The power failure threshold is unknown.
  462. */
  463. SVCALL(SD_POWER_POF_THRESHOLD_SET, uint32_t, sd_power_pof_threshold_set(uint8_t threshold));
  464. /**@brief Writes the NRF_POWER->RAM[index].POWERSET register.
  465. *
  466. * @param[in] index Contains the index in the NRF_POWER->RAM[index].POWERSET register to write to.
  467. * @param[in] ram_powerset Contains the word to write to the NRF_POWER->RAM[index].POWERSET register.
  468. *
  469. * @retval ::NRF_SUCCESS
  470. */
  471. SVCALL(SD_POWER_RAM_POWER_SET, uint32_t, sd_power_ram_power_set(uint8_t index, uint32_t ram_powerset));
  472. /**@brief Writes the NRF_POWER->RAM[index].POWERCLR register.
  473. *
  474. * @param[in] index Contains the index in the NRF_POWER->RAM[index].POWERCLR register to write to.
  475. * @param[in] ram_powerclr Contains the word to write to the NRF_POWER->RAM[index].POWERCLR register.
  476. *
  477. * @retval ::NRF_SUCCESS
  478. */
  479. SVCALL(SD_POWER_RAM_POWER_CLR, uint32_t, sd_power_ram_power_clr(uint8_t index, uint32_t ram_powerclr));
  480. /**@brief Get contents of NRF_POWER->RAM[index].POWER register, indicates power status of RAM[index] blocks.
  481. *
  482. * @param[in] index Contains the index in the NRF_POWER->RAM[index].POWER register to read from.
  483. * @param[out] p_ram_power Content of NRF_POWER->RAM[index].POWER register.
  484. *
  485. * @retval ::NRF_SUCCESS
  486. */
  487. SVCALL(SD_POWER_RAM_POWER_GET, uint32_t, sd_power_ram_power_get(uint8_t index, uint32_t * p_ram_power));
  488. /**@brief Set bits in the general purpose retention registers (NRF_POWER->GPREGRET*).
  489. *
  490. * @param[in] gpregret_id 0 for GPREGRET, 1 for GPREGRET2.
  491. * @param[in] gpregret_msk Bits to be set in the GPREGRET register.
  492. *
  493. * @retval ::NRF_SUCCESS
  494. */
  495. SVCALL(SD_POWER_GPREGRET_SET, uint32_t, sd_power_gpregret_set(uint32_t gpregret_id, uint32_t gpregret_msk));
  496. /**@brief Clear bits in the general purpose retention registers (NRF_POWER->GPREGRET*).
  497. *
  498. * @param[in] gpregret_id 0 for GPREGRET, 1 for GPREGRET2.
  499. * @param[in] gpregret_msk Bits to be clear in the GPREGRET register.
  500. *
  501. * @retval ::NRF_SUCCESS
  502. */
  503. SVCALL(SD_POWER_GPREGRET_CLR, uint32_t, sd_power_gpregret_clr(uint32_t gpregret_id, uint32_t gpregret_msk));
  504. /**@brief Get contents of the general purpose retention registers (NRF_POWER->GPREGRET*).
  505. *
  506. * @param[in] gpregret_id 0 for GPREGRET, 1 for GPREGRET2.
  507. * @param[out] p_gpregret Contents of the GPREGRET register.
  508. *
  509. * @retval ::NRF_SUCCESS
  510. */
  511. SVCALL(SD_POWER_GPREGRET_GET, uint32_t, sd_power_gpregret_get(uint32_t gpregret_id, uint32_t *p_gpregret));
  512. /**@brief Enable or disable the DC/DC regulator.
  513. *
  514. * @param[in] dcdc_mode The mode of the DCDC, see @ref NRF_POWER_DCDC_MODES.
  515. *
  516. * @retval ::NRF_SUCCESS
  517. * @retval ::NRF_ERROR_INVALID_PARAM The DCDC mode is invalid.
  518. */
  519. SVCALL(SD_POWER_DCDC_MODE_SET, uint32_t, sd_power_dcdc_mode_set(uint8_t dcdc_mode));
  520. /**@brief Request the high frequency crystal oscillator.
  521. *
  522. * Will start the high frequency crystal oscillator, the startup time of the crystal varies
  523. * and the ::sd_clock_hfclk_is_running function can be polled to check if it has started.
  524. *
  525. * @see sd_clock_hfclk_is_running
  526. * @see sd_clock_hfclk_release
  527. *
  528. * @retval ::NRF_SUCCESS
  529. */
  530. SVCALL(SD_CLOCK_HFCLK_REQUEST, uint32_t, sd_clock_hfclk_request(void));
  531. /**@brief Releases the high frequency crystal oscillator.
  532. *
  533. * Will stop the high frequency crystal oscillator, this happens immediately.
  534. *
  535. * @see sd_clock_hfclk_is_running
  536. * @see sd_clock_hfclk_request
  537. *
  538. * @retval ::NRF_SUCCESS
  539. */
  540. SVCALL(SD_CLOCK_HFCLK_RELEASE, uint32_t, sd_clock_hfclk_release(void));
  541. /**@brief Checks if the high frequency crystal oscillator is running.
  542. *
  543. * @see sd_clock_hfclk_request
  544. * @see sd_clock_hfclk_release
  545. *
  546. * @param[out] p_is_running 1 if the external crystal oscillator is running, 0 if not.
  547. *
  548. * @retval ::NRF_SUCCESS
  549. */
  550. SVCALL(SD_CLOCK_HFCLK_IS_RUNNING, uint32_t, sd_clock_hfclk_is_running(uint32_t * p_is_running));
  551. /**@brief Waits for an application event.
  552. *
  553. * An application event is either an application interrupt or a pended interrupt when the interrupt
  554. * is disabled.
  555. *
  556. * When the application waits for an application event by calling this function, an interrupt that
  557. * is enabled will be taken immediately on pending since this function will wait in thread mode,
  558. * then the execution will return in the application's main thread.
  559. *
  560. * In order to wake up from disabled interrupts, the SEVONPEND flag has to be set in the Cortex-M
  561. * MCU's System Control Register (SCR), CMSIS_SCB. In that case, when a disabled interrupt gets
  562. * pended, this function will return to the application's main thread.
  563. *
  564. * @note The application must ensure that the pended flag is cleared using ::sd_nvic_ClearPendingIRQ
  565. * in order to sleep using this function. This is only necessary for disabled interrupts, as
  566. * the interrupt handler will clear the pending flag automatically for enabled interrupts.
  567. *
  568. * @note If an application interrupt has happened since the last time sd_app_evt_wait was
  569. * called this function will return immediately and not go to sleep. This is to avoid race
  570. * conditions that can occur when a flag is updated in the interrupt handler and processed
  571. * in the main loop.
  572. *
  573. * @post An application interrupt has happened or a interrupt pending flag is set.
  574. *
  575. * @retval ::NRF_SUCCESS
  576. */
  577. SVCALL(SD_APP_EVT_WAIT, uint32_t, sd_app_evt_wait(void));
  578. /**@brief Get PPI channel enable register contents.
  579. *
  580. * @param[out] p_channel_enable The contents of the PPI CHEN register.
  581. *
  582. * @retval ::NRF_SUCCESS
  583. */
  584. SVCALL(SD_PPI_CHANNEL_ENABLE_GET, uint32_t, sd_ppi_channel_enable_get(uint32_t * p_channel_enable));
  585. /**@brief Set PPI channel enable register.
  586. *
  587. * @param[in] channel_enable_set_msk Mask containing the bits to set in the PPI CHEN register.
  588. *
  589. * @retval ::NRF_SUCCESS
  590. */
  591. SVCALL(SD_PPI_CHANNEL_ENABLE_SET, uint32_t, sd_ppi_channel_enable_set(uint32_t channel_enable_set_msk));
  592. /**@brief Clear PPI channel enable register.
  593. *
  594. * @param[in] channel_enable_clr_msk Mask containing the bits to clear in the PPI CHEN register.
  595. *
  596. * @retval ::NRF_SUCCESS
  597. */
  598. SVCALL(SD_PPI_CHANNEL_ENABLE_CLR, uint32_t, sd_ppi_channel_enable_clr(uint32_t channel_enable_clr_msk));
  599. /**@brief Assign endpoints to a PPI channel.
  600. *
  601. * @param[in] channel_num Number of the PPI channel to assign.
  602. * @param[in] evt_endpoint Event endpoint of the PPI channel.
  603. * @param[in] task_endpoint Task endpoint of the PPI channel.
  604. *
  605. * @retval ::NRF_ERROR_SOC_PPI_INVALID_CHANNEL The channel number is invalid.
  606. * @retval ::NRF_SUCCESS
  607. */
  608. 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));
  609. /**@brief Task to enable a channel group.
  610. *
  611. * @param[in] group_num Number of the channel group.
  612. *
  613. * @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid
  614. * @retval ::NRF_SUCCESS
  615. */
  616. SVCALL(SD_PPI_GROUP_TASK_ENABLE, uint32_t, sd_ppi_group_task_enable(uint8_t group_num));
  617. /**@brief Task to disable a channel group.
  618. *
  619. * @param[in] group_num Number of the PPI group.
  620. *
  621. * @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid.
  622. * @retval ::NRF_SUCCESS
  623. */
  624. SVCALL(SD_PPI_GROUP_TASK_DISABLE, uint32_t, sd_ppi_group_task_disable(uint8_t group_num));
  625. /**@brief Assign PPI channels to a channel group.
  626. *
  627. * @param[in] group_num Number of the channel group.
  628. * @param[in] channel_msk Mask of the channels to assign to the group.
  629. *
  630. * @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid.
  631. * @retval ::NRF_SUCCESS
  632. */
  633. SVCALL(SD_PPI_GROUP_ASSIGN, uint32_t, sd_ppi_group_assign(uint8_t group_num, uint32_t channel_msk));
  634. /**@brief Gets the PPI channels of a channel group.
  635. *
  636. * @param[in] group_num Number of the channel group.
  637. * @param[out] p_channel_msk Mask of the channels assigned to the group.
  638. *
  639. * @retval ::NRF_ERROR_SOC_PPI_INVALID_GROUP The group number is invalid.
  640. * @retval ::NRF_SUCCESS
  641. */
  642. SVCALL(SD_PPI_GROUP_GET, uint32_t, sd_ppi_group_get(uint8_t group_num, uint32_t * p_channel_msk));
  643. /**@brief Configures the Radio Notification signal.
  644. *
  645. * @note
  646. * - The notification signal latency depends on the interrupt priority settings of SWI used
  647. * for notification signal.
  648. * - To ensure that the radio notification signal behaves in a consistent way, the radio
  649. * notifications must be configured when there is no protocol stack or other SoftDevice
  650. * activity in progress. It is recommended that the radio notification signal is
  651. * configured directly after the SoftDevice has been enabled.
  652. * - In the period between the ACTIVE signal and the start of the Radio Event, the SoftDevice
  653. * will interrupt the application to do Radio Event preparation.
  654. * - Using the Radio Notification feature may limit the bandwidth, as the SoftDevice may have
  655. * to shorten the connection events to have time for the Radio Notification signals.
  656. *
  657. * @param[in] type Type of notification signal, see @ref NRF_RADIO_NOTIFICATION_TYPES.
  658. * @ref NRF_RADIO_NOTIFICATION_TYPE_NONE shall be used to turn off radio
  659. * notification. Using @ref NRF_RADIO_NOTIFICATION_DISTANCE_NONE is
  660. * recommended (but not required) to be used with
  661. * @ref NRF_RADIO_NOTIFICATION_TYPE_NONE.
  662. *
  663. * @param[in] distance Distance between the notification signal and start of radio activity, see @ref NRF_RADIO_NOTIFICATION_DISTANCES.
  664. * This parameter is ignored when @ref NRF_RADIO_NOTIFICATION_TYPE_NONE or
  665. * @ref NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE is used.
  666. *
  667. * @retval ::NRF_ERROR_INVALID_PARAM The group number is invalid.
  668. * @retval ::NRF_ERROR_INVALID_STATE A protocol stack or other SoftDevice is running. Stop all
  669. * running activities and retry.
  670. * @retval ::NRF_SUCCESS
  671. */
  672. SVCALL(SD_RADIO_NOTIFICATION_CFG_SET, uint32_t, sd_radio_notification_cfg_set(uint8_t type, uint8_t distance));
  673. /**@brief Encrypts a block according to the specified parameters.
  674. *
  675. * 128-bit AES encryption.
  676. *
  677. * @note:
  678. * - The application may set the SEVONPEND bit in the SCR to 1 to make the SoftDevice sleep while
  679. * the ECB is running. The SEVONPEND bit should only be cleared (set to 0) from application
  680. * main or low interrupt level.
  681. *
  682. * @param[in, out] p_ecb_data Pointer to the ECB parameters' struct (two input
  683. * parameters and one output parameter).
  684. *
  685. * @retval ::NRF_SUCCESS
  686. */
  687. SVCALL(SD_ECB_BLOCK_ENCRYPT, uint32_t, sd_ecb_block_encrypt(nrf_ecb_hal_data_t * p_ecb_data));
  688. /**@brief Encrypts multiple data blocks provided as an array of data block structures.
  689. *
  690. * @details: Performs 128-bit AES encryption on multiple data blocks
  691. *
  692. * @note:
  693. * - The application may set the SEVONPEND bit in the SCR to 1 to make the SoftDevice sleep while
  694. * the ECB is running. The SEVONPEND bit should only be cleared (set to 0) from application
  695. * main or low interrupt level.
  696. *
  697. * @param[in] block_count Count of blocks in the p_data_blocks array.
  698. * @param[in,out] p_data_blocks Pointer to the first entry in a contiguous array of
  699. * @ref nrf_ecb_hal_data_block_t structures.
  700. *
  701. * @retval ::NRF_SUCCESS
  702. */
  703. SVCALL(SD_ECB_BLOCKS_ENCRYPT, uint32_t, sd_ecb_blocks_encrypt(uint8_t block_count, nrf_ecb_hal_data_block_t * p_data_blocks));
  704. /**@brief Gets any pending events generated by the SoC API.
  705. *
  706. * The application should keep calling this function to get events, until ::NRF_ERROR_NOT_FOUND is returned.
  707. *
  708. * @param[out] p_evt_id Set to one of the values in @ref NRF_SOC_EVTS, if any events are pending.
  709. *
  710. * @retval ::NRF_SUCCESS An event was pending. The event id is written in the p_evt_id parameter.
  711. * @retval ::NRF_ERROR_NOT_FOUND No pending events.
  712. */
  713. SVCALL(SD_EVT_GET, uint32_t, sd_evt_get(uint32_t * p_evt_id));
  714. /**@brief Get the temperature measured on the chip
  715. *
  716. * This function will block until the temperature measurement is done.
  717. * It takes around 50 us from call to return.
  718. *
  719. * @param[out] p_temp Result of temperature measurement. Die temperature in 0.25 degrees Celsius.
  720. *
  721. * @retval ::NRF_SUCCESS A temperature measurement was done, and the temperature was written to temp
  722. */
  723. SVCALL(SD_TEMP_GET, uint32_t, sd_temp_get(int32_t * p_temp));
  724. /**@brief Flash Write
  725. *
  726. * Commands to write a buffer to flash
  727. *
  728. * If the SoftDevice is enabled:
  729. * This call initiates the flash access command, and its completion will be communicated to the
  730. * application with exactly one of the following events:
  731. * - @ref NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
  732. * - @ref NRF_EVT_FLASH_OPERATION_ERROR - The command could not be started.
  733. *
  734. * If the SoftDevice is not enabled no event will be generated, and this call will return @ref NRF_SUCCESS when the
  735. * write has been completed
  736. *
  737. * @note
  738. * - This call takes control over the radio and the CPU during flash erase and write to make sure that
  739. * they will not interfere with the flash access. This means that all interrupts will be blocked
  740. * for a predictable time (depending on the NVMC specification in the device's Product Specification
  741. * and the command parameters).
  742. * - The data in the p_src buffer should not be modified before the @ref NRF_EVT_FLASH_OPERATION_SUCCESS
  743. * or the @ref NRF_EVT_FLASH_OPERATION_ERROR have been received if the SoftDevice is enabled.
  744. * - This call will make the SoftDevice trigger a hardfault when the page is written, if it is
  745. * protected.
  746. *
  747. *
  748. * @param[in] p_dst Pointer to start of flash location to be written.
  749. * @param[in] p_src Pointer to buffer with data to be written.
  750. * @param[in] size Number of 32-bit words to write. Maximum size is the number of words in one
  751. * flash page. See the device's Product Specification for details.
  752. *
  753. * @retval ::NRF_ERROR_INVALID_ADDR Tried to write to a non existing flash address, or p_dst or p_src was unaligned.
  754. * @retval ::NRF_ERROR_BUSY The previous command has not yet completed.
  755. * @retval ::NRF_ERROR_INVALID_LENGTH Size was 0, or higher than the maximum allowed size.
  756. * @retval ::NRF_ERROR_FORBIDDEN Tried to write to an address outside the application flash area.
  757. * @retval ::NRF_SUCCESS The command was accepted.
  758. */
  759. SVCALL(SD_FLASH_WRITE, uint32_t, sd_flash_write(uint32_t * p_dst, uint32_t const * p_src, uint32_t size));
  760. /**@brief Flash Erase page
  761. *
  762. * Commands to erase a flash page
  763. * If the SoftDevice is enabled:
  764. * This call initiates the flash access command, and its completion will be communicated to the
  765. * application with exactly one of the following events:
  766. * - @ref NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
  767. * - @ref NRF_EVT_FLASH_OPERATION_ERROR - The command could not be started.
  768. *
  769. * If the SoftDevice is not enabled no event will be generated, and this call will return @ref NRF_SUCCESS when the
  770. * erase has been completed
  771. *
  772. * @note
  773. * - This call takes control over the radio and the CPU during flash erase and write to make sure that
  774. * they will not interfere with the flash access. This means that all interrupts will be blocked
  775. * for a predictable time (depending on the NVMC specification in the device's Product Specification
  776. * and the command parameters).
  777. * - This call will make the SoftDevice trigger a hardfault when the page is erased, if it is
  778. * protected.
  779. *
  780. *
  781. * @param[in] page_number Page number of the page to erase
  782. *
  783. * @retval ::NRF_ERROR_INTERNAL If a new session could not be opened due to an internal error.
  784. * @retval ::NRF_ERROR_INVALID_ADDR Tried to erase to a non existing flash page.
  785. * @retval ::NRF_ERROR_BUSY The previous command has not yet completed.
  786. * @retval ::NRF_ERROR_FORBIDDEN Tried to erase a page outside the application flash area.
  787. * @retval ::NRF_SUCCESS The command was accepted.
  788. */
  789. SVCALL(SD_FLASH_PAGE_ERASE, uint32_t, sd_flash_page_erase(uint32_t page_number));
  790. /**@brief Flash Protection set
  791. *
  792. * Commands to set the flash protection configuration registers.
  793. This sets the CONFIGx registers of the BPROT peripheral.
  794. *
  795. * @note Not all parameters are valid for all products. Some bits in each parameter may not be
  796. * valid for your product. Please refer your Product Specification for more details.
  797. *
  798. * @note To read the values read them directly. They are only write-protected.
  799. *
  800. * @note It is possible to use @ref sd_protected_register_write instead of this function.
  801. *
  802. * @param[in] block_cfg0 Value to be written to the configuration register.
  803. * @param[in] block_cfg1 Value to be written to the configuration register.
  804. * @param[in] block_cfg2 Value to be written to the configuration register.
  805. * @param[in] block_cfg3 Value to be written to the configuration register.
  806. *
  807. * @retval ::NRF_ERROR_NOT_SUPPORTED Non-zero value supplied to one or more of the unsupported parameters.
  808. * @retval ::NRF_SUCCESS Values successfully written to configuration registers.
  809. */
  810. 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));
  811. /**@brief Opens a session for radio timeslot requests.
  812. *
  813. * @note Only one session can be open at a time.
  814. * @note p_radio_signal_callback(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START) will be called when the radio timeslot
  815. * starts. From this point the NRF_RADIO and NRF_TIMER0 peripherals can be freely accessed
  816. * by the application.
  817. * @note p_radio_signal_callback(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_TIMER0) is called whenever the NRF_TIMER0
  818. * interrupt occurs.
  819. * @note p_radio_signal_callback(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_RADIO) is called whenever the NRF_RADIO
  820. * interrupt occurs.
  821. * @note p_radio_signal_callback() will be called at ARM interrupt priority level 0. This
  822. * implies that none of the sd_* API calls can be used from p_radio_signal_callback().
  823. *
  824. * @param[in] p_radio_signal_callback The signal callback.
  825. *
  826. * @retval ::NRF_ERROR_INVALID_ADDR p_radio_signal_callback is an invalid function pointer.
  827. * @retval ::NRF_ERROR_BUSY If session cannot be opened.
  828. * @retval ::NRF_ERROR_INTERNAL If a new session could not be opened due to an internal error.
  829. * @retval ::NRF_SUCCESS Otherwise.
  830. */
  831. SVCALL(SD_RADIO_SESSION_OPEN, uint32_t, sd_radio_session_open(nrf_radio_signal_callback_t p_radio_signal_callback));
  832. /**@brief Closes a session for radio timeslot requests.
  833. *
  834. * @note Any current radio timeslot will be finished before the session is closed.
  835. * @note If a radio timeslot is scheduled when the session is closed, it will be canceled.
  836. * @note The application cannot consider the session closed until the @ref NRF_EVT_RADIO_SESSION_CLOSED
  837. * event is received.
  838. *
  839. * @retval ::NRF_ERROR_FORBIDDEN If session not opened.
  840. * @retval ::NRF_ERROR_BUSY If session is currently being closed.
  841. * @retval ::NRF_SUCCESS Otherwise.
  842. */
  843. SVCALL(SD_RADIO_SESSION_CLOSE, uint32_t, sd_radio_session_close(void));
  844. /**@brief Requests a radio timeslot.
  845. *
  846. * @note The request type is determined by p_request->request_type, and can be one of @ref NRF_RADIO_REQ_TYPE_EARLIEST
  847. * and @ref NRF_RADIO_REQ_TYPE_NORMAL. The first request in a session must always be of type @ref NRF_RADIO_REQ_TYPE_EARLIEST.
  848. * @note For a normal request (@ref NRF_RADIO_REQ_TYPE_NORMAL), the start time of a radio timeslot is specified by
  849. * p_request->distance_us and is given relative to the start of the previous timeslot.
  850. * @note A too small p_request->distance_us will lead to a @ref NRF_EVT_RADIO_BLOCKED event.
  851. * @note Timeslots scheduled too close will lead to a @ref NRF_EVT_RADIO_BLOCKED event.
  852. * @note See the SoftDevice Specification for more on radio timeslot scheduling, distances and lengths.
  853. * @note If an opportunity for the first radio timeslot is not found before 100 ms after the call to this
  854. * function, it is not scheduled, and instead a @ref NRF_EVT_RADIO_BLOCKED event is sent.
  855. * The application may then try to schedule the first radio timeslot again.
  856. * @note Successful requests will result in nrf_radio_signal_callback_t(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START).
  857. * Unsuccessful requests will result in a @ref NRF_EVT_RADIO_BLOCKED event, see @ref NRF_SOC_EVTS.
  858. * @note The jitter in the start time of the radio timeslots is +/- @ref NRF_RADIO_START_JITTER_US us.
  859. * @note The nrf_radio_signal_callback_t(@ref NRF_RADIO_CALLBACK_SIGNAL_TYPE_START) call has a latency relative to the
  860. * specified radio timeslot start, but this does not affect the actual start time of the timeslot.
  861. * @note NRF_TIMER0 is reset at the start of the radio timeslot, and is clocked at 1MHz from the high frequency
  862. * (16 MHz) clock source. If p_request->hfclk_force_xtal is true, the high frequency clock is
  863. * guaranteed to be clocked from the external crystal.
  864. * @note The SoftDevice will neither access the NRF_RADIO peripheral nor the NRF_TIMER0 peripheral
  865. * during the radio timeslot.
  866. *
  867. * @param[in] p_request Pointer to the request parameters.
  868. *
  869. * @retval ::NRF_ERROR_FORBIDDEN If session not opened or the session is not IDLE.
  870. * @retval ::NRF_ERROR_INVALID_ADDR If the p_request pointer is invalid.
  871. * @retval ::NRF_ERROR_INVALID_PARAM If the parameters of p_request are not valid.
  872. * @retval ::NRF_SUCCESS Otherwise.
  873. */
  874. SVCALL(SD_RADIO_REQUEST, uint32_t, sd_radio_request(nrf_radio_request_t const * p_request));
  875. /**@brief Write register protected by the SoftDevice
  876. *
  877. * This function writes to a register that is write-protected by the SoftDevice. Please refer to your
  878. * SoftDevice Specification for more details about which registers that are protected by SoftDevice.
  879. * This function can write to the following protected peripheral:
  880. * - BPROT
  881. *
  882. * @note Protected registers may be read directly.
  883. * @note Register that are write-once will return @ref NRF_SUCCESS on second set, even the value in
  884. * the register has not changed. See the Product Specification for more details about register
  885. * properties.
  886. *
  887. * @param[in] p_register Pointer to register to be written.
  888. * @param[in] value Value to be written to the register.
  889. *
  890. * @retval ::NRF_ERROR_INVALID_ADDR This function can not write to the reguested register.
  891. * @retval ::NRF_SUCCESS Value successfully written to register.
  892. *
  893. */
  894. SVCALL(SD_PROTECTED_REGISTER_WRITE, uint32_t, sd_protected_register_write(volatile uint32_t * p_register, uint32_t value));
  895. /**@} */
  896. #ifdef __cplusplus
  897. }
  898. #endif
  899. #endif // NRF_SOC_H__
  900. /**@} */