-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create 16/32-bit compatible AVR Registers mocks, _SFR_MEM8 in particular #120
Comments
The comment you linked suggests mocking all registers to a single memory location, but I'm not sure that's helpful, since it does not allow the tests to see read back any values written to the registers by the sketch or library code. Doing so could be quite helpful in testing in some cases. Also, this is actually already used in the SPI mock: I presume this reads back the SPI hardware register to see if the sketch/library wrote anything to it to configure the byte order, snice there is no official Arduino API to do so I think, so sketches probably do this manually if they need a non-default byte order. If all registers would map back to the same memory location, this code would not work as expected. One approach I can imagine is to just allocate a block of memory to represent all of the registers, and just let the This approach allows keeping the current approach (that I rather like) of including the
Note the difference between SFR_IO and SFR_MEM: On AVR, the general purpose registers (r0, r1, etc.) are mapped at adress 0x0 - 0x20, the I/O registers are mapped starting at 0x20 (up to |
Note that the above is heavily based on what AVR-libc does itself in its |
Could we discuss this on #183 ? What I really need are some unit test cases in here: Specifically, I'm looking for some reading & writing tests as a hint into whatever data structure is required to implement this. |
I'm stuck because // hardware mocks, consolidated from _AVR_IO_REG and __SFR_OFFSET
volatile long long __ARDUINO_CI_SFR_MOCK[1024];
#define _SFR_IO8(io_addr) (*(volatile uint8_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))
#define _SFR_IO16(io_addr) (*(volatile uint16_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))
#define _SFR_MEM8(io_addr) (*(volatile uint8_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))
#define _SFR_MEM16(io_addr) (*(volatile uint16_t *)(__ARDUINO_CI_SFR_MOCK + io_addr))
#define _SFR_MEM32(io_addr) (*(volatile uint32_t *)(__ARDUINO_CI_SFR_MOCK + io_addr)) Depending on where I put this, I get
or
I'm sure there's something obvious I'm missing with regards to the way I'm doing |
The duplicate symbol issue is because you are defining a variable in a header. It should be declared in the header as |
I think this was fixed by #183 but if not please reopen |
I think it is. Re-reading #120 (comment) I do see that I originally suggested to use a 0x20 offset for the |
If it's trivial to fix, I'll take a PR. Otherwise, just an idea of a unit test that demonstrates the issue would be fine for me to make progress on |
Feature Request
See discussion here: #115 (comment)
It's time to take a more formal approach to the issue of AVR register mocks. All options will be on the table including refactoring/renaming the files that are there already.
Figuring out where
AdrAdc.{h,cpp}
should live is minimum acceptance criteria for this issue.The text was updated successfully, but these errors were encountered: