Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

enabled clk1 clock dividing function

  • Loading branch information...
commit edff0521758462806821525c3ea14d871ae8d509 1 parent b047e3c
Sebastian Niller authored
View
3  Language/Copilot/Examples/ClockExamples.hs
@@ -10,10 +10,11 @@ clkTest :: Streams
clkTest = do
let x = varB "x"
let y = varB "y"
+ let z = varB "z"
let a = varW8 "a"
let b = varW8 "b"
x `clk` (period 3, phase 1)
y `clk` (period 4, phase 3)
a .= [0] ++ mux x (a + 2) a
b .= [1] ++ mux y (b + 2) b
- y `clk` (period 4, phase 3)
+ z `clk1` ("zclock", period 4, phase 3)
View
36 Language/Copilot/Libs/Clocks.hs
@@ -19,10 +19,10 @@
-- The phase must be less than the period.
module Language.Copilot.Libs.Clocks
- ( clk, period, phase
+ ( clk, clk1, period, phase
) where
-import Prelude (error, show)
+import Prelude (error, show, fromIntegral, String)
import qualified Prelude as P
import Data.List (replicate)
import Data.Int
@@ -55,20 +55,20 @@ clk v (Period per, Phase ph) =
else v .= ((replicate ph False)
P.++ (True : (replicate ((per - ph) - 1) False)) ++ v)
--- -- clk' generates a clock that counts n ticks by using a
--- -- 32 bit counter variable
--- clk' :: String -> Spec Bool -> (Period, Phase) -> Streams
--- clk' clockName v (Period per, Phase ph) = do
--- { let counter = varI32 ( clockName P.++ "_counter" )
--- ; counter .= [ 0 ] ++ ( mux ( counter /= ( fromIntegral ) per - 1 )
--- ( counter + 1 )
--- ( 0 ) )
--- ; if (per P.< 1) then error ("Error in stream " P.++ (show v)
--- P.++ ": period must be 1 or greater.")
--- else if (ph P.< 0) then error ("Error in stream " P.++ (show v)
--- P.++ ": phase must be 0 or greater.")
--- else if (ph P.>= per) then error ("Error in stream " P.++ (show v)
--- P.++ ": phase must be less than period.")
--- else v .= counter == ( fromIntegral ) ph
--- }
+-- clk1 generates a clock that counts n ticks by using a
+-- 32 bit counter variable
+clk1 :: Spec Bool -> (String, Period, Phase) -> Streams
+clk1 v (clockName, Period per, Phase ph) = do
+ { let counter = varI32 ( clockName P.++ "_counter" )
+ ; counter .= [ 0 ] ++ ( mux ( counter /= ( fromIntegral per ) - 1 )
+ ( counter + 1 )
+ ( 0 ) )
+ ; if (per P.< 1) then error ("Error in stream " P.++ (show v)
+ P.++ ": period must be 1 or greater.")
+ else if (ph P.< 0) then error ("Error in stream " P.++ (show v)
+ P.++ ": phase must be 0 or greater.")
+ else if (ph P.>= per) then error ("Error in stream " P.++ (show v)
+ P.++ ": phase must be less than period.")
+ else v .= counter == ( fromIntegral ph )
+ }
Please sign in to comment.
Something went wrong with that request. Please try again.