/*************************************************************************** * Copyright (c) 2024 Microsoft Corporation * * 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. * * SPDX-License-Identifier: MIT **************************************************************************/ #ifndef RISCV_HWTIMER_H #define RISCV_HWTIMER_H #include "platform.h" #define TICKNUM_PER_SECOND 32768 #define TICKNUM_PER_TIMER (TICKNUM_PER_SECOND / 1000) // ~ 1ms timer static inline int hwtimer_init(void) { uint64_t time = get_aclint_mtime(aclint); set_aclint_mtimecmp(aclint, time + TICKNUM_PER_TIMER); return 0; } static inline int hwtimer_handler(void) { uint64_t time = get_aclint_mtime(aclint); set_aclint_mtimecmp(aclint, time + TICKNUM_PER_TIMER); return 0; } #endif