timer.c

来自「Coldfire MCF5282 DBug bootloader」· C语言 代码 · 共 58 行

C
58
字号
/*
 * File:		timer.c
 * Purpose:		routines for accessing integrated timer modules
 *
 * Notes:
 *
 * Modifications:
 *
 */

#include "src/include/dbug.h"
#include "src/dev/mpc5xx/timer.h"

/********************************************************************/

static mpc5xx_timer timer = {0, 0, 0, 0};

const uint8 TIMER_NETWORK = 1;

/********************************************************************/
uint32
timer_set_secs(uint8 channel, uint32 secs)
{
	uint32 ticks;
	int timer_clock;
	(void) channel;
	
	timer_clock = board_get_speed()/16;
	
	/*
	 * Only allow 32-bits worth of Timer ticks before we time-out
	 */
	if (secs > (uint32)(0xFFFFFFFF/timer_clock))
		return FALSE;	
	
	ticks = secs * timer_clock;
	timer.reference = ticks;
	
	/*
	 * Restart the Time Base counter
	 */
	mpc5xx_wr_tbl(0);
	
	return TRUE;
}

/********************************************************************/
uint32
timer_get_reference(uint8 channel)
{
	(void) channel;
	/*
	 * Return value is FALSE if Timer has timed-out
	 */
	return (mpc5xx_rd_tbl() < timer.reference);
}

/********************************************************************/

⌨️ 快捷键说明

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