:name: FPGA ISP on Zynq
:description: This script runs Linux with FPGA ISP driver.

using sysbus
$name?="FPGA-ISP"
mach create $name

machine LoadPlatformDescription @platforms/boards/mars_zx3.repl
machine LoadPlatformDescriptionFromString 'virtio: Storage.VirtIOBlockDevice @ sysbus 0x400d0000 { IRQ->gic@32 }'
machine LoadPlatformDescriptionFromString 'isp: CoSimulated.CoSimulatedPeripheral @ sysbus <0x43c00000, +0x20000> { frequency: 100000; limitBuffer: 1000000; timeout: 10000; 0->gic@29; 1->gic@31; cosimToRenodeSignalRange: <0, +2> }'

sysbus Redirect 0xC0000000 0x0 0x10000000

$bin?=@https://dl.antmicro.com/projects/renode/zynq-verilated-fpga-isp--vmlinux-s_13735336-6a3e10bd5b6d301cc8846490cad6de9ec541e067
$rootfs?=@https://dl.antmicro.com/projects/renode/zynq-verilated-fpga-isp--rootfs.ext2-s_33554432-cc9664564461b5be36a4d1841e50a760dc7f5ad1
$dtb?=@https://dl.antmicro.com/projects/renode/zynq-verilated-fpga-isp--video-board.dtb-s_13451-bdb696327471e2247f811b03f37be84df994379a
$ispLinux?=@https://dl.antmicro.com/projects/renode/libVfpga_isp-Linux-x86_64-12746432362.so-s_2489608-a59deb01cc5c468b4d3e6ff334111616212bed77
$ispWindows?=@https://dl.antmicro.com/projects/renode/libVfpga_isp-Windows-x86_64-12746432362.dll-s_3674314-2ce8c0c902ab1c4ea8b4768082bb8d1c8d8b4780
$ispMacOS?=@https://dl.antmicro.com/projects/renode/libVfpga_isp-macOS-x86_64-12746432362.dylib-s_466960-768bc1b71cf8cc6149e535c03c8d7309389f35f3

## set timer frequency ##
ttc0 Frequency 33333333
ttc1 Frequency 33333333

### create externals ###
showAnalyzer sysbus.uart0

### set registers ###
cpu SetRegister 0 0x000
cpu SetRegister 1 0xD32 # processor variant (cortex-a9)
cpu SetRegister 2 0x100 # device tree address

### load binaries ###
sysbus LoadELF $bin
sysbus LoadFdt $dtb 0x100 "console=ttyPS0,115200 root=/dev/ram0 rw initrd=0x1a000000,32M" false
sysbus ZeroRange 0x1a000000 0x800000
sysbus LoadBinary $rootfs 0x1a000000

isp SimulationFilePathLinux $ispLinux
isp SimulationFilePathWindows $ispWindows
isp SimulationFilePathMacOS $ispMacOS

$virtio?=@https://dl.antmicro.com/projects/renode/empty-ext4-filesystem.img-s_33554432-1eb65a808612389cc35a69b81178fbad5708a863
virtio LoadImage $virtio
