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