Forum Discussion
Altera_Forum
Honored Contributor
14 years agoThink of alignment in bytes instead of bits. In your original post you where using a 32-bit write macro which requires 4 byte alignment. So when accessing a slave port that contains 32-bit registers you would access them using 4 byte aligned addresses such as 0, 4, 8, etc....
IOWR is a little different. It performs 32-bit accesses too but the offset field is in terms of 4 byte words. So IOWR_32DIRECT uses offsets such as 0, 4, 8, etc... but using IOWR you would use offsets 0, 1, 2, etc... to access the same locations. This can become confusing so I recommend sticking to one type of macros. I personally prefer IOWR_32DIRECT over IOWR since I find it necessary to use IOWR_8DIRECT and IOWR_16DIRECT which there is no equivalent using IOWR. So using the "direct" macros you control the size of the access and always use a byte offset. For _8DIRECT you can use any alignment and with _16DIRECT you use 2 byte alignment. 9203 was not aligned for use by IOWR_32DIRECT because it is not divisible by 4. To write a single byte to offset 9203 you would use IOWR_8DIRECT. Now be careful doing this, if the slave port you are accessing doesn't contain byteenables you might need to perform a read-modify-write to avoid sideeffects. If the slave is 32-bit and doesn't use byte enables writing a byte to address 9203 will cause addresses 9200-9202 to become written with zeros. If this is the case you might be able to read all four bytes, modify the upper byte, then write the full 32-bit word back out to address 9200.