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 /* ==== define the number of slow peripheral irqs ==== */
15 /*====== AXI4 Lite slave declarations =======*/
18 /*===========================*/
19 /*=== package imports ===*/
22 import ClientServer::*;
23 import Connectable::*;
26 /*=======================*/
27 /*===== Import the slow peripherals ====*/
36 import axiexpansion ::*;
41 /*=====================================*/
43 /*===== interface declaration =====*/
44 interface SP_dedicated_ios;
46 interface Get#(Bit#(67)) axiexp1_out;
47 interface Put#(Bit#(67)) axiexp1_in;
50 interface Ifc_slow_peripherals;
51 interface AXI4_Slave_IFC#(`ADDR,`DATA,`USERSPACE) axi_slave;
52 interface SP_dedicated_ios slow_ios;
54 method Bit#(1) msip_int;
55 method Bit#(1) mtip_int;
56 method Bit#(`DATA) mtime;
58 `ifdef PLIC method ActionValue#(Tuple2#(Bool,Bool)) intrpt_note; `endif
59 interface IOCellSide iocell_side; // mandatory interface
62 /*================================*/
64 function Tuple2#(Bool, Bit#(TLog#(Num_Slow_Slaves)))
65 fn_address_mapping (Bit#(`ADDR) addr);
67 if(addr>=`ClintBase && addr<=`ClintEnd)
68 return tuple2(True,fromInteger(valueOf(CLINT_slave_num)));
72 if(addr>=`PLICBase && addr<=`PLICEnd)
73 return tuple2(True,fromInteger(valueOf(Plic_slave_num)));
77 if(addr>=`AxiExp1Base && addr<=`AxiExp1End)
78 return tuple2(True,fromInteger(valueOf(AxiExp1_slave_num)));
82 return tuple2(False,?);
86 module mkslow_peripherals#(Clock fast_clock, Reset fast_reset,
87 Clock uart_clock, Reset uart_reset
88 `ifdef PWM_AXI4Lite ,Clock ext_pwm_clock `endif
89 )(Ifc_slow_peripherals);
90 Clock sp_clock <-exposeCurrentClock; // slow peripheral clock
91 Reset sp_reset <-exposeCurrentReset; // slow peripheral reset
93 /*======= Module declarations for each peripheral =======*/
96 Ifc_clint clint <- mkclint();
99 Ifc_PLIC_AXI plic <- mkplicperipheral();
100 Wire#(Bit#(TLog#(`INTERRUPT_PINS))) interrupt_id <- mkWire();
101 Vector#(`INTERRUPT_PINS, FIFO#(bit)) ff_gateway_queue <- replicateM(mkFIFO);
104 Ifc_AxiExpansion axiexp1 <- mkAxiExpansion();
106 Ifc_pinmux pinmux <- mkpinmux; // mandatory
107 /*=======================================================*/
109 AXI4_Lite_Fabric_IFC #(1, Num_Slow_Slaves, `ADDR, `DATA,`USERSPACE)
110 slow_fabric <- mkAXI4_Lite_Fabric(fn_address_mapping);
111 Ifc_AXI4Lite_AXI4_Bridge
112 bridge<-mkAXI4Lite_AXI4_Bridge(fast_clock,fast_reset);
114 mkConnection (bridge.axi4_lite_master, slow_fabric.v_from_masters [0]);
115 /*======= Slave connections to AXI4Lite fabric =========*/
118 mkConnection (slow_fabric.v_to_slaves
119 [fromInteger(valueOf(CLINT_slave_num))],
123 mkConnection (slow_fabric.v_to_slaves
124 [fromInteger(valueOf(Plic_slave_num))],
125 plic.axi4_slave_plic); //
128 mkConnection (slow_fabric.v_to_slaves
129 [fromInteger(valueOf(AxiExp1_slave_num))],
130 axiexp1.axi_slave); //
133 /*========== pinmux connections ============*/
136 rule rl_completion_msg_from_plic;
137 let id <- plic.intrpt_completion;
139 `ifdef verbose $display("Dequeing the FIFO -- PLIC Interrupt Serviced id: %d",id); `endif
142 for(Integer i=0; i <`NUM_INTERRUPTS; i=i+1) begin
143 rule deq_gateway_queue;
144 if(interrupt_id==fromInteger(i)) begin
145 ff_gateway_queue[i].deq;
146 `ifdef $display($time,"Dequeing the Interrupt request for ID: %d",i); `endif
151 /*=======================================================*/
152 /*=================== PLIC Connections ==================== */
154 /*TODO DMA interrupt need to be connected to the plic
155 for(Integer i=1; i<8; i=i+1) begin
157 rule rl_connect_dma_interrupts_to_plic;
158 if(dma.interrupt_to_processor[i-1]==1'b1) begin
159 ff_gateway_queue[i].enq(1);
160 plic.ifc_external_irq[i].irq_frm_gateway(True);
164 rule rl_connect_dma_interrupts_to_plic;
165 ff_gateway_queue[i].enq(0);
171 for(Integer i = 14; i < 20; i=i+1) begin
172 rule rl_connect_qspi0_to_plic;
174 if(qspi0.interrupts()[i-14]==1'b1) begin
175 ff_gateway_queue[i].enq(1);
176 plic.ifc_external_irq[i].irq_frm_gateway(True);
179 ff_gateway_queue[i].enq(0);
184 for(Integer i = 20; i<26; i=i+1) begin
185 rule rl_connect_qspi1_to_plic;
187 if(qspi1.interrupts()[i-20]==1'b1) begin
188 ff_gateway_queue[i].enq(1);
189 plic.ifc_external_irq[i].irq_frm_gateway(True);
192 ff_gateway_queue[i].enq(0);
198 SyncBitIfc#(Bit#(1)) uart0_interrupt <-
199 mkSyncBitToCC(sp_clock, uart_reset);
200 rule synchronize_the_uart0_interrupt;
201 uart0_interrupt.send(uart0.irq);
204 rule rl_connect_uart_to_plic;
206 if(uart0_interrupt.read==1'b1) begin
207 ff_gateway_queue[27].enq(1);
208 plic.ifc_external_irq[27].irq_frm_gateway(True);
212 ff_gateway_queue[27].enq(0);
216 for(Integer i = 28; i<`INTERRUPT_PINS; i=i+1) begin
217 rule rl_raise_interrupts;
218 if((i-28)<`IONum) begin //Peripheral interrupts
219 if(gpio.to_plic[i-28]==1'b1) begin
220 plic.ifc_external_irq[i].irq_frm_gateway(True);
221 ff_gateway_queue[i].enq(1);
227 rule rl_completion_msg_from_plic;
228 let id <- plic.intrpt_completion;
230 `ifdef verbose $display("Dequeing the FIFO -- PLIC Interrupt Serviced id: %d",id); `endif
233 for(Integer i=0; i <`INTERRUPT_PINS; i=i+1) begin
234 rule deq_gateway_queue;
235 if(interrupt_id==fromInteger(i)) begin
236 ff_gateway_queue[i].deq;
237 `ifdef $display($time,"Dequeing the Interrupt request for ID: %d",i); `endif
244 /*======================================================= */
246 /* ===== interface definition =======*/
247 interface axi_slave=bridge.axi_slave;
248 `ifdef PLIC method intrpt_note = plic.intrpt_note; `endif
250 method msip_int=clint.msip_int;
251 method mtip_int=clint.mtip_int;
252 method mtime=clint.mtime;
255 method i2c0_isint=i2c0.isint;
258 method i2c1_isint=i2c1.isint;
260 `ifdef QSPI0 method qspi0_isint=qspi0.interrupts[5]; `endif
261 `ifdef QSPI1 method qspi1_isint=qspi1.interrupts[5]; `endif
262 `ifdef UART0 method uart0_intr=uart0.irq; `endif
263 interface SP_dedicated_ios slow_ios;
264 /* template for dedicated peripherals
266 interface uart0_coe=uart0.coe_rs232;
269 interface uart1_coe=uart1.coe_rs232;
272 interface i2c0_out=i2c0.out;
275 interface i2c1_out=i2c1.out;
278 interface qspi0_out = qspi0.out;
281 interface qspi1_out = qspi1.out;
284 interface axiexp1_out=axiexp1.slave_out;
285 interface axiexp1_in=axiexp1.slave_in;
288 interface pwm_o = pwm_bus.pwm_io;
293 interface iocell_side=pinmux.iocell_side;
294 interface pad_config0= gpioa.pad_config;
297 /*===================================*/