Create src/lib
This commit is contained in:
parent
4cb229e472
commit
d3823b9455
11 changed files with 5 additions and 2 deletions
45
src/timer.ml
45
src/timer.ml
|
@ -1,45 +0,0 @@
|
|||
(**
|
||||
* Copyright (c) 2016, Fabien Freling
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD 2-clause license found in the
|
||||
* LICENSE file at the top level directory of this source tree.
|
||||
*)
|
||||
|
||||
let frequence = 4194304
|
||||
|
||||
type t = {
|
||||
clock_rate : int;
|
||||
period : int;
|
||||
mutable enabled : bool;
|
||||
mutable cycles_left : int;
|
||||
}
|
||||
|
||||
let create clock_rate enabled =
|
||||
let period = frequence / clock_rate in
|
||||
{
|
||||
clock_rate;
|
||||
period;
|
||||
enabled;
|
||||
cycles_left = period;
|
||||
}
|
||||
|
||||
(** TIMA - Timer counter *)
|
||||
let create_tima tac =
|
||||
let enabled = Bit.is_set tac 2 in
|
||||
let clock_select = tac land 0b00000011 in
|
||||
let clock_rate = match clock_select with
|
||||
| 0 -> 4096
|
||||
| 1 -> 262144
|
||||
| 2 -> 65536
|
||||
| 3 -> 16384
|
||||
| _ -> failwith "Unreachable clock rate code."
|
||||
in
|
||||
create clock_rate enabled
|
||||
|
||||
let update timer cycles =
|
||||
let remain = timer.cycles_left - cycles in
|
||||
let should_inc = remain <= 0 in
|
||||
if should_inc then
|
||||
timer.cycles_left <- remain + timer.period;
|
||||
should_inc
|
Loading…
Add table
Add a link
Reference in a new issue