VSF Documented
gptimer.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "driver/gptimer.h"
20 * plus its companion "driver/gptimer_types.h", collapsed into a single
21 * header for the shim.
22 *
23 * Authored from ESP-IDF v5.1 public API only. No code copied from the
24 * ESP-IDF source tree. The VSF port bridges onto
25 *
26 * hal/driver/common/template/vsf_template_timer.h
27 *
28 * via a caller-supplied pool of vsf_timer_t * instances (see
29 * vsf_espidf_cfg_t::gptimer
30 * ).
31 *
32 * Notes on semantics (v5.1 public contract preserved where feasible):
33 *
34 * - gptimer_new_timer() allocates a handle opaquely; the port draws
35 * one vsf_timer_t * from the injected pool. No allocation of VSF
36 * hardware is performed here.
37 * - gptimer_alarm_config_t::alarm_count is interpreted in "resolution
38 * ticks" just like in ESP-IDF: alarm fires when the internal counter
39 * reaches this value. It is wired to vsf_timer_cfg_t::period.
40 * - resolution_hz is wired to vsf_timer_cfg_t::freq (min_freq). The
41 * actual tick frequency depends on the underlying hardware and may
42 * not exactly match the request; ESP-IDF applications that rely on
43 * cycle-accurate timing should cross-check using the counter value
44 * returned by gptimer_get_raw_count() -- which, when the VSF backend
45 * cannot expose it, returns ESP_ERR_NOT_SUPPORTED.
46 * - Clock source selection is accepted but ignored: VSF's timer
47 * abstraction does not surface per-peripheral clock muxing.
48 * - The on_alarm callback's boolean return value is accepted but
49 * ignored -- there is no ISR-to-task yield semantics in the shim.
50 */
51
52#ifndef __VSF_ESPIDF_DRIVER_GPTIMER_H__
53#define __VSF_ESPIDF_DRIVER_GPTIMER_H__
54
55#include <stdint.h>
56#include <stdbool.h>
57#include <stddef.h>
58
59#include "esp_err.h"
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65/*============================ TYPES =========================================*/
66
71
80typedef enum {
88
95typedef enum {
99
106typedef struct {
111 struct {
114 } flags;
116
124typedef struct {
128
136 const gptimer_alarm_event_data_t *edata,
137 void *user_ctx);
138
146typedef struct {
149
158typedef struct {
161 struct {
163 } flags;
165
166/*============================ PROTOTYPES ====================================*/
167
176extern esp_err_t gptimer_new_timer(const gptimer_config_t *config,
177 gptimer_handle_t *ret_timer);
178
187
195 const gptimer_event_callbacks_t *cbs,
196 void *user_data);
197
209 const gptimer_alarm_config_t *config);
210
217
222
227
232
239
246
255 uint32_t *out_resolution);
256
263 uint64_t *value);
264
265#ifdef __cplusplus
266}
267#endif
268
269#endif // __VSF_ESPIDF_DRIVER_GPTIMER_H__
bool
Definition type.h:60
int esp_err_t
Definition esp_err.h:41
bool(* gptimer_alarm_cb_t)(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_ctx)
User callback invoked from the alarm ISR.
Definition gptimer.h:135
esp_err_t gptimer_new_timer(const gptimer_config_t *config, gptimer_handle_t *ret_timer)
Allocate a new gptimer handle drawn from the injected VSF pool.
Definition driver_gptimer_port.c:188
esp_err_t gptimer_start(gptimer_handle_t timer)
Start the counter. The timer must already be enabled.
Definition driver_gptimer_port.c:323
esp_err_t gptimer_set_alarm_action(gptimer_handle_t timer, const gptimer_alarm_config_t *config)
Configure the alarm action applied at the next alarm event.
Definition driver_gptimer_port.c:257
esp_err_t gptimer_enable(gptimer_handle_t timer)
Transition the timer into the "enabled" state.
Definition driver_gptimer_port.c:291
esp_err_t gptimer_stop(gptimer_handle_t timer)
Stop the counter. The counter value is retained.
Definition driver_gptimer_port.c:355
esp_err_t gptimer_get_raw_count(gptimer_handle_t timer, uint64_t *value)
Read the raw counter value.
Definition driver_gptimer_port.c:390
gptimer_count_direction_t
Count direction.
Definition gptimer.h:95
@ GPTIMER_COUNT_UP
Definition gptimer.h:97
@ GPTIMER_COUNT_DOWN
Definition gptimer.h:96
esp_err_t gptimer_get_resolution(gptimer_handle_t timer, uint32_t *out_resolution)
Query the actual resolution chosen by the underlying hardware.
Definition driver_gptimer_port.c:400
esp_err_t gptimer_set_raw_count(gptimer_handle_t timer, uint64_t value)
Set the raw counter value.
Definition driver_gptimer_port.c:380
esp_err_t gptimer_register_event_callbacks(gptimer_handle_t timer, const gptimer_event_callbacks_t *cbs, void *user_data)
Register the alarm callback (and future per-event callbacks).
Definition driver_gptimer_port.c:242
gptimer_clock_source_t
Timer clock source.
Definition gptimer.h:80
@ GPTIMER_CLK_SRC_XTAL
Definition gptimer.h:83
@ GPTIMER_CLK_SRC_PLL_F80M
Definition gptimer.h:86
@ GPTIMER_CLK_SRC_DEFAULT
Definition gptimer.h:81
@ GPTIMER_CLK_SRC_RC_FAST
Definition gptimer.h:84
@ GPTIMER_CLK_SRC_PLL_F40M
Definition gptimer.h:85
@ GPTIMER_CLK_SRC_APB
Definition gptimer.h:82
struct gptimer_t * gptimer_handle_t
Opaque handle for a general-purpose timer.
Definition gptimer.h:70
esp_err_t gptimer_disable(gptimer_handle_t timer)
Transition the timer out of the "enabled" state.
Definition driver_gptimer_port.c:307
esp_err_t gptimer_get_captured_count(gptimer_handle_t timer, uint64_t *value)
Return the number of alarms that have fired since enable.
Definition driver_gptimer_port.c:409
esp_err_t gptimer_del_timer(gptimer_handle_t timer)
Release a gptimer handle, stopping the underlying timer first.
Definition driver_gptimer_port.c:225
unsigned uint32_t
Definition stdint.h:9
unsigned long long uint64_t
Definition stdint.h:11
Behaviour applied to the counter when the alarm matches.
Definition gptimer.h:158
uint32_t auto_reload_on_alarm
Definition gptimer.h:162
uint64_t reload_count
Definition gptimer.h:160
uint64_t alarm_count
Definition gptimer.h:159
Data passed to gptimer_alarm_cb_t at each alarm event.
Definition gptimer.h:124
uint64_t alarm_value
Definition gptimer.h:126
uint64_t count_value
Definition gptimer.h:125
Initial configuration for gptimer_new_timer().
Definition gptimer.h:106
uint32_t backup_before_sleep
Definition gptimer.h:113
gptimer_clock_source_t clk_src
Definition gptimer.h:107
int intr_priority
Definition gptimer.h:110
uint32_t intr_shared
Definition gptimer.h:112
uint32_t resolution_hz
Definition gptimer.h:109
gptimer_count_direction_t direction
Definition gptimer.h:108
Event callback set attachable via gptimer_register_event_callbacks().
Definition gptimer.h:146
gptimer_alarm_cb_t on_alarm
Definition gptimer.h:147
Definition driver_gptimer_port.c:69
vk_av_control_value_t value
Definition vsf_audio.h:171
Generated from commit: vsfteam/vsf@015f4d1