HPET: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
added some theory
m fix formatting
Line 51:
==HPET - timer vs comparators==
 
There is just one up counting main counter in the timer, but interrupt generation is handled by *comparators*. There's from 3 to 256 comparators, and the exact amount is indicated by <code>comparator_count</code> field in the above <code>hpet</code> structure. Keep in mind you have to initialize both the main counter and all of the comparators. Also, the routing as well as **'''allowed**''' routing of comparator interrupts is independent, so you have to detect and set it up for each of them individually. More information on this procedure is provided further in the text.
 
==HPET operating modes==
Line 61:
In non-periodic mode, the OS programs one of timer's comparator registers with value of main counter that is to trigger an interrupt. If the timer is set to 32 bit mode, it will also generate an interrupt when the counter wraps around. The comparator register's value is never written by the hardware, you are free to write to it and read from it at any time, therefore you can change at what value in the main counter the interrupt will be generated.
 
Every comparator in HPET **'''must support**''' non-periodic mode.
 
===Periodic mode===
 
Periodic mode is more tricky than non-periodic mode. For periodic mode, similarly to one-shot mode, you write a value at which an interrupt shall be generated to the comparator's match register. When the interrupt is generated, however, the hardware will **'''increase the value ofin comparator's register by the last value written to it**'''! This is a consequence of HPET's main counter being up-counting.
 
So, if the main counter's value is 12345 when we set the timer up, and we write 12456 to comparator (i.e. the interrupt should trigger 111 time units from now), when the interrupt triggers, 12456 will be *''added*'' to the comparator register, so it will become 24912, which is 12456 time units from the first interrupt. There are two techniques to deal with this problem; they will both be described in later part of the article.
 
Comparators are **'''NOT required**''' to support this mode; you must detect this capability when initializing a comparator. More information on this is provided further in the article.
 
==See also==