45288745eea84b817fef7043b1a10e5427f59eec
[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
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of IIT Madras nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 --------------------------------------------------------------------
30 */
31
32 package spi;
33
34 import qspi::*;
35
36 (*always_ready, always_enabled*)
37 interface SPI_out;
38 interface Get#(Bit#(1)) clk_o;
39 interface Get#(Bit#(1)) io_out;
40 method Bit#(9) io0_sdio_ctrl;
41 method Bit#(9) io1_sdio_ctrl;
42 // index 0 is MOSI, index 1 is MISO.
43 interface Get#(Bit#(2)) io_out_en;
44 interface Put#(Bit#(2)) io_in;
45 interface Get#(Bit#(1)) ncs_o;
46 endinterface
47
48 interface Ifc_spi;
49 interface SPI_out out;
50 interface AXI4_Lite_Slave_IFC#(`PADDR,`Reg_width,`USERSPACE) slave;
51 // 0=TOF, 1=SMF, 2=Threshold, 3=TCF, 4=TEF 5 = request_ready
52 method Bit#(6) interrupts;
53 endinterface
54
55
56 (*synthesize*)
57 module mkspi(Ifc_spi);
58
59 Ifc_qspi qspi <- mkqspi();
60
61 interface SPI_out out;
62 method Bit#(9) io0_sdio_ctrl;
63 return qspi.out.io0_sdio_ctrl;
64 endmethod
65 method Bit#(9) io1_sdio_ctrl;
66 return qspi.out.io1_sdio_ctrl;
67 endmethod
68 interface io_out = interface Get
69 method ActionValue#(Bit#(2)) get;
70 return qspi.out.io_out[1:0];
71 endmethod
72 endinterface;
73 interface io_out_en = interface Get
74 method ActionValue#(Bit#(2)) get;
75 return qspi.out.io_out_en[1:0];
76 endmethod
77 endinterface;
78 interface io_in = interface Put
79 method Action put(Bit#(2) in);
80 Bit(#4) temp = { 0, 0, in[1], in[0] };
81 qspi.out.io_in(temp);
82 endmethod
83 endinterface;
84 interface clk_o = qspi.out.clk_o;
85 interface io_out = qspi.out.io_out;
86 interface io_out_en = qspi.out.io_out_en;
87 interface io_in = qspi.out.io_in;
88 interface ncs_o = qspi.ncs_o;
89 endinterface
90
91 interface slave = qspi.slave;
92
93 // 0=TOF, 1=SMF, 2=Threshold, 3=TCF, 4=TEF 5=request_ready
94 method Bit#(6) interrupts;
95 return qspi.interripts;
96 endmethod
97
98 endpackage