-
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
UARTSerial: Free resources #10843
UARTSerial: Free resources #10843
Conversation
@ghseb, thank you for your changes. |
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.
I like the concept, but this is potentially problematic from backwards compatibility because we've never called serial_free
before (I think). I don't know how good HAL implementations are.
We would need a specific Greentea test to exercise this in hardware.
I'm also not happy with complexity here for being inside a critical section. If init calls can happen inside |
How could a test look like? As far as I know the only default UART is used by greentea itself. |
Indeed. I know there is some work being done on HAL testing with special loopback adapter boards, but I don't what the state of serial is with respect to that. Actually, it's probably very rare to destroy a |
drivers/SerialBase.cpp
Outdated
@@ -161,6 +153,26 @@ void SerialBase:: unlock() | |||
// Stub | |||
} | |||
|
|||
void SerialBase::init(void) | |||
{ | |||
lock(); |
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.
Just to save a little ROM, I think I'd leave the locks out here. They're not needed in the constructor and destructor, and UARTSerial
has them dummied anyway.
If you're going to be calling init
or deinit
you need more sequencing than just the basic lock
anyway - imagine if someone just decided to do some more serial stuff after deinit
did its unlock
!
(Maybe stick a _
in front of the method name to give a clue that they're unlocked methods. Some things use that convention, not sure if the serial stuff does).
Let me know if that doesn't make sense to you - I'm not quite 100% confident.
Another thought - with this logic, it may be worth putting a base It could do it by enabling/disabling interrupts from the HAL layer with That would in turn allow testing of the |
I wanted to keep the change as small as possible. For the use-case of avoiding current drain when Putting the whole or a part of the implementation into |
Yes, it would be a bigger change, but it would extend the logic nicely. The rx_enabled/tx_disabled would go into the SerialBase, because it would be implementing those calls. The knowledge of interrupt enable vs buffer level comes in via SerialBase making the attach calls, which is then reflected in the A disable input would turn off the HAL interrupt. An enable input would re-enable the HAL interrupt if the corresponding The logic gets more complex in SerialBase, but simpler in UARTSerial, as it doesn't need to care whether rx or tx is enabled any more - it just attaches or deattaches the interrupt based on buffer level, and whether those interrupts happen or not depend on the enable in the serial base. |
I dont know if i got everything you mentioned, but i try to propose another solution next week. |
@ghseb Any update? |
Closing in favor of #10924 |
Description
If output and input is disabled for
UARTSerial
the pins should be reconfigured to archive lowest power consumption (e.g. to avoid current drain through TX pin).With this change the UART interface is switched off if both input and output is disabled. If input or output is enabled again the UART pins are reinitialized.
Pull request type
Reviewers
Release Notes