{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "automatic-budget",
   "metadata": {},
   "source": [
    "<link rel=\"preconnect\" href=\"https://fonts.gstatic.com\">\n",
    "<link href=\"https://fonts.googleapis.com/css2?family=Fira+Code&display=swap\" rel=\"stylesheet\">\n",
    "\n",
    "### License\n",
    "\n",
    "<p style=\"font-family: 'Fira Code', monospace; font-size: 1.2rem\">\n",
    "Copyright 2022 Xilinx, Inc.<br><br>\n",
    "Licensed under the Apache License, Version 2.0 (the \"License\");<br>\n",
    "you may not use this file except in compliance with the License.<br><br>\n",
    "You may obtain a copy of the License at <a href=\"http://www.apache.org/licenses/LICENSE-2.0\"?>http://www.apache.org/licenses/LICENSE-2.0</a><br><br>\n",
    "Unless required by applicable law or agreed to in writing, software<br>\n",
    "distributed under the License is distributed on an \"AS IS\" BASIS,<br>\n",
    "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br>\n",
    "See the License for the specific language governing permissions and<br>\n",
    "limitations under the License.<br>\n",
    "</p>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "maritime-shock",
   "metadata": {},
   "source": [
    "# ChipScoPy VIO Example\n",
    "\n",
    "\n",
    "<img src=\"../img/api_overview.png\" width=\"500\" align=\"left\">"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "solid-rebel",
   "metadata": {},
   "source": [
    "## Description\n",
    "This example demonstrates how to program and communicate with\n",
    "VIO (Virtual IO) cores using the ChipScoPy Python API.\n",
    "\n",
    "\n",
    "## Requirements\n",
    "- Local or remote Xilinx Versal board, such as a VCK190\n",
    "- Xilinx hw_server 2022.1 installed and running\n",
    "- Xilinx cs_server 2022.1 installed and running\n",
    "- Python 3.8 or greater installed\n",
    "- ChipScoPy 2022.1 installed\n",
    "- Jupyter notebook support installed - Please do so, using the command `pip install chipscopy[jupyter]`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "noted-characterization",
   "metadata": {},
   "source": [
    "## 1 - Initialization: Imports and File Paths\n",
    "\n",
    "After this step,\n",
    "- Required functions and classes are imported\n",
    "- URL paths are set correctly\n",
    "- File paths to example files are set correctly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "amino-plaintiff",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from chipscopy import get_design_files\n",
    "from chipscopy import create_session, report_versions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "indonesian-relations",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HW_URL: TCP:localhost:3121\n",
      "CS_URL: TCP:localhost:3042\n",
      "PROGRAMMING_FILE: C:\\wrk\\chipscopy\\chipscopy-venv\\Lib\\site-packages\\chipscopy\\examples\\designs\\vck190\\production\\chipscopy_ced\\chipscopy_wrapper.pdi\n",
      "PROBES_FILE:C:\\wrk\\chipscopy\\chipscopy-venv\\Lib\\site-packages\\chipscopy\\examples\\designs\\vck190\\production\\chipscopy_ced\\chipscopy_wrapper.ltx\n"
     ]
    }
   ],
   "source": [
    "# Make sure to start the hw_server and cs_server prior to running.\n",
    "# Specify locations of the running hw_server and cs_server below.\n",
    "# The default is localhost - but can be other locations on the network.\n",
    "CS_URL = os.getenv(\"CS_SERVER_URL\", \"TCP:localhost:3042\")\n",
    "HW_URL = os.getenv(\"HW_SERVER_URL\", \"TCP:localhost:3121\")\n",
    "\n",
    "# The get_design_files() function tries to find the PDI and LTX files. In non-standard\n",
    "# configurations, you can put the path for PROGRAMMING_FILE and PROBES_FILE below.\n",
    "design_files = get_design_files(\"vck190/production/chipscopy_ced\")\n",
    "\n",
    "PROGRAMMING_FILE = design_files.programming_file\n",
    "PROBES_FILE = design_files.probes_file\n",
    "\n",
    "print(f\"HW_URL: {HW_URL}\")\n",
    "print(f\"CS_URL: {CS_URL}\")\n",
    "print(f\"PROGRAMMING_FILE: {PROGRAMMING_FILE}\")\n",
    "print(f\"PROBES_FILE:{PROBES_FILE}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "norwegian-wagner",
   "metadata": {},
   "source": [
    "## 2 - Create a session and connect to the hw_server and cs_server\n",
    "\n",
    "The session is a container that keeps track of devices and debug cores.\n",
    "After this step,\n",
    "- Session is initialized and connected to server(s)\n",
    "- Versions are detected and reported to stdout"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "front-conflict",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "\n",
       "</pre>\n"
      ],
      "text/plain": [
       "<rich.jupyter.JupyterRenderable at 0x11357439c40>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-style: italic\">                         ChipScoPy Version Information                          </span>\n",
       "┌────────────────────────────┬─────────────────────────────────────────────────┐\n",
       "│<span style=\"font-weight: bold\">                     Entity </span>│<span style=\"font-weight: bold\"> Version                                         </span>│\n",
       "├────────────────────────────┼─────────────────────────────────────────────────┤\n",
       "│                  ChipScoPy │ ┌───────────┬──────────────────────┐            │\n",
       "│                            │ │<span style=\"font-weight: bold\"> Attribute </span>│<span style=\"font-weight: bold\"> Value                </span>│            │\n",
       "│                            │ ├───────────┼──────────────────────┤            │\n",
       "│                            │ │     Build │ 2022.1.1654231490    │            │\n",
       "│                            │ │ Timestamp │ Jun 02 2022-22:44:50 │            │\n",
       "│                            │ └───────────┴──────────────────────┘            │\n",
       "│                            │                                                 │\n",
       "│ hw_server @ localhost:3121 │ ┌───────────┬─────────────────────────────────┐ │\n",
       "│                            │ │<span style=\"font-weight: bold\"> Attribute </span>│<span style=\"font-weight: bold\"> Value                           </span>│ │\n",
       "│                            │ ├───────────┼─────────────────────────────────┤ │\n",
       "│                            │ │    Status │ Connected                       │ │\n",
       "│                            │ │     Build │ 1641456835                      │ │\n",
       "│                            │ │   Version │ 2022.1                          │ │\n",
       "│                            │ │ Timestamp │ Thu 06 Jan 2022 08:13:55 AM UTC │ │\n",
       "│                            │ └───────────┴─────────────────────────────────┘ │\n",
       "│                            │                                                 │\n",
       "│ cs_server @ localhost:3042 │ ┌───────────────┬──────────────────────┐        │\n",
       "│                            │ │<span style=\"font-weight: bold\">     Attribute </span>│<span style=\"font-weight: bold\"> Value                </span>│        │\n",
       "│                            │ ├───────────────┼──────────────────────┤        │\n",
       "│                            │ │        Status │ Connected            │        │\n",
       "│                            │ │         Build │ 1649790728           │        │\n",
       "│                            │ │       Version │ 2022.1.0             │        │\n",
       "│                            │ │     Timestamp │ Apr 12 2022-13:12:08 │        │\n",
       "│                            │ │       Package │ 2022.1.1649790728    │        │\n",
       "│                            │ │ Artifact type │ pyinstaller          │        │\n",
       "│                            │ └───────────────┴──────────────────────┘        │\n",
       "└────────────────────────────┴─────────────────────────────────────────────────┘\n",
       "</pre>\n"
      ],
      "text/plain": [
       "<rich.jupyter.JupyterRenderable at 0x113572ec040>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "\n",
       "</pre>\n"
      ],
      "text/plain": [
       "<rich.jupyter.JupyterRenderable at 0x113572ec040>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "session = create_session(cs_server_url=CS_URL, hw_server_url=HW_URL)\n",
    "report_versions(session)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "after-region",
   "metadata": {},
   "source": [
    "## 3 - Program the device with the example design\n",
    "\n",
    "After this step,\n",
    "- Device is programmed with the example programming file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "chemical-hands",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "<span style=\"font-weight: bold\">--&gt; INFO: </span>Programming device with: C:\\wrk\\chipscopy\\chipscopy-venv\\Lib\\site-packages\\chipscop\n",
       "y\\examples\\designs\\vck190\\production\\chipscopy_ced\\chipscopy_wrapper.pdi\n",
       "    \n",
       "</pre>\n"
      ],
      "text/plain": [
       "<rich.jupyter.JupyterRenderable at 0x113574b24c0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "48fad4dbb5aa402695cdcc993e0239f4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Output()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Typical case - one device on the board - get it.\n",
    "device = session.devices.filter_by(family=\"versal\").get()\n",
    "device.program(PROGRAMMING_FILE)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "mineral-antarctica",
   "metadata": {},
   "source": [
    "## 4 - Discover Debug Cores\n",
    "\n",
    "Debug core discovery initializes the chipscope server debug cores. This brings debug cores in the chipscope server online.\n",
    "\n",
    "After this step,\n",
    "\n",
    "- The cs_server is initialized and ready for use\n",
    "- Debug cores in the cs_server may be accessed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "sapphire-constraint",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Debug cores setup and ready for use.\n"
     ]
    }
   ],
   "source": [
    "device.discover_and_setup_cores(ltx_file=PROBES_FILE)\n",
    "print(f\"Debug cores setup and ready for use.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "falling-gamma",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "source": [
    "## 5 - Using The VIO Core\n",
    "\n",
    "The following cells demonstrate how to perform various operations with the VIO core.\n",
    "These are meant to be useful code snippets that can be copy/pasted for your own application."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "423971bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       UUID                              INSTANCE NAME\n",
      "VIO-0  0E76DEFA789D564080CFA5332A88DB12  chipscopy_i/noc_tg_bc/noc_tg/inst/u_top_axi_mst/u_tg_top/gen_aximm_reg_space.u_reg_space/gen_vio_status_monitor.u_vio_status_monitor\n",
      "VIO-1  718A03DBCD265D969EA5C15840AEFD17  chipscopy_i/counters/vio_fast_counter_0\n",
      "VIO-2  22BC7ED6C4145AAB88C58EAEDFF2B04C  chipscopy_i/counters/vio_slow_counter_0\n",
      "VIO-3  021098F58FE659EFAD76657E635E53FE  chipscopy_i/noc_tg_bc/axis_vio_0\n"
     ]
    }
   ],
   "source": [
    "# Enumerate all VIO cores in the device.\n",
    "# Every VIO core has properties including a UUID and instance name.\n",
    "#\n",
    "# Print out the VIO core instance UUIDs and instance names\n",
    "# It is normal for this call to be slower the first time, and faster subsequent iterations.\n",
    "\n",
    "vio_cores = device.vio_cores\n",
    "print(\"       UUID                              INSTANCE NAME\")\n",
    "for index, vio_core in enumerate(vio_cores):\n",
    "    print(f\"VIO-{index}  {vio_core.core_info.uuid}  {vio_core.name}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "69b8d5dd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "vio_by_instance_name and vio_by_uuid match!\n"
     ]
    }
   ],
   "source": [
    "# You can get a VIO core by instance name or uuid\n",
    "vio_by_instance_name = device.vio_cores.get(name=\"chipscopy_i/counters/vio_slow_counter_0\")\n",
    "the_vio_uuid = vio_by_instance_name.uuid\n",
    "\n",
    "# Grab the same VIO by UUID and ensure it is the same core\n",
    "vio_by_uuid = device.vio_cores.get(uuid = the_vio_uuid)\n",
    "assert(vio_by_instance_name == vio_by_uuid)\n",
    "\n",
    "print(\"vio_by_instance_name and vio_by_uuid match!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c7f28079",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "VIO Port <---> Probe mapping:\n",
      "probe_in0 <-- chipscopy_i/counters/slow_counter_0_Q\n",
      "probe_out0 --> chipscopy_i/counters/slow_counter_0_CE\n",
      "probe_out1 --> chipscopy_i/counters/slow_counter_0_SCLR\n",
      "probe_out2 --> chipscopy_i/counters/slow_counter_0_UP\n",
      "probe_out3 --> chipscopy_i/counters/slow_counter_0_LOAD\n",
      "probe_out4 --> chipscopy_i/counters/slow_counter_0_L\n"
     ]
    }
   ],
   "source": [
    "# The VIO API knows the mapping between logical probes and ports on the VIO core.\n",
    "# The code below prints the probe to port mapping.\n",
    "\n",
    "vio = device.vio_cores.get(name=\"chipscopy_i/counters/vio_slow_counter_0\")\n",
    "\n",
    "print(\"VIO Port <---> Probe mapping:\")\n",
    "for probe in vio.probes:\n",
    "    if probe.direction == \"in\":\n",
    "        print(f\"{probe.port_name} <-- {probe.probe_name}\")\n",
    "    else:\n",
    "        print(f\"{probe.port_name} --> {probe.probe_name}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "52541381",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wrote 0x12345678 to chipscopy_i/counters/slow_counter_0_L\n",
      "Wrote 0x11223344 to probe_out4\n"
     ]
    }
   ],
   "source": [
    "# Writing values\n",
    "# Values may be written to the ouput ports or logical named probes.\n",
    "\n",
    "vio = device.vio_cores.get(name=\"chipscopy_i/counters/vio_slow_counter_0\")\n",
    "\n",
    "# Writing values to a logical named probes:\n",
    "vio.write_probes({\n",
    "    \"chipscopy_i/counters/slow_counter_0_L\": 0x12345678\n",
    "})\n",
    "print(\"Wrote 0x12345678 to chipscopy_i/counters/slow_counter_0_L\")\n",
    "\n",
    "# Writing the value to the same VIO port:\n",
    "vio.write_ports({\n",
    "    \"probe_out4\": 0x11223344\n",
    "})\n",
    "print(\"Wrote 0x11223344 to probe_out4\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a6a4579f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counter Value: 335050467, Activity: NNNRBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n",
      "Counter Value: 341425265, Activity: NNNNNRFFFBBBBBBBBBBBBBBBBBBBBBBB\n",
      "Counter Value: 347677156, Activity: NNNNNNNNRFBBBBBBBBBBBBBBBBBBBBBB\n"
     ]
    }
   ],
   "source": [
    "# Reading VIO probe values\n",
    "# Probes are the logical names mapped to VIO ports in the LTX file.\n",
    "\n",
    "vio = device.vio_cores.get(name=\"chipscopy_i/counters/vio_slow_counter_0\")\n",
    "vio.reset_vio()\n",
    "\n",
    "# Reading all probes at once and extracting one of interest returns a dictionary of probe data.\n",
    "#   value is returned as an integer\n",
    "#   activity is a string, one acivity per bit: N=None, R=Rising, F=Falling, B=Both\n",
    "all_probe_info = vio.read_probes()\n",
    "value = all_probe_info[\"chipscopy_i/counters/slow_counter_0_Q\"][\"value\"]\n",
    "activity = all_probe_info[\"chipscopy_i/counters/slow_counter_0_Q\"][\"activity\"]\n",
    "print(f\"Counter Value: {value}, Activity: {activity}\")\n",
    "\n",
    "# Reading from a single named logical probe\n",
    "# For convenience, you can ask specifically for one or more probes to reduce the data size.\n",
    "# The returned dictionary format is the same.\n",
    "one_probe_info = vio.read_probes(\"chipscopy_i/counters/slow_counter_0_Q\")\n",
    "value = one_probe_info[\"chipscopy_i/counters/slow_counter_0_Q\"][\"value\"]\n",
    "activity = one_probe_info[\"chipscopy_i/counters/slow_counter_0_Q\"][\"activity\"]\n",
    "print(f\"Counter Value: {value}, Activity: {activity}\")\n",
    "\n",
    "# Reading the same value directly from the VIO port \"probe_in0\" - mapped to the same counter\n",
    "port_info = vio.read_ports(\"probe_in0\")\n",
    "value = port_info[\"probe_in0\"][\"value\"]\n",
    "activity = port_info[\"probe_in0\"][\"activity\"]\n",
    "print(f\"Counter Value: {value}, Activity: {activity}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "67c9f09b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Reading probe values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "477a8f20",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "VIO core chipscopy_i/counters/vio_slow_counter_0 reset to initial values.\n"
     ]
    }
   ],
   "source": [
    "# Resetting the VIO core resets all output values to the their default.\n",
    "# Default values were optionally set during implementation as a property on the VIO IP.\n",
    "\n",
    "vio = device.vio_cores.get(name=\"chipscopy_i/counters/vio_slow_counter_0\")\n",
    "vio.reset_vio()\n",
    "print(f\"VIO core {vio} reset to initial values.\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "37b5430f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{   'core_info': {   'core_major_ver': 1,\n",
      "                     'core_minor_ver': 0,\n",
      "                     'core_type': 2,\n",
      "                     'drv_ver': 3,\n",
      "                     'tool_major_ver': 226,\n",
      "                     'tool_minor_ver': 0,\n",
      "                     'uuid': '22BC7ED6C4145AAB88C58EAEDFF2B04C'},\n",
      "    'input_ports': {'probe_in0': 32},\n",
      "    'instance': 'chipscopy_i/counters/vio_slow_counter_0',\n",
      "    'name': 'chipscopy_i/counters/vio_slow_counter_0',\n",
      "    'output_ports': {   'probe_out0': 1,\n",
      "                        'probe_out1': 1,\n",
      "                        'probe_out2': 1,\n",
      "                        'probe_out3': 1,\n",
      "                        'probe_out4': 32},\n",
      "    'probes': [   {   'bus_left_index': 31,\n",
      "                      'bus_right_index': 0,\n",
      "                      'direction': 'in',\n",
      "                      'is_bus': True,\n",
      "                      'port_bit_offset': 0,\n",
      "                      'port_index': 0,\n",
      "                      'probe_name': 'chipscopy_i/counters/slow_counter_0_Q'},\n",
      "                  {   'bus_left_index': 0,\n",
      "                      'bus_right_index': 0,\n",
      "                      'direction': 'out',\n",
      "                      'is_bus': False,\n",
      "                      'port_bit_offset': 0,\n",
      "                      'port_index': 0,\n",
      "                      'probe_name': 'chipscopy_i/counters/slow_counter_0_CE'},\n",
      "                  {   'bus_left_index': 0,\n",
      "                      'bus_right_index': 0,\n",
      "                      'direction': 'out',\n",
      "                      'is_bus': False,\n",
      "                      'port_bit_offset': 0,\n",
      "                      'port_index': 1,\n",
      "                      'probe_name': 'chipscopy_i/counters/slow_counter_0_SCLR'},\n",
      "                  {   'bus_left_index': 0,\n",
      "                      'bus_right_index': 0,\n",
      "                      'direction': 'out',\n",
      "                      'is_bus': False,\n",
      "                      'port_bit_offset': 0,\n",
      "                      'port_index': 2,\n",
      "                      'probe_name': 'chipscopy_i/counters/slow_counter_0_UP'},\n",
      "                  {   'bus_left_index': 0,\n",
      "                      'bus_right_index': 0,\n",
      "                      'direction': 'out',\n",
      "                      'is_bus': False,\n",
      "                      'port_bit_offset': 0,\n",
      "                      'port_index': 3,\n",
      "                      'probe_name': 'chipscopy_i/counters/slow_counter_0_LOAD'},\n",
      "                  {   'bus_left_index': 31,\n",
      "                      'bus_right_index': 0,\n",
      "                      'direction': 'out',\n",
      "                      'is_bus': True,\n",
      "                      'port_bit_offset': 0,\n",
      "                      'port_index': 4,\n",
      "                      'probe_name': 'chipscopy_i/counters/slow_counter_0_L'}],\n",
      "    'type': 'CoreType.AXIS_VIO'}\n"
     ]
    }
   ],
   "source": [
    "# You can access low level VIO properties as a dictionary or in json.\n",
    "# This gives easy python access to probe and port information.\n",
    "\n",
    "import pprint\n",
    "\n",
    "pp = pprint.PrettyPrinter(indent = 4)\n",
    "\n",
    "vio = device.vio_cores.get(name=\"chipscopy_i/counters/vio_slow_counter_0\")\n",
    "\n",
    "vio_dict = vio.to_dict()\n",
    "pp.pprint(vio_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "74dfa3ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "    \"core_info\": {\n",
      "        \"core_type\": 2,\n",
      "        \"drv_ver\": 3,\n",
      "        \"core_major_ver\": 1,\n",
      "        \"core_minor_ver\": 0,\n",
      "        \"tool_major_ver\": 226,\n",
      "        \"tool_minor_ver\": 0,\n",
      "        \"uuid\": \"22BC7ED6C4145AAB88C58EAEDFF2B04C\"\n",
      "    },\n",
      "    \"input_ports\": {\n",
      "        \"probe_in0\": 32\n",
      "    },\n",
      "    \"instance\": \"chipscopy_i/counters/vio_slow_counter_0\",\n",
      "    \"name\": \"chipscopy_i/counters/vio_slow_counter_0\",\n",
      "    \"output_ports\": {\n",
      "        \"probe_out0\": 1,\n",
      "        \"probe_out1\": 1,\n",
      "        \"probe_out2\": 1,\n",
      "        \"probe_out3\": 1,\n",
      "        \"probe_out4\": 32\n",
      "    },\n",
      "    \"probes\": [\n",
      "        {\n",
      "            \"probe_name\": \"chipscopy_i/counters/slow_counter_0_Q\",\n",
      "            \"direction\": \"in\",\n",
      "            \"is_bus\": true,\n",
      "            \"bus_left_index\": 31,\n",
      "            \"bus_right_index\": 0,\n",
      "            \"port_index\": 0,\n",
      "            \"port_bit_offset\": 0\n",
      "        },\n",
      "        {\n",
      "            \"probe_name\": \"chipscopy_i/counters/slow_counter_0_CE\",\n",
      "            \"direction\": \"out\",\n",
      "            \"is_bus\": false,\n",
      "            \"bus_left_index\": 0,\n",
      "            \"bus_right_index\": 0,\n",
      "            \"port_index\": 0,\n",
      "            \"port_bit_offset\": 0\n",
      "        },\n",
      "        {\n",
      "            \"probe_name\": \"chipscopy_i/counters/slow_counter_0_SCLR\",\n",
      "            \"direction\": \"out\",\n",
      "            \"is_bus\": false,\n",
      "            \"bus_left_index\": 0,\n",
      "            \"bus_right_index\": 0,\n",
      "            \"port_index\": 1,\n",
      "            \"port_bit_offset\": 0\n",
      "        },\n",
      "        {\n",
      "            \"probe_name\": \"chipscopy_i/counters/slow_counter_0_UP\",\n",
      "            \"direction\": \"out\",\n",
      "            \"is_bus\": false,\n",
      "            \"bus_left_index\": 0,\n",
      "            \"bus_right_index\": 0,\n",
      "            \"port_index\": 2,\n",
      "            \"port_bit_offset\": 0\n",
      "        },\n",
      "        {\n",
      "            \"probe_name\": \"chipscopy_i/counters/slow_counter_0_LOAD\",\n",
      "            \"direction\": \"out\",\n",
      "            \"is_bus\": false,\n",
      "            \"bus_left_index\": 0,\n",
      "            \"bus_right_index\": 0,\n",
      "            \"port_index\": 3,\n",
      "            \"port_bit_offset\": 0\n",
      "        },\n",
      "        {\n",
      "            \"probe_name\": \"chipscopy_i/counters/slow_counter_0_L\",\n",
      "            \"direction\": \"out\",\n",
      "            \"is_bus\": true,\n",
      "            \"bus_left_index\": 31,\n",
      "            \"bus_right_index\": 0,\n",
      "            \"port_index\": 4,\n",
      "            \"port_bit_offset\": 0\n",
      "        }\n",
      "    ],\n",
      "    \"type\": \"CoreType.AXIS_VIO\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "# The VIO properties can conveniently be accessed as JSON as well.\n",
    "# This is convenient when interfacing with other languages.\n",
    "vio = device.vio_cores.get(name=\"chipscopy_i/counters/vio_slow_counter_0\")\n",
    "vio_json = vio.to_json()\n",
    "print(vio_json)"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
