// apply union to read and arrange some useful register value
//============================ contains in *.h
typedef struct {
//register 0
union {
uint32 interrupt_register_0;
struct InterruptRegister0{
uint8 command;
uint8 control;
uint8 feature;
uint8 feature_ext;
}isr;
..... omit more other register ....
};
}TaskFile;
//------------------------------------------------- defined in IC spec, each 32 bit register has divided into several part
// for example, InterruptSatausRegister0[31...24] = command
// InterruptSatausRegister0[23...16] = control
//
typedef struct { /* DWORD Offset */ /* BYTE Offset */
volatile uint32 InterruptSatausRegister0; /* 0x00 */ /* 0x00 */
volatile uint32 InterruptSatausRegister1; /* 0x01 */ /* 0x04 */
............. omit more other register ....................
}IcRegister;
#define READ_REGISTER(regname, data32) { (data32) = g_register->regname; }
#define REGES_BASE 0xC0000000 //physicall register address
IcRegister (* const g_register) = (IcRegister *)REGS_BASE;
//============================ contains in *.c
void main()
{
TaskFile task_file;
READ_REGISTER(InterruptSatausRegister0, task_file.interrupt_register_0);
//finally we can get data in task_file easily
//e.g. task_file.isr.command , task_file.isr.control .... etc.
}