I’m trying to use BlackBox
, but I’m having a hard time getting things to work
in the way I want.
What I wanna do is have the Clash generated Verilog instantiate into my
BlackBox’d Verilog module.
First, my verilog file. I checked that this compiles / has valid syntax using
Verilator. Didn’t really check to see if it works:
module counter(input CLK, input RST, input EN, output [15:0] DATA);
reg [15:0] iDATA;
initial iDATA = 0;
assign DATA = iDATA;
always @(posedge CLK)
begin
if (RST)
iDATA <= 0;
else if (EN)
begin
iDATA <= iDATA + 1;
end
end
endmodule
Next, my clash file:
import Clash.Prelude
import Clash.Annotations.Primitive
{-# ANN counter (Primitive [Verilog] "C:/path/to/my/verilog/counter.v") #-}
{-# ANN counter hasBlackBox #-}
{-# NOINLINE counter #-}
counter :: Clock System
-> Reset System
-> Enable System
-> Signal System (Unsigned 16)
counter = undefined
top :: Clock System
-> Reset System
-> Enable System
-> Signal System (Unsigned 16)
top = counter
{-# ANN top
(Synthesize
{ t_name = "myCounter"
, t_inputs = [ PortName "CLK"
, PortName "RST"
, PortName "EN"
]
, t_output = PortName "DATA"
}) #-}
When I call clash, I get an error:
GHC: Setting up GHC took: 2.285s
GHC: Compiling and loading modules took: 0.192s
<no location info>: error:
Clash error call:
No BlackBox definition for '<MODULE>.counter' even though thi
s value was annotated with 'HasBlackBox'.
CallStack (from HasCallStack):
error, called at src\Clash\Primitives\Util.hs:150:11 in clash-lib-1.8.1-
JBnXUEN9hOK2TSlskJFs4:Clash.Primitives.Util
If I remove the hasBlackBox
annotation, clash generates Verilog. But the
Verilog doesn’t do what I expect.
/* AUTOMATICALLY GENERATED VERILOG-2001 SOURCE CODE.
** GENERATED BY CLASH 1.8.1. DO NOT MODIFY.
*/
`default_nettype none
`timescale 100fs/100fs
module myCounter
( // Inputs
input wire CLK // clock
, input wire RST // reset
, input wire EN // enable
// Outputs
, output wire [15:0] DATA
);
<MODULE>_top_counter <MODULE>_top_counter_DATA
( .result (DATA)
, .c$arg (CLK)
, .c$arg_0 (RST)
, .c$arg_1 (EN) );
endmodule
I’d like the generated verilog to be:
module myCounter
( // Inputs
input wire CLK // clock
, input wire RST // reset
, input wire EN // enable
// Outputs
, output wire [15:0] DATA
);
counter <MODULE>_top_counter_DATA
( .DATA (DATA)
, .CLK (CLK)
, .RST (RST)
, .EN (EN) );
endmodule
Any ideas? My guess is that I’m not providing the path to BlackBox in the right
way.