Skip to content
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

cpu/sam0_common: avoid bitfield usage #20747

Merged
merged 19 commits into from
Jun 26, 2024

Conversation

dylad
Copy link
Member

@dylad dylad commented Jun 11, 2024

Contribution description

This PR removes all bitfields usage from cpu/sam0_common/ folder.
I decided to go with a commit per file to allow an easy revert in case something got terribly wrong. Nevertheless, CI should catch most of the issues early. However, I might get sleepy here and there so please, take a careful eyes at this.

/!\ Breakages are highly probable here /!\

Testing procedure

Triple careful review and CI should save us hopefully.

Issues/PRs references

#20457

@github-actions github-actions bot added Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: cpu Area: CPU/MCU ports labels Jun 11, 2024
@dylad dylad added CI: run tests If set, CI server will run tests on hardware for the labeled PR CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 11, 2024
@riot-ci
Copy link

riot-ci commented Jun 11, 2024

Murdock results

✔️ PASSED

ccc155e cpu/sam0: remove bitfield usage in sdhc driver

Success Failures Total Runtime
10178 0 10178 18m:06s

Artifacts

@dylad dylad removed the CI: run tests If set, CI server will run tests on hardware for the labeled PR label Jun 12, 2024
cpu/sam0_common/periph/adc.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/dma.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/dma.c Outdated Show resolved Hide resolved
Copy link
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a lot of 1 rmw to 2 rmw cases.

some might need a temporary, can probably be some thing like

REG = (REG & ~Msk) | ((val << Pos) &Msk);

there might be a macro for this

cpu/sam0_common/include/periph_cpu_common.h Outdated Show resolved Hide resolved
cpu/sam0_common/periph/adc.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/dma.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/dma.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/rtc_rtt.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/wdt.c Outdated Show resolved Hide resolved
Copy link
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not merge until the doubling of the rmws is fixed

@dylad
Copy link
Member Author

dylad commented Jun 12, 2024

@kfessel I've pushed my fixup commits.

Copy link
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

mostly good

cpu/sam0_common/periph/dma.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/wdt.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/uart.c Outdated Show resolved Hide resolved
Comment on lines +353 to +356
do {
cmd = ((dev(tim)->CTRLBSET.reg & TC_CTRLBSET_CMD_Msk) >> TC_CTRLBSET_CMD_Pos);
} while(cmd == TC_CTRLBSET_CMD_READSYNC_Val);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be faster but please ignore unless someone objdumped

Suggested change
do {
cmd = ((dev(tim)->CTRLBSET.reg & TC_CTRLBSET_CMD_Msk) >> TC_CTRLBSET_CMD_Pos);
} while(cmd == TC_CTRLBSET_CMD_READSYNC_Val);
do {
cmd = ((dev(tim)->CTRLBSET.reg & TC_CTRLBSET_CMD_Msk));
} while(cmd == TC_CTRLBSET_CMD_READSYNC_Val << TC_CTRLBSET_CMD_Pos);

cpu/sam0_common/periph/adc.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/adc.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/adc.c Outdated Show resolved Hide resolved
@dylad
Copy link
Member Author

dylad commented Jun 14, 2024

@kfessel A new round of fixups has been pushed.

Copy link
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it getting fewer

btw i'd like to ask: if you are doing tests?

cpu/sam0_common/periph/adc.c Show resolved Hide resolved
cpu/sam0_common/periph/uart.c Outdated Show resolved Hide resolved
Comment on lines +193 to +198
uint32_t ctrlc = dev->CTRLC.reg;
dev->CTRLC.reg = ((ctrlc & ~ADC_CTRLC_RESSEL_Msk) | ADC_CTRLC_RESSEL(res));
#else
/* Reset resolution bits in CTRLB */
dev->CTRLB.bit.RESSEL = res & 0x3;
uint32_t ctrlb = dev->CTRLB.reg;
dev->CTRLB.reg = ((ctrlb & ~ADC_CTRLB_RESSEL_Msk) | ADC_CTRLB_RESSEL(res));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function is called configure but does not configure all the bits (and nothing else in this file does) this seem to me like bad code translated well.

you might ignore this comment your translation mimics the old behavior

cpu/sam0_common/include/periph_cpu_common.h Outdated Show resolved Hide resolved
cpu/sam0_common/periph/adc.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/uart.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/usbdev.c Outdated Show resolved Hide resolved
cpu/sam0_common/periph/wdt.c Outdated Show resolved Hide resolved
cpu/sam0_common/sam0_sdhc/sdhc.c Outdated Show resolved Hide resolved
@dylad
Copy link
Member Author

dylad commented Jun 14, 2024

@benpicco @kfessel Third round is done.

Copy link
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine testing?

@kfessel kfessel dismissed their stale review June 14, 2024 10:47

obvious issues are resolved -- looks fine

@dylad
Copy link
Member Author

dylad commented Jun 14, 2024

looks fine testing?

I don't have hardware with me right now. I'll re-run tests on hardware this weekend if I manage to get some time.

@dylad
Copy link
Member Author

dylad commented Jun 17, 2024

I've run basics tests (timers, RTC, I2C, SPI, UART, USB, PWM) on saml11-xpro, saml21-xpro, samr21-xpro. I didn't spot any regression so far.

@dylad
Copy link
Member Author

dylad commented Jun 20, 2024

@benpicco @kfessel May I squash this one ?

@kfessel
Copy link
Contributor

kfessel commented Jun 20, 2024

thanks for testing; please squash

Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
@dylad dylad force-pushed the pr/cpu/sam0/avoid_bitfield_usage branch from fa40dc1 to f32f08a Compare June 21, 2024 07:46
@dylad
Copy link
Member Author

dylad commented Jun 21, 2024

Squashed !

@dylad dylad force-pushed the pr/cpu/sam0/avoid_bitfield_usage branch from f32f08a to f1116f2 Compare June 24, 2024 11:57
@dylad
Copy link
Member Author

dylad commented Jun 24, 2024

Fixed a typo in the UART driver spotted by Murdock.
Let's see if it's happy now.

@dylad
Copy link
Member Author

dylad commented Jun 24, 2024

All green !

Copy link
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

translation looks correct,

For the test i trust @dylad.

@dylad dylad added this pull request to the merge queue Jun 25, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 25, 2024
dylad added 11 commits June 25, 2024 16:13
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
@dylad dylad force-pushed the pr/cpu/sam0/avoid_bitfield_usage branch from f1116f2 to ccc155e Compare June 25, 2024 14:13
@dylad
Copy link
Member Author

dylad commented Jun 25, 2024

Murdock spotted an inconsistency in PWM driver for SAMD20. That should be good now.

@dylad dylad enabled auto-merge June 25, 2024 14:17
@dylad dylad added this pull request to the merge queue Jun 25, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 25, 2024
@dylad dylad added this pull request to the merge queue Jun 25, 2024
Merged via the queue into RIOT-OS:master with commit 8f645a9 Jun 26, 2024
25 checks passed
@dylad dylad deleted the pr/cpu/sam0/avoid_bitfield_usage branch June 26, 2024 05:24
@dylad
Copy link
Member Author

dylad commented Jun 26, 2024

Thanks !

@mguetschow mguetschow added this to the Release 2024.07 milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants