2017-07-18 11:15:10 +08:00
|
|
|
|
// һЩ<D2BB><D0A9><EFBFBD>õġ<C3B5><C4A1><EFBFBD><EFBFBD>õĽӿ<C4BD>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>1
|
|
|
|
|
* @reg <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @bit <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һbit
|
|
|
|
|
*/
|
|
|
|
|
void reg_set_one_bit(volatile unsigned int *reg, unsigned int bit)
|
|
|
|
|
{
|
|
|
|
|
unsigned int temp, mask;
|
|
|
|
|
|
|
|
|
|
mask = 1 << bit;
|
|
|
|
|
temp = *reg;
|
|
|
|
|
temp |= mask;
|
|
|
|
|
*reg = temp;
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @reg <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @bit <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һbit
|
|
|
|
|
*/
|
|
|
|
|
void reg_clr_one_bit(volatile unsigned int *reg, unsigned int bit)
|
|
|
|
|
{
|
|
|
|
|
unsigned int temp, mask;
|
|
|
|
|
|
|
|
|
|
mask = 1 << bit;
|
|
|
|
|
temp = *reg;
|
|
|
|
|
temp &= ~mask;
|
|
|
|
|
*reg = temp;
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ȡָ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @reg <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @bit <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ȡֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һbit
|
|
|
|
|
* @ret ָ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>ֵ
|
|
|
|
|
*/
|
|
|
|
|
unsigned int reg_get_bit(volatile unsigned int *reg, unsigned int bit)
|
|
|
|
|
{
|
|
|
|
|
unsigned int temp;
|
|
|
|
|
|
|
|
|
|
temp = *reg;
|
|
|
|
|
temp = (temp >> bit) & 1;
|
|
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-09-06 12:11:46 +08:00
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>8bit(һ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>)<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @data <EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @addr <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
*/
|
|
|
|
|
void reg_write_8(unsigned char data, volatile unsigned char *addr)
|
|
|
|
|
{
|
|
|
|
|
*addr = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD>ӼĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8bit(һ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>)<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @addr <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @ret <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
unsigned char reg_read_8(volatile unsigned char *addr)
|
|
|
|
|
{
|
|
|
|
|
return (*addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-07-18 11:15:10 +08:00
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дһ<EFBFBD><EFBFBD>32bit<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @data <EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @addr <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
*/
|
|
|
|
|
void reg_write_32(unsigned int data, volatile unsigned int *addr)
|
|
|
|
|
{
|
|
|
|
|
*addr = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD>ӼĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>32bit<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @addr <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @ret <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
unsigned int reg_read_32(volatile unsigned int *addr)
|
|
|
|
|
{
|
|
|
|
|
return (*addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-20 17:05:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* ffs - find first bit set
|
|
|
|
|
* @x: the word to search
|
|
|
|
|
*
|
|
|
|
|
* This is defined the same way as
|
|
|
|
|
* the libc and compiler builtin ffs routines, therefore
|
|
|
|
|
* differs in spirit from the above ffz (man ffs).
|
|
|
|
|
*/
|
|
|
|
|
int ls1c_ffs(int x)
|
|
|
|
|
{
|
|
|
|
|
int r = 1;
|
|
|
|
|
|
|
|
|
|
if (!x)
|
|
|
|
|
return 0;
|
|
|
|
|
if (!(x & 0xffff)) {
|
|
|
|
|
x >>= 16;
|
|
|
|
|
r += 16;
|
|
|
|
|
}
|
|
|
|
|
if (!(x & 0xff)) {
|
|
|
|
|
x >>= 8;
|
|
|
|
|
r += 8;
|
|
|
|
|
}
|
|
|
|
|
if (!(x & 0xf)) {
|
|
|
|
|
x >>= 4;
|
|
|
|
|
r += 4;
|
|
|
|
|
}
|
|
|
|
|
if (!(x & 3)) {
|
|
|
|
|
x >>= 2;
|
|
|
|
|
r += 2;
|
|
|
|
|
}
|
|
|
|
|
if (!(x & 1)) {
|
|
|
|
|
x >>= 1;
|
|
|
|
|
r += 1;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|