1/* 2 * Copyright 2019, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#pragma once 14 15#include <platsupport/io.h> 16#include <platsupport/ltimer.h> 17#include <platsupport/fdt.h> 18#include <platsupport/timer.h> 19#include <platsupport/plat/epit_constants.h> 20 21#include <stdint.h> 22 23typedef struct { 24 /* initialised ps_io_ops_t structure to allocate resources with */ 25 ps_io_ops_t io_ops; 26 /* user callback function to be called on interrupt */ 27 ltimer_callback_fn_t user_callback; 28 /* token to be passed into the callback function */ 29 void *user_callback_token; 30 /* path to the epit node in the DTB */ 31 char *device_path; 32 /* flag determining if this timer should be configured as a timestamp timer */ 33 bool is_timestamp; 34 /* prescaler to scale time by. 0 = divide by 1. 1 = divide by 2. ...*/ 35 uint32_t prescaler; 36} epit_config_t; 37 38struct epit_map; 39typedef struct epit { 40 ps_io_ops_t io_ops; 41 irq_id_t irq_id; 42 ltimer_callback_fn_t user_callback; 43 void *user_callback_token; 44 pmem_region_t timer_pmem; 45 volatile struct epit_map *epit_map; 46 uint32_t prescaler; 47 bool is_timestamp; 48 uint64_t high_bits; 49} epit_t; 50 51static inline timer_properties_t epit_timer_properties(void) 52{ 53 return (timer_properties_t) { 54 .upcounter = false, 55 .timeouts = true, 56 .relative_timeouts = true, 57 .absolute_timeouts = false, 58 .periodic_timeouts = true, 59 .bit_width = 32, 60 .irqs = 1, 61 }; 62} 63 64/* initialise an epit struct */ 65int epit_init(epit_t *epit, epit_config_t config); 66/* destroy the epit */ 67int epit_destroy(epit_t *epit); 68/* turn off any pending irqs */ 69int epit_stop(epit_t *epit); 70/* set a relative timeout */ 71int epit_set_timeout(epit_t *epit, uint64_t ns, bool periodic); 72/* set a relative timeout in ticks */ 73int epit_set_timeout_ticks(epit_t *epit, uint64_t ticks, bool periodic); 74/* convert epit ticks to ns */ 75uint64_t epit_get_time(epit_t *epit); 76