Code: Select all
#define A (1)
#define B (2)
#define C(32)Code: Select all
PageSize = sysconf(_SC_PAGESIZE);
PageMask = (~(PageSize-1));
addr_start = IO_BASE & PageMask;
addr_offset = IO_BASE & ~PageMask;Code: Select all
#define A (1)
#define B (2)
#define C(32)Code: Select all
PageSize = sysconf(_SC_PAGESIZE);
PageMask = (~(PageSize-1));
addr_start = IO_BASE & PageMask;
addr_offset = IO_BASE & ~PageMask;jamesh wrote:Not sure what the third define is - have you copied it correctly? But the other two simple define A to be (1) and B to be (2) - remember the preprocessor is a direct text substitution.
The second question ,sysconf returns a long int, that's probably a 64 bit value but it depends on the build IRC. _SC_PAGESIZE inquire about the virtual memory page size of the machine.
So lets say it's 4K (4096, or 001000000000000 in binary). Pagemask is then set to the inverse of 4096 -1, which would be ~(11111111111), or 1111111111111111111111111111100000000000 (I may have got the number of 1 wrong, but its all of them)
Now that is then applied to various other values. Try working the numbers out to see what happens.
Always a good idea when trying to work out code - try it with some numbers, and see what happens.
Taking James' example of a 4K pagesize, address_start will hold an address that is aligned to 4K (upper 20 bits of IO_BASE with the lowest 12 bits set to zero), and address_offset will hold the value that you need to add to address_start (lowest 12 bits of IO_BASE with the upper 20 bits set to zero) such that address_start + address_offset = IO_BASE.lilzz wrote:jamesh wrote:Not sure what the third define is - have you copied it correctly? But the other two simple define A to be (1) and B to be (2) - remember the preprocessor is a direct text substitution.
The second question ,sysconf returns a long int, that's probably a 64 bit value but it depends on the build IRC. _SC_PAGESIZE inquire about the virtual memory page size of the machine.
So lets say it's 4K (4096, or 001000000000000 in binary). Pagemask is then set to the inverse of 4096 -1, which would be ~(11111111111), or 1111111111111111111111111111100000000000 (I may have got the number of 1 wrong, but its all of them)
Now that is then applied to various other values. Try working the numbers out to see what happens.
Always a good idea when trying to work out code - try it with some numbers, and see what happens.
thanks but I fail to see how page mask is related to address_start and ~pagemask relates to address offset.