init_qtime_mx21.c

来自「QNX ADS BSP code for i.MX27 chips」· C语言 代码 · 共 98 行

C
98
字号
/* * $QNXLicenseC:  * Copyright 2007, QNX Software Systems.   *   * Licensed under the Apache License, Version 2.0 (the "License"). You   * may not reproduce, modify or distribute this software except in   * compliance with the License. You may obtain a copy of the License   * at: http://www.apache.org/licenses/LICENSE-2.0   *   * Unless required by applicable law or agreed to in writing, software   * distributed under the License is distributed on an "AS IS" basis,   * WITHOUT WARRANTIES OF ANY KIND, either express or implied.  *  * This file may contain contributions from others, either as   * contributors under the License or as licensors under other terms.    * Please review this entire file for other proprietary rights or license   * notices, as well as the QNX Development Suite License Guide at   * http://licensing.qnx.com/license-guide/ for other information.  * $ *//* * MC9328MX21 specific timer support. * * This should be usable by any board that uses an MC9328MX21 */#include "startup.h"#include <arm/mx1.h>#include <arm/mx21.h>extern struct callout_rtn	timer_load_mx21;extern struct callout_rtn	timer_value_mx21;extern struct callout_rtn	timer_reload_mx21;static uintptr_t	mx21_timer_base;static const struct callout_slot	timer_callouts[] = {	{ CALLOUT_SLOT(timer_load, _mx21) },	{ CALLOUT_SLOT(timer_value, _mx21) },	{ CALLOUT_SLOT(timer_reload, _mx21) },};static unsignedtimer_start_mx21(){	return in32(mx21_timer_base + MX1_TIMER_CN);}static unsignedtimer_diff_mx21(unsigned start){	unsigned now = in32(mx21_timer_base + MX1_TIMER_CN);	return (unsigned)((int)now - (int)start);}voidinit_qtime_mx21(){	struct qtime_entry	*qtime = alloc_qtime();	/*	 * Map the timer registers	 */	mx21_timer_base = startup_io_map(MX1_TIMER_SIZE, MX21_GPT1_BASE);	/*	 * Clear match status and interrupt enable, and disable watchdog reset	 */	out32(mx21_timer_base + MX1_TIMER_CTL, 2);	/*	 * Prescaler = 2	 */	out32(mx21_timer_base + MX1_TIMER_PRER, 1);	timer_start = timer_start_mx21;	timer_diff = timer_diff_mx21;	/* 	 * IRQ number for Timer 1 is 26	 */	qtime->intr = 26;#define MX21_CLOCK_FREQ		22166667UL#define MX21_CLOCK_RATE		45112781UL#define MX21_CLOCK_SCALE	-15	qtime->timer_rate  = MX21_CLOCK_RATE;	qtime->timer_scale = MX21_CLOCK_SCALE;	qtime->cycles_per_sec = (uint64_t)MX21_CLOCK_FREQ;	add_callout_array(timer_callouts, sizeof(timer_callouts));}

⌨️ 快捷键说明

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