no-OS
Classes | Functions
timer.h File Reference

Timer control module header. More...

#include <stdint.h>
Include dependency graph for timer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  timer_desc
 Structure holding timer descriptor. More...
 
struct  timer_init_param
 Structure holding the parameters for timer initialization. More...
 

Functions

int32_t timer_init (struct timer_desc **desc, struct timer_init_param *param)
 Initialize a instance of a timer. More...
 
int32_t timer_remove (struct timer_desc *desc)
 Remove a instance of a timer. More...
 
int32_t timer_start (struct timer_desc *desc)
 Enable counting in the timer instance. More...
 
int32_t timer_stop (struct timer_desc *desc)
 Stop counting the timer instance. More...
 
int32_t timer_counter_get (struct timer_desc *desc, uint32_t *counter)
 Get the value the timer is at. More...
 
int32_t timer_counter_set (struct timer_desc *desc, uint32_t new_val)
 Set a new value for the timer. More...
 
int32_t timer_count_clk_get (struct timer_desc *desc, uint32_t *freq_hz)
 Get the frequency the timer counts with. More...
 
int32_t timer_count_clk_set (struct timer_desc *desc, uint32_t freq_hz)
 Set the frequency the timer counts with. More...
 

Detailed Description

Timer control module header.

Author
Andrei Drimbarean (andre.nosp@m.i.dr.nosp@m.imbar.nosp@m.ean@.nosp@m.analo.nosp@m.g.co.nosp@m.m)

Copyright 2019(c) Analog Devices, Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Andrei Drimbarean (andre.nosp@m.i.dr.nosp@m.imbar.nosp@m.ean@.nosp@m.analo.nosp@m.g.co.nosp@m.m)

Copyright 2020(c) Analog Devices, Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ timer_count_clk_get()

int32_t timer_count_clk_get ( struct timer_desc desc,
uint32_t *  freq_hz 
)

Get the frequency the timer counts with.

Parameters
desc- Descriptor of the timer instance.
freq_hz- Pointer where the frequency value will be stored
Returns
SUCCESS in case of success, FAILURE otherwise.

Get the frequency the timer counts with.

Parameters
[in]desc- Pointer to the device handler.
[out]freq_hz- The value in Hz of the timer clock.
Returns
0 in case of success, error code otherwise.

Get the frequency the timer counts with.

Parameters
[in]desc- Pointer to the device handler.
[out]freq_hz- Pointer to the returned frequency.
Returns
SUCCESS in case of success, FAILURE otherwise

◆ timer_count_clk_set()

int32_t timer_count_clk_set ( struct timer_desc desc,
uint32_t  freq_hz 
)

Set the frequency the timer counts with.

Note
This function can be called only when the timer is stopped.
Parameters
desc- Descriptor of the timer instance.
freq_hz- Value of the new frequency to be set
Returns
SUCCESS in case of success, FAILURE otherwise.

Set the frequency the timer counts with.

Parameters
[in]desc- Pointer to the device handler.
[in]freq_hz- The value in Hz of the new timer clock.
Returns
0 in case of success, error code otherwise.

Set the frequency the timer counts with.

Parameters
[in]desc- Pointer to the device handler.
[in]freq_hz- New timer frequency in hertz.
Returns
SUCCESS in case of success, FAILURE otherwise
Here is the caller graph for this function:

◆ timer_counter_get()

int32_t timer_counter_get ( struct timer_desc desc,
uint32_t *  counter 
)

Get the value the timer is at.

Parameters
desc- Descriptor of the timer instance.
counter- Pointer were the timer counter is stored.
Returns
SUCCESS in case of success, FAILURE otherwise.

Get the value the timer is at.

Parameters
[in]desc- Pointer to the device handler.
[out]counter- Pointer to the counter value.
Returns
0 in case of success, error code otherwise.

Get the value the timer is at.

Parameters
[in]desc- Pointer to the device handler.
[out]counter- Pointer to the current counter value.
Returns
SUCCESS in case of success, FAILURE otherwise
Here is the caller graph for this function:

◆ timer_counter_set()

int32_t timer_counter_set ( struct timer_desc desc,
uint32_t  new_val 
)

Set a new value for the timer.

Note
This function can be called only when the timer is stopped.
Parameters
desc- Descriptor of the timer instance.
new_val- Value of the new counter to be set
Returns
SUCCESS in case of success, FAILURE otherwise.

Set a new value for the timer.

Parameters
[in]desc- Pointer to the device handler.
[in]new_val- The new value of the counter register.
Returns
0 in case of success, error code otherwise.

Set a new value for the timer.

Parameters
[in]desc- Pointer to the device handler.
[in]new_val- New value for the timer counter.
Returns
SUCCESS in case of success, FAILURE otherwise
Here is the caller graph for this function:

◆ timer_init()

int32_t timer_init ( struct timer_desc **  desc,
struct timer_init_param param 
)

Initialize a instance of a timer.

The created descriptor must be used in the next driver calls to identify the timer instance.
The user can create multiple instances but only one hardware timer will be used.
The timer used is defined by the timer_init_param::id .
The driver will use the timer selected for the first instance for all the new ones. If it is needed to change the hardware timer, the user must remove all the instances and initialize a new one for the desired hardware timer.

Parameters
desc- Pointer to descriptor of the instance that will be created.
param- Parameter used to configure the new instance. The extra field is unused and should be NULL.
Returns
SUCCESS in case of success, FAILURE otherwise.

Initialize a instance of a timer.

Parameters
[out]desc- Pointer to the reference of the device handler.
[in]param- Initialization structure.
Returns
0 in case of success, negative error code otherwise

Initialize a instance of a timer.

Parameters
[out]desc- Pointer to the reference of the device handler.
[in]param- Initialization structure.
Returns
SUCCESS in case of success, FAILURE otherwise
Here is the caller graph for this function:

◆ timer_remove()

int32_t timer_remove ( struct timer_desc desc)

Remove a instance of a timer.

If there are no more instances it stops the hardware timer.

Parameters
desc- Descriptor of the timer instance.
Returns
SUCCESS in case of success, FAILURE otherwise.

Remove a instance of a timer.

Parameters
[in]desc- Pointer to the device handler.
Returns
0 in case of success, negative error code otherwise

Remove a instance of a timer.

Parameters
[in]desc- Pointer to the device handler.
Returns
SUCCESS in case of success, FAILURE otherwise

◆ timer_start()

int32_t timer_start ( struct timer_desc desc)

Enable counting in the timer instance.

The timer starts counting from the load value used in timer_init(), set by timer_counter_set() or from the value the timer stopped at.

Parameters
desc- Descriptor of the timer instance.
Returns
SUCCESS in case of success, FAILURE otherwise.

Enable counting in the timer instance.

Parameters
[in]desc- Pointer to the device handler.
Returns
0 in case of success, negative error code otherwise

Enable counting in the timer instance.

Parameters
[in]desc- Pointer to the device handler.
Returns
SUCCESS in case of success, FAILURE otherwise

◆ timer_stop()

int32_t timer_stop ( struct timer_desc desc)

Stop counting the timer instance.

If there are no more timer instance started it also stops the hardware timer.

Parameters
desc- Descriptor of the timer instance.
Returns
SUCCESS in case of success, FAILURE otherwise.

Stop counting the timer instance.

Parameters
[in]desc- Pointer to the device handler.
Returns
0 in case of success, negative error code otherwise

Stop counting the timer instance.

Parameters
[in]desc- Pointer to the device handler.
Returns
SUCCESS in case of success, FAILURE otherwise