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

_acquire() function added & removed duplication in format/freq calls #4635

Merged
merged 3 commits into from
Jul 7, 2017

Conversation

deepikabhavnani
Copy link

Description

  1. Private _acquire() function is added to avoid multiple locking/unlocking
  2. format and frequenct functions updated to use appropriate function calls
    instead of a aquire()

Issue

#4626

Status

READY

Copy link
Contributor

@geky geky left a comment

Choose a reason for hiding this comment

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

Seems fine to me

1. Private _acquire() function is added to avoid multiple locking/unlocking
2. format and frequency functions updated to use appropriate function calls
instead of a aquire()
drivers/SPI.cpp Outdated
SPI::_owner = NULL; // Not that elegant, but works. rmeyer
aquire();
spi_frequency(&_spi, _hz);
_owner = this;
Copy link
Contributor

Choose a reason for hiding this comment

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

The owner can be changed here without ensuring that both frequency and format are set. The format setting maybe be incorrect on the next write since it was not updated.

A sequence similar to this would cause that:

spi_a.write(value_a)                 <-Internal call to _acquire will change owner and set frequency and format for SPI A
spi_b.frequency(freq_b)              <- Owner changed to B and frequency set
spi_b.write(value_b)                 <- Interal call to _acquire won't change setting. Frequency will be set correctly for B and format will be set for A

Copy link
Contributor

@c1728p9 c1728p9 left a comment

Choose a reason for hiding this comment

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

Thanks for updating this

drivers/SPI.h Outdated
@@ -270,6 +270,12 @@ class SPI {
int _bits;
int _mode;
int _hz;

private:
/* Private acquire fucntion without locking/unlocking
Copy link
Contributor

Choose a reason for hiding this comment

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

typo fucntion

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 28, 2017

A question, now we use _acquire private method. The old one (aquire) is without a change . How does this affect current programs? I don't see any virtual for aquire so should not have any impacts, correct?

@deepikabhavnani
Copy link
Author

Private _acquire has no locking, but since we lock before using this function behavior will be same. We do not have virtual function for aquire in code base, but some user might be having it, hence old aquire API is kept unchanged.

@theotherjimmy
Copy link
Contributor

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 697

All builds and test passed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants