Radio Control Layer (RCL)
RCL_Scheduler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2025, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef ti_drivers_rcl_RCL_Scheduler__include
34 #define ti_drivers_rcl_RCL_Scheduler__include
35 
36 #include <stdint.h>
37 #include <stddef.h>
38 
41 #include <ti/drivers/rcl/LRF.h>
42 
46 #define RCL_SCHEDULER_SYSTIM_US(x) (((uint32_t) (x)) * 4U)
47 
50 #define RCL_SCHEDULER_SYSTIM_MS(x) (((uint32_t) (x)) * 4U * 1000U)
51 
52 
53 /* Timing constants */
54 #define ABS_START_TIME_OFFSET RCL_SCHEDULER_SYSTIM_US(100U)
55 #define IMM_START_TIME_OFFSET RCL_SCHEDULER_SYSTIM_US(90U)
56 #define RCL_SCHEDULER_MARGIN_ARM RCL_SCHEDULER_SYSTIM_US(40U)
57 #define RCL_SCHEDULER_MARGIN_CONFIGURE RCL_SCHEDULER_SYSTIM_US(76U)
58 #define RCL_SCHEDULER_MARGIN_LOAD RCL_SCHEDULER_SYSTIM_US(460U)
59 #define RCL_SCHEDULER_SLEEP_CUTOFF RCL_SCHEDULER_SYSTIM_MS(5U)
60 #define RCL_SCHEDULER_TRIG_NOW_DELAY RCL_SCHEDULER_SYSTIM_US(50U)
61 #if (DeviceFamily_LRF_PARENT == DeviceFamily_PARENT_CC23X0)
62 #define RCL_SCHEDULER_WAKEUP_MARGIN RCL_SCHEDULER_SYSTIM_US(390U)
63 #elif (DeviceFamily_LRF_PARENT == DeviceFamily_PARENT_CC27XX)
64 #define RCL_SCHEDULER_WAKEUP_MARGIN RCL_SCHEDULER_SYSTIM_US(150U)
65 #else
66 #define RCL_SCHEDULER_WAKEUP_MARGIN RCL_SCHEDULER_SYSTIM_US(1000U)
67 #endif
68 
69 typedef enum RCL_SchedulerStopReason_e {
75 
76 typedef enum RCL_SchedulerStopTimeState_e {
81 
82 typedef struct RCL_SchedulerStopInfo_s {
83  uint32_t cmdStopEnabled : 1;
84  uint32_t schedStopEnabled : 1;
85  uint32_t apiStopEnabled : 1;
86  RCL_SchedulerStopReason stopReason : 2;
87  uint32_t cmdStopTime;
88  uint32_t schedStopTime;
90 
91 typedef struct RCL_SchedulerState_s {
92  RCL_Command *currCmd;
93  RCL_Command *stopCmd;
94  uint32_t nextWantsStop : 1;
95  RCL_SchedulerStopTimeState stopTimeState : 2;
96  RCL_SchedulerStopReason descheduleReason : 2;
97  RCL_Events postedRclEvents; /* Events to be handled by the command handler */
98  uint32_t actualStartTime;
103 
105 
124 
138 
150 RCL_CommandStatus RCL_Scheduler_setStartStopTime(const RCL_Command *cmd);
151 
165 RCL_CommandStatus RCL_Scheduler_setStartStopTimeEarliestStart(const RCL_Command *cmd, uint32_t earliestStartTime);
166 
182 RCL_CommandStatus RCL_Scheduler_setCustomStartStopTime(const RCL_CommandTiming *timing, RCL_ScheduleType scheduling, bool allowDelay);
183 
201 RCL_CommandStatus RCL_Scheduler_setCustomStartStopTimeEarliestStart(const RCL_CommandTiming *timing, RCL_ScheduleType scheduling, bool allowDelay, uint32_t earliestStartTime);
202 
215 
224 
236 RCL_CommandStatus RCL_Scheduler_setNewStartAbsTime(uint32_t startTime, bool allowDelay);
237 
248 
259 
282 bool RCL_Scheduler_isLater(uint32_t refTime, uint32_t chkTime);
283 
299 int32_t RCL_Scheduler_delta(uint32_t refTime, uint32_t chkTime);
300 
306 static inline uint32_t RCL_Scheduler_getCurrentTime(void)
307 {
308  return RCL_Hal_getCurrentTime();
309 }
310 
324 RCL_StopType RCL_Scheduler_setSchedStopTime(RCL_SchedulerStopInfo *stopInfo, uint32_t schedStopTime);
325 
339 RCL_StopType RCL_Scheduler_setCmdStopTime(RCL_SchedulerStopInfo *stopInfo, uint32_t cmdStopTime);
340 
353 
366 
375 bool RCL_Scheduler_postEvent(RCL_Command_Handle c, RCL_Events e);
376 
380 #endif /* ti_drivers_rcl_RCL_Scheduler__include */
RCL_StopType RCL_Scheduler_setStopTimes(void)
Function to apply relevant stop times.
Definition: RCL_Scheduler.c:507
RCL_CommandStatus RCL_Scheduler_updateStopStatus(RCL_StopType stopType, RCL_SchedulerStopReason stopReason)
Update relevant status when a command was stopped.
Definition: RCL_Scheduler.c:70
RCL_Events postedRclEvents
Definition: RCL_Scheduler.h:97
uint32_t RCL_Hal_getCurrentTime(void)
Definition: RCLLPF3_Hal.c:188
RCL_SchedulerStopInfo gracefulStopInfo
Definition: RCL_Scheduler.h:100
RCL_SchedulerState rclSchedulerState
Definition: RCL_Scheduler.c:51
Definition: RCL_Scheduler.h:77
RCL_CommandStatus RCL_Scheduler_setStartStopTime(const RCL_Command *cmd)
Set start and stop time for LRF based on command.
Definition: RCL_Scheduler.c:162
RCL_CommandStatus RCL_Scheduler_setNewStartRelTime(uint32_t relStartTime)
Set new start time for LRF to given time relative to previous LRF start.
Definition: RCL_Scheduler.c:340
bool RCL_Scheduler_isLater(uint32_t refTime, uint32_t chkTime)
Find if a time instant occurs after another, allowing wrap-around.
Definition: RCL_Scheduler.c:558
RCL_Command * stopCmd
Definition: RCL_Scheduler.h:93
static uint32_t RCL_Scheduler_getCurrentTime(void)
Get current time.
Definition: RCL_Scheduler.h:305
Definition: RCL_Scheduler.h:78
RCL_StopType
Stop types.
Definition: RCL_Command.h:145
RCL_StopType RCL_Scheduler_setSchedStopTime(RCL_SchedulerStopInfo *stopInfo, uint32_t schedStopTime)
Set scheduler stop time.
Definition: RCL_Scheduler.c:604
Definition: RCL_Scheduler.h:82
Definition: RCL_Scheduler.h:73
RCL_ScheduleType
Schedule type.
Definition: RCL_Command.h:157
RCL_StopType RCL_Scheduler_setCmdStopTime(RCL_SchedulerStopInfo *stopInfo, uint32_t cmdStopTime)
Set command stop time.
Definition: RCL_Scheduler.c:612
RCL_SchedulerStopReason
Definition: RCL_Scheduler.h:69
RCL_StopType RCL_Scheduler_cancelSchedStopTime(RCL_SchedulerStopInfo *stopInfo)
Cancel scheduler stop time.
Definition: RCL_Scheduler.c:620
RCL_SchedulerStopTimeState
Definition: RCL_Scheduler.h:76
RCL_CommandStatus RCL_Scheduler_setNewStartNow(void)
Set new start time for LRF to now, after a previous start.
Definition: RCL_Scheduler.c:323
RCL_CommandStatus RCL_Scheduler_setStartStopTimeEarliestStart(const RCL_Command *cmd, uint32_t earliestStartTime)
Set start and stop time for LRF based on command with earliest start time.
Definition: RCL_Scheduler.c:193
Definition: RCL_Scheduler.h:71
Definition: RCL_Scheduler.h:72
Definition: RCL_Scheduler.h:70
int32_t RCL_Scheduler_delta(uint32_t refTime, uint32_t chkTime)
Find the time difference between two times, allowing wrap-around.
Definition: RCL_Scheduler.c:576
void * RCL_Command_Handle
Definition: RCL_Types.h:36
uint32_t schedStopTime
Definition: RCL_Scheduler.h:88
uint32_t actualStartTime
Definition: RCL_Scheduler.h:98
RCL_StopType RCL_Scheduler_cancelCmdStopTime(RCL_SchedulerStopInfo *stopInfo)
Cancel command stop time.
Definition: RCL_Scheduler.c:628
RCL_Command * currCmd
Definition: RCL_Scheduler.h:92
RCL_CommandStatus RCL_Scheduler_setCmdStopTimeNoStartTrigger(const RCL_Command *cmd)
Set stop time for LRF based on command when it does not need a start trigger.
Definition: RCL_Scheduler.c:313
Definition: RCL_Scheduler.h:79
uint16_t requestedPhyFeatures
Definition: RCL_Scheduler.h:101
bool RCL_Scheduler_postEvent(RCL_Command_Handle c, RCL_Events e)
Post event to command handler.
Definition: RCL_Scheduler.c:820
Definition: RCL_Scheduler.h:91
RCL_CommandStatus RCL_Scheduler_setNewStartAbsTime(uint32_t startTime, bool allowDelay)
Set new start time for LRF to given absolute time, after a previous start.
Definition: RCL_Scheduler.c:331
uint32_t cmdStopTime
Definition: RCL_Scheduler.h:87
RCL_CommandStatus RCL_Scheduler_setCustomStartStopTimeEarliestStart(const RCL_CommandTiming *timing, RCL_ScheduleType scheduling, bool allowDelay, uint32_t earliestStartTime)
Set start and stop time for LRF with earliest start time.
Definition: RCL_Scheduler.c:268
RCL_CommandStatus
Command status.
Definition: RCL_Command.h:86
RCL_SchedulerStopInfo hardStopInfo
Definition: RCL_Scheduler.h:99
RCL_CommandStatus RCL_Scheduler_findStopStatus(RCL_StopType stopType)
Get relevant status when a command was stopped.
Definition: RCL_Scheduler.c:139
RCL_CommandStatus RCL_Scheduler_setCustomStartStopTime(const RCL_CommandTiming *timing, RCL_ScheduleType scheduling, bool allowDelay)
Set start and stop time for LRF.
Definition: RCL_Scheduler.c:237