timer.c

来自「bootloader源代码」· C语言 代码 · 共 54 行

C
54
字号
/***************************************** Copyright (c) 2001-2002  Sigma Designs, Inc. All Rights Reserved Proprietary and Confidential *****************************************//* This file is part of the boot loader *//* * timer.c * * timer for ARM */#include "util.h"#include "uart.h"#include "jasper.h"#include "jasper_const.h"#include "io.h"static int g_ticks = 0;static unsigned int g_last = 0;void timer_init(void){	__raw_writel(0xffff, JASPER_TIMER_BASE + TIMER_TMR0LOAD);	__raw_writel(0xc8, JASPER_TIMER_BASE + TIMER_TMR0CTL);}unsigned int timer_getticks(void){	unsigned int timerval = __raw_readl(JASPER_TIMER_BASE + TIMER_TMR0VAL);		if ((g_last & 0x8000) != (timerval & 0x8000))		++g_ticks;	g_last = timerval;	return g_ticks;}int timer_timeout(unsigned int startticks, int timeout){	unsigned int ticks = timer_getticks();		if (timeout == 0)		return 1;	else if (timeout > 0) {		if ((ticks - startticks) > (timeout >> 8))			return 1;	}	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?