reformat header
[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 Bit#(2) temp;
76 temp[1] = qspi.out.io_out.get[1];
77 temp[0] = qspi.out.io_out.get[0];
78 return temp;
79 endmethod
80 endinterface;
81 interface io_out_en = interface Get
82 method ActionValue#(Bit#(2)) get;
83 Bit#(2) temp;
84 temp[1] = qspi.out.io_out_en.get[1];
85 temp[0] = qspi.out.io_out_en.get[0];
86 return temp;
87 endmethod
88 endinterface;
89 interface io_in = interface Put
90 method Action put(Bit#(2) in);
91 Bit#(4) temp;
92 temp[3] = 0;
93 temp[2] = 0;
94 temp[1] = in[1];
95 temp[0] = in[0];
96 qspi.out.io_in.put(temp);
97 endmethod
98 endinterface;
99 interface clk_o = qspi.out.clk_o;
100 interface ncs_o = qspi.out.ncs_o;
101 endinterface;
102
103 interface slave = qspi.slave;
104
105 // 0=TOF, 1=SMF, 2=Threshold, 3=TCF, 4=TEF 5=request_ready
106 method Bit#(6) interrupts;
107 return qspi.interripts;
108 endmethod
109
110 endmodule
111 endpackage