1 /* 2 * Copyright (c) 2022 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #include "hpm_mchtmr_drv.h" 9 mchtmr_init_counter(MCHTMR_Type * ptr,uint64_t v)10void mchtmr_init_counter(MCHTMR_Type *ptr, uint64_t v) 11 { 12 volatile uint32_t *p = (volatile uint32_t *) &ptr->MTIME; 13 /* 14 * When [31:29] == 7, low 32 bits need to be set to 0 first, 15 * then set high 32 bits and low 32 bits; otherwise, 16 * low 32 bit can be set firstly then high 32 bits. 17 */ 18 if ((v & 0xE0000000) == 0xE0000000) { 19 *p = 0; 20 *(p + 1) = v >> 32; 21 *p = v & 0xFFFFFFFF; 22 } else { 23 *p = v & 0xFFFFFFFF; 24 *(p + 1) = v >> 32; 25 } 26 } 27