now converted clock divider

This commit is contained in:
Yehowshua Immanuel 2023-09-25 02:45:27 -04:00
parent b1c14f5aba
commit 1209f6a700
2 changed files with 41 additions and 0 deletions

View file

@ -1,40 +0,0 @@
package ClkDivider(mkClkDivider, ClkDivider(..)) where
interface (ClkDivider :: # -> *) hi =
{
reset :: Action
;isAdvancing :: Bool
;isHalfCycle :: Bool
}
mkClkDivider :: Handle -> Module (ClkDivider hi)
mkClkDivider fileHandle = do
counter <- mkReg(0 :: UInt (TLog hi))
let hi_value :: UInt (TLog hi) = (fromInteger $ valueOf hi)
let half_hi_value :: UInt (TLog hi) = (fromInteger $ valueOf (TDiv hi 2))
let val :: Real = (fromInteger $ valueOf hi)
let msg = "Clock Div Period : " + (realToString val) + "\n"
hPutStr fileHandle msg
hPutStr fileHandle genModuleName
addRules $
rules
{-# ASSERT fire when enabled #-}
{-# ASSERT no implicit conditions #-}
"tick" : when True ==> action
$display (counter)
counter := if (counter == hi_value)
then 0
else counter + 1
return $
interface ClkDivider
reset :: Action
reset = do
counter := 0
isAdvancing :: Bool
isAdvancing = (counter == hi_value)
isHalfCycle = (counter == half_hi_value)

41
src/ClkDivider.bsv Normal file
View file

@ -0,0 +1,41 @@
package ClkDivider;
export mkClkDivider;
export ClkDivider(..);
interface ClkDivider#(numeric type hi);
method Action reset();
method Bool isAdvancing();
method Bool isHalfCycle();
endinterface
module mkClkDivider#(Handle fileHandle)(ClkDivider#(hi));
Reg#(UInt#(TLog#(hi))) counter <- mkReg(0);
UInt#(TLog#(hi)) hi_value = fromInteger(valueOf(hi));
UInt#(TLog#(hi)) half_hi_value = fromInteger(valueOf(TDiv#(hi, 2)));
Real val = fromInteger(valueOf(hi));
let msg = "Clock Div Period : " + realToString(val) + "\n";
hPutStr(fileHandle, msg);
hPutStr(fileHandle, genModuleName);
rule tick;
$display(counter);
counter <= (counter == hi_value) ? 0 : counter + 1;
endrule
method Action reset();
counter <= 0;
endmethod
method Bool isAdvancing();
return (counter == hi_value);
endmethod
method Bool isHalfCycle();
return (counter == half_hi_value);
endmethod
endmodule
endpackage