nrf_soc.h 52 KB

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