Skip to content
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

C HAL function to check Serial FIFO status #4408

Closed
bridadan opened this issue May 30, 2017 · 12 comments
Closed

C HAL function to check Serial FIFO status #4408

bridadan opened this issue May 30, 2017 · 12 comments

Comments

@bridadan
Copy link
Contributor

Description


Enhancement

Reason to enhance or problem with existing solution
When using the Serial API, most implementations take the to-be-transmitted data and place it in the UART hardware's FIFO. At this point the function returns, however there is no way to actually check via the mbed API whether this data has actually been transmitted "on the wire".

Suggested enhancement
It has been suggested in past discussions (#1849, #3132, #2966) to add a C HAL function that would allow applications to check if the FIFO buffer is empty. This would allow applications to ensure all data has been transmitted before doing certain actions that affect the serial hardware (eg. sleep/deepsleep).

Pros

  • Allows applications to delay until all data has been transmitted before moving on to other tasks.

Cons

  • Time intensive task of ensure all targets implement this function
  • Not all targets may support this functionality

FYI @LMESTM @0xc0170

@LMESTM
Copy link
Contributor

LMESTM commented May 30, 2017

@bridadan sounds good to me - problem is clearly exposed. Thx
[Mirrored to Jira]

@LMESTM
Copy link
Contributor

LMESTM commented Aug 16, 2017

@bridadan : any plan for adding the C API that is suggested here ?
[Mirrored to Jira]

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 16, 2017

@bridadan : any plan for adding the C API that is suggested here ?

It has been asked few times recently (due to reset of MCU and sleep). We will consider this while reviewing the current serial HAL API. I can't comment on any specific date at the moment. Thanks for bringing this up again.

cc @c1728p9 @bulislaw @scartmell-arm
[Mirrored to Jira]

LMESTM added a commit to LMESTM/mbed that referenced this issue Aug 7, 2018
As suggested by Russ Butler in mbed-os issue ARMmbed#7328, and until there is an
implementation of mbed-os issue ARMmbed#4408, we are implementing a workaround
at HAL level to check if there is any ongoing serial transfer (which happens
if HW FIFO is not yet empty).

In case a transfer is ongoing, we're not entering deep sleep and
return immediately.
adbridge pushed a commit that referenced this issue Aug 10, 2018
As suggested by Russ Butler in mbed-os issue #7328, and until there is an
implementation of mbed-os issue #4408, we are implementing a workaround
at HAL level to check if there is any ongoing serial transfer (which happens
if HW FIFO is not yet empty).

In case a transfer is ongoing, we're not entering deep sleep and
return immediately.
adbridge pushed a commit that referenced this issue Aug 13, 2018
As suggested by Russ Butler in mbed-os issue #7328, and until there is an
implementation of mbed-os issue #4408, we are implementing a workaround
at HAL level to check if there is any ongoing serial transfer (which happens
if HW FIFO is not yet empty).

In case a transfer is ongoing, we're not entering deep sleep and
return immediately.
pan- pushed a commit to pan-/mbed that referenced this issue Aug 22, 2018
As suggested by Russ Butler in mbed-os issue ARMmbed#7328, and until there is an
implementation of mbed-os issue ARMmbed#4408, we are implementing a workaround
at HAL level to check if there is any ongoing serial transfer (which happens
if HW FIFO is not yet empty).

In case a transfer is ongoing, we're not entering deep sleep and
return immediately.
@ARMmbed ARMmbed deleted a comment from ciarmcom Oct 2, 2018
@adbridge
Copy link
Contributor

adbridge commented Oct 4, 2018

Internal Jira reference: https://jira.arm.com/browse/IOTHAL-75

@daniel-maiorano
Copy link

Any news on this?

@amak-cy
Copy link

amak-cy commented Feb 20, 2019

Hello is there any updates here?

One additional question:
Whom responsibility is to provide HW readiness to enter or not into the Deep Sleep? mbed-os (hal) or application level?

I mean for example the UART has not empty TX buffer and all data in this buffer would be lost if we just enter Deep Sleep (without any additional actions).

@cmonr
Copy link
Contributor

cmonr commented Feb 20, 2019

Hmm... @ARMmbed/mbed-os-hal Any updates?

@kjbracey-arm might know as well.

@amak-cy
Copy link

amak-cy commented Feb 20, 2019

simple example

With enable MBED_TICKLESS we have the following code:

int main()
{
unsigned int i=0,m;
while (true) {
led1 = !led1;
printf("%d", ++i);
printf(" ");
if(!(i%10)) {
printf("\n");
}
wait(0.1f); // When this delay is commented the deep sleep is not entered and prints work fine
}
}

  1. When the wait(0.1) is in the code here the default idle hook function see that there is a lot of ticks and decides to put the CPU into Deep Sleep instead of Sleep. Then the buffer lost it data and there is nothing to print out after the the Deep Sleep.

  2. If we comment the wait(0.1) then the Deep Sleep is not entered and prints work just fine.

So how to avoid situation in #1? Should we update the hal_deepsleep not enter into the Deep Sleep if some HW indicated that it is not yet ready to enter into Deep Sleep.

More over, it looks like that greentea tests do not support such graceful low power transitions.
If the UART buffer is not empty before Deep Sleep and for this reason we did not have a Deep Sleep the "deep-sleep - high-speed clocks are turned off" case fails. As the test do not expect to have a kind of valid rejection of putting the CPU into Deep Sleep.

I think the following should discussed in a separate thread but lets start from here
We found one more interesting thing in sleep greentea tests -
SERIAL_FLUSH_TIME_MS 20 - this define considers that all FIFO buffers are 16 bits?
16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to 40 * 20ms here for safe.

What if we have 128 bits wide buffer?
For this buffer we need to have SERIAL_FLUSH_TIME_MS -> 150:
128 * 10 * 1000 / 9600 = 133.3 ms

Can I get a justification about the 20 ms for SERIAL_FLUSH_TIME_MS define?

I think it is too much here, but let it be the starting point of discussion. Will continue in whatever thread you tell me to jump.

@donatieng
Copy link
Contributor

Hello, We're planning to improve the UART HAL APIs - this is something we've flagged and take into account.

@amak-cy Currently drivers can prevent the MCU to go into deep sleep.

@kjbracey
Copy link
Contributor

Related issue: #9770

@amak-cy
Copy link

amak-cy commented Jul 19, 2019

Hello

Any updates on this request?

@ciarmcom
Copy link
Member

Thank you for raising this issue. Please note we have updated our policies and
now only defects should be raised directly in GitHub. Going forward questions and
enhancements will be considered in our forums, https://forums.mbed.com/ . If this
issue is still relevant please re-raise it there.
This GitHub issue will now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants