Created
April 5, 2019 15:31
-
-
Save schelleg/9d78a4b72032cde9133c6c6297514d9b to your computer and use it in GitHub Desktop.
PYNQ PR #842 Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Some Arduino IO testing for PR #842\n", | |
"\n", | |
"[Pull Request #842](https://github.com/Xilinx/PYNQ/pull/842)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"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.lib.arduino import Arduino_IO, ARDUINO_DIO_BASEADDR, ARDUINO_DIO_TRI_OFFSET\n", | |
"from pynq.overlays.base import BaseOverlay" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#### Load Base Overlay and create some pins" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"base = BaseOverlay(\"base.bit\")\n", | |
"ard_pin0_out = Arduino_IO(base.ARDUINO,0,'out')\n", | |
"ard_pin1_in = Arduino_IO(base.ARDUINO,1,'in')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#### Verify both IO instances are sharing the same Microblaze instance" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ard_pin0_out.microblaze is ard_pin1_in.microblaze" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#### Some testing - connected D0 and D1 with a jumper wirte" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Two pin test passed.\n" | |
] | |
} | |
], | |
"source": [ | |
"import random\n", | |
"\n", | |
"vals = [random.choice([0, 1]) for _ in range(100)]\n", | |
"\n", | |
"for v in vals:\n", | |
" ard_pin0_out.write(v)\n", | |
" assert ard_pin1_in.read() == v\n", | |
"\n", | |
"print(\"Two pin test passed.\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#### Some testing - instantiate them all and match expected tri register to real value" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Instantiate them all test passed.\n" | |
] | |
} | |
], | |
"source": [ | |
"for _ in range(100):\n", | |
"\n", | |
" all_io = [Arduino_IO(base.ARDUINO,i,random.choice(['in', 'out'])) for i in reversed(range(20))]\n", | |
"\n", | |
" expected_tri_bits = ['1' if io.direction == 'in' else '0' for io in all_io]\n", | |
" expected_tri_reg = int(\"\".join(expected_tri_bits), 2)\n", | |
" curr_tri_reg = all_io[0].microblaze.read_cmd(ARDUINO_DIO_BASEADDR + ARDUINO_DIO_TRI_OFFSET)\n", | |
" \n", | |
" assert curr_tri_reg == expected_tri_reg\n", | |
"print(\"Instantiate them all test passed.\")" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment