From: Luke Kenneth Casson Leighton Date: Sun, 5 Aug 2018 10:31:08 +0000 (+0100) Subject: add emmc to slow_peripherals X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fdc4741e1c195b8e76ddcc2dbc45c6ffe319f614;p=pinmux.git add emmc to slow_peripherals --- diff --git a/docs/AddingPeripherals.mdwn b/docs/AddingPeripherals.mdwn index 359588f..a781c90 100644 --- a/docs/AddingPeripherals.mdwn +++ b/docs/AddingPeripherals.mdwn @@ -406,7 +406,7 @@ at the bottom of src/bsv/peripheral\_gen/base.py, in the "PFactory" for k, v in {'uart': uart, 'rs232': rs232, - 'sdr': sdram, + 'sdr': sdram, <-- 'twi': twi, 'quart': quart, @@ -988,7 +988,7 @@ fulfilled. Note that we did *not* declare in PinSpec that this peripheral is to be added onto the fastbus, as by default peripherals are added to a single AXI4-Lite interface. -## Adding the code auto-generators. +## Adding the pinmux code auto-generator The next phase begins with adding class support to auto-generate the pinmux code. Starting with the following command: @@ -1060,6 +1060,69 @@ it could understand that it had been passed 8-pins worth of data with exactly the same names, rather than 4. This is encouraging in the sense that re-using the SD/MMC BSV generation code should also be as easy. +## Adding the slow peripheral code-generator + +So this time we will try cut/pasting src/bsv/peripheral\_gen/sdmmc.py +to create a base class, MMCBase. The only two common functions are +pinname\_out and \_mk\_pincon. + +class MMCBase(PBase): + + def pinname_out(self, pname): + if pname in ['cmd', 'clk']: + return pname + return '' + + def _mk_pincon(self, name, count, typ): + ... + ... + +Then, the sdmmc class is modified to inherit it, this time cutting *out* +all but those two functions: + + from bsv.peripheral\_gen.mmcbase import MMCBase <-- + + class sdmmc(MMCBase): <-- + +And at the same time we create an emmc.py file where all occurrences of +sdmmc are replaced with emmc: + + class emmc(MMCBase): + + def slowimport(self): + return "import emmc_dummy :: *;" + + ... + ... + + def _mk_connection(self, name=None, count=0): + return "emmc{0}.slave" + +Finally, to use it, just as with sdram, we add the new peripheral +at the bottom of src/bsv/peripheral\_gen/base.py, in the "PFactory" +(Peripheral Factory) class: + + from gpio import gpio + from rgbttl import rgbttl + from flexbus import flexbus + from emmc import emmc <-- + + for k, v in {'uart': uart, + 'rs232': rs232, + 'emmc': emmc, <-- + +For the actual auto-generation phase, this really should be all that's +needed. Re-running the code-generator we can examine the auto-generated +slow\_peripherals.bsv file and can confirm that yes, an "import emmc\_dummy" +has been added, that an mmc0 instance has been created, that it is added +to the slave fabric, and that its cmd, clk and in/out/out\_en are all +connected up. + +The last remaining task will therefore be to create an interim emmc +"dummy" BSV file. + +## Creating the dummy emmc peripheral + # Conclusion This is not a small project, by any means. However the payoff in saved diff --git a/src/bsv/peripheral_gen/base.py b/src/bsv/peripheral_gen/base.py index e07ba18..b9fcdc5 100644 --- a/src/bsv/peripheral_gen/base.py +++ b/src/bsv/peripheral_gen/base.py @@ -985,6 +985,7 @@ class PFactory(object): from uart import uart from quart import quart from sdmmc import sdmmc + from emmc import emmc from pwm import pwm from eint import eint from rs232 import rs232 @@ -1010,6 +1011,7 @@ class PFactory(object): 'pwm': pwm, 'eint': eint, 'mmc': sdmmc, + 'emmc': emmc, 'jtag': jtag, 'lcd': rgbttl, 'fb': flexbus, diff --git a/src/bsv/peripheral_gen/emmc.py b/src/bsv/peripheral_gen/emmc.py new file mode 100644 index 0000000..3dea943 --- /dev/null +++ b/src/bsv/peripheral_gen/emmc.py @@ -0,0 +1,17 @@ +from bsv.peripheral_gen.mmcbase import MMCBase + + +class emmc(MMCBase): + + def slowimport(self): + return "import emmc_dummy :: *;" + + def num_axi_regs32(self): + return 13 + + def mkslow_peripheral(self): + return "Ifc_emmc_dummy emmc{0} <- mkemmc_dummy();" + + def _mk_connection(self, name=None, count=0): + return "emmc{0}.slave" + diff --git a/src/bsv/peripheral_gen/mmcbase.py b/src/bsv/peripheral_gen/mmcbase.py new file mode 100644 index 0000000..85d34de --- /dev/null +++ b/src/bsv/peripheral_gen/mmcbase.py @@ -0,0 +1,23 @@ +from bsv.peripheral_gen.base import PBase + + +class MMCBase(PBase): + + def pinname_out(self, pname): + if pname in ['cmd', 'clk']: + return pname + return '' + + def _mk_pincon(self, name, count, typ): + assert typ == 'slow', "TODO: mkConnection for fast" + ret = [PBase._mk_pincon(self, name, count, typ)] + # special-case for gpio in, store in a temporary vector + plen = len(self.peripheral.pinspecs) + template = "mkConnection({0}.{1},\n\t\t\t{2}.{1});" + sname = self.peripheral.iname().format(count) + name = self.get_iname(count) + ps = "pinmux.peripheral_side.%s" % sname + n = "{0}".format(name) + for ptype in ['out', 'out_en', 'in']: + ret.append(template.format(ps, ptype, n)) + return '\n'.join(ret) diff --git a/src/bsv/peripheral_gen/sdmmc.py b/src/bsv/peripheral_gen/sdmmc.py index dcdb57c..3497df6 100644 --- a/src/bsv/peripheral_gen/sdmmc.py +++ b/src/bsv/peripheral_gen/sdmmc.py @@ -1,7 +1,7 @@ -from bsv.peripheral_gen.base import PBase +from bsv.peripheral_gen.mmcbase import MMCBase -class sdmmc(PBase): +class sdmmc(MMCBase): def slowimport(self): return "import sdcard_dummy :: *;" @@ -15,21 +15,3 @@ class sdmmc(PBase): def _mk_connection(self, name=None, count=0): return "mmc{0}.slave" - def pinname_out(self, pname): - if pname in ['cmd', 'clk']: - return pname - return '' - - def _mk_pincon(self, name, count, typ): - assert typ == 'slow', "TODO: mkConnection for fast" - ret = [PBase._mk_pincon(self, name, count, typ)] - # special-case for gpio in, store in a temporary vector - plen = len(self.peripheral.pinspecs) - template = "mkConnection({0}.{1},\n\t\t\t{2}.{1});" - sname = self.peripheral.iname().format(count) - name = self.get_iname(count) - ps = "pinmux.peripheral_side.%s" % sname - n = "{0}".format(name) - for ptype in ['out', 'out_en', 'in']: - ret.append(template.format(ps, ptype, n)) - return '\n'.join(ret)