33package tech .rocksavage .chiselware .timer
44
55import chisel3 ._
6- import tech .rocksavage .chiselware .addrdecode .{AddrDecode , AddrDecodeError }
6+ import tech .rocksavage .chiselware .addrdecode .AddrDecode
7+ import tech .rocksavage .chiselware .addrdecode .AddrDecodeError
78import tech .rocksavage .chiselware .addressable .RegisterMap
8- import tech .rocksavage .chiselware .apb .{ApbBundle , ApbParams }
9+ import tech .rocksavage .chiselware .apb .ApbBundle
10+ import tech .rocksavage .chiselware .apb .ApbParams
911import tech .rocksavage .chiselware .timer .bundle .TimerOutputBundle
1012import tech .rocksavage .chiselware .timer .param .TimerParams
13+ import tech .rocksavage .test .TestUtils .coverAll
1114
12- /** A Timer module that implements a configurable timer with various
13- * functionalities.
15+ /** A Timer module that implements a configurable timer with various functionalities.
1416 *
1517 * @param timerParams
1618 * Parameters for configuring the timer.
1719 * @param formal
1820 * A boolean value to enable formal verification.
1921 */
20- class Timer (val timerParams : TimerParams , formal : Boolean ) extends Module {
22+ class Timer (
23+ val timerParams : TimerParams ,
24+ formal : Boolean )
25+ extends Module {
2126
2227 /** Data width for the timer */
2328 val dataWidth = timerParams.dataWidth
@@ -50,55 +55,55 @@ class Timer(val timerParams: TimerParams, formal: Boolean) extends Module {
5055 registerMap.createAddressableRegister(
5156 en,
5257 " en" ,
53- verbose = timerParams.verbose
58+ verbose = timerParams.verbose,
5459 )
5560
5661 /** Prescaler value register */
5762 val prescaler : UInt = RegInit (0 .U (timerParams.prescalerWidth.W ))
5863 registerMap.createAddressableRegister(
5964 prescaler,
6065 " prescaler" ,
61- verbose = timerParams.verbose
66+ verbose = timerParams.verbose,
6267 )
6368
6469 /** Maximum count value register */
6570 val maxCount : UInt = RegInit (0 .U (timerParams.countWidth.W ))
6671 registerMap.createAddressableRegister(
6772 maxCount,
6873 " maxCount" ,
69- verbose = timerParams.verbose
74+ verbose = timerParams.verbose,
7075 )
7176
7277 /** PWM ceiling value register */
7378 val pwmCeiling : UInt = RegInit (0 .U (timerParams.countWidth.W ))
7479 registerMap.createAddressableRegister(
7580 pwmCeiling,
7681 " pwmCeiling" ,
77- verbose = timerParams.verbose
82+ verbose = timerParams.verbose,
7883 )
7984
8085 /** Value to set the count register */
8186 val setCountValue : UInt = RegInit (0 .U (timerParams.countWidth.W ))
8287 registerMap.createAddressableRegister(
8388 setCountValue,
8489 " setCountValue" ,
85- verbose = timerParams.verbose
90+ verbose = timerParams.verbose,
8691 )
8792
8893 /** Signal to set the count register */
8994 val setCount : Bool = RegInit (false .B )
9095 registerMap.createAddressableRegister(
9196 setCount,
9297 " setCount" ,
93- verbose = timerParams.verbose
98+ verbose = timerParams.verbose,
9499 )
95100
96101 /** Enable interrupt for maximum count register */
97102 val maxCountEnableInterrupt : Bool = RegInit (false .B )
98103 registerMap.createAddressableRegister(
99104 maxCountEnableInterrupt,
100105 " maxCountEnableInterrupt" ,
101- verbose = timerParams.verbose
106+ verbose = timerParams.verbose,
102107 )
103108
104109 // Generate AddrDecode
@@ -111,37 +116,39 @@ class Timer(val timerParams: TimerParams, formal: Boolean) extends Module {
111116 addrDecode.io.en := true .B
112117 addrDecode.io.selInput := true .B
113118 io.apb.PREADY := (io.apb.PENABLE && io.apb.PSEL )
114- io.apb.PSLVERR := addrDecode.io.errorCode === AddrDecodeError .AddressOutOfRange
115- io.apb.PRDATA := 0 .U
119+ io.apb.PSLVERR := addrDecode.io.errorCode === AddrDecodeError .AddressOutOfRange
120+ io.apb.PRDATA := 0 .U
116121
117122 // Control Register Read/Write
118123 when(io.apb.PSEL && io.apb.PENABLE ) {
119124 when(io.apb.PWRITE ) {
120- for (reg <- registerMap.getRegisters) {
125+ for (reg <- registerMap.getRegisters)
121126 when(addrDecode.io.sel(reg.id)) {
122127 reg.writeCallback(addrDecode.io.addrOut, io.apb.PWDATA )
123128 }
124- }
125129 }.otherwise {
126- for (reg <- registerMap.getRegisters) {
130+ for (reg <- registerMap.getRegisters)
127131 when(addrDecode.io.sel(reg.id)) {
128132 io.apb.PRDATA := reg.readCallback(addrDecode.io.addrOut)
129133 }
130- }
131134 }
132135 }
133136
134137 // Instantiate the TimerInner module
135138 /** TimerInner module instance */
136139 val timerInner = Module (new TimerInner (timerParams, formal))
137- timerInner.io.timerInputBundle.en := en
138- timerInner.io.timerInputBundle.setCount := setCount
139- timerInner.io.timerInputBundle.prescaler := prescaler
140- timerInner.io.timerInputBundle.maxCount := maxCount
141- timerInner.io.timerInputBundle.pwmCeiling := pwmCeiling
142- timerInner.io.timerInputBundle.setCountValue := setCountValue
140+ timerInner.io.timerInputBundle.en := en
141+ timerInner.io.timerInputBundle.setCount := setCount
142+ timerInner.io.timerInputBundle.prescaler := prescaler
143+ timerInner.io.timerInputBundle.maxCount := maxCount
144+ timerInner.io.timerInputBundle.pwmCeiling := pwmCeiling
145+ timerInner.io.timerInputBundle.setCountValue := setCountValue
143146 timerInner.io.timerInputBundle.maxCountEnableInterrupt := maxCountEnableInterrupt
144147
145148 // Connect the TimerInner outputs to the top-level outputs
146149 io.timerOutput <> timerInner.io.timerOutputBundle
150+
151+ if (timerParams.coverage)
152+ // Cover the entire IO bundle recursively.
153+ coverAll(io, " _io" )
147154}
0 commit comments