INOS
CINOS1ms Class Reference

#include <inos_1ms.h>

Inheritance diagram for CINOS1ms:

Public Types

typedef uintptr_t tIntervalId
 
typedef uintptr_t tTimeoutId
 
- Public Types inherited from CINOSTask
enum  ETskType {
  eTskTypeBoot = 0 , eTskTypeResource = 1 , eTskTypeSystem = 2 , eTskTypeApplication = 3 ,
  eTskTypeCommunication = 4 , eTskTypeRealtime = 5 , eTskTypeInterrupt = 6 , eTskTypeBackground = 7 ,
  eTskTypeLua = 8 , eTskTypeTest = 9 , eTskTypeReserved0 = 10 , eTskTypeReserved1 = 11 ,
  eTskTypeUser0 = 12 , eTskTypeUser1 = 13 , eTskTypeUser2 = 14 , eTskTypeUser3 = 15
}
 Task types.
 

Public Member Functions

CINOSxmsHandlerAddHandler (void *aHandler, void *aObject, int32 aMS, bool aActive=true, bool aSingle=false)
 
CINOSxmsHandlerFunctionAddHandler (uintptr_t &aTimeoutId, const CINOSxmsHandlerFunction::tFunction &aFunction, int32 aMS, bool aActive=true, bool aSingle=false)
 
void AddHandler (CINOSxmsHandlerBase *aHandler)
 
void RemoveHandler (CINOSxmsHandlerBase *aHandler, bool aDelete=true)
 
void eAddTimer (uint32 aTimerPtr)
 
void AddTimer (int32 *aTimer)
 
int32 GetTickCount ()
 
int32 GetTickDelta (int32 aiTickCount)
 
int32 * GetTickAddress ()
 
void SetTickAddress (int32 *apAddress)
 
uint32 GetSystemTicksAtLast1msTick ()
 
template<typename TFct >
void SetInterval (TFct aFct, uint32 aIntervalMs, tIntervalId &aIntervalId)
 
void ClearInterval (tIntervalId &aIntervalId)
 
template<typename TFct >
void SetTimeout (TFct aFct, uint32 aTimeoutMs, tTimeoutId &aTimeoutId)
 
void ClearTimeout (tTimeoutId &aTimeoutId)
 
bool HasHandlers (uint32 auNumber)
 
bool KickExactly (CINOSTask *apSource=0) INOS_COMPILE_OPTIMIZED
 
bool KickSporadically () INOS_COMPILE_OPTIMIZED
 
- Public Member Functions inherited from CINOSTask
 CINOSTask (char *apName=nullptr, uint32 auStackSize=defDefaultStackSize, uint32 auPriority=DF_INOS_TASK_PRIO_LOWEST, bool abFloatingPoint=true, uint32 auTimeSlice=defDefaultTimeSlice, bool abInterruptsDisabled=false, void *apHandler=0, void *apObject=0)
 Create a task with given properties. One needs to Resume the task after creation to get it running.
 
 CINOSTask (std::function< void(void *)> aFunction, void *apParam=nullptr, uint8 auPriority=DF_INOS_TASK_PRIO_LOWEST)
 Create a task with given properties. One needs to Resume the task after creation to get it running.
 
 CINOSTask (const char *apName, std::function< void(void *)> aFunction, void *apParam=nullptr, uint8 auPriority=DF_INOS_TASK_PRIO_LOWEST)
 Create a task with given properties. One needs to Resume the task after creation to get it running.
 
virtual ~CINOSTask ()
 Destroy task.
 
virtual uint32 Shutdown (CINOSSync *apSync=DF_INOS_SYNCHRONOUS)
 Shutdown task, used to shutdown a foreign task.
 
virtual uint32 Join ()
 Join task or in other words, wait till it terminates.
 
virtual void Detach ()
 Detach task from parent. One uses this method if one doesn't want this task to be shut down if the parent shuts down.
 
virtual void Exit ()
 Terminate myself. Exit code is INOS_OK or the code previously set with SetExitCode.
 
virtual void Exit (uint32 auExitCode)
 Terminate myself.
 
virtual void SetExitCode (uint32 auExitCode)
 Set exit code.
 
virtual uint32 GetExitCode ()
 Get exit code.
 
virtual bool CheckShutdown ()
 Check if a shutdown is pending.
 
virtual void SetSuspendHook (void *apSuspendHook)
 Set Suspend hook.
 
virtual void ClrSuspendHook ()
 Clear Suspend hook.
 
virtual voidGetSuspendHook ()
 Get Suspend hook if any.
 
INOS_INLINE ETskType GetTskType ()
 Get task type.
 
INOS_INLINE ETskType SetTskType (ETskType aeType)
 Set task type.
 

Static Public Member Functions

static CINOS1msInstance ()
 singleton
 
static CINOS1mspInstance ()
 

Static Public Attributes

static CINOSMutex m_Mutex
 public
 
static uint32 m_uCoreMask
 core mask
 

Protected Member Functions

virtual void Action ()
 Task action loop, needs to be overwritten by the user. For more info, see section Creation.
 

Detailed Description

A global 'INOS timing service' running with 1 millisecond resolution. It's intended to register "callbacks", which are called at specific points in time in the future. Such "callbacks" will either be called once or multiple time. Such a "callback" registration (identified by a 'handler'), can temporarily be disabled or permanently unregistered to avoid "callback" calls.

Member Function Documentation

◆ Action()

virtual void CINOS1ms::Action ( )
protectedvirtual

Task action loop, needs to be overwritten by the user. For more info, see section Creation.

Reimplemented from CINOSTask.

◆ AddHandler() [1/3]

void CINOS1ms::AddHandler ( CINOSxmsHandlerBase aHandler)

Add a preconstructed handler object. Usually, using the overloaded 'AddHandler' function is the recommended way to create and add new handlers. This one is for more sophisticated use cases

◆ AddHandler() [2/3]

CINOSxmsHandlerFunction * CINOS1ms::AddHandler ( uintptr_t aTimeoutId,
const CINOSxmsHandlerFunction::tFunction &  aFunction,
int32  aMS,
bool  aActive = true,
bool  aSingle = false 
)

Same as AddHandler(void*,void*,int32,bool,bool) but for a C++11 std::function.

Example: Register a C++ lambda that's getting called on every 1 second. auto pHandler = CINOS1ms::Instance().AddHandler(aTokenId, [this]() { ... do whatever needs to be done every second ... }, 1000); ... do whatever ... CIONS1ms::Instance().RemoveHandler(pHandler);

◆ AddHandler() [3/3]

CINOSxmsHandler * CINOS1ms::AddHandler ( void aHandler,
void aObject,
int32  aMS,
bool  aActive = true,
bool  aSingle = false 
)

Register "callback" specified by a function address and a this pointer.

Parameters
aHandlerthe function address
aObjectthe 'this' pointer if the callback is a member function.
aMsPeriod by which the "callback" will be called
aActiveIf false, the "callback" is registered, but will not yet be called. Call 'Activate' on the returned object to activate it later. Default is 'true', which means the timer will be active immediately.
aSingleBy default, the "callback" will be called endlessly, unless the handler will be inactivated or removed. By passing 'true' here, the "callback" will be called exactly once and the handler will then automatically be removed. In that case, the user doesn't need to call RemoveHandler anymore.
Returns
"Callback" handler, identifying the registered function. That object is used to unregister the "callback" (RemoveHandler) or to modify it (e.g. change call period, disable/enable it, etc.)

Example:

Register MyCallback being called every second auto pHandler = CINOS1ms::Instance().AddHandler( ClassMemberPointer(CMyClass, MyCallback), this, 1000); ... do whatever ...

finally, remove handler and cleanup resources CINOS1ms::Instance().RemoveHandler(pHandler);

Note that it is allowed to remove the returned handler within the context of "callback" (by calling RemoveHandler).

◆ AddTimer()

void CINOS1ms::AddTimer ( int32 *  aTimer)

decrement '*aTimer' every ms until it is 0

◆ ClearInterval()

void CINOS1ms::ClearInterval ( tIntervalId aIntervalId)
inline

Cancel a callback registration done by SetInterval. This operation is intended to abort a setup callback. Do not call this function with the same handler id twice as it may in worst case cause another interval callback from getting cancelled as that new interval may have recycled the previous id.

Parameters
aIntervalIdA valid 'interval id' or zero.

◆ ClearTimeout()

void CINOS1ms::ClearTimeout ( tTimeoutId aTimeoutId)
inline

Cancel a callback registration done by SetTimeout. This operation is intended to abort a setup callback before it actually occurred. Calling it afterwards is forbidden and may in worst case cause another timeout callback from getting cancelled as that new timeout may have recycled the previous id.

Parameters
aTimeoutIdA valid 'timeout id' or zero.

◆ eAddTimer()

void CINOS1ms::eAddTimer ( uint32  aTimerPtr)

Same as AddTimer, but for being registered in the INCO tree. aTimerPtr is expected to be the value of a pointer.

◆ GetSystemTicksAtLast1msTick()

uint32 CINOS1ms::GetSystemTicksAtLast1msTick ( )
inline

return system ticks at last 1ms tick

◆ GetTickAddress()

int32 * CINOS1ms::GetTickAddress ( )
inline

return address of 1ms ticker

◆ GetTickCount()

int32 CINOS1ms::GetTickCount ( )
inline

return actual 1ms timer value

◆ GetTickDelta()

int32 CINOS1ms::GetTickDelta ( int32  aiTickCount)
inline

return actual 1ms timer value

◆ HasHandlers()

bool CINOS1ms::HasHandlers ( uint32  auNumber)
inline

return true if at least auNumber of handlers free

◆ KickExactly()

bool CINOS1ms::KickExactly ( CINOSTask apSource = 0)

If there are 'exact sources', they shall call this function exactly every 1ms. Typical 'exact sources' are field busses.

Returns
true if the 1ms task was set to 'Ready' at the scheduler. The caller is responsible to call 'schedule()' or another re-scheduling function if appropriate.

◆ KickSporadically()

bool CINOS1ms::KickSporadically ( )

Shall be called 'sporadically' e.g. by the "Idle" task or from time to time by the scheduler. The caller is responsible to disable interrupts (no core lock is required, as each core has a separate instance of this class). Without such a lock, the 1ms timing would "in average" be much worse, because we could get interrupted in between the "timing calculations" and the "Resume" which would cause the timing calculation to be wrong and ultimately causing that the 1ms task would "in average" run only e.g. every 1.0123ms.

Returns
true if the 1ms task was set to 'Ready' at the scheduler. The caller is responsible to call 'schedule()' or another re-scheduling function if appropriate.

◆ RemoveHandler()

void CINOS1ms::RemoveHandler ( CINOSxmsHandlerBase aHandler,
bool  aDelete = true 
)

Remove 'aHandler' from list of handlers. note that it is allowed to remove "itself" while being within the callback function - but it's not allowed to remove any other handlers within that context. (The reason is that we are iterating through the list of all handlers and removing a handler modifies the list while iterating...)

Parameters
aDeleteIf 'true', the handler object will be deleted. If 'false', the object will not be deleted and must either be deleted by the caller to cleanup resources, or can be re-used using AddHandler().

◆ SetInterval()

template<typename TFct >
void CINOS1ms::SetInterval ( TFct  aFct,
uint32  aIntervalMs,
tIntervalId aIntervalId 
)
inline

Register C++11 std::function that gets called periodically with the specified time.

The function has been inspired by JavaScripts 'SetInterval'.

Parameters
aIntervalMsPeriod time in [ms] by which the function shall be called
aIntervalIdInput & output parameter, if the incoming value is unequal zero, it is treated as a valid 'id' and the system ensures to cancel the previous setup interval belonging to the id. The output id is the new 'inteval id' that can be passed to ClearInterval. Note that the output value may be equal to what has been passed in (i.e. the id may be reused).

◆ SetTickAddress()

void CINOS1ms::SetTickAddress ( int32 *  apAddress)
inline

set address of 1ms ticker

◆ SetTimeout()

template<typename TFct >
void CINOS1ms::SetTimeout ( TFct  aFct,
uint32  aTimeoutMs,
tTimeoutId aTimeoutId 
)
inline

Register C++11 std::function that gets called exactly once after a specified time.

The function has been inspired by JavaScripts 'SetTimeout'.

Parameters
aTimeoutMsTime in [ms] after which the function shall be called
aTimeoutIdInput & output parameter, if the incoming value is unequal zero, it is treated as a valid 'id' and the system ensures to cancel the previous setup timeout belonging to the id. The output id is the new 'timeout id' that can be passed to ClearTimeout. Note that the output value may be equal to what has been passed in (i.e. the id may be reused).

Member Data Documentation

◆ m_Mutex

CINOSMutex CINOS1ms::m_Mutex
static

public

creation mutex


The documentation for this class was generated from the following file: