M
ma740988
The member variable addr2 -below- is the address received from a
_vendor_ function (not shown). For discussion purposes lets assume the
address is 0xCFF44000
The code:
typedef unsigned int UINT32;
#define LLSB(x) ((x) & 0xff)
#define LNLSB(x) (((x) >> 8) & 0xff)
#define LNMSB(x) (((x) >> 16) & 0xff)
#define LMSB(x) (((x) >> 24) & 0xff)
UINT32 LongSwap(UINT32 x) {
return (LLSB(x) << 24) |
(LNLSB(x) << 16) |
(LNMSB(x) << 8) | LMSB(x);
}
struct Register {
operator UINT32() {
return *reinterpret_cast<uint32_t *>(this);
}
void set(UINT32 n) {
*reinterpret_cast<uint32_t *>(this)=LongSwap(n);
}
};
// register2 is comprised of two 16 bit values..
struct register2 : public Register{
UINT32 start_vec : 16;
UINT32 stop_vec : 16;
};
// later
UINT32 Bar2Addr;
UINT32 *cReg2Addr;
register2* reg2;
STATUS initialize()
{
STATUS stat;
UINT32 addr2 = 0xCFF44000;
cReg2Addr = (UINT32 *)addr2;
cReg2Addr += 4;
reg2 = (register2*)cReg2Addr ; // map reg2 pointer to addr2
}
void write_to_reg2(
unsigned short val1,
unsigned short val2
)
{
register2 reg;
reg.start_vec = val1;
reg.stop_vec = val2;
reg2->set(UINT32(reg)); // write val1 and val2 to address but first
endian conversion..
}
Prior to modifying the contents of the address (cReg2Addr) provided, I
must perform an endian conversion (hence the longSwap). The question.
Am I on the right track as far as my approach?
Thanks in advance.
_vendor_ function (not shown). For discussion purposes lets assume the
address is 0xCFF44000
The code:
typedef unsigned int UINT32;
#define LLSB(x) ((x) & 0xff)
#define LNLSB(x) (((x) >> 8) & 0xff)
#define LNMSB(x) (((x) >> 16) & 0xff)
#define LMSB(x) (((x) >> 24) & 0xff)
UINT32 LongSwap(UINT32 x) {
return (LLSB(x) << 24) |
(LNLSB(x) << 16) |
(LNMSB(x) << 8) | LMSB(x);
}
struct Register {
operator UINT32() {
return *reinterpret_cast<uint32_t *>(this);
}
void set(UINT32 n) {
*reinterpret_cast<uint32_t *>(this)=LongSwap(n);
}
};
// register2 is comprised of two 16 bit values..
struct register2 : public Register{
UINT32 start_vec : 16;
UINT32 stop_vec : 16;
};
// later
UINT32 Bar2Addr;
UINT32 *cReg2Addr;
register2* reg2;
STATUS initialize()
{
STATUS stat;
UINT32 addr2 = 0xCFF44000;
cReg2Addr = (UINT32 *)addr2;
cReg2Addr += 4;
reg2 = (register2*)cReg2Addr ; // map reg2 pointer to addr2
}
void write_to_reg2(
unsigned short val1,
unsigned short val2
)
{
register2 reg;
reg.start_vec = val1;
reg.stop_vec = val2;
reg2->set(UINT32(reg)); // write val1 and val2 to address but first
endian conversion..
}
Prior to modifying the contents of the address (cReg2Addr) provided, I
must perform an endian conversion (hence the longSwap). The question.
Am I on the right track as far as my approach?
Thanks in advance.