2015-03-17 14:50:05 +00:00
|
|
|
/*
|
2019-09-24 15:59:56 +01:00
|
|
|
* Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
|
|
|
|
* Copyright (c) 2019, Linaro Limited
|
2015-03-17 14:50:05 +00:00
|
|
|
*
|
2017-05-03 09:38:09 +01:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2015-03-17 14:50:05 +00:00
|
|
|
*/
|
|
|
|
|
2018-11-08 10:20:19 +00:00
|
|
|
#ifndef DELAY_TIMER_H
|
|
|
|
#define DELAY_TIMER_H
|
2015-03-17 14:50:05 +00:00
|
|
|
|
2019-09-24 15:59:56 +01:00
|
|
|
#include <stdbool.h>
|
2015-03-17 14:50:05 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2019-09-24 15:59:56 +01:00
|
|
|
#include <arch_helpers.h>
|
|
|
|
|
2015-03-17 14:50:05 +00:00
|
|
|
/********************************************************************
|
|
|
|
* A simple timer driver providing synchronous delay functionality.
|
|
|
|
* The driver must be initialized with a structure that provides a
|
|
|
|
* function pointer to return the timer value and a clock
|
|
|
|
* multiplier/divider. The ratio of the multiplier and the divider is
|
2015-12-01 16:10:15 +00:00
|
|
|
* the clock period in microseconds.
|
2015-03-17 14:50:05 +00:00
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
typedef struct timer_ops {
|
|
|
|
uint32_t (*get_timer_value)(void);
|
|
|
|
uint32_t clk_mult;
|
|
|
|
uint32_t clk_div;
|
|
|
|
} timer_ops_t;
|
|
|
|
|
2019-09-24 15:59:56 +01:00
|
|
|
static inline uint64_t timeout_cnt_us2cnt(uint32_t us)
|
|
|
|
{
|
|
|
|
return ((uint64_t)us * (uint64_t)read_cntfrq_el0()) / 1000000ULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t timeout_init_us(uint32_t us)
|
|
|
|
{
|
|
|
|
uint64_t cnt = timeout_cnt_us2cnt(us);
|
|
|
|
|
2019-10-08 10:13:06 +01:00
|
|
|
cnt += read_cntpct_el0();
|
2019-09-24 15:59:56 +01:00
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool timeout_elapsed(uint64_t expire_cnt)
|
|
|
|
{
|
|
|
|
return read_cntpct_el0() > expire_cnt;
|
|
|
|
}
|
|
|
|
|
2015-03-17 14:50:05 +00:00
|
|
|
void mdelay(uint32_t msec);
|
|
|
|
void udelay(uint32_t usec);
|
2018-02-12 12:36:17 +00:00
|
|
|
void timer_init(const timer_ops_t *ops_ptr);
|
2015-03-17 14:50:05 +00:00
|
|
|
|
2018-11-08 10:20:19 +00:00
|
|
|
#endif /* DELAY_TIMER_H */
|