-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
TwiMaster rework #568
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
TwiMaster rework #568
Conversation
|
Does disabling the bus or changing pin configuration actually save power? |
I think I found some info in datasheet/nrf devzone saying that the peripherals (spi, twi,...) would consume a bit of current when enabled (even with no communication happening). They also keep the HFClock enabled. That's why I tried to disabled them as soon as the watch goes to sleep mode. |
src/drivers/TwiMaster.cpp
Outdated
| // TODO use DMA/IRQ | ||
|
|
||
| TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {module}, params {params} { | ||
| mutex = xSemaphoreCreateBinary(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialization of the mutex was previously done in the ctor(), but I moved it to Init() in 6d524eb. The goal was to avoid Static Initialization Order Fiasco (see this.
I also wanted to ensure FreeRTOS was correctly initialized before instantiating mutexes and other objects.
Can we ensure this won't cause any issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a separate function called xSemaphoreCreateBinaryStatic(), so I'd assume that one isn't static and works correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't say I completely understand the issue, but this doesn't access global state so it doesn't apply right? I dont think we shoud be afraid of using constructors either because they can make the classes safe to use right away, and I would even like to move more stuff to the constructors to reduce the Init functions in code that can be avoided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course, most of the time, we shouldn't need an Init() function and use the ctor() to initialise the whole object. However, in this case, the ctor is called by the Startup code, before main() is called.
When you look at the code of xSemaphoreCreateBinary() you see it access to variables from FreeRTOS and even calls pvPortMalloc().
I'm not sure completely sure that it's ok that call freertos function before the scheduler is init'd and running.
It might work, as previously, all mutexes were initialized in the ctro(), but I moved them when I was chasing memory corruption issue (which, in the end, were not caused by those initializations in the ctor() so...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it back so we don't need to worry about it now.
|
I found something weird.
But then it is cast to Frequencies. What will happen here? The attempted frequency parameters value is slightly smaller than the K400 value, but can we be sure its safe because its not documented? |
|
Indeed, this casting for the frequency does not look right. |
Okay I found the same issue mentioned there and the same workaround so it seems fine to use. |
|
But I think this cast and |
I already fixed it :) |
Awesome, you're too fast for me ! :-D |
Made using TwiMaster simpler. The bus is simply enabled on each read/write and disabled when done. There's no need to think about or control the state outside of TwiMaster. I don't know if this is more expensive, but it seems to work just fine.
Internal pullups were enabled. They're unnecessary because external pullups are used.
This will fix the freezing issue in #492 so I can finally move forwards with it.Sleep() and Wakeup() can almost be made private, but there's still this piece of code in SystemTask I'm not brave enough to touch.