From e12f9ef58cf4153725be65992c1935126aae8a9d Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 1 Aug 2018 12:49:17 +0100 Subject: [PATCH] AddingPeripherals.mdwn --- docs/AddingPeripherals.mdwn | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/docs/AddingPeripherals.mdwn b/docs/AddingPeripherals.mdwn index 38d8c4e..736a7c3 100644 --- a/docs/AddingPeripherals.mdwn +++ b/docs/AddingPeripherals.mdwn @@ -752,3 +752,79 @@ This generates *one* mkConnection for each multi-entry pintype, and here we match up with the "InterfaceMultiBus" class from the specification side, where pin entries with numerically matching names were "grouped" into single multi-bit declarations. + +## Adjusting the BSV Interface to a get/put style + +For various reasons, related to BSV not permitting wires to be connected +back-to-back inside the pinmux code, a get/put style of interface had to +be done. This requirement has a knock-on effect up the chain into the +actual peripheral code. So now the actual interface (Ifc\_sdram\_out) +has to be converted. All straight methods (outputs) are converted to Get, +and Action methods (inputs) converted to Put. Also, it is just plain +sensible not to use Bool but to use Bit#, and for the pack / unpack to +be carried out in the interface. After conversion, the code looks like this: + + interface Ifc_sdram_out; + (*always_enabled, always_ready*) + interface Put#(Bit#(64)) ipad_sdr_din; + interface Get#(Bit#(64)) osdr_dout; + interface Get#(Bit#(64)) osdr_den_n; + interface Get#(Bit#(1)) osdr_cke; + interface Get#(Bit#(1)) osdr_cs_n; + interface Get#(Bit#(1)) osdr_ras_n; + interface Get#(Bit#(1)) osdr_cas_n; + interface Get#(Bit#(1)) osdr_we_n; + interface Get#(Bit#(8)) osdr_dqm; + interface Get#(Bit#(2)) osdr_ba; + interface Get#(Bit#(13)) osdr_addr; + + method Bit#(9) sdram_sdio_ctrl; + interface Clock sdram_clk; + endinterface + +Note that osdr\_den\_n is now **64** bit **not** 8, as discussed above. +After conversion, the code looks like this: + + interface Ifc_sdram_out ifc_sdram_out; + + interface ipad_sdr_din = interface Put + method Action put(Bit#(64) in) + sdr_cntrl.ipad_sdr_din <= in; + endmethod + endinterface; + + interface osdr_dout = interface Get + method ActionValue#(Bit#(64)) get; + return sdr_cntrl.osdr_dout(); + endmethod + endinterface; + + interface osdr_den_n = interface Get + method ActionValue#(Bit#(64)) get; + Bit#(64) temp; + for (int i=0; i<8; i=i+1) begin + temp[i*8] = sdr_cntrl.osdr_den_n[i]; + end + return temp; + endmethod + endinterface; + + interface osdr_cke = interface Get + method ActionValue#(Bit#(1)) get; + return pack(sdr_cntrl.osdr_cke()); + endmethod + endinterface; + + ... + ... + + endinterface; + +Note that the data input is quite straightforward, as is data out, +and cke: whether 8-bit, 13-bit or 64-bit, the conversion process is +mundane, with only Bool having to be converted to Bit#(1) with a call +to pack. The data-enable however is a massive hack: whilst 64 enable +lines come in, only every 8th bit is actually utilised and passed +through. Whether this should be changed is a matter for debate that +is outside of the scope of this document. + -- 2.30.2