-
Notifications
You must be signed in to change notification settings - Fork 146
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
Open
kikass13
wants to merge
30
commits into
modm-io:develop
Choose a base branch
from
kikass13:mcp2515_protothread_update_3
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
148e788
changed mcp2515 driver to use rx and tx buffers as well as uphold the…
kikass13 10b0e46
added example; small line cleanup
kikass13 33db784
added update function to example, change build out dir
kikass13 21e4036
added nonblocking stuff for can send api part; the read is still bloc…
kikass13 03639b4
changed read/receive part so that it is polled in the update function…
kikass13 bf7b0fa
the should now be non static (the rx/tx queues as well); a modm::SpiD…
kikass13 9584f22
WIP: Add SPI user configuration handler for speed reconfiguration
chris-durand 8e6a52f
added configurationHanlder for spi device, which should also change t…
kikass13 bda5887
moved example to nucleo_f439; fixed example to work properly
kikass13 7c9065d
re-enable debug messages in main
kikass13 5357bc2
re-enable @chris-durand hack for changing bus clock speed in configur…
kikass13 c177db3
whitespaces
kikass13 d737638
removed @chris-durand hack again and put the configuration handler in…
kikass13 f94d31a
small fixes for ci
kikass13 6f773fc
removed unnecessary function
kikass13 33a621f
tried to keep the external api static, this means nonblocking initial…
kikass13 ed406ca
memory error when reading messages,
kikass13 ec7cf30
fixed bug in receiveMessage part, where status register was not read …
kikass13 a34f35d
accidentally commited stuff that was not supposed to be in here
kikass13 6c79bc2
merge other modm stuff
kikass13 6e6e359
removed debug log because ci will fail for avr if we leave the log le…
kikass13 49091cf
small acquire/release spi master fix for blocking setFilter and bitMo…
kikass13 dadd55f
small send rearrange, The send function will now skip sending a packe…
kikass13 5ac11f4
fixed some things related to comments from @rleh; cleanup of exmaple …
kikass13 2b5b355
@rleh: added rx & tx queue options to lbuild + mcp2515 driver; remove…
kikass13 5aa143e
remove useless / harmful modm log level overwrite + debug logs from p…
kikass13 4d7df65
Merge branch 'develop' into mcp2515_protothread_update_3
kikass13 2e4ad3b
Update src/modm/driver/can/mcp2515_options.hpp.in
kikass13 5906e17
Update src/modm/driver/can/mcp2515_impl.hpp
kikass13 0ff3eef
fixed some minor pedantic things
kikass13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* Copyright (c) 2013, Kevin Läufer | ||
* Copyright (c) 2013-2017, Niklas Hauser | ||
* Copyright (c) 2016, Raphael Lehmann | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/platform/spi/spi_master_1.hpp> | ||
#include <modm/processing/protothread.hpp> | ||
#include <modm/driver/can/mcp2515.hpp> | ||
|
||
// Set the log level | ||
#undef MODM_LOG_LEVEL | ||
#define MODM_LOG_LEVEL modm::log::DEBUG | ||
|
||
// If you use a different SPI instance, you may have to also choose different | ||
// GPIOs to connect to. | ||
using Cs = GpioOutputA4; | ||
using Mosi = GpioOutputB5; | ||
using Miso = GpioInputB4; | ||
using Sck = GpioOutputB3; | ||
using Int = GpioInputC7; | ||
using SpiMaster = SpiMaster1; | ||
// Note that you can also use a bit-banged SPI driver as a drop-in replacement | ||
// using SpiMaster = BitBangSpiMaster<Sck, Mosi, Miso>; | ||
|
||
// Default filters to receive any extended CAN frame | ||
FLASH_STORAGE(uint8_t canFilter[]) = { | ||
MCP2515_FILTER_EXTENDED(0), // Filter 0 | ||
MCP2515_FILTER_EXTENDED(0), // Filter 1 | ||
|
||
MCP2515_FILTER(0), // Filter 2 | ||
MCP2515_FILTER(0), // Filter 3 | ||
MCP2515_FILTER(0), // Filter 4 | ||
MCP2515_FILTER(0), // Filter 5 | ||
|
||
MCP2515_MASK_EXTENDED(0), // Mask 0 | ||
MCP2515_MASK(0), // Mask 1 | ||
}; | ||
|
||
modm::Mcp2515<SpiMaster, Cs, Int> mcp2515; | ||
|
||
class CanThread : modm::pt::Protothread | ||
{ | ||
public: | ||
CanThread() : | ||
message_{}, | ||
wait_{1s}, | ||
i{0}, | ||
j{0} | ||
{} | ||
|
||
bool | ||
run() | ||
{ | ||
PT_BEGIN(); | ||
|
||
MODM_LOG_INFO << "Initializing mcp2515 ..." << modm::endl; | ||
// Configure MCP2515 | ||
while (!mcp2515.initialize<8_MHz, 500_kbps>()){ | ||
PT_WAIT_UNTIL(wait_.isExpired()); | ||
wait_.restart(); | ||
} | ||
/// Set filters of MCP2515 | ||
MODM_LOG_INFO << "Setting filters of mcp2515 ..." << modm::endl; | ||
mcp2515.setFilter(modm::accessor::asFlash(canFilter)); | ||
MODM_LOG_INFO << "Running ... " << modm::endl; | ||
while (true) | ||
{ | ||
// receive messages | ||
if (mcp2515.isMessageAvailable()) | ||
{ | ||
MODM_LOG_INFO << "Message Available ... " << modm::endl; | ||
mcp2515.getMessage(message_); | ||
MODM_LOG_INFO << "Received message: " << modm::hex << message_.identifier << modm::endl; | ||
for(i = 0; i < message_.length; ++i){ | ||
MODM_LOG_INFO << modm::hex<< " 0x" << message_.data[i]; | ||
} | ||
MODM_LOG_INFO << modm::endl; | ||
MODM_LOG_INFO << modm::endl; | ||
} | ||
|
||
if(wait_.isExpired()) | ||
{ | ||
wait_.restart(1000ms); | ||
message_.identifier = 0xAA; | ||
message_.length = 2; | ||
message_.data[0] = 13; | ||
message_.data[1] = 37; | ||
MODM_LOG_INFO << "Sending Message ... "<< modm::endl; | ||
for(j = 0; j < message_.length; ++j){ | ||
MODM_LOG_INFO << modm::hex<< " 0x" << message_.data[j]; | ||
} | ||
MODM_LOG_INFO << modm::endl; | ||
MODM_LOG_INFO << "Success: " << mcp2515.sendMessage(message_) << modm::endl; | ||
} | ||
|
||
/// process internal mcp2515 queues | ||
PT_CALL(mcp2515.update()); | ||
PT_YIELD(); | ||
} | ||
|
||
PT_END(); | ||
} | ||
|
||
private: | ||
modm::can::Message message_; | ||
modm::ShortTimeout wait_; | ||
uint8_t i, j; | ||
}; | ||
|
||
CanThread canThread; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
MODM_LOG_INFO << "Mcp2515 Example" << modm::endl; | ||
// Initialize SPI interface and the other pins | ||
// needed by the MCP2515 | ||
SpiMaster::connect<Miso::Miso, Mosi::Mosi, Sck::Sck>(); | ||
/// we initialize a higher baud rate then n the avr example, dunnow hats the mcp2515 is capable | ||
/// of | ||
SpiMaster::initialize<Board::SystemClock, 10_MHz>(); | ||
Cs::setOutput(); | ||
Int::setInput(Gpio::InputType::PullUp); | ||
|
||
while (true) { | ||
canThread.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<library> | ||
<extends>modm:nucleo-f439zi</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo-f439zi/mcp2515</option> | ||
<option name="modm:driver:mcp2515:buffer.tx">32</option> | ||
<option name="modm:driver:mcp2515:buffer.rx">32</option> | ||
</options> | ||
<modules> | ||
<module>modm:platform:spi:1</module> | ||
<module>modm:build:scons</module> | ||
<module>modm:processing:protothread</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:driver:mcp2515</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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...