-
Notifications
You must be signed in to change notification settings - Fork 133
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
[#169] STM32: make UART thread safe #27
base: master
Are you sure you want to change the base?
Conversation
if(value == -1) | ||
{ | ||
Logger.LogAs(this, LogLevel.Debug, "Client disconnected, stream closed."); | ||
writerCancellationToken.Cancel(); | ||
break; | ||
} | ||
|
||
var dataReceived = DataReceived; |
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.
FYI:
I changed the order, otherwise the value -1 would be used as dataReceived!
receiveFifo.Enqueue(value); | ||
readFifoNotEmpty.Value = true; | ||
Update(); | ||
lock (receiveFifo) |
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.
FYI: The queue was used in two threads but never locked. This led to crashes.
(transmitDataRegisterEmptyInterruptEnabled.Value) || // TXE is assumed to be true | ||
(transmissionCompleteInterruptEnabled.Value && transmissionComplete.Value) | ||
); | ||
machine.ClockSource.ExecuteInLock(() => |
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 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.
@Viatorus Sorry, How do you generate this figure? Could you please tell me the name of the tool?
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 a debug tool from Rider: https://www.jetbrains.com/help/rider/Debugging_Multithreaded_Applications.html#parallel-stacks
.WithFlag(5, out readFifoNotEmpty, FieldMode.Read | FieldMode.WriteZeroToClear, name: "RXNE") // as these two flags are WZTC, we cannot just calculate their results | ||
.WithFlag(5, FieldMode.Read | FieldMode.WriteZeroToClear, name: "RXNE", valueProviderCallback: _ => | ||
{ | ||
return readFifoNotEmpty; |
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.
FYI:
This workaround I don't understand my self but otherwise, it is not working.
if readFifoNotEmpty is a IFlagRegisterField, it happens that the machine does not see the change and the application stucks.
If we put inside the callback function, this is not happening anymore.
|
||
machine.ClockSource.ExecuteInLock(() => | ||
{ | ||
if (receiverNotEmptyInterruptEnabled.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.
FYI:
So there is the case, that the machine is not yet done with the last interrupt handling:
receiverNotEmptyInterruptEnabled is not yet set to true but transmissionCompleteInterruptEnabled and transmissionComplete are so the Update() method would wrongly set IRQ to true again.
If this happens, the IRQ hangs somehow.
Overall I am not a fan of updating the IRQ from a different thread than the machine thread.
renode/renode#169