-
Notifications
You must be signed in to change notification settings - Fork 136
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
changed mcp2515 driver to use nonblocking spi #817
base: develop
Are you sure you want to change the base?
Conversation
… standard modm::can api
…king, which should be fine because it is controlled via interrupt
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.
Nice!
Thanks for taking care of this!
src/modm/driver/can/mcp2515_impl.hpp
Outdated
return true; | ||
} | ||
|
||
template <typename SPI, typename CS, typename INT> | ||
modm::ResumableResult<bool> |
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.
Shouldn't update()
return modm::ResumableResult<void>
?
Because nobody (in the main loop) will handle the return value...
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.
it's just the return value of sendMessage indicating if a message was sent this cycle ... not really useful but i thought why not :D ... iwill remove it
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.
it is void now
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.
it is void now
No it's not.
… as well; fixed some things in example
dc57d6f
to
03639b4
Compare
Another addition: This driver thould use the Off-topic discussion: In the case mentioned above the SPI clock has to be limited to 1MHz or 2MHz (ADIS16470 limitation), but for the MCP2515 a higher SPI clock would be desirable. This probably affects many (SPI) drivers, what would be the most elegant way to solve this in modm? |
That requires to reconfigure SPI timings when the |
@rleh I have quickly hacked together a sub-optimal implementation for switching the SPI baudrate with multiple devices. This is just a rough proof of concept for STM32 only and makes changes to the https://github.com/chris-durand/modm/tree/wip_spi_user_conf_handler |
I don't know what that is bit I'll look into it tomorrow (after our work meeting stuff) |
The configuration handler is actually quite simple. If you have multiple devices on one bus that require different SPI modes you'll need to reconfigure the mode whenever you run a transfer on the next device. You can define a callback that configures the required parameters and modm will call it automatically when needed. Here is an example. EDIT: if you mean the |
Yeah the second one .. you explained what it does quite well, thanks :) |
…evice is now used internally for aquiring / releasing the bus whenever accessed
…he spi clock frequency when master is acquired
…ationHandler in example; changes canbdaudrate to 500kbps
@rleh @chris-durand |
SpiDevice test seems to be broken? Or did I do something wrong? |
That is because of my experimental commit that was cherry-picked. It is only a proof of concept for STM32. Remove it and everything will be fine :) |
This does not have to happen in this PR, in my view it is even nicer to do it in a separate PR. |
I guess @kikass13 might be asking if we should change the API of the MCP2515 driver, not the |
@chris-durand currently i like the fact that this thing is static. I dislike the "mix" but i can live with it ... I have some software running this thing currently (successfully), and I really depend on the fact, that the can interfaces can be used statically.
At least the current implementation works for me
|
Can't you in the class where you passed the static class as a template argument instantiate an object of the template argument? Then it works with both static and non-static classes. |
sure, i was just trying to explain that the old "design" could still be valid. @rleh you blocked my initial changes because I changed the API, so changing it back again now seems kind of redundant :D |
…t (aka NOT attempting to send it) if the mcp is not readyToSend() instead of waiting for it to be ready, which defeats the point of buffering packets indefiniteley
@@ -16,24 +16,13 @@ | |||
#ifndef MODM_MCP2515_HPP | |||
#error "Don't include this file directly, use 'mcp2515.hpp' instead!" | |||
#endif | |||
|
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.
Unnecessary whitespace change.
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.
Not resolved.
src/modm/driver/can/mcp2515_impl.hpp
Outdated
if(not modm_assert_continue_ignore(rxQueue.push(messageBuffer_), "mcp2515.can.tx", | ||
"CAN transmit software buffer overflowed!", 1)){ | ||
/// ignore | ||
} |
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.
Remove the if statement if the body is empty.
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.
well it was there before ... it shows intent .. so i kept it for now
…code; minor style changes to mcp2515 driver impl
@rleh i have changed all the points you made (hopefully to your satisfaction) :) |
…d unused project xml things; cleaned up unused headers; changed mcp2515 driver class attributes to not have _ underscore postfix
814c603
to
5aa143e
Compare
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.
- Inside
initializeWithPrescaler()
SPI access is performed without locking the bus (usingSpiDevice::acquireMaster()
/::releaseMaster()
) writeRegister()
,readRegister()
andbitModify()
also perform SPI access without usingSpiDevice::acquireMaster()
/::releaseMaster()
and are not resumable
You have to switch from the update()
resumable function to a protothread, and inside the protothread you can then do the initialization stuff, triggered by a flag set from the initialize()
function.
<option name="modm:driver:mcp2515:buffer.tx">32</option> | ||
<option name="modm:driver:mcp2515:buffer.rx">32</option> |
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.
32 is already the default value. Remove?
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.
not a good idea, this shows intent .. nobody would know that this exists otherwise
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.
Everybody that reads the documentation or uses lbuild discover-options
will know about it...
namespace mcp2515{ | ||
namespace options{ | ||
|
||
%% if options["buffer.tx"] > 0 |
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.
%% if options["buffer.tx"] > 0 |
buffer.tx
is enforced to be within range 1..(2^16-2) by the lbuild module.
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.
(Same for rx buffer)
@@ -16,24 +16,13 @@ | |||
#ifndef MODM_MCP2515_HPP | |||
#error "Don't include this file directly, use 'mcp2515.hpp' instead!" | |||
#endif | |||
|
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.
Not resolved.
src/modm/driver/can/mcp2515_impl.hpp
Outdated
return true; | ||
} | ||
|
||
template <typename SPI, typename CS, typename INT> | ||
modm::ResumableResult<bool> |
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.
it is void now
No it's not.
src/modm/driver/can/mcp2515_impl.hpp
Outdated
template <typename SPI, typename CS, typename INT> | ||
modm::ResumableResult<bool> | ||
modm::Mcp2515<SPI, CS, INT>::update(){ | ||
using namespace mcp2515; | ||
|
||
RF_BEGIN(); |
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.
Shouldn't that rather be a Protothread and not a resumable function?
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.
dunno what you mean. As the api is right now (static), there exists a protothread in the user code (which you told me in a prior version of this driver update, that it should be consistent to the general driver api) ... which one is it?
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.
Hint:
template <typename SPI, typename CS, typename INT> | |
modm::ResumableResult<bool> | |
modm::Mcp2515<SPI, CS, INT>::update(){ | |
using namespace mcp2515; | |
RF_BEGIN(); | |
template <typename SPI, typename CS, typename INT> | |
void | |
modm::Mcp2515<SPI, CS, INT>::run() | |
{ | |
PT_BEGIN(); | |
//... |
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.
then the user hjas two protothreads runnign inside each other?
why should the thread be in the driver instead of the user deciding when or in which context update
is called?
Hint:
- not making a point clear / answering the implicity question of
what do you actually want to do and why
does not help me :D
src/modm/driver/can/mcp2515_impl.hpp
Outdated
if ((readStatus(READ_STATUS) & (TXB2CNTRL_TXREQ | TXB1CNTRL_TXREQ | TXB0CNTRL_TXREQ)) == | ||
RF_BEGIN(); | ||
|
||
tempS = true; |
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.
Meaningful variable name or explanation please...
src/modm/driver/can/mcp2515_impl.hpp
Outdated
ready = false; | ||
} | ||
return ready; |
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.
ready = false; | |
} | |
return ready; | |
return false; | |
} | |
return true; |
@@ -313,11 +398,9 @@ void | |||
modm::Mcp2515<SPI, CS, INT>::writeRegister(uint8_t address, uint8_t data) | |||
{ | |||
chipSelect.reset(); | |||
|
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.
Still a lot of unnecessary whitespace change in this part of the file.
Co-authored-by: Raphael Lehmann <[email protected]>
Co-authored-by: Raphael Lehmann <[email protected]>
@kikass13 Please stop marking my change requests which are not resolved as resolved. |
attachConfigurationHandler
for switching device spi typesor discovery boardattachConfigurationHandler
for switching device clock speeds