1 /*
2 * Copyright (c) 2017, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other 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 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 /**
36 * @file
37 * This file implements debug helpers for the nRF 802.15.4 radio driver.
38 *
39 */
40
41 #include "nrf_802154_debug.h"
42
43 #include <stdint.h>
44
45 #include "nrfx.h"
46 #include "hal/nrf_gpio.h"
47 #include "hal/nrf_gpiote.h"
48 #include "hal/nrf_ppi.h"
49
50 /**
51 * @brief Initialize PPI to toggle GPIO pins on radio events.
52 */
radio_event_gpio_toggle_init(void)53 static void radio_event_gpio_toggle_init(void)
54 {
55 nrf_gpio_cfg_output(PIN_DBG_RADIO_EVT_END);
56 nrf_gpio_cfg_output(PIN_DBG_RADIO_EVT_DISABLED);
57 nrf_gpio_cfg_output(PIN_DBG_RADIO_EVT_READY);
58
59 nrf_gpiote_task_configure(GPIOTE_DBG_RADIO_EVT_END,
60 PIN_DBG_RADIO_EVT_END,
61 NRF_GPIOTE_POLARITY_TOGGLE,
62 NRF_GPIOTE_INITIAL_VALUE_HIGH);
63 nrf_gpiote_task_configure(GPIOTE_DBG_RADIO_EVT_DISABLED,
64 PIN_DBG_RADIO_EVT_DISABLED,
65 NRF_GPIOTE_POLARITY_TOGGLE,
66 NRF_GPIOTE_INITIAL_VALUE_HIGH);
67 nrf_gpiote_task_configure(GPIOTE_DBG_RADIO_EVT_READY,
68 PIN_DBG_RADIO_EVT_READY,
69 NRF_GPIOTE_POLARITY_TOGGLE,
70 NRF_GPIOTE_INITIAL_VALUE_HIGH);
71
72 nrf_gpiote_task_enable(GPIOTE_DBG_RADIO_EVT_END);
73 nrf_gpiote_task_enable(GPIOTE_DBG_RADIO_EVT_DISABLED);
74 nrf_gpiote_task_enable(GPIOTE_DBG_RADIO_EVT_READY);
75
76 nrf_ppi_channel_endpoint_setup((nrf_ppi_channel_t)PPI_DBG_RADIO_EVT_END,
77 (uint32_t)&NRF_RADIO->EVENTS_END,
78 nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_0));
79 nrf_ppi_channel_endpoint_setup((nrf_ppi_channel_t)PPI_DBG_RADIO_EVT_DISABLED,
80 (uint32_t)&NRF_RADIO->EVENTS_DISABLED,
81 nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_1));
82 nrf_ppi_channel_endpoint_setup((nrf_ppi_channel_t)PPI_DBG_RADIO_EVT_READY,
83 (uint32_t)&NRF_RADIO->EVENTS_READY,
84 nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_2));
85
86 nrf_ppi_channel_enable((nrf_ppi_channel_t)PPI_DBG_RADIO_EVT_END);
87 nrf_ppi_channel_enable((nrf_ppi_channel_t)PPI_DBG_RADIO_EVT_DISABLED);
88 nrf_ppi_channel_enable((nrf_ppi_channel_t)PPI_DBG_RADIO_EVT_READY);
89 }
90
91 /**
92 * @brief Initialize GPIO to set it simulated arbiter events.
93 */
raal_simulator_gpio_init(void)94 static void raal_simulator_gpio_init(void)
95 {
96 #if RAAL_SIMULATOR
97 nrf_gpio_cfg_output(PIN_DBG_TIMESLOT_ACTIVE);
98 nrf_gpio_cfg_output(PIN_DBG_RAAL_CRITICAL_SECTION);
99 #endif
100 }
101
nrf_802154_debug_gpio_init(void)102 void nrf_802154_debug_gpio_init(void)
103 {
104 radio_event_gpio_toggle_init();
105 raal_simulator_gpio_init();
106 }
107