no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stm32_timer.c File Reference

Implementation of stm32 timer driver. More...

#include <stdlib.h>
#include <errno.h>
#include "no_os_util.h"
#include "no_os_timer.h"
#include "no_os_alloc.h"
#include "stm32_timer.h"
Include dependency graph for stm32_timer.c:

Functions

int32_t stm32_timer_init (struct no_os_timer_desc **desc, const struct no_os_timer_init_param *param)
 Initialize the timer peripheral.
 
int32_t stm32_timer_remove (struct no_os_timer_desc *desc)
 Free the resources allocated by no_os_timer_init().
 
int32_t stm32_timer_start (struct no_os_timer_desc *desc)
 Start a timer.
 
int32_t stm32_timer_stop (struct no_os_timer_desc *desc)
 Stop a timer from counting.
 
int32_t stm32_timer_counter_get (struct no_os_timer_desc *desc, uint32_t *counter)
 Get the value of the counter register for the timer.
 
int32_t stm32_timer_counter_set (struct no_os_timer_desc *desc, uint32_t new_val)
 Set the timer counter register value.
 
int32_t stm32_timer_count_clk_get (struct no_os_timer_desc *desc, uint32_t *freq_hz)
 Get the timer clock frequency.
 
int32_t stm32_timer_count_clk_set (struct no_os_timer_desc *desc, uint32_t freq_hz)
 Set the timer clock frequency.
 
int32_t stm32_timer_get_elapsed_time_nsec (struct no_os_timer_desc *desc, uint64_t *elapsed_time)
 Get the elapsed time in nsec for the timer.
 

Variables

const struct no_os_timer_platform_ops stm32_timer_ops
 stm32 platform specific timer platform ops structure
 

Detailed Description

Implementation of stm32 timer driver.

Author
RBolboac (ramon.nosp@m.a.bo.nosp@m.lboac.nosp@m.a@an.nosp@m.alog..nosp@m.com)

Copyright 2022(c) Analog Devices, Inc.

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

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 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

◆ stm32_timer_count_clk_get()

int32_t stm32_timer_count_clk_get ( struct no_os_timer_desc * desc,
uint32_t * freq_hz )

Get the timer clock frequency.

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.

◆ stm32_timer_count_clk_set()

int32_t stm32_timer_count_clk_set ( struct no_os_timer_desc * desc,
uint32_t freq_hz )

Set the timer clock frequency.

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.

◆ stm32_timer_counter_get()

int32_t stm32_timer_counter_get ( struct no_os_timer_desc * desc,
uint32_t * counter )

Get the value of the counter register for the timer.

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

◆ stm32_timer_counter_set()

int32_t stm32_timer_counter_set ( struct no_os_timer_desc * desc,
uint32_t new_val )

Set the timer counter register value.

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.

◆ stm32_timer_get_elapsed_time_nsec()

int32_t stm32_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.

◆ stm32_timer_init()

int32_t stm32_timer_init ( struct no_os_timer_desc ** desc,
const struct no_os_timer_init_param * param )

Initialize the timer peripheral.

Parameters
desc- The timer descriptor.
param- The structure that contains the timer parameters.
Returns
ret - Result of the init procedure.

◆ stm32_timer_remove()

int32_t stm32_timer_remove ( struct no_os_timer_desc * desc)

Free the resources allocated by no_os_timer_init().

Parameters
desc- The timer descriptor.
Returns
ret - Result of the remove procedure.

◆ stm32_timer_start()

int32_t stm32_timer_start ( struct no_os_timer_desc * desc)

Start a timer.

Parameters
desc- Pointer to the device handler.
Returns
ret - Result of the start procedure.

◆ stm32_timer_stop()

int32_t stm32_timer_stop ( struct no_os_timer_desc * desc)

Stop a timer from counting.

Parameters
desc- Pointer to the device handler.
Returns
ret - Result of the stop procedure.

Variable Documentation

◆ stm32_timer_ops

const struct no_os_timer_platform_ops stm32_timer_ops
Initial value:
= {
.init = &stm32_timer_init,
.start = &stm32_timer_start,
.stop = &stm32_timer_stop,
.counter_get = &stm32_timer_counter_get,
.counter_set = &stm32_timer_counter_set,
.count_clk_get = &stm32_timer_count_clk_get,
.count_clk_set = &stm32_timer_count_clk_set,
.get_elapsed_time_nsec = &stm32_timer_get_elapsed_time_nsec,
.remove = &stm32_timer_remove
}
int32_t stm32_timer_counter_set(struct no_os_timer_desc *desc, uint32_t new_val)
Set the timer counter register value.
Definition stm32_timer.c:266
int32_t stm32_timer_remove(struct no_os_timer_desc *desc)
Free the resources allocated by no_os_timer_init().
Definition stm32_timer.c:197
int32_t stm32_timer_count_clk_get(struct no_os_timer_desc *desc, uint32_t *freq_hz)
Get the timer clock frequency.
Definition stm32_timer.c:281
int32_t stm32_timer_start(struct no_os_timer_desc *desc)
Start a timer.
Definition stm32_timer.c:216
int32_t stm32_timer_counter_get(struct no_os_timer_desc *desc, uint32_t *counter)
Get the value of the counter register for the timer.
Definition stm32_timer.c:250
int32_t stm32_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 stm32_timer.c:331
int32_t stm32_timer_init(struct no_os_timer_desc **desc, const struct no_os_timer_init_param *param)
Initialize the timer peripheral.
Definition stm32_timer.c:134
int32_t stm32_timer_count_clk_set(struct no_os_timer_desc *desc, uint32_t freq_hz)
Set the timer clock frequency.
Definition stm32_timer.c:297
int32_t stm32_timer_stop(struct no_os_timer_desc *desc)
Stop a timer from counting.
Definition stm32_timer.c:233

stm32 platform specific timer platform ops structure

stm32 specific timer platform ops structure