-
Notifications
You must be signed in to change notification settings - Fork 1
/
deca.hsfiles
901 lines (749 loc) · 25.7 KB
/
deca.hsfiles
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
{-# START_FILE .gitignore #-}
dist/
dist-newstyle/
.stack-work/
cabal-dev
/cabal.project.local
.ghc.environment.*
*.o
*.o-boot
*.hi
*.hi-boot
*.po
*.po-boot
*.p_o
*.p_o-boot
*.chi
*.chs.h
*.dyn_o
*.dyn_o-boot
*.dyn_hi
*.dyn_hi-boot
.virtualenv
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
cabal.config
*.prof
*.aux
*.hp
*.bin
*.log
*.tar.gz
*~
*.DS_Store
# IntelliJ
/.idea
*.iml
# HDL directories often created during development cycle
/vhdl
/verilog
/systemverilog
{-# START_FILE .vscode/extensions.json #-}
{
"recommendations": ["haskell.haskell"]
}
{-# START_FILE .vscode/settings.json #-}
{
"files.exclude": {
"**/*.dyn_hi": true,
"**/*.dyn_o": true,
"**/*.hi": true,
"**/*.o": true,
"**/dist-newstyle": true,
"**/.stack-work": true,
"**/.ghc.environment.*": true,
"**/*.o-boot": true,
"**/*.hi-boot": true,
},
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"editor.tabSize": 2
}
{-# START_FILE README.md #-}
<!-- omit in toc -->
# DECA Starter Project
This DECA starter project should make it easier to get started with Clash on the
[Arrow DECA development kit](https://www.arrow.com/en/products/deca/arrow-development-tools).
<!-- omit in toc -->
# Table of Contents
- [Getting this project](#getting-this-project)
- [Building and testing this project](#building-and-testing-this-project)
- [Stack (Windows, Linux, MacOS) [recommended]](#stack-windows-linux-macos-recommended)
- [Cabal (Linux, MacOS)](#cabal-linux-macos)
- [REPL](#repl)
- [IDE support](#ide-support)
- [Running the project on the DECA](#running-the-project-on-the-deca)
- [Creating the FPGA bitstream](#creating-the-fpga-bitstream)
- [Programming the FPGA](#programming-the-fpga)
- [Project overview](#project-overview)
- [{{name}}.cabal](#namecabal)
- [cabal.project](#cabalproject)
- [stack.yaml](#stackyaml)
- [src/](#src)
- [syn/](#syn)
- [tests/](#tests)
- [Change the license](#change-the-license)
# Getting this project
Stack users can run `stack new my-clash-project clash-lang/deca`. Cabal users can
[download a zip](https://raw.githubusercontent.com/clash-lang/clash-starters/main/deca.zip)
containing the project.
# Building and testing this project
There's a number of ways to build this project on your machine. The recommended
way of doing so is using _Stack_, whose instructions will follow directly after
this section.
## Stack (Windows, Linux, MacOS) [recommended]
Install Stack using your package manager or refer to the
[How to install](https://docs.haskellstack.org/en/stable/README/#how-to-install)
section of the [Stack manual](https://docs.haskellstack.org/en/stable/README/).
Build the project with:
```bash
stack build
```
To compile the project to VHDL, run:
```bash
stack run clash -- DECA --vhdl
```
You can find the HDL files in `vhdl/`. The source can be found in `src/DECA.hs`.
## Cabal (Linux, MacOS)
**The following instructions only work for Cabal >=3.0 and GHC >=8.4.**
First, update your cabal package database:
```bash
cabal update
```
You only have to run the update command once. After that, you can keep
rebuilding your project by running the build command:
```bash
cabal build
```
To compile the project to VHDL, run:
```bash
cabal run clash -- DECA --vhdl
```
You can find the HDL files in `vhdl/`. The source can be found in `src/DECA.hs`.
## REPL
Clash offers a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)
as a quick way to try things, similar to Python's `python` or Ruby's `irb`.
Stack users can open the REPL by invoking:
```
stack run clashi
```
Cabal users use:
```
cabal run clashi
```
## IDE support
We currently recommend Visual Studio Code in combination with the _Haskell_ plugin.
All you need to do is open this folder in VSCode; it will prompt you to install
the plugin.
# Running the project on the DECA
## Creating the FPGA bitstream
First, compile the project to VHDL by running:
```bash
stack run clash -- DECA --vhdl
```
Now start [Quartus Prime](https://fpgasoftware.intel.com/?edition=lite); once started,
in the menu bar, click `File -> Open Project` and open `syn/deca.qpf`.
In the menu bar, click: `Processing -> Start Compilation`.
This can take up to a minute depending on your machine.
If everything worked as it was supposed to the last messages in the logs should be in
the spirit of:
```
Info (332101): Design is fully constrained for setup requirements
Info (332101): Design is fully constrained for hold requirements
Info: Quartus Prime Timing Analyzer was successful. 0 errors, 2 warnings
Info: Peak virtual memory: 550 megabytes
Info: Processing ended: Tue Jun 1 09:51:50 2021
Info: Elapsed time: 00:00:01
Info: Total CPU time (on all processors): 00:00:01
Info (293000): Quartus Prime Full Compilation was successful. 0 errors, 11 warnings
```
## Programming the FPGA
After synthesis has finished, it is time to program our FPGA board.
Connect the FPGA board to a USB port, and start the programmer from the menu
bar: `Tools -> Programmer`. Press the `Start` button on the left to program your FPGA
and wait until the progress bar says `100% (Successful)`.
Once programmed, you should be able to operate the DECA devkit as seen here:
[![IMAGE ALT TEXT](http://img.youtube.com/vi/zsChH7q03mg/0.jpg)](http://www.youtube.com/watch?v=zsChH7q03mg "Clash DECA starter")
# Project overview
This section will give a tour of all the files present in this starter project.
It's also a general introduction into Clash dependency management. It's not an
introduction to Clash itself though. If you're looking for an introduction to
Clash, read ["Clash.Tutorial" on Hackage](https://hackage.haskell.org/package/clash-prelude).
```
{{name}}
├── bin
│ ├── Clash.hs
│ └── Clashi.hs
├── syn
│ └── deca_ext.sdc
| └── deca.qpf
| └── deca.qsf
├── src
│ └── DECA.hs
├─── tests
│ ├── Tests
│ │ └── DECA.hs
│ ├── doctests.hs
│ └── unittests.hs
├── cabal.project
├── {{name}}.cabal
└── stack.yaml
```
## {{name}}.cabal
This is the most important file in your project. It describes how to build your
project. Even though it ends in `.cabal`, Stack will use this file too. It
starts of with meta-information:
```yaml
cabal-version: 2.4
name: {{name}}
version: 0.1
license: BSD-2-Clause
author: Author <[email protected]>
maintainer: Author <[email protected]>
```
If you decide to publish your code on [Hackage](https://hackage.haskell.org/),
this will show up on your package's front page. Take note of the license, it's
set to `BSD-2-Clause` by default, but this might bee too liberal for your project.
You can use any of the licenses on [spdx.org/licenses](https://spdx.org/licenses/).
If none of those suit, remove the `license` line, add `license-file: LICENSE`,
and add a `LICENSE` file of your choice to the root of this project. Moving on:
```yaml
common common-options
default-extensions:
BangPatterns
BinaryLiterals
ConstraintKinds
[..]
QuasiQuotes
-- Prelude isn't imported by default as Clash offers Clash.Prelude
NoImplicitPrelude
```
Clash's parent language is Haskell and its de-facto compiler, GHC, does a lot of
heavy lifting before Clash gets to see anything. Because using Clash's Prelude
requires a lot of extensions to be enabled to be used, we enable them here for
all files in the project. Alternatively, you could add them where needed using
`{-# LANGUAGE SomeExtension #-}` at the top of a `.hs` file instead. The next
section, `ghc-options`, sets warning flags (`-Wall -Wcompat`) and flags that
make GHC generate code Clash can handle.
Note that this whole section is a `common` "stanza". We'll use it as a template
for any other definitions (more on those later). The last thing we add to the
common section is some build dependencies:
```yaml
build-depends:
base,
Cabal,
-- clash-prelude will set suitable version bounds for the plugins
clash-prelude >= 1.6.4 && < 1.8,
ghc-typelits-natnormalise,
ghc-typelits-extra,
ghc-typelits-knownnat
```
These dependencies are fetched from [Hackage](https://hackage.haskell.org/),
Haskell's repository for packages. Next up is a `library` stanza. It defines
where the source is located, in our case `src/`, and what modules can be found
there. In our case that's just a single module, `DECA`.
```yaml
library
import: common-options
hs-source-dirs: src
exposed-modules:
DECA
default-language: Haskell2010
```
Note that extra dependencies could be added by adding a `build-depends` line to
this section.
The following section defines a testsuite called _doctests_. Doctests are tests
that are defined in the documentation of your project. We'll see this in action
in [src/](#src).
```yaml
test-suite doctests
type: exitcode-stdio-1.0
default-language: Haskell2010
main-is: doctests.hs
ghc-options: -Wall -Wcompat -threaded
hs-source-dirs: tests
build-depends:
base,
{{ name }},
doctest-parallel >= 0.2 && < 0.4,
```
Last but not least, another testsuite stanza is defined:
```yaml
test-suite test-library
import: common-options
default-language: Haskell2010
hs-source-dirs: tests
type: exitcode-stdio-1.0
ghc-options: -threaded
main-is: unittests.hs
other-modules:
Tests.DECA
build-depends:
{{name}},
QuickCheck,
hedgehog,
tasty >= 1.2 && < 1.5,
tasty-hedgehog,
tasty-th
```
These testsuites are executed when using `stack test` or `cabal test`.
Note that Cabal swallows the output if more than one testsuite is defined, as
is the case here. You might want to consider running the testsuites separately.
More on tests in [/tests](#tests).
## cabal.project
A `cabal.project` file is used to configure details of the build, more info can
be found in the [Cabal user documentation](https://cabal.readthedocs.io/en/latest/cabal-project.html).
We use it to make Cabal always generate GHC environment files, which is a
feature Clash needs when using Cabal.
```haskell
packages:
{{name}}.cabal
write-ghc-environment-files: always
```
`cabal.project` can be used to build multi-package projects, by extending `packages`.
## stack.yaml
While Cabal fetches packages straight from Hackage (with a bias towards the
latest versions), Stack works through _snapshots_. Snapshots are an index of
packages from Hackage know to work well with each other. In addition to that,
they specify a GHC version. These snapshots are curated by the community and
FP Complete and can be found on [stackage.org](https://www.stackage.org/).
```yaml
resolver: lts-19.32
```
This project uses [lts-19.32](https://www.stackage.org/lts-19.32), which
includes Clash 1.6.4. Snapshots tightly couple GHC and package versions. By
working this way, Stack projects build on a cohesive set of packages. Plus, it
guarantees that if a `stack build` works now, it will work in 10 years too.
Note: If you need a newer Clash version, simply change the version bounds in
`{{name}}.cabal` and follow the hints given by Stack.
## src/
This is where the Haskell source code of the project lives, as specified in
`{{name}}.cabal`. It contains a single file, `DECA.hs`.
One aspect that's worth highlighting is that in this file there is the following
definition:
```haskell
-- | Changes the LED mode
--
-- >>> flipMode Rotate
-- Complement
-- >>> flipMode Complement
-- Rotate
flipMode :: LedMode -> LedMode
flipMode Rotate = Complement
flipMode Complement = Rotate
```
Where the example (`>>> flipMode Rotate`) in the comments gets executed by the
_doctests_ defined for this project and checked for consistency with the result
in the documentation (`Complement`).
## syn/
This contains the Quartus projects, it expects that you already generated the
VHDL.
## tests/
Most of this directory is scaffolding, with the meat of the tests being defined
in `tests/Tests/DECA.hs`. Writing good test cases is pretty hard: edge cases are
easy to forget both in the implementation and tests. To this end, it's a good
idea to use _fuzz testing_. In this project we use [Hedgehog](https://hedgehog.qa/):
```haskell
import DECA (LedMode (..), flipMode)
prop_flipTwiceOriginal :: H.Property
prop_flipTwiceOriginal = H.property $ do
a <- H.forAll (Gen.enum Rotate Complement)
a === flipMode (flipMode a)
```
This test generates an LED mode, `a`, enumerating from the `Rotate` mode to the
`Complement` mode. It then tests whether flipping the LED mode twice give you
back the original LED mode.
All functions called `prop_*` are collected automatically:
```haskell
tests :: TestTree
tests = $(testGroupGenerator)
```
We can run the tests using `stack test` or `cabal run test-library`:
```
.
Tests.DECA
flipTwiceOriginal: OK
✓ flipTwiceOriginal passed 100 tests.
All 1 tests passed (0.00s)
```
# Change the license
By default `{{name}}.cabal` sets its `license` field to `BSD-2-Clause`. You
might want to change this.
{-# START_FILE bin/Clash.hs #-}
import Prelude
import System.Environment (getArgs)
import Clash.Main (defaultMain)
main :: IO ()
main = getArgs >>= defaultMain
{-# START_FILE bin/Clashi.hs #-}
import Prelude
import System.Environment (getArgs)
import Clash.Main (defaultMain)
main :: IO ()
main = getArgs >>= defaultMain . ("--interactive":)
{-# START_FILE cabal.project #-}
packages:
{{name}}.cabal
write-ghc-environment-files: always
-- Eliminates the need for `--enable-tests`, which is needed for HLS.
tests: true
{-# START_FILE src/DECA.hs #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module DECA where
import Clash.Prelude
import Clash.Intel.ClockGen
import Clash.Annotations.SynthesisAttributes
data LedMode
= Rotate
-- ^ After some period, rotate active led to the left
| Complement
-- ^ After some period, turn on all disable LEDs, and vice versa
deriving (Show, Eq, Enum, Generic, NFDataX)
-- Define a synthesis domain with a clock with a period of 20000 /ps/.
createDomain vSystem{vName="Input", vPeriod=20000}
-- Define a synthesis domain with a clock with a period of 50000 /ps/.
createDomain vSystem{vName="Dom50", vPeriod=50000}
{-# ANN deca
(Synthesize
{ t_name = "deca"
, t_inputs = [ PortName "MAX10_CLK1_50"
, PortName "KEY0"
, PortName "KEY1"
]
, t_output = PortName "LED"
}) #-}
deca
:: Clock Input
`Annotate` 'StringAttr "chip_pin" "M8"
`Annotate` 'StringAttr "altera_attribute" "-name IO_STANDARD \"2.5 V\""
-- ^ Incoming clock
--
-- Annotate with attributes to map the argument to the correct pin, with the
-- correct voltage settings, on the DECA development kit.
-> Signal Input Bool
`Annotate` 'StringAttr "chip_pin" "H21"
`Annotate` 'StringAttr "altera_attribute" "-name IO_STANDARD \"1.5 V Schmitt Trigger\""
-- ^ Reset signal, straight from KEY0
-> Signal Dom50 Bit
`Annotate` 'StringAttr "chip_pin" "H22"
`Annotate` 'StringAttr "altera_attribute" "-name IO_STANDARD \"1.5 V Schmitt Trigger\""
-- ^ Mode choice, straight from KEY1. See 'LedMode'.
-> Signal Dom50 (BitVector 8)
`Annotate` 'StringAttr "chip_pin" "C5, B4, A5, C4, B7, A6, C8, C7"
`Annotate` 'StringAttr "altera_attribute" "-name IO_STANDARD \"1.2 V\""
-- ^ Output containing 8 bits, corresponding to 8 LEDs, LEDs are active-low
--
-- Use comma-seperated list in the "chip_pin" attribute to maps the individual
-- bits of the result to the correct pins on the DECA development kit
deca clk20 rstBtn modeBtn =
exposeClockResetEnable
(mealy blinkerT initialStateBlinkerT . isRising 1)
clk50
rstSync
en
modeBtn
where
-- | Enable line for subcomponents: we'll keep it always running
en = enableGen
-- Start with the first LED turned on, in rotate mode, with the counter on zero
initialStateBlinkerT = (1, Rotate, 0)
-- Signal coming from the reset button is low when pressed, and high when
-- not pressed. We convert this signal to the polarity of our domain with
-- 'unsafeFromLowPolarity'.
rst = unsafeFromLowPolarity rstBtn
-- Instantiate a PLL: this stabilizes the incoming clock signal and indicates
-- when the signal is stable. We're also using it to transform an incoming
-- clock signal running at 20 MHz to a clock signal running at 50 MHz.
(clk50, pllStable) =
altpll
@Dom50
(SSymbol @"altpll50")
clk20
rst
-- Synchronize reset to clock signal coming from PLL. We want the reset to
-- remain active while the PLL is NOT stable, hence the conversion with
-- 'unsafeFromLowPolarity'
rstSync =
resetSynchronizer
clk50
(unsafeFromLowPolarity pllStable)
-- | Changes the LED mode
--
-- >>> flipMode Rotate
-- Complement
-- >>> flipMode Complement
-- Rotate
flipMode :: LedMode -> LedMode
flipMode Rotate = Complement
flipMode Complement = Rotate
blinkerT
:: (BitVector 8, LedMode, Index 6660000)
-> Bool
-> ((BitVector 8, LedMode, Index 6660000), BitVector 8)
blinkerT (leds, mode, cntr) key1R = ((leds', mode', cntr'), complement leds)
where
-- clock frequency = 20e6 (20 MHz)
-- led update rate = 333e-3 (every 333ms)
cnt_max = maxBound :: Index 6660000 -- 20e6 * 333e-3
cntr' | cntr == cnt_max = 0
| otherwise = cntr + 1
mode' | key1R = flipMode mode
| otherwise = mode
leds' | cntr == 0 =
case mode of
Rotate -> rotateL leds 1
Complement -> complement leds
| otherwise = leds
{-# START_FILE stack.yaml #-}
resolver: lts-21.20
extra-deps:
- clash-ghc-1.8.1@sha256:3bab304fa5584f3541650bddd01160f2710b9ced52e52c06481a91ac73d71bb8,9753
- clash-lib-1.8.1@sha256:17d78e786dedf16a76394cd5813372870a3d70a1a4c7f964309f126b800e90f6,15693
- clash-prelude-1.8.1@sha256:c3fbb9f6b8e74140fb3d5c4d59ec84cfe4a53e9f8520e606c187cfc04b149065,17626
- clash-prelude-hedgehog-1.8.1@sha256:9ec3aa3f8195481f5ce4942b34a49c97dd132dd1c8f1fa58aeecbd82c2602e86,1410
- concurrent-supply-0.1.8@sha256:80b658533141660818d0781b8c8fb9a8cf69b987fcfbab782dc788bfc7df4846,1627
- prettyprinter-interp-0.2.0.0@sha256:69c339a95b265dab9b3478ca19ec96952b6b472bd0ff6e2127112a9562362c1d,2086
{-# START_FILE syn/addclashsources.tcl #-}
package require json
namespace eval clash {
variable options
variable db
namespace export options buildDB addClashFiles
proc buildDB {} {
variable options
variable db
proc parseManifest {manifestF} {
variable db
set manC [open $manifestF r]
set manifest [json::json2dict [read $manC]]
close $manC
set top [dict get $manifest top_component name]
if [dict exists $db $top] {
return
}
dict set db $top hdlFiles {}
dict set db $top qsysFiles {}
dict set db $top sdcFiles {}
foreach fileEntry [dict get $manifest files] {
set name [dict get $fileEntry name]
if [string match {*.vhdl} $name] {
dict with db $top {
lappend hdlFiles "[file dirname $manifestF]/$name"
}
}
if [string match {*.qsys} $name] {
dict with db $top {
lappend qsysFiles "[file dirname $manifestF]/$name"
}
}
if [string match {*.sdc} $name] {
dict with db $top {
lappend sdcFiles "[file dirname $manifestF]/$name"
}
}
}
foreach dependency [dict get $manifest dependencies transitive] {
parseManifest "[file dirname \
$manifestF]/../$dependency/clash-manifest.json" false
}
}
set db [dict create]
foreach manifestF \
[glob -type f -directory $options(clash-hdldir) \
$options(top-qual-name)/clash-manifest.json] {
parseManifest $manifestF
}
}
proc addClashFiles {} {
variable db
dict for {top topDict} $db {
foreach hdlFile [dict get $topDict hdlFiles] {
set_global_assignment -name VHDL_FILE $hdlFile
post_message "Adding VHDL file: $hdlFile"
}
foreach qsysFile [dict get $topDict qsysFiles] {
set_global_assignment -name QSYS_FILE $qsysFile
post_message "Adding QSYS file: $qsysFile"
}
foreach sdcFile [dict get $topDict sdcFiles] {
set_global_assignment -name SDC_FILE $sdcFile
post_message "Adding QSYS file: $sdcFile"
}
}
}
}
set project [lindex $quartus(args) 1]
set revision [lindex $quartus(args) 2]
project_open $project -revision $revision
set clash::options(clash-hdldir) {../vhdl}
set clash::options(top-qual-name) {DECA.deca}
clash::buildDB
clash::addClashFiles
{-# START_FILE syn/deca.qpf #-}
PROJECT_REVISION = "deca"
{-# START_FILE syn/deca.qsf #-}
set_global_assignment -name FAMILY "MAX 10"
set_global_assignment -name DEVICE 10M50DAF484C6GES
set_global_assignment -name PRE_FLOW_SCRIPT_FILE "quartus_sh:addclashsources.tcl"
set_global_assignment -name TOP_LEVEL_ENTITY deca
set_global_assignment -name SDC_FILE deca_ext.sdc
set_global_assignment -name AUTO_RESTART_CONFIGURATION ON
set_global_assignment -name ENABLE_CONFIGURATION_PINS OFF
set_global_assignment -name ENABLE_BOOT_SEL_PIN OFF
{-# START_FILE syn/deca_ext.sdc #-}
derive_pll_clocks
derive_clock_uncertainty
set_false_path -from * -to [get_ports {LED[*]}]
set_false_path -from [get_ports {KEY0}] -to *
set_false_path -from [get_ports {KEY1}] -to *
{-# START_FILE tests/Tests/DECA.hs #-}
module Tests.DECA where
import Prelude
import Test.Tasty
import Test.Tasty.TH
import Test.Tasty.Hedgehog
import Hedgehog ((===))
import qualified Hedgehog as H
import qualified Hedgehog.Gen as Gen
import DECA (LedMode (..), flipMode)
prop_flipTwiceOriginal :: H.Property
prop_flipTwiceOriginal = H.property $ do
a <- H.forAll (Gen.enum Rotate Complement)
a === flipMode (flipMode a)
tests :: TestTree
tests = $(testGroupGenerator)
main :: IO ()
main = defaultMain tests
{-# START_FILE tests/doctests.hs #-}
module Main where
import System.Environment (getArgs)
import Test.DocTest (mainFromCabal)
main :: IO ()
main = mainFromCabal "{{ name }}" =<< getArgs
{-# START_FILE tests/unittests.hs #-}
import Prelude
import Test.Tasty
import qualified Tests.DECA
main :: IO ()
main = defaultMain $ testGroup "."
[ Tests.DECA.tests
]
{-# START_FILE {{name}}.cabal #-}
cabal-version: 2.4
name: {{name}}
version: 0.1
license: BSD-2-Clause
author: Author <[email protected]>
maintainer: Author <[email protected]>
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,
-- clash-prelude will set suitable version bounds for the plugins
clash-prelude >= 1.8.1 && < 1.10,
ghc-typelits-natnormalise,
ghc-typelits-extra,
ghc-typelits-knownnat
library
import: common-options
hs-source-dirs: src
exposed-modules:
DECA
default-language: Haskell2010
-- Builds the executable 'clash', with {{name}} project in scope
executable clash
main-is: bin/Clash.hs
default-language: Haskell2010
Build-Depends: base, clash-ghc, {{name}}
if !os(Windows)
ghc-options: -dynamic
-- Builds the executable 'clashi', with {{name}} project in scope
executable clashi
main-is: bin/Clashi.hs
default-language: Haskell2010
if !os(Windows)
ghc-options: -dynamic
build-depends: base, clash-ghc, {{name}}
test-suite doctests
type: exitcode-stdio-1.0
default-language: Haskell2010
main-is: doctests.hs
ghc-options: -Wall -Wcompat -threaded
hs-source-dirs: tests
build-depends:
base,
{{ name }},
doctest-parallel >= 0.2 && < 0.4,
test-suite test-library
import: common-options
default-language: Haskell2010
hs-source-dirs: tests
type: exitcode-stdio-1.0
ghc-options: -threaded
main-is: unittests.hs
other-modules:
Tests.DECA
build-depends:
{{name}},
QuickCheck,
hedgehog,
tasty >= 1.2 && < 1.5,
tasty-hedgehog,
tasty-th