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

📄 utilfunc.c

📁 usb 检验程序
💻 C
字号:
#include "UtilFunc.h"
#include "XsOstRegs.h"
#include "SitsangBrdDrv.h"

void Util_Delay(int time)
{
	int i,j;
	
	for(i=0;i<time;i++)
		for(j=0;j<100000;j++);
}

void Util_TestCpldLed()
{
	int time = 30;
	
	LED_L_ALL_ON();
	Util_Delay(time);
	LED_H_ALL_ON();
	Util_Delay(time);

	LED_L_ALL_OFF();
	Util_Delay(time);
	LED_H_ALL_OFF();
	Util_Delay(time);
}

void Util_TestCpldLed_OneByeOne(void)
{
	int time = 2;
	int i;
	
	for(i = 0; i < 16; i++)
	{
		//light led_L one bye one
		LED_L_ON(i);
		Util_Delay(time);
		LED_L_OFF(i);
		Util_Delay(time);
	}
	
	for(i = 0; i < 16; i++)
	{
		//light led_H one bye one
		LED_H_ON(i);
		Util_Delay(time);
		LED_H_OFF(i);
		Util_Delay(time);
	}
}

void Util_DelayUs(unsigned int usecs)
{
	unsigned int start;
	unsigned int numOfTicks;
	
	// Compute the number of ticks 
    numOfTicks = ((3 * usecs) +         // Whole part
                  (6 * usecs/10) +      // Fractional parts
                  (8 * usecs/100) +
                  (6 * usecs/1000) +
                  (4 * usecs/10000)
                 );
    
    start = OST_OSCR;
    while( (OST_OSCR - start) < numOfTicks);
}

void Util_DelayMs(unsigned int count)
{
	Util_DelayUs(count*1000);
}

void Util_DelayS(unsigned int count)
{
	while(count-->0)
	Util_DelayUs(1000000);
}

unsigned int Util_GetTickCount()
{
    return OST_OSCR;
}

unsigned int Util_UsToClock(unsigned int usecs)
{ 
	unsigned int numOfTicks;
	
	// Compute the number of ticks 
    numOfTicks = ((3 * usecs) +         // Whole part
                  (6 * usecs/10) +      // Fractional parts
                  (8 * usecs/100) +
                  (6 * usecs/1000) +
                  (4 * usecs/10000)
                 );
    
    return numOfTicks;
}

void Util_GetTimeoutBase(unsigned * TimeoutBase)
{ 
	*TimeoutBase = Util_GetTickCount();
}

int Util_IsTimeOut(unsigned TimeoutBase, unsigned int TimeOutValue)
{ 
	Util_DelayUs (100);
  	if ((Util_GetTickCount() - TimeoutBase) < Util_UsToClock(TimeOutValue))
  		return 0;
  	else
  		return 1;
}

⌨️ 快捷键说明

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