LoRa-BLE-Sensor
Loading...
Searching...
No Matches
Functions
sensor_timer.c File Reference

This is a library to keep track of sensor and radio timers. Manages alarms for sensors and radio transmissions. This library is used by the sensor_scheduling library to schedule sensor readings and radio transmissions. More...

#include <sensor_timer.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
Include dependency graph for sensor_timer.c:

Functions

 LOG_MODULE_REGISTER (SENSOR_TIMER, LOG_LEVEL_INF)
 
int sensor_timer_init (const struct device *dev)
 Initialize the chosen sensor timer instance and create a top value callback to increment the total overflown seconds. This also starts the timer.
 
int sensor_timer_start (const struct device *dev)
 Start the chosen sensor timer instance.
 
int sensor_timer_get_current_seconds (const struct device *dev)
 Get the current seconds the timer was started. This value resets every time the timer is reset or top value is reached.
 
int sensor_timer_get_total_seconds (const struct device *dev)
 Get the total seconds the timer has been running. This value is reset when the timer is reset.
 
int sensor_timer_reset (const struct device *dev)
 Reset the chosen sensor timer instance. This also resets the total seconds to 0.
 
int sensor_timer_stop (const struct device *dev)
 Stop the chosen sensor timer instance. Timer will remain at the current value.
 
int sensor_timer_set_alarm (const struct device *dev, sensor_timer_alarm_cfg_t *sensor_timer_alarm_cfg)
 Set the alarm for the chosen sensor timer instance, also setting the top value of the timer to the chosen alarm value. When the alarm is triggered, the callback function will be called and the timer will be reset. In alarm callback, the is_alarm_set needs to be set to 0 manually.
 
int sensor_timer_cancel_alarm (const struct device *dev, uint8_t channel)
 Cancel the alarm for the chosen channel of the sensor timer instance.
 

Detailed Description

This is a library to keep track of sensor and radio timers. Manages alarms for sensors and radio transmissions. This library is used by the sensor_scheduling library to schedule sensor readings and radio transmissions.

Author
Tyler Garcia
Version
0.1
Date
2025-05-09

Function Documentation

◆ sensor_timer_cancel_alarm()

int sensor_timer_cancel_alarm ( const struct device *  dev,
uint8_t  channel 
)

Cancel the alarm for the chosen channel of the sensor timer instance.

Parameters
devThe timer device to cancel the alarm for.
channelThe channel to cancel the alarm for.
Returns
0 on success, negative error code on failure.

◆ sensor_timer_get_current_seconds()

int sensor_timer_get_current_seconds ( const struct device *  dev)

Get the current seconds the timer was started. This value resets every time the timer is reset or top value is reached.

Parameters
devThe timer device to get the seconds from.
Returns
The seconds elapsed since the timer was started, or negative error code on failure.

◆ sensor_timer_get_total_seconds()

int sensor_timer_get_total_seconds ( const struct device *  dev)

Get the total seconds the timer has been running. This value is reset when the timer is reset.

Parameters
devThe timer device to get the total seconds from.
Returns
The total seconds the timer has been running, or negative error code on failure.

◆ sensor_timer_init()

int sensor_timer_init ( const struct device *  dev)

Initialize the chosen sensor timer instance and create a top value callback to increment the total overflown seconds. This also starts the timer.

Parameters
devThe timer device to initialize.
Returns
0 on success, negative error code on failure.

◆ sensor_timer_reset()

int sensor_timer_reset ( const struct device *  dev)

Reset the chosen sensor timer instance. This also resets the total seconds to 0.

Parameters
devThe timer device to reset.
Returns
0 on success, negative error code on failure.

◆ sensor_timer_set_alarm()

int sensor_timer_set_alarm ( const struct device *  dev,
sensor_timer_alarm_cfg_t sensor_timer_alarm_cfg 
)

Set the alarm for the chosen sensor timer instance, also setting the top value of the timer to the chosen alarm value. When the alarm is triggered, the callback function will be called and the timer will be reset. In alarm callback, the is_alarm_set needs to be set to 0 manually.

Parameters
devThe timer device to set the alarm for.
sensor_timer_alarm_cfgThe alarm configuration to set.
Returns
0 on success, negative error code on failure.

◆ sensor_timer_start()

int sensor_timer_start ( const struct device *  dev)

Start the chosen sensor timer instance.

Parameters
devThe timer device to start.
Returns
0 on success, negative error code on failure.

◆ sensor_timer_stop()

int sensor_timer_stop ( const struct device *  dev)

Stop the chosen sensor timer instance. Timer will remain at the current value.

Parameters
devThe timer device to stop.
Returns
0 on success, negative error code on failure.