Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Fix CriticalSection lock for nrf51 targets. #77

Merged
merged 1 commit into from
Feb 29, 2016

Conversation

pan-
Copy link
Member

@pan- pan- commented Feb 19, 2016

The previous implementation of CriticalSectionLock for nrf51 was only
relying to softdevice primitives sd_nvic_critical_region_enter and
sd_nvic_critical_region_exit .
If the soft device is not enabled, these functions have no effect. This
means that CriticalSectionLock was not locking anything if the softdevice
was not enabled.

This fix allow the usage of CriticalSectionLock, even if the softdevice is
not enabled. If the softdevice is not enabled, all irq are disabled until
the destruction of the lock.

This PR should be merged with: ARMmbed/mbed-hal-nrf51822-mcu#48

@pan-
Copy link
Member Author

pan- commented Feb 19, 2016

@rgrover @0xc0170 @emidttun could you review this please ?

@rgrover
Copy link
Contributor

rgrover commented Feb 22, 2016

+1

@emidttun
Copy link

Looks correct to me, but out of curiosity: Why isn't there an IRQ enable in the destructor? (It was like that before the change.)

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 22, 2016

Looks correct to me, but out of curiosity: Why isn't there an IRQ enable in the destructor? (It was like that before the change.)

Which line are you referencing ? It restores primask, as it was before.

// get the state of exceptions for the CPU
_PRIMASK_state = __get_PRIMASK();

// if exceptions are not enabled, there is nothing more to do
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the formatting in the changes:

an example:

        if (_PRIMASK_state == 1) {
            _use_softdevice_routine = false;
        } else {

Copy link
Member Author

Choose a reason for hiding this comment

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

I've done it.

@emidttun
Copy link

@0xc0170 So the __disable_irq() only writes to PRIMASK? Wasn't aware of it; then no further comments.

The previous implementation of CriticalSectionLock for nrf51 was only
relying to softdevice primitives sd_nvic_critical_region_enter and
sd_nvic_critical_region_exit .
If the soft device is not enabled, these functions have no effect. This
means that CriticalSectionLock was not locking anything if the softdevice
was not enabled.

This fix allow the usage of CriticalSectionLock, even if the softdevice is
not enabled. If the softdevice is not enabled, all irq are disabled until
the destruction of the lock.
@pan- pan- force-pushed the fix_critical_section_lock_nrf51 branch from 3e3e2bf to f90ab01 Compare February 22, 2016 11:12
@0xc0170
Copy link
Contributor

0xc0170 commented Feb 23, 2016

LGTM, however it is lot of code for for critical section :-)

cc @bogdanm

@bogdanm
Copy link
Contributor

bogdanm commented Feb 23, 2016

That does look like a lot of code, thus quite a few opportunities for race conditions. I'm going to trust @rgrover on this one, since I'm not that familiar with nRF51 targets. So, +1.

bogdanm added a commit that referenced this pull request Feb 29, 2016
Fix CriticalSection lock for nrf51 targets.
@bogdanm bogdanm merged commit 7aedf7b into ARMmbed:master Feb 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants