-
-
Notifications
You must be signed in to change notification settings - Fork 725
Port some AVR Serial_ (SerialUSB) API's over #65
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
Conversation
Just had a quick look over this commit, which looks good. Just one atomicity issue to fix. |
@matthijskooijman I've address the atomicity issue by disabling and re-enabling USB interrupts in Again as mentioned in arduino/Arduino#4171 (comment), any ideas on how to test this condition? |
@sandeepmistry, two more remarks:
As for testing this, one trick is to put a delay between the read and write of To test, you could send a "break on" immediately followed by a "break off" and repeat that over and over again (with a bit of delay in between, so you can be sure that |
@matthijskooijman thanks for reviewing and the tips on how to test! I've addressed your feedback in sandeepmistry@d848264, by taking a similar approach to |
@sandeepmistry, I actually think this change makes things worse (also, I think the implementation of |
@matthijskooijman good points, I think It only calls |
Yup, that is indeed to solution I was aiming for. I'm not sure if it's worthwile to only disable the USB interrupt, or disable interrupts globally, though. The latter is safer, but only in corner cases that will probably never occur, and causes extra interrupt delay in other cases. But since the delay is minimal, I think I'd favor the global disabling. On another note, never knew about the |
Oh, just noticed that that function is defined by SPI.cpp itself: https://github.com/sandeepmistry/ArduinoCore-samd/blob/master/libraries/SPI/SPI.cpp#L85-L93 |
I'll move |
Note that |
Another changed pushed, I've decided to use |
That sounds good to me. I dug in a little more (to verify that "PRIMASK" is really the same bit as the one modified by
In other words, Also note that the above code limits to just looking at bit 0 and masks out the rest, while the current commit (and SPI code) look at all bits. According to the documentation all bits but 0 are reserved, so this is probably not a problem in practice, but masking would be appropriate. |
It turns out Instead the one from /** \brief Disable IRQ Interrupts
This function disables IRQ interrupts by setting the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
{
__ASM volatile ("cpsid i" : : : "memory");
}
I've updated to mask. |
Here's a link to the relevant M0 documentation for my comment above: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/BABEDCBC.html
Agreed, I've pushed changes for this. |
Ah, good point. I just looked at the first one I found using grep :-) The code looks good now. Before merging, it would probably be good to squash all commits into one? Also, it might be good to let |
18efa35
to
3ea315a
Compare
Done, I've squash and rebased.
I'll open a new PR for this today. |
Looks good to me! |
Port over the following
Serial_
API's over from the AVR core to SAMD:readBreak
baud
stopbits
paritytype
numbits
dtr
rts
That were added to AVR in the following commits:
cc/ @matthijskooijman