-
Notifications
You must be signed in to change notification settings - Fork 521
Actioned Issue 89 as feature/serial2 #181
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
…ll test RX when I've had some sleep. Some refactoring and variable name improvements are no doubt needed. Too much pointer dereferencing going on, too. It’s a work in progress, still.
…ware into feature/serial2
…ve code readibality.
…s (4 x 32bit words) of binary code. :-/ Oh well. It's more consistent with the rest of the code, now.
Added ::end method code to undo pin re-mapping.
Will submit pull request.
Hi @gruvin Looks great! One very tiny point: I just wanted to make sure you knew there is a makefile target |
Build script? Oh crap! -- I just attempted to analyse the cost in Flash and RAM for my changes. Have added those notes to |
EDIT: This comment can be ignored. The test mentioned in next comment invalidates this one, entirely. Just realised that I'm dereferencing an additional level of pointers to rx/tx_buffer, using that _UMAP macro, in many places. This may account for quite a lot of extra machine instructions. Perhaps I should return to my earlier version, of storing a pointer to the appropriate USART_MAP array, like it was at d31730c. Example: I was using I think in the second (and present code) case, there's extra instructions required to dereference USART_MAP[...]. Since this appears in quite a number of locations throughout the code, I believe it may be unnecessarily consuming signifiant code space. Comments anyone? If I get time tomorrow, I'll do a bunch of search/replaces in vim to test this theory. If it turns out I am right, then I suppose a regression to the pointer version would also get rid of the extra code readability issue, with the _UMAP macro, which couldn't hurt -- the irony being that the _UMAP macro etc was intended to save code space, actually. But I think I got it backwards. :-P |
I tested the above just now IE. reverted to use of pointers instead of USART_MAP[usartNum] array dereferencing. To my surprise, the final Flash size came out identical, to the byte. So I suppose the compiler's optimization is taking care of coding styles for me. So, I think this is as optimal as I can get it. Pull request stands as-is, then. Thanks. |
Great, thanks @gruvin. I look forward to reviewing this. With a little luck I'll get to it today or tomorrow. |
I'm reviewing this now @gruvin — if my tests continue to go well I would like to merge it in before I tag v0.2.2 (like, in the next couple hours) — but I just noticed you haven't signed the CLA. It's here: https://docs.google.com/a/spark.io/forms/d/1_2P-vRKGUFg5bmpcKLHO_qNZWGi5HKYnfrrkd-sbZoA/viewform I realize it's 5:45 a.m. in New Zealand, so this might end up waiting until after Maker Faire to get merged in. Sorry I didn't think to check the list of signers until now. In any case, comment here in the PR when you've signed. Thanks! |
Also, I like the idea of not instantiating Serial2 by default, since RAM optimization is moving quickly up the priority list. |
Sweet. Yes. Thank you. This looks great. Please make two changes for me:
It's OK for now to do require users to instantiate with |
This might be a n00b suggestion, but just in case - would it be possible to have |
Absolutely possible. It doesn't fit with the naming of the rest of our file naming scheme—more consistent would be |
good point. I think in this case it’s worth diverging. We might also want to split libraries that aren’t included by default in a separate folder within the file structure, not unlike what Arduino does: https://github.com/arduino/Arduino/tree/master/hardware/arduino/cores/arduino That will make it easy for someone to discover the libraries that could be included through #include. This could also be an opportunity for RAM optimization for us (taking things that are currently always built in and pulling them out, requiring that they be included first) On May 8, 2014 at 1:24:41 PM, Zachary Crockett (notifications@github.com) wrote: Absolutely possible. It doesn't fit with the naming of the rest of our file naming scheme—more consistent would be spark_wiring_serial2.h, but that's obviously less intuitive for users. — |
Hear, hear! @gruvin you have your task!
|
OK, got all that. So an include file to instantiate Serial2 and the other housework ... and after Maker Faire. (Rome wasn't built in a day.) Thanks. :-) Oh and, I just signed the agreement. |
Alas, I wasn't able to get to this before moving house (presently in progress) due to a melt down of a business server and the work that required. Might be another couple weeks. |
I've run into a bit of a snag. I wanted to have unneeded code excluded for the case when The only way forward then, given how I've implemented Serial2 by sharing the existing Serial driver class (most efficient method overall, I think) is to simply accept the additional overhead. :-/ Other data could have been saved, including the second record in the USART_Info array. These two items amount to only a hand full of wasted 32-bit data words. But it irks me, none the less. Ordinarily, an unused C function would be excluded from the final output by the linker. But the interrupt function (ISR) is a special case. It will be included, even if it's not used, because its tied to an ISR vector. Luckily, all that function does is call the larger, 'real' ISR routine, passing in a single pointer. So not a lot of code. But still a little frustrating, not being able to remove it entirely (due to the approach I took earlier, pretty much.) In any case, I will proceed as originally planned -- that being to keep what we have now and to simply separate instantiation of Serial2 off into its own |
…ries/Serial2/Serial2.h. Edited build/makefile accordingly. Have left simple test code in application.cpp for now. Will address this and the documentation requrests in Issue 89 later (soon, hopefully).
Code size, as things stand right now ... Without
With
|
Oh dear. There seems to be a mix of |
Another possible problem I just realised: The ISR function It looks OK to me ... but I'm very tired. Can I get a second opinion? |
Are interrupts reenabled ? If not then, I don't think reentrancy is an
|
…rial2/Serial2.h + Reverted to tidier pointer (usartMap) instead of _UMAP macro. + Tidied up comments. + Physical testing OK. + Removed test code from src/application.cpp.
@andyw-lala -- Thanks for that. I will add a comment, in case someone maybe wants to add static variables or something to the ISR some day, which would be one example of what could seriously break the shared function. |
…ding to remain reentrance compliant.
Right. That last Now I can go figure out how to edit Spark documentation. Any hints on that score welcomed! :-P |
Documentation pull request submitted: particle-iot/docs#160 This should mean we are ready to merge and roll. |
OK. Now we should be ready to merge and roll (after a final test by @towynlin, of course. I need to get better organised or something. :-P |
Increase commissioner's inactivity timeout
This implements a second USART serial port on pins D1(TX) and (D0)RX.
Please see Issue 89 comments, in additional to prepended notes in README.md for further details.