aa9007cdb4e53bd2bc6b570c2f8371bb8ef23246
[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 GetPut::*;
35 import qspi::*;
36 `include "instance_defines.bsv"
37
38
39 (*always_ready, always_enabled*)
40 interface SPI_out;
41 interface Get#(Bit#(1)) clk_o;
42 method Bit#(9) io0_sdio_ctrl;
43 method Bit#(9) io1_sdio_ctrl;
44 // index 0 is MOSI, index 1 is MISO.
45 interface Get#(Bit#(2)) io_out;
46 interface Get#(Bit#(2)) io_out_en;
47 interface Put#(Bit#(2)) io_in;
48 interface Get#(Bit#(1)) ncs_o;
49 endinterface
50
51 interface Ifc_spi;
52 interface SPI_out out;
53 interface AXI4_Lite_Slave_IFC#(`PADDR,`Reg_width,`USERSPACE) slave;
54 // 0=TOF, 1=SMF, 2=Threshold, 3=TCF, 4=TEF 5 = request_ready
55 method Bit#(6) interrupts;
56 endinterface
57
58
59 (*synthesize*)
60 module mkspi(Ifc_spi);
61
62 Ifc_qspi qspi <- mkqspi();
63
64 interface out = interface SPI_out
65 method Bit#(9) io0_sdio_ctrl;
66 return qspi.out.io0_sdio_ctrl;
67 endmethod
68 method Bit#(9) io1_sdio_ctrl;
69 return qspi.out.io1_sdio_ctrl;
70 endmethod
71 interface io_out = interface Get
72 method ActionValue#(Bit#(2)) get;
73 return qspi.out.io_out[1:0];
74 endmethod
75 endinterface;
76 interface io_out_en = interface Get
77 method ActionValue#(Bit#(2)) get;
78 return qspi.out.io_out_en[1:0];
79 endmethod
80 endinterface;
81 interface io_in = interface Put
82 method Action put(Bit#(2) in);
83 Bit#(4) temp;
84 temp[3] = 0;
85 temp[2] = 0;
86 temp[1] = in[1];
87 temp[0] = in[0];
88 qspi.out.io_in(temp);
89 endmethod
90 endinterface;
91 interface clk_o = qspi.out.clk_o;
92 interface ncs_o = qspi.ncs_o;
93 endinterface;
94
95 interface slave = qspi.slave;
96
97 // 0=TOF, 1=SMF, 2=Threshold, 3=TCF, 4=TEF 5=request_ready
98 method Bit#(6) interrupts;
99 return qspi.interripts;
100 endmethod
101
102 endmodule
103 endpackage