-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Solution for mutex problem in CAN read ISR #14688
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
033b08d
Implementation for can_read to be deferred to thread context when rx
MubeenHCLite 1a2d624
Added Raw CAN (unlocked can read api) and updated the code for the
MubeenHCLite 5d861f8
Merge branch 'master' into CAN_rxinterrupt_fix
MubeenHCLite 3565ae3
Removed the new line at the end of file.
MubeenHCLite 7a4a4ea
Added a newline at the end of RawCAN.cpp
MubeenHCLite debfda6
Updated the Licenses for RawCAN and aligned indentation
MubeenHCLite d4eba5c
Resolving the astyle error
MubeenHCLite 8622f66
Resolved review comments
MubeenHCLite ff01046
Spell check corrected
MubeenHCLite 65a72c2
Added documentation for the implementation
MubeenHCLite 27df8c7
Indentation set for the comments
MubeenHCLite d477efe
Corrected the conditional compilation of RawCAN.
MubeenHCLite 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,94 @@ | ||
/* | ||
* Copyright (C) 2021, STMicroelectronics, All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef RAWCAN_H | ||
#define RAWCAN_H | ||
|
||
#include "platform/platform.h" | ||
#include "drivers/CAN.h" | ||
|
||
#if DEVICE_CAN || defined(DOXYGEN_ONLY) | ||
|
||
#include "interfaces/InterfaceCAN.h" | ||
#include "hal/can_api.h" | ||
#include "platform/Callback.h" | ||
#include "platform/PlatformMutex.h" | ||
|
||
namespace mbed { | ||
#ifndef FEATURE_EXPERIMENTAL_API | ||
class RawCAN: public CAN { | ||
public: | ||
/** Creates an unlocked CAN interface connected to specific pins. | ||
* | ||
* @param rd read from transmitter | ||
* @param td transmit to transmitter | ||
* | ||
* Example: | ||
* @code | ||
* #include "mbed.h" | ||
* | ||
* | ||
* Ticker ticker; | ||
* DigitalOut led1(LED1); | ||
* DigitalOut led2(LED2); | ||
* //The constructor takes in RX, and TX pin respectively. | ||
* //These pins, for this example, are defined in mbed_app.json | ||
* RawCAN can1(MBED_CONF_APP_CAN1_RD, MBED_CONF_APP_CAN1_TD); | ||
* RawCAN can2(MBED_CONF_APP_CAN2_RD, MBED_CONF_APP_CAN2_TD); | ||
* | ||
* unsigned char counter = 0; | ||
* | ||
* void send() { | ||
* if(can1.write(CANMessage(1337U, &counter, 1))) { | ||
* printf("Message sent: %d\n", counter); | ||
* counter++; | ||
* } | ||
* led1 = !led1; | ||
* } | ||
* | ||
* int main() { | ||
* ticker.attach(&send, 1); | ||
* CANMessage msg; | ||
* while(1) { | ||
* if(can2.read(msg)) { | ||
* printf("Message received: %d\n\n", msg.data[0]); | ||
* led2 = !led2; | ||
* } | ||
* ThisThread::sleep_for(200); | ||
* } | ||
* } | ||
* | ||
* @endcode | ||
*/ | ||
|
||
/* Note: The can apis are unlocked hence using this when multiple | ||
* threads are accessing a single instance of CAN will lead to | ||
* race conditions, can be used in single threaded CAN. | ||
*/ | ||
using CAN::CAN; | ||
|
||
|
||
// override lock apis to create unlocked CAN | ||
void lock() override {}; | ||
void unlock() override {}; | ||
|
||
}; | ||
#endif //FEATURE_EXPERIMENTAL_API | ||
} | ||
|
||
#endif | ||
#endif //RAWCAN_H |
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
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 |
---|---|---|
|
@@ -155,6 +155,7 @@ struct can_s { | |
CAN_HandleTypeDef CanHandle; | ||
int index; | ||
int hz; | ||
int rxIrqEnabled; | ||
}; | ||
#endif | ||
|
||
|
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 |
---|---|---|
|
@@ -145,6 +145,7 @@ struct can_s { | |
CAN_HandleTypeDef CanHandle; | ||
int index; | ||
int hz; | ||
int rxIrqEnabled; | ||
}; | ||
#endif | ||
|
||
|
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 |
---|---|---|
|
@@ -154,6 +154,7 @@ struct can_s { | |
CAN_HandleTypeDef CanHandle; | ||
int index; | ||
int hz; | ||
int rxIrqEnabled; | ||
}; | ||
#endif | ||
|
||
|
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 |
---|---|---|
|
@@ -142,6 +142,7 @@ struct can_s { | |
CAN_HandleTypeDef CanHandle; | ||
int index; | ||
int hz; | ||
int rxIrqEnabled; | ||
}; | ||
#endif | ||
|
||
|
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 |
---|---|---|
|
@@ -157,6 +157,7 @@ struct can_s { | |
CAN_HandleTypeDef CanHandle; | ||
int index; | ||
int hz; | ||
int rxIrqEnabled; | ||
}; | ||
#endif | ||
|
||
|
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 |
---|---|---|
|
@@ -166,6 +166,7 @@ struct can_s { | |
CAN_HandleTypeDef CanHandle; | ||
int index; | ||
int hz; | ||
int rxIrqEnabled; | ||
}; | ||
#endif | ||
|
||
|
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 |
---|---|---|
|
@@ -156,6 +156,7 @@ struct can_s { | |
CAN_HandleTypeDef CanHandle; | ||
int index; | ||
int hz; | ||
int rxIrqEnabled; | ||
}; | ||
#endif | ||
|
||
|
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 |
---|---|---|
|
@@ -156,6 +156,7 @@ struct can_s { | |
CAN_HandleTypeDef CanHandle; | ||
int index; | ||
int hz; | ||
int rxIrqEnabled; | ||
}; | ||
#endif | ||
|
||
|
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
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.
Do we believe this is race clear? If new data has already arrived before this line, will this generate an interrupt?
Hopefully this is solid, but it's possible you may have to do
to make sure the thing is ready to generate interrupts as the FIFO is released. I don't know if it's worth doing that just in case.