Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/composable-exp' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolu1990 committed Feb 1, 2024
2 parents 12453e6 + a1c826b commit a648c10
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
59 changes: 59 additions & 0 deletions lib/src/main/scala/spinal/lib/com/uart/TilelinkUartCtrl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package spinal.lib.com.uart

import spinal.core._
import spinal.core.fiber._
import spinal.lib._
import spinal.lib.bus.tilelink._
import spinal.lib.misc.InterruptNode

object TilelinkUartCtrl{
def getTilelinkSupport(proposed: bus.tilelink.M2sSupport) = bus.tilelink.SlaveFactory.getSupported(
addressWidth = addressWidth,
dataWidth = 32,
allowBurst = true,
proposed
)
def addressWidth = 6
}

case class TilelinkUartCtrl(config : UartCtrlMemoryMappedConfig, tilelinkParameter: BusParameter) extends Component{
val io = new Bundle{
val bus = slave(Bus(tilelinkParameter))
val uart = master(Uart(ctsGen = config.uartCtrlConfig.ctsGen, rtsGen = config.uartCtrlConfig.rtsGen))
val interrupt = out Bool()
}

val uartCtrl = new UartCtrl(config.uartCtrlConfig)
io.uart <> uartCtrl.io.uart

val busCtrl = new SlaveFactory(io.bus, false)
val bridge = uartCtrl.driveFrom32(busCtrl,config)
io.interrupt := bridge.interruptCtrl.interrupt
}


case class TilelinkUartFiber() extends Area{
val node = bus.tilelink.fabric.Node.slave()
val interrupt = InterruptNode.master()

var config = UartCtrlMemoryMappedConfig(
uartCtrlConfig = UartCtrlGenerics(),
initConfig = UartCtrlInitConfig(
baudrate = 115200,
dataLength = 7, // 8 bits
parity = UartParityType.NONE,
stop = UartStopType.ONE
)
)

val logic = Fiber build new Area{
node.m2s.supported.load(TilelinkUartCtrl.getTilelinkSupport(node.m2s.proposed))
node.s2m.none()

val core = TilelinkUartCtrl(config, node.bus.p)
core.io.bus <> node.bus
interrupt.flag := core.io.interrupt

val uart = core.io.uart.toIo()
}
}
4 changes: 4 additions & 0 deletions lib/src/main/scala/spinal/lib/misc/plugin/Fiber.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class FiberPlugin extends Area with Hostable {

var pluginEnabled = true
var host : PluginHost = null
val hostLock = Lock().retain()

val subservices = ArrayBuffer[Any]()
def addService[T](that : T) : T = {
Expand Down Expand Up @@ -55,11 +56,13 @@ class FiberPlugin extends Area with Hostable {
h.addService(this)
subservices.foreach(h.addService)
host = h
hostLock.release()
}

def during = new {
def setup[T: ClassTag](body: => T): Handle[T] = spinal.core.fiber.Fiber setup {
pluginEnabled generate {
hostLock.await()
host.rework(body)
}
}
Expand All @@ -68,6 +71,7 @@ class FiberPlugin extends Area with Hostable {
buildCount += 1
spinal.core.fiber.Fiber build {
pluginEnabled generate {
hostLock.await()
val ret = host.rework(body)
buildCount -= 1
if (buildCount == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ object Example2 extends App{

class DriverPlugin extends FiberPlugin {
lazy val sp = host[StatePlugin].logic.get
val lock = Lock()
val hostLockX = Lock()

// incrementBy will be set by others plugin at elaboration time
var incrementBy = 0
val logic = during build new Area {
lock.await()
hostLockX.await()
// Generate the incrementer hardware
sp.signal := sp.signal + incrementBy
}
Expand All @@ -74,14 +74,14 @@ object Example2 extends App{
// during setup { body } will run the body of code in the Fiber setup phase (it is before the Fiber build phase)
during setup {
// Prevent the DriverPlugin from executing its build's body (until release() is called)
dp.lock.retain()
dp.hostLock.retain()
}
val logic = during build new Area {
// Let's mutate DriverPlugin.incrementBy
dp.incrementBy += 1

// Allows the DriverPlugin to execute its build's body
dp.lock.release()
dp.hostLock.release()
}
}

Expand Down

0 comments on commit a648c10

Please sign in to comment.