hardcaml-examples provides a small framework for creating HardCaml based cores and six example designs. The framework code provides the general plumbing required to create a console based application with features including code generation, simulation, and waveform viewing. A recent update extends the framework so that cores can be run on a webpage.
WebApp Examples
- Sorting networks
- Linear feedback shift registers
- Wallace and Dadda tree multipliers
- Prefix networks
- ROM-accumulator
- CORDIC
Plugging a design into the framework
A design compatible with the framework should implement the signature given in
HardCamlFramework.Framework.Design
.
module My_design = struct
let name = "design_name"
let desc = "design description (in markdown)"
(* configuration *)
module Hw_config = struct
include interface (* design parameters *) end
let params = (* default parameters *)
end
module Tb_config = struct
include interface (* testbench parameters *) end
let params = (* default parameters *)
end
let validate hw tb = (* parameter validation *)
(* design and testbench construction *)
module Make
(B : HardCaml.Comb.S)
(* user provided parameters *)
(H : Params with type 'a t = 'a Hw_config.t)
(T : Params with type 'a t = 'a Tb_config.t) = struct
module I = interface (* design inputs *) end
module O = interface (* design outputs *) end
let wave_cfg = (* configuration of waveform *)
let hw i = (* design construction *)
let tb sim i o n = (* testbench *)
end
end
A console application can be created as follows
module A = HardCamlFrameworkConsole.App.Make(MyDesign)
The application should be linked with the hardcaml-framework.console
ocamlfind
library. The following generic options will be available
option | description |
---|---|
-vlog |
generate verilog netlist |
-vhdl |
generate vhdl netlist |
-csim |
generate C simulation model |
-tb | run testbench |
-llvm | use LLVM backend to run testbench |
-vpi | use Icarus Verilog to run testbench |
-checktb | compare ocaml simulation with LLVM/VPI backend |
-interactive | interactive text driven testbench mode |
-vcd |
generate VCD file |
-waveterm | integrated waveform viewer |
-gtkwave | gtkwave waveform viewer |
The remaining options will configure design and testbench parameters.
Webapps
A web based application is created by building two bytecode applications
(linked with hardcaml-framework.js
) and compiling them with js_of_ocaml.
user interface (ie mydesign.js)
module A = HardCamlFrameworkJS.Appmain.Make(MyDesign)
webworker (mydesign_ww.js)
module A = HardCamlFrameworkJS.Appww.Make(MyDesign)
To include the application in a html page load the user interface in a script
tag and include a div with id hardcaml-framework-webapp
and a data attribute
called data-hcww
which points to the webworker javascript file. The webapp will
create itself within the div.
<div data-hcww="mydesign_ww.js" id="hardcaml-framework-webapp"></div>
<script type="text/javascript" src="mydesign.js"></script>