1 /* 2 * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved. 3 * 4 * UniProton is licensed under Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * http://license.coscl.org.cn/MulanPSL2 8 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 9 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 10 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 11 * See the Mulan PSL v2 for more details. 12 * Create: 2009-12-22 13 * Description: Tick interrupt implementation 14 */ 15 #include "prt_hw_tick_internal.h" 16 17 /* 系统当前运行的时间,单位cycle */ 18 OS_SEC_BSS U64 g_cycleNow; 19 /* 在tick中记录的系统当前cycle值 */ 20 OS_SEC_BSS U64 g_cycleInTick; 21 /* 系统当前运行的时间,时间是g_cyclePerTick的整数倍 */ 22 OS_SEC_BSS U64 g_cycleByTickNow; 23 OsTickIsr(void)24OS_SEC_TEXT void OsTickIsr(void) 25 { 26 uintptr_t intSave; 27 intSave = PRT_HwiLock(); 28 TICK_NO_RESPOND_CNT++; 29 /* 调用CycleUpdate更新g_cycleNow g_cycleByTickNow */ 30 OsCycleUpdate(); 31 PRT_HwiRestore(intSave); 32 OsHwiTrap(); 33 } 34 35 /* 36 * 描述:设置Tick硬件定时器定时时长,使能Tick中断定时器 37 */ OsTickStartRegSet(U16 tickHwTimerIndex,U32 cyclePerTick)38OS_SEC_TEXT void OsTickStartRegSet(U16 tickHwTimerIndex, U32 cyclePerTick) 39 { 40 (void)tickHwTimerIndex; 41 g_cycleByTickNow = 0; 42 g_cycleInTick = 0; 43 TICK_NO_RESPOND_CNT = 0; 44 /* 系统初始化的时候将其初始化为0,因为初始化时为关中断,不会响应tick中断,只有在切换到多线程的模式才会开始计数 */ 45 g_uniTicks = 0; 46 47 /* M3时钟计数寄存器,当计数到0时,该值会被重新装载 */ 48 *(volatile U32 *)OS_SYSTICK_RELOAD_REG = cyclePerTick; 49 /* 50 * M4时钟控制寄存器: bit0为使能位,1表示使能;bit1为计数减为0 51 * 时是否产生中断源,1表示产生中断;bit2为使用内部时钟还是外部时钟,1表示未内部时钟 52 */ 53 *(volatile U32 *)OS_SYSTICK_CONTROL_REG = OS_BIT0_MASK | OS_BIT1_MASK | OS_BIT2_MASK; 54 } 55 OsTickTimerStartMx(U32 cyclePerTick)56OS_SEC_L4_TEXT U32 OsTickTimerStartMx(U32 cyclePerTick) 57 { 58 OsTickStartRegSet(0, cyclePerTick); 59 return OS_OK; 60 } 61