dragoon  4383
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
nrf_soc.h
1 /*
2  * Copyright (c) 2015 - 2017, 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 
47 #ifndef NRF_SOC_H__
48 #define NRF_SOC_H__
49 
50 #include <stdint.h>
51 #include <stdbool.h>
52 #include "nrf_svc.h"
53 #include "nrf.h"
54 
55 #include "nrf_error_soc.h"
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
65 #define SOC_SVC_BASE (0x20)
66 #define SOC_SVC_BASE_NOT_AVAILABLE (0x2B)
69 #define NRF_RADIO_NOTIFICATION_INACTIVE_GUARANTEED_TIME_US (62)
70 
72 #define NRF_RADIO_MINIMUM_TIMESLOT_LENGTH_EXTENSION_TIME_US (200)
73 
74 #define SOC_ECB_KEY_LENGTH (16)
75 #define SOC_ECB_CLEARTEXT_LENGTH (16)
76 #define SOC_ECB_CIPHERTEXT_LENGTH (SOC_ECB_CLEARTEXT_LENGTH)
78 #define SD_EVT_IRQn (SWI2_EGU2_IRQn)
79 #define SD_EVT_IRQHandler (SWI2_EGU2_IRQHandler)
81 #define RADIO_NOTIFICATION_IRQn (SWI1_EGU1_IRQn)
82 #define RADIO_NOTIFICATION_IRQHandler (SWI1_EGU1_IRQHandler)
84 #define NRF_RADIO_LENGTH_MIN_US (100)
85 #define NRF_RADIO_LENGTH_MAX_US (100000)
87 #define NRF_RADIO_DISTANCE_MAX_US (128000000UL - 1UL)
89 #define NRF_RADIO_EARLIEST_TIMEOUT_MAX_US (128000000UL - 1UL)
91 #define NRF_RADIO_START_JITTER_US (2)
99 enum NRF_SOC_SVCS
100 {
102  SD_PPI_CHANNEL_ENABLE_SET,
103  SD_PPI_CHANNEL_ENABLE_CLR,
104  SD_PPI_CHANNEL_ASSIGN,
105  SD_PPI_GROUP_TASK_ENABLE,
106  SD_PPI_GROUP_TASK_DISABLE,
107  SD_PPI_GROUP_ASSIGN,
108  SD_PPI_GROUP_GET,
109  SD_FLASH_PAGE_ERASE,
110  SD_FLASH_WRITE,
111  SD_FLASH_PROTECT,
113  SD_MUTEX_ACQUIRE,
114  SD_MUTEX_RELEASE,
115  SD_RAND_APPLICATION_POOL_CAPACITY_GET,
116  SD_RAND_APPLICATION_BYTES_AVAILABLE_GET,
117  SD_RAND_APPLICATION_VECTOR_GET,
118  SD_POWER_MODE_SET,
119  SD_POWER_SYSTEM_OFF,
120  SD_POWER_RESET_REASON_GET,
121  SD_POWER_RESET_REASON_CLR,
122  SD_POWER_POF_ENABLE,
123  SD_POWER_POF_THRESHOLD_SET,
124  SD_POWER_RAM_POWER_SET,
125  SD_POWER_RAM_POWER_CLR,
126  SD_POWER_RAM_POWER_GET,
127  SD_POWER_GPREGRET_SET,
128  SD_POWER_GPREGRET_CLR,
129  SD_POWER_GPREGRET_GET,
130  SD_POWER_DCDC_MODE_SET,
131  SD_APP_EVT_WAIT,
132  SD_CLOCK_HFCLK_REQUEST,
133  SD_CLOCK_HFCLK_RELEASE,
134  SD_CLOCK_HFCLK_IS_RUNNING,
135  SD_RADIO_NOTIFICATION_CFG_SET,
136  SD_ECB_BLOCK_ENCRYPT,
137  SD_ECB_BLOCKS_ENCRYPT,
138  SD_RADIO_SESSION_OPEN,
139  SD_RADIO_SESSION_CLOSE,
140  SD_RADIO_REQUEST,
141  SD_EVT_GET,
142  SD_TEMP_GET,
143  SVC_SOC_LAST
144 };
145 
147 enum NRF_MUTEX_VALUES
148 {
149  NRF_MUTEX_FREE,
150  NRF_MUTEX_TAKEN
151 };
152 
154 enum NRF_POWER_MODES
155 {
158 };
160 
163 {
176 };
178 
181 {
184 };
188 {
196 };
198 
201 {
206 };
210 {
216 };
224 {
229 };
233 {
246 };
247 
250 {
253 };
257 {
260 };
263 enum NRF_SOC_EVTS
264 {
274  NRF_EVT_NUMBER_OF_EVTS
275 };
276 
286 typedef volatile uint8_t nrf_mutex_t;
287 
289 typedef struct
290 {
291  uint8_t hfclk;
292  uint8_t priority;
293  uint32_t length_us;
294  uint32_t timeout_us;
298 typedef struct
299 {
300  uint8_t hfclk;
301  uint8_t priority;
302  uint32_t distance_us;
303  uint32_t length_us;
307 typedef struct
308 {
309  uint8_t request_type;
310  union
311  {
314  } params;
316 
318 typedef struct
319 {
320  uint8_t callback_action;
321  union
322  {
323  struct
324  {
325  nrf_radio_request_t * p_next;
326  } request;
327  struct
328  {
329  uint32_t length_us;
330  } extend;
331  } params;
333 
346 typedef nrf_radio_signal_callback_return_param_t * (*nrf_radio_signal_callback_t) (uint8_t signal_type);
347 
349 typedef uint8_t soc_ecb_key_t[SOC_ECB_KEY_LENGTH];
354 typedef struct
355 {
356  soc_ecb_key_t key;
357  soc_ecb_cleartext_t cleartext;
358  soc_ecb_ciphertext_t ciphertext;
363 typedef struct
364 {
365  soc_ecb_key_t const * p_key;
366  soc_ecb_cleartext_t const * p_cleartext;
367  soc_ecb_ciphertext_t * p_ciphertext;
381 SVCALL(SD_MUTEX_NEW, uint32_t, sd_mutex_new(nrf_mutex_t * p_mutex));
382 
390 SVCALL(SD_MUTEX_ACQUIRE, uint32_t, sd_mutex_acquire(nrf_mutex_t * p_mutex));
391 
398 SVCALL(SD_MUTEX_RELEASE, uint32_t, sd_mutex_release(nrf_mutex_t * p_mutex));
399 
406 SVCALL(SD_RAND_APPLICATION_POOL_CAPACITY_GET, uint32_t, sd_rand_application_pool_capacity_get(uint8_t * p_pool_capacity));
407 
414 SVCALL(SD_RAND_APPLICATION_BYTES_AVAILABLE_GET, uint32_t, sd_rand_application_bytes_available_get(uint8_t * p_bytes_available));
415 
424 SVCALL(SD_RAND_APPLICATION_VECTOR_GET, uint32_t, sd_rand_application_vector_get(uint8_t * p_buff, uint8_t length));
425 
432 SVCALL(SD_POWER_RESET_REASON_GET, uint32_t, sd_power_reset_reason_get(uint32_t * p_reset_reason));
433 
440 SVCALL(SD_POWER_RESET_REASON_CLR, uint32_t, sd_power_reset_reason_clr(uint32_t reset_reason_clr_msk));
441 
449 SVCALL(SD_POWER_MODE_SET, uint32_t, sd_power_mode_set(uint8_t power_mode));
450 
455 SVCALL(SD_POWER_SYSTEM_OFF, uint32_t, sd_power_system_off(void));
456 
466 SVCALL(SD_POWER_POF_ENABLE, uint32_t, sd_power_pof_enable(uint8_t pof_enable));
467 
475 SVCALL(SD_POWER_POF_THRESHOLD_SET, uint32_t, sd_power_pof_threshold_set(uint8_t threshold));
476 
484 SVCALL(SD_POWER_RAM_POWER_SET, uint32_t, sd_power_ram_power_set(uint8_t index, uint32_t ram_powerset));
485 
493 SVCALL(SD_POWER_RAM_POWER_CLR, uint32_t, sd_power_ram_power_clr(uint8_t index, uint32_t ram_powerclr));
494 
502 SVCALL(SD_POWER_RAM_POWER_GET, uint32_t, sd_power_ram_power_get(uint8_t index, uint32_t * p_ram_power));
503 
511 SVCALL(SD_POWER_GPREGRET_SET, uint32_t, sd_power_gpregret_set(uint32_t gpregret_id, uint32_t gpregret_msk));
512 
520 SVCALL(SD_POWER_GPREGRET_CLR, uint32_t, sd_power_gpregret_clr(uint32_t gpregret_id, uint32_t gpregret_msk));
521 
529 SVCALL(SD_POWER_GPREGRET_GET, uint32_t, sd_power_gpregret_get(uint32_t gpregret_id, uint32_t *p_gpregret));
530 
540 SVCALL(SD_POWER_DCDC_MODE_SET, uint32_t, sd_power_dcdc_mode_set(uint8_t dcdc_mode));
541 
552 SVCALL(SD_CLOCK_HFCLK_REQUEST, uint32_t, sd_clock_hfclk_request(void));
553 
563 SVCALL(SD_CLOCK_HFCLK_RELEASE, uint32_t, sd_clock_hfclk_release(void));
564 
574 SVCALL(SD_CLOCK_HFCLK_IS_RUNNING, uint32_t, sd_clock_hfclk_is_running(uint32_t * p_is_running));
575 
602 SVCALL(SD_APP_EVT_WAIT, uint32_t, sd_app_evt_wait(void));
603 
610 SVCALL(SD_PPI_CHANNEL_ENABLE_GET, uint32_t, sd_ppi_channel_enable_get(uint32_t * p_channel_enable));
611 
618 SVCALL(SD_PPI_CHANNEL_ENABLE_SET, uint32_t, sd_ppi_channel_enable_set(uint32_t channel_enable_set_msk));
619 
626 SVCALL(SD_PPI_CHANNEL_ENABLE_CLR, uint32_t, sd_ppi_channel_enable_clr(uint32_t channel_enable_clr_msk));
627 
637 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));
638 
646 SVCALL(SD_PPI_GROUP_TASK_ENABLE, uint32_t, sd_ppi_group_task_enable(uint8_t group_num));
647 
655 SVCALL(SD_PPI_GROUP_TASK_DISABLE, uint32_t, sd_ppi_group_task_disable(uint8_t group_num));
656 
665 SVCALL(SD_PPI_GROUP_ASSIGN, uint32_t, sd_ppi_group_assign(uint8_t group_num, uint32_t channel_msk));
666 
675 SVCALL(SD_PPI_GROUP_GET, uint32_t, sd_ppi_group_get(uint8_t group_num, uint32_t * p_channel_msk));
676 
706 SVCALL(SD_RADIO_NOTIFICATION_CFG_SET, uint32_t, sd_radio_notification_cfg_set(uint8_t type, uint8_t distance));
707 
722 SVCALL(SD_ECB_BLOCK_ENCRYPT, uint32_t, sd_ecb_block_encrypt(nrf_ecb_hal_data_t * p_ecb_data));
723 
739 SVCALL(SD_ECB_BLOCKS_ENCRYPT, uint32_t, sd_ecb_blocks_encrypt(uint8_t block_count, nrf_ecb_hal_data_block_t * p_data_blocks));
740 
750 SVCALL(SD_EVT_GET, uint32_t, sd_evt_get(uint32_t * p_evt_id));
751 
761 SVCALL(SD_TEMP_GET, uint32_t, sd_temp_get(int32_t * p_temp));
762 
796 SVCALL(SD_FLASH_WRITE, uint32_t, sd_flash_write(uint32_t * p_dst, uint32_t const * p_src, uint32_t size));
797 
798 
826 SVCALL(SD_FLASH_PAGE_ERASE, uint32_t, sd_flash_page_erase(uint32_t page_number));
827 
828 
844 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));
845 
866  SVCALL(SD_RADIO_SESSION_OPEN, uint32_t, sd_radio_session_open(nrf_radio_signal_callback_t p_radio_signal_callback));
867 
879  SVCALL(SD_RADIO_SESSION_CLOSE, uint32_t, sd_radio_session_close(void));
880 
911  SVCALL(SD_RADIO_REQUEST, uint32_t, sd_radio_request(nrf_radio_request_t const * p_request));
912 
915 #ifdef __cplusplus
916 }
917 #endif
918 #endif // NRF_SOC_H__
919