-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from denizkasap/gpio_virtualization
GPIO Virtualization.
- Loading branch information
Showing
12 changed files
with
989 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2023 EPFL | ||
# Solderpad Hardware License, Version 2.1, see LICENSE.md for details. | ||
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 | ||
# | ||
# Author: Deniz Kasap - deniz.kasap@epfl.ch | ||
|
||
# Import the X-HEEP Python class | ||
from pynq import x_heep | ||
import random | ||
|
||
# Load the X-HEEP bitstream | ||
x_heep = x_heep() | ||
|
||
# Compile the application | ||
x_heep.compile_app("virtual_gpio_read") | ||
|
||
# Write all ones to GPIO pins | ||
for gpio_pin in range(30): | ||
x_heep.GPIO_write(1, gpio_pin) | ||
|
||
# Run the application | ||
x_heep.run_app() | ||
|
||
# Verify the output | ||
stdout_path = "/home/xilinx/x-heep-femu-sdk/sw/riscv/build/stdout.txt" | ||
expected_output = "Read operation successful." | ||
f = open(stdout_path, "r") | ||
if f.read().strip() == expected_output: | ||
print("Test Passed!") | ||
else: | ||
print("Test Failed!") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2023 EPFL | ||
# Solderpad Hardware License, Version 2.1, see LICENSE.md for details. | ||
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 | ||
# | ||
# Author: Deniz Kasap - deniz.kasap@epfl.ch | ||
|
||
# Import the X-HEEP Python class | ||
from pynq import x_heep | ||
import random | ||
|
||
# Load the X-HEEP bitstream | ||
x_heep = x_heep() | ||
|
||
# Compile the application | ||
x_heep.compile_app("virtual_gpio_write") | ||
|
||
# Run the application | ||
x_heep.run_app() | ||
|
||
# Compare the results | ||
bit_array_read = "" | ||
bit_array_expected = "101010101010101010101010101010" | ||
|
||
for gpio_pin in range(30): | ||
pin_read = x_heep.GPIO_read(gpio_pin+8) | ||
bit_array_read += str(pin_read) | ||
print(bit_array_read) | ||
|
||
if bit_array_read == bit_array_expected: | ||
print("Test Passed!") | ||
else: | ||
print("Test Failed!") |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "63f1eaa7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Import the X-HEEP Python class\n", | ||
"from pynq import x_heep\n", | ||
"import random" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "2d224b64", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Load the X-HEEP bitstream\n", | ||
"x_heep = x_heep()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "538601e2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Compile the application\n", | ||
"x_heep.compile_app(\"virtual_gpio_read\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4fbcd989", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Write all ones to GPIO pins\n", | ||
"for gpio_pin in range(30):\n", | ||
" x_heep.GPIO_write(1, gpio_pin)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4ce20521", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Run the application\n", | ||
"x_heep.run_app()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9e9b1537", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Verify the output\n", | ||
"stdout_path = \"/home/xilinx/x-heep-femu-sdk/sw/riscv/build/stdout.txt\"\n", | ||
"expected_output = \"Read operation successful.\"\n", | ||
"f = open(stdout_path, \"r\")\n", | ||
"if f.read().strip() == expected_output:\n", | ||
" print(\"Test Passed!\")\n", | ||
"else:\n", | ||
" print(\"Test Failed!\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"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.10.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "63f1eaa7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Import the X-HEEP Python class\n", | ||
"from pynq import x_heep\n", | ||
"import random" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "2d224b64", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Load the X-HEEP bitstream\n", | ||
"x_heep = x_heep()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d6af7d95", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Compile the application\n", | ||
"x_heep.compile_app(\"virtual_gpio_write\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fd8e74c7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Run the application\n", | ||
"x_heep.run_app()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4fbcd989", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Compare the results\n", | ||
"bit_array_read = \"\"\n", | ||
"bit_array_expected = \"101010101010101010101010101010\"\n", | ||
"\n", | ||
"for gpio_pin in range(30):\n", | ||
" pin_read = x_heep.GPIO_read(gpio_pin+8)\n", | ||
" bit_array_read += str(pin_read)\n", | ||
"print(bit_array_read)\n", | ||
"\n", | ||
"if bit_array_read == bit_array_expected:\n", | ||
" print(\"Test Passed!\")\n", | ||
"else:\n", | ||
" print(\"Test Failed!\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"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.10.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "csr.h" | ||
#include "hart.h" | ||
#include "handler.h" | ||
#include "core_v_mini_mcu.h" | ||
#include "gpio.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
gpio_params_t gpio_params; | ||
gpio_t gpio; | ||
gpio_result_t gpio_res; | ||
|
||
//Start writing to GPIO of Always-On Peripheral [7:0] | ||
gpio_params.base_addr = mmio_region_from_addr((uintptr_t)GPIO_AO_START_ADDRESS); | ||
bool read_from_pin; | ||
|
||
for (int i=2; i < 8; i++){ //Skip first 2 GPIO's since they are alread used | ||
gpio_res = gpio_init(gpio_params, &gpio); | ||
gpio_res = gpio_input_enabled(&gpio, i, true); | ||
gpio_res = gpio_read(&gpio, i, &read_from_pin); | ||
if (read_from_pin != 1){ | ||
printf("An element does not match!"); | ||
printf("Not matching at GPIO-AO at pin %d", i); | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
|
||
//Start writing to GPIO of Peripheral [31:8] | ||
gpio_params.base_addr = mmio_region_from_addr((uintptr_t)GPIO_START_ADDRESS); | ||
|
||
for (int i=8; i < 32; i++){ | ||
gpio_res = gpio_init(gpio_params, &gpio); | ||
gpio_res = gpio_input_enabled(&gpio, i, true); | ||
gpio_res = gpio_read(&gpio, i, &read_from_pin); | ||
if (read_from_pin != 1){ | ||
printf("An element does not match!"); | ||
printf("Not matching at GPIO at pin %d", i); | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
|
||
printf("Read operation successful."); | ||
|
||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.