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

spinal.lib.com.uart.sim.UartEncoder.scala Maven / Gradle / Ivy

There is a newer version: 1.10.2a
Show newest version
package spinal.lib.com.uart.sim

import spinal.core.Bool
import spinal.core.sim._
import spinal.sim._

object UartEncoder {
  def apply(uartPin : Bool, baudPeriod : Long) = fork{
    uartPin #= true
    while(true) {
      if(System.in.available() != 0){
        val buffer = System.in.read()
        uartPin #= false
        sleep(baudPeriod)

        (0 to 7).foreach{ bitId =>
          uartPin #= ((buffer >> bitId) & 1) != 0
          sleep(baudPeriod)
        }

        uartPin #= true
        sleep(baudPeriod)
      } else {
        sleep(baudPeriod * 1000)
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy