Using timing functions - page 7 - General Discussion and Assistance - CHDK Forum  

Using timing functions

  • 66 Replies
  • 25107 Views
Difference between msleep and HPTimer functions
« Reply #60 on: 12 / May / 2014, 03:45:57 »
Advertisements
Hi,

Sorry, may this is a stupid question.
If I want to create a certain delay what is the difference using msleep() and the (new) HPTimer functions like e.g. _SetHPTimerAfterTimeout()?

Thanks...
2 x IXUS 860IS 100c
2 x Powershot S110 103a

Re: Difference between msleep and HPTimer functions
« Reply #61 on: 12 / May / 2014, 09:01:04 »
@reyalp : please move this thread to http://chdk.setepontos.com/index.php?topic=11342.0

If I want to create a certain delay what is the difference using msleep() and the (new) HPTimer functions like e.g. _SetHPTimerAfterTimeout()?

msleep()
  • minimum delay interval = 10 msSec
  • delay resolution = 10 mSec
  • simple to use - just insert the call into code at appropriate point
  • safe to use - no know negative side effects

HPTimer
  • minimum delay interval < 1 mSec (minimum safe value unknown)
  • delay resolution = 1 uSec
  • complicated to use - requires setting up various parameters an a callback function
  • possible negative side effects if timer interval set too short ( < 1 msec)
  • other possible side effects not know - function has not been used a lot to date
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Difference between msleep and HPTimer functions
« Reply #62 on: 12 / May / 2014, 09:19:42 »
Hi waterwingz,

thanks that made it clear to me!

2 x IXUS 860IS 100c
2 x Powershot S110 103a

*

Offline reyalp

  • ******
  • 14080
Re: Using timing functions
« Reply #63 on: 12 / May / 2014, 15:59:53 »
Merged as requested.

To expand slightly on waterwingz response, msleep() yields the current task, telling the operating system to run other tasks until the time is up (how close the operating system gets to the requested delay isn't clear, though we could measure it with the high res counter discussed earlier)

The _SetHPTimerAfterTimeout() sets a callback that gets called from an interrupt handler. What you can do in interrupt handlers is generally very limited, and for a reverse engineered system like this, not well known.

In general, if you wanted to use _SetHPTimerAfterTimeout() as a short (<10ms) sleep, I think you would set the timer and then wait on something like a semaphore or eventflag, which the callback would trigger.
Don't forget what the H stands for.


Re: Using timing functions
« Reply #64 on: 13 / May / 2014, 03:38:07 »
Hi reyalp,

thanks, sorry I could not 100% understand what you wrote.

Quote
msleep() yields the current task

'Yealds' - What does it mean exactly? (an online translation into German did not give me adequate help).

Quote
I think you would set the timer and then wait on something like a semaphore or eventflag, which the callback would trigger.

Could you also make this a littlebit more clear to me? What is a semaphore and an eventflag? Is it something I have to program or does it exists and I use it?

Thanks a lot!
2 x IXUS 860IS 100c
2 x Powershot S110 103a

*

Offline reyalp

  • ******
  • 14080
Re: Using timing functions
« Reply #65 on: 13 / May / 2014, 17:12:47 »
'Yealds' - What does it mean exactly? (an online translation into German did not give me adequate help).
Note if you are searching, the correct spelling is "yield".

The camera OS is a multitasking OS like Windows or Linux.
Each "task" is similar to a process or thread on those operating systems. A bit more like a thread, since they share memory.
Only a single task can physically execute at a given time.
When a task yields, it means it stops executing and the OS can execute some other task.
CHDK runs in several different tasks: spytask is created specifically by CHDK, and we also run modified code in kbd_task, capt_seq_task and some others.

Quote
Could you also make this a littlebit more clear to me? What is a semaphore and an eventflag? Is it something I have to program or does it exists and I use it?
These are synchronization objects that exist in the Canon firmware. There are functions to use them in stubs_entry and the address list files. The recent FsIoNotify crash fixes in 1.3 uses a semaphore that already exists in the canon firmware.

Semaphores are a standard primitive used in many different systems, though the exact details may vary. See http://en.wikipedia.org/wiki/Semaphore_%28programming%29

Event flags is less standard terminology but  http://en.wikipedia.org/wiki/Event_flag should give you the right general idea. The stuff about specific bits etc doesn't apply to the camera OSes. Windows Event objects should be conceptually similar http://msdn.microsoft.com/en-us/library/windows/desktop/ms682655%28v=vs.85%29.aspx

To understand the exact details of how to use them on the camera OSes, you need to look at the firmware disassembly.
Don't forget what the H stands for.

Re: Using timing functions
« Reply #66 on: 14 / May / 2014, 02:15:22 »
Hi reyalp,

thanks for reply,

Quote
Yealds

Yes you are right, it was a syntax error just in the thread here - in the web search I used the correct one  :-[

The other stuff seems to blow my small brain  ;)

2 x IXUS 860IS 100c
2 x Powershot S110 103a

 

Related Topics