Skip to content

Commit e044680

Browse files
committed
Mark timeslot exit on sleep state enter.
1 parent 7aefe04 commit e044680

File tree

10 files changed

+110
-70
lines changed

10 files changed

+110
-70
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
*.orig
44
.deps/
55
.dirstamp
6+
build/
67
cmock/
8+
gcc/

src/nrf_802154_core.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ static void falling_asleep_terminate(void)
886886
static void sleep_terminate(void)
887887
{
888888
nrf_802154_priority_drop_timeslot_exit_terminate();
889+
nrf_raal_continuous_mode_enter();
889890
}
890891

891892
/** Terminate RX procedure. */
@@ -1108,13 +1109,10 @@ static bool current_operation_terminate(nrf_802154_term_t term_lvl,
11081109
switch (m_state)
11091110
{
11101111
case RADIO_STATE_SLEEP:
1111-
sleep_terminate();
1112-
11131112
if (req_orig != REQ_ORIG_RAAL)
11141113
{
1115-
// Enter continuous mode unless terminating current operation is requested by
1116-
// RAAL during timeslot end procedure.
1117-
nrf_raal_continuous_mode_enter();
1114+
// Terminate sleep state unless it is requested by RAAL during timeslot end.
1115+
sleep_terminate();
11181116
}
11191117

11201118
break;
@@ -1249,6 +1247,7 @@ static bool current_operation_terminate(nrf_802154_term_t term_lvl,
12491247
static void sleep_init(void)
12501248
{
12511249
nrf_802154_priority_drop_timeslot_exit();
1250+
m_timeslot_is_granted = false;
12521251
}
12531252

12541253
/** Initialize Falling Asleep operation. */
@@ -1601,7 +1600,10 @@ void nrf_raal_timeslot_started(void)
16011600
nrf_radio_init();
16021601
irq_init();
16031602

1604-
m_timeslot_is_granted = true;
1603+
if (m_state != RADIO_STATE_SLEEP)
1604+
{
1605+
m_timeslot_is_granted = true;
1606+
}
16051607

16061608
assert(nrf_radio_shorts_get() == SHORTS_IDLE);
16071609

@@ -1661,12 +1663,12 @@ void nrf_raal_timeslot_ended(void)
16611663
nrf_radio_reset();
16621664
nrf_fem_control_pin_clear();
16631665

1664-
m_timeslot_is_granted = false;
1665-
16661666
result = current_operation_terminate(NRF_802154_TERM_802154, REQ_ORIG_RAAL, false);
16671667
assert(result);
16681668
(void)result;
16691669

1670+
m_timeslot_is_granted = false;
1671+
16701672
switch (m_state)
16711673
{
16721674
case RADIO_STATE_SLEEP:

src/raal/single_phy/single_phy.c

+19-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444

4545
#include "platform/clock/nrf_802154_clock.h"
4646

47-
static bool m_continuous;
47+
static bool m_continuous;
48+
static volatile bool m_critical_section;
49+
static volatile bool m_started_pending;
4850

4951
void nrf_raal_init(void)
5052
{
@@ -93,15 +95,28 @@ uint32_t nrf_raal_timeslot_us_left_get(void)
9395

9496
void nrf_raal_critical_section_enter(void)
9597
{
96-
// Intentionally empty.
98+
m_critical_section = true;
9799
}
98100

99101
void nrf_raal_critical_section_exit(void)
100102
{
101-
// Intentionally empty.
103+
m_critical_section = false;
104+
105+
if (m_started_pending)
106+
{
107+
nrf_raal_timeslot_started();
108+
m_started_pending = false;
109+
}
102110
}
103111

104112
void nrf_802154_clock_hfclk_ready(void)
105113
{
106-
nrf_raal_timeslot_started();
114+
if (m_critical_section)
115+
{
116+
m_started_pending = true;
117+
}
118+
else
119+
{
120+
nrf_raal_timeslot_started();
121+
}
107122
}

test/unit tests/fsm_cca/unity_test.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ static void verify_receive_begin_finds_free_buffer(void)
157157

158158
static void verify_complete_receive_begin(void)
159159
{
160-
nrf_raal_timeslot_is_granted_ExpectAndReturn(true);
160+
m_timeslot_is_granted = true;
161+
161162
verify_setting_tx_power();
162163
verify_receive_begin_setup(NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK |
163164
NRF_RADIO_SHORT_END_DISABLE_MASK |
@@ -328,8 +329,6 @@ static void verify_cca_terminate_periph_reset(bool in_timeslot)
328329
nrf_ppi_channel_remove_from_group_Expect(PPI_EGU_RAMP_UP, PPI_CHGRP0);
329330
nrf_ppi_fork_endpoint_setup_Expect(PPI_EGU_RAMP_UP, 0);
330331

331-
nrf_raal_timeslot_is_granted_ExpectAndReturn(in_timeslot);
332-
333332
if (in_timeslot)
334333
{
335334
nrf_radio_int_disable_Expect(NRF_RADIO_INT_CCAIDLE_MASK | NRF_RADIO_INT_CCABUSY_MASK);
@@ -340,13 +339,17 @@ static void verify_cca_terminate_periph_reset(bool in_timeslot)
340339

341340
void test_cca_terminate_ShallNotModifyRadioRegistersOutOfTimeslot(void)
342341
{
342+
m_timeslot_is_granted = false;
343+
343344
verify_cca_terminate_periph_reset(false);
344345

345346
cca_terminate();
346347
}
347348

348349
void test_cca_terminate_ShallResetPeriphAndTriggerDisableTask(void)
349350
{
351+
m_timeslot_is_granted = true;
352+
350353
verify_cca_terminate_periph_reset(true);
351354

352355
cca_terminate();

test/unit tests/fsm_cont_carrier/unity_test.c

+15-7
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void nrf_802154_tx_ack_started(void){}
9090

9191
void test_continuous_carrier_begin_ShallDoNothingIfOutOfTimeslot(void)
9292
{
93-
nrf_raal_timeslot_is_granted_ExpectAndReturn(false);
93+
m_timeslot_is_granted = false;
9494

9595
continuous_carrier_init(true);
9696
}
@@ -103,8 +103,6 @@ static void verify_continuous_carrier_begin_periph_setup(void)
103103
uint32_t task_addr;
104104
uint32_t fork_addr;
105105

106-
nrf_raal_timeslot_is_granted_ExpectAndReturn(true);
107-
108106
nrf_fem_control_ppi_enable_Expect(NRF_FEM_CONTROL_PA_PIN, NRF_TIMER_CC_CHANNEL2);
109107
nrf_fem_control_timer_set_Expect(NRF_FEM_CONTROL_PA_PIN, NRF_TIMER_CC_CHANNEL2, NRF_TIMER_SHORT_COMPARE2_STOP_MASK);
110108
fork_addr = rand();
@@ -131,6 +129,8 @@ static void verify_continuous_carrier_begin_periph_setup(void)
131129

132130
void test_continuous_carrier_begin_ShallPrepareHardwareToTransmitCarrier(void)
133131
{
132+
m_timeslot_is_granted = true;
133+
134134
verify_continuous_carrier_begin_periph_setup();
135135

136136
nrf_radio_task_trigger_Expect(NRF_RADIO_TASK_DISABLE);
@@ -142,6 +142,8 @@ void test_continuous_carrier_begin_ShallPrepareHardwareToTransmitCarrier(void)
142142

143143
void test_continuous_carrier_begin_ShallTriggerDisableIfRequestedByArgument(void)
144144
{
145+
m_timeslot_is_granted = true;
146+
145147
verify_continuous_carrier_begin_periph_setup();
146148

147149
nrf_radio_task_trigger_Expect(NRF_RADIO_TASK_DISABLE);
@@ -151,6 +153,8 @@ void test_continuous_carrier_begin_ShallTriggerDisableIfRequestedByArgument(void
151153

152154
void test_continuous_carrier_begin_ShallNotTriggerDisableIfRadioIsRampingDown(void)
153155
{
156+
m_timeslot_is_granted = true;
157+
154158
verify_continuous_carrier_begin_periph_setup();
155159

156160
nrf_radio_state_get_ExpectAndReturn(NRF_RADIO_STATE_RX_DISABLE);
@@ -160,6 +164,8 @@ void test_continuous_carrier_begin_ShallNotTriggerDisableIfRadioIsRampingDown(vo
160164

161165
void test_continuous_carrier_begin_ShallNotTriggerDisableIfEguEventIsSet(void)
162166
{
167+
m_timeslot_is_granted = true;
168+
163169
verify_continuous_carrier_begin_periph_setup();
164170

165171
nrf_radio_state_get_ExpectAndReturn(NRF_RADIO_STATE_DISABLED);
@@ -170,6 +176,8 @@ void test_continuous_carrier_begin_ShallNotTriggerDisableIfEguEventIsSet(void)
170176

171177
void test_continuous_carrier_begin_ShallTriggerDisableIfRadioIsDisabledAndEguDidNotWork(void)
172178
{
179+
m_timeslot_is_granted = true;
180+
173181
verify_continuous_carrier_begin_periph_setup();
174182

175183
nrf_radio_state_get_ExpectAndReturn(NRF_RADIO_STATE_DISABLED);
@@ -185,29 +193,29 @@ void test_continuous_carrier_begin_ShallTriggerDisableIfRadioIsDisabledAndEguDid
185193

186194
void test_continuous_carrier_terminate_ShallDoNothingOutOfTimeslot(void)
187195
{
196+
m_timeslot_is_granted = false;
197+
188198
nrf_ppi_channel_disable_Expect(PPI_DISABLED_EGU);
189199
nrf_ppi_channel_disable_Expect(PPI_EGU_RAMP_UP);
190200

191201
nrf_fem_control_ppi_disable_Expect(NRF_FEM_CONTROL_PA_PIN);
192202
nrf_fem_control_timer_reset_Expect(NRF_FEM_CONTROL_PA_PIN, NRF_TIMER_SHORT_COMPARE2_STOP_MASK);
193203
nrf_fem_control_ppi_fork_clear_Expect(NRF_FEM_CONTROL_PA_PIN, PPI_EGU_RAMP_UP);
194204

195-
nrf_raal_timeslot_is_granted_ExpectAndReturn(false);
196-
197205
continuous_carrier_terminate();
198206
}
199207

200208
void test_continuous_carrier_terminate_ShallResetPeriphAndTriggerDisableTask(void)
201209
{
210+
m_timeslot_is_granted = true;
211+
202212
nrf_ppi_channel_disable_Expect(PPI_DISABLED_EGU);
203213
nrf_ppi_channel_disable_Expect(PPI_EGU_RAMP_UP);
204214

205215
nrf_fem_control_ppi_disable_Expect(NRF_FEM_CONTROL_PA_PIN);
206216
nrf_fem_control_timer_reset_Expect(NRF_FEM_CONTROL_PA_PIN, NRF_TIMER_SHORT_COMPARE2_STOP_MASK);
207217
nrf_fem_control_ppi_fork_clear_Expect(NRF_FEM_CONTROL_PA_PIN, PPI_EGU_RAMP_UP);
208218

209-
nrf_raal_timeslot_is_granted_ExpectAndReturn(true);
210-
211219
nrf_radio_task_trigger_Expect(NRF_RADIO_TASK_DISABLE);
212220

213221
continuous_carrier_terminate();

test/unit tests/fsm_ed/unity_test.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ static void verify_receive_begin_finds_free_buffer(void)
157157

158158
static void verify_complete_receive_begin(void)
159159
{
160-
nrf_raal_timeslot_is_granted_ExpectAndReturn(true);
161160
verify_setting_tx_power();
162161
verify_receive_begin_setup(NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK |
163162
NRF_RADIO_SHORT_END_DISABLE_MASK |
@@ -193,9 +192,9 @@ void nrf_802154_tx_ack_started(void){}
193192

194193
void test_ed_begin_ShallDoNothingIfOutOfTimeslot(void)
195194
{
196-
nrf_raal_timeslot_us_left_get_ExpectAndReturn(0);
195+
m_timeslot_is_granted = false;
197196

198-
nrf_raal_timeslot_is_granted_ExpectAndReturn(false);
197+
nrf_raal_timeslot_us_left_get_ExpectAndReturn(0);
199198

200199
nrf_fem_control_ppi_disable_Expect(NRF_FEM_CONTROL_LNA_PIN);
201200
nrf_fem_control_pin_clear_Expect();
@@ -205,9 +204,9 @@ void test_ed_begin_ShallDoNothingIfOutOfTimeslot(void)
205204

206205
void test_ed_begin_ShallResetRadioIfTimeslotIsTooShort(void)
207206
{
208-
nrf_raal_timeslot_us_left_get_ExpectAndReturn(1);
207+
m_timeslot_is_granted = true;
209208

210-
nrf_raal_timeslot_is_granted_ExpectAndReturn(true);
209+
nrf_raal_timeslot_us_left_get_ExpectAndReturn(1);
211210

212211
nrf_radio_power_set_Expect(false);
213212
nrf_radio_power_set_Expect(true);
@@ -342,8 +341,6 @@ static void verify_ed_terminate_periph_reset(bool is_in_timeslot)
342341
nrf_ppi_channel_remove_from_group_Expect(PPI_EGU_RAMP_UP, PPI_CHGRP0);
343342
nrf_ppi_fork_endpoint_setup_Expect(PPI_EGU_RAMP_UP, 0);
344343

345-
nrf_raal_timeslot_is_granted_ExpectAndReturn(is_in_timeslot);
346-
347344
if (is_in_timeslot)
348345
{
349346
nrf_radio_int_disable_Expect(NRF_RADIO_INT_EDEND_MASK);
@@ -354,13 +351,15 @@ static void verify_ed_terminate_periph_reset(bool is_in_timeslot)
354351

355352
void test_ed_terminate_ShallNotModifyRadioRegistersIfTimslotIsNotGranted(void)
356353
{
354+
m_timeslot_is_granted = false;
357355
verify_ed_terminate_periph_reset(false);
358356

359357
ed_terminate();
360358
}
361359

362360
void test_ed_terminate_ShallResetPeriphAndTriggerDisableTask(void)
363361
{
362+
m_timeslot_is_granted = true;
364363
verify_ed_terminate_periph_reset(true);
365364

366365
ed_terminate();
@@ -386,6 +385,8 @@ void test_edend_handler_ShallResetToRxStateAndNotifySuccessIfEdEnded(void)
386385
m_ed_result = 0;
387386
m_ed_time_left = 0;
388387

388+
m_timeslot_is_granted = true;
389+
389390
nrf_radio_ed_sample_get_ExpectAndReturn(result);
390391

391392
nrf_802154_pib_channel_get_ExpectAndReturn(channel);
@@ -423,10 +424,11 @@ void test_edend_handler_ShallResetRadioAndWaitForNextTimeslotIfCannotStartNextIt
423424
m_ed_time_left = rand();
424425
m_ed_time_left = m_ed_time_left ? m_ed_time_left : 1;
425426

427+
m_timeslot_is_granted = true;
428+
426429
nrf_radio_ed_sample_get_ExpectAndReturn(result);
427430

428431
nrf_raal_timeslot_us_left_get_ExpectAndReturn(0);
429-
nrf_raal_timeslot_is_granted_ExpectAndReturn(true);
430432

431433
nrf_radio_power_set_Expect(false);
432434
nrf_radio_power_set_Expect(true);

0 commit comments

Comments
 (0)