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 {
71 
72 typedef enum {
77 
78 typedef struct RCL_SchedulerStopInfo_s {
79  uint32_t cmdStopEnabled : 1;
80  uint32_t schedStopEnabled : 1;
81  uint32_t apiStopEnabled : 1;
83  uint32_t cmdStopTime;
84  uint32_t schedStopTime;
86 
87 typedef struct RCL_SchedulerState_s {
88  RCL_Command *currCmd;
89  uint32_t nextWantsStop : 1;
91  RCL_Events postedRclEvents; /* Events to be handled by the command handler */
92  uint32_t actualStartTime;
96 
98 
115 RCL_CommandStatus RCL_Scheduler_setStartStopTime(const RCL_Command *cmd);
116 
130 RCL_CommandStatus RCL_Scheduler_setStartStopTimeEarliestStart(const RCL_Command *cmd, uint32_t earliestStartTime);
131 
144 
153 
164 
175 
186 
209 bool RCL_Scheduler_isLater(uint32_t refTime, uint32_t chkTime);
210 
226 int32_t RCL_Scheduler_delta(uint32_t refTime, uint32_t chkTime);
227 
233 static inline uint32_t RCL_Scheduler_getCurrentTime(void)
234 {
235  return hal_get_current_time();
236 }
237 
251 RCL_StopType RCL_Scheduler_setSchedStopTime(RCL_SchedulerStopInfo *stopInfo, uint32_t schedStopTime);
252 
261 bool RCL_Scheduler_postEvent(RCL_Command_Handle c, RCL_Events e);
262 
266 #endif
hal_trigger_command_fsm
void hal_trigger_command_fsm(void)
Definition: hal_octopus.c:115
RCL_Scheduler.h
RCL_Scheduler_setStartStopTimeEarliestStart
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:94
SchedulerStartAbsTimeNoDelay
@ SchedulerStartAbsTimeNoDelay
Definition: RCL_Scheduler.c:59
RCL_SchedulerStopInfo::cmdStopTime
uint32_t cmdStopTime
Definition: RCL_Scheduler.h:83
SchedulerStartType
SchedulerStartType
Definition: RCL_Scheduler.c:55
RCL_SchedulerStopTimeSelect_None
@ RCL_SchedulerStopTimeSelect_None
Definition: RCL_Scheduler.h:67
RCL_Scheduler_setSchedStopTime
RCL_StopType RCL_Scheduler_setSchedStopTime(RCL_SchedulerStopInfo *stopInfo, uint32_t schedStopTime)
Set scheduler stop time.
Definition: RCL_Scheduler.c:391
RCL_SchedulerStopInfo::apiStopEnabled
uint32_t apiStopEnabled
Definition: RCL_Scheduler.h:81
hal.h
RCL_SchedulerState::currCmd
RCL_Command * currCmd
Definition: RCL_Scheduler.h:88
rclSchedulerState
RCL_SchedulerState rclSchedulerState
Definition: RCL_Scheduler.c:51
RCL_Scheduler_setStartStopTime
RCL_CommandStatus RCL_Scheduler_setStartStopTime(const RCL_Command *cmd)
Set start and stop time for LRF based on command.
Definition: RCL_Scheduler.c:69
hal_setup_start_time
void hal_setup_start_time(uint32_t startTime)
Definition: hal_octopus.c:159
RCL_StopType
RCL_StopType
Stop types.
Definition: RCL_Command.h:129
hal_cancel_hard_stop_time
void hal_cancel_hard_stop_time(void)
Definition: hal_octopus.c:210
LRF.h
RCL_Scheduler_getCurrentTime
static uint32_t RCL_Scheduler_getCurrentTime(void)
Get current time.
Definition: RCL_Scheduler.h:233
RCL_Scheduler_setCmdStopTimeNoStartTrigger
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:132
RCL_Command.h
RCL_CommandStatus_Finished
@ RCL_CommandStatus_Finished
Definition: RCL_Command.h:90
RCL_SchedulerState::gracefulStopInfo
RCL_SchedulerStopInfo gracefulStopInfo
Definition: RCL_Scheduler.h:94
RCL_CommandStatus_Queued
@ RCL_CommandStatus_Queued
Definition: RCL_Command.h:85
RCL_Scheduler_isLater
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:345
RCL_Debug_assert
#define RCL_Debug_assert(expr)
Definition: RCL_Debug.h:39
RCL_CommandStatus
RCL_CommandStatus
Command status.
Definition: RCL_Command.h:83
RCL_SchedulerStopInfo::cmdStopEnabled
uint32_t cmdStopEnabled
Definition: RCL_Scheduler.h:79
RCL_StopType_Graceful
@ RCL_StopType_Graceful
Definition: RCL_Command.h:132
RCL_SchedulerState::postedRclEvents
RCL_Events postedRclEvents
Definition: RCL_Scheduler.h:91
RCL_Scheduler_setNewStartNow
RCL_CommandStatus RCL_Scheduler_setNewStartNow(void)
Set new start time for LRF to now, after a previous start.
Definition: RCL_Scheduler.c:142
RCL_Scheduler_setNewStartAbsTime
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:150
RCL_SchedulerStopInfo::schedStopEnabled
uint32_t schedStopEnabled
Definition: RCL_Scheduler.h:80
RCL_SchedulerStopTimeSelect_Sched
@ RCL_SchedulerStopTimeSelect_Sched
Definition: RCL_Scheduler.h:69
RCL_Scheduler_delta
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:363
RCL_StopType_None
@ RCL_StopType_None
Definition: RCL_Command.h:130
RCL_SchedulerState
Definition: RCL_Scheduler.h:87
RCL_SchedulerStopInfo::schedStopTime
uint32_t schedStopTime
Definition: RCL_Scheduler.h:84
RCL_SchedulerState::nextWantsStop
uint32_t nextWantsStop
Definition: RCL_Scheduler.h:89
RCL_Scheduler_setNewStartRelTime
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:158
RCL_SchedulerStopInfo
Definition: RCL_Scheduler.h:78
RCL_SchedulerState::stopTimeState
RCL_SchedulerStopTimeState stopTimeState
Definition: RCL_Scheduler.h:90
RCL_CommandStatus_Error_StartTooLate
@ RCL_CommandStatus_Error_StartTooLate
Definition: RCL_Command.h:108
RCL_Debug.h
hal_get_current_time
uint32_t hal_get_current_time(void)
Definition: hal_octopus.c:133
hal_setup_graceful_stop_time
void hal_setup_graceful_stop_time(uint32_t stopTime)
Definition: hal_octopus.c:184
RCL_Schedule_AbsTime
@ RCL_Schedule_AbsTime
Definition: RCL_Command.h:144
RCL_SchedulerStopTimeState
RCL_SchedulerStopTimeState
Definition: RCL_Scheduler.h:72
RCL_CommandStatus_Active
@ RCL_CommandStatus_Active
Definition: RCL_Command.h:87
RCL_SchedulerStopInfo::stopTimeSelect
RCL_SchedulerStopTimeSelect stopTimeSelect
Definition: RCL_Scheduler.h:82
RCL_SchedulerStopTimeState_Found
@ RCL_SchedulerStopTimeState_Found
Definition: RCL_Scheduler.h:74
RCL_CommandStatus_GracefulStop
@ RCL_CommandStatus_GracefulStop
Definition: RCL_Command.h:96
RCL_SchedulerStopTimeState_Programmed
@ RCL_SchedulerStopTimeState_Programmed
Definition: RCL_Scheduler.h:75
RCL_EventSoftwareTriggered
#define RCL_EventSoftwareTriggered
Definition: RCL_Event.h:44
RCL_SCHEDULER_TRIG_NOW_DELAY
#define RCL_SCHEDULER_TRIG_NOW_DELAY
Definition: RCL_Scheduler.h:59
RCL_CommandStatus_HardStop
@ RCL_CommandStatus_HardStop
Definition: RCL_Command.h:97
RCL_SchedulerStopTimeState_Init
@ RCL_SchedulerStopTimeState_Init
Definition: RCL_Scheduler.h:73
SchedulerNoStart
@ SchedulerNoStart
Definition: RCL_Scheduler.c:56
SchedulerStartNow
@ SchedulerStartNow
Definition: RCL_Scheduler.c:57
rclSchedulerFindEarliestStopTime
static void rclSchedulerFindEarliestStopTime(RCL_SchedulerStopInfo *stopInfo)
Definition: RCL_Scheduler.c:440
rclSchedulerProcessCmdStartStopTime
static RCL_CommandStatus rclSchedulerProcessCmdStartStopTime(const RCL_Command *cmd, uint32_t startTime, SchedulerStartType startType)
Definition: RCL_Scheduler.c:168
RCL_SchedulerState::hardStopInfo
RCL_SchedulerStopInfo hardStopInfo
Definition: RCL_Scheduler.h:93
RCL_Command_Handle
void * RCL_Command_Handle
Definition: RCL_Types.h:36
SchedulerStartAbsTimeAllowDelay
@ SchedulerStartAbsTimeAllowDelay
Definition: RCL_Scheduler.c:58
RCL_SchedulerState::actualStartTime
uint32_t actualStartTime
Definition: RCL_Scheduler.h:92
hal_cancel_graceful_stop_time
void hal_cancel_graceful_stop_time(void)
Definition: hal_octopus.c:216
RCL_Scheduler_postEvent
bool RCL_Scheduler_postEvent(RCL_Command_Handle c, RCL_Events e)
Post event to command handler.
Definition: RCL_Scheduler.c:498
hal_setup_hard_stop_time
void hal_setup_hard_stop_time(uint32_t stopTime)
Definition: hal_octopus.c:169
rclSchedulerState
RCL_SchedulerState rclSchedulerState
Definition: RCL_Scheduler.c:51
RCL_StopType_Hard
@ RCL_StopType_Hard
Definition: RCL_Command.h:133
RCL_SchedulerStopTimeSelect
RCL_SchedulerStopTimeSelect
Definition: RCL_Scheduler.h:66
RCL_SchedulerStopTimeSelect_Cmd
@ RCL_SchedulerStopTimeSelect_Cmd
Definition: RCL_Scheduler.h:68
RCL_Scheduler_setStopTimes
RCL_StopType RCL_Scheduler_setStopTimes(void)
Function to apply relevant stop times.
Definition: RCL_Scheduler.c:294