no-OS
Macros | Functions
timer.c File Reference

Implementation of TIMER driver for ADuCM302x. More...

#include <stdlib.h>
#include <drivers/tmr/adi_tmr.h>
#include "timer_extra.h"
#include "timer.h"
#include "error.h"
Include dependency graph for timer.c:

Macros

#define HFOSC_LOAD   26000u
 
#define FREQ_1KHZ   1000u
 
#define FREQ_1MHZ   1000000u
 
#define MHZ26_TO_US(count)   ((HFOSC_LOAD - count) / (HFOSC_LOAD / 1000u))
 

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

Implementation of TIMER driver for ADuCM302x.

This driver enables the user to create multiple instance of a timer using only one hardware timer of the ADuCM3029.

Author
Mihail Chindris (mihai.nosp@m.l.ch.nosp@m.indri.nosp@m.s@an.nosp@m.alog..nosp@m.com)

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.

Macro Definition Documentation

◆ FREQ_1KHZ

#define FREQ_1KHZ   1000u

1 KHz value

◆ FREQ_1MHZ

#define FREQ_1MHZ   1000000u

1 MHz value

◆ HFOSC_LOAD

#define HFOSC_LOAD   26000u

With this load we get an interrupt each millisecond

◆ MHZ26_TO_US

#define MHZ26_TO_US (   count)    ((HFOSC_LOAD - count) / (HFOSC_LOAD / 1000u))

Converts the timer value into microseconds

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.

◆ 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.

◆ 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.
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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.