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