⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usdelay.c

📁 X-scale 27x 平台
💻 C
字号:
//
// Copyright (c) Chrontel Inc.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Chrontel end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:  
  usdelay.c

Abstract:  
   Delay in us using Xscale OS timer unit.

Revision:
   11/27/02 Created by Roger Yu, 
      Following PXA250 DM section 9.6.2, 9.6.3

Notes: 
--*/

#include "chrontel.h"


#define   TIMERTICK   4  // 1 microsecond is 3.7 clock ticks  for 3.6864MHz
#define   TIMER_SECOND (1000 *1000)


#define  TIMERTICK_MUL  0x75f7    // 0x75f7=3.6864*(2<<13)


//extern REG_MAP  Xsl_MapReg[REGCAT_SIZE];

static  volatile POST_REGS ost;
void delay_us( unsigned usVal)
{
	unsigned lValue,Time;
    static unsigned firstCall=1;
    if (usVal==0) return;

	if (firstCall) {
		ost = (volatile POST_REGS)Xsl_MapReg[TIMERREG].mapaddr;
	    if (!ost) return;
		firstCall=0;
	}

	Time=ost->oscr;
//	lValue=Time+(usVal*TIMERTICK);
	lValue=Time+((usVal*TIMERTICK_MUL)>>13);
	if (lValue < Time) {  // test for wrap
		while (Time < ost->oscr);
	}
	while(ost->oscr <= lValue);
}    


void delay_ms( unsigned msVal)
{
	unsigned i;

	msVal *=10;
	for (i=0; i<msVal; i++) delay_us(100);
	return;
}


⌨️ 快捷键说明

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