Skip to content

Instantly share code, notes, and snippets.

@PeterOgden
Created September 28, 2018 11:01
Show Gist options
  • Save PeterOgden/5a873352381fc06c1e460ea357c0d21e to your computer and use it in GitHub Desktop.
Save PeterOgden/5a873352381fc06c1e460ea357c0d21e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Getting the Physical Address of a Live Frame\n",
"\n",
"This notebook shows how to remove the circular-buffer aspect of the VDMA and instead write to a constant frame address.\n",
"\n",
"First we need to import everything and set up the pipeline in the desired form. Note we do not start the pipelines at this point."
]
},
{
"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.overlays.base import BaseOverlay\n",
"from pynq.lib.video import *"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<contextlib._GeneratorContextManager at 0xac689c70>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"base = BaseOverlay('base.bit')\n",
"video = base.video\n",
"video.hdmi_in.configure(PIXEL_BGR)\n",
"video.hdmi_out.configure(video.hdmi_in.mode, PIXEL_BGR)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All of the operations we need to do are on the VDMA so lets get an easier handle to it."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"vdma = video.axi_vdma"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we need to start the read channel of the VDMA and park it on a particular frame - in the base overlay there are 4 frames to choose from (0-3)."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"vdma.readchannel.start()\n",
"vdma.readchannel.parked = True\n",
"vdma.readchannel.desiredframe = 0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we can pull out the frame from the internal `._frames` frame list."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"frame = vdma.readchannel._frames[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally we can start the write channel and tell it to write the specified frame. The write channel will be implicitly parked on this channel. We also need to remove the writechannel's ownership of the frame otherwise when the channels are stopped a double-free can occur as both channels think they own the frame."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"vdma.writechannel.start()\n",
"vdma.writechannel.writeframe(frame)\n",
"vdma.writechannel._frames.takeownership(vdma.writechannel.desiredframe)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We now have a NumPy array in the `frame` object and its physical address"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0x18100000\n"
]
}
],
"source": [
"print(hex(frame.physical_address))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To clean up we need to stop the DMA channels"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"vdma.writechannel.stop()\n",
"vdma.readchannel.stop()"
]
}
],
"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