add QSPI-to-SPI wrapper
[shakti-peripherals.git] / src / peripherals / spi / spi.bsv
1 /*
2 Copyright (c) 2013, IIT Madras
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 * Neither the name of IIT Madras nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
13 */
14 package spi;
15 /*
16 TODOs
17 To use the following registers:
18 dcr_csht
19 * Done Pre-scaler.
20 > Memory mapped mode should continue to fetch data and fill the fifo even if the Core
21 is not requesting
22 * Done Status polling mode.
23 > This could not be replicated since the tof flag is set.
24 Memory mapped mode with dcyc =10 creates an extra cycle after Dummy phase.
25 > Data Read phase is on posedge and Data write is on negdege
26 -- send the received arid and bid's so that DMA can identify. duplicate instead of extend
27 */
28 import qspi::*;
29
30 (*always_ready, always_enabled*)
31 interface SPI_out;
32 interface Get#(Bit#(1)) clk_o;
33 interface Get#(Bit#(1)) io_out;
34 method Bit#(9) io0_sdio_ctrl;
35 method Bit#(9) io1_sdio_ctrl;
36 // index 0 is MOSI, index 1 is MISO.
37 interface Get#(Bit#(2)) io_out_en;
38 interface Put#(Bit#(2)) io_in;
39 interface Get#(Bit#(1)) ncs_o;
40 endinterface
41
42 interface Ifc_spi;
43 interface SPI_out out;
44 interface AXI4_Lite_Slave_IFC#(`PADDR,`Reg_width,`USERSPACE) slave;
45 // 0=TOF, 1=SMF, 2=Threshold, 3=TCF, 4=TEF 5 = request_ready
46 method Bit#(6) interrupts;
47 endinterface
48
49
50 (*synthesize*)
51 module mkspi(Ifc_spi);
52
53 Ifc_qspi qspi <- mkqspi();
54
55 interface SPI_out out;
56 method Bit#(9) io0_sdio_ctrl;
57 return qspi.out.io0_sdio_ctrl;
58 endmethod
59 method Bit#(9) io1_sdio_ctrl;
60 return qspi.out.io1_sdio_ctrl;
61 endmethod
62 interface io_out = interface Get
63 method ActionValue#(Bit#(2)) get;
64 return qspi.out.io_out[1:0];
65 endmethod
66 endinterface;
67 interface io_out_en = interface Get
68 method ActionValue#(Bit#(2)) get;
69 return qspi.out.io_out_en[1:0];
70 endmethod
71 endinterface;
72 interface io_in = interface Put
73 method Action put(Bit#(2) in);
74 Bit(#4) temp = { 0, 0, in[1], in[0] };
75 qspi.out.io_in(temp);
76 endmethod
77 endinterface;
78 interface clk_o = qspi.out.clk_o;
79 interface io_out = qspi.out.io_out;
80 interface io_out_en = qspi.out.io_out_en;
81 interface io_in = qspi.out.io_in;
82 interface ncs_o = qspi.ncs_o;
83 endinterface
84
85 interface slave = qspi.slave;
86
87 // 0=TOF, 1=SMF, 2=Threshold, 3=TCF, 4=TEF 5=request_ready
88 method Bit#(6) interrupts;
89 return qspi.interripts;
90 endmethod
91
92 endpackage