Add shadow register for UBRRH to keep it separate from UCSRC#309
Open
StefanKrupop wants to merge 1 commit intobuserror:masterfrom
Open
Add shadow register for UBRRH to keep it separate from UCSRC#309StefanKrupop wants to merge 1 commit intobuserror:masterfrom
StefanKrupop wants to merge 1 commit intobuserror:masterfrom
Conversation
In e.g. ATmega8 UBRRH and UCSRC registers share the same I/O location.
Bit URSEL decides in which physical register written data should go.
As there are now more registers then I/O locations, "shadow" versions of
certain regbit functions that store to a pointer ("shadow register")
instead of the main registers in avr->data[] were introduced.
UBRRH was moved into a shadow register, while UCSRC stays a regular register.
Therefore, writes to UBRRH/UCSRC with URSEL bit set do not set the baudrate
falsely anymore.
|
Thank You, I applied Your patch and working well. Great job. |
buserror
reviewed
Nov 27, 2019
Comment on lines
+242
to
+259
| if (addr == p->ubrrh.reg) { | ||
| if (p->ubrrh.reg == p->r_ucsrc) { | ||
| // UBRRH and UCSRC registers can share the same I/O location. | ||
| // URSEL bit decides which register gets written. If it's UBRRH, | ||
| // store to shadow register, else to regular register | ||
| if ((v & (1 << 7)) == 0) { // URSEL | ||
| avr_regbit_setto_shadow(avr, p->ubrrh, v, &p->ubrrh_shadow); | ||
| } else { | ||
| avr_core_watch_write(avr, addr, v); | ||
| } | ||
| } else { | ||
| // If UBRRH have different I/O locations, update shadow register and | ||
| // regular register | ||
| avr_core_watch_write(avr, addr, v); | ||
| avr_regbit_setto_shadow(avr, p->ubrrh, v, &p->ubrrh_shadow); | ||
| } | ||
| return; | ||
| } |
Owner
There was a problem hiding this comment.
I think that sort of behaviour should be encoded in the core declaration, for example a new field with 'ursel' would both allow feature testing and encode the feature in a generic way. here it's all hard coded.
Also for that sort of feature, I don't /think/ we really need the new _shadow accessors for regbits, it's a simple enough behaviour that is just visible in the set/get for this feature, AFAIK...
Personally, I would introduce a more generic behaviour where the two (or more) values are stored part of a regbit with a discriminant, instead of having to carry around a pointer to an uint8_t...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In e.g. ATmega8 UBRRH and UCSRC registers share the same I/O location.
Bit URSEL decides in which physical register written data should go.
As there are now more registers then I/O locations, "shadow" versions of
certain regbit functions that store to a pointer ("shadow register")
instead of the main registers in avr->data[] were introduced.
UBRRH was moved into a shadow register, while UCSRC stays a regular register.
Therefore, writes to UBRRH/UCSRC with URSEL bit set do not set the baudrate
falsely anymore.