1 /* 2 * Copyright (c) 2017 The Fuchsia Authors. 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 #pragma once 9 10 #include <lk/err.h> 11 #include <kernel/spinlock.h> 12 #include <stdbool.h> 13 #include <stdint.h> 14 #include <stm32f0xx.h> 15 16 #define STM32_TIMER_CAPTURE_CHAN_FLAG_ENABLE (1 << 0) 17 #define STM32_TIMER_CAPTURE_CHAN_FLAG_RISING (1 << 1) 18 #define STM32_TIMER_CAPTURE_CHAN_FLAG_FALLING (1 << 2) 19 20 typedef struct { 21 uint32_t flags; 22 bool (*cb)(uint64_t val); 23 } stm32_timer_capture_channel_t; 24 25 typedef struct stm32_timer_config_ stm32_timer_config_t; 26 27 typedef struct { 28 const stm32_timer_config_t *config; 29 stm32_timer_capture_channel_t chan[4]; 30 31 volatile uint64_t overflow; 32 spin_lock_t overflow_lock; 33 } stm32_timer_capture_t; 34 35 // Set tc->chan[] cb and flags before calling. 36 // 37 // `prescaler` is the desired prescaling factor and must be positive. The value stored in the 38 // prescaler register will be `prescaler - 1` (see ST reference manual RM0091, section 18.4.11). 39 status_t stm32_timer_capture_setup(stm32_timer_capture_t *tc, int timer, uint16_t prescaler); 40 41 uint64_t stm32_timer_capture_get_counter(stm32_timer_capture_t *tc); 42 43