no-OS
Loading...
Searching...
No Matches
riscvrx_timer.c File Reference

Timer control module source for Lattice RISC-V RX. More...

#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include "no_os_alloc.h"
#include "no_os_error.h"
#include "riscvrx_timer.h"
#include "hal.h"
#include "parameters.h"
Include dependency graph for riscvrx_timer.c:

Functions

int32_t lattice_timer_set_callback (struct no_os_timer_desc *desc, void(*handler)(void *), void *ctx)
 Register timer callback and context.
 
int32_t lattice_timer_start (struct no_os_timer_desc *desc)
 Start timer counting.
 
int32_t lattice_timer_stop (struct no_os_timer_desc *desc)
 Stop timer counting.
 
int32_t lattice_timer_counter_get (struct no_os_timer_desc *desc, uint32_t *counter)
 Read current timer counter.
 
int32_t lattice_timer_counter_set (struct no_os_timer_desc *desc, uint32_t new_val)
 Set timer counter reload value.
 
int32_t lattice_timer_count_clk_get (struct no_os_timer_desc *desc, uint32_t *freq_hz)
 Get timer input clock frequency.
 
int32_t lattice_timer_count_clk_set (struct no_os_timer_desc *desc, uint32_t freq_hz)
 Set timer input clock frequency.
 
int32_t lattice_timer_get_elapsed_time_nsec (struct no_os_timer_desc *desc, uint64_t *elapsed_time)
 Get elapsed time in nanoseconds from MTIME.
 
int32_t lattice_timer_init (struct no_os_timer_desc **desc, const struct no_os_timer_init_param *param)
 Initialize Lattice timer descriptor.
 
int32_t lattice_timer_remove (struct no_os_timer_desc *desc)
 Remove timer instance and free resources.
 

Variables

const struct no_os_timer_platform_ops latt_timer_ops
 Lattice platform specific timer platform ops structure.
 

Detailed Description

Timer control module source for Lattice RISC-V RX.

Author
Vilmos-Csaba Jozsa (vilmo.nosp@m.scsa.nosp@m.ba.jo.nosp@m.zsa@.nosp@m.analo.nosp@m.g.co.nosp@m.m)

Copyright 2025-2026(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:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • 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.
  • 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.
  • The use of this software may or may not infringe the patent rights of one or more patent holders. This license does not release you from the requirement that you obtain separate licenses from these patent holders to use this software.
  • Use of the software either in source or binary form, must be run on or directly connected to an Analog Devices Inc. component.

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

◆ lattice_timer_count_clk_get()

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

Get timer input clock frequency.

Parameters
desc- no-OS timer descriptor.
freq_hz- Pointer to returned frequency.
Returns
0 in case of success, negative error code otherwise.

◆ lattice_timer_count_clk_set()

int32_t lattice_timer_count_clk_set ( struct no_os_timer_desc * desc,
uint32_t freq_hz )

Set timer input clock frequency.

Parameters
desc- no-OS timer descriptor.
freq_hz- Requested frequency.
Returns
0 in case of success, negative error code otherwise.

◆ lattice_timer_counter_get()

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

Read current timer counter.

Parameters
desc- no-OS timer descriptor.
counter- Pointer to returned counter value.
Returns
0 in case of success, negative error code otherwise.

◆ lattice_timer_counter_set()

int32_t lattice_timer_counter_set ( struct no_os_timer_desc * desc,
uint32_t new_val )

Set timer counter reload value.

Parameters
desc- no-OS timer descriptor.
new_val- New tick count value.
Returns
0 in case of success, negative error code otherwise.

◆ lattice_timer_get_elapsed_time_nsec()

int32_t lattice_timer_get_elapsed_time_nsec ( struct no_os_timer_desc * desc,
uint64_t * elapsed_time )

Get elapsed time in nanoseconds from MTIME.

Parameters
desc- no-OS timer descriptor.
elapsed_time- Pointer to returned elapsed nanoseconds.
Returns
0 in case of success, negative error code otherwise.

◆ lattice_timer_init()

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

Initialize Lattice timer descriptor.

Parameters
desc- Pointer to no-OS timer descriptor.
param- no-OS timer init parameters.
Returns
0 in case of success, negative error code otherwise.

◆ lattice_timer_remove()

int32_t lattice_timer_remove ( struct no_os_timer_desc * desc)

Remove timer instance and free resources.

Parameters
desc- no-OS timer descriptor.
Returns
0 in case of success, negative error code otherwise.

◆ lattice_timer_set_callback()

int32_t lattice_timer_set_callback ( struct no_os_timer_desc * desc,
void(* handler )(void *),
void * ctx )

Register timer callback and context.

Register timer callback and context for Lattice timer backend.

Parameters
desc- no-OS timer descriptor.
handler- User callback function.
ctx- User callback context.
Returns
0 in case of success, negative error code otherwise.

◆ lattice_timer_start()

int32_t lattice_timer_start ( struct no_os_timer_desc * desc)

Start timer counting.

Parameters
desc- no-OS timer descriptor.
Returns
0 in case of success, negative error code otherwise.

◆ lattice_timer_stop()

int32_t lattice_timer_stop ( struct no_os_timer_desc * desc)

Stop timer counting.

Parameters
desc- no-OS timer descriptor.
Returns
0 in case of success, negative error code otherwise.

Variable Documentation

◆ latt_timer_ops

const struct no_os_timer_platform_ops latt_timer_ops
Initial value:
= {
.set_callback = &lattice_timer_set_callback,
.counter_get = &lattice_timer_counter_get,
.counter_set = &lattice_timer_counter_set,
.count_clk_get = &lattice_timer_count_clk_get,
.count_clk_set = &lattice_timer_count_clk_set,
.get_elapsed_time_nsec = &lattice_timer_get_elapsed_time_nsec,
}
int32_t lattice_timer_count_clk_get(struct no_os_timer_desc *desc, uint32_t *freq_hz)
Get timer input clock frequency.
Definition riscvrx_timer.c:222
int32_t lattice_timer_counter_set(struct no_os_timer_desc *desc, uint32_t new_val)
Set timer counter reload value.
Definition riscvrx_timer.c:199
int32_t lattice_timer_remove(struct no_os_timer_desc *desc)
Remove timer instance and free resources.
Definition riscvrx_timer.c:331
int32_t lattice_timer_counter_get(struct no_os_timer_desc *desc, uint32_t *counter)
Read current timer counter.
Definition riscvrx_timer.c:182
int32_t lattice_timer_init(struct no_os_timer_desc **desc, const struct no_os_timer_init_param *param)
Initialize Lattice timer descriptor.
Definition riscvrx_timer.c:279
int32_t lattice_timer_stop(struct no_os_timer_desc *desc)
Stop timer counting.
Definition riscvrx_timer.c:162
int32_t lattice_timer_set_callback(struct no_os_timer_desc *desc, void(*handler)(void *), void *ctx)
Register timer callback and context.
Definition riscvrx_timer.c:121
int32_t lattice_timer_get_elapsed_time_nsec(struct no_os_timer_desc *desc, uint64_t *elapsed_time)
Get elapsed time in nanoseconds from MTIME.
Definition riscvrx_timer.c:259
int32_t lattice_timer_start(struct no_os_timer_desc *desc)
Start timer counting.
Definition riscvrx_timer.c:142
int32_t lattice_timer_count_clk_set(struct no_os_timer_desc *desc, uint32_t freq_hz)
Set timer input clock frequency.
Definition riscvrx_timer.c:239

Lattice platform specific timer platform ops structure.