no-OS
Macros | Functions | Variables
aducm3029_timer.c File Reference

Implementation of TIMER driver for ADuCM302x. More...

#include <stdlib.h>
#include <drivers/pwr/adi_pwr.h>
#include "aducm3029_timer.h"
#include "no_os_timer.h"
#include "no_os_error.h"
#include "no_os_alloc.h"
Include dependency graph for aducm3029_timer.c:

Macros

#define NO_OS_HFOSC_LOAD   26000u
 
#define NO_OS_FREQ_1KHZ   1000u
 
#define NO_OS_FREQ_1MHZ   1000000u
 
#define NO_OS_MHZ26_TO_US(count)   ((NO_OS_HFOSC_LOAD - count) / (NO_OS_HFOSC_LOAD / 1000u))
 

Functions

int32_t aducm3029_timer_init (struct no_os_timer_desc **desc, const struct no_os_timer_init_param *param)
 Initialize a instance of a timer. More...
 
int32_t aducm3029_timer_remove (struct no_os_timer_desc *desc)
 Remove a instance of a timer. More...
 
int32_t aducm3029_timer_start (struct no_os_timer_desc *desc)
 Enable counting in the timer instance. More...
 
int32_t aducm3029_timer_stop (struct no_os_timer_desc *desc)
 Stop counting the timer instance. More...
 
int32_t aducm3029_timer_counter_get (struct no_os_timer_desc *desc, uint32_t *counter)
 Get the value the timer is at. More...
 
int32_t aducm3029_timer_counter_set (struct no_os_timer_desc *desc, uint32_t new_val)
 Set a new value for the timer. More...
 
int32_t aducm3029_timer_count_clk_get (struct no_os_timer_desc *desc, uint32_t *freq_hz)
 Get the frequency the timer counts with. More...
 
int32_t aducm3029_timer_count_clk_set (struct no_os_timer_desc *desc, uint32_t freq_hz)
 Set the frequency the timer counts with. More...
 
int32_t aducm3029_timer_get_elapsed_time_nsec (struct no_os_timer_desc *desc, uint64_t *elapsed_time)
 Get the elapsed time in nsec for the timer. More...
 

Variables

const struct no_os_timer_platform_ops aducm_timer_ops
 aducm3029 platform specific timer platform ops structure 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

◆ NO_OS_FREQ_1KHZ

#define NO_OS_FREQ_1KHZ   1000u

1 KHz value

◆ NO_OS_FREQ_1MHZ

#define NO_OS_FREQ_1MHZ   1000000u

1 MHz value

◆ NO_OS_HFOSC_LOAD

#define NO_OS_HFOSC_LOAD   26000u

With this load we get an interrupt each millisecond

◆ NO_OS_MHZ26_TO_US

#define NO_OS_MHZ26_TO_US (   count)    ((NO_OS_HFOSC_LOAD - count) / (NO_OS_HFOSC_LOAD / 1000u))

Converts the timer value into microseconds

Function Documentation

◆ aducm3029_timer_count_clk_get()

int32_t aducm3029_timer_count_clk_get ( struct no_os_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
0 in case of success, -1 otherwise.

◆ aducm3029_timer_count_clk_set()

int32_t aducm3029_timer_count_clk_set ( struct no_os_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
0 in case of success, -1 otherwise.

◆ aducm3029_timer_counter_get()

int32_t aducm3029_timer_counter_get ( struct no_os_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
0 in case of success, -1 otherwise.

◆ aducm3029_timer_counter_set()

int32_t aducm3029_timer_counter_set ( struct no_os_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
0 in case of success, -1 otherwise.

◆ aducm3029_timer_get_elapsed_time_nsec()

int32_t aducm3029_timer_get_elapsed_time_nsec ( struct no_os_timer_desc desc,
uint64_t *  elapsed_time 
)

Get the elapsed time in nsec for the timer.

Parameters
[in]desc- Pointer to the device handler.
[in]elapsed_time- The elapsed time in nsec.
Returns
0 in case of success, error code otherwise.

◆ aducm3029_timer_init()

int32_t aducm3029_timer_init ( struct no_os_timer_desc **  desc,
const struct no_os_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 no_os_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
0 in case of success, -1 otherwise.

◆ aducm3029_timer_remove()

int32_t aducm3029_timer_remove ( struct no_os_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
0 in case of success, -1 otherwise.

◆ aducm3029_timer_start()

int32_t aducm3029_timer_start ( struct no_os_timer_desc desc)

Enable counting in the timer instance.

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

Parameters
desc- Descriptor of the timer instance.
Returns
0 in case of success, -1 otherwise.

◆ aducm3029_timer_stop()

int32_t aducm3029_timer_stop ( struct no_os_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
0 in case of success, -1 otherwise.

Variable Documentation

◆ aducm_timer_ops

const struct no_os_timer_platform_ops aducm_timer_ops
Initial value:
= {
.counter_get = &aducm3029_timer_counter_get,
.counter_set = &aducm3029_timer_counter_set,
.count_clk_get = &aducm3029_timer_count_clk_get,
.count_clk_set = &aducm3029_timer_count_clk_set,
.get_elapsed_time_nsec = &aducm3029_timer_get_elapsed_time_nsec,
}

aducm3029 platform specific timer platform ops structure

aducm3029 specific timer platform ops structure

aducm3029_timer_start
int32_t aducm3029_timer_start(struct no_os_timer_desc *desc)
Enable counting in the timer instance.
Definition: aducm3029_timer.c:257
aducm3029_timer_count_clk_set
int32_t aducm3029_timer_count_clk_set(struct no_os_timer_desc *desc, uint32_t freq_hz)
Set the frequency the timer counts with.
Definition: aducm3029_timer.c:413
aducm3029_timer_stop
int32_t aducm3029_timer_stop(struct no_os_timer_desc *desc)
Stop counting the timer instance.
Definition: aducm3029_timer.c:288
aducm3029_timer_counter_get
int32_t aducm3029_timer_counter_get(struct no_os_timer_desc *desc, uint32_t *counter)
Get the value the timer is at.
Definition: aducm3029_timer.c:320
aducm3029_timer_get_elapsed_time_nsec
int32_t aducm3029_timer_get_elapsed_time_nsec(struct no_os_timer_desc *desc, uint64_t *elapsed_time)
Get the elapsed time in nsec for the timer.
Definition: aducm3029_timer.c:430
aducm3029_timer_counter_set
int32_t aducm3029_timer_counter_set(struct no_os_timer_desc *desc, uint32_t new_val)
Set a new value for the timer.
Definition: aducm3029_timer.c:374
aducm3029_timer_remove
int32_t aducm3029_timer_remove(struct no_os_timer_desc *desc)
Remove a instance of a timer.
Definition: aducm3029_timer.c:217
aducm3029_timer_init
int32_t aducm3029_timer_init(struct no_os_timer_desc **desc, const struct no_os_timer_init_param *param)
Initialize a instance of a timer.
Definition: aducm3029_timer.c:110
aducm3029_timer_count_clk_get
int32_t aducm3029_timer_count_clk_get(struct no_os_timer_desc *desc, uint32_t *freq_hz)
Get the frequency the timer counts with.
Definition: aducm3029_timer.c:395