From d9c752164644ebdbf7f96e4cd7d96661d1276a34 Mon Sep 17 00:00:00 2001 From: Peter Ogden Date: Fri, 22 Feb 2019 16:11:40 +0000 Subject: [PATCH] Add register map text to the overlay tutorial (#821) --- .../overlay_tutorial.ipynb | 175 ++++++++++++------ 1 file changed, 114 insertions(+), 61 deletions(-) diff --git a/docs/source/overlay_design_methodology/overlay_tutorial.ipynb b/docs/source/overlay_design_methodology/overlay_tutorial.ipynb index ae24a36592..2f0cfb55d3 100644 --- a/docs/source/overlay_design_methodology/overlay_tutorial.ipynb +++ b/docs/source/overlay_design_methodology/overlay_tutorial.ipynb @@ -45,10 +45,26 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": true - }, - "outputs": [], + "metadata": {}, + "outputs": [ + { + "data": { + "application/javascript": [ + "\n", + "require(['notebook/js/codecell'], function(codecell) {\n", + " codecell.CodeCell.options_default.highlight_modes[\n", + " 'magic_text/x-csrc'] = {'reg':[/^%%microblaze/]};\n", + " Jupyter.notebook.events.one('kernel_ready.Kernel', function(){\n", + " Jupyter.notebook.get_cells().map(function(cell){\n", + " if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;\n", + " });\n", + "});\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from pynq import Overlay\n", "\n", @@ -66,7 +82,6 @@ "cell_type": "code", "execution_count": 2, "metadata": { - "collapsed": true, "scrolled": true }, "outputs": [], @@ -85,7 +100,6 @@ "cell_type": "code", "execution_count": 3, "metadata": { - "collapsed": true, "scrolled": true }, "outputs": [], @@ -98,7 +112,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Reading the source code generated by HLS tells us that use the core we need to write the two arguments to offset `0x10` and `0x18` and read the result back from `0x20`." + "By providing the HWH file along with overlay we can also expose the register map associated with IP." ] }, { @@ -109,7 +123,12 @@ { "data": { "text/plain": [ - "9" + "RegisterMap {\n", + " a = Register(a=0),\n", + " b = Register(b=0),\n", + " c = Register(c=0),\n", + " c_ctrl = Register(c_ap_vld=1, RESERVED=0)\n", + "}" ] }, "execution_count": 4, @@ -117,6 +136,62 @@ "output_type": "execute_result" } ], + "source": [ + "add_ip.register_map" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can interact with the IP using the register map directly" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Register(c=7)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "add_ip.register_map.a = 3\n", + "add_ip.register_map.b = 4\n", + "add_ip.register_map.c" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Alternatively by reading the driver source code generated by HLS we can determine that offsets we need to write the two arguments are at offsets `0x10` and `0x18` and the result can be read back from `0x20`." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "add_ip.write(0x10, 4)\n", "add_ip.write(0x18, 5)\n", @@ -134,10 +209,8 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": true - }, + "execution_count": 7, + "metadata": {}, "outputs": [], "source": [ "from pynq import DefaultIP\n", @@ -163,10 +236,8 @@ }, { "cell_type": "code", - "execution_count": 6, - "metadata": { - "collapsed": true - }, + "execution_count": 8, + "metadata": {}, "outputs": [], "source": [ "overlay = Overlay('/home/xilinx/tutorial_1.bit')\n", @@ -182,7 +253,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -191,7 +262,7 @@ "35" ] }, - "execution_count": 7, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -215,10 +286,8 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": { - "collapsed": true - }, + "execution_count": 10, + "metadata": {}, "outputs": [], "source": [ "overlay = Overlay('/home/xilinx/tutorial_2.bit')\n", @@ -261,10 +330,8 @@ }, { "cell_type": "code", - "execution_count": 9, - "metadata": { - "collapsed": true - }, + "execution_count": 11, + "metadata": {}, "outputs": [], "source": [ "class ConstantMultiplyDriver(DefaultIP):\n", @@ -291,10 +358,8 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": { - "collapsed": true - }, + "execution_count": 12, + "metadata": {}, "outputs": [], "source": [ "import pynq.lib.dma\n", @@ -314,7 +379,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -323,7 +388,7 @@ "ContiguousArray([ 0, 3, 6, 9, 12], dtype=uint32)" ] }, - "execution_count": 11, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -361,10 +426,8 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": true - }, + "execution_count": 14, + "metadata": {}, "outputs": [], "source": [ "from pynq import DefaultHierarchy\n", @@ -405,10 +468,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": true - }, + "execution_count": 15, + "metadata": {}, "outputs": [], "source": [ "overlay = Overlay('/home/xilinx/tutorial_2.bit')\n", @@ -424,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -433,7 +494,7 @@ "ContiguousArray([ 5, 10, 15, 20, 25], dtype=uint32)" ] }, - "execution_count": 14, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -453,10 +514,8 @@ }, { "cell_type": "code", - "execution_count": 15, - "metadata": { - "collapsed": true - }, + "execution_count": 17, + "metadata": {}, "outputs": [], "source": [ "base = Overlay('base.bit')\n", @@ -477,10 +536,8 @@ }, { "cell_type": "code", - "execution_count": 16, - "metadata": { - "collapsed": true - }, + "execution_count": 18, + "metadata": {}, "outputs": [], "source": [ "from pynq.overlays.base import BaseOverlay\n", @@ -498,10 +555,8 @@ }, { "cell_type": "code", - "execution_count": 17, - "metadata": { - "collapsed": true - }, + "execution_count": 19, + "metadata": {}, "outputs": [], "source": [ "base?" @@ -518,10 +573,8 @@ }, { "cell_type": "code", - "execution_count": 18, - "metadata": { - "collapsed": true - }, + "execution_count": 20, + "metadata": {}, "outputs": [], "source": [ "class TestOverlay(Overlay):\n", @@ -541,7 +594,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -550,7 +603,7 @@ "ContiguousArray([ 8, 12, 16, 20, 24], dtype=uint32)" ] }, - "execution_count": 19, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -598,7 +651,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.3" + "version": "3.6.5" } }, "nbformat": 4,