when I read SYSTEMC code,I find a function return int like this:
static inline int rp_get_busaccess_response(struct rp_pkt *pkt)
{
return (pkt->busaccess_ext_base.attributes & RP_BUS_RESP_MASK) >>
RP_BUS_RESP_SHIFT;
}
pkt->busaccess_ext_base.attributes defined as uint64_t.
RP_BUS_RESP_MASK and RP_BUS_RESP_SHIFT defined as:
enum {
RP_RESP_OK = 0x0,
RP_RESP_BUS_GENERIC_ERROR = 0x1,
RP_RESP_ADDR_ERROR = 0x2,
RP_RESP_MAX = 0xF,
};
enum {
RP_BUS_RESP_SHIFT = 8,
RP_BUS_RESP_MASK = (RP_RESP_MAX << RP_BUS_RESP_SHIFT),
};
What the meaning of this function's return?
Thanks!
a & bis a bitwise operation, this will perform a logicalANDto each pair of bits, let's say you have262 & 261this will translate to100000110 & 100000101the result will be100000100(260), the logic behind the result is that each1 AND 1will result in1whereas1 AND 0and0 AND 0will result in0, these are normal logical operations but are performed at bit level:In
(a & b) >> c,>>will shift the bits of the resulting value ofa & bto the right bycpositions. For example for the previous result100000100and having acvalue of8, all bits will shift to the right by8, and the result is000000001. The left most1bit in the original value will become the first most right whereas the third1bit from the right in the original value will be shifted away.With this knowledge in mind and looking at the function, we can see that the
RP_BUS_RESP_MASKconstant is a mask that protects the field of bits from 9th through 12th position(from the right, i.e. the first four bits of the second byte), setting them to1(RP_RESP_MAX << RP_BUS_RESP_SHIFTwhich translates to1111<<8resulting in111100000000), this will preserve the bit values in that range. Then it sets the other bits ofpkt->busaccess_ext_base.attributesto0when it performs the bitwise&against this mask. Finally it shifts this field to the right byRP_BUS_RESP_SHIFT(8).It basically extracts the the first four bits in the second byte of
kt->busaccess_ext_base.attributesand returns the result as an integer.What it's for specifically? You must consult the documentation if it exists or try to understand its use in the global context, for what I can see this belongs to LibSystemCTLM-SoC (In case you didn't know)