m2mb API docs  25.30.003
m2mb API sets documentation
m2mb_hwTmr.h File Reference

HW timer prototypes. More...

Go to the source code of this file.

Macros

#define M2MB_HWTMR_INVALID   0
 
#define M2MB_HWTMR_INVALID_ATTR   0
 
#define M2MB_HWTMR_PERIODIC_TMR   1
 
#define M2MB_HWTMR_ONESHOT_TMR   0
 
#define M2MB_HWTMR_AUTOSTART   1
 
#define M2MB_HWTMR_NOT_START   0
 
#define M2MB_HW_TASK_AUTOSTART   1 /* use M2MB_HWTMR_AUTOSTART instead */
 
#define M2MB_HW_TASK_NOT_START   0 /* use M2MB_HWTMR_NOT_START instead */
 
#define M2MB_HWTMR_MIN_TIMEOUT   ( 100 ) /* minimum allowed timeout in us */
 
#define M2MB_HWTMR_MAX_TIMEOUT   ( ( 1<<(sizeof(MEM_W)*4 - 1) ) | ~( 1<<(sizeof(MEM_W)*4 - 1) ) )
 
#define M2MB_HWTMR_UNIT_FACTOR   ( 1000 ) /* is ms to us: current base time in us */
 
#define M2MB_HWTMR_TIME_MS(timems)   ( timems * M2MB_HWTMR_UNIT_FACTOR )
 
#define M2MB_HWTMR_TIME_S(times)   M2MB_HWTMR_TIME_MS(times * 1000 )
 
#define m2mb_hwTmr_setAttrItem_(h, args...)   m2mb_hwTmr_setAttrItem( h, CMDS_ARGS( args ) )
 
#define enum_rename(a)   M2MB_HW_##a, M2MB_HWTMR_##a = M2MB_HW_##a
 
#define enum_rename_set(a, val)   M2MB_HW_##a = val, M2MB_HWTMR_##a = M2MB_HW_##a
 

Typedefs

typedef enum M2MB_HWTMR_RESULT M2MB_HWTMR_RESULT_E
 
typedef struct M2MB_HWTMR_HANDLE_TAG * M2MB_HWTMR_HANDLE
 
typedef struct M2MB_HWTMR_ATTR_HANDLE_TAG * M2MB_HWTMR_ATTR_HANDLE
 
typedef void(* USR_HWTMR_CB) (M2MB_HWTMR_HANDLE handle, void *arg)
 

Enumerations

enum  M2MB_HWTMR_RESULT {
  enum_rename_set =( SUCCESS, 0 ), enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ),
  enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ),
  enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ),
  enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ),
  enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ),
  enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ),
  enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ), enum_rename =( DELETED ),
  enum_rename =( DELETED ), enum_rename_set =( SUCCESS, 0 ), enum_rename =( DELETED )
}
 
enum  M2MB_HWTMR_STATE_E { M2MB_HWTMR_STATE_TOSTART, M2MB_HWTMR_STATE_RUN, M2MB_HWTMR_STATE_STOP, M2MB_HWTMR_STATE_DELETED }
 
enum  M2MB_HWTMR_SEL_CMD_E {
  M2MB_HWTMR_SEL_CMD_CREATE_ATTR, M2MB_HWTMR_SEL_CMD_DEL_ATTR, M2MB_HWTMR_SEL_CMD_NAME_ATTR_NO_SUPPORTED, M2MB_HWTMR_SEL_CMD_USRNAME_ATTR_NO_SUPPORTED,
  M2MB_HWTMR_SEL_CMD_CB_FUNC, M2MB_HWTMR_SEL_CMD_ARG_CB, M2MB_HWTMR_SEL_CMD_TICKS_PERIOD, M2MB_HWTMR_SEL_CMD_TICKS2ELAPSE,
  M2MB_HWTMR_SEL_CMD_TIME_DURATION, M2MB_HWTMR_SEL_CMD_PERIODIC, M2MB_HWTMR_SEL_CMD_AUTOSTART, M2MB_HWTMR_SEL_CMD_STATE,
  M2MB_HWTMR_SEL_CMD_END
}
 

Functions

M2MB_HWTMR_RESULT_E m2mb_hwTmr_init (M2MB_HWTMR_HANDLE *pTmrHwHandle, M2MB_HWTMR_ATTR_HANDLE *pTmrHwAttr)
 Application timer Creation. More...
 
M2MB_HWTMR_RESULT_E m2mb_hwTmr_deinit (M2MB_HWTMR_HANDLE tmrHwHandle)
 Timer deinit => deletion. More...
 
M2MB_HWTMR_RESULT_E m2mb_hwTmr_start (M2MB_HWTMR_HANDLE tmrHwHandle)
 Start application timer. More...
 
M2MB_HWTMR_RESULT_E m2mb_hwTmr_stop (M2MB_HWTMR_HANDLE tmrHwHandle)
 Stop an application timer. More...
 
M2MB_HWTMR_RESULT_E m2mb_hwTmr_setAttrItem (M2MB_HWTMR_ATTR_HANDLE *pTmrHwAttrHandle, UINT8 nCmds,...)
 Set specific attribute for timer creation. More...
 
M2MB_HWTMR_RESULT_E m2mb_hwTmr_getItem (M2MB_HWTMR_HANDLE tmrHwHandle, M2MB_HWTMR_SEL_CMD_E selCmd, MEM_W *pOut, void *pIn)
 Get specific properties of the timer. More...
 
M2MB_HWTMR_RESULT_E m2mb_hwTmr_setItem (M2MB_HWTMR_HANDLE tmrHwHandle, M2MB_HWTMR_SEL_CMD_E selCmd, void *pIn)
 Set specific properties of the timer. More...
 
M2MB_HWTMR_RESULT_E m2mb_hwTmr_timeGet_ms (UINT64 *ms_time)
 get time in ms More...
 

Detailed Description

HW timer prototypes.

m2m/m2m_generic/common/m2mb_inc/m2mb_hwTmr.h

Basic functions for HW timer are provided

@notes Dependencies: m2mb_types.h

Author
Goran Paic
Date
22/01/2018

Function Documentation

◆ m2mb_hwTmr_deinit()

M2MB_HWTMR_RESULT_E m2mb_hwTmr_deinit ( M2MB_HWTMR_HANDLE  tmrHwHandle)

Timer deinit => deletion.

This service deletes the specified hw timer. The resources will be released. It is the application responsibility to prevent use of a deleted timer.

Parameters
[in]tmrHwHandlehandle of the timer
Returns
M2MB_HWTMR_SUCCESS in case of success see M2MB_HWTMR_RESULT_E in case of error
Note
It is the application's responsibility to prevent use of a deleted timer. Allowed From tasks Preemption Possible No

Example

◆ m2mb_hwTmr_getItem()

M2MB_HWTMR_RESULT_E m2mb_hwTmr_getItem ( M2MB_HWTMR_HANDLE  tmrHwHandle,
M2MB_HWTMR_SEL_CMD_E  selCmd,
MEM_W *  pOut,
void *  pIn 
)

Get specific properties of the timer.

This service retrieve value for specified parameter of the specified timer Selecting cmd, a parameter to be retrieved can be set To be used when timer is already created: Right usage is under application's responsibility

Parameters
[in]tmrHwHandlehandle of timer
[in]selCmdSelect parameter to be set (see M2MB_HWTMR_SEL_CMD_E) param [out] pOut pointer Output parameter got: its meaning depend on selCmd used See examples as general pointer it is set to MEM_W
[in]pInpointer to void, general Parameter to be specified, if any, to get right output See examples If parameter is not needed, use NULL
Returns
M2MB_HWTMR_SUCCESS in case of success see M2MB_HWTMR_RESULT_E in case of error
Note
Not all M2MB_HWTMR_SEL_CMD_E are allowed. Allowed: M2MB_HWTMR_SEL_CMD_AUTOSTART M2MB_HWTMR_SEL_CMD_PERIODIC M2MB_HWTMR_SEL_CMD_TIME_DURATION M2MB_HWTMR_SEL_CMD_TICKS_PERIOD M2MB_HWTMR_SEL_CMD_ARG_CB M2MB_HWTMR_SEL_CMD_CB_FUNC M2MB_HWTMR_SEL_CMD_STATE

Example

◆ m2mb_hwTmr_init()

M2MB_HWTMR_RESULT_E m2mb_hwTmr_init ( M2MB_HWTMR_HANDLE *  pTmrHwHandle,
M2MB_HWTMR_ATTR_HANDLE *  pTmrHwAttr 
)

Application timer Creation.

This service creates an application timer with the specified Timer attributes

Parameters
[out]pTmrHwHandlepointer to timer handle
[in]pTmrHwAttrpointer to timer attribute handle
Returns
M2MB_HWTMR_SUCCESS in case of success see M2MB_HWTMR_RESULT_E in case of error
Note
After successful timer creation, timer attributes will be deleted, their resources free and pointed by pTmrHwAttr set to M2MB_HWTMR_INVALID_ATTR Also in case of error return, timer attribute will be deleted, their resources free and pointed by pTmrHwAttr set to M2MB_HWTMR_INVALID_ATTR Allowed From Initialization and tasks Preemption Possible No

Example Complete use of Timer with its callback, the time unit in USEC. Also ticks period M2MB_HWTMR_SEL_CMD_TICKS_PERIOD can be select, which is the period expressed in number of system ticks Period MUST BE not 0

static void TimerCb( M2MB_HWTMR_HANDLE hwTmrHandle, void *argCb )
{
static unsigned int Count = 0;
// here just as example for debug: using print inside callback
// can drive to system crash or hung : is not guaranteed
// avoid using print
PrintToUart("\r\nCallback Count: [%u]", Count++);
}
void M2MB_main( int argc, char **argv )
{
M2MB_HWTMR_RESULT_E hwRes;
M2MB_HWTMR_ATTR_HANDLE tmrHwAttrHandle;
M2MB_HWTMR_HANDLE tmrHwHandle;
UINT32 timeDuration;
MEM_W argCb;
if( m2mb_hwTmr_setAttrItem( &tmrHwAttrHandle, 1, M2MB_HWTMR_SEL_CMD_CREATE_ATTR, NULL ) != M2MB_HWTMR_SUCCESS )
{
PrintToUart("\r\nCreate the timer attributes, error %d", hwRes);
}
hwRes = m2mb_hwTmr_setAttrItem( &tmrHwAttrHandle,
CMDS_ARGS(
M2MB_HWTMR_SEL_CMD_CB_FUNC, &TimerCb,
M2MB_HWTMR_SEL_CMD_ARG_CB, argCb,
M2MB_HWTMR_SEL_CMD_TIME_DURATION, 1000, //or M2MB_HWTMR_TIME_MS(1)
M2MB_HWTMR_SEL_CMD_PERIODIC, M2MB_HWTMR_PERIODIC_TMR,
M2MB_HWTMR_SEL_CMD_AUTOSTART, M2MB_HWTMR_AUTOSTART
)
);
// if M2MB_HWTMR_SEL_CMD_TICKS_PERIOD is used instead of M2MB_HWTMR_SEL_CMD_TIME_DURATION
// at the end no more than M2MB_HWTMR_MAX_TIMEOUT in us can be get as period
// so the limit is M2MB_HWTMR_MAX_TIMEOUT[us]/SystemTimeTick[us]
if( hwRes != M2MB_HWTMR_SUCCESS )
{
PrintToUart("\r\nCreate the timer attributes, error %d", hwRes);
}
else
{
PrintToUart( "\r\nCreate the timer attributes" );
}
//Define the timer
hwRes = m2mb_hwTmr_init( &tmrHwHandle, &tmrHwAttrHandle );
if( hwRes != M2MB_HWTMR_SUCCESS )
{
m2mb_hwTmr_setAttrItem( &tmrHwAttrHandle, 1, M2MB_HWTMR_SEL_CMD_DEL_ATTR, NULL );
PrintToUart("\r\nDefine the timer, error %d", hwRes);
}
else
{
PrintToUart( "\r\nDefine the timer" );
}
//Start the timer in case no M2MB_HWTMR_AUTOSTART attribute was used
hwRes = m2mb_hwTmr_start( tmrHwHandle );
if( hwRes != M2MB_HWTMR_SUCCESS )
{
PrintToUart("\r\nStart the timer, error %d", hwRes);
}
else
{
PrintToUart( "\r\nStart the timer" );
}
//Stop a running the timer
hwRes = m2mb_hwTmr_stop( tmrHwHandle );
if( hwRes != M2MB_HWTMR_SUCCESS )
{
PrintToUart("\r\nStopa running the timer, error %d", hwRes);
}
else
{
PrintToUart("\r\nStopa running the timer" );
}
timeDuration++;
//Set attribute [time duration] of the timer
hwRes = m2mb_hwTmr_setItem( tmrHwHandle, M2MB_HWTMR_SEL_CMD_TIME_DURATION, ( void * )timeDuration );
if( hwRes != M2MB_HWTMR_SUCCESS )
{
PrintToUart("\r\nSet attribute [time duration] of the timer, error %d", hwRes);
}
else
{
PrintToUart("\r\nSet attribute [time duration] of the timer" );
}
//Undef the timer
m2mb_hwTmr_deinit( tmrHwHandle );
}

◆ m2mb_hwTmr_setAttrItem()

M2MB_HWTMR_RESULT_E m2mb_hwTmr_setAttrItem ( M2MB_HWTMR_ATTR_HANDLE *  pTmrHwAttrHandle,
UINT8  nCmds,
  ... 
)

Set specific attribute for timer creation.

This service set the attribute (or create it) to be used for timer creation

Parameters
[in]pTmrHwAttrHandlepointer to timer attribute
[in]nCmdsnumber of commands to be issued at once
[in]...variable inputs, N cmds (see M2MB_HWTMR_SEL_CMD_E) followed by N arguments for their respective issued commands. CMDS(...) and CMDS_ARGS(...) macro can be used to better insert cmd and parameters and to better control right insertion
Returns
M2MB_HWTMR_SUCCESS in case of success see M2MB_HWTMR_RESULT_E in case of error
Note
The attribute set are useful for timer creation. Once created, use instead m2mb_hwTmr_setItem() to set only available timer properties It is under application responsibility the right use of m2mb_hwTmr_setAttrItem.

Example

◆ m2mb_hwTmr_setItem()

M2MB_HWTMR_RESULT_E m2mb_hwTmr_setItem ( M2MB_HWTMR_HANDLE  tmrHwHandle,
M2MB_HWTMR_SEL_CMD_E  selCmd,
void *  pIn 
)

Set specific properties of the timer.

This service set value for specified parameter of the specified timer if available Selecting cmd, a parameter to be set can be selected To be used when timer is already created: its right usage is under application responsibility

Parameters
[in]tmrHwHandlehandle of timer
[in]selCmdSelect parameter to be set (see M2MB_HWTMR_SEL_CMD_E)
[in]pIn
Returns
M2MB_HWTMR_SUCCESS in case of success see M2MB_HWTMR_RESULT_E in case of error
Note
It is the application's responsibility to set the values in right context, for example the change of callback or periodicity should better be done inside expiration callback, or by stopping involved timer first Not all M2MB_HWTMR_SEL_CMD_E are allowed: none if timer is not running e.g Allowed only if timer is not running: M2MB_HWTMR_SEL_CMD_CB_FUNC M2MB_HWTMR_SEL_CMD_ARG_CB M2MB_HWTMR_SEL_CMD_TICKS_PERIOD M2MB_HWTMR_SEL_CMD_TIME_DURATION M2MB_HWTMR_SEL_CMD_PERIODIC

Example

◆ m2mb_hwTmr_start()

M2MB_HWTMR_RESULT_E m2mb_hwTmr_start ( M2MB_HWTMR_HANDLE  tmrHwHandle)

Start application timer.

This service starts the specified application timer. The expiration routines of timers that expire at the same time are executed in the order they were activated.

Parameters
[in]tmrHwHandlehandle of timer
Returns
M2MB_HWTMR_SUCCESS in case of success see M2MB_HWTMR_RESULT_E in case of error
Note
Start is allowed only if timeout is grater than 0

Example

◆ m2mb_hwTmr_stop()

M2MB_HWTMR_RESULT_E m2mb_hwTmr_stop ( M2MB_HWTMR_HANDLE  tmrHwHandle)

Stop an application timer.

This service stops the specified application timer. If the timer is already stopped, this service has no effect

Parameters
[in]tmrHwHandlehandle of timer
Returns
M2MB_HWTMR_SUCCESS in case of success see M2MB_HWTMR_RESULT_E in case of error
Note

Example

◆ m2mb_hwTmr_timeGet_ms()

M2MB_HWTMR_RESULT_E m2mb_hwTmr_timeGet_ms ( UINT64 *  ms_time)

get time in ms

Get a timestamp from System Time in millisecond units from 6 Jan 1980 00:00:00.

Returns
M2MB_HWTMR_SUCCESS in case of success see M2MB_HWTMR_RESULT_E in case of error

Example

m2mb_hwTmr_init
M2MB_HWTMR_RESULT_E m2mb_hwTmr_init(M2MB_HWTMR_HANDLE *pTmrHwHandle, M2MB_HWTMR_ATTR_HANDLE *pTmrHwAttr)
Application timer Creation.
m2mb_hwTmr_setAttrItem
M2MB_HWTMR_RESULT_E m2mb_hwTmr_setAttrItem(M2MB_HWTMR_ATTR_HANDLE *pTmrHwAttrHandle, UINT8 nCmds,...)
Set specific attribute for timer creation.
m2mb_hwTmr_start
M2MB_HWTMR_RESULT_E m2mb_hwTmr_start(M2MB_HWTMR_HANDLE tmrHwHandle)
Start application timer.
m2mb_hwTmr_setItem
M2MB_HWTMR_RESULT_E m2mb_hwTmr_setItem(M2MB_HWTMR_HANDLE tmrHwHandle, M2MB_HWTMR_SEL_CMD_E selCmd, void *pIn)
Set specific properties of the timer.
m2mb_hwTmr_deinit
M2MB_HWTMR_RESULT_E m2mb_hwTmr_deinit(M2MB_HWTMR_HANDLE tmrHwHandle)
Timer deinit => deletion.
m2mb_hwTmr_stop
M2MB_HWTMR_RESULT_E m2mb_hwTmr_stop(M2MB_HWTMR_HANDLE tmrHwHandle)
Stop an application timer.