diff --git a/README.md b/README.md index fae9f76cf583a6cc8b271baf618799b247466957..763a413beb8ae2055c72c86bdde2cdc49afaee37 100644 --- a/README.md +++ b/README.md @@ -385,6 +385,45 @@ fi run custom_autoboot" > uenv.scr.txt ``` +With DHCP for User Firmware + +``` +$ echo -e "echo [INFO] ===== Scalp board boot settings =====; +echo [INFO] Setup MAC address and IP address; +run setup_eth; +setenv boot_from_qspi \"ubi part \${UBI_PART_NAME} && ubifsmount \${UBI_PART_ID}:\${UBI_DATAFS_VOL_NAME} && ubifsload \${UBI_VOL_LOAD_ADDR} /\${KERNEL_FIT_IMAGE_NAME} && ubifsumount && ubi detach && iminfo \${UBI_VOL_LOAD_ADDR} && bootm \${UBI_VOL_LOAD_ADDR}\"; +setenv boot_from_mmc \"bootm \${loadaddr}\" +setenv bootargs_ubifs \"\${mtdparts} ubi.mtd=1 root=ubi0:rootfs-vol rootfstype=ubifs rw earlyprintk cpuidle.off=1 crashkernel=256M uio_pdrv_genirq.of_id=generic-uio ip=\${ipaddr}:::::eth0\" +setenv bootargs_ext4 \"\${mtdparts} root=/dev/mmcblk0p2 rootfstype=ext4 rw rootwait earlyprintk cpuidle.off=1 crashkernel=256M uio_pdrv_genirq.of_id=generic-uio ip=dhcp:::::eth0\" +setenv custom_autoboot \"echo Scalp board autoboot from QSPI && run boot_from_qspi\" +setenv bootcmd \"run spi_init && run uenv_scr_load\"; +echo [INFO] Check if the file /\${KERNEL_FIT_IMAGE_NAME} exists; +if ext4load mmc 0:1 \${loadaddr} /\${KERNEL_FIT_IMAGE_NAME} ; then +echo [INFO] \${KERNEL_FIT_IMAGE_NAME} found; +echo [INFO] Check if the file /init exists; +if ext4load mmc 0:2 \${initloadaddr} /init ; then +echo [INFO] /init found; +echo [INFO] Config bootargs for MMC EXT4; +setenv bootargs \"\${mtdparts} root=/dev/mmcblk0p2 rootfstype=ext4 rw rootwait earlyprintk cpuidle.off=1 crashkernel=256M uio_pdrv_genirq.of_id=generic-uio ip=dhcp:::::eth0\"; +echo [INFO] Config boot mode from MMC; +setenv custom_autoboot \"echo Scalp board autoboot from MMC && run boot_from_mmc\"; +else +echo [INFO] init not found; +echo [INFO] Config bootargs for UBI/UBIFS; +setenv bootargs \"\${mtdparts} ubi.mtd=1 root=ubi0:rootfs-vol rootfstype=ubifs rw earlyprintk cpuidle.off=1 crashkernel=256M uio_pdrv_genirq.of_id=generic-uio ip=\${ipaddr}:::::eth0\"; +echo [INFO] Config boot mode from SPI NOR; +setenv custom_autoboot \"echo Scalp board autoboot from QSPI && run boot_from_qspi\"; +fi +else +echo [INFO] /\${KERNEL_FIT_IMAGE_NAME} not found; +echo [INFO] Config bootargs for UBI/UBIFS; +setenv bootargs \"\${mtdparts} ubi.mtd=1 root=ubi0:rootfs-vol rootfstype=ubifs rw earlyprintk cpuidle.off=1 crashkernel=256M uio_pdrv_genirq.of_id=generic-uio ip=\${ipaddr}:::::eth0\"; +echo [INFO] Config boot mode from SPI NOR; +setenv custom_autoboot \"echo Scalp board autoboot from QSPI && run boot_from_qspi\"; +fi +run custom_autoboot" > uenv.scr.txt +``` + ``` $ ../../../tools/u-boot-tools/mkimage -T script -C none -n 'Scalp U-Boot Script File' -A arm -d uenv.scr.txt uenv.scr ``` diff --git a/bsp/SCALP-ROUTER-FIRMWARE-BSP-V0.1.bsp b/bsp/SCALP-ROUTER-FIRMWARE-BSP-V0.1.bsp new file mode 100644 index 0000000000000000000000000000000000000000..34a9df01bd90f262534d10de5410b20f14f2bc1f Binary files /dev/null and b/bsp/SCALP-ROUTER-FIRMWARE-BSP-V0.1.bsp differ diff --git a/scalp_router_firmware_petalinux/.petalinux/metadata b/scalp_router_firmware_petalinux/.petalinux/metadata index 787744ad2dc83529915f39d5a8d2dd6a3eef6929..44c72fc697dfdefaaac7a9b3fb17f54610f8e244 100644 --- a/scalp_router_firmware_petalinux/.petalinux/metadata +++ b/scalp_router_firmware_petalinux/.petalinux/metadata @@ -1,5 +1,6 @@ PETALINUX_VER=2020.2 VALIDATE_HW_CHKSUM=1 -HARDWARE_CHECKSUM=59c7f9b9ce074eccc39c685baf22b9c8 +HARDWARE_CHECKSUM=de7ad126b920e49a3bd0b3db07874706 YOCTO_SDK=5ff8fc5f85d1566b314bb73eaa378212 -RFSCONFIG_CHKSUM=68e7a39ee8a3ea7b75a4d172a70a3a69 +RFSCONFIG_CHKSUM=e658a66255d397f49ad8494748910c66 +HARDWARE_PATH=/home/jo/Documents/Projets/Hepia/scalp_project/scalp_firmware/designs/vivado/scalp_router_firmware/2020.2/lin64/scalp_router_firmware/scalp_router_firmware.xsa diff --git a/scalp_router_firmware_petalinux/SCALP-ROUTER-FIRMWARE-BSP-V0.1.bsp b/scalp_router_firmware_petalinux/SCALP-ROUTER-FIRMWARE-BSP-V0.1.bsp new file mode 100644 index 0000000000000000000000000000000000000000..34a9df01bd90f262534d10de5410b20f14f2bc1f Binary files /dev/null and b/scalp_router_firmware_petalinux/SCALP-ROUTER-FIRMWARE-BSP-V0.1.bsp differ diff --git a/scalp_router_firmware_petalinux/project-spec/configs/config b/scalp_router_firmware_petalinux/project-spec/configs/config index 0f1aa3dd1a22447e63b4ca44668d7b1197cd201e..aaea5216d4c97c5ffe10e2659db3a87992c33cc8 100644 --- a/scalp_router_firmware_petalinux/project-spec/configs/config +++ b/scalp_router_firmware_petalinux/project-spec/configs/config @@ -26,7 +26,7 @@ CONFIG_SUBSYSTEM_COMPONENT_LINUX__KERNEL_NAME_LINUX__XLNX=y CONFIG_SUBSYSTEM_AUTOCONFIG_DEVICE__TREE=y # CONFIG_SUBSYSTEM_DEVICE_TREE_MANUAL_INCLUDE is not set # CONFIG_SUBSYSTEM_AUTOCONFIG_KERNEL is not set -CONFIG_SUBSYSTEM_AUTOCONFIG_U__BOOT=y +# CONFIG_SUBSYSTEM_AUTOCONFIG_U__BOOT is not set CONFIG_SUBSYSTEM_HARDWARE_AUTO=y CONFIG_SUBSYSTEM_PROCESSOR0_IP_NAME="ps7_cortexa9_0" CONFIG_SUBSYSTEM_PROCESSOR_ps7_cortexa9_0_SELECT=y @@ -182,8 +182,6 @@ CONFIG_FPGA_HW_PATH="" # u-boot Configuration # CONFIG_SUBSYSTEM_UBOOT_CONFIG_TARGET="xilinx_zynq_virt_defconfig" -CONFIG_SUBSYSTEM_NETBOOT_OFFSET=0x1000000 -CONFIG_SUBSYSTEM_U__BOOT_TFTPSERVER_IP="AUTO" # CONFIG_SUBSYSTEM_UBOOT_EXT_DTB is not set # @@ -209,9 +207,9 @@ CONFIG_SUBSYSTEM_TFTPBOOT_DIR="/tftpboot" # # Firmware Version Configuration # -CONFIG_SUBSYSTEM_HOSTNAME="scalp_safe_petalinux" -CONFIG_SUBSYSTEM_PRODUCT="scalp_safe_petalinux" -CONFIG_SUBSYSTEM_FW_VERSION="1.00" +CONFIG_SUBSYSTEM_HOSTNAME="scalp_router_firmware_petalinux" +CONFIG_SUBSYSTEM_PRODUCT="scalp_router_firmware_petalinux" +CONFIG_SUBSYSTEM_FW_VERSION="0.10" # # Yocto Settings diff --git a/scalp_router_firmware_petalinux/project-spec/configs/rootfs_config b/scalp_router_firmware_petalinux/project-spec/configs/rootfs_config index 310f14b90083ce4502f7d999a66a03a201aa6964..40672bce213235f390c555aa6f02a777d6aaf5b2 100644 --- a/scalp_router_firmware_petalinux/project-spec/configs/rootfs_config +++ b/scalp_router_firmware_petalinux/project-spec/configs/rootfs_config @@ -4026,15 +4026,22 @@ CONFIG_bitstream-conf=y CONFIG_bitstream-init=y # CONFIG_gpio-demo is not set # CONFIG_peekpoke is not set +# CONFIG_sampleapp is not set +CONFIG_sampleread=y +CONFIG_samplewrite=y +# CONFIG_scalp-lib is not set +# CONFIG_scalp-locaddr is not set +CONFIG_scalplocaddr=y CONFIG_sja1105-conf=y CONFIG_sja1105-init=y # # user packages # +CONFIG_libscalp=y # # PetaLinux RootFS Settings # -CONFIG_ROOTFS_ROOT_PASSWD="root" -CONFIG_ADD_EXTRA_USERS="petalinux:petalinux;" +CONFIG_ROOTFS_ROOT_PASSWD="scalp_router" +CONFIG_ADD_EXTRA_USERS="scalp_router:scalp_router;" diff --git a/scalp_router_firmware_petalinux/project-spec/configs/u-boot-xlnx/platform-auto.h b/scalp_router_firmware_petalinux/project-spec/configs/u-boot-xlnx/platform-auto.h index 16b4f360eeb5412701432ac13900bb56aa53411f..d66e74f31fb7fc972cb1d6ac4eec32522aa317df 100644 --- a/scalp_router_firmware_petalinux/project-spec/configs/u-boot-xlnx/platform-auto.h +++ b/scalp_router_firmware_petalinux/project-spec/configs/u-boot-xlnx/platform-auto.h @@ -35,7 +35,7 @@ #define CONFIG_MII #define CONFIG_NET_MULTI #define CONFIG_NETCONSOLE 1 -#define CONFIG_SERVERIP 10.136.135.67 +#define CONFIG_SERVERIP 10.136.133.100 #define CONFIG_IPADDR 192.168.0.10 #define CONFIG_GATEWAYIP 192.168.0.1 #define CONFIG_NETMASK 255.255.255.0 diff --git a/scalp_router_firmware_petalinux/project-spec/hw-description/scalp_router_firmware.bit b/scalp_router_firmware_petalinux/project-spec/hw-description/scalp_router_firmware.bit new file mode 100644 index 0000000000000000000000000000000000000000..bd8332a1f46259a07967b24acc3ac5364e20ba07 Binary files /dev/null and b/scalp_router_firmware_petalinux/project-spec/hw-description/scalp_router_firmware.bit differ diff --git a/scalp_router_firmware_petalinux/project-spec/hw-description/system.xsa b/scalp_router_firmware_petalinux/project-spec/hw-description/system.xsa index d461f7119ebc8bf932f04023de7d5e5fde89a922..b629939e32c6e810cf5555b1f58d71d8de1d19c1 100644 Binary files a/scalp_router_firmware_petalinux/project-spec/hw-description/system.xsa and b/scalp_router_firmware_petalinux/project-spec/hw-description/system.xsa differ diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/conf/user-rootfsconfig b/scalp_router_firmware_petalinux/project-spec/meta-user/conf/user-rootfsconfig index a31c7cda48ce9c38e14fe43553117c0ce9590b37..1610a2ddf1d0fc7c9f139107d2fde97dc45ef2cc 100644 --- a/scalp_router_firmware_petalinux/project-spec/meta-user/conf/user-rootfsconfig +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/conf/user-rootfsconfig @@ -7,3 +7,10 @@ CONFIG_sja1105-init CONFIG_sja1105-conf CONFIG_bitstream-init CONFIG_bitstream-conf +CONFIG_scalp-lib +CONFIG_libscalp +CONFIG_sampleapp +CONFIG_samplewrite +CONFIG_sampleread +CONFIG_scalp-locaddr +CONFIG_scalplocaddr diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/bitstream-conf/files/bitstream-conf b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/bitstream-conf/files/bitstream-conf index 58493068002416eef318d024d21644083f5fa3bd..40126691ac7e52f572a7b354f3823503cdf5836c 100644 --- a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/bitstream-conf/files/bitstream-conf +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/bitstream-conf/files/bitstream-conf @@ -2,7 +2,7 @@ export FIRMWARE_FOLDER_PATH="/lib/firmware/" export FIRMWARE_BASE_FOLDER_PATH=${FIRMWARE_FOLDER_PATH}"base/" -export BITSTREAM_FILE_NAME="scalp_user_firmware.bit.bin" +export BITSTREAM_FILE_NAME="scalp_router_firmware.bit.bin" export BITSTREAM_PATH=${FIRMWARE_FOLDER_PATH}${BITSTREAM_FILE_NAME} export BITSTREAM_BASE_PATH=${FIRMWARE_BASE_FOLDER_PATH}${BITSTREAM_FILE_NAME} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/.gdbinit b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/.gdbinit new file mode 100644 index 0000000000000000000000000000000000000000..d59fb8d90efb393c83d35becbecddcfa493a5e67 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/.gdbinit @@ -0,0 +1,2 @@ +# Load the PetaLinux SDK main gdbinit script +source plnx_gdbinit diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/README b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/README new file mode 100644 index 0000000000000000000000000000000000000000..fc736e61e5a2bb779eace062e0719eb7925c753e --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/README @@ -0,0 +1,32 @@ +PetaLinux User Application Template +=================================== + +This directory contains a PetaLinux user application created from a template. + +If you are developing your application from scratch, simply start editing the +file libscalp.c. + +You can easily import any existing application code by copying it into this +directory, and editing the automatically generated Makefile. + +Before building the application, you will need to enable the application +from PetaLinux menuconfig by running: + "petalinux-config -c rootfs" +You will see your application in the "apps --->" submenu. + +To build your application, simply run "petalinux-build -c libscalp". +This command will build your application and will install your application +into the target file system host copy. + +You will also need to rebuild PetaLinux bootable images so that the images +is updated with the updated target filesystem copy, run this command: + "petalinux-build -c rootfs" + +You can also run one PetaLinux command to install the application to the +target filesystem host copy and update the bootable images as follows: + "petalinux-build" + +To add extra source code files (for example, to split a large application into +multiple source files), add the relevant .o files to the list in the local +Makefile where indicated. + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/Makefile b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..8e64797d5d8da610771d96fafe439d8ff00e5a39 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/Makefile @@ -0,0 +1,24 @@ +APP = scalp + +LIBSOURCES=*.cc +OUTS = *.o +NAME := scalp +MAJOR = 0.1 +MINOR = 1 +VERSION = $(MAJOR).$(MINOR) + +all: lib$(NAME).so +lib$(NAME).so.$(VERSION): $(OUTS) + $(CXX) $(LDFLAGS) $(OUTS) -shared -Wl,-soname,lib$(NAME).so.$(MAJOR) -o lib$(NAME).so.$(VERSION) + +lib$(NAME).so: lib$(NAME).so.$(VERSION) + rm -f lib$(NAME).so.$(MAJOR) lib$(NAME).so + ln -s lib$(NAME).so.$(VERSION) lib$(NAME).so.$(MAJOR) + ln -s lib$(NAME).so.$(MAJOR) lib$(NAME).so + +%.o: %.cc + $(CXX) $(CFLAGS) -c -fPIC $(LIBSOURCES) + +clean: + rm -rf *.o *.so *.so.* *~ *# + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.cc b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.cc new file mode 100644 index 0000000000000000000000000000000000000000..c84de67fbb76a4d081e80afee25fd82d35cfa023 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.cc @@ -0,0 +1,314 @@ +#include <iostream> +#include <unistd.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <cstdlib> +#include <cstdint> +#include <poll.h> +#include <errno.h> +#include <stdexcept> + +#include "scalp.hh" + +using namespace std; + +libscalp::uio::uio(const char *dev) +{ + if((_uiofd = open(dev, O_RDWR)) < 0) + { + throw std::runtime_error("failed to open UIO device"); + } +} + +libscalp::uio::~uio() +{ + close(_uiofd); +} + +void libscalp::uio::unmask_interrupt() +{ + uint32_t unmask = 1; + ssize_t rv; + + if((rv = write(_uiofd, &unmask, sizeof(unmask))) != (ssize_t)sizeof(unmask)) + { + perror("libscalp::uio::unmask_interrupt()"); + } + +} + +void libscalp::uio::wait_interrupt(uint32_t timeout_ms) +{ + // Wait for interrupt + struct pollfd pfd = {.fd = _uiofd, + .events = POLLIN}; + int32_t rv = poll(&pfd, 1, timeout_ms); + + // Clear interrupt + if(rv >= 1) + { + uint32_t info; + read(_uiofd, &info, sizeof(info)); + } + else if(rv == 0) + { + cout << "libscalp::uio::wait_interrupt() : device busy" << endl; + } + else + { + perror("libscalp::uio::wait_interrupt()"); + } +} + +libscalp::uio_mmap::uio_mmap(const libscalp::uio &u, uint32_t index, size_t size) : _size(size) +{ + if((_ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, u._uiofd, index * getpagesize())) == MAP_FAILED) + { + perror("libscalp::uio_mmap::uio_mmap"); + std::runtime_error("uio_mmap construction failed"); + } +} + +libscalp::uio_mmap::uio_mmap(libscalp::uio *u, uint32_t index, size_t size) : _size(size) +{ + if((_ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, u->_uiofd, index * getpagesize())) == MAP_FAILED) + { + perror("libscalp::uio_mmap::uio_mmap"); + std::runtime_error("uio_mmap construction failed"); + } +} + +libscalp::uio_mmap::~uio_mmap() +{ + munmap(_ptr, _size); +} + +// +// Wrapper functions +// + +void * libscalp::scalp_noc_init(const char *dev, void **devuio, void **mmap_regs) +{ + libscalp::uio *_devuio = NULL; + libscalp::uio_mmap *_mmap_regs = NULL; + void *regs = NULL; + + if(dev == NULL) + return NULL; + + _devuio = new libscalp::uio(dev); + _mmap_regs = new libscalp::uio_mmap(_devuio, 0, SCALP_ROUTER_MMAP_SIZE); + //regs = reinterpret_cast<libscalp::scalp_noc_regs *>(mmap_regs->get_ptr()); + regs = _mmap_regs->get_ptr(); + + *devuio = _devuio; + *mmap_regs = _mmap_regs; + + return regs; +} + +void libscalp::scalp_noc_free(void *devuio, void *mmap_regs) +{ + libscalp::uio *_devuio = NULL; + libscalp::uio_mmap *_mmap_regs = NULL; + + _devuio = reinterpret_cast<libscalp::uio *>(devuio); + _mmap_regs = reinterpret_cast<libscalp::uio_mmap *>(mmap_regs); + + _mmap_regs->~uio_mmap(); + _devuio->~uio(); +} + +bool libscalp::scalp_noc_set_locaddr(void *regs, uint32_t x, uint32_t y, uint32_t z) +{ + libscalp::scalp_noc_regs *_regs = NULL; + uint32_t locaddr = 0; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + if(regs == NULL) + return false; + + locaddr = (uint32_t)((uint32_t)(0x00000000 << 24) | (uint32_t)(z << 16) | (uint32_t)(y << 8) | (uint32_t)(x << 0)); + _regs->loc_netaddr = (uint32_t)locaddr; + + return true; +} + +uint32_t libscalp::scalp_noc_get_locaddr(void *regs) +{ + libscalp::scalp_noc_regs *_regs = NULL; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + if(regs == NULL) + return false; + + return (uint32_t)_regs->loc_netaddr; +} + +// Read function + +bool libscalp::scalp_noc_data_is_valid(void *regs, bool new_packet) +{ + libscalp::scalp_noc_regs *_regs = NULL; + + if(regs == NULL) + return false; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + if(new_packet == true) + { + _regs->ctrl = 0x00000000; + _regs->set_ctrl = libscalp::E_RD_NEW_PACKET; + _regs->clr_ctrl = libscalp::E_RD_NEXT; + _regs->clr_ctrl = libscalp::E_RD_NEW_PACKET; + } + + if(_regs->status & libscalp::E_RD_VALID) + return true; + else + return false; +} + +uint32_t libscalp::scalp_noc_read_data(void *regs, bool *is_last) +{ + libscalp::scalp_noc_regs *_regs = NULL; + uint32_t data = 0; + + if(regs == NULL) + return 0; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + data = (uint32_t)(_regs->rd_data); + + while(!(_regs->status & libscalp::E_RD_WAIT_NEXT)){} + + if(_regs->status & libscalp::E_RD_WAIT_NEXT) + { + _regs->set_ctrl = libscalp::E_RD_NEXT; + _regs->clr_ctrl = libscalp::E_RD_NEXT; + } + + if(_regs->status & libscalp::E_RD_LAST) + { + *is_last = true; + _regs->ctrl = 0x00000000; + } + else + { + *is_last = false; + } + + return data; +} + +uint32_t libscalp::scalp_noc_read_packet(void *regs, uint32_t *scalp_packet) +{ + // void *regs = NULL; + uint32_t spword = 0; + bool is_last = false; + uint32_t size = 0; + + // if((regs = libscalp::scalp_noc_init("/dev/uio0")) == NULL) + // return EXIT_FAILURE; + + do + { + if(libscalp::scalp_noc_data_is_valid(regs, (size == 0) ? true : false) == true) + { + spword = (uint32_t)libscalp::scalp_noc_read_data(regs, &is_last); + scalp_packet[size] = spword; + size++; + } + else + break; + }while(true); + + return size; +} + +bool libscalp::scalp_noc_ready_for_data(void *regs, bool new_packet) +{ + libscalp::scalp_noc_regs *_regs = NULL; + + if(regs == NULL) + return false; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + if(new_packet == true) + { + _regs->ctrl = 0x00000000; + _regs->set_ctrl = libscalp::E_WR_NEW_PACKET; + } + + if(!(_regs->status & libscalp::E_TX_PROG_FULL)) + return true; + else + return false; +} + +bool libscalp::scalp_noc_write_data(void *regs, uint32_t data, bool is_last) +{ + libscalp::scalp_noc_regs *_regs = NULL; + + if(regs == NULL) + return false; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + _regs->wr_data = data; + + // Unset next header word and valid current header word. + _regs->ctrl = 0x00000000; + if(is_last) + _regs->set_ctrl = libscalp::E_WR_LAST; + _regs->clr_ctrl = libscalp::E_WR_NEXT; + _regs->set_ctrl = libscalp::E_WR_VALID; + + // Go to next header word + _regs->ctrl = 0x00000000; + _regs->clr_ctrl = libscalp::E_WR_VALID; + _regs->set_ctrl = libscalp::E_WR_NEXT; + + return true; +} + +uint32_t libscalp::scalp_noc_write_packet(void *regs, uint32_t *scalp_packet, uint32_t size) +{ + // void *regs = NULL; + uint32_t i = 0; + + // if((regs = libscalp::scalp_noc_init("/dev/uio0")) == NULL) + // return EXIT_FAILURE; + + for(i = 0; i < size;) + { + if(i < (size - 1)) + { + if(libscalp::scalp_noc_ready_for_data(regs, (i == 0) ? true : false) == true) + { + if(libscalp::scalp_noc_write_data(regs, scalp_packet[i], false) == true) + { + i++; + } + } + } + else + { + if(libscalp::scalp_noc_ready_for_data(regs, false) == true) + { + if(libscalp::scalp_noc_write_data(regs, scalp_packet[i], true) == true) + { + i++; + } + } + } + } + + return i; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.cc~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.cc~ new file mode 100644 index 0000000000000000000000000000000000000000..77914b0a234f71be1bb314ed6f7710aef4989944 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.cc~ @@ -0,0 +1,212 @@ +#include <iostream> +#include <unistd.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <cstdlib> +#include <cstdint> +#include <poll.h> +#include <errno.h> +#include <stdexcept> + +#include "scalp.hh" + +using namespace std; + +libscalp::uio::uio(const char *dev) +{ + if((_uiofd = open(dev, O_RDWR)) < 0) + { + throw std::runtime_error("failed to open UIO device"); + } +} + +libscalp::uio::~uio() +{ + close(_uiofd); +} + +void libscalp::uio::unmask_interrupt() +{ + uint32_t unmask = 1; + ssize_t rv; + + if((rv = write(_uiofd, &unmask, sizeof(unmask))) != (ssize_t)sizeof(unmask)) + { + perror("libscalp::uio::unmask_interrupt()"); + } + +} + +void libscalp::uio::wait_interrupt(uint32_t timeout_ms) +{ + // Wait for interrupt + struct pollfd pfd = {.fd = _uiofd, + .events = POLLIN}; + int32_t rv = poll(&pfd, 1, timeout_ms); + + // Clear interrupt + if(rv >= 1) + { + uint32_t info; + read(_uiofd, &info, sizeof(info)); + } + else if(rv == 0) + { + cout << "libscalp::uio::wait_interrupt() : device busy" << endl; + } + else + { + perror("libscalp::uio::wait_interrupt()"); + } +} + +libscalp::uio_mmap::uio_mmap(const libscalp::uio &u, uint32_t index, size_t size) : _size(size) +{ + if((_ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, u._uiofd, index * getpagesize())) == MAP_FAILED) + { + perror("libscalp::uio_mmap::uio_mmap"); + std::runtime_error("uio_mmap construction failed"); + } +} + +libscalp::uio_mmap::uio_mmap(libscalp::uio *u, uint32_t index, size_t size) : _size(size) +{ + if((_ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, u->_uiofd, index * getpagesize())) == MAP_FAILED) + { + perror("libscalp::uio_mmap::uio_mmap"); + std::runtime_error("uio_mmap construction failed"); + } +} + +libscalp::uio_mmap::~uio_mmap() +{ + munmap(_ptr, _size); +} + +// +// Wrapper functions +// + +void * libscalp::scalp_noc_init(const char *dev) +{ + libscalp::uio *devuio = NULL; + libscalp::uio_mmap *mmap_regs = NULL; + void *regs = NULL; + + if(dev == NULL) + return NULL; + + devuio = new libscalp::uio(dev); + mmap_regs = new libscalp::uio_mmap(devuio, 0, SCALP_ROUTER_MMAP_SIZE); + //regs = reinterpret_cast<libscalp::scalp_noc_regs *>(mmap_regs->get_ptr()); + regs = mmap_regs->get_ptr(); + + return regs; +} + +// void libscalp::scalp_noc_free(libscalp::uio *devuio, libscalp::uio_mmap *mmap_regs) +// { +// mmap_regs->~uio_mmap(); +// devuio->~uio(); +// } + +bool libscalp::scalp_noc_set_locaddr(void *regs, uint32_t x, uint32_t y, uint32_t z) +{ + libscalp::scalp_noc_regs *_regs = NULL; + uint32_t locaddr = 0; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + if(regs == NULL) + return false; + + locaddr = (uint32_t)((uint32_t)(0x00000000 << 24) | (uint32_t)(z << 16) | (uint32_t)(y << 8) | (uint32_t)(x << 0)); + _regs->loc_netaddr = (uint32_t)locaddr; + + return true; +} + +// Read function + +bool libscalp::scalp_noc_data_is_valid(void *regs, bool new_packet) +{ + libscalp::scalp_noc_regs *_regs = NULL; + + if(regs == NULL) + return false; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + if(new_packet == true) + { + _regs->ctrl = 0x00000000; + _regs->set_ctrl = libscalp::E_RD_NEW_PACKET; + _regs->clr_ctrl = libscalp::E_RD_NEXT; + _regs->clr_ctrl = libscalp::E_RD_NEW_PACKET; + } + + if(_regs->status & libscalp::E_RD_VALID) + return true; + else + return false; +} + +uint32_t libscalp::scalp_noc_read_data(void *regs, bool *is_last) +{ + libscalp::scalp_noc_regs *_regs = NULL; + uint32_t data = 0; + + if(regs == NULL) + return 0; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + data = (uint32_t)(_regs->rd_data); + + while(!(_regs->status & libscalp::E_RD_WAIT_NEXT)){} + + if(_regs->status & libscalp::E_RD_WAIT_NEXT) + { + _regs->set_ctrl = libscalp::E_RD_NEXT; + _regs->clr_ctrl = libscalp::E_RD_NEXT; + } + + if(_regs->status & libscalp::E_RD_LAST) + { + *is_last = true; + _regs->ctrl = 0x00000000; + } + else + { + *is_last = false; + } + + return data; +} + +uint32_t libscalp::scalp_noc_read_packet(uint32_t *scalp_packet) +{ + void *regs = NULL; + libscalp::scalp_noc_regs *_regs = NULL; + uint32_t spword = 0; + bool is_last = false; + uint32_t size = 0; + + if((regs = libscalp::scalp_noc_init("/dev/uio0")) == NULL) + return EXIT_FAILURE; + + do + { + if(libscalp::scalp_noc_data_is_valid(regs, (size == 0) ? true : false) == true) + { + spword = (uint32_t)libscalp::scalp_noc_read_data(regs, &is_last); + scalp_packet[size] = spword; + size++; + } + else + break; + }while(true); + + return size; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.hh b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.hh new file mode 100644 index 0000000000000000000000000000000000000000..2cc5ce14799637808256e61465f89caf3340f8c2 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.hh @@ -0,0 +1,111 @@ +#ifndef __SCALP_HH__ +#define __SCALP_HH__ + +#include <cstdint> +#include <cstddef> +#include <atomic> + +#define SCALP_ROUTER_UIO_DEV "/dev/uio0" +#define SCALP_ROUTER_MMAP_SIZE 0x1000 +#define SCALP_MAX_SP_SIZE 64 +#define SCALP_TX_FIFO_SIZE 1024 + +using namespace std; + +namespace libscalp +{ + struct scalp_noc_regs + { + public : + std::atomic<uint32_t> wr_data; + std::atomic<uint32_t> rd_data; + // Same register, but different access + std::atomic<uint32_t> ctrl; + std::atomic<uint32_t> set_ctrl; + std::atomic<uint32_t> clr_ctrl; + // + std::atomic<uint32_t> status; + std::atomic<uint32_t> txwr_datacnt; + std::atomic<uint32_t> txrd_datacnt; + std::atomic<uint32_t> rxwr_datacnt; + std::atomic<uint32_t> rxrd_datacnt; + std::atomic<uint32_t> loc_netaddr; + }; + + enum ctrl_reg_fields + { + E_WR_VALID = 0x1, + E_WR_LAST = 0x2, + E_WR_READY = 0x4, + E_WR_NEXT = 0x8, + E_RESET_ALL_FIFO = 0x10, + E_WR_H0 = 0x20, + E_WR_H1 = 0x40, + E_WR_H2 = 0x80, + E_WR_PLD = 0x100, + E_WR_NEW_PACKET = 0x200, + E_RD_NEXT = 0x400, + E_RD_NEW_PACKET = 0x800 + }; + + enum status_reg_fields + { + E_RD_VALID = 0x1, + E_RD_LAST = 0x2, + E_TX_PROG_FULL = 0x4, + E_RX_PROG_FULL = 0x8, + E_RD_WAIT_NEXT = 0x10 + }; + + class uio + { + private : + int32_t _uiofd; + + public : + explicit uio(const char * dev); + ~uio(); + void unmask_interrupt(); + void wait_interrupt(uint32_t timeout_ms); + friend class uio_mmap; + }; + + class uio_mmap + { + private : + size_t _size; + void * _ptr; + + public : + uio_mmap(const uio &u, uint32_t index, size_t size); + uio_mmap(uio *u, uint32_t index, size_t size); + ~uio_mmap(); + size_t size() const { return _size; } + void *get_ptr() const { return _ptr; } + }; + + void * scalp_noc_init (const char *dev, void **devuio, void **mmap_regs); + bool scalp_noc_set_locaddr (void *regs, uint32_t x, uint32_t y, uint32_t z); + uint32_t scalp_noc_get_locaddr (void *regs); + void scalp_noc_free (void *devuio, void *mmap_regs); + bool scalp_noc_data_is_valid (void *regs, bool new_packet); + uint32_t scalp_noc_read_data (void *regs, bool *is_last); + uint32_t scalp_noc_read_packet (void *regs, uint32_t *scalp_packet); + bool scalp_noc_ready_for_data(void *regs, bool new_packet); + bool scalp_noc_write_data (void *regs, uint32_t data, bool is_last); + uint32_t scalp_noc_write_packet (void *regs, uint32_t *scalp_packet, uint32_t size); +}; + +extern "C" +{ + libscalp::uio * uio_new(const char *dev){ return new libscalp::uio(dev); } + void uio_del(libscalp::uio *obj_uio){ obj_uio->~uio(); } + void uio_unmask_interrupt(libscalp::uio *obj_uio){ obj_uio->unmask_interrupt(); } + void uio_wait_interrupt(libscalp::uio *obj_uio, uint32_t timeout_ms){ obj_uio->wait_interrupt(timeout_ms); } + libscalp::uio_mmap * uio_mmap_new(const libscalp::uio &u, uint32_t index, size_t size) { return new libscalp::uio_mmap(u, index, size); } + void uio_mmap_del(libscalp::uio_mmap *obj_uio_mmap){ obj_uio_mmap->~uio_mmap(); } + size_t uio_mmap_size(libscalp::uio_mmap *obj_uio_mmap) { return obj_uio_mmap->size(); } + void * uio_mmap_get_ptr(libscalp::uio_mmap *obj_uio_mmap) { return obj_uio_mmap->get_ptr(); } +} + +#endif diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.hh~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.hh~ new file mode 100644 index 0000000000000000000000000000000000000000..b87da1888ed2b19a85f87a2cbda0ca53d361113e --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/files/scalp.hh~ @@ -0,0 +1,106 @@ +#ifndef __SCALP_HH__ +#define __SCALP_HH__ + +#include <cstdint> +#include <cstddef> +#include <atomic> + +#define SCALP_ROUTER_UIO_DEV "/dev/uio0" +#define SCALP_ROUTER_MMAP_SIZE 0x1000 +#define SCALP_MAX_SP_SIZE 64 + +using namespace std; + +namespace libscalp +{ + struct scalp_noc_regs + { + public : + std::atomic<uint32_t> wr_data; + std::atomic<uint32_t> rd_data; + // Same register, but different access + std::atomic<uint32_t> ctrl; + std::atomic<uint32_t> set_ctrl; + std::atomic<uint32_t> clr_ctrl; + // + std::atomic<uint32_t> status; + std::atomic<uint32_t> txwr_datacnt; + std::atomic<uint32_t> txrd_datacnt; + std::atomic<uint32_t> rxwr_datacnt; + std::atomic<uint32_t> rxrd_datacnt; + std::atomic<uint32_t> loc_netaddr; + }; + + enum ctrl_reg_fields + { + E_WR_VALID = 0x1, + E_WR_LAST = 0x2, + E_WR_READY = 0x4, + E_WR_NEXT = 0x8, + E_RESET_ALL_FIFO = 0x10, + E_WR_H0 = 0x20, + E_WR_H1 = 0x40, + E_WR_H2 = 0x80, + E_WR_PLD = 0x100, + E_WR_NEW_PACKET = 0x200, + E_RD_NEXT = 0x400, + E_RD_NEW_PACKET = 0x800 + }; + + enum status_reg_fields + { + E_RD_VALID = 0x1, + E_RD_LAST = 0x2, + E_TX_PROG_FULL = 0x4, + E_RX_PROG_FULL = 0x8, + E_RD_WAIT_NEXT = 0x10 + }; + + class uio + { + private : + int32_t _uiofd; + + public : + explicit uio(const char * dev); + ~uio(); + void unmask_interrupt(); + void wait_interrupt(uint32_t timeout_ms); + friend class uio_mmap; + }; + + class uio_mmap + { + private : + size_t _size; + void * _ptr; + + public : + uio_mmap(const uio &u, uint32_t index, size_t size); + uio_mmap(uio *u, uint32_t index, size_t size); + ~uio_mmap(); + size_t size() const { return _size; } + void *get_ptr() const { return _ptr; } + }; + + void * scalp_noc_init (const char *dev); + bool scalp_noc_set_locaddr (void *regs, uint32_t x, uint32_t y, uint32_t z); + //void scalp_noc_free (uio *devuio, uio_mmap *mmap_regs); + bool scalp_noc_data_is_valid(void *regs, bool new_packet); + uint32_t scalp_noc_read_data (void *regs, bool *is_last); + uint32_t scalp_noc_read_packet (uint32_t *scalp_packet); +}; + +extern "C" +{ + libscalp::uio * uio_new(const char *dev){ return new libscalp::uio(dev); } + void uio_del(libscalp::uio *obj_uio){ obj_uio->~uio(); } + void uio_unmask_interrupt(libscalp::uio *obj_uio){ obj_uio->unmask_interrupt(); } + void uio_wait_interrupt(libscalp::uio *obj_uio, uint32_t timeout_ms){ obj_uio->wait_interrupt(timeout_ms); } + libscalp::uio_mmap * uio_mmap_new(const libscalp::uio &u, uint32_t index, size_t size) { return new libscalp::uio_mmap(u, index, size); } + void uio_mmap_del(libscalp::uio_mmap *obj_uio_mmap){ obj_uio_mmap->~uio_mmap(); } + size_t uio_mmap_size(libscalp::uio_mmap *obj_uio_mmap) { return obj_uio_mmap->size(); } + void * uio_mmap_get_ptr(libscalp::uio_mmap *obj_uio_mmap) { return obj_uio_mmap->get_ptr(); } +} + +#endif diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/libscalp.bb b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/libscalp.bb new file mode 100644 index 0000000000000000000000000000000000000000..76b30951ea0589bcba973336a54c89283f201954 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/libscalp/libscalp.bb @@ -0,0 +1,33 @@ +# +# This file is the libscalp recipe. +# + +SUMMARY = "Simple libscalp application" +SECTION = "libs" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files:" + +SRC_URI = "file://scalp.cc \ + file://scalp.hh \ + file://Makefile \ + " + +S = "${WORKDIR}" + +PACKAGE_ARCH = "${MACHINE_ARCH}" +PROVIDES = "scalp" +TARGET_CC_ARCH += "${LDFLAGS}" + +do_install() { + install -d ${D}${libdir} + install -d ${D}${includedir} + oe_libinstall -so libscalp ${D}${libdir} + + install -d -m 0655 ${D}${includedir}/scalp + install -m 0644 ${S}/*.hh ${D}${includedir}/scalp +} + +FILES_${PN} = "${libdir}/*.so.* ${includedir}/*" +FILES_${PN}-dev = "${libdir}/*.so" diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/.gdbinit b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/.gdbinit new file mode 100644 index 0000000000000000000000000000000000000000..d59fb8d90efb393c83d35becbecddcfa493a5e67 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/.gdbinit @@ -0,0 +1,2 @@ +# Load the PetaLinux SDK main gdbinit script +source plnx_gdbinit diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/README b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/README new file mode 100644 index 0000000000000000000000000000000000000000..fe033e7471a68b3b8b062d8c4e7d4c09cd2034d7 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/README @@ -0,0 +1,32 @@ +PetaLinux User Application Template +=================================== + +This directory contains a PetaLinux user application created from a template. + +If you are developing your application from scratch, simply start editing the +file sampleapp.c. + +You can easily import any existing application code by copying it into this +directory, and editing the automatically generated Makefile. + +Before building the application, you will need to enable the application +from PetaLinux menuconfig by running: + "petalinux-config -c rootfs" +You will see your application in the "apps --->" submenu. + +To build your application, simply run "petalinux-build -c sampleapp". +This command will build your application and will install your application +into the target file system host copy. + +You will also need to rebuild PetaLinux bootable images so that the images +is updated with the updated target filesystem copy, run this command: + "petalinux-build -c rootfs" + +You can also run one PetaLinux command to install the application to the +target filesystem host copy and update the bootable images as follows: + "petalinux-build" + +To add extra source code files (for example, to split a large application into +multiple source files), add the relevant .o files to the list in the local +Makefile where indicated. + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/files/Makefile b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/files/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..a53c51d318cff0982ce2d7e7e0aec1373baf77b3 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/files/Makefile @@ -0,0 +1,14 @@ +APP = sampleapp + +# Add any other object files to this list below +APP_OBJS = sampleapp.o + +all: build + +build: $(APP) + +$(APP): $(APP_OBJS) + $(CXX) -o $@ $(APP_OBJS) $(LDFLAGS) $(LDLIBS) -llibscalp +clean: + rm -f $(APP) *.o + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/files/sampleapp.cc b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/files/sampleapp.cc new file mode 100644 index 0000000000000000000000000000000000000000..5ae910aab90754eb859609afd2ef7b3078cf5d39 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/files/sampleapp.cc @@ -0,0 +1,172 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <scalp/scalp.hh> + +int main(int argc, char **argv) +{ + int tmp; + + libscalp::uio devuio("/dev/uio0"); + libscalp::uio_mmap mmap_regs(devuio, 0, 4096); + libscalp::scalp_noc_regs *regs = reinterpret_cast<libscalp::scalp_noc_regs *>(mmap_regs.get_ptr()); + + std::cout << "[INFO] Scalp packet is sending..." << std::endl; + + // Set local Scalp NoC address. + regs->loc_netaddr = 0x00000001; + // std::cout << "Loc NetAddr : " << regs->loc_netaddr << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Set write new packet. + regs->ctrl = 0x00000000; + regs->set_ctrl = libscalp::E_WR_NEW_PACKET; + // std::cout << "Write new packet" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Set header H0 + regs->wr_data = 0x02000001; + // std::cout << "Set header H0" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Unset next header word and valid current header word. + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Clr write next + Set write valid" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Go to next header word + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_VALID; + regs->set_ctrl = libscalp::E_WR_NEXT; + // std::cout << "Clr write valid + Set write next" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Set header H1 + regs->wr_data = 0x01000000; + // std::cout << "Set header H1" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Unset next header word and valid current header word. + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Clr write next + Set write valid" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Go to next header word + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_VALID; + regs->set_ctrl = libscalp::E_WR_NEXT; + // std::cout << "Clr write valid + Set write next" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Set header H2 + regs->wr_data = 0x00080000; + // std::cout << "Set header H2" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Unset next header word and valid current header word. + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Clr write next + Set write valid" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Go to next header word + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_VALID; + regs->set_ctrl = libscalp::E_WR_NEXT; + // std::cout << "Clr write valid + Set write next" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Set payload + for(uint32_t i = 0; i < 8; i++) + { + regs->wr_data = i; + // std::cout << "Set payload " << i << std::endl; + + if(i < 7) + { + // Unset next header word and valid current header word. + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Clr write next + Set write valid" << std::endl; + } + else + { + regs->ctrl = 0x00000000; + regs->set_ctrl = libscalp::E_WR_LAST; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Set write last" << std::endl; + // std::cout << "Clr write next + Set write valid" << std::endl; + } + + //if(i < 7) + //{ + // Go to next header word + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_VALID; + regs->set_ctrl = libscalp::E_WR_NEXT; + // std::cout << "Clr write valid + Set write next" << std::endl; + // //} + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + } + + regs->ctrl = 0x00000000; + std::cout << "[INFO] Scalp packet has been sent!" << std::endl; + + return 0; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/files/sampleapp.cc~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/files/sampleapp.cc~ new file mode 100644 index 0000000000000000000000000000000000000000..22da235cfe77a0f515a7103ca35ccfb6b00b95e9 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/files/sampleapp.cc~ @@ -0,0 +1,44 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <scalp/scalp.hh> + +int main(int argc, char **argv) +{ + libscalp::uio devuio("/dev/uio0"); + libscalp::uio_mmap mmap_regs(devuio, 0, 4096); + libscalp::scalp_noc_regs *regs = reinterpret_cast<libscalp::scalp_noc_regs *>(mmap_regs.get_ptr()); + + std::cout << "Hello World!" << std::endl; + + regs->loc_netaddr = 0x00030201; + + std::cout << "Loc NetAddr : " << regs->loc_netaddr << std::endl; + + return 0; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/sampleapp.bb b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/sampleapp.bb new file mode 100644 index 0000000000000000000000000000000000000000..e825abfa8c8304012d1196d483f3b4465aa0686c --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleapp/sampleapp.bb @@ -0,0 +1,30 @@ +# +# This file is the sampleapp recipe. +# + +SUMMARY = "Simple sampleapp application" +SECTION = "PETALINUX/apps" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files:" + +SRC_URI = "file://sampleapp.cc" +# file://Makefile \ +# " + +S = "${WORKDIR}" + +DEPENDS = "scalp" + +do_compile() { +# oe_runmake + ${CXX} ${CFLAGS} ${LDFLAGS} -o sampleapp sampleapp.cc -lscalp +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 sampleapp ${D}${bindir} +} + +FILES_${PN} += "sampleapp" \ No newline at end of file diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/.gdbinit b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/.gdbinit new file mode 100644 index 0000000000000000000000000000000000000000..d59fb8d90efb393c83d35becbecddcfa493a5e67 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/.gdbinit @@ -0,0 +1,2 @@ +# Load the PetaLinux SDK main gdbinit script +source plnx_gdbinit diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/README b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/README new file mode 100644 index 0000000000000000000000000000000000000000..bfa8b19561d0f8c8ef07043c204b474b8bd4c65f --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/README @@ -0,0 +1,32 @@ +PetaLinux User Application Template +=================================== + +This directory contains a PetaLinux user application created from a template. + +If you are developing your application from scratch, simply start editing the +file sampleread.c. + +You can easily import any existing application code by copying it into this +directory, and editing the automatically generated Makefile. + +Before building the application, you will need to enable the application +from PetaLinux menuconfig by running: + "petalinux-config -c rootfs" +You will see your application in the "apps --->" submenu. + +To build your application, simply run "petalinux-build -c sampleread". +This command will build your application and will install your application +into the target file system host copy. + +You will also need to rebuild PetaLinux bootable images so that the images +is updated with the updated target filesystem copy, run this command: + "petalinux-build -c rootfs" + +You can also run one PetaLinux command to install the application to the +target filesystem host copy and update the bootable images as follows: + "petalinux-build" + +To add extra source code files (for example, to split a large application into +multiple source files), add the relevant .o files to the list in the local +Makefile where indicated. + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/files/Makefile b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/files/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..87fbc1b31db44fbc39db5ebd6cc18abc757a0598 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/files/Makefile @@ -0,0 +1,14 @@ +APP = sampleread + +# Add any other object files to this list below +APP_OBJS = sampleread.o + +all: build + +build: $(APP) + +$(APP): $(APP_OBJS) + $(CC) -o $@ $(APP_OBJS) $(LDFLAGS) $(LDLIBS) +clean: + rm -f $(APP) *.o + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/files/sampleread.cc b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/files/sampleread.cc new file mode 100644 index 0000000000000000000000000000000000000000..33f51a519e650e61ec74ff9bca49778880ac32cb --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/files/sampleread.cc @@ -0,0 +1,86 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <scalp/scalp.hh> + +int main(int argc, char **argv) +{ + void *regs = NULL; + void *devuio = NULL; + void *mmap_regs = NULL; + + uint32_t scalp_packet[SCALP_MAX_SP_SIZE]; + uint32_t size = 0; + + // uint32_t spword = 0; + // bool is_last = false; + // uint32_t i = 0; + + if((regs = libscalp::scalp_noc_init("/dev/uio0", &devuio, &mmap_regs)) == NULL) + return EXIT_FAILURE; + + std::cout << "[INFO] Scalp packet is receiving..." << std::endl; + + size = libscalp::scalp_noc_read_packet(regs, scalp_packet); + + std::cout << "[INFO] Scalp packet size = " << size << std::endl; + + for(int i = 0; i < size; i++) + { + std::cout << "[INFO] " << i << " : 0x" << std::hex << scalp_packet[i] << std::endl; + } + + libscalp::scalp_noc_free(devuio, mmap_regs); + + // do + // { + // if(libscalp::scalp_noc_data_is_valid(regs, (i == 0) ? true : false) == true) + // { + // std::cout << "Data valid" << std::endl; + // spword = (uint32_t)libscalp::scalp_noc_read_data(regs, &is_last); + // std::cout << "0x" << std::hex << spword << std::endl; + + // i++; + + // if(is_last) + // { + // std::cout << "Read last word" << std::endl; + // //break; + // } + // } + // else + // { + // std::cout << "Data not valid" << std::endl; + // break; + // } + // }while(true); + + std::cout << "[INFO] Scalp package has been received!" << std::endl; + + return 0; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/files/sampleread.cc~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/files/sampleread.cc~ new file mode 100644 index 0000000000000000000000000000000000000000..84f2da605fcd6865f9dde16d7c1f596a3954f98a --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/files/sampleread.cc~ @@ -0,0 +1,81 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <scalp/scalp.hh> + +int main(int argc, char **argv) +{ + void *regs = NULL; + uint32_t scalp_packet[SCALP_MAX_SP_SIZE]; + uint32_t size = 0; + + // uint32_t spword = 0; + // bool is_last = false; + // uint32_t i = 0; + + if((regs = libscalp::scalp_noc_init("/dev/uio0")) == NULL) + return EXIT_FAILURE; + + std::cout << "[INFO] Scalp packet is receiving..." << std::endl; + + size = libscalp::scalp_noc_read_packet(scalp_packet); + + std::cout << "[INFO] Scalp packet size = " << size << std::endl; + + for(int i = 0; i < size; i++) + { + std::cout << "[INFO] " << i << " : 0x" << std::hex << scalp_packet[i] << std::endl; + } + + // do + // { + // if(libscalp::scalp_noc_data_is_valid(regs, (i == 0) ? true : false) == true) + // { + // std::cout << "Data valid" << std::endl; + // spword = (uint32_t)libscalp::scalp_noc_read_data(regs, &is_last); + // std::cout << "0x" << std::hex << spword << std::endl; + + // i++; + + // if(is_last) + // { + // std::cout << "Read last word" << std::endl; + // //break; + // } + // } + // else + // { + // std::cout << "Data not valid" << std::endl; + // break; + // } + // }while(true); + + std::cout << "[INFO] Scalp package has been received!" << std::endl; + + return 0; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/sampleread.bb b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/sampleread.bb new file mode 100644 index 0000000000000000000000000000000000000000..a2be5c22fcaa190809f4751c8f5c6517a33cd32d --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/sampleread/sampleread.bb @@ -0,0 +1,30 @@ +# +# This file is the sampleread recipe. +# + +SUMMARY = "Simple sampleread application" +SECTION = "PETALINUX/apps" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files:" + +SRC_URI = "file://sampleread.cc" +# file://Makefile \ +# " + +S = "${WORKDIR}" + +DEPENDS = "scalp" + +do_compile() { +# oe_runmake + ${CXX} ${CFLAGS} ${LDFLAGS} -o sampleread sampleread.cc -lscalp +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 sampleread ${D}${bindir} +} + +FILES_${PN} += "sampleread" \ No newline at end of file diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/.gdbinit b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/.gdbinit new file mode 100644 index 0000000000000000000000000000000000000000..d59fb8d90efb393c83d35becbecddcfa493a5e67 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/.gdbinit @@ -0,0 +1,2 @@ +# Load the PetaLinux SDK main gdbinit script +source plnx_gdbinit diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/README b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/README new file mode 100644 index 0000000000000000000000000000000000000000..bdb2a0b0c11add71869c2ba9526852fcc5b5382b --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/README @@ -0,0 +1,32 @@ +PetaLinux User Application Template +=================================== + +This directory contains a PetaLinux user application created from a template. + +If you are developing your application from scratch, simply start editing the +file samplewrite.c. + +You can easily import any existing application code by copying it into this +directory, and editing the automatically generated Makefile. + +Before building the application, you will need to enable the application +from PetaLinux menuconfig by running: + "petalinux-config -c rootfs" +You will see your application in the "apps --->" submenu. + +To build your application, simply run "petalinux-build -c samplewrite". +This command will build your application and will install your application +into the target file system host copy. + +You will also need to rebuild PetaLinux bootable images so that the images +is updated with the updated target filesystem copy, run this command: + "petalinux-build -c rootfs" + +You can also run one PetaLinux command to install the application to the +target filesystem host copy and update the bootable images as follows: + "petalinux-build" + +To add extra source code files (for example, to split a large application into +multiple source files), add the relevant .o files to the list in the local +Makefile where indicated. + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/files/Makefile b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/files/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..7deaca991a75093916f83a3c5bea1fba0d21b709 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/files/Makefile @@ -0,0 +1,14 @@ +APP = samplewrite + +# Add any other object files to this list below +APP_OBJS = samplewrite.o + +all: build + +build: $(APP) + +$(APP): $(APP_OBJS) + $(CC) -o $@ $(APP_OBJS) $(LDFLAGS) $(LDLIBS) +clean: + rm -f $(APP) *.o + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/files/samplewrite.cc b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/files/samplewrite.cc new file mode 100644 index 0000000000000000000000000000000000000000..5f18de6ffb404842b94dbd445ea6f169ba42b49c --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/files/samplewrite.cc @@ -0,0 +1,178 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h> +#include <scalp/scalp.hh> + +int main(int argc, char **argv) +{ + int tmp; + uint32_t x_addr = 0; + uint32_t y_addr = 0; + uint32_t z_addr = 0; + uint32_t h0 = 0; + uint32_t h1 = 0; + uint32_t h2 = 0; + uint32_t pld = 0; + uint32_t len = 0; + uint32_t scalp_packet[SCALP_MAX_SP_SIZE]; + uint32_t size = 0; + + // libscalp::uio devuio("/dev/uio0"); + // libscalp::uio_mmap mmap_regs(devuio, 0, 4096); + // libscalp::scalp_noc_regs *_regs = NULL; + + void *regs = NULL; + void *devuio = NULL; + void *mmap_regs = NULL; + + if((regs = libscalp::scalp_noc_init("/dev/uio0", &devuio, &mmap_regs)) == NULL) + return EXIT_FAILURE; + + // _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + std::cout << "[INFO] Set dest addr" << std::endl; + std::cout << "[INFO] Set X : "; + cin >> x_addr; + //x_addr = (uint8_t)atoi(c_x_addr); + std::cout << "[INFO] Set Y : "; + cin >> y_addr; + //y_addr = (uint8_t)atoi(c_y_addr); + std::cout << "[INFO] Set Z : "; + cin >> z_addr; + //z_addr = (uint8_t)atoi(c_z_addr); + std::cout << "[INFO] X : " << x_addr << " Y : " << y_addr << " Z : " << z_addr << std::endl; + + std::cout << "[INFO] Set length" << std::endl; + std::cout << "[INFO] Len : "; + cin >> len; + + std::cout << "[INFO] Scalp packet is sending..." << std::endl; + + h0 = (uint32_t)(x_addr << 24) | (uint32_t)(y_addr << 16) | (uint32_t)(z_addr << 8) | (uint32_t)0x00000001; + h1 = 0x01000000; + h2 = 0x00080000; + + scalp_packet[0] = h0; + scalp_packet[1] = h1; + scalp_packet[2] = h2; + + std::cout << "[INFO] H0 : 0x" << std::hex << h0 << std::endl; + std::cout << "[INFO] H1 : 0x" << std::hex << h1 << std::endl; + std::cout << "[INFO] H2 : 0x" << std::hex << h2 << std::endl; + + for(int i = 0; i < len; i++) + { + scalp_packet[i + 3] = i; + std::cout << "[INFO] PLD : 0x" << std::hex << i << std::endl; + } + + if((size = libscalp::scalp_noc_write_packet(regs, scalp_packet, (len + 3))) == (len + 3)) + { + std::cout << "[INFO] Scalp packet has been sent!" << std::endl; + } + else + { + std::cout << "[INFO] Scalp packet has not been sent!" << std::endl; + return EXIT_FAILURE; + } + + libscalp::scalp_noc_free(devuio, mmap_regs); + + // h0 = (uint32_t)(x_addr << 24) | (uint32_t)(y_addr << 16) | (uint32_t)(z_addr << 8) | (uint32_t)0x00000001; + // std::cout << "[INFO] H0 : 0x" << std::hex << h0 << std::endl; + + // // Send header 0 + set new packet + // if(libscalp::scalp_noc_ready_for_data(regs, true) == true) + // { + // if(libscalp::scalp_noc_write_data(regs, h0, false) == false) + // return EXIT_FAILURE; + // } + // else + // return EXIT_FAILURE; + + // h1 = 0x01000000; + // std::cout << "[INFO] H1 : 0x" << std::hex << h1 << std::endl; + + // // Send header 1 + // if(libscalp::scalp_noc_ready_for_data(regs, false) == true) + // { + // if(libscalp::scalp_noc_write_data(regs, h1, false) == false) + // return EXIT_FAILURE; + // } + // else + // return EXIT_FAILURE; + + // h2 = 0x00080000; + // std::cout << "[INFO] H2 : 0x" << std::hex << h2 << std::endl; + + // // Send header 2 + // if(libscalp::scalp_noc_ready_for_data(regs, false) == true) + // { + // if(libscalp::scalp_noc_write_data(regs, h2, false) == false) + // return EXIT_FAILURE; + // } + // else + // return EXIT_FAILURE; + + // // Send payload + + // for(uint32_t i = 0; i < len; i++) + // { + // pld = i; + + // if(i < (len - 1)) + // { + // if(libscalp::scalp_noc_ready_for_data(regs, false) == true) + // { + // if(libscalp::scalp_noc_write_data(regs, pld, false) == false) + // return EXIT_FAILURE; + // } + // else + // return EXIT_FAILURE; + // } + // else + // { + // if(libscalp::scalp_noc_ready_for_data(regs, false) == true) + // { + // if(libscalp::scalp_noc_write_data(regs, pld, true) == false) + // return EXIT_FAILURE; + // } + // else + // return EXIT_FAILURE; + // } + // std::cout << "[INFO] PLD : 0x" << std::hex << i << std::endl; + // } + + // std::cout << "[INFO] Scalp packet has been sent!" << std::endl; + + return 0; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/files/samplewrite.cc~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/files/samplewrite.cc~ new file mode 100644 index 0000000000000000000000000000000000000000..e2e40c90dd0f51c5ff576bbb9b94a5bb1414e618 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/files/samplewrite.cc~ @@ -0,0 +1,205 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h> +#include <scalp/scalp.hh> + +int main(int argc, char **argv) +{ + int tmp; + uint32_t x_addr = 0; + uint32_t y_addr = 0; + uint32_t z_addr = 0; + uint32_t dest_addr = 0; + uint32_t len = 0; + + libscalp::uio devuio("/dev/uio0"); + libscalp::uio_mmap mmap_regs(devuio, 0, 4096); + libscalp::scalp_noc_regs *regs = reinterpret_cast<libscalp::scalp_noc_regs *>(mmap_regs.get_ptr()); + + std::cout << "[INFO] Set dest addr" << std::endl; + std::cout << "[INFO] Set X : "; + cin >> x_addr; + //x_addr = (uint8_t)atoi(c_x_addr); + std::cout << "[INFO] Set Y : "; + cin >> y_addr; + //y_addr = (uint8_t)atoi(c_y_addr); + std::cout << "[INFO] Set Z : "; + cin >> z_addr; + //z_addr = (uint8_t)atoi(c_z_addr); + std::cout << "[INFO] X : " << x_addr << " Y : " << y_addr << " Z : " << z_addr << std::endl; + + std::cout << "[INFO] Set length" << std::endl; + std::cout << "[INFO] Len : "; + cin >> len; + + std::cout << "[INFO] Scalp packet is sending..." << std::endl; + + // Set local Scalp NoC address. + // regs->loc_netaddr = 0x00000001; + // std::cout << "Loc NetAddr : " << regs->loc_netaddr << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // for(int i = 0; i < 10; i++) + // { + + // Set write new packet. + regs->ctrl = 0x00000000; + regs->set_ctrl = libscalp::E_WR_NEW_PACKET; + // std::cout << "Write new packet" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Set header H0 + //regs->wr_data = 0x02000001; + //regs->wr_data = 0x02010001; + dest_addr = (uint32_t)(x_addr << 24) | (uint32_t)(y_addr << 16) | (uint32_t)(z_addr << 8) | (uint32_t)0x00000001; + std::cout << "[INFO] H0 : 0x" << std::hex << dest_addr << std::endl; + regs->wr_data = dest_addr; + // std::cout << "Set header H0" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Unset next header word and valid current header word. + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Clr write next + Set write valid" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Go to next header word + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_VALID; + regs->set_ctrl = libscalp::E_WR_NEXT; + // std::cout << "Clr write valid + Set write next" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Set header H1 + regs->wr_data = 0x01000000; + // std::cout << "Set header H1" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Unset next header word and valid current header word. + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Clr write next + Set write valid" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Go to next header word + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_VALID; + regs->set_ctrl = libscalp::E_WR_NEXT; + // std::cout << "Clr write valid + Set write next" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Set header H2 + regs->wr_data = 0x00080000; + // std::cout << "Set header H2" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Unset next header word and valid current header word. + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Clr write next + Set write valid" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Go to next header word + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_VALID; + regs->set_ctrl = libscalp::E_WR_NEXT; + // std::cout << "Clr write valid + Set write next" << std::endl; + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + + // Set payload + for(uint32_t i = 0; i < len; i++) + { + regs->wr_data = i; + // std::cout << "Set payload " << i << std::endl; + + if(i < (len - 1)) + { + // Unset next header word and valid current header word. + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Clr write next + Set write valid" << std::endl; + } + else + { + regs->ctrl = 0x00000000; + regs->set_ctrl = libscalp::E_WR_LAST; + regs->clr_ctrl = libscalp::E_WR_NEXT; + regs->set_ctrl = libscalp::E_WR_VALID; + // std::cout << "Set write last" << std::endl; + // std::cout << "Clr write next + Set write valid" << std::endl; + } + + //if(i < 7) + //{ + // Go to next header word + regs->ctrl = 0x00000000; + regs->clr_ctrl = libscalp::E_WR_VALID; + regs->set_ctrl = libscalp::E_WR_NEXT; + // std::cout << "Clr write valid + Set write next" << std::endl; + // //} + + // std::cout << "Next : " << std::endl; + // std::cin >> tmp; + } + //} + + regs->ctrl = 0x00000000; + std::cout << "[INFO] Scalp packet has been sent!" << std::endl; + + return 0; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/samplewrite.bb b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/samplewrite.bb new file mode 100644 index 0000000000000000000000000000000000000000..d986660edd77f447ce8b3c80ddcd65cfbf6ab685 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/samplewrite/samplewrite.bb @@ -0,0 +1,30 @@ +# +# This file is the samplewrite recipe. +# + +SUMMARY = "Simple samplewrite application" +SECTION = "PETALINUX/apps" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files:" + +SRC_URI = "file://samplewrite.cc" +# file://Makefile \ +# " + +S = "${WORKDIR}" + +DEPENDS = "scalp" + +do_compile() { +# oe_runmake + ${CXX} ${CFLAGS} ${LDFLAGS} -o samplewrite samplewrite.cc -lscalp +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 samplewrite ${D}${bindir} +} + +FILES_${PN} += "samplewrite" \ No newline at end of file diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/.gdbinit b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/.gdbinit new file mode 100644 index 0000000000000000000000000000000000000000..760896a756bada91c6625fe928d9dfbb17efd8bf --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/.gdbinit @@ -0,0 +1,3 @@ +# Load the PetaLinux SDK main gdbinit script +source plnx_gdbinit + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/README b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/README new file mode 100644 index 0000000000000000000000000000000000000000..2ef792f18d66beb815736deae9ac6e9c51d5917c --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/README @@ -0,0 +1,32 @@ +PetaLinux User Application Template +=================================== + +This directory contains a PetaLinux user application created from a template. + +If you are developing your application from scratch, simply start editing the +file scalp-lib.c. + +You can easily import any existing application code by copying it into this +directory, and editing the automatically generated Makefile. + +Before building the application, you will need to enable the application +from PetaLinux menuconfig by running: + "petalinux-config -c rootfs" +You will see your application in the "apps --->" submenu. + +To build your application, simply run "petalinux-build -c scalp-lib". +This command will build your application and will install your application +into the target file system host copy. + +You will also need to rebuild PetaLinux bootable images so that the images +is updated with the updated target filesystem copy, run this command: + "petalinux-build -c rootfs" + +You can also run one PetaLinux command to install the application to the +target filesystem host copy and update the bootable images as follows: + "petalinux-build" + +To add extra source code files (for example, to split a large application into +multiple source files), add the relevant .o files to the list in the local +Makefile where indicated. + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/Makefile b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..27e9e286f420eb184a66cc4b50d78299bc02cc7a --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/Makefile @@ -0,0 +1,25 @@ +# Makefile template for a shared library in C + +CXXFLAGS = -std=c++17 -fPIC -Wall -Wextra -O2 -g +LDFLAGS = -shared +RM = rm -f +TARGET_LIB = scalp-lib.so + +SRCS = scalp-lib.cc +OBJS = $(SRCS:.cc=.o) +OTHS = *~ + +.PHONY: all +all: ${TARGET_LIB} + +$(TARGET_LIB): $(OBJS) + $(CXX) ${LDFLAGS} -o $@ $^ + +$(SRCS:.cc=.d):%.d:%.cc + $(CXX) $(CFLAGS) -MM $< >$@ + +include $(SRCS:.cc=.d) + +.PHONY: clean +clean: + -${RM} ${TARGET_LIB} ${OBJS} $(SRCS:.cc=.d) ${OTHS} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/include/#scalp-lib.hh# b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/include/#scalp-lib.hh# new file mode 100644 index 0000000000000000000000000000000000000000..219589c52e3436c6f64358b7b81e543fd82ee44d --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/include/#scalp-lib.hh# @@ -0,0 +1,62 @@ +#ifndef __SCALP_LIB_HH__ +#define __SCALP_LIB_HH__ + +#include <cstdint> +#include <cstddef> +#include <atomic> + +#define SCALP_ROUTER_UIO_DEV "/dev/uio0" + +using namespace std; + +namespace scalp_lib +{ + struct sr_regs + { + public : + // Registers + std::atomic<uint32_t> sp_wr_data; + std::atomic<uint32_t> sp_rd_data; + // Same register, but different access + std::atomic<uint32_t> sp_ctrl; + std::atomic<uint32_t> sp_set_ctrl; + std::atomic<uint32_t> sp_clr_ctrl; + // + std::atomic<uint32_t> sp_status; + std::atomic<uint32_t> sp_txwr_datacnt; + std::atomic<uint32_t> sp_txrd_datacnt; + std::atomic<uint32_t> sp_rxwr_datacnt; + std::atomic<uint32_t> sp_rxrd_datacnt; + std::atomic<uint32_t> sp_loc_netaddr; + // Others + static const std::size_t sp_mmap_size = 4096; + }; + + class uio + { + private : + int32_t _uiofd; + + public : + explicit uio(const char *dev); + ~uio(); + void unmask_interrupt(); + void wait_interrupt(uint32_t timeout_ms); + friend class uio_mmap; + }; + + class uio_mmap + { + private : + size_t _size; + void *_ptr; + + public : + uio_mmap(const uio &u, uint32_t index, size_t size); + ~uio_mmap(); + size_t size() const { return _size; } + void *get_ptr() const { return _ptr; } + }; +}; + +#endif diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/include/scalp-lib.hh b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/include/scalp-lib.hh new file mode 100644 index 0000000000000000000000000000000000000000..e68a145b835dcc609728082962fe5b0b0f9a2650 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/include/scalp-lib.hh @@ -0,0 +1,60 @@ +#ifndef __SCALP_LIB_HH__ +#define __SCALP_LIB_HH__ + +#include <cstdint> +#include <cstddef> +#include <atomic> + +#define SCALP_ROUTER_UIO_DEV "/dev/uio0" +#define SCALP_ROUTER_MMAP_SIZE 0x1000 + +using namespace std; + +namespace scalp_lib +{ + struct sr_regs + { + public : + std::atomic<uint32_t> sp_wr_data; + std::atomic<uint32_t> sp_rd_data; + // Same register, but different access + std::atomic<uint32_t> sp_ctrl; + std::atomic<uint32_t> sp_set_ctrl; + std::atomic<uint32_t> sp_clr_ctrl; + // + std::atomic<uint32_t> sp_status; + std::atomic<uint32_t> sp_txwr_datacnt; + std::atomic<uint32_t> sp_txrd_datacnt; + std::atomic<uint32_t> sp_rxwr_datacnt; + std::atomic<uint32_t> sp_rxrd_datacnt; + std::atomic<uint32_t> sp_loc_netaddr; + }; + + class uio + { + private : + int32_t _uiofd; + + public : + explicit uio(const char *dev); + ~uio(); + void unmask_interrupt(); + void wait_interrupt(uint32_t timeout_ms); + friend class uio_mmap; + }; + + class uio_mmap + { + private : + size_t _size; + void *_ptr; + + public : + uio_mmap(const uio &u, uint32_t index, size_t size); + ~uio_mmap(); + size_t size() const { return _size; } + void *get_ptr() const { return _ptr; } + }; +}; + +#endif diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/include/scalp-lib.hh~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/include/scalp-lib.hh~ new file mode 100644 index 0000000000000000000000000000000000000000..26af3fc3c6287bf1798e693fe118a3c03d26f5e1 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/include/scalp-lib.hh~ @@ -0,0 +1,6 @@ +#ifndef __SCALP_LIB_HH__ +#define __SCALP_LIB_HH__ + +#define SCALP_ROUTER_MMAP_SIZE 0x1000 + +#endif diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/scalp-lib.cc b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/scalp-lib.cc new file mode 100644 index 0000000000000000000000000000000000000000..ee85254505d8eec7da2bd855b647a305fe7bf326 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/files/scalp-lib.cc @@ -0,0 +1,94 @@ +#include <iostream> +#include <unistd.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <cstdlib> +#include <cstdint> +#include <poll.h> +#include <errno.h> +#include <stdexcept> + +#include "include/scalp-lib.hh" + +using namespace std; + +scalp_lib::uio::uio(const char *dev) +{ + if((_uiofd = open(dev, O_RDWR)) < 0) + { + throw std::runtime_error("failed to open UIO device"); + } +} + +scalp_lib::uio::~uio() +{ + close(_uiofd); +} + +void scalp_lib::uio::unmask_interrupt() +{ + uint32_t unmask = 1; + ssize_t rv; + + if((rv = write(_uiofd, &unmask, sizeof(unmask))) != (ssize_t)sizeof(unmask)) + { + perror("scalp_lib::uio::unmask_interrupt()"); + } + +} + +void scalp_lib::uio::wait_interrupt(uint32_t timeout_ms) +{ + // Wait for interrupt + struct pollfd pfd = {.fd = _uiofd, + .events = POLLIN}; + int32_t rv = poll(&pfd, 1, timeout_ms); + + // Clear interrupt + if(rv >= 1) + { + uint32_t info; + read(_uiofd, &info, sizeof(info)); + } + else if(rv == 0) + { + cout << "scalp_lib::uio::wait_interrupt() : device busy" << endl; + } + else + { + perror("scalp_lib::uio::wait_interrupt()"); + } +} + +scalp_lib::uio_mmap::uio_mmap(const scalp_lib::uio &u, uint32_t index, size_t size) : _size(size) +{ + if((_ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, u._uiofd, index * getpagesize())) == MAP_FAILED) + { + perror("scalp_lib::uio_mmap::uio_mmap"); + std::runtime_error("uio_mmap construction failed"); + } +} + +scalp_lib::uio_mmap::~uio_mmap() +{ + munmap(_ptr, _size); +} + +// int main(int argc, char *argv[]) +// { +// scalp_lib::uio uio_dev("/dev/uio0"); +// scalp_lib::uio_mmap mmap_sr_regs(uio_dev, 0, 4096); +// scalp_lib::sr_regs *regs = reinterpret_cast<scalp_lib::sr_regs *>(mmap_sr_regs.get_ptr()); + +// cout << "Hello, PetaLinux World!\n"; +// cout << "cmdline args:\n"; +// while(argc--) +// cout << *argv++ << endl; + +// cout << SCALP_ROUTER_MMAP_SIZE; + +// return 0; +// } + + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/scalp-lib.bb b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/scalp-lib.bb new file mode 100644 index 0000000000000000000000000000000000000000..63c2c81d4e7fb200a8633c78ed4eafb4d32d448a --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-lib/scalp-lib.bb @@ -0,0 +1,26 @@ +# +# This file is the scalp-lib recipe. +# + +SUMMARY = "Simple scalp-lib libs application" +SECTION = "PETALINUX/apps" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +SRC_URI = "file://scalp-lib.cpp \ + file://Makefile \ + " + +S = "${WORKDIR}" + +do_compile() { + oe_runmake +} + +do_install() { + install -d ${D}${libdir} + install -m 0755 scalp-lib.so ${D}${libdir} +} + +# FILES_${PN} += "${libdir}" +# FILES_SOLIBSDEV = "" \ No newline at end of file diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/.gdbinit b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/.gdbinit new file mode 100644 index 0000000000000000000000000000000000000000..d59fb8d90efb393c83d35becbecddcfa493a5e67 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/.gdbinit @@ -0,0 +1,2 @@ +# Load the PetaLinux SDK main gdbinit script +source plnx_gdbinit diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/README b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/README new file mode 100644 index 0000000000000000000000000000000000000000..0d659a457ac2095730cb9ae5761cef9408a35519 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/README @@ -0,0 +1,32 @@ +PetaLinux User Application Template +=================================== + +This directory contains a PetaLinux user application created from a template. + +If you are developing your application from scratch, simply start editing the +file scalp-locaddr.c. + +You can easily import any existing application code by copying it into this +directory, and editing the automatically generated Makefile. + +Before building the application, you will need to enable the application +from PetaLinux menuconfig by running: + "petalinux-config -c rootfs" +You will see your application in the "apps --->" submenu. + +To build your application, simply run "petalinux-build -c scalp-locaddr". +This command will build your application and will install your application +into the target file system host copy. + +You will also need to rebuild PetaLinux bootable images so that the images +is updated with the updated target filesystem copy, run this command: + "petalinux-build -c rootfs" + +You can also run one PetaLinux command to install the application to the +target filesystem host copy and update the bootable images as follows: + "petalinux-build" + +To add extra source code files (for example, to split a large application into +multiple source files), add the relevant .o files to the list in the local +Makefile where indicated. + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/#scalp-locaddr.cc# b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/#scalp-locaddr.cc# new file mode 100644 index 0000000000000000000000000000000000000000..60e474d363fa837d73e4da1382d9b7f46d45d789 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/#scalp-locaddr.cc# @@ -0,0 +1,115 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h> +#include <scalp/scalp.hh> + +void print_help(void); +uint32_t get_locaddr(void); +uint32_t set_locaddr(uint8_t x, uint8_t y, uint8_t z); + +int main(int argc, char **argv) +{ + char arg_help[4] = "-h"; + char arg_setaddr[4] = "-s"; + char arg_getaddr[4] = "-g"; + + libscalp::uio devuio("/dev/uio0"); + libscalp::uio_mmap mmap_regs(devuio, 0, 4096); + libscalp::scalp_noc_regs *regs = reinterpret_cast<libscalp::scalp_noc_regs *>(mmap_regs.get_ptr()); + + if(argc >= 1) + { + print_help(); + return EXIT_SUCCESS; + } + else if(argc == 2) + { + if(strncmp(argv[1], arg_help, 2) == 0) + { + print_help(); + return EXIT_SUCCESS; + } + else if(strncmp(argv[1], arg_getaddr, 2) == 0) + { + get_locaddr(); + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else if(argc == 5) + { + if(strncmp(argv[1], arg_setaddr, 2) == 0) + { + set_locaddr(atoi(argv[2]), atoi(argv[3]), atoi(argv[4])); + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +void print_help(void) +{ + std::cout << "Usage :\n" << std::endl; + std::cout << "\tscalp-locaddr -h : print this help" << std::endl; + std::cout << "\tscalp-locaddr -g : print the local Scalp node address" << std::endl; + std::cout << "\tscalp-locaddr -s <X> <Y> <Z> : set the local Scalp node address" << std::endl; + + return; +} + +uint32_t set_locaddr(uint8_t x, uint8_t y, uint8_t z) +{ + uint32_t locaddr = 0x0; + + locaddr = (0x00 << 24) & (z << 16) & (y << 8) & x; + + // Set local Scalp NoC address. + regs->loc_netaddr = (uint32_t)locaddr; + std::cout << "[INFO] Loc NetAddr : " << regs->loc_netaddr << std::endl; + + return 0; +} + +uint32_t get_locaddr(void) +{ + // Get local Scalp NoC address. + std::cout << "[INFO] Loc NetAddr : " << regs->loc_netaddr << std::endl; + + return 0; +} + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/Makefile b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..119baaca77b56f00a0bef1598490a4e8b18f5a16 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/Makefile @@ -0,0 +1,14 @@ +APP = scalp-locaddr + +# Add any other object files to this list below +APP_OBJS = scalp-locaddr.o + +all: build + +build: $(APP) + +$(APP): $(APP_OBJS) + $(CC) -o $@ $(APP_OBJS) $(LDFLAGS) $(LDLIBS) +clean: + rm -f $(APP) *.o + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/scalp-locaddr.cc b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/scalp-locaddr.cc new file mode 100644 index 0000000000000000000000000000000000000000..cfe4fede9c06fbe258fc53978141731c6bfa56e0 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/scalp-locaddr.cc @@ -0,0 +1,116 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h> +#include <scalp/scalp.hh> + +void print_help(void); +uint32_t get_locaddr(void); +uint32_t set_locaddr(uint8_t x, uint8_t y, uint8_t z); + +int main(int argc, char **argv) +{ + char arg_help[4] = "-h"; + char arg_setaddr[4] = "-s"; + char arg_getaddr[4] = "-g"; + + libscalp::uio devuio("/dev/uio0"); + libscalp::uio_mmap mmap_regs(devuio, 0, 4096); + libscalp::scalp_noc_regs *regs = reinterpret_cast<libscalp::scalp_noc_regs *>(mmap_regs.get_ptr()); + + if(argc >= 1) + { + print_help(); + return EXIT_SUCCESS; + } + else if(argc == 2) + { + if(strncmp(argv[1], arg_help, 2) == 0) + { + print_help(); + return EXIT_SUCCESS; + } + else if(strncmp(argv[1], arg_getaddr, 2) == 0) + { + get_locaddr(); + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else if(argc == 5) + { + if(strncmp(argv[1], arg_setaddr, 2) == 0) + { + set_locaddr(atoi(argv[2]), atoi(argv[3]), atoi(argv[4])); + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +void print_help(void) +{ + std::cout << "Usage :\n" << std::endl; + std::cout << "\tscalp-locaddr -h : print this help" << std::endl; + std::cout << "\tscalp-locaddr -g : print the local Scalp node address" << std::endl; + std::cout << "\tscalp-locaddr -s <X> <Y> <Z> : set the local Scalp node address" << std::endl; + + return; +} + +uint32_t set_locaddr(uint8_t x, uint8_t y, uint8_t z) +{ + uint32_t locaddr = 0x0; + + locaddr = (0x00 << 24) & (z << 16) & (y << 8) & x; + + // Set local Scalp NoC address. + regs->loc_netaddr = (uint32_t)locaddr; + std::cout << "[INFO] Loc NetAddr : " << regs->loc_netaddr << std::endl; + + return 0; +} + +uint32_t get_locaddr(void) +{ + // Get local Scalp NoC address. + std::cout << "[INFO] Loc NetAddr : " << regs->loc_netaddr << std::endl; + + return 0; +} + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/scalp-locaddr.cc~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/scalp-locaddr.cc~ new file mode 100644 index 0000000000000000000000000000000000000000..17f78a20b4662150e035f4111992f04d247da7dd --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/files/scalp-locaddr.cc~ @@ -0,0 +1,101 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +//#include <scalp/scalp.hh> + +void print_help(void); +uint32_t set_locaddr(void); +uint32_t get_locaddr(void); + +int main(int argc, char **argv) +{ + char arg_help[4] = "-h"; + char arg_setaddr[4] = "-s"; + char arg_getaddr[4] = "-g"; + + // Set local Scalp NoC address. + //regs->loc_netaddr = 0x00000001; + //std::cout << "Loc NetAddr : " << regs->loc_netaddr << std::endl; + + + + if(argc >= 1) + { + print_help(); + return EXIT_SUCCESS; + } + else if(argc == 2) + { + if(strncmp(argv[1], arg_help, 2) == 0) + { + print_help(); + return EXIT_SUCCESS; + } + else if(strncmp(argv[1], arg_getaddr, 2) == 0) + { + get_locaddr(); + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else if(argc == 3) + { + if(strncmp(argv[1], arg_setaddr, 2) == 0) + { + set_locaddr(); + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +void print_help(void) +{ + return; +} + +uint32_t set_locaddr(void) +{ + return 0; +} + +uint32_t get_locaddr(void) +{ + return 0; +} + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/scalp-locaddr.bb b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/scalp-locaddr.bb new file mode 100644 index 0000000000000000000000000000000000000000..fb5853a11ee7cc2b7089a8de899e8dfbb729928c --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/scalp-locaddr.bb @@ -0,0 +1,31 @@ +# +# This file is the scalp-locaddr recipe. +# + +SUMMARY = "Simple scalp-locaddr application" +SECTION = "PETALINUX/apps" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +#FILESEXTRAPATHS_prepend := "${THISDIR}/files: + +SRC_URI = "file://scalp-locaddr.cc" +# \ +# file://Makefile \ +# " + +S = "${WORKDIR}" + +DEPENDS = "scalp" + +do_compile() { + #oe_runmake + ${CXX} ${CFLAGS} ${LDFLAGS} -o scalp-locaddr scalp-locaddr.cc -lscalp +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 scalp-locaddr ${D}${bindir} +} + +#FILES_${PN} += "scalp-locaddr" \ No newline at end of file diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/scalp-locaddr.bb~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/scalp-locaddr.bb~ new file mode 100644 index 0000000000000000000000000000000000000000..67a6dde7957f7a0f851ead33fc68dbb863225b62 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalp-locaddr/scalp-locaddr.bb~ @@ -0,0 +1,31 @@ +# +# This file is the scalp-locaddr recipe. +# + +SUMMARY = "Simple scalp-locaddr application" +SECTION = "PETALINUX/apps" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files: + +SRC_URI = "file://scalp-locaddr.cc" +# \ +# file://Makefile \ +# " + +S = "${WORKDIR}" + +DEPENDS = "scalp" + +do_compile() { + #oe_runmake + ${CXX} ${CFLAGS} ${LDFLAGS} -o scalp-locaddr scalp-locaddr.cc -lscalp +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 scalp-locaddr ${D}${bindir} +} + +FILES_${PN} += "scalp-locaddr" \ No newline at end of file diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/.gdbinit b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/.gdbinit new file mode 100644 index 0000000000000000000000000000000000000000..d59fb8d90efb393c83d35becbecddcfa493a5e67 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/.gdbinit @@ -0,0 +1,2 @@ +# Load the PetaLinux SDK main gdbinit script +source plnx_gdbinit diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/README b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/README new file mode 100644 index 0000000000000000000000000000000000000000..a31b76647ae4ad10ac279010c81ef1a04f50d55b --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/README @@ -0,0 +1,32 @@ +PetaLinux User Application Template +=================================== + +This directory contains a PetaLinux user application created from a template. + +If you are developing your application from scratch, simply start editing the +file scalplocaddr.c. + +You can easily import any existing application code by copying it into this +directory, and editing the automatically generated Makefile. + +Before building the application, you will need to enable the application +from PetaLinux menuconfig by running: + "petalinux-config -c rootfs" +You will see your application in the "apps --->" submenu. + +To build your application, simply run "petalinux-build -c scalplocaddr". +This command will build your application and will install your application +into the target file system host copy. + +You will also need to rebuild PetaLinux bootable images so that the images +is updated with the updated target filesystem copy, run this command: + "petalinux-build -c rootfs" + +You can also run one PetaLinux command to install the application to the +target filesystem host copy and update the bootable images as follows: + "petalinux-build" + +To add extra source code files (for example, to split a large application into +multiple source files), add the relevant .o files to the list in the local +Makefile where indicated. + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/Makefile b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2069eb12133625b819eaed2c3300051b5de67af --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/Makefile @@ -0,0 +1,14 @@ +APP = scalplocaddr + +# Add any other object files to this list below +APP_OBJS = scalplocaddr.o + +all: build + +build: $(APP) + +$(APP): $(APP_OBJS) + $(CC) -o $@ $(APP_OBJS) $(LDFLAGS) $(LDLIBS) +clean: + rm -f $(APP) *.o + diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/scalplocaddr b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/scalplocaddr new file mode 100755 index 0000000000000000000000000000000000000000..7a5460fc258d618764a5cf99ef3fa798e346aafc Binary files /dev/null and b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/scalplocaddr differ diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/scalplocaddr.cc b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/scalplocaddr.cc new file mode 100644 index 0000000000000000000000000000000000000000..3a593f9a80fb31fbfa9fd286e5575ddc54751b7e --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/scalplocaddr.cc @@ -0,0 +1,112 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h> +#include <scalp/scalp.hh> + +void print_help(void); + +int main(int argc, char **argv) +{ + char arg_help[4] = "-h"; + char arg_setaddr[4] = "-s"; + char arg_getaddr[4] = "-g"; + + uint32_t locaddr = 0x0; + + // libscalp::uio devuio("/dev/uio0"); + // libscalp::uio_mmap mmap_regs(devuio, 0, 4096); + // libscalp::scalp_noc_regs *regs = reinterpret_cast<libscalp::scalp_noc_regs *>(mmap_regs.get_ptr()); + // libscalp::uio *devuio = NULL; + // libscalp::uio_mmap *mmap_regs = NULL; + //libscalp::scalp_noc_regs *regs = NULL; + void *regs = NULL; + void *devuio = NULL; + void *mmap_regs = NULL; + + if((regs = libscalp::scalp_noc_init("/dev/uio0", &devuio, &mmap_regs)) == NULL) + return EXIT_FAILURE; + + if(argc <= 1) + { + print_help(); + return EXIT_SUCCESS; + } + else if(argc == 2) + { + if(strncmp(argv[1], arg_help, 2) == 0) + { + print_help(); + return EXIT_SUCCESS; + } + else if(strncmp(argv[1], arg_getaddr, 2) == 0) + { + std::cout << "[INFO] Get Loc NetAddr : " << std::hex << libscalp::scalp_noc_get_locaddr(regs) << std::endl; + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else if(argc == 5) + { + if(strncmp(argv[1], arg_setaddr, 2) == 0) + { + // locaddr = (0x00 << 24) | ((uint8_t)(atoi(argv[4])) << 16) | ((uint8_t)(atoi(argv[3])) << 8) | (uint8_t)(atoi(argv[2])); + // std::cout << "[INFO] Set Loc NetAddr : " << std::hex << locaddr << std::endl; + // regs->loc_netaddr = (uint32_t)locaddr; + + if(libscalp::scalp_noc_set_locaddr(regs, (uint32_t)atoi(argv[2]), (uint32_t)atoi(argv[3]), (uint32_t)atoi(argv[4])) == false) + return EXIT_FAILURE; + + std::cout << "[INFO] Set Loc NetAddr : " << std::hex << libscalp::scalp_noc_get_locaddr(regs) << std::endl; + + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else + return EXIT_FAILURE; + + libscalp::scalp_noc_free(devuio, mmap_regs); + + return EXIT_SUCCESS; +} + +void print_help(void) +{ + std::cout << "Usage :\n" << std::endl; + std::cout << "\tscalp-locaddr -h : print this help" << std::endl; + std::cout << "\tscalp-locaddr -g : print the local Scalp node address" << std::endl; + std::cout << "\tscalp-locaddr -s <X> <Y> <Z> : set the local Scalp node address" << std::endl; + + return; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/scalplocaddr.cc~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/scalplocaddr.cc~ new file mode 100644 index 0000000000000000000000000000000000000000..3241b4847c5d9bc05851f49a3f28aedf26abb128 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/files/scalplocaddr.cc~ @@ -0,0 +1,115 @@ +/* +* Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in this +* Software without prior written authorization from Xilinx. +* +*/ + +#include <iostream> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h> +#include <scalp/scalp.hh> + +void print_help(void); + +int main(int argc, char **argv) +{ + char arg_help[4] = "-h"; + char arg_setaddr[4] = "-s"; + char arg_getaddr[4] = "-g"; + + uint32_t locaddr = 0x0; + + // libscalp::uio devuio("/dev/uio0"); + // libscalp::uio_mmap mmap_regs(devuio, 0, 4096); + // libscalp::scalp_noc_regs *regs = reinterpret_cast<libscalp::scalp_noc_regs *>(mmap_regs.get_ptr()); + // libscalp::uio *devuio = NULL; + // libscalp::uio_mmap *mmap_regs = NULL; + //libscalp::scalp_noc_regs *regs = NULL; + void *regs = NULL; + libscalp::scalp_noc_regs *_regs = NULL; + + if((regs = libscalp::scalp_noc_init("/dev/uio0")) == NULL) + return EXIT_FAILURE; + + _regs = reinterpret_cast<libscalp::scalp_noc_regs *>(regs); + + if(argc <= 1) + { + print_help(); + return EXIT_SUCCESS; + } + else if(argc == 2) + { + if(strncmp(argv[1], arg_help, 2) == 0) + { + print_help(); + return EXIT_SUCCESS; + } + else if(strncmp(argv[1], arg_getaddr, 2) == 0) + { + std::cout << "[INFO] Get Loc NetAddr : " << std::hex << _regs->loc_netaddr << std::endl; + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else if(argc == 5) + { + if(strncmp(argv[1], arg_setaddr, 2) == 0) + { + // locaddr = (0x00 << 24) | ((uint8_t)(atoi(argv[4])) << 16) | ((uint8_t)(atoi(argv[3])) << 8) | (uint8_t)(atoi(argv[2])); + // std::cout << "[INFO] Set Loc NetAddr : " << std::hex << locaddr << std::endl; + // regs->loc_netaddr = (uint32_t)locaddr; + + if(libscalp::scalp_noc_set_locaddr(regs, (uint32_t)atoi(argv[2]), (uint32_t)atoi(argv[3]), (uint32_t)atoi(argv[4])) == false) + return EXIT_FAILURE; + + std::cout << "[INFO] Set Loc NetAddr : " << std::hex << _regs->loc_netaddr << std::endl; + + return EXIT_SUCCESS; + } + else + return EXIT_FAILURE; + } + else + return EXIT_FAILURE; + + _regs->ctrl = 0x00000000; + + //libscalp::scalp_noc_free(devuio, mmap_regs); + + return EXIT_SUCCESS; +} + +void print_help(void) +{ + std::cout << "Usage :\n" << std::endl; + std::cout << "\tscalp-locaddr -h : print this help" << std::endl; + std::cout << "\tscalp-locaddr -g : print the local Scalp node address" << std::endl; + std::cout << "\tscalp-locaddr -s <X> <Y> <Z> : set the local Scalp node address" << std::endl; + + return; +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/scalplocaddr.bb b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/scalplocaddr.bb new file mode 100644 index 0000000000000000000000000000000000000000..e3919168efa2588f0956150cf69cff84ef9ad72d --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/scalplocaddr.bb @@ -0,0 +1,30 @@ +# +# This file is the scalplocaddr recipe. +# + +SUMMARY = "Simple scalplocaddr application" +SECTION = "PETALINUX/apps" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files:" + +SRC_URI = "file://scalplocaddr.cc" +# file://Makefile \ +# " + +S = "${WORKDIR}" + +DEPENDS = "scalp" + +do_compile() { +# oe_runmake + ${CXX} ${CFLAGS} ${LDFLAGS} -o scalplocaddr scalplocaddr.cc -lscalp +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 scalplocaddr ${D}${bindir} +} + +FILES_${PN} += "scalplocaddr" \ No newline at end of file diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/scalplocaddr.bb~ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/scalplocaddr.bb~ new file mode 100644 index 0000000000000000000000000000000000000000..0b1141d970bcab5e6bb08957236ab732940a5bb8 --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-apps/scalplocaddr/scalplocaddr.bb~ @@ -0,0 +1,23 @@ +# +# This file is the scalplocaddr recipe. +# + +SUMMARY = "Simple scalplocaddr application" +SECTION = "PETALINUX/apps" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +SRC_URI = "file://scalplocaddr.c \ + file://Makefile \ + " + +S = "${WORKDIR}" + +do_compile() { + oe_runmake +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 scalplocaddr ${D}${bindir} +} diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/device-tree.bbappend b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/device-tree.bbappend index fabb6de7cabf4a734b560038fb88f5f7dedbee69..59555f20b8d5c06e2f5c136cadab9aaca3aadde4 100644 --- a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/device-tree.bbappend +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/device-tree.bbappend @@ -1,6 +1,7 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/files:" SRC_URI += "file://system-user.dtsi" +SRC_URI += "file://scalp-router.dtsi" python () { if d.getVar("CONFIG_DISABLE"): diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/pl-custom.dtsi b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/pl-custom.dtsi index 336d7a2506781606dfd8067e11ce7dd0ea8d5b06..449383576f4596d42956e1c787b3c8afbf2acc5e 100644 --- a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/pl-custom.dtsi +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/pl-custom.dtsi @@ -1,2 +1,14 @@ / { -}; + // amba_pl: amba_pl { + // #address-cells = <1>; + // #size-cells = <1>; + // compatible = "simple-bus"; + // ranges ; + + // scalp_router_regbank_1: scalp_router_regbank@43c00000 { + // compatible = "generic-uio"; + // reg = <0x43c00000 0x1000>; + // status = "okay"; + // }; + // }; +}; \ No newline at end of file diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/scalp-router.dtsi b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/scalp-router.dtsi new file mode 100644 index 0000000000000000000000000000000000000000..bf1de771e5c02e6223e81a3eceba7a3315432e0e --- /dev/null +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/scalp-router.dtsi @@ -0,0 +1,14 @@ +/ { + amba_pl: amba_pl { + #address-cells = <1>; + #size-cells = <1>; + compatible = "simple-bus"; + ranges ; + + scalp_router_regbank_1: scalp_router_regbank@43c00000 { + compatible = "generic-uio"; + reg = <0x43c00000 0x1000>; + status = "okay"; + }; + }; +}; \ No newline at end of file diff --git a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi index 2c0e8cc6497ed7de071acfe01eecb0ea4c4bf7a0..e9f6b87507129cffd70c017e838235516a860199 100644 --- a/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi +++ b/scalp_router_firmware_petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi @@ -7,6 +7,7 @@ */ /include/ "system-conf.dtsi" +/include/ "scalp-router.dtsi" #include <dt-bindings/gpio/gpio.h> / { @@ -301,4 +302,19 @@ &can1 { u-boot,dm-pre-reloc; status = "okay"; -}; \ No newline at end of file +}; + +// / { +// amba_pl: amba_pl { +// #address-cells = <1>; +// #size-cells = <1>; +// compatible = "simple-bus"; +// ranges ; + +// scalp_router_regbank_1: scalp_router_regbank@43c00000 { +// compatible = "generic-uio"; +// reg = <0x43c00000 0x1000>; +// status = "okay"; +// }; +// }; +// };