forked from IBM/esp-chisel-accelerators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CounterAccelerator.scala
74 lines (60 loc) · 2.3 KB
/
CounterAccelerator.scala
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
// Copyright 2018-2019 IBM
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package esp.examples
import chisel3._
import esp.{Config, AcceleratorWrapperIO, AcceleratorIO, Implementation, Parameter, Specification}
import sys.process._
/** An ESP accelerator that is done a parameterized number of clock ticks in the future
* @param ticks the number of clock ticks until done
*/
trait CounterSpecification extends Specification {
/* This defines the abstract member config that provides necessary information for the ESP framework to generate an XML
* accelerator configuration. At the Chisel level, this will be used to emit an [[esp.EspConfigAnnotation]] which will
* be converted to an XML description by a custom FIRRTL transform, [[esp.transforms.EmitXML]]. */
override lazy val config: Config = Config(
name = "CounterAccelerator",
description = s"Fixed-count timer",
memoryFootprintMiB = 0,
deviceId = 0xC,
param = Array(
Parameter(
name = "gitHash",
description = Some("Git short SHA hash of the repo used to generate this accelerator"),
value = Some(Integer.parseInt(("git log -n1 --format=%h" !!).filter(_ >= ' '), 16))
),
Parameter(
name = "ticks",
description = Some("Ticks to timeout"),
value = None)
)
)
}
class CounterAccelerator(dmaWidth: Int) extends Implementation(dmaWidth) with CounterSpecification {
override val implementationName: String = "Default"
val ticks, value = Reg(UInt(config.paramMap("ticks").size.W))
val enabled = RegInit(false.B)
val fire = enabled && (value === ticks)
when (io.enable) {
enabled := true.B
ticks := io.config.get("ticks").asUInt
value := 0.U
}
when (enabled) {
value := value + 1.U
}
when (fire) {
enabled := false.B
}
io.done := fire
}