// 源程序
#include <stdio.h>
#define HIETH_SYSREG_BASE (0x101e0000)
#define REG_RESET 0x01C // 外设控制寄存器(IP软复位控制)
#define RESET_SHIFT 12
static void hieth_set_regbit(unsigned long addr, int bit, int shift)
{
unsigned long reg;
reg = 0xffffffff;
bit = bit ? 1 : 0;
printf("bit = %s\n", bit ? "Ture" : "Flase");
reg &= ~(1 << shift);
printf("reg & = %lx\n", reg);
reg |= bit << shift;
printf("reg | = %lx\n", reg);
reg = 0x00000000;
bit = bit ? 1 : 0;
printf("bit = %s\n", bit ? "Ture" : "Flase");
reg &= ~(1 << shift);
printf("reg & = %lx\n", reg);
reg |= bit << shift;
printf("reg | = %lx\n", reg);
}
typedef struct _DEF
{
#define W 5
int i;
}sdef;
void perfect()
{
#define P 5
printf("perfect = %d sizeof(sdef) = %ld\n", P, sizeof(sdef));
}
void perfect2()
{
printf("perfect2 = %d\n", P);
}
#define MK_BITS(shift, nbits) ((((shift)&0x1f)<<16) | ((nbits)&0x1f))
#define BITS_RXPKG_RDY MK_BITS(0,1)
#define hieth_readl_bits(ld, ofs, bits_desc) ({ \
unsigned long _bits_desc = bits_desc; \
unsigned long _shift = (_bits_desc)>>16; \
unsigned long _mask = ((1<<(_bits_desc & 0x1F)) - 1)<<(_shift); \
printf("[%ld %ld %ld]\n", _bits_desc, _shift, _mask);\
printf("%ld\n", ((ld+ofs)&_mask)>>(_shift)); })
#define BITS_RXPKG_ID MK_BITS(16, 6)
int main()
{
int rst = 1;
rst = !rst;
printf("!rst = %d\n", rst);
hieth_set_regbit(HIETH_SYSREG_BASE + REG_RESET, 1, RESET_SHIFT);
perfect();
perfect2();
//printf("%d shift(1>>16) = %d %d %d\n", MK_BITS(0,1), 1>>16, MK_BITS(16,6), MK_BITS(0,11));
//printf("%d %d %d\n", MK_BITS(16,0), MK_BITS(17,0), MK_BITS(25,0));
//printf("%d %d %d\n", 16 & 0x1f, 17 & 0x1f, 32 & 0x1f );
printf("main %d\n", hieth_readl_bits(0, 1, BITS_RXPKG_ID));
return 0;
}