|
10 | 10 | #include <mpsl_dppi_protocol_api.h> |
11 | 11 | #include <nrfx_gpiote.h> |
12 | 12 | #include <helpers/nrfx_gppi.h> |
13 | | -#include <nrfx_dppi.h> |
14 | 13 | #include <hal/nrf_radio.h> |
15 | 14 | #include <zephyr/device.h> |
16 | 15 | #include <zephyr/drivers/gpio.h> |
17 | 16 |
|
18 | 17 | const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(20); |
19 | | -const nrfx_dppi_t dppi_radio_domain = NRFX_DPPI_INSTANCE(10); |
20 | | -const nrfx_dppi_t dppi_gpio_domain = NRFX_DPPI_INSTANCE(20); |
21 | 18 | LOG_MODULE_REGISTER(mpsl_radio_pin_debug, CONFIG_MPSL_LOG_LEVEL); |
22 | 19 |
|
23 | 20 | static int m_ppi_config(void) |
24 | 21 | { |
25 | | - uint8_t gppi_chan_radio_ready; |
26 | | - uint8_t gppi_chan_radio_disabled; |
27 | | - uint8_t gppi_chan_radio_address; |
28 | | - uint8_t gppi_chan_radio_end; |
29 | | - |
30 | | - uint8_t dppi_chan_gpio_ready; |
31 | | - uint8_t dppi_chan_gpio_disabled; |
32 | | - uint8_t dppi_chan_gpio_address; |
33 | | - uint8_t dppi_chan_gpio_end; |
34 | | - |
35 | | - if (nrfx_gppi_channel_alloc(&gppi_chan_radio_ready) != |
36 | | - NRFX_SUCCESS) { |
37 | | - LOG_ERR("Failed allocating gppi_chan_radio_ready"); |
38 | | - return -ENOMEM; |
39 | | - } |
40 | | - |
41 | | - if (nrfx_gppi_channel_alloc(&gppi_chan_radio_disabled) != |
42 | | - NRFX_SUCCESS) { |
43 | | - LOG_ERR("Failed allocating gppi_chan_radio_disabled"); |
44 | | - return -ENOMEM; |
45 | | - } |
46 | | - |
47 | | - if (nrfx_gppi_channel_alloc(&gppi_chan_radio_address) != |
48 | | - NRFX_SUCCESS) { |
49 | | - LOG_ERR("Failed allocating gppi_chan_radio_address"); |
50 | | - return -ENOMEM; |
51 | | - } |
52 | | - |
53 | | - if (nrfx_gppi_channel_alloc(&gppi_chan_radio_end) != |
54 | | - NRFX_SUCCESS) { |
55 | | - LOG_ERR("Failed allocating gppi_chan_radio_end"); |
56 | | - return -ENOMEM; |
57 | | - } |
58 | | - |
59 | | - if (nrfx_dppi_channel_alloc(&dppi_gpio_domain, &dppi_chan_gpio_ready) != |
60 | | - NRFX_SUCCESS) { |
61 | | - LOG_ERR("Failed allocating dppi_chan_gpio_ready"); |
62 | | - return -ENOMEM; |
63 | | - } |
64 | | - |
65 | | - if (nrfx_dppi_channel_alloc(&dppi_gpio_domain, &dppi_chan_gpio_disabled) != |
66 | | - NRFX_SUCCESS) { |
67 | | - LOG_ERR("Failed allocating dppi_chan_gpio_disabled"); |
68 | | - return -ENOMEM; |
69 | | - } |
70 | | - |
71 | | - if (nrfx_dppi_channel_alloc(&dppi_gpio_domain, &dppi_chan_gpio_address) != |
72 | | - NRFX_SUCCESS) { |
73 | | - LOG_ERR("Failed allocating dppi_chan_gpio_address"); |
74 | | - return -ENOMEM; |
75 | | - } |
76 | | - |
77 | | - if (nrfx_dppi_channel_alloc(&dppi_gpio_domain, &dppi_chan_gpio_end) != |
78 | | - NRFX_SUCCESS) { |
79 | | - LOG_ERR("Failed allocating dppi_chan_gpio_end"); |
80 | | - return -ENOMEM; |
81 | | - } |
82 | | - |
83 | | - if (nrfx_gppi_edge_connection_setup(gppi_chan_radio_ready, |
84 | | - &dppi_radio_domain, |
85 | | - MPSL_DPPI_RADIO_PUBLISH_READY_CHANNEL_IDX, |
86 | | - &dppi_gpio_domain, |
87 | | - dppi_chan_gpio_ready) != NRFX_SUCCESS) { |
88 | | - LOG_ERR("Failed edge setup chan ready"); |
89 | | - return -ENOMEM; |
90 | | - } |
91 | | - |
92 | | - if (nrfx_gppi_edge_connection_setup(gppi_chan_radio_disabled, |
93 | | - &dppi_radio_domain, |
94 | | - MPSL_DPPI_RADIO_PUBLISH_DISABLED_CH_IDX, |
95 | | - &dppi_gpio_domain, |
96 | | - dppi_chan_gpio_disabled) != NRFX_SUCCESS) { |
97 | | - LOG_ERR("Failed edge setup chan disabled"); |
98 | | - return -ENOMEM; |
99 | | - } |
100 | | - |
101 | | - if (nrfx_gppi_edge_connection_setup(gppi_chan_radio_address, |
102 | | - &dppi_radio_domain, |
103 | | - MPSL_DPPI_RADIO_PUBLISH_ADDRESS_CHANNEL_IDX, |
104 | | - &dppi_gpio_domain, |
105 | | - dppi_chan_gpio_address) != NRFX_SUCCESS) { |
106 | | - LOG_ERR("Failed edge setup chan address"); |
107 | | - return -ENOMEM; |
108 | | - } |
109 | | - |
110 | | - /* Setup a PPI bridge between the radio domain and the domain of the GPIO pin. */ |
111 | | - if (nrfx_gppi_edge_connection_setup(gppi_chan_radio_address, |
112 | | - &dppi_radio_domain, |
113 | | - MPSL_DPPI_RADIO_PUBLISH_END_CHANNEL_IDX, |
114 | | - &dppi_gpio_domain, |
115 | | - dppi_chan_gpio_end) != NRFX_SUCCESS) { |
116 | | - LOG_ERR("Failed edge setup chan end"); |
117 | | - return -ENOMEM; |
118 | | - } |
119 | | - |
120 | | - nrf_gpiote_subscribe_set( |
121 | | - gpiote.p_reg, |
122 | | - nrfx_gpiote_set_task_address_get( |
123 | | - &gpiote, CONFIG_MPSL_PIN_DEBUG_RADIO_READY_AND_DISABLED_PIN), |
124 | | - dppi_chan_gpio_ready); |
125 | | - |
126 | | - nrf_gpiote_subscribe_set( |
127 | | - gpiote.p_reg, |
128 | | - nrfx_gpiote_clr_task_address_get( |
129 | | - &gpiote, CONFIG_MPSL_PIN_DEBUG_RADIO_READY_AND_DISABLED_PIN), |
130 | | - dppi_chan_gpio_disabled); |
131 | | - |
132 | | - nrf_gpiote_subscribe_set( |
133 | | - gpiote.p_reg, |
134 | | - nrfx_gpiote_set_task_address_get(&gpiote, |
135 | | - CONFIG_MPSL_PIN_DEBUG_RADIO_ADDRESS_AND_END_PIN), |
136 | | - dppi_chan_gpio_address); |
137 | | - |
138 | | - nrf_gpiote_subscribe_set( |
139 | | - gpiote.p_reg, |
140 | | - nrfx_gpiote_clr_task_address_get(&gpiote, |
141 | | - CONFIG_MPSL_PIN_DEBUG_RADIO_ADDRESS_AND_END_PIN), |
142 | | - dppi_chan_gpio_end); |
143 | | - |
144 | | - nrfx_gppi_channels_enable(NRFX_BIT(gppi_chan_radio_ready) | |
145 | | - NRFX_BIT(gppi_chan_radio_disabled) | |
146 | | - NRFX_BIT(gppi_chan_radio_address) | |
147 | | - NRFX_BIT(gppi_chan_radio_end)); |
148 | | - |
149 | | - if (nrfx_dppi_channel_enable(&dppi_gpio_domain, dppi_chan_gpio_ready) != NRFX_SUCCESS) { |
150 | | - LOG_ERR("Failed chan enable gpio_ready"); |
151 | | - return -ENOMEM; |
152 | | - } |
153 | | - |
154 | | - if (nrfx_dppi_channel_enable(&dppi_gpio_domain, dppi_chan_gpio_disabled) != NRFX_SUCCESS) { |
155 | | - LOG_ERR("Failed chan enable gpio_disabled"); |
156 | | - return -ENOMEM; |
157 | | - } |
158 | | - |
159 | | - if (nrfx_dppi_channel_enable(&dppi_gpio_domain, dppi_chan_gpio_address) != NRFX_SUCCESS) { |
160 | | - LOG_ERR("Failed chan enable gpio_address"); |
161 | | - return -ENOMEM; |
162 | | - } |
| 22 | + uint32_t rad_domain = nrfx_gppi_domain_id_get(NRF_DPPIC10); |
| 23 | + uint32_t dst_domain = nrfx_gppi_domain_id_get(gpiote.p_reg); |
| 24 | + nrfx_gppi_resource_t rad_resource; |
| 25 | + nrfx_gppi_handle_t handle; |
| 26 | + uint32_t tep[4]; |
| 27 | + int err; |
| 28 | + static const uint32_t pub_ch[] = { |
| 29 | + MPSL_DPPI_RADIO_PUBLISH_READY_CHANNEL_IDX, |
| 30 | + MPSL_DPPI_RADIO_PUBLISH_DISABLED_CH_IDX, |
| 31 | + MPSL_DPPI_RADIO_PUBLISH_ADDRESS_CHANNEL_IDX, |
| 32 | + MPSL_DPPI_RADIO_PUBLISH_END_CHANNEL_IDX |
| 33 | + }; |
163 | 34 |
|
164 | | - if (nrfx_dppi_channel_enable(&dppi_gpio_domain, dppi_chan_gpio_end) != NRFX_SUCCESS) { |
165 | | - LOG_ERR("Failed chan enable gpio_end"); |
166 | | - return -ENOMEM; |
| 35 | + tep[0] = nrfx_gpiote_set_task_address_get(&gpiote, |
| 36 | + CONFIG_MPSL_PIN_DEBUG_RADIO_READY_AND_DISABLED_PIN); |
| 37 | + tep[1] = nrfx_gpiote_clr_task_address_get(&gpiote, |
| 38 | + CONFIG_MPSL_PIN_DEBUG_RADIO_READY_AND_DISABLED_PIN); |
| 39 | + tep[2] = nrfx_gpiote_set_task_address_get(&gpiote, |
| 40 | + CONFIG_MPSL_PIN_DEBUG_RADIO_ADDRESS_AND_END_PIN); |
| 41 | + tep[3] = nrfx_gpiote_clr_task_address_get(&gpiote, |
| 42 | + CONFIG_MPSL_PIN_DEBUG_RADIO_ADDRESS_AND_END_PIN); |
| 43 | + rad_resource.rad_domain = nrfx_gppi_domain_id_get(NRF_DPPIC10); |
| 44 | + |
| 45 | + for (size_t i = 0; i < ARRAY_SIZE(pub_ch); i++) { |
| 46 | + rad_resource.channel = pub_ch[i]; |
| 47 | + err = nrfx_gppi_ext_conn_alloc(rad_domain, dst_domain, &handle, &rad_resource); |
| 48 | + if (err < 0) { |
| 49 | + return err; |
| 50 | + } |
| 51 | + nrfx_gppi_ep_attach(handle, tep[i]); |
| 52 | + /* Channel in radio domain is not enabled by this function. */ |
| 53 | + nrfx_gppi_conn_enable(handle); |
167 | 54 | } |
168 | 55 |
|
169 | 56 | return 0; |
|
0 commit comments