Microchip® Advanced Software Framework

thirdparty/wireless/lorawan/services/sw_timer/inc/sw_timer.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include "sys.h"
#include "stack_common.h"
#include "system_task_manager.h"

Data Structures

struct  _SwTimer
 

Macros

#define ADD_TIME(a, b)   ((a) + (b))
 Adds two time values. More...
 
#define MS_TO_US(m)   ((m) * (1000))
 
#define SUB_TIME(a, b)   ((a) - (b))
 Subtracts two time values. More...
 
#define SW_TIMESTAMP_INVALID   (UINT64_MAX)
 
#define SW_TIMESTAMP_MAX   (UINT64_MAX)
 
#define SWTIMER_HWTIME_MASK   (0xFFFF)
 
#define SWTIMER_INVALID   (0xFF)
 
#define SWTIMER_INVALID_TIMEOUT   (0xFFFFFFFF)
 
#define SWTIMER_MAX_TIMEOUT   (0x7FFFFFFF)
 
#define SWTIMER_MIN_TIMEOUT   (0xff)
 
#define SWTIMER_SYSTIME_SHIFTMASK   (16)
 
#define US_TO_MS(u)   ((u) / (1000))
 

Typedefs

typedef enum _SwTimeoutType SwTimeoutType_t
 
typedef struct _SwTimer SwTimer_t
 
typedef void(* SwTimerCallbackFunc_t )(void *)
 
typedef uint64_t SwTimestamp_t
 

Enumerations

enum  _SwTimeoutType {
  SW_TIMEOUT_RELATIVE,
  SW_TIMEOUT_ABSOLUTE
}
 

Functions

StackRetStatus_t SwTimerCreate (uint8_t *timerId)
 Returns a timer id to be used before starting a timer. More...
 
uint64_t SwTimerGetTime (void)
 Get current system time. More...
 
bool SwTimerIsRunning (uint8_t timerid)
 Checks whether a given timer is running or not. More...
 
uint32_t SwTimerNextExpiryDuration (void)
 Returns the duration until the next timer expiry. More...
 
void SwTimerReadTimestamp (uint8_t index, SwTimestamp_t *timestamp)
 Returns the timestamp stored in the given timestamp index. More...
 
uint32_t SwTimerReadValue (uint8_t timerId)
 Returns the remaining timeout for the given timerId. More...
 
void SwTimerReset (void)
 Resets the Software Timer module. More...
 
void SwTimerRunRemainingTime (uint32_t offset)
 Run the running timer for the given offset. More...
 
void SwTimersExecute (void)
 Handles Queues and Callbacks for Expired Timers. More...
 
StackRetStatus_t SwTimerStart (uint8_t timerId, uint32_t timerCount, SwTimeoutType_t timeoutType, void *timerCb, void *paramCb)
 Starts a timer. More...
 
StackRetStatus_t SwTimerStop (uint8_t timerId)
 Stops a running timer. More...
 
SwTimestamp_t SwTimerTimeDiff (SwTimestamp_t *earlier, SwTimestamp_t *later)
 Difference between the given timestamps. More...
 
StackRetStatus_t SwTimerTimestampCreate (uint8_t *timestampId)
 Returns a timestamp id to be used before using it. More...
 
void SwTimerWriteTimestamp (uint8_t index, SwTimestamp_t *timestamp)
 Stores the timestamp in the given timestamp index. More...
 
void SystemTimerInit (void)
 Initializes the Software Timer module. More...
 
void SystemTimerSuspend (void)
 Suspends the software timer. More...
 
void SystemTimerSync (uint64_t timeToSync)
 Resumes the software timer by offseting it with given time. More...
 
SYSTEM_TaskStatus_t TIMER_TaskHandler (void)
 Handler for the timer tasks. More...
 

#define ADD_TIME (   a,
 
)    ((a) + (b))

Adds two time values.

Referenced by pal_add_time_us().

#define SUB_TIME (   a,
 
)    ((a) - (b))

Subtracts two time values.

Referenced by calculate_time_duration(), and pal_sub_time_us().

#define SW_TIMESTAMP_INVALID   (UINT64_MAX)
#define SW_TIMESTAMP_MAX   (UINT64_MAX)
#define SWTIMER_HWTIME_MASK   (0xFFFF)
#define SWTIMER_INVALID   (0xFF)

Referenced by LongTimerReset(), and LongTimerStart().

#define SWTIMER_INVALID_TIMEOUT   (0xFFFFFFFF)

Referenced by PMM_Sleep(), and validateSleepDuration().

#define SWTIMER_MAX_TIMEOUT   (0x7FFFFFFF)
#define SWTIMER_MIN_TIMEOUT   (0xff)
#define SWTIMER_SYSTIME_SHIFTMASK   (16)

typedef struct _SwTimer SwTimer_t
typedef void(* SwTimerCallbackFunc_t)(void *)
typedef uint64_t SwTimestamp_t

Enumerator
SW_TIMEOUT_RELATIVE 

The timeout is relative to the current time.

SW_TIMEOUT_ABSOLUTE 

The timeout is an absolute value.

StackRetStatus_t SwTimerCreate ( uint8_t *  timerId)

Returns a timer id to be used before starting a timer.

Parameters
[out]timerIdValue of the id returned by the function
Returns
LORAWAN_SUCCESS if new timerId is allocated LORAWAN_RESOURCE_UNAVAILABLE if there is no more timerId to allocate

Referenced by cert_app_init(), CreateAllRegSoftwareTimers(), LongTimerInit(), main(), and MSG_Init().

uint64_t SwTimerGetTime ( void  )

Get current system time.

Returns
Returns current system time in microseconds
bool SwTimerIsRunning ( uint8_t  timerid)

Checks whether a given timer is running or not.

Parameters
[in]timerIdTimer ID to be checked for running
Returns
True if the timer is running else False

Referenced by enddevice_cpc_execute_command(), LongTimerReset(), LORAREG_GetAttr_JoinDutyCycleRemainingTime(), SearchAvailableChannel1(), SearchAvailableChannel2(), setDutyCycleTimer(), setJoinBackoffCntl(), setJoinDutyCycleTimer(), and setLBTTimer().

uint32_t SwTimerNextExpiryDuration ( void  )

Returns the duration until the next timer expiry.

Returns
Returns the duration until the next timeout in microseconds

Referenced by PMM_Sleep().

void SwTimerReadTimestamp ( uint8_t  index,
SwTimestamp_t timestamp 
)

Returns the timestamp stored in the given timestamp index.

Parameters
[in]indexIndex of the system timestamp
[out]*timestampPointer-to-timestamp to be read from the given index
uint32_t SwTimerReadValue ( uint8_t  timerId)

Returns the remaining timeout for the given timerId.

Parameters
[in]timerIdTimer ID to get the remaining time
Returns
Remaining time until expiry in microseconds

Referenced by LORAREG_GetAttr_DutyCycleTimer(), LORAREG_GetAttr_JoinDutyCycleRemainingTime(), setDutyCycleTimer(), setJoinDutyCycleTimer(), and setLBTTimer().

void SwTimerReset ( void  )

Resets the Software Timer module.

void SwTimerRunRemainingTime ( uint32_t  offset)

Run the running timer for the given offset.

Parameters
[in]offsetNew time duration for the running timer
void SwTimersExecute ( void  )

Handles Queues and Callbacks for Expired Timers.

StackRetStatus_t SwTimerStart ( uint8_t  timerId,
uint32_t  timerCount,
SwTimeoutType_t  timeoutType,
void *  timerCb,
void *  paramCb 
)

Starts a timer.

   This function starts a regular timer and installs the corresponding
   callback function handle the timeout event.
Parameters
[in]timerIdTimer identifier
[in]timerCountTimeout in microseconds
[in]timeoutTypeSW_TIMEOUT_RELATIVE or SW_TIMEOUT_ABSOLUTE
[in]timerCbCallback handler invoked upon timer expiry
[in]paramCbArgument for the callback handler
Returns
LORAWAN_INVALID_PARAMETER if at least one input parameter in invalid LORAWAN_INVALID_REQUEST if is already running LORAWAN_SUCCESS if is successfully queued for running

Referenced by cert_app_timer_callback(), cert_joindata_callback(), demoTimerCb(), DutyCycleCallback(), enddevice_cpc_execute_command(), JoinBackoffCallback(), JoinDutyCycleCallback(), LBTChannelPauseCallback(), LongTimerCallback(), LongTimerStart(), lTimerCb(), messageSendProcess(), mote_demo_init(), processTransactionComplete(), setDutyCycleTimer(), setJoinBackOffTimer(), setJoinDutyCycleTimer(), and setLBTTimer().

StackRetStatus_t SwTimerStop ( uint8_t  timerId)

Stops a running timer.

It stops a running timer with specified timerId

Parameters
timer_idTimer identifier
Returns
LORAWAN_INVALID_PARAMETER if timerId is not valid LORAWAN_INVALID_REQUEST if timerId was not started before LORAWAN_SUCCESS if it is successfully stopped

Referenced by cert_handle_cert_rx_data(), demo_appdata_callback(), enddevice_cpc_execute_command(), enddevice_cpc_fresh_join(), JoinDutyCycleCallback(), LongTimerReset(), setDutyCycleTimer(), setJoinBackoffCntl(), setJoinBackOffTimer(), setJoinDutyCycleTimer(), setLBTTimer(), StopAllRegSoftwareTimers(), and SysExitFromSleep().

SwTimestamp_t SwTimerTimeDiff ( SwTimestamp_t earlier,
SwTimestamp_t later 
)

Difference between the given timestamps.

Parameters
[in]*earlierPointer-to-timestamp of known-to-be-earlier time
[in]*laterPointer-to-timestamp of known-to-be-later time
Returns
SwTimestamp_t - time difference between later and earlier timestamps
StackRetStatus_t SwTimerTimestampCreate ( uint8_t *  timestampId)

Returns a timestamp id to be used before using it.

Parameters
[out]timestampIdValue of the id returned by the function
Returns
LORAWAN_SUCCESS if new timerId is allocated LORAWAN_RESOURCE_UNAVAILABLE if there is no more timerId to allocate
void SwTimerWriteTimestamp ( uint8_t  index,
SwTimestamp_t timestamp 
)

Stores the timestamp in the given timestamp index.

Parameters
[in]indexIndex of the system timestamp
[in]*timestampPointer-to-timestamp to be stored in the given index
void SystemTimerInit ( void  )

Initializes the Software Timer module.

void SystemTimerSuspend ( void  )

Suspends the software timer.

Referenced by PMM_Sleep().

void SystemTimerSync ( uint64_t  timeToSync)

Resumes the software timer by offseting it with given time.

Parameters
[in]timeToSyncAmount of duration to offset from known system time

Referenced by PMM_Wakeup().

SYSTEM_TaskStatus_t TIMER_TaskHandler ( void  )

Handler for the timer tasks.

Returns
SYSTEM_TASK_SUCCESS after servicing the timer triggers