1 package slow_peripherals;
2 /*===== Project imports =====*/
3 import defined_types::*;
4 import AXI4_Lite_Fabric::*;
5 import AXI4_Lite_Types::*;
9 import AXI4Lite_AXI4_Bridge::*;
10 `include "instance_defines.bsv"
11 /* ==== define the AXI Addresses ==== */
13 /*====== AXI4 Lite slave declarations =======*/
16 /*===========================*/
17 /*=== package imports ===*/
20 import ClientServer::*;
21 import Connectable::*;
24 /*=======================*/
25 /*===== Import the slow peripherals ====*/
34 import axiexpansion ::*;
39 /*=====================================*/
41 /*===== interface declaration =====*/
42 interface SP_dedicated_ios;
44 interface Get#(Bit#(67)) axiexp1_out;
45 interface Put#(Bit#(67)) axiexp1_in;
48 interface Ifc_slow_peripherals;
49 interface AXI4_Slave_IFC#(`ADDR,`DATA,`USERSPACE) axi_slave;
50 interface SP_dedicated_ios slow_ios;
52 method Bit#(1) msip_int;
53 method Bit#(1) mtip_int;
54 method Bit#(`DATA) mtime;
56 `ifdef PLIC method ActionValue#(Tuple2#(Bool,Bool)) intrpt_note; `endif
57 interface IOCellSide iocell_side; // mandatory interface
60 /*================================*/
62 function Tuple2#(Bool, Bit#(TLog#(Num_Slow_Slaves)))
63 fn_address_mapping (Bit#(`ADDR) addr);
65 if(addr>=`ClintBase && addr<=`ClintEnd)
66 return tuple2(True,fromInteger(valueOf(CLINT_slave_num)));
70 if(addr>=`PLICBase && addr<=`PLICEnd)
71 return tuple2(True,fromInteger(valueOf(Plic_slave_num)));
75 if(addr>=`AxiExp1Base && addr<=`AxiExp1End)
76 return tuple2(True,fromInteger(valueOf(AxiExp1_slave_num)));
80 return tuple2(False,?);
84 module mkslow_peripherals#(Clock fast_clock, Reset fast_reset,
85 Clock uart_clock, Reset uart_reset
86 `ifdef PWM_AXI4Lite ,Clock ext_pwm_clock `endif
87 )(Ifc_slow_peripherals);
88 Clock sp_clock <-exposeCurrentClock; // slow peripheral clock
89 Reset sp_reset <-exposeCurrentReset; // slow peripheral reset
91 /*======= Module declarations for each peripheral =======*/
94 Ifc_clint clint <- mkclint();
97 Ifc_PLIC_AXI plic <- mkplicperipheral();
98 Wire#(Bit#(TLog#(`INTERRUPT_PINS))) interrupt_id <- mkWire();
99 Vector#(`INTERRUPT_PINS, FIFO#(bit)) ff_gateway_queue <- replicateM(mkFIFO);
102 Ifc_AxiExpansion axiexp1 <- mkAxiExpansion();
104 Ifc_pinmux pinmux <- mkpinmux; // mandatory
105 /*=======================================================*/
107 AXI4_Lite_Fabric_IFC #(1, Num_Slow_Slaves, `ADDR, `DATA,`USERSPACE)
108 slow_fabric <- mkAXI4_Lite_Fabric(fn_address_mapping);
109 Ifc_AXI4Lite_AXI4_Bridge
110 bridge<-mkAXI4Lite_AXI4_Bridge(fast_clock,fast_reset);
112 mkConnection (bridge.axi4_lite_master, slow_fabric.v_from_masters [0]);
113 /*======= Slave connections to AXI4Lite fabric =========*/
116 mkConnection (slow_fabric.v_to_slaves
117 [fromInteger(valueOf(CLINT_slave_num))],
121 mkConnection (slow_fabric.v_to_slaves
122 [fromInteger(valueOf(Plic_slave_num))],
123 plic.axi4_slave_plic); //
126 mkConnection (slow_fabric.v_to_slaves
127 [fromInteger(valueOf(AxiExp1_slave_num))],
128 axiexp1.axi_slave); //
131 /*========== pinmux connections ============*/
134 rule rl_completion_msg_from_plic;
135 let id <- plic.intrpt_completion;
137 `ifdef verbose $display("Dequeing the FIFO -- PLIC Interrupt Serviced id: %d",id); `endif
140 for(Integer i=0; i <`NUM_INTERRUPTS; i=i+1) begin
141 rule deq_gateway_queue;
142 if(interrupt_id==fromInteger(i)) begin
143 ff_gateway_queue[i].deq;
144 `ifdef $display($time,"Dequeing the Interrupt request for ID: %d",i); `endif
149 /*=======================================================*/
150 /*=================== PLIC Connections ==================== */
152 /*TODO DMA interrupt need to be connected to the plic
153 for(Integer i=1; i<8; i=i+1) begin
155 rule rl_connect_dma_interrupts_to_plic;
156 if(dma.interrupt_to_processor[i-1]==1'b1) begin
157 ff_gateway_queue[i].enq(1);
158 plic.ifc_external_irq[i].irq_frm_gateway(True);
162 rule rl_connect_dma_interrupts_to_plic;
163 ff_gateway_queue[i].enq(0);
169 for(Integer i = 14; i < 20; i=i+1) begin
170 rule rl_connect_qspi0_to_plic;
172 if(qspi0.interrupts()[i-14]==1'b1) begin
173 ff_gateway_queue[i].enq(1);
174 plic.ifc_external_irq[i].irq_frm_gateway(True);
177 ff_gateway_queue[i].enq(0);
182 for(Integer i = 20; i<26; i=i+1) begin
183 rule rl_connect_qspi1_to_plic;
185 if(qspi1.interrupts()[i-20]==1'b1) begin
186 ff_gateway_queue[i].enq(1);
187 plic.ifc_external_irq[i].irq_frm_gateway(True);
190 ff_gateway_queue[i].enq(0);
196 SyncBitIfc#(Bit#(1)) uart0_interrupt <-
197 mkSyncBitToCC(sp_clock, uart_reset);
198 rule synchronize_the_uart0_interrupt;
199 uart0_interrupt.send(uart0.irq);
202 rule rl_connect_uart_to_plic;
204 if(uart0_interrupt.read==1'b1) begin
205 ff_gateway_queue[27].enq(1);
206 plic.ifc_external_irq[27].irq_frm_gateway(True);
210 ff_gateway_queue[27].enq(0);
214 for(Integer i = 28; i<`INTERRUPT_PINS; i=i+1) begin
215 rule rl_raise_interrupts;
216 if((i-28)<`IONum) begin //Peripheral interrupts
217 if(gpio.to_plic[i-28]==1'b1) begin
218 plic.ifc_external_irq[i].irq_frm_gateway(True);
219 ff_gateway_queue[i].enq(1);
225 rule rl_completion_msg_from_plic;
226 let id <- plic.intrpt_completion;
228 `ifdef verbose $display("Dequeing the FIFO -- PLIC Interrupt Serviced id: %d",id); `endif
231 for(Integer i=0; i <`INTERRUPT_PINS; i=i+1) begin
232 rule deq_gateway_queue;
233 if(interrupt_id==fromInteger(i)) begin
234 ff_gateway_queue[i].deq;
235 `ifdef $display($time,"Dequeing the Interrupt request for ID: %d",i); `endif
242 /*======================================================= */
244 /* ===== interface definition =======*/
245 interface axi_slave=bridge.axi_slave;
246 `ifdef PLIC method intrpt_note = plic.intrpt_note; `endif
248 method msip_int=clint.msip_int;
249 method mtip_int=clint.mtip_int;
250 method mtime=clint.mtime;
253 method i2c0_isint=i2c0.isint;
256 method i2c1_isint=i2c1.isint;
258 `ifdef QSPI0 method qspi0_isint=qspi0.interrupts[5]; `endif
259 `ifdef QSPI1 method qspi1_isint=qspi1.interrupts[5]; `endif
260 `ifdef UART0 method uart0_intr=uart0.irq; `endif
261 interface SP_dedicated_ios slow_ios;
262 /* template for dedicated peripherals
264 interface uart0_coe=uart0.coe_rs232;
267 interface uart1_coe=uart1.coe_rs232;
270 interface i2c0_out=i2c0.out;
273 interface i2c1_out=i2c1.out;
276 interface qspi0_out = qspi0.out;
279 interface qspi1_out = qspi1.out;
282 interface axiexp1_out=axiexp1.slave_out;
283 interface axiexp1_in=axiexp1.slave_in;
286 interface pwm_o = pwm_bus.pwm_io;
291 interface iocell_side=pinmux.iocell_side;
292 interface pad_config0= gpioa.pad_config;
295 /*===================================*/