Radio Control Layer (RCL)
RCL_Scheduler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2023, 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_Scheduler_h__include
34 #define ti_drivers_RCL_Scheduler_h__include
35 
36 #include <stdint.h>
37 #include <stddef.h>
38 
40 #include <ti/drivers/rcl/hal/hal.h>
41 
45 #define RCL_SCHEDULER_SYSTIM_US(x) (((uint32_t) (x)) * 4U)
46 
49 #define RCL_SCHEDULER_SYSTIM_MS(x) (((uint32_t) (x)) * 4U * 1000U)
50 
51 
52 /* Timing constants */
53 #define ABS_START_TIME_OFFSET RCL_SCHEDULER_SYSTIM_US(100U)
54 #define IMM_START_TIME_OFFSET RCL_SCHEDULER_SYSTIM_US(90U)
55 #define RCL_SCHEDULER_MARGIN_ARM RCL_SCHEDULER_SYSTIM_US(40U)
56 #define RCL_SCHEDULER_MARGIN_CONFIGURE RCL_SCHEDULER_SYSTIM_US(76U)
57 #define RCL_SCHEDULER_MARGIN_LOAD RCL_SCHEDULER_SYSTIM_US(460U)
58 #define RCL_SCHEDULER_SLEEP_CUTOFF RCL_SCHEDULER_SYSTIM_MS(10U)
59 #define RCL_SCHEDULER_TRIG_NOW_DELAY RCL_SCHEDULER_SYSTIM_US(50U)
60 #if defined(DeviceFamily_CC23X0R5) || defined(DeviceFamily_CC23X0R2)
61 #define RCL_SCHEDULER_WAKEUP_MARGIN RCL_SCHEDULER_SYSTIM_US(390U)
62 #else
63 #define RCL_SCHEDULER_WAKEUP_MARGIN RCL_SCHEDULER_SYSTIM_US(1000U)
64 #endif
65 
66 typedef enum {
72 
73 typedef enum {
78 
79 typedef struct RCL_SchedulerStopInfo_s {
80  uint32_t cmdStopEnabled : 1;
81  uint32_t schedStopEnabled : 1;
82  uint32_t apiStopEnabled : 1;
83  RCL_SchedulerStopReason stopReason : 2;
84  uint32_t cmdStopTime;
85  uint32_t schedStopTime;
87 
88 typedef struct RCL_SchedulerState_s {
89  RCL_Command *currCmd;
90  uint32_t nextWantsStop : 1;
91  RCL_SchedulerStopTimeState stopTimeState : 2;
92  RCL_SchedulerStopReason descheduleReason : 2;
93  RCL_Events postedRclEvents; /* Events to be handled by the command handler */
94  uint32_t actualStartTime;
99 
101 
120 
132 RCL_CommandStatus RCL_Scheduler_setStartStopTime(const RCL_Command *cmd);
133 
147 RCL_CommandStatus RCL_Scheduler_setStartStopTimeEarliestStart(const RCL_Command *cmd, uint32_t earliestStartTime);
148 
161 
170 
181 
192 
203 
226 bool RCL_Scheduler_isLater(uint32_t refTime, uint32_t chkTime);
227 
243 int32_t RCL_Scheduler_delta(uint32_t refTime, uint32_t chkTime);
244 
250 static inline uint32_t RCL_Scheduler_getCurrentTime(void)
251 {
252  return hal_get_current_time();
253 }
254 
268 RCL_StopType RCL_Scheduler_setSchedStopTime(RCL_SchedulerStopInfo *stopInfo, uint32_t schedStopTime);
269 
278 bool RCL_Scheduler_postEvent(RCL_Command_Handle c, RCL_Events e);
279 
283 #endif
RCL_CommandStatus RCL_Scheduler_setNewStartAbsTime(uint32_t startTime)
Set new start time for LRF to given absolute time, after a previous start.
Definition: RCL_Scheduler.c:218
RCL_StopType RCL_Scheduler_setStopTimes(void)
Function to apply relevant stop times.
Definition: RCL_Scheduler.c:362
RCL_Events postedRclEvents
Definition: RCL_Scheduler.h:93
RCL_SchedulerStopInfo gracefulStopInfo
Definition: RCL_Scheduler.h:96
RCL_SchedulerState rclSchedulerState
Definition: RCL_Scheduler.c:51
Definition: RCL_Scheduler.h:74
RCL_CommandStatus RCL_Scheduler_setStartStopTime(const RCL_Command *cmd)
Set start and stop time for LRF based on command.
Definition: RCL_Scheduler.c:137
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:226
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:413
static uint32_t RCL_Scheduler_getCurrentTime(void)
Get current time.
Definition: RCL_Scheduler.h:249
Definition: RCL_Scheduler.h:75
RCL_StopType
Stop types.
Definition: RCL_Command.h:138
RCL_StopType RCL_Scheduler_setSchedStopTime(RCL_SchedulerStopInfo *stopInfo, uint32_t schedStopTime)
Set scheduler stop time.
Definition: RCL_Scheduler.c:459
Definition: RCL_Scheduler.h:79
Definition: RCL_Scheduler.h:70
RCL_SchedulerStopReason
Definition: RCL_Scheduler.h:66
RCL_SchedulerStopTimeState
Definition: RCL_Scheduler.h:73
RCL_CommandStatus RCL_Scheduler_setNewStartNow(void)
Set new start time for LRF to now, after a previous start.
Definition: RCL_Scheduler.c:210
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:162
Definition: RCL_Scheduler.h:68
Definition: RCL_Scheduler.h:69
Definition: RCL_Scheduler.h:67
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:431
void * RCL_Command_Handle
Definition: RCL_Types.h:36
uint32_t schedStopTime
Definition: RCL_Scheduler.h:85
uint32_t actualStartTime
Definition: RCL_Scheduler.h:94
uint32_t hal_get_current_time(void)
Definition: hal_cc23x0.c:160
RCL_Command * currCmd
Definition: RCL_Scheduler.h:89
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:200
Definition: RCL_Scheduler.h:76
uint16_t requestedPhyFeatures
Definition: RCL_Scheduler.h:97
bool RCL_Scheduler_postEvent(RCL_Command_Handle c, RCL_Events e)
Post event to command handler.
Definition: RCL_Scheduler.c:566
Definition: RCL_Scheduler.h:88
uint32_t cmdStopTime
Definition: RCL_Scheduler.h:84
RCL_CommandStatus
Command status.
Definition: RCL_Command.h:83
RCL_SchedulerStopInfo hardStopInfo
Definition: RCL_Scheduler.h:95
RCL_CommandStatus RCL_Scheduler_findStopStatus(RCL_StopType stopType)
Get relevant status when a command was stopped.
Definition: RCL_Scheduler.c:68