now converted clock divider
This commit is contained in:
parent
b1c14f5aba
commit
1209f6a700
2 changed files with 41 additions and 0 deletions
40
old_src/ClkDivider.bs
Normal file
40
old_src/ClkDivider.bs
Normal file
|
@ -0,0 +1,40 @@
|
|||
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)
|
Reference in a new issue