summaryrefslogtreecommitdiff
path: root/ports/risc-v64/gnu/example_build/erbium/hwtimer.h
blob: 3b9bf4e3d14db92ee610be9b1c260a964d15966b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/***************************************************************************
 * Copyright (c) 2026 Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * AI Disclosure: This file was largely AI-generated by Claude Code (Opus 5.5).
 * The AI-generated portions may be considered public domain (CC0-1.0)
 * and not subject to the project's licence. The human contributor has
 * reviewed and verified that the code is correct.
 *
 * SPDX-License-Identifier: MIT and CC0-1.0
 **************************************************************************/

#ifndef RISCV_HWTIMER_H
#define RISCV_HWTIMER_H

#include <stdint.h>

/* Erbium machine timer.  mtime and a single mtimecmp live in the CPU
   register block; mtime_local_target selects which harts see the timer
   interrupt and resets to all harts.

   The mtime rate depends on the reference clock and time_config, which the
   boot firmware programs.  The default is the 2 MHz timebase used by the
   Zephyr and NuttX Erbium ports; define ERBIUM_MTIME_FREQ_HZ when the
   firmware selects another rate.  */
#define ERBIUM_MTIME            0x80F40200UL
#define ERBIUM_MTIMECMP         0x80F40208UL

#ifndef ERBIUM_MTIME_FREQ_HZ
#define ERBIUM_MTIME_FREQ_HZ    2000000UL
#endif

#define TICKNUM_PER_TIMER       (ERBIUM_MTIME_FREQ_HZ / TX_TIMER_TICKS_PER_SECOND)

int hwtimer_init(void);
int hwtimer_handler(void);

#endif /* RISCV_HWTIMER_H */