From 2d3e55c69d8ff08af0bc0363dd70879b8b6dc873 Mon Sep 17 00:00:00 2001 From: tzlil Date: Fri, 23 Feb 2024 16:28:14 +0200 Subject: rename stuff, add SSAM2603 ADC/DAC chip docs --- blinker.cabal | 87 --------------------------------------------------------- fpga.cabal | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Blinker.hs | 71 ---------------------------------------------- src/Main.hs | 71 ++++++++++++++++++++++++++++++++++++++++++++++ ssm2603.pdf | Bin 0 -> 509001 bytes 5 files changed, 158 insertions(+), 158 deletions(-) delete mode 100644 blinker.cabal create mode 100644 fpga.cabal delete mode 100644 src/Blinker.hs create mode 100644 src/Main.hs create mode 100644 ssm2603.pdf diff --git a/blinker.cabal b/blinker.cabal deleted file mode 100644 index 35e0781..0000000 --- a/blinker.cabal +++ /dev/null @@ -1,87 +0,0 @@ -cabal-version: 2.4 -name: Blinker -version: 0.1 -license: BSD-2-Clause -author: John Smith -maintainer: John Smith - -common common-options - default-extensions: - BangPatterns - BinaryLiterals - ConstraintKinds - DataKinds - DefaultSignatures - DeriveAnyClass - DeriveDataTypeable - DeriveFoldable - DeriveFunctor - DeriveGeneric - DeriveLift - DeriveTraversable - DerivingStrategies - InstanceSigs - KindSignatures - LambdaCase - NoStarIsType - PolyKinds - RankNTypes - ScopedTypeVariables - StandaloneDeriving - TupleSections - TypeApplications - TypeFamilies - TypeOperators - ViewPatterns - - -- TemplateHaskell is used to support convenience functions such as - -- 'listToVecTH' and 'bLit'. - TemplateHaskell - QuasiQuotes - - -- Prelude isn't imported by default as Clash offers Clash.Prelude - NoImplicitPrelude - ghc-options: - -Wall -Wcompat - -haddock - - -- Plugins to support type-level constraint solving on naturals - -fplugin GHC.TypeLits.Extra.Solver - -fplugin GHC.TypeLits.Normalise - -fplugin GHC.TypeLits.KnownNat.Solver - - -- Clash needs access to the source code in compiled modules - -fexpose-all-unfoldings - - -- Worker wrappers introduce unstable names for functions that might have - -- blackboxes attached for them. You can disable this, but be sure to add - -- a no-specialize pragma to every function with a blackbox. - -fno-worker-wrapper - - -- Strict annotations - while sometimes preventing space leaks - trigger - -- optimizations Clash can't deal with. See: - -- - -- https://github.com/clash-lang/clash-compiler/issues/2361 - -- - -- These flags disables these optimizations. Note that the fields will - -- remain strict. - -fno-unbox-small-strict-fields - -fno-unbox-strict-fields - build-depends: - base, - Cabal, - mtl, - transformers, - - -- clash-prelude will set suitable version bounds for the plugins - clash-prelude >= 1.8.1 && < 1.10, - clash-cores, - ghc-typelits-natnormalise, - ghc-typelits-extra, - ghc-typelits-knownnat - -library - import: common-options - hs-source-dirs: src - exposed-modules: Blinker - default-language: Haskell2010 \ No newline at end of file diff --git a/fpga.cabal b/fpga.cabal new file mode 100644 index 0000000..14ac474 --- /dev/null +++ b/fpga.cabal @@ -0,0 +1,87 @@ +cabal-version: 2.4 +name: Blinker +version: 0.1 +license: BSD-2-Clause +author: John Smith +maintainer: John Smith + +common common-options + default-extensions: + BangPatterns + BinaryLiterals + ConstraintKinds + DataKinds + DefaultSignatures + DeriveAnyClass + DeriveDataTypeable + DeriveFoldable + DeriveFunctor + DeriveGeneric + DeriveLift + DeriveTraversable + DerivingStrategies + InstanceSigs + KindSignatures + LambdaCase + NoStarIsType + PolyKinds + RankNTypes + ScopedTypeVariables + StandaloneDeriving + TupleSections + TypeApplications + TypeFamilies + TypeOperators + ViewPatterns + + -- TemplateHaskell is used to support convenience functions such as + -- 'listToVecTH' and 'bLit'. + TemplateHaskell + QuasiQuotes + + -- Prelude isn't imported by default as Clash offers Clash.Prelude + NoImplicitPrelude + ghc-options: + -Wall -Wcompat + -haddock + + -- Plugins to support type-level constraint solving on naturals + -fplugin GHC.TypeLits.Extra.Solver + -fplugin GHC.TypeLits.Normalise + -fplugin GHC.TypeLits.KnownNat.Solver + + -- Clash needs access to the source code in compiled modules + -fexpose-all-unfoldings + + -- Worker wrappers introduce unstable names for functions that might have + -- blackboxes attached for them. You can disable this, but be sure to add + -- a no-specialize pragma to every function with a blackbox. + -fno-worker-wrapper + + -- Strict annotations - while sometimes preventing space leaks - trigger + -- optimizations Clash can't deal with. See: + -- + -- https://github.com/clash-lang/clash-compiler/issues/2361 + -- + -- These flags disables these optimizations. Note that the fields will + -- remain strict. + -fno-unbox-small-strict-fields + -fno-unbox-strict-fields + build-depends: + base, + Cabal, + mtl, + transformers, + + -- clash-prelude will set suitable version bounds for the plugins + clash-prelude >= 1.8.1 && < 1.10, + clash-cores, + ghc-typelits-natnormalise, + ghc-typelits-extra, + ghc-typelits-knownnat + +library + import: common-options + hs-source-dirs: src + exposed-modules: Main + default-language: Haskell2010 \ No newline at end of file diff --git a/src/Blinker.hs b/src/Blinker.hs deleted file mode 100644 index 9dc9778..0000000 --- a/src/Blinker.hs +++ /dev/null @@ -1,71 +0,0 @@ -{-# LANGUAGE ImplicitParams #-} -{-# LANGUAGE NumericUnderscores #-} -{-# LANGUAGE AllowAmbiguousTypes #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE LambdaCase #-} -{-# OPTIONS_GHC -option #-} -module Blinker where - -import Clash.Prelude -import Clash.Annotations.SynthesisAttributes -import Clash.Cores.UART -import Data.Char (ord) -import Control.Monad.Trans.State.Strict - --- 50 MHz -createDomain vSystem{vName="Input", vPeriod=20_000} - -{-# ANN topEntity - (Synthesize - { t_name = "Blinker" - , t_inputs = [ - PortName "CLK0", - PortName "UART_RX" - ] - , t_output = PortName "UART_TX" - }) #-} -topEntity :: - "CLK" ::: Clock Input - `Annotate` 'StringAttr "chip_pin" "R20" - `Annotate` 'StringAttr - "altera_attribute" "-name IO_STANDARD \"3.3-V LVTTL\"" - -> "RX" ::: Signal Input Bit - `Annotate` 'StringAttr - "chip_pin" "M9" - `Annotate` 'StringAttr - "altera_attribute" "-name IO_STANDARD \"2.5V\"" - -> "KEY0" ::: Signal Input Bit - `Annotate` 'StringAttr - "chip_pin" "P11" - `Annotate` 'StringAttr - "altera_attribute" "-name IO_STANDARD \"1.2V\"" - -> Signal Input Bit - `Annotate` 'StringAttr - "chip_pin" "L9" - `Annotate` 'StringAttr - "altera_attribute" "-name IO_STANDARD \"2.5V\"" -topEntity clk rx key0 = txBit - where - baud = SNat @115200 - uart' = exposeClockResetEnable (uart baud) clk resetGen enableGen - (rxWord, txBit, ack) = uart' rx txM - txM = (exposeClockResetEnable mealyS clk resetGen enableGen) cpu Listening (CPUIn <$> key0 <*> ack <*> rxWord) - - -data CPUIn = CPUIn { - key0 :: Bit, - ack :: Bool, - rx :: Maybe (BitVector 8) -} - -data CPUState = Transmitting (BitVector 8) | Listening deriving (Generic, NFDataX) -cpu :: CPUIn -> State CPUState (Maybe (BitVector 8)) -cpu CPUIn{rx=Just rx} = do - put $ Transmitting $ rx - return Nothing - -cpu CPUIn{ack=True} = put Listening >> return Nothing - -cpu CPUIn{ack=False,rx=Nothing} = get >>= \case - Transmitting s -> return $ Just s - Listening -> return Nothing \ No newline at end of file diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..43f4746 --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,71 @@ +{-# LANGUAGE ImplicitParams #-} +{-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE AllowAmbiguousTypes #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE LambdaCase #-} +{-# OPTIONS_GHC -option #-} +module Main where + +import Clash.Prelude +import Clash.Annotations.SynthesisAttributes +import Clash.Cores.UART +import Data.Char (ord) +import Control.Monad.Trans.State.Strict + +-- 50 MHz +createDomain vSystem{vName="Input", vPeriod=20_000} + +{-# ANN topEntity + (Synthesize + { t_name = "Main" + , t_inputs = [ + PortName "CLK0", + PortName "UART_RX" + ] + , t_output = PortName "UART_TX" + }) #-} +topEntity :: + "CLK" ::: Clock Input + `Annotate` 'StringAttr "chip_pin" "R20" + `Annotate` 'StringAttr + "altera_attribute" "-name IO_STANDARD \"3.3-V LVTTL\"" + -> "RX" ::: Signal Input Bit + `Annotate` 'StringAttr + "chip_pin" "M9" + `Annotate` 'StringAttr + "altera_attribute" "-name IO_STANDARD \"2.5V\"" + -> "KEY0" ::: Signal Input Bit + `Annotate` 'StringAttr + "chip_pin" "P11" + `Annotate` 'StringAttr + "altera_attribute" "-name IO_STANDARD \"1.2V\"" + -> Signal Input Bit + `Annotate` 'StringAttr + "chip_pin" "L9" + `Annotate` 'StringAttr + "altera_attribute" "-name IO_STANDARD \"2.5V\"" +topEntity clk rx key0 = txBit + where + baud = SNat @115200 + uart' = exposeClockResetEnable (uart baud) clk resetGen enableGen + (rxWord, txBit, ack) = uart' rx txM + txM = (exposeClockResetEnable mealyS clk resetGen enableGen) cpu Listening (CPUIn <$> key0 <*> ack <*> rxWord) + + +data CPUIn = CPUIn { + key0 :: Bit, + ack :: Bool, + rx :: Maybe (BitVector 8) +} + +data CPUState = Transmitting (BitVector 8) | Listening deriving (Generic, NFDataX) +cpu :: CPUIn -> State CPUState (Maybe (BitVector 8)) +cpu CPUIn{rx=Just rx} = do + put $ Transmitting $ rx + return Nothing + +cpu CPUIn{ack=True} = put Listening >> return Nothing + +cpu CPUIn{ack=False,rx=Nothing} = get >>= \case + Transmitting s -> return $ Just s + Listening -> return Nothing \ No newline at end of file diff --git a/ssm2603.pdf b/ssm2603.pdf new file mode 100644 index 0000000..5699e03 Binary files /dev/null and b/ssm2603.pdf differ -- cgit 1.4.1