All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spinal.lib.misc.Prescaler.scala Maven / Gradle / Ivy

There is a newer version: 1.10.2a
Show newest version
package spinal.lib.misc

import spinal.core._
import spinal.lib._
import spinal.lib.bus.misc.BusSlaveFactory

case class Prescaler(width : Int) extends Component{
  val io = new    Bundle{
    val clear    = in Bool()
    val limit    = in UInt(width bits)
    val overflow = out Bool()
  }

  val counter = Reg(UInt(width bits))
  counter := counter + 1

  when(io.clear || io.overflow){
    counter := 0
  }

  io.overflow := counter === io.limit


  def driveFrom(busCtrl : BusSlaveFactory,baseAddress : BigInt, readLimit : Boolean = true) = new Area {
    busCtrl.drive(io.limit,baseAddress)
    if(readLimit) busCtrl.read(io.limit,baseAddress)
    io.clear := busCtrl.isWriting(baseAddress)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy