1 /*
2  * Copyright (c) 2020 - 2023, 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 #include "nrf_802154_sl_rsch.h"
36 
37 #include <assert.h>
38 #include <stddef.h>
39 #include <string.h>
40 #include <nrfx.h>
41 
42 #include "rsch/nrf_802154_rsch.h"
43 #include "platform/nrf_802154_clock.h"
44 
45 static rsch_prio_t m_prev_prio;
46 static bool        m_ready;
47 
48 /**
49  * @brief Notifies the core that the approved RSCH priority has changed.
50  *
51  * @note This function is called from the critical section context and does not preempt
52  *       other critical sections.
53  *
54  * @param[in]  prio  Approved priority level.
55  */
56 extern void nrf_802154_rsch_crit_sect_prio_changed(rsch_prio_t prio);
57 
58 /***************************************************************************************************
59  * Public API
60  **************************************************************************************************/
61 
nrf_802154_rsch_init(void)62 void nrf_802154_rsch_init(void)
63 {
64     m_ready     = false;
65     m_prev_prio = RSCH_PRIO_IDLE;
66 }
67 
nrf_802154_rsch_uninit(void)68 void nrf_802154_rsch_uninit(void)
69 {
70     // Intenionally empty
71 }
72 
nrf_802154_rsch_continuous_ended(void)73 void nrf_802154_rsch_continuous_ended(void)
74 {
75     // Intentionally empty
76 }
77 
nrf_802154_rsch_timeslot_request(uint32_t length_us)78 bool nrf_802154_rsch_timeslot_request(uint32_t length_us)
79 {
80     (void)length_us;
81 
82     assert(m_ready);
83 
84     return true;
85 }
86 
nrf_802154_rsch_timeslot_is_requested(void)87 bool nrf_802154_rsch_timeslot_is_requested(void)
88 {
89     return false;
90 }
91 
nrf_802154_rsch_prec_is_approved(rsch_prec_t prec,rsch_prio_t prio)92 bool nrf_802154_rsch_prec_is_approved(rsch_prec_t prec, rsch_prio_t prio)
93 {
94     return prio == RSCH_PRIO_IDLE ? true : m_ready;
95 }
96 
nrf_802154_rsch_timeslot_us_left_get(void)97 uint32_t nrf_802154_rsch_timeslot_us_left_get(void)
98 {
99     return UINT32_MAX;
100 }
101 
nrf_802154_clock_hfclk_ready(void)102 void nrf_802154_clock_hfclk_ready(void)
103 {
104     m_ready = true;
105     nrf_802154_rsch_crit_sect_prio_changed(RSCH_PRIO_MAX);
106 }
107 
nrf_802154_rsch_crit_sect_prio_request(rsch_prio_t prio)108 void nrf_802154_rsch_crit_sect_prio_request(rsch_prio_t prio)
109 {
110     if (m_prev_prio != prio)
111     {
112         if (prio == RSCH_PRIO_IDLE)
113         {
114             nrf_802154_clock_hfclk_stop();
115 
116             m_ready = false;
117 
118             nrf_802154_rsch_crit_sect_prio_changed(RSCH_PRIO_IDLE);
119         }
120         else if (m_prev_prio == RSCH_PRIO_IDLE)
121         {
122             assert(!m_ready);
123 
124             nrf_802154_clock_hfclk_start();
125         }
126         else
127         {
128             // Intentionally empty
129         }
130 
131         m_prev_prio = prio;
132     }
133 }
134 
nrf_802154_rsch_crit_sect_init(void)135 void nrf_802154_rsch_crit_sect_init(void)
136 {
137     // Intentionally empty
138 }
139 
nrf_802154_critical_section_rsch_enter(void)140 void nrf_802154_critical_section_rsch_enter(void)
141 {
142     // Intentionally empty
143 }
144 
nrf_802154_critical_section_rsch_exit(void)145 void nrf_802154_critical_section_rsch_exit(void)
146 {
147     // Intentionally empty
148 }
149 
nrf_802154_critical_section_rsch_event_is_pending(void)150 bool nrf_802154_critical_section_rsch_event_is_pending(void)
151 {
152     return false;
153 }
154 
nrf_802154_critical_section_rsch_process_pending(void)155 void nrf_802154_critical_section_rsch_process_pending(void)
156 {
157     // Intentionally empty
158 }
159 
nrf_802154_rsch_delayed_timeslot_request(const rsch_dly_ts_param_t * p_dly_ts_param)160 bool nrf_802154_rsch_delayed_timeslot_request(const rsch_dly_ts_param_t * p_dly_ts_param)
161 {
162     (void)p_dly_ts_param;
163 
164     return false;
165 }
166 
nrf_802154_rsch_delayed_timeslot_cancel(rsch_dly_ts_id_t dly_ts_id,bool handler)167 bool nrf_802154_rsch_delayed_timeslot_cancel(rsch_dly_ts_id_t dly_ts_id, bool handler)
168 {
169     (void)dly_ts_id;
170     (void)handler;
171 
172     return false;
173 }
174 
nrf_802154_rsch_delayed_timeslot_priority_update(rsch_dly_ts_id_t dly_ts_id,rsch_prio_t dly_ts_prio)175 bool nrf_802154_rsch_delayed_timeslot_priority_update(rsch_dly_ts_id_t dly_ts_id,
176                                                       rsch_prio_t      dly_ts_prio)
177 {
178     (void)dly_ts_id;
179     (void)dly_ts_prio;
180 
181     return false;
182 }
183 
nrf_802154_rsch_delayed_timeslot_ppi_update(uint32_t ppi_channel)184 bool nrf_802154_rsch_delayed_timeslot_ppi_update(uint32_t ppi_channel)
185 {
186     (void)ppi_channel;
187 
188     return false;
189 }
190