1/*************************************************************************************** 2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3* Copyright (c) 2020-2021 Peng Cheng Laboratory 4* 5* XiangShan is licensed under Mulan PSL v2. 6* You can use this software according to the terms and conditions of the Mulan PSL v2. 7* You may obtain a copy of Mulan PSL v2 at: 8* http://license.coscl.org.cn/MulanPSL2 9* 10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13* 14* See the Mulan PSL v2 for more details. 15***************************************************************************************/ 16 17package device 18 19import chisel3._ 20import chisel3.util._ 21import org.chipsalliance.cde.config.Parameters 22import freechips.rocketchip.diplomacy.AddressSet 23import utils._ 24import utility._ 25 26class KeyboardIO extends Bundle { 27 val ps2Clk = Input(Bool()) 28 val ps2Data = Input(Bool()) 29} 30 31// this Module is not tested 32class AXI4Keyboard 33( 34 address: Seq[AddressSet] 35)(implicit p: Parameters) 36 extends AXI4SlaveModule(address, executable = false, _extra = new KeyboardIO) 37{ 38 override lazy val module = new AXI4SlaveModuleImp[KeyboardIO](this){ 39 val buf = Reg(UInt(10.W)) 40 val ps2ClkLatch = RegNext(io.extra.get.ps2Clk) 41 val negedge = RegNext(ps2ClkLatch) && ~ps2ClkLatch 42 when (negedge) { buf := Cat(io.extra.get.ps2Data, buf(9,1)) } 43 44 val cnt = Counter(negedge, 10) 45 val queue = Module(new Queue(UInt(8.W), 8)) 46 queue.io.enq.valid := cnt._2 && !buf(0) && io.extra.get.ps2Data && buf(9,1).xorR 47 queue.io.enq.bits := buf(8,1) 48 queue.io.deq.ready := in.r.ready 49 50 in.r.bits.data := Mux(queue.io.deq.valid, queue.io.deq.bits, 0.U) 51 } 52 53} 54