Skip to content

cpu/nrf52/i2c: use static mutex initializtion#8486

Merged
PeterKietzmann merged 1 commit intoRIOT-OS:masterfrom
haukepetersen:fix_nrf52_i2c-mutexinit
Feb 2, 2018
Merged

cpu/nrf52/i2c: use static mutex initializtion#8486
PeterKietzmann merged 1 commit intoRIOT-OS:masterfrom
haukepetersen:fix_nrf52_i2c-mutexinit

Conversation

@haukepetersen
Copy link
Copy Markdown
Contributor

Contribution description

The I2C driver breaks for certain device drivers, e.g. when they call i2c_acquire before calling i2c_init_master (and also there could be concurrency issues down the line if not).

Issues/PRs references

fixes parts of #8446

*/
static mutex_t locks[] = {
MUTEX_INIT,
MUTEX_INIT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is there two elements in the array ? What if we use only one I2C ? there is no need for the second lock then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that is correct. But the way the I2C devices are currently defined, there is no easy way to do on-demand static mutex initialization, so I rather waste 4 byte of memory here than to deal with potentially ugly code overhead. Keep in mind that something like #if I2C_NUMOF > 1 does not work here...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there is no easy way to do on-demand static mutex initialization

I fully agree with you as I encounter the same issue with #7588
But I don't really like to waste memory with unused stuff.
Personally, I think we should init dynamically (but we must solve #8446 first)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree with not wasting memory (in general)!

In this particular case though, I think we can live with it: this fix is rather temporary, as the driver is going to be slightly reworked once we finally start to tackle the adaption of #6576. With the changes coming there, we can easily go back to dynamic initialization of the mutex(es), as the init_master function will only be called once during system startup...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this fix is rather temporary

Good to know.

once we finally start to tackle the adaption of #6576

Can't wait we start this one !

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't wait we start this one !

@dylad happy to hear that :-)! You seem quite experienced so it would be great to have you on board for that. Bit off-topic: are you aware of any kind of reference I2C-slave device/implementation?

@PeterKietzmann PeterKietzmann added Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 2, 2018
@PeterKietzmann
Copy link
Copy Markdown
Member

I would ACK this PR, @dylad how about you?

@dylad
Copy link
Copy Markdown
Member

dylad commented Feb 2, 2018

it would be great to have you on board for that

I would love to help you with this new API and start asap :)

are you aware of any kind of reference I2C-slave device/implementation?

I think I only used such implementation once, it was with an Arduino Uno. Maybe we can have a look there ?

@dylad how about you?

I'm fine with the current change. I did not run any test, but IMHO this PR should go.

@PeterKietzmann PeterKietzmann added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 2, 2018
Copy link
Copy Markdown
Member

@PeterKietzmann PeterKietzmann left a comment

Choose a reason for hiding this comment

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

Tested together with #8385. ACK and go

@PeterKietzmann PeterKietzmann merged commit 047219a into RIOT-OS:master Feb 2, 2018
@haukepetersen haukepetersen deleted the fix_nrf52_i2c-mutexinit branch February 2, 2018 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants