Skip to content
Snippets Groups Projects
Commit e2bd15bc authored by dwf1m12's avatar dwf1m12
Browse files

upgrade ADP to v4 with 8/16/32-bit support (byte-count upload count)

parent 91ce5d7d
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# nanosoc ADP validation
This notebook demonstrates how to download an FPGA overlay and examine programmable logic state.
## 1. Setting up and checking the overlay
With the following overlay bundle present in the `overlays` folder, users can instantiate the overlay easily.
* A bitstream file (\*.bit).
* An hwh file (\*.hwh).
* A python class (\*.py).
For example, an overlay called `base` can be loaded by:
```python
from pynq.overlays.base import BaseOverlay
overlay = BaseOverlay("base.bit")
```
Users can also use the absolute file path of the bitstream to instantiate the overlay.
In this notebook, we get the current bitstream loaded on PL, and try to download it multiple times.
%% Cell type:code id: tags:
``` python
import os, warnings
from pynq import PL
from pynq import Overlay
ol = Overlay("/home/xilinx/pynq/overlays/soclabs/design_1.bit")
if not os.path.exists(PL.bitfile_name):
warnings.warn('There is no overlay loaded after boot.', UserWarning)
```
%% Output
%% Cell type:markdown id: tags:
**Note**: If you see a warning message in the above cell, it means that no overlay
has been loaded after boot, hence the PL server is not aware of the
current status of the PL. In that case you won't be able to run this notebook
until you manually load an overlay at least once using:
```python
from pynq import Overlay
ol = Overlay('your_overlay.bit')
```
If you do not see any warning message, you can safely proceed.
%% Cell type:code id: tags:
``` python
ol = Overlay(PL.bitfile_name)
```
%% Cell type:markdown id: tags:
Now we can check the download timestamp for this overlay.
%% Cell type:code id: tags:
``` python
ol.download()
ol.timestamp
```
%% Output
'2023/4/24 19:21:45 +459963'
%% Cell type:markdown id: tags:
## 2. Examining the overlay
Uncomment the #PL.ip_dict command to see the full details
%% Cell type:code id: tags:
``` python
print(PL.bitfile_name)
print(PL.timestamp)
#PL.ip_dict
```
%% Output
/home/xilinx/pynq/overlays/soclabs/design_1.bit
2023/4/24 19:21:45 +459963
%% Cell type:markdown id: tags:
### Interrogate the HWH database for interface addresses
%% Cell type:code id: tags:
``` python
ADP_address = PL.ip_dict['cmsdk_socket/axi_stream_io_0']['phys_addr']
print("ADPIO stream interface: ",hex(ADP_address))
UART2_address = PL.ip_dict['cmsdk_socket/axi_uartlite_0']['phys_addr']
print("UART(2) interface: ",hex(UART2_address))
```
%% Output
ADPIO stream interface: 0x43c00000
UART(2) interface: 0x42c00000
%% Cell type:markdown id: tags:
### Set up interface functions for ADP
%% Cell type:code id: tags:
``` python
from pynq import Overlay
from pynq import MMIO
import time
from time import sleep, time
# HARDWARE CONSTANTS
RX_FIFO = 0x00
TX_FIFO = 0x04
# Status Reg
STAT_REG = 0x08
RX_VALID = 0
RX_FULL = 1
TX_EMPTY = 2
TX_FULL = 3
IS_INTR = 4
# Ctrl Reg
CTRL_REG = 0x0C
RST_TX = 0
RST_RX = 1
INTR_EN = 4
class ADPIO:
def __init__(self, address):
# Setup axi core
self.uart = MMIO(address, 0x10000, debug=False)
self.address = address
def setupCtrlReg(self):
# # Reset FIFOs, disable interrupts
# self.uart.write(CTRL_REG, 1 << RST_TX | 1 << RST_RX)
# sleep(1)
self.uart.write(CTRL_REG, 0)
sleep(1)
def monitorModeEnter(self):
self.uart.write(TX_FIFO, 0x1b)
def monitorModeExit(self):
self.uart.write(TX_FIFO, 0x04)
def wbyte(self, b, timeout=1):
# Write bytes via UART
while (self.uart.read(STAT_REG) & 1 << TX_FULL):
pass
self.uart.write_reg(TX_FIFO,int(b))
return
def read(self, count, timeout=1):
# status = currentStatus(uart) bad idea
buf = ""
stop_time = time() + timeout
for i in range(count):
# Wait till RX fifo has valid data, stop waiting if timeoutpasses
while (not (self.uart.read(STAT_REG) & 1 << RX_VALID)) and (time() < stop_time):
pass
if time() >= stop_time:
break
buf += chr(self.uart.read(RX_FIFO))
return buf
def write(self, buf, timeout=1):
# Write bytes via UART
stop_time = time() + timeout
wr_count = 0
for i in buf:
# Wait while TX FIFO is Full, stop waiting if timeout passes
while (self.uart.read(STAT_REG) & 1 << TX_FULL) and (time() < stop_time):
pass
# Check timeout
if time() > stop_time:
wr_count = -1
break
self.uart.write(TX_FIFO, ord(i))
wr_count += 1
return wr_count
```
%% Cell type:markdown id: tags:
Inspect the ADP banner after reset (0x50CLAB03 expected)
%% Cell type:code id: tags:
``` python
adp = ADPIO(ADP_address)
# Setup AXI UART register
adp.setupCtrlReg()
print(adp.read(100))
```
%% Output
0x50c1ab03
0x50c1ab04
SOCLABS: ARM Cortex-M0 nanosoc
** Remap->RAM2
%% Cell type:markdown id: tags:
### Enter ADP monitor mode ('ESC' char)
And check the ']' prompt appears
%% Cell type:code id: tags:
``` python
adp.monitorModeEnter()
print(adp.read(4))
```
%% Output
]
%% Cell type:markdown id: tags:
Also check the UART2 RX channel for any boot message
%% Cell type:code id: tags:
``` python
uart = ADPIO(UART2_address)
# Setup AXI UART register
uart.setupCtrlReg()
uart.read(50)
```
%% Output
''
%% Cell type:markdown id: tags:
Test 'binary' file upload to memory:
set base address with 'A <hex_address>'
Calculate transfer length in words , padding out final bytes to word boundary
Use the 'U <hex_word_count>' Up-load command (and newline) floolowed by binary file byte-stream
After hex_word_count transfers the ADP prompt is generated and transfer is complete
%% Cell type:code id: tags:
``` python
adp.monitorModeEnter()
print(adp.read(4))
```
%% Output
%% Cell type:code id: tags:
``` python
import os
file_name= "arm_tests/aes128_tests.bin"
file_stats= os.stat(file_name)
file_len_in_bytes = file_stats.st_size
file_len_in_words = int((file_len_in_bytes + 3)/4)
file_pad_in_bytes = (file_len_in_words * 4) - file_len_in_bytes
print(f'file size in bytes is {file_len_in_bytes}')
print(f'file pad in bytes is {file_pad_in_bytes}')
print(f'file size in words is {file_len_in_words}')
wordcount_hex=hex(file_len_in_words)
print(f'file size in words is {wordcount_hex}')
print(f'U '+wordcount_hex+'\n')
bytecount_hex=hex(file_len_in_bytes)
print(f'file size in bytes is {bytecount_hex}')
print(f'U '+bytecount_hex+'\n')
adp.write('A 0x20000000\n')
adp.write('U '+wordcount_hex+'\n')
adp.write('U '+bytecount_hex+'\n')
count = file_len_in_bytes
print(count)
with open(file_name, mode='rb') as file:
while (count>0) :
b=file.read(1)
adp.wbyte(ord(b))
count-=1
count = file_pad_in_bytes
while (count>0) :
b=0
adp.wbyte(b)
count=count-1
print(count)
print(adp.read(100))
```
%% Output
file size in bytes is 7192
file pad in bytes is 0
file size in words is 1798
file size in words is 0x706
U 0x706
U 0x1C18
7192
0
?
]U 0x00000706
]U 0x00001C18
]
%% Cell type:code id: tags:
``` python
adp.write('A 0x20000000\n')
adp.write('R 40\n')
print(adp.read(10000))
```
%% Output
A 0x20000000
]R 0x30001ca0
R 0x00001149
R 0x00001151
R 0x00001153
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00001155
R 0x00000000
R 0x00000000
R 0x00001157
R 0x00001159
R 0x00000cf3
R 0x00000d17
R 0x00000d3b
R 0x00000d5f
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x00000cb1
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0xf802f000
R 0xf842f000
R 0xc830a00c
R 0x18243808
R 0x46a2182d
R 0x46ab1e67
R 0x465d4654
R 0xd10142ac
R 0xf834f000
R 0x3e0f467e
R 0x46b6cc0f
R 0x42332601
R 0x1afbd000
R 0x46ab46a2
R 0x47184333
R 0x00001938
]
%% Cell type:markdown id: tags:
Soft reset to enter the downloaded code
%% Cell type:code id: tags:
``` python
adp.write('C 0x200\n')
adp.write('C 0x201\n')
print(adp.read(10000))
```
%% Output
C 0x00000200
] 0x50c1ab03
] 0x50c1ab04
SOCLABS: ARM Cortex-M0 nanosoc
** Remap->RAM2
soclabs AES128v1
AES128 test program
AES128 ID: aes128 0.01
AES128 SW (memcpy) tests...
AES128 reference pattern test
AES128 input/output bypass test
AES128 encrypt test
AES128 decrypt test
AES128 logic toggle test
AES128 input/output pattern test
AES128 pattern encrypt test
AES128 pattern decrypt test
AES128 DMA tests...
AES128 dma input/output bypass test
++ DMA_DONE IRQ count = 2
AES128 dma encrypt test
AES128 dma decrypt test
++ DMA_DONE IRQ count = 6
AES128 dma unaligned pattern test
AES128 dma input/output pattern test
AES128 dma pattern encrypt test
AES128 dma pattern decrypt test
++ DMA_DONE IRQ count = 14
Data retrieved from the AES is: aes128 0.01
Data expected from the AES is: soclabs AES128v1
** AES TEST PASSED **

......
%% Cell type:markdown id: tags:
# nanosoc ADP validation
This notebook demonstrates how to download an FPGA overlay and examine programmable logic state.
## 1. Setting up and checking the overlay
With the following overlay bundle present in the `overlays` folder, users can instantiate the overlay easily.
* A bitstream file (\*.bit).
* An hwh file (\*.hwh).
* A python class (\*.py).
For example, an overlay called `base` can be loaded by:
```python
from pynq.overlays.base import BaseOverlay
overlay = BaseOverlay("base.bit")
```
Users can also use the absolute file path of the bitstream to instantiate the overlay.
In this notebook, we get the current bitstream loaded on PL, and try to download it multiple times.
%% Cell type:code id: tags:
``` python
import os, warnings
from pynq import PL
from pynq import Overlay
ol = Overlay("/home/xilinx/pynq/overlays/soclabs/design_1.bit")
if not os.path.exists(PL.bitfile_name):
warnings.warn('There is no overlay loaded after boot.', UserWarning)
```
%% Output
%% Cell type:markdown id: tags:
**Note**: If you see a warning message in the above cell, it means that no overlay
has been loaded after boot, hence the PL server is not aware of the
current status of the PL. In that case you won't be able to run this notebook
until you manually load an overlay at least once using:
```python
from pynq import Overlay
ol = Overlay('your_overlay.bit')
```
If you do not see any warning message, you can safely proceed.
%% Cell type:code id: tags:
``` python
ol = Overlay(PL.bitfile_name)
```
%% Cell type:markdown id: tags:
Now we can check the download timestamp for this overlay.
%% Cell type:code id: tags:
``` python
ol.download()
ol.timestamp
```
%% Output
'2023/4/24 19:21:45 +459963'
%% Cell type:markdown id: tags:
## 2. Examining the overlay
Uncomment the #PL.ip_dict command to see the full details
%% Cell type:code id: tags:
``` python
print(PL.bitfile_name)
print(PL.timestamp)
#PL.ip_dict
```
%% Output
/home/xilinx/pynq/overlays/soclabs/design_1.bit
2023/4/24 19:21:45 +459963
%% Cell type:markdown id: tags:
### Interrogate the HWH database for interface addresses
%% Cell type:code id: tags:
``` python
ADP_address = PL.ip_dict['cmsdk_socket/axi_stream_io_0']['phys_addr']
print("ADPIO stream interface: ",hex(ADP_address))
UART2_address = PL.ip_dict['cmsdk_socket/axi_uartlite_0']['phys_addr']
print("UART(2) interface: ",hex(UART2_address))
```
%% Output
ADPIO stream interface: 0x43c00000
UART(2) interface: 0x42c00000
%% Cell type:markdown id: tags:
### Set up interface functions for ADP
%% Cell type:code id: tags:
``` python
from pynq import Overlay
from pynq import MMIO
import time
from time import sleep, time
# HARDWARE CONSTANTS
RX_FIFO = 0x00
TX_FIFO = 0x04
# Status Reg
STAT_REG = 0x08
RX_VALID = 0
RX_FULL = 1
TX_EMPTY = 2
TX_FULL = 3
IS_INTR = 4
# Ctrl Reg
CTRL_REG = 0x0C
RST_TX = 0
RST_RX = 1
INTR_EN = 4
class ADPIO:
def __init__(self, address):
# Setup axi core
self.uart = MMIO(address, 0x10000, debug=False)
self.address = address
def setupCtrlReg(self):
# # Reset FIFOs, disable interrupts
# self.uart.write(CTRL_REG, 1 << RST_TX | 1 << RST_RX)
# sleep(1)
self.uart.write(CTRL_REG, 0)
sleep(1)
def monitorModeEnter(self):
self.uart.write(TX_FIFO, 0x1b)
def monitorModeExit(self):
self.uart.write(TX_FIFO, 0x04)
def wbyte(self, b, timeout=1):
# Write bytes via UART
while (self.uart.read(STAT_REG) & 1 << TX_FULL):
pass
self.uart.write_reg(TX_FIFO,int(b))
return
def read(self, count, timeout=1):
# status = currentStatus(uart) bad idea
buf = ""
stop_time = time() + timeout
for i in range(count):
# Wait till RX fifo has valid data, stop waiting if timeoutpasses
while (not (self.uart.read(STAT_REG) & 1 << RX_VALID)) and (time() < stop_time):
pass
if time() >= stop_time:
break
buf += chr(self.uart.read(RX_FIFO))
return buf
def write(self, buf, timeout=1):
# Write bytes via UART
stop_time = time() + timeout
wr_count = 0
for i in buf:
# Wait while TX FIFO is Full, stop waiting if timeout passes
while (self.uart.read(STAT_REG) & 1 << TX_FULL) and (time() < stop_time):
pass
# Check timeout
if time() > stop_time:
wr_count = -1
break
self.uart.write(TX_FIFO, ord(i))
wr_count += 1
return wr_count
```
%% Cell type:markdown id: tags:
Inspect the ADP banner after reset (0x50CLAB03 expected)
%% Cell type:code id: tags:
``` python
adp = ADPIO(ADP_address)
# Setup AXI UART register
adp.setupCtrlReg()
print(adp.read(100))
```
%% Output
0x50c1ab03
0x50c1ab04
SOCLABS: ARM Cortex-M0 nanosoc
** Remap->RAM2
%% Cell type:markdown id: tags:
### Enter ADP monitor mode ('ESC' char)
And check the ']' prompt appears
%% Cell type:code id: tags:
``` python
adp.monitorModeEnter()
print(adp.read(4))
```
%% Output
]
%% Cell type:markdown id: tags:
Also check the UART2 RX channel for any boot message
%% Cell type:code id: tags:
``` python
uart = ADPIO(UART2_address)
# Setup AXI UART register
uart.setupCtrlReg()
uart.read(50)
```
%% Output
''
%% Cell type:markdown id: tags:
Test 'binary' file upload to memory:
set base address with 'A <hex_address>'
Calculate transfer length in words , padding out final bytes to word boundary
Use the 'U <hex_word_count>' Up-load command (and newline) floolowed by binary file byte-stream
After hex_word_count transfers the ADP prompt is generated and transfer is complete
%% Cell type:code id: tags:
``` python
adp.monitorModeEnter()
print(adp.read(4))
```
%% Output
%% Cell type:code id: tags:
``` python
import os
file_name= "arm_tests/aes128_tests.bin"
file_stats= os.stat(file_name)
file_len_in_bytes = file_stats.st_size
file_len_in_words = int((file_len_in_bytes + 3)/4)
file_pad_in_bytes = (file_len_in_words * 4) - file_len_in_bytes
print(f'file size in bytes is {file_len_in_bytes}')
print(f'file pad in bytes is {file_pad_in_bytes}')
print(f'file size in words is {file_len_in_words}')
wordcount_hex=hex(file_len_in_words)
print(f'file size in words is {wordcount_hex}')
print(f'U '+wordcount_hex+'\n')
bytecount_hex=hex(file_len_in_bytes)
print(f'file size in bytes is {bytecount_hex}')
print(f'U '+bytecount_hex+'\n')
adp.write('A 0x20000000\n')
adp.write('U '+wordcount_hex+'\n')
adp.write('U '+bytecount_hex+'\n')
count = file_len_in_bytes
print(count)
with open(file_name, mode='rb') as file:
while (count>0) :
b=file.read(1)
adp.wbyte(ord(b))
count-=1
count = file_pad_in_bytes
while (count>0) :
b=0
adp.wbyte(b)
count=count-1
print(count)
print(adp.read(100))
```
%% Output
file size in bytes is 7192
file pad in bytes is 0
file size in words is 1798
file size in words is 0x706
U 0x706
U 0x1C18
7192
0
?
]U 0x00000706
]U 0x00001C18
]
%% Cell type:code id: tags:
``` python
adp.write('A 0x20000000\n')
adp.write('R 40\n')
print(adp.read(10000))
```
%% Output
A 0x20000000
]R 0x30001ca0
R 0x00001149
R 0x00001151
R 0x00001153
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00000000
R 0x00001155
R 0x00000000
R 0x00000000
R 0x00001157
R 0x00001159
R 0x00000cf3
R 0x00000d17
R 0x00000d3b
R 0x00000d5f
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x00000cb1
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0x0000115b
R 0xf802f000
R 0xf842f000
R 0xc830a00c
R 0x18243808
R 0x46a2182d
R 0x46ab1e67
R 0x465d4654
R 0xd10142ac
R 0xf834f000
R 0x3e0f467e
R 0x46b6cc0f
R 0x42332601
R 0x1afbd000
R 0x46ab46a2
R 0x47184333
R 0x00001938
]
%% Cell type:markdown id: tags:
Soft reset to enter the downloaded code
%% Cell type:code id: tags:
``` python
adp.write('C 0x200\n')
adp.write('C 0x201\n')
print(adp.read(10000))
```
%% Output
C 0x00000200
] 0x50c1ab03
] 0x50c1ab04
SOCLABS: ARM Cortex-M0 nanosoc
** Remap->RAM2
soclabs AES128v1
AES128 test program
AES128 ID: aes128 0.01
AES128 SW (memcpy) tests...
AES128 reference pattern test
AES128 input/output bypass test
AES128 encrypt test
AES128 decrypt test
AES128 logic toggle test
AES128 input/output pattern test
AES128 pattern encrypt test
AES128 pattern decrypt test
AES128 DMA tests...
AES128 dma input/output bypass test
++ DMA_DONE IRQ count = 2
AES128 dma encrypt test
AES128 dma decrypt test
++ DMA_DONE IRQ count = 6
AES128 dma unaligned pattern test
AES128 dma input/output pattern test
AES128 dma pattern encrypt test
AES128 dma pattern decrypt test
++ DMA_DONE IRQ count = 14
Data retrieved from the AES is: aes128 0.01
Data expected from the AES is: soclabs AES128v1
** AES TEST PASSED **

......
......@@ -11,7 +11,8 @@
//`define ADPBASIC 1
//`begin_keywords "1364-2001"
`define ADPFSMDESIGN 1
module nanosoc_adp_manager // AHB initiator interface
#(parameter PROMPT_CHAR = "]"
......@@ -32,20 +33,16 @@ module nanosoc_adp_manager // AHB initiator interface
// COMIO interface
output wire [ 7:0] GPO8_o,
input wire [ 7:0] GPI8_i,
// input wire COM_RXE_i,
input wire [ 7:0] COMRX_TDATA_i,
input wire COMRX_TVALID_i,
output wire COMRX_TREADY_o,
// input wire COM_TXF_i,
output wire [ 7:0] COMTX_TDATA_o,
output wire COMTX_TVALID_o,
input wire COMTX_TREADY_i,
// STDIO interface
// input wire STDOUT_RXE_i,
input wire [ 7:0] STDRX_TDATA_i,
input wire STDRX_TVALID_i,
output wire STDRX_TREADY_o,
// input wire STDIN_TXF_i
output wire [ 7:0] STDTX_TDATA_o,
output wire STDTX_TVALID_o,
input wire STDTX_TREADY_i
......@@ -64,7 +61,7 @@ wire STD_RXE_i = !STDRX_TVALID_i;
`ifdef ADPBASIC
localparam BANNERHEX = 32'h50c1ab01;
`else
localparam BANNERHEX = 32'h50c1ab03;
localparam BANNERHEX = 32'h50c1ab04;
`endif
localparam CMD_bad = 4'b0000;
......@@ -145,87 +142,66 @@ input [7:0] char8;
FNuppercase = (char8[6]) ? (char8 & 8'h5f) : (char8);
endfunction
function [63:0] FNBuild_param64_hexdigit;
input [63:0] param64;
input [7:0] char8;
case (char8[7:0])
"\t":FNBuild_param64_hexdigit = 64'b0; // tab starts new (zeroed) param64
" ": FNBuild_param64_hexdigit = 64'b0; // space starts new (zeroed) param64
"x": FNBuild_param64_hexdigit = 64'b0; // hex prefix starts new (zeroed) param64
"X": FNBuild_param64_hexdigit = 64'b0; // hex prefix starts new (zeroed) param64
"0": FNBuild_param64_hexdigit = {param64[59:0],4'b0000};
"1": FNBuild_param64_hexdigit = {param64[59:0],4'b0001};
"2": FNBuild_param64_hexdigit = {param64[59:0],4'b0010};
"3": FNBuild_param64_hexdigit = {param64[59:0],4'b0011};
"4": FNBuild_param64_hexdigit = {param64[59:0],4'b0100};
"5": FNBuild_param64_hexdigit = {param64[59:0],4'b0101};
"6": FNBuild_param64_hexdigit = {param64[59:0],4'b0110};
"7": FNBuild_param64_hexdigit = {param64[59:0],4'b0111};
"8": FNBuild_param64_hexdigit = {param64[59:0],4'b1000};
"9": FNBuild_param64_hexdigit = {param64[59:0],4'b1001};
"A": FNBuild_param64_hexdigit = {param64[59:0],4'b1010};
"B": FNBuild_param64_hexdigit = {param64[59:0],4'b1011};
"C": FNBuild_param64_hexdigit = {param64[59:0],4'b1100};
"D": FNBuild_param64_hexdigit = {param64[59:0],4'b1101};
"E": FNBuild_param64_hexdigit = {param64[59:0],4'b1110};
"F": FNBuild_param64_hexdigit = {param64[59:0],4'b1111};
"a": FNBuild_param64_hexdigit = {param64[59:0],4'b1010};
"b": FNBuild_param64_hexdigit = {param64[59:0],4'b1011};
"c": FNBuild_param64_hexdigit = {param64[59:0],4'b1100};
"d": FNBuild_param64_hexdigit = {param64[59:0],4'b1101};
"e": FNBuild_param64_hexdigit = {param64[59:0],4'b1110};
"f": FNBuild_param64_hexdigit = {param64[59:0],4'b1111};
default: FNBuild_param64_hexdigit = param64; // EOL etc returns param64 unchanged
function [2:0] FNsize_inc;
// top 2 bits encode 01 (byte), 10 (halfword), 11 (word) 00 - no parameter
input [2:0] cnt8;
case (cnt8[2:0])
3'b000: FNsize_inc = 3'b010;
3'b010: FNsize_inc = 3'b011;
3'b011: FNsize_inc = 3'b100;
3'b100: FNsize_inc = 3'b101;
default:
FNsize_inc = 3'b111;
endcase
endfunction
function [63:0] FNBuild_param64_byte;
input [63:0] param64;
input [7:0] octet;
FNBuild_param64_byte = {octet[7:0], param64[63:08]};
function [1:0] FNparam2size;
// top 2 bits encode 01 (byte), 10 (halfword), 11 (word) 00 - no parameter
input [1:0] parm2;
case (parm2[1:0])
2'b01: FNparam2size = 2'b00; // 8-bit
2'b10: FNparam2size = 2'b01; // 16-bit
2'b11: FNparam2size = 2'b10; // 32-bit
default:
FNparam2size = 2'b10;// default to 32-bit
endcase
endfunction
function [31:0] FNBuild_param32_hexdigit;
input [31:0] param32;
function [34:0] FNBuild_size3_param32_hexdigit;
input [34:0] param32;
input [7:0] char8;
case (char8[7:0])
"\t":FNBuild_param32_hexdigit = 32'b0; // tab starts new (zeroed) param32
" ": FNBuild_param32_hexdigit = 32'b0; // space starts new (zeroed) param32
"x": FNBuild_param32_hexdigit = 32'b0; // hex prefix starts new (zeroed) param32
"X": FNBuild_param32_hexdigit = 32'b0; // hex prefix starts new (zeroed) param32
"0": FNBuild_param32_hexdigit = {param32[27:0],4'b0000};
"1": FNBuild_param32_hexdigit = {param32[27:0],4'b0001};
"2": FNBuild_param32_hexdigit = {param32[27:0],4'b0010};
"3": FNBuild_param32_hexdigit = {param32[27:0],4'b0011};
"4": FNBuild_param32_hexdigit = {param32[27:0],4'b0100};
"5": FNBuild_param32_hexdigit = {param32[27:0],4'b0101};
"6": FNBuild_param32_hexdigit = {param32[27:0],4'b0110};
"7": FNBuild_param32_hexdigit = {param32[27:0],4'b0111};
"8": FNBuild_param32_hexdigit = {param32[27:0],4'b1000};
"9": FNBuild_param32_hexdigit = {param32[27:0],4'b1001};
"A": FNBuild_param32_hexdigit = {param32[27:0],4'b1010};
"B": FNBuild_param32_hexdigit = {param32[27:0],4'b1011};
"C": FNBuild_param32_hexdigit = {param32[27:0],4'b1100};
"D": FNBuild_param32_hexdigit = {param32[27:0],4'b1101};
"E": FNBuild_param32_hexdigit = {param32[27:0],4'b1110};
"F": FNBuild_param32_hexdigit = {param32[27:0],4'b1111};
"a": FNBuild_param32_hexdigit = {param32[27:0],4'b1010};
"b": FNBuild_param32_hexdigit = {param32[27:0],4'b1011};
"c": FNBuild_param32_hexdigit = {param32[27:0],4'b1100};
"d": FNBuild_param32_hexdigit = {param32[27:0],4'b1101};
"e": FNBuild_param32_hexdigit = {param32[27:0],4'b1110};
"f": FNBuild_param32_hexdigit = {param32[27:0],4'b1111};
default: FNBuild_param32_hexdigit = param32; // EOL etc returns param32 unchanged
"\t":FNBuild_size3_param32_hexdigit = 35'b0; // tab starts new (zeroed) param32
" ": FNBuild_size3_param32_hexdigit = 35'b0; // space starts new (zeroed) param32
"x": FNBuild_size3_param32_hexdigit = 35'b0; // hex prefix starts new (zeroed) param32
"X": FNBuild_size3_param32_hexdigit = 35'b0; // hex prefix starts new (zeroed) param32
"0": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b0000};
"1": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b0001};
"2": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b0010};
"3": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b0011};
"4": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b0100};
"5": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b0101};
"6": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b0110};
"7": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b0111};
"8": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1000};
"9": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1001};
"A": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1010};
"B": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1011};
"C": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1100};
"D": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1101};
"E": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1110};
"F": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1111};
"a": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1010};
"b": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1011};
"c": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1100};
"d": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1101};
"e": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1110};
"f": FNBuild_size3_param32_hexdigit = {FNsize_inc(param32[34:32]),param32[27:0],4'b1111};
default: FNBuild_size3_param32_hexdigit = param32; // EOL etc returns param32 unchanged
endcase
endfunction
function [31:0] FNBuild_param32_byte;
input [31:0] param32;
input [7:0] octet;
FNBuild_param32_byte = {octet[7:0], param32[31:08]};
endfunction
function [7:0] FNmap_hex_digit;
input [3:0] nibble;
......@@ -250,7 +226,6 @@ default: FNmap_hex_digit = "0";
endcase
endfunction
// as per Vivado synthesis mapping
`ifdef ADPFSMDESIGN
localparam ADP_WRITEHEX = 6'b000000 ;
......@@ -288,71 +263,65 @@ localparam STD_RXD2 = 6'b011111 ;
localparam STD_TXD1 = 6'b100000 ;
localparam STD_TXD2 = 6'b100001 ;
localparam ADP_UCTRL = 6'b100010 ;
localparam ADP_UREADB0 = 6'b100011 ;
localparam ADP_UREADB1 = 6'b100100 ;
localparam ADP_UREADB2 = 6'b100101 ;
localparam ADP_UREADB3 = 6'b100110 ;
localparam ADP_UWRITE = 6'b100111 ;
localparam ADP_POLL = 6'b101000 ;
localparam ADP_POLL1 = 6'b101001 ;
localparam ADP_POLL2 = 6'b101010 ;
localparam ADP_FCTRL = 6'b101011 ;
localparam ADP_FWRITE = 6'b101100 ;
localparam ADP_ECHOCMD = 6'b101101 ;
localparam ADP_ECHOBUS = 6'b101110 ;
localparam ADP_UNKNOWN = 6'b101111 ;
localparam ADP_UREADB = 6'b100011 ;
localparam ADP_UWRITE = 6'b100100 ;
localparam ADP_POLL = 6'b100101 ;
localparam ADP_POLL1 = 6'b100110 ;
localparam ADP_POLL2 = 6'b100111 ;
localparam ADP_FCTRL = 6'b101000 ;
localparam ADP_FWRITE = 6'b101001 ;
localparam ADP_ECHOCMD = 6'b101010 ;
localparam ADP_ECHOBUS = 6'b101011 ;
localparam ADP_UNKNOWN = 6'b101100 ;
reg [5:0] adp_state ;
`else
// one-hot encoded explicitly
localparam ADP_WRITEHEX = 48'b000000000000000000000000000000000000000000000001 ; // = 6'b000000
localparam ADP_WRITEHEXS = 48'b000000000000000000000000000000000000000000000010 ; // = 6'b000001
localparam ADP_WRITEHEX9 = 48'b000000000000000000000000000000000000000000000100 ; // = 6'b000010
localparam ADP_WRITEHEX8 = 48'b000000000000000000000000000000000000000000001000 ; // = 6'b000011
localparam ADP_WRITEHEX7 = 48'b000000000000000000000000000000000000000000010000 ; // = 6'b000100
localparam ADP_WRITEHEX6 = 48'b000000000000000000000000000000000000000000100000 ; // = 6'b000101
localparam ADP_WRITEHEX5 = 48'b000000000000000000000000000000000000000001000000 ; // = 6'b000110
localparam ADP_WRITEHEX4 = 48'b000000000000000000000000000000000000000010000000 ; // = 6'b000111
localparam ADP_WRITEHEX3 = 48'b000000000000000000000000000000000000000100000000 ; // = 6'b001000
localparam ADP_WRITEHEX2 = 48'b000000000000000000000000000000000000001000000000 ; // = 6'b001001
localparam ADP_WRITEHEX1 = 48'b000000000000000000000000000000000000010000000000 ; // = 6'b001010
localparam ADP_WRITEHEX0 = 48'b000000000000000000000000000000000000100000000000 ; // = 6'b001011
localparam ADP_LINEACK = 48'b000000000000000000000000000000000001000000000000 ; // = 6'b001100
localparam ADP_LINEACK2 = 48'b000000000000000000000000000000000010000000000000 ; // = 6'b001101
localparam ADP_PROMPT = 48'b000000000000000000000000000000000100000000000000 ; // = 6'b001110
localparam ADP_IOCHK = 48'b000000000000000000000000000000001000000000000000 ; // = 6'b001111
localparam ADP_STDOUT = 48'b000000000000000000000000000000010000000000000000 ; // = 6'b010000
localparam ADP_STDOUT1 = 48'b000000000000000000000000000000100000000000000000 ; // = 6'b010001
localparam ADP_STDOUT2 = 48'b000000000000000000000000000001000000000000000000 ; // = 6'b010010
localparam ADP_STDOUT3 = 48'b000000000000000000000000000010000000000000000000 ; // = 6'b010011
localparam ADP_RXCMD = 48'b000000000000000000000000000100000000000000000000 ; // = 6'b010100
localparam ADP_RXPARAM = 48'b000000000000000000000000001000000000000000000000 ; // = 6'b010101
localparam ADP_ACTION = 48'b000000000000000000000000010000000000000000000000 ; // = 6'b010110
localparam ADP_SYSCTL = 48'b000000000000000000000000100000000000000000000000 ; // = 6'b010111
localparam ADP_READ = 48'b000000000000000000000001000000000000000000000000 ; // = 6'b011000
localparam ADP_SYSCHK = 48'b000000000000000000000010000000000000000000000000 ; // = 6'b011001
localparam ADP_STDIN = 48'b000000000000000000000100000000000000000000000000 ; // = 6'b011010
localparam ADP_WRITE = 48'b000000000000000000001000000000000000000000000000 ; // = 6'b011011
localparam ADP_EXIT = 48'b000000000000000000010000000000000000000000000000 ; // = 6'b011100
localparam STD_IOCHK = 48'b000000000000000000100000000000000000000000000000 ; // = 6'b011101
localparam STD_RXD1 = 48'b000000000000000001000000000000000000000000000000 ; // = 6'b011110
localparam STD_RXD2 = 48'b000000000000000010000000000000000000000000000000 ; // = 6'b011111
localparam STD_TXD1 = 48'b000000000000000100000000000000000000000000000000 ; // = 6'b100000
localparam STD_TXD2 = 48'b000000000000001000000000000000000000000000000000 ; // = 6'b100001
localparam ADP_UCTRL = 48'b000000000000010000000000000000000000000000000000 ; // = 6'b100010
localparam ADP_UREADB0 = 48'b000000000000100000000000000000000000000000000000 ; // = 6'b100011
localparam ADP_UREADB1 = 48'b000000000001000000000000000000000000000000000000 ; // = 6'b100100
localparam ADP_UREADB2 = 48'b000000000010000000000000000000000000000000000000 ; // = 6'b100101
localparam ADP_UREADB3 = 48'b000000000100000000000000000000000000000000000000 ; // = 6'b100110
localparam ADP_UWRITE = 48'b000000001000000000000000000000000000000000000000 ; // = 6'b100111
localparam ADP_POLL = 48'b000000010000000000000000000000000000000000000000 ; // = 6'b101000
localparam ADP_POLL1 = 48'b000000100000000000000000000000000000000000000000 ; // = 6'b101001
localparam ADP_POLL2 = 48'b000001000000000000000000000000000000000000000000 ; // = 6'b101010
localparam ADP_FCTRL = 48'b000010000000000000000000000000000000000000000000 ; // = 6'b101011
localparam ADP_FWRITE = 48'b000100000000000000000000000000000000000000000000 ; // = 6'b101100
localparam ADP_ECHOCMD = 48'b001000000000000000000000000000000000000000000000 ; // = 6'b101101
localparam ADP_ECHOBUS = 48'b010000000000000000000000000000000000000000000000 ; // = 6'b101110
localparam ADP_UNKNOWN = 48'b100000000000000000000000000000000000000000000000 ; // = 6'b101111
reg [47:0] adp_state ;
localparam ADP_WRITEHEX = 45'b000000000000000000000000000000000000000000001 ; // = 6'b000000 ;
localparam ADP_WRITEHEXS = 45'b000000000000000000000000000000000000000000010 ; // = 6'b000001 ;
localparam ADP_WRITEHEX9 = 45'b000000000000000000000000000000000000000000100 ; // = 6'b000010 ;
localparam ADP_WRITEHEX8 = 45'b000000000000000000000000000000000000000001000 ; // = 6'b000011 ;
localparam ADP_WRITEHEX7 = 45'b000000000000000000000000000000000000000010000 ; // = 6'b000100 ;
localparam ADP_WRITEHEX6 = 45'b000000000000000000000000000000000000000100000 ; // = 6'b000101 ;
localparam ADP_WRITEHEX5 = 45'b000000000000000000000000000000000000001000000 ; // = 6'b000110 ;
localparam ADP_WRITEHEX4 = 45'b000000000000000000000000000000000000010000000 ; // = 6'b000111 ;
localparam ADP_WRITEHEX3 = 45'b000000000000000000000000000000000000100000000 ; // = 6'b001000 ;
localparam ADP_WRITEHEX2 = 45'b000000000000000000000000000000000001000000000 ; // = 6'b001001 ;
localparam ADP_WRITEHEX1 = 45'b000000000000000000000000000000000010000000000 ; // = 6'b001010 ;
localparam ADP_WRITEHEX0 = 45'b000000000000000000000000000000000100000000000 ; // = 6'b001011 ;
localparam ADP_LINEACK = 45'b000000000000000000000000000000001000000000000 ; // = 6'b001100 ;
localparam ADP_LINEACK2 = 45'b000000000000000000000000000000010000000000000 ; // = 6'b001101 ;
localparam ADP_PROMPT = 45'b000000000000000000000000000000100000000000000 ; // = 6'b001110 ;
localparam ADP_IOCHK = 45'b000000000000000000000000000001000000000000000 ; // = 6'b001111 ;
localparam ADP_STDOUT = 45'b000000000000000000000000000010000000000000000 ; // = 6'b010000 ;
localparam ADP_STDOUT1 = 45'b000000000000000000000000000100000000000000000 ; // = 6'b010001 ;
localparam ADP_STDOUT2 = 45'b000000000000000000000000001000000000000000000 ; // = 6'b010010 ;
localparam ADP_STDOUT3 = 45'b000000000000000000000000010000000000000000000 ; // = 6'b010011 ;
localparam ADP_RXCMD = 45'b000000000000000000000000100000000000000000000 ; // = 6'b010100 ;
localparam ADP_RXPARAM = 45'b000000000000000000000001000000000000000000000 ; // = 6'b010101 ;
localparam ADP_ACTION = 45'b000000000000000000000010000000000000000000000 ; // = 6'b010110 ;
localparam ADP_SYSCTL = 45'b000000000000000000000100000000000000000000000 ; // = 6'b010111 ;
localparam ADP_READ = 45'b000000000000000000001000000000000000000000000 ; // = 6'b011000 ;
localparam ADP_SYSCHK = 45'b000000000000000000010000000000000000000000000 ; // = 6'b011001 ;
localparam ADP_STDIN = 45'b000000000000000000100000000000000000000000000 ; // = 6'b011010 ;
localparam ADP_WRITE = 45'b000000000000000001000000000000000000000000000 ; // = 6'b011011 ;
localparam ADP_EXIT = 45'b000000000000000010000000000000000000000000000 ; // = 6'b011100 ;
localparam STD_IOCHK = 45'b000000000000000100000000000000000000000000000 ; // = 6'b011101 ;
localparam STD_RXD1 = 45'b000000000000001000000000000000000000000000000 ; // = 6'b011110 ;
localparam STD_RXD2 = 45'b000000000000010000000000000000000000000000000 ; // = 6'b011111 ;
localparam STD_TXD1 = 45'b000000000000100000000000000000000000000000000 ; // = 6'b100000 ;
localparam STD_TXD2 = 45'b000000000001000000000000000000000000000000000 ; // = 6'b100001 ;
localparam ADP_UCTRL = 45'b000000000010000000000000000000000000000000000 ; // = 6'b100010 ;
localparam ADP_UREADB = 45'b000000000100000000000000000000000000000000000 ; // = 6'b100011 ;
localparam ADP_UWRITE = 45'b000000001000000000000000000000000000000000000 ; // = 6'b100100 ;
localparam ADP_POLL = 45'b000000010000000000000000000000000000000000000 ; // = 6'b100101 ;
localparam ADP_POLL1 = 45'b000000100000000000000000000000000000000000000 ; // = 6'b100110 ;
localparam ADP_POLL2 = 45'b000001000000000000000000000000000000000000000 ; // = 6'b100111 ;
localparam ADP_FCTRL = 45'b000010000000000000000000000000000000000000000 ; // = 6'b101000 ;
localparam ADP_FWRITE = 45'b000100000000000000000000000000000000000000000 ; // = 6'b101001 ;
localparam ADP_ECHOCMD = 45'b001000000000000000000000000000000000000000000 ; // = 6'b101010 ;
localparam ADP_ECHOBUS = 45'b010000000000000000000000000000000000000000000 ; // = 6'b101011 ;
localparam ADP_UNKNOWN = 45'b100000000000000000000000000000000000000000000 ; // = 6'b101100 ;
reg [44:0] adp_state ;
`endif
reg [31:0] adp_bus_data;
......@@ -367,8 +336,10 @@ reg adp_bus_req ;
reg adp_bus_write ;
reg adp_bus_err ;
reg [7:0] adp_cmd ;
reg [32:0] adp_param ;
reg [7:0] adp_cmdwid ;
reg [34:0] adp_param ;
reg [31:0] adp_addr ;
reg [1:0] adp_size ;
reg adp_addr_inc;
reg [31:0] adp_sys ;
......@@ -402,18 +373,25 @@ always @(posedge HCLK or negedge HRESETn)
else if (HREADY_i)
ahb_dphase <= (ahb_aphase);
assign HADDR32_o = adp_addr;
wire [1:0] byteaddr;
assign byteaddr = (adp_size[1]) ? 2'b00 : (adp_size[0]) ? {adp_addr[1], 1'b0} : adp_addr[1:0];
assign HADDR32_o[31:2] = adp_addr[31:2];
assign HADDR32_o[ 1:0] = byteaddr[1:0];
assign HBURST3_o = 3'b001; // "INCR" burst signalled whenever transfer;
assign HMASTLOCK_o = 1'b0;
assign HPROT4_o[3:0] = {1'b0, 1'b0, 1'b1, 1'b1};
assign HSIZE3_o[2:0] = {1'b0, 2'b10};
assign HSIZE3_o[2:0] = {1'b0, adp_size};
assign HTRANS2_o = {ahb_aphase,1'b0}; // non-seq
assign HWDATA32_o = adp_bus_data;
assign HWDATA32_o = (adp_size[1]) ? adp_bus_data
: (adp_size[0]) ? {2{adp_bus_data[15:0]}}
: {4{adp_bus_data[7:0]}} ;
assign HWRITE_o = adp_bus_write;
`ifndef ADPBASIC
reg [31:0] adp_val;
reg [34:0] adp_val;
reg [31:0] adp_mask;
reg [31:0] adp_poll;
reg [31:0] adp_count;
......@@ -477,6 +455,7 @@ always @(posedge HCLK or negedge HRESETn)
adp_bus_err <= 0; // default no bus error
adp_cmd <= 0;
adp_param <= 0;
adp_size <= 2'b10; // default to 32-bit word size
adp_addr <= 0;
adp_addr_inc <= 0;
adp_bus_write<= 0;
......@@ -494,7 +473,7 @@ always @(posedge HCLK or negedge HRESETn)
std_tx_req <= 0; // default no TX req
std_rx_ack <= 0; // default no RX ack
adp_bus_req <= 0; // default no bus transaction
adp_addr <= (adp_addr_inc & adp_bus_done) ? adp_addr + 4 : adp_addr; // address++
adp_addr <= (adp_addr_inc & adp_bus_done) ? adp_addr + (1 << adp_size) : adp_addr; // address++
adp_addr_inc <= 0;
`ifndef ADPBASIC
adp_count <= (adp_count_dec & adp_bus_done & |adp_count) ? adp_count - 1 : adp_count; // param--
......@@ -553,8 +532,8 @@ always @(posedge HCLK or negedge HRESETn)
if (com_rx_done) begin
if (FNexit(com_rx_byte)) adp_state <= STD_IOCHK; // immediate exit
else if (FNvalid_space(com_rx_byte)) com_rx_ack <= 1; // retry for a command
else if (FNvalid_EOL(com_rx_byte)) begin adp_cmd <= "?"; adp_state <= ADP_ACTION; end // no command, skip param
else begin adp_cmd <= com_rx_byte; adp_param <= 33'h1_00000000; com_rx_ack <= 1; adp_state <= ADP_RXPARAM; end // get optional parameter
else if (FNvalid_EOL(com_rx_byte)) begin adp_cmd <= "?"; adp_state <= ADP_LINEACK; end // no command, skip param
else begin adp_cmd <= com_rx_byte; adp_param <= 35'h0_00000000; com_rx_ack <= 1; adp_state <= ADP_RXPARAM; end // get optional parameter
end
else com_rx_ack <= 1; // extend stream request if not ready
ADP_RXPARAM: // read and build hex parameter
......@@ -562,12 +541,14 @@ always @(posedge HCLK or negedge HRESETn)
if (FNexit(com_rx_byte)) adp_state <= STD_IOCHK; // exit
else if (FNvalid_EOL(com_rx_byte))
`ifndef ADPBASIC
begin adp_count <= adp_param[31:0]; adp_state <= ADP_ACTION; end // parameter complete on EOL
begin adp_count <= adp_param[31:0]; adp_state <= ADP_ACTION;
adp_size <= FNparam2size(adp_param[34:33]); end // parameter complete on EOL
`else
begin adp_state <= ADP_ACTION; end // parameter complete on EOL
begin adp_state <= ADP_ACTION;
adp_size <= FNparam2size(adp_param[34:33]); end // parameter complete on EOL
`endif
else
begin adp_param <= {1'b0,FNBuild_param32_hexdigit(adp_param[31:0], com_rx_byte)}; com_rx_ack <= 1; end // build parameter
begin adp_param <= FNBuild_size3_param32_hexdigit(adp_param[34:0], com_rx_byte); com_rx_ack <= 1; end // build parameter
end
else com_rx_ack <= 1;
......@@ -575,10 +556,10 @@ always @(posedge HCLK or negedge HRESETn)
if (FNexit(com_rx_byte))
adp_state <= STD_IOCHK;
else if (FNvalid_cmd(adp_cmd) == CMD_A)
begin if (adp_param[32] == 1'b1) adp_param <= {1'b0, adp_addr}; else adp_addr <= adp_param[31:0];
begin if (|adp_param[34:32]) adp_addr <= adp_param[31:0]; else adp_param <= {3'b111, adp_addr} ;
adp_state <= ADP_ECHOCMD; end
else if (FNvalid_cmd(adp_cmd) == CMD_C) begin
if (adp_param[32]) // report GPO
if (|adp_param[34:32] == 1'b0) // report GPO
begin adp_state <= ADP_SYSCTL; end
else if (adp_param[31:8] == 1) // clear selected bits in GPO
begin adp_sys[7:0] <= adp_sys[7:0] & ~adp_param[7:0]; adp_state <= ADP_SYSCTL; end
......@@ -590,7 +571,7 @@ always @(posedge HCLK or negedge HRESETn)
begin adp_state <= ADP_SYSCTL; end
end
else if (FNvalid_cmd(adp_cmd) == CMD_R)
begin ADP_BUSREADINC_next; adp_state <= ADP_READ;
begin adp_size <= FNparam2size(adp_param[34:33]); ADP_BUSREADINC_next; adp_state <= ADP_READ;
`ifndef ADPBASIC
adp_count_dec <= 1'b1; // optional loop param
`endif
......@@ -598,19 +579,20 @@ always @(posedge HCLK or negedge HRESETn)
else if (FNvalid_cmd(adp_cmd) == CMD_S)
begin adp_state <= ADP_SYSCHK; end
else if (FNvalid_cmd(adp_cmd) == CMD_W)
begin adp_bus_data <= adp_param[31:0]; ADP_BUSWRITEINC_next; adp_state <= ADP_WRITE; end
begin adp_size <= FNparam2size(adp_param[34:33]); adp_bus_data <= adp_param[31:0]; ADP_BUSWRITEINC_next; adp_state <= ADP_WRITE; end
else if (FNvalid_cmd(adp_cmd) == CMD_X)
begin com_tx_byte <= 8'h0a; com_tx_req <= 1; adp_state <= ADP_EXIT; end
`ifndef ADPBASIC
else if (FNvalid_cmd(adp_cmd) == CMD_U)
if (FNcount_down_zero_next(adp_param[31:0])) adp_state <= ADP_ECHOCMD; else adp_state <= ADP_UCTRL; // non-zero count
else if (FNvalid_cmd(adp_cmd) == CMD_M)
begin if (adp_param[32] == 1'b1) adp_param <= {1'b0,adp_mask}; else adp_mask <= adp_param[31:0];
begin if (|adp_param[34:32]) adp_mask <= adp_param[31:0]; else adp_param <= {3'b111,adp_mask};
adp_state <= ADP_ECHOCMD; end
else if (FNvalid_cmd(adp_cmd) == CMD_P)
if (FNcount_down_zero_next(adp_param[31:0])) adp_state <= ADP_ECHOCMD; else adp_state <= ADP_POLL; // non-zero count
else if (FNvalid_cmd(adp_cmd) == CMD_V)
begin if (adp_param[32] == 1'b1) adp_param <= {1'b0,adp_val}; else adp_val <= adp_param[31:0];
begin if (|adp_param[34:32]) begin adp_size <= FNparam2size(adp_param[34:33]); adp_val <= adp_param[34:0]; end
else adp_param <= adp_val;
adp_state <= ADP_ECHOCMD; end
else if (FNvalid_cmd(adp_cmd) == CMD_F)
if (FNcount_down_zero_next(adp_param[31:0])) adp_state <= ADP_ECHOCMD; else adp_state <= ADP_FCTRL; // non-zero count
......@@ -625,7 +607,12 @@ always @(posedge HCLK or negedge HRESETn)
else begin ADP_BUSWRITEINC_next; end // extend request
ADP_READ: // perform bus read at current adp address (and auto increment) - and report in hex
if (adp_bus_done) begin adp_bus_data <= HRDATA32_i; adp_bus_err <= HRESP_i; ADP_txchar_next("R"); adp_state <= ADP_ECHOBUS; end
if (adp_bus_done) begin adp_bus_data <= (byteaddr[1:0] == 2'b01) ? {HRDATA32_i[ 7: 0],HRDATA32_i[31: 8]}
: (byteaddr[1:0] == 2'b10) ? {HRDATA32_i[15: 0],HRDATA32_i[31:16]}
: (byteaddr[1:0] == 2'b11) ? {HRDATA32_i[23: 0],HRDATA32_i[31:24]}
: HRDATA32_i;
adp_bus_err <= HRESP_i; ADP_txchar_next("R"); adp_state <= ADP_ECHOBUS;
end
else begin
ADP_BUSREADINC_next;
`ifndef ADPBASIC
......@@ -637,23 +624,14 @@ always @(posedge HCLK or negedge HRESETn)
// >>>>>>>>>>>>>>>> ADP BINARY UPLOAD >>>>>>>>>>>>>>>>>>>>>>
ADP_UCTRL: // set control value
begin com_rx_ack <= 1; adp_state <= ADP_UREADB0; end // read next 4 bytes
ADP_UREADB0: // read raw binary byte 0
if (com_rx_done) begin com_rx_ack <= 1; adp_bus_data[ 7: 0] <= com_rx_byte; adp_state <= ADP_UREADB1; end
else com_rx_ack <= 1; // extend stream request if not ready
ADP_UREADB1: // read raw binary byte 1
if (com_rx_done) begin com_rx_ack <= 1; adp_bus_data[15: 8] <= com_rx_byte; adp_state <= ADP_UREADB2; end
else com_rx_ack <= 1; // extend stream request if not ready
ADP_UREADB2: // read raw binary byte 2
if (com_rx_done) begin com_rx_ack <= 1; adp_bus_data[23:16] <= com_rx_byte; adp_state <= ADP_UREADB3; end
else com_rx_ack <= 1; // extend stream request if not ready
ADP_UREADB3: // read raw binary byte 3
begin com_rx_ack <= 1; adp_size = 2'b00; adp_state <= ADP_UREADB; end // read next byte
ADP_UREADB: // read raw binary byte
if (com_rx_done)
begin adp_bus_data[31:24] <= com_rx_byte; ADP_BUSWRITEINC_next; adp_count_dec <= 1; adp_state <= ADP_UWRITE; end
begin adp_bus_data[31:0] <= {4{com_rx_byte}}; ADP_BUSWRITEINC_next; adp_count_dec <= 1; adp_state <= ADP_UWRITE; end
else com_rx_ack <= 1; // extend stream request if not ready
ADP_UWRITE: // Write word to Addr++
if (adp_bus_done) begin // auto address++, count--
if (FNcount_down_zero_next(adp_count)) adp_state <= ADP_ECHOCMD; else begin adp_state <= ADP_UREADB0; adp_bus_err <= adp_bus_err | HRESP_i; end
if (FNcount_down_zero_next(adp_count)) adp_state <= ADP_ECHOCMD; else begin adp_state <= ADP_UREADB; adp_bus_err <= adp_bus_err | HRESP_i; end
end else begin ADP_BUSWRITEINC_next; adp_count_dec <= 1; end // extend request
// >>>>>>>>>>>>>>>> ADP BUS READ LOOP >>>>>>>>>>>>>>>>>>>>>>
......@@ -664,12 +642,12 @@ always @(posedge HCLK or negedge HRESETn)
else begin adp_bus_req <= 1; adp_count_dec <=1; end
ADP_POLL2:
if (FNcount_down_zero_next(adp_count)) begin adp_state <= ADP_ECHOCMD; adp_bus_err <= 1'b1; end // timeout
else if (((adp_bus_data & adp_mask) ^ adp_val) == 0) begin adp_state <= ADP_ECHOCMD; adp_param <= {1'b0, (adp_param[31:0] - adp_count)}; end // exact match
else if (((adp_bus_data & adp_mask) ^ adp_val[31:0]) == 0) begin adp_state <= ADP_ECHOCMD; adp_param <= {1'b0, (adp_param[31:0] - adp_count)}; end // exact match
else adp_state <= ADP_POLL;
// >>>>>>>>>>>>>>>> ADP (ZERO) FILL MEMORY >>>>>>>>>>>>>>>>>>>>>>
ADP_FCTRL: // set control value
begin adp_bus_data <= adp_val; ADP_BUSWRITEINC_next; adp_count_dec <= 1; adp_state <= ADP_FWRITE; end
begin adp_size <= FNparam2size(adp_val[34:33]); adp_bus_data <= adp_val[31:0]; ADP_BUSWRITEINC_next; adp_count_dec <= 1; adp_state <= ADP_FWRITE; end
ADP_FWRITE: // Write word to Addr++
if (adp_bus_done) begin // auto address++, count--
if (FNcount_down_zero_next(adp_count)) adp_state <= ADP_ECHOCMD; else begin adp_state <= ADP_FCTRL; adp_bus_err <= adp_bus_err | HRESP_i; end
......@@ -711,7 +689,9 @@ always @(posedge HCLK or negedge HRESETn)
if (com_tx_done) begin adp_state <= ADP_WRITEHEX9; ADP_txchar_next("0"); end // output "0" hex prefix
else com_tx_req <= 1; // extend
ADP_WRITEHEX9:
if (com_tx_done) begin adp_state <= ADP_WRITEHEX8; ADP_txchar_next("x"); end // output "x" hex prefix
if (com_tx_done & adp_size[1]) begin adp_state <= ADP_WRITEHEX8; ADP_txchar_next("x"); end // output "x" hex prefix
else if (com_tx_done & adp_size[0]) begin adp_state <= ADP_WRITEHEX4; ADP_txchar_next("x"); end // output "x" hex prefix
else if (com_tx_done) begin adp_state <= ADP_WRITEHEX2; ADP_txchar_next("x"); end // output "x" hex prefix
else com_tx_req <= 1; // extend
ADP_WRITEHEX8:
if (com_tx_done) begin adp_state <= ADP_WRITEHEX7; ADP_hexdigit_next(adp_bus_data[31:28]); end // hex nibble 7
......@@ -764,12 +744,10 @@ always @(posedge HCLK or negedge HRESETn)
endmodule
//`end_keywords
////AHBLITE_ADPMASTER instancing
//ADPmaster
//adp_manager
// #(.PROMPT_CHAR ("]"))
// ADPmaster(
// ADPmanager(
// .HCLK (ahb_hclk ),
// .HRESETn (ahb_hrestn ),
// .HADDR32_o (ahb_haddr ),
......@@ -783,7 +761,8 @@ endmodule
// .HRDATA32_i (ahb_hrdata ),
// .HREADY_i (ahb_hready ),
// .HRESP_i (ahb_hresp ),
// .GPO8_o (gpio8 ),
// .GPI8_i (gpio8 ),
// .COMRX_TREADY_o(com_rx_tready),
// .COMRX_TDATA_i(com_rx_tdata),
// .COMRX_TVALID_i(com_rx_tvalid),
......@@ -796,5 +775,4 @@ endmodule
// .STDTX_TVALID_o(std_tx_tvalid),
// .STDTX_TDATA_o(std_tx_tdata),
// .STDTX_TREADY_i(std_tx_tready)
// );
......@@ -21,12 +21,40 @@ r
r
A
a 0x80000000
a
w 0xb0
a
w 0xb1
a
w 0xb3b2
a
w 0xb7b6b5b4
a
a 0x80000000
a
r 0x8
a
a 0x80000000
a
r 0x004
a
a 0x80000000
a
r 0x000002
a
a 0x80000000
a
r
r
a
v 0xe5e5e5e5
a 80000000
f 4000
A
a 90000000
U 4
U 0x0f
0123456789ABCDE
A
A 0x90000000
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment