-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
qapi_Timer_Sleep() does not work with other units than TICK #2
Comments
I did encounter this problem as well and will look into it, once I'm back home. PS: There is now a debug/trace header in utils that allows for printf like traces but prepends the module (and one i figured it out the time). |
Do you use GCC or ARM ? |
Will try to change the last argument to false. I use GCC |
How did you reverse engineer the .lib files? |
I used Cutter which is a gui for radare2. EDIT: One thing to note is that unlike all other functions, the sleep api seems to swap parameter positions 1. gets second and 2. gets first. But I tried it the other way and it doesn't work either. |
It seems like UNIT_TICK is working, a tick is just extremly short.
Resulted in a delay of about 1s between both prints. I tried smaller values and it seems to scale and be constant. EDIT: if the last param is true it does not return. |
It could be a solution, but it gives a max delay of 3.58 min, which is not that long. Sleep with UNIT_USEC seems to run over and return, I know because I waited for over an hour and it returned. uint32_t max = 4294967295 and with 1000000 usec every sec gives a overrun time of 71.6min. |
If the delay would be larger than say 2 minutes one could just divide by 2 minutes and way multiple times. |
Note that the 19200081 is a guess based on output, but I think it is good enough since you won't be able to do really accurate timing anyway. |
I agree, it should be good enough. |
However I still think there might be a bug in my code, since I have an app that uses the original lib together with armcc and there is |
I just tested by creating a second thread and setting it to sleep there, it does not make a differens. |
I wrote a small example for timers and it seems to me the problem is not with stop. It looks like the timing of qapi_Timer_Sleep changes once you start a timer 😒 However the call to qapi_Timer_Stop worked fine and the callback was no more called after it. |
I have done som digging, |
tx_thread_sleep seems to work (at least it did in all cases I used it so far) but I'm not sure if TX_TIMER_TICKS_PER_SECOND is really 100 in this case. I used it in example 03-gpio and it seemed more like its defined to a value in the neighbourhood of 60. |
So after my first attempt to calculate a valid time using UNIT_TICK did not work and all units seem to somehow depend on the system state I decided to emulate them using a timer, which as far as I know seems to work fine. This, however, comes with some implications:
You can check it out here: d631fcb Thus requesting UNIT_USEC or UNIT_MSEC with a timeout of less than 10 will just return ERR_NOT_SUPPORTED. |
The reason why a delay smaller than 10 is not supported is because the OS simply cannot by definition create a delay smaller than the tick smaller than the tick size (because it's software timers.). I do not think it's your implementation of the libs. The problem must be that the hardware timer has not been init. |
Na I don't think so, In fact, I assume qapi_Timer is backed by a hardware timer of some sort because the real limit was about 5ms, but the problem is that using a timer + event flags means that there will be calls to the scheduler which makes anything below a certain time helplessly inaccurate.
If there is one, I don't have the slightest idea how to do so. Even if a timer is running sleeps based on tick are totally unpredictable. The same program that had a sleep time of 103 seconds this week took only 98s, so maybe it depends on how the stars are aligned? Everything with more than 10ms is now backed by a timer and is quite accurate (+/- ~2ms). |
I'm not sure anymore if my implementation is really correct because I have a simple gpio example that works fine with armcc but not with gcc. |
Seems like this is not the end of the story: |
First of all, thank you for your amazing work!
The issue:
When I try to use the qapi_Timer_Sleep function from the qapi_timer.h, the module never comes back if I use other time units than QAPI_TIMER_UNIT_TICK.
Here is my code (That does not work unless I use the QAPI_TIMER_UNIT_TICK):
The text was updated successfully, but these errors were encountered: