📄 common.c
字号:
/****************************************************************
* Viaon Technology (Suzhou) Co.,Ltd
*
* Copyright 2007, Viaon Technology (Suzhou) Co.,Ltd,Suzhou,China
* All rights reserved.
*
*
* Filename: common.c
*
* Programmer: Greg
*
* Created: 1/2/2008
*
* Description: public functions
*
*
* Change History (most recent first): 2008.1.2
****************************************************************/
//#include <intrins.h>
#include "utiltypedef.h"
#include "va4010reg.h"
#include "common.h"
WORD WordSwap(WORD dat)
{
#if 0
return(((dat&0x00FF)<<8)|((dat&0xFF00)>>8));
#else
WORD in;
WORD out;
in = dat;
out = LoadAlien16(&in);
return out;
#endif
}
DWORD SwapINT32(DWORD dat)
{
#if 0
dData = (dData&0xff)<<24|(dData&0xff00)<<8|(dData&0xff000000)>>24|(dData&0xff0000)>>8;
return dData;
#else
DWORD in, out;
in = dat;
LoadAlien32(&in, &out);
return out;
#endif
}
void DelayMs(BYTE nFactor)
{
BYTE i;
for(i=0; i<nFactor; i++){
DelayUs(200);
}
}
void DelayUs(BYTE nFactor)
{
BYTE i;
volatile BYTE tmp=0;
for(i=0; i<nFactor; i++){
tmp ++;
// _nop_ ();
}
}
#if (UART_DEBUG == UART_DEBUG_ENABLE)
void UartOutText(unsigned char *buffer)
{
//WDT = 0X00;
while(*buffer != '\0')
{
SBUF = *buffer;
while(!(SCON & 0x02)); // wait till tx done
SCON &= ~(0x02); //Clear tx done
buffer++;
}
//WDT = 0X1F;
return;
}
unsigned char UartOutText1(unsigned char *pUsrBuf, unsigned int num)
{
#if 1
unsigned int i;
unsigned char *ptr;
//WDT = 0X00;
ptr = pUsrBuf;
for (i=0;i<num;i++)
{
SBUF = *ptr;
while(!(SCON & SCON_TXINT)); // wait till tx done
SCON &= ~(0x02); //Clear tx done
ptr++;
}
//WDT = 0X1F;
//UartOutText("\r\n");
#endif
return(1);
}
void UartOutValue(unsigned long value, unsigned char length)
{
#if 0
UART *uart;
BYTE byte;
BYTE *point;
uart = (UART *)(UART_BASE);
value = value << ((8-length) * 4);
while(length)
{
byte = (value & 0xf0000000) >> 28;
byte += 0x30;
if(byte > 0x39) byte += 7;
while(!(uart->UartInt & 0x0040)); // wait until tx fifo ready
uart->UartData = byte;
value = value << 4;
length --;
}
#else
unsigned char byte;
//unsigned char *point;
//WDT = 0X00;
value = value << ((8-length) * 4);
while(length) {
byte = (value & 0xf0000000) >> 28;
byte += 0x30;
if(byte > 0x39) byte += 7;
//while(!(uart->UartInt & 0x0040)); // wait until tx fifo ready
//uart->UartData = byte;
SBUF = byte;
while(!(SCON & 0x02)); // wait till tx done
SCON &= ~(0x02); //Clear tx done
value = value << 4;
length --;
}
//WDT = 0X1F;
UartOutText("\r\n");
#endif
return;
}
#endif
#if (UART_DEBUG == UART_DEBUG_ENABLE)
//#if 1
void UartOutInfo(unsigned char *buffer)
{
while(*buffer != '\0')
{
SBUF = *buffer;
while(!(SCON & 0x02)); // wait till tx done
SCON &= ~(0x02); //Clear tx done
buffer++;
}
return;
}
#if 0
unsigned char UartOutInfo1(unsigned char *pUsrBuf, unsigned int num)
{
#if 1
unsigned int i;
unsigned char *ptr;
ptr = pUsrBuf;
for (i=0;i<num;i++)
{
SBUF = *ptr;
while(!(SCON & SCON_TXINT)); // wait till tx done
SCON &= ~(0x02); //Clear tx done
ptr++;
}
UartOutInfo("\r\n");
#endif
return(1);
}
#endif
void UartOutData(unsigned long value, unsigned char length)
{
#if 0
UART *uart;
BYTE byte;
BYTE *point;
uart = (UART *)(UART_BASE);
value = value << ((8-length) * 4);
while(length)
{
byte = (value & 0xf0000000) >> 28;
byte += 0x30;
if(byte > 0x39) byte += 7;
while(!(uart->UartInt & 0x0040)); // wait until tx fifo ready
uart->UartData = byte;
value = value << 4;
length --;
}
#else
unsigned char byte;
//unsigned char *point;
value = value << ((8-length) * 4);
while(length) {
byte = (value & 0xf0000000) >> 28;
byte += 0x30;
if(byte > 0x39) byte += 7;
//while(!(uart->UartInt & 0x0040)); // wait until tx fifo ready
//uart->UartData = byte;
SBUF = byte;
while(!(SCON & 0x02)); // wait till tx done
SCON &= ~(0x02); //Clear tx done
value = value << 4;
length --;
}
UartOutInfo("\r\n");
#endif
return;
}
#endif
void memclr(void* a, WORD c)
{
WORD i;
for(i = 0 ; i < c ; i++)
*((BYTE *)a + i) = 0;
return;
}
BYTE memcomp(const BYTE* a, const BYTE* b, BYTE c)
{
while(c)
{
if((*a) != (*b))
return c;
c--;
a++;
b++;
}
return 0;//the same
}
void *memcopy(BYTE* a, const BYTE* b, BYTE c) //max only 255 bytes, ; DWORD c)
{
while(c)
{
*a = *b;
c--;
a++;
b++;
}
return a+=c;
}
BYTE Value2Exp(WORD wVal)
{
BYTE byExp = 0;
while(wVal = (wVal>>1))
byExp ++;
return byExp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -