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