UART
UARTについて
http://www.altima.jp/column/fpga_edison/uart.html
UART / USART
https://www.youtube.com/watch?v=FQpbIvhY7es
UART = Universal Asyncronus Receiver-Transmitter
USART = Universal Syncronus / Asyncronus Receiver-Transmitter
RS-232
https://www.youtube.com/watch?v=XVEnxipCIJ0
RS-232 Recommended Standard
Tx <--> Rx
Tx = Transmmit Data Rx = Receive Data
DTR <--> DSR
DTR = Data Terminal Ready DSR = Data Set Ready
RST <--> CTS
RTS = Request To Send CTS = Carrier To Send
DCD = Data Carrier Detect RI = ??
FPGAプログラミング大全 Xilinx編 10章
- 作者: 小林優
- 出版社/メーカー: 秀和システム
- 発売日: 2016/12/15
- メディア: 単行本
- この商品を含むブログ (1件) を見る
手元の環境Vivado 2017.3
と10章で書籍と少し違っていた点
P.503 図10-28 (a) IPの登録
P.504 図10-29 乗加算回路IPを追加したかいあダイアグラムが完成
少し嵌った点
10章の最初のサンプルはFPGA\XilinxFPGA\common
にある。(XilinxFPGA\Zybo\dai10sho\muladd_zq
ではない)
hetero-mapの使い方
hetero-map
パッケージを使おうと思ったのですが、サンプルが見つけられず、使い方に悩みました。
このようにして、型の整合はとれても、undefined
をつかっているので実行時にエラーになります。
*Main HeteroMap.Map> let k1 = undefined :: Key Char Char *Main HeteroMap.Map> let k2 = undefined :: Key Int Int *Main HeteroMap.Map> let m = insert k2 2 $ insert k1 'a' empty *Main HeteroMap.Map> :t m m :: Map (Int HeteroMap.Map.:* (Char HeteroMap.Map.:* HeteroMap.Map.Z)) *Main HeteroMap.Map> let v = lookup k1 m *Main HeteroMap.Map> v *** Exception: Prelude.undefined CallStack (from HasCallStack): error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err undefined, called at <interactive>:19:10 in interactive:Ghci2 *Main HeteroMap.Map>
Key
の実装は
data Key x a where Key :: Key a a
となっていますが、データコンストラクタは公開されていません。
key
を作る実装も関数cc
を与えるだけになっており、関数を与えるけれど、その関数の第1引数はKey
固定になっています。これはどのように使うのでしょうか?
-- | Allocate a new key, which is only valid within the passed function -- (and will be a type error if it tries to escape). newKey :: (forall x. Key x a -> b) -> b newKey cc = cc Key
検索しても本当にこのパッケージの情報がなくて、途方に暮れていたところ、HMap
のexample
がヒントになりました。
ポイントとしては、
1つの関数の中で閉じて使う。別の関数とMapを共有できない。(<-この理解であってる?)
ということのようです。
import HeteroMap.Map import Prelude hiding (lookup) example :: Key aaa String -> Key bbb Double -> Key ccc Bool -> String example name salary female = format a ++ "\n" ++ format b ++ "\n" where a = insert name "Edsger" $ insert salary 4450.0 $ insert female False empty b = insert name "Ada" $ insert salary 5000.0 $ insert female True empty format x = lookup name x ++ ": salary=" ++ show (lookup salary x) ++ ", female=" ++ show (lookup female x) keyLocal :: String keyLocal = newKey $ newKey $ newKey example main = do print "local" putStr keyLocal
HaskellでFPGAの最小のサンプル
入力を反転するだけのコード
$ stack exec -- clash --interactive CLaSHi, version 0.99 (using clash-lib, version 0.99): http://www.clash-lang.org/ :? for help Clash.Prelude> :cd ../worka Clash.Prelude> :! ls Clash01.hs Clash.Prelude> :l Clash01.hs [1 of 1] Compiling Clash01 ( Clash01.hs, interpreted ) Ok, modules loaded: Clash01. *Clash01>
Verilog生成
*Clash01> :verilog Loading dependencies took 2.500923s Compiling: Clash01.topEntity Applied 64 transformations Normalisation took 1.056631s Netlist generation took 0.006391s Compiling: Clash01.testBench Applied 219 transformations Testbench normalisation took 0.550645s Testbench netlist generation took 0.030401s Total compilation took 4.170923s *Clash01> :! ls Clash01.dyn_hi Clash01.dyn_o Clash01.hi Clash01.hs Clash01.o verilog *Clash01> :! tree . ├── Clash01.dyn_hi ├── Clash01.dyn_o ├── Clash01.hi ├── Clash01.hs ├── Clash01.o └── verilog └── Clash01 ├── Clash01_testBench │ ├── Clash01_outputVerifier.v │ ├── Clash01_stimuliGenerator.v │ └── Clash01_testBench.v ├── Clash01_testBench.vcd ├── Clash01_topEntity.manifest ├── Clash01_topEntity.v └── main.exe 3 directories, 12 files *Clash01>
波形ファイルを作るためにテストベンチを修正
波形ファイル生成
$ find . -name "*.v" | xargs iverilog -o main.exe $ ./main.exe VCD info: dumpfile Clash01_testBench.vcd opened for output.
波形ファイルの確認
ターゲット指定のcabalのrepl
cabalファイルで複数のターゲットを作り、cabal repl
すると起動ができなくなります。
$ cabal repl cabal: The 'repl' command does not support multiple targets at once. $
また、ターゲットの名前が重複すると起動しません。
$ cabal repl myprotobuf cabal: Ambiguous build target 'myprotobuf'. It could be: exe:myprotobuf (component) lib:myprotobuf (component)
この場合、cabal repl 種別:名称
で指定します。
$ cabal repl exe:myprotobuf
$ cabal repl lib:myprotobuf
$ cabal repl test:MyTestSuite01
cabal
ファイルで記載する場所の例は下記です。
name: myprotobuf version: 0.1.0.0 ... executable myprotobuf ### ここの名称 main-is: TCP01.hs other-extensions: BangPatterns, DeriveDataTypeable, DeriveGeneric, FlexibleInstances, MultiParamTypeClasses ... library lib-xproto ### ここの名称 ... exposed-modules: DataBase.MySQLX.CRUD ... Test-Suite MyTestSuite01 ### ここの名称 type: exitcode-stdio-1.0
Haskellのドキュメント生成
haddock
コマンド自体はディレクトリを指定してその配下にあるhs
ファイルを再帰的に処理してくれるオプションはないようです。xargs
を使うのが手っ取り早いようです。
haskell - how to generate documentations with haddock? - Stack Overflow
$ find . -name '*.hs' | xargs haddock --html -o doc_dir
Implicit Parameters
Clash
のプログラミングでサンプルを作り始めたところ、?変数名 :: 型
というシグネチャが出てきました。
*> :t notM notM :: (?rst::Reset domain synchronous, ?clk::Clock domain gated) => Signal domain Bool -> Signal domain Bool
Implicit Paremters
という機能でした。
https://www.haskell.org/hugs/pages/users_guide/implicit-parameters.html
Readerモナドに似た挙動をするようです。
まずは、このような関数を考えてみます。
*> let foo = (*2) . (+2) *> :t foo foo :: Num c => c -> c *> foo 1 6 *> foo 2 8 *> foo 3 10
次に、上の関数の実装内で2つあった関数((*2)
と(+2)
)の1番目の関数を、パラメータとして外出しします。
*> let foo' z = z . (+2) *> :t foo' foo' :: Num b => (b -> c) -> b -> c *> foo' (*2) 1 6 *> foo' (*2) 2 8 *> foo' (*2) 3 10
さらに、上の関数で外出ししたパラメータを暗黙化します。
*> let foo'' = undefined :: (Num a, ?z::a->a) => a -> a *> let foo'' = let ?z=(*2) in ?z . (+2) :: (Num a, ?z::a->a) => a -> a *> foo'' 1 6 *> foo'' 2 8 *> foo'' 3 10
参考情報