shengine pre-release
shengine by mrsinho
Loading...
Searching...
No Matches
shTime.h File Reference

Handling time-related functionalities in the shengine framework. More...

Go to the source code of this file.

Data Structures

struct  ShTime
 Structure representing time in the shengine framework. More...
 

Macros

#define SH_TIME_MAX_TICK_COUNT   1024
 Maximum number of ticks in the time structure.
 
#define shOnTick(time, seconds_d, tick_idx, expression)
 Macro to execute an expression on a tick in the shengine framework.
 

Typedefs

typedef uint64_t ShTimeFunc(void *)
 Function type for time-related callbacks.
 
typedef enum ShTickStatus ShTickStatus
 
typedef struct ShTime ShTime
 

Enumerations

enum  ShTickStatus {
  SH_TICK_UNDEFINED = 0 , SH_TICK_INITIALIZED = 1 , SH_TICK_WAITING = 2 , SH_TICK_EXECUTING = 3 ,
  SH_TICK_FINISHED_EXECUTING = 4 , SH_TICK_STATUS_MAX_ENUM
}
 Enumerates possible tick statuses. More...
 

Functions

uint8_t shGetTime (ShTime *p_time)
 Gets the current time in the shengine framework.
 
uint8_t shSetTime (double now, ShTime *p_time)
 Sets the time in the shengine framework.
 
uint8_t shCallOnTick (ShTime *p_time, double seconds, uint32_t tick_idx, ShTimeFunc *p_func, void *p_arg, uint64_t *p_return_value)
 Calls a function on a tick in the shengine framework.
 
void shSleep (uint32_t ms)
 Sleeps for a specified number of milliseconds.
 

Detailed Description

Handling time-related functionalities in the shengine framework.

The shTime.h file contains structures and functions related to handling time in the shengine framework.

Macro Definition Documentation

◆ SH_TIME_MAX_TICK_COUNT

#define SH_TIME_MAX_TICK_COUNT   1024

Maximum number of ticks in the time structure.

SH_TIME_MAX_TICK_COUNT defines the maximum number of ticks that can be tracked in the ShTime structure.

◆ shOnTick

#define shOnTick (   time,
  seconds_d,
  tick_idx,
  expression 
)
Value:
if ((time).ticks_status[tick_idx] == SH_TICK_UNDEFINED) {\
(time).ticks_status[tick_idx] = SH_TICK_INITIALIZED;\
}\
if (\
(\
((time).now - (time).ticks_last_time[tick_idx]) >= (double)(seconds_d)\
) &&\
(tick_idx < SH_TIME_MAX_TICK_COUNT) &&\
(\
(time).ticks_status[tick_idx] != SH_TICK_UNDEFINED &&\
(time).ticks_status[tick_idx] != SH_TICK_EXECUTING\
)\
) {\
(time).ticks_status[tick_idx] = SH_TICK_EXECUTING;\
expression;\
(time).ticks_last_time[tick_idx] = (time).now;\
(time).ticks_status[tick_idx] = SH_TICK_FINISHED_EXECUTING;\
}\
else {\
(time).ticks_status[tick_idx] = SH_TICK_WAITING;\
}
@ SH_TICK_UNDEFINED
Definition shTime.h:46
@ SH_TICK_WAITING
Definition shTime.h:48
@ SH_TICK_FINISHED_EXECUTING
Definition shTime.h:50
@ SH_TICK_INITIALIZED
Definition shTime.h:47
@ SH_TICK_EXECUTING
Definition shTime.h:49
#define SH_TIME_MAX_TICK_COUNT
Maximum number of ticks in the time structure.
Definition shTime.h:23

Macro to execute an expression on a tick in the shengine framework.

The shOnTick macro executes the specified expression when a tick condition is met in the ShTime structure.

Example:

shOnTick(time, 0.5, 1, printf("Tick 1 executed!"))
#define shOnTick(time, seconds_d, tick_idx, expression)
Macro to execute an expression on a tick in the shengine framework.
Definition shTime.h:134
Parameters
timeShTime structure to check for ticks.
seconds_dTime interval in seconds for the tick.
tick_idxIndex of the tick.
expressionExpression to execute when the tick condition is met.

Typedef Documentation

◆ ShTickStatus

typedef enum ShTickStatus ShTickStatus

◆ ShTime

typedef struct ShTime ShTime

◆ ShTimeFunc

ShTimeFunc

Function type for time-related callbacks.

The ShTimeFunc typedef defines a function type for time-related callbacks, taking a void pointer as an argument and returning a uint64_t.

Enumeration Type Documentation

◆ ShTickStatus

Enumerates possible tick statuses.

The ShTickStatus enumeration defines possible statuses of a tick in the ShTime structure, including undefined, initialized, waiting, executing, and finished executing.

Enumerator
SH_TICK_UNDEFINED 

Tick status undefined.

SH_TICK_INITIALIZED 

Tick status initialized.

SH_TICK_WAITING 

Tick status waiting.

SH_TICK_EXECUTING 

Tick status executing.

SH_TICK_FINISHED_EXECUTING 

Tick status finished executing.

SH_TICK_STATUS_MAX_ENUM 

Function Documentation

◆ shCallOnTick()

uint8_t shCallOnTick ( ShTime p_time,
double  seconds,
uint32_t  tick_idx,
ShTimeFunc p_func,
void *  p_arg,
uint64_t *  p_return_value 
)
extern

Calls a function on a tick in the shengine framework.

Parameters
p_timePointer to a valid ShTime structure.
secondsTime interval in seconds for the tick.
tick_idxIndex of the tick.
p_funcPointer to the time function to call.
p_argPointer to an argument for the time function.
p_return_valuePointer to store the return value of the time function.
Returns
1 on success, 0 on failure.

◆ shGetTime()

uint8_t shGetTime ( ShTime p_time)
extern

Gets the current time in the shengine framework.

Parameters
p_timePointer to a valid ShTime structure.
Returns
1 on success, 0 on failure.

◆ shSetTime()

uint8_t shSetTime ( double  now,
ShTime p_time 
)
extern

Sets the time in the shengine framework.

Parameters
nowCurrent time to set.
p_timePointer to a valid ShTime structure.
Returns
1 on success, 0 on failure.

◆ shSleep()

void shSleep ( uint32_t  ms)
extern

Sleeps for a specified number of milliseconds.

Parameters
msNumber of milliseconds to sleep.