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