Skip to content

Commit d0a5283

Browse files
committed
maxcount interrupt
1 parent cabf8bf commit d0a5283

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

src/main/scala/tech/rocksavage/chiselware/timer/Timer.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class Timer(val timerParams: TimerParams, formal: Boolean) extends Module {
2222
val io = IO(new Bundle {
2323
val apb = new ApbBundle(ApbParams(dataWidth, addressWidth))
2424
val timerOutput = new TimerOutputBundle(timerParams)
25-
val interrupt = new TimerInterruptBundle
2625
})
2726

2827
// Create a RegisterMap to manage the addressable registers
@@ -47,6 +46,9 @@ class Timer(val timerParams: TimerParams, formal: Boolean) extends Module {
4746
val setCount: Bool = RegInit(false.B)
4847
registerMap.createAddressableRegister(setCount, "setCount", verbose = timerParams.verbose)
4948

49+
val maxCountEnableInterrupt: Bool = RegInit(false.B)
50+
registerMap.createAddressableRegister(maxCountEnableInterrupt, "maxCountEnableInterrupt", verbose = timerParams.verbose)
51+
5052
// println("Register Map: " + registerMap.getRegisters)
5153

5254
// Generate AddrDecode
@@ -86,11 +88,8 @@ class Timer(val timerParams: TimerParams, formal: Boolean) extends Module {
8688
timerInner.io.timerInputBundle.maxCount := maxCount
8789
timerInner.io.timerInputBundle.pwmCeiling := pwmCeiling
8890
timerInner.io.timerInputBundle.setCountValue := setCountValue
91+
timerInner.io.timerInputBundle.maxCountEnableInterrupt := maxCountEnableInterrupt
8992
// Connect the TimerInner outputs to the top-level outputs
9093
io.timerOutput <> timerInner.io.timerOutputBundle
91-
// Handle interrupts
92-
io.interrupt.interrupt := TimerInterruptEnum.None
93-
when(timerInner.io.timerOutputBundle.maxReached) {
94-
io.interrupt.interrupt := TimerInterruptEnum.MaxReached
95-
}
94+
9695
}

src/main/scala/tech/rocksavage/chiselware/timer/TimerInner.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class TimerInner(
4343
val pwmCeilingWire = WireInit(0.U(params.countWidth.W))
4444
val setCountValueWire = WireInit(0.U(params.countWidth.W))
4545
val setCountWire = WireInit(false.B)
46+
val maxCountEnableInterruptWire = WireInit(false.B)
47+
4648

4749
// Assign input signals to wires
4850
enWire := io.timerInputBundle.en
@@ -51,6 +53,7 @@ class TimerInner(
5153
pwmCeilingWire := io.timerInputBundle.pwmCeiling
5254
setCountValueWire := io.timerInputBundle.setCountValue
5355
setCountWire := io.timerInputBundle.setCount
56+
maxCountEnableInterruptWire := io.timerInputBundle.maxCountEnableInterrupt
5457

5558
// ###################
5659
// Output
@@ -60,21 +63,25 @@ class TimerInner(
6063
val countNext = WireInit(0.U(params.countWidth.W))
6164
val maxReachedNext = WireInit(false.B)
6265
val pwmNext = WireInit(false.B)
66+
val maxCountInterruptNext = WireInit(false.B)
6367

6468
// Registers for output signals
6569
val countReg = RegInit(0.U(params.countWidth.W))
6670
val maxReachedReg = RegInit(false.B)
6771
val pwmReg = RegInit(false.B)
72+
val maxCountInterruptReg = RegInit(false.B)
6873

6974
// Assign next values to registers
7075
countReg := countNext
7176
maxReachedReg := maxReachedNext
7277
pwmReg := pwmNext
78+
maxCountInterruptReg := maxCountInterruptNext
7379

7480
// Assign registers to output bundle
7581
io.timerOutputBundle.count := countReg
7682
io.timerOutputBundle.maxReached := maxReachedReg
7783
io.timerOutputBundle.pwm := pwmReg
84+
io.timerOutputBundle.interrupts.maxCountInterrupt := maxCountInterruptReg
7885

7986
// ###################
8087
// Internal
@@ -137,6 +144,13 @@ class TimerInner(
137144
prescaler = prescalerWire
138145
)
139146

147+
// Interrupts
148+
maxCountInterruptNext := false.B
149+
when(maxReachedNext && maxCountEnableInterruptWire) {
150+
maxCountInterruptNext := true.B
151+
}
152+
153+
140154
// ###################
141155
// Formal verification
142156
// ###################
@@ -195,6 +209,13 @@ class TimerInner(
195209
when(prescalerStableLow3 && setCountStableLow3) {
196210
assert(prescalerCounterNext <= prescalerWire)
197211
}
212+
213+
// ######################
214+
// Interrupt Specification
215+
// ######################
216+
when (maxReachedFV && maxCountEnableInterruptWire) {
217+
assert(maxCountInterruptNext)
218+
}
198219
}
199220
}
200221

src/main/scala/tech/rocksavage/chiselware/timer/bundle/TimerInputBundle.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ class TimerInputBundle(params: TimerParams) extends Bundle {
3232
/** Signal to set the counter to `setCountValue`. */
3333
val setCount = Input(Bool())
3434

35+
/** Signal to enable the interrupt when the counter reaches the maximum count. */
36+
val maxCountEnableInterrupt = Input(Bool())
37+
3538
}

src/main/scala/tech/rocksavage/chiselware/timer/bundle/TimerInterruptBundle.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import chisel3._
66
import chisel3.util._
77

88
class TimerInterruptBundle extends Bundle {
9-
val interrupt = Output(TimerInterruptEnum())
9+
val maxCountInterrupt = Output(Bool())
1010
}

src/main/scala/tech/rocksavage/chiselware/timer/bundle/TimerOutputBundle.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ class TimerOutputBundle(params: TimerParams) extends Bundle {
2222

2323
/** PWM output signal with a duty cycle controlled by `pwmCeiling`. */
2424
val pwm = Output(Bool())
25+
26+
/** Interrupt signals for the timer. */
27+
val interrupts = new TimerInterruptBundle
2528
}

src/test/scala/tech/rocksavage/chiselware/timer/TimerInnerFVHarness.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TimerInnerFVHarness(
4242
val pwmCeilingReg = RegInit(0.U(params.countWidth.W))
4343
val setCountValueReg = RegInit(0.U(params.countWidth.W))
4444
val setCountReg = RegInit(false.B)
45+
val maxCountEnableInterruptReg = RegInit(false.B)
4546

4647
// Assignment
4748
enReg := io.timerInputBundle.en
@@ -50,6 +51,7 @@ class TimerInnerFVHarness(
5051
pwmCeilingReg := io.timerInputBundle.pwmCeiling
5152
setCountValueReg := io.timerInputBundle.setCountValue
5253
setCountReg := io.timerInputBundle.setCount
54+
maxCountEnableInterruptReg := io.timerInputBundle.maxCountEnableInterrupt
5355

5456
// ###################
5557
// Output
@@ -59,6 +61,7 @@ class TimerInnerFVHarness(
5961
val countNext = WireInit(0.U(params.countWidth.W))
6062
val maxReachedNext = WireInit(false.B)
6163
val pwmNext = WireInit(false.B)
64+
val maxCountInterruptNext = WireInit(false.B)
6265

6366
// ###################
6467
// Module Instantiation
@@ -72,12 +75,15 @@ class TimerInnerFVHarness(
7275
timerInner.io.timerInputBundle.pwmCeiling := pwmCeilingReg
7376
timerInner.io.timerInputBundle.setCountValue := setCountValueReg
7477
timerInner.io.timerInputBundle.setCount := setCountReg
78+
timerInner.io.timerInputBundle.maxCountEnableInterrupt := maxCountEnableInterruptReg
7579

7680
countNext := timerInner.io.timerOutputBundle.count
7781
maxReachedNext := timerInner.io.timerOutputBundle.maxReached
7882
pwmNext := timerInner.io.timerOutputBundle.pwm
83+
maxCountInterruptNext := timerInner.io.timerOutputBundle.interrupts.maxCountInterrupt
7984

8085
io.timerOutputBundle.count := countNext
8186
io.timerOutputBundle.maxReached := maxReachedNext
8287
io.timerOutputBundle.pwm := pwmNext
88+
io.timerOutputBundle.interrupts.maxCountInterrupt := maxCountInterruptNext
8389
}

0 commit comments

Comments
 (0)