Add Batch 3 with 10 repos
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- WangXuan95_FPGA-NFC/README.md +858 -0
- WangXuan95_FPGA-NFC/RTL/ad7276_read.v +60 -0
- WangXuan95_FPGA-NFC/RTL/fifo_sync.v +73 -0
- WangXuan95_FPGA-NFC/RTL/fpga_top.v +60 -0
- WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_controller.v +119 -0
- WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_rx_dsp.v +88 -0
- WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_rx_tobits.v +115 -0
- WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_rx_tobytes.v +86 -0
- WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_tx_frame.v +142 -0
- WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_tx_modulate.v +117 -0
- WangXuan95_FPGA-NFC/RTL/uart2nfca_system_top.v +145 -0
- WangXuan95_FPGA-NFC/RTL/uart_rx.v +335 -0
- WangXuan95_FPGA-NFC/RTL/uart_rx_parser.v +130 -0
- WangXuan95_FPGA-NFC/RTL/uart_tx.v +340 -0
- WangXuan95_FPGA-NFC/SIM/tb_nfca_controller.v +90 -0
- aquaxis_IPCORE/README.md +2 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.model/cjpeg.c +728 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.model/convbtoh.c +41 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.model/convsim.c +118 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.model/djpeg.c +863 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sim/tb_aq_djpeg.v +412 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_axi_djpeg.v +195 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_axi_djpeg_ctrl.v +113 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_axi_lite_slave.v +176 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg.v +272 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_dht.v +92 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_dqt.v +59 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_fsm.v +470 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_hm_decode.v +755 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_huffman.v +173 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_idct.v +111 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_idct_calc.v +498 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_idctb.v +177 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_regdata.v +271 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_ycbcr.v +159 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_ycbcr2rgb.v +225 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_ycbcr_mem.v +201 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_ziguzagu.v +319 -0
- aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/xgui/aq_axi_djpeg_v1_0.tcl +37 -0
- aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sim/tb_aq_axi_fifo.v +472 -0
- aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sim/tb_aq_axi_master.v +361 -0
- aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sim/tb_aq_fifo.v +109 -0
- aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sources/aq_axi_fifo.v +412 -0
- aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sources/aq_axi_fifo_ctl.v +269 -0
- aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sources/aq_axi_lite_slave.v +176 -0
- aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sources/aq_axi_master.v +366 -0
- aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sources/aq_fifo.v +86 -0
- aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/xgui/aq_axi_fifo_v1_0.tcl +37 -0
- aquaxis_IPCORE/aq_axi_i2c/aq_axi_i2c.srcs/sources/aq_axi_i2c.v +161 -0
- aquaxis_IPCORE/aq_axi_i2c/aq_axi_i2c.srcs/sources/aq_axi_lite_slave.v +173 -0
WangXuan95_FPGA-NFC/README.md
ADDED
|
@@ -0,0 +1,858 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-9A90FD.svg)   
|
| 2 |
+
|
| 3 |
+
[English](#en) | [中文](#cn)
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
<span id="en">FPGA NFC (RFID)</span>
|
| 8 |
+
===========================
|
| 9 |
+
|
| 10 |
+
Use FPGA to build an NFC PCD (card reader) from discrete components to protocol layer, supporting the ISO14443A standard.
|
| 11 |
+
|
| 12 |
+

|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
## Why?
|
| 17 |
+
|
| 18 |
+
I want to play with Radio Freqency (RF), and show something different from others who play SDR. Then I find that the carrier frequency of NFC is only 13.56MHz, and the modulation method is amplitude modulation (ASK), which can realize a card reader with very low cost (the cheapest FPGA + 3Msps ADC + several discrete components). Both digital signal processing and protocol processing are performed in the FPGA, which is a complete small system. So here comes this project, which can fully support ISO14443A under the control of the serial port commands, and has successfully interacted with the M1 card.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
## Concept Definition
|
| 23 |
+
|
| 24 |
+
| concept | short name | introduction |
|
| 25 |
+
| ------------------------- | --------------- | ------------------------------------------------------------ |
|
| 26 |
+
| Proximity Coupling Device | PCD, reader | Provides energy to PICC and acts as a communication host, which is what this project wants to implement using FPGA. |
|
| 27 |
+
| Proximity Card | PICC, card, tag | These cards such as M1 card, UID card, electronic tag and so on. |
|
| 28 |
+
| PCD-to-PICC | TX, send | PCD modulates the carrier to send information to the PICC. |
|
| 29 |
+
| PICC-to-PCD | RX, receive | PICC changes its impedance, so that the PCD can detect changes of carrier amplitude to receive information from PICC. |
|
| 30 |
+
| NXP MIFARE Classic 1K | M1 card | A type of card that meets ISO14443A, which is very common in daily life, such as door control cards. |
|
| 31 |
+
| ISO14443A | NFCA | An NFC standard for personal cards. This project fully supports it from hardware to protocol. See [1,2,3] for details. |
|
| 32 |
+
| ISO14443B | NFCB | An NFC standard for personal cards. This project do not support its hardware. |
|
| 33 |
+
| ISO15693 | NFCV | An NFC standard for industrial electronic tags. This project supports its hardware, but I haven't write its protocol in FPGA. |
|
| 34 |
+
| Carrier | fc | 13.56MHz, the drive coil of PCD resonates at this frequency. |
|
| 35 |
+
| Subcarrier | fs | The smallest unit of modulation, that is, PCD and PICC will change the carrier amplitude at this frequency, 847.5 kHz, which is 1/16 of the carrier frequency. |
|
| 36 |
+
| bit rate | | 8 subcarrier cycles may carry one bit, so bit rate is 105.9375 kHz |
|
| 37 |
+
| Amplitude Shift Keying | ASK | carry information by changing the amplitude of the carrier. |
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
## Poject ideas
|
| 42 |
+
|
| 43 |
+
The 1st step is carrier generation. I use an FPGA pin to generate a 13.56MHz signal, which drives a resonant circuit by a MOSFET (FDV301N). Corresponding to the source file nfca_tx_modulate.v
|
| 44 |
+
|
| 45 |
+
The 2nd step is the implementation of PCD-to-PICC (sub-carrier modulation). The modulation method of ISO14443A's PCD-to-PICC is 100% ASK (that is, in a sub-carrier cycle, either the carrier is sent at full amplitude, or the carrier is not sent at all), which is also very easy for FPGA. Corresponding to the source file nfca_tx_modulate.v.
|
| 46 |
+
|
| 47 |
+
The 3rd step is the implementation of PCD-to-PICC-to-PCD. The modulation method of PICC-to-PCD is 2%~10% ASK (that is, in a subcarrier cycle, the carrier is either attenuated a little or not attenuated). I use a diode (1N4148), a capacitor, and a resistor for envelope detection, obtain the frequency of envelope=subcarrier frequency=847.5kHz, and then use an ADC to sample this envelope (corresponding to the source file ad7276_read.v). Envelope detection reduces the requirement for ADC sampling rate, avoiding directly sample the carrier with an ADC ≥ 20Msps, but only using a 3Msps ADC (AD7276B) to sample the subcarrier. In the FPGA, a digital signal processing (DSP) algorithm is used to detect the ASK signal of the PICC-to-PCD from the ADC sampling data, that is, to detect the small change of the ADC sampling data amplitude, which requires anti-noise capability and adaptive signal amplitude. I use median filtering to subtract the original signal, and then do proportional threshold judgment, the effect is good enough. corresponding to the source file nfca_rx_dsp.v.
|
| 48 |
+
|
| 49 |
+
The last step is to implement the codec protocol of ISO14443A, including sending checksum generation and packetization (corresponding to the source file nfca_tx_frame.v), unpacking the receiving protocol (corresponding to the source files nfca_rx_tobits.v and nfca_rx_tobytes.v), this part is in accordance with the Specification [3].
|
| 50 |
+
|
| 51 |
+
I also implemented the serial port control logic in FPGA, parsed the serial port commands sent by the Host-PC to the FPGA into NFC send data (corresponding to the code files uart_rx.v and uart_rx_parser.v), and sent the NFC received data to the Host- PC (corresponding to the code file uart_tx.v). The user can send data to the card in the "serial assistant" software, and then receive the data returned by the PICC.
|
| 52 |
+
|
| 53 |
+
The following figure is the system block diagram, in which the Verilog source file names are marked under the modules.
|
| 54 |
+
|
| 55 |
+
```
|
| 56 |
+
_________ _________________________________________________________________________________________________________
|
| 57 |
+
| | ___________________________________________________________________________________________________ |
|
| 58 |
+
| | | _________________________________________________________ | |
|
| 59 |
+
| | | ___________ | ____________ _____________ | | | ____________ ____________
|
| 60 |
+
| | | uart_rx | UART RX | | | frame | | RFID TX | | | | | FDV301N | | Resonant | ___________
|
| 61 |
+
uart_tx |---|->|-------->| logic |---|--->| pack |--------->| modulate |--------------->|---------------->|--|-->| N-MOSFET |--->| circuit | | |
|
| 62 |
+
| | | ----------- | ------------ ------------- | carrier_out | | | | | |---v->| Antenna |
|
| 63 |
+
| | | uart_rx.v | nfca_tx_frame.v | nfca_tx_modulate.v | | | ------------ ------------ | | Coil |
|
| 64 |
+
| | | uart_rx_parser.v | rx_on | | | | | | |
|
| 65 |
+
| | | fifo_sync.v | | | | | | -----------
|
| 66 |
+
| | | ___________ | ___________ ______V____ ____________ | _____________ | | ___________ ____________ |
|
| 67 |
+
| | | uart_tx | UART TX | | | bytes | | bits | | ADC data | | | AD7276B | | | | AD7276B | | Envelop | |
|
| 68 |
+
uart_rx |<--|--|<--------| logic |<--|--| rebuild |<--------| rebuild |<-------| DSP |<-|--|ADC reader |<-|<-|-----| ADC |<--| detection|<---
|
| 69 |
+
| | | ----------- | ----------- ----------- ------------ | ------------- | | SPI | | | |
|
| 70 |
+
| | | uart_tx.v |nfca_rx_tobytes.v nfca_rx_tobits.v nfca_rx_dsp.v | ad7276_read.v | | ----------- ------------
|
| 71 |
+
GND |---| | --------------------------------------------------------| | |
|
| 72 |
+
| | | nfca_controller.v | |
|
| 73 |
+
| | --------------------------------------------------------------------------------------------------- |
|
| 74 |
+
| | uart2nfca_system_top.v |
|
| 75 |
+
--------- --------------------------------------------------------------------------------------------------------
|
| 76 |
+
Host-PC FPGA (fpga_top.v ) Analog Circuit
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# Build Hardware
|
| 82 |
+
|
| 83 |
+
This PCB design is available at LCEDA: [oshwhub.com/wangxuan/rfid_nfc_iso14443a_iso15693_breakoutboard](https://oshwhub.com/wangxuan/rfid_nfc_iso14443a_iso15693_breakoutboard)
|
| 84 |
+
|
| 85 |
+
In the PCB folder is the hardware design of this repository (named NFC_BreakoutBoard), which mainly includes:
|
| 86 |
+
|
| 87 |
+
- Sender circuit: N-MOSFET, inductor, etc.
|
| 88 |
+
- Receiver circuit: envelop detection diode, AD7276B.
|
| 89 |
+
- A 4 turns coil.
|
| 90 |
+
|
| 91 |
+
Please use the manufacturing file [NFC_BreakoutBoard_gerber.zip](./PCB) to proof the PCB and then solder its components.
|
| 92 |
+
|
| 93 |
+
After soldering, connect the PCB to FPGA:
|
| 94 |
+
|
| 95 |
+
- J1 should be connected to 7V\~9V power supply.
|
| 96 |
+
- J2 should be connected to the FPGA board (occupies 4 common IO pins of the FPGA, and the level should be 3.3V or 2.5V). Note: The frequency of ADC_SCK is up to 40.68MHz, so it is not recommended to use Dupont wires, but to plug it directly into the FPGA development board with pin headers.
|
| 97 |
+
|
| 98 |
+
|  |
|
| 99 |
+
| :------------------------------------------: |
|
| 100 |
+
| **Figure** : Schematic of NFC_BreakoutBoard. |
|
| 101 |
+
|
| 102 |
+
|  |
|
| 103 |
+
| :---------------------------------------: |
|
| 104 |
+
| **Figure** : NFC_BreakoutBoard. |
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
# FPGA Deployment
|
| 109 |
+
|
| 110 |
+
When deploying to an FPGA, all [.v]() files in the [RTL](./RTL) directory and the [RTL/nfca_controller](./RTL/nfca_controller) directory need to be added to the project. The top-level file is fpga_top.v , and the constraint method of each pin of it is shown in the code comments, as follows:
|
| 111 |
+
|
| 112 |
+
```verilog
|
| 113 |
+
module fpga_top(
|
| 114 |
+
input wire rstn_btn, // press button to reset, pressed=0, unpressed=1
|
| 115 |
+
input wire clk50m, // a 50MHz Crystal oscillator
|
| 116 |
+
|
| 117 |
+
// AD7276 ADC SPI interface
|
| 118 |
+
output wire ad7276_csn, // connect to AD7276's CSN (NFC_Breakboard's AD7276_CSN)
|
| 119 |
+
output wire ad7276_sclk, // connect to AD7276's SCLK (NFC_Breakboard's AD7276_SCLK)
|
| 120 |
+
input wire ad7276_sdata, // connect to AD7276's SDATA (NFC_Breakboard's AD7276_SDATA)
|
| 121 |
+
|
| 122 |
+
// NFC carrier generation signal
|
| 123 |
+
output wire carrier_out, // connect to FDV301N(N-MOSFET)'s gate (栅极) (NFC_Breakboard's CARRIER_OUT)
|
| 124 |
+
|
| 125 |
+
// connect to Host-PC (typically via a USB-to-UART chip on FPGA board, such as FT232, CP2102 or CH340)
|
| 126 |
+
input wire uart_rx, // connect to USB-to-UART chip's UART-TX
|
| 127 |
+
output wire uart_tx, // connect to USB-to-UART chip's UART-RX
|
| 128 |
+
|
| 129 |
+
// connect to on-board LED's (optional)
|
| 130 |
+
output wire led0, // led0=1 indicates PLL is normally run
|
| 131 |
+
output wire led1, // led1=1 indicates carrier is on
|
| 132 |
+
output wire led2 // led2=1 indicates PCD-to-PICC communication is done, and PCD is waiting for PICC-to-PCD
|
| 133 |
+
);
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
All code is a Verilog behavior-level implementation that supports any FPGA platform. Except that the altpll block in fpga_top.v is an Altera Cyclone IV-only primitive that generates the 81.36MHz clock to drive the NFC controller. If you are not using Altera Cyclone IV, please use other IP cores (such as Xilinx's clock wizard) or primitives instead, just generate an 81.36MHz clock to drive the NFC submodule.
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
# Interaction via serial port
|
| 141 |
+
|
| 142 |
+
After the FPGA is programmed, the Host-PC can control the FPGA to interact with the PICC through the serial port. The serial port configuration should be `9600,8,n,1` (that is, baud rate=9600, 8 data bits, no parity bit, 1 stop bit). Serial port communication is in the form of "one question and one answer", sending the data you want to send to the card, and then the card returns the data. Each command and response ends with `\r` or `\n` or `\r\n` (i.e. one command/response per line)
|
| 143 |
+
|
| 144 |
+
First of all, it is recommended to use the "Serial Assistant" software on the PC instead of software such as Putty. Because the logic I designed is: FPGA will turn on the carrier when it receives a serial command, and automatically turn off the carrier if there is no next command within 1.2 seconds. This is enough time for an application that controls the serial port. But 1.2 seconds is not enough for human to type the next command, which will cause the carrier to be turned off, the card to be powered off, and the state obtained before the card will disappear. "Serial Assistant" can send multiple lines of commands at a time, while Putty cannot.
|
| 145 |
+
|
| 146 |
+
## Communicate with an M1 card
|
| 147 |
+
|
| 148 |
+
I tried it with my door control card and some M1 "white cards" I bought online, because they are all M1 cards and behave similarly. Take one of the cards as an example:
|
| 149 |
+
|
| 150 |
+
Enter the following command in the "Serial Assistant" and click send, which will send 0x26 (which is the "REQA" specified by ISO14443 [3]) to the card (note that a carriage return (`\n`) must be added at the end, so that it will be regarded as a complete command):
|
| 151 |
+
|
| 152 |
+
```
|
| 153 |
+
26
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
Then the "Serial Assistant" gets receives as following, which is the "ATQA" specified by ISO14443, which means Bit frame anticollision.
|
| 157 |
+
|
| 158 |
+
```
|
| 159 |
+
04 00
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
+
> **Note**: If the card is not detected, or a waveform that does not meet the standard is received due to noise interference, the serial port will receive the character `n` . Indicates: The FPGA is functioning normally, but no card detected/error has occurred.
|
| 163 |
+
|
| 164 |
+
Then we add an "AntiCollision" command specified by ISO14443 to the next line in the "send box", this new command is to obtain the UID of the card.
|
| 165 |
+
|
| 166 |
+
```
|
| 167 |
+
26
|
| 168 |
+
93 20
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
The card response is as follows (the first line is the "ATQA" in response to "REQA", the second line is the UID in response to the "AntiCollision" command):
|
| 172 |
+
|
| 173 |
+
```
|
| 174 |
+
04 00
|
| 175 |
+
4B BE DE 79 52
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
Then we append a "SELECT" command specified by ISO14443 to the next line in the "send box", it will select the card with the UID we just obtained:
|
| 179 |
+
|
| 180 |
+
```
|
| 181 |
+
26
|
| 182 |
+
93 20
|
| 183 |
+
93 70 4B BE DE 79 52
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
The card responds "SAK=0x08" specified by ISO14443 (representing it is an M1 card. The following 0xB6 0xDD is the CRC code):
|
| 187 |
+
|
| 188 |
+
```
|
| 189 |
+
04 00
|
| 190 |
+
4B BE DE 79 52
|
| 191 |
+
08 B6 DD
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
> **Note**: The user does not need to add the CRC code when sending, FPGA will automatically calculate and append the CRC where the check code needs to be added as specified in the protocol.
|
| 195 |
+
>
|
| 196 |
+
> **Note**: When receiving, the CRC code will not be checked and deleted by FPGA, and will be displayed on the serial port.
|
| 197 |
+
|
| 198 |
+
After knowing that this is the M1 card, we can send Phase1 (the first stage) of the M1 card's Key authentication command to obtain a random number from the card (note that this command is not specified by ISO14443, but is unique to the M1 card, and other cards do not will respond to this command). We append the next line in the "Send Box":
|
| 199 |
+
|
| 200 |
+
```
|
| 201 |
+
26
|
| 202 |
+
93 20
|
| 203 |
+
93 70 4B BE DE 79 52
|
| 204 |
+
60 07
|
| 205 |
+
```
|
| 206 |
+
|
| 207 |
+
The card responds with a 4-byte random number:
|
| 208 |
+
|
| 209 |
+
```
|
| 210 |
+
04 00
|
| 211 |
+
4B BE DE 79 52
|
| 212 |
+
08 B6 DD
|
| 213 |
+
EF 9B B6 5A
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
The subsequent authentication, reading, and writing steps of M1 card are very complicated and are not the scope of this project. This project only focuses on the underlying implementation of the interaction between PCD and PICC. You can use the upper-layer application (C, Python, C# programming) to control the serial port for further operation of the M1 card.
|
| 217 |
+
|
| 218 |
+
## More test for AntiCollision
|
| 219 |
+
|
| 220 |
+
"AntiCollision" is a multi-card detection and anti-collision mechanism specified by ISO14443, because different cards have different UIDs, and the PCD uses UIDs to distinguish different cards.
|
| 221 |
+
|
| 222 |
+
I put two M1 cards on the coil, and sends REQA and AntiCollision commands, trying to get the UID of the card:
|
| 223 |
+
|
| 224 |
+
```
|
| 225 |
+
26
|
| 226 |
+
93 20
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
Serial port receives:
|
| 230 |
+
|
| 231 |
+
```
|
| 232 |
+
04 00
|
| 233 |
+
01:1
|
| 234 |
+
```
|
| 235 |
+
|
| 236 |
+
The meaning of `01:1` is an incomplete byte 0x01 (00000001), and `:1` means that the collision occurred in the lowest 1st bit of the byte. This shows that the lower 2 bits of the first byte of the UIDs of the two cards are 01 and 11 respectively. The 0th bit is the same, so there is no conflict, and the 1st bit is different, so there is a conflict.
|
| 237 |
+
|
| 238 |
+
Now if you want to select the card whose lower 2 bits are 11, you need to send a bit-oriented frame specified by ISO14443, the last byte of this frame is incomplete. Send with serial port:
|
| 239 |
+
|
| 240 |
+
```
|
| 241 |
+
26
|
| 242 |
+
93 20
|
| 243 |
+
93 22 03:2
|
| 244 |
+
```
|
| 245 |
+
|
| 246 |
+
Note that `93 22 03:2` is a bit-oriented frame. `22` means: The card reader additionally specifies 2 bits in the UID, and the card that is satisfied will respond, and the card that is not satisfied will not respond. The following `03:2` means that only the lower 2 bits of 0x03 (00000011) are sent, which is 11 .
|
| 247 |
+
|
| 248 |
+
Serial port receives:
|
| 249 |
+
|
| 250 |
+
```
|
| 251 |
+
04 00
|
| 252 |
+
01:1
|
| 253 |
+
48 BE DE 79 52
|
| 254 |
+
```
|
| 255 |
+
|
| 256 |
+
The last response is 48 BE DE 79 52. Note that 48 is not a complete byte. It is only valid for the upper 6 bits. It also needs to be spliced with the lower 2 bits (that is, the lower 2 bits of 0x03) to be a complete byte.
|
| 257 |
+
|
| 258 |
+
A simple splicing method is to bitwise OR the incomplete byte 0x03 sent by the card reader and the incomplete byte 0x48 returned by the card to get 0x4B. Indicate the UID of this card = 4B BE DE 79 52.
|
| 259 |
+
|
| 260 |
+
Similarly, if you want to select the card whose lower 2 bits are 01, you need to send via serial port:
|
| 261 |
+
|
| 262 |
+
```
|
| 263 |
+
26
|
| 264 |
+
93 20
|
| 265 |
+
93 22 01:2
|
| 266 |
+
```
|
| 267 |
+
|
| 268 |
+
Serial port receives:
|
| 269 |
+
|
| 270 |
+
```
|
| 271 |
+
04 00
|
| 272 |
+
01:1
|
| 273 |
+
00 1D DD 79 B8
|
| 274 |
+
```
|
| 275 |
+
|
| 276 |
+
Bitwise OR the incomplete byte 0x01 sent by the card reader and the incomplete byte 0x00 returned by the card to get 0x01. Indicates the UID of the other card = 01 1D DD 79 B8.
|
| 277 |
+
|
| 278 |
+
If the number of cards is more than 3, there may be multiple conflicts according to this process. For each conflict, you must specify the card with the digit = 0 or the card with = 1 that you want to choose.
|
| 279 |
+
|
| 280 |
+
## Bitwise AntiCollision Example
|
| 281 |
+
|
| 282 |
+
In order to facilitate everyone to deepen the understanding of the AntiCollision process of ISO14443, here we show an example of bit-by-bit AntiCollision, send the following commands through the serial port, and each command only specifies one more bit.
|
| 283 |
+
|
| 284 |
+
```
|
| 285 |
+
26
|
| 286 |
+
93 20
|
| 287 |
+
93 21 01:1
|
| 288 |
+
93 22 01:2
|
| 289 |
+
93 23 01:3
|
| 290 |
+
93 24 01:4
|
| 291 |
+
93 25 01:5
|
| 292 |
+
93 26 01:6
|
| 293 |
+
93 27 01:7
|
| 294 |
+
93 30 01
|
| 295 |
+
93 31 01 01:1
|
| 296 |
+
93 32 01 01:2
|
| 297 |
+
93 33 01 05:3
|
| 298 |
+
93 34 01 0D:4
|
| 299 |
+
93 35 01 1D:5
|
| 300 |
+
93 36 01 1D:6
|
| 301 |
+
93 37 01 1D:7
|
| 302 |
+
93 40 01 1D
|
| 303 |
+
93 41 01 1D 01:1
|
| 304 |
+
93 42 01 1D 01:2
|
| 305 |
+
93 43 01 1D 05:3
|
| 306 |
+
93 44 01 1D 0D:4
|
| 307 |
+
93 45 01 1D 1D:5
|
| 308 |
+
93 46 01 1D 1D:6
|
| 309 |
+
93 47 01 1D 5D:7
|
| 310 |
+
93 50 01 1D DD
|
| 311 |
+
93 51 01 1D DD 01:1
|
| 312 |
+
93 52 01 1D DD 01:2
|
| 313 |
+
93 53 01 1D DD 01:3
|
| 314 |
+
93 54 01 1D DD 09:4
|
| 315 |
+
93 55 01 1D DD 19:5
|
| 316 |
+
93 56 01 1D DD 39:6
|
| 317 |
+
93 57 01 1D DD 79:7
|
| 318 |
+
93 60 01 1D DD 79
|
| 319 |
+
93 61 01 1D DD 79 00:1
|
| 320 |
+
93 62 01 1D DD 79 00:2
|
| 321 |
+
93 63 01 1D DD 79 00:3
|
| 322 |
+
93 64 01 1D DD 79 08:4
|
| 323 |
+
93 65 01 1D DD 79 18:5
|
| 324 |
+
93 66 01 1D DD 79 38:6
|
| 325 |
+
93 67 01 1D DD 79 38:7
|
| 326 |
+
```
|
| 327 |
+
|
| 328 |
+
Serial port will receive:
|
| 329 |
+
|
| 330 |
+
```
|
| 331 |
+
04 00
|
| 332 |
+
01 1D DD 79 B8
|
| 333 |
+
00 1D DD 79 B8
|
| 334 |
+
00 1D DD 79 B8
|
| 335 |
+
00 1D DD 79 B8
|
| 336 |
+
00 1D DD 79 B8
|
| 337 |
+
00 1D DD 79 B8
|
| 338 |
+
00 1D DD 79 B8
|
| 339 |
+
00 1D DD 79 B8
|
| 340 |
+
1D DD 79 B8
|
| 341 |
+
1C DD 79 B8
|
| 342 |
+
1C DD 79 B8
|
| 343 |
+
18 DD 79 B8
|
| 344 |
+
10 DD 79 B8
|
| 345 |
+
00 DD 79 B8
|
| 346 |
+
00 DD 79 B8
|
| 347 |
+
00 DD 79 B8
|
| 348 |
+
DD 79 B8
|
| 349 |
+
DC 79 B8
|
| 350 |
+
DC 79 B8
|
| 351 |
+
D8 79 B8
|
| 352 |
+
D0 79 B8
|
| 353 |
+
C0 79 B8
|
| 354 |
+
C0 79 B8
|
| 355 |
+
80 79 B8
|
| 356 |
+
79 B8
|
| 357 |
+
78 B8
|
| 358 |
+
78 B8
|
| 359 |
+
78 B8
|
| 360 |
+
70 B8
|
| 361 |
+
60 B8
|
| 362 |
+
40 B8
|
| 363 |
+
00 B8
|
| 364 |
+
B8
|
| 365 |
+
B8
|
| 366 |
+
B8
|
| 367 |
+
B8
|
| 368 |
+
B0
|
| 369 |
+
A0
|
| 370 |
+
80
|
| 371 |
+
80
|
| 372 |
+
```
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
# Debug
|
| 377 |
+
|
| 378 |
+
If you put the card on the coil and send serial commands, the serial response is not as expected, you should:
|
| 379 |
+
|
| 380 |
+
- Check if the serial port responds with the character `n`, if not, the FPGA is not working properly. Check the serial connection and baud rate settings, and see if the program is programed into the FPGA.
|
| 381 |
+
- If it responds with the character `n` no matter what, it means that the FPGA is working properly, but no card is detected. Please check the NFC_BreakoutBoard's power supply, FPGA and NFC_BreakoutBoard's connections and pin assignments. If there's no problem, stick the card to the coil to ensure signal strength.
|
| 382 |
+
- If it still doesn't work, the further debugging method is to observe the signal with an oscilloscope, connect the oscilloscope to the J3 (SMA interface) of the NFC_BreakoutBoard, and the envelope detection of the carrier should be observed here. Let the serial port send 26 (REQA) every 2 seconds, and you should be able to see the modulation process of carrier startup and modulation of 0x26 on the oscilloscope. Then observe whether there is a weak signal change (probably only a few tens of mV) after the modulation is sent, which is the response of the card to the card reader.
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
# RTL Simulation
|
| 387 |
+
|
| 388 |
+
The files of simulation are in the directory [SIM](./SIM), where:
|
| 389 |
+
|
| 390 |
+
- [tb_nfca_controller.v](./SIM) is a testbench for nfca_controller.v.
|
| 391 |
+
- [tb_nfca_controller_run_iverilog.bat](./SIM) is a iverilog simulation command script.
|
| 392 |
+
|
| 393 |
+
The behavior of the simulation is: send some frames to the nfca_controller's transmit interface, and on the carrier_out signal you can see the modulated PCD-to-PICC modulation waveform. But it cannot simulate PICC-to-PCD because I didn't write the PICC's Verilog model.
|
| 394 |
+
|
| 395 |
+
Before using iverilog for simulation, you need to install iverilog , see: [iverilog_usage](https://github.com/WangXuan95/WangXuan95/blob/main/iverilog_usage/iverilog_usage.md)
|
| 396 |
+
|
| 397 |
+
Then double-click tb_nfca_controller_run_iverilog.bat to run the simulation, and then you can open the generated dump.vcd file to view the waveform. The following figure is the modulation waveform of the 0x26 (REQA) frame:
|
| 398 |
+
|
| 399 |
+
|  |
|
| 400 |
+
| :----------------------------------------------------------: |
|
| 401 |
+
| Figure: Modulation waveform for frame 0x26 (REQA) in simulation. |
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
# Reference
|
| 406 |
+
|
| 407 |
+
* [1] ST TN1216 Technical note, ST NFC guide, https://www.st.com/resource/en/technical_note/dm00190233-st25-nfc-guide-stmicroelectronics.pdf
|
| 408 |
+
* [2] ISO/NFC Standards and Specifications Overview, https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/667/2072.ISO_5F00_NFC-Standards-and-Specifications-Overview_5F00_2014.pdf
|
| 409 |
+
* [3] ISO/IEC STANDARD 14443-3, http://emutag.com/iso/14443-3.pdf
|
| 410 |
+
* [4] THM3060 Card Reader.
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
<span id="cn">FPGA NFC (RFID)</span>
|
| 424 |
+
===========================
|
| 425 |
+
|
| 426 |
+
用 FPGA 从底层开始搭建一个 NFC PCD (读卡器),支持 ISO14443A 标准。
|
| 427 |
+
|
| 428 |
+

|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
## 为什么要做本项目?
|
| 433 |
+
|
| 434 |
+
本人想玩玩射频,又想展示一些和其它玩 SDR 的人不一样的东西。然后发现 NFC 的载波频率只有 13.56MHz,且调制方式为调幅(ASK) ,可以用很低的成本(最廉价的 FPGA + 1个3Msps 的ADC + 几个分立器件)实现一个读卡器。FPGA内既进行数字信号处理,又进行协议处理,是一个完整的~~可以装X的~~小系统。于是就有了本项目,它能在 PC 端串口命令控制下,完整地支持 ISO14443A 。并成功地与 M1卡 交互。
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
## 名词释义
|
| 439 |
+
|
| 440 |
+
| 名词 | 简称 | 直观名称 | 释义 |
|
| 441 |
+
| ------------------------- | ---- | ---------------------- | ------------------------------------------------------------ |
|
| 442 |
+
| Proximity Coupling Device | PCD | 读卡器、读写器、Reader | 给卡片提供能量,并作为通讯主机的设备,其实就是读卡器,也就是本项目要实现的东西。 |
|
| 443 |
+
| Proximity Card | PICC | 标签、卡片、TAG | M1卡、UID卡、电子标签这些卡片。不同类的卡片可能满足不同标准。 |
|
| 444 |
+
| PCD-to-PICC | TX | 发送 | PCD 对载波进行调制,传输信息到 PICC |
|
| 445 |
+
| PICC-to-PCD | RX | 接收 | PICC 改变自身阻抗,使得 PCD 探测到载波幅度发生变化,从而传输信息到 PCD 。 |
|
| 446 |
+
| NXP MIFARE Classic 1K | M1卡 | | 一种满足 ISO14443A 的卡片,日常生活很常见,比如门禁卡。 |
|
| 447 |
+
| ISO14443A | NFCA | | 一种 NFC 标准,用于个人卡片。本项目从硬件到协议完全支持。详见 [1,2,3] |
|
| 448 |
+
| ISO14443B | NFCB | | 一种 NFC 标准,用于个人卡片。本项目硬件不支持。详见 [1,2,3] |
|
| 449 |
+
| ISO15693 | NFCV | | 一种 NFC 标准,用于工业电子标签。本项目硬件支持,但 FPGA 尚未编写其协议。详见 [1,2] |
|
| 450 |
+
| Carrier、载波 | fc | 13.56MHz 载波 | FPGA 发射引脚需要产生的频率,驱动线圈在这个频率下谐振。 |
|
| 451 |
+
| Subcarrier、副载波 | fs | 847.5 kHz 副载波 | 调制的最小单位(PCD和PICC会以这个频率改变调制幅度),是载波频率的 1/16 |
|
| 452 |
+
| 位频率 | | 105.9375 kHz | 8个副载波周期可能携带一位 (bit) 数据信息 |
|
| 453 |
+
| Amplitude Shift Keying | ASK | 调幅 | 通过改变载波幅度来传送信息 |
|
| 454 |
+
|
| 455 |
+
更多简称详见引用 [1,2,3]
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
## 项目思路
|
| 460 |
+
|
| 461 |
+
首先是载波生成,我们用 FPGA 的引脚产生 13.56MHz 的信号(对应代码文件 nfca_tx_modulate.v),该信号驱动一个 MOS 管 (FDV301N) + 一个谐振电路来让天线(线圈)谐振。
|
| 462 |
+
|
| 463 |
+
其次是载波调制发送,ISO14443A 的 PCD-to-PICC 的副载波调制方式是 100% ASK (即在一个副载波周期内,要么满幅度发送载波,要么完全不发送载波),这对 FPGA 也是很容易实现的(对应代码文件 nfca_tx_modulate.v)。
|
| 464 |
+
|
| 465 |
+
然后是接收卡片的调制信息,PICC-to-PCD 的调制方式是 2%~10% 的 ASK (即在一个副载波周期内,要么让载波衰减一点,要么不衰减)。我用二极管(1N4148)+电容+电阻来做包络检波,得到包络线的频率=副载波频率=847.5kHz,然后用 ADC 对包络线采样(对应代码文件 ad7276_read.v)。包络检波降低了 ADC 采样率的需求,避免直接使用 ≥20Msps 的 ADC 来采样载波,而是只用一个 3Msps 的 ADC (AD7276B) 来采样副载波即可。在 FPGA 内,用一个数字信号处理(DSP)算法来从 ADC 采样数据中检测 PICC-to-PCD 的 ASK 信号,即检测 ADC 采样数据幅度的微小变化,需要有抗噪声能力,并自适应信号幅度。我用的是中值滤波减去原始信号,再做比例阈值判断,效果不错(对应代码文件 nfca_rx_dsp.v)。
|
| 466 |
+
|
| 467 |
+
最后是实现 ISO14443A 的编解码协议,包括发送校验生成和封包(对应代码文件 nfca_tx_frame.v)、接收协议的解包(对应代码文件 nfca_rx_tobits.v 和 nfca_rx_tobytes.v),这部分是按照 Spec 文档 [3] 编写的。
|
| 468 |
+
|
| 469 |
+
我还在 FPGA 中实现了串口控制逻辑,将 Host-PC 发送给 FPGA 的串口命令解析成 NFC 发送数据(对应代码文件 uart_rx.v 和 uart_rx_parser.v),并将 NFC 接收数据通过串口发送给 Host-PC (对应代码文件 uart_tx.v)。用户可以在 Host-PC 的”串口调试工具“中发送数据给卡片,然后收到卡片返回的数据。
|
| 470 |
+
|
| 471 |
+
下图是系统框图,其中 FPGA 中的模块下方逐个标注了 Verilog 代码文件名。
|
| 472 |
+
|
| 473 |
+
```
|
| 474 |
+
_________ _________________________________________________________________________________________________________
|
| 475 |
+
| | ___________________________________________________________________________________________________ |
|
| 476 |
+
| | | _________________________________________________________ | |
|
| 477 |
+
| | | ___________ | ____________ _____________ | | | ____________ ____________
|
| 478 |
+
| | | uart_rx | UART RX | | | frame | | RFID TX | | | | | FDV301N | | Resonant | ___________
|
| 479 |
+
uart_tx |---|->|-------->| logic |---|--->| pack |--------->| modulate |--------------->|---------------->|--|-->| N-MOSFET |--->| circuit | | |
|
| 480 |
+
| | | ----------- | ------------ ------------- | carrier_out | | | | | |---v->| Antenna |
|
| 481 |
+
| | | uart_rx.v | nfca_tx_frame.v | nfca_tx_modulate.v | | | ------------ ------------ | | Coil |
|
| 482 |
+
| | | uart_rx_parser.v | rx_on | | | | | | |
|
| 483 |
+
| | | fifo_sync.v | | | | | | -----------
|
| 484 |
+
| | | ___________ | ___________ ______V____ ____________ | _____________ | | ___________ ____________ |
|
| 485 |
+
| | | uart_tx | UART TX | | | bytes | | bits | | ADC data | | | AD7276B | | | | AD7276B | | Envelop | |
|
| 486 |
+
uart_rx |<--|--|<--------| logic |<--|--| rebuild |<--------| rebuild |<-------| DSP |<-|--|ADC reader |<-|<-|-----| ADC |<--| detection|<---
|
| 487 |
+
| | | ----------- | ----------- ----------- ------------ | ------------- | | SPI | | | |
|
| 488 |
+
| | | uart_tx.v |nfca_rx_tobytes.v nfca_rx_tobits.v nfca_rx_dsp.v | ad7276_read.v | | ----------- ------------
|
| 489 |
+
GND |---| | --------------------------------------------------------| | |
|
| 490 |
+
| | | nfca_controller.v | |
|
| 491 |
+
| | --------------------------------------------------------------------------------------------------- |
|
| 492 |
+
| | uart2nfca_system_top.v |
|
| 493 |
+
--------- --------------------------------------------------------------------------------------------------------
|
| 494 |
+
Host-PC FPGA (fpga_top.v ) Analog Circuit
|
| 495 |
+
```
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
|
| 499 |
+
# 搭建硬件
|
| 500 |
+
|
| 501 |
+
该 PCB 设计在立创 EDA 开源: [oshwhub.com/wangxuan/rfid_nfc_iso14443a_iso15693_breakoutboard](https://oshwhub.com/wangxuan/rfid_nfc_iso14443a_iso15693_breakoutboard)
|
| 502 |
+
|
| 503 |
+
PCB 文件夹里是硬件设计(命名为 NFC_BreakoutBoard),上面主要包括:
|
| 504 |
+
|
| 505 |
+
- 发送电路 (驱动电路): N-MOSFET、电感等。
|
| 506 |
+
- 接收电路 (检波电路):检波二极管、AD7276B。
|
| 507 |
+
- 4匝线圈。
|
| 508 |
+
|
| 509 |
+
请用制造文件 NFC_BreakoutBoard_gerber.zip 来打样 PCB 。然后焊接元件。最后把该PCB与FPGA连接,连接方法为:
|
| 510 |
+
|
| 511 |
+
- J1 连接 7V~9V 的电源。
|
| 512 |
+
- J2 连接 FPGA 开发板(占用 FPGA 4 个普通 IO 引脚,电平为 3.3V 或 2.5V 均可)。注意:ADC_SCK 的频率高达 40.68MHz,因此不建议用杜邦线,而是用排针直插到 FPGA 开发板。
|
| 513 |
+
|
| 514 |
+
|  |
|
| 515 |
+
| :-----------------------------------------: |
|
| 516 |
+
| 图: NFC_BreakoutBoard 原理图 |
|
| 517 |
+
|
| 518 |
+
|  |
|
| 519 |
+
| :---------------------------------------: |
|
| 520 |
+
| 图: NFC_BreakoutBoard |
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
# FPGA 部署
|
| 525 |
+
|
| 526 |
+
部署到 FPGA 时,所有 RTL 目录 和 RTL/nfca_controller 目录 中的 .v 文件都需要加入工程。顶层文件为 fpga_top.v ,它的每个引脚的连接方式见代码注释,如下:
|
| 527 |
+
|
| 528 |
+
```verilog
|
| 529 |
+
module fpga_top(
|
| 530 |
+
input wire rstn_btn, // press button to reset, pressed=0, unpressed=1
|
| 531 |
+
input wire clk50m, // a 50MHz Crystal oscillator
|
| 532 |
+
|
| 533 |
+
// AD7276 ADC SPI interface
|
| 534 |
+
output wire ad7276_csn, // connect to AD7276's CSN (NFC_Breakboard's AD7276_CSN)
|
| 535 |
+
output wire ad7276_sclk, // connect to AD7276's SCLK (NFC_Breakboard's AD7276_SCLK)
|
| 536 |
+
input wire ad7276_sdata, // connect to AD7276's SDATA (NFC_Breakboard's AD7276_SDATA)
|
| 537 |
+
|
| 538 |
+
// NFC carrier generation signal
|
| 539 |
+
output wire carrier_out, // connect to FDV301N(N-MOSFET)'s gate (栅极) (NFC_Breakboard's CARRIER_OUT)
|
| 540 |
+
|
| 541 |
+
// connect to Host-PC (typically via a USB-to-UART chip on FPGA board, such as FT232, CP2102 or CH340)
|
| 542 |
+
input wire uart_rx, // connect to USB-to-UART chip's UART-TX
|
| 543 |
+
output wire uart_tx, // connect to USB-to-UART chip's UART-RX
|
| 544 |
+
|
| 545 |
+
// connect to on-board LED's (optional)
|
| 546 |
+
output wire led0, // led0=1 indicates PLL is normally run
|
| 547 |
+
output wire led1, // led1=1 indicates carrier is on
|
| 548 |
+
output wire led2 // led2=1 indicates PCD-to-PICC communication is done, and PCD is waiting for PICC-to-PCD
|
| 549 |
+
);
|
| 550 |
+
```
|
| 551 |
+
|
| 552 |
+
所有代码都是 Verilog 行为级实现,支持任意 FPGA 平台。除了 fpga_top.v 里的 altpll 模块是仅限于 Altera Cyclone IV 的原语,它用来生成 81.36MHz 时钟,驱动 NFC 控制器。如果你用的不是 Altera Cyclone IV,请使用其它的 IP 核(例如Xilinx 的 clock wizard)或原语来替换,总之只要生成 81.36MHz 的时钟来驱动 NFC 子模块即可。
|
| 553 |
+
|
| 554 |
+
|
| 555 |
+
|
| 556 |
+
# 串口交互
|
| 557 |
+
|
| 558 |
+
FPGA 烧录之后,Host-PC 可以通过串口控制 FPGA 和 PICC 进行交互。串口格式为 9600,8,n,1 (即波特率=9600,8个数据位,无校验位,1个停止位)。串口通信是“一问一答”的形式,发送你要发给卡片的数据,然后卡片返回数据。每个命令和响应都以 \r 或 \n 或 \r\n 结尾(也就是一行一个命令/响应)
|
| 559 |
+
|
| 560 |
+
首先,建议在 PC 上使用“串口调试助手”,而不是 putty 等软件。因为我设计的逻辑是: FPGA 会在收到串口命令时打开载波,如果1.2秒内没有下一个命令到来,就自动关闭载波。这对于一个控制串口的应用程序是足够的时间。但1.2秒是不够人是打出下一条命令的,会导致载波关闭,卡片下电,卡片之前获得的状态都消失了。“串口调试助手”可以一次发送多行命令,而 Putty 则一次只能打一条命令。
|
| 561 |
+
|
| 562 |
+
> 注意:“串口调试助手” 往往有“16进制显示”和“16进制发送”选项,不需要勾选。本项目里 FPGA 会把收到的 ASCII 的十六进制形式处理成数字,也会把发出的 数字转成 ASCII 十六进制形��。
|
| 563 |
+
|
| 564 |
+
## 与 M1 卡通信
|
| 565 |
+
|
| 566 |
+
我用自己的门禁卡,和几个在 taobao 上买了的 M1 “白卡”试了试,因为都是 M1 卡,行为类似。以其中一个卡举例:
|
| 567 |
+
|
| 568 |
+
在 “串口调试助手” 中输入如下命令并点击发送,这会发送 0x26(ISO14443 [3] 规定的 REQA)给卡片(注意末尾要加回车,这样才会被当成一条完整的命令):
|
| 569 |
+
|
| 570 |
+
```
|
| 571 |
+
26
|
| 572 |
+
```
|
| 573 |
+
|
| 574 |
+
然后串口收到如下,这是 ISO14443 规定的 ATQA,含义是 Bit frame anticollision 。
|
| 575 |
+
|
| 576 |
+
```
|
| 577 |
+
04 00
|
| 578 |
+
```
|
| 579 |
+
|
| 580 |
+
> **注:如果没检测到卡,或者因噪声干扰而收到不符合标准规定的波形,串口的行尾会收到字符 n。表示: FPGA正常工作,但没检测到卡/出现错误。**
|
| 581 |
+
|
| 582 |
+
然后我们在“发送框”里下一行附加一个 ISO14443 规定的 AntiCollision 命令,用来获得卡的 UID (因为很可能1.2秒已经过去了,卡片已经丢失了上次上电的信息,需要重新发送 REQA 0x26)。
|
| 583 |
+
|
| 584 |
+
```
|
| 585 |
+
26
|
| 586 |
+
93 20
|
| 587 |
+
```
|
| 588 |
+
|
| 589 |
+
卡片响应如下(第一行是响应 REQA 的 ATQA,第二行是 响应 anticollision 的 UID):
|
| 590 |
+
|
| 591 |
+
```
|
| 592 |
+
04 00
|
| 593 |
+
4B BE DE 79 52
|
| 594 |
+
```
|
| 595 |
+
|
| 596 |
+
然后我们在“发送框”里下一行附加一个 ISO14443 规定的 SELECT 命令,用刚刚获取到的 UID 选中该卡:
|
| 597 |
+
|
| 598 |
+
```
|
| 599 |
+
26
|
| 600 |
+
93 20
|
| 601 |
+
93 70 4B BE DE 79 52
|
| 602 |
+
```
|
| 603 |
+
|
| 604 |
+
卡响应 ISO14443 规定的 SAK=0x08(代表它是 M1 卡。后面的 0xB6 0xDD 则是 CRC 校验码):
|
| 605 |
+
|
| 606 |
+
```
|
| 607 |
+
04 00
|
| 608 |
+
4B BE DE 79 52
|
| 609 |
+
08 B6 DD
|
| 610 |
+
```
|
| 611 |
+
|
| 612 |
+
> **注:发送时不需要用户附加 CRC 校验码, FPGA 会在协议规定的需要加校验码的地方自动计算并追加 CRC。**
|
| 613 |
+
>
|
| 614 |
+
> **注:接收时,CRC 码不会被 FPGA 检查和删掉,会从串口展示出来。**
|
| 615 |
+
|
| 616 |
+
根据卡片返回的 SAK ,知道这是 M1 卡后,我们可以发送 M1 卡的 Key 认证命令的 Phase1 (第一阶段),从卡片获取随机数(注意,该命令不是 ISO14443 规定的,而是 M1 卡独有的,其它卡不会响应这个命令)。我们在“发送框”里下一行附加:
|
| 617 |
+
|
| 618 |
+
```
|
| 619 |
+
26
|
| 620 |
+
93 20
|
| 621 |
+
93 70 4B BE DE 79 52
|
| 622 |
+
60 07
|
| 623 |
+
```
|
| 624 |
+
|
| 625 |
+
卡片响应 4 字节随机数:
|
| 626 |
+
|
| 627 |
+
```
|
| 628 |
+
04 00
|
| 629 |
+
4B BE DE 79 52
|
| 630 |
+
08 B6 DD
|
| 631 |
+
EF 9B B6 5A
|
| 632 |
+
```
|
| 633 |
+
|
| 634 |
+
M1 卡的后续认证、读写步骤很复杂,不是本工程关注的范围。本工程仅关注 ISO14443A PCD 与 PICC 交互的底层实现。你可以用上层应用程序(C, Python, C# 编程)控制串口来进行 M1 卡的进一步操作。
|
| 635 |
+
|
| 636 |
+
## 测试 AntiCollision
|
| 637 |
+
|
| 638 |
+
AntiCollision 是 ISO14443 规定的多卡检测和防冲突机制,因为不同的卡拥有不同的 UID,读卡器用 UID 来区分不同的卡。
|
| 639 |
+
|
| 640 |
+
我把 2 张 M1 卡放在线圈上,串口发送 REQA 和 AntiCollision 命令,试图获取卡的 UID:
|
| 641 |
+
|
| 642 |
+
```
|
| 643 |
+
26
|
| 644 |
+
93 20
|
| 645 |
+
```
|
| 646 |
+
|
| 647 |
+
串口收到:
|
| 648 |
+
|
| 649 |
+
```
|
| 650 |
+
04 00
|
| 651 |
+
01:1
|
| 652 |
+
```
|
| 653 |
+
|
| 654 |
+
01:1 的含义是一个不完整的字节 0x01(00000001),:1 代表该冲突发生在该字节的从低到高第1位。
|
| 655 |
+
|
| 656 |
+
这说明,这两个卡的 UID 的第一个字节的低2位分别是 01 和 11。第0位一样所以没发生冲突,第1位不一样所以发生了冲突。
|
| 657 |
+
|
| 658 |
+
现在你想选择低2位是 11 的那个卡,就需要发送 ISO14443 规定的 bit-oriented 帧,这种帧的最后一个字节是不完整的。用串口发送:
|
| 659 |
+
|
| 660 |
+
```
|
| 661 |
+
26
|
| 662 |
+
93 20
|
| 663 |
+
93 22 03:2
|
| 664 |
+
```
|
| 665 |
+
|
| 666 |
+
93 22 03:2 是一个 bit-oriented 帧。 22 代表:读卡器额外指定 UID 中的 2 个 bit,满足的卡才会响应,不满足的卡就不要响应。后面的 03:2 代表只发送 0x03 (00000011) 的低2位,即 11 。
|
| 667 |
+
|
| 668 |
+
串口收到:
|
| 669 |
+
|
| 670 |
+
```
|
| 671 |
+
04 00
|
| 672 |
+
01:1
|
| 673 |
+
48 BE DE 79 52
|
| 674 |
+
```
|
| 675 |
+
|
| 676 |
+
最后一条响应是 48 BE DE 79 52 ,注意,48 并不是一个完整字节,它只有高6bit有效,他还需要拼接上低2bit(即0x03的低2bit),才是完整的字节。
|
| 677 |
+
|
| 678 |
+
一个简单的拼接方法是将读卡器发送的不完整字节 0x03 和卡片返回的不完整字节 0x48 进行按位或,得到 0x4B。
|
| 679 |
+
|
| 680 |
+
表明这张卡的 UID = 4B BE DE 79 52。
|
| 681 |
+
|
| 682 |
+
同理,如果想选择低2位是 01 的那个卡,就需要串口发送:
|
| 683 |
+
|
| 684 |
+
```
|
| 685 |
+
26
|
| 686 |
+
93 20
|
| 687 |
+
93 22 01:2
|
| 688 |
+
```
|
| 689 |
+
|
| 690 |
+
串口收到:
|
| 691 |
+
|
| 692 |
+
```
|
| 693 |
+
04 00
|
| 694 |
+
01:1
|
| 695 |
+
00 1D DD 79 B8
|
| 696 |
+
```
|
| 697 |
+
|
| 698 |
+
将读卡器发送的不完整字节 0x01 和卡片返回的不完整字节 0x00 进行按位或,得到 0x01。
|
| 699 |
+
|
| 700 |
+
表明另一张卡的 UID = 01 1D DD 79 B8。
|
| 701 |
+
|
| 702 |
+
如果卡的数量有3张以上,依照这个流程还可能发生多次冲突,每发生一次冲突都要指定你要选择发生冲突的那一位=0的卡,还是=1的卡。
|
| 703 |
+
|
| 704 |
+
## 逐位 AntiCollision 的例子
|
| 705 |
+
|
| 706 |
+
为了方便大家加深对 ISO14443 的 AntiCollision 过程的理解,下面我们展示一个逐位 AntiCollision 的例子,用串口发送如下这些命令,每条命令都只多指定一位。
|
| 707 |
+
|
| 708 |
+
```
|
| 709 |
+
26
|
| 710 |
+
93 20
|
| 711 |
+
93 21 01:1
|
| 712 |
+
93 22 01:2
|
| 713 |
+
93 23 01:3
|
| 714 |
+
93 24 01:4
|
| 715 |
+
93 25 01:5
|
| 716 |
+
93 26 01:6
|
| 717 |
+
93 27 01:7
|
| 718 |
+
93 30 01
|
| 719 |
+
93 31 01 01:1
|
| 720 |
+
93 32 01 01:2
|
| 721 |
+
93 33 01 05:3
|
| 722 |
+
93 34 01 0D:4
|
| 723 |
+
93 35 01 1D:5
|
| 724 |
+
93 36 01 1D:6
|
| 725 |
+
93 37 01 1D:7
|
| 726 |
+
93 40 01 1D
|
| 727 |
+
93 41 01 1D 01:1
|
| 728 |
+
93 42 01 1D 01:2
|
| 729 |
+
93 43 01 1D 05:3
|
| 730 |
+
93 44 01 1D 0D:4
|
| 731 |
+
93 45 01 1D 1D:5
|
| 732 |
+
93 46 01 1D 1D:6
|
| 733 |
+
93 47 01 1D 5D:7
|
| 734 |
+
93 50 01 1D DD
|
| 735 |
+
93 51 01 1D DD 01:1
|
| 736 |
+
93 52 01 1D DD 01:2
|
| 737 |
+
93 53 01 1D DD 01:3
|
| 738 |
+
93 54 01 1D DD 09:4
|
| 739 |
+
93 55 01 1D DD 19:5
|
| 740 |
+
93 56 01 1D DD 39:6
|
| 741 |
+
93 57 01 1D DD 79:7
|
| 742 |
+
93 60 01 1D DD 79
|
| 743 |
+
93 61 01 1D DD 79 00:1
|
| 744 |
+
93 62 01 1D DD 79 00:2
|
| 745 |
+
93 63 01 1D DD 79 00:3
|
| 746 |
+
93 64 01 1D DD 79 08:4
|
| 747 |
+
93 65 01 1D DD 79 18:5
|
| 748 |
+
93 66 01 1D DD 79 38:6
|
| 749 |
+
93 67 01 1D DD 79 38:7
|
| 750 |
+
```
|
| 751 |
+
|
| 752 |
+
串口收到:
|
| 753 |
+
|
| 754 |
+
```
|
| 755 |
+
04 00
|
| 756 |
+
01 1D DD 79 B8
|
| 757 |
+
00 1D DD 79 B8
|
| 758 |
+
00 1D DD 79 B8
|
| 759 |
+
00 1D DD 79 B8
|
| 760 |
+
00 1D DD 79 B8
|
| 761 |
+
00 1D DD 79 B8
|
| 762 |
+
00 1D DD 79 B8
|
| 763 |
+
00 1D DD 79 B8
|
| 764 |
+
1D DD 79 B8
|
| 765 |
+
1C DD 79 B8
|
| 766 |
+
1C DD 79 B8
|
| 767 |
+
18 DD 79 B8
|
| 768 |
+
10 DD 79 B8
|
| 769 |
+
00 DD 79 B8
|
| 770 |
+
00 DD 79 B8
|
| 771 |
+
00 DD 79 B8
|
| 772 |
+
DD 79 B8
|
| 773 |
+
DC 79 B8
|
| 774 |
+
DC 79 B8
|
| 775 |
+
D8 79 B8
|
| 776 |
+
D0 79 B8
|
| 777 |
+
C0 79 B8
|
| 778 |
+
C0 79 B8
|
| 779 |
+
80 79 B8
|
| 780 |
+
79 B8
|
| 781 |
+
78 B8
|
| 782 |
+
78 B8
|
| 783 |
+
78 B8
|
| 784 |
+
70 B8
|
| 785 |
+
60 B8
|
| 786 |
+
40 B8
|
| 787 |
+
00 B8
|
| 788 |
+
B8
|
| 789 |
+
B8
|
| 790 |
+
B8
|
| 791 |
+
B8
|
| 792 |
+
B0
|
| 793 |
+
A0
|
| 794 |
+
80
|
| 795 |
+
80
|
| 796 |
+
```
|
| 797 |
+
|
| 798 |
+
|
| 799 |
+
~~读卡器:你这每一位都保响应吗?~~
|
| 800 |
+
|
| 801 |
+
~~卡片:瞧瞧你附近哪儿有那么多卡啊?这都是近场的通信,你想防冲突我还没必要防冲突呢。~~
|
| 802 |
+
|
| 803 |
+
~~读卡器:我问你你每一位都保响应吗?~~
|
| 804 |
+
|
| 805 |
+
~~卡片:你是故意找茬是不是?你 SELECT 不 SELECT 吧!~~
|
| 806 |
+
|
| 807 |
+
~~读卡器:你要每一位都正确响应我肯定 SELECT 啊。~~
|
| 808 |
+
|
| 809 |
+
~~读卡器:那他要是不响应呢?~~
|
| 810 |
+
|
| 811 |
+
~~卡片:不响应,我免认证让你读写,满意了吧?~~
|
| 812 |
+
|
| 813 |
+
~~卡片:00 1D DD 79 B8,无冲突。~~
|
| 814 |
+
|
| 815 |
+
~~读卡器:93 22 01:2,剩下 38 bit 响应给我看看。~~
|
| 816 |
+
|
| 817 |
+
~~卡片:你是故意找茬是不是!你 SELECT 不 SELECT 吧!~~
|
| 818 |
+
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
# 调试
|
| 822 |
+
|
| 823 |
+
如果你将卡放在线圈上,并发送串口命令后,串口响应不符合预期,应该:
|
| 824 |
+
|
| 825 |
+
- 看看串口是否响应字符 'n',若没有,说明 FPGA 工作不正常。检查串口连接和波特率设置,并看看程序有没有烧到 FPGA 里。
|
| 826 |
+
- 如果无论发什么,都响应字符 'n' ,说明 FPGA 正常工作,但没检测到卡。请检查 NFC_BreakoutBoard 的电源、FPGA 和 NFC_BreakoutBoard 的连接和引脚分配。如果没问题,将卡贴在线圈上保证信号强度。
|
| 827 |
+
- 如果还不行,进一步的调试方法是用示波器观察信号,将示波器接在 NFC_BreakoutBoard 的 J3 (SMA 接口上),这里应该能观察到对载波的包络检波。让串口每隔2秒发送一次 26 (REQA),在示波器上应该能看到载波启动、调制 0x26 的调制过程。然后观察发送调制后大概 8us 后是否有微弱的信号变化(大概只会有几十 mV的浮动),这就是卡片对读卡器的响应。
|
| 828 |
+
|
| 829 |
+
|
| 830 |
+
|
| 831 |
+
# 仿真
|
| 832 |
+
|
| 833 |
+
仿真所需要的文件在目录 SIM 里,其中:
|
| 834 |
+
|
| 835 |
+
- tb_nfca_controller.v 是针对 nfca_controller.v 的 testbench 。
|
| 836 |
+
- tb_nfca_controller_run_iverilog.bat 包含了 iverilog 仿真命令。
|
| 837 |
+
|
| 838 |
+
该仿真的行为是:向 nfca_controller 的发送接口发送一些帧,在 carrier_out 信号上可以看到调制的 PCD-to-PICC 发送数据。但该仿真并不会仿真 PICC-to-PCD ,因为我没有编写 PICC 的 model 代码。
|
| 839 |
+
|
| 840 |
+
使用 iverilog 进行仿真前,需要安装 iverilog ,见:[iverilog_usage](https://github.com/WangXuan95/WangXuan95/blob/main/iverilog_usage/iverilog_usage.md)
|
| 841 |
+
|
| 842 |
+
然后双击 tb_nfca_controller_run_iverilog.bat 运行仿真,然后可以打开生成的 dump.vcd 文件查看波形。下图是看到的 0x26(REQA)帧的调制波形:
|
| 843 |
+
|
| 844 |
+
|  |
|
| 845 |
+
| :-----------------------------------------: |
|
| 846 |
+
| 图:仿真中看到的 0x26(REQA)帧的调制波形。 |
|
| 847 |
+
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
# 引用
|
| 851 |
+
|
| 852 |
+
* [1] ST TN1216 Technical note, ST NFC guide, https://www.st.com/resource/en/technical_note/dm00190233-st25-nfc-guide-stmicroelectronics.pdf
|
| 853 |
+
* [2] ISO/NFC Standards and Specifications Overview, https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/667/2072.ISO_5F00_NFC-Standards-and-Specifications-Overview_5F00_2014.pdf
|
| 854 |
+
* [3] ISO/IEC STANDARD 14443-3, http://emutag.com/iso/14443-3.pdf
|
| 855 |
+
* [4] THM3060 读卡器 原理图(好像没有官方公开,~~国内公司老毛病了~~。可以上 baidu 搜,或 taobao 买个模块,商家就给你原理图了)
|
| 856 |
+
|
| 857 |
+
|
| 858 |
+
|
WangXuan95_FPGA-NFC/RTL/ad7276_read.v
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module ad7276_read (
|
| 3 |
+
input wire rstn,
|
| 4 |
+
input wire clk, // require 81.36MHz
|
| 5 |
+
// connect to AD7276
|
| 6 |
+
output reg ad7276_csn,
|
| 7 |
+
output reg ad7276_sclk,
|
| 8 |
+
input wire ad7276_sdata,
|
| 9 |
+
// 12bit ADC data output
|
| 10 |
+
output reg adc_data_en,
|
| 11 |
+
output reg [11:0] adc_data
|
| 12 |
+
);
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
initial {ad7276_csn, ad7276_sclk} = 2'b11;
|
| 16 |
+
initial {adc_data_en, adc_data} = 0;
|
| 17 |
+
|
| 18 |
+
reg [ 4:0] cnt = 0;
|
| 19 |
+
reg data_en = 0;
|
| 20 |
+
reg [11:0] data = 0;
|
| 21 |
+
|
| 22 |
+
// cnt runs from 0~31 cyclic
|
| 23 |
+
always @ (posedge clk or negedge rstn)
|
| 24 |
+
if(~rstn)
|
| 25 |
+
cnt <= 0;
|
| 26 |
+
else
|
| 27 |
+
cnt <= cnt + 5'd1;
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
always @ (posedge clk or negedge rstn)
|
| 31 |
+
if(~rstn) begin
|
| 32 |
+
{ad7276_csn, ad7276_sclk} <= 2'b11;
|
| 33 |
+
end else begin
|
| 34 |
+
if(cnt >= 5'd29 || cnt == 5'd0)
|
| 35 |
+
{ad7276_csn, ad7276_sclk} <= 2'b11;
|
| 36 |
+
else
|
| 37 |
+
{ad7276_csn, ad7276_sclk} <= {1'b0, cnt[0]};
|
| 38 |
+
end
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
always @ (posedge clk or negedge rstn)
|
| 42 |
+
if(~rstn) begin
|
| 43 |
+
data_en <= 1'b0;
|
| 44 |
+
data <= 0;
|
| 45 |
+
adc_data_en <= 1'b0;
|
| 46 |
+
adc_data <= 0;
|
| 47 |
+
end else begin
|
| 48 |
+
if(ad7276_csn) begin // submit result
|
| 49 |
+
data_en <= 1'b0;
|
| 50 |
+
adc_data_en <= data_en;
|
| 51 |
+
if(data_en) adc_data <= data;
|
| 52 |
+
end else if(ad7276_sclk) begin // sample at negedge of ad7276_sclk
|
| 53 |
+
data_en <= 1'b1;
|
| 54 |
+
data <= {data[10:0], ad7276_sdata};
|
| 55 |
+
adc_data_en <= 1'b0;
|
| 56 |
+
end
|
| 57 |
+
end
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/fifo_sync.v
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : fifo_sync
|
| 4 |
+
// Type : synthesizable, IP's sub-module
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: synchronous fifo
|
| 7 |
+
//--------------------------------------------------------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
module fifo_sync #(
|
| 10 |
+
parameter DW = 8, // bit width
|
| 11 |
+
parameter EA = 10 // 9:depth=512 10:depth=1024 11:depth=2048 12:depth=4096
|
| 12 |
+
) (
|
| 13 |
+
input wire rstn,
|
| 14 |
+
input wire clk,
|
| 15 |
+
// input interface
|
| 16 |
+
output wire i_rdy,
|
| 17 |
+
input wire i_en,
|
| 18 |
+
input wire [DW-1:0] i_data,
|
| 19 |
+
// output interface
|
| 20 |
+
input wire o_rdy,
|
| 21 |
+
output reg o_en,
|
| 22 |
+
output reg [DW-1:0] o_data
|
| 23 |
+
);
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
reg [DW-1:0] buffer [ ((1<<EA)-1) : 0 ];
|
| 28 |
+
|
| 29 |
+
localparam [EA:0] A_ZERO = {{EA{1'b0}}, 1'b0};
|
| 30 |
+
localparam [EA:0] A_ONE = {{EA{1'b0}}, 1'b1};
|
| 31 |
+
|
| 32 |
+
reg [EA:0] wptr = A_ZERO;
|
| 33 |
+
reg [EA:0] wptr_d1 = A_ZERO;
|
| 34 |
+
reg [EA:0] wptr_d2 = A_ZERO;
|
| 35 |
+
reg [EA:0] rptr = A_ZERO;
|
| 36 |
+
wire [EA:0] rptr_next = (o_en & o_rdy) ? (rptr+A_ONE) : rptr;
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
assign i_rdy = ( wptr != {~rptr[EA], rptr[EA-1:0]} );
|
| 41 |
+
|
| 42 |
+
always @ (posedge clk or negedge rstn)
|
| 43 |
+
if (~rstn) begin
|
| 44 |
+
wptr <= A_ZERO;
|
| 45 |
+
wptr_d1 <= A_ZERO;
|
| 46 |
+
wptr_d2 <= A_ZERO;
|
| 47 |
+
end else begin
|
| 48 |
+
if (i_en & i_rdy)
|
| 49 |
+
wptr <= wptr + A_ONE;
|
| 50 |
+
wptr_d1 <= wptr;
|
| 51 |
+
wptr_d2 <= wptr_d1;
|
| 52 |
+
end
|
| 53 |
+
|
| 54 |
+
always @ (posedge clk)
|
| 55 |
+
if (i_en & i_rdy)
|
| 56 |
+
buffer[wptr[EA-1:0]] <= i_data;
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
always @ (posedge clk or negedge rstn)
|
| 61 |
+
if (~rstn) begin
|
| 62 |
+
rptr <= A_ZERO;
|
| 63 |
+
o_en <= 1'b0;
|
| 64 |
+
end else begin
|
| 65 |
+
rptr <= rptr_next;
|
| 66 |
+
o_en <= (rptr_next != wptr_d2);
|
| 67 |
+
end
|
| 68 |
+
|
| 69 |
+
always @ (posedge clk)
|
| 70 |
+
o_data <= buffer[rptr_next[EA-1:0]];
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/fpga_top.v
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module fpga_top (
|
| 3 |
+
|
| 4 |
+
input wire rstn_btn, // press button to reset, pressed=0, unpressed=1
|
| 5 |
+
input wire clk50m, // a 50MHz Crystal oscillator
|
| 6 |
+
|
| 7 |
+
// AD7276 ADC SPI interface
|
| 8 |
+
output wire ad7276_csn, // connect to AD7276's CSN (NFC_Breakboard's AD7276_CSN)
|
| 9 |
+
output wire ad7276_sclk, // connect to AD7276's SCLK (NFC_Breakboard's AD7276_SCLK)
|
| 10 |
+
input wire ad7276_sdata, // connect to AD7276's SDATA (NFC_Breakboard's AD7276_SDATA)
|
| 11 |
+
|
| 12 |
+
// NFC carrier generation signal
|
| 13 |
+
output wire carrier_out, // connect to FDV301N(N-MOSFET)'s gate (栅极) (NFC_Breakboard's CARRIER_OUT)
|
| 14 |
+
|
| 15 |
+
// connect to Host-PC (typically via a USB-to-UART chip on FPGA board, such as FT232, CP2102 or CH340)
|
| 16 |
+
input wire uart_rx, // connect to USB-to-UART chip's UART-TX
|
| 17 |
+
output wire uart_tx, // connect to USB-to-UART chip's UART-RX
|
| 18 |
+
|
| 19 |
+
// connect to on-board LED's (optional)
|
| 20 |
+
output wire led0, // led0=1 indicates PLL is normally run
|
| 21 |
+
output wire led1, // led1=1 indicates carrier is on
|
| 22 |
+
output wire led2 // led2=1 indicates PCD-to-PICC communication is done, and PCD is waiting for PICC-to-PCD
|
| 23 |
+
);
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
//-------------------------------------------------------------------------------------------------------------------------------------
|
| 27 |
+
// The NFC controller core needs a 81.36MHz clock, this PLL module is to convert clk50m to clk81m36
|
| 28 |
+
// This PLL module is only available on Altera Cyclone IV E.
|
| 29 |
+
// If you use other FPGA families, please use their compatible primitives or IP-cores to generate clk81m36
|
| 30 |
+
//-------------------------------------------------------------------------------------------------------------------------------------
|
| 31 |
+
wire [3:0] subwire0;
|
| 32 |
+
wire clk81m36;
|
| 33 |
+
wire clk_locked;
|
| 34 |
+
altpll pll_i ( .areset (~rstn_btn), .inclk ({1'b0,clk50m}), .clk ({subwire0,clk81m36}), .locked (clk_locked), .activeclock (), .clkbad (), .clkena ({6{1'b1}}), .clkloss (), .clkswitch (1'b0), .configupdate (1'b0), .enable0 (), .enable1 (), .extclk (), .extclkena ({4{1'b1}}), .fbin (1'b1), .fbmimicbidir (), .fbout (), .fref (), .icdrclk (), .pfdena (1'b1), .phasecounterselect ({4{1'b1}}), .phasedone (), .phasestep (1'b1), .phaseupdown (1'b1), .pllena (1'b1), .scanaclr (1'b0), .scanclk (1'b0), .scanclkena (1'b1), .scandata (1'b0), .scandataout (), .scandone (), .scanread (1'b0), .scanwrite (1'b0), .sclkout0 (), .sclkout1 (), .vcooverrange (), .vcounderrange ()); defparam pll_i.bandwidth_type = "AUTO", pll_i.clk0_divide_by = 625, pll_i.clk0_duty_cycle = 50, pll_i.clk0_multiply_by = 1017, pll_i.clk0_phase_shift = "0", pll_i.compensate_clock = "CLK0", pll_i.inclk0_input_frequency = 20000, pll_i.intended_device_family = "Cyclone IV E", pll_i.lpm_hint = "CBX_MODULE_PREFIX=pll", pll_i.lpm_type = "altpll", pll_i.operation_mode = "NORMAL", pll_i.pll_type = "AUTO", pll_i.port_activeclock = "PORT_UNUSED", pll_i.port_areset = "PORT_USED", pll_i.port_clkbad0 = "PORT_UNUSED", pll_i.port_clkbad1 = "PORT_UNUSED", pll_i.port_clkloss = "PORT_UNUSED", pll_i.port_clkswitch = "PORT_UNUSED", pll_i.port_configupdate = "PORT_UNUSED", pll_i.port_fbin = "PORT_UNUSED", pll_i.port_inclk0 = "PORT_USED", pll_i.port_inclk1 = "PORT_UNUSED", pll_i.port_locked = "PORT_USED", pll_i.port_pfdena = "PORT_UNUSED", pll_i.port_phasecounterselect = "PORT_UNUSED", pll_i.port_phasedone = "PORT_UNUSED", pll_i.port_phasestep = "PORT_UNUSED", pll_i.port_phaseupdown = "PORT_UNUSED", pll_i.port_pllena = "PORT_UNUSED", pll_i.port_scanaclr = "PORT_UNUSED", pll_i.port_scanclk = "PORT_UNUSED", pll_i.port_scanclkena = "PORT_UNUSED", pll_i.port_scandata = "PORT_UNUSED", pll_i.port_scandataout = "PORT_UNUSED", pll_i.port_scandone = "PORT_UNUSED", pll_i.port_scanread = "PORT_UNUSED", pll_i.port_scanwrite = "PORT_UNUSED", pll_i.port_clk0 = "PORT_USED", pll_i.port_clk1 = "PORT_UNUSED", pll_i.port_clk2 = "PORT_UNUSED", pll_i.port_clk3 = "PORT_UNUSED", pll_i.port_clk4 = "PORT_UNUSED", pll_i.port_clk5 = "PORT_UNUSED", pll_i.port_clkena0 = "PORT_UNUSED", pll_i.port_clkena1 = "PORT_UNUSED", pll_i.port_clkena2 = "PORT_UNUSED", pll_i.port_clkena3 = "PORT_UNUSED", pll_i.port_clkena4 = "PORT_UNUSED", pll_i.port_clkena5 = "PORT_UNUSED", pll_i.port_extclk0 = "PORT_UNUSED", pll_i.port_extclk1 = "PORT_UNUSED", pll_i.port_extclk2 = "PORT_UNUSED", pll_i.port_extclk3 = "PORT_UNUSED", pll_i.self_reset_on_loss_lock = "OFF", pll_i.width_clock = 5;
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
//-------------------------------------------------------------------------------------------------------------------------------------
|
| 38 |
+
// UART-to-NFCA system
|
| 39 |
+
//-------------------------------------------------------------------------------------------------------------------------------------
|
| 40 |
+
uart2nfca_system_top u_uart2nfca_system (
|
| 41 |
+
.rstn ( clk_locked ),
|
| 42 |
+
.clk ( clk81m36 ),
|
| 43 |
+
.ad7276_csn ( ad7276_csn ),
|
| 44 |
+
.ad7276_sclk ( ad7276_sclk ),
|
| 45 |
+
.ad7276_sdata ( ad7276_sdata ),
|
| 46 |
+
.carrier_out ( carrier_out ),
|
| 47 |
+
.uart_rx ( uart_rx ),
|
| 48 |
+
.uart_tx ( uart_tx ),
|
| 49 |
+
.rx_on ( led2 )
|
| 50 |
+
);
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
//-------------------------------------------------------------------------------------------------------------------------------------
|
| 54 |
+
// LEDs' assignment
|
| 55 |
+
//-------------------------------------------------------------------------------------------------------------------------------------
|
| 56 |
+
assign led0 = clk_locked;
|
| 57 |
+
assign led1 = carrier_out;
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_controller.v
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : nfca_controller
|
| 4 |
+
// Type : synthesizable, IP's top
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: NFC-A (ISO14443A) controller
|
| 7 |
+
//--------------------------------------------------------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
module nfca_controller (
|
| 10 |
+
input wire rstn, // 0:reset, 1:work
|
| 11 |
+
input wire clk, // require 81.36MHz, (81.36 = 13.56*6)
|
| 12 |
+
// TX byte stream interface for NFC PCD-to-PICC (axis sink liked)
|
| 13 |
+
input wire tx_tvalid,
|
| 14 |
+
output wire tx_tready,
|
| 15 |
+
input wire [7:0] tx_tdata,
|
| 16 |
+
input wire [3:0] tx_tdatab, // indicate how many bits are valid in the last byte. range=[1,8]. for the last byte of bit-oriented frame
|
| 17 |
+
input wire tx_tlast,
|
| 18 |
+
// RX status
|
| 19 |
+
output wire rx_on,
|
| 20 |
+
// RX byte stream interface for NFC PICC-to-PCD (axis source liked, without tready)
|
| 21 |
+
output wire rx_tvalid,
|
| 22 |
+
output wire [7:0] rx_tdata,
|
| 23 |
+
output wire [3:0] rx_tdatab,
|
| 24 |
+
output wire rx_tend,
|
| 25 |
+
output wire rx_terr,
|
| 26 |
+
// 12bit ADC data interface, the ADC is to sample the envelope detection signal of RFID RX. Required sample rate = 2.5425Msa/s = 81.36/32, that is, transmit 12bit on adc_data every 32 clk cycles.
|
| 27 |
+
input wire adc_data_en, // After starting to work, adc_data_en=1 pulse needs to be generated every 32 clk cycles, and adc_data_en=0 in the rest of the cycles. adc_data_en=1 means adc_data is valid.
|
| 28 |
+
input wire[11:0] adc_data, // adc_data should valid when adc_data_en=1
|
| 29 |
+
// RFID carrier output, connect to a NMOS transistor to drive the antenna coil
|
| 30 |
+
output wire carrier_out
|
| 31 |
+
);
|
| 32 |
+
|
| 33 |
+
wire [2:0] remainb;
|
| 34 |
+
|
| 35 |
+
wire tx_req;
|
| 36 |
+
wire tx_en;
|
| 37 |
+
wire tx_bit;
|
| 38 |
+
|
| 39 |
+
wire rx_ask_en;
|
| 40 |
+
wire rx_ask;
|
| 41 |
+
|
| 42 |
+
// RX bit parsed (105.9375 kbps base-band)
|
| 43 |
+
wire rx_bit_en; // when rx_bit_en=1 pulses, a received bit is valid on rx_bit
|
| 44 |
+
wire rx_bit; // exclude S (start of communication) and E (end of communication)
|
| 45 |
+
wire rx_end; // end of a communication pulse, because of detect E, or detect a bit collision, or detect an error.
|
| 46 |
+
wire rx_end_col; // indicate a bit collision, only valid when rx_end=1
|
| 47 |
+
wire rx_end_err; // indicate an unknown error, such a PICC (card) do not match ISO14443A, or noise, only valid when rx_end=1
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
nfca_tx_frame u_nfca_tx_frame (
|
| 51 |
+
.rstn ( rstn ),
|
| 52 |
+
.clk ( clk ),
|
| 53 |
+
.tx_tvalid ( tx_tvalid ),
|
| 54 |
+
.tx_tready ( tx_tready ),
|
| 55 |
+
.tx_tdata ( tx_tdata ),
|
| 56 |
+
.tx_tdatab ( tx_tdatab ),
|
| 57 |
+
.tx_tlast ( tx_tlast ),
|
| 58 |
+
.tx_req ( tx_req ),
|
| 59 |
+
.tx_en ( tx_en ),
|
| 60 |
+
.tx_bit ( tx_bit ),
|
| 61 |
+
.remainb ( remainb )
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
nfca_tx_modulate u_nfca_tx_modulate (
|
| 66 |
+
.rstn ( rstn ),
|
| 67 |
+
.clk ( clk ),
|
| 68 |
+
.tx_req ( tx_req ),
|
| 69 |
+
.tx_en ( tx_en ),
|
| 70 |
+
.tx_bit ( tx_bit ),
|
| 71 |
+
.carrier_out ( carrier_out ),
|
| 72 |
+
.rx_on ( rx_on )
|
| 73 |
+
);
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
nfca_rx_dsp u_nfca_rx_dsp (
|
| 77 |
+
.rstn ( rstn ),
|
| 78 |
+
.clk ( clk ),
|
| 79 |
+
.adc_data_en ( adc_data_en ),
|
| 80 |
+
.adc_data ( adc_data ),
|
| 81 |
+
.rx_ask_en ( rx_ask_en ),
|
| 82 |
+
.rx_ask ( rx_ask ),
|
| 83 |
+
.rx_lpf_data ( ),
|
| 84 |
+
.rx_raw_data ( )
|
| 85 |
+
);
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
nfca_rx_tobits u_nfca_rx_tobits (
|
| 89 |
+
.rstn ( rstn ),
|
| 90 |
+
.clk ( clk ),
|
| 91 |
+
.rx_on ( rx_on ),
|
| 92 |
+
.rx_ask_en ( rx_ask_en ),
|
| 93 |
+
.rx_ask ( rx_ask ),
|
| 94 |
+
.rx_bit_en ( rx_bit_en ),
|
| 95 |
+
.rx_bit ( rx_bit ),
|
| 96 |
+
.rx_end ( rx_end ),
|
| 97 |
+
.rx_end_col ( rx_end_col ),
|
| 98 |
+
.rx_end_err ( rx_end_err )
|
| 99 |
+
);
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
nfca_rx_tobytes u_nfca_rx_tobytes (
|
| 103 |
+
.rstn ( rstn ),
|
| 104 |
+
.clk ( clk ),
|
| 105 |
+
.rx_on ( rx_on ),
|
| 106 |
+
.remainb ( remainb ),
|
| 107 |
+
.rx_bit_en ( rx_bit_en ),
|
| 108 |
+
.rx_bit ( rx_bit ),
|
| 109 |
+
.rx_end ( rx_end ),
|
| 110 |
+
.rx_end_col ( rx_end_col ),
|
| 111 |
+
.rx_end_err ( rx_end_err ),
|
| 112 |
+
.rx_tvalid ( rx_tvalid ),
|
| 113 |
+
.rx_tdata ( rx_tdata ),
|
| 114 |
+
.rx_tdatab ( rx_tdatab ),
|
| 115 |
+
.rx_tend ( rx_tend ),
|
| 116 |
+
.rx_terr ( rx_terr )
|
| 117 |
+
);
|
| 118 |
+
|
| 119 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_rx_dsp.v
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : nfca_rx_dsp
|
| 4 |
+
// Type : synthesizable, IP's sub module
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: called by nfca_controller
|
| 7 |
+
//--------------------------------------------------------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
module nfca_rx_dsp (
|
| 10 |
+
input wire rstn, // 0:reset, 1:work
|
| 11 |
+
input wire clk, // require 81.36MHz
|
| 12 |
+
// 12bit ADC data input (2.5425 Msa/s)
|
| 13 |
+
input wire adc_data_en,
|
| 14 |
+
input wire[11:0] adc_data,
|
| 15 |
+
// RX DSP result (2.5425 Mbps)
|
| 16 |
+
output reg rx_ask_en, // rx_ask_en=1 will pulses every 32 clk cycles. When rx_ask_en=1, rx_ask, rx_lpf_data and rx_raw_data is valid.
|
| 17 |
+
output reg rx_ask, // ASK demodulated signal. 1 means detected rx_raw_data is significantly less than rx_lpf_data, that is, the PICC (TAG) is sending a ASK signal.
|
| 18 |
+
output reg [11:0] rx_lpf_data, // low-frequency baseline, only for debug
|
| 19 |
+
output reg [11:0] rx_raw_data // rx_raw_data, which is to compare with rx_lpf_data, only for debug
|
| 20 |
+
);
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
initial {rx_ask_en, rx_ask, rx_lpf_data, rx_raw_data} = 0;
|
| 24 |
+
|
| 25 |
+
localparam N = 21;
|
| 26 |
+
localparam [5:0] SORT_CYCLES = 6'd24;
|
| 27 |
+
|
| 28 |
+
reg [ 5:0] ccnt = 0;
|
| 29 |
+
reg [ 5:0] acnt = 0;
|
| 30 |
+
reg [11:0] array [0:(N-1)];
|
| 31 |
+
reg [11:0] sorted [0:(N-1)];
|
| 32 |
+
|
| 33 |
+
wire [11:0] lpf = sorted[12]; // sorted 是 排序后的过去21个样点,lpf 取其中第12个(中间偏大一点的一个),可以将 lpf 看作中值滤波的结果。
|
| 34 |
+
wire [11:0] raw = array [10]; // array 是 未排序的过去21个样点,raw 取其中第10个(最中间那个),即 raw 是观察窗内最中心的数据。
|
| 35 |
+
|
| 36 |
+
integer ii;
|
| 37 |
+
|
| 38 |
+
// ASK 解调的 DSP 算法的思路: 用中值滤波获取 ADC 数据的基线(baseline), ADC 数据小于 baseline 一定的值,认为检测到 ASK 调制的 '1'
|
| 39 |
+
// 中值滤波: 用 array 存储过去 21 个 ADC 样点,每获取一个新样点,就用把 array 赋值给 sorted,并用排序网络(冒泡排序)花费 22 个周期对 sorted 排序。最终得到的 sorted 的中间数就是中值滤波结果。
|
| 40 |
+
always @ (posedge clk or negedge rstn)
|
| 41 |
+
if(~rstn) begin
|
| 42 |
+
rx_ask_en <= 1'b0;
|
| 43 |
+
{rx_ask, rx_lpf_data, rx_raw_data} <= 0;
|
| 44 |
+
ccnt <= 0;
|
| 45 |
+
acnt <= 0;
|
| 46 |
+
for (ii=0; ii<N; ii=ii+1) begin
|
| 47 |
+
array[ii] <= 0;
|
| 48 |
+
sorted[ii] <= 0;
|
| 49 |
+
end
|
| 50 |
+
end else begin
|
| 51 |
+
rx_ask_en <= 1'b0;
|
| 52 |
+
if(adc_data_en) begin
|
| 53 |
+
ccnt <= 0;
|
| 54 |
+
array[0] <= adc_data;
|
| 55 |
+
for(ii=0; ii<N-1; ii=ii+1) array[ii+1] <= array[ii];
|
| 56 |
+
end else if(ccnt <= 6'd0) begin
|
| 57 |
+
ccnt <= ccnt + 6'd1;
|
| 58 |
+
for(ii=0; ii<N; ii=ii+1) sorted[ii] <= array[ii];
|
| 59 |
+
end else if(ccnt <= SORT_CYCLES) begin // 花费 SORT_CYCLES 周期运行冒泡排序网络(实际上考虑到 array len=N,只要 N+1 个周期就够,更多无害)
|
| 60 |
+
ccnt <= ccnt + 6'd1;
|
| 61 |
+
if(ccnt[0]) begin
|
| 62 |
+
for(ii=0; ii<N-1; ii=ii+2) begin // 排序网络在 ccnt=奇数 时的行为: 0和1尝试交换,2和3尝试交换,4和5尝试交换,……以此类推
|
| 63 |
+
if( sorted[ii] > sorted[ii+1] ) begin
|
| 64 |
+
sorted[ii] <= sorted[ii+1];
|
| 65 |
+
sorted[ii+1] <= sorted[ii];
|
| 66 |
+
end
|
| 67 |
+
end
|
| 68 |
+
end else begin
|
| 69 |
+
for(ii=1; ii<N ; ii=ii+2) begin // 排序网络在 ccnt=偶数 时的行为: 1和2尝试交换,3和4尝试交换,5和6尝试交换,……以此类推
|
| 70 |
+
if( sorted[ii] > sorted[ii+1] ) begin
|
| 71 |
+
sorted[ii] <= sorted[ii+1];
|
| 72 |
+
sorted[ii+1] <= sorted[ii];
|
| 73 |
+
end
|
| 74 |
+
end
|
| 75 |
+
end
|
| 76 |
+
end else if(ccnt == SORT_CYCLES + 6'd1) begin
|
| 77 |
+
ccnt <= ccnt + 6'd1;
|
| 78 |
+
if(acnt[5]) begin
|
| 79 |
+
rx_ask_en <= 1'b1;
|
| 80 |
+
rx_ask <= ( lpf - {7'h0,lpf[11:7]} - {8'h0,lpf[11:8]} > raw ); // 若 raw < 0.988*lpf , 认为 PICC 在发送 ASK 。
|
| 81 |
+
rx_lpf_data <= lpf;
|
| 82 |
+
rx_raw_data <= raw;
|
| 83 |
+
end else
|
| 84 |
+
acnt <= acnt + 6'd1;
|
| 85 |
+
end
|
| 86 |
+
end
|
| 87 |
+
|
| 88 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_rx_tobits.v
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : nfca_rx_tobits
|
| 4 |
+
// Type : synthesizable, IP's sub module
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: called by nfca_controller
|
| 7 |
+
//--------------------------------------------------------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
module nfca_rx_tobits (
|
| 10 |
+
input wire rstn, // 0:reset, 1:work
|
| 11 |
+
input wire clk, // require 81.36MHz
|
| 12 |
+
// RX on/off control
|
| 13 |
+
input wire rx_on, // 0:off, 1:on
|
| 14 |
+
// RX DSP result input (2.5425 Mbps)
|
| 15 |
+
input wire rx_ask_en,
|
| 16 |
+
input wire rx_ask,
|
| 17 |
+
// RX bit parsed (105.9375 kbps base-band)
|
| 18 |
+
output reg rx_bit_en, // when rx_bit_en=1 pulses, a received bit is valid on rx_bit
|
| 19 |
+
output reg rx_bit, // exclude S (start of communication) and E (end of communication)
|
| 20 |
+
output reg rx_end, // end of a communication pulse, because of detect E, or detect a bit collision, or detect an error.
|
| 21 |
+
output reg rx_end_col, // indicate a bit collision, only valid when rx_end=1
|
| 22 |
+
output reg rx_end_err // indicate an unknown error, such a PICC (card) do not match ISO14443A, or noise, or PICC's frame is too long. Only valid when rx_end=1
|
| 23 |
+
);
|
| 24 |
+
|
| 25 |
+
initial {rx_bit_en, rx_bit, rx_end, rx_end_err, rx_end_col} = 0;
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
reg [ 3:0] detect_zeros = 0;
|
| 29 |
+
reg [ 3:0] detect_ones = 0;
|
| 30 |
+
reg [11:0] shift0 = 0;
|
| 31 |
+
reg [11:0] shift1 = 0;
|
| 32 |
+
reg [11:0] shift2 = 0;
|
| 33 |
+
reg [11:0] shift3 = 0;
|
| 34 |
+
reg [ 4:0] cnt = 0;
|
| 35 |
+
|
| 36 |
+
localparam [1:0] IDLE = 2'd0,
|
| 37 |
+
PARSE = 2'd1,
|
| 38 |
+
STOP = 2'd2;
|
| 39 |
+
|
| 40 |
+
reg [1:0] status = IDLE;
|
| 41 |
+
|
| 42 |
+
reg [3:0] sum [0:3]; // not real register
|
| 43 |
+
|
| 44 |
+
integer ii, jj; // not real register, just loop variable
|
| 45 |
+
|
| 46 |
+
always @ (posedge clk or negedge rstn)
|
| 47 |
+
if(~rstn) begin
|
| 48 |
+
detect_zeros <= 0;
|
| 49 |
+
detect_ones <= 0;
|
| 50 |
+
{shift3, shift2, shift1, shift0} <= 0;
|
| 51 |
+
end else begin
|
| 52 |
+
if(~rx_on) begin
|
| 53 |
+
detect_zeros <= 0;
|
| 54 |
+
detect_ones <= 0;
|
| 55 |
+
{shift3, shift2, shift1, shift0} <= 0;
|
| 56 |
+
end else if(rx_ask_en) begin
|
| 57 |
+
for(ii=0; ii<4; ii=ii+1) sum[ii] = 0;
|
| 58 |
+
for(ii=0; ii<12; ii=ii+1) begin
|
| 59 |
+
sum[0] = sum[0] + {3'h0, shift0[ii]};
|
| 60 |
+
sum[1] = sum[1] + {3'h0, shift1[ii]};
|
| 61 |
+
sum[2] = sum[2] + {3'h0, shift2[ii]};
|
| 62 |
+
sum[3] = sum[3] + {3'h0, shift3[ii]};
|
| 63 |
+
end
|
| 64 |
+
for(jj=0; jj<4; jj=jj+1) begin
|
| 65 |
+
detect_ones[jj] <= sum[jj] >= 4'd3;
|
| 66 |
+
detect_zeros[jj] <= sum[jj] <= 4'd1;
|
| 67 |
+
end
|
| 68 |
+
{shift3, shift2, shift1, shift0} <= {shift3[10:0], shift2, shift1, shift0, rx_ask};
|
| 69 |
+
end
|
| 70 |
+
end
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
always @ (posedge clk or negedge rstn)
|
| 74 |
+
if(~rstn) begin
|
| 75 |
+
{rx_bit_en, rx_bit, rx_end, rx_end_err, rx_end_col} <= 0;
|
| 76 |
+
cnt <= 0;
|
| 77 |
+
status <= IDLE;
|
| 78 |
+
end else begin
|
| 79 |
+
{rx_bit_en, rx_bit, rx_end, rx_end_err, rx_end_col} <= 0;
|
| 80 |
+
if(~rx_on) begin
|
| 81 |
+
cnt <= 0;
|
| 82 |
+
status <= IDLE;
|
| 83 |
+
end else if(rx_ask_en) begin
|
| 84 |
+
if(status == IDLE) begin
|
| 85 |
+
cnt <= 0;
|
| 86 |
+
if(detect_ones == 4'b0010 && detect_zeros == 4'b1101)
|
| 87 |
+
status <= PARSE;
|
| 88 |
+
end else if(status == PARSE) begin
|
| 89 |
+
if(cnt < 5'd23) begin
|
| 90 |
+
cnt <= cnt + 5'd1;
|
| 91 |
+
end else begin
|
| 92 |
+
cnt <= 0;
|
| 93 |
+
if(~(&(detect_ones^detect_zeros))) begin // noise
|
| 94 |
+
{rx_end, rx_end_err} <= 2'b11;
|
| 95 |
+
status <= STOP;
|
| 96 |
+
end else if(detect_ones[1:0] == 2'b00) begin // end of communication
|
| 97 |
+
rx_end <= 1'b1;
|
| 98 |
+
status <= STOP;
|
| 99 |
+
end else if(detect_ones[1:0] == 2'b11) begin // collision
|
| 100 |
+
{rx_end, rx_end_col} <= 2'b11;
|
| 101 |
+
status <= STOP;
|
| 102 |
+
end else if(detect_ones[1:0] == 2'b10) begin // logic '1'
|
| 103 |
+
{rx_bit_en, rx_bit} <= 2'b11;
|
| 104 |
+
end else if(detect_ones[1:0] == 2'b01) begin // logic '0'
|
| 105 |
+
rx_bit_en <= 1'b1;
|
| 106 |
+
end else begin // undefined error
|
| 107 |
+
{rx_end, rx_end_err} <= 2'b11;
|
| 108 |
+
status <= STOP;
|
| 109 |
+
end
|
| 110 |
+
end
|
| 111 |
+
end
|
| 112 |
+
end
|
| 113 |
+
end
|
| 114 |
+
|
| 115 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_rx_tobytes.v
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : nfca_rx_tobytes
|
| 4 |
+
// Type : synthesizable, IP's sub module
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: called by nfca_controller
|
| 7 |
+
//--------------------------------------------------------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
module nfca_rx_tobytes (
|
| 10 |
+
input wire rstn, // 0:reset, 1:work
|
| 11 |
+
input wire clk, // require 81.36MHz
|
| 12 |
+
// RX on/off control
|
| 13 |
+
input wire rx_on, // 0:off, 1:on
|
| 14 |
+
// indicate how many bits remain for an incomplete byte for PICC to send
|
| 15 |
+
input wire [2:0] remainb,
|
| 16 |
+
// RX bit parsed (105.9375 kbps base-band)
|
| 17 |
+
input wire rx_bit_en, // when rx_bit_en=1 pulses, a received bit is valid on rx_bit
|
| 18 |
+
input wire rx_bit, // exclude S (start of communication) and E (end of communication)
|
| 19 |
+
input wire rx_end, // end of a communication pulse, because of detect E, or detect a bit collision, or detect an error.
|
| 20 |
+
input wire rx_end_col, // indicate a bit collision, only valid when rx_end=1
|
| 21 |
+
input wire rx_end_err, // indicate an unknown error, such a PICC (card) do not match ISO14443A, or noise, or PICC's frame is too long. Only valid when rx_end=1
|
| 22 |
+
// RX byte parsed
|
| 23 |
+
output reg rx_tvalid,
|
| 24 |
+
output reg [7:0] rx_tdata,
|
| 25 |
+
output reg [3:0] rx_tdatab,
|
| 26 |
+
output reg rx_tend,
|
| 27 |
+
output reg rx_terr
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
initial {rx_tvalid, rx_tdata, rx_tend, rx_tdatab, rx_terr} = 0;
|
| 31 |
+
|
| 32 |
+
reg [3:0] cnt = 0;
|
| 33 |
+
reg [7:0] byte_saved = 0;
|
| 34 |
+
|
| 35 |
+
localparam [2:0] IDLE = 3'd0,
|
| 36 |
+
START = 3'd1,
|
| 37 |
+
PARSE = 3'd2,
|
| 38 |
+
CSTOP = 3'd3,
|
| 39 |
+
STOP = 3'd4;
|
| 40 |
+
reg [2:0] status = IDLE;
|
| 41 |
+
|
| 42 |
+
wire error_parity = (status==PARSE) & ~(^{rx_bit,byte_saved});
|
| 43 |
+
|
| 44 |
+
always @ (posedge clk or negedge rstn)
|
| 45 |
+
if(~rstn) begin
|
| 46 |
+
{rx_tvalid, rx_tdata, rx_tdatab, rx_tend, rx_terr} <= 0;
|
| 47 |
+
cnt <= 0;
|
| 48 |
+
byte_saved <= 0;
|
| 49 |
+
status <= IDLE;
|
| 50 |
+
end else begin
|
| 51 |
+
{rx_tvalid, rx_tdata, rx_tdatab, rx_tend, rx_terr} <= 0;
|
| 52 |
+
if(status == CSTOP) begin
|
| 53 |
+
{rx_tvalid, rx_tdata, rx_tdatab, rx_tend, rx_terr} <= {1'b1, 8'h00, 4'd0, 1'b1, 1'b0}; // end with collision (step2)
|
| 54 |
+
status <= STOP;
|
| 55 |
+
end else if(~rx_on) begin
|
| 56 |
+
cnt <= {1'b0, remainb};
|
| 57 |
+
byte_saved <= 0;
|
| 58 |
+
status <= IDLE;
|
| 59 |
+
if(status == START || status == PARSE)
|
| 60 |
+
{rx_tvalid, rx_tdata, rx_tdatab, rx_tend, rx_terr} <= {1'b1, byte_saved, cnt, 1'b1, 1'b1};
|
| 61 |
+
end else if(status == IDLE) begin
|
| 62 |
+
status <= START;
|
| 63 |
+
end else if(status != STOP) begin
|
| 64 |
+
if(rx_bit_en) begin
|
| 65 |
+
if(cnt < 4'd8) begin
|
| 66 |
+
cnt <= cnt + 4'd1;
|
| 67 |
+
byte_saved[cnt] <= rx_bit;
|
| 68 |
+
end else begin
|
| 69 |
+
{rx_tvalid, rx_tdata, rx_tdatab, rx_tend, rx_terr} <= {1'b1, byte_saved,4'd8, error_parity, error_parity};
|
| 70 |
+
cnt <= 0;
|
| 71 |
+
byte_saved <= 0;
|
| 72 |
+
status <= error_parity ? STOP : PARSE;
|
| 73 |
+
end
|
| 74 |
+
end else if(rx_end) begin
|
| 75 |
+
status <= rx_end_col ? CSTOP : STOP;
|
| 76 |
+
if(rx_end_col)
|
| 77 |
+
{rx_tvalid, rx_tdata, rx_tdatab, rx_tend, rx_terr} <= {1'b1, byte_saved, cnt, 1'b0, 1'b0}; // end with collision
|
| 78 |
+
else if(rx_end_err | (|cnt) )
|
| 79 |
+
{rx_tvalid, rx_tdata, rx_tdatab, rx_tend, rx_terr} <= {1'b1, byte_saved, cnt, 1'b1, 1'b1}; // end with error
|
| 80 |
+
else
|
| 81 |
+
{rx_tvalid, rx_tdata, rx_tdatab, rx_tend, rx_terr} <= {1'b1, 8'h00,4'd0, 1'b1, 1'b0}; // end normally
|
| 82 |
+
end
|
| 83 |
+
end
|
| 84 |
+
end
|
| 85 |
+
|
| 86 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_tx_frame.v
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : nfca_tx_frame
|
| 4 |
+
// Type : synthesizable, IP's sub module
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: called by nfca_controller
|
| 7 |
+
//--------------------------------------------------------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
module nfca_tx_frame (
|
| 10 |
+
input wire rstn, // 0:reset, 1:work
|
| 11 |
+
input wire clk, // require 81.36MHz
|
| 12 |
+
// TX byte stream interface (axis sink liked)
|
| 13 |
+
input wire tx_tvalid,
|
| 14 |
+
output reg tx_tready,
|
| 15 |
+
input wire [7:0] tx_tdata,
|
| 16 |
+
input wire [3:0] tx_tdatab, // indicate how many bits are valid in the last byte. range=[1,8]. for the last byte of bit-oriented frame
|
| 17 |
+
input wire tx_tlast,
|
| 18 |
+
// tx bit modulate interface
|
| 19 |
+
input wire tx_req,
|
| 20 |
+
output reg tx_en,
|
| 21 |
+
output reg tx_bit,
|
| 22 |
+
// indicate how many bits remain for an incomplete byte for PICC to send, for nfca_rx_tobytes to reconstruct the bytes
|
| 23 |
+
output reg [2:0] remainb
|
| 24 |
+
);
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
function [15:0] CRC16;
|
| 28 |
+
input [15:0] crc;
|
| 29 |
+
input [ 7:0] inbyte;
|
| 30 |
+
//function automatic logic [15:0] CRC16(input logic [15:0] crc, input logic [7:0] inbyte);
|
| 31 |
+
reg [ 7:0] tmp;
|
| 32 |
+
begin
|
| 33 |
+
tmp = inbyte ^ crc[7:0];
|
| 34 |
+
tmp = tmp ^ {tmp[3:0], 4'h0};
|
| 35 |
+
CRC16 = ( {8'h0, crc[15:8]} ^ {tmp, 8'h0} ^ {5'h0, tmp, 3'h0} ^ {12'h0, tmp[7:4]} );
|
| 36 |
+
end
|
| 37 |
+
endfunction
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
initial tx_tready = 1'b0;
|
| 41 |
+
initial {tx_en, tx_bit} = 0;
|
| 42 |
+
initial remainb = 0;
|
| 43 |
+
|
| 44 |
+
reg [ 7:0] buffer [0:4095]; // will synthesis to BRAM
|
| 45 |
+
reg [ 7:0] rdata = 0;
|
| 46 |
+
reg [11:0] wptr = 0;
|
| 47 |
+
reg [11:0] rptr = 0;
|
| 48 |
+
reg [ 3:0] lastb = 0;
|
| 49 |
+
reg [17:0] txshift = 0;
|
| 50 |
+
reg [ 4:0] txcount = 0;
|
| 51 |
+
reg end_of = 1'b0;
|
| 52 |
+
reg has_crc = 1'b0;
|
| 53 |
+
reg [15:0] crc = 16'h6363;
|
| 54 |
+
reg incomplete = 1'b0;
|
| 55 |
+
|
| 56 |
+
wire short_frame = (rdata == 8'h26 || rdata == 8'h52 || rdata == 8'h35 || rdata[7:4] == 4'h4 || rdata[7:3] == 5'h0F);
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
always @ (posedge clk)
|
| 60 |
+
rdata <= buffer[rptr];
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
always @ (posedge clk)
|
| 64 |
+
if(tx_tready & tx_tvalid)
|
| 65 |
+
buffer[wptr] <= tx_tdata;
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
always @ (posedge clk or negedge rstn)
|
| 69 |
+
if(~rstn) begin
|
| 70 |
+
tx_tready <= 0;
|
| 71 |
+
{tx_bit, tx_en} <= 0;
|
| 72 |
+
{wptr, rptr} <= 0;
|
| 73 |
+
lastb <= 0;
|
| 74 |
+
txshift <= 0;
|
| 75 |
+
txcount <= 0;
|
| 76 |
+
end_of <= 1'b0;
|
| 77 |
+
has_crc <= 1'b0;
|
| 78 |
+
crc <= 16'h6363;
|
| 79 |
+
incomplete <= 1'b0;
|
| 80 |
+
remainb <= 0;
|
| 81 |
+
end else begin
|
| 82 |
+
if(tx_tready) begin
|
| 83 |
+
if(tx_tvalid) begin
|
| 84 |
+
crc <= CRC16(crc, tx_tdata);
|
| 85 |
+
if (wptr != 12'hFFF) wptr <= wptr + 12'd1;
|
| 86 |
+
lastb <= tx_tdatab==4'd0 ? 4'd1 : tx_tdatab>4'd8 ? 4'd8 : tx_tdatab;
|
| 87 |
+
if(tx_tlast) begin // end of a frame input
|
| 88 |
+
if (wptr != 12'hFFF) begin // not overflow
|
| 89 |
+
txshift <= 0; //
|
| 90 |
+
txcount <= 5'd1; // send the S bit (start of communication)
|
| 91 |
+
tx_tready <= 1'b0; // start to send a frame
|
| 92 |
+
end else begin // overflow!
|
| 93 |
+
wptr <= 0; // reset wptr
|
| 94 |
+
crc <= 16'h6363; // reset CRC
|
| 95 |
+
end
|
| 96 |
+
end
|
| 97 |
+
end
|
| 98 |
+
end else if(txcount != 0) begin
|
| 99 |
+
if(tx_req) begin
|
| 100 |
+
{txshift, tx_bit, tx_en} <= {1'b0, txshift, 1'b1};
|
| 101 |
+
txcount <= txcount - 5'd1;
|
| 102 |
+
end
|
| 103 |
+
end else if(rptr == wptr) begin
|
| 104 |
+
if(has_crc) begin
|
| 105 |
+
txshift <= {~(^crc[15:8]), crc[15:8], ~(^crc[7:0]), crc[7:0]}; // append CRC (16bit + 2bit parity)
|
| 106 |
+
txcount <= 5'd18;
|
| 107 |
+
end else if(end_of) begin
|
| 108 |
+
txshift <= 0;
|
| 109 |
+
txcount <= 5'd1; // send the E bit (end of communication)
|
| 110 |
+
end_of <= 1'b0;
|
| 111 |
+
remainb <= incomplete ? lastb[2:0] : 3'd0;
|
| 112 |
+
end else if(tx_req) begin
|
| 113 |
+
tx_tready <= 1'b1;
|
| 114 |
+
{tx_bit, tx_en} <= 0;
|
| 115 |
+
{wptr, rptr} <= 0;
|
| 116 |
+
end
|
| 117 |
+
has_crc <= 1'b0;
|
| 118 |
+
crc <= 16'h6363;
|
| 119 |
+
end else begin
|
| 120 |
+
incomplete <= 1'b0;
|
| 121 |
+
end_of <= 1'b1;
|
| 122 |
+
rptr <= rptr + 12'd1;
|
| 123 |
+
txshift <= {9'd0, ~(^rdata), rdata};
|
| 124 |
+
if (rptr == 12'h0) begin // the 1st byte
|
| 125 |
+
has_crc <= ~(rdata == 8'h93 || rdata == 8'h95 || rdata == 8'h97 || short_frame);
|
| 126 |
+
txcount <= short_frame ? 4'd7 : 4'd9;
|
| 127 |
+
end else if(rptr == 12'h1) begin // the 2nd byte
|
| 128 |
+
has_crc <= has_crc | (rdata == 8'h70);
|
| 129 |
+
txcount <= 4'd9;
|
| 130 |
+
end else if(rptr+12'd1 < wptr) begin // inner bytes
|
| 131 |
+
txcount <= 4'd9;
|
| 132 |
+
end else if(lastb < 4'd8) begin // last byte (incomplete)
|
| 133 |
+
incomplete <= 1'b1;
|
| 134 |
+
has_crc <= 1'b0;
|
| 135 |
+
txcount <= {1'h0,lastb};
|
| 136 |
+
end else begin // last byte (complete)
|
| 137 |
+
txcount <= 5'd9;
|
| 138 |
+
end
|
| 139 |
+
end
|
| 140 |
+
end
|
| 141 |
+
|
| 142 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/nfca_controller/nfca_tx_modulate.v
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : nfca_tx_modulate
|
| 4 |
+
// Type : synthesizable, IP's sub module
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: called by nfca_controller
|
| 7 |
+
//--------------------------------------------------------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
module nfca_tx_modulate (
|
| 10 |
+
input wire rstn, // 0:reset, 1:work
|
| 11 |
+
input wire clk, // require 81.36MHz
|
| 12 |
+
// tx bit modulate interface
|
| 13 |
+
output reg tx_req,
|
| 14 |
+
input wire tx_en,
|
| 15 |
+
input wire tx_bit,
|
| 16 |
+
// RFID carrier output, connect to a NMOS transistor to drive the antenna coil
|
| 17 |
+
output reg carrier_out,
|
| 18 |
+
// 1:in RX window, 0:out of RX window
|
| 19 |
+
output reg rx_on
|
| 20 |
+
);
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
localparam CARRIER_SETUP = 2048;
|
| 24 |
+
localparam CARRIER_HOLD = 131072;
|
| 25 |
+
|
| 26 |
+
initial tx_req = 1'b0;
|
| 27 |
+
initial carrier_out = 1'b0;
|
| 28 |
+
initial rx_on = 1'b0;
|
| 29 |
+
|
| 30 |
+
reg [ 1:0] clkcnt = 2'd0;
|
| 31 |
+
reg [ 7:0] ccnt = 8'd0;
|
| 32 |
+
reg [31:0] wcnt = 32'hFFFFFFFF;
|
| 33 |
+
reg [ 1:0] bdata = 2'd0; // {1 bits for future, 1 bit for current, 1 bit for past}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
always @ (posedge clk or negedge rstn)
|
| 37 |
+
if(~rstn) begin
|
| 38 |
+
clkcnt <= 2'd0;
|
| 39 |
+
ccnt <= 8'd0;
|
| 40 |
+
end else begin
|
| 41 |
+
if(clkcnt >= 2'd2) begin
|
| 42 |
+
clkcnt <= 2'd0;
|
| 43 |
+
ccnt <= ccnt + 8'h01;
|
| 44 |
+
end else begin
|
| 45 |
+
clkcnt <= clkcnt + 2'd1;
|
| 46 |
+
end
|
| 47 |
+
end
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
always @ (posedge clk or negedge rstn)
|
| 51 |
+
if(~rstn)
|
| 52 |
+
tx_req <= 1'b0;
|
| 53 |
+
else
|
| 54 |
+
tx_req <= clkcnt == 2'h0 && ccnt == 8'hff && (wcnt == CARRIER_SETUP || wcnt >= CARRIER_SETUP*2 && wcnt <= CARRIER_SETUP*2 + CARRIER_HOLD || wcnt > CARRIER_SETUP*2 + CARRIER_HOLD + 16);
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
always @ (posedge clk or negedge rstn)
|
| 58 |
+
if(~rstn) begin
|
| 59 |
+
wcnt <= 32'hFFFFFFFF;
|
| 60 |
+
bdata <= 2'd0;
|
| 61 |
+
end else begin
|
| 62 |
+
if(clkcnt >= 2'd2 && ccnt == 8'hff) begin
|
| 63 |
+
if (wcnt < CARRIER_SETUP) begin
|
| 64 |
+
wcnt <= wcnt + 1;
|
| 65 |
+
end else if(wcnt == CARRIER_SETUP) begin
|
| 66 |
+
if(tx_en) begin
|
| 67 |
+
bdata <= {tx_bit, bdata[1]};
|
| 68 |
+
//$write("%d", tx_bit); // only for simulation
|
| 69 |
+
end else begin
|
| 70 |
+
wcnt <= wcnt + 1;
|
| 71 |
+
//$write("\n"); // only for simulation
|
| 72 |
+
end
|
| 73 |
+
end else if(wcnt < CARRIER_SETUP*2) begin
|
| 74 |
+
wcnt <= wcnt + 1;
|
| 75 |
+
end else if(wcnt <= CARRIER_SETUP*2 + CARRIER_HOLD) begin
|
| 76 |
+
if(tx_en) begin
|
| 77 |
+
wcnt <= CARRIER_SETUP;
|
| 78 |
+
bdata <= {tx_bit, 1'b0};
|
| 79 |
+
//$write("%d", tx_bit); // only for simulation
|
| 80 |
+
end else
|
| 81 |
+
wcnt <= wcnt + 1;
|
| 82 |
+
end else if(wcnt <= CARRIER_SETUP*2 + CARRIER_HOLD + 16) begin
|
| 83 |
+
wcnt <= wcnt + 1;
|
| 84 |
+
end else if(tx_en) begin
|
| 85 |
+
wcnt <= 0;
|
| 86 |
+
bdata <= {tx_bit, 1'b0};
|
| 87 |
+
//$write("%d", tx_bit); // only for simulation
|
| 88 |
+
end
|
| 89 |
+
end
|
| 90 |
+
end
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
always @ (posedge clk or negedge rstn)
|
| 94 |
+
if(~rstn) begin
|
| 95 |
+
carrier_out <= 1'b0;
|
| 96 |
+
end else begin
|
| 97 |
+
if(wcnt == CARRIER_SETUP && ~ccnt[6]) begin
|
| 98 |
+
if(ccnt[7])
|
| 99 |
+
carrier_out <= ~ccnt[0] && bdata[1] == 1'b0;
|
| 100 |
+
else
|
| 101 |
+
carrier_out <= ~ccnt[0] && bdata[1:0] != 2'b00;
|
| 102 |
+
end else if(wcnt <= CARRIER_SETUP*2 + CARRIER_HOLD) begin
|
| 103 |
+
carrier_out <= ~ccnt[0];
|
| 104 |
+
end else begin
|
| 105 |
+
carrier_out <= 1'b0;
|
| 106 |
+
end
|
| 107 |
+
end
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
always @ (posedge clk or negedge rstn)
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module uart2nfca_system_top (
|
| 3 |
+
input wire rstn, // 0:reset, 1:work
|
| 4 |
+
input wire clk, // require 81.36MHz, (81.36 = 13.56*6)
|
| 5 |
+
// connect to AD7276, which is a 12bit 3Msps ADC to sample the envelope detection result of RFID RX. Actually work at 2.5456 Msa/s in this system
|
| 6 |
+
output wire ad7276_csn,
|
| 7 |
+
output wire ad7276_sclk,
|
| 8 |
+
input wire ad7276_sdata,
|
| 9 |
+
// RFID carrier output, connect to a NMOS transistor to drive the antenna coil
|
| 10 |
+
output wire carrier_out,
|
| 11 |
+
// UART interface, typically connect to host-PC or MCU, and run NFC user applications on host-PC or MCU.
|
| 12 |
+
input wire uart_rx,
|
| 13 |
+
output wire uart_tx,
|
| 14 |
+
// for debug external trigger (optional)
|
| 15 |
+
output wire rx_on
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
wire adc_data_en;
|
| 19 |
+
wire[11:0] adc_data;
|
| 20 |
+
|
| 21 |
+
wire uart_rx_byte_en;
|
| 22 |
+
wire [7:0] uart_rx_byte;
|
| 23 |
+
|
| 24 |
+
wire tvalid;
|
| 25 |
+
wire [7:0] tdata;
|
| 26 |
+
wire [3:0] tdatab;
|
| 27 |
+
wire tlast;
|
| 28 |
+
|
| 29 |
+
wire tx_tvalid;
|
| 30 |
+
wire tx_tready;
|
| 31 |
+
wire [7:0] tx_tdata;
|
| 32 |
+
wire [3:0] tx_tdatab;
|
| 33 |
+
wire tx_tlast;
|
| 34 |
+
|
| 35 |
+
wire rx_tvalid;
|
| 36 |
+
wire [7:0] rx_tdata;
|
| 37 |
+
wire [3:0] rx_tdatab;
|
| 38 |
+
wire rx_tend;
|
| 39 |
+
wire rx_terr;
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
ad7276_read u_ad7276_read (
|
| 43 |
+
.rstn ( rstn ),
|
| 44 |
+
.clk ( clk ),
|
| 45 |
+
.ad7276_csn ( ad7276_csn ),
|
| 46 |
+
.ad7276_sclk ( ad7276_sclk ),
|
| 47 |
+
.ad7276_sdata ( ad7276_sdata ),
|
| 48 |
+
.adc_data_en ( adc_data_en ),
|
| 49 |
+
.adc_data ( adc_data )
|
| 50 |
+
);
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
uart_rx #(
|
| 54 |
+
.CLK_FREQ ( 81360000 ), // 81.36 MHz
|
| 55 |
+
.BAUD_RATE ( 9600 ),
|
| 56 |
+
.PARITY ( "NONE" ),
|
| 57 |
+
.FIFO_EA ( 0 )
|
| 58 |
+
) u_uart_rx (
|
| 59 |
+
.rstn ( rstn ),
|
| 60 |
+
.clk ( clk ),
|
| 61 |
+
.i_uart_rx ( uart_rx ),
|
| 62 |
+
.o_tready ( 1'b1 ),
|
| 63 |
+
.o_tvalid ( uart_rx_byte_en ),
|
| 64 |
+
.o_tdata ( uart_rx_byte ),
|
| 65 |
+
.o_overflow ( )
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
uart_rx_parser u_uart_rx_parser (
|
| 70 |
+
.rstn ( rstn ),
|
| 71 |
+
.clk ( clk ),
|
| 72 |
+
.uart_rx_byte_en ( uart_rx_byte_en ),
|
| 73 |
+
.uart_rx_byte ( uart_rx_byte ),
|
| 74 |
+
.tvalid ( tvalid ),
|
| 75 |
+
.tdata ( tdata ),
|
| 76 |
+
.tdatab ( tdatab ),
|
| 77 |
+
.tlast ( tlast )
|
| 78 |
+
);
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
fifo_sync #(
|
| 82 |
+
.DW ( 8 + 4 + 1 ),
|
| 83 |
+
.EA ( 12 )
|
| 84 |
+
) u_fifo_sync (
|
| 85 |
+
.rstn ( rstn ),
|
| 86 |
+
.clk ( clk ),
|
| 87 |
+
.i_rdy ( ),
|
| 88 |
+
.i_en ( tvalid ),
|
| 89 |
+
.i_data ( { tdata, tdatab, tlast} ),
|
| 90 |
+
.o_rdy ( tx_tready ),
|
| 91 |
+
.o_en ( tx_tvalid ),
|
| 92 |
+
.o_data ( {tx_tdata, tx_tdatab, tx_tlast} )
|
| 93 |
+
);
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
nfca_controller u_nfca_controller (
|
| 97 |
+
.rstn ( rstn ),
|
| 98 |
+
.clk ( clk ),
|
| 99 |
+
.tx_tvalid ( tx_tvalid ),
|
| 100 |
+
.tx_tready ( tx_tready ),
|
| 101 |
+
.tx_tdata ( tx_tdata ),
|
| 102 |
+
.tx_tdatab ( tx_tdatab ),
|
| 103 |
+
.tx_tlast ( tx_tlast ),
|
| 104 |
+
.rx_on ( rx_on ),
|
| 105 |
+
.rx_tvalid ( rx_tvalid ),
|
| 106 |
+
.rx_tdata ( rx_tdata ),
|
| 107 |
+
.rx_tdatab ( rx_tdatab ),
|
| 108 |
+
.rx_tend ( rx_tend ),
|
| 109 |
+
.rx_terr ( rx_terr ),
|
| 110 |
+
.adc_data_en ( adc_data_en ),
|
| 111 |
+
.adc_data ( adc_data ),
|
| 112 |
+
.carrier_out ( carrier_out )
|
| 113 |
+
);
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
function [7:0] hex2ascii;
|
| 117 |
+
input [3:0] hex;
|
| 118 |
+
begin
|
| 119 |
+
hex2ascii = (hex<4'hA) ? (hex+"0") : (hex+("A"-8'hA)) ;
|
| 120 |
+
end
|
| 121 |
+
endfunction
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
uart_tx #(
|
| 125 |
+
.CLK_FREQ ( 81360000 ),
|
| 126 |
+
.BAUD_RATE ( 9600 ),
|
| 127 |
+
.PARITY ( "NONE" ),
|
| 128 |
+
.STOP_BITS ( 4 ),
|
| 129 |
+
.BYTE_WIDTH ( 4 ),
|
| 130 |
+
.FIFO_EA ( 12 ),
|
| 131 |
+
.EXTRA_BYTE_AFTER_TRANSFER ( "" ),
|
| 132 |
+
.EXTRA_BYTE_AFTER_PACKET ( "" )
|
| 133 |
+
) u_uart_tx (
|
| 134 |
+
.rstn ( rstn ),
|
| 135 |
+
.clk ( clk ),
|
| 136 |
+
.i_tready ( ),
|
| 137 |
+
.i_tvalid ( rx_tvalid ),
|
| 138 |
+
.i_tdata ( rx_tend ? {8'h00, 8'h00, "\n", (rx_terr ? "n" : 8'h00)} : { ((rx_tdatab<4'd8) ? hex2ascii(rx_tdatab) : 8'h00), ((rx_tdatab<4'd8) ? ":" : " "), hex2ascii(rx_tdata[3:0]), hex2ascii(rx_tdata[7:4]) } ),
|
| 139 |
+
.i_tkeep ( rx_tend ? {1'b0 , 1'b0 , 1'b1, (rx_terr ? 1'b1 : 1'b0)} : { ((rx_tdatab<4'd8) ? 1'b1 : 1'b0 ), 3'b111 } ),
|
| 140 |
+
.i_tlast ( 1'b0 ),
|
| 141 |
+
.o_uart_tx ( uart_tx )
|
| 142 |
+
);
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/uart_rx.v
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : uart_rx
|
| 4 |
+
// Type : synthesizable, IP's top
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: input UART signal,
|
| 7 |
+
// output AXI-stream (1 byte data width)
|
| 8 |
+
//--------------------------------------------------------------------------------------------------------
|
| 9 |
+
|
| 10 |
+
module uart_rx #(
|
| 11 |
+
// clock frequency
|
| 12 |
+
parameter CLK_FREQ = 50000000, // clk frequency, Unit : Hz
|
| 13 |
+
// UART format
|
| 14 |
+
parameter BAUD_RATE = 115200, // Unit : Hz
|
| 15 |
+
parameter PARITY = "NONE", // "NONE", "ODD", or "EVEN"
|
| 16 |
+
// RX fifo depth
|
| 17 |
+
parameter FIFO_EA = 0 // 0:no fifo 1,2:depth=4 3:depth=8 4:depth=16 ... 10:depth=1024 11:depth=2048 ...
|
| 18 |
+
) (
|
| 19 |
+
input wire rstn,
|
| 20 |
+
input wire clk,
|
| 21 |
+
// UART RX input signal
|
| 22 |
+
input wire i_uart_rx,
|
| 23 |
+
// output AXI-stream master. Associated clock = clk.
|
| 24 |
+
input wire o_tready,
|
| 25 |
+
output reg o_tvalid,
|
| 26 |
+
output reg [ 7:0] o_tdata,
|
| 27 |
+
// report whether there's a overflow
|
| 28 |
+
output reg o_overflow
|
| 29 |
+
);
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 34 |
+
// Generate fractional precise upper limit for counter
|
| 35 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 36 |
+
localparam BAUD_CYCLES = ( (CLK_FREQ*10*2 + BAUD_RATE) / (BAUD_RATE*2) ) / 10 ;
|
| 37 |
+
localparam BAUD_CYCLES_FRAC = ( (CLK_FREQ*10*2 + BAUD_RATE) / (BAUD_RATE*2) ) % 10 ;
|
| 38 |
+
|
| 39 |
+
localparam HALF_BAUD_CYCLES = BAUD_CYCLES / 2;
|
| 40 |
+
localparam THREE_QUARTER_BAUD_CYCLES = (BAUD_CYCLES*3) / 4;
|
| 41 |
+
|
| 42 |
+
localparam [9:0] ADDITION_CYCLES = (BAUD_CYCLES_FRAC == 0) ? 10'b0000000000 :
|
| 43 |
+
(BAUD_CYCLES_FRAC == 1) ? 10'b0000010000 :
|
| 44 |
+
(BAUD_CYCLES_FRAC == 2) ? 10'b0010000100 :
|
| 45 |
+
(BAUD_CYCLES_FRAC == 3) ? 10'b0010010010 :
|
| 46 |
+
(BAUD_CYCLES_FRAC == 4) ? 10'b0101001010 :
|
| 47 |
+
(BAUD_CYCLES_FRAC == 5) ? 10'b0101010101 :
|
| 48 |
+
(BAUD_CYCLES_FRAC == 6) ? 10'b1010110101 :
|
| 49 |
+
(BAUD_CYCLES_FRAC == 7) ? 10'b1101101101 :
|
| 50 |
+
(BAUD_CYCLES_FRAC == 8) ? 10'b1101111011 :
|
| 51 |
+
/*BAUD_CYCLES_FRAC == 9)*/ 10'b1111101111 ;
|
| 52 |
+
|
| 53 |
+
wire [31:0] cycles [9:0];
|
| 54 |
+
|
| 55 |
+
assign cycles[0] = BAUD_CYCLES + (ADDITION_CYCLES[0] ? 1 : 0);
|
| 56 |
+
assign cycles[1] = BAUD_CYCLES + (ADDITION_CYCLES[1] ? 1 : 0);
|
| 57 |
+
assign cycles[2] = BAUD_CYCLES + (ADDITION_CYCLES[2] ? 1 : 0);
|
| 58 |
+
assign cycles[3] = BAUD_CYCLES + (ADDITION_CYCLES[3] ? 1 : 0);
|
| 59 |
+
assign cycles[4] = BAUD_CYCLES + (ADDITION_CYCLES[4] ? 1 : 0);
|
| 60 |
+
assign cycles[5] = BAUD_CYCLES + (ADDITION_CYCLES[5] ? 1 : 0);
|
| 61 |
+
assign cycles[6] = BAUD_CYCLES + (ADDITION_CYCLES[6] ? 1 : 0);
|
| 62 |
+
assign cycles[7] = BAUD_CYCLES + (ADDITION_CYCLES[7] ? 1 : 0);
|
| 63 |
+
assign cycles[8] = BAUD_CYCLES + (ADDITION_CYCLES[8] ? 1 : 0);
|
| 64 |
+
assign cycles[9] = BAUD_CYCLES + (ADDITION_CYCLES[9] ? 1 : 0);
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 69 |
+
// Input beat
|
| 70 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 71 |
+
reg rx_d1 = 1'b0;
|
| 72 |
+
|
| 73 |
+
always @ (posedge clk or negedge rstn)
|
| 74 |
+
if (~rstn)
|
| 75 |
+
rx_d1 <= 1'b0;
|
| 76 |
+
else
|
| 77 |
+
rx_d1 <= i_uart_rx;
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 82 |
+
// count continuous '1'
|
| 83 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 84 |
+
reg [31:0] count1 = 0;
|
| 85 |
+
|
| 86 |
+
always @ (posedge clk or negedge rstn)
|
| 87 |
+
if (~rstn) begin
|
| 88 |
+
count1 <= 0;
|
| 89 |
+
end else begin
|
| 90 |
+
if (rx_d1)
|
| 91 |
+
count1 <= (count1 < 'hFFFFFFFF) ? (count1 + 1) : count1;
|
| 92 |
+
else
|
| 93 |
+
count1 <= 0;
|
| 94 |
+
end
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 99 |
+
// main FSM
|
| 100 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 101 |
+
localparam [ 3:0] TOTAL_BITS_MINUS1 = (PARITY == "ODD" || PARITY == "EVEN") ? 4'd9 : 4'd8;
|
| 102 |
+
|
| 103 |
+
localparam [ 1:0] S_IDLE = 2'd0 ,
|
| 104 |
+
S_RX = 2'd1 ,
|
| 105 |
+
S_STOP_BIT = 2'd2 ;
|
| 106 |
+
|
| 107 |
+
reg [ 1:0] state = S_IDLE;
|
| 108 |
+
reg [ 8:0] rxbits = 9'b0;
|
| 109 |
+
reg [ 3:0] rxcnt = 4'd0;
|
| 110 |
+
reg [31:0] cycle = 1;
|
| 111 |
+
reg [32:0] countp = 33'h1_0000_0000; // countp>=0x100000000 means '1' is majority , countp<0x100000000 means '0' is majority
|
| 112 |
+
wire rxbit = countp[32]; // countp>=0x100000000 corresponds to countp[32]==1, countp<0x100000000 corresponds to countp[32]==0
|
| 113 |
+
|
| 114 |
+
wire [ 7:0] rbyte = (PARITY == "ODD" ) ? rxbits[7:0] :
|
| 115 |
+
(PARITY == "EVEN") ? rxbits[7:0] :
|
| 116 |
+
/*(PARITY == "NONE")*/ rxbits[8:1] ;
|
| 117 |
+
|
| 118 |
+
wire parity_correct = (PARITY == "ODD" ) ? ((~(^(rbyte))) == rxbits[8]) :
|
| 119 |
+
(PARITY == "EVEN") ? ( (^(rbyte)) == rxbits[8]) :
|
| 120 |
+
/*(PARITY == "NONE")*/ 1'b1 ;
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
always @ (posedge clk or negedge rstn)
|
| 124 |
+
if (~rstn) begin
|
| 125 |
+
state <= S_IDLE;
|
| 126 |
+
rxbits <= 9'b0;
|
| 127 |
+
rxcnt <= 4'd0;
|
| 128 |
+
cycle <= 1;
|
| 129 |
+
countp <= 33'h1_0000_0000;
|
| 130 |
+
end else begin
|
| 131 |
+
case (state)
|
| 132 |
+
S_IDLE : begin
|
| 133 |
+
if ((count1 >= THREE_QUARTER_BAUD_CYCLES) && (rx_d1 == 1'b0)) // receive a '0' which is followed by continuous '1' for half baud cycles
|
| 134 |
+
state <= S_RX;
|
| 135 |
+
rxcnt <= 4'd0;
|
| 136 |
+
cycle <= 2; // we've already receive a '0', so here cycle = 2
|
| 137 |
+
countp <= (33'h1_0000_0000 - 33'd1); // we've already receive a '0', so here countp = initial_value - 1
|
| 138 |
+
end
|
| 139 |
+
|
| 140 |
+
S_RX :
|
| 141 |
+
if ( cycle < cycles[rxcnt] ) begin // cycle loop from 1 to cycles[rxcnt]
|
| 142 |
+
cycle <= cycle + 1;
|
| 143 |
+
countp <= rx_d1 ? (countp + 33'd1) : (countp - 33'd1);
|
| 144 |
+
end else begin
|
| 145 |
+
cycle <= 1; // reset counter
|
| 146 |
+
countp <= 33'h1_0000_0000; // reset counter
|
| 147 |
+
|
| 148 |
+
if ( rxcnt < TOTAL_BITS_MINUS1 ) begin // rxcnt loop from 0 to TOTAL_BITS_MINUS1
|
| 149 |
+
rxcnt <= rxcnt + 4'd1;
|
| 150 |
+
if ((rxcnt == 4'd0) && (rxbit == 1'b1)) // except start bit, but get '1'
|
| 151 |
+
state <= S_IDLE; // RX failed, back to IDLE
|
| 152 |
+
end else begin
|
| 153 |
+
rxcnt <= 4'd0;
|
| 154 |
+
state <= S_STOP_BIT;
|
| 155 |
+
end
|
| 156 |
+
|
| 157 |
+
rxbits <= {rxbit, rxbits[8:1]}; // put current rxbit to MSB of rxbits, and right shift other bits
|
| 158 |
+
end
|
| 159 |
+
|
| 160 |
+
default : // S_STOP_BIT
|
| 161 |
+
if ( cycle < THREE_QUARTER_BAUD_CYCLES) begin // cycle loop from 1 to THREE_QUARTER_BAUD_CYCLES
|
| 162 |
+
cycle <= cycle + 1;
|
| 163 |
+
end else begin
|
| 164 |
+
cycle <= 1; // reset counter
|
| 165 |
+
state <= S_IDLE; // back to IDLE
|
| 166 |
+
end
|
| 167 |
+
endcase
|
| 168 |
+
end
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 173 |
+
// RX result byte
|
| 174 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 175 |
+
reg f_tvalid = 1'b0;
|
| 176 |
+
reg [7:0] f_tdata = 8'h0;
|
| 177 |
+
|
| 178 |
+
always @ (posedge clk or negedge rstn)
|
| 179 |
+
if (~rstn) begin
|
| 180 |
+
f_tvalid <= 1'b0;
|
| 181 |
+
f_tdata <= 8'h0;
|
| 182 |
+
end else begin
|
| 183 |
+
f_tvalid <= 1'b0;
|
| 184 |
+
f_tdata <= 8'h0;
|
| 185 |
+
if (state == S_STOP_BIT) begin
|
| 186 |
+
if ( cycle < THREE_QUARTER_BAUD_CYCLES) begin
|
| 187 |
+
end else begin
|
| 188 |
+
if ((count1 >= HALF_BAUD_CYCLES) && parity_correct) begin // stop bit have enough '1', and parity correct
|
| 189 |
+
f_tvalid <= 1'b1;
|
| 190 |
+
f_tdata <= rbyte; // received a correct byte, output it
|
| 191 |
+
end
|
| 192 |
+
end
|
| 193 |
+
end
|
| 194 |
+
end
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 199 |
+
// RX fifo
|
| 200 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 201 |
+
wire f_tready;
|
| 202 |
+
|
| 203 |
+
generate if (FIFO_EA <= 0) begin // no RX fifo
|
| 204 |
+
|
| 205 |
+
assign f_tready = o_tready;
|
| 206 |
+
always @ (*) o_tvalid = f_tvalid;
|
| 207 |
+
always @ (*) o_tdata = f_tdata;
|
| 208 |
+
|
| 209 |
+
end else begin // TX fifo
|
| 210 |
+
|
| 211 |
+
localparam EA = (FIFO_EA <= 2) ? 2 : FIFO_EA;
|
| 212 |
+
|
| 213 |
+
reg [7:0] buffer [ ((1<<EA)-1) : 0 ];
|
| 214 |
+
|
| 215 |
+
localparam [EA:0] A_ZERO = {{EA{1'b0}}, 1'b0};
|
| 216 |
+
localparam [EA:0] A_ONE = {{EA{1'b0}}, 1'b1};
|
| 217 |
+
|
| 218 |
+
reg [EA:0] wptr = A_ZERO;
|
| 219 |
+
reg [EA:0] wptr_d1 = A_ZERO;
|
| 220 |
+
reg [EA:0] wptr_d2 = A_ZERO;
|
| 221 |
+
reg [EA:0] rptr = A_ZERO;
|
| 222 |
+
wire [EA:0] rptr_next = (o_tvalid & o_tready) ? (rptr+A_ONE) : rptr;
|
| 223 |
+
|
| 224 |
+
assign f_tready = ( wptr != {~rptr[EA], rptr[EA-1:0]} );
|
| 225 |
+
|
| 226 |
+
always @ (posedge clk or negedge rstn)
|
| 227 |
+
if (~rstn) begin
|
| 228 |
+
wptr <= A_ZERO;
|
| 229 |
+
wptr_d1 <= A_ZERO;
|
| 230 |
+
wptr_d2 <= A_ZERO;
|
| 231 |
+
end else begin
|
| 232 |
+
if (f_tvalid & f_tready)
|
| 233 |
+
wptr <= wptr + A_ONE;
|
| 234 |
+
wptr_d1 <= wptr;
|
| 235 |
+
wptr_d2 <= wptr_d1;
|
| 236 |
+
end
|
| 237 |
+
|
| 238 |
+
always @ (posedge clk)
|
| 239 |
+
if (f_tvalid & f_tready)
|
| 240 |
+
buffer[wptr[EA-1:0]] <= f_tdata;
|
| 241 |
+
|
| 242 |
+
always @ (posedge clk or negedge rstn)
|
| 243 |
+
if (~rstn) begin
|
| 244 |
+
rptr <= A_ZERO;
|
| 245 |
+
o_tvalid <= 1'b0;
|
| 246 |
+
end else begin
|
| 247 |
+
rptr <= rptr_next;
|
| 248 |
+
o_tvalid <= (rptr_next != wptr_d2);
|
| 249 |
+
end
|
| 250 |
+
|
| 251 |
+
always @ (posedge clk)
|
| 252 |
+
o_tdata <= buffer[rptr_next[EA-1:0]];
|
| 253 |
+
|
| 254 |
+
initial o_tvalid = 1'b0;
|
| 255 |
+
initial o_tdata = 8'h0;
|
| 256 |
+
end endgenerate
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 261 |
+
// detect RX fifo overflow
|
| 262 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 263 |
+
initial o_overflow = 1'b0;
|
| 264 |
+
|
| 265 |
+
always @ (posedge clk or negedge rstn)
|
| 266 |
+
if (~rstn)
|
| 267 |
+
o_overflow <= 1'b0;
|
| 268 |
+
else
|
| 269 |
+
o_overflow <= (f_tvalid & (~f_tready));
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 274 |
+
// parameter checking
|
| 275 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 276 |
+
initial begin
|
| 277 |
+
if (BAUD_CYCLES < 10) begin $error("invalid parameter : BAUD_CYCLES < 10, please use a faster driving clock"); $stop; end
|
| 278 |
+
|
| 279 |
+
$display("uart_rx : parity = %s" , PARITY );
|
| 280 |
+
$display("uart_rx : clock period = %.0f ns (%-10d Hz)" , 1000000000.0/CLK_FREQ , CLK_FREQ );
|
| 281 |
+
$display("uart_rx : baud rate period = %.0f ns (%-10d Hz)" , 1000000000.0/BAUD_RATE , BAUD_RATE);
|
| 282 |
+
$display("uart_rx : baud cycles = %-10d" , BAUD_CYCLES );
|
| 283 |
+
$display("uart_rx : baud cycles frac = %-10d" , BAUD_CYCLES_FRAC );
|
| 284 |
+
|
| 285 |
+
if (PARITY == "ODD" || PARITY == "EVEN") begin
|
| 286 |
+
$display("uart_rx : __ ____ ____ ____ ____ ____ ____ ____ ____________ ");
|
| 287 |
+
$display("uart_rx : wave \\____/____X____X____X____X____X____X____X____X____/ ");
|
| 288 |
+
$display("uart_rx : bits | S | B0 | B1 | B2 | B3 | B4 | B5 | B6 | B7 | P | ");
|
| 289 |
+
$display("uart_rx : time_points t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 ");
|
| 290 |
+
$display("uart_rx :");
|
| 291 |
+
end else begin
|
| 292 |
+
$display("uart_rx : __ ____ ____ ____ ____ ____ ____ ____ _______ ");
|
| 293 |
+
$display("uart_rx : wave \\____/____X____X____X____X____X____X____X____/ ");
|
| 294 |
+
$display("uart_rx : bits | S | B0 | B1 | B2 | B3 | B4 | B5 | B6 | B7 | ");
|
| 295 |
+
$display("uart_rx : time_points t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 ");
|
| 296 |
+
$display("uart_rx :");
|
| 297 |
+
end
|
| 298 |
+
end
|
| 299 |
+
|
| 300 |
+
generate genvar index;
|
| 301 |
+
for (index=0; index<=9; index=index+1) begin : print_and_check_time
|
| 302 |
+
localparam cycles_acc = ( (index >= 0) ? (BAUD_CYCLES + (ADDITION_CYCLES[0] ? 1 : 0)) : 0 )
|
| 303 |
+
+ ( (index >= 1) ? (BAUD_CYCLES + (ADDITION_CYCLES[1] ? 1 : 0)) : 0 )
|
| 304 |
+
+ ( (index >= 2) ? (BAUD_CYCLES + (ADDITION_CYCLES[2] ? 1 : 0)) : 0 )
|
| 305 |
+
+ ( (index >= 3) ? (BAUD_CYCLES + (ADDITION_CYCLES[3] ? 1 : 0)) : 0 )
|
| 306 |
+
+ ( (index >= 4) ? (BAUD_CYCLES + (ADDITION_CYCLES[4] ? 1 : 0)) : 0 )
|
| 307 |
+
+ ( (index >= 5) ? (BAUD_CYCLES + (ADDITION_CYCLES[5] ? 1 : 0)) : 0 )
|
| 308 |
+
+ ( (index >= 6) ? (BAUD_CYCLES + (ADDITION_CYCLES[6] ? 1 : 0)) : 0 )
|
| 309 |
+
+ ( (index >= 7) ? (BAUD_CYCLES + (ADDITION_CYCLES[7] ? 1 : 0)) : 0 )
|
| 310 |
+
+ ( (index >= 8) ? (BAUD_CYCLES + (ADDITION_CYCLES[8] ? 1 : 0)) : 0 )
|
| 311 |
+
+ ( (index >= 9) ? (BAUD_CYCLES + (ADDITION_CYCLES[9] ? 1 : 0)) : 0 ) ;
|
| 312 |
+
|
| 313 |
+
localparam real ideal_time_ns = ((index+1)*1000000000.0/BAUD_RATE);
|
| 314 |
+
localparam real actual_time_ns = (cycles_acc*1000000000.0/CLK_FREQ);
|
| 315 |
+
localparam real uncertainty = (1000000000.0/CLK_FREQ);
|
| 316 |
+
localparam real error = ( (ideal_time_ns>actual_time_ns) ? (ideal_time_ns-actual_time_ns) : (-ideal_time_ns+actual_time_ns) ) + uncertainty;
|
| 317 |
+
localparam real relative_error_percent = (error / (1000000000.0/BAUD_RATE)) * 100.0;
|
| 318 |
+
|
| 319 |
+
initial if (PARITY == "ODD" || PARITY == "EVEN" || index < 9) begin
|
| 320 |
+
$display("uart_rx : t%-2d- t0 = %.0f ns (ideal) %.0f +- %.0f ns (actual). error=%.0f ns relative_error=%.3f%%" ,
|
| 321 |
+
(index+1) ,
|
| 322 |
+
ideal_time_ns ,
|
| 323 |
+
actual_time_ns,
|
| 324 |
+
uncertainty,
|
| 325 |
+
error,
|
| 326 |
+
relative_error_percent
|
| 327 |
+
);
|
| 328 |
+
|
| 329 |
+
if ( relative_error_percent > 8.0 ) begin $error("relative_error is too large"); $stop; end // if relative error larger than 8%
|
| 330 |
+
end
|
| 331 |
+
end
|
| 332 |
+
endgenerate
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/uart_rx_parser.v
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module uart_rx_parser #(
|
| 3 |
+
parameter CLK_DIV = 108 // UART baud rate = clk freq/(4*CLK_DIV), modify CLK_DIV to change the UART baud
|
| 4 |
+
// for example, when clk=125MHz, CLK_DIV=271, then baud=125MHz/(4*271)=115200, 115200 is a typical baud rate for UART
|
| 5 |
+
) (
|
| 6 |
+
input wire rstn,
|
| 7 |
+
input wire clk,
|
| 8 |
+
// uart RX bytes input
|
| 9 |
+
input wire uart_rx_byte_en,
|
| 10 |
+
input wire [7:0] uart_rx_byte,
|
| 11 |
+
// parsed byte stream
|
| 12 |
+
output reg tvalid,
|
| 13 |
+
output reg [7:0] tdata,
|
| 14 |
+
output reg [3:0] tdatab,
|
| 15 |
+
output reg tlast
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
initial {tvalid, tdata, tlast, tdatab} = 0;
|
| 20 |
+
|
| 21 |
+
localparam [7:0] CHAR_0 = 8'h30, // "0"
|
| 22 |
+
CHAR_9 = 8'h39, // "9"
|
| 23 |
+
CHAR_A = 8'h41, // "A"
|
| 24 |
+
CHAR_F = 8'h46, // "F"
|
| 25 |
+
CHAR_a = 8'h61, // "a"
|
| 26 |
+
CHAR_f = 8'h66, // "f"
|
| 27 |
+
CHAR_ht = 8'h09, // "\t"
|
| 28 |
+
CHAR_sp = 8'h20, // " "
|
| 29 |
+
CHAR_cr = 8'h0D, // "\r"
|
| 30 |
+
CHAR_lf = 8'h0A, // "\n"
|
| 31 |
+
CHAR_cl = 8'h3A; // ":"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
function [4:0] ascii2hex;
|
| 35 |
+
input [7:0] ascii;
|
| 36 |
+
reg [7:0] tmp;
|
| 37 |
+
begin
|
| 38 |
+
if ( ascii >= CHAR_0 && ascii <= CHAR_9 ) begin
|
| 39 |
+
tmp = ascii - CHAR_0;
|
| 40 |
+
ascii2hex = {1'b1, tmp[3:0]};
|
| 41 |
+
end else if( ascii >= CHAR_A && ascii <= CHAR_F ) begin
|
| 42 |
+
tmp = ascii - CHAR_A + 8'd10;
|
| 43 |
+
ascii2hex = {1'b1, tmp[3:0]};
|
| 44 |
+
end else if( ascii >= CHAR_a && ascii <= CHAR_f ) begin
|
| 45 |
+
tmp = ascii - CHAR_a + 8'd10;
|
| 46 |
+
ascii2hex = {1'b1, tmp[3:0]};
|
| 47 |
+
end else begin
|
| 48 |
+
tmp = ascii;
|
| 49 |
+
ascii2hex = {1'b0, 4'h0};
|
| 50 |
+
end
|
| 51 |
+
end
|
| 52 |
+
endfunction
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
wire isspace = (uart_rx_byte == CHAR_sp) || (uart_rx_byte == CHAR_ht);
|
| 56 |
+
wire iscrlf = (uart_rx_byte == CHAR_cr) || (uart_rx_byte == CHAR_lf);
|
| 57 |
+
wire iscolon = (uart_rx_byte == CHAR_cl);
|
| 58 |
+
wire ishex;
|
| 59 |
+
wire [3:0] hexvalue;
|
| 60 |
+
|
| 61 |
+
assign {ishex, hexvalue} = ascii2hex(uart_rx_byte);
|
| 62 |
+
|
| 63 |
+
localparam [2:0] INIT = 3'd0,
|
| 64 |
+
HEXH = 3'd1,
|
| 65 |
+
HEXL = 3'd2,
|
| 66 |
+
LASTB = 3'd3,
|
| 67 |
+
INVALID= 3'd4;
|
| 68 |
+
reg [2:0] fsm = INIT;
|
| 69 |
+
|
| 70 |
+
reg [7:0] savedata = 0;
|
| 71 |
+
|
| 72 |
+
always @ (posedge clk or negedge rstn)
|
| 73 |
+
if(~rstn) begin
|
| 74 |
+
{tvalid, tdata, tlast, tdatab} <= 0;
|
| 75 |
+
fsm <= INIT;
|
| 76 |
+
savedata <= 0;
|
| 77 |
+
end else begin
|
| 78 |
+
{tvalid, tdata, tlast} <= 0;
|
| 79 |
+
tdatab <= 4'd8;
|
| 80 |
+
if(uart_rx_byte_en) begin
|
| 81 |
+
if (fsm == INIT) begin
|
| 82 |
+
if(ishex) begin
|
| 83 |
+
savedata <= {4'h0, hexvalue};
|
| 84 |
+
fsm <= HEXH;
|
| 85 |
+
end else if(~iscrlf & ~isspace) begin
|
| 86 |
+
fsm <= INVALID;
|
| 87 |
+
end
|
| 88 |
+
end else if(fsm == HEXH || fsm==HEXL) begin
|
| 89 |
+
if(ishex) begin
|
| 90 |
+
if(fsm == HEXH) begin
|
| 91 |
+
savedata <= {savedata[3:0], hexvalue};
|
| 92 |
+
fsm <= HEXL;
|
| 93 |
+
end else begin
|
| 94 |
+
{tvalid, tdata, tlast} <= {1'b1, savedata, 1'b0};
|
| 95 |
+
savedata <= {4'h0, hexvalue};
|
| 96 |
+
fsm <= HEXH;
|
| 97 |
+
end
|
| 98 |
+
end else if(iscolon) begin
|
| 99 |
+
fsm <= LASTB;
|
| 100 |
+
end else if(isspace) begin
|
| 101 |
+
fsm <= HEXL;
|
| 102 |
+
end else if(iscrlf) begin
|
| 103 |
+
{tvalid, tdata, tlast} <= {1'b1, savedata, 1'b1};
|
| 104 |
+
fsm <= INIT;
|
| 105 |
+
end else begin
|
| 106 |
+
{tvalid, tdata, tlast} <= {1'b1, savedata, 1'b1};
|
| 107 |
+
fsm <= INVALID;
|
| 108 |
+
end
|
| 109 |
+
end else if(fsm == LASTB) begin
|
| 110 |
+
if(ishex) begin
|
| 111 |
+
{tvalid, tdata, tlast} <= {1'b1, savedata, 1'b1};
|
| 112 |
+
if (hexvalue == 4'd0)
|
| 113 |
+
tdatab <= 4'd1;
|
| 114 |
+
else if(hexvalue <= 4'd7)
|
| 115 |
+
tdatab <= hexvalue;
|
| 116 |
+
fsm <= INVALID;
|
| 117 |
+
end else if(iscrlf) begin
|
| 118 |
+
{tvalid, tdata, tlast} <= {1'b1, savedata, 1'b1};
|
| 119 |
+
fsm <= INIT;
|
| 120 |
+
end else begin
|
| 121 |
+
{tvalid, tdata, tlast} <= {1'b1, savedata, 1'b1};
|
| 122 |
+
fsm <= INVALID;
|
| 123 |
+
end
|
| 124 |
+
end else if(iscrlf) begin
|
| 125 |
+
fsm <= INIT;
|
| 126 |
+
end
|
| 127 |
+
end
|
| 128 |
+
end
|
| 129 |
+
|
| 130 |
+
endmodule
|
WangXuan95_FPGA-NFC/RTL/uart_tx.v
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : uart_tx
|
| 4 |
+
// Type : synthesizable, IP's top
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: input AXI-stream (configurable data width),
|
| 7 |
+
// output UART signal
|
| 8 |
+
//--------------------------------------------------------------------------------------------------------
|
| 9 |
+
|
| 10 |
+
module uart_tx #(
|
| 11 |
+
// clock frequency
|
| 12 |
+
parameter CLK_FREQ = 50000000, // clk frequency, Unit : Hz
|
| 13 |
+
// UART format
|
| 14 |
+
parameter BAUD_RATE = 115200, // Unit : Hz
|
| 15 |
+
parameter PARITY = "NONE", // "NONE", "ODD", or "EVEN"
|
| 16 |
+
parameter STOP_BITS = 2, // can be 1, 2, 3, 4, ...
|
| 17 |
+
// AXI stream data width
|
| 18 |
+
parameter BYTE_WIDTH = 1, // can be 1, 2, 3, 4, ...
|
| 19 |
+
// TX fifo depth
|
| 20 |
+
parameter FIFO_EA = 0, // 0:no fifo 1,2:depth=4 3:depth=8 4:depth=16 ... 10:depth=1024 11:depth=2048 ...
|
| 21 |
+
// do you want to send extra byte after each AXI-stream transfer or packet?
|
| 22 |
+
parameter EXTRA_BYTE_AFTER_TRANSFER = "", // specify a extra byte to send after each AXI-stream transfer. when ="", do not send this extra byte
|
| 23 |
+
parameter EXTRA_BYTE_AFTER_PACKET = "" // specify a extra byte to send after each AXI-stream packet . when ="", do not send this extra byte
|
| 24 |
+
) (
|
| 25 |
+
input wire rstn,
|
| 26 |
+
input wire clk,
|
| 27 |
+
// input stream : AXI-stream slave. Associated clock = clk
|
| 28 |
+
output wire i_tready,
|
| 29 |
+
input wire i_tvalid,
|
| 30 |
+
input wire [8*BYTE_WIDTH-1:0] i_tdata,
|
| 31 |
+
input wire [ BYTE_WIDTH-1:0] i_tkeep,
|
| 32 |
+
input wire i_tlast,
|
| 33 |
+
// UART TX output signal
|
| 34 |
+
output reg o_uart_tx
|
| 35 |
+
);
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 40 |
+
// TX fifo
|
| 41 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 42 |
+
wire f_tready;
|
| 43 |
+
reg f_tvalid;
|
| 44 |
+
reg [8*BYTE_WIDTH-1:0] f_tdata;
|
| 45 |
+
reg [ BYTE_WIDTH-1:0] f_tkeep;
|
| 46 |
+
reg f_tlast;
|
| 47 |
+
|
| 48 |
+
generate if (FIFO_EA <= 0) begin // no TX fifo
|
| 49 |
+
|
| 50 |
+
assign i_tready = f_tready;
|
| 51 |
+
always @ (*) f_tvalid = i_tvalid;
|
| 52 |
+
always @ (*) f_tdata = i_tdata;
|
| 53 |
+
always @ (*) f_tkeep = i_tkeep;
|
| 54 |
+
always @ (*) f_tlast = i_tlast;
|
| 55 |
+
|
| 56 |
+
end else begin // TX fifo
|
| 57 |
+
|
| 58 |
+
localparam EA = (FIFO_EA<=2) ? 2 : FIFO_EA;
|
| 59 |
+
localparam DW = ( 1 + BYTE_WIDTH + 8*BYTE_WIDTH ); // 1-bit tlast, (BYTE_WIDTH)-bit tkeep, (8*BYTE_WIDTH)-bit tdata
|
| 60 |
+
|
| 61 |
+
reg [DW-1:0] buffer [ ((1<<EA)-1) : 0 ];
|
| 62 |
+
|
| 63 |
+
localparam [EA:0] A_ZERO = {{EA{1'b0}}, 1'b0};
|
| 64 |
+
localparam [EA:0] A_ONE = {{EA{1'b0}}, 1'b1};
|
| 65 |
+
|
| 66 |
+
reg [EA:0] wptr = A_ZERO;
|
| 67 |
+
reg [EA:0] wptr_d1 = A_ZERO;
|
| 68 |
+
reg [EA:0] wptr_d2 = A_ZERO;
|
| 69 |
+
reg [EA:0] rptr = A_ZERO;
|
| 70 |
+
wire [EA:0] rptr_next = (f_tvalid & f_tready) ? (rptr+A_ONE) : rptr;
|
| 71 |
+
|
| 72 |
+
assign i_tready = ( wptr != {~rptr[EA], rptr[EA-1:0]} );
|
| 73 |
+
|
| 74 |
+
always @ (posedge clk or negedge rstn)
|
| 75 |
+
if (~rstn) begin
|
| 76 |
+
wptr <= A_ZERO;
|
| 77 |
+
wptr_d1 <= A_ZERO;
|
| 78 |
+
wptr_d2 <= A_ZERO;
|
| 79 |
+
end else begin
|
| 80 |
+
if (i_tvalid & i_tready)
|
| 81 |
+
wptr <= wptr + A_ONE;
|
| 82 |
+
wptr_d1 <= wptr;
|
| 83 |
+
wptr_d2 <= wptr_d1;
|
| 84 |
+
end
|
| 85 |
+
|
| 86 |
+
always @ (posedge clk)
|
| 87 |
+
if (i_tvalid & i_tready)
|
| 88 |
+
buffer[wptr[EA-1:0]] <= {i_tlast, i_tkeep, i_tdata};
|
| 89 |
+
|
| 90 |
+
always @ (posedge clk or negedge rstn)
|
| 91 |
+
if (~rstn) begin
|
| 92 |
+
rptr <= A_ZERO;
|
| 93 |
+
f_tvalid <= 1'b0;
|
| 94 |
+
end else begin
|
| 95 |
+
rptr <= rptr_next;
|
| 96 |
+
f_tvalid <= (rptr_next != wptr_d2);
|
| 97 |
+
end
|
| 98 |
+
|
| 99 |
+
always @ (posedge clk)
|
| 100 |
+
{f_tlast, f_tkeep, f_tdata} <= buffer[rptr_next[EA-1:0]];
|
| 101 |
+
|
| 102 |
+
initial {f_tvalid, f_tlast, f_tkeep, f_tdata} = 0;
|
| 103 |
+
|
| 104 |
+
end endgenerate
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 110 |
+
// Generate fractional precise upper limit for counter
|
| 111 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 112 |
+
localparam BAUD_CYCLES = ( (CLK_FREQ*10*2 + BAUD_RATE) / (BAUD_RATE*2) ) / 10 ;
|
| 113 |
+
localparam BAUD_CYCLES_FRAC = ( (CLK_FREQ*10*2 + BAUD_RATE) / (BAUD_RATE*2) ) % 10 ;
|
| 114 |
+
localparam STOP_BIT_CYCLES = (BAUD_CYCLES_FRAC == 0) ? BAUD_CYCLES : (BAUD_CYCLES + 1);
|
| 115 |
+
|
| 116 |
+
localparam [9:0] ADDITION_CYCLES = (BAUD_CYCLES_FRAC == 0) ? 10'b0000000000 :
|
| 117 |
+
(BAUD_CYCLES_FRAC == 1) ? 10'b0000010000 :
|
| 118 |
+
(BAUD_CYCLES_FRAC == 2) ? 10'b0010000100 :
|
| 119 |
+
(BAUD_CYCLES_FRAC == 3) ? 10'b0010010010 :
|
| 120 |
+
(BAUD_CYCLES_FRAC == 4) ? 10'b0101001010 :
|
| 121 |
+
(BAUD_CYCLES_FRAC == 5) ? 10'b0101010101 :
|
| 122 |
+
(BAUD_CYCLES_FRAC == 6) ? 10'b1010110101 :
|
| 123 |
+
(BAUD_CYCLES_FRAC == 7) ? 10'b1101101101 :
|
| 124 |
+
(BAUD_CYCLES_FRAC == 8) ? 10'b1101111011 :
|
| 125 |
+
/*BAUD_CYCLES_FRAC == 9)*/ 10'b1111101111 ;
|
| 126 |
+
|
| 127 |
+
wire [31:0] cycles [9:0];
|
| 128 |
+
|
| 129 |
+
assign cycles[0] = BAUD_CYCLES + (ADDITION_CYCLES[0] ? 1 : 0);
|
| 130 |
+
assign cycles[1] = BAUD_CYCLES + (ADDITION_CYCLES[1] ? 1 : 0);
|
| 131 |
+
assign cycles[2] = BAUD_CYCLES + (ADDITION_CYCLES[2] ? 1 : 0);
|
| 132 |
+
assign cycles[3] = BAUD_CYCLES + (ADDITION_CYCLES[3] ? 1 : 0);
|
| 133 |
+
assign cycles[4] = BAUD_CYCLES + (ADDITION_CYCLES[4] ? 1 : 0);
|
| 134 |
+
assign cycles[5] = BAUD_CYCLES + (ADDITION_CYCLES[5] ? 1 : 0);
|
| 135 |
+
assign cycles[6] = BAUD_CYCLES + (ADDITION_CYCLES[6] ? 1 : 0);
|
| 136 |
+
assign cycles[7] = BAUD_CYCLES + (ADDITION_CYCLES[7] ? 1 : 0);
|
| 137 |
+
assign cycles[8] = BAUD_CYCLES + (ADDITION_CYCLES[8] ? 1 : 0);
|
| 138 |
+
assign cycles[9] = BAUD_CYCLES + (ADDITION_CYCLES[9] ? 1 : 0);
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 143 |
+
//
|
| 144 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 145 |
+
localparam [BYTE_WIDTH-1:0] ZERO_KEEP = 0;
|
| 146 |
+
|
| 147 |
+
localparam [31:0] PARITY_BITS = (PARITY == "ODD" || PARITY == "EVEN") ? 1 : 0;
|
| 148 |
+
localparam [31:0] TOTAL_BITS = (STOP_BITS >= ('hFFFFFFFF-9-PARITY_BITS)) ? 'hFFFFFFFF : (PARITY_BITS+STOP_BITS+9);
|
| 149 |
+
|
| 150 |
+
localparam [ 0:0] BYTE_T_EN = (EXTRA_BYTE_AFTER_TRANSFER == "") ? 1'b0 : 1'b1;
|
| 151 |
+
localparam [ 0:0] BYTE_B_EN = (EXTRA_BYTE_AFTER_PACKET == "") ? 1'b0 : 1'b1;
|
| 152 |
+
localparam [ 7:0] BYTE_T = EXTRA_BYTE_AFTER_TRANSFER;
|
| 153 |
+
localparam [ 7:0] BYTE_P = EXTRA_BYTE_AFTER_PACKET;
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 158 |
+
// function for calculate parity bit
|
| 159 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 160 |
+
function [0:0] get_parity;
|
| 161 |
+
input [7:0] data;
|
| 162 |
+
begin
|
| 163 |
+
get_parity = (PARITY == "ODD" ) ? (~(^(data[7:0]))) :
|
| 164 |
+
(PARITY == "EVEN") ? (^(data[7:0])) :
|
| 165 |
+
/*(PARITY == "NONE")*/ 1'b1 ;
|
| 166 |
+
end
|
| 167 |
+
endfunction
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 172 |
+
// main FSM
|
| 173 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 174 |
+
localparam [ 1:0] S_IDLE = 2'b01 , // only in state S_IDLE, state[0]==1, the goal is to make f_tready pure register-out
|
| 175 |
+
S_PREPARE = 2'b00 ,
|
| 176 |
+
S_TX = 2'b10 ;
|
| 177 |
+
|
| 178 |
+
reg [ 1:0] state = S_IDLE; // FSM state register
|
| 179 |
+
|
| 180 |
+
reg [8*BYTE_WIDTH-1:0] data = 0;
|
| 181 |
+
reg [ BYTE_WIDTH-1:0] keep = 0;
|
| 182 |
+
reg byte_t_en = 1'b0;
|
| 183 |
+
reg byte_p_en = 1'b0;
|
| 184 |
+
reg [ 9:0] txbits = 10'b0;
|
| 185 |
+
reg [ 31:0] txcnt = 0;
|
| 186 |
+
reg [ 31:0] cycle = 1;
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
always @ (posedge clk or negedge rstn)
|
| 190 |
+
if (~rstn) begin
|
| 191 |
+
state <= S_IDLE;
|
| 192 |
+
data <= 0;
|
| 193 |
+
keep <= 0;
|
| 194 |
+
byte_t_en <= 1'b0;
|
| 195 |
+
byte_p_en <= 1'b0;
|
| 196 |
+
txbits <= 10'b0;
|
| 197 |
+
txcnt <= 0;
|
| 198 |
+
cycle <= 1;
|
| 199 |
+
end else begin
|
| 200 |
+
case (state)
|
| 201 |
+
S_IDLE : begin
|
| 202 |
+
state <= f_tvalid ? S_PREPARE : S_IDLE;
|
| 203 |
+
data <= f_tdata;
|
| 204 |
+
keep <= f_tkeep;
|
| 205 |
+
byte_t_en <= BYTE_T_EN;
|
| 206 |
+
byte_p_en <= BYTE_B_EN & f_tlast;
|
| 207 |
+
txbits <= 10'b0;
|
| 208 |
+
txcnt <= 0;
|
| 209 |
+
cycle <= 1;
|
| 210 |
+
end
|
| 211 |
+
|
| 212 |
+
S_PREPARE : begin
|
| 213 |
+
data <= (data >> 8);
|
| 214 |
+
keep <= (keep >> 1);
|
| 215 |
+
if ( keep[0] == 1'b1 ) begin
|
| 216 |
+
txbits <= {get_parity(data[7:0]), data[7:0], 1'b0};
|
| 217 |
+
state <= S_TX;
|
| 218 |
+
end else if ( keep != ZERO_KEEP ) begin
|
| 219 |
+
state <= S_PREPARE;
|
| 220 |
+
end else if ( byte_t_en ) begin
|
| 221 |
+
byte_t_en <= 1'b0;
|
| 222 |
+
txbits <= {get_parity(BYTE_T), BYTE_T, 1'b0};
|
| 223 |
+
state <= S_TX;
|
| 224 |
+
end else if ( byte_p_en ) begin
|
| 225 |
+
byte_p_en <= 1'b0;
|
| 226 |
+
txbits <= {get_parity(BYTE_P), BYTE_P, 1'b0};
|
| 227 |
+
state <= S_TX;
|
| 228 |
+
end else begin
|
| 229 |
+
state <= S_IDLE;
|
| 230 |
+
end
|
| 231 |
+
txcnt <= 0;
|
| 232 |
+
cycle <= 1;
|
| 233 |
+
end
|
| 234 |
+
|
| 235 |
+
default : begin // S_TX
|
| 236 |
+
if (keep[0] == 1'b0) begin
|
| 237 |
+
data <= (data >> 8);
|
| 238 |
+
keep <= (keep >> 1);
|
| 239 |
+
end
|
| 240 |
+
if ( cycle < ((txcnt<=9) ? cycles[txcnt] : STOP_BIT_CYCLES) ) begin // cycle loop from 1 to ((txcnt<=9) ? cycles[txcnt] : STOP_BIT_CYCLES)
|
| 241 |
+
cycle <= cycle + 1;
|
| 242 |
+
end else begin
|
| 243 |
+
cycle <= 1;
|
| 244 |
+
txbits <= {1'b1, txbits[9:1]}; // right shift txbits, and fill '1' to MSB
|
| 245 |
+
if ( txcnt < (TOTAL_BITS-1) ) begin // txcnt loop from 0 to (TOTAL_BITS-1)
|
| 246 |
+
txcnt <= txcnt + 1;
|
| 247 |
+
end else begin
|
| 248 |
+
txcnt <= 0;
|
| 249 |
+
state <= S_PREPARE;
|
| 250 |
+
end
|
| 251 |
+
end
|
| 252 |
+
end
|
| 253 |
+
endcase
|
| 254 |
+
end
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 259 |
+
// generate UART output
|
| 260 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 261 |
+
initial o_uart_tx = 1'b1;
|
| 262 |
+
|
| 263 |
+
always @ (posedge clk or negedge rstn)
|
| 264 |
+
if (~rstn)
|
| 265 |
+
o_uart_tx <= 1'b1;
|
| 266 |
+
else
|
| 267 |
+
o_uart_tx <= (state == S_TX) ? txbits[0] : 1'b1;
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 272 |
+
// generate AXI-stream TREADY
|
| 273 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 274 |
+
assign f_tready = state[0]; // (state == S_IDLE)
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 279 |
+
// parameter checking
|
| 280 |
+
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 281 |
+
initial begin
|
| 282 |
+
if (BYTE_WIDTH <= 0) begin $error("invalid parameter : BYTE_WIDTH<=0"); $stop; end
|
| 283 |
+
if (STOP_BITS <= 0) begin $error("invalid parameter : STOP_BITS <=0"); $stop; end
|
| 284 |
+
if (BAUD_CYCLES < 1) begin $error("invalid parameter : BAUD_CYCLES < 1, please use a faster driving clock"); $stop; end
|
| 285 |
+
|
| 286 |
+
$display("uart_tx : parity = %s" , PARITY );
|
| 287 |
+
$display("uart_tx : clock period = %.0f ns (%-10d Hz)" , 1000000000.0/CLK_FREQ , CLK_FREQ );
|
| 288 |
+
$display("uart_tx : baud rate period = %.0f ns (%-10d Hz)" , 1000000000.0/BAUD_RATE , BAUD_RATE);
|
| 289 |
+
$display("uart_tx : baud cycles = %-10d" , BAUD_CYCLES );
|
| 290 |
+
$display("uart_tx : baud cycles frac = %-10d" , BAUD_CYCLES_FRAC );
|
| 291 |
+
|
| 292 |
+
if (PARITY == "ODD" || PARITY == "EVEN") begin
|
| 293 |
+
$display("uart_tx : __ ____ ____ ____ ____ ____ ____ ____ ____________ ");
|
| 294 |
+
$display("uart_tx : wave \\____/____X____X____X____X____X____X____X____X____/ ");
|
| 295 |
+
$display("uart_tx : bits | S | B0 | B1 | B2 | B3 | B4 | B5 | B6 | B7 | P | ");
|
| 296 |
+
$display("uart_tx : time_points t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 ");
|
| 297 |
+
$display("uart_tx :");
|
| 298 |
+
end else begin
|
| 299 |
+
$display("uart_tx : __ ____ ____ ____ ____ ____ ____ ____ _______ ");
|
| 300 |
+
$display("uart_tx : wave \\____/____X____X____X____X____X____X____X____/ ");
|
| 301 |
+
$display("uart_tx : bits | S | B0 | B1 | B2 | B3 | B4 | B5 | B6 | B7 | ");
|
| 302 |
+
$display("uart_tx : time_points t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 ");
|
| 303 |
+
$display("uart_tx :");
|
| 304 |
+
end
|
| 305 |
+
end
|
| 306 |
+
|
| 307 |
+
generate genvar index, i;
|
| 308 |
+
for (index=0; index<=9; index=index+1) begin : print_and_check_time
|
| 309 |
+
localparam cycles_acc = ( (index >= 0) ? (BAUD_CYCLES + (ADDITION_CYCLES[0] ? 1 : 0)) : 0 )
|
| 310 |
+
+ ( (index >= 1) ? (BAUD_CYCLES + (ADDITION_CYCLES[1] ? 1 : 0)) : 0 )
|
| 311 |
+
+ ( (index >= 2) ? (BAUD_CYCLES + (ADDITION_CYCLES[2] ? 1 : 0)) : 0 )
|
| 312 |
+
+ ( (index >= 3) ? (BAUD_CYCLES + (ADDITION_CYCLES[3] ? 1 : 0)) : 0 )
|
| 313 |
+
+ ( (index >= 4) ? (BAUD_CYCLES + (ADDITION_CYCLES[4] ? 1 : 0)) : 0 )
|
| 314 |
+
+ ( (index >= 5) ? (BAUD_CYCLES + (ADDITION_CYCLES[5] ? 1 : 0)) : 0 )
|
| 315 |
+
+ ( (index >= 6) ? (BAUD_CYCLES + (ADDITION_CYCLES[6] ? 1 : 0)) : 0 )
|
| 316 |
+
+ ( (index >= 7) ? (BAUD_CYCLES + (ADDITION_CYCLES[7] ? 1 : 0)) : 0 )
|
| 317 |
+
+ ( (index >= 8) ? (BAUD_CYCLES + (ADDITION_CYCLES[8] ? 1 : 0)) : 0 )
|
| 318 |
+
+ ( (index >= 9) ? (BAUD_CYCLES + (ADDITION_CYCLES[9] ? 1 : 0)) : 0 ) ;
|
| 319 |
+
|
| 320 |
+
localparam real ideal_time_ns = ((index+1)*1000000000.0/BAUD_RATE);
|
| 321 |
+
localparam real actual_time_ns = (cycles_acc*1000000000.0/CLK_FREQ);
|
| 322 |
+
localparam real error = (ideal_time_ns>actual_time_ns) ? (ideal_time_ns-actual_time_ns) : (-ideal_time_ns+actual_time_ns);
|
| 323 |
+
localparam real relative_error_percent = (error / (1000000000.0/BAUD_RATE)) * 100.0;
|
| 324 |
+
|
| 325 |
+
initial if (PARITY == "ODD" || PARITY == "EVEN" || index < 9) begin
|
| 326 |
+
$display("uart_tx : t%-2d- t0 = %.0f ns (ideal) %.0f ns (actual). error=%.0f ns relative_error=%.3f%%" ,
|
| 327 |
+
(index+1) ,
|
| 328 |
+
ideal_time_ns ,
|
| 329 |
+
actual_time_ns,
|
| 330 |
+
error,
|
| 331 |
+
relative_error_percent
|
| 332 |
+
);
|
| 333 |
+
|
| 334 |
+
if ( relative_error_percent > 3.0 ) begin $error("relative_error is too large"); $stop; end // if relative error larger than 3%
|
| 335 |
+
end
|
| 336 |
+
end
|
| 337 |
+
endgenerate
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
endmodule
|
WangXuan95_FPGA-NFC/SIM/tb_nfca_controller.v
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
//--------------------------------------------------------------------------------------------------------
|
| 3 |
+
// Module : tb_nfca_controller
|
| 4 |
+
// Type : simulation, top
|
| 5 |
+
// Standard: Verilog 2001 (IEEE1364-2001)
|
| 6 |
+
// Function: testbench for nfca_controller
|
| 7 |
+
// only a simulation for PCD-to-PICC,
|
| 8 |
+
// because there is no PICC model, it can not simulate PICC-to-PCD
|
| 9 |
+
//--------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
`timescale 1ps/1ps
|
| 12 |
+
|
| 13 |
+
module tb_nfca_controller ();
|
| 14 |
+
|
| 15 |
+
initial $dumpvars(0, tb_nfca_controller);
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
reg clk = 1'b0;
|
| 19 |
+
always #6000 clk = ~clk; // 81.36MHz approx.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
reg tx_tvalid = 1'b0;
|
| 23 |
+
wire tx_tready;
|
| 24 |
+
reg [7:0] tx_tdata = 0;
|
| 25 |
+
reg [3:0] tx_tdatab = 0;
|
| 26 |
+
reg tx_tlast = 0;
|
| 27 |
+
|
| 28 |
+
wire carrier_out;
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
nfca_controller nfca_controller_i (
|
| 32 |
+
.rstn ( 1'b1 ),
|
| 33 |
+
.clk ( clk ),
|
| 34 |
+
.tx_tvalid ( tx_tvalid ),
|
| 35 |
+
.tx_tready ( tx_tready ),
|
| 36 |
+
.tx_tdata ( tx_tdata ),
|
| 37 |
+
.tx_tdatab ( tx_tdatab ),
|
| 38 |
+
.tx_tlast ( tx_tlast ),
|
| 39 |
+
.rx_on ( ),
|
| 40 |
+
.rx_tvalid ( ),
|
| 41 |
+
.rx_tdata ( ),
|
| 42 |
+
.rx_tdatab ( ),
|
| 43 |
+
.rx_tend ( ),
|
| 44 |
+
.rx_terr ( ),
|
| 45 |
+
.adc_data_en ( 1'b0 ),
|
| 46 |
+
.adc_data ( 12'h0 ),
|
| 47 |
+
.carrier_out ( carrier_out )
|
| 48 |
+
);
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
task tx_frame;
|
| 52 |
+
input [255:0] data_array;
|
| 53 |
+
input integer byte_len;
|
| 54 |
+
input [ 3:0] datab;
|
| 55 |
+
integer ii;
|
| 56 |
+
begin
|
| 57 |
+
$display("PCD-to-PICC: %d Bytes", byte_len);
|
| 58 |
+
{tx_tvalid, tx_tdata, tx_tdatab, tx_tlast} <= 0;
|
| 59 |
+
@ (posedge clk);
|
| 60 |
+
for (ii=0; ii<byte_len; ii=ii+1) begin
|
| 61 |
+
tx_tvalid <= 1'b1;
|
| 62 |
+
tx_tdata <= data_array[8*ii+:8];
|
| 63 |
+
tx_tdatab <= ii+1 == byte_len ? datab : 4'd8;
|
| 64 |
+
tx_tlast <= ii+1 == byte_len;
|
| 65 |
+
@ (posedge clk);
|
| 66 |
+
while(~tx_tready) @ (posedge clk);
|
| 67 |
+
end
|
| 68 |
+
{tx_tvalid, tx_tdata, tx_tdatab, tx_tlast} <= 0;
|
| 69 |
+
end
|
| 70 |
+
endtask
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
initial begin
|
| 74 |
+
tx_frame(256'h00_00_00_26, 1, 4'd8);
|
| 75 |
+
tx_frame(256'h00_00_34_12, 2, 4'd8);
|
| 76 |
+
tx_frame(256'h00_12_34_12, 3, 4'd6);
|
| 77 |
+
tx_frame(256'h00_12_56_93, 3, 4'd7);
|
| 78 |
+
tx_frame(256'h34_12_56_93, 4, 4'd1);
|
| 79 |
+
tx_frame(256'h34_12_70_95, 4, 4'd8);
|
| 80 |
+
tx_frame(256'h34_12_6f_95, 4, 4'd8);
|
| 81 |
+
|
| 82 |
+
@ (posedge clk);
|
| 83 |
+
while(~tx_tready) @ (posedge clk);
|
| 84 |
+
repeat(10000) @ (posedge clk);
|
| 85 |
+
$finish;
|
| 86 |
+
end
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
endmodule
|
| 90 |
+
|
aquaxis_IPCORE/README.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
IPCORE
|
| 2 |
+
======
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.model/cjpeg.c
ADDED
|
@@ -0,0 +1,728 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2005-2014 H.Ishihara
|
| 3 |
+
*
|
| 4 |
+
* License: The Open Software License 3.0
|
| 5 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 6 |
+
*
|
| 7 |
+
* For further information please contact.
|
| 8 |
+
* http://www.aquaxis.com/
|
| 9 |
+
* info(at)aquaxis.com or hidemi(at)sweetcafe.jp
|
| 10 |
+
*/
|
| 11 |
+
#include <stdio.h>
|
| 12 |
+
#include <stdlib.h>
|
| 13 |
+
#include <string.h>
|
| 14 |
+
|
| 15 |
+
static struct APP0infotype {
|
| 16 |
+
unsigned short int marker; // = 0xFFE0
|
| 17 |
+
unsigned short int length; // = 16 for usual JPEG, no thumbnail
|
| 18 |
+
unsigned char JFIFsignature[5]; // = "JFIF",'\0'
|
| 19 |
+
unsigned char versionhi; // 1
|
| 20 |
+
unsigned char versionlo; // 1
|
| 21 |
+
unsigned char xyunits; // 0 = no units, normal density
|
| 22 |
+
unsigned short int xdensity; // 1
|
| 23 |
+
unsigned short int ydensity; // 1
|
| 24 |
+
unsigned char thumbnwidth; // 0
|
| 25 |
+
unsigned char thumbnheight; // 0
|
| 26 |
+
} APP0info={0xFFE0,16,'J','F','I','F',0,1,1,0,1,1,0,0};
|
| 27 |
+
|
| 28 |
+
static struct SOF0infotype {
|
| 29 |
+
unsigned short int marker; // = 0xFFC0
|
| 30 |
+
unsigned short int length; // = 17 for a truecolor YCbCr JPG
|
| 31 |
+
unsigned char precision ; // Should be 8: 8 bits/sample
|
| 32 |
+
unsigned short int height ;
|
| 33 |
+
unsigned short int width;
|
| 34 |
+
unsigned char nrofcomponents; //Should be 3: We encode a truecolor JPG
|
| 35 |
+
unsigned char IdY; // = 1
|
| 36 |
+
unsigned char HVY; // sampling factors for Y
|
| 37 |
+
// (bit 0-3 vert., 4-7 hor.)
|
| 38 |
+
unsigned char QTY; // Quantization Table number for Y = 0
|
| 39 |
+
unsigned char IdCb; // = 2
|
| 40 |
+
unsigned char HVCb;
|
| 41 |
+
unsigned char QTCb; // 1
|
| 42 |
+
unsigned char IdCr; // = 3
|
| 43 |
+
unsigned char HVCr;
|
| 44 |
+
unsigned char QTCr; // Normally equal to QTCb = 1
|
| 45 |
+
} SOF0info = { 0xFFC0,17,8,0,0,3,1,0x22,0,2,0x11,1,3,0x11,1};
|
| 46 |
+
// Default sampling factors are 1,1 for every image component: No downsampling
|
| 47 |
+
|
| 48 |
+
static struct DQTinfotype {
|
| 49 |
+
unsigned short int marker; // = 0xFFDB
|
| 50 |
+
unsigned short int length; // = 132
|
| 51 |
+
unsigned char QTYinfo; // = 0: bit 0..3: number of QT = 0
|
| 52 |
+
// (table for Y)
|
| 53 |
+
// bit 4..7: precision of QT, 0 = 8 bit
|
| 54 |
+
unsigned char Ytable[64];
|
| 55 |
+
unsigned char QTCbinfo; // = 1 (quantization table for Cb,Cr}
|
| 56 |
+
unsigned char Cbtable[64];
|
| 57 |
+
} DQTinfo;
|
| 58 |
+
// Ytable from DQTinfo should be equal to a scaled and zizag reordered version
|
| 59 |
+
// of the table which can be found in "tables.h": std_luminance_qt
|
| 60 |
+
// Cbtable , similar = std_chrominance_qt
|
| 61 |
+
// We'll init them in the program using set_DQTinfo function
|
| 62 |
+
|
| 63 |
+
static struct DHTinfotype {
|
| 64 |
+
unsigned short int marker; // = 0xFFC4
|
| 65 |
+
unsigned short int length; //0x01A2
|
| 66 |
+
unsigned char HTYDCinfo; // bit 0..3: number of HT (0..3), for Y =0
|
| 67 |
+
//bit 4 :type of HT, 0 = DC table,1 = AC table
|
| 68 |
+
//bit 5..7: not used, must be 0
|
| 69 |
+
unsigned char YDC_nrcodes[16]; //at index i = nr of codes with length i
|
| 70 |
+
unsigned char YDC_values[12];
|
| 71 |
+
unsigned char HTYACinfo; // = 0x10
|
| 72 |
+
unsigned char YAC_nrcodes[16];
|
| 73 |
+
unsigned char YAC_values[162]; //we'll use the standard Huffman tables
|
| 74 |
+
unsigned char HTCbDCinfo; // = 1
|
| 75 |
+
unsigned char CbDC_nrcodes[16];
|
| 76 |
+
unsigned char CbDC_values[12];
|
| 77 |
+
unsigned char HTCbACinfo; // = 0x11
|
| 78 |
+
unsigned char CbAC_nrcodes[16];
|
| 79 |
+
unsigned char CbAC_values[162];
|
| 80 |
+
} DHTinfo;
|
| 81 |
+
|
| 82 |
+
static struct SOSinfotype {
|
| 83 |
+
unsigned short int marker; // = 0xFFDA
|
| 84 |
+
unsigned short int length; // = 12
|
| 85 |
+
unsigned char nrofcomponents; // Should be 3: truecolor JPG
|
| 86 |
+
unsigned char IdY; //1
|
| 87 |
+
unsigned char HTY; //0 // bits 0..3: AC table (0..3)
|
| 88 |
+
// bits 4..7: DC table (0..3)
|
| 89 |
+
unsigned char IdCb; //2
|
| 90 |
+
unsigned char HTCb; //0x11
|
| 91 |
+
unsigned char IdCr; //3
|
| 92 |
+
unsigned char HTCr; //0x11
|
| 93 |
+
unsigned char Ss,Se,Bf; // not interesting, they should be 0,63,0
|
| 94 |
+
} SOSinfo={0xFFDA,12,3,1,0,2,0x11,3,0x11,0,0x3F,0};
|
| 95 |
+
|
| 96 |
+
typedef struct { unsigned char length; unsigned short int value;} bitstring;
|
| 97 |
+
|
| 98 |
+
#define Y(R,G,B) ((unsigned char)( (YRtab[(R)]+YGtab[(G)]+YBtab[(B)])>>16 ) - 128)
|
| 99 |
+
#define Cb(R,G,B) ((unsigned char)( (CbRtab[(R)]+CbGtab[(G)]+CbBtab[(B)])>>16 ) )
|
| 100 |
+
#define Cr(R,G,B) ((unsigned char)( (CrRtab[(R)]+CrGtab[(G)]+CrBtab[(B)])>>16 ) )
|
| 101 |
+
|
| 102 |
+
#define writebyte(b) fputc((b),fp_jpeg_stream)
|
| 103 |
+
#define writeword(w) writebyte((w)/256);writebyte((w)%256);
|
| 104 |
+
|
| 105 |
+
static unsigned char zigzag[64]={
|
| 106 |
+
0, 1, 5, 6,14,15,27,28,
|
| 107 |
+
2, 4, 7,13,16,26,29,42,
|
| 108 |
+
3, 8,12,17,25,30,41,43,
|
| 109 |
+
9,11,18,24,31,40,44,53,
|
| 110 |
+
10,19,23,32,39,45,52,54,
|
| 111 |
+
20,22,33,38,46,51,55,60,
|
| 112 |
+
21,34,37,47,50,56,59,61,
|
| 113 |
+
35,36,48,49,57,58,62,63
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
/* These are the sample quantization tables given in JPEG spec section K.1.
|
| 117 |
+
The spec says that the values given produce "good" quality, and
|
| 118 |
+
when divided by 2, "very good" quality.*/
|
| 119 |
+
static unsigned char DQT_Y[64] = {
|
| 120 |
+
0x08, 0x06, 0x06, 0x07, 0x06, 0x05, 0x08, 0x07,
|
| 121 |
+
0x07, 0x07, 0x09, 0x09, 0x08, 0x0a, 0x0c, 0x14,
|
| 122 |
+
0x0d, 0x0c, 0x0b, 0x0b, 0x0c, 0x19, 0x12, 0x13,
|
| 123 |
+
0x0f, 0x14, 0x1d, 0x1a, 0x1f, 0x1e, 0x1d, 0x1a,
|
| 124 |
+
0x1c, 0x1c, 0x20, 0x24, 0x2e, 0x27, 0x20, 0x22,
|
| 125 |
+
0x2c, 0x23, 0x1c, 0x1c, 0x28, 0x37, 0x29, 0x2c,
|
| 126 |
+
0x30, 0x31, 0x34, 0x34, 0x34, 0x1f, 0x27, 0x39,
|
| 127 |
+
0x3d, 0x38, 0x32, 0x3c, 0x2e, 0x33, 0x34, 0x32
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
static unsigned char DQT_C[64] = {
|
| 131 |
+
0x09, 0x09, 0x09, 0x0c, 0x0b, 0x0c, 0x18, 0x0d,
|
| 132 |
+
0x0d, 0x18, 0x32, 0x21, 0x1c, 0x21, 0x32, 0x32,
|
| 133 |
+
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
|
| 134 |
+
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
|
| 135 |
+
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
|
| 136 |
+
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
|
| 137 |
+
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
|
| 138 |
+
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
static unsigned char std_luminance_qt[64] = {
|
| 142 |
+
16, 11, 10, 16, 24, 40, 51, 61,
|
| 143 |
+
12, 12, 14, 19, 26, 58, 60, 55,
|
| 144 |
+
14, 13, 16, 24, 40, 57, 69, 56,
|
| 145 |
+
14, 17, 22, 29, 51, 87, 80, 62,
|
| 146 |
+
18, 22, 37, 56, 68, 109, 103, 77,
|
| 147 |
+
24, 35, 55, 64, 81, 104, 113, 92,
|
| 148 |
+
49, 64, 78, 87, 103, 121, 120, 101,
|
| 149 |
+
72, 92, 95, 98, 112, 100, 103, 99
|
| 150 |
+
};
|
| 151 |
+
static unsigned char std_chrominance_qt[64] = {
|
| 152 |
+
17, 18, 24, 47, 99, 99, 99, 99,
|
| 153 |
+
18, 21, 26, 66, 99, 99, 99, 99,
|
| 154 |
+
24, 26, 56, 99, 99, 99, 99, 99,
|
| 155 |
+
47, 66, 99, 99, 99, 99, 99, 99,
|
| 156 |
+
99, 99, 99, 99, 99, 99, 99, 99,
|
| 157 |
+
99, 99, 99, 99, 99, 99, 99, 99,
|
| 158 |
+
99, 99, 99, 99, 99, 99, 99, 99,
|
| 159 |
+
99, 99, 99, 99, 99, 99, 99, 99
|
| 160 |
+
};
|
| 161 |
+
// Standard Huffman tables (cf. JPEG standard section K.3) */
|
| 162 |
+
|
| 163 |
+
static unsigned char std_dc_luminance_nrcodes[17]={0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0};
|
| 164 |
+
static unsigned char std_dc_luminance_values[12]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
| 165 |
+
|
| 166 |
+
static unsigned char std_dc_chrominance_nrcodes[17]={0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0};
|
| 167 |
+
static unsigned char std_dc_chrominance_values[12]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
| 168 |
+
|
| 169 |
+
static unsigned char std_ac_luminance_nrcodes[17]={0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d };
|
| 170 |
+
static unsigned char std_ac_luminance_values[162]= {
|
| 171 |
+
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
|
| 172 |
+
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
|
| 173 |
+
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
|
| 174 |
+
0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
|
| 175 |
+
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
|
| 176 |
+
0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
|
| 177 |
+
0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
|
| 178 |
+
0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
|
| 179 |
+
0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
|
| 180 |
+
0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
|
| 181 |
+
0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
|
| 182 |
+
0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
|
| 183 |
+
0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
|
| 184 |
+
0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
| 185 |
+
0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
|
| 186 |
+
0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
|
| 187 |
+
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
|
| 188 |
+
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
|
| 189 |
+
0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
|
| 190 |
+
0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
| 191 |
+
0xf9, 0xfa };
|
| 192 |
+
|
| 193 |
+
static unsigned char std_ac_chrominance_nrcodes[17]={0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77};
|
| 194 |
+
static unsigned char std_ac_chrominance_values[162]={
|
| 195 |
+
0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
|
| 196 |
+
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
|
| 197 |
+
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
|
| 198 |
+
0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
|
| 199 |
+
0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
|
| 200 |
+
0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
|
| 201 |
+
0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
|
| 202 |
+
0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
|
| 203 |
+
0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
|
| 204 |
+
0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
|
| 205 |
+
0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
|
| 206 |
+
0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
| 207 |
+
0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
|
| 208 |
+
0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
|
| 209 |
+
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
|
| 210 |
+
0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
|
| 211 |
+
0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
|
| 212 |
+
0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
|
| 213 |
+
0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
|
| 214 |
+
0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
| 215 |
+
0xf9, 0xfa };
|
| 216 |
+
|
| 217 |
+
static unsigned char bytenew=0; // The byte that will be written in the JPG file
|
| 218 |
+
static signed char bytepos=7; //bit position in the byte we write (bytenew)
|
| 219 |
+
//should be<=7 and >=0
|
| 220 |
+
static unsigned short int mask[16]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
|
| 221 |
+
|
| 222 |
+
// The Huffman tables we'll use:
|
| 223 |
+
static bitstring YDC_HT[12];
|
| 224 |
+
static bitstring CbDC_HT[12];
|
| 225 |
+
static bitstring YAC_HT[256];
|
| 226 |
+
static bitstring CbAC_HT[256];
|
| 227 |
+
|
| 228 |
+
static unsigned char *category_alloc;
|
| 229 |
+
static unsigned char *category; //Here we'll keep the category of the numbers in range: -32767..32767
|
| 230 |
+
static bitstring *bitcode_alloc;
|
| 231 |
+
static bitstring *bitcode; // their bitcoded representation
|
| 232 |
+
|
| 233 |
+
static unsigned char *buffer; //image to be encoded
|
| 234 |
+
unsigned short int Ximage,Yimage;// image dimensions divisible by 8
|
| 235 |
+
|
| 236 |
+
// Data Unit YCbCr
|
| 237 |
+
static signed char DU_Y[256];
|
| 238 |
+
static signed char DU_Cb[64];
|
| 239 |
+
static signed char DU_Cr[64];
|
| 240 |
+
|
| 241 |
+
static signed short int DU_DCT[64]; // Current DU (after DCT and quantization) which we'll zigzag
|
| 242 |
+
|
| 243 |
+
static signed short int DU[64]; //zigzag reordered DU which will be Huffman coded
|
| 244 |
+
|
| 245 |
+
FILE *fp_jpeg_stream;
|
| 246 |
+
|
| 247 |
+
void write_APP0info(){
|
| 248 |
+
//Nothing to overwrite for APP0info
|
| 249 |
+
writeword(APP0info.marker);
|
| 250 |
+
writeword(APP0info.length);
|
| 251 |
+
writebyte('J');writebyte('F');writebyte('I');writebyte('F');writebyte(0);
|
| 252 |
+
writebyte(APP0info.versionhi);
|
| 253 |
+
writebyte(APP0info.versionlo);
|
| 254 |
+
writebyte(APP0info.xyunits);
|
| 255 |
+
writeword(APP0info.xdensity);
|
| 256 |
+
writeword(APP0info.ydensity);
|
| 257 |
+
writebyte(APP0info.thumbnwidth);
|
| 258 |
+
writebyte(APP0info.thumbnheight);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
void write_SOF0info(){
|
| 262 |
+
// We should overwrite width and height
|
| 263 |
+
writeword(SOF0info.marker);
|
| 264 |
+
writeword(SOF0info.length);
|
| 265 |
+
writebyte(SOF0info.precision);
|
| 266 |
+
writeword(SOF0info.height);
|
| 267 |
+
writeword(SOF0info.width);
|
| 268 |
+
writebyte(SOF0info.nrofcomponents);
|
| 269 |
+
writebyte(SOF0info.IdY);
|
| 270 |
+
writebyte(SOF0info.HVY);
|
| 271 |
+
writebyte(SOF0info.QTY);
|
| 272 |
+
writebyte(SOF0info.IdCb);
|
| 273 |
+
writebyte(SOF0info.HVCb);
|
| 274 |
+
writebyte(SOF0info.QTCb);
|
| 275 |
+
writebyte(SOF0info.IdCr);
|
| 276 |
+
writebyte(SOF0info.HVCr);
|
| 277 |
+
writebyte(SOF0info.QTCr);
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
void write_DQTinfo(){
|
| 281 |
+
unsigned char i;
|
| 282 |
+
writeword(DQTinfo.marker);
|
| 283 |
+
writeword(DQTinfo.length);
|
| 284 |
+
writebyte(DQTinfo.QTYinfo);
|
| 285 |
+
for (i=0;i<64;i++) writebyte(DQTinfo.Ytable[i]);
|
| 286 |
+
writebyte(DQTinfo.QTCbinfo);
|
| 287 |
+
for (i=0;i<64;i++) writebyte(DQTinfo.Cbtable[i]);
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
void set_DQTinfo(){
|
| 291 |
+
int i;
|
| 292 |
+
DQTinfo.marker=0xFFDB;
|
| 293 |
+
DQTinfo.length=132;
|
| 294 |
+
DQTinfo.QTYinfo=0;
|
| 295 |
+
DQTinfo.QTCbinfo=1;
|
| 296 |
+
for(i=0;i<64;i++) DQTinfo.Ytable[i] = DQT_Y[i];
|
| 297 |
+
for(i=0;i<64;i++) DQTinfo.Cbtable[i] = DQT_C[i];
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
void write_DHTinfo(){
|
| 301 |
+
unsigned char i;
|
| 302 |
+
writeword(DHTinfo.marker);
|
| 303 |
+
writeword(DHTinfo.length);
|
| 304 |
+
writebyte(DHTinfo.HTYDCinfo);
|
| 305 |
+
for (i=0;i<16;i++) writebyte(DHTinfo.YDC_nrcodes[i]);
|
| 306 |
+
for (i=0;i<=11;i++) writebyte(DHTinfo.YDC_values[i]);
|
| 307 |
+
writebyte(DHTinfo.HTYACinfo);
|
| 308 |
+
for (i=0;i<16;i++) writebyte(DHTinfo.YAC_nrcodes[i]);
|
| 309 |
+
for (i=0;i<=161;i++) writebyte(DHTinfo.YAC_values[i]);
|
| 310 |
+
writebyte(DHTinfo.HTCbDCinfo);
|
| 311 |
+
for (i=0;i<16;i++) writebyte(DHTinfo.CbDC_nrcodes[i]);
|
| 312 |
+
for (i=0;i<=11;i++) writebyte(DHTinfo.CbDC_values[i]);
|
| 313 |
+
writebyte(DHTinfo.HTCbACinfo);
|
| 314 |
+
for (i=0;i<16;i++) writebyte(DHTinfo.CbAC_nrcodes[i]);
|
| 315 |
+
for (i=0;i<=161;i++) writebyte(DHTinfo.CbAC_values[i]);
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
void set_DHTinfo(){
|
| 319 |
+
unsigned char i;
|
| 320 |
+
DHTinfo.marker=0xFFC4;
|
| 321 |
+
DHTinfo.length=0x01A2;
|
| 322 |
+
DHTinfo.HTYDCinfo=0;
|
| 323 |
+
for (i=0;i<16;i++) DHTinfo.YDC_nrcodes[i]=std_dc_luminance_nrcodes[i+1];
|
| 324 |
+
for (i=0;i<=11;i++) DHTinfo.YDC_values[i]=std_dc_luminance_values[i];
|
| 325 |
+
DHTinfo.HTYACinfo=0x10;
|
| 326 |
+
for (i=0;i<16;i++) DHTinfo.YAC_nrcodes[i]=std_ac_luminance_nrcodes[i+1];
|
| 327 |
+
for (i=0;i<=161;i++) DHTinfo.YAC_values[i]=std_ac_luminance_values[i];
|
| 328 |
+
DHTinfo.HTCbDCinfo=1;
|
| 329 |
+
for (i=0;i<16;i++) DHTinfo.CbDC_nrcodes[i]=std_dc_chrominance_nrcodes[i+1];
|
| 330 |
+
for (i=0;i<=11;i++) DHTinfo.CbDC_values[i]=std_dc_chrominance_values[i];
|
| 331 |
+
DHTinfo.HTCbACinfo=0x11;
|
| 332 |
+
for (i=0;i<16;i++) DHTinfo.CbAC_nrcodes[i]=std_ac_chrominance_nrcodes[i+1];
|
| 333 |
+
for (i=0;i<=161;i++) DHTinfo.CbAC_values[i]=std_ac_chrominance_values[i];
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
void write_SOSinfo(){
|
| 337 |
+
//Nothing to overwrite for SOSinfo
|
| 338 |
+
writeword(SOSinfo.marker);
|
| 339 |
+
writeword(SOSinfo.length);
|
| 340 |
+
writebyte(SOSinfo.nrofcomponents);
|
| 341 |
+
writebyte(SOSinfo.IdY);
|
| 342 |
+
writebyte(SOSinfo.HTY);
|
| 343 |
+
writebyte(SOSinfo.IdCb);
|
| 344 |
+
writebyte(SOSinfo.HTCb);
|
| 345 |
+
writebyte(SOSinfo.IdCr);
|
| 346 |
+
writebyte(SOSinfo.HTCr);
|
| 347 |
+
writebyte(SOSinfo.Ss);
|
| 348 |
+
writebyte(SOSinfo.Se);
|
| 349 |
+
writebyte(SOSinfo.Bf);
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
void writebits(bitstring bs){
|
| 353 |
+
unsigned short int value;
|
| 354 |
+
signed char posval;
|
| 355 |
+
value=bs.value;
|
| 356 |
+
posval=bs.length-1;
|
| 357 |
+
while(posval>=0){
|
| 358 |
+
if(value & mask[posval]) bytenew|=mask[bytepos];
|
| 359 |
+
posval--;bytepos--;
|
| 360 |
+
if(bytepos<0) {
|
| 361 |
+
if(bytenew==0xFF) {
|
| 362 |
+
writebyte(0xFF);
|
| 363 |
+
writebyte(0);
|
| 364 |
+
}else{
|
| 365 |
+
writebyte(bytenew);
|
| 366 |
+
}
|
| 367 |
+
bytepos=7;
|
| 368 |
+
bytenew=0;
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
void compute_Huffman_table(unsigned char *nrcodes,unsigned char *std_table,bitstring *HT){
|
| 374 |
+
unsigned char k,j;
|
| 375 |
+
unsigned char pos_in_table;
|
| 376 |
+
unsigned short int codevalue;
|
| 377 |
+
codevalue=0; pos_in_table=0;
|
| 378 |
+
for (k=1;k<=16;k++){
|
| 379 |
+
for (j=1;j<=nrcodes[k];j++) {
|
| 380 |
+
HT[std_table[pos_in_table]].value=codevalue;
|
| 381 |
+
HT[std_table[pos_in_table]].length=k;
|
| 382 |
+
pos_in_table++;
|
| 383 |
+
codevalue++;
|
| 384 |
+
}
|
| 385 |
+
codevalue*=2;
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
void init_Huffman_tables(){
|
| 389 |
+
compute_Huffman_table(std_dc_luminance_nrcodes,std_dc_luminance_values,YDC_HT);
|
| 390 |
+
compute_Huffman_table(std_dc_chrominance_nrcodes,std_dc_chrominance_values,CbDC_HT);
|
| 391 |
+
compute_Huffman_table(std_ac_luminance_nrcodes,std_ac_luminance_values,YAC_HT);
|
| 392 |
+
compute_Huffman_table(std_ac_chrominance_nrcodes,std_ac_chrominance_values,CbAC_HT);
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
void set_numbers_category_and_bitcode(){
|
| 396 |
+
signed long int nr;
|
| 397 |
+
signed long int nrlower,nrupper;
|
| 398 |
+
unsigned char cat,value;
|
| 399 |
+
|
| 400 |
+
category_alloc=(unsigned char *)malloc(65535*sizeof(unsigned char));
|
| 401 |
+
category=category_alloc+32767; //allow negative subscripts
|
| 402 |
+
bitcode_alloc=(bitstring *)malloc(65535*sizeof(bitstring));
|
| 403 |
+
bitcode=bitcode_alloc+32767;
|
| 404 |
+
nrlower=1;nrupper=2;
|
| 405 |
+
for (cat=1;cat<=15;cat++) {
|
| 406 |
+
//Positive numbers
|
| 407 |
+
for (nr=nrlower;nr<nrupper;nr++){
|
| 408 |
+
category[nr]=cat;
|
| 409 |
+
bitcode[nr].length=cat;
|
| 410 |
+
bitcode[nr].value=(unsigned short int)nr;
|
| 411 |
+
}
|
| 412 |
+
//Negative numbers
|
| 413 |
+
for (nr=-(nrupper-1);nr<=-nrlower;nr++){
|
| 414 |
+
category[nr]=cat;
|
| 415 |
+
bitcode[nr].length=cat;
|
| 416 |
+
bitcode[nr].value=(unsigned short int)(nrupper-1+nr);
|
| 417 |
+
}
|
| 418 |
+
nrlower<<=1;
|
| 419 |
+
nrupper<<=1;
|
| 420 |
+
}
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
void DCT(signed char *data,unsigned char *fdtbl,signed short int *outdata){
|
| 424 |
+
double aanscalefactor[8] = {1.0, 1.387039845, 1.306562965, 1.175875602,
|
| 425 |
+
1.0, 0.785694958, 0.541196100, 0.275899379};
|
| 426 |
+
float tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
| 427 |
+
float tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17, tmp18, tmp19;
|
| 428 |
+
float z1, z2, z3, z4, z5, z11, z13;
|
| 429 |
+
float *dataptr;
|
| 430 |
+
float datafloat[64];
|
| 431 |
+
float temp;
|
| 432 |
+
signed char ctr;
|
| 433 |
+
unsigned char i;
|
| 434 |
+
for (i=0;i<64;i++) datafloat[i]=data[i];
|
| 435 |
+
|
| 436 |
+
/* Pass 1: process rows. */
|
| 437 |
+
dataptr=datafloat;
|
| 438 |
+
for (ctr = 7; ctr >= 0; ctr--) {
|
| 439 |
+
tmp0 = dataptr[0] + dataptr[7];
|
| 440 |
+
tmp7 = dataptr[0] - dataptr[7];
|
| 441 |
+
tmp1 = dataptr[1] + dataptr[6];
|
| 442 |
+
tmp6 = dataptr[1] - dataptr[6];
|
| 443 |
+
tmp2 = dataptr[2] + dataptr[5];
|
| 444 |
+
tmp5 = dataptr[2] - dataptr[5];
|
| 445 |
+
tmp3 = dataptr[3] + dataptr[4];
|
| 446 |
+
tmp4 = dataptr[3] - dataptr[4];
|
| 447 |
+
|
| 448 |
+
// Phase 2
|
| 449 |
+
tmp10 = tmp0 + tmp3;
|
| 450 |
+
tmp13 = tmp0 - tmp3;
|
| 451 |
+
tmp11 = tmp1 + tmp2;
|
| 452 |
+
tmp12 = tmp1 - tmp2;
|
| 453 |
+
tmp14 = (tmp4 + tmp5) * ((float) 0.923879533);
|
| 454 |
+
tmp15 = (tmp4 + tmp5) * ((float) 0.382683432);
|
| 455 |
+
tmp16 = (tmp6 + tmp7) * ((float) 0.382683432);
|
| 456 |
+
tmp17 = (tmp6 + tmp7) * ((float) 0.923879533) ;
|
| 457 |
+
tmp18 = tmp7;
|
| 458 |
+
tmp19 = (tmp5 + tmp6) * ((float) 0.707106781);
|
| 459 |
+
|
| 460 |
+
// Phase 3
|
| 461 |
+
dataptr[0] = (tmp10 + tmp11) / aanscalefactor[0];
|
| 462 |
+
dataptr[4] = (tmp10 - tmp11) / aanscalefactor[1];
|
| 463 |
+
z1 = (tmp12 + tmp13) * ((float) 0.707106781);
|
| 464 |
+
z2 = tmp14 - tmp16;
|
| 465 |
+
z4 = tmp15 + tmp17;
|
| 466 |
+
z11 = tmp18 + tmp19;
|
| 467 |
+
z13 = tmp18 - tmp19;
|
| 468 |
+
|
| 469 |
+
// Phase 4
|
| 470 |
+
dataptr[2] = (tmp13 + z1) / aanscalefactor[2];
|
| 471 |
+
dataptr[6] = (tmp13 - z1) / aanscalefactor[6];
|
| 472 |
+
dataptr[5] = (z13 + z2) / aanscalefactor[5];
|
| 473 |
+
dataptr[3] = (z13 - z2) / aanscalefactor[3];
|
| 474 |
+
dataptr[1] = (z11 + z4) / aanscalefactor[1];
|
| 475 |
+
dataptr[7] = (z11 - z4) / aanscalefactor[7];
|
| 476 |
+
|
| 477 |
+
dataptr += 8;
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
/* Pass 2: process columns. */
|
| 481 |
+
|
| 482 |
+
dataptr -= 64;
|
| 483 |
+
for (ctr = 7; ctr >= 0; ctr--) {
|
| 484 |
+
tmp0 = dataptr[0] + dataptr[56];
|
| 485 |
+
tmp7 = dataptr[0] - dataptr[56];
|
| 486 |
+
tmp1 = dataptr[8] + dataptr[48];
|
| 487 |
+
tmp6 = dataptr[8] - dataptr[48];
|
| 488 |
+
tmp2 = dataptr[16] + dataptr[40];
|
| 489 |
+
tmp5 = dataptr[16] - dataptr[40];
|
| 490 |
+
tmp3 = dataptr[24] + dataptr[32];
|
| 491 |
+
tmp4 = dataptr[24] - dataptr[32];
|
| 492 |
+
|
| 493 |
+
// Phase 2
|
| 494 |
+
tmp10 = tmp0 + tmp3;
|
| 495 |
+
tmp13 = tmp0 - tmp3;
|
| 496 |
+
tmp11 = tmp1 + tmp2;
|
| 497 |
+
tmp12 = tmp1 - tmp2;
|
| 498 |
+
tmp14 = (tmp4 + tmp5) * ((float) 0.923879533);
|
| 499 |
+
tmp15 = (tmp4 + tmp5) * ((float) 0.382683432);
|
| 500 |
+
tmp16 = (tmp6 + tmp7) * ((float) 0.382683432);
|
| 501 |
+
tmp17 = (tmp6 + tmp7) * ((float) 0.923879533) ;
|
| 502 |
+
tmp18 = tmp7;
|
| 503 |
+
tmp19 = (tmp5 + tmp6) * ((float) 0.707106781);
|
| 504 |
+
|
| 505 |
+
// Phase 3
|
| 506 |
+
dataptr[ 0] = (tmp10 + tmp11) / aanscalefactor[0];
|
| 507 |
+
dataptr[32] = (tmp10 - tmp11) / aanscalefactor[1];
|
| 508 |
+
z1 = (tmp12 + tmp13) * ((float) 0.707106781);
|
| 509 |
+
z2 = tmp14 - tmp16;
|
| 510 |
+
z4 = tmp15 + tmp17;
|
| 511 |
+
z11 = tmp18 + tmp19;
|
| 512 |
+
z13 = tmp18 - tmp19;
|
| 513 |
+
|
| 514 |
+
// Phase 4
|
| 515 |
+
dataptr[16] = (tmp13 + z1) / aanscalefactor[2];
|
| 516 |
+
dataptr[48] = (tmp13 - z1) / aanscalefactor[6];
|
| 517 |
+
dataptr[40] = (z13 + z2) / aanscalefactor[5];
|
| 518 |
+
dataptr[24] = (z13 - z2) / aanscalefactor[3];
|
| 519 |
+
dataptr[ 8] = (z11 + z4) / aanscalefactor[1];
|
| 520 |
+
dataptr[56] = (z11 - z4) / aanscalefactor[7];
|
| 521 |
+
|
| 522 |
+
dataptr ++;
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
// DQT
|
| 526 |
+
for (i = 0; i < 64; i++) {
|
| 527 |
+
temp = datafloat[i] / (float)((double) fdtbl[zigzag[i]] * 8.0);
|
| 528 |
+
outdata[i] = (signed short int) ((signed short int)(temp + 16384.5) - 16384);
|
| 529 |
+
}
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
void process_DU(signed char *ComponentDU,unsigned char *fdtbl,
|
| 533 |
+
signed short int *DC,
|
| 534 |
+
bitstring *HTDC,bitstring *HTAC){
|
| 535 |
+
unsigned char i;
|
| 536 |
+
unsigned char startpos;
|
| 537 |
+
unsigned char end0pos;
|
| 538 |
+
unsigned char nrzeroes;
|
| 539 |
+
unsigned char nrmarker;
|
| 540 |
+
signed short int Diff;
|
| 541 |
+
|
| 542 |
+
DCT(ComponentDU,fdtbl,DU_DCT);
|
| 543 |
+
// ��������
|
| 544 |
+
for (i=0;i<=63;i++) DU[zigzag[i]]=DU_DCT[i];
|
| 545 |
+
Diff=DU[0]-*DC;
|
| 546 |
+
*DC=DU[0];
|
| 547 |
+
// DC��ʬ�Υ�����
|
| 548 |
+
if (Diff==0) writebits(HTDC[0]); //Diff might be 0
|
| 549 |
+
else {
|
| 550 |
+
writebits(HTDC[category[Diff]]);
|
| 551 |
+
writebits(bitcode[Diff]);
|
| 552 |
+
}
|
| 553 |
+
// AC��ʬ�Υ�����
|
| 554 |
+
// 0�ο���դ��������
|
| 555 |
+
for (end0pos=63;(end0pos>0)&&(DU[end0pos]==0);end0pos--) ;
|
| 556 |
+
if (end0pos==0) {
|
| 557 |
+
// ����0�ʤ�EOB(����ɥ��֥֥��å�)�����
|
| 558 |
+
writebits(HTAC[0x00]);
|
| 559 |
+
return;
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
i=1;
|
| 563 |
+
while (i<=end0pos){
|
| 564 |
+
startpos=i;
|
| 565 |
+
for (; (DU[i]==0)&&(i<=end0pos);i++) ;
|
| 566 |
+
nrzeroes=i-startpos;
|
| 567 |
+
if (nrzeroes>=16) {
|
| 568 |
+
// 0��16�İʾ�³������0��16�ĥ����ɤ���Ϥ���
|
| 569 |
+
for (nrmarker=1;nrmarker<=nrzeroes/16;nrmarker++) writebits(HTAC[0xF0]);
|
| 570 |
+
nrzeroes=nrzeroes%16;
|
| 571 |
+
}
|
| 572 |
+
writebits(HTAC[nrzeroes*16+category[DU[i]]]);
|
| 573 |
+
writebits(bitcode[DU[i]]);
|
| 574 |
+
i++;
|
| 575 |
+
}
|
| 576 |
+
if (end0pos!=63) writebits(HTAC[0x00]); // �Ĥ꤬���ʤ�EOB
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
void RGB2YCbCr(unsigned short int xpos,unsigned short int ypos){
|
| 580 |
+
unsigned char x,y;
|
| 581 |
+
unsigned char R,G,B;
|
| 582 |
+
for(y=0;y<16;y++){
|
| 583 |
+
for(x=0;x<16;x++){
|
| 584 |
+
R=buffer[ypos*Ximage*3+xpos*3+y*Ximage*3+x*3+2];
|
| 585 |
+
G=buffer[ypos*Ximage*3+xpos*3+y*Ximage*3+x*3+1];
|
| 586 |
+
B=buffer[ypos*Ximage*3+xpos*3+y*Ximage*3+x*3+0];
|
| 587 |
+
DU_Y[y*16+x] = (unsigned char)(0.299 *R + 0.587 *G + 0.114 *B) -128;
|
| 588 |
+
if(x%2==0 & y%2==0){
|
| 589 |
+
DU_Cb[y/2*8+x/2] = (unsigned char)(0.5 *B - 0.33126 *G - 0.16874 *R);
|
| 590 |
+
DU_Cr[y/2*8+x/2] = (unsigned char)(0.5 *R - 0.41869 *G - 0.08131 *B);
|
| 591 |
+
}
|
| 592 |
+
}
|
| 593 |
+
}
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
void main_encoder(){
|
| 597 |
+
signed short int DCY=0,DCCb=0,DCCr=0;
|
| 598 |
+
unsigned short int xpos,ypos;
|
| 599 |
+
signed char DU[64];
|
| 600 |
+
int i;
|
| 601 |
+
for (ypos=0;ypos<Yimage;ypos+=16){
|
| 602 |
+
for (xpos=0;xpos<Ximage;xpos+=16){
|
| 603 |
+
RGB2YCbCr(xpos,ypos);
|
| 604 |
+
for(i=0;i<64;i++) DU[i] = DU_Y[(i/8)*16+i%8+0];
|
| 605 |
+
process_DU(DU,DQTinfo.Ytable,&DCY,YDC_HT,YAC_HT);
|
| 606 |
+
for(i=0;i<64;i++) DU[i] = DU_Y[(i/8)*16+i%8+8];
|
| 607 |
+
process_DU(DU,DQTinfo.Ytable,&DCY,YDC_HT,YAC_HT);
|
| 608 |
+
for(i=0;i<64;i++) DU[i] = DU_Y[(i/8)*16+i%8+128];
|
| 609 |
+
process_DU(DU,DQTinfo.Ytable,&DCY,YDC_HT,YAC_HT);
|
| 610 |
+
for(i=0;i<64;i++) DU[i] = DU_Y[(i/8)*16+i%8+136];
|
| 611 |
+
process_DU(DU,DQTinfo.Ytable,&DCY,YDC_HT,YAC_HT);
|
| 612 |
+
process_DU(DU_Cb,DQTinfo.Cbtable,&DCCb,CbDC_HT,CbAC_HT);
|
| 613 |
+
process_DU(DU_Cr,DQTinfo.Cbtable,&DCCr,CbDC_HT,CbAC_HT);
|
| 614 |
+
}
|
| 615 |
+
}
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
void load_bitmap(char *bitmap_name, unsigned short int *Ximage_original, unsigned short int *Yimage_original){
|
| 619 |
+
unsigned short int Xdiv8,Ydiv8;
|
| 620 |
+
unsigned char nr_fillingbytes;//The number of the filling bytes in the BMP file
|
| 621 |
+
unsigned int offset;
|
| 622 |
+
// (the dimension in bytes of a BMP line on the disk is divisible by 4)
|
| 623 |
+
unsigned char lastcolor[3];
|
| 624 |
+
unsigned short int column;
|
| 625 |
+
unsigned char TMPBUF[256];
|
| 626 |
+
unsigned short int nrline_up,nrline_dn,nrline;
|
| 627 |
+
unsigned short int dimline;
|
| 628 |
+
unsigned char *tmpline;
|
| 629 |
+
FILE *fp_bitmap=fopen(bitmap_name,"rb");
|
| 630 |
+
fread(TMPBUF,1,54,fp_bitmap);
|
| 631 |
+
Ximage=(unsigned short int)TMPBUF[19]*256+TMPBUF[18];Yimage=(unsigned short int)TMPBUF[23]*256+TMPBUF[22];
|
| 632 |
+
*Ximage_original=Ximage;
|
| 633 |
+
*Yimage_original=Yimage; //Keep the old dimensions of the image
|
| 634 |
+
if (Ximage%16!=0) Xdiv8=(Ximage/16)*16+16;
|
| 635 |
+
else Xdiv8=Ximage;
|
| 636 |
+
if (Yimage%16!=0) Ydiv8=(Yimage/16)*16+16;
|
| 637 |
+
else Ydiv8=Yimage;
|
| 638 |
+
|
| 639 |
+
offset = TMPBUF[10];
|
| 640 |
+
if(offset > 54){
|
| 641 |
+
offset -= 51;
|
| 642 |
+
fread(TMPBUF,1,offset,fp_bitmap);
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
// The image we encode shall be filled with the last line and the last column
|
| 646 |
+
// from the original bitmap, until Ximage and Yimage are divisible by 8
|
| 647 |
+
// Load BMP image from disk and complete X
|
| 648 |
+
buffer=(unsigned char *)(malloc(3*Xdiv8*Ydiv8));
|
| 649 |
+
if (Ximage%4!=0) nr_fillingbytes=4-(Ximage%4);
|
| 650 |
+
else nr_fillingbytes=0;
|
| 651 |
+
for (nrline=0;nrline<Yimage;nrline++){
|
| 652 |
+
fread(buffer+nrline*Xdiv8*3,1,Ximage*3,fp_bitmap);
|
| 653 |
+
fread(TMPBUF,1,nr_fillingbytes,fp_bitmap);
|
| 654 |
+
memcpy(&lastcolor,buffer+nrline*Xdiv8*3+Ximage*3-1,3);
|
| 655 |
+
for (column=Ximage;column<Xdiv8;column++){
|
| 656 |
+
memcpy(buffer+nrline*Xdiv8*3+column,&lastcolor,3);
|
| 657 |
+
}
|
| 658 |
+
}
|
| 659 |
+
Ximage=Xdiv8;
|
| 660 |
+
dimline=Ximage*3;
|
| 661 |
+
tmpline=(unsigned char *)malloc(dimline);
|
| 662 |
+
|
| 663 |
+
//Reorder in memory the inversed bitmap
|
| 664 |
+
for (nrline_up=Yimage-1,nrline_dn=0;nrline_up>nrline_dn;nrline_up--,nrline_dn++){
|
| 665 |
+
memcpy(tmpline,buffer+nrline_up*Ximage*3, dimline);
|
| 666 |
+
memcpy(buffer+nrline_up*Ximage*3,buffer+nrline_dn*Ximage*3,dimline);
|
| 667 |
+
memcpy(buffer+nrline_dn*Ximage*3,tmpline,dimline);
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
// Y completion:
|
| 671 |
+
memcpy(tmpline,buffer+(Yimage-1)*Ximage*3,dimline);
|
| 672 |
+
for (nrline=Yimage;nrline<Ydiv8;nrline++){
|
| 673 |
+
memcpy(buffer+nrline*Ximage*3,tmpline,dimline);
|
| 674 |
+
}
|
| 675 |
+
Yimage=Ydiv8;
|
| 676 |
+
free(tmpline);fclose(fp_bitmap);
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
void init_all(){
|
| 680 |
+
set_DQTinfo();
|
| 681 |
+
set_DHTinfo();
|
| 682 |
+
init_Huffman_tables();
|
| 683 |
+
set_numbers_category_and_bitcode();
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
int main(int argc,char *argv[]){
|
| 687 |
+
char BMP_filename[64];
|
| 688 |
+
char JPG_filename[64];
|
| 689 |
+
unsigned short int Ximage_original,Yimage_original; //the original image dimensions,
|
| 690 |
+
// before we made them divisible by 8
|
| 691 |
+
unsigned char len_filename;
|
| 692 |
+
bitstring fillbits; //filling bitstring for the bit alignment of the EOI marker
|
| 693 |
+
if (argc>1) { strcpy(BMP_filename,argv[1]);
|
| 694 |
+
if (argc>2) strcpy(JPG_filename,argv[2]);
|
| 695 |
+
else{
|
| 696 |
+
strcpy(JPG_filename,BMP_filename);
|
| 697 |
+
len_filename=strlen(BMP_filename);
|
| 698 |
+
strcpy(JPG_filename+(len_filename-3),"jpg");
|
| 699 |
+
}
|
| 700 |
+
}
|
| 701 |
+
load_bitmap(BMP_filename, &Ximage_original, &Yimage_original);
|
| 702 |
+
fp_jpeg_stream=fopen(JPG_filename,"wb");
|
| 703 |
+
init_all();
|
| 704 |
+
SOF0info.width=Ximage_original;
|
| 705 |
+
SOF0info.height=Yimage_original;
|
| 706 |
+
|
| 707 |
+
writeword(0xFFD8); //SOI
|
| 708 |
+
|
| 709 |
+
write_APP0info();
|
| 710 |
+
write_DQTinfo();
|
| 711 |
+
write_SOF0info();
|
| 712 |
+
write_DHTinfo();
|
| 713 |
+
write_SOSinfo();
|
| 714 |
+
|
| 715 |
+
bytenew=0;bytepos=7;
|
| 716 |
+
main_encoder();
|
| 717 |
+
//Do the bit alignment of the EOI marker
|
| 718 |
+
if(bytepos>=0){
|
| 719 |
+
fillbits.length=bytepos+1;
|
| 720 |
+
fillbits.value=(1<<(bytepos+1))-1;
|
| 721 |
+
writebits(fillbits);
|
| 722 |
+
}
|
| 723 |
+
writeword(0xFFD9); //EOI
|
| 724 |
+
free(buffer);
|
| 725 |
+
free(category_alloc);
|
| 726 |
+
free(bitcode_alloc);
|
| 727 |
+
fclose(fp_jpeg_stream);
|
| 728 |
+
}
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.model/convbtoh.c
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2005-2014 H.Ishihara
|
| 3 |
+
*
|
| 4 |
+
* License: The Open Software License 3.0
|
| 5 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 6 |
+
*
|
| 7 |
+
* For further information please contact.
|
| 8 |
+
* http://www.aquaxis.com/
|
| 9 |
+
* info(at)aquaxis.com or hidemi(at)sweetcafe.jp
|
| 10 |
+
*/
|
| 11 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 12 |
+
#include <stdio.h>
|
| 13 |
+
#include <stdlib.h>
|
| 14 |
+
|
| 15 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
// ���C����
|
| 17 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 18 |
+
int main(int argc, char *argv[])
|
| 19 |
+
{
|
| 20 |
+
unsigned char buff[4];
|
| 21 |
+
char data[256];
|
| 22 |
+
FILE *rfp,*wfp;
|
| 23 |
+
|
| 24 |
+
if((rfp = fopen(argv[1],"rb")) == NULL){
|
| 25 |
+
perror(0);
|
| 26 |
+
exit(0);
|
| 27 |
+
}
|
| 28 |
+
if((wfp = fopen(argv[2],"wb")) == NULL){
|
| 29 |
+
perror(0);
|
| 30 |
+
exit(0);
|
| 31 |
+
}
|
| 32 |
+
while(!feof(rfp)){
|
| 33 |
+
fread(buff,1,4,rfp);
|
| 34 |
+
sprintf(data,"%02X%02X%02X%02X\n",buff[3],buff[2],buff[1],buff[0]);
|
| 35 |
+
fwrite(data,1,9,wfp);
|
| 36 |
+
}
|
| 37 |
+
fclose(rfp);
|
| 38 |
+
fclose(wfp);
|
| 39 |
+
|
| 40 |
+
return 0;
|
| 41 |
+
}
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.model/convsim.c
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2005-2014 H.Ishihara
|
| 3 |
+
*
|
| 4 |
+
* License: The Open Software License 3.0
|
| 5 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 6 |
+
*
|
| 7 |
+
* For further information please contact.
|
| 8 |
+
* http://www.aquaxis.com/
|
| 9 |
+
* info(at)aquaxis.com or hidemi(at)sweetcafe.jp
|
| 10 |
+
*/
|
| 11 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 12 |
+
#include <stdio.h>
|
| 13 |
+
#include <stdlib.h>
|
| 14 |
+
|
| 15 |
+
typedef unsigned short WORD;
|
| 16 |
+
typedef unsigned int DWORD;
|
| 17 |
+
typedef int LONG;
|
| 18 |
+
|
| 19 |
+
typedef struct tagBITMAPINFOHEADER{
|
| 20 |
+
DWORD biSize;
|
| 21 |
+
LONG biWidth;
|
| 22 |
+
LONG biHeight;
|
| 23 |
+
WORD biPlanes;
|
| 24 |
+
WORD biBitCount;
|
| 25 |
+
DWORD biCompression;
|
| 26 |
+
DWORD biSizeImage;
|
| 27 |
+
LONG biXPelsPerMeter;
|
| 28 |
+
LONG biYPelsPerMeter;
|
| 29 |
+
DWORD biClrUsed;
|
| 30 |
+
DWORD biClrImportant;
|
| 31 |
+
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;
|
| 32 |
+
|
| 33 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 34 |
+
// メイン関数
|
| 35 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 36 |
+
int main(int argc, char *argv[])
|
| 37 |
+
{
|
| 38 |
+
unsigned char buff[4];
|
| 39 |
+
char data[256];
|
| 40 |
+
FILE *rfp,*wfp;
|
| 41 |
+
|
| 42 |
+
unsigned long width;
|
| 43 |
+
unsigned long height;
|
| 44 |
+
unsigned long bitdata;
|
| 45 |
+
unsigned char tbuff[4];
|
| 46 |
+
BITMAPINFOHEADER lpBi;
|
| 47 |
+
|
| 48 |
+
unsigned char *image;
|
| 49 |
+
unsigned int i;
|
| 50 |
+
|
| 51 |
+
if((rfp = fopen(argv[1],"rb")) == NULL){
|
| 52 |
+
perror(0);
|
| 53 |
+
exit(0);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
if((wfp = fopen(argv[2],"wb")) == NULL){
|
| 57 |
+
perror(0);
|
| 58 |
+
exit(0);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
fgets(data,256,rfp);
|
| 63 |
+
width = (unsigned int)strtol(data,NULL,10);
|
| 64 |
+
fgets(data,256,rfp);
|
| 65 |
+
height = (unsigned int)strtol(data,NULL,10);
|
| 66 |
+
|
| 67 |
+
image = (unsigned char *)malloc(height*width*3);
|
| 68 |
+
|
| 69 |
+
// ファイルヘッダの設定
|
| 70 |
+
tbuff[0] = 'B';
|
| 71 |
+
tbuff[1] = 'M';
|
| 72 |
+
fwrite(tbuff,2,1,wfp);
|
| 73 |
+
tbuff[3] = ((14 +40 +width * height * 3) >> 24) & 0xff;
|
| 74 |
+
tbuff[2] = ((14 +40 +width * height * 3) >> 16) & 0xff;
|
| 75 |
+
tbuff[1] = ((14 +40 +width * height * 3) >> 8) & 0xff;
|
| 76 |
+
tbuff[0] = ((14 +40 +width * height * 3) >> 0) & 0xff;
|
| 77 |
+
fwrite(tbuff,4,1,wfp);
|
| 78 |
+
tbuff[1] = 0;
|
| 79 |
+
tbuff[0] = 0;
|
| 80 |
+
fwrite(tbuff,2,1,wfp);
|
| 81 |
+
fwrite(tbuff,2,1,wfp);
|
| 82 |
+
tbuff[3] = 0;
|
| 83 |
+
tbuff[2] = 0;
|
| 84 |
+
tbuff[1] = 0;
|
| 85 |
+
tbuff[0] = 54;
|
| 86 |
+
fwrite(tbuff,4,1,wfp);
|
| 87 |
+
|
| 88 |
+
// インフォメーションの設定
|
| 89 |
+
lpBi.biSize = 40;
|
| 90 |
+
lpBi.biWidth = width;
|
| 91 |
+
lpBi.biHeight = height;
|
| 92 |
+
lpBi.biPlanes = 1;
|
| 93 |
+
lpBi.biBitCount = 3*8;
|
| 94 |
+
lpBi.biCompression = 0;
|
| 95 |
+
lpBi.biSizeImage = width*height*3;
|
| 96 |
+
lpBi.biXPelsPerMeter = 300;
|
| 97 |
+
lpBi.biYPelsPerMeter = 300;
|
| 98 |
+
lpBi.biClrUsed = 0;
|
| 99 |
+
lpBi.biClrImportant = 0;
|
| 100 |
+
fwrite(&lpBi,1,40,wfp);
|
| 101 |
+
|
| 102 |
+
i = 0;
|
| 103 |
+
while(!feof(rfp)){
|
| 104 |
+
if(i>=width*height) break;
|
| 105 |
+
fgets(data,256,rfp);
|
| 106 |
+
bitdata=strtol(data,NULL,16);
|
| 107 |
+
image[((height-i/width-1)*width*3)+(i%width)*3+0] = (bitdata >> 0) & 0xff;
|
| 108 |
+
image[((height-i/width-1)*width*3)+(i%width)*3+1] = (bitdata >> 8) & 0xff;
|
| 109 |
+
image[((height-i/width-1)*width*3)+(i%width)*3+2] = (bitdata >> 16) & 0xff;
|
| 110 |
+
i++;
|
| 111 |
+
}
|
| 112 |
+
fwrite(image,1,width*height*3,wfp);
|
| 113 |
+
fclose(rfp);
|
| 114 |
+
fclose(wfp);
|
| 115 |
+
free(image);
|
| 116 |
+
|
| 117 |
+
return 0;
|
| 118 |
+
}
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.model/djpeg.c
ADDED
|
@@ -0,0 +1,863 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2005-2014 H.Ishihara
|
| 3 |
+
*
|
| 4 |
+
* License: The Open Software License 3.0
|
| 5 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 6 |
+
*
|
| 7 |
+
* For further information please contact.
|
| 8 |
+
* http://www.aquaxis.com/
|
| 9 |
+
* info(at)aquaxis.com or hidemi(at)sweetcafe.jp
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 13 |
+
// JPEGデコード
|
| 14 |
+
// 2005年10月26日 V1.0
|
| 15 |
+
// All Rights Reserved, Copyright (c) Hidemi Ishihara
|
| 16 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 17 |
+
//
|
| 18 |
+
// JPEGを入力するとBitmapを出力します。
|
| 19 |
+
//
|
| 20 |
+
// % gcc -o djpeg fjpeg.c
|
| 21 |
+
// % djpeg 入力ファイル名 出力ファイル名
|
| 22 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 23 |
+
#include <stdio.h>
|
| 24 |
+
#include <stdlib.h>
|
| 25 |
+
|
| 26 |
+
#define log_printf(...)
|
| 27 |
+
|
| 28 |
+
unsigned int BuffIndex; // JPEGデータの位置
|
| 29 |
+
unsigned int BuffSize; // JPEGデータの大きさ
|
| 30 |
+
unsigned int BuffX; // 画像の横サイズ
|
| 31 |
+
unsigned int BuffY; // 画像の縦サイズ
|
| 32 |
+
unsigned int BuffBlockX; // MCUの横個数
|
| 33 |
+
unsigned int BuffBlockY; // MCUの縦個数
|
| 34 |
+
unsigned char *Buff; // 伸長したデータを入れるバッファ
|
| 35 |
+
|
| 36 |
+
unsigned char TableDQT[4][64]; // 量子化テーブル
|
| 37 |
+
unsigned short TableDHT[4][162]; // ハフマンテーブル
|
| 38 |
+
|
| 39 |
+
unsigned short TableHT[4][16]; // ハフマンスタートテーブル
|
| 40 |
+
unsigned char TableHN[4][16]; // ハフマンスタート番号
|
| 41 |
+
|
| 42 |
+
unsigned char BitCount = 0; // 圧縮データの読み込み位置
|
| 43 |
+
unsigned int LineData; // 伸長に使うデータ
|
| 44 |
+
unsigned int NextData; // 伸長に使うデータ
|
| 45 |
+
|
| 46 |
+
unsigned int PreData[3]; // DC成分用の貯めバッファ
|
| 47 |
+
|
| 48 |
+
unsigned char CompCount; // コンポーネント数
|
| 49 |
+
unsigned char CompNum[4]; // コンポーネント番号(未使用)
|
| 50 |
+
unsigned char CompSample[4]; // コンポーネント
|
| 51 |
+
unsigned char CompDQT[4]; // コンポーネントのDQTテーブル番号
|
| 52 |
+
unsigned char CompDHT[4]; // コンポーネントのDHTテーブル番号
|
| 53 |
+
unsigned char CompSampleX, CompSampleY;
|
| 54 |
+
|
| 55 |
+
// ジグザグテーブル
|
| 56 |
+
int zigzag_table[]={
|
| 57 |
+
0, 1, 8, 16,9, 2, 3,10,
|
| 58 |
+
17,24,32,25,18,11, 4, 5,
|
| 59 |
+
12,19,26,33,40,48,41,34,
|
| 60 |
+
27,20,13, 6, 7,14,21,28,
|
| 61 |
+
35,42,49,56,57,50,43,36,
|
| 62 |
+
29,22,15,23,30,37,44,51,
|
| 63 |
+
58,59,52,45,38,31,39,46,
|
| 64 |
+
53,60,61,54,47,55,62,63,
|
| 65 |
+
0
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
typedef unsigned short WORD;
|
| 69 |
+
//typedef unsigned long DWORD;
|
| 70 |
+
//typedef long LONG;
|
| 71 |
+
typedef unsigned int DWORD;
|
| 72 |
+
typedef int LONG;
|
| 73 |
+
|
| 74 |
+
typedef struct tagBITMAPFILEHEADER {
|
| 75 |
+
WORD bfType;
|
| 76 |
+
DWORD bfSize;
|
| 77 |
+
WORD bfReserved1;
|
| 78 |
+
WORD bfReserved2;
|
| 79 |
+
DWORD bfOffBits;
|
| 80 |
+
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;
|
| 81 |
+
|
| 82 |
+
typedef struct tagBITMAPINFOHEADER{
|
| 83 |
+
DWORD biSize;
|
| 84 |
+
LONG biWidth;
|
| 85 |
+
LONG biHeight;
|
| 86 |
+
WORD biPlanes;
|
| 87 |
+
WORD biBitCount;
|
| 88 |
+
DWORD biCompression;
|
| 89 |
+
DWORD biSizeImage;
|
| 90 |
+
LONG biXPelsPerMeter;
|
| 91 |
+
LONG biYPelsPerMeter;
|
| 92 |
+
DWORD biClrUsed;
|
| 93 |
+
DWORD biClrImportant;
|
| 94 |
+
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;
|
| 95 |
+
|
| 96 |
+
/*
|
| 97 |
+
* Bitmap出力
|
| 98 |
+
* file: ファイル名
|
| 99 |
+
* x,y: 画像のサイズ
|
| 100 |
+
* b: バイトカウント(1ドット辺りのバイト数)
|
| 101 |
+
*/
|
| 102 |
+
void BmpSave(unsigned char *file,unsigned char *buff,
|
| 103 |
+
unsigned int x,unsigned int y,unsigned int b){
|
| 104 |
+
BITMAPFILEHEADER lpBf;
|
| 105 |
+
BITMAPINFOHEADER lpBi;
|
| 106 |
+
unsigned char tbuff[4];
|
| 107 |
+
FILE *fp;
|
| 108 |
+
unsigned char str;
|
| 109 |
+
int i,k;
|
| 110 |
+
|
| 111 |
+
if((fp = fopen(file,"wb")) == NULL){
|
| 112 |
+
perror(0);
|
| 113 |
+
exit(0);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// ファイルヘッダの設定
|
| 117 |
+
tbuff[0] = 'B';
|
| 118 |
+
tbuff[1] = 'M';
|
| 119 |
+
fwrite(tbuff,2,1,fp);
|
| 120 |
+
tbuff[3] = ((14 +40 +x *y *b) >> 24) & 0xff;
|
| 121 |
+
tbuff[2] = ((14 +40 +x *y *b) >> 16) & 0xff;
|
| 122 |
+
tbuff[1] = ((14 +40 +x *y *b) >> 8) & 0xff;
|
| 123 |
+
tbuff[0] = ((14 +40 +x *y *b) >> 0) & 0xff;
|
| 124 |
+
fwrite(tbuff,4,1,fp);
|
| 125 |
+
tbuff[1] = 0;
|
| 126 |
+
tbuff[0] = 0;
|
| 127 |
+
fwrite(tbuff,2,1,fp);
|
| 128 |
+
fwrite(tbuff,2,1,fp);
|
| 129 |
+
tbuff[3] = 0;
|
| 130 |
+
tbuff[2] = 0;
|
| 131 |
+
tbuff[1] = 0;
|
| 132 |
+
tbuff[0] = 54;
|
| 133 |
+
fwrite(tbuff,4,1,fp);
|
| 134 |
+
|
| 135 |
+
// インフォメーションの設定
|
| 136 |
+
lpBi.biSize = 40;
|
| 137 |
+
lpBi.biWidth = x;
|
| 138 |
+
lpBi.biHeight = y;
|
| 139 |
+
lpBi.biPlanes = 1;
|
| 140 |
+
lpBi.biBitCount = b*8;
|
| 141 |
+
lpBi.biCompression = 0;
|
| 142 |
+
lpBi.biSizeImage = x*y*b;
|
| 143 |
+
lpBi.biXPelsPerMeter = 300;
|
| 144 |
+
lpBi.biYPelsPerMeter = 300;
|
| 145 |
+
lpBi.biClrUsed = 0;
|
| 146 |
+
lpBi.biClrImportant = 0;
|
| 147 |
+
fwrite(&lpBi,1,40,fp);
|
| 148 |
+
|
| 149 |
+
// 上下反転
|
| 150 |
+
for(k=0;k<y/2;k++){
|
| 151 |
+
for(i=0;i<x*3;i++){
|
| 152 |
+
str = buff[k*x*3+i];
|
| 153 |
+
buff[k*x*3+i] = buff[((y-1)*x*3 -k*x*3) +i];
|
| 154 |
+
buff[((y-1)*x*3-k*x*3) +i] = str;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
fwrite(buff,1,x*y*b,fp);
|
| 159 |
+
|
| 160 |
+
fclose(fp);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/*****************************************
|
| 164 |
+
* データ取得部
|
| 165 |
+
*****************************************/
|
| 166 |
+
|
| 167 |
+
/*
|
| 168 |
+
* 1Byte取得
|
| 169 |
+
*/
|
| 170 |
+
unsigned char get_byte(unsigned char *buff){
|
| 171 |
+
if(BuffIndex >= BuffSize) return 0;
|
| 172 |
+
return buff[BuffIndex++];
|
| 173 |
+
}
|
| 174 |
+
/*
|
| 175 |
+
* 2Byte取得
|
| 176 |
+
*/
|
| 177 |
+
unsigned short get_word(unsigned char *buff){
|
| 178 |
+
unsigned char h,l;
|
| 179 |
+
h = get_byte(buff);
|
| 180 |
+
l = get_byte(buff);
|
| 181 |
+
return (h<<8)|l;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/*
|
| 185 |
+
* 4Byte取得(伸張時のみ使��)
|
| 186 |
+
*/
|
| 187 |
+
unsigned int get_data(unsigned char *buff){
|
| 188 |
+
unsigned char str = 0;
|
| 189 |
+
unsigned int data = 0;
|
| 190 |
+
str = get_byte(buff);
|
| 191 |
+
if(str ==0xff) if(get_byte(buff)== 0x00) str = 0xFF; else str = 0x00;
|
| 192 |
+
data = str;
|
| 193 |
+
str = get_byte(buff);
|
| 194 |
+
if(str ==0xff) if(get_byte(buff)== 0x00) str = 0xFF; else str = 0x00;
|
| 195 |
+
data = (data << 8) | str;
|
| 196 |
+
str = get_byte(buff);
|
| 197 |
+
if(str ==0xff) if(get_byte(buff)== 0x00) str = 0xFF; else str = 0x00;
|
| 198 |
+
data = (data << 8) | str;
|
| 199 |
+
str = get_byte(buff);
|
| 200 |
+
if(str ==0xff) if(get_byte(buff)== 0x00) str = 0xFF; else str = 0x00;
|
| 201 |
+
data = (data << 8) | str;
|
| 202 |
+
//log_printf(" Get Data: %08x\n",data);
|
| 203 |
+
return data;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/*
|
| 207 |
+
* ビットデータ取得(伸張時のみ使用)
|
| 208 |
+
*/
|
| 209 |
+
unsigned int get_bit(unsigned char *buff){
|
| 210 |
+
unsigned int BitData;
|
| 211 |
+
|
| 212 |
+
// ビットカウントの位置が32を越えた場合、新たにデータを取得する
|
| 213 |
+
if(BitCount >=32){
|
| 214 |
+
LineData = NextData;
|
| 215 |
+
NextData = get_data(buff);
|
| 216 |
+
BitCount -= 32;
|
| 217 |
+
}
|
| 218 |
+
// Huffmanデコードで使用するデータに置き換える
|
| 219 |
+
if(BitCount >0){
|
| 220 |
+
BitData = (LineData << BitCount) | (NextData >> (32 - BitCount));
|
| 221 |
+
}else{
|
| 222 |
+
BitData = LineData;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
return BitData;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
/********************
|
| 229 |
+
* マーカー解析
|
| 230 |
+
********************/
|
| 231 |
+
/*
|
| 232 |
+
* APP0処理
|
| 233 |
+
*/
|
| 234 |
+
void GetAPP0(unsigned char *buff){
|
| 235 |
+
unsigned short data;
|
| 236 |
+
unsigned char str;
|
| 237 |
+
unsigned int i;
|
| 238 |
+
|
| 239 |
+
data = get_word(buff); // Lp(レングス)
|
| 240 |
+
// APP0は読まなくてもいいので取り合えずレングス分スキップする
|
| 241 |
+
for(i=0;i<data-2;i++){
|
| 242 |
+
str = get_byte(buff);
|
| 243 |
+
}
|
| 244 |
+
#if 0
|
| 245 |
+
str = get_byte(buff); // 識別子(5文字,"JFIF"と[00])
|
| 246 |
+
str = get_byte(buff);
|
| 247 |
+
str = get_byte(buff);
|
| 248 |
+
str = get_byte(buff);
|
| 249 |
+
str = get_byte(buff);
|
| 250 |
+
data = get_word(buff); // バージョン
|
| 251 |
+
str = get_byte(buff); // 解像度の単位
|
| 252 |
+
data = get_word(buff); // 横方向の解像度
|
| 253 |
+
data = get_word(buff); // 縦方向の解像度
|
| 254 |
+
data = get_word(buff); // サムネイルの横ピクセル数
|
| 255 |
+
data = get_word(buff); // サムネイルの縦ピクセル数
|
| 256 |
+
data = get_word(buff); // サムネイルデータ(ある場合だけ)
|
| 257 |
+
#endif
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
/*
|
| 261 |
+
* DQT処理
|
| 262 |
+
*/
|
| 263 |
+
void GetDQT(unsigned char *buff){
|
| 264 |
+
unsigned short data;
|
| 265 |
+
unsigned char str;
|
| 266 |
+
unsigned int i;
|
| 267 |
+
unsigned int tablenum;
|
| 268 |
+
|
| 269 |
+
data = get_word(buff);
|
| 270 |
+
str = get_byte(buff); // テーブル番号
|
| 271 |
+
|
| 272 |
+
log_printf("*** DQT Table %d\n",str);
|
| 273 |
+
for(i=0;i<64;i++){
|
| 274 |
+
TableDQT[str][i] = get_byte(buff);
|
| 275 |
+
log_printf(" %2d: %2x\n",i,TableDQT[str][i]);
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
/*
|
| 280 |
+
* DHT処理
|
| 281 |
+
*/
|
| 282 |
+
void GetDHT(unsigned char *buff){
|
| 283 |
+
unsigned short data;
|
| 284 |
+
unsigned char str;
|
| 285 |
+
unsigned int i;
|
| 286 |
+
unsigned char max,count;
|
| 287 |
+
unsigned short ShiftData = 0x8000,HuffmanData =0x0000;
|
| 288 |
+
unsigned int tablenum;
|
| 289 |
+
|
| 290 |
+
data = get_word(buff);
|
| 291 |
+
str = get_byte(buff);
|
| 292 |
+
|
| 293 |
+
switch(str){
|
| 294 |
+
case 0x00:
|
| 295 |
+
// Y直流成分
|
| 296 |
+
tablenum = 0x00;
|
| 297 |
+
break;
|
| 298 |
+
case 0x10:
|
| 299 |
+
// Y交流成分
|
| 300 |
+
tablenum = 0x01;
|
| 301 |
+
break;
|
| 302 |
+
case 0x01:
|
| 303 |
+
// CbCr直流成分
|
| 304 |
+
tablenum = 0x02;
|
| 305 |
+
break;
|
| 306 |
+
case 0x11:
|
| 307 |
+
// CbCr交流成分
|
| 308 |
+
tablenum = 0x03;
|
| 309 |
+
break;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
log_printf("*** DHT Table/Number %d\n",tablenum);
|
| 313 |
+
// テーブルを作成する
|
| 314 |
+
max = 0;
|
| 315 |
+
for(i=0;i<16;i++){
|
| 316 |
+
count = get_byte(buff);
|
| 317 |
+
TableHT[tablenum][i] = HuffmanData;
|
| 318 |
+
TableHN[tablenum][i] = max;
|
| 319 |
+
log_printf(" %2d: %4x,%2x\n",i,TableHT[tablenum][i],TableHN[tablenum][i]);
|
| 320 |
+
max = max + count;
|
| 321 |
+
while(!(count==0)){
|
| 322 |
+
HuffmanData += ShiftData;
|
| 323 |
+
count--;
|
| 324 |
+
}
|
| 325 |
+
ShiftData = ShiftData >> 1; // 右に1bitシフトする
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
log_printf("*** DHT Table %d\n",tablenum);
|
| 329 |
+
for(i=0;i<max;i++){
|
| 330 |
+
TableDHT[tablenum][i] = get_byte(buff);
|
| 331 |
+
log_printf(" %2d: %2x\n",i,TableDHT[tablenum][i]);
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
/*
|
| 336 |
+
* SOF処理
|
| 337 |
+
*/
|
| 338 |
+
void GetSOF(unsigned char *buff){
|
| 339 |
+
unsigned short data;
|
| 340 |
+
unsigned char str;
|
| 341 |
+
unsigned int i;
|
| 342 |
+
unsigned char count;
|
| 343 |
+
unsigned char num;
|
| 344 |
+
|
| 345 |
+
data = get_word(buff);
|
| 346 |
+
str = get_byte(buff);
|
| 347 |
+
BuffY = get_word(buff); // 画像の横サイズ
|
| 348 |
+
BuffX = get_word(buff); // 画像の縦サイズ
|
| 349 |
+
CompCount = get_byte(buff); // データのコンポーネント数
|
| 350 |
+
log_printf(" CompCount: %d\n", CompCount);
|
| 351 |
+
for(i=0;i<CompCount;i++){
|
| 352 |
+
str = get_byte(buff); // コンポーネント番号
|
| 353 |
+
num = str;
|
| 354 |
+
log_printf(" Comp[%d]: %02X\n", i, str);
|
| 355 |
+
str = get_byte(buff); // サンプリング比率
|
| 356 |
+
CompSample[num] = str;
|
| 357 |
+
log_printf(" Sample[%d]: %02X\n", i, str);
|
| 358 |
+
str = get_byte(buff); // DQTテーブル番号
|
| 359 |
+
CompDQT[num] = str;
|
| 360 |
+
log_printf(" DQT[%d]: %02X\n", i, str);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
if(CompCount == 1){
|
| 364 |
+
CompSampleX = 1;
|
| 365 |
+
CompSampleY = 1;
|
| 366 |
+
}else{
|
| 367 |
+
CompSampleX = CompSample[1] & 0x0F;
|
| 368 |
+
CompSampleY = (CompSample[1] >> 4) & 0x0F;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
// MCUのサイズを算出する(ひと塊分)
|
| 372 |
+
BuffBlockX = (int)(BuffX /(8 * CompSampleX));
|
| 373 |
+
if(BuffX % (8 * CompSampleX) >0) BuffBlockX++;
|
| 374 |
+
BuffBlockY = (int)(BuffY /(8 * CompSampleY));
|
| 375 |
+
if(BuffY % (8 * CompSampleY) >0) BuffBlockY++;
|
| 376 |
+
Buff = (unsigned char*)malloc(BuffBlockY*(8 * CompSampleY)*BuffBlockX*(8 * CompSampleX)*3);
|
| 377 |
+
|
| 378 |
+
log_printf(" size : %d x %d,(%d x %d)\n",BuffX,BuffY,BuffBlockX,BuffBlockY);
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
/*
|
| 382 |
+
* SOS処理
|
| 383 |
+
*/
|
| 384 |
+
void GetSOS(unsigned char *buff){
|
| 385 |
+
unsigned short data;
|
| 386 |
+
unsigned char str;
|
| 387 |
+
unsigned int i;
|
| 388 |
+
unsigned char count;
|
| 389 |
+
unsigned char num;
|
| 390 |
+
|
| 391 |
+
data = get_word(buff);
|
| 392 |
+
count = get_byte(buff);
|
| 393 |
+
for(i=0;i<count;i++){
|
| 394 |
+
str = get_byte(buff);
|
| 395 |
+
num = str;
|
| 396 |
+
log_printf(" CompNum[%d]: %02X\n", i, str);
|
| 397 |
+
str = get_byte(buff);
|
| 398 |
+
CompDHT[num] = str;
|
| 399 |
+
log_printf(" CompDHT[%d]: %02X\n", i, str);
|
| 400 |
+
}
|
| 401 |
+
str = get_byte(buff);
|
| 402 |
+
str = get_byte(buff);
|
| 403 |
+
str = get_byte(buff);
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
/*
|
| 407 |
+
* ハフマンデコード+逆量子化+逆ジグザグ
|
| 408 |
+
*/
|
| 409 |
+
void HuffmanDecode(unsigned char *buff, unsigned char table, int *BlockData){
|
| 410 |
+
unsigned int data;
|
| 411 |
+
unsigned char zero;
|
| 412 |
+
unsigned short code,huffman;
|
| 413 |
+
unsigned char count =0;
|
| 414 |
+
unsigned int BitData;
|
| 415 |
+
unsigned int i;
|
| 416 |
+
unsigned char tabledqt,tabledc,tableac,tablen;
|
| 417 |
+
unsigned char ZeroCount,DataCount;
|
| 418 |
+
int DataCode;
|
| 419 |
+
|
| 420 |
+
for(i=0;i<64;i++) BlockData[i] = 0x0; // データのリセット
|
| 421 |
+
|
| 422 |
+
// テーブル番号を設定する
|
| 423 |
+
if(table ==0x00){
|
| 424 |
+
tabledqt =0x00;
|
| 425 |
+
tabledc =0x00;
|
| 426 |
+
tableac =0x01;
|
| 427 |
+
}else if(table ==0x01){
|
| 428 |
+
tabledqt =0x01;
|
| 429 |
+
tabledc =0x02;
|
| 430 |
+
tableac =0x03;
|
| 431 |
+
}else{
|
| 432 |
+
tabledqt =0x01;
|
| 433 |
+
tabledc =0x02;
|
| 434 |
+
tableac =0x03;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
count = 0; // 念のために
|
| 438 |
+
while(count <64){
|
| 439 |
+
|
| 440 |
+
BitData = get_bit(buff);
|
| 441 |
+
|
| 442 |
+
log_printf(" Haffuman BitData(%2d,%2d): %8x\n",table,count,BitData);
|
| 443 |
+
|
| 444 |
+
// 使用するテーブルのセレクト
|
| 445 |
+
if(count ==0) tablen = tabledc; else tablen = tableac;
|
| 446 |
+
code = (unsigned short)(BitData >> 16); // コードは16ビット使用する
|
| 447 |
+
// ハフマンコードがどのビット数にいるか割り出す
|
| 448 |
+
for(i=0;i<16;i++) {
|
| 449 |
+
log_printf(" Haff hit(%2d:%2d): %8x,%8x\n",table,i,TableHT[tablen][i],code);
|
| 450 |
+
if(TableHT[tablen][i]>code) break;
|
| 451 |
+
}
|
| 452 |
+
i--;
|
| 453 |
+
|
| 454 |
+
code = (unsigned short)(code >> (15 - i)); // コードの下位を揃える
|
| 455 |
+
huffman = (unsigned short)(TableHT[tablen][i] >> (15 - i));
|
| 456 |
+
|
| 457 |
+
log_printf(" PreUse Dht Number(%2d): %8x,%8x,%8x\n",i,code,huffman,TableHN[tablen][i]);
|
| 458 |
+
|
| 459 |
+
// ハフマンテーブルの場所を算出する
|
| 460 |
+
code = code - huffman + TableHN[tablen][i];
|
| 461 |
+
|
| 462 |
+
log_printf(" Use Dht Number: %8x\n",code);
|
| 463 |
+
|
| 464 |
+
ZeroCount = (TableDHT[tablen][code] >> 4) & 0x0F; // ゼロレングスの個数
|
| 465 |
+
DataCount = (TableDHT[tablen][code]) & 0x0F; // 続くデータのビット長
|
| 466 |
+
log_printf(" Dht Table: %8x,%8x\n",ZeroCount,DataCount);
|
| 467 |
+
// ハフマンコードを抜き、続くデータを取得する
|
| 468 |
+
DataCode = (BitData << (i + 1)) >> (16 + (16 - DataCount));
|
| 469 |
+
// 先頭ビットが"0"であれば負のデータ、上位ビットに1を立てて、1を足す
|
| 470 |
+
//if(!(DataCode & (1<<(DataCount-1)))) DataCode=DataCode-(1<<DataCount)+1;
|
| 471 |
+
if(!(DataCode & (1<<(DataCount-1))) && DataCount !=0){
|
| 472 |
+
DataCode |= (~0) << DataCount;
|
| 473 |
+
DataCode += 1;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
log_printf(" Use Bit: %d\n",(i + DataCount +1));
|
| 477 |
+
BitCount += (i + DataCount +1); // 使用したビット数を加算する
|
| 478 |
+
|
| 479 |
+
if(count ==0){
|
| 480 |
+
// DC成分の場合、データとなる
|
| 481 |
+
if(DataCount ==0) DataCode =0x0; // DataCountが0ならデータは0である
|
| 482 |
+
PreData[table] += DataCode; // DC成分は加算しなければならない
|
| 483 |
+
// 逆量子化+ジグザグ
|
| 484 |
+
BlockData[zigzag_table[count]] =PreData[table]*TableDQT[tabledqt][count];
|
| 485 |
+
count ++;
|
| 486 |
+
}else{
|
| 487 |
+
if(ZeroCount == 0x0 && DataCount == 0x0){
|
| 488 |
+
// AC成分でEOB符号が来た場合は終了する
|
| 489 |
+
break;
|
| 490 |
+
}else if(ZeroCount ==0xF && DataCount == 0x0){
|
| 491 |
+
// ZRL符号が来た場合、15個のゼロデータとみなす
|
| 492 |
+
count += 15;
|
| 493 |
+
}else{
|
| 494 |
+
count += ZeroCount;
|
| 495 |
+
// 逆量子化+ジグザグ
|
| 496 |
+
BlockData[zigzag_table[count]] = DataCode * TableDQT[tabledqt][count];
|
| 497 |
+
}
|
| 498 |
+
count ++;
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
const int C1_16 = 4017; // cos( pi/16) x4096
|
| 504 |
+
const int C2_16 = 3784; // cos(2pi/16) x4096
|
| 505 |
+
const int C3_16 = 3406; // cos(3pi/16) x4096
|
| 506 |
+
const int C4_16 = 2896; // cos(4pi/16) x4096
|
| 507 |
+
const int C5_16 = 2276; // cos(5pi/16) x4096
|
| 508 |
+
const int C6_16 = 1567; // cos(6pi/16) x4096
|
| 509 |
+
const int C7_16 = 799; // cos(7pi/16) x4096
|
| 510 |
+
|
| 511 |
+
/*
|
| 512 |
+
* iDCT
|
| 513 |
+
*/
|
| 514 |
+
void DctDecode(int *BlockIn, int *BlockOut){
|
| 515 |
+
int i;
|
| 516 |
+
int s0,s1,s2,s3,s4,s5,s6,s7;
|
| 517 |
+
int t0,t1,t2,t3,t4,t5,t6,t7;
|
| 518 |
+
|
| 519 |
+
/* iDCT X方向 */
|
| 520 |
+
log_printf("-----------------------------\n");
|
| 521 |
+
log_printf(" iDCT(In)\n");
|
| 522 |
+
log_printf("-----------------------------\n");
|
| 523 |
+
for(i=0;i<64;i++){
|
| 524 |
+
log_printf("%2d: %8x\n",i,BlockIn[i]);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
for(i=0;i<8;i++) {
|
| 528 |
+
s0 = (BlockIn[0] + BlockIn[4]) * C4_16;
|
| 529 |
+
s1 = (BlockIn[0] - BlockIn[4]) * C4_16;
|
| 530 |
+
s3 = (BlockIn[2] * C2_16) + (BlockIn[6] * C6_16);
|
| 531 |
+
s2 = (BlockIn[2] * C6_16) - (BlockIn[6] * C2_16);
|
| 532 |
+
s7 = (BlockIn[1] * C1_16) + (BlockIn[7] * C7_16);
|
| 533 |
+
s4 = (BlockIn[1] * C7_16) - (BlockIn[7] * C1_16);
|
| 534 |
+
s6 = (BlockIn[5] * C5_16) + (BlockIn[3] * C3_16);
|
| 535 |
+
s5 = (BlockIn[5] * C3_16) - (BlockIn[3] * C5_16);
|
| 536 |
+
|
| 537 |
+
log_printf("s0:%8x\n",s0);
|
| 538 |
+
log_printf("s1:%8x\n",s1);
|
| 539 |
+
log_printf("s2:%8x\n",s2);
|
| 540 |
+
log_printf("s3:%8x\n",s3);
|
| 541 |
+
log_printf("s4:%8x\n",s4);
|
| 542 |
+
log_printf("s5:%8x\n",s5);
|
| 543 |
+
log_printf("s6:%8x\n",s6);
|
| 544 |
+
log_printf("s7:%8x\n",s7);
|
| 545 |
+
|
| 546 |
+
t0 = s0 + s3;
|
| 547 |
+
t3 = s0 - s3;
|
| 548 |
+
t1 = s1 + s2;
|
| 549 |
+
t2 = s1 - s2;
|
| 550 |
+
t4 = s4 + s5;
|
| 551 |
+
t5 = s4 - s5;
|
| 552 |
+
t7 = s7 + s6;
|
| 553 |
+
t6 = s7 - s6;
|
| 554 |
+
|
| 555 |
+
log_printf("t0:%8x\n",t0);
|
| 556 |
+
log_printf("t1:%8x\n",t1);
|
| 557 |
+
log_printf("t2:%8x\n",t2);
|
| 558 |
+
log_printf("t3:%8x\n",t3);
|
| 559 |
+
log_printf("t4:%8x\n",t4);
|
| 560 |
+
log_printf("t5:%8x\n",t5);
|
| 561 |
+
log_printf("t6:%8x\n",t6);
|
| 562 |
+
log_printf("t7:%8x\n",t7);
|
| 563 |
+
|
| 564 |
+
s6 = (t5 + t6) * 181 / 256; // 1/sqrt(2)
|
| 565 |
+
s5 = (t6 - t5) * 181 / 256; // 1/sqrt(2)
|
| 566 |
+
|
| 567 |
+
log_printf("s5:%8x\n",s5);
|
| 568 |
+
log_printf("s6:%8x\n",s6);
|
| 569 |
+
|
| 570 |
+
*BlockIn++ = (t0 + t7) >> 11;
|
| 571 |
+
*BlockIn++ = (t1 + s6) >> 11;
|
| 572 |
+
*BlockIn++ = (t2 + s5) >> 11;
|
| 573 |
+
*BlockIn++ = (t3 + t4) >> 11;
|
| 574 |
+
*BlockIn++ = (t3 - t4) >> 11;
|
| 575 |
+
*BlockIn++ = (t2 - s5) >> 11;
|
| 576 |
+
*BlockIn++ = (t1 - s6) >> 11;
|
| 577 |
+
*BlockIn++ = (t0 - t7) >> 11;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
BlockIn -= 64;
|
| 581 |
+
|
| 582 |
+
/* iDCT Y方向 */
|
| 583 |
+
log_printf("-----------------------------\n");
|
| 584 |
+
log_printf(" iDCT(Middle)\n");
|
| 585 |
+
log_printf("-----------------------------\n");
|
| 586 |
+
for(i=0;i<64;i++){
|
| 587 |
+
log_printf("%2d: %8x\n",i,BlockIn[i]);
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
for(i=0;i<8;i++){
|
| 591 |
+
s0 = (BlockIn[ 0] + BlockIn[32]) * C4_16;
|
| 592 |
+
s1 = (BlockIn[ 0] - BlockIn[32]) * C4_16;
|
| 593 |
+
s3 = BlockIn[16] * C2_16 + BlockIn[48] * C6_16;
|
| 594 |
+
s2 = BlockIn[16] * C6_16 - BlockIn[48] * C2_16;
|
| 595 |
+
s7 = BlockIn[ 8] * C1_16 + BlockIn[56] * C7_16;
|
| 596 |
+
s4 = BlockIn[ 8] * C7_16 - BlockIn[56] * C1_16;
|
| 597 |
+
s6 = BlockIn[40] * C5_16 + BlockIn[24] * C3_16;
|
| 598 |
+
s5 = BlockIn[40] * C3_16 - BlockIn[24] * C5_16;
|
| 599 |
+
|
| 600 |
+
log_printf("s0:%8x\n",s0);
|
| 601 |
+
log_printf("s1:%8x\n",s1);
|
| 602 |
+
log_printf("s2:%8x\n",s2);
|
| 603 |
+
log_printf("s3:%8x\n",s3);
|
| 604 |
+
log_printf("s4:%8x\n",s4);
|
| 605 |
+
log_printf("s5:%8x\n",s5);
|
| 606 |
+
log_printf("s6:%8x\n",s6);
|
| 607 |
+
log_printf("s7:%8x\n",s7);
|
| 608 |
+
|
| 609 |
+
t0 = s0 + s3;
|
| 610 |
+
t1 = s1 + s2;
|
| 611 |
+
t2 = s1 - s2;
|
| 612 |
+
t3 = s0 - s3;
|
| 613 |
+
t4 = s4 + s5;
|
| 614 |
+
t5 = s4 - s5;
|
| 615 |
+
t6 = s7 - s6;
|
| 616 |
+
t7 = s6 + s7;
|
| 617 |
+
|
| 618 |
+
log_printf("t0:%8x\n",t0);
|
| 619 |
+
log_printf("t1:%8x\n",t1);
|
| 620 |
+
log_printf("t2:%8x\n",t2);
|
| 621 |
+
log_printf("t3:%8x\n",t3);
|
| 622 |
+
log_printf("t4:%8x\n",t4);
|
| 623 |
+
log_printf("t5:%8x\n",t5);
|
| 624 |
+
log_printf("t6:%8x\n",t6);
|
| 625 |
+
log_printf("t7:%8x\n",t7);
|
| 626 |
+
|
| 627 |
+
s5 = (t6 - t5) * 181 / 256; // 1/sqrt(2)
|
| 628 |
+
s6 = (t5 + t6) * 181 / 256; // 1/sqrt(2)
|
| 629 |
+
|
| 630 |
+
log_printf("s5:%8x\n",s5);
|
| 631 |
+
log_printf("s6:%8x\n",s6);
|
| 632 |
+
|
| 633 |
+
BlockOut[ 0] = ((t0 + t7) >> 15);
|
| 634 |
+
BlockOut[56] = ((t0 - t7) >> 15);
|
| 635 |
+
BlockOut[ 8] = ((t1 + s6) >> 15);
|
| 636 |
+
BlockOut[48] = ((t1 - s6) >> 15);
|
| 637 |
+
BlockOut[16] = ((t2 + s5) >> 15);
|
| 638 |
+
BlockOut[40] = ((t2 - s5) >> 15);
|
| 639 |
+
BlockOut[24] = ((t3 + t4) >> 15);
|
| 640 |
+
BlockOut[32] = ((t3 - t4) >> 15);
|
| 641 |
+
|
| 642 |
+
BlockIn++;
|
| 643 |
+
BlockOut++;
|
| 644 |
+
}
|
| 645 |
+
BlockOut-=8;
|
| 646 |
+
|
| 647 |
+
log_printf("-----------------------------\n");
|
| 648 |
+
log_printf(" iDCT(Out)\n");
|
| 649 |
+
log_printf("-----------------------------\n");
|
| 650 |
+
for(i=0;i<8;i++){
|
| 651 |
+
log_printf(" %2d: %04x;\n",i+ 0,BlockOut[i+ 0]&0xFFFF);
|
| 652 |
+
log_printf(" %2d: %04x;\n",i+56,BlockOut[i+56]&0xFFFF);
|
| 653 |
+
log_printf(" %2d: %04x;\n",i+ 8,BlockOut[i+ 8]&0xFFFF);
|
| 654 |
+
log_printf(" %2d: %04x;\n",i+48,BlockOut[i+48]&0xFFFF);
|
| 655 |
+
log_printf(" %2d: %04x;\n",i+16,BlockOut[i+16]&0xFFFF);
|
| 656 |
+
log_printf(" %2d: %04x;\n",i+40,BlockOut[i+40]&0xFFFF);
|
| 657 |
+
log_printf(" %2d: %04x;\n",i+24,BlockOut[i+24]&0xFFFF);
|
| 658 |
+
log_printf(" %2d: %04x;\n",i+32,BlockOut[i+32]&0xFFFF);
|
| 659 |
+
}
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 663 |
+
// 4:1:1のデコード処理
|
| 664 |
+
void Decode411(unsigned char *buff, int *BlockY, int *BlockCb, int *BlockCr){
|
| 665 |
+
int BlockHuffman[64];
|
| 666 |
+
int BlockYLT[64];
|
| 667 |
+
int BlockYRT[64];
|
| 668 |
+
int BlockYLB[64];
|
| 669 |
+
int BlockYRB[64];
|
| 670 |
+
int Block[64];
|
| 671 |
+
unsigned int i;
|
| 672 |
+
unsigned int m, n;
|
| 673 |
+
|
| 674 |
+
for(n=0;n<CompSampleY;n++){
|
| 675 |
+
for(m=0;m<CompSampleX;m++){
|
| 676 |
+
log_printf("BlockY:%d,%d\n",m,n);
|
| 677 |
+
HuffmanDecode(buff,0x00,BlockHuffman);
|
| 678 |
+
DctDecode(BlockHuffman,Block);
|
| 679 |
+
for(i=0;i<64;i++){
|
| 680 |
+
BlockY[(int)(i/8)*8*CompSampleX+(i%8)+(m*8)+(n*64*CompSampleY)] = Block[i];
|
| 681 |
+
}
|
| 682 |
+
}
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
if(CompCount > 1){
|
| 686 |
+
// 青色差
|
| 687 |
+
log_printf("Block:10\n");
|
| 688 |
+
HuffmanDecode(buff,0x01,BlockHuffman);
|
| 689 |
+
DctDecode(BlockHuffman,BlockCb);
|
| 690 |
+
|
| 691 |
+
// 赤色差
|
| 692 |
+
log_printf("Block:11\n");
|
| 693 |
+
HuffmanDecode(buff,0x02,BlockHuffman);
|
| 694 |
+
DctDecode(BlockHuffman,BlockCr);
|
| 695 |
+
}
|
| 696 |
+
}
|
| 697 |
+
|
| 698 |
+
/*
|
| 699 |
+
* YUV→RGBに変換
|
| 700 |
+
*/
|
| 701 |
+
void DecodeYUV(int *y, int *cb, int *cr, unsigned char *rgb){
|
| 702 |
+
int r,g,b;
|
| 703 |
+
int p,i;
|
| 704 |
+
|
| 705 |
+
log_printf("----RGB----\n");
|
| 706 |
+
for(i=0;i<((CompCount>1)?256:64);i++){
|
| 707 |
+
p = ((int)(i/32) * 8) + ((int)((i % 16)/2));
|
| 708 |
+
r = 128 + y[i] + ((CompCount>1)?cr[p]*1.402:0);
|
| 709 |
+
r = (r & 0xffffff00) ? (r >> 24) ^ 0xff : r;
|
| 710 |
+
g = 128 + y[i] - ((CompCount>1)?cb[p]*0.34414:0) - ((CompCount>1)?cr[p]*0.71414:0);
|
| 711 |
+
g = (g & 0xffffff00) ? (g >> 24) ^ 0xff : g;
|
| 712 |
+
b = 128 + y[i] + ((CompCount>1)?cb[p]*1.772:0);
|
| 713 |
+
b = (b & 0xffffff00) ? (b >> 24) ^ 0xff : b;
|
| 714 |
+
rgb[i*3+0] = b;
|
| 715 |
+
rgb[i*3+1] = g;
|
| 716 |
+
rgb[i*3+2] = r;
|
| 717 |
+
log_printf("[RGB]%3d: %3x,%3x,%3x = %2x,%2x,%2x\n",i,
|
| 718 |
+
y[i]&0x1FF,cr[p]&0x1FF,cb[p]&0x1FF,
|
| 719 |
+
rgb[i*3+2],rgb[i*3+1],rgb[i*3+0]);
|
| 720 |
+
}
|
| 721 |
+
}
|
| 722 |
+
|
| 723 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 724 |
+
// イメージのデコード
|
| 725 |
+
void Decode(unsigned char *buff,unsigned char *rgb){
|
| 726 |
+
int BlockY[256];
|
| 727 |
+
int BlockCb[256];
|
| 728 |
+
int BlockCr[256];
|
| 729 |
+
int x,y,i,p;
|
| 730 |
+
|
| 731 |
+
for(y=0;y<BuffBlockY;y++){
|
| 732 |
+
for(x=0;x<BuffBlockX;x++){
|
| 733 |
+
Decode411(buff,BlockY,BlockCb,BlockCr); // 4:1:1のデコード
|
| 734 |
+
DecodeYUV(BlockY,BlockCb,BlockCr,rgb); // YUV→RGB変換
|
| 735 |
+
for(i=0;i<((CompCount>1)?256:64);i++){
|
| 736 |
+
if((x*(8*CompSampleX)+(i%(8*CompSampleX))<BuffX) && (y*(8*CompSampleY)+i/(8*CompSampleY)<BuffY)){
|
| 737 |
+
p=y*(8*CompSampleY)*BuffX*3+x*(8*CompSampleX)*3+(int)(i/(8*CompSampleY))*BuffX*3+(i%(8*CompSampleX))*3;
|
| 738 |
+
Buff[p+0] = rgb[i*3+0];
|
| 739 |
+
Buff[p+1] = rgb[i*3+1];
|
| 740 |
+
Buff[p+2] = rgb[i*3+2];
|
| 741 |
+
|
| 742 |
+
log_printf("RGB[%4d,%4d]: %2x,%2x,%2x\n",x*(8*CompSampleX)+(i%(8*CompSampleX)),y*(8*CompSampleY)+i/(8*CompSampleY),rgb[i*3+2],rgb[i*3+1],rgb[i*3+0]);
|
| 743 |
+
}
|
| 744 |
+
}
|
| 745 |
+
}
|
| 746 |
+
}
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
/*
|
| 750 |
+
* デコード
|
| 751 |
+
*/
|
| 752 |
+
void JpegDecode(unsigned char *buff){
|
| 753 |
+
unsigned short data;
|
| 754 |
+
unsigned int i;
|
| 755 |
+
unsigned int Image =0;
|
| 756 |
+
unsigned char RGB[256*3];
|
| 757 |
+
while(!(BuffIndex >= BuffSize)){
|
| 758 |
+
if(Image ==0){
|
| 759 |
+
data = get_word(buff);
|
| 760 |
+
switch(data){
|
| 761 |
+
case 0xFFD8: // SOI
|
| 762 |
+
log_printf("Header: SOI\n");
|
| 763 |
+
break;
|
| 764 |
+
case 0xFFE0: // APP0
|
| 765 |
+
log_printf("Header: APP0\n");
|
| 766 |
+
GetAPP0(buff);
|
| 767 |
+
break;
|
| 768 |
+
case 0xFFDB: // DQT
|
| 769 |
+
log_printf("Header: DQT\n");
|
| 770 |
+
GetDQT(buff);
|
| 771 |
+
break;
|
| 772 |
+
case 0xFFC4: // DHT
|
| 773 |
+
log_printf("Header: DHT\n");
|
| 774 |
+
GetDHT(buff);
|
| 775 |
+
break;
|
| 776 |
+
case 0xFFC0: // SOF
|
| 777 |
+
log_printf("Header: SOF\n");
|
| 778 |
+
GetSOF(buff);
|
| 779 |
+
break;
|
| 780 |
+
case 0xFFDA: // SOS
|
| 781 |
+
log_printf("Header: SOS\n");
|
| 782 |
+
GetSOS(buff);
|
| 783 |
+
Image = 1;
|
| 784 |
+
// データの準備
|
| 785 |
+
PreData[0] = 0x00;
|
| 786 |
+
PreData[1] = 0x00;
|
| 787 |
+
PreData[2] = 0x00;
|
| 788 |
+
LineData = get_data(buff);
|
| 789 |
+
NextData = get_data(buff);
|
| 790 |
+
BitCount =0;
|
| 791 |
+
break;
|
| 792 |
+
case 0xFFD9: // EOI
|
| 793 |
+
log_printf("Header: EOI\n");
|
| 794 |
+
break;
|
| 795 |
+
default:
|
| 796 |
+
// 判別できないヘッダーは読み飛ばす
|
| 797 |
+
log_printf("Header: other(%X)\n", data);
|
| 798 |
+
if((data & 0xFF00) == 0xFF00 && !(data == 0xFF00)){
|
| 799 |
+
data = get_word(buff);
|
| 800 |
+
for(i=0;i<data-2;i++){
|
| 801 |
+
get_byte(buff);
|
| 802 |
+
}
|
| 803 |
+
}
|
| 804 |
+
break;
|
| 805 |
+
}
|
| 806 |
+
}else{
|
| 807 |
+
// 伸長(SOSが来ている)
|
| 808 |
+
log_printf("/****Image****/\n");
|
| 809 |
+
Decode(buff,RGB);
|
| 810 |
+
}
|
| 811 |
+
}
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 815 |
+
// メイン関数
|
| 816 |
+
//////////////////////////////////////////////////////////////////////////////
|
| 817 |
+
int main(int argc, char* argv[])
|
| 818 |
+
{
|
| 819 |
+
unsigned char *buff;
|
| 820 |
+
FILE *fp;
|
| 821 |
+
|
| 822 |
+
// 型のサイズを表示する
|
| 823 |
+
log_printf( " sizeof(char): %02d\n", sizeof( char ) );
|
| 824 |
+
log_printf( " sizeof(unsigned char): %02d\n", sizeof( unsigned char ) );
|
| 825 |
+
log_printf( " sizeof(short): %02d\n", sizeof( short ) );
|
| 826 |
+
log_printf( " sizeof(unsigned short): %02d\n", sizeof( unsigned short ) );
|
| 827 |
+
log_printf( " sizeof(int): %02d\n", sizeof( int ) );
|
| 828 |
+
log_printf( " sizeof(unsigned int): %02d\n", sizeof( unsigned int ) );
|
| 829 |
+
log_printf( " sizeof(long): %02d\n", sizeof( long ) );
|
| 830 |
+
log_printf( " sizeof(unsigned long): %02d\n", sizeof( unsigned long ) );
|
| 831 |
+
|
| 832 |
+
log_printf( " sizeof: %02d\n", sizeof( BITMAPFILEHEADER ) );
|
| 833 |
+
log_printf( " sizeof: %02d\n", sizeof( BITMAPINFOHEADER ) );
|
| 834 |
+
|
| 835 |
+
if((fp = fopen(argv[1], "rb")) == NULL){
|
| 836 |
+
perror(0);
|
| 837 |
+
exit(0);
|
| 838 |
+
}
|
| 839 |
+
|
| 840 |
+
// ファイルサイズを取得する
|
| 841 |
+
BuffSize = 0;
|
| 842 |
+
while(!feof(fp)){
|
| 843 |
+
fgetc(fp);
|
| 844 |
+
BuffSize ++;
|
| 845 |
+
}
|
| 846 |
+
BuffSize--;
|
| 847 |
+
rewind(fp); // ファイルポインタを最初に戻す
|
| 848 |
+
|
| 849 |
+
buff = (unsigned char *)malloc(BuffSize); // バッファを確保する
|
| 850 |
+
fread(buff,1,BuffSize,fp); // バッファに読み込む
|
| 851 |
+
BuffIndex = 0;
|
| 852 |
+
JpegDecode(buff); // JPEGデコードする
|
| 853 |
+
log_printf("Finished decode\n");
|
| 854 |
+
BmpSave(argv[2],Buff,BuffX,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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module tb_aq_djpeg;
|
| 22 |
+
reg rst;
|
| 23 |
+
reg clk;
|
| 24 |
+
|
| 25 |
+
reg [31:0] JPEG_MEM [0:1*1024*1024-1];
|
| 26 |
+
|
| 27 |
+
integer DATA_COUNT;
|
| 28 |
+
|
| 29 |
+
parameter clkP = 10000; // 100MHz
|
| 30 |
+
parameter clkH = clkP /2;
|
| 31 |
+
parameter clkL = clkP - clkH;
|
| 32 |
+
|
| 33 |
+
wire [31:0] JPEG_DATA;
|
| 34 |
+
reg DATA_ENABLE;
|
| 35 |
+
wire READ_ENABLE;
|
| 36 |
+
wire JPEG_IDLE;
|
| 37 |
+
|
| 38 |
+
wire OutEnable;
|
| 39 |
+
wire [15:0] OutWidth;
|
| 40 |
+
wire [15:0] OutHeight;
|
| 41 |
+
wire [15:0] OutPixelX;
|
| 42 |
+
wire [15:0] OutPixelY;
|
| 43 |
+
wire [7:0] OutR;
|
| 44 |
+
wire [7:0] OutG;
|
| 45 |
+
wire [7:0] OutB;
|
| 46 |
+
|
| 47 |
+
integer count;
|
| 48 |
+
reg [23:0] rgb_mem [0:1920*1080-1];
|
| 49 |
+
|
| 50 |
+
initial begin
|
| 51 |
+
count = 0;
|
| 52 |
+
while(1) begin
|
| 53 |
+
@(posedge clk);
|
| 54 |
+
count = count +1;
|
| 55 |
+
end
|
| 56 |
+
end
|
| 57 |
+
|
| 58 |
+
aq_djpeg u_aq_djpeg
|
| 59 |
+
(
|
| 60 |
+
.rst(rst),
|
| 61 |
+
.clk(clk),
|
| 62 |
+
|
| 63 |
+
.DataIn (JPEG_DATA),
|
| 64 |
+
.DataInEnable (DATA_ENABLE),
|
| 65 |
+
.DataInRead (READ_ENABLE),
|
| 66 |
+
.JpegDecodeIdle (JPEG_IDLE),
|
| 67 |
+
|
| 68 |
+
.OutEnable ( OutEnable ),
|
| 69 |
+
.OutWidth ( OutWidth ),
|
| 70 |
+
.OutHeight ( OutHeight ),
|
| 71 |
+
.OutPixelX ( OutPixelX ),
|
| 72 |
+
.OutPixelY ( OutPixelY ),
|
| 73 |
+
.OutR ( OutR ),
|
| 74 |
+
.OutG ( OutG ),
|
| 75 |
+
.OutB ( OutB )
|
| 76 |
+
);
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
// Clock
|
| 80 |
+
always begin
|
| 81 |
+
#clkH clk = 0;
|
| 82 |
+
#clkL clk = 1;
|
| 83 |
+
end
|
| 84 |
+
|
| 85 |
+
initial begin
|
| 86 |
+
rst = 1'b0;
|
| 87 |
+
repeat (300) @(posedge clk);
|
| 88 |
+
rst = 1'b1;
|
| 89 |
+
end
|
| 90 |
+
|
| 91 |
+
// Read JPEG File
|
| 92 |
+
initial begin
|
| 93 |
+
$readmemh("/mnt/disk1/Public/FPGA_Magazine_No.6/DJPEG_IP/test.mem",JPEG_MEM);
|
| 94 |
+
end
|
| 95 |
+
|
| 96 |
+
// Initial
|
| 97 |
+
initial begin
|
| 98 |
+
DATA_COUNT <= 0;
|
| 99 |
+
DATA_ENABLE <= 1'b0;
|
| 100 |
+
wait (rst == 1'b1);
|
| 101 |
+
@(posedge clk);
|
| 102 |
+
$display(" Start Clock: %d",count);
|
| 103 |
+
@(posedge clk);
|
| 104 |
+
@(posedge clk);
|
| 105 |
+
DATA_ENABLE <= 1'b1;
|
| 106 |
+
forever begin
|
| 107 |
+
if(READ_ENABLE == 1'b1) begin
|
| 108 |
+
DATA_COUNT <= DATA_COUNT +1;
|
| 109 |
+
end
|
| 110 |
+
@(posedge clk);
|
| 111 |
+
end
|
| 112 |
+
end // initial begin
|
| 113 |
+
|
| 114 |
+
assign JPEG_DATA = JPEG_MEM[DATA_COUNT];
|
| 115 |
+
|
| 116 |
+
integer i;
|
| 117 |
+
|
| 118 |
+
initial begin
|
| 119 |
+
@(posedge u_aq_djpeg.ImageEnable);
|
| 120 |
+
|
| 121 |
+
$display("------------------------------");
|
| 122 |
+
$display("Image Run");
|
| 123 |
+
$display("------------------------------");
|
| 124 |
+
$display(" X: %4d",i,u_aq_djpeg.OutWidth);
|
| 125 |
+
$display(" Y: %4d",i,u_aq_djpeg.OutHeight);
|
| 126 |
+
$display(" Component: %4d",i,u_aq_djpeg.JpegComp);
|
| 127 |
+
$display(" BlockWidth: %4d",i,u_aq_djpeg.JpegBlockWidth);
|
| 128 |
+
$display("------------------------------");
|
| 129 |
+
$display(" DQT Y Table");
|
| 130 |
+
for(i=0;i<64;i=i+1) begin
|
| 131 |
+
$display(" %2d: %2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_dqt.DQT_Y[i]);
|
| 132 |
+
end
|
| 133 |
+
|
| 134 |
+
$display("------------------------------");
|
| 135 |
+
$display(" DQT Cb/Cr Table");
|
| 136 |
+
for(i=0;i<64;i=i+1) begin
|
| 137 |
+
$display(" %2d: %2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_dqt.DQT_C[i]);
|
| 138 |
+
end
|
| 139 |
+
$display("------------------------------");
|
| 140 |
+
|
| 141 |
+
$display("------------------------------");
|
| 142 |
+
$display(" huffman Y-DC Code/Number");
|
| 143 |
+
for(i=0;i<16;i=i+1) begin
|
| 144 |
+
$display(" %2d: %2x,%2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanTable0r[i],u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanNumber0r[i]);
|
| 145 |
+
end
|
| 146 |
+
$display("------------------------------");
|
| 147 |
+
|
| 148 |
+
$display("------------------------------");
|
| 149 |
+
$display(" huffman Y-DC Table");
|
| 150 |
+
for(i=0;i<16;i=i+1) begin
|
| 151 |
+
$display(" %2d: %2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_dht.DHT_Ydc[i]);
|
| 152 |
+
end
|
| 153 |
+
$display("------------------------------");
|
| 154 |
+
|
| 155 |
+
$display("------------------------------");
|
| 156 |
+
$display(" huffman Y-AC Code/Number");
|
| 157 |
+
for(i=0;i<16;i=i+1) begin
|
| 158 |
+
$display(" %2d: %2x,%2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanTable1r[i],u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanNumber1r[i]);
|
| 159 |
+
end
|
| 160 |
+
$display("------------------------------");
|
| 161 |
+
|
| 162 |
+
$display("------------------------------");
|
| 163 |
+
$display(" huffman Y-AC Table");
|
| 164 |
+
for(i=0;i<162;i=i+1) begin
|
| 165 |
+
$display(" %2d: %2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_dht.DHT_Yac[i]);
|
| 166 |
+
end
|
| 167 |
+
$display("------------------------------");
|
| 168 |
+
|
| 169 |
+
$display("------------------------------");
|
| 170 |
+
$display(" huffman C-DC Table");
|
| 171 |
+
for(i=0;i<16;i=i+1) begin
|
| 172 |
+
$display(" %2d: %2x,%2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanTable2r[i],u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanNumber2r[i]);
|
| 173 |
+
end
|
| 174 |
+
$display("------------------------------");
|
| 175 |
+
|
| 176 |
+
$display("------------------------------");
|
| 177 |
+
$display(" huffman C-DC Table");
|
| 178 |
+
for(i=0;i<16;i=i+1) begin
|
| 179 |
+
$display(" %2d: %2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_dht.DHT_Cdc[i]);
|
| 180 |
+
end
|
| 181 |
+
$display("------------------------------");
|
| 182 |
+
|
| 183 |
+
$display("------------------------------");
|
| 184 |
+
$display(" huffman C-AC Table");
|
| 185 |
+
for(i=0;i<16;i=i+1) begin
|
| 186 |
+
$display(" %2d: %2x,%2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanTable3r[i],u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanNumber3r[i]);
|
| 187 |
+
end
|
| 188 |
+
$display("------------------------------");
|
| 189 |
+
|
| 190 |
+
$display("------------------------------");
|
| 191 |
+
$display(" huffman C-AC Table");
|
| 192 |
+
for(i=0;i<162;i=i+1) begin
|
| 193 |
+
$display(" %2d: %2x",i,u_aq_djpeg.u_jpeg_huffman.u_jpeg_dht.DHT_Cac[i]);
|
| 194 |
+
end
|
| 195 |
+
$display("------------------------------");
|
| 196 |
+
end
|
| 197 |
+
/*
|
| 198 |
+
integer Phase8Count;
|
| 199 |
+
initial begin
|
| 200 |
+
Phase8Count <= 0;
|
| 201 |
+
while(1) begin
|
| 202 |
+
@(posedge clk);
|
| 203 |
+
if((u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.Process == 4'h8) && !(u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.ProcessCount < 63)) begin
|
| 204 |
+
Phase8Count <= Phase8Count + 1;
|
| 205 |
+
$display(" Process Phase8: %d", Phase8Count);
|
| 206 |
+
end
|
| 207 |
+
end
|
| 208 |
+
end
|
| 209 |
+
*/
|
| 210 |
+
integer DataOutEnable;
|
| 211 |
+
initial begin
|
| 212 |
+
DataOutEnable <= 0;
|
| 213 |
+
while(1) begin
|
| 214 |
+
@(posedge clk);
|
| 215 |
+
if(u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.DataOutEnable == 1'b1) begin
|
| 216 |
+
DataOutEnable <= DataOutEnable + 1;
|
| 217 |
+
$display(" DataOutEnable: %d", DataOutEnable);
|
| 218 |
+
end
|
| 219 |
+
end
|
| 220 |
+
end
|
| 221 |
+
|
| 222 |
+
integer ConvertEnable;
|
| 223 |
+
initial begin
|
| 224 |
+
ConvertEnable <= 0;
|
| 225 |
+
while(1) begin
|
| 226 |
+
@(posedge clk);
|
| 227 |
+
if((u_aq_djpeg.u_jpeg_ycbcr.ConvertRead == 1'b1 == 1'b1) && (u_aq_djpeg.u_jpeg_ycbcr.ConvertAddress == 8'd255)) begin
|
| 228 |
+
ConvertEnable <= ConvertEnable + 1;
|
| 229 |
+
$display(" ConvertEnable: %d", ConvertEnable);
|
| 230 |
+
end
|
| 231 |
+
end
|
| 232 |
+
end
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
/*
|
| 236 |
+
initial begin
|
| 237 |
+
while(1) begin
|
| 238 |
+
@(posedge clk);
|
| 239 |
+
if(u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.Process == 4'h2)
|
| 240 |
+
$display(" Color: %d,%d",u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.ProcessColor,
|
| 241 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.ProcessCount);
|
| 242 |
+
end
|
| 243 |
+
end
|
| 244 |
+
|
| 245 |
+
initial begin
|
| 246 |
+
while(1) begin
|
| 247 |
+
@(posedge clk);
|
| 248 |
+
if(u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.Process == 4'h4)
|
| 249 |
+
for(i=0;i<16;i=i+1) begin
|
| 250 |
+
$display(" Data Code: %8x,%8x",u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanTable[i],u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.HuffmanNumber[i]);
|
| 251 |
+
end
|
| 252 |
+
end
|
| 253 |
+
end
|
| 254 |
+
*/
|
| 255 |
+
|
| 256 |
+
/*
|
| 257 |
+
initial begin
|
| 258 |
+
while(1) begin
|
| 259 |
+
@(posedge clk);
|
| 260 |
+
if(u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.Process == 4'h6)
|
| 261 |
+
$display(" Wait for RAM");
|
| 262 |
+
end
|
| 263 |
+
end
|
| 264 |
+
*/
|
| 265 |
+
/*
|
| 266 |
+
initial begin
|
| 267 |
+
while(1) begin
|
| 268 |
+
@(posedge clk);
|
| 269 |
+
if(u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.Process == 4'h4)
|
| 270 |
+
$display(" Data Code: %8x",u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.ProcessData);
|
| 271 |
+
end
|
| 272 |
+
end
|
| 273 |
+
*/
|
| 274 |
+
/*
|
| 275 |
+
initial begin
|
| 276 |
+
while(1) begin
|
| 277 |
+
@(posedge clk);
|
| 278 |
+
if(u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.Process == 4'hB)
|
| 279 |
+
$display(" Data Code: %d,%d,%4x,%4x,%4x,%4x,%2x,%4x,%4x,%4x,%8x",
|
| 280 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.CodeNumber,
|
| 281 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.ProcessCount,
|
| 282 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.DhtNumber,
|
| 283 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.DhtZero,
|
| 284 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.DataNumber,
|
| 285 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.TableCode,
|
| 286 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.NumberCode,
|
| 287 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.DqtData,
|
| 288 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.OutCode,
|
| 289 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.OutData,
|
| 290 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_hm_decode.ProcessData);
|
| 291 |
+
end
|
| 292 |
+
end
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
initial begin
|
| 297 |
+
while(1) begin
|
| 298 |
+
@(posedge clk);
|
| 299 |
+
if(u_aq_djpeg.u_jpeg_huffman.HmDecEnable == 1'b1)
|
| 300 |
+
$display(" HmDec Code: %d,%4x",
|
| 301 |
+
u_aq_djpeg.u_jpeg_huffman.HmDecCount,
|
| 302 |
+
u_aq_djpeg.u_jpeg_huffman.HmDecData);
|
| 303 |
+
end
|
| 304 |
+
end
|
| 305 |
+
*/
|
| 306 |
+
|
| 307 |
+
/*
|
| 308 |
+
initial begin
|
| 309 |
+
while(1) begin
|
| 310 |
+
@(posedge clk);
|
| 311 |
+
if(u_aq_djpeg.u_jpeg_huffman.HmOutEnable == 1'b1)
|
| 312 |
+
for(i=0;i<64;i=i+1) begin
|
| 313 |
+
$display(" Data Code: %d,%4x",i,
|
| 314 |
+
u_aq_djpeg.u_jpeg_huffman.u_jpeg_ziguzagu.RegData[i]);
|
| 315 |
+
end
|
| 316 |
+
end
|
| 317 |
+
end
|
| 318 |
+
*/
|
| 319 |
+
|
| 320 |
+
/*
|
| 321 |
+
initial begin
|
| 322 |
+
while(1) begin
|
| 323 |
+
@(posedge clk);
|
| 324 |
+
if(u_aq_djpeg.u_jpeg_idct.u_jpeg_idctx.Phase4Enable.O == 1'b1)
|
| 325 |
+
//if(u_aq_djpeg.u_jpeg_idct.u_jpeg_idctx.Phase4Enable == 1'b1)
|
| 326 |
+
$display(" Dct Data[X]: %d:%d,%016x,%016x",u_aq_djpeg.u_jpeg_idct.u_jpeg_idctx.Phase4Page,u_aq_djpeg.u_jpeg_idct.u_jpeg_idctx.Phase4Count,u_aq_djpeg.u_jpeg_idct.u_jpeg_idctx.Phase4R0r,u_aq_djpeg.u_jpeg_idct.u_jpeg_idctx.Phase4R1r);
|
| 327 |
+
end
|
| 328 |
+
end
|
| 329 |
+
*/
|
| 330 |
+
/*
|
| 331 |
+
initial begin
|
| 332 |
+
while(1) begin
|
| 333 |
+
@(posedge clk);
|
| 334 |
+
if(u_aq_djpeg.u_jpeg_idct.DctXEnable == 1'b1)
|
| 335 |
+
$display(" Dct Data[X]: %d:%d,%4x,%4x",u_aq_djpeg.u_jpeg_idct.DctXPage,u_aq_djpeg.u_jpeg_idct.DctXCount,u_aq_djpeg.u_jpeg_idct.DctXData0r,u_aq_djpeg.u_jpeg_idct.DctXData1r);
|
| 336 |
+
end
|
| 337 |
+
end
|
| 338 |
+
*/
|
| 339 |
+
|
| 340 |
+
/*
|
| 341 |
+
initial begin
|
| 342 |
+
while(1) begin
|
| 343 |
+
@(posedge clk);
|
| 344 |
+
if(u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Enable == 1'b1)
|
| 345 |
+
$display(" Dct Data[Y2]: %d,%8x,%8x,%8x,%8x,%8x,%8x,%8x,%8x",u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Count,u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase2Reg[0],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase2Reg[1],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase2Reg[2],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase2Reg[3],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase2Reg[4],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase2Reg[5],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Reg[6],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase2Reg[7]);
|
| 346 |
+
end
|
| 347 |
+
end
|
| 348 |
+
|
| 349 |
+
initial begin
|
| 350 |
+
while(1) begin
|
| 351 |
+
@(posedge clk);
|
| 352 |
+
if(u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase5Enable == 1'b1)
|
| 353 |
+
$display(" Dct Data[Y5]: %d,%8x,%8x,%8x,%8x,%8x,%8x,%8x,%8x,%8x,%8x",u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase5Count,u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase5R0w,u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase5R1w,u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Reg[0],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Reg[1],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Reg[2],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Reg[3],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Reg[4],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Reg[5],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Reg[6],u_aq_djpeg.u_jpeg_idct.u_jpeg_idcty.Phase3Reg[7]);
|
| 354 |
+
end
|
| 355 |
+
end
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
initial begin
|
| 360 |
+
while(1) begin
|
| 361 |
+
@(posedge clk);
|
| 362 |
+
if(u_aq_djpeg.DctEnable == 1'b1)
|
| 363 |
+
$display(" Dct Data[Y]: %d,%4x,%4x",u_aq_djpeg.DctCount,u_aq_djpeg.Dct0Data,u_aq_djpeg.Dct1Data);
|
| 364 |
+
end
|
| 365 |
+
end
|
| 366 |
+
*/
|
| 367 |
+
|
| 368 |
+
integer address;
|
| 369 |
+
integer fp;
|
| 370 |
+
|
| 371 |
+
// ??????????????????????????????
|
| 372 |
+
initial begin
|
| 373 |
+
while(1) begin
|
| 374 |
+
if(u_aq_djpeg.OutEnable == 1'b1) begin
|
| 375 |
+
address = u_aq_djpeg.OutWidth * u_aq_djpeg.OutPixelY + u_aq_djpeg.OutPixelX;
|
| 376 |
+
$display(" RGB[%4d,%4d][%4d,%4d]: %2x,%2x,%2x",OutPixelX,OutPixelY,OutWidth,OutHeight,OutR,OutG,OutB);
|
| 377 |
+
rgb_mem[address] = {OutR,OutG,OutB};
|
| 378 |
+
end
|
| 379 |
+
@(posedge clk);
|
| 380 |
+
end
|
| 381 |
+
end
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
initial begin
|
| 385 |
+
wait(!JPEG_IDLE);
|
| 386 |
+
wait(JPEG_IDLE);
|
| 387 |
+
|
| 388 |
+
@(posedge clk);
|
| 389 |
+
@(posedge clk);
|
| 390 |
+
@(posedge clk);
|
| 391 |
+
@(posedge clk);
|
| 392 |
+
@(posedge clk);
|
| 393 |
+
@(posedge clk);
|
| 394 |
+
@(posedge clk);
|
| 395 |
+
@(posedge clk);
|
| 396 |
+
|
| 397 |
+
$display(" End Clock %d",count);
|
| 398 |
+
fp = $fopen("sim.dat");
|
| 399 |
+
$fwrite(fp,"%0d\n",OutWidth);
|
| 400 |
+
$fwrite(fp,"%0d\n",OutHeight);
|
| 401 |
+
|
| 402 |
+
for(i=0;i<OutWidth*OutHeight;i=i+1) begin
|
| 403 |
+
$fwrite(fp,"%06x\n",rgb_mem[i]);
|
| 404 |
+
end
|
| 405 |
+
$fclose(fp);
|
| 406 |
+
|
| 407 |
+
// $coverage_save("sim.cov");
|
| 408 |
+
$finish();
|
| 409 |
+
//$stop();
|
| 410 |
+
end
|
| 411 |
+
|
| 412 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_axi_djpeg.v
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_axi_djpeg
|
| 22 |
+
#(
|
| 23 |
+
parameter C_BASEADRS = 32'h4001_0000,
|
| 24 |
+
parameter C_ADRSWIDTH = 8
|
| 25 |
+
)
|
| 26 |
+
(
|
| 27 |
+
input RST_N,
|
| 28 |
+
input CLK,
|
| 29 |
+
|
| 30 |
+
// --------------------------------------------------
|
| 31 |
+
// AXI4 Lite Interface
|
| 32 |
+
// --------------------------------------------------
|
| 33 |
+
input S_AXI_ACLK,
|
| 34 |
+
|
| 35 |
+
// Write Address Channel
|
| 36 |
+
input [31:0] S_AXI_AWADDR,
|
| 37 |
+
input [3:0] S_AXI_AWCACHE,
|
| 38 |
+
input [2:0] S_AXI_AWPROT,
|
| 39 |
+
input S_AXI_AWVALID,
|
| 40 |
+
output S_AXI_AWREADY,
|
| 41 |
+
|
| 42 |
+
// Write Data Channel
|
| 43 |
+
input [31:0] S_AXI_WDATA,
|
| 44 |
+
input [3:0] S_AXI_WSTRB,
|
| 45 |
+
input S_AXI_WVALID,
|
| 46 |
+
output S_AXI_WREADY,
|
| 47 |
+
|
| 48 |
+
// Write Response Channel
|
| 49 |
+
output S_AXI_BVALID,
|
| 50 |
+
input S_AXI_BREADY,
|
| 51 |
+
output [1:0] S_AXI_BRESP,
|
| 52 |
+
|
| 53 |
+
// Read Address Channel
|
| 54 |
+
input [31:0] S_AXI_ARADDR,
|
| 55 |
+
input [3:0] S_AXI_ARCACHE,
|
| 56 |
+
input [2:0] S_AXI_ARPROT,
|
| 57 |
+
input S_AXI_ARVALID,
|
| 58 |
+
output S_AXI_ARREADY,
|
| 59 |
+
|
| 60 |
+
// Read Data Channel
|
| 61 |
+
output [31:0] S_AXI_RDATA,
|
| 62 |
+
output [1:0] S_AXI_RRESP,
|
| 63 |
+
output S_AXI_RVALID,
|
| 64 |
+
input S_AXI_RREADY,
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
// JPEG Data In
|
| 68 |
+
input [31:0] DATA_IN,
|
| 69 |
+
input EMPTY,
|
| 70 |
+
output READ,
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
// Bitmap Data Out
|
| 74 |
+
output [31:0] DATA_OUT,
|
| 75 |
+
output WRITE,
|
| 76 |
+
input FULL,
|
| 77 |
+
|
| 78 |
+
output [31:0] DEBUG
|
| 79 |
+
);
|
| 80 |
+
|
| 81 |
+
wire local_cs;
|
| 82 |
+
wire local_rnw;
|
| 83 |
+
wire local_ack;
|
| 84 |
+
wire [31:0] local_addr;
|
| 85 |
+
wire [3:0] local_be;
|
| 86 |
+
wire [31:0] local_wdata;
|
| 87 |
+
wire [31:0] local_rdata;
|
| 88 |
+
|
| 89 |
+
wire Empty, Read;
|
| 90 |
+
wire [31:0] Data;
|
| 91 |
+
|
| 92 |
+
wire JpegDecodeIdle;
|
| 93 |
+
wire [15:0] OutWidth, OutHeight, OutPixelX, OutPixelY;
|
| 94 |
+
wire [7:0] OutR, OutG, OutB;
|
| 95 |
+
|
| 96 |
+
aq_axi_lite_slave
|
| 97 |
+
#(
|
| 98 |
+
.C_BASEADRS(C_BASEADRS),
|
| 99 |
+
.C_ADRSWIDTH(C_ADRSWIDTH)
|
| 100 |
+
)
|
| 101 |
+
u_aq_axi_lite_slave
|
| 102 |
+
(
|
| 103 |
+
.ARESETN(RST_N),
|
| 104 |
+
.ACLK(S_AXI_ACLK),
|
| 105 |
+
|
| 106 |
+
.S_AXI_AWADDR(S_AXI_AWADDR),
|
| 107 |
+
.S_AXI_AWCACHE(S_AXI_AWCACHE),
|
| 108 |
+
.S_AXI_AWPROT(S_AXI_AWPROT),
|
| 109 |
+
.S_AXI_AWVALID(S_AXI_AWVALID),
|
| 110 |
+
.S_AXI_AWREADY(S_AXI_AWREADY),
|
| 111 |
+
|
| 112 |
+
.S_AXI_WDATA(S_AXI_WDATA),
|
| 113 |
+
.S_AXI_WSTRB(S_AXI_WSTRB),
|
| 114 |
+
.S_AXI_WVALID(S_AXI_WVALID),
|
| 115 |
+
.S_AXI_WREADY(S_AXI_WREADY),
|
| 116 |
+
|
| 117 |
+
.S_AXI_BVALID(S_AXI_BVALID),
|
| 118 |
+
.S_AXI_BREADY(S_AXI_BREADY),
|
| 119 |
+
.S_AXI_BRESP(S_AXI_BRESP),
|
| 120 |
+
|
| 121 |
+
.S_AXI_ARADDR(S_AXI_ARADDR),
|
| 122 |
+
.S_AXI_ARCACHE(S_AXI_ARCACHE),
|
| 123 |
+
.S_AXI_ARPROT(S_AXI_ARPROT),
|
| 124 |
+
.S_AXI_ARVALID(S_AXI_ARVALID),
|
| 125 |
+
.S_AXI_ARREADY(S_AXI_ARREADY),
|
| 126 |
+
|
| 127 |
+
.S_AXI_RDATA(S_AXI_RDATA),
|
| 128 |
+
.S_AXI_RRESP(S_AXI_RRESP),
|
| 129 |
+
.S_AXI_RVALID(S_AXI_RVALID),
|
| 130 |
+
.S_AXI_RREADY(S_AXI_RREADY),
|
| 131 |
+
|
| 132 |
+
.LOCAL_CS(local_cs),
|
| 133 |
+
.LOCAL_RNW(local_rnw),
|
| 134 |
+
.LOCAL_ACK(local_ack),
|
| 135 |
+
.LOCAL_ADDR(local_addr),
|
| 136 |
+
.LOCAL_BE(local_be),
|
| 137 |
+
.LOCAL_WDATA(local_wdata),
|
| 138 |
+
.LOCAL_RDATA(local_rdata),
|
| 139 |
+
|
| 140 |
+
.DEBUG(debug_slave)
|
| 141 |
+
);
|
| 142 |
+
|
| 143 |
+
wire JpegDecodeRst;
|
| 144 |
+
|
| 145 |
+
aq_djpeg u_aq_djpeg(
|
| 146 |
+
.rst ( ~JpegDecodeRst ),
|
| 147 |
+
.clk ( CLK ),
|
| 148 |
+
|
| 149 |
+
// From FIFO
|
| 150 |
+
.DataIn ( DATA_IN[31:0] ),
|
| 151 |
+
.DataInEnable ( ~EMPTY ),
|
| 152 |
+
.DataInRead ( READ ),
|
| 153 |
+
|
| 154 |
+
.JpegDecodeIdle ( JpegDecodeIdle ),
|
| 155 |
+
|
| 156 |
+
.OutEnable ( WRITE ),
|
| 157 |
+
.OutWidth ( OutWidth[15:0] ),
|
| 158 |
+
.OutHeight ( OutHeight[15:0] ),
|
| 159 |
+
.OutPixelX ( OutPixelX[15:0] ),
|
| 160 |
+
.OutPixelY ( OutPixelY[15:0] ),
|
| 161 |
+
.OutR ( OutR[7:0] ),
|
| 162 |
+
.OutG ( OutG[7:0] ),
|
| 163 |
+
.OutB ( OutB[7:0] )
|
| 164 |
+
);
|
| 165 |
+
|
| 166 |
+
assign DATA_OUT[31:0] = {8'd0, OutR[7:0], OutG[7:0], OutB[7:0]};
|
| 167 |
+
//assign DATA_OUT[31:0] = {OutPixelY[15:0], OutPixelX[15:0]};
|
| 168 |
+
|
| 169 |
+
aq_axi_djpeg_ctl u_aq_axi_djpeg_ctl
|
| 170 |
+
(
|
| 171 |
+
.RST_N(RST_N),
|
| 172 |
+
.CLK(S_AXI_ACLK),
|
| 173 |
+
|
| 174 |
+
.LOCAL_CS(local_cs),
|
| 175 |
+
.LOCAL_RNW(local_rnw),
|
| 176 |
+
.LOCAL_ACK(local_ack),
|
| 177 |
+
.LOCAL_ADDR(local_addr),
|
| 178 |
+
.LOCAL_BE(local_be),
|
| 179 |
+
.LOCAL_WDATA(local_wdata),
|
| 180 |
+
.LOCAL_RDATA(local_rdata),
|
| 181 |
+
|
| 182 |
+
.LOGIC_RST(JpegDecodeRst),
|
| 183 |
+
.LOGIC_IDLE(JpegDecodeIdle),
|
| 184 |
+
|
| 185 |
+
.WIDTH(OutWidth[15:0]),
|
| 186 |
+
.HEIGHT(OutHeight[15:0]),
|
| 187 |
+
.PIXELX(OutPixelX[15:0]),
|
| 188 |
+
.PIXELY(OutPixelY[15:0]),
|
| 189 |
+
|
| 190 |
+
.DEBUG()
|
| 191 |
+
);
|
| 192 |
+
|
| 193 |
+
assign DEBUG = {24'd0, 2'b00, S_AXI_RREADY, S_AXI_RVALID, local_ack, local_rnw, local_cs, RST_N};
|
| 194 |
+
|
| 195 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_axi_djpeg_ctrl.v
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
module aq_axi_djpeg_ctl(
|
| 20 |
+
input RST_N,
|
| 21 |
+
input CLK,
|
| 22 |
+
|
| 23 |
+
input LOCAL_CS,
|
| 24 |
+
input LOCAL_RNW,
|
| 25 |
+
output LOCAL_ACK,
|
| 26 |
+
input [31:0] LOCAL_ADDR,
|
| 27 |
+
input [3:0] LOCAL_BE,
|
| 28 |
+
input [31:0] LOCAL_WDATA,
|
| 29 |
+
output [31:0] LOCAL_RDATA,
|
| 30 |
+
|
| 31 |
+
output LOGIC_RST,
|
| 32 |
+
input LOGIC_IDLE,
|
| 33 |
+
|
| 34 |
+
input [15:0] WIDTH,
|
| 35 |
+
input [15:0] HEIGHT,
|
| 36 |
+
input [15:0] PIXELX,
|
| 37 |
+
input [15:0] PIXELY,
|
| 38 |
+
|
| 39 |
+
output [31:0] DEBUG
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
localparam A_STATUS = 8'h00;
|
| 43 |
+
localparam A_SIZE = 8'h04;
|
| 44 |
+
localparam A_PIXEL = 8'h08;
|
| 45 |
+
|
| 46 |
+
wire wr_ena, rd_ena, wr_ack;
|
| 47 |
+
reg rd_ack;
|
| 48 |
+
|
| 49 |
+
reg [31:0] reg_rdata;
|
| 50 |
+
|
| 51 |
+
reg reg_rst;
|
| 52 |
+
|
| 53 |
+
assign wr_ena = (LOCAL_CS & ~LOCAL_RNW)?1'b1:1'b0;
|
| 54 |
+
assign rd_ena = (LOCAL_CS & LOCAL_RNW)?1'b1:1'b0;
|
| 55 |
+
assign wr_ack = wr_ena;
|
| 56 |
+
|
| 57 |
+
// Write Register
|
| 58 |
+
always @(posedge CLK or negedge RST_N) begin
|
| 59 |
+
if(!RST_N) begin
|
| 60 |
+
reg_rst <= 1'b0;
|
| 61 |
+
end else begin
|
| 62 |
+
if(wr_ena) begin
|
| 63 |
+
case(LOCAL_ADDR[7:0] & 8'hFC)
|
| 64 |
+
A_STATUS: begin
|
| 65 |
+
reg_rst <= LOCAL_WDATA[31];
|
| 66 |
+
end
|
| 67 |
+
A_SIZE: begin
|
| 68 |
+
end
|
| 69 |
+
A_PIXEL: begin
|
| 70 |
+
end
|
| 71 |
+
default: begin
|
| 72 |
+
end
|
| 73 |
+
endcase
|
| 74 |
+
end
|
| 75 |
+
end
|
| 76 |
+
end
|
| 77 |
+
|
| 78 |
+
// Read Register
|
| 79 |
+
always @(posedge CLK or negedge RST_N) begin
|
| 80 |
+
if(!RST_N) begin
|
| 81 |
+
reg_rdata[31:0] <= 32'd0;
|
| 82 |
+
rd_ack <= 1'b0;
|
| 83 |
+
end else begin
|
| 84 |
+
rd_ack <= rd_ena;
|
| 85 |
+
if(rd_ena) begin
|
| 86 |
+
case(LOCAL_ADDR[7:0] & 8'hFC)
|
| 87 |
+
A_STATUS: begin
|
| 88 |
+
reg_rdata[31:0] <= {reg_rst, 30'd0, LOGIC_IDLE};
|
| 89 |
+
end
|
| 90 |
+
A_SIZE: begin
|
| 91 |
+
reg_rdata[31:0] <= {HEIGHT[15:0], WIDTH[15:0]};
|
| 92 |
+
end
|
| 93 |
+
A_PIXEL: begin
|
| 94 |
+
reg_rdata[31:0] <= {PIXELY[15:0], PIXELX[15:0]};
|
| 95 |
+
end
|
| 96 |
+
default: begin
|
| 97 |
+
reg_rdata[31:0] <= 32'd0;
|
| 98 |
+
end
|
| 99 |
+
endcase
|
| 100 |
+
end else begin
|
| 101 |
+
reg_rdata[31:0] <= 32'd0;
|
| 102 |
+
end
|
| 103 |
+
end
|
| 104 |
+
end
|
| 105 |
+
|
| 106 |
+
assign LOGIC_RST = reg_rst;
|
| 107 |
+
|
| 108 |
+
assign LOC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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
module aq_axi_lite_slave
|
| 20 |
+
#(
|
| 21 |
+
parameter C_BASEADRS = 32'h0000_0000,
|
| 22 |
+
parameter C_ADRSWIDTH = 16
|
| 23 |
+
)
|
| 24 |
+
(
|
| 25 |
+
// AXI4 Lite Interface
|
| 26 |
+
input ARESETN,
|
| 27 |
+
input ACLK,
|
| 28 |
+
|
| 29 |
+
// Write Address Channel
|
| 30 |
+
input [31:0] S_AXI_AWADDR,
|
| 31 |
+
input [3:0] S_AXI_AWCACHE, // 4'b0011
|
| 32 |
+
input [2:0] S_AXI_AWPROT, // 3'b000
|
| 33 |
+
input S_AXI_AWVALID,
|
| 34 |
+
output S_AXI_AWREADY,
|
| 35 |
+
|
| 36 |
+
// Write Data Channel
|
| 37 |
+
input [31:0] S_AXI_WDATA,
|
| 38 |
+
input [3:0] S_AXI_WSTRB,
|
| 39 |
+
input S_AXI_WVALID,
|
| 40 |
+
output S_AXI_WREADY,
|
| 41 |
+
|
| 42 |
+
// Write Response Channel
|
| 43 |
+
output S_AXI_BVALID,
|
| 44 |
+
input S_AXI_BREADY,
|
| 45 |
+
output [1:0] S_AXI_BRESP,
|
| 46 |
+
|
| 47 |
+
// Read Address Channel
|
| 48 |
+
input [31:0] S_AXI_ARADDR,
|
| 49 |
+
input [3:0] S_AXI_ARCACHE, // 4'b0011
|
| 50 |
+
input [2:0] S_AXI_ARPROT, // 3'b000
|
| 51 |
+
input S_AXI_ARVALID,
|
| 52 |
+
output S_AXI_ARREADY,
|
| 53 |
+
|
| 54 |
+
// Read Data Channel
|
| 55 |
+
output [31:0] S_AXI_RDATA,
|
| 56 |
+
output [1:0] S_AXI_RRESP,
|
| 57 |
+
output S_AXI_RVALID,
|
| 58 |
+
input S_AXI_RREADY,
|
| 59 |
+
|
| 60 |
+
// Local Interface
|
| 61 |
+
output LOCAL_CS,
|
| 62 |
+
output LOCAL_RNW,
|
| 63 |
+
input LOCAL_ACK,
|
| 64 |
+
output [31:0] LOCAL_ADDR,
|
| 65 |
+
output [3:0] LOCAL_BE,
|
| 66 |
+
output [31:0] LOCAL_WDATA,
|
| 67 |
+
input [31:0] LOCAL_RDATA,
|
| 68 |
+
|
| 69 |
+
output [31:0] DEBUG
|
| 70 |
+
);
|
| 71 |
+
|
| 72 |
+
/*
|
| 73 |
+
CACHE[3:0]
|
| 74 |
+
WA RA C B
|
| 75 |
+
0 0 0 0 Noncacheable and nonbufferable
|
| 76 |
+
0 0 0 1 Bufferable only
|
| 77 |
+
0 0 1 0 Cacheable, but do not allocate
|
| 78 |
+
0 0 1 1 Cacheable and Bufferable, but do not allocate
|
| 79 |
+
0 1 1 0 Cacheable write-through, allocate on reads only
|
| 80 |
+
0 1 1 1 Cacheable write-back, allocate on reads only
|
| 81 |
+
1 0 1 0 Cacheable write-through, allocate on write only
|
| 82 |
+
1 0 1 1 Cacheable write-back, allocate on writes only
|
| 83 |
+
1 1 1 0 Cacheable write-through, allocate on both reads and writes
|
| 84 |
+
1 1 1 1 Cacheable write-back, allocate on both reads and writes
|
| 85 |
+
|
| 86 |
+
PROR
|
| 87 |
+
[2]:0:Data Access
|
| 88 |
+
1:Instruction Access
|
| 89 |
+
[1]:0:Secure Access
|
| 90 |
+
1:NoSecure Access
|
| 91 |
+
[0]:0:Privileged Access
|
| 92 |
+
1:Normal Access
|
| 93 |
+
|
| 94 |
+
RESP
|
| 95 |
+
00: OK
|
| 96 |
+
01: EXOK
|
| 97 |
+
10: SLVERR
|
| 98 |
+
11: DECERR
|
| 99 |
+
*/
|
| 100 |
+
|
| 101 |
+
localparam S_IDLE = 2'd0;
|
| 102 |
+
localparam S_WRITE = 2'd1;
|
| 103 |
+
localparam S_WRITE2 = 2'd2;
|
| 104 |
+
localparam S_READ = 2'd3;
|
| 105 |
+
|
| 106 |
+
reg [1:0] state;
|
| 107 |
+
reg reg_rnw;
|
| 108 |
+
reg [31:0] reg_addr, reg_wdata;
|
| 109 |
+
reg [3:0] reg_be;
|
| 110 |
+
|
| 111 |
+
always @( posedge ACLK or negedge ARESETN ) begin
|
| 112 |
+
if( !ARESETN ) begin
|
| 113 |
+
state <= S_IDLE;
|
| 114 |
+
reg_rnw <= 1'b0;
|
| 115 |
+
reg_addr <= 32'd0;
|
| 116 |
+
reg_wdata <= 32'd0;
|
| 117 |
+
reg_be <= 4'd0;
|
| 118 |
+
end else begin
|
| 119 |
+
case( state )
|
| 120 |
+
S_IDLE: begin
|
| 121 |
+
if( S_AXI_AWVALID && ( S_AXI_AWADDR[31:(32 - C_ADRSWIDTH)] == C_BASEADRS[31:(32 - C_ADRSWIDTH)] ) ) begin
|
| 122 |
+
reg_rnw <= 1'b0;
|
| 123 |
+
reg_addr <= S_AXI_AWADDR;
|
| 124 |
+
state <= S_WRITE;
|
| 125 |
+
end else if( S_AXI_ARVALID && (S_AXI_ARADDR[31:(32 - C_ADRSWIDTH)] == C_BASEADRS[31:(32 - C_ADRSWIDTH)]) ) begin
|
| 126 |
+
reg_rnw <= 1'b1;
|
| 127 |
+
reg_addr <= S_AXI_ARADDR;
|
| 128 |
+
state <= S_READ;
|
| 129 |
+
end
|
| 130 |
+
end
|
| 131 |
+
S_WRITE: begin
|
| 132 |
+
if( S_AXI_WVALID ) begin
|
| 133 |
+
state <= S_WRITE2;
|
| 134 |
+
reg_wdata <= S_AXI_WDATA;
|
| 135 |
+
reg_be <= S_AXI_WSTRB;
|
| 136 |
+
end
|
| 137 |
+
end
|
| 138 |
+
S_WRITE2: begin
|
| 139 |
+
if( LOCAL_ACK & S_AXI_BREADY ) begin
|
| 140 |
+
state <= S_IDLE;
|
| 141 |
+
end
|
| 142 |
+
end
|
| 143 |
+
S_READ: begin
|
| 144 |
+
if( LOCAL_ACK & S_AXI_RREADY ) begin
|
| 145 |
+
state <= S_IDLE;
|
| 146 |
+
end
|
| 147 |
+
end
|
| 148 |
+
default: begin
|
| 149 |
+
state <= S_IDLE;
|
| 150 |
+
end
|
| 151 |
+
endcase
|
| 152 |
+
end
|
| 153 |
+
end
|
| 154 |
+
|
| 155 |
+
// Local Interface
|
| 156 |
+
assign LOCAL_CS = (( state == S_WRITE2 )?1'b1:1'b0) | (( state == S_READ )?1'b1:1'b0) | 1'b0;
|
| 157 |
+
assign LOCAL_RNW = reg_rnw;
|
| 158 |
+
assign LOCAL_ADDR = reg_addr;
|
| 159 |
+
assign LOCAL_BE = reg_be;
|
| 160 |
+
assign LOCAL_WDATA = reg_wdata;
|
| 161 |
+
|
| 162 |
+
// Write Channel
|
| 163 |
+
assign S_AXI_AWREADY = ( state == S_WRITE )?S_AXI_AWVALID:1'b0;
|
| 164 |
+
assign S_AXI_WREADY = ( state == S_WRITE )?S_AXI_WVALID:1'b0;
|
| 165 |
+
assign S_AXI_BVALID = ( state == S_WRITE2 )?LOCAL_ACK:1'b0;
|
| 166 |
+
assign S_AXI_BRESP = 2'b00;
|
| 167 |
+
|
| 168 |
+
// Read Channel
|
| 169 |
+
assign S_AXI_ARREADY = ( state == S_READ )?S_AXI_ARVALID:1'b0;
|
| 170 |
+
assign S_AXI_RVALID = ( state == S_READ )?LOCAL_ACK:1'b0;
|
| 171 |
+
assign S_AXI_RRESP = 2'b00;
|
| 172 |
+
assign S_AXI_RDATA = ( state == S_READ )?LOCAL_RDATA:32'd0;
|
| 173 |
+
|
| 174 |
+
// Debug
|
| 175 |
+
assign DEBUG[31:0] = {24'd0, 1'd0, S_AXI_RVALID, S_AXI_ARREADY, LOCAL_ACK, LOCAL_RNW, LOCAL_CS, state[1:0]};
|
| 176 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg.v
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
|
| 25 |
+
// From FIFO
|
| 26 |
+
input [31:0] DataIn,
|
| 27 |
+
input DataInEnable,
|
| 28 |
+
output DataInRead,
|
| 29 |
+
|
| 30 |
+
output JpegDecodeIdle, // Deocdeer Process Idle(1:Idle, 0:Run)
|
| 31 |
+
|
| 32 |
+
output OutEnable,
|
| 33 |
+
output [15:0] OutWidth,
|
| 34 |
+
output [15:0] OutHeight,
|
| 35 |
+
output [15:0] OutPixelX,
|
| 36 |
+
output [15:0] OutPixelY,
|
| 37 |
+
output [7:0] OutR,
|
| 38 |
+
output [7:0] OutG,
|
| 39 |
+
output [7:0] OutB
|
| 40 |
+
);
|
| 41 |
+
wire [31:0] JpegData;
|
| 42 |
+
wire JpegDataEnable;
|
| 43 |
+
wire JpegDecodeIdle;
|
| 44 |
+
|
| 45 |
+
wire UseBit;
|
| 46 |
+
wire [6:0] UseWidth;
|
| 47 |
+
wire UseByte;
|
| 48 |
+
wire UseWord;
|
| 49 |
+
|
| 50 |
+
wire ImageEnable;
|
| 51 |
+
wire EnableFF00;
|
| 52 |
+
wire DataInFull;
|
| 53 |
+
|
| 54 |
+
//reg ProcessIdle;
|
| 55 |
+
|
| 56 |
+
wire JpegDataEnableW;
|
| 57 |
+
|
| 58 |
+
assign JpegDataEnable = (!DataInFull)?JpegDataEnableW:1'b0;
|
| 59 |
+
|
| 60 |
+
//--------------------------------------------------------------------------
|
| 61 |
+
// Read JPEG Data from FIFO
|
| 62 |
+
//--------------------------------------------------------------------------
|
| 63 |
+
aq_djpeg_regdata u_jpeg_regdata(
|
| 64 |
+
.rst ( rst ),
|
| 65 |
+
.clk ( clk ),
|
| 66 |
+
|
| 67 |
+
// Read Data
|
| 68 |
+
.DataIn ( DataIn ),
|
| 69 |
+
.DataInEnable ( DataInEnable ),
|
| 70 |
+
.DataInRead ( DataInRead ),
|
| 71 |
+
|
| 72 |
+
// DataOut
|
| 73 |
+
.DataOut ( JpegData ),
|
| 74 |
+
.DataOutEnable ( JpegDataEnableW ),
|
| 75 |
+
|
| 76 |
+
//
|
| 77 |
+
.ImageEnable ( ImageEnable ),
|
| 78 |
+
.ProcessIdle ( JpegDecodeIdle ),
|
| 79 |
+
|
| 80 |
+
// UseData
|
| 81 |
+
.UseBit ( UseBit ),
|
| 82 |
+
.UseWidth ( UseWidth ),
|
| 83 |
+
.UseByte ( UseByte ),
|
| 84 |
+
.UseWord ( UseWord )
|
| 85 |
+
);
|
| 86 |
+
|
| 87 |
+
//--------------------------------------------------------------------------
|
| 88 |
+
// Read Maker from Jpeg Data
|
| 89 |
+
//--------------------------------------------------------------------------
|
| 90 |
+
wire DqtEnable;
|
| 91 |
+
wire DqtTable;
|
| 92 |
+
wire [5:0] DqtCount;
|
| 93 |
+
wire [7:0] DqtData;
|
| 94 |
+
|
| 95 |
+
wire DhtEnable;
|
| 96 |
+
wire [1:0] DhtTable;
|
| 97 |
+
wire [7:0] DhtCount;
|
| 98 |
+
wire [7:0] DhtData;
|
| 99 |
+
|
| 100 |
+
//
|
| 101 |
+
wire HuffmanEnable;
|
| 102 |
+
wire [1:0] HuffmanTable;
|
| 103 |
+
wire [3:0] HuffmanCount;
|
| 104 |
+
wire [15:0] HuffmanData;
|
| 105 |
+
wire [7:0] HuffmanStart;
|
| 106 |
+
|
| 107 |
+
wire [11:0] JpegBlockWidth;
|
| 108 |
+
wire [2:0] JpegComp;
|
| 109 |
+
|
| 110 |
+
aq_djpeg_fsm u_jpeg_fsm(
|
| 111 |
+
.rst ( rst ),
|
| 112 |
+
.clk ( clk ),
|
| 113 |
+
|
| 114 |
+
// From FIFO
|
| 115 |
+
.DataInEnable ( JpegDataEnable ),
|
| 116 |
+
.DataIn ( JpegData ),
|
| 117 |
+
|
| 118 |
+
.JpegDecodeIdle ( JpegDecodeIdle ),
|
| 119 |
+
|
| 120 |
+
.OutWidth ( OutWidth ),
|
| 121 |
+
.OutHeight ( OutHeight ),
|
| 122 |
+
.OutBlockWidth ( JpegBlockWidth ),
|
| 123 |
+
.OutEnable ( OutEnable ),
|
| 124 |
+
.OutPixelX ( OutPixelX ),
|
| 125 |
+
.OutPixelY ( OutPixelY ),
|
| 126 |
+
|
| 127 |
+
//
|
| 128 |
+
.DqtEnable ( DqtEnable ),
|
| 129 |
+
.DqtTable ( DqtTable ),
|
| 130 |
+
.DqtCount ( DqtCount ),
|
| 131 |
+
.DqtData ( DqtData ),
|
| 132 |
+
|
| 133 |
+
//
|
| 134 |
+
.DhtEnable ( DhtEnable ),
|
| 135 |
+
.DhtTable ( DhtTable ),
|
| 136 |
+
.DhtCount ( DhtCount ),
|
| 137 |
+
.DhtData ( DhtData ),
|
| 138 |
+
|
| 139 |
+
//
|
| 140 |
+
.HuffmanEnable ( HuffmanEnable ),
|
| 141 |
+
.HuffmanTable ( HuffmanTable ),
|
| 142 |
+
.HuffmanCount ( HuffmanCount ),
|
| 143 |
+
.HuffmanData ( HuffmanData ),
|
| 144 |
+
.HuffmanStart ( HuffmanStart ),
|
| 145 |
+
|
| 146 |
+
//
|
| 147 |
+
.ImageEnable ( ImageEnable ),
|
| 148 |
+
.JpegComp ( JpegComp ),
|
| 149 |
+
|
| 150 |
+
//
|
| 151 |
+
.UseByte ( UseByte ),
|
| 152 |
+
.UseWord ( UseWord )
|
| 153 |
+
);
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
wire HmDecEnable;
|
| 157 |
+
wire [2:0] HmDecColor;
|
| 158 |
+
wire HmRead;
|
| 159 |
+
wire [4:0] HmAddress;
|
| 160 |
+
|
| 161 |
+
wire [15:0] HmDataA, HmDataB;
|
| 162 |
+
|
| 163 |
+
aq_djpeg_huffman u_jpeg_huffman(
|
| 164 |
+
.rst ( rst ),
|
| 165 |
+
.clk ( clk ),
|
| 166 |
+
|
| 167 |
+
.ProcessInit ( JpegDecodeIdle ),
|
| 168 |
+
|
| 169 |
+
// DQT Table
|
| 170 |
+
.DqtInEnable ( DqtEnable ),
|
| 171 |
+
.DqtInColor ( DqtTable ),
|
| 172 |
+
.DqtInCount ( DqtCount[5:0] ),
|
| 173 |
+
.DqtInData ( DqtData ),
|
| 174 |
+
|
| 175 |
+
// DHT Table
|
| 176 |
+
.DhtInEnable ( DhtEnable ),
|
| 177 |
+
.DhtInColor ( DhtTable ),
|
| 178 |
+
.DhtInCount ( DhtCount ),
|
| 179 |
+
.DhtInData ( DhtData ),
|
| 180 |
+
|
| 181 |
+
// Huffman Table
|
| 182 |
+
.HuffmanTableEnable ( HuffmanEnable ),
|
| 183 |
+
.HuffmanTableColor ( HuffmanTable ),
|
| 184 |
+
.HuffmanTableCount ( HuffmanCount ),
|
| 185 |
+
.HuffmanTableCode ( HuffmanData ),
|
| 186 |
+
.HuffmanTableStart ( HuffmanStart ),
|
| 187 |
+
|
| 188 |
+
// Huffman Decode
|
| 189 |
+
.DataInRun ( ImageEnable ),
|
| 190 |
+
.DataInEnable ( JpegDataEnable ),
|
| 191 |
+
.DataIn ( JpegData ),
|
| 192 |
+
.JpegComp ( JpegComp ),
|
| 193 |
+
|
| 194 |
+
// Output decode data
|
| 195 |
+
.DecodeUseBit ( UseBit ),
|
| 196 |
+
.DecodeUseWidth ( UseWidth ),
|
| 197 |
+
|
| 198 |
+
// Data Out
|
| 199 |
+
.DataOutEnable ( HmDecEnable ),
|
| 200 |
+
.DataOutRead ( HmRead ),
|
| 201 |
+
.DataOutAddress ( HmAddress ),
|
| 202 |
+
.DataOutColor ( HmDecColor ),
|
| 203 |
+
.DataOutA ( HmDataA ),
|
| 204 |
+
.DataOutB ( HmDataB )
|
| 205 |
+
);
|
| 206 |
+
|
| 207 |
+
wire DctEnable;
|
| 208 |
+
wire [2:0] DctColor;
|
| 209 |
+
wire [2:0] DctPage;
|
| 210 |
+
wire [1:0] DctCount;
|
| 211 |
+
wire [8:0] Dct0Data, Dct1Data;
|
| 212 |
+
|
| 213 |
+
wire [15:0] DctWidth, DctHeight;
|
| 214 |
+
wire [11:0] DctBlockX, DctBlockY;
|
| 215 |
+
|
| 216 |
+
wire YCbCrIdle;
|
| 217 |
+
|
| 218 |
+
aq_djpeg_idct u_jpeg_idct(
|
| 219 |
+
.rst ( rst ),
|
| 220 |
+
.clk ( clk ),
|
| 221 |
+
|
| 222 |
+
.ProcessInit ( JpegDecodeIdle ),
|
| 223 |
+
|
| 224 |
+
.DataInEnable ( HmDecEnable ),
|
| 225 |
+
.DataInRead ( HmRead ),
|
| 226 |
+
.DataInAddress ( HmAddress ),
|
| 227 |
+
.DataInA ( HmDataA ),
|
| 228 |
+
.DataInB ( HmDataB ),
|
| 229 |
+
|
| 230 |
+
.DataOutEnable ( DctEnable ),
|
| 231 |
+
.DataOutPage ( DctPage ),
|
| 232 |
+
.DataOutCount ( DctCount ),
|
| 233 |
+
.Data0Out ( Dct0Data ),
|
| 234 |
+
.Data1Out ( Dct1Data )
|
| 235 |
+
);
|
| 236 |
+
|
| 237 |
+
wire ColorEnable;
|
| 238 |
+
wire [15:0] ColorPixelX, ColorPixelY;
|
| 239 |
+
wire [7:0] ColorR, ColorG, ColorB;
|
| 240 |
+
aq_djpeg_ycbcr u_jpeg_ycbcr(
|
| 241 |
+
.rst ( rst ),
|
| 242 |
+
.clk ( clk ),
|
| 243 |
+
|
| 244 |
+
.ProcessInit ( JpegDecodeIdle ),
|
| 245 |
+
.JpegComp ( JpegComp ),
|
| 246 |
+
|
| 247 |
+
.DataInEnable ( DctEnable ),
|
| 248 |
+
.DataInPage ( DctPage ),
|
| 249 |
+
.DataInCount ( DctCount ),
|
| 250 |
+
.DataInIdle ( YCbCrIdle ),
|
| 251 |
+
.Data0In ( Dct0Data ),
|
| 252 |
+
.Data1In ( Dct1Data ),
|
| 253 |
+
.DataInBlockWidth ( JpegBlockWidth ),
|
| 254 |
+
.DataInFull ( DataInFull ),
|
| 255 |
+
|
| 256 |
+
.OutEnable ( ColorEnable ),
|
| 257 |
+
.OutPixelX ( ColorPixelX ),
|
| 258 |
+
.OutPixelY ( ColorPixelY ),
|
| 259 |
+
.OutR ( ColorR ),
|
| 260 |
+
.OutG ( ColorG ),
|
| 261 |
+
.OutB ( ColorB )
|
| 262 |
+
);
|
| 263 |
+
// OutData
|
| 264 |
+
// assign OutEnable = (ImageEnable)?ColorEnable:1'b0;
|
| 265 |
+
assign OutEnable = (ImageEnable && (ColorPixelX < OutWidth) && (ColorPixelY < OutHeight))?ColorEnable:1'b0;
|
| 266 |
+
assign OutPixelX = (ImageEnable)?ColorPixelX:16'd0;
|
| 267 |
+
assign OutPixelY = (ImageEnable)?ColorPixelY:16'd0;
|
| 268 |
+
assign OutR = (ImageEnable)?ColorR:8'd0;
|
| 269 |
+
assign OutG = (ImageEnable)?ColorG:8'd0;
|
| 270 |
+
assign OutB = (ImageEnable)?ColorB:8'd0;
|
| 271 |
+
|
| 272 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_dht.v
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_dht(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
|
| 25 |
+
input DataInEnable,
|
| 26 |
+
input [1:0] DataInColor,
|
| 27 |
+
input [7:0] DataInCount,
|
| 28 |
+
input [7:0] DataIn,
|
| 29 |
+
|
| 30 |
+
input [1:0] ColorNumber,
|
| 31 |
+
input [7:0] TableNumber,
|
| 32 |
+
output [3:0] ZeroTable,
|
| 33 |
+
output [3:0] WidhtTable
|
| 34 |
+
);
|
| 35 |
+
// RAM
|
| 36 |
+
reg [7:0] DHT_Ydc [0:15];
|
| 37 |
+
reg [7:0] DHT_Yac [0:255];
|
| 38 |
+
reg [7:0] DHT_Cdc [0:15];
|
| 39 |
+
reg [7:0] DHT_Cac [0:255];
|
| 40 |
+
|
| 41 |
+
reg [7:0] ReadDataYdc;
|
| 42 |
+
reg [7:0] ReadDataYac;
|
| 43 |
+
reg [7:0] ReadDataCdc;
|
| 44 |
+
reg [7:0] ReadDataCac;
|
| 45 |
+
|
| 46 |
+
wire [7:0] ReadData;
|
| 47 |
+
|
| 48 |
+
// RAM
|
| 49 |
+
always @(posedge clk) begin
|
| 50 |
+
if((DataInEnable == 1'b1) & (DataInColor == 2'b00)) begin
|
| 51 |
+
DHT_Ydc[DataInCount[3:0]] <= DataIn;
|
| 52 |
+
end
|
| 53 |
+
if(DataInEnable ==1'b1 & DataInColor ==2'b01) begin
|
| 54 |
+
DHT_Yac[DataInCount] <= DataIn;
|
| 55 |
+
end
|
| 56 |
+
if(DataInEnable ==1'b1 & DataInColor ==2'b10) begin
|
| 57 |
+
DHT_Cdc[DataInCount[3:0]] <= DataIn;
|
| 58 |
+
end
|
| 59 |
+
if(DataInEnable ==1'b1 & DataInColor ==2'b11) begin
|
| 60 |
+
DHT_Cac[DataInCount] <= DataIn;
|
| 61 |
+
end
|
| 62 |
+
end
|
| 63 |
+
|
| 64 |
+
always @(posedge clk) begin
|
| 65 |
+
ReadDataYdc[7:0] <= DHT_Ydc[TableNumber[3:0]];
|
| 66 |
+
ReadDataYac[7:0] <= DHT_Yac[TableNumber];
|
| 67 |
+
ReadDataCdc[7:0] <= DHT_Cdc[TableNumber[3:0]];
|
| 68 |
+
ReadDataCac[7:0] <= DHT_Cac[TableNumber];
|
| 69 |
+
end
|
| 70 |
+
|
| 71 |
+
// Selector
|
| 72 |
+
function [7:0] ReadDataSel;
|
| 73 |
+
input [1:0] ColorNumber;
|
| 74 |
+
input [7:0] ReadDataYdc;
|
| 75 |
+
input [7:0] ReadDataYac;
|
| 76 |
+
input [7:0] ReadDataCdc;
|
| 77 |
+
input [7:0] ReadDataCac;
|
| 78 |
+
begin
|
| 79 |
+
case (ColorNumber[1:0])
|
| 80 |
+
2'b00: ReadDataSel[7:0] = ReadDataYdc[7:0];
|
| 81 |
+
2'b01: ReadDataSel[7:0] = ReadDataYac[7:0];
|
| 82 |
+
2'b10: ReadDataSel[7:0] = ReadDataCdc[7:0];
|
| 83 |
+
2'b11: ReadDataSel[7:0] = ReadDataCac[7:0];
|
| 84 |
+
endcase
|
| 85 |
+
end
|
| 86 |
+
endfunction
|
| 87 |
+
|
| 88 |
+
assign ReadData = ReadDataSel(ColorNumber, ReadDataYdc, ReadDataYac, ReadDataCdc, ReadDataCac);
|
| 89 |
+
|
| 90 |
+
assign ZeroTable = ReadData[7:4];
|
| 91 |
+
assign WidhtTable = ReadData[3:0];
|
| 92 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_dqt.v
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_dqt(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
|
| 25 |
+
input DataInEnable,
|
| 26 |
+
input DataInColor,
|
| 27 |
+
input [5:0] DataInCount,
|
| 28 |
+
input [7:0] DataIn,
|
| 29 |
+
|
| 30 |
+
input TableColor,
|
| 31 |
+
input [5:0] TableNumber,
|
| 32 |
+
output [7:0] TableData
|
| 33 |
+
);
|
| 34 |
+
// RAM
|
| 35 |
+
reg [7:0] DQT_Y [0:63];
|
| 36 |
+
reg [7:0] DQT_C [0:63];
|
| 37 |
+
|
| 38 |
+
// RAM
|
| 39 |
+
always @(posedge clk) begin
|
| 40 |
+
if(DataInEnable ==1'b1 && DataInColor ==1'b0) begin
|
| 41 |
+
DQT_Y[DataInCount] <= DataIn;
|
| 42 |
+
end
|
| 43 |
+
if(DataInEnable ==1'b1 && DataInColor ==1'b1) begin
|
| 44 |
+
DQT_C[DataInCount] <= DataIn;
|
| 45 |
+
end
|
| 46 |
+
end
|
| 47 |
+
|
| 48 |
+
reg [7:0] TableDataY;
|
| 49 |
+
reg [7:0] TableDataC;
|
| 50 |
+
|
| 51 |
+
// RAM out
|
| 52 |
+
always @(posedge clk) begin
|
| 53 |
+
TableDataY <= DQT_Y[TableNumber];
|
| 54 |
+
TableDataC <= DQT_C[TableNumber];
|
| 55 |
+
end
|
| 56 |
+
|
| 57 |
+
// Selector
|
| 58 |
+
assign TableData = (TableColor)?TableDataC:TableDataY;
|
| 59 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_fsm.v
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_fsm(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
|
| 25 |
+
// From FIFO
|
| 26 |
+
input DataInEnable,
|
| 27 |
+
input [31:0] DataIn,
|
| 28 |
+
|
| 29 |
+
output JpegDecodeIdle, // Deocder Process Idle(1:Idle, 0:Run)
|
| 30 |
+
|
| 31 |
+
//
|
| 32 |
+
output [15:0] OutWidth,
|
| 33 |
+
output [15:0] OutHeight,
|
| 34 |
+
output [11:0] OutBlockWidth,
|
| 35 |
+
input OutEnable,
|
| 36 |
+
input [15:0] OutPixelX,
|
| 37 |
+
input [15:0] OutPixelY,
|
| 38 |
+
|
| 39 |
+
//
|
| 40 |
+
output DqtEnable,
|
| 41 |
+
output DqtTable,
|
| 42 |
+
output [5:0] DqtCount,
|
| 43 |
+
output [7:0] DqtData,
|
| 44 |
+
|
| 45 |
+
//
|
| 46 |
+
output DhtEnable,
|
| 47 |
+
output [1:0] DhtTable,
|
| 48 |
+
output [7:0] DhtCount,
|
| 49 |
+
output [7:0] DhtData,
|
| 50 |
+
|
| 51 |
+
//
|
| 52 |
+
output HuffmanEnable,
|
| 53 |
+
output [1:0] HuffmanTable,
|
| 54 |
+
output [3:0] HuffmanCount,
|
| 55 |
+
output [15:0] HuffmanData,
|
| 56 |
+
output [7:0] HuffmanStart,
|
| 57 |
+
|
| 58 |
+
//
|
| 59 |
+
output ImageEnable,
|
| 60 |
+
output [2:0] JpegComp,
|
| 61 |
+
|
| 62 |
+
//
|
| 63 |
+
output UseByte,
|
| 64 |
+
output UseWord
|
| 65 |
+
);
|
| 66 |
+
|
| 67 |
+
//--------------------------------------------------------------------------
|
| 68 |
+
// Read Maker from Jpeg Data
|
| 69 |
+
//--------------------------------------------------------------------------
|
| 70 |
+
// State Machine localparam
|
| 71 |
+
localparam S_Idle = 5'd0;
|
| 72 |
+
localparam S_GetMarker = 5'd1;
|
| 73 |
+
localparam S_ImageData = 5'd2;
|
| 74 |
+
// APP Segment
|
| 75 |
+
localparam S_APPLength = 5'd3;
|
| 76 |
+
localparam S_APPRead = 5'd4;
|
| 77 |
+
// DQT Segment
|
| 78 |
+
localparam S_DQTLength = 5'd5;
|
| 79 |
+
localparam S_DQTTable = 5'd6;
|
| 80 |
+
localparam S_DQTRead = 5'd7;
|
| 81 |
+
// DHT Segmen
|
| 82 |
+
localparam S_DHTLength = 5'd8;
|
| 83 |
+
localparam S_DHTTable = 5'd9;
|
| 84 |
+
localparam S_DHTMakeHm0 = 5'd10;
|
| 85 |
+
localparam S_DHTMakeHm1 = 5'd11;
|
| 86 |
+
localparam S_DHTMakeHm2 = 5'd12;
|
| 87 |
+
localparam S_DHTReadTable = 5'd13;
|
| 88 |
+
// SOS Segment
|
| 89 |
+
localparam S_SOSLength = 5'd14;
|
| 90 |
+
localparam S_SOSRead0 = 5'd15;
|
| 91 |
+
localparam S_SOSRead1 = 5'd16;
|
| 92 |
+
localparam S_SOSRead2 = 5'd17;
|
| 93 |
+
localparam S_SOSRead3 = 5'd18;
|
| 94 |
+
localparam S_SOSRead4 = 5'd19;
|
| 95 |
+
// SOF Segment
|
| 96 |
+
localparam S_SOFLength = 5'd20;
|
| 97 |
+
localparam S_SOFRead0 = 5'd21;
|
| 98 |
+
localparam S_SOFReadY = 5'd22;
|
| 99 |
+
localparam S_SOFReadX = 5'd23;
|
| 100 |
+
localparam S_SOFReadComp = 5'd24;
|
| 101 |
+
localparam S_SOFReadCompColor = 5'd25;
|
| 102 |
+
localparam S_SOFReadCompColor0 = 5'd26;
|
| 103 |
+
localparam S_SOFReadCompColor1 = 5'd27;
|
| 104 |
+
localparam S_SOFReadCompColor2 = 5'd28;
|
| 105 |
+
localparam S_SOFMakeBlock0 = 5'd29;
|
| 106 |
+
localparam S_SOFMakeBlock1 = 5'd30;
|
| 107 |
+
|
| 108 |
+
reg [4:0] State;
|
| 109 |
+
//wire ImageEnable;
|
| 110 |
+
reg [15:0] ReadCount;
|
| 111 |
+
|
| 112 |
+
reg [15:0] JpegWidth;
|
| 113 |
+
reg [15:0] JpegHeight;
|
| 114 |
+
|
| 115 |
+
reg ReadDqtTable;
|
| 116 |
+
reg [1:0] ReadDhtTable;
|
| 117 |
+
|
| 118 |
+
reg [15:0] HmShift;
|
| 119 |
+
reg [15:0] HmData;
|
| 120 |
+
reg [7:0] HmMax;
|
| 121 |
+
reg [7:0] HmCount;
|
| 122 |
+
reg HmEnable;
|
| 123 |
+
|
| 124 |
+
reg [2:0] JpegComp;
|
| 125 |
+
reg [15:0] JpegBlockWidth;
|
| 126 |
+
reg [15:0] JpegBlockHeight;
|
| 127 |
+
|
| 128 |
+
reg ImageEnable;
|
| 129 |
+
|
| 130 |
+
always @(posedge clk or negedge rst) begin
|
| 131 |
+
if(!rst) begin
|
| 132 |
+
State <= S_Idle;
|
| 133 |
+
ReadCount <= 16'd0;
|
| 134 |
+
JpegWidth <= 16'd0;
|
| 135 |
+
JpegHeight <= 16'd0;
|
| 136 |
+
ReadDqtTable <= 1'b0;
|
| 137 |
+
ReadDhtTable <= 2'd0;
|
| 138 |
+
HmShift <= 16'd0;
|
| 139 |
+
HmData <= 16'd0;
|
| 140 |
+
HmMax <= 8'd0;
|
| 141 |
+
HmCount <= 8'd0;
|
| 142 |
+
HmEnable <= 1'b0;
|
| 143 |
+
JpegBlockWidth <= 16'd0;
|
| 144 |
+
JpegBlockHeight <= 16'd0;
|
| 145 |
+
JpegComp <= 3'd0;
|
| 146 |
+
ImageEnable <= 1'b0;
|
| 147 |
+
end else begin
|
| 148 |
+
case(State)
|
| 149 |
+
S_Idle: begin
|
| 150 |
+
if(DataInEnable == 1'b1) begin
|
| 151 |
+
State <= S_GetMarker;
|
| 152 |
+
end
|
| 153 |
+
end
|
| 154 |
+
|
| 155 |
+
// Get Marker(with Header)
|
| 156 |
+
S_GetMarker: begin
|
| 157 |
+
if(DataInEnable == 1'b1) begin
|
| 158 |
+
case(DataIn[31:16])
|
| 159 |
+
16'hFFD8: begin // SOI Segment
|
| 160 |
+
State <= S_GetMarker;
|
| 161 |
+
end
|
| 162 |
+
16'hFFE0: begin // APP0 Segment
|
| 163 |
+
State <= S_APPLength;
|
| 164 |
+
end
|
| 165 |
+
16'hFFDB: begin // DQT Segment
|
| 166 |
+
State <= S_DQTLength;
|
| 167 |
+
end
|
| 168 |
+
16'hFFC4: begin // DHT Segment
|
| 169 |
+
State <= S_DHTLength;
|
| 170 |
+
end
|
| 171 |
+
16'hFFC0: begin // SOF0 Segment
|
| 172 |
+
State <= S_SOFLength;
|
| 173 |
+
end
|
| 174 |
+
16'hFFDA: begin // SOS Segment
|
| 175 |
+
State <= S_SOSLength;
|
| 176 |
+
end
|
| 177 |
+
//16'hFFDD: begin // DRI Segment
|
| 178 |
+
// State <= S_DRI;
|
| 179 |
+
//end
|
| 180 |
+
//16'hFFDx: begin // RSTn Segment
|
| 181 |
+
// State <= S_RST;
|
| 182 |
+
//end
|
| 183 |
+
//16'hFFD9: begin // EOI Segment
|
| 184 |
+
// State <= S_EOI;
|
| 185 |
+
//end
|
| 186 |
+
default: begin
|
| 187 |
+
State <= S_APPLength;
|
| 188 |
+
end
|
| 189 |
+
endcase
|
| 190 |
+
end
|
| 191 |
+
end
|
| 192 |
+
|
| 193 |
+
// APP Segment
|
| 194 |
+
S_APPLength: begin
|
| 195 |
+
if(DataInEnable == 1'b1) begin
|
| 196 |
+
ReadCount <= DataIn[31:16] -16'd2;
|
| 197 |
+
State <= S_APPRead;
|
| 198 |
+
end
|
| 199 |
+
end
|
| 200 |
+
S_APPRead: begin
|
| 201 |
+
if(DataInEnable == 1'b1) begin
|
| 202 |
+
if(ReadCount == 16'd1) begin
|
| 203 |
+
State <= S_GetMarker;
|
| 204 |
+
end else begin
|
| 205 |
+
ReadCount <= ReadCount -16'd1;
|
| 206 |
+
end
|
| 207 |
+
end
|
| 208 |
+
end
|
| 209 |
+
|
| 210 |
+
// DQT Segment
|
| 211 |
+
S_DQTLength: begin
|
| 212 |
+
if(DataInEnable == 1'b1) begin
|
| 213 |
+
State <= S_DQTTable;
|
| 214 |
+
ReadCount <= DataIn[31:16] -16'd2;
|
| 215 |
+
end
|
| 216 |
+
end
|
| 217 |
+
S_DQTTable: begin
|
| 218 |
+
if(DataInEnable == 1'b1) begin
|
| 219 |
+
State <= S_DQTRead;
|
| 220 |
+
ReadDqtTable <= DataIn[24];
|
| 221 |
+
ReadCount <= 16'd0;
|
| 222 |
+
end
|
| 223 |
+
end
|
| 224 |
+
S_DQTRead: begin
|
| 225 |
+
if(DataInEnable == 1'b1) begin
|
| 226 |
+
if(ReadCount ==63) begin
|
| 227 |
+
State <= S_GetMarker;
|
| 228 |
+
end
|
| 229 |
+
ReadCount <= ReadCount +16'd1;
|
| 230 |
+
end
|
| 231 |
+
end
|
| 232 |
+
|
| 233 |
+
// DHT Segment
|
| 234 |
+
S_DHTLength: begin
|
| 235 |
+
if(DataInEnable == 1'b1) begin
|
| 236 |
+
State <= S_DHTTable;
|
| 237 |
+
ReadCount <= DataIn[31:16];
|
| 238 |
+
end
|
| 239 |
+
end
|
| 240 |
+
S_DHTTable: begin
|
| 241 |
+
if(DataInEnable == 1'b1) begin
|
| 242 |
+
State <= S_DHTMakeHm0;
|
| 243 |
+
case(DataIn[31:24])
|
| 244 |
+
8'h00: ReadDhtTable <= 2'b00;
|
| 245 |
+
8'h10: ReadDhtTable <= 2'b01;
|
| 246 |
+
8'h01: ReadDhtTable <= 2'b10;
|
| 247 |
+
8'h11: ReadDhtTable <= 2'b11;
|
| 248 |
+
endcase
|
| 249 |
+
end
|
| 250 |
+
HmShift <= 16'h8000;
|
| 251 |
+
HmData <= 16'h0000;
|
| 252 |
+
HmMax <= 8'h00;
|
| 253 |
+
ReadCount <= 16'd0;
|
| 254 |
+
end
|
| 255 |
+
S_DHTMakeHm0: begin
|
| 256 |
+
if(DataInEnable == 1'b1) begin
|
| 257 |
+
State <= S_DHTMakeHm1;
|
| 258 |
+
HmCount <= DataIn[31:24];
|
| 259 |
+
end
|
| 260 |
+
HmEnable <= 1'b0;
|
| 261 |
+
end
|
| 262 |
+
S_DHTMakeHm1: begin
|
| 263 |
+
State <= S_DHTMakeHm2;
|
| 264 |
+
HmMax <= HmMax + HmCount;
|
| 265 |
+
end
|
| 266 |
+
S_DHTMakeHm2: begin
|
| 267 |
+
if(HmCount != 0) begin
|
| 268 |
+
HmData <= HmData + HmShift;
|
| 269 |
+
HmCount <= HmCount -8'd1;
|
| 270 |
+
end else begin
|
| 271 |
+
if(ReadCount == 15) begin
|
| 272 |
+
State <= S_DHTReadTable;
|
| 273 |
+
HmCount <= 8'h00;
|
| 274 |
+
end else begin
|
| 275 |
+
HmEnable <= 1'b1;
|
| 276 |
+
State <= S_DHTMakeHm0;
|
| 277 |
+
ReadCount <= ReadCount +16'd1;
|
| 278 |
+
end
|
| 279 |
+
HmShift <= HmShift >> 1;
|
| 280 |
+
end
|
| 281 |
+
end
|
| 282 |
+
S_DHTReadTable: begin
|
| 283 |
+
HmEnable <= 1'b0;
|
| 284 |
+
if(DataInEnable == 1'b1) begin
|
| 285 |
+
if(HmMax == HmCount +1) begin
|
| 286 |
+
State <= S_GetMarker;
|
| 287 |
+
end
|
| 288 |
+
HmCount <= HmCount +8'd1;
|
| 289 |
+
end
|
| 290 |
+
end
|
| 291 |
+
|
| 292 |
+
// SOS Segment
|
| 293 |
+
S_SOSLength: begin
|
| 294 |
+
if(DataInEnable == 1'b1) begin
|
| 295 |
+
State <= S_SOSRead0;
|
| 296 |
+
ReadCount <= DataIn[31:16];
|
| 297 |
+
end
|
| 298 |
+
end
|
| 299 |
+
S_SOSRead0: begin
|
| 300 |
+
if(DataInEnable == 1'b1) begin
|
| 301 |
+
State <= S_SOSRead1;
|
| 302 |
+
ReadCount <= {8'h00,DataIn[31:24]};
|
| 303 |
+
end
|
| 304 |
+
end
|
| 305 |
+
S_SOSRead1: begin
|
| 306 |
+
if(DataInEnable == 1'b1) begin
|
| 307 |
+
if(ReadCount == 1) begin
|
| 308 |
+
State <= S_SOSRead2;
|
| 309 |
+
end else begin
|
| 310 |
+
ReadCount <= ReadCount -16'd1;
|
| 311 |
+
end
|
| 312 |
+
end
|
| 313 |
+
end
|
| 314 |
+
S_SOSRead2: begin
|
| 315 |
+
if(DataInEnable == 1'b1) begin
|
| 316 |
+
State <= S_SOSRead3;
|
| 317 |
+
end
|
| 318 |
+
end
|
| 319 |
+
S_SOSRead3: begin
|
| 320 |
+
if(DataInEnable == 1'b1) begin
|
| 321 |
+
State <= S_SOSRead4;
|
| 322 |
+
end
|
| 323 |
+
end
|
| 324 |
+
S_SOSRead4: begin
|
| 325 |
+
if(DataInEnable == 1'b1) begin
|
| 326 |
+
State <= S_ImageData;
|
| 327 |
+
ImageEnable <= 1'b1;
|
| 328 |
+
end
|
| 329 |
+
end
|
| 330 |
+
|
| 331 |
+
// SOF0 Segment
|
| 332 |
+
S_SOFLength: begin
|
| 333 |
+
if(DataInEnable == 1'b1) begin
|
| 334 |
+
State <= S_SOFRead0;
|
| 335 |
+
ReadCount <= DataIn[31:16];
|
| 336 |
+
end
|
| 337 |
+
end
|
| 338 |
+
S_SOFRead0: begin
|
| 339 |
+
if(DataInEnable == 1'b1) begin
|
| 340 |
+
State <= S_SOFReadY;
|
| 341 |
+
end
|
| 342 |
+
end
|
| 343 |
+
S_SOFReadY: begin
|
| 344 |
+
if(DataInEnable == 1'b1) begin
|
| 345 |
+
State <= S_SOFReadX;
|
| 346 |
+
JpegHeight <= DataIn[31:16];
|
| 347 |
+
JpegBlockHeight <= DataIn[31:16];
|
| 348 |
+
end
|
| 349 |
+
end
|
| 350 |
+
S_SOFReadX: begin
|
| 351 |
+
if(DataInEnable == 1'b1) begin
|
| 352 |
+
State <= S_SOFReadComp;
|
| 353 |
+
JpegWidth <= DataIn[31:16];
|
| 354 |
+
JpegBlockWidth <= DataIn[31:16];
|
| 355 |
+
ReadCount <= 16'd0;
|
| 356 |
+
end
|
| 357 |
+
end
|
| 358 |
+
S_SOFReadComp: begin
|
| 359 |
+
// コンポーネント数
|
| 360 |
+
// 1:グレースケール
|
| 361 |
+
// 3:YCbCr or YIQ
|
| 362 |
+
// 4:CMYK
|
| 363 |
+
if(DataInEnable == 1'b1) begin
|
| 364 |
+
State <= S_SOFReadCompColor;
|
| 365 |
+
JpegComp <= DataIn[26:24];
|
| 366 |
+
if(ReadCount == 9) begin
|
| 367 |
+
end else begin
|
| 368 |
+
ReadCount <= ReadCount +16'd1;
|
| 369 |
+
end
|
| 370 |
+
end
|
| 371 |
+
end
|
| 372 |
+
S_SOFReadCompColor: begin
|
| 373 |
+
State <= S_SOFReadCompColor0;
|
| 374 |
+
ReadCount <= {13'd0, JpegComp[2:0]} - 16'd1;
|
| 375 |
+
end
|
| 376 |
+
S_SOFReadCompColor0: begin
|
| 377 |
+
if(DataInEnable == 1'b1) begin
|
| 378 |
+
State <= S_SOFReadCompColor1;
|
| 379 |
+
end
|
| 380 |
+
end
|
| 381 |
+
S_SOFReadCompColor1: begin
|
| 382 |
+
if(DataInEnable == 1'b1) begin
|
| 383 |
+
State <= S_SOFReadCompColor2;
|
| 384 |
+
end
|
| 385 |
+
end
|
| 386 |
+
S_SOFReadCompColor2: begin
|
| 387 |
+
if(DataInEnable == 1'b1) begin
|
| 388 |
+
if(ReadCount == 0) begin
|
| 389 |
+
State <= S_SOFMakeBlock0;
|
| 390 |
+
end else begin
|
| 391 |
+
ReadCount <= ReadCount -16'd1;
|
| 392 |
+
State <= S_SOFReadCompColor0;
|
| 393 |
+
end
|
| 394 |
+
end
|
| 395 |
+
end
|
| 396 |
+
S_SOFMakeBlock0:begin
|
| 397 |
+
State <= S_SOFMakeBlock1;
|
| 398 |
+
if(JpegComp == 3) begin
|
| 399 |
+
// コンポーネント数が3の場合、16x16が1ブロック
|
| 400 |
+
JpegBlockWidth <= JpegBlockWidth +16'd15;
|
| 401 |
+
JpegBlockHeight <= JpegBlockHeight +16'd15;
|
| 402 |
+
end else begin
|
| 403 |
+
// コンポーネント数が1の場合、32x8が1ブロック
|
| 404 |
+
JpegBlockWidth <= JpegBlockWidth +16'd31;
|
| 405 |
+
JpegBlockHeight <= JpegBlockHeight +16'd7;
|
| 406 |
+
end
|
| 407 |
+
end
|
| 408 |
+
S_SOFMakeBlock1:begin
|
| 409 |
+
State <= S_GetMarker;
|
| 410 |
+
if(JpegComp == 3) begin
|
| 411 |
+
// コンポーネント数が3の場合、16x16が1ブロック
|
| 412 |
+
JpegBlockWidth <= JpegBlockWidth >> 4;
|
| 413 |
+
JpegBlockHeight <= JpegBlockHeight >> 4;
|
| 414 |
+
end else begin
|
| 415 |
+
// コンポーネント数が1の場合、32x8が1ブロック
|
| 416 |
+
JpegBlockWidth <= JpegBlockWidth >> 5;
|
| 417 |
+
JpegBlockHeight <= JpegBlockHeight >> 3;
|
| 418 |
+
end
|
| 419 |
+
end
|
| 420 |
+
|
| 421 |
+
// Image Process
|
| 422 |
+
S_ImageData: begin
|
| 423 |
+
if(OutEnable & (JpegWidth == (OutPixelX +1)) & (JpegHeight == (OutPixelY +1))) begin
|
| 424 |
+
State <= S_Idle;
|
| 425 |
+
ImageEnable <= 1'b0;
|
| 426 |
+
end
|
| 427 |
+
end
|
| 428 |
+
endcase
|
| 429 |
+
end
|
| 430 |
+
end
|
| 431 |
+
|
| 432 |
+
assign UseByte = (DataInEnable == 1'b1) & ((State == S_APPRead) |
|
| 433 |
+
(State == S_DQTRead) | (State == S_DQTTable) |
|
| 434 |
+
(State == S_DHTTable) | (State == S_DHTMakeHm0) | (State == S_DHTReadTable) |
|
| 435 |
+
(State == S_SOSRead0) | (State == S_SOSRead2) | (State == S_SOSRead3) | (State == S_SOSRead4) |
|
| 436 |
+
(State == S_SOFRead0) | (State == S_SOFReadComp) |
|
| 437 |
+
(State == S_SOFReadComp) | (State == S_SOFReadCompColor0) | (State == S_SOFReadCompColor1) | (State == S_SOFReadCompColor2)
|
| 438 |
+
);
|
| 439 |
+
assign UseWord = (DataInEnable == 1'b1) & ((State == S_GetMarker) |
|
| 440 |
+
(State == S_APPLength) |
|
| 441 |
+
(State == S_DQTLength) |
|
| 442 |
+
(State == S_DHTLength) |
|
| 443 |
+
(State == S_SOSLength) | (State == S_SOSRead1) |
|
| 444 |
+
(State == S_SOFLength) | (State == S_SOFReadX) | (State == S_SOFReadY)
|
| 445 |
+
);
|
| 446 |
+
|
| 447 |
+
assign JpegDecodeIdle = (State == S_Idle);
|
| 448 |
+
//assign ImageEnable = (State == S_ImageData);
|
| 449 |
+
|
| 450 |
+
assign OutWidth = JpegWidth;
|
| 451 |
+
assign OutHeight = JpegHeight;
|
| 452 |
+
assign OutBlockWidth = JpegBlockWidth[11:0];
|
| 453 |
+
|
| 454 |
+
assign DqtEnable = (State == S_DQTRead);
|
| 455 |
+
assign DqtTable = ReadDqtTable;
|
| 456 |
+
assign DqtCount = ReadCount[5:0];
|
| 457 |
+
assign DqtData = DataIn[31:24];
|
| 458 |
+
|
| 459 |
+
assign DhtEnable = (State == S_DHTReadTable);
|
| 460 |
+
assign DhtTable = ReadDhtTable;
|
| 461 |
+
assign DhtCount = HmCount;
|
| 462 |
+
assign DhtData = DataIn[31:24];
|
| 463 |
+
|
| 464 |
+
assign HuffmanEnable = HmEnable;
|
| 465 |
+
assign HuffmanTable = ReadDhtTable;
|
| 466 |
+
assign HuffmanCount = ReadCount[3:0];
|
| 467 |
+
assign HuffmanData = HmData;
|
| 468 |
+
assign HuffmanStart = HmMax;
|
| 469 |
+
|
| 470 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_hm_decode.v
ADDED
|
@@ -0,0 +1,755 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_hm_decode(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk, // Reset and Clock
|
| 24 |
+
|
| 25 |
+
// Huffman Table
|
| 26 |
+
input HuffmanTableEnable, // Table Data In Enable
|
| 27 |
+
input [1:0] HuffmanTableColor, // Huffman Table Color Number
|
| 28 |
+
input [3:0] HuffmanTableCount, // Table Number
|
| 29 |
+
input [15:0] HuffmanTableCode, // Huffman Table Data
|
| 30 |
+
input [7:0] HuffmanTableStart, // Huffman Table Start Number
|
| 31 |
+
|
| 32 |
+
// Huffman Decode
|
| 33 |
+
input DataInRun, // Data In Start
|
| 34 |
+
input DataInEnable, // Data In Enable
|
| 35 |
+
input [31:0] DataIn, // Data In
|
| 36 |
+
input [2:0] JpegComp,
|
| 37 |
+
|
| 38 |
+
// DHT table
|
| 39 |
+
output [1:0] DhtColor, // Color Number
|
| 40 |
+
output [7:0] DhtNumber, // Decode Dht Number
|
| 41 |
+
input [3:0] DhtZero, // Zero Count of Dht Number
|
| 42 |
+
input [3:0] DhtWidth, // Data Width of Dht Number
|
| 43 |
+
|
| 44 |
+
// DQT Table
|
| 45 |
+
output DqtColor, // Color Number
|
| 46 |
+
output [5:0] DqtNumber, // Dqt Number
|
| 47 |
+
input [7:0] DqtData, // Dqt Data
|
| 48 |
+
|
| 49 |
+
input DataOutIdle,
|
| 50 |
+
output DataOutEnable,
|
| 51 |
+
output [2:0] DataOutColor,
|
| 52 |
+
|
| 53 |
+
// Output decode data
|
| 54 |
+
output DecodeUseBit, // Used Data Bit
|
| 55 |
+
output [6:0] DecodeUseWidth, // Used Data Width
|
| 56 |
+
output DecodeEnable, // Data Out Enable
|
| 57 |
+
output [2:0] DecodeColor,
|
| 58 |
+
output [5:0] DecodeCount,
|
| 59 |
+
output [3:0] DecodeZero, // Data Out with Zero Count
|
| 60 |
+
output [15:0] DecodeCode // Data Out with Code
|
| 61 |
+
);
|
| 62 |
+
//--------------------------------------------------------------------------
|
| 63 |
+
// Register Huffman Table(YCbCr)
|
| 64 |
+
//--------------------------------------------------------------------------
|
| 65 |
+
// Y-DC Huffman Table
|
| 66 |
+
reg [15:0] HuffmanTable0r [0:15]; // Y-DC Huffman Table
|
| 67 |
+
reg [15:0] HuffmanTable1r [0:15]; // Y-AC Huffman Table
|
| 68 |
+
reg [15:0] HuffmanTable2r [0:15]; // C-DC Huffman Table
|
| 69 |
+
reg [15:0] HuffmanTable3r [0:15]; // C-AC Huffman Table
|
| 70 |
+
|
| 71 |
+
reg [7:0] HuffmanNumber0r [0:15]; // Y-DC Huffman Number
|
| 72 |
+
reg [7:0] HuffmanNumber1r [0:15]; // Y-AC Huffman Number
|
| 73 |
+
reg [7:0] HuffmanNumber2r [0:15]; // C-DC Huffman Number
|
| 74 |
+
reg [7:0] HuffmanNumber3r [0:15]; // C-AC Huffman Number
|
| 75 |
+
|
| 76 |
+
always @(posedge clk or negedge rst) begin
|
| 77 |
+
if(!rst) begin
|
| 78 |
+
HuffmanTable0r[0] <= 16'h0000;
|
| 79 |
+
HuffmanNumber0r[0] <= 8'h00;
|
| 80 |
+
HuffmanTable1r[0] <= 16'h0000;
|
| 81 |
+
HuffmanNumber1r[0] <= 8'h00;
|
| 82 |
+
HuffmanTable2r[0] <= 16'h0000;
|
| 83 |
+
HuffmanNumber2r[0] <= 8'h00;
|
| 84 |
+
HuffmanTable3r[0] <= 16'h0000;
|
| 85 |
+
HuffmanNumber3r[0] <= 8'h00;
|
| 86 |
+
|
| 87 |
+
HuffmanTable0r[1] <= 16'h0000;
|
| 88 |
+
HuffmanNumber0r[1] <= 8'h00;
|
| 89 |
+
HuffmanTable1r[1] <= 16'h0000;
|
| 90 |
+
HuffmanNumber1r[1] <= 8'h00;
|
| 91 |
+
HuffmanTable2r[1] <= 16'h0000;
|
| 92 |
+
HuffmanNumber2r[1] <= 8'h00;
|
| 93 |
+
HuffmanTable3r[1] <= 16'h0000;
|
| 94 |
+
HuffmanNumber3r[1] <= 8'h00;
|
| 95 |
+
|
| 96 |
+
HuffmanTable0r[2] <= 16'h0000;
|
| 97 |
+
HuffmanNumber0r[2] <= 8'h00;
|
| 98 |
+
HuffmanTable1r[2] <= 16'h0000;
|
| 99 |
+
HuffmanNumber1r[2] <= 8'h00;
|
| 100 |
+
HuffmanTable2r[2] <= 16'h0000;
|
| 101 |
+
HuffmanNumber2r[2] <= 8'h00;
|
| 102 |
+
HuffmanTable3r[2] <= 16'h0000;
|
| 103 |
+
HuffmanNumber3r[2] <= 8'h00;
|
| 104 |
+
|
| 105 |
+
HuffmanTable0r[3] <= 16'h0000;
|
| 106 |
+
HuffmanNumber0r[3] <= 8'h00;
|
| 107 |
+
HuffmanTable1r[3] <= 16'h0000;
|
| 108 |
+
HuffmanNumber1r[3] <= 8'h00;
|
| 109 |
+
HuffmanTable2r[3] <= 16'h0000;
|
| 110 |
+
HuffmanNumber2r[3] <= 8'h00;
|
| 111 |
+
HuffmanTable3r[3] <= 16'h0000;
|
| 112 |
+
HuffmanNumber3r[3] <= 8'h00;
|
| 113 |
+
|
| 114 |
+
HuffmanTable0r[4] <= 16'h0000;
|
| 115 |
+
HuffmanNumber0r[4] <= 8'h00;
|
| 116 |
+
HuffmanTable1r[4] <= 16'h0000;
|
| 117 |
+
HuffmanNumber1r[4] <= 8'h00;
|
| 118 |
+
HuffmanTable2r[4] <= 16'h0000;
|
| 119 |
+
HuffmanNumber2r[4] <= 8'h00;
|
| 120 |
+
HuffmanTable3r[4] <= 16'h0000;
|
| 121 |
+
HuffmanNumber3r[4] <= 8'h00;
|
| 122 |
+
|
| 123 |
+
HuffmanTable0r[5] <= 16'h0000;
|
| 124 |
+
HuffmanNumber0r[5] <= 8'h00;
|
| 125 |
+
HuffmanTable1r[5] <= 16'h0000;
|
| 126 |
+
HuffmanNumber1r[5] <= 8'h00;
|
| 127 |
+
HuffmanTable2r[5] <= 16'h0000;
|
| 128 |
+
HuffmanNumber2r[5] <= 8'h00;
|
| 129 |
+
HuffmanTable3r[5] <= 16'h0000;
|
| 130 |
+
HuffmanNumber3r[5] <= 8'h00;
|
| 131 |
+
|
| 132 |
+
HuffmanTable0r[6] <= 16'h0000;
|
| 133 |
+
HuffmanNumber0r[6] <= 8'h00;
|
| 134 |
+
HuffmanTable1r[6] <= 16'h0000;
|
| 135 |
+
HuffmanNumber1r[6] <= 8'h00;
|
| 136 |
+
HuffmanTable2r[6] <= 16'h0000;
|
| 137 |
+
HuffmanNumber2r[6] <= 8'h00;
|
| 138 |
+
HuffmanTable3r[6] <= 16'h0000;
|
| 139 |
+
HuffmanNumber3r[6] <= 8'h00;
|
| 140 |
+
|
| 141 |
+
HuffmanTable0r[7] <= 16'h0000;
|
| 142 |
+
HuffmanNumber0r[7] <= 8'h00;
|
| 143 |
+
HuffmanTable1r[7] <= 16'h0000;
|
| 144 |
+
HuffmanNumber1r[7] <= 8'h00;
|
| 145 |
+
HuffmanTable2r[7] <= 16'h0000;
|
| 146 |
+
HuffmanNumber2r[7] <= 8'h00;
|
| 147 |
+
HuffmanTable3r[7] <= 16'h0000;
|
| 148 |
+
HuffmanNumber3r[7] <= 8'h00;
|
| 149 |
+
|
| 150 |
+
HuffmanTable0r[8] <= 16'h0000;
|
| 151 |
+
HuffmanNumber0r[8] <= 8'h00;
|
| 152 |
+
HuffmanTable1r[8] <= 16'h0000;
|
| 153 |
+
HuffmanNumber1r[8] <= 8'h00;
|
| 154 |
+
HuffmanTable2r[8] <= 16'h0000;
|
| 155 |
+
HuffmanNumber2r[8] <= 8'h00;
|
| 156 |
+
HuffmanTable3r[8] <= 16'h0000;
|
| 157 |
+
HuffmanNumber3r[8] <= 8'h00;
|
| 158 |
+
|
| 159 |
+
HuffmanTable0r[9] <= 16'h0000;
|
| 160 |
+
HuffmanNumber0r[9] <= 8'h00;
|
| 161 |
+
HuffmanTable1r[9] <= 16'h0000;
|
| 162 |
+
HuffmanNumber1r[9] <= 8'h00;
|
| 163 |
+
HuffmanTable2r[9] <= 16'h0000;
|
| 164 |
+
HuffmanNumber2r[9] <= 8'h00;
|
| 165 |
+
HuffmanTable3r[9] <= 16'h0000;
|
| 166 |
+
HuffmanNumber3r[9] <= 8'h00;
|
| 167 |
+
|
| 168 |
+
HuffmanTable0r[10] <= 16'h0000;
|
| 169 |
+
HuffmanNumber0r[10] <= 8'h00;
|
| 170 |
+
HuffmanTable1r[10] <= 16'h0000;
|
| 171 |
+
HuffmanNumber1r[10] <= 8'h00;
|
| 172 |
+
HuffmanTable2r[10] <= 16'h0000;
|
| 173 |
+
HuffmanNumber2r[10] <= 8'h00;
|
| 174 |
+
HuffmanTable3r[10] <= 16'h0000;
|
| 175 |
+
HuffmanNumber3r[10] <= 8'h00;
|
| 176 |
+
|
| 177 |
+
HuffmanTable0r[11] <= 16'h0000;
|
| 178 |
+
HuffmanNumber0r[11] <= 8'h00;
|
| 179 |
+
HuffmanTable1r[11] <= 16'h0000;
|
| 180 |
+
HuffmanNumber1r[11] <= 8'h00;
|
| 181 |
+
HuffmanTable2r[11] <= 16'h0000;
|
| 182 |
+
HuffmanNumber2r[11] <= 8'h00;
|
| 183 |
+
HuffmanTable3r[11] <= 16'h0000;
|
| 184 |
+
HuffmanNumber3r[11] <= 8'h00;
|
| 185 |
+
|
| 186 |
+
HuffmanTable0r[12] <= 16'h0000;
|
| 187 |
+
HuffmanNumber0r[12] <= 8'h00;
|
| 188 |
+
HuffmanTable1r[12] <= 16'h0000;
|
| 189 |
+
HuffmanNumber1r[12] <= 8'h00;
|
| 190 |
+
HuffmanTable2r[12] <= 16'h0000;
|
| 191 |
+
HuffmanNumber2r[12] <= 8'h00;
|
| 192 |
+
HuffmanTable3r[12] <= 16'h0000;
|
| 193 |
+
HuffmanNumber3r[12] <= 8'h00;
|
| 194 |
+
|
| 195 |
+
HuffmanTable0r[13] <= 16'h0000;
|
| 196 |
+
HuffmanNumber0r[13] <= 8'h00;
|
| 197 |
+
HuffmanTable1r[13] <= 16'h0000;
|
| 198 |
+
HuffmanNumber1r[13] <= 8'h00;
|
| 199 |
+
HuffmanTable2r[13] <= 16'h0000;
|
| 200 |
+
HuffmanNumber2r[13] <= 8'h00;
|
| 201 |
+
HuffmanTable3r[13] <= 16'h0000;
|
| 202 |
+
HuffmanNumber3r[13] <= 8'h00;
|
| 203 |
+
|
| 204 |
+
HuffmanTable0r[14] <= 16'h0000;
|
| 205 |
+
HuffmanNumber0r[14] <= 8'h00;
|
| 206 |
+
HuffmanTable1r[14] <= 16'h0000;
|
| 207 |
+
HuffmanNumber1r[14] <= 8'h00;
|
| 208 |
+
HuffmanTable2r[14] <= 16'h0000;
|
| 209 |
+
HuffmanNumber2r[14] <= 8'h00;
|
| 210 |
+
HuffmanTable3r[14] <= 16'h0000;
|
| 211 |
+
HuffmanNumber3r[14] <= 8'h00;
|
| 212 |
+
|
| 213 |
+
HuffmanTable0r[15] <= 16'h0000;
|
| 214 |
+
HuffmanNumber0r[15] <= 8'h00;
|
| 215 |
+
HuffmanTable1r[15] <= 16'h0000;
|
| 216 |
+
HuffmanNumber1r[15] <= 8'h00;
|
| 217 |
+
HuffmanTable2r[15] <= 16'h0000;
|
| 218 |
+
HuffmanNumber2r[15] <= 8'h00;
|
| 219 |
+
HuffmanTable3r[15] <= 16'h0000;
|
| 220 |
+
HuffmanNumber3r[15] <= 8'h00;
|
| 221 |
+
end else begin
|
| 222 |
+
if(HuffmanTableEnable ==2'b1) begin
|
| 223 |
+
if(HuffmanTableColor ==2'b00) begin
|
| 224 |
+
HuffmanTable0r[HuffmanTableCount] <= HuffmanTableCode;
|
| 225 |
+
HuffmanNumber0r[HuffmanTableCount] <= HuffmanTableStart;
|
| 226 |
+
end else if(HuffmanTableColor ==2'b01) begin
|
| 227 |
+
HuffmanTable1r[HuffmanTableCount] <= HuffmanTableCode;
|
| 228 |
+
HuffmanNumber1r[HuffmanTableCount] <= HuffmanTableStart;
|
| 229 |
+
end else if(HuffmanTableColor ==2'b10) begin
|
| 230 |
+
HuffmanTable2r[HuffmanTableCount] <= HuffmanTableCode;
|
| 231 |
+
HuffmanNumber2r[HuffmanTableCount] <= HuffmanTableStart;
|
| 232 |
+
end else begin
|
| 233 |
+
HuffmanTable3r[HuffmanTableCount] <= HuffmanTableCode;
|
| 234 |
+
HuffmanNumber3r[HuffmanTableCount] <= HuffmanTableStart;
|
| 235 |
+
end
|
| 236 |
+
end
|
| 237 |
+
end
|
| 238 |
+
end
|
| 239 |
+
|
| 240 |
+
//--------------------------------------------------------------------------
|
| 241 |
+
// Decode Process
|
| 242 |
+
//--------------------------------------------------------------------------
|
| 243 |
+
reg [3:0] Process; // Process State
|
| 244 |
+
reg [31:0] ProcessData; // Data
|
| 245 |
+
|
| 246 |
+
// Huffman Table
|
| 247 |
+
reg [15:0] HuffmanTable [0:15];
|
| 248 |
+
// Huffman Table Number
|
| 249 |
+
reg [7:0] HuffmanNumber [0:15];
|
| 250 |
+
|
| 251 |
+
reg [15:0] Place; // Place bit
|
| 252 |
+
reg [15:0] TableCode; // Table Code
|
| 253 |
+
reg [7:0] NumberCode; // Start Number of Table Code
|
| 254 |
+
reg [3:0] CodeNumber; // Huffman code width
|
| 255 |
+
reg [15:0] DataNumber; // Huffman code
|
| 256 |
+
|
| 257 |
+
reg [2:0] ProcessColor;
|
| 258 |
+
reg [5:0] ProcessCount;
|
| 259 |
+
|
| 260 |
+
reg OutEnable; // Output Enable
|
| 261 |
+
reg [3:0] OutZero; // Output Zero Count
|
| 262 |
+
reg [15:0] OutCode; // Output Data Code
|
| 263 |
+
wire [15:0] OutCodeP; // Output Data Code
|
| 264 |
+
|
| 265 |
+
reg [4:0] UseWidth; // Output used width
|
| 266 |
+
|
| 267 |
+
// reg DataOutEnable;
|
| 268 |
+
reg [2:0] DataOutColor;
|
| 269 |
+
|
| 270 |
+
reg signed [31:0] PreData [0:2];
|
| 271 |
+
|
| 272 |
+
wire [15:0] SubCode;
|
| 273 |
+
|
| 274 |
+
localparam ProcIdle = 4'h0;
|
| 275 |
+
localparam Phase1 = 4'h1;
|
| 276 |
+
localparam Phase2 = 4'h2;
|
| 277 |
+
localparam Phase3 = 4'h3;
|
| 278 |
+
localparam Phase4 = 4'h4;
|
| 279 |
+
localparam Phase5 = 4'h5;
|
| 280 |
+
localparam Phase6 = 4'h6;
|
| 281 |
+
localparam Phase7 = 4'h7;
|
| 282 |
+
localparam Phase8 = 4'h8;
|
| 283 |
+
|
| 284 |
+
function [15:0] OutCodePSel;
|
| 285 |
+
input [3:0] DhtWidth;
|
| 286 |
+
input [31:0] ProcessData;
|
| 287 |
+
begin
|
| 288 |
+
case (DhtWidth)
|
| 289 |
+
4'h0: OutCodePSel = 16'h0000;
|
| 290 |
+
4'h1: OutCodePSel = {15'h0000,ProcessData[31]};
|
| 291 |
+
4'h2: OutCodePSel = {14'h0000,ProcessData[31:30]};
|
| 292 |
+
4'h3: OutCodePSel = {13'h0000,ProcessData[31:29]};
|
| 293 |
+
4'h4: OutCodePSel = {12'h000, ProcessData[31:28]};
|
| 294 |
+
4'h5: OutCodePSel = {11'h000, ProcessData[31:27]};
|
| 295 |
+
4'h6: OutCodePSel = {10'h000, ProcessData[31:26]};
|
| 296 |
+
4'h7: OutCodePSel = {9'h000, ProcessData[31:25]};
|
| 297 |
+
4'h8: OutCodePSel = {8'h00, ProcessData[31:24]};
|
| 298 |
+
4'h9: OutCodePSel = {7'h00, ProcessData[31:23]};
|
| 299 |
+
4'hA: OutCodePSel = {6'h00, ProcessData[31:22]};
|
| 300 |
+
4'hB: OutCodePSel = {5'h00, ProcessData[31:21]};
|
| 301 |
+
4'hC: OutCodePSel = {4'h0, ProcessData[31:20]};
|
| 302 |
+
4'hD: OutCodePSel = {3'h0, ProcessData[31:19]};
|
| 303 |
+
4'hE: OutCodePSel = {2'h0, ProcessData[31:18]};
|
| 304 |
+
4'hF: OutCodePSel = {1'h0, ProcessData[31:17]};
|
| 305 |
+
endcase
|
| 306 |
+
end
|
| 307 |
+
endfunction
|
| 308 |
+
assign OutCodeP = OutCodePSel(DhtWidth, ProcessData);
|
| 309 |
+
|
| 310 |
+
function [15:0] SubCodeSel;
|
| 311 |
+
input [3:0] DhtWidth;
|
| 312 |
+
begin
|
| 313 |
+
case (DhtWidth)
|
| 314 |
+
4'h0: SubCodeSel = 16'hFFFF;
|
| 315 |
+
4'h1: SubCodeSel = 16'hFFFE;
|
| 316 |
+
4'h2: SubCodeSel = 16'hFFFC;
|
| 317 |
+
4'h3: SubCodeSel = 16'hFFF8;
|
| 318 |
+
4'h4: SubCodeSel = 16'hFFF0;
|
| 319 |
+
4'h5: SubCodeSel = 16'hFFE0;
|
| 320 |
+
4'h6: SubCodeSel = 16'hFFC0;
|
| 321 |
+
4'h7: SubCodeSel = 16'hFF80;
|
| 322 |
+
4'h8: SubCodeSel = 16'hFF00;
|
| 323 |
+
4'h9: SubCodeSel = 16'hFE00;
|
| 324 |
+
4'hA: SubCodeSel = 16'hFC00;
|
| 325 |
+
4'hB: SubCodeSel = 16'hF800;
|
| 326 |
+
4'hC: SubCodeSel = 16'hF000;
|
| 327 |
+
4'hD: SubCodeSel = 16'hE000;
|
| 328 |
+
4'hE: SubCodeSel = 16'hC000;
|
| 329 |
+
4'hF: SubCodeSel = 16'h8000;
|
| 330 |
+
endcase
|
| 331 |
+
end
|
| 332 |
+
endfunction
|
| 333 |
+
assign SubCode = SubCodeSel(DhtWidth);
|
| 334 |
+
|
| 335 |
+
always @(posedge clk or negedge rst) begin
|
| 336 |
+
if(!rst) begin
|
| 337 |
+
Process <= ProcIdle;
|
| 338 |
+
ProcessData <= 32'h00000000;
|
| 339 |
+
ProcessCount <= 6'd0;
|
| 340 |
+
OutEnable <= 1'b0;
|
| 341 |
+
// DataOutEnable <= 1'b0;
|
| 342 |
+
DataOutColor <= 3'b000;
|
| 343 |
+
PreData[0] <= 32'h00000000;
|
| 344 |
+
PreData[1] <= 32'h00000000;
|
| 345 |
+
PreData[2] <= 32'h00000000;
|
| 346 |
+
UseWidth <= 5'h00;
|
| 347 |
+
CodeNumber <= 4'd0;
|
| 348 |
+
end else begin
|
| 349 |
+
case (Process)
|
| 350 |
+
ProcIdle: begin
|
| 351 |
+
if(DataInRun == 1'b1) begin
|
| 352 |
+
Process <= Phase1;
|
| 353 |
+
end else begin
|
| 354 |
+
// Reset DC code
|
| 355 |
+
PreData[0] <= 32'h00000000;
|
| 356 |
+
PreData[1] <= 32'h00000000;
|
| 357 |
+
PreData[2] <= 32'h00000000;
|
| 358 |
+
end
|
| 359 |
+
OutEnable <= 1'b0;
|
| 360 |
+
ProcessColor <= 3'b000;
|
| 361 |
+
ProcessCount <= 6'd0;
|
| 362 |
+
// DataOutEnable <= 1'b0;
|
| 363 |
+
DataOutColor <= 3'b000;
|
| 364 |
+
end
|
| 365 |
+
// get a table-data and table-number
|
| 366 |
+
Phase1: begin
|
| 367 |
+
if(DataInRun == 1'b0) begin
|
| 368 |
+
Process <= ProcIdle;
|
| 369 |
+
end else if(DataInEnable == 1'b1 & DataOutIdle == 1'b1) begin
|
| 370 |
+
Process <= Phase2;
|
| 371 |
+
ProcessData <= DataIn;
|
| 372 |
+
end
|
| 373 |
+
OutEnable <= 1'b0;
|
| 374 |
+
// DataOutEnable <= 1'b0;
|
| 375 |
+
if(ProcessColor[2] == 1'b0) begin
|
| 376 |
+
if(ProcessCount == 0) begin
|
| 377 |
+
HuffmanTable[0] <= HuffmanTable0r[0];
|
| 378 |
+
HuffmanNumber[0] <= HuffmanNumber0r[0];
|
| 379 |
+
HuffmanTable[1] <= HuffmanTable0r[1];
|
| 380 |
+
HuffmanNumber[1] <= HuffmanNumber0r[1];
|
| 381 |
+
HuffmanTable[2] <= HuffmanTable0r[2];
|
| 382 |
+
HuffmanNumber[2] <= HuffmanNumber0r[2];
|
| 383 |
+
HuffmanTable[3] <= HuffmanTable0r[3];
|
| 384 |
+
HuffmanNumber[3] <= HuffmanNumber0r[3];
|
| 385 |
+
HuffmanTable[4] <= HuffmanTable0r[4];
|
| 386 |
+
HuffmanNumber[4] <= HuffmanNumber0r[4];
|
| 387 |
+
HuffmanTable[5] <= HuffmanTable0r[5];
|
| 388 |
+
HuffmanNumber[5] <= HuffmanNumber0r[5];
|
| 389 |
+
HuffmanTable[6] <= HuffmanTable0r[6];
|
| 390 |
+
HuffmanNumber[6] <= HuffmanNumber0r[6];
|
| 391 |
+
HuffmanTable[7] <= HuffmanTable0r[7];
|
| 392 |
+
HuffmanNumber[7] <= HuffmanNumber0r[7];
|
| 393 |
+
HuffmanTable[8] <= HuffmanTable0r[8];
|
| 394 |
+
HuffmanNumber[8] <= HuffmanNumber0r[8];
|
| 395 |
+
HuffmanTable[9] <= HuffmanTable0r[9];
|
| 396 |
+
HuffmanNumber[9] <= HuffmanNumber0r[9];
|
| 397 |
+
HuffmanTable[10] <= HuffmanTable0r[10];
|
| 398 |
+
HuffmanNumber[10] <= HuffmanNumber0r[10];
|
| 399 |
+
HuffmanTable[11] <= HuffmanTable0r[11];
|
| 400 |
+
HuffmanNumber[11] <= HuffmanNumber0r[11];
|
| 401 |
+
HuffmanTable[12] <= HuffmanTable0r[12];
|
| 402 |
+
HuffmanNumber[12] <= HuffmanNumber0r[12];
|
| 403 |
+
HuffmanTable[13] <= HuffmanTable0r[13];
|
| 404 |
+
HuffmanNumber[13] <= HuffmanNumber0r[13];
|
| 405 |
+
HuffmanTable[14] <= HuffmanTable0r[14];
|
| 406 |
+
HuffmanNumber[14] <= HuffmanNumber0r[14];
|
| 407 |
+
HuffmanTable[15] <= HuffmanTable0r[15];
|
| 408 |
+
HuffmanNumber[15] <= HuffmanNumber0r[15];
|
| 409 |
+
end else begin
|
| 410 |
+
HuffmanTable[0] <= HuffmanTable1r[0];
|
| 411 |
+
HuffmanNumber[0] <= HuffmanNumber1r[0];
|
| 412 |
+
HuffmanTable[1] <= HuffmanTable1r[1];
|
| 413 |
+
HuffmanNumber[1] <= HuffmanNumber1r[1];
|
| 414 |
+
HuffmanTable[2] <= HuffmanTable1r[2];
|
| 415 |
+
HuffmanNumber[2] <= HuffmanNumber1r[2];
|
| 416 |
+
HuffmanTable[3] <= HuffmanTable1r[3];
|
| 417 |
+
HuffmanNumber[3] <= HuffmanNumber1r[3];
|
| 418 |
+
HuffmanTable[4] <= HuffmanTable1r[4];
|
| 419 |
+
HuffmanNumber[4] <= HuffmanNumber1r[4];
|
| 420 |
+
HuffmanTable[5] <= HuffmanTable1r[5];
|
| 421 |
+
HuffmanNumber[5] <= HuffmanNumber1r[5];
|
| 422 |
+
HuffmanTable[6] <= HuffmanTable1r[6];
|
| 423 |
+
HuffmanNumber[6] <= HuffmanNumber1r[6];
|
| 424 |
+
HuffmanTable[7] <= HuffmanTable1r[7];
|
| 425 |
+
HuffmanNumber[7] <= HuffmanNumber1r[7];
|
| 426 |
+
HuffmanTable[8] <= HuffmanTable1r[8];
|
| 427 |
+
HuffmanNumber[8] <= HuffmanNumber1r[8];
|
| 428 |
+
HuffmanTable[9] <= HuffmanTable1r[9];
|
| 429 |
+
HuffmanNumber[9] <= HuffmanNumber1r[9];
|
| 430 |
+
HuffmanTable[10] <= HuffmanTable1r[10];
|
| 431 |
+
HuffmanNumber[10] <= HuffmanNumber1r[10];
|
| 432 |
+
HuffmanTable[11] <= HuffmanTable1r[11];
|
| 433 |
+
HuffmanNumber[11] <= HuffmanNumber1r[11];
|
| 434 |
+
HuffmanTable[12] <= HuffmanTable1r[12];
|
| 435 |
+
HuffmanNumber[12] <= HuffmanNumber1r[12];
|
| 436 |
+
HuffmanTable[13] <= HuffmanTable1r[13];
|
| 437 |
+
HuffmanNumber[13] <= HuffmanNumber1r[13];
|
| 438 |
+
HuffmanTable[14] <= HuffmanTable1r[14];
|
| 439 |
+
HuffmanNumber[14] <= HuffmanNumber1r[14];
|
| 440 |
+
HuffmanTable[15] <= HuffmanTable1r[15];
|
| 441 |
+
HuffmanNumber[15] <= HuffmanNumber1r[15];
|
| 442 |
+
end
|
| 443 |
+
end else begin
|
| 444 |
+
if(ProcessCount == 0) begin
|
| 445 |
+
HuffmanTable[0] <= HuffmanTable2r[0];
|
| 446 |
+
HuffmanNumber[0] <= HuffmanNumber2r[0];
|
| 447 |
+
HuffmanTable[1] <= HuffmanTable2r[1];
|
| 448 |
+
HuffmanNumber[1] <= HuffmanNumber2r[1];
|
| 449 |
+
HuffmanTable[2] <= HuffmanTable2r[2];
|
| 450 |
+
HuffmanNumber[2] <= HuffmanNumber2r[2];
|
| 451 |
+
HuffmanTable[3] <= HuffmanTable2r[3];
|
| 452 |
+
HuffmanNumber[3] <= HuffmanNumber2r[3];
|
| 453 |
+
HuffmanTable[4] <= HuffmanTable2r[4];
|
| 454 |
+
HuffmanNumber[4] <= HuffmanNumber2r[4];
|
| 455 |
+
HuffmanTable[5] <= HuffmanTable2r[5];
|
| 456 |
+
HuffmanNumber[5] <= HuffmanNumber2r[5];
|
| 457 |
+
HuffmanTable[6] <= HuffmanTable2r[6];
|
| 458 |
+
HuffmanNumber[6] <= HuffmanNumber2r[6];
|
| 459 |
+
HuffmanTable[7] <= HuffmanTable2r[7];
|
| 460 |
+
HuffmanNumber[7] <= HuffmanNumber2r[7];
|
| 461 |
+
HuffmanTable[8] <= HuffmanTable2r[8];
|
| 462 |
+
HuffmanNumber[8] <= HuffmanNumber2r[8];
|
| 463 |
+
HuffmanTable[9] <= HuffmanTable2r[9];
|
| 464 |
+
HuffmanNumber[9] <= HuffmanNumber2r[9];
|
| 465 |
+
HuffmanTable[10] <= HuffmanTable2r[10];
|
| 466 |
+
HuffmanNumber[10] <= HuffmanNumber2r[10];
|
| 467 |
+
HuffmanTable[11] <= HuffmanTable2r[11];
|
| 468 |
+
HuffmanNumber[11] <= HuffmanNumber2r[11];
|
| 469 |
+
HuffmanTable[12] <= HuffmanTable2r[12];
|
| 470 |
+
HuffmanNumber[12] <= HuffmanNumber2r[12];
|
| 471 |
+
HuffmanTable[13] <= HuffmanTable2r[13];
|
| 472 |
+
HuffmanNumber[13] <= HuffmanNumber2r[13];
|
| 473 |
+
HuffmanTable[14] <= HuffmanTable2r[14];
|
| 474 |
+
HuffmanNumber[14] <= HuffmanNumber2r[14];
|
| 475 |
+
HuffmanTable[15] <= HuffmanTable2r[15];
|
| 476 |
+
HuffmanNumber[15] <= HuffmanNumber2r[15];
|
| 477 |
+
end else begin
|
| 478 |
+
HuffmanTable[0] <= HuffmanTable3r[0];
|
| 479 |
+
HuffmanNumber[0] <= HuffmanNumber3r[0];
|
| 480 |
+
HuffmanTable[1] <= HuffmanTable3r[1];
|
| 481 |
+
HuffmanNumber[1] <= HuffmanNumber3r[1];
|
| 482 |
+
HuffmanTable[2] <= HuffmanTable3r[2];
|
| 483 |
+
HuffmanNumber[2] <= HuffmanNumber3r[2];
|
| 484 |
+
HuffmanTable[3] <= HuffmanTable3r[3];
|
| 485 |
+
HuffmanNumber[3] <= HuffmanNumber3r[3];
|
| 486 |
+
HuffmanTable[4] <= HuffmanTable3r[4];
|
| 487 |
+
HuffmanNumber[4] <= HuffmanNumber3r[4];
|
| 488 |
+
HuffmanTable[5] <= HuffmanTable3r[5];
|
| 489 |
+
HuffmanNumber[5] <= HuffmanNumber3r[5];
|
| 490 |
+
HuffmanTable[6] <= HuffmanTable3r[6];
|
| 491 |
+
HuffmanNumber[6] <= HuffmanNumber3r[6];
|
| 492 |
+
HuffmanTable[7] <= HuffmanTable3r[7];
|
| 493 |
+
HuffmanNumber[7] <= HuffmanNumber3r[7];
|
| 494 |
+
HuffmanTable[8] <= HuffmanTable3r[8];
|
| 495 |
+
HuffmanNumber[8] <= HuffmanNumber3r[8];
|
| 496 |
+
HuffmanTable[9] <= HuffmanTable3r[9];
|
| 497 |
+
HuffmanNumber[9] <= HuffmanNumber3r[9];
|
| 498 |
+
HuffmanTable[10] <= HuffmanTable3r[10];
|
| 499 |
+
HuffmanNumber[10] <= HuffmanNumber3r[10];
|
| 500 |
+
HuffmanTable[11] <= HuffmanTable3r[11];
|
| 501 |
+
HuffmanNumber[11] <= HuffmanNumber3r[11];
|
| 502 |
+
HuffmanTable[12] <= HuffmanTable3r[12];
|
| 503 |
+
HuffmanNumber[12] <= HuffmanNumber3r[12];
|
| 504 |
+
HuffmanTable[13] <= HuffmanTable3r[13];
|
| 505 |
+
HuffmanNumber[13] <= HuffmanNumber3r[13];
|
| 506 |
+
HuffmanTable[14] <= HuffmanTable3r[14];
|
| 507 |
+
HuffmanNumber[14] <= HuffmanNumber3r[14];
|
| 508 |
+
HuffmanTable[15] <= HuffmanTable3r[15];
|
| 509 |
+
HuffmanNumber[15] <= HuffmanNumber3r[15];
|
| 510 |
+
end
|
| 511 |
+
end
|
| 512 |
+
end
|
| 513 |
+
// compare table
|
| 514 |
+
Phase2: begin
|
| 515 |
+
Process <= Phase4;
|
| 516 |
+
if(ProcessData[31:16] >= HuffmanTable[0]) Place[0] <= 1'b1;
|
| 517 |
+
else Place[0] <= 1'b0;
|
| 518 |
+
if(ProcessData[31:16] >= HuffmanTable[1]) Place[1] <= 1'b1;
|
| 519 |
+
else Place[1] <= 1'b0;
|
| 520 |
+
if(ProcessData[31:16] >= HuffmanTable[2]) Place[2] <= 1'b1;
|
| 521 |
+
else Place[2] <= 1'b0;
|
| 522 |
+
if(ProcessData[31:16] >= HuffmanTable[3]) Place[3] <= 1'b1;
|
| 523 |
+
else Place[3] <= 1'b0;
|
| 524 |
+
if(ProcessData[31:16] >= HuffmanTable[4]) Place[4] <= 1'b1;
|
| 525 |
+
else Place[4] <= 1'b0;
|
| 526 |
+
if(ProcessData[31:16] >= HuffmanTable[5]) Place[5] <= 1'b1;
|
| 527 |
+
else Place[5] <= 1'b0;
|
| 528 |
+
if(ProcessData[31:16] >= HuffmanTable[6]) Place[6] <= 1'b1;
|
| 529 |
+
else Place[6] <= 1'b0;
|
| 530 |
+
if(ProcessData[31:16] >= HuffmanTable[7]) Place[7] <= 1'b1;
|
| 531 |
+
else Place[7] <= 1'b0;
|
| 532 |
+
if(ProcessData[31:16] >= HuffmanTable[8]) Place[8] <= 1'b1;
|
| 533 |
+
else Place[8] <= 1'b0;
|
| 534 |
+
if(ProcessData[31:16] >= HuffmanTable[9]) Place[9] <= 1'b1;
|
| 535 |
+
else Place[9] <= 1'b0;
|
| 536 |
+
if(ProcessData[31:16] >= HuffmanTable[10]) Place[10] <= 1'b1;
|
| 537 |
+
else Place[10] <= 1'b0;
|
| 538 |
+
if(ProcessData[31:16] >= HuffmanTable[11]) Place[11] <= 1'b1;
|
| 539 |
+
else Place[11] <= 1'b0;
|
| 540 |
+
if(ProcessData[31:16] >= HuffmanTable[12]) Place[12] <= 1'b1;
|
| 541 |
+
else Place[12] <= 1'b0;
|
| 542 |
+
if(ProcessData[31:16] >= HuffmanTable[13]) Place[13] <= 1'b1;
|
| 543 |
+
else Place[13] <= 1'b0;
|
| 544 |
+
if(ProcessData[31:16] >= HuffmanTable[14]) Place[14] <= 1'b1;
|
| 545 |
+
else Place[14] <= 1'b0;
|
| 546 |
+
if(ProcessData[31:16] >= HuffmanTable[15]) Place[15] <= 1'b1;
|
| 547 |
+
else Place[15] <= 1'b0;
|
| 548 |
+
end
|
| 549 |
+
// shift code
|
| 550 |
+
Phase4: begin
|
| 551 |
+
Process <= Phase5;
|
| 552 |
+
case (Place)
|
| 553 |
+
16'b0000000000000001: begin
|
| 554 |
+
TableCode <= {15'h0000,HuffmanTable[0][15]};
|
| 555 |
+
NumberCode <= HuffmanNumber[0];
|
| 556 |
+
CodeNumber <= 4'h0;
|
| 557 |
+
DataNumber <= {15'h0000,ProcessData[31]};
|
| 558 |
+
ProcessData <= {ProcessData[30:0],1'b0};
|
| 559 |
+
end
|
| 560 |
+
16'b0000000000000011: begin
|
| 561 |
+
TableCode <= {14'h0000,HuffmanTable[1][15:14]};
|
| 562 |
+
NumberCode <= HuffmanNumber[1];
|
| 563 |
+
CodeNumber <= 4'h1;
|
| 564 |
+
DataNumber <= {14'h0000,ProcessData[31:30]};
|
| 565 |
+
ProcessData <= {ProcessData[29:0],2'b00};
|
| 566 |
+
end
|
| 567 |
+
16'b0000000000000111: begin
|
| 568 |
+
TableCode <= {13'h0000,HuffmanTable[2][15:13]};
|
| 569 |
+
NumberCode <= HuffmanNumber[2];
|
| 570 |
+
CodeNumber <= 4'h2;
|
| 571 |
+
DataNumber <= {13'h0000,ProcessData[31:29]};
|
| 572 |
+
ProcessData <= {ProcessData[28:0],3'b000};
|
| 573 |
+
end
|
| 574 |
+
16'b0000000000001111: begin
|
| 575 |
+
TableCode <= {12'h000,HuffmanTable[3][15:12]};
|
| 576 |
+
NumberCode <= HuffmanNumber[3];
|
| 577 |
+
CodeNumber <= 4'h3;
|
| 578 |
+
DataNumber <= {12'h000,ProcessData[31:28]};
|
| 579 |
+
ProcessData <= {ProcessData[27:0],4'h0};
|
| 580 |
+
end
|
| 581 |
+
16'b0000000000011111: begin
|
| 582 |
+
TableCode <= {11'h000,HuffmanTable[4][15:11]};
|
| 583 |
+
NumberCode <= HuffmanNumber[4];
|
| 584 |
+
CodeNumber <= 4'h4;
|
| 585 |
+
DataNumber <= {11'h000,ProcessData[31:27]};
|
| 586 |
+
ProcessData <= {ProcessData[26:0],5'h00};
|
| 587 |
+
end
|
| 588 |
+
16'b0000000000111111: begin
|
| 589 |
+
TableCode <= {10'h000,HuffmanTable[5][15:10]};
|
| 590 |
+
NumberCode <= HuffmanNumber[5];
|
| 591 |
+
CodeNumber <= 4'h5;
|
| 592 |
+
DataNumber <= {10'h000,ProcessData[31:26]};
|
| 593 |
+
ProcessData <= {ProcessData[25:0],6'h00};
|
| 594 |
+
end
|
| 595 |
+
16'b0000000001111111: begin
|
| 596 |
+
TableCode <= {9'h000,HuffmanTable[6][15:9]};
|
| 597 |
+
NumberCode <= HuffmanNumber[6];
|
| 598 |
+
CodeNumber <= 4'h6;
|
| 599 |
+
DataNumber <= {9'h000,ProcessData[31:25]};
|
| 600 |
+
ProcessData <= {ProcessData[24:0],7'h00};
|
| 601 |
+
end
|
| 602 |
+
16'b0000000011111111: begin
|
| 603 |
+
TableCode <= {8'h00,HuffmanTable[7][15:8]};
|
| 604 |
+
NumberCode <= HuffmanNumber[7];
|
| 605 |
+
CodeNumber <= 4'h7;
|
| 606 |
+
DataNumber <= {8'h00,ProcessData[31:24]};
|
| 607 |
+
ProcessData <= {ProcessData[23:0],8'h00};
|
| 608 |
+
end
|
| 609 |
+
16'b0000000111111111: begin
|
| 610 |
+
TableCode <= {7'h00,HuffmanTable[8][15:7]};
|
| 611 |
+
NumberCode <= HuffmanNumber[8];
|
| 612 |
+
CodeNumber <= 4'h8;
|
| 613 |
+
DataNumber <= {7'h00,ProcessData[31:23]};
|
| 614 |
+
ProcessData <= {ProcessData[22:0],9'h000};
|
| 615 |
+
end
|
| 616 |
+
16'b0000001111111111: begin
|
| 617 |
+
TableCode <= {6'h00,HuffmanTable[9][15:6]};
|
| 618 |
+
NumberCode <= HuffmanNumber[9];
|
| 619 |
+
CodeNumber <= 4'h9;
|
| 620 |
+
DataNumber <= {6'h00,ProcessData[31:22]};
|
| 621 |
+
ProcessData <= {ProcessData[21:0],10'h000};
|
| 622 |
+
end
|
| 623 |
+
16'b0000011111111111: begin
|
| 624 |
+
TableCode <= {5'h00,HuffmanTable[10][15:5]};
|
| 625 |
+
NumberCode <= HuffmanNumber[10];
|
| 626 |
+
CodeNumber <= 4'hA;
|
| 627 |
+
DataNumber <= {5'h00,ProcessData[31:21]};
|
| 628 |
+
ProcessData <= {ProcessData[20:0],11'h000};
|
| 629 |
+
end
|
| 630 |
+
16'b0000111111111111: begin
|
| 631 |
+
TableCode <= {4'h0,HuffmanTable[11][15:4]};
|
| 632 |
+
NumberCode <= HuffmanNumber[11];
|
| 633 |
+
CodeNumber <= 4'hB;
|
| 634 |
+
DataNumber <= {4'h0,ProcessData[31:20]};
|
| 635 |
+
ProcessData <= {ProcessData[19:0],12'h000};
|
| 636 |
+
end
|
| 637 |
+
16'b0001111111111111: begin
|
| 638 |
+
TableCode <= {3'h0,HuffmanTable[12][15:3]};
|
| 639 |
+
NumberCode <= HuffmanNumber[12];
|
| 640 |
+
CodeNumber <= 4'hC;
|
| 641 |
+
DataNumber <= {3'h0,ProcessData[31:19]};
|
| 642 |
+
ProcessData <= {ProcessData[18:0],13'h0000};
|
| 643 |
+
end
|
| 644 |
+
16'b0011111111111111: begin
|
| 645 |
+
TableCode <= {2'h0,HuffmanTable[13][15:2]};
|
| 646 |
+
NumberCode <= HuffmanNumber[13];
|
| 647 |
+
CodeNumber <= 4'hD;
|
| 648 |
+
DataNumber <= {2'h0,ProcessData[31:18]};
|
| 649 |
+
ProcessData <= {ProcessData[17:0],14'h0000};
|
| 650 |
+
end
|
| 651 |
+
16'b0111111111111111: begin
|
| 652 |
+
TableCode <= {1'h0,HuffmanTable[14][15:1]};
|
| 653 |
+
NumberCode <= HuffmanNumber[14];
|
| 654 |
+
CodeNumber <= 4'hE;
|
| 655 |
+
DataNumber <= {1'h0,ProcessData[31:17]};
|
| 656 |
+
ProcessData <= {ProcessData[16:0],15'h0000};
|
| 657 |
+
end
|
| 658 |
+
16'b1111111111111111: begin
|
| 659 |
+
TableCode <= HuffmanTable[15];
|
| 660 |
+
NumberCode <= HuffmanNumber[15];
|
| 661 |
+
CodeNumber <= 4'hF;
|
| 662 |
+
DataNumber <= ProcessData[31:16] ;
|
| 663 |
+
ProcessData <= {ProcessData[15:0],16'h0000};
|
| 664 |
+
end
|
| 665 |
+
endcase
|
| 666 |
+
end
|
| 667 |
+
Phase5: begin
|
| 668 |
+
if(DataOutIdle == 1'b1) Process <= Phase6;
|
| 669 |
+
end
|
| 670 |
+
Phase6: begin
|
| 671 |
+
Process <= Phase7;
|
| 672 |
+
OutZero <= DhtZero;
|
| 673 |
+
UseWidth <= CodeNumber + DhtWidth +5'd1;
|
| 674 |
+
if(ProcessCount == 0) begin
|
| 675 |
+
OutEnable <= 1'b1;
|
| 676 |
+
end else begin
|
| 677 |
+
if(DhtZero == 4'h0 & DhtWidth == 4'h0) begin
|
| 678 |
+
ProcessCount <= 6'd63;
|
| 679 |
+
OutEnable <= 1'b0;
|
| 680 |
+
end else if(DhtZero == 4'hF & DhtWidth == 4'h0) begin
|
| 681 |
+
ProcessCount <= ProcessCount + 6'd15;
|
| 682 |
+
OutEnable <= 1'b0;
|
| 683 |
+
end else begin
|
| 684 |
+
ProcessCount <= ProcessCount + DhtZero;
|
| 685 |
+
OutEnable <= 1'b1;
|
| 686 |
+
end
|
| 687 |
+
end
|
| 688 |
+
|
| 689 |
+
if(ProcessData[31] == 1'b0 & DhtWidth != 0) begin
|
| 690 |
+
OutCode <= (OutCodeP | SubCode) + 16'h0001;
|
| 691 |
+
end else begin
|
| 692 |
+
OutCode <= OutCodeP;
|
| 693 |
+
end
|
| 694 |
+
end
|
| 695 |
+
Phase7: begin
|
| 696 |
+
Process <= Phase8;
|
| 697 |
+
if(ProcessCount == 0) begin
|
| 698 |
+
if(ProcessColor[2] == 1'b0) begin
|
| 699 |
+
OutCode <= OutCode + PreData[0][15:0];
|
| 700 |
+
PreData[0] <= OutCode + PreData[0];
|
| 701 |
+
end else begin
|
| 702 |
+
if(ProcessColor[0] == 1'b0) begin
|
| 703 |
+
OutCode <= OutCode + PreData[1][15:0];
|
| 704 |
+
PreData[1] <= OutCode + PreData[1];
|
| 705 |
+
end else begin
|
| 706 |
+
OutCode <= OutCode + PreData[2][15:0];
|
| 707 |
+
PreData[2] <= OutCode + PreData[2];
|
| 708 |
+
end
|
| 709 |
+
end
|
| 710 |
+
end
|
| 711 |
+
end
|
| 712 |
+
Phase8: begin
|
| 713 |
+
OutEnable <= 1'b0;
|
| 714 |
+
Process <= Phase1;
|
| 715 |
+
if(ProcessCount <6'd63) begin
|
| 716 |
+
ProcessCount <= ProcessCount +6'd1;
|
| 717 |
+
end else begin
|
| 718 |
+
ProcessCount <= 6'd0;
|
| 719 |
+
// DataOutEnable <= 1'b1;
|
| 720 |
+
DataOutColor <= ProcessColor;
|
| 721 |
+
// JPEGコンポーネント数が3ならブロックは6つある
|
| 722 |
+
// JPEGコンポーネント数が1ならブロックは4つしかない(グレースケール)
|
| 723 |
+
if( ((JpegComp == 3) && (ProcessColor == 5)) ||
|
| 724 |
+
((JpegComp == 1) && (ProcessColor == 3))
|
| 725 |
+
) begin
|
| 726 |
+
// if(ProcessColor == 5) begin
|
| 727 |
+
ProcessColor <= 3'b000;
|
| 728 |
+
end else begin
|
| 729 |
+
ProcessColor <= ProcessColor +3'd1;
|
| 730 |
+
end
|
| 731 |
+
end
|
| 732 |
+
end
|
| 733 |
+
endcase
|
| 734 |
+
end
|
| 735 |
+
end
|
| 736 |
+
|
| 737 |
+
assign DhtColor[1] = ProcessColor[2];
|
| 738 |
+
assign DhtColor[0] = ProcessCount != 6'd0;
|
| 739 |
+
assign DhtNumber = DataNumber - TableCode + NumberCode;
|
| 740 |
+
|
| 741 |
+
assign DqtColor = ProcessColor[2];
|
| 742 |
+
assign DqtNumber = ProcessCount[5:0];
|
| 743 |
+
|
| 744 |
+
assign DecodeUseBit = Process == Phase7;
|
| 745 |
+
assign DecodeUseWidth = UseWidth;
|
| 746 |
+
|
| 747 |
+
assign DecodeEnable = OutEnable == 1'b1 & Process == Phase8;
|
| 748 |
+
assign DecodeColor = ProcessColor;
|
| 749 |
+
assign DecodeCount = ProcessCount[5:0];
|
| 750 |
+
assign DecodeZero = OutZero;
|
| 751 |
+
assign DecodeCode = DqtData * OutCode;
|
| 752 |
+
|
| 753 |
+
assign DataOutEnable = (Process == Phase8) & (ProcessCount >= 6'd63);
|
| 754 |
+
|
| 755 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_huffman.v
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_huffman(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
|
| 25 |
+
// Init
|
| 26 |
+
input ProcessInit,
|
| 27 |
+
|
| 28 |
+
// DQT Table
|
| 29 |
+
input DqtInEnable,
|
| 30 |
+
input DqtInColor,
|
| 31 |
+
input [5:0] DqtInCount,
|
| 32 |
+
input [7:0] DqtInData,
|
| 33 |
+
|
| 34 |
+
// DHT Table
|
| 35 |
+
input DhtInEnable,
|
| 36 |
+
input [1:0] DhtInColor,
|
| 37 |
+
input [7:0] DhtInCount,
|
| 38 |
+
input [7:0] DhtInData,
|
| 39 |
+
|
| 40 |
+
// Huffman Table
|
| 41 |
+
input HuffmanTableEnable, // Table Data In Enable
|
| 42 |
+
input [1:0] HuffmanTableColor, // Huffman Table Color Number
|
| 43 |
+
input [3:0] HuffmanTableCount, // Table Number
|
| 44 |
+
input [15:0] HuffmanTableCode, // Huffman Table Data
|
| 45 |
+
input [7:0] HuffmanTableStart, // Huffman Table Start Number
|
| 46 |
+
|
| 47 |
+
// Huffman Decode
|
| 48 |
+
input DataInRun, // Data In Start
|
| 49 |
+
input DataInEnable, // Data In Enable
|
| 50 |
+
input [31:0] DataIn, // Data In
|
| 51 |
+
input [2:0] JpegComp,
|
| 52 |
+
|
| 53 |
+
output DecodeUseBit,
|
| 54 |
+
output [6:0] DecodeUseWidth,
|
| 55 |
+
|
| 56 |
+
// Data Out
|
| 57 |
+
output DataOutEnable,
|
| 58 |
+
output [2:0] DataOutColor,
|
| 59 |
+
input DataOutRead,
|
| 60 |
+
input [4:0] DataOutAddress,
|
| 61 |
+
output [15:0] DataOutA,
|
| 62 |
+
output [15:0] DataOutB
|
| 63 |
+
);
|
| 64 |
+
wire HmDqtColor;
|
| 65 |
+
wire [5:0] HmDqtNumber;
|
| 66 |
+
wire [7:0] HmDqtData;
|
| 67 |
+
|
| 68 |
+
// DQT Table
|
| 69 |
+
aq_djpeg_dqt u_jpeg_dqt(
|
| 70 |
+
.rst ( rst ),
|
| 71 |
+
.clk ( clk ),
|
| 72 |
+
|
| 73 |
+
.DataInEnable ( DqtInEnable ),
|
| 74 |
+
.DataInColor ( DqtInColor ),
|
| 75 |
+
.DataInCount ( DqtInCount[5:0] ),
|
| 76 |
+
.DataIn ( DqtInData ),
|
| 77 |
+
|
| 78 |
+
.TableColor ( HmDqtColor ),
|
| 79 |
+
.TableNumber ( HmDqtNumber ),
|
| 80 |
+
.TableData ( HmDqtData )
|
| 81 |
+
);
|
| 82 |
+
|
| 83 |
+
wire [1:0] HmDhtColor;
|
| 84 |
+
wire [7:0] HmDhtNumber;
|
| 85 |
+
wire [3:0] HmDhtZero;
|
| 86 |
+
wire [3:0] HmDhtWidth;
|
| 87 |
+
|
| 88 |
+
aq_djpeg_dht u_jpeg_dht(
|
| 89 |
+
.rst ( rst ),
|
| 90 |
+
.clk ( clk ),
|
| 91 |
+
|
| 92 |
+
.DataInEnable ( DhtInEnable ),
|
| 93 |
+
.DataInColor ( DhtInColor ),
|
| 94 |
+
.DataInCount ( DhtInCount ),
|
| 95 |
+
.DataIn ( DhtInData ),
|
| 96 |
+
|
| 97 |
+
.ColorNumber ( HmDhtColor ),
|
| 98 |
+
.TableNumber ( HmDhtNumber ),
|
| 99 |
+
.ZeroTable ( HmDhtZero ),
|
| 100 |
+
.WidhtTable ( HmDhtWidth )
|
| 101 |
+
);
|
| 102 |
+
|
| 103 |
+
wire [5:0] HmDecCount;
|
| 104 |
+
wire [15:0] HmDecData;
|
| 105 |
+
|
| 106 |
+
wire HmOutEnable;
|
| 107 |
+
wire [2:0] HmOutColor;
|
| 108 |
+
|
| 109 |
+
aq_djpeg_hm_decode u_jpeg_hm_decode(
|
| 110 |
+
.rst ( rst ),
|
| 111 |
+
.clk ( clk ),
|
| 112 |
+
|
| 113 |
+
// Huffman Table
|
| 114 |
+
.HuffmanTableEnable ( HuffmanTableEnable ),
|
| 115 |
+
.HuffmanTableColor ( HuffmanTableColor ),
|
| 116 |
+
.HuffmanTableCount ( HuffmanTableCount ),
|
| 117 |
+
.HuffmanTableCode ( HuffmanTableCode ),
|
| 118 |
+
.HuffmanTableStart ( HuffmanTableStart ),
|
| 119 |
+
|
| 120 |
+
// Huffman Decode
|
| 121 |
+
.DataInRun ( DataInRun ),
|
| 122 |
+
.DataInEnable ( DataInEnable ),
|
| 123 |
+
.DataIn ( DataIn ),
|
| 124 |
+
.JpegComp ( JpegComp ),
|
| 125 |
+
|
| 126 |
+
// Huffman Table List
|
| 127 |
+
.DhtColor ( HmDhtColor ),
|
| 128 |
+
.DhtNumber ( HmDhtNumber ),
|
| 129 |
+
.DhtZero ( HmDhtZero ),
|
| 130 |
+
.DhtWidth ( HmDhtWidth ),
|
| 131 |
+
|
| 132 |
+
// DQT Table
|
| 133 |
+
.DqtColor ( HmDqtColor ),
|
| 134 |
+
.DqtNumber ( HmDqtNumber ),
|
| 135 |
+
.DqtData ( HmDqtData ),
|
| 136 |
+
|
| 137 |
+
.DataOutIdle ( HmOutIdle ),
|
| 138 |
+
.DataOutEnable ( HmOutEnable ),
|
| 139 |
+
.DataOutColor ( HmOutColor ),
|
| 140 |
+
|
| 141 |
+
// Output decode data
|
| 142 |
+
.DecodeUseBit ( DecodeUseBit ),
|
| 143 |
+
.DecodeUseWidth ( DecodeUseWidth ),
|
| 144 |
+
|
| 145 |
+
.DecodeEnable ( HmDecEnable ),
|
| 146 |
+
.DecodeColor ( ),
|
| 147 |
+
.DecodeCount ( HmDecCount ),
|
| 148 |
+
.DecodeZero ( ),
|
| 149 |
+
.DecodeCode ( HmDecData )
|
| 150 |
+
);
|
| 151 |
+
|
| 152 |
+
// Ziguzagu to iDCTx Matrix
|
| 153 |
+
aq_djpeg_ziguzagu u_jpeg_ziguzagu(
|
| 154 |
+
.rst ( rst ),
|
| 155 |
+
.clk ( clk ),
|
| 156 |
+
|
| 157 |
+
.DataInit ( ProcessInit ),
|
| 158 |
+
.HuffmanEndEnable ( HmOutEnable ),
|
| 159 |
+
|
| 160 |
+
.DataInEnable ( HmDecEnable ),
|
| 161 |
+
.DataInAddress ( HmDecCount ),
|
| 162 |
+
.DataInColor ( HmOutColor ),
|
| 163 |
+
.DataInIdle ( HmOutIdle ),
|
| 164 |
+
.DataIn ( HmDecData ),
|
| 165 |
+
|
| 166 |
+
.DataOutEnable ( DataOutEnable ),
|
| 167 |
+
.DataOutRead ( DataOutRead ),
|
| 168 |
+
.DataOutAddress ( DataOutAddress ),
|
| 169 |
+
.DataOutColor ( DataOutColor ),
|
| 170 |
+
.DataOutA ( DataOutA ),
|
| 171 |
+
.DataOutB ( DataOutB )
|
| 172 |
+
);
|
| 173 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_idct.v
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_idct(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
|
| 25 |
+
input ProcessInit,
|
| 26 |
+
|
| 27 |
+
input DataInEnable,
|
| 28 |
+
output DataInRead,
|
| 29 |
+
output [4:0] DataInAddress,
|
| 30 |
+
input [15:0] DataInA,
|
| 31 |
+
input [15:0] DataInB,
|
| 32 |
+
|
| 33 |
+
output DataOutEnable,
|
| 34 |
+
output [2:0] DataOutPage,
|
| 35 |
+
output [1:0] DataOutCount,
|
| 36 |
+
output [8:0] Data0Out,
|
| 37 |
+
output [8:0] Data1Out
|
| 38 |
+
);
|
| 39 |
+
wire DctXEnable;
|
| 40 |
+
wire [2:0] DctXPage;
|
| 41 |
+
wire [1:0] DctXCount;
|
| 42 |
+
wire [31:0] DctXData0r;
|
| 43 |
+
wire [31:0] DctXData1r;
|
| 44 |
+
|
| 45 |
+
aq_djpeg_idct_calc u_jpeg_idctx(
|
| 46 |
+
.rst ( rst ),
|
| 47 |
+
.clk ( clk ),
|
| 48 |
+
|
| 49 |
+
.DataInEnable ( DataInEnable ),
|
| 50 |
+
.DataInRead ( DataInRead ),
|
| 51 |
+
.DataInAddress ( DataInAddress ),
|
| 52 |
+
.DataInA ( DataInA ),
|
| 53 |
+
.DataInB ( DataInB ),
|
| 54 |
+
|
| 55 |
+
.DataOutEnable ( DctXEnable ),
|
| 56 |
+
.DataOutPage ( DctXPage ),
|
| 57 |
+
.DataOutCount ( DctXCount ),
|
| 58 |
+
.Data0Out ( DctXData0r ),
|
| 59 |
+
.Data1Out ( DctXData1r )
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
wire DctBEnable;
|
| 63 |
+
wire DctBRead;
|
| 64 |
+
wire [4:0] DctBAddress;
|
| 65 |
+
wire [15:0] DctBDataA;
|
| 66 |
+
wire [15:0] DctBDataB;
|
| 67 |
+
|
| 68 |
+
aq_djpeg_idctb u_jpeg_idctb(
|
| 69 |
+
.rst ( rst ),
|
| 70 |
+
.clk ( clk ),
|
| 71 |
+
|
| 72 |
+
.DataInit ( ProcessInit ),
|
| 73 |
+
|
| 74 |
+
.DataInEnable ( DctXEnable ),
|
| 75 |
+
.DataInPage ( DctXPage ),
|
| 76 |
+
.DataInCount ( DctXCount ),
|
| 77 |
+
.DataInIdle ( DctBIdle ),
|
| 78 |
+
.DataInA ( DctXData0r[26:11] ),
|
| 79 |
+
.DataInB ( DctXData1r[26:11] ),
|
| 80 |
+
|
| 81 |
+
.DataOutEnable ( DctBEnable ),
|
| 82 |
+
.DataOutRead ( DctBRead ),
|
| 83 |
+
.DataOutAddress ( DctBAddress ),
|
| 84 |
+
.DataOutA ( DctBDataA ),
|
| 85 |
+
.DataOutB ( DctBDataB )
|
| 86 |
+
|
| 87 |
+
);
|
| 88 |
+
|
| 89 |
+
wire [31:0] Data0OutW, Data1OutW;
|
| 90 |
+
|
| 91 |
+
aq_djpeg_idct_calc u_jpeg_idcty(
|
| 92 |
+
.rst ( rst ),
|
| 93 |
+
.clk ( clk ),
|
| 94 |
+
|
| 95 |
+
.DataInEnable ( DctBEnable ),
|
| 96 |
+
.DataInRead ( DctBRead ),
|
| 97 |
+
.DataInAddress ( DctBAddress ),
|
| 98 |
+
.DataInA ( DctBDataA ),
|
| 99 |
+
.DataInB ( DctBDataB ),
|
| 100 |
+
|
| 101 |
+
.DataOutEnable ( DataOutEnable ),
|
| 102 |
+
.DataOutPage ( DataOutPage ),
|
| 103 |
+
.DataOutCount ( DataOutCount ),
|
| 104 |
+
.Data0Out ( Data0OutW ),
|
| 105 |
+
.Data1Out ( Data1OutW )
|
| 106 |
+
);
|
| 107 |
+
|
| 108 |
+
assign Data0Out = Data0OutW[23:15];
|
| 109 |
+
assign Data1Out = Data1OutW[23:15];
|
| 110 |
+
|
| 111 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_idct_calc.v
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_idct_calc(
|
| 22 |
+
input clk,
|
| 23 |
+
input rst,
|
| 24 |
+
|
| 25 |
+
input DataInEnable,
|
| 26 |
+
output DataInRead,
|
| 27 |
+
output [4:0] DataInAddress,
|
| 28 |
+
input [15:0] DataInA,
|
| 29 |
+
input [15:0] DataInB,
|
| 30 |
+
|
| 31 |
+
output DataOutEnable,
|
| 32 |
+
output [2:0] DataOutPage,
|
| 33 |
+
output [1:0] DataOutCount,
|
| 34 |
+
output [31:0] Data0Out,
|
| 35 |
+
output [31:0] Data1Out
|
| 36 |
+
);
|
| 37 |
+
//-------------------------------------------------------------------------
|
| 38 |
+
// Phase1
|
| 39 |
+
//-------------------------------------------------------------------------
|
| 40 |
+
reg Phase1Enable;
|
| 41 |
+
reg [2:0] Phase1Page;
|
| 42 |
+
reg [2:0] Phase1Count;
|
| 43 |
+
reg Phase1EnableD;
|
| 44 |
+
reg [2:0] Phase1PageD;
|
| 45 |
+
reg [2:0] Phase1CountD;
|
| 46 |
+
|
| 47 |
+
always @(posedge clk or negedge rst) begin
|
| 48 |
+
if(!rst) begin
|
| 49 |
+
Phase1Enable <= 1'b0;
|
| 50 |
+
Phase1Page <= 3'd0;
|
| 51 |
+
Phase1Count <= 3'd0;
|
| 52 |
+
Phase1EnableD <= 1'b0;
|
| 53 |
+
Phase1PageD <= 3'd0;
|
| 54 |
+
Phase1CountD <= 3'd0;
|
| 55 |
+
end else begin
|
| 56 |
+
if(Phase1Enable == 1'b0) begin
|
| 57 |
+
if(DataInEnable == 1'b1) begin
|
| 58 |
+
Phase1Enable <= 1'b1;
|
| 59 |
+
Phase1Page <= 3'd0;
|
| 60 |
+
Phase1Count <= 3'd0;
|
| 61 |
+
end
|
| 62 |
+
end else begin
|
| 63 |
+
if(Phase1Count == 3'd6) begin
|
| 64 |
+
if(Phase1Page == 3'd7) begin
|
| 65 |
+
Phase1Enable <= 1'b0;
|
| 66 |
+
Phase1Page <= 3'd0;
|
| 67 |
+
end else begin
|
| 68 |
+
Phase1Page <= Phase1Page + 3'd1;
|
| 69 |
+
end
|
| 70 |
+
Phase1Count <= 3'd0;
|
| 71 |
+
end else begin
|
| 72 |
+
Phase1Count <= Phase1Count + 3'd1;
|
| 73 |
+
end
|
| 74 |
+
end
|
| 75 |
+
Phase1EnableD <= Phase1Enable;
|
| 76 |
+
Phase1PageD <= Phase1Page;
|
| 77 |
+
Phase1CountD <= Phase1Count;
|
| 78 |
+
end
|
| 79 |
+
end
|
| 80 |
+
|
| 81 |
+
assign DataInRead = Phase1Enable & (Phase1Count < 3'd4);
|
| 82 |
+
assign DataInAddress = {Phase1Page, Phase1Count[1:0]};
|
| 83 |
+
|
| 84 |
+
wire signed [15:0] Phase1R0w;
|
| 85 |
+
wire signed [15:0] Phase1R1w;
|
| 86 |
+
wire signed [15:0] Phase1C0w;
|
| 87 |
+
wire signed [15:0] Phase1C1w;
|
| 88 |
+
wire signed [15:0] Phase1C2w;
|
| 89 |
+
wire signed [15:0] Phase1C3w;
|
| 90 |
+
|
| 91 |
+
assign Phase1R0w = DataInA;
|
| 92 |
+
assign Phase1R1w = DataInB;
|
| 93 |
+
|
| 94 |
+
function [15:0] Phase1C0wSel;
|
| 95 |
+
input [2:0] Phase1Count;
|
| 96 |
+
begin
|
| 97 |
+
case(Phase1Count)
|
| 98 |
+
3'd0: begin
|
| 99 |
+
Phase1C0wSel = 16'd2896; // C4_16
|
| 100 |
+
end
|
| 101 |
+
3'd1: begin
|
| 102 |
+
Phase1C0wSel = 16'd3784; // C2_16
|
| 103 |
+
end
|
| 104 |
+
3'd2: begin
|
| 105 |
+
Phase1C0wSel = 16'd4017; // C1_16
|
| 106 |
+
end
|
| 107 |
+
3'd3: begin
|
| 108 |
+
Phase1C0wSel = 16'd2276; // C5_16
|
| 109 |
+
end
|
| 110 |
+
default: begin
|
| 111 |
+
Phase1C0wSel = 16'd0;
|
| 112 |
+
end
|
| 113 |
+
endcase
|
| 114 |
+
end
|
| 115 |
+
endfunction
|
| 116 |
+
|
| 117 |
+
function [15:0] Phase1C1wSel;
|
| 118 |
+
input [2:0] Phase1Count;
|
| 119 |
+
begin
|
| 120 |
+
case(Phase1Count)
|
| 121 |
+
3'd0: begin
|
| 122 |
+
Phase1C1wSel = 16'd2896; // C4_16
|
| 123 |
+
end
|
| 124 |
+
3'd1: begin
|
| 125 |
+
Phase1C1wSel = 16'd1567; // C6_16
|
| 126 |
+
end
|
| 127 |
+
3'd2: begin
|
| 128 |
+
Phase1C1wSel = 16'd799; // C7_16
|
| 129 |
+
end
|
| 130 |
+
3'd3: begin
|
| 131 |
+
Phase1C1wSel = 16'd3406; // C3_16
|
| 132 |
+
end
|
| 133 |
+
default: begin
|
| 134 |
+
Phase1C1wSel = 16'd0;
|
| 135 |
+
end
|
| 136 |
+
endcase
|
| 137 |
+
end
|
| 138 |
+
endfunction
|
| 139 |
+
|
| 140 |
+
function [15:0] Phase1C2wSel;
|
| 141 |
+
input [2:0] Phase1Count;
|
| 142 |
+
begin
|
| 143 |
+
case(Phase1Count)
|
| 144 |
+
3'd0: begin
|
| 145 |
+
Phase1C2wSel = 16'd2896; // C4_16
|
| 146 |
+
end
|
| 147 |
+
3'd1: begin
|
| 148 |
+
Phase1C2wSel = 16'd1567; // C6_16
|
| 149 |
+
end
|
| 150 |
+
3'd2: begin
|
| 151 |
+
Phase1C2wSel = 16'd799; // C7_16
|
| 152 |
+
end
|
| 153 |
+
3'd3: begin
|
| 154 |
+
Phase1C2wSel = 16'd3406; // C3_16
|
| 155 |
+
end
|
| 156 |
+
default: begin
|
| 157 |
+
Phase1C2wSel = 16'd0;
|
| 158 |
+
end
|
| 159 |
+
endcase
|
| 160 |
+
end
|
| 161 |
+
endfunction
|
| 162 |
+
|
| 163 |
+
function [15:0] Phase1C3wSel;
|
| 164 |
+
input [2:0] Phase1Count;
|
| 165 |
+
begin
|
| 166 |
+
case(Phase1Count)
|
| 167 |
+
3'd0: begin
|
| 168 |
+
Phase1C3wSel = 16'd2896; // C4_16
|
| 169 |
+
end
|
| 170 |
+
3'd1: begin
|
| 171 |
+
Phase1C3wSel = 16'd3784; // C2_16
|
| 172 |
+
end
|
| 173 |
+
3'd2: begin
|
| 174 |
+
Phase1C3wSel = 16'd4017; // C1_16
|
| 175 |
+
end
|
| 176 |
+
3'd3: begin
|
| 177 |
+
Phase1C3wSel = 16'd2276; // C5_16
|
| 178 |
+
end
|
| 179 |
+
default: begin
|
| 180 |
+
Phase1C3wSel = 16'd0;
|
| 181 |
+
end
|
| 182 |
+
endcase
|
| 183 |
+
end
|
| 184 |
+
endfunction
|
| 185 |
+
|
| 186 |
+
assign Phase1C0w = Phase1C0wSel(Phase1CountD);
|
| 187 |
+
assign Phase1C1w = Phase1C1wSel(Phase1CountD);
|
| 188 |
+
assign Phase1C2w = Phase1C2wSel(Phase1CountD);
|
| 189 |
+
assign Phase1C3w = Phase1C3wSel(Phase1CountD);
|
| 190 |
+
|
| 191 |
+
reg signed [31:0] Phase1R0r;
|
| 192 |
+
reg signed [31:0] Phase1R1r;
|
| 193 |
+
reg signed [31:0] Phase1R2r;
|
| 194 |
+
reg signed [31:0] Phase1R3r;
|
| 195 |
+
|
| 196 |
+
always @(posedge clk or negedge rst) begin
|
| 197 |
+
if(!rst) begin
|
| 198 |
+
Phase1R0r <= 0;
|
| 199 |
+
Phase1R1r <= 0;
|
| 200 |
+
Phase1R2r <= 0;
|
| 201 |
+
Phase1R3r <= 0;
|
| 202 |
+
end else begin
|
| 203 |
+
Phase1R0r <= Phase1R0w * Phase1C0w;
|
| 204 |
+
Phase1R1r <= Phase1R1w * Phase1C1w;
|
| 205 |
+
Phase1R2r <= Phase1R0w * Phase1C2w;
|
| 206 |
+
Phase1R3r <= Phase1R1w * Phase1C3w;
|
| 207 |
+
end
|
| 208 |
+
end
|
| 209 |
+
|
| 210 |
+
/*
|
| 211 |
+
always @(posedge clk) begin
|
| 212 |
+
if((Phase1EnableD == 1'b1) && (Phase1CountD < 3'd4)) begin
|
| 213 |
+
$display("(%d,%d) = %8x, %8x",Phase1PageD ,Phase1CountD,
|
| 214 |
+
Phase1R0w, Phase1R1w);
|
| 215 |
+
end
|
| 216 |
+
//if((Phase1EnableD == 1'b1) && (Phase1CountD < 3'd4)) begin
|
| 217 |
+
// $display("(%d,%d) = %8x, %8x, %8x, %8x",Phase1PageD ,Phase1CountD,
|
| 218 |
+
// Phase1R0r, Phase1R1r, Phase1R2r, Phase1R3r);
|
| 219 |
+
//end
|
| 220 |
+
end
|
| 221 |
+
*/
|
| 222 |
+
//-------------------------------------------------------------------------
|
| 223 |
+
// Phase2
|
| 224 |
+
// R0: s0,s3,s7,s6
|
| 225 |
+
// R1: s1,s2,s4,s5
|
| 226 |
+
//-------------------------------------------------------------------------
|
| 227 |
+
reg Phase2Enable;
|
| 228 |
+
reg [2:0] Phase2Page;
|
| 229 |
+
reg [2:0] Phase2Count;
|
| 230 |
+
reg Phase2EnableD;
|
| 231 |
+
reg [2:0] Phase2PageD;
|
| 232 |
+
reg [2:0] Phase2CountD;
|
| 233 |
+
|
| 234 |
+
always @(posedge clk or negedge rst) begin
|
| 235 |
+
if(!rst) begin
|
| 236 |
+
Phase2Enable <= 1'b0;
|
| 237 |
+
Phase2Page <= 3'd0;
|
| 238 |
+
Phase2Count <= 3'd0;
|
| 239 |
+
Phase2EnableD <= 1'b0;
|
| 240 |
+
Phase2PageD <= 3'd0;
|
| 241 |
+
Phase2CountD <= 3'd0;
|
| 242 |
+
end else begin
|
| 243 |
+
Phase2Enable <= Phase1EnableD;
|
| 244 |
+
Phase2Page <= Phase1PageD;
|
| 245 |
+
Phase2Count <= Phase1CountD;
|
| 246 |
+
Phase2EnableD <= Phase2Enable;
|
| 247 |
+
Phase2PageD <= Phase2Page;
|
| 248 |
+
Phase2CountD <= Phase2Count;
|
| 249 |
+
end
|
| 250 |
+
end
|
| 251 |
+
|
| 252 |
+
wire signed [31:0] Phase2A0w;
|
| 253 |
+
wire signed [31:0] Phase2A1w;
|
| 254 |
+
|
| 255 |
+
assign Phase2A0w = Phase1R0r + Phase1R1r;
|
| 256 |
+
assign Phase2A1w = Phase1R2r - Phase1R3r;
|
| 257 |
+
|
| 258 |
+
reg signed [31:0] Phase2Reg [0:7];
|
| 259 |
+
|
| 260 |
+
always @(posedge clk or negedge rst) begin
|
| 261 |
+
if(!rst) begin
|
| 262 |
+
Phase2Reg[0] <= 0;
|
| 263 |
+
Phase2Reg[1] <= 0;
|
| 264 |
+
Phase2Reg[2] <= 0;
|
| 265 |
+
Phase2Reg[3] <= 0;
|
| 266 |
+
Phase2Reg[4] <= 0;
|
| 267 |
+
Phase2Reg[5] <= 0;
|
| 268 |
+
Phase2Reg[6] <= 0;
|
| 269 |
+
Phase2Reg[7] <= 0;
|
| 270 |
+
end else begin
|
| 271 |
+
case(Phase2Count)
|
| 272 |
+
3'd0: begin
|
| 273 |
+
Phase2Reg[0] <= Phase2A0w;
|
| 274 |
+
Phase2Reg[1] <= Phase2A1w;
|
| 275 |
+
end
|
| 276 |
+
3'd1: begin
|
| 277 |
+
Phase2Reg[3] <= Phase2A0w;
|
| 278 |
+
Phase2Reg[2] <= Phase2A1w;
|
| 279 |
+
end
|
| 280 |
+
3'd2: begin
|
| 281 |
+
Phase2Reg[7] <= Phase2A0w;
|
| 282 |
+
Phase2Reg[4] <= Phase2A1w;
|
| 283 |
+
end
|
| 284 |
+
3'd3: begin
|
| 285 |
+
Phase2Reg[6] <= Phase2A0w;
|
| 286 |
+
Phase2Reg[5] <= Phase2A1w;
|
| 287 |
+
end
|
| 288 |
+
endcase
|
| 289 |
+
end
|
| 290 |
+
end
|
| 291 |
+
|
| 292 |
+
//-------------------------------------------------------------------------
|
| 293 |
+
// Phase3
|
| 294 |
+
// R0: t0,t1,t4,t7
|
| 295 |
+
// R1: t3,t2,t5,t6
|
| 296 |
+
//-------------------------------------------------------------------------
|
| 297 |
+
reg Phase3Enable;
|
| 298 |
+
reg [2:0] Phase3Page;
|
| 299 |
+
reg [2:0] Phase3Count;
|
| 300 |
+
reg Phase3EnableD;
|
| 301 |
+
reg [2:0] Phase3PageD;
|
| 302 |
+
reg [2:0] Phase3CountD;
|
| 303 |
+
|
| 304 |
+
always @(posedge clk or negedge rst) begin
|
| 305 |
+
if(!rst) begin
|
| 306 |
+
Phase3Enable <= 1'b0;
|
| 307 |
+
Phase3Page <= 3'd0;
|
| 308 |
+
Phase3Count <= 3'd0;
|
| 309 |
+
Phase3EnableD <= 1'b0;
|
| 310 |
+
Phase3PageD <= 3'd0;
|
| 311 |
+
Phase3CountD <= 3'd0;
|
| 312 |
+
end else begin
|
| 313 |
+
Phase3Enable <= Phase2EnableD;
|
| 314 |
+
Phase3Page <= Phase2PageD;
|
| 315 |
+
Phase3Count <= Phase2CountD;
|
| 316 |
+
Phase3EnableD <= Phase3Enable;
|
| 317 |
+
Phase3PageD <= Phase3Page;
|
| 318 |
+
Phase3CountD <= Phase3Count;
|
| 319 |
+
end
|
| 320 |
+
end
|
| 321 |
+
|
| 322 |
+
wire signed [31:0] Phase3R0w;
|
| 323 |
+
wire signed [31:0] Phase3R1w;
|
| 324 |
+
|
| 325 |
+
assign Phase3R0w = (Phase3Count == 3'd0)?Phase2Reg[0]:
|
| 326 |
+
(Phase3Count == 3'd1)?Phase2Reg[1]:
|
| 327 |
+
(Phase3Count == 3'd2)?Phase2Reg[4]:
|
| 328 |
+
(Phase3Count == 3'd3)?Phase2Reg[7]:
|
| 329 |
+
32'd0;
|
| 330 |
+
assign Phase3R1w = (Phase3Count == 3'd0)?Phase2Reg[3]:
|
| 331 |
+
(Phase3Count == 3'd1)?Phase2Reg[2]:
|
| 332 |
+
(Phase3Count == 3'd2)?Phase2Reg[5]:
|
| 333 |
+
(Phase3Count == 3'd3)?Phase2Reg[6]:
|
| 334 |
+
32'd0;
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
wire signed [31:0] Phase3A0w;
|
| 339 |
+
wire signed [31:0] Phase3A1w;
|
| 340 |
+
assign Phase3A0w = Phase3R0w + Phase3R1w;
|
| 341 |
+
assign Phase3A1w = Phase3R0w - Phase3R1w;
|
| 342 |
+
|
| 343 |
+
reg signed [31:0] Phase3Reg [0:7];
|
| 344 |
+
|
| 345 |
+
always @(posedge clk or negedge rst) begin
|
| 346 |
+
if(!rst) begin
|
| 347 |
+
Phase3Reg[0] <= 0;
|
| 348 |
+
Phase3Reg[1] <= 0;
|
| 349 |
+
Phase3Reg[2] <= 0;
|
| 350 |
+
Phase3Reg[3] <= 0;
|
| 351 |
+
Phase3Reg[4] <= 0;
|
| 352 |
+
Phase3Reg[5] <= 0;
|
| 353 |
+
Phase3Reg[6] <= 0;
|
| 354 |
+
Phase3Reg[7] <= 0;
|
| 355 |
+
end else begin
|
| 356 |
+
case(Phase3Count)
|
| 357 |
+
3'd0: begin
|
| 358 |
+
Phase3Reg[0] <= Phase3A0w;
|
| 359 |
+
Phase3Reg[3] <= Phase3A1w;
|
| 360 |
+
end
|
| 361 |
+
3'd1: begin
|
| 362 |
+
Phase3Reg[1] <= Phase3A0w;
|
| 363 |
+
Phase3Reg[2] <= Phase3A1w;
|
| 364 |
+
end
|
| 365 |
+
3'd2: begin
|
| 366 |
+
Phase3Reg[4] <= Phase3A0w;
|
| 367 |
+
Phase3Reg[5] <= Phase3A1w;
|
| 368 |
+
end
|
| 369 |
+
3'd3: begin
|
| 370 |
+
Phase3Reg[7] <= Phase3A0w;
|
| 371 |
+
Phase3Reg[6] <= Phase3A1w;
|
| 372 |
+
end
|
| 373 |
+
endcase
|
| 374 |
+
end
|
| 375 |
+
end
|
| 376 |
+
|
| 377 |
+
//-------------------------------------------------------------------------
|
| 378 |
+
// Phase4
|
| 379 |
+
// R0: s6
|
| 380 |
+
// R1: s5
|
| 381 |
+
//-------------------------------------------------------------------------
|
| 382 |
+
reg Phase4Enable;
|
| 383 |
+
reg [2:0] Phase4Page;
|
| 384 |
+
reg [2:0] Phase4Count;
|
| 385 |
+
reg Phase4EnableD;
|
| 386 |
+
reg [2:0] Phase4PageD;
|
| 387 |
+
reg [2:0] Phase4CountD;
|
| 388 |
+
|
| 389 |
+
always @(posedge clk or negedge rst) begin
|
| 390 |
+
if(!rst) begin
|
| 391 |
+
Phase4Enable <= 1'b0;
|
| 392 |
+
Phase4Page <= 3'd0;
|
| 393 |
+
Phase4Count <= 3'd0;
|
| 394 |
+
Phase4EnableD <= 1'b0;
|
| 395 |
+
Phase4PageD <= 3'd0;
|
| 396 |
+
Phase4CountD <= 3'd0;
|
| 397 |
+
end else begin
|
| 398 |
+
Phase4Enable <= Phase3EnableD;
|
| 399 |
+
Phase4Page <= Phase3PageD;
|
| 400 |
+
Phase4Count <= Phase3CountD;
|
| 401 |
+
Phase4EnableD <= Phase4Enable;
|
| 402 |
+
Phase4PageD <= Phase4Page;
|
| 403 |
+
Phase4CountD <= Phase4Count;
|
| 404 |
+
end
|
| 405 |
+
end
|
| 406 |
+
|
| 407 |
+
reg signed [42:0] Phase4R0r;
|
| 408 |
+
reg signed [42:0] Phase4R1r;
|
| 409 |
+
|
| 410 |
+
wire signed [8:0] C_181;
|
| 411 |
+
assign C_181 = 9'h0B5;
|
| 412 |
+
|
| 413 |
+
wire signed [32:0] Phase4R0w;
|
| 414 |
+
wire signed [32:0] Phase4R1w;
|
| 415 |
+
|
| 416 |
+
assign Phase4R0w = Phase3Reg[6] + Phase3Reg[5];
|
| 417 |
+
assign Phase4R1w = Phase3Reg[6] - Phase3Reg[5];
|
| 418 |
+
|
| 419 |
+
always @(posedge clk or negedge rst) begin
|
| 420 |
+
if(!rst) begin
|
| 421 |
+
Phase4R0r <= 0;
|
| 422 |
+
Phase4R1r <= 0;
|
| 423 |
+
end else begin
|
| 424 |
+
case(Phase4Count)
|
| 425 |
+
3'd2: begin
|
| 426 |
+
//Phase4R0r <= (Phase3Reg[6] + Phase3Reg[5]) * C_181;
|
| 427 |
+
//Phase4R1r <= (Phase3Reg[6] - Phase3Reg[5]) * C_181;
|
| 428 |
+
Phase4R0r <= Phase4R0w * C_181;
|
| 429 |
+
Phase4R1r <= Phase4R1w * C_181;
|
| 430 |
+
end
|
| 431 |
+
endcase
|
| 432 |
+
end
|
| 433 |
+
end
|
| 434 |
+
|
| 435 |
+
//-------------------------------------------------------------------------
|
| 436 |
+
// Phase5
|
| 437 |
+
// R0: B0,B1,B2,B3
|
| 438 |
+
// R1: B7,B6,B5,B4
|
| 439 |
+
//-------------------------------------------------------------------------
|
| 440 |
+
reg Phase5Enable;
|
| 441 |
+
reg [2:0] Phase5Page;
|
| 442 |
+
reg [2:0] Phase5Count;
|
| 443 |
+
reg Phase5EnableD;
|
| 444 |
+
reg [2:0] Phase5PageD;
|
| 445 |
+
reg [2:0] Phase5CountD;
|
| 446 |
+
|
| 447 |
+
always @(posedge clk or negedge rst) begin
|
| 448 |
+
if(!rst) begin
|
| 449 |
+
Phase5Enable <= 1'b0;
|
| 450 |
+
Phase5Page <= 3'd0;
|
| 451 |
+
Phase5Count <= 3'd0;
|
| 452 |
+
Phase5EnableD <= 1'b0;
|
| 453 |
+
Phase5PageD <= 3'd0;
|
| 454 |
+
Phase5CountD <= 3'd0;
|
| 455 |
+
end else begin
|
| 456 |
+
Phase5Enable <= Phase4EnableD;
|
| 457 |
+
Phase5Page <= Phase4PageD;
|
| 458 |
+
Phase5Count <= Phase4CountD;
|
| 459 |
+
Phase5EnableD <= Phase5Enable;
|
| 460 |
+
Phase5PageD <= Phase5Page;
|
| 461 |
+
Phase5CountD <= Phase5Count;
|
| 462 |
+
end
|
| 463 |
+
end
|
| 464 |
+
|
| 465 |
+
wire signed [31:0] Phase5R0w;
|
| 466 |
+
wire signed [31:0] Phase5R1w;
|
| 467 |
+
assign Phase5R0w = (Phase5Count == 3'd0)?Phase3Reg[0]:
|
| 468 |
+
(Phase5Count == 3'd1)?Phase3Reg[1]:
|
| 469 |
+
(Phase5Count == 3'd2)?Phase3Reg[2]:
|
| 470 |
+
(Phase5Count == 3'd3)?Phase3Reg[3]:
|
| 471 |
+
32'd0;
|
| 472 |
+
assign Phase5R1w = (Phase5Count == 3'd0)?Phase3Reg[7]:
|
| 473 |
+
(Phase5Count == 3'd1)?Phase4R0r >> 8:
|
| 474 |
+
(Phase5Count == 3'd2)?Phase4R1r >> 8:
|
| 475 |
+
(Phase5Count == 3'd3)?Phase3Reg[4]:
|
| 476 |
+
32'd0;
|
| 477 |
+
|
| 478 |
+
reg signed [31:0] Phase5R0r;
|
| 479 |
+
reg signed [31:0] Phase5R1r;
|
| 480 |
+
|
| 481 |
+
always @(posedge clk or negedge rst) begin
|
| 482 |
+
if(!rst) begin
|
| 483 |
+
Phase5R0r <= 0;
|
| 484 |
+
Phase5R1r <= 0;
|
| 485 |
+
end else begin
|
| 486 |
+
Phase5R0r <= Phase5R0w + Phase5R1w;
|
| 487 |
+
Phase5R1r <= Phase5R0w - Phase5R1w;
|
| 488 |
+
end
|
| 489 |
+
end
|
| 490 |
+
|
| 491 |
+
assign DataOutEnable = Phase5EnableD == 1'b1 & Phase5CountD[2] == 1'b0;
|
| 492 |
+
assign DataOutPage = Phase5PageD;
|
| 493 |
+
assign DataOutCount = Phase5CountD[1:0];
|
| 494 |
+
|
| 495 |
+
assign Data0Out = Phase5R0r;
|
| 496 |
+
assign Data1Out = Phase5R1r;
|
| 497 |
+
|
| 498 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_idctb.v
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_idctb(
|
| 22 |
+
input clk,
|
| 23 |
+
input rst,
|
| 24 |
+
|
| 25 |
+
input DataInit,
|
| 26 |
+
|
| 27 |
+
input DataInEnable,
|
| 28 |
+
input [2:0] DataInPage,
|
| 29 |
+
input [1:0] DataInCount,
|
| 30 |
+
output DataInIdle,
|
| 31 |
+
input [15:0] DataInA,
|
| 32 |
+
input [15:0] DataInB,
|
| 33 |
+
|
| 34 |
+
output DataOutEnable,
|
| 35 |
+
input DataOutRead,
|
| 36 |
+
input [4:0] DataOutAddress,
|
| 37 |
+
output [15:0] DataOutA,
|
| 38 |
+
output [15:0] DataOutB
|
| 39 |
+
);
|
| 40 |
+
wire [4:0] DataInAddress;
|
| 41 |
+
reg [1:0] WriteBank, ReadBank;
|
| 42 |
+
|
| 43 |
+
assign DataInAddress = {DataInPage, DataInCount};
|
| 44 |
+
|
| 45 |
+
// Bank
|
| 46 |
+
always @(posedge clk or negedge rst) begin
|
| 47 |
+
if(!rst) begin
|
| 48 |
+
WriteBank <= 2'd0;
|
| 49 |
+
ReadBank <= 2'd0;
|
| 50 |
+
end else begin
|
| 51 |
+
if(DataInit) begin
|
| 52 |
+
WriteBank <= 2'd0;
|
| 53 |
+
end else if(DataInEnable && (DataInAddress == 5'h1F)) begin
|
| 54 |
+
WriteBank <= WriteBank + 2'd1;
|
| 55 |
+
end
|
| 56 |
+
if(DataInit) begin
|
| 57 |
+
ReadBank <= 2'd0;
|
| 58 |
+
end else if(DataOutRead && (DataOutAddress == 5'h1F)) begin
|
| 59 |
+
ReadBank <= ReadBank + 2'd1;
|
| 60 |
+
end
|
| 61 |
+
end
|
| 62 |
+
end
|
| 63 |
+
|
| 64 |
+
wire [5:0] WriteQueryA, WriteQueryB;
|
| 65 |
+
|
| 66 |
+
// Make a Write Address
|
| 67 |
+
function [5:0] F_WriteQueryA;
|
| 68 |
+
input [4:0] Count;
|
| 69 |
+
case(Count)
|
| 70 |
+
5'd0: F_WriteQueryA = {1'd0, 5'd0}; // 0
|
| 71 |
+
5'd1: F_WriteQueryA = {1'd0, 5'd4}; // 1
|
| 72 |
+
5'd2: F_WriteQueryA = {1'd0, 5'd8}; // 2
|
| 73 |
+
5'd3: F_WriteQueryA = {1'd0, 5'd12}; // 3
|
| 74 |
+
5'd4: F_WriteQueryA = {1'd0, 5'd2}; // 8
|
| 75 |
+
5'd5: F_WriteQueryA = {1'd0, 5'd6}; // 9
|
| 76 |
+
5'd6: F_WriteQueryA = {1'd0, 5'd10}; // 10
|
| 77 |
+
5'd7: F_WriteQueryA = {1'd0, 5'd14}; // 11
|
| 78 |
+
5'd8: F_WriteQueryA = {1'd0, 5'd1}; // 16
|
| 79 |
+
5'd9: F_WriteQueryA = {1'd0, 5'd5}; // 17
|
| 80 |
+
5'd10: F_WriteQueryA = {1'd0, 5'd9}; // 18
|
| 81 |
+
5'd11: F_WriteQueryA = {1'd0, 5'd13}; // 19
|
| 82 |
+
5'd12: F_WriteQueryA = {1'd1, 5'd3}; // 24
|
| 83 |
+
5'd13: F_WriteQueryA = {1'd1, 5'd7}; // 25
|
| 84 |
+
5'd14: F_WriteQueryA = {1'd1, 5'd11}; // 26
|
| 85 |
+
5'd15: F_WriteQueryA = {1'd1, 5'd15}; // 27
|
| 86 |
+
5'd16: F_WriteQueryA = {1'd1, 5'd0}; // 32
|
| 87 |
+
5'd17: F_WriteQueryA = {1'd1, 5'd4}; // 33
|
| 88 |
+
5'd18: F_WriteQueryA = {1'd1, 5'd8}; // 34
|
| 89 |
+
5'd19: F_WriteQueryA = {1'd1, 5'd12}; // 35
|
| 90 |
+
5'd20: F_WriteQueryA = {1'd0, 5'd3}; // 40
|
| 91 |
+
5'd21: F_WriteQueryA = {1'd0, 5'd7}; // 41
|
| 92 |
+
5'd22: F_WriteQueryA = {1'd0, 5'd11}; // 42
|
| 93 |
+
5'd23: F_WriteQueryA = {1'd0, 5'd15}; // 43
|
| 94 |
+
5'd24: F_WriteQueryA = {1'd1, 5'd1}; // 48
|
| 95 |
+
5'd25: F_WriteQueryA = {1'd1, 5'd5}; // 49
|
| 96 |
+
5'd26: F_WriteQueryA = {1'd1, 5'd9}; // 50
|
| 97 |
+
5'd27: F_WriteQueryA = {1'd1, 5'd13}; // 51
|
| 98 |
+
5'd28: F_WriteQueryA = {1'd1, 5'd2}; // 56
|
| 99 |
+
5'd29: F_WriteQueryA = {1'd1, 5'd6}; // 57
|
| 100 |
+
5'd30: F_WriteQueryA = {1'd1, 5'd10}; // 58
|
| 101 |
+
5'd31: F_WriteQueryA = {1'd1, 5'd14}; // 59
|
| 102 |
+
endcase
|
| 103 |
+
endfunction
|
| 104 |
+
|
| 105 |
+
function [5:0] F_WriteQueryB;
|
| 106 |
+
input [4:0] Count;
|
| 107 |
+
case(Count)
|
| 108 |
+
5'd0: F_WriteQueryB = {1'd1, 5'd28}; // 7
|
| 109 |
+
5'd1: F_WriteQueryB = {1'd1, 5'd24}; // 6
|
| 110 |
+
5'd2: F_WriteQueryB = {1'd1, 5'd20}; // 5
|
| 111 |
+
5'd3: F_WriteQueryB = {1'd1, 5'd16}; // 4
|
| 112 |
+
5'd4: F_WriteQueryB = {1'd1, 5'd30}; // 15
|
| 113 |
+
5'd5: F_WriteQueryB = {1'd1, 5'd26}; // 14
|
| 114 |
+
5'd6: F_WriteQueryB = {1'd1, 5'd22}; // 13
|
| 115 |
+
5'd7: F_WriteQueryB = {1'd1, 5'd18}; // 12
|
| 116 |
+
5'd8: F_WriteQueryB = {1'd1, 5'd29}; // 23
|
| 117 |
+
5'd9: F_WriteQueryB = {1'd1, 5'd25}; // 22
|
| 118 |
+
5'd10: F_WriteQueryB = {1'd1, 5'd21}; // 21
|
| 119 |
+
5'd11: F_WriteQueryB = {1'd1, 5'd17}; // 20
|
| 120 |
+
5'd12: F_WriteQueryB = {1'd0, 5'd31}; // 31
|
| 121 |
+
5'd13: F_WriteQueryB = {1'd0, 5'd27}; // 30
|
| 122 |
+
5'd14: F_WriteQueryB = {1'd0, 5'd23}; // 29
|
| 123 |
+
5'd15: F_WriteQueryB = {1'd0, 5'd19}; // 28
|
| 124 |
+
5'd16: F_WriteQueryB = {1'd0, 5'd28}; // 39
|
| 125 |
+
5'd17: F_WriteQueryB = {1'd0, 5'd24}; // 38
|
| 126 |
+
5'd18: F_WriteQueryB = {1'd0, 5'd20}; // 37
|
| 127 |
+
5'd19: F_WriteQueryB = {1'd0, 5'd16}; // 36
|
| 128 |
+
5'd20: F_WriteQueryB = {1'd1, 5'd31}; // 47
|
| 129 |
+
5'd21: F_WriteQueryB = {1'd1, 5'd27}; // 46
|
| 130 |
+
5'd22: F_WriteQueryB = {1'd1, 5'd23}; // 45
|
| 131 |
+
5'd23: F_WriteQueryB = {1'd1, 5'd19}; // 44
|
| 132 |
+
5'd24: F_WriteQueryB = {1'd0, 5'd29}; // 55
|
| 133 |
+
5'd25: F_WriteQueryB = {1'd0, 5'd25}; // 54
|
| 134 |
+
5'd26: F_WriteQueryB = {1'd0, 5'd21}; // 53
|
| 135 |
+
5'd27: F_WriteQueryB = {1'd0, 5'd17}; // 52
|
| 136 |
+
5'd28: F_WriteQueryB = {1'd0, 5'd30}; // 63
|
| 137 |
+
5'd29: F_WriteQueryB = {1'd0, 5'd26}; // 62
|
| 138 |
+
5'd30: F_WriteQueryB = {1'd0, 5'd22}; // 61
|
| 139 |
+
5'd31: F_WriteQueryB = {1'd0, 5'd18}; // 60
|
| 140 |
+
endcase
|
| 141 |
+
endfunction
|
| 142 |
+
|
| 143 |
+
assign WriteQueryA = F_WriteQueryA(DataInAddress);
|
| 144 |
+
assign WriteQueryB = F_WriteQueryB(DataInAddress);
|
| 145 |
+
|
| 146 |
+
// RAM(16bit x 32word x 2Bank)
|
| 147 |
+
reg [15:0] MemoryA [0:127];
|
| 148 |
+
reg [15:0] MemoryB [0:127];
|
| 149 |
+
|
| 150 |
+
wire [6:0] WriteAddressA, WriteAddressB;
|
| 151 |
+
wire [15:0] WriteDataA, WriteDataB;
|
| 152 |
+
|
| 153 |
+
assign WriteAddressA = {WriteBank, (WriteQueryA[5])?WriteQueryB[4:0]:WriteQueryA[4:0]};
|
| 154 |
+
assign WriteAddressB = {WriteBank, (WriteQueryB[5])?WriteQueryB[4:0]:WriteQueryA[4:0]};
|
| 155 |
+
|
| 156 |
+
assign WriteDataA = (WriteQueryA[5])?DataInB:DataInA;
|
| 157 |
+
assign WriteDataB = (WriteQueryB[5])?DataInB:DataInA;
|
| 158 |
+
|
| 159 |
+
// Port A(Write Only)
|
| 160 |
+
always @(posedge clk) begin
|
| 161 |
+
if(DataInEnable) MemoryA[WriteAddressA] <= WriteDataA;
|
| 162 |
+
if(DataInEnable) MemoryB[WriteAddressB] <= WriteDataB;
|
| 163 |
+
end
|
| 164 |
+
|
| 165 |
+
reg [15:0] RegMemoryA, RegMemoryB;
|
| 166 |
+
|
| 167 |
+
// Port B(Read/Wirte)
|
| 168 |
+
always @(posedge clk) begin
|
| 169 |
+
RegMemoryA <= MemoryA[{ReadBank, DataOutAddress}];
|
| 170 |
+
RegMemoryB <= MemoryB[{ReadBank, DataOutAddress}];
|
| 171 |
+
end
|
| 172 |
+
|
| 173 |
+
assign DataOutEnable = (WriteBank != ReadBank);
|
| 174 |
+
assign DataOutA = (DataOutAddress[4])?RegMemoryB:RegMemoryA;
|
| 175 |
+
assign DataOutB = (DataOutAddress[4])?RegMemoryA:RegMemoryB;
|
| 176 |
+
|
| 177 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_dj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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_regdata(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
|
| 25 |
+
// Read Data
|
| 26 |
+
input [31:0] DataIn,
|
| 27 |
+
input DataInEnable, // Data Enable
|
| 28 |
+
output DataInRead, // Data Read
|
| 29 |
+
|
| 30 |
+
// DataOut
|
| 31 |
+
output [31:0] DataOut, // Data Out
|
| 32 |
+
output DataOutEnable, // Data Out Enable
|
| 33 |
+
|
| 34 |
+
input ImageEnable,
|
| 35 |
+
input ProcessIdle,
|
| 36 |
+
|
| 37 |
+
// UseData
|
| 38 |
+
input UseBit, // Used data bit
|
| 39 |
+
input [6:0] UseWidth, // Used data bit width
|
| 40 |
+
input UseByte, // Used data byte
|
| 41 |
+
input UseWord // Used data word
|
| 42 |
+
);
|
| 43 |
+
wire RegValid;
|
| 44 |
+
reg [95:0] RegData;
|
| 45 |
+
reg [6:0] RegWidth;
|
| 46 |
+
reg CheckMode;
|
| 47 |
+
reg DataEnd;
|
| 48 |
+
|
| 49 |
+
wire PreImageEnable;
|
| 50 |
+
reg ImageReady;
|
| 51 |
+
|
| 52 |
+
// assign RegValid = (ImageEnable)?(RegWidth > 7'd64):(RegWidth > 7'd32);
|
| 53 |
+
assign RegValid = (ImageReady)?(RegWidth > 7'd64):(RegWidth > 7'd32);
|
| 54 |
+
assign DataInRead = ((RegValid == 1'b0) & (DataInEnable == 1'b1) & (DataEnd == 1'b0));
|
| 55 |
+
|
| 56 |
+
assign PreImageEnable = ((ImageEnable == 1'b1) && (ImageReady == 1'b0))?1'b1:1'b0;
|
| 57 |
+
|
| 58 |
+
always @(posedge clk or negedge rst) begin
|
| 59 |
+
if(!rst) begin
|
| 60 |
+
RegData <= 96'd0;
|
| 61 |
+
RegWidth <= 7'd0;
|
| 62 |
+
CheckMode <= 1'b0;
|
| 63 |
+
ImageReady <= 1'b0;
|
| 64 |
+
end else begin
|
| 65 |
+
if(DataEnd == 1'b1 & ProcessIdle == 1'b1) begin
|
| 66 |
+
RegData <= 96'd0;
|
| 67 |
+
RegWidth <= 7'd0;
|
| 68 |
+
CheckMode <= 1'b0;
|
| 69 |
+
ImageReady <= 1'b0;
|
| 70 |
+
end else if(RegValid == 1'b0 & (DataInEnable == 1'b1 | DataEnd == 1'b1)) begin
|
| 71 |
+
if(ImageReady == 1'b1) begin
|
| 72 |
+
if(RegData[39: 8] == 32'hFF00FF00 & CheckMode != 1'b1) begin
|
| 73 |
+
RegWidth <= RegWidth + 7'd16;
|
| 74 |
+
RegData[95:64] <= {8'h00,RegData[71:48]};
|
| 75 |
+
RegData[63:32] <= {RegData[47:40],16'hFFFF,RegData[7:0]};
|
| 76 |
+
CheckMode <= 1'b0;
|
| 77 |
+
end else if(RegData[39:24] == 16'hFF00 & RegData[15: 0] == 16'hFF00 & CheckMode != 1'b1) begin
|
| 78 |
+
RegWidth <= RegWidth + 7'd16;
|
| 79 |
+
RegData[95:64] <= {8'h00,RegData[71:48]};
|
| 80 |
+
RegData[63:32] <= {RegData[47:40],8'hFF,RegData[23:16],8'hFF};
|
| 81 |
+
CheckMode <= 1'b1;
|
| 82 |
+
end else if(RegData[31: 0] == 32'hFF00FF00) begin
|
| 83 |
+
RegWidth <= RegWidth + 7'd16;
|
| 84 |
+
RegData[95:64] <= {16'h0000,RegData[63:48]};
|
| 85 |
+
RegData[63:32] <= {RegData[47:32],16'hFFFF};
|
| 86 |
+
CheckMode <= 1'b1;
|
| 87 |
+
end else if(RegData[39:24] == 16'hFF00 & CheckMode != 1'b1) begin
|
| 88 |
+
RegWidth <= RegWidth + 7'd24;
|
| 89 |
+
RegData[95:64] <= {RegData[71:40]};
|
| 90 |
+
RegData[63:32] <= {8'hFF,RegData[23:0]};
|
| 91 |
+
CheckMode <= 1'b0;
|
| 92 |
+
end else if(RegData[31:16] == 16'hFF00) begin
|
| 93 |
+
RegWidth <= RegWidth + 7'd24;
|
| 94 |
+
RegData[95:64] <= {RegData[71:40]};
|
| 95 |
+
RegData[63:32] <= {RegData[39:32],8'hFF,RegData[15:0]};
|
| 96 |
+
CheckMode <= 1'b0;
|
| 97 |
+
end else if(RegData[23: 8] == 16'hFF00) begin
|
| 98 |
+
RegWidth <= RegWidth + 7'd24;
|
| 99 |
+
RegData[95:64] <= {RegData[71:40]};
|
| 100 |
+
RegData[63:32] <= {RegData[39:32],RegData[31:24],8'hFF,RegData[7:0]};
|
| 101 |
+
CheckMode <= 1'b0;
|
| 102 |
+
end else if(RegData[15: 0] == 16'hFF00) begin
|
| 103 |
+
RegWidth <= RegWidth + 7'd24;
|
| 104 |
+
RegData[95:64] <= {RegData[71:40]};
|
| 105 |
+
RegData[63:32] <= {RegData[39:32],RegData[31:16],8'hFF};
|
| 106 |
+
CheckMode <= 1'b1;
|
| 107 |
+
end else begin
|
| 108 |
+
RegWidth <= RegWidth + 7'd32;
|
| 109 |
+
RegData[95:64] <= RegData[63:32];
|
| 110 |
+
RegData[63:32] <= RegData[31:0];
|
| 111 |
+
CheckMode <= 1'b0;
|
| 112 |
+
end
|
| 113 |
+
end else begin
|
| 114 |
+
RegWidth <= RegWidth + 7'd32;
|
| 115 |
+
RegData[95:64] <= RegData[63:32];
|
| 116 |
+
RegData[63:32] <= RegData[31:0];
|
| 117 |
+
CheckMode <= 1'b0;
|
| 118 |
+
end
|
| 119 |
+
RegData[31: 0] <= {DataIn[7:0],DataIn[15:8],DataIn[23:16],DataIn[31:24]};
|
| 120 |
+
end else if(PreImageEnable == 1'b1) begin
|
| 121 |
+
if((RegData[63:32] == 32'hFF00FF00) && (RegWidth == 7'd64)) begin
|
| 122 |
+
RegWidth <= 7'd48;
|
| 123 |
+
RegData[63:32] <= {32'h0000FFFF};
|
| 124 |
+
CheckMode <= 1'b1;
|
| 125 |
+
end else if ((RegData[63:48] == 16'hFF00) && (RegWidth == 7'd64)) begin
|
| 126 |
+
RegWidth <= 7'd56;
|
| 127 |
+
RegData[63:32] <= {16'h00FF, RegData[47:32]};
|
| 128 |
+
CheckMode <= 1'b0;
|
| 129 |
+
end else if ((RegData[55:40] == 16'hFF00) && (RegWidth == 7'd64)) begin
|
| 130 |
+
RegWidth <= 7'd56;
|
| 131 |
+
RegData[63:32] <= {8'h00,RegData[63:56],8'hFF,RegData[39:32]};
|
| 132 |
+
CheckMode <= 1'b0;
|
| 133 |
+
end else if ((RegData[47:32] == 16'hFF00) && (RegWidth == 7'd64)) begin
|
| 134 |
+
RegWidth <= 7'd56;
|
| 135 |
+
RegData[63:32] <= {8'h00,RegData[55:48],8'hFF};
|
| 136 |
+
CheckMode <= 1'b1;
|
| 137 |
+
end else if ((RegData[55:40] == 16'hFF00) && (RegWidth == 7'd56)) begin
|
| 138 |
+
RegWidth <= 7'd48;
|
| 139 |
+
RegData[63:32] <= {24'h0000FF, RegData[39:32]};
|
| 140 |
+
CheckMode <= 1'b0;
|
| 141 |
+
end else if ((RegData[47:32] == 16'hFF00) && (RegWidth == 7'd56)) begin
|
| 142 |
+
RegWidth <= 7'd48;
|
| 143 |
+
RegData[63:32] <= {16'h0000, RegData[55:48],8'hFF};
|
| 144 |
+
CheckMode <= 1'b1;
|
| 145 |
+
end else if ((RegData[47:32] == 16'hFF00) && (RegWidth == 7'd48)) begin
|
| 146 |
+
RegWidth <= 7'd40;
|
| 147 |
+
RegData[63:32] <= {24'h000000FF};
|
| 148 |
+
CheckMode <= 1'b1;
|
| 149 |
+
end
|
| 150 |
+
ImageReady <= 1'b1;
|
| 151 |
+
end else if(UseBit == 1'b1) begin
|
| 152 |
+
RegWidth <= RegWidth - UseWidth;
|
| 153 |
+
end else if(UseByte == 1'b1) begin
|
| 154 |
+
RegWidth <= RegWidth - 7'd8;
|
| 155 |
+
end else if(UseWord == 1'b1) begin
|
| 156 |
+
RegWidth <= RegWidth - 7'd16;
|
| 157 |
+
end
|
| 158 |
+
end
|
| 159 |
+
end
|
| 160 |
+
|
| 161 |
+
// PickUp with End of Jpeg Data
|
| 162 |
+
always @(posedge clk or negedge rst) begin
|
| 163 |
+
if(!rst) begin
|
| 164 |
+
DataEnd <= 1'b0;
|
| 165 |
+
end else begin
|
| 166 |
+
if(ProcessIdle) begin
|
| 167 |
+
DataEnd <= 1'b0;
|
| 168 |
+
end else if(ImageEnable == 1'b1 & ((RegData[39:24] == 16'hFFD9 & CheckMode != 1'b1) | RegData[31:16] == 16'hFFD9 | RegData[23: 8] == 16'hFFD9 | RegData[15: 0] == 16'hFFD9)) begin
|
| 169 |
+
DataEnd <= 1'b1;
|
| 170 |
+
end
|
| 171 |
+
end
|
| 172 |
+
end
|
| 173 |
+
|
| 174 |
+
function [31:0] SliceData;
|
| 175 |
+
input [95:0] RegData;
|
| 176 |
+
input [7:0] RegWidth;
|
| 177 |
+
|
| 178 |
+
case(RegWidth)
|
| 179 |
+
//8'd33: SliceData = RegData[32: 1];
|
| 180 |
+
//8'd34: SliceData = RegData[33: 2];
|
| 181 |
+
//8'd35: SliceData = RegData[34: 3];
|
| 182 |
+
//8'd36: SliceData = RegData[35: 4];
|
| 183 |
+
//8'd37: SliceData = RegData[36: 5];
|
| 184 |
+
//8'd38: SliceData = RegData[37: 6];
|
| 185 |
+
//8'd39: SliceData = RegData[38: 7];
|
| 186 |
+
8'd40: SliceData = RegData[39: 8];
|
| 187 |
+
//8'd41: SliceData = RegData[40: 9];
|
| 188 |
+
//8'd42: SliceData = RegData[41:10];
|
| 189 |
+
//8'd43: SliceData = RegData[42:11];
|
| 190 |
+
//8'd44: SliceData = RegData[43:12];
|
| 191 |
+
//8'd45: SliceData = RegData[44:13];
|
| 192 |
+
//8'd46: SliceData = RegData[45:14];
|
| 193 |
+
//8'd47: SliceData = RegData[46:15];
|
| 194 |
+
8'd48: SliceData = RegData[47:16];
|
| 195 |
+
//8'd49: SliceData = RegData[48:17];
|
| 196 |
+
//8'd50: SliceData = RegData[49:18];
|
| 197 |
+
//8'd51: SliceData = RegData[50:19];
|
| 198 |
+
//8'd52: SliceData = RegData[51:20];
|
| 199 |
+
//8'd53: SliceData = RegData[52:21];
|
| 200 |
+
//8'd54: SliceData = RegData[53:22];
|
| 201 |
+
//8'd55: SliceData = RegData[54:23];
|
| 202 |
+
8'd56: SliceData = RegData[55:24];
|
| 203 |
+
//8'd57: SliceData = RegData[56:25];
|
| 204 |
+
//8'd58: SliceData = RegData[57:26];
|
| 205 |
+
//8'd59: SliceData = RegData[58:27];
|
| 206 |
+
//8'd60: SliceData = RegData[59:28];
|
| 207 |
+
//8'd61: SliceData = RegData[60:29];
|
| 208 |
+
//8'd62: SliceData = RegData[61:30];
|
| 209 |
+
//8'd63: SliceData = RegData[62:31];
|
| 210 |
+
8'd64: SliceData = RegData[63:32];
|
| 211 |
+
8'd65: SliceData = RegData[64:33];
|
| 212 |
+
8'd66: SliceData = RegData[65:34];
|
| 213 |
+
8'd67: SliceData = RegData[66:35];
|
| 214 |
+
8'd68: SliceData = RegData[67:36];
|
| 215 |
+
8'd69: SliceData = RegData[68:37];
|
| 216 |
+
8'd70: SliceData = RegData[69:38];
|
| 217 |
+
8'd71: SliceData = RegData[70:39];
|
| 218 |
+
8'd72: SliceData = RegData[71:40];
|
| 219 |
+
8'd73: SliceData = RegData[72:41];
|
| 220 |
+
8'd74: SliceData = RegData[73:42];
|
| 221 |
+
8'd75: SliceData = RegData[74:43];
|
| 222 |
+
8'd76: SliceData = RegData[75:44];
|
| 223 |
+
8'd77: SliceData = RegData[76:45];
|
| 224 |
+
8'd78: SliceData = RegData[77:46];
|
| 225 |
+
8'd79: SliceData = RegData[78:47];
|
| 226 |
+
8'd80: SliceData = RegData[79:48];
|
| 227 |
+
8'd81: SliceData = RegData[80:49];
|
| 228 |
+
8'd82: SliceData = RegData[81:50];
|
| 229 |
+
8'd83: SliceData = RegData[82:51];
|
| 230 |
+
8'd84: SliceData = RegData[83:52];
|
| 231 |
+
8'd85: SliceData = RegData[84:53];
|
| 232 |
+
8'd86: SliceData = RegData[85:54];
|
| 233 |
+
8'd87: SliceData = RegData[86:55];
|
| 234 |
+
8'd88: SliceData = RegData[87:56];
|
| 235 |
+
8'd89: SliceData = RegData[88:57];
|
| 236 |
+
8'd90: SliceData = RegData[89:58];
|
| 237 |
+
8'd91: SliceData = RegData[90:59];
|
| 238 |
+
8'd92: SliceData = RegData[91:60];
|
| 239 |
+
8'd93: SliceData = RegData[92:61];
|
| 240 |
+
8'd94: SliceData = RegData[93:62];
|
| 241 |
+
8'd95: SliceData = RegData[94:63];
|
| 242 |
+
8'd96: SliceData = RegData[95:64];
|
| 243 |
+
default: SliceData = 32'h00000000;
|
| 244 |
+
endcase
|
| 245 |
+
endfunction
|
| 246 |
+
|
| 247 |
+
reg OutEnable;
|
| 248 |
+
reg PreEnable;
|
| 249 |
+
reg [31:0] DataOut;
|
| 250 |
+
|
| 251 |
+
always @(posedge clk or negedge rst) begin
|
| 252 |
+
if(!rst) begin
|
| 253 |
+
OutEnable <= 1'b0;
|
| 254 |
+
PreEnable <= 1'b0;
|
| 255 |
+
DataOut <= 32'h00000000;
|
| 256 |
+
end else begin
|
| 257 |
+
if(DataEnd == 1'b1 & ProcessIdle == 1'b1) begin
|
| 258 |
+
OutEnable <= 1'b0;
|
| 259 |
+
PreEnable <= 1'b0;
|
| 260 |
+
DataOut <= 32'h00000000;
|
| 261 |
+
end else begin
|
| 262 |
+
OutEnable <= RegValid;
|
| 263 |
+
PreEnable <= (UseBit == 1'b1 | UseByte == 1'b1 | UseWord == 1'b1);
|
| 264 |
+
DataOut <= SliceData(RegData,RegWidth);
|
| 265 |
+
end
|
| 266 |
+
end
|
| 267 |
+
end
|
| 268 |
+
|
| 269 |
+
assign DataOutEnable = (PreEnable == 1'b0)?OutEnable:1'b0;
|
| 270 |
+
|
| 271 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_ycbcr.v
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_ycbcr(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
|
| 25 |
+
input ProcessInit,
|
| 26 |
+
input [2:0] JpegComp,
|
| 27 |
+
|
| 28 |
+
input DataInEnable,
|
| 29 |
+
input [2:0] DataInPage,
|
| 30 |
+
input [1:0] DataInCount,
|
| 31 |
+
output DataInIdle,
|
| 32 |
+
input [8:0] Data0In,
|
| 33 |
+
input [8:0] Data1In,
|
| 34 |
+
input [11:0] DataInBlockWidth,
|
| 35 |
+
output DataInFull,
|
| 36 |
+
|
| 37 |
+
output OutEnable,
|
| 38 |
+
output [15:0] OutPixelX,
|
| 39 |
+
output [15:0] OutPixelY,
|
| 40 |
+
output [7:0] OutR,
|
| 41 |
+
output [7:0] OutG,
|
| 42 |
+
output [7:0] OutB
|
| 43 |
+
);
|
| 44 |
+
reg [2:0] DataInColor;
|
| 45 |
+
reg [11:0] DataInBlockX;
|
| 46 |
+
reg [11:0] DataInBlockY;
|
| 47 |
+
|
| 48 |
+
wire ConvertEnable;
|
| 49 |
+
wire ConvertRead;
|
| 50 |
+
wire ConvertBank;
|
| 51 |
+
wire [7:0] ConvertAddress;
|
| 52 |
+
wire [8:0] DataY;
|
| 53 |
+
wire [8:0] DataCb;
|
| 54 |
+
wire [8:0] DataCr;
|
| 55 |
+
wire [11:0] ConvertBlockX;
|
| 56 |
+
wire [11:0] ConvertBlockY;
|
| 57 |
+
|
| 58 |
+
always @(posedge clk or negedge rst) begin
|
| 59 |
+
if(!rst) begin
|
| 60 |
+
DataInColor <= 3'd0;
|
| 61 |
+
end else begin
|
| 62 |
+
if(ProcessInit) begin
|
| 63 |
+
DataInColor <= 3'd0;
|
| 64 |
+
end else if((DataInEnable == 1'b1) && (DataInPage == 3'd7) && (DataInCount == 2'd3)) begin
|
| 65 |
+
// コンポーネント数が3ならYCbCrで411
|
| 66 |
+
// コンポーネント数が1ならグレースケールで400
|
| 67 |
+
if( ((JpegComp == 3) && (DataInColor == 3'd5)) ||
|
| 68 |
+
((JpegComp == 1) && (DataInColor == 3'd3))) begin
|
| 69 |
+
// if(DataInColor == 3'd5) begin
|
| 70 |
+
DataInColor <= 3'd0;
|
| 71 |
+
end else begin
|
| 72 |
+
DataInColor <= DataInColor + 3'd1;
|
| 73 |
+
end
|
| 74 |
+
end
|
| 75 |
+
end
|
| 76 |
+
end
|
| 77 |
+
|
| 78 |
+
//------------------------------------------------------------------------
|
| 79 |
+
// YCbCr Memory
|
| 80 |
+
//------------------------------------------------------------------------
|
| 81 |
+
aq_djpeg_ycbcr_mem u_jpeg_ycbcr_mem(
|
| 82 |
+
.rst ( rst ),
|
| 83 |
+
.clk ( clk ),
|
| 84 |
+
|
| 85 |
+
.DataInit ( ProcessInit ),
|
| 86 |
+
.JpegComp ( JpegComp ),
|
| 87 |
+
|
| 88 |
+
.DataInEnable ( DataInEnable ),
|
| 89 |
+
.DataInColor ( DataInColor ),
|
| 90 |
+
.DataInPage ( DataInPage ),
|
| 91 |
+
.DataInCount ( DataInCount ),
|
| 92 |
+
.Data0In ( Data0In ),
|
| 93 |
+
.Data1In ( Data1In ),
|
| 94 |
+
.DataInFull ( DataInFull ),
|
| 95 |
+
|
| 96 |
+
.DataOutEnable ( ConvertEnable ),
|
| 97 |
+
.DataOutAddress ( ConvertAddress ),
|
| 98 |
+
.DataOutRead ( ConvertRead ),
|
| 99 |
+
.DataOutY ( DataY ),
|
| 100 |
+
.DataOutCb ( DataCb ),
|
| 101 |
+
.DataOutCr ( DataCr )
|
| 102 |
+
);
|
| 103 |
+
//------------------------------------------------------------------------
|
| 104 |
+
// YCbCr to RGB
|
| 105 |
+
//------------------------------------------------------------------------
|
| 106 |
+
always @(posedge clk or negedge rst) begin
|
| 107 |
+
if(!rst) begin
|
| 108 |
+
DataInBlockX <= 12'd0;
|
| 109 |
+
DataInBlockY <= 12'd0;
|
| 110 |
+
end else begin
|
| 111 |
+
if(ProcessInit) begin
|
| 112 |
+
DataInBlockX <= 12'd0;
|
| 113 |
+
DataInBlockY <= 12'd0;
|
| 114 |
+
end else if((ConvertRead == 1'b1) && (ConvertAddress == 8'd255)) begin
|
| 115 |
+
// if(JpegComp == 3) begin
|
| 116 |
+
if(DataInBlockWidth == DataInBlockX +1) begin
|
| 117 |
+
DataInBlockX <= 12'd0;
|
| 118 |
+
DataInBlockY <= DataInBlockY + 12'd1;
|
| 119 |
+
end else begin
|
| 120 |
+
DataInBlockX <= DataInBlockX + 12'd1;
|
| 121 |
+
end
|
| 122 |
+
// end else begin
|
| 123 |
+
// if(DataInBlockWidth == DataInBlockX +3) begin
|
| 124 |
+
// DataInBlockX <= 12'd0;
|
| 125 |
+
// DataInBlockY <= DataInBlockY + 12'd1;
|
| 126 |
+
// end else begin
|
| 127 |
+
// DataInBlockX <= DataInBlockX + 12'd1;
|
| 128 |
+
// end
|
| 129 |
+
// end
|
| 130 |
+
end
|
| 131 |
+
end
|
| 132 |
+
end
|
| 133 |
+
|
| 134 |
+
wire [8:0] tDataCb,tDataCr;
|
| 135 |
+
assign tDataCb = (JpegComp == 1)?9'd0:DataCb;
|
| 136 |
+
assign tDataCr = (JpegComp == 1)?9'd0:DataCr;
|
| 137 |
+
|
| 138 |
+
aq_djpeg_ycbcr2rgb u_jpeg_yccr2rgb(
|
| 139 |
+
.rst ( rst ),
|
| 140 |
+
.clk ( clk ),
|
| 141 |
+
|
| 142 |
+
.InEnable ( ConvertEnable ),
|
| 143 |
+
.InRead ( ConvertRead ),
|
| 144 |
+
.InBlockX ( DataInBlockX ),
|
| 145 |
+
.InBlockY ( DataInBlockY ),
|
| 146 |
+
.InComp ( JpegComp ),
|
| 147 |
+
.InAddress ( ConvertAddress ),
|
| 148 |
+
.InY ( DataY ),
|
| 149 |
+
.InCb ( tDataCb ),
|
| 150 |
+
.InCr ( tDataCr ),
|
| 151 |
+
|
| 152 |
+
.OutEnable ( OutEnable ),
|
| 153 |
+
.OutPixelX ( OutPixelX ),
|
| 154 |
+
.OutPixelY ( OutPixelY ),
|
| 155 |
+
.OutR ( OutR ),
|
| 156 |
+
.OutG ( OutG ),
|
| 157 |
+
.OutB ( OutB )
|
| 158 |
+
);
|
| 159 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_ycbcr2rgb.v
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
//----------------------------------------------------------------------------
|
| 22 |
+
// JPEG YCbCr -> RGB Conveter
|
| 23 |
+
//----------------------------------------------------------------------------
|
| 24 |
+
module aq_djpeg_ycbcr2rgb(
|
| 25 |
+
input clk,
|
| 26 |
+
input rst,
|
| 27 |
+
|
| 28 |
+
input InEnable,
|
| 29 |
+
output InRead,
|
| 30 |
+
input [11:0] InBlockX,
|
| 31 |
+
input [11:0] InBlockY,
|
| 32 |
+
input [2:0] InComp,
|
| 33 |
+
output [7:0] InAddress,
|
| 34 |
+
input [8:0] InY,
|
| 35 |
+
input [8:0] InCb,
|
| 36 |
+
input [8:0] InCr,
|
| 37 |
+
|
| 38 |
+
output OutEnable,
|
| 39 |
+
output [15:0] OutPixelX,
|
| 40 |
+
output [15:0] OutPixelY,
|
| 41 |
+
output [7:0] OutR,
|
| 42 |
+
output [7:0] OutG,
|
| 43 |
+
output [7:0] OutB
|
| 44 |
+
);
|
| 45 |
+
reg RunActive;
|
| 46 |
+
reg [7:0] RunCount;
|
| 47 |
+
reg [11:0] RunBlockX;
|
| 48 |
+
reg [11:0] RunBlockY;
|
| 49 |
+
reg [2:0] RunComp;
|
| 50 |
+
|
| 51 |
+
always @(posedge clk or negedge rst) begin
|
| 52 |
+
if(!rst) begin
|
| 53 |
+
RunActive <= 1'b0;
|
| 54 |
+
RunCount <= 8'h00;
|
| 55 |
+
RunBlockX <= 12'h000;
|
| 56 |
+
RunBlockY <= 12'h000;
|
| 57 |
+
RunComp <= 1'b0;
|
| 58 |
+
end else begin
|
| 59 |
+
if(RunActive == 1'b0) begin
|
| 60 |
+
if(InEnable == 1'b1) begin
|
| 61 |
+
RunActive <= 1'b1;
|
| 62 |
+
RunBlockX <= InBlockX;
|
| 63 |
+
RunBlockY <= InBlockY;
|
| 64 |
+
RunComp <= InComp;
|
| 65 |
+
end
|
| 66 |
+
RunCount <= 8'h00;
|
| 67 |
+
end else begin
|
| 68 |
+
if(RunCount == 8'd255) begin
|
| 69 |
+
RunActive <= 1'b0;
|
| 70 |
+
RunCount <= 8'd0;
|
| 71 |
+
end else begin
|
| 72 |
+
RunCount <= RunCount +8'd1;
|
| 73 |
+
end
|
| 74 |
+
end
|
| 75 |
+
end
|
| 76 |
+
end
|
| 77 |
+
|
| 78 |
+
assign InRead = RunActive;
|
| 79 |
+
assign InAddress = RunCount;
|
| 80 |
+
|
| 81 |
+
reg PreEnable;
|
| 82 |
+
reg [15:0] PreCountX;
|
| 83 |
+
reg [15:0] PreCountY;
|
| 84 |
+
reg Phase0Enable;
|
| 85 |
+
reg [15:0] Phase0CountX;
|
| 86 |
+
reg [15:0] Phase0CountY;
|
| 87 |
+
reg Phase1Enable;
|
| 88 |
+
reg [15:0] Phase1CountX;
|
| 89 |
+
reg [15:0] Phase1CountY;
|
| 90 |
+
reg Phase2Enable;
|
| 91 |
+
reg [15:0] Phase2CountX;
|
| 92 |
+
reg [15:0] Phase2CountY;
|
| 93 |
+
reg Phase3Enable;
|
| 94 |
+
reg [15:0] Phase3CountX;
|
| 95 |
+
reg [15:0] Phase3CountY;
|
| 96 |
+
|
| 97 |
+
reg signed [31:0] rgb00r;
|
| 98 |
+
reg signed [31:0] r00r;
|
| 99 |
+
reg signed [31:0] g00r;
|
| 100 |
+
reg signed [31:0] g01r;
|
| 101 |
+
reg signed [31:0] b00r;
|
| 102 |
+
reg signed [31:0] r10r;
|
| 103 |
+
reg signed [31:0] g10r;
|
| 104 |
+
reg signed [31:0] g11r;
|
| 105 |
+
reg signed [31:0] b10r;
|
| 106 |
+
reg signed [31:0] r20r;
|
| 107 |
+
reg signed [31:0] g20r;
|
| 108 |
+
reg signed [31:0] b20r;
|
| 109 |
+
|
| 110 |
+
wire signed [8:0] DataY;
|
| 111 |
+
wire signed [8:0] DataCb;
|
| 112 |
+
wire signed [8:0] DataCr;
|
| 113 |
+
|
| 114 |
+
reg signed [8:0] Phase0Y;
|
| 115 |
+
reg signed [8:0] Phase0Cb;
|
| 116 |
+
reg signed [8:0] Phase0Cr;
|
| 117 |
+
|
| 118 |
+
wire signed [19:0] C_RR = 20'h59BA5; // R_Cr: 1.402 * 0x4000
|
| 119 |
+
wire signed [19:0] C_GB = 20'h16066; // G_Cb: 0.34414 * 0x4000
|
| 120 |
+
wire signed [19:0] C_GR = 20'h2DB47; // G_Cr: 0.71414 * 0x4000
|
| 121 |
+
wire signed [19:0] C_BB = 20'h71687; // B_Cb: 1.772 * 0x4000
|
| 122 |
+
|
| 123 |
+
assign DataY = InY;
|
| 124 |
+
assign DataCb = InCb;
|
| 125 |
+
assign DataCr = InCr;
|
| 126 |
+
|
| 127 |
+
reg signed [8:0] Phase1Y,Phase1Cb,Phase1Cr;
|
| 128 |
+
reg signed [8:0] Phase2Y,Phase2Cb,Phase2Cr;
|
| 129 |
+
|
| 130 |
+
always @(posedge clk or negedge rst) begin
|
| 131 |
+
if(!rst) begin
|
| 132 |
+
rgb00r <= 0;
|
| 133 |
+
r00r <= 0;
|
| 134 |
+
g00r <= 0;
|
| 135 |
+
g01r <= 0;
|
| 136 |
+
b00r <= 0;
|
| 137 |
+
|
| 138 |
+
r10r <= 0;
|
| 139 |
+
g10r <= 0;
|
| 140 |
+
g11r <= 0;
|
| 141 |
+
b10r <= 0;
|
| 142 |
+
|
| 143 |
+
r20r <= 0;
|
| 144 |
+
g20r <= 0;
|
| 145 |
+
b20r <= 0;
|
| 146 |
+
|
| 147 |
+
Phase0Enable <= 1'b0;
|
| 148 |
+
Phase0CountX <= 16'h0000;
|
| 149 |
+
Phase0CountY <= 16'h0000;
|
| 150 |
+
Phase1Enable <= 1'b0;
|
| 151 |
+
Phase1CountX <= 16'h0000;
|
| 152 |
+
Phase1CountY <= 16'h0000;
|
| 153 |
+
Phase2Enable <= 1'b0;
|
| 154 |
+
Phase2CountX <= 16'h0000;
|
| 155 |
+
Phase2CountY <= 16'h0000;
|
| 156 |
+
Phase3Enable <= 1'b0;
|
| 157 |
+
Phase3CountX <= 16'h0000;
|
| 158 |
+
Phase3CountY <= 16'h0000;
|
| 159 |
+
end else begin
|
| 160 |
+
// Pre
|
| 161 |
+
PreEnable <= RunActive;
|
| 162 |
+
if(RunComp == 3) begin
|
| 163 |
+
// コンポーネント数が3のとき、16x16が1ブロック
|
| 164 |
+
PreCountX <= {RunBlockX,RunCount[3:0]};
|
| 165 |
+
PreCountY <= {RunBlockY,RunCount[7:4]};
|
| 166 |
+
end else begin
|
| 167 |
+
// コンポーネント数が1のとき、32x8が1ブロック
|
| 168 |
+
PreCountX <= {RunBlockX[10:0],RunCount[7],RunCount[3:0]};
|
| 169 |
+
PreCountY <= {1'b0,RunBlockY[11:0],RunCount[6:4]};
|
| 170 |
+
end
|
| 171 |
+
|
| 172 |
+
// Phase0
|
| 173 |
+
Phase0Enable <= PreEnable;
|
| 174 |
+
Phase0CountX <= PreCountX;
|
| 175 |
+
Phase0CountY <= PreCountY;
|
| 176 |
+
Phase0Y <= DataY;
|
| 177 |
+
Phase0Cb <= DataCb;
|
| 178 |
+
Phase0Cr <= DataCr;
|
| 179 |
+
|
| 180 |
+
// Phase1
|
| 181 |
+
Phase1Enable <= Phase0Enable;
|
| 182 |
+
Phase1CountX <= Phase0CountX;
|
| 183 |
+
Phase1CountY <= Phase0CountY;
|
| 184 |
+
|
| 185 |
+
rgb00r <= 32'h02000000 + {Phase0Y[8],Phase0Y[8],Phase0Y[8],Phase0Y[8],Phase0Y[8],Phase0Y[8:0],18'h0000};
|
| 186 |
+
r00r <= Phase0Cr * C_RR;
|
| 187 |
+
g00r <= Phase0Cb * C_GB;
|
| 188 |
+
g01r <= Phase0Cr * C_GR;
|
| 189 |
+
b00r <= Phase0Cb * C_BB;
|
| 190 |
+
|
| 191 |
+
Phase1Y <= Phase0Y;
|
| 192 |
+
Phase1Cb <= Phase0Cb;
|
| 193 |
+
Phase1Cr <= Phase0Cr;
|
| 194 |
+
|
| 195 |
+
// Phase2
|
| 196 |
+
Phase2Enable <= Phase1Enable;
|
| 197 |
+
Phase2CountX <= Phase1CountX;
|
| 198 |
+
Phase2CountY <= Phase1CountY;
|
| 199 |
+
|
| 200 |
+
r10r <= rgb00r + r00r;
|
| 201 |
+
g10r <= rgb00r - g00r;
|
| 202 |
+
g11r <= g01r;
|
| 203 |
+
b10r <= rgb00r + b00r;
|
| 204 |
+
|
| 205 |
+
Phase2Y <= Phase1Y;
|
| 206 |
+
Phase2Cb <= Phase1Cb;
|
| 207 |
+
Phase2Cr <= Phase1Cr;
|
| 208 |
+
|
| 209 |
+
// Phase3
|
| 210 |
+
Phase3Enable <= Phase2Enable;
|
| 211 |
+
Phase3CountX <= Phase2CountX;
|
| 212 |
+
Phase3CountY <= Phase2CountY;
|
| 213 |
+
r20r <= r10r;
|
| 214 |
+
g20r <= g10r - g11r;
|
| 215 |
+
b20r <= b10r;
|
| 216 |
+
end
|
| 217 |
+
end
|
| 218 |
+
|
| 219 |
+
assign OutEnable = Phase3Enable;
|
| 220 |
+
assign OutPixelX = Phase3CountX;
|
| 221 |
+
assign OutPixelY = Phase3CountY;
|
| 222 |
+
assign OutR = (r20r[31])?8'h00:(r20r[26])?8'hFF:r20r[25:18];
|
| 223 |
+
assign OutG = (g20r[31])?8'h00:(g20r[26])?8'hFF:g20r[25:18];
|
| 224 |
+
assign OutB = (b20r[31])?8'h00:(b20r[26])?8'hFF:b20r[25:18];
|
| 225 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_ycbcr_mem.v
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_ycbcr_mem(
|
| 22 |
+
input rst,
|
| 23 |
+
input clk,
|
| 24 |
+
|
| 25 |
+
input DataInit,
|
| 26 |
+
input [2:0] JpegComp,
|
| 27 |
+
|
| 28 |
+
input DataInEnable,
|
| 29 |
+
input [2:0] DataInColor,
|
| 30 |
+
input [2:0] DataInPage,
|
| 31 |
+
input [1:0] DataInCount,
|
| 32 |
+
input [8:0] Data0In,
|
| 33 |
+
input [8:0] Data1In,
|
| 34 |
+
output DataInFull,
|
| 35 |
+
|
| 36 |
+
output DataOutEnable,
|
| 37 |
+
input [7:0] DataOutAddress,
|
| 38 |
+
input DataOutRead,
|
| 39 |
+
output [8:0] DataOutY,
|
| 40 |
+
output [8:0] DataOutCb,
|
| 41 |
+
output [8:0] DataOutCr
|
| 42 |
+
);
|
| 43 |
+
reg [8:0] MemYA [0:511];
|
| 44 |
+
reg [8:0] MemYB [0:511];
|
| 45 |
+
reg [8:0] MemCbA [0:127];
|
| 46 |
+
reg [8:0] MemCbB [0:127];
|
| 47 |
+
reg [8:0] MemCrA [0:127];
|
| 48 |
+
reg [8:0] MemCrB [0:127];
|
| 49 |
+
|
| 50 |
+
reg [1:0] WriteBank, ReadBank;
|
| 51 |
+
|
| 52 |
+
wire [5:0] DataInAddress;
|
| 53 |
+
|
| 54 |
+
assign DataInAddress = {DataInPage, DataInCount};
|
| 55 |
+
|
| 56 |
+
wire WriteNext, ReadNext;
|
| 57 |
+
|
| 58 |
+
assign WriteNext = (DataInEnable && (DataInAddress == 5'd63) &&
|
| 59 |
+
(((JpegComp == 3'd3) && (DataInColor == 3'd5)) ||
|
| 60 |
+
((JpegComp == 3'd1) && (DataInColor == 3'd3))))?1'b1:1'b0;
|
| 61 |
+
assign ReadNext = (DataOutRead && (DataOutAddress == 8'd255))?1'b1:1'b0;
|
| 62 |
+
|
| 63 |
+
// Bank
|
| 64 |
+
always @(posedge clk or negedge rst) begin
|
| 65 |
+
if(!rst) begin
|
| 66 |
+
WriteBank <= 2'd0;
|
| 67 |
+
ReadBank <= 2'd0;
|
| 68 |
+
end else begin
|
| 69 |
+
if(DataInit) begin
|
| 70 |
+
WriteBank <= 2'd0;
|
| 71 |
+
end else if(WriteNext == 1'b1) begin
|
| 72 |
+
// (DataInColor == 3'd5)) begin
|
| 73 |
+
WriteBank <= WriteBank + 2'd1;
|
| 74 |
+
end
|
| 75 |
+
if(DataInit) begin
|
| 76 |
+
ReadBank <= 2'd0;
|
| 77 |
+
end else if(ReadNext == 1'b1) begin
|
| 78 |
+
ReadBank <= ReadBank + 2'd1;
|
| 79 |
+
end
|
| 80 |
+
end
|
| 81 |
+
end
|
| 82 |
+
|
| 83 |
+
reg [1:0] state;
|
| 84 |
+
localparam S_IDLE = 2'd0;
|
| 85 |
+
localparam S_FULL = 2'd1;
|
| 86 |
+
|
| 87 |
+
always @(posedge clk or negedge rst) begin
|
| 88 |
+
if(!rst) begin
|
| 89 |
+
state <= S_IDLE;
|
| 90 |
+
end else begin
|
| 91 |
+
if(DataInit) begin
|
| 92 |
+
state <= S_IDLE;
|
| 93 |
+
end else begin
|
| 94 |
+
case(state)
|
| 95 |
+
S_IDLE: begin
|
| 96 |
+
if((WriteNext == 1'b1) && (ReadBank == (WriteBank +2'b1)) && (ReadNext == 1'b0)) begin
|
| 97 |
+
state <= S_FULL;
|
| 98 |
+
end
|
| 99 |
+
end
|
| 100 |
+
S_FULL: begin
|
| 101 |
+
if((ReadNext == 1'b1) && (ReadBank == WriteBank)) begin
|
| 102 |
+
state <= S_IDLE;
|
| 103 |
+
end
|
| 104 |
+
end
|
| 105 |
+
default: begin
|
| 106 |
+
state <= S_IDLE;
|
| 107 |
+
end
|
| 108 |
+
endcase
|
| 109 |
+
end
|
| 110 |
+
end
|
| 111 |
+
end
|
| 112 |
+
assign DataInFull = (state == S_FULL)?1'b1:1'b0;
|
| 113 |
+
|
| 114 |
+
wire [6:0] WriteAddressA;
|
| 115 |
+
wire [6:0] WriteAddressB;
|
| 116 |
+
|
| 117 |
+
function [6:0] F_WriteAddressA;
|
| 118 |
+
input [2:0] DataInColor;
|
| 119 |
+
input [2:0] DataInPage;
|
| 120 |
+
input [1:0] DataInCount;
|
| 121 |
+
begin
|
| 122 |
+
F_WriteAddressA[6] = DataInColor[1];
|
| 123 |
+
if(DataInColor[2] == 1'b0) begin
|
| 124 |
+
F_WriteAddressA[5:4] = DataInCount[1:0];
|
| 125 |
+
F_WriteAddressA[3] = DataInColor[0] & ~DataInColor[2];
|
| 126 |
+
end else begin
|
| 127 |
+
F_WriteAddressA[5] = 1'b0;
|
| 128 |
+
F_WriteAddressA[4:3] = DataInCount[1:0];
|
| 129 |
+
end
|
| 130 |
+
F_WriteAddressA[2:0] = DataInPage[2:0];
|
| 131 |
+
end
|
| 132 |
+
endfunction
|
| 133 |
+
|
| 134 |
+
function [6:0] F_WriteAddressB;
|
| 135 |
+
input [2:0] DataInColor;
|
| 136 |
+
input [2:0] DataInPage;
|
| 137 |
+
input [1:0] DataInCount;
|
| 138 |
+
begin
|
| 139 |
+
F_WriteAddressB[6] = DataInColor[1];
|
| 140 |
+
if(DataInColor[2] == 1'b0) begin
|
| 141 |
+
F_WriteAddressB[5:4] = ~DataInCount[1:0];
|
| 142 |
+
F_WriteAddressB[3] = DataInColor[0] & ~DataInColor[2];
|
| 143 |
+
end else begin
|
| 144 |
+
F_WriteAddressB[5] = 1'b0;
|
| 145 |
+
F_WriteAddressB[4:3] = ~DataInCount[1:0];
|
| 146 |
+
end
|
| 147 |
+
F_WriteAddressB[2:0] = DataInPage[2:0];
|
| 148 |
+
end
|
| 149 |
+
endfunction
|
| 150 |
+
|
| 151 |
+
assign WriteAddressA = F_WriteAddressA(DataInColor, DataInPage, DataInCount);
|
| 152 |
+
assign WriteAddressB = F_WriteAddressB(DataInColor, DataInPage, DataInCount);
|
| 153 |
+
|
| 154 |
+
always @(posedge clk) begin
|
| 155 |
+
if(DataInColor[2] == 1'b0 & DataInEnable == 1'b1) begin
|
| 156 |
+
MemYA[{WriteBank, WriteAddressA}] <= Data0In;
|
| 157 |
+
MemYB[{WriteBank, WriteAddressB}] <= Data1In;
|
| 158 |
+
end
|
| 159 |
+
end
|
| 160 |
+
|
| 161 |
+
always @(posedge clk) begin
|
| 162 |
+
if(DataInColor == 3'b100 & DataInEnable == 1'b1) begin
|
| 163 |
+
MemCbA[{WriteBank, WriteAddressA[4:0]}] <= Data0In;
|
| 164 |
+
MemCbB[{WriteBank, WriteAddressB[4:0]}] <= Data1In;
|
| 165 |
+
end
|
| 166 |
+
end
|
| 167 |
+
|
| 168 |
+
always @(posedge clk) begin
|
| 169 |
+
if(DataInColor == 3'b101 & DataInEnable == 1'b1) begin
|
| 170 |
+
MemCrA[{WriteBank, WriteAddressA[4:0]}] <= Data0In;
|
| 171 |
+
MemCrB[{WriteBank, WriteAddressB[4:0]}] <= Data1In;
|
| 172 |
+
end
|
| 173 |
+
end
|
| 174 |
+
|
| 175 |
+
reg [8:0] ReadYA;
|
| 176 |
+
reg [8:0] ReadYB;
|
| 177 |
+
reg [8:0] ReadCbA;
|
| 178 |
+
reg [8:0] ReadCbB;
|
| 179 |
+
reg [8:0] ReadCrA;
|
| 180 |
+
reg [8:0] ReadCrB;
|
| 181 |
+
|
| 182 |
+
reg [7:0] RegAdrs;
|
| 183 |
+
|
| 184 |
+
always @(posedge clk) begin
|
| 185 |
+
RegAdrs <= DataOutAddress;
|
| 186 |
+
|
| 187 |
+
ReadYA <= MemYA[{ReadBank, DataOutAddress[7],DataOutAddress[5:0]}];
|
| 188 |
+
ReadYB <= MemYB[{ReadBank, DataOutAddress[7],DataOutAddress[5:0]}];
|
| 189 |
+
|
| 190 |
+
ReadCbA <= MemCbA[{ReadBank, DataOutAddress[6:5],DataOutAddress[3:1]}];
|
| 191 |
+
ReadCrA <= MemCrA[{ReadBank, DataOutAddress[6:5],DataOutAddress[3:1]}];
|
| 192 |
+
|
| 193 |
+
ReadCbB <= MemCbB[{ReadBank, DataOutAddress[6:5],DataOutAddress[3:1]}];
|
| 194 |
+
ReadCrB <= MemCrB[{ReadBank, DataOutAddress[6:5],DataOutAddress[3:1]}];
|
| 195 |
+
end
|
| 196 |
+
|
| 197 |
+
assign DataOutEnable = (WriteBank != ReadBank);
|
| 198 |
+
assign DataOutY = (RegAdrs[6] ==1'b0)?ReadYA:ReadYB;
|
| 199 |
+
assign DataOutCb = (RegAdrs[7] ==1'b0)?ReadCbA:ReadCbB;
|
| 200 |
+
assign DataOutCr = (RegAdrs[7] ==1'b0)?ReadCrA:ReadCrB;
|
| 201 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/sources/aq_djpeg_ziguzagu.v
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2006-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ps / 1ps
|
| 20 |
+
|
| 21 |
+
module aq_djpeg_ziguzagu(
|
| 22 |
+
input clk,
|
| 23 |
+
input rst,
|
| 24 |
+
|
| 25 |
+
input DataInit,
|
| 26 |
+
input HuffmanEndEnable,
|
| 27 |
+
|
| 28 |
+
input DataInEnable,
|
| 29 |
+
input [5:0] DataInAddress,
|
| 30 |
+
input [2:0] DataInColor,
|
| 31 |
+
output DataInIdle,
|
| 32 |
+
input [15:0] DataIn,
|
| 33 |
+
|
| 34 |
+
output DataOutEnable,
|
| 35 |
+
input DataOutRead,
|
| 36 |
+
input [4:0] DataOutAddress,
|
| 37 |
+
output [2:0] DataOutColor,
|
| 38 |
+
output [15:0] DataOutA,
|
| 39 |
+
output [15:0] DataOutB
|
| 40 |
+
);
|
| 41 |
+
// State Machine Parameter
|
| 42 |
+
parameter S_IDLE = 2'd0;
|
| 43 |
+
parameter S_VALID = 2'd1;
|
| 44 |
+
parameter S_FULL = 2'd2;
|
| 45 |
+
parameter S_INIT = 2'd3;
|
| 46 |
+
|
| 47 |
+
reg [1:0] State;
|
| 48 |
+
reg [1:0] BankCount;
|
| 49 |
+
|
| 50 |
+
reg [2:0] BankColor [0:3];
|
| 51 |
+
reg [1:0] WriteBank;
|
| 52 |
+
reg [1:0] ReadBank;
|
| 53 |
+
|
| 54 |
+
wire [5:0] WriteQuery;
|
| 55 |
+
|
| 56 |
+
// State Machine
|
| 57 |
+
always @(posedge clk or negedge rst) begin
|
| 58 |
+
if(!rst) begin
|
| 59 |
+
State <= S_IDLE;
|
| 60 |
+
BankCount <= 2'd0;
|
| 61 |
+
end else begin
|
| 62 |
+
case(State)
|
| 63 |
+
S_IDLE: begin
|
| 64 |
+
if(DataInit) begin
|
| 65 |
+
State <= S_INIT;
|
| 66 |
+
end else if(HuffmanEndEnable) begin
|
| 67 |
+
State <= S_VALID;
|
| 68 |
+
BankCount <= 2'd0;
|
| 69 |
+
end
|
| 70 |
+
end
|
| 71 |
+
S_VALID: begin
|
| 72 |
+
if(HuffmanEndEnable && !(DataOutRead && (DataOutAddress == 5'd31))) begin
|
| 73 |
+
if(BankCount == 2'd2) begin
|
| 74 |
+
State <= S_FULL;
|
| 75 |
+
BankCount <= 2'd3;
|
| 76 |
+
end else begin
|
| 77 |
+
BankCount <= BankCount + 2'd1;
|
| 78 |
+
end
|
| 79 |
+
end else if(!HuffmanEndEnable && (DataOutRead && (DataOutAddress == 5'd31))) begin
|
| 80 |
+
if(BankCount == 2'd0) begin
|
| 81 |
+
State <= S_IDLE;
|
| 82 |
+
BankCount <= 2'd0;
|
| 83 |
+
end else begin
|
| 84 |
+
BankCount <= BankCount - 2'd1;
|
| 85 |
+
end
|
| 86 |
+
end
|
| 87 |
+
end
|
| 88 |
+
S_FULL: begin
|
| 89 |
+
if(DataOutRead && (DataOutAddress == 5'd31)) begin
|
| 90 |
+
State <= S_VALID;
|
| 91 |
+
BankCount <= 2'd2;
|
| 92 |
+
end
|
| 93 |
+
end
|
| 94 |
+
S_INIT: begin
|
| 95 |
+
State <= S_IDLE;
|
| 96 |
+
end
|
| 97 |
+
endcase
|
| 98 |
+
end
|
| 99 |
+
end
|
| 100 |
+
|
| 101 |
+
// Color
|
| 102 |
+
always @(posedge clk or negedge rst) begin
|
| 103 |
+
if(!rst) begin
|
| 104 |
+
BankColor[0] <= 3'd0;
|
| 105 |
+
BankColor[1] <= 3'd0;
|
| 106 |
+
BankColor[2] <= 3'd0;
|
| 107 |
+
BankColor[3] <= 3'd0;
|
| 108 |
+
end else begin
|
| 109 |
+
if(HuffmanEndEnable) BankColor[WriteBank] <= DataInColor;
|
| 110 |
+
end
|
| 111 |
+
end
|
| 112 |
+
|
| 113 |
+
// Bank
|
| 114 |
+
always @(posedge clk or negedge rst) begin
|
| 115 |
+
if(!rst) begin
|
| 116 |
+
WriteBank <= 2'd0;
|
| 117 |
+
ReadBank <= 2'd0;
|
| 118 |
+
end else begin
|
| 119 |
+
// Write Bank
|
| 120 |
+
if(State == S_INIT) begin
|
| 121 |
+
WriteBank <= 2'd0;
|
| 122 |
+
end else if(HuffmanEndEnable) begin
|
| 123 |
+
WriteBank <= WriteBank + 2'd1;
|
| 124 |
+
end
|
| 125 |
+
// Read Bank
|
| 126 |
+
if(State == S_INIT) begin
|
| 127 |
+
ReadBank <= 2'd0;
|
| 128 |
+
end else if(DataOutRead && (DataOutAddress == 5'd31)) begin
|
| 129 |
+
ReadBank <= ReadBank + 2'd1;
|
| 130 |
+
end
|
| 131 |
+
end
|
| 132 |
+
end
|
| 133 |
+
|
| 134 |
+
// Make a Write Address
|
| 135 |
+
function [5:0] F_WriteQuery;
|
| 136 |
+
input [5:0] Count;
|
| 137 |
+
case(Count)
|
| 138 |
+
6'd0: F_WriteQuery = {1'b0, 5'd0 };
|
| 139 |
+
6'd1: F_WriteQuery = {1'b0, 5'd2 };
|
| 140 |
+
6'd2: F_WriteQuery = {1'b0, 5'd4 };
|
| 141 |
+
6'd3: F_WriteQuery = {1'b0, 5'd8 };
|
| 142 |
+
6'd4: F_WriteQuery = {1'b0, 5'd6 };
|
| 143 |
+
6'd5: F_WriteQuery = {1'b0, 5'd1 };
|
| 144 |
+
6'd6: F_WriteQuery = {1'b1, 5'd3 };
|
| 145 |
+
6'd7: F_WriteQuery = {1'b0, 5'd5 };
|
| 146 |
+
6'd8: F_WriteQuery = {1'b0, 5'd10};
|
| 147 |
+
6'd9: F_WriteQuery = {1'b0, 5'd12};
|
| 148 |
+
6'd10: F_WriteQuery = {1'b0, 5'd16};
|
| 149 |
+
6'd11: F_WriteQuery = {1'b0, 5'd14};
|
| 150 |
+
6'd12: F_WriteQuery = {1'b0, 5'd9 };
|
| 151 |
+
6'd13: F_WriteQuery = {1'b1, 5'd7 };
|
| 152 |
+
6'd14: F_WriteQuery = {1'b1, 5'd0 };
|
| 153 |
+
6'd15: F_WriteQuery = {1'b0, 5'd3 };
|
| 154 |
+
6'd16: F_WriteQuery = {1'b1, 5'd4 };
|
| 155 |
+
6'd17: F_WriteQuery = {1'b1, 5'd11};
|
| 156 |
+
6'd18: F_WriteQuery = {1'b0, 5'd13};
|
| 157 |
+
6'd19: F_WriteQuery = {1'b0, 5'd18};
|
| 158 |
+
6'd20: F_WriteQuery = {1'b0, 5'd20};
|
| 159 |
+
6'd21: F_WriteQuery = {1'b0, 5'd24};
|
| 160 |
+
6'd22: F_WriteQuery = {1'b0, 5'd22};
|
| 161 |
+
6'd23: F_WriteQuery = {1'b0, 5'd17};
|
| 162 |
+
6'd24: F_WriteQuery = {1'b1, 5'd15};
|
| 163 |
+
6'd25: F_WriteQuery = {1'b1, 5'd8 };
|
| 164 |
+
6'd26: F_WriteQuery = {1'b0, 5'd7 };
|
| 165 |
+
6'd27: F_WriteQuery = {1'b1, 5'd1 };
|
| 166 |
+
6'd28: F_WriteQuery = {1'b1, 5'd2 };
|
| 167 |
+
6'd29: F_WriteQuery = {1'b1, 5'd5 };
|
| 168 |
+
6'd30: F_WriteQuery = {1'b0, 5'd11};
|
| 169 |
+
6'd31: F_WriteQuery = {1'b1, 5'd12};
|
| 170 |
+
6'd32: F_WriteQuery = {1'b1, 5'd19};
|
| 171 |
+
6'd33: F_WriteQuery = {1'b0, 5'd21};
|
| 172 |
+
6'd34: F_WriteQuery = {1'b0, 5'd26};
|
| 173 |
+
6'd35: F_WriteQuery = {1'b0, 5'd28};
|
| 174 |
+
6'd36: F_WriteQuery = {1'b0, 5'd30};
|
| 175 |
+
6'd37: F_WriteQuery = {1'b0, 5'd25};
|
| 176 |
+
6'd38: F_WriteQuery = {1'b1, 5'd23};
|
| 177 |
+
6'd39: F_WriteQuery = {1'b1, 5'd16};
|
| 178 |
+
6'd40: F_WriteQuery = {1'b0, 5'd15};
|
| 179 |
+
6'd41: F_WriteQuery = {1'b1, 5'd9 };
|
| 180 |
+
6'd42: F_WriteQuery = {1'b1, 5'd6 };
|
| 181 |
+
6'd43: F_WriteQuery = {1'b1, 5'd10};
|
| 182 |
+
6'd44: F_WriteQuery = {1'b1, 5'd13};
|
| 183 |
+
6'd45: F_WriteQuery = {1'b0, 5'd19};
|
| 184 |
+
6'd46: F_WriteQuery = {1'b1, 5'd20};
|
| 185 |
+
6'd47: F_WriteQuery = {1'b1, 5'd27};
|
| 186 |
+
6'd48: F_WriteQuery = {1'b0, 5'd29};
|
| 187 |
+
6'd49: F_WriteQuery = {1'b1, 5'd31};
|
| 188 |
+
6'd50: F_WriteQuery = {1'b1, 5'd24};
|
| 189 |
+
6'd51: F_WriteQuery = {1'b0, 5'd23};
|
| 190 |
+
6'd52: F_WriteQuery = {1'b1, 5'd17};
|
| 191 |
+
6'd53: F_WriteQuery = {1'b1, 5'd14};
|
| 192 |
+
6'd54: F_WriteQuery = {1'b1, 5'd18};
|
| 193 |
+
6'd55: F_WriteQuery = {1'b1, 5'd21};
|
| 194 |
+
6'd56: F_WriteQuery = {1'b0, 5'd27};
|
| 195 |
+
6'd57: F_WriteQuery = {1'b1, 5'd28};
|
| 196 |
+
6'd58: F_WriteQuery = {1'b0, 5'd31};
|
| 197 |
+
6'd59: F_WriteQuery = {1'b1, 5'd25};
|
| 198 |
+
6'd60: F_WriteQuery = {1'b1, 5'd22};
|
| 199 |
+
6'd61: F_WriteQuery = {1'b1, 5'd26};
|
| 200 |
+
6'd62: F_WriteQuery = {1'b1, 5'd29};
|
| 201 |
+
6'd63: F_WriteQuery = {1'b1, 5'd30};
|
| 202 |
+
endcase
|
| 203 |
+
endfunction
|
| 204 |
+
|
| 205 |
+
assign WriteQuery = F_WriteQuery(DataInAddress);
|
| 206 |
+
|
| 207 |
+
// RAM(16bit x 32word x 2Bank)
|
| 208 |
+
reg [15:0] MemoryA [0:127];
|
| 209 |
+
reg [15:0] MemoryB [0:127];
|
| 210 |
+
|
| 211 |
+
wire [6:0] WriteAddress;
|
| 212 |
+
wire WriteEnableA, WriteEnableB;
|
| 213 |
+
|
| 214 |
+
assign WriteEnableA = DataInEnable & ~WriteQuery[5];
|
| 215 |
+
assign WriteEnableB = DataInEnable & WriteQuery[5];
|
| 216 |
+
assign WriteAddress = {WriteBank, WriteQuery[4:0]};
|
| 217 |
+
|
| 218 |
+
// Port A(Write Only)
|
| 219 |
+
always @(posedge clk) begin
|
| 220 |
+
if(WriteEnableA) MemoryA[WriteAddress] <= DataIn;
|
| 221 |
+
if(WriteEnableB) MemoryB[WriteAddress] <= DataIn;
|
| 222 |
+
end
|
| 223 |
+
|
| 224 |
+
reg [15:0] RegMemoryA, RegMemoryB;
|
| 225 |
+
|
| 226 |
+
// Port B(Read/Wirte)
|
| 227 |
+
always @(posedge clk) begin
|
| 228 |
+
RegMemoryA <= MemoryA[{ReadBank, DataOutAddress}];
|
| 229 |
+
RegMemoryB <= MemoryB[{ReadBank, DataOutAddress}];
|
| 230 |
+
end
|
| 231 |
+
|
| 232 |
+
// Data Enable Register
|
| 233 |
+
reg [127:0] DataEnableA, DataEnableB;
|
| 234 |
+
|
| 235 |
+
always @(posedge clk or negedge rst) begin
|
| 236 |
+
if(!rst) begin
|
| 237 |
+
DataEnableA <= 128'd0;
|
| 238 |
+
DataEnableB <= 128'd0;
|
| 239 |
+
end else begin
|
| 240 |
+
if(State == S_INIT) begin
|
| 241 |
+
DataEnableA <= 128'd0;
|
| 242 |
+
DataEnableB <= 128'd0;
|
| 243 |
+
end else begin
|
| 244 |
+
if(DataInEnable && (WriteBank == 2'd0)) begin
|
| 245 |
+
if(WriteEnableA) begin
|
| 246 |
+
if(WriteAddress[4:0] == 5'd0) begin
|
| 247 |
+
DataEnableA[{2'd0, WriteAddress[4:0]}] <= 1'b1;
|
| 248 |
+
DataEnableA[31:1] <= 31'd0;
|
| 249 |
+
DataEnableB[31:0] <= 32'd0;
|
| 250 |
+
end else begin
|
| 251 |
+
DataEnableA[{2'd0, WriteAddress[4:0]}] <= 1'b1;
|
| 252 |
+
end
|
| 253 |
+
end else begin
|
| 254 |
+
DataEnableB[{2'd0, WriteAddress[4:0]}] <= 1'b1;
|
| 255 |
+
end
|
| 256 |
+
end
|
| 257 |
+
if(DataInEnable && (WriteBank == 2'd1)) begin
|
| 258 |
+
if(WriteEnableA) begin
|
| 259 |
+
if(WriteAddress[4:0] == 5'd0) begin
|
| 260 |
+
DataEnableA[{2'd1, WriteAddress[4:0]}] <= 1'b1;
|
| 261 |
+
DataEnableA[63:33] <= 31'd0;
|
| 262 |
+
DataEnableB[63:32] <= 32'd0;
|
| 263 |
+
end else begin
|
| 264 |
+
DataEnableA[{2'd1, WriteAddress[4:0]}] <= 1'b1;
|
| 265 |
+
end
|
| 266 |
+
end else begin
|
| 267 |
+
DataEnableB[{2'd1, WriteAddress[4:0]}] <= 1'b1;
|
| 268 |
+
end
|
| 269 |
+
end
|
| 270 |
+
if(DataInEnable && (WriteBank == 2'd2)) begin
|
| 271 |
+
if(WriteEnableA) begin
|
| 272 |
+
if(WriteAddress[4:0] == 5'd0) begin
|
| 273 |
+
DataEnableA[{2'd2, WriteAddress[4:0]}] <= 1'b1;
|
| 274 |
+
DataEnableA[95:65] <= 31'd0;
|
| 275 |
+
DataEnableB[95:64] <= 32'd0;
|
| 276 |
+
end else begin
|
| 277 |
+
DataEnableA[{2'd2, WriteAddress[4:0]}] <= 1'b1;
|
| 278 |
+
end
|
| 279 |
+
end else begin
|
| 280 |
+
DataEnableB[{2'd2, WriteAddress[4:0]}] <= 1'b1;
|
| 281 |
+
end
|
| 282 |
+
end
|
| 283 |
+
if(DataInEnable && (WriteBank == 2'd3)) begin
|
| 284 |
+
if(WriteEnableA) begin
|
| 285 |
+
if(WriteAddress[4:0] == 5'd0) begin
|
| 286 |
+
DataEnableA[{2'd3, WriteAddress[4:0]}] <= 1'b1;
|
| 287 |
+
DataEnableA[127:97] <= 31'd0;
|
| 288 |
+
DataEnableB[127:96] <= 32'd0;
|
| 289 |
+
end else begin
|
| 290 |
+
DataEnableA[{2'd3, WriteAddress[4:0]}] <= 1'b1;
|
| 291 |
+
end
|
| 292 |
+
end else begin
|
| 293 |
+
DataEnableB[{2'd3, WriteAddress[4:0]}] <= 1'b1;
|
| 294 |
+
end
|
| 295 |
+
end
|
| 296 |
+
end
|
| 297 |
+
end
|
| 298 |
+
end
|
| 299 |
+
|
| 300 |
+
reg AddressDelayA, AddressDelayB;
|
| 301 |
+
|
| 302 |
+
always @(posedge clk or negedge rst) begin
|
| 303 |
+
if(!rst) begin
|
| 304 |
+
AddressDelayA <= 1'b0;
|
| 305 |
+
AddressDelayB <= 1'b0;
|
| 306 |
+
end else begin
|
| 307 |
+
AddressDelayA <= DataEnableA[{ReadBank, DataOutAddress}];
|
| 308 |
+
AddressDelayB <= DataEnableB[{ReadBank, DataOutAddress}];
|
| 309 |
+
end
|
| 310 |
+
end
|
| 311 |
+
|
| 312 |
+
// Output Signal
|
| 313 |
+
assign DataInIdle = (State == S_IDLE) | (State == S_VALID);
|
| 314 |
+
assign DataOutEnable = (State == S_VALID) | (State == S_FULL);
|
| 315 |
+
assign DataOutColor = BankColor[ReadBank];
|
| 316 |
+
assign DataOutA = (AddressDelayA)?RegMemoryA:16'd0;
|
| 317 |
+
assign DataOutB = (AddressDelayB)?RegMemoryB:16'd0;
|
| 318 |
+
|
| 319 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_djpeg/aq_axi_djpeg.srcs/xgui/aq_axi_djpeg_v1_0.tcl
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Definitional proc to organize widgets for parameters.
|
| 2 |
+
proc init_gui { IPINST } {
|
| 3 |
+
set Page0 [ipgui::add_page $IPINST -name "Page 0" -layout vertical]
|
| 4 |
+
set Component_Name [ipgui::add_param $IPINST -parent $Page0 -name Component_Name]
|
| 5 |
+
set C_ADRSWIDTH [ipgui::add_param $IPINST -parent $Page0 -name C_ADRSWIDTH]
|
| 6 |
+
set C_BASEADRS [ipgui::add_param $IPINST -parent $Page0 -name C_BASEADRS]
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
proc update_PARAM_VALUE.C_ADRSWIDTH { PARAM_VALUE.C_ADRSWIDTH } {
|
| 10 |
+
# Procedure called to update C_ADRSWIDTH when any of the dependent parameters in the arguments change
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
proc validate_PARAM_VALUE.C_ADRSWIDTH { PARAM_VALUE.C_ADRSWIDTH } {
|
| 14 |
+
# Procedure called to validate C_ADRSWIDTH
|
| 15 |
+
return true
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
proc update_PARAM_VALUE.C_BASEADRS { PARAM_VALUE.C_BASEADRS } {
|
| 19 |
+
# Procedure called to update C_BASEADRS when any of the dependent parameters in the arguments change
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
proc validate_PARAM_VALUE.C_BASEADRS { PARAM_VALUE.C_BASEADRS } {
|
| 23 |
+
# Procedure called to validate C_BASEADRS
|
| 24 |
+
return true
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
proc update_MODELPARAM_VALUE.C_BASEADRS { MODELPARAM_VALUE.C_BASEADRS PARAM_VALUE.C_BASEADRS } {
|
| 29 |
+
# Procedure called to set VHDL generic/Verilog parameter value(s) based on TCL parameter value
|
| 30 |
+
set_property value [get_property value ${PARAM_VALUE.C_BASEADRS}] ${MODELPARAM_VALUE.C_BASEADRS}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
proc update_MODELPARAM_VALUE.C_ADRSWIDTH { MODELPARAM_VALUE.C_ADRSWIDTH PARAM_VALUE.C_ADRSWIDTH } {
|
| 34 |
+
# Procedure called to set VHDL generic/Verilog parameter value(s) based on TCL parameter value
|
| 35 |
+
set_property value [get_property value ${PARAM_VALUE.C_ADRSWIDTH}] ${MODELPARAM_VALUE.C_ADRSWIDTH}
|
| 36 |
+
}
|
| 37 |
+
|
aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sim/tb_aq_axi_fifo.v
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ns / 100ps
|
| 20 |
+
module tb_aq_axi_fifo;
|
| 21 |
+
|
| 22 |
+
// Reset, Clock
|
| 23 |
+
reg ARESETN;
|
| 24 |
+
reg ACLK;
|
| 25 |
+
|
| 26 |
+
reg S_AXI_ACLK;
|
| 27 |
+
|
| 28 |
+
// Write Address Channel
|
| 29 |
+
reg [31:0] S_AXI_AWADDR;
|
| 30 |
+
reg [3:0] S_AXI_AWCACHE;
|
| 31 |
+
reg [2:0] S_AXI_AWPROT;
|
| 32 |
+
reg S_AXI_AWVALID;
|
| 33 |
+
wire S_AXI_AWREADY;
|
| 34 |
+
|
| 35 |
+
// Write Data Channel
|
| 36 |
+
reg [31:0] S_AXI_WDATA;
|
| 37 |
+
reg [3:0] S_AXI_WSTRB;
|
| 38 |
+
reg S_AXI_WVALID;
|
| 39 |
+
wire S_AXI_WREADY;
|
| 40 |
+
|
| 41 |
+
// Write Response Channel
|
| 42 |
+
wire S_AXI_BVALID;
|
| 43 |
+
wire S_AXI_BREADY;
|
| 44 |
+
wire [1:0] S_AXI_BRESP;
|
| 45 |
+
|
| 46 |
+
// Read Address Channe
|
| 47 |
+
reg [31:0] S_AXI_ARADDR;
|
| 48 |
+
reg [3:0] S_AXI_ARCACHE;
|
| 49 |
+
reg [2:0] S_AXI_ARPROT;
|
| 50 |
+
reg S_AXI_ARVALID;
|
| 51 |
+
wire S_AXI_ARREADY;
|
| 52 |
+
|
| 53 |
+
// Read Data Channel
|
| 54 |
+
wire [31:0] S_AXI_RDATA;
|
| 55 |
+
wire [1:0] S_AXI_RRESP;
|
| 56 |
+
wire S_AXI_RVALID;
|
| 57 |
+
reg S_AXI_RREADY;
|
| 58 |
+
|
| 59 |
+
// Master Write Address
|
| 60 |
+
wire [0:0] M_AXI_AWID;
|
| 61 |
+
wire [31:0] M_AXI_AWADDR;
|
| 62 |
+
wire [7:0] M_AXI_AWLEN;
|
| 63 |
+
wire [2:0] M_AXI_AWSIZE;
|
| 64 |
+
wire [1:0] M_AXI_AWBURST;
|
| 65 |
+
wire M_AXI_AWLOCK;
|
| 66 |
+
wire [3:0] M_AXI_AWCACHE;
|
| 67 |
+
wire [2:0] M_AXI_AWPROT;
|
| 68 |
+
wire [3:0] M_AXI_AWQOS;
|
| 69 |
+
wire [0:0] M_AXI_AWUSER;
|
| 70 |
+
wire M_AXI_AWVALID;
|
| 71 |
+
reg M_AXI_AWREADY;
|
| 72 |
+
|
| 73 |
+
// Master Write Data
|
| 74 |
+
wire [63:0] M_AXI_WDATA;
|
| 75 |
+
wire [2:0] M_AXI_WSTRB;
|
| 76 |
+
wire M_AXI_WLAST;
|
| 77 |
+
wire [0:0] M_AXI_WUSER;
|
| 78 |
+
wire M_AXI_WVALID;
|
| 79 |
+
reg M_AXI_WREADY;
|
| 80 |
+
|
| 81 |
+
// Master Write Response
|
| 82 |
+
reg [0:0] M_AXI_BID;
|
| 83 |
+
reg [1:0] M_AXI_BRESP;
|
| 84 |
+
reg [0:0] M_AXI_BUSER;
|
| 85 |
+
reg M_AXI_BVALID;
|
| 86 |
+
wire M_AXI_BREADY;
|
| 87 |
+
|
| 88 |
+
// Master Read Address
|
| 89 |
+
wire [0:0] M_AXI_ARID;
|
| 90 |
+
wire [31:0] M_AXI_ARADDR;
|
| 91 |
+
wire [7:0] M_AXI_ARLEN;
|
| 92 |
+
wire [2:0] M_AXI_ARSIZE;
|
| 93 |
+
wire [1:0] M_AXI_ARBURST;
|
| 94 |
+
wire [1:0] M_AXI_ARLOCK;
|
| 95 |
+
wire [3:0] M_AXI_ARCACHE;
|
| 96 |
+
wire [2:0] M_AXI_ARPROT;
|
| 97 |
+
wire [3:0] M_AXI_ARQOS;
|
| 98 |
+
wire [0:0] M_AXI_ARUSER;
|
| 99 |
+
wire M_AXI_ARVALID;
|
| 100 |
+
reg M_AXI_ARREADY;
|
| 101 |
+
|
| 102 |
+
// Master Read Data
|
| 103 |
+
reg [0:0] M_AXI_RID;
|
| 104 |
+
wire [63:0] M_AXI_RDATA;
|
| 105 |
+
reg [1:0] M_AXI_RRESP;
|
| 106 |
+
reg M_AXI_RLAST;
|
| 107 |
+
reg [0:0] M_AXI_RUSER;
|
| 108 |
+
reg M_AXI_RVALID;
|
| 109 |
+
wire M_AXI_RREADY;
|
| 110 |
+
|
| 111 |
+
// Local Bus
|
| 112 |
+
reg WR_START;
|
| 113 |
+
reg [31:0] WR_ADRS;
|
| 114 |
+
reg [15:0] WR_LEN;
|
| 115 |
+
wire WR_READY;
|
| 116 |
+
wire WR_FIFO_RE;
|
| 117 |
+
reg WR_FIFO_EMPTY;
|
| 118 |
+
reg [63:0] WR_FIFO_DATA;
|
| 119 |
+
|
| 120 |
+
reg RD_START;
|
| 121 |
+
reg [31:0] RD_ADRS;
|
| 122 |
+
reg [15:0] RD_LEN;
|
| 123 |
+
wire RD_READY;
|
| 124 |
+
wire RD_FIFO_WE;
|
| 125 |
+
reg RD_FIFO_FULL;
|
| 126 |
+
wire [63:0] RD_FIFO_DATA;
|
| 127 |
+
|
| 128 |
+
wire [31:0] DEBUG;
|
| 129 |
+
|
| 130 |
+
// FIFO
|
| 131 |
+
wire FIFO_RST;
|
| 132 |
+
|
| 133 |
+
reg FIFO_RD_CLK;
|
| 134 |
+
reg FIFO_RD_EN;
|
| 135 |
+
wire [63:0] FIFO_DOUT;
|
| 136 |
+
wire FIFO_EMPTY;
|
| 137 |
+
|
| 138 |
+
reg FIFO_WR_CLK;
|
| 139 |
+
reg [63:0] FIFO_DIN;
|
| 140 |
+
reg FIFO_WR_EN;
|
| 141 |
+
wire FIFO_FULL;
|
| 142 |
+
|
| 143 |
+
wire fifo_we;
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
parameter CLK10N = 10;
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
aq_axi_fifo u_aq_axi_fifo(
|
| 150 |
+
// Reset, Clock
|
| 151 |
+
.ARESETN(ARESETN),
|
| 152 |
+
|
| 153 |
+
.S_AXI_ACLK(ACLK),
|
| 154 |
+
|
| 155 |
+
// Write Address Channel
|
| 156 |
+
.S_AXI_AWADDR(S_AXI_AWADDR),
|
| 157 |
+
.S_AXI_AWCACHE(S_AXI_AWCACHE),
|
| 158 |
+
.S_AXI_AWPROT(S_AXI_AWPROT),
|
| 159 |
+
.S_AXI_AWVALID(S_AXI_AWVALID),
|
| 160 |
+
.S_AXI_AWREADY(S_AXI_AWREADY),
|
| 161 |
+
|
| 162 |
+
// Write Data Channel
|
| 163 |
+
.S_AXI_WDATA(S_AXI_WDATA),
|
| 164 |
+
.S_AXI_WSTRB(S_AXI_WSTRB),
|
| 165 |
+
.S_AXI_WVALID(S_AXI_WVALID),
|
| 166 |
+
.S_AXI_WREADY(S_AXI_WREADY),
|
| 167 |
+
|
| 168 |
+
// Write Response Channel
|
| 169 |
+
.S_AXI_BVALID(S_AXI_BVALID),
|
| 170 |
+
.S_AXI_BREADY(S_AXI_BREADY),
|
| 171 |
+
.S_AXI_BRESP(S_AXI_BRESP),
|
| 172 |
+
|
| 173 |
+
// Read Address Channel
|
| 174 |
+
.S_AXI_ARADDR(S_AXI_ARADDR),
|
| 175 |
+
.S_AXI_ARCACHE(S_AXI_ARCACHE),
|
| 176 |
+
.S_AXI_ARPROT(S_AXI_ARPROT),
|
| 177 |
+
.S_AXI_ARVALID(S_AXI_ARVALID),
|
| 178 |
+
.S_AXI_ARREADY(S_AXI_ARREADY),
|
| 179 |
+
|
| 180 |
+
// Read Data Channel
|
| 181 |
+
.S_AXI_RDATA(S_AXI_RDATA),
|
| 182 |
+
.S_AXI_RRESP(S_AXI_RRESP),
|
| 183 |
+
.S_AXI_RVALID(S_AXI_RVALID),
|
| 184 |
+
.S_AXI_RREADY(S_AXI_RREADY),
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
.M_AXI_ACLK(ACLK),
|
| 188 |
+
|
| 189 |
+
// Master Write Address
|
| 190 |
+
.M_AXI_AWID(M_AXI_AWID),
|
| 191 |
+
.M_AXI_AWADDR(M_AXI_AWADDR),
|
| 192 |
+
.M_AXI_AWLEN(M_AXI_AWLEN),
|
| 193 |
+
.M_AXI_AWSIZE(M_AXI_AWSIZE),
|
| 194 |
+
.M_AXI_AWBURST(M_AXI_AWBURST),
|
| 195 |
+
.M_AXI_AWLOCK(M_AXI_AWLOCK),
|
| 196 |
+
.M_AXI_AWCACHE(M_AXI_AWCACHE),
|
| 197 |
+
.M_AXI_AWPROT(M_AXI_AWPROT),
|
| 198 |
+
.M_AXI_AWQOS(M_AXI_AWQOS),
|
| 199 |
+
.M_AXI_AWUSER(M_AXI_AWUSER),
|
| 200 |
+
.M_AXI_AWVALID(M_AXI_AWVALID),
|
| 201 |
+
.M_AXI_AWREADY(M_AXI_AWREADY),
|
| 202 |
+
|
| 203 |
+
// Master Write Data
|
| 204 |
+
.M_AXI_WDATA(M_AXI_WDATA),
|
| 205 |
+
.M_AXI_WSTRB(M_AXI_WSTRB),
|
| 206 |
+
.M_AXI_WLAST(M_AXI_WLAST),
|
| 207 |
+
.M_AXI_WUSER(M_AXI_WUSER),
|
| 208 |
+
.M_AXI_WVALID(M_AXI_WVALID),
|
| 209 |
+
.M_AXI_WREADY(M_AXI_WREADY),
|
| 210 |
+
|
| 211 |
+
// Master Write Response
|
| 212 |
+
.M_AXI_BID(M_AXI_BID),
|
| 213 |
+
.M_AXI_BRESP(M_AXI_BRESP),
|
| 214 |
+
.M_AXI_BUSER(M_AXI_BUSER),
|
| 215 |
+
.M_AXI_BVALID(M_AXI_BVALID),
|
| 216 |
+
.M_AXI_BREADY(M_AXI_BREADY),
|
| 217 |
+
|
| 218 |
+
// Master Read Address
|
| 219 |
+
.M_AXI_ARID(M_AXI_ARID),
|
| 220 |
+
.M_AXI_ARADDR(M_AXI_ARADDR),
|
| 221 |
+
.M_AXI_ARLEN(M_AXI_ARLEN),
|
| 222 |
+
.M_AXI_ARSIZE(M_AXI_ARSIZE),
|
| 223 |
+
.M_AXI_ARBURST(M_AXI_ARBURST),
|
| 224 |
+
.M_AXI_ARLOCK(M_AXI_ARLOCK),
|
| 225 |
+
.M_AXI_ARCACHE(M_AXI_ARCACHE),
|
| 226 |
+
.M_AXI_ARPROT(M_AXI_ARPROT),
|
| 227 |
+
.M_AXI_ARQOS(M_AXI_ARQOS),
|
| 228 |
+
.M_AXI_ARUSER(M_AXI_ARUSER),
|
| 229 |
+
.M_AXI_ARVALID(M_AXI_ARVALID),
|
| 230 |
+
.M_AXI_ARREADY(M_AXI_ARREADY),
|
| 231 |
+
|
| 232 |
+
// Master Read Data
|
| 233 |
+
.M_AXI_RID(M_AXI_RID),
|
| 234 |
+
.M_AXI_RDATA(M_AXI_RDATA),
|
| 235 |
+
.M_AXI_RRESP(M_AXI_RRESP),
|
| 236 |
+
.M_AXI_RLAST(M_AXI_RLAST),
|
| 237 |
+
.M_AXI_RUSER(M_AXI_RUSER),
|
| 238 |
+
.M_AXI_RVALID(M_AXI_RVALID),
|
| 239 |
+
.M_AXI_RREADY(M_AXI_RREADY),
|
| 240 |
+
|
| 241 |
+
.FIFO_RST(FIFO_RST),
|
| 242 |
+
|
| 243 |
+
.FIFO_RD_CLK(ACLK),
|
| 244 |
+
.FIFO_RD_EN(fifo_we),
|
| 245 |
+
.FIFO_DOUT(FIFO_DOUT),
|
| 246 |
+
.FIFO_EMPTY(FIFO_EMPTY),
|
| 247 |
+
|
| 248 |
+
.FIFO_WR_CLK(ACLK),
|
| 249 |
+
.FIFO_DIN(FIFO_DOUT),
|
| 250 |
+
.FIFO_WR_EN(fifo_we),
|
| 251 |
+
.FIFO_FULL(FIFO_FULL),
|
| 252 |
+
|
| 253 |
+
.DEBUG(DEBUG)
|
| 254 |
+
);
|
| 255 |
+
|
| 256 |
+
reg fifo_we_ena;
|
| 257 |
+
initial begin
|
| 258 |
+
fifo_we_ena <= 0;
|
| 259 |
+
|
| 260 |
+
wait(!FIFO_EMPTY);
|
| 261 |
+
|
| 262 |
+
end
|
| 263 |
+
|
| 264 |
+
assign fifo_we = (fifo_we_ena)?~FIFO_EMPTY:1'b0;
|
| 265 |
+
|
| 266 |
+
initial begin
|
| 267 |
+
ACLK <=1'b0;
|
| 268 |
+
end
|
| 269 |
+
|
| 270 |
+
// Clock
|
| 271 |
+
always begin
|
| 272 |
+
#(CLK10N/2) ACLK <= ~ACLK;
|
| 273 |
+
end
|
| 274 |
+
|
| 275 |
+
// Reset
|
| 276 |
+
initial begin
|
| 277 |
+
ARESETN <= 1'b0;
|
| 278 |
+
#(100);
|
| 279 |
+
ARESETN <= 1'b1;
|
| 280 |
+
end
|
| 281 |
+
|
| 282 |
+
assign S_AXI_BREADY = S_AXI_BVALID;
|
| 283 |
+
|
| 284 |
+
// Read Control
|
| 285 |
+
initial begin
|
| 286 |
+
S_AXI_AWADDR <= 32'h4000_0000;
|
| 287 |
+
S_AXI_AWCACHE <= 3'd0;
|
| 288 |
+
S_AXI_AWPROT <= 2'd0;
|
| 289 |
+
S_AXI_AWVALID <= 1'b0;
|
| 290 |
+
S_AXI_WDATA <= 32'h0000_0000;
|
| 291 |
+
S_AXI_WSTRB <= 4'H0;
|
| 292 |
+
S_AXI_WVALID <= 1'b0;
|
| 293 |
+
|
| 294 |
+
wait (ARESETN);
|
| 295 |
+
|
| 296 |
+
@(negedge ACLK);
|
| 297 |
+
@(negedge ACLK);
|
| 298 |
+
|
| 299 |
+
// Read Count
|
| 300 |
+
@(negedge ACLK);
|
| 301 |
+
|
| 302 |
+
S_AXI_AWADDR <= 32'h4000_0014;
|
| 303 |
+
S_AXI_AWVALID <= 1'b1;
|
| 304 |
+
|
| 305 |
+
@(negedge ACLK);
|
| 306 |
+
|
| 307 |
+
wait(S_AXI_AWREADY);
|
| 308 |
+
S_AXI_AWVALID <= 1'b0;
|
| 309 |
+
|
| 310 |
+
@(negedge ACLK);
|
| 311 |
+
|
| 312 |
+
S_AXI_WDATA <= 32'h0000_2000;
|
| 313 |
+
S_AXI_WSTRB <= 4'HF;
|
| 314 |
+
S_AXI_WVALID <= 1'b1;
|
| 315 |
+
|
| 316 |
+
wait(S_AXI_WREADY);
|
| 317 |
+
|
| 318 |
+
@(negedge ACLK);
|
| 319 |
+
|
| 320 |
+
S_AXI_WVALID <= 1'b0;
|
| 321 |
+
|
| 322 |
+
@(negedge ACLK);
|
| 323 |
+
//
|
| 324 |
+
|
| 325 |
+
// Read Address
|
| 326 |
+
@(negedge ACLK);
|
| 327 |
+
|
| 328 |
+
S_AXI_AWADDR <= 32'h4000_0010;
|
| 329 |
+
S_AXI_AWVALID <= 1'b1;
|
| 330 |
+
|
| 331 |
+
@(negedge ACLK);
|
| 332 |
+
|
| 333 |
+
wait(S_AXI_AWREADY);
|
| 334 |
+
S_AXI_AWVALID <= 1'b0;
|
| 335 |
+
|
| 336 |
+
@(negedge ACLK);
|
| 337 |
+
|
| 338 |
+
S_AXI_WDATA <= 32'h3322_1100;
|
| 339 |
+
S_AXI_WSTRB <= 4'HF;
|
| 340 |
+
S_AXI_WVALID <= 1'b1;
|
| 341 |
+
|
| 342 |
+
wait(S_AXI_WREADY);
|
| 343 |
+
|
| 344 |
+
@(negedge ACLK);
|
| 345 |
+
|
| 346 |
+
S_AXI_WVALID <= 1'b0;
|
| 347 |
+
|
| 348 |
+
@(negedge ACLK);
|
| 349 |
+
//
|
| 350 |
+
|
| 351 |
+
// Start Read
|
| 352 |
+
@(negedge ACLK);
|
| 353 |
+
|
| 354 |
+
S_AXI_AWADDR <= 32'h4000_000C;
|
| 355 |
+
S_AXI_AWVALID <= 1'b1;
|
| 356 |
+
|
| 357 |
+
@(negedge ACLK);
|
| 358 |
+
|
| 359 |
+
wait(S_AXI_AWREADY);
|
| 360 |
+
S_AXI_AWVALID <= 1'b0;
|
| 361 |
+
|
| 362 |
+
@(negedge ACLK);
|
| 363 |
+
|
| 364 |
+
S_AXI_WDATA <= 32'h0000_0001;
|
| 365 |
+
S_AXI_WSTRB <= 4'HF;
|
| 366 |
+
S_AXI_WVALID <= 1'b1;
|
| 367 |
+
|
| 368 |
+
wait(S_AXI_WREADY);
|
| 369 |
+
|
| 370 |
+
@(negedge ACLK);
|
| 371 |
+
|
| 372 |
+
S_AXI_WVALID <= 1'b0;
|
| 373 |
+
|
| 374 |
+
@(negedge ACLK);
|
| 375 |
+
//
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
end
|
| 379 |
+
|
| 380 |
+
initial begin
|
| 381 |
+
RD_FIFO_FULL <= 1'b0;
|
| 382 |
+
end
|
| 383 |
+
|
| 384 |
+
// Write Control
|
| 385 |
+
initial begin
|
| 386 |
+
WR_START <= 1'b0;
|
| 387 |
+
WR_ADRS <= 32'd0;
|
| 388 |
+
WR_LEN <= 16'd0;
|
| 389 |
+
|
| 390 |
+
wait (ARESETN);
|
| 391 |
+
|
| 392 |
+
@(negedge ACLK);
|
| 393 |
+
@(negedge ACLK);
|
| 394 |
+
@(negedge ACLK);
|
| 395 |
+
|
| 396 |
+
WR_START <= 1'b1;
|
| 397 |
+
WR_ADRS <= 32'h1C800000;
|
| 398 |
+
WR_LEN <= 16'd8;
|
| 399 |
+
|
| 400 |
+
@(negedge ACLK);
|
| 401 |
+
|
| 402 |
+
WR_START <= 1'b0;
|
| 403 |
+
|
| 404 |
+
@(negedge ACLK);
|
| 405 |
+
@(negedge ACLK);
|
| 406 |
+
|
| 407 |
+
@(negedge ACLK);
|
| 408 |
+
@(negedge ACLK);
|
| 409 |
+
@(negedge ACLK);
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
end
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
// AXI Read Data
|
| 417 |
+
assign M_AXI_ARREADY = M_AXI_ARVALID;
|
| 418 |
+
|
| 419 |
+
reg [31:0] count,rcount;
|
| 420 |
+
always @(posedge ACLK or negedge ARESETN) begin
|
| 421 |
+
if(!ARESETN) begin
|
| 422 |
+
count <= 32'd0;
|
| 423 |
+
rcount <= 32'd0;
|
| 424 |
+
M_AXI_RVALID<=1'b0;
|
| 425 |
+
end else begin
|
| 426 |
+
if(M_AXI_RLAST) begin
|
| 427 |
+
axi_rena <= 0;
|
| 428 |
+
end else if(M_AXI_ARVALID) begin
|
| 429 |
+
axi_rena <= 1;
|
| 430 |
+
end
|
| 431 |
+
|
| 432 |
+
if(axi_rena) begin
|
| 433 |
+
count <= count + 32'd1;
|
| 434 |
+
end else begin
|
| 435 |
+
count <= 0;
|
| 436 |
+
end
|
| 437 |
+
|
| 438 |
+
if(M_AXI_RVALID & M_AXI_RREADY) begin
|
| 439 |
+
rcount <= rcount + 32'd1;
|
| 440 |
+
end
|
| 441 |
+
end
|
| 442 |
+
end
|
| 443 |
+
assign M_AXI_RDATA = {rcount,rcount};
|
| 444 |
+
assign M_AXI_RLAST = (axi_rena & (count == 255))?1:0;
|
| 445 |
+
assign M_AXI_RVALID = axi_rena;
|
| 446 |
+
|
| 447 |
+
// AXI Write Control
|
| 448 |
+
initial begin
|
| 449 |
+
|
| 450 |
+
M_AXI_BID <= 1'b0;
|
| 451 |
+
M_AXI_BRESP <= 2'b00;
|
| 452 |
+
M_AXI_BUSER <= 1'b0;
|
| 453 |
+
|
| 454 |
+
end
|
| 455 |
+
|
| 456 |
+
always @(posedge ACLK or negedge ARESETN)begin
|
| 457 |
+
if(!ARESETN) begin
|
| 458 |
+
axiwvalid <= 0;
|
| 459 |
+
end else begin
|
| 460 |
+
if(M_AXI_BREADY) begin
|
| 461 |
+
axiwvalid <= 0;
|
| 462 |
+
end else if (M_AXI_WVALID & M_AXI_WLAST) begin
|
| 463 |
+
axiwvalid <= 1;
|
| 464 |
+
end
|
| 465 |
+
end
|
| 466 |
+
end
|
| 467 |
+
|
| 468 |
+
assign M_AXI_AWREADY = M_AXI_AWVALID;
|
| 469 |
+
assign M_AXI_WREADY = M_AXI_WVALID;
|
| 470 |
+
assign M_AXI_BVALID = axi_wvalid;
|
| 471 |
+
|
| 472 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sim/tb_aq_axi_master.v
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ns / 100ps
|
| 20 |
+
module tb_aq_axi_master;
|
| 21 |
+
|
| 22 |
+
// Reset, Clock
|
| 23 |
+
reg ARESETN;
|
| 24 |
+
reg ACLK;
|
| 25 |
+
|
| 26 |
+
// Master Write Address
|
| 27 |
+
wire [0:0] M_AXI_AWID;
|
| 28 |
+
wire [31:0] M_AXI_AWADDR;
|
| 29 |
+
wire [7:0] M_AXI_AWLEN;
|
| 30 |
+
wire [2:0] M_AXI_AWSIZE;
|
| 31 |
+
wire [1:0] M_AXI_AWBURST;
|
| 32 |
+
wire M_AXI_AWLOCK;
|
| 33 |
+
wire [3:0] M_AXI_AWCACHE;
|
| 34 |
+
wire [2:0] M_AXI_AWPROT;
|
| 35 |
+
wire [3:0] M_AXI_AWQOS;
|
| 36 |
+
wire [0:0] M_AXI_AWUSER;
|
| 37 |
+
wire M_AXI_AWVALID;
|
| 38 |
+
reg M_AXI_AWREADY;
|
| 39 |
+
|
| 40 |
+
// Master Write Data
|
| 41 |
+
wire [63:0] M_AXI_WDATA;
|
| 42 |
+
wire [2:0] M_AXI_WSTRB;
|
| 43 |
+
wire M_AXI_WLAST;
|
| 44 |
+
wire [0:0] M_AXI_WUSER;
|
| 45 |
+
wire M_AXI_WVALID;
|
| 46 |
+
reg M_AXI_WREADY;
|
| 47 |
+
|
| 48 |
+
// Master Write Response
|
| 49 |
+
reg [0:0] M_AXI_BID;
|
| 50 |
+
reg [1:0] M_AXI_BRESP;
|
| 51 |
+
reg [0:0] M_AXI_BUSER;
|
| 52 |
+
reg M_AXI_BVALID;
|
| 53 |
+
wire M_AXI_BREADY;
|
| 54 |
+
|
| 55 |
+
// Master Read Address
|
| 56 |
+
wire [0:0] M_AXI_ARID;
|
| 57 |
+
wire [31:0] M_AXI_ARADDR;
|
| 58 |
+
wire [7:0] M_AXI_ARLEN;
|
| 59 |
+
wire [2:0] M_AXI_ARSIZE;
|
| 60 |
+
wire [1:0] M_AXI_ARBURST;
|
| 61 |
+
wire [1:0] M_AXI_ARLOCK;
|
| 62 |
+
wire [3:0] M_AXI_ARCACHE;
|
| 63 |
+
wire [2:0] M_AXI_ARPROT;
|
| 64 |
+
wire [3:0] M_AXI_ARQOS;
|
| 65 |
+
wire [0:0] M_AXI_ARUSER;
|
| 66 |
+
wire M_AXI_ARVALID;
|
| 67 |
+
reg M_AXI_ARREADY;
|
| 68 |
+
|
| 69 |
+
// Master Read Data
|
| 70 |
+
reg [0:0] M_AXI_RID;
|
| 71 |
+
reg [63:0] M_AXI_RDATA;
|
| 72 |
+
reg [1:0] M_AXI_RRESP;
|
| 73 |
+
reg M_AXI_RLAST;
|
| 74 |
+
reg [0:0] M_AXI_RUSER;
|
| 75 |
+
reg M_AXI_RVALID;
|
| 76 |
+
wire M_AXI_RREADY;
|
| 77 |
+
|
| 78 |
+
// Local Bus
|
| 79 |
+
reg WR_START;
|
| 80 |
+
reg [31:0] WR_ADRS;
|
| 81 |
+
reg [15:0] WR_LEN;
|
| 82 |
+
wire WR_READY;
|
| 83 |
+
wire WR_FIFO_RE;
|
| 84 |
+
reg WR_FIFO_EMPTY;
|
| 85 |
+
reg [63:0] WR_FIFO_DATA;
|
| 86 |
+
|
| 87 |
+
reg RD_START;
|
| 88 |
+
reg [31:0] RD_ADRS;
|
| 89 |
+
reg [15:0] RD_LEN;
|
| 90 |
+
wire RD_READY;
|
| 91 |
+
wire RD_FIFO_WE;
|
| 92 |
+
reg RD_FIFO_FULL;
|
| 93 |
+
wire [63:0] RD_FIFO_DATA;
|
| 94 |
+
|
| 95 |
+
wire [31:0] DEBUG;
|
| 96 |
+
|
| 97 |
+
parameter CLK10N = 10;
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
aq_axi_master u_aq_axi_master(
|
| 101 |
+
// Reset, Clock
|
| 102 |
+
.ARESETN(ARESETN),
|
| 103 |
+
.ACLK(ACLK),
|
| 104 |
+
|
| 105 |
+
// Master Write Address
|
| 106 |
+
.M_AXI_AWID(M_AXI_AWID),
|
| 107 |
+
.M_AXI_AWADDR(M_AXI_AWADDR),
|
| 108 |
+
.M_AXI_AWLEN(M_AXI_AWLEN),
|
| 109 |
+
.M_AXI_AWSIZE(M_AXI_AWSIZE),
|
| 110 |
+
.M_AXI_AWBURST(M_AXI_AWBURST),
|
| 111 |
+
.M_AXI_AWLOCK(M_AXI_AWLOCK),
|
| 112 |
+
.M_AXI_AWCACHE(M_AXI_AWCACHE),
|
| 113 |
+
.M_AXI_AWPROT(M_AXI_AWPROT),
|
| 114 |
+
.M_AXI_AWQOS(M_AXI_AWQOS),
|
| 115 |
+
.M_AXI_AWUSER(M_AXI_AWUSER),
|
| 116 |
+
.M_AXI_AWVALID(M_AXI_AWVALID),
|
| 117 |
+
.M_AXI_AWREADY(M_AXI_AWREADY),
|
| 118 |
+
|
| 119 |
+
// Master Write Data
|
| 120 |
+
.M_AXI_WDATA(M_AXI_WDATA),
|
| 121 |
+
.M_AXI_WSTRB(M_AXI_WSTRB),
|
| 122 |
+
.M_AXI_WLAST(M_AXI_WLAST),
|
| 123 |
+
.M_AXI_WUSER(M_AXI_WUSER),
|
| 124 |
+
.M_AXI_WVALID(M_AXI_WVALID),
|
| 125 |
+
.M_AXI_WREADY(M_AXI_WREADY),
|
| 126 |
+
|
| 127 |
+
// Master Write Response
|
| 128 |
+
.M_AXI_BID(M_AXI_BID),
|
| 129 |
+
.M_AXI_BRESP(M_AXI_BRESP),
|
| 130 |
+
.M_AXI_BUSER(M_AXI_BUSER),
|
| 131 |
+
.M_AXI_BVALID(M_AXI_BVALID),
|
| 132 |
+
.M_AXI_BREADY(M_AXI_BREADY),
|
| 133 |
+
|
| 134 |
+
// Master Read Address
|
| 135 |
+
.M_AXI_ARID(M_AXI_ARID),
|
| 136 |
+
.M_AXI_ARADDR(M_AXI_ARADDR),
|
| 137 |
+
.M_AXI_ARLEN(M_AXI_ARLEN),
|
| 138 |
+
.M_AXI_ARSIZE(M_AXI_ARSIZE),
|
| 139 |
+
.M_AXI_ARBURST(M_AXI_ARBURST),
|
| 140 |
+
.M_AXI_ARLOCK(M_AXI_ARLOCK),
|
| 141 |
+
.M_AXI_ARCACHE(M_AXI_ARCACHE),
|
| 142 |
+
.M_AXI_ARPROT(M_AXI_ARPROT),
|
| 143 |
+
.M_AXI_ARQOS(M_AXI_ARQOS),
|
| 144 |
+
.M_AXI_ARUSER(M_AXI_ARUSER),
|
| 145 |
+
.M_AXI_ARVALID(M_AXI_ARVALID),
|
| 146 |
+
.M_AXI_ARREADY(M_AXI_ARREADY),
|
| 147 |
+
|
| 148 |
+
// Master Read Data
|
| 149 |
+
.M_AXI_RID(M_AXI_RID),
|
| 150 |
+
.M_AXI_RDATA(M_AXI_RDATA),
|
| 151 |
+
.M_AXI_RRESP(M_AXI_RRESP),
|
| 152 |
+
.M_AXI_RLAST(M_AXI_RLAST),
|
| 153 |
+
.M_AXI_RUSER(M_AXI_RUSER),
|
| 154 |
+
.M_AXI_RVALID(M_AXI_RVALID),
|
| 155 |
+
.M_AXI_RREADY(M_AXI_RREADY),
|
| 156 |
+
|
| 157 |
+
// Local Bus
|
| 158 |
+
.WR_START(WR_START),
|
| 159 |
+
.WR_ADRS(WR_ADRS),
|
| 160 |
+
.WR_LEN(WR_LEN),
|
| 161 |
+
.WR_READY(WR_READY),
|
| 162 |
+
.WR_FIFO_RE(WR_FIFO_RE),
|
| 163 |
+
.WR_FIFO_EMPTY(WR_FIFO_EMPTY),
|
| 164 |
+
.WR_FIFO_DATA(WR_FIFO_DATA),
|
| 165 |
+
|
| 166 |
+
.RD_START(RD_START),
|
| 167 |
+
.RD_ADRS(RD_ADRS),
|
| 168 |
+
.RD_LEN(RD_LEN),
|
| 169 |
+
.RD_READY(RD_READY),
|
| 170 |
+
.RD_FIFO_WE(RD_FIFO_WE),
|
| 171 |
+
.RD_FIFO_FULL(RD_FIFO_FULL),
|
| 172 |
+
.RD_FIFO_DATA(RD_FIFO_DATA),
|
| 173 |
+
|
| 174 |
+
.DEBUG(DEBUG)
|
| 175 |
+
);
|
| 176 |
+
|
| 177 |
+
initial begin
|
| 178 |
+
ACLK <=1'b0;
|
| 179 |
+
end
|
| 180 |
+
|
| 181 |
+
// Clock
|
| 182 |
+
always begin
|
| 183 |
+
#(CLK10N/2) ACLK <= ~ACLK;
|
| 184 |
+
end
|
| 185 |
+
|
| 186 |
+
// Reset
|
| 187 |
+
initial begin
|
| 188 |
+
ARESETN <= 1'b0;
|
| 189 |
+
#(100);
|
| 190 |
+
ARESETN <= 1'b1;
|
| 191 |
+
end
|
| 192 |
+
|
| 193 |
+
// Read Control
|
| 194 |
+
initial begin
|
| 195 |
+
RD_START <= 1'b0;
|
| 196 |
+
RD_ADRS <= 32'd0;
|
| 197 |
+
RD_LEN <= 16'd0;
|
| 198 |
+
|
| 199 |
+
wait (ARESETN);
|
| 200 |
+
|
| 201 |
+
@(negedge ACLK);
|
| 202 |
+
@(negedge ACLK);
|
| 203 |
+
@(negedge ACLK);
|
| 204 |
+
|
| 205 |
+
RD_START <= 1'b0;
|
| 206 |
+
RD_ADRS <= 32'h1C000000;
|
| 207 |
+
RD_LEN <= 16'd8;
|
| 208 |
+
|
| 209 |
+
@(negedge ACLK);
|
| 210 |
+
|
| 211 |
+
RD_START <= 1'b0;
|
| 212 |
+
RD_ADRS <= 32'd0;
|
| 213 |
+
RD_LEN <= 16'd0;
|
| 214 |
+
|
| 215 |
+
@(negedge ACLK);
|
| 216 |
+
|
| 217 |
+
end
|
| 218 |
+
|
| 219 |
+
initial begin
|
| 220 |
+
RD_FIFO_FULL <= 1'b0;
|
| 221 |
+
end
|
| 222 |
+
|
| 223 |
+
// Write Control
|
| 224 |
+
initial begin
|
| 225 |
+
WR_START <= 1'b0;
|
| 226 |
+
WR_ADRS <= 32'd0;
|
| 227 |
+
WR_LEN <= 16'd0;
|
| 228 |
+
|
| 229 |
+
wait (ARESETN);
|
| 230 |
+
|
| 231 |
+
@(negedge ACLK);
|
| 232 |
+
@(negedge ACLK);
|
| 233 |
+
@(negedge ACLK);
|
| 234 |
+
|
| 235 |
+
WR_START <= 1'b1;
|
| 236 |
+
WR_ADRS <= 32'h1C800000;
|
| 237 |
+
WR_LEN <= 16'd8;
|
| 238 |
+
|
| 239 |
+
@(negedge ACLK);
|
| 240 |
+
|
| 241 |
+
WR_START <= 1'b0;
|
| 242 |
+
|
| 243 |
+
@(negedge ACLK);
|
| 244 |
+
@(negedge ACLK);
|
| 245 |
+
|
| 246 |
+
@(negedge ACLK);
|
| 247 |
+
@(negedge ACLK);
|
| 248 |
+
@(negedge ACLK);
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
end
|
| 252 |
+
|
| 253 |
+
initial begin
|
| 254 |
+
WR_FIFO_EMPTY <= 1'b0;
|
| 255 |
+
WR_FIFO_DATA <= 64'h0000_0000_0000_0000;
|
| 256 |
+
|
| 257 |
+
wait (ARESETN);
|
| 258 |
+
|
| 259 |
+
@(negedge ACLK);
|
| 260 |
+
@(negedge ACLK);
|
| 261 |
+
@(negedge ACLK);
|
| 262 |
+
|
| 263 |
+
WR_FIFO_DATA <= 64'h3333_2222_1111_1010;
|
| 264 |
+
|
| 265 |
+
wait(WR_FIFO_RE);
|
| 266 |
+
|
| 267 |
+
WR_FIFO_DATA <= 64'h4444_3333_2222_1111;
|
| 268 |
+
|
| 269 |
+
wait(WR_FIFO_RE);
|
| 270 |
+
|
| 271 |
+
WR_FIFO_DATA <= 64'h5555_4444_3333_2222;
|
| 272 |
+
|
| 273 |
+
wait(WR_FIFO_RE);
|
| 274 |
+
|
| 275 |
+
WR_FIFO_DATA <= 64'h6666_5555_4444_3333;
|
| 276 |
+
|
| 277 |
+
end
|
| 278 |
+
|
| 279 |
+
// AXI Read Control
|
| 280 |
+
initial begin
|
| 281 |
+
|
| 282 |
+
M_AXI_ARREADY <= 1'b0;
|
| 283 |
+
|
| 284 |
+
wait (ARESETN);
|
| 285 |
+
|
| 286 |
+
@(negedge ACLK);
|
| 287 |
+
@(negedge ACLK);
|
| 288 |
+
@(negedge ACLK);
|
| 289 |
+
|
| 290 |
+
wait(M_AXI_ARVALID);
|
| 291 |
+
|
| 292 |
+
@(negedge ACLK);
|
| 293 |
+
|
| 294 |
+
M_AXI_ARREADY <= 1'b1;
|
| 295 |
+
|
| 296 |
+
@(negedge ACLK);
|
| 297 |
+
|
| 298 |
+
M_AXI_ARREADY <= 1'b0;
|
| 299 |
+
|
| 300 |
+
@(negedge ACLK);
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
end
|
| 305 |
+
|
| 306 |
+
// AXI Write Control
|
| 307 |
+
initial begin
|
| 308 |
+
|
| 309 |
+
M_AXI_AWREADY <= 1'b0;
|
| 310 |
+
M_AXI_WREADY <= 1'b0;
|
| 311 |
+
M_AXI_BID <= 1'b0;
|
| 312 |
+
M_AXI_BRESP <= 2'b00;
|
| 313 |
+
M_AXI_BUSER <= 1'b0;
|
| 314 |
+
M_AXI_BVALID <= 1'b0;
|
| 315 |
+
|
| 316 |
+
wait (ARESETN);
|
| 317 |
+
|
| 318 |
+
@(negedge ACLK);
|
| 319 |
+
@(negedge ACLK);
|
| 320 |
+
@(negedge ACLK);
|
| 321 |
+
|
| 322 |
+
wait(M_AXI_AWVALID);
|
| 323 |
+
|
| 324 |
+
@(negedge ACLK);
|
| 325 |
+
|
| 326 |
+
M_AXI_AWREADY <= 1'b1;
|
| 327 |
+
|
| 328 |
+
@(negedge ACLK);
|
| 329 |
+
|
| 330 |
+
M_AXI_AWREADY <= 1'b0;
|
| 331 |
+
|
| 332 |
+
wait(M_AXI_WVALID);
|
| 333 |
+
|
| 334 |
+
@(negedge ACLK);
|
| 335 |
+
|
| 336 |
+
M_AXI_WREADY <= 1'b1;
|
| 337 |
+
|
| 338 |
+
@(negedge ACLK);
|
| 339 |
+
|
| 340 |
+
M_AXI_WREADY <= 1'b0;
|
| 341 |
+
|
| 342 |
+
@(negedge ACLK);
|
| 343 |
+
|
| 344 |
+
M_AXI_BID <= 1'b0;
|
| 345 |
+
M_AXI_BRESP <= 2'b00;
|
| 346 |
+
M_AXI_BUSER <= 1'b0;
|
| 347 |
+
|
| 348 |
+
wait(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4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ns / 1ps
|
| 20 |
+
module tb_aq_fifo;
|
| 21 |
+
|
| 22 |
+
reg RST;
|
| 23 |
+
|
| 24 |
+
reg WRCLK;
|
| 25 |
+
reg WREN;
|
| 26 |
+
reg [63:0] DI;
|
| 27 |
+
wire FULL;
|
| 28 |
+
wire AFULL;
|
| 29 |
+
wire [7:0] WRCOUNT;
|
| 30 |
+
|
| 31 |
+
reg RDCLK;
|
| 32 |
+
reg RDEN;
|
| 33 |
+
wire [63:0] DO;
|
| 34 |
+
wire EMPTY;
|
| 35 |
+
wire AEMPTY;
|
| 36 |
+
wire [7:0] RDCOUNT;
|
| 37 |
+
|
| 38 |
+
aq_fifo u_aq_rfifo
|
| 39 |
+
(
|
| 40 |
+
.RST(RST),
|
| 41 |
+
|
| 42 |
+
.WRCLK(WRCLK),
|
| 43 |
+
.WREN(WREN),
|
| 44 |
+
.DI(DI),
|
| 45 |
+
.FULL(FULL),
|
| 46 |
+
.AFULL(AFULL),
|
| 47 |
+
.WRCOUNT(WRCOUNT),
|
| 48 |
+
|
| 49 |
+
.RDCLK(RDCLK),
|
| 50 |
+
.RDEN(RDEN),
|
| 51 |
+
.DO(DO),
|
| 52 |
+
.EMPTY(EMPTY),
|
| 53 |
+
.AEMPTY(AEMPTY),
|
| 54 |
+
.RDCOUNT(RDCOUNT)
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
// Clock
|
| 58 |
+
initial begin
|
| 59 |
+
WRCLK <= 1'b0;
|
| 60 |
+
RDCLK <= 1'b0;
|
| 61 |
+
end
|
| 62 |
+
|
| 63 |
+
parameter CLK100N = 10;
|
| 64 |
+
|
| 65 |
+
always begin
|
| 66 |
+
#(CLK100N/2) WRCLK <= ~WRCLK;
|
| 67 |
+
end
|
| 68 |
+
always begin
|
| 69 |
+
#(CLK100N/2) RDCLK <= ~RDCLK;
|
| 70 |
+
end
|
| 71 |
+
|
| 72 |
+
// Reset
|
| 73 |
+
initial begin
|
| 74 |
+
RST <= 1'b0;
|
| 75 |
+
#(1000);
|
| 76 |
+
RST <= 1'b1;
|
| 77 |
+
#(1000);
|
| 78 |
+
RST <= 1'b0;
|
| 79 |
+
end
|
| 80 |
+
|
| 81 |
+
// Signal
|
| 82 |
+
integer wrcount, rdcount;
|
| 83 |
+
|
| 84 |
+
always @(negedge WRCLK or posedge RST) begin
|
| 85 |
+
if(RST) begin
|
| 86 |
+
wrcount <= 0;
|
| 87 |
+
WREN <= 1'b0;
|
| 88 |
+
DI <= 64'd0;
|
| 89 |
+
end else begin
|
| 90 |
+
wrcount <= wrcount +1;
|
| 91 |
+
if((wrcount >= 100) && (wrcount < 1024+100-256)) begin
|
| 92 |
+
WREN <= 1'b1;
|
| 93 |
+
DI <= DI + 64'd1;
|
| 94 |
+
end else begin
|
| 95 |
+
WREN <= 1'b0;
|
| 96 |
+
DI <= 64'd0;
|
| 97 |
+
end
|
| 98 |
+
end
|
| 99 |
+
end
|
| 100 |
+
|
| 101 |
+
always @(negedge RDCLK or posedge RST) begin
|
| 102 |
+
if(RST) begin
|
| 103 |
+
rdcount <= 0;
|
| 104 |
+
RDEN <= 1'b0;
|
| 105 |
+
end else begin
|
| 106 |
+
end
|
| 107 |
+
end
|
| 108 |
+
|
| 109 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sources/aq_axi_fifo.v
ADDED
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
module aq_axi_fifo
|
| 20 |
+
#(
|
| 21 |
+
parameter C_BASEADRS = 32'h4000_0000,
|
| 22 |
+
parameter C_ADRSWIDTH = 8
|
| 23 |
+
)
|
| 24 |
+
(
|
| 25 |
+
input ARESETN,
|
| 26 |
+
|
| 27 |
+
// --------------------------------------------------
|
| 28 |
+
// AXI4 Lite Interface
|
| 29 |
+
// --------------------------------------------------
|
| 30 |
+
input S_AXI_ACLK,
|
| 31 |
+
|
| 32 |
+
// Write Address Channel
|
| 33 |
+
input [31:0] S_AXI_AWADDR,
|
| 34 |
+
input [3:0] S_AXI_AWCACHE,
|
| 35 |
+
input [2:0] S_AXI_AWPROT,
|
| 36 |
+
input S_AXI_AWVALID,
|
| 37 |
+
output S_AXI_AWREADY,
|
| 38 |
+
|
| 39 |
+
// Write Data Channel
|
| 40 |
+
input [31:0] S_AXI_WDATA,
|
| 41 |
+
input [3:0] S_AXI_WSTRB,
|
| 42 |
+
input S_AXI_WVALID,
|
| 43 |
+
output S_AXI_WREADY,
|
| 44 |
+
|
| 45 |
+
// Write Response Channel
|
| 46 |
+
output S_AXI_BVALID,
|
| 47 |
+
input S_AXI_BREADY,
|
| 48 |
+
output [1:0] S_AXI_BRESP,
|
| 49 |
+
|
| 50 |
+
// Read Address Channel
|
| 51 |
+
input [31:0] S_AXI_ARADDR,
|
| 52 |
+
input [3:0] S_AXI_ARCACHE,
|
| 53 |
+
input [2:0] S_AXI_ARPROT,
|
| 54 |
+
input S_AXI_ARVALID,
|
| 55 |
+
output S_AXI_ARREADY,
|
| 56 |
+
|
| 57 |
+
// Read Data Channel
|
| 58 |
+
output [31:0] S_AXI_RDATA,
|
| 59 |
+
output [1:0] S_AXI_RRESP,
|
| 60 |
+
output S_AXI_RVALID,
|
| 61 |
+
input S_AXI_RREADY,
|
| 62 |
+
|
| 63 |
+
// --------------------------------------------------
|
| 64 |
+
// AXI4 Master
|
| 65 |
+
// --------------------------------------------------
|
| 66 |
+
// Reset, Clock
|
| 67 |
+
input M_AXI_ACLK,
|
| 68 |
+
|
| 69 |
+
// Master Write Address
|
| 70 |
+
output [0:0] M_AXI_AWID,
|
| 71 |
+
output [31:0] M_AXI_AWADDR,
|
| 72 |
+
output [7:0] M_AXI_AWLEN,
|
| 73 |
+
output [2:0] M_AXI_AWSIZE,
|
| 74 |
+
output [1:0] M_AXI_AWBURST,
|
| 75 |
+
output M_AXI_AWLOCK,
|
| 76 |
+
output [3:0] M_AXI_AWCACHE,
|
| 77 |
+
output [2:0] M_AXI_AWPROT,
|
| 78 |
+
output [3:0] M_AXI_AWQOS,
|
| 79 |
+
output [0:0] M_AXI_AWUSER,
|
| 80 |
+
output M_AXI_AWVALID,
|
| 81 |
+
input M_AXI_AWREADY,
|
| 82 |
+
|
| 83 |
+
// Master Write Data
|
| 84 |
+
output [63:0] M_AXI_WDATA,
|
| 85 |
+
output [7:0] M_AXI_WSTRB,
|
| 86 |
+
output M_AXI_WLAST,
|
| 87 |
+
output [0:0] M_AXI_WUSER,
|
| 88 |
+
output M_AXI_WVALID,
|
| 89 |
+
input M_AXI_WREADY,
|
| 90 |
+
|
| 91 |
+
// Master Write Response
|
| 92 |
+
input [0:0] M_AXI_BID,
|
| 93 |
+
input [1:0] M_AXI_BRESP,
|
| 94 |
+
input [0:0] M_AXI_BUSER,
|
| 95 |
+
input M_AXI_BVALID,
|
| 96 |
+
output M_AXI_BREADY,
|
| 97 |
+
|
| 98 |
+
// Master Read Address
|
| 99 |
+
output [0:0] M_AXI_ARID,
|
| 100 |
+
output [31:0] M_AXI_ARADDR,
|
| 101 |
+
output [7:0] M_AXI_ARLEN,
|
| 102 |
+
output [2:0] M_AXI_ARSIZE,
|
| 103 |
+
output [1:0] M_AXI_ARBURST,
|
| 104 |
+
output [1:0] M_AXI_ARLOCK,
|
| 105 |
+
output [3:0] M_AXI_ARCACHE,
|
| 106 |
+
output [2:0] M_AXI_ARPROT,
|
| 107 |
+
output [3:0] M_AXI_ARQOS,
|
| 108 |
+
output [0:0] M_AXI_ARUSER,
|
| 109 |
+
output M_AXI_ARVALID,
|
| 110 |
+
input M_AXI_ARREADY,
|
| 111 |
+
|
| 112 |
+
// Master Read Data
|
| 113 |
+
input [0:0] M_AXI_RID,
|
| 114 |
+
input [63:0] M_AXI_RDATA,
|
| 115 |
+
input [1:0] M_AXI_RRESP,
|
| 116 |
+
input M_AXI_RLAST,
|
| 117 |
+
input [0:0] M_AXI_RUSER,
|
| 118 |
+
input M_AXI_RVALID,
|
| 119 |
+
output M_AXI_RREADY,
|
| 120 |
+
|
| 121 |
+
// FIFO
|
| 122 |
+
output FIFO_RST,
|
| 123 |
+
|
| 124 |
+
input FIFO_RD_CLK,
|
| 125 |
+
input FIFO_RD_EN,
|
| 126 |
+
output [63:0] FIFO_RD_DO,
|
| 127 |
+
output FIFO_RD_EMPTY,
|
| 128 |
+
|
| 129 |
+
input FIFO_WR_CLK,
|
| 130 |
+
input [63:0] FIFO_WR_DI,
|
| 131 |
+
input FIFO_WR_EN,
|
| 132 |
+
output FIFO_WR_FULL,
|
| 133 |
+
|
| 134 |
+
output [31:0] DEBUG
|
| 135 |
+
);
|
| 136 |
+
|
| 137 |
+
wire local_cs;
|
| 138 |
+
wire local_rnw;
|
| 139 |
+
wire local_ack;
|
| 140 |
+
wire [31:0] local_addr;
|
| 141 |
+
wire [3:0] local_be;
|
| 142 |
+
wire [31:0] local_wdata;
|
| 143 |
+
wire [31:0] local_rdata;
|
| 144 |
+
|
| 145 |
+
wire wr_start;
|
| 146 |
+
|
| 147 |
+
wire [31:0] wr_adrs;
|
| 148 |
+
wire [31:0] wr_len;
|
| 149 |
+
wire wr_ready;
|
| 150 |
+
wire wr_fifo_re;
|
| 151 |
+
wire wr_fifo_empty;
|
| 152 |
+
wire wr_fifo_aempty;
|
| 153 |
+
wire [63:0] wr_fifo_data;
|
| 154 |
+
|
| 155 |
+
wire rd_start;
|
| 156 |
+
wire [31:0] rd_adrs;
|
| 157 |
+
wire [31:0] rd_len;
|
| 158 |
+
wire rd_ready;
|
| 159 |
+
wire rd_fifo_we;
|
| 160 |
+
wire rd_fifo_full;
|
| 161 |
+
wire rd_fifo_afull;
|
| 162 |
+
wire [63:0] rd_fifo_data;
|
| 163 |
+
|
| 164 |
+
wire [31:0] master_status;
|
| 165 |
+
|
| 166 |
+
reg [31:0] wr_fifo_wrcnt, wr_fifo_rdcnt, rd_fifo_wrcnt, rd_fifo_rdcnt;
|
| 167 |
+
|
| 168 |
+
wire [31:0] debug_slave, debug_ctl, debug_master;
|
| 169 |
+
|
| 170 |
+
aq_axi_lite_slave
|
| 171 |
+
#(
|
| 172 |
+
.C_BASEADRS(C_BASEADRS),
|
| 173 |
+
.C_ADRSWIDTH(C_ADRSWIDTH)
|
| 174 |
+
)
|
| 175 |
+
u_aq_axi_lite_slave
|
| 176 |
+
(
|
| 177 |
+
.ARESETN(ARESETN),
|
| 178 |
+
.ACLK(S_AXI_ACLK),
|
| 179 |
+
|
| 180 |
+
.S_AXI_AWADDR(S_AXI_AWADDR),
|
| 181 |
+
.S_AXI_AWCACHE(S_AXI_AWCACHE),
|
| 182 |
+
.S_AXI_AWPROT(S_AXI_AWPROT),
|
| 183 |
+
.S_AXI_AWVALID(S_AXI_AWVALID),
|
| 184 |
+
.S_AXI_AWREADY(S_AXI_AWREADY),
|
| 185 |
+
|
| 186 |
+
.S_AXI_WDATA(S_AXI_WDATA),
|
| 187 |
+
.S_AXI_WSTRB(S_AXI_WSTRB),
|
| 188 |
+
.S_AXI_WVALID(S_AXI_WVALID),
|
| 189 |
+
.S_AXI_WREADY(S_AXI_WREADY),
|
| 190 |
+
|
| 191 |
+
.S_AXI_BVALID(S_AXI_BVALID),
|
| 192 |
+
.S_AXI_BREADY(S_AXI_BREADY),
|
| 193 |
+
.S_AXI_BRESP(S_AXI_BRESP),
|
| 194 |
+
|
| 195 |
+
.S_AXI_ARADDR(S_AXI_ARADDR),
|
| 196 |
+
.S_AXI_ARCACHE(S_AXI_ARCACHE),
|
| 197 |
+
.S_AXI_ARPROT(S_AXI_ARPROT),
|
| 198 |
+
.S_AXI_ARVALID(S_AXI_ARVALID),
|
| 199 |
+
.S_AXI_ARREADY(S_AXI_ARREADY),
|
| 200 |
+
|
| 201 |
+
.S_AXI_RDATA(S_AXI_RDATA),
|
| 202 |
+
.S_AXI_RRESP(S_AXI_RRESP),
|
| 203 |
+
.S_AXI_RVALID(S_AXI_RVALID),
|
| 204 |
+
.S_AXI_RREADY(S_AXI_RREADY),
|
| 205 |
+
|
| 206 |
+
.LOCAL_CS(local_cs),
|
| 207 |
+
.LOCAL_RNW(local_rnw),
|
| 208 |
+
.LOCAL_ACK(local_ack),
|
| 209 |
+
.LOCAL_ADDR(local_addr),
|
| 210 |
+
.LOCAL_BE(local_be),
|
| 211 |
+
.LOCAL_WDATA(local_wdata),
|
| 212 |
+
.LOCAL_RDATA(local_rdata),
|
| 213 |
+
|
| 214 |
+
.DEBUG(debug_slave)
|
| 215 |
+
);
|
| 216 |
+
|
| 217 |
+
aq_axi_master u_aq_axi_master
|
| 218 |
+
(
|
| 219 |
+
.ARESETN(ARESETN),
|
| 220 |
+
.ACLK(M_AXI_ACLK),
|
| 221 |
+
|
| 222 |
+
.M_AXI_AWID(M_AXI_AWID),
|
| 223 |
+
.M_AXI_AWADDR(M_AXI_AWADDR),
|
| 224 |
+
.M_AXI_AWLEN(M_AXI_AWLEN),
|
| 225 |
+
.M_AXI_AWSIZE(M_AXI_AWSIZE),
|
| 226 |
+
.M_AXI_AWBURST(M_AXI_AWBURST),
|
| 227 |
+
.M_AXI_AWLOCK(M_AXI_AWLOCK),
|
| 228 |
+
.M_AXI_AWCACHE(M_AXI_AWCACHE),
|
| 229 |
+
.M_AXI_AWPROT(M_AXI_AWPROT),
|
| 230 |
+
.M_AXI_AWQOS(M_AXI_AWQOS),
|
| 231 |
+
.M_AXI_AWUSER(M_AXI_AWUSER),
|
| 232 |
+
.M_AXI_AWVALID(M_AXI_AWVALID),
|
| 233 |
+
.M_AXI_AWREADY(M_AXI_AWREADY),
|
| 234 |
+
|
| 235 |
+
.M_AXI_WDATA(M_AXI_WDATA),
|
| 236 |
+
.M_AXI_WSTRB(M_AXI_WSTRB),
|
| 237 |
+
.M_AXI_WLAST(M_AXI_WLAST),
|
| 238 |
+
.M_AXI_WUSER(M_AXI_WUSER),
|
| 239 |
+
.M_AXI_WVALID(M_AXI_WVALID),
|
| 240 |
+
.M_AXI_WREADY(M_AXI_WREADY),
|
| 241 |
+
|
| 242 |
+
.M_AXI_BID(M_AXI_BID),
|
| 243 |
+
.M_AXI_BRESP(M_AXI_BRESP),
|
| 244 |
+
.M_AXI_BUSER(M_AXI_BUSER),
|
| 245 |
+
.M_AXI_BVALID(M_AXI_BVALID),
|
| 246 |
+
.M_AXI_BREADY(M_AXI_BREADY),
|
| 247 |
+
|
| 248 |
+
.M_AXI_ARID(M_AXI_ARID),
|
| 249 |
+
.M_AXI_ARADDR(M_AXI_ARADDR),
|
| 250 |
+
.M_AXI_ARLEN(M_AXI_ARLEN),
|
| 251 |
+
.M_AXI_ARSIZE(M_AXI_ARSIZE),
|
| 252 |
+
.M_AXI_ARBURST(M_AXI_ARBURST),
|
| 253 |
+
.M_AXI_ARLOCK(M_AXI_ARLOCK),
|
| 254 |
+
.M_AXI_ARCACHE(M_AXI_ARCACHE),
|
| 255 |
+
.M_AXI_ARPROT(M_AXI_ARPROT),
|
| 256 |
+
.M_AXI_ARQOS(M_AXI_ARQOS),
|
| 257 |
+
.M_AXI_ARUSER(M_AXI_ARUSER),
|
| 258 |
+
.M_AXI_ARVALID(M_AXI_ARVALID),
|
| 259 |
+
.M_AXI_ARREADY(M_AXI_ARREADY),
|
| 260 |
+
|
| 261 |
+
.M_AXI_RID(M_AXI_RID),
|
| 262 |
+
.M_AXI_RDATA(M_AXI_RDATA),
|
| 263 |
+
.M_AXI_RRESP(M_AXI_RRESP),
|
| 264 |
+
.M_AXI_RLAST(M_AXI_RLAST),
|
| 265 |
+
.M_AXI_RUSER(M_AXI_RUSER),
|
| 266 |
+
.M_AXI_RVALID(M_AXI_RVALID),
|
| 267 |
+
.M_AXI_RREADY(M_AXI_RREADY),
|
| 268 |
+
|
| 269 |
+
.MASTER_RST(FIFO_RST),
|
| 270 |
+
|
| 271 |
+
.WR_START(wr_start),
|
| 272 |
+
.WR_ADRS(wr_adrs),
|
| 273 |
+
.WR_LEN(wr_len),
|
| 274 |
+
.WR_READY(wr_ready),
|
| 275 |
+
.WR_FIFO_RE(wr_fifo_re),
|
| 276 |
+
.WR_FIFO_EMPTY(wr_fifo_empty),
|
| 277 |
+
.WR_FIFO_AEMPTY(wr_fifo_aempty),
|
| 278 |
+
.WR_FIFO_DATA(wr_fifo_data),
|
| 279 |
+
|
| 280 |
+
.RD_START(rd_start),
|
| 281 |
+
.RD_ADRS(rd_adrs),
|
| 282 |
+
.RD_LEN(rd_len),
|
| 283 |
+
.RD_READY(rd_ready),
|
| 284 |
+
.RD_FIFO_WE(rd_fifo_we),
|
| 285 |
+
.RD_FIFO_FULL(rd_fifo_full),
|
| 286 |
+
.RD_FIFO_AFULL(rd_fifo_afull),
|
| 287 |
+
.RD_FIFO_DATA(rd_fifo_data),
|
| 288 |
+
|
| 289 |
+
.DEBUG(debug_master)
|
| 290 |
+
);
|
| 291 |
+
|
| 292 |
+
aq_fifo u_aq_wfifo
|
| 293 |
+
(
|
| 294 |
+
.RST(FIFO_RST),
|
| 295 |
+
|
| 296 |
+
.WRCLK(M_AXI_ACLK),
|
| 297 |
+
.WREN(rd_fifo_we),
|
| 298 |
+
.DI(rd_fifo_data),
|
| 299 |
+
.FULL(rd_fifo_full),
|
| 300 |
+
.AFULL(rd_fifo_afull),
|
| 301 |
+
.WRCOUNT(),
|
| 302 |
+
|
| 303 |
+
.RDCLK(FIFO_RD_CLK),
|
| 304 |
+
.RDEN(FIFO_RD_EN),
|
| 305 |
+
.DO(FIFO_RD_DO),
|
| 306 |
+
.EMPTY(FIFO_RD_EMPTY),
|
| 307 |
+
.AEMPTY(),
|
| 308 |
+
.RDCOUNT()
|
| 309 |
+
);
|
| 310 |
+
always @(posedge M_AXI_ACLK or posedge FIFO_RST) begin
|
| 311 |
+
if(FIFO_RST) begin
|
| 312 |
+
rd_fifo_wrcnt <= 32'd0;
|
| 313 |
+
end else begin
|
| 314 |
+
if(rd_fifo_we) begin
|
| 315 |
+
rd_fifo_wrcnt <= rd_fifo_wrcnt +32'd1;
|
| 316 |
+
end
|
| 317 |
+
end
|
| 318 |
+
end
|
| 319 |
+
always @(posedge FIFO_RD_CLK or posedge FIFO_RST) begin
|
| 320 |
+
if(FIFO_RST) begin
|
| 321 |
+
rd_fifo_rdcnt <= 32'd0;
|
| 322 |
+
end else begin
|
| 323 |
+
if(FIFO_RD_EN) begin
|
| 324 |
+
rd_fifo_rdcnt <= rd_fifo_rdcnt +32'd1;
|
| 325 |
+
end
|
| 326 |
+
end
|
| 327 |
+
end
|
| 328 |
+
|
| 329 |
+
aq_fifo u_aq_rfifo
|
| 330 |
+
(
|
| 331 |
+
.RST(FIFO_RST),
|
| 332 |
+
|
| 333 |
+
.WRCLK(FIFO_WR_CLK),
|
| 334 |
+
.WREN(FIFO_WR_EN),
|
| 335 |
+
.DI(FIFO_WR_DI),
|
| 336 |
+
.FULL(FIFO_WR_FULL),
|
| 337 |
+
.AFULL(),
|
| 338 |
+
.WRCOUNT(),
|
| 339 |
+
|
| 340 |
+
.RDCLK(M_AXI_ACLK),
|
| 341 |
+
.RDEN(wr_fifo_re),
|
| 342 |
+
.DO(wr_fifo_data),
|
| 343 |
+
.EMPTY(wr_fifo_empty),
|
| 344 |
+
.AEMPTY(wr_fifo_aempty),
|
| 345 |
+
.RDCOUNT()
|
| 346 |
+
);
|
| 347 |
+
always @(posedge FIFO_WR_CLK or posedge FIFO_RST) begin
|
| 348 |
+
if(FIFO_RST) begin
|
| 349 |
+
wr_fifo_wrcnt <= 32'd0;
|
| 350 |
+
end else begin
|
| 351 |
+
if(FIFO_WR_EN) begin
|
| 352 |
+
wr_fifo_wrcnt <= wr_fifo_wrcnt +32'd1;
|
| 353 |
+
end
|
| 354 |
+
end
|
| 355 |
+
end
|
| 356 |
+
always @(posedge M_AXI_ACLK or posedge FIFO_RST) begin
|
| 357 |
+
if(FIFO_RST) begin
|
| 358 |
+
wr_fifo_rdcnt <= 32'd0;
|
| 359 |
+
end else begin
|
| 360 |
+
if(wr_fifo_re) begin
|
| 361 |
+
wr_fifo_rdcnt <= wr_fifo_rdcnt +32'd1;
|
| 362 |
+
end
|
| 363 |
+
end
|
| 364 |
+
end
|
| 365 |
+
|
| 366 |
+
aq_axi_fifo_ctl u_aq_axi_fifo_ctl
|
| 367 |
+
(
|
| 368 |
+
.RST_N(ARESETN),
|
| 369 |
+
.CLK(S_AXI_ACLK),
|
| 370 |
+
|
| 371 |
+
.LOCAL_CS(local_cs),
|
| 372 |
+
.LOCAL_RNW(local_rnw),
|
| 373 |
+
.LOCAL_ACK(local_ack),
|
| 374 |
+
.LOCAL_ADDR(local_addr),
|
| 375 |
+
.LOCAL_BE(local_be),
|
| 376 |
+
.LOCAL_WDATA(local_wdata),
|
| 377 |
+
.LOCAL_RDATA(local_rdata),
|
| 378 |
+
|
| 379 |
+
.CMD_CLK(M_AXI_ACLK),
|
| 380 |
+
|
| 381 |
+
.WR_START(wr_start),
|
| 382 |
+
.WR_ADRS(wr_adrs),
|
| 383 |
+
.WR_COUNT(wr_len),
|
| 384 |
+
.WR_READY(wr_ready),
|
| 385 |
+
.WR_FIFO_EMPTY(wr_fifo_empty),
|
| 386 |
+
.WR_FIFO_AEMPTY(wr_fifo_aempty),
|
| 387 |
+
.WR_FIFO_FULL(FIFO_RD_FULL),
|
| 388 |
+
.WR_FIFO_AFULL(1'b0),
|
| 389 |
+
|
| 390 |
+
.RD_START(rd_start),
|
| 391 |
+
.RD_ADRS(rd_adrs),
|
| 392 |
+
.RD_COUNT(rd_len),
|
| 393 |
+
.RD_READY(rd_ready),
|
| 394 |
+
.RD_FIFO_EMPTY(FIFO_WR_EMPTY),
|
| 395 |
+
.RD_FIFO_AEMPTY(1'b0),
|
| 396 |
+
.RD_FIFO_FULL(rd_fifo_full),
|
| 397 |
+
.RD_FIFO_AFULL(rd_fifo_afull),
|
| 398 |
+
|
| 399 |
+
.MASTER_STATUS(debug_master),
|
| 400 |
+
.FIFO_STATUS0(rd_fifo_wrcnt),
|
| 401 |
+
.FIFO_STATU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 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
module aq_axi_fifo_ctl(
|
| 20 |
+
input RST_N,
|
| 21 |
+
input CLK,
|
| 22 |
+
|
| 23 |
+
input LOCAL_CS,
|
| 24 |
+
input LOCAL_RNW,
|
| 25 |
+
output LOCAL_ACK,
|
| 26 |
+
input [31:0] LOCAL_ADDR,
|
| 27 |
+
input [3:0] LOCAL_BE,
|
| 28 |
+
input [31:0] LOCAL_WDATA,
|
| 29 |
+
output [31:0] LOCAL_RDATA,
|
| 30 |
+
|
| 31 |
+
input CMD_CLK,
|
| 32 |
+
|
| 33 |
+
output WR_START,
|
| 34 |
+
output [31:0] WR_ADRS,
|
| 35 |
+
output [31:0] WR_COUNT,
|
| 36 |
+
input WR_READY,
|
| 37 |
+
input WR_FIFO_EMPTY,
|
| 38 |
+
input WR_FIFO_AEMPTY,
|
| 39 |
+
input WR_FIFO_FULL,
|
| 40 |
+
input WR_FIFO_AFULL,
|
| 41 |
+
|
| 42 |
+
output RD_START,
|
| 43 |
+
output [31:0] RD_ADRS,
|
| 44 |
+
output [31:0] RD_COUNT,
|
| 45 |
+
input RD_READY,
|
| 46 |
+
input RD_FIFO_EMPTY,
|
| 47 |
+
input RD_FIFO_AEMPTY,
|
| 48 |
+
input RD_FIFO_FULL,
|
| 49 |
+
input RD_FIFO_AFULL,
|
| 50 |
+
|
| 51 |
+
input [31:0] MASTER_STATUS,
|
| 52 |
+
input [31:0] FIFO_STATUS0,
|
| 53 |
+
input [31:0] FIFO_STATUS1,
|
| 54 |
+
input [31:0] FIFO_STATUS2,
|
| 55 |
+
input [31:0] FIFO_STATUS3,
|
| 56 |
+
|
| 57 |
+
output FIFO_RST,
|
| 58 |
+
|
| 59 |
+
output [31:0] DEBUG
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
localparam A_WR_START = 8'h00;
|
| 63 |
+
localparam A_WR_ADRS = 8'h04;
|
| 64 |
+
localparam A_WR_COUNT = 8'h08;
|
| 65 |
+
localparam A_RD_START = 8'h0C;
|
| 66 |
+
localparam A_RD_ADRS = 8'h10;
|
| 67 |
+
localparam A_RD_COUNT = 8'h14;
|
| 68 |
+
localparam A_MASTER_STATUS = 8'h18;
|
| 69 |
+
localparam A_TESTDATA = 8'h1C;
|
| 70 |
+
localparam A_FIFORST = 8'h20;
|
| 71 |
+
localparam A_DEBUG = 8'h24;
|
| 72 |
+
localparam A_FIFO_STATUS0 = 8'h28;
|
| 73 |
+
localparam A_FIFO_STATUS1 = 8'h2C;
|
| 74 |
+
localparam A_FIFO_STATUS2 = 8'h30;
|
| 75 |
+
localparam A_FIFO_STATUS3 = 8'h34;
|
| 76 |
+
|
| 77 |
+
wire wr_ena, rd_ena, wr_ack;
|
| 78 |
+
reg rd_ack;
|
| 79 |
+
|
| 80 |
+
reg reg_wrreq_clk;
|
| 81 |
+
reg [1:0] req_wrack_clk;
|
| 82 |
+
reg [2:0] reg_wrreq_cmd_clk;
|
| 83 |
+
|
| 84 |
+
reg reg_rdreq_clk;
|
| 85 |
+
reg [1:0] req_rdack_clk;
|
| 86 |
+
reg [2:0] reg_rdreq_cmd_clk;
|
| 87 |
+
|
| 88 |
+
reg [31:0] reg_wr_adrs, reg_rd_adrs;
|
| 89 |
+
reg [31:0] reg_wr_count, reg_rd_count;
|
| 90 |
+
reg [31:0] reg_testdata;
|
| 91 |
+
|
| 92 |
+
reg [31:0] reg_rdata;
|
| 93 |
+
|
| 94 |
+
reg reg_fifo_rst;
|
| 95 |
+
|
| 96 |
+
reg [7:0] reg_rdreq_count;
|
| 97 |
+
|
| 98 |
+
assign wr_ena = (LOCAL_CS & ~LOCAL_RNW)?1'b1:1'b0;
|
| 99 |
+
assign rd_ena = (LOCAL_CS & LOCAL_RNW)?1'b1:1'b0;
|
| 100 |
+
assign wr_ack = wr_ena;
|
| 101 |
+
|
| 102 |
+
// Write Register
|
| 103 |
+
always @(posedge CLK or negedge RST_N) begin
|
| 104 |
+
if(!RST_N) begin
|
| 105 |
+
reg_wr_adrs[31:0] <= 32'd0;
|
| 106 |
+
reg_wr_count[31:0] <= 32'd0;
|
| 107 |
+
reg_rd_adrs[31:0] <= 32'd0;
|
| 108 |
+
reg_rd_count[31:0] <= 32'd0;
|
| 109 |
+
reg_fifo_rst <= 1'b0;
|
| 110 |
+
end else begin
|
| 111 |
+
if(wr_ena) begin
|
| 112 |
+
case(LOCAL_ADDR[7:0] & 8'hFC)
|
| 113 |
+
A_WR_START: begin
|
| 114 |
+
end
|
| 115 |
+
A_WR_ADRS: begin
|
| 116 |
+
reg_wr_adrs[31:0] <= LOCAL_WDATA[31:0];
|
| 117 |
+
end
|
| 118 |
+
A_WR_COUNT: begin
|
| 119 |
+
reg_wr_count[31:0] <= LOCAL_WDATA[31:0];
|
| 120 |
+
end
|
| 121 |
+
A_RD_START: begin
|
| 122 |
+
end
|
| 123 |
+
A_RD_ADRS: begin
|
| 124 |
+
reg_rd_adrs[31:0] <= LOCAL_WDATA[31:0];
|
| 125 |
+
end
|
| 126 |
+
A_RD_COUNT: begin
|
| 127 |
+
reg_rd_count[31:0] <= LOCAL_WDATA[31:0];
|
| 128 |
+
end
|
| 129 |
+
A_MASTER_STATUS: begin
|
| 130 |
+
end
|
| 131 |
+
A_TESTDATA: begin
|
| 132 |
+
reg_testdata[31:0] <= LOCAL_WDATA[31:0];
|
| 133 |
+
end
|
| 134 |
+
A_FIFORST: begin
|
| 135 |
+
reg_fifo_rst <= LOCAL_WDATA[0];
|
| 136 |
+
end
|
| 137 |
+
default: begin
|
| 138 |
+
end
|
| 139 |
+
endcase
|
| 140 |
+
end
|
| 141 |
+
end
|
| 142 |
+
end
|
| 143 |
+
|
| 144 |
+
// Read Register
|
| 145 |
+
always @(posedge CLK or negedge RST_N) begin
|
| 146 |
+
if(!RST_N) begin
|
| 147 |
+
reg_rdata[31:0] <= 32'd0;
|
| 148 |
+
rd_ack <= 1'b0;
|
| 149 |
+
end else begin
|
| 150 |
+
rd_ack <= rd_ena;
|
| 151 |
+
if(rd_ena) begin
|
| 152 |
+
case(LOCAL_ADDR[7:0] & 8'hFC)
|
| 153 |
+
A_WR_START: begin
|
| 154 |
+
reg_rdata[31:0] <= {12'd0, WR_FIFO_AEMPTY, WR_FIFO_EMPTY, WR_FIFO_AFULL, WR_FIFO_FULL, 7'd0, WR_READY, 7'd0, reg_wrreq_clk};
|
| 155 |
+
end
|
| 156 |
+
A_WR_ADRS: begin
|
| 157 |
+
reg_rdata[31:0] <= reg_wr_adrs[31:0];
|
| 158 |
+
end
|
| 159 |
+
A_WR_COUNT: begin
|
| 160 |
+
reg_rdata[31:0] <= reg_wr_count[31:0];
|
| 161 |
+
end
|
| 162 |
+
A_RD_START: begin
|
| 163 |
+
reg_rdata[31:0] <= {12'd0, RD_FIFO_AEMPTY, RD_FIFO_EMPTY, RD_FIFO_AFULL, RD_FIFO_FULL, 7'd0, RD_READY, 7'd0, reg_rdreq_clk};
|
| 164 |
+
end
|
| 165 |
+
A_RD_ADRS: begin
|
| 166 |
+
reg_rdata[31:0] <= reg_rd_adrs[31:0];
|
| 167 |
+
end
|
| 168 |
+
A_RD_COUNT: begin
|
| 169 |
+
reg_rdata[31:0] <= reg_rd_count[31:0];
|
| 170 |
+
end
|
| 171 |
+
A_MASTER_STATUS: begin
|
| 172 |
+
reg_rdata[31:0] <= MASTER_STATUS;
|
| 173 |
+
end
|
| 174 |
+
A_TESTDATA: begin
|
| 175 |
+
reg_rdata[31:0] <= reg_testdata[31:0];
|
| 176 |
+
end
|
| 177 |
+
A_FIFORST: begin
|
| 178 |
+
reg_rdata[31:0] <= {31'd0, reg_fifo_rst};
|
| 179 |
+
end
|
| 180 |
+
A_DEBUG: begin
|
| 181 |
+
reg_rdata[31:0] <= {24'd0, reg_rdreq_count};
|
| 182 |
+
end
|
| 183 |
+
A_FIFO_STATUS0: begin
|
| 184 |
+
reg_rdata[31:0] <= FIFO_STATUS0;
|
| 185 |
+
end
|
| 186 |
+
A_FIFO_STATUS1: begin
|
| 187 |
+
reg_rdata[31:0] <= FIFO_STATUS1;
|
| 188 |
+
end
|
| 189 |
+
A_FIFO_STATUS2: begin
|
| 190 |
+
reg_rdata[31:0] <= FIFO_STATUS2;
|
| 191 |
+
end
|
| 192 |
+
A_FIFO_STATUS3: begin
|
| 193 |
+
reg_rdata[31:0] <= FIFO_STATUS3;
|
| 194 |
+
end
|
| 195 |
+
default: begin
|
| 196 |
+
reg_rdata[31:0] <= 32'd0;
|
| 197 |
+
end
|
| 198 |
+
endcase
|
| 199 |
+
end else begin
|
| 200 |
+
reg_rdata[31:0] <= 32'd0;
|
| 201 |
+
end
|
| 202 |
+
end
|
| 203 |
+
end
|
| 204 |
+
|
| 205 |
+
assign LOCAL_ACK = (wr_ack | rd_ack);
|
| 206 |
+
assign LOCAL_RDATA[31:0] = reg_rdata[31:0];
|
| 207 |
+
|
| 208 |
+
// Request Sending(1shot)
|
| 209 |
+
always @(posedge CLK or negedge RST_N) begin
|
| 210 |
+
if(!RST_N) begin
|
| 211 |
+
reg_wrreq_clk <= 1'b0;
|
| 212 |
+
req_wrack_clk[1:0] <= 2'd0;
|
| 213 |
+
end else begin
|
| 214 |
+
if(req_wrack_clk[1]) begin
|
| 215 |
+
reg_wrreq_clk <= 1'b0;
|
| 216 |
+
end else if((wr_ena && (LOCAL_ADDR[7:0] == A_WR_START[7:0])) &&
|
| 217 |
+
(WR_READY)) begin
|
| 218 |
+
reg_wrreq_clk <= 1'b1;
|
| 219 |
+
end
|
| 220 |
+
req_wrack_clk[1:0] <= {req_wrack_clk[0], reg_wrreq_cmd_clk[2]};
|
| 221 |
+
end
|
| 222 |
+
end
|
| 223 |
+
|
| 224 |
+
always @(posedge CMD_CLK or negedge RST_N) begin
|
| 225 |
+
if(!RST_N) begin
|
| 226 |
+
reg_wrreq_cmd_clk[2:0] <= 3'd0;
|
| 227 |
+
end else begin
|
| 228 |
+
reg_wrreq_cmd_clk[2:0] <= {reg_wrreq_cmd_clk[1:0], reg_wrreq_clk};
|
| 229 |
+
end
|
| 230 |
+
end
|
| 231 |
+
|
| 232 |
+
always @(posedge CLK or negedge RST_N) begin
|
| 233 |
+
if(!RST_N) begin
|
| 234 |
+
reg_rdreq_clk <= 1'b0;
|
| 235 |
+
req_rdack_clk[1:0] <= 2'd0;
|
| 236 |
+
reg_rdreq_count[7:0] <= 8'd0;
|
| 237 |
+
end else begin
|
| 238 |
+
if(req_rdack_clk[1]) begin
|
| 239 |
+
reg_rdreq_clk <= 1'b0;
|
| 240 |
+
end else if((wr_ena && (LOCAL_ADDR[7:0] == A_RD_START[7:0])) &&
|
| 241 |
+
(RD_READY)) begin
|
| 242 |
+
reg_rdreq_clk <= 1'b1;
|
| 243 |
+
reg_rdreq_count[7:0] <= reg_rdreq_count[7:0] + 8'd1;
|
| 244 |
+
end
|
| 245 |
+
req_rdack_clk[1:0] <= {req_rdack_clk[0], reg_rdreq_cmd_clk[2]};
|
| 246 |
+
end
|
| 247 |
+
end
|
| 248 |
+
|
| 249 |
+
always @(posedge CMD_CLK or negedge RST_N) begin
|
| 250 |
+
if(!RST_N) begin
|
| 251 |
+
reg_rdreq_cmd_clk[2:0] <= 3'd0;
|
| 252 |
+
end else begin
|
| 253 |
+
reg_rdreq_cmd_clk[2:0] <= {reg_rdreq_cmd_clk[1:0], reg_rdreq_clk};
|
| 254 |
+
end
|
| 255 |
+
end
|
| 256 |
+
|
| 257 |
+
assign WR_START = (reg_wrreq_cmd_clk[2:1] == 2'b01)?1'b1:1'b0;
|
| 258 |
+
assign WR_ADRS[31:0] = reg_wr_adrs[31:0];
|
| 259 |
+
assign WR_COUNT[31:0] = reg_wr_count[31:0];
|
| 260 |
+
assign RD_START = (reg_rdreq_cmd_clk[2:1] == 2'b01)?1'b1:1'b0;
|
| 261 |
+
assign RD_ADRS[31:0] = reg_rd_adrs[31:0];
|
| 262 |
+
assign RD_COUNT[31:0] = reg_rd_count[31:0];
|
| 263 |
+
|
| 264 |
+
assign FIFO_RST = reg_fifo_rst;
|
| 265 |
+
|
| 266 |
+
assign DEBUG[31:0] = {24'd0, rd_ack, rd_ena, LOCAL_RNW, LOCAL_CS};
|
| 267 |
+
|
| 268 |
+
endmodule
|
| 269 |
+
|
aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sources/aq_axi_lite_slave.v
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
module aq_axi_lite_slave
|
| 20 |
+
#(
|
| 21 |
+
parameter C_BASEADRS = 32'h0000_0000,
|
| 22 |
+
parameter C_ADRSWIDTH = 16
|
| 23 |
+
)
|
| 24 |
+
(
|
| 25 |
+
// AXI4 Lite Interface
|
| 26 |
+
input ARESETN,
|
| 27 |
+
input ACLK,
|
| 28 |
+
|
| 29 |
+
// Write Address Channel
|
| 30 |
+
input [31:0] S_AXI_AWADDR,
|
| 31 |
+
input [3:0] S_AXI_AWCACHE, // 4'b0011
|
| 32 |
+
input [2:0] S_AXI_AWPROT, // 3'b000
|
| 33 |
+
input S_AXI_AWVALID,
|
| 34 |
+
output S_AXI_AWREADY,
|
| 35 |
+
|
| 36 |
+
// Write Data Channel
|
| 37 |
+
input [31:0] S_AXI_WDATA,
|
| 38 |
+
input [3:0] S_AXI_WSTRB,
|
| 39 |
+
input S_AXI_WVALID,
|
| 40 |
+
output S_AXI_WREADY,
|
| 41 |
+
|
| 42 |
+
// Write Response Channel
|
| 43 |
+
output S_AXI_BVALID,
|
| 44 |
+
input S_AXI_BREADY,
|
| 45 |
+
output [1:0] S_AXI_BRESP,
|
| 46 |
+
|
| 47 |
+
// Read Address Channel
|
| 48 |
+
input [31:0] S_AXI_ARADDR,
|
| 49 |
+
input [3:0] S_AXI_ARCACHE, // 4'b0011
|
| 50 |
+
input [2:0] S_AXI_ARPROT, // 3'b000
|
| 51 |
+
input S_AXI_ARVALID,
|
| 52 |
+
output S_AXI_ARREADY,
|
| 53 |
+
|
| 54 |
+
// Read Data Channel
|
| 55 |
+
output [31:0] S_AXI_RDATA,
|
| 56 |
+
output [1:0] S_AXI_RRESP,
|
| 57 |
+
output S_AXI_RVALID,
|
| 58 |
+
input S_AXI_RREADY,
|
| 59 |
+
|
| 60 |
+
// Local Interface
|
| 61 |
+
output LOCAL_CS,
|
| 62 |
+
output LOCAL_RNW,
|
| 63 |
+
input LOCAL_ACK,
|
| 64 |
+
output [31:0] LOCAL_ADDR,
|
| 65 |
+
output [3:0] LOCAL_BE,
|
| 66 |
+
output [31:0] LOCAL_WDATA,
|
| 67 |
+
input [31:0] LOCAL_RDATA,
|
| 68 |
+
|
| 69 |
+
output [31:0] DEBUG
|
| 70 |
+
);
|
| 71 |
+
|
| 72 |
+
/*
|
| 73 |
+
CACHE[3:0]
|
| 74 |
+
WA RA C B
|
| 75 |
+
0 0 0 0 Noncacheable and nonbufferable
|
| 76 |
+
0 0 0 1 Bufferable only
|
| 77 |
+
0 0 1 0 Cacheable, but do not allocate
|
| 78 |
+
0 0 1 1 Cacheable and Bufferable, but do not allocate
|
| 79 |
+
0 1 1 0 Cacheable write-through, allocate on reads only
|
| 80 |
+
0 1 1 1 Cacheable write-back, allocate on reads only
|
| 81 |
+
1 0 1 0 Cacheable write-through, allocate on write only
|
| 82 |
+
1 0 1 1 Cacheable write-back, allocate on writes only
|
| 83 |
+
1 1 1 0 Cacheable write-through, allocate on both reads and writes
|
| 84 |
+
1 1 1 1 Cacheable write-back, allocate on both reads and writes
|
| 85 |
+
|
| 86 |
+
PROR
|
| 87 |
+
[2]:0:Data Access
|
| 88 |
+
1:Instruction Access
|
| 89 |
+
[1]:0:Secure Access
|
| 90 |
+
1:NoSecure Access
|
| 91 |
+
[0]:0:Privileged Access
|
| 92 |
+
1:Normal Access
|
| 93 |
+
|
| 94 |
+
RESP
|
| 95 |
+
00: OK
|
| 96 |
+
01: EXOK
|
| 97 |
+
10: SLVERR
|
| 98 |
+
11: DECERR
|
| 99 |
+
*/
|
| 100 |
+
|
| 101 |
+
localparam S_IDLE = 2'd0;
|
| 102 |
+
localparam S_WRITE = 2'd1;
|
| 103 |
+
localparam S_WRITE2 = 2'd2;
|
| 104 |
+
localparam S_READ = 2'd3;
|
| 105 |
+
|
| 106 |
+
reg [1:0] state;
|
| 107 |
+
reg reg_rnw;
|
| 108 |
+
reg [31:0] reg_addr, reg_wdata;
|
| 109 |
+
reg [3:0] reg_be;
|
| 110 |
+
|
| 111 |
+
always @( posedge ACLK or negedge ARESETN ) begin
|
| 112 |
+
if( !ARESETN ) begin
|
| 113 |
+
state <= S_IDLE;
|
| 114 |
+
reg_rnw <= 1'b0;
|
| 115 |
+
reg_addr <= 32'd0;
|
| 116 |
+
reg_wdata <= 32'd0;
|
| 117 |
+
reg_be <= 4'd0;
|
| 118 |
+
end else begin
|
| 119 |
+
case( state )
|
| 120 |
+
S_IDLE: begin
|
| 121 |
+
if( S_AXI_AWVALID && ( S_AXI_AWADDR[31:(32 - C_ADRSWIDTH)] == C_BASEADRS[31:(32 - C_ADRSWIDTH)] ) ) begin
|
| 122 |
+
reg_rnw <= 1'b0;
|
| 123 |
+
reg_addr <= S_AXI_AWADDR;
|
| 124 |
+
state <= S_WRITE;
|
| 125 |
+
end else if( S_AXI_ARVALID && (S_AXI_ARADDR[31:(32 - C_ADRSWIDTH)] == C_BASEADRS[31:(32 - C_ADRSWIDTH)]) ) begin
|
| 126 |
+
reg_rnw <= 1'b1;
|
| 127 |
+
reg_addr <= S_AXI_ARADDR;
|
| 128 |
+
state <= S_READ;
|
| 129 |
+
end
|
| 130 |
+
end
|
| 131 |
+
S_WRITE: begin
|
| 132 |
+
if( S_AXI_WVALID ) begin
|
| 133 |
+
state <= S_WRITE2;
|
| 134 |
+
reg_wdata <= S_AXI_WDATA;
|
| 135 |
+
reg_be <= S_AXI_WSTRB;
|
| 136 |
+
end
|
| 137 |
+
end
|
| 138 |
+
S_WRITE2: begin
|
| 139 |
+
if( LOCAL_ACK & S_AXI_BREADY ) begin
|
| 140 |
+
state <= S_IDLE;
|
| 141 |
+
end
|
| 142 |
+
end
|
| 143 |
+
S_READ: begin
|
| 144 |
+
if( LOCAL_ACK & S_AXI_RREADY ) begin
|
| 145 |
+
state <= S_IDLE;
|
| 146 |
+
end
|
| 147 |
+
end
|
| 148 |
+
default: begin
|
| 149 |
+
state <= S_IDLE;
|
| 150 |
+
end
|
| 151 |
+
endcase
|
| 152 |
+
end
|
| 153 |
+
end
|
| 154 |
+
|
| 155 |
+
// Local Interface
|
| 156 |
+
assign LOCAL_CS = (( state == S_WRITE2 )?1'b1:1'b0) | (( state == S_READ )?1'b1:1'b0) | 1'b0;
|
| 157 |
+
assign LOCAL_RNW = reg_rnw;
|
| 158 |
+
assign LOCAL_ADDR = reg_addr;
|
| 159 |
+
assign LOCAL_BE = reg_be;
|
| 160 |
+
assign LOCAL_WDATA = reg_wdata;
|
| 161 |
+
|
| 162 |
+
// Write Channel
|
| 163 |
+
assign S_AXI_AWREADY = ( state == S_WRITE )?S_AXI_AWVALID:1'b0;
|
| 164 |
+
assign S_AXI_WREADY = ( state == S_WRITE )?S_AXI_WVALID:1'b0;
|
| 165 |
+
assign S_AXI_BVALID = ( state == S_WRITE2 )?LOCAL_ACK:1'b0;
|
| 166 |
+
assign S_AXI_BRESP = 2'b00;
|
| 167 |
+
|
| 168 |
+
// Read Channel
|
| 169 |
+
assign S_AXI_ARREADY = ( state == S_READ )?S_AXI_ARVALID:1'b0;
|
| 170 |
+
assign S_AXI_RVALID = ( state == S_READ )?LOCAL_ACK:1'b0;
|
| 171 |
+
assign S_AXI_RRESP = 2'b00;
|
| 172 |
+
assign S_AXI_RDATA = ( state == S_READ )?LOCAL_RDATA:32'd0;
|
| 173 |
+
|
| 174 |
+
// Debug
|
| 175 |
+
assign DEBUG[31:0] = {24'd0, 1'd0, S_AXI_RVALID, S_AXI_ARREADY, LOCAL_ACK, LOCAL_RNW, LOCAL_CS, state[1:0]};
|
| 176 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sources/aq_axi_master.v
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
module aq_axi_master(
|
| 20 |
+
// Reset, Clock
|
| 21 |
+
input ARESETN,
|
| 22 |
+
input ACLK,
|
| 23 |
+
|
| 24 |
+
// Master Write Address
|
| 25 |
+
output [0:0] M_AXI_AWID,
|
| 26 |
+
output [31:0] M_AXI_AWADDR,
|
| 27 |
+
output [7:0] M_AXI_AWLEN, // Burst Length: 0-255
|
| 28 |
+
output [2:0] M_AXI_AWSIZE, // Burst Size: Fixed 2'b011
|
| 29 |
+
output [1:0] M_AXI_AWBURST, // Burst Type: Fixed 2'b01(Incremental Burst)
|
| 30 |
+
output M_AXI_AWLOCK, // Lock: Fixed 2'b00
|
| 31 |
+
output [3:0] M_AXI_AWCACHE, // Cache: Fiex 2'b0011
|
| 32 |
+
output [2:0] M_AXI_AWPROT, // Protect: Fixed 2'b000
|
| 33 |
+
output [3:0] M_AXI_AWQOS, // QoS: Fixed 2'b0000
|
| 34 |
+
output [0:0] M_AXI_AWUSER, // User: Fixed 32'd0
|
| 35 |
+
output M_AXI_AWVALID,
|
| 36 |
+
input M_AXI_AWREADY,
|
| 37 |
+
|
| 38 |
+
// Master Write Data
|
| 39 |
+
output [63:0] M_AXI_WDATA,
|
| 40 |
+
output [7:0] M_AXI_WSTRB,
|
| 41 |
+
output M_AXI_WLAST,
|
| 42 |
+
output [0:0] M_AXI_WUSER,
|
| 43 |
+
output M_AXI_WVALID,
|
| 44 |
+
input M_AXI_WREADY,
|
| 45 |
+
|
| 46 |
+
// Master Write Response
|
| 47 |
+
input [0:0] M_AXI_BID,
|
| 48 |
+
input [1:0] M_AXI_BRESP,
|
| 49 |
+
input [0:0] M_AXI_BUSER,
|
| 50 |
+
input M_AXI_BVALID,
|
| 51 |
+
output M_AXI_BREADY,
|
| 52 |
+
|
| 53 |
+
// Master Read Address
|
| 54 |
+
output [0:0] M_AXI_ARID,
|
| 55 |
+
output [31:0] M_AXI_ARADDR,
|
| 56 |
+
output [7:0] M_AXI_ARLEN,
|
| 57 |
+
output [2:0] M_AXI_ARSIZE,
|
| 58 |
+
output [1:0] M_AXI_ARBURST,
|
| 59 |
+
output [1:0] M_AXI_ARLOCK,
|
| 60 |
+
output [3:0] M_AXI_ARCACHE,
|
| 61 |
+
output [2:0] M_AXI_ARPROT,
|
| 62 |
+
output [3:0] M_AXI_ARQOS,
|
| 63 |
+
output [0:0] M_AXI_ARUSER,
|
| 64 |
+
output M_AXI_ARVALID,
|
| 65 |
+
input M_AXI_ARREADY,
|
| 66 |
+
|
| 67 |
+
// Master Read Data
|
| 68 |
+
input [0:0] M_AXI_RID,
|
| 69 |
+
input [63:0] M_AXI_RDATA,
|
| 70 |
+
input [1:0] M_AXI_RRESP,
|
| 71 |
+
input M_AXI_RLAST,
|
| 72 |
+
input [0:0] M_AXI_RUSER,
|
| 73 |
+
input M_AXI_RVALID,
|
| 74 |
+
output M_AXI_RREADY,
|
| 75 |
+
|
| 76 |
+
// Local Bus
|
| 77 |
+
input MASTER_RST,
|
| 78 |
+
|
| 79 |
+
input WR_START,
|
| 80 |
+
input [31:0] WR_ADRS,
|
| 81 |
+
input [31:0] WR_LEN,
|
| 82 |
+
output WR_READY,
|
| 83 |
+
output WR_FIFO_RE,
|
| 84 |
+
input WR_FIFO_EMPTY,
|
| 85 |
+
input WR_FIFO_AEMPTY,
|
| 86 |
+
input [63:0] WR_FIFO_DATA,
|
| 87 |
+
|
| 88 |
+
input RD_START,
|
| 89 |
+
input [31:0] RD_ADRS,
|
| 90 |
+
input [31:0] RD_LEN,
|
| 91 |
+
output RD_READY,
|
| 92 |
+
output RD_FIFO_WE,
|
| 93 |
+
input RD_FIFO_FULL,
|
| 94 |
+
input RD_FIFO_AFULL,
|
| 95 |
+
output [63:0] RD_FIFO_DATA,
|
| 96 |
+
|
| 97 |
+
output [31:0] DEBUG
|
| 98 |
+
);
|
| 99 |
+
|
| 100 |
+
localparam S_WR_IDLE = 3'd0;
|
| 101 |
+
localparam S_WA_WAIT = 3'd1;
|
| 102 |
+
localparam S_WA_START = 3'd2;
|
| 103 |
+
localparam S_WD_WAIT = 3'd3;
|
| 104 |
+
localparam S_WD_PROC = 3'd4;
|
| 105 |
+
localparam S_WR_WAIT = 3'd5;
|
| 106 |
+
|
| 107 |
+
reg [2:0] wr_state;
|
| 108 |
+
reg [31:0] reg_wr_adrs;
|
| 109 |
+
reg [31:0] reg_wr_len;
|
| 110 |
+
reg reg_awvalid, reg_wvalid, reg_w_last;
|
| 111 |
+
reg [7:0] reg_w_len;
|
| 112 |
+
reg [7:0] reg_w_stb;
|
| 113 |
+
reg [1:0] reg_wr_status;
|
| 114 |
+
reg [3:0] reg_w_count, reg_r_count;
|
| 115 |
+
|
| 116 |
+
reg [7:0] rd_chkdata, wr_chkdata;
|
| 117 |
+
reg [1:0] resp;
|
| 118 |
+
|
| 119 |
+
// Write State
|
| 120 |
+
always @(posedge ACLK or negedge ARESETN) begin
|
| 121 |
+
if(!ARESETN) begin
|
| 122 |
+
wr_state <= S_WR_IDLE;
|
| 123 |
+
reg_wr_adrs[31:0] <= 32'd0;
|
| 124 |
+
reg_wr_len[31:0] <= 32'd0;
|
| 125 |
+
reg_awvalid <= 1'b0;
|
| 126 |
+
reg_wvalid <= 1'b0;
|
| 127 |
+
reg_w_last <= 1'b0;
|
| 128 |
+
reg_w_len[7:0] <= 8'd0;
|
| 129 |
+
reg_w_stb[7:0] <= 8'd0;
|
| 130 |
+
reg_wr_status[1:0] <= 2'd0;
|
| 131 |
+
reg_w_count[3:0] <= 4'd0;
|
| 132 |
+
reg_r_count[3:0] <= 4'd0;
|
| 133 |
+
wr_chkdata <= 8'd0;
|
| 134 |
+
rd_chkdata <= 8'd0;
|
| 135 |
+
resp <= 2'd0;
|
| 136 |
+
end else begin
|
| 137 |
+
if(MASTER_RST) begin
|
| 138 |
+
wr_state <= S_WR_IDLE;
|
| 139 |
+
end else begin
|
| 140 |
+
case(wr_state)
|
| 141 |
+
S_WR_IDLE: begin
|
| 142 |
+
if(WR_START) begin
|
| 143 |
+
wr_state <= S_WA_WAIT;
|
| 144 |
+
reg_wr_adrs[31:0] <= WR_ADRS[31:0];
|
| 145 |
+
reg_wr_len[31:0] <= WR_LEN[31:0] -32'd1;
|
| 146 |
+
end
|
| 147 |
+
reg_awvalid <= 1'b0;
|
| 148 |
+
reg_wvalid <= 1'b0;
|
| 149 |
+
reg_w_last <= 1'b0;
|
| 150 |
+
reg_w_len[7:0] <= 8'd0;
|
| 151 |
+
reg_w_stb[7:0] <= 8'd0;
|
| 152 |
+
reg_wr_status[1:0] <= 2'd0;
|
| 153 |
+
end
|
| 154 |
+
S_WA_WAIT: begin
|
| 155 |
+
if(!WR_FIFO_AEMPTY | (reg_wr_len[31:11] == 21'd0)) begin
|
| 156 |
+
wr_state <= S_WA_START;
|
| 157 |
+
end
|
| 158 |
+
end
|
| 159 |
+
S_WA_START: begin
|
| 160 |
+
wr_state <= S_WD_WAIT;
|
| 161 |
+
reg_awvalid <= 1'b1;
|
| 162 |
+
reg_wr_len[31:11] <= reg_wr_len[31:11] - 21'd1;
|
| 163 |
+
if(reg_wr_len[31:11] != 21'd0) begin
|
| 164 |
+
reg_w_len[7:0] <= 8'hFF;
|
| 165 |
+
reg_w_last <= 1'b0;
|
| 166 |
+
reg_w_stb[7:0] <= 8'hFF;
|
| 167 |
+
end else begin
|
| 168 |
+
reg_w_len[7:0] <= reg_wr_len[10:3];
|
| 169 |
+
reg_w_last <= 1'b1;
|
| 170 |
+
reg_w_stb[7:0] <= 8'hFF;
|
| 171 |
+
/*
|
| 172 |
+
case(reg_wr_len[2:0]) begin
|
| 173 |
+
case 3'd0: reg_w_stb[7:0] <= 8'b0000_0000;
|
| 174 |
+
case 3'd1: reg_w_stb[7:0] <= 8'b0000_0001;
|
| 175 |
+
case 3'd2: reg_w_stb[7:0] <= 8'b0000_0011;
|
| 176 |
+
case 3'd3: reg_w_stb[7:0] <= 8'b0000_0111;
|
| 177 |
+
case 3'd4: reg_w_stb[7:0] <= 8'b0000_1111;
|
| 178 |
+
case 3'd5: reg_w_stb[7:0] <= 8'b0001_1111;
|
| 179 |
+
case 3'd6: reg_w_stb[7:0] <= 8'b0011_1111;
|
| 180 |
+
case 3'd7: reg_w_stb[7:0] <= 8'b0111_1111;
|
| 181 |
+
default: reg_w_stb[7:0] <= 8'b1111_1111;
|
| 182 |
+
endcase
|
| 183 |
+
*/
|
| 184 |
+
end
|
| 185 |
+
end
|
| 186 |
+
S_WD_WAIT: begin
|
| 187 |
+
if(M_AXI_AWREADY) begin
|
| 188 |
+
wr_state <= S_WD_PROC;
|
| 189 |
+
reg_awvalid <= 1'b0;
|
| 190 |
+
reg_wvalid <= 1'b1;
|
| 191 |
+
end
|
| 192 |
+
end
|
| 193 |
+
S_WD_PROC: begin
|
| 194 |
+
if(M_AXI_WREADY & ~WR_FIFO_EMPTY) begin
|
| 195 |
+
if(reg_w_len[7:0] == 8'd0) begin
|
| 196 |
+
wr_state <= S_WR_WAIT;
|
| 197 |
+
reg_wvalid <= 1'b0;
|
| 198 |
+
reg_w_stb[7:0] <= 8'h00;
|
| 199 |
+
end else begin
|
| 200 |
+
reg_w_len[7:0] <= reg_w_len[7:0] -8'd1;
|
| 201 |
+
end
|
| 202 |
+
end
|
| 203 |
+
end
|
| 204 |
+
S_WR_WAIT: begin
|
| 205 |
+
if(M_AXI_BVALID) begin
|
| 206 |
+
reg_wr_status[1:0] <= reg_wr_status[1:0] | M_AXI_BRESP[1:0];
|
| 207 |
+
if(reg_w_last) begin
|
| 208 |
+
wr_state <= S_WR_IDLE;
|
| 209 |
+
end else begin
|
| 210 |
+
wr_state <= S_WA_WAIT;
|
| 211 |
+
reg_wr_adrs[31:0] <= reg_wr_adrs[31:0] + 32'd2048;
|
| 212 |
+
end
|
| 213 |
+
end
|
| 214 |
+
end
|
| 215 |
+
default: begin
|
| 216 |
+
wr_state <= S_WR_IDLE;
|
| 217 |
+
end
|
| 218 |
+
endcase
|
| 219 |
+
/*
|
| 220 |
+
if(WR_FIFO_RE) begin
|
| 221 |
+
reg_w_count[3:0] <= reg_w_count[3:0] + 4'd1;
|
| 222 |
+
end
|
| 223 |
+
if(RD_FIFO_WE)begin
|
| 224 |
+
reg_r_count[3:0] <= reg_r_count[3:0] + 4'd1;
|
| 225 |
+
end
|
| 226 |
+
if(M_AXI_AWREADY & M_AXI_AWVALID) begin
|
| 227 |
+
wr_chkdata <= 8'hEE;
|
| 228 |
+
end else if(M_AXI_WSTRB[7] & M_AXI_WVALID) begin
|
| 229 |
+
wr_chkdata <= WR_FIFO_DATA[63:56];
|
| 230 |
+
end
|
| 231 |
+
if(M_AXI_AWREADY & M_AXI_AWVALID) begin
|
| 232 |
+
rd_chkdata <= 8'hDD;
|
| 233 |
+
end else if(M_AXI_WSTRB[7] & M_AXI_WREADY) begin
|
| 234 |
+
rd_chkdata <= WR_FIFO_DATA[63:56];
|
| 235 |
+
end
|
| 236 |
+
if(M_AXI_BVALID & M_AXI_BREADY) begin
|
| 237 |
+
resp <= M_AXI_BRESP;
|
| 238 |
+
end
|
| 239 |
+
*/
|
| 240 |
+
end
|
| 241 |
+
end
|
| 242 |
+
end
|
| 243 |
+
|
| 244 |
+
assign M_AXI_AWID = 1'b0;
|
| 245 |
+
assign M_AXI_AWADDR[31:0] = reg_wr_adrs[31:0];
|
| 246 |
+
assign M_AXI_AWLEN[7:0] = reg_w_len[7:0];
|
| 247 |
+
assign M_AXI_AWSIZE[2:0] = 2'b011;
|
| 248 |
+
assign M_AXI_AWBURST[1:0] = 2'b01;
|
| 249 |
+
assign M_AXI_AWLOCK = 1'b0;
|
| 250 |
+
assign M_AXI_AWCACHE[3:0] = 4'b0011;
|
| 251 |
+
assign M_AXI_AWPROT[2:0] = 3'b000;
|
| 252 |
+
assign M_AXI_AWQOS[3:0] = 4'b0000;
|
| 253 |
+
assign M_AXI_AWUSER[0] = 1'b1;
|
| 254 |
+
assign M_AXI_AWVALID = reg_awvalid;
|
| 255 |
+
|
| 256 |
+
assign M_AXI_WDATA[63:0] = WR_FIFO_DATA[63:0];
|
| 257 |
+
// assign M_AXI_WSTRB[7:0] = (reg_w_len[7:0] == 8'd0)?reg_w_stb[7:0]:8'hFF;
|
| 258 |
+
// assign M_AXI_WSTRB[7:0] = (wr_state == S_WD_PROC)?8'hFF:8'h00;
|
| 259 |
+
assign M_AXI_WSTRB[7:0] = (reg_wvalid & ~WR_FIFO_EMPTY)?8'hFF:8'h00;
|
| 260 |
+
assign M_AXI_WLAST = (reg_w_len[7:0] == 8'd0)?1'b1:1'b0;
|
| 261 |
+
assign M_AXI_WUSER = 1;
|
| 262 |
+
assign M_AXI_WVALID = reg_wvalid & ~WR_FIFO_EMPTY;
|
| 263 |
+
// assign M_AXI_WVALID = (wr_state == S_WD_PROC)?1'b1:1'b0;
|
| 264 |
+
|
| 265 |
+
assign M_AXI_BREADY = M_AXI_BVALID;
|
| 266 |
+
|
| 267 |
+
assign WR_READY = (wr_state == S_WR_IDLE)?1'b1:1'b0;
|
| 268 |
+
assign WR_FIFO_RE = reg_wvalid & ~WR_FIFO_EMPTY & M_AXI_WREADY;
|
| 269 |
+
// assign WR_FIFO_RE = (wr_state == S_WD_PROC)?M_AXI_WREADY:1'b0;
|
| 270 |
+
|
| 271 |
+
localparam S_RD_IDLE = 3'd0;
|
| 272 |
+
localparam S_RA_WAIT = 3'd1;
|
| 273 |
+
localparam S_RA_START = 3'd2;
|
| 274 |
+
localparam S_RD_WAIT = 3'd3;
|
| 275 |
+
localparam S_RD_PROC = 3'd4;
|
| 276 |
+
|
| 277 |
+
reg [2:0] rd_state;
|
| 278 |
+
reg [31:0] reg_rd_adrs;
|
| 279 |
+
reg [31:0] reg_rd_len;
|
| 280 |
+
reg reg_arvalid, reg_r_last;
|
| 281 |
+
reg [7:0] reg_r_len;
|
| 282 |
+
|
| 283 |
+
// Read State
|
| 284 |
+
always @(posedge ACLK or negedge ARESETN) begin
|
| 285 |
+
if(!ARESETN) begin
|
| 286 |
+
rd_state <= S_RD_IDLE;
|
| 287 |
+
reg_rd_adrs[31:0] <= 32'd0;
|
| 288 |
+
reg_rd_len[31:0] <= 32'd0;
|
| 289 |
+
reg_arvalid <= 1'b0;
|
| 290 |
+
reg_r_len[7:0] <= 8'd0;
|
| 291 |
+
end else begin
|
| 292 |
+
case(rd_state)
|
| 293 |
+
S_RD_IDLE: begin
|
| 294 |
+
if(RD_START) begin
|
| 295 |
+
rd_state <= S_RA_WAIT;
|
| 296 |
+
reg_rd_adrs[31:0] <= RD_ADRS[31:0];
|
| 297 |
+
reg_rd_len[31:0] <= RD_LEN[31:0] -32'd1;
|
| 298 |
+
end
|
| 299 |
+
reg_arvalid <= 1'b0;
|
| 300 |
+
reg_r_len[7:0] <= 8'd0;
|
| 301 |
+
end
|
| 302 |
+
S_RA_WAIT: begin
|
| 303 |
+
if(~RD_FIFO_AFULL) begin
|
| 304 |
+
rd_state <= S_RA_START;
|
| 305 |
+
end
|
| 306 |
+
end
|
| 307 |
+
S_RA_START: begin
|
| 308 |
+
rd_state <= S_RD_WAIT;
|
| 309 |
+
reg_arvalid <= 1'b1;
|
| 310 |
+
reg_rd_len[31:11] <= reg_rd_len[31:11] -21'd1;
|
| 311 |
+
if(reg_rd_len[31:11] != 21'd0) begin
|
| 312 |
+
reg_r_last <= 1'b0;
|
| 313 |
+
reg_r_len[7:0] <= 8'd255;
|
| 314 |
+
end else begin
|
| 315 |
+
reg_r_last <= 1'b1;
|
| 316 |
+
reg_r_len[7:0] <= reg_rd_len[10:3];
|
| 317 |
+
end
|
| 318 |
+
end
|
| 319 |
+
S_RD_WAIT: begin
|
| 320 |
+
if(M_AXI_ARREADY) begin
|
| 321 |
+
rd_state <= S_RD_PROC;
|
| 322 |
+
reg_arvalid <= 1'b0;
|
| 323 |
+
end
|
| 324 |
+
end
|
| 325 |
+
S_RD_PROC: begin
|
| 326 |
+
if(M_AXI_RVALID) begin
|
| 327 |
+
if(M_AXI_RLAST) begin
|
| 328 |
+
if(reg_r_last) begin
|
| 329 |
+
rd_state <= S_RD_IDLE;
|
| 330 |
+
end else begin
|
| 331 |
+
rd_state <= S_RA_WAIT;
|
| 332 |
+
reg_rd_adrs[31:0] <= reg_rd_adrs[31:0] + 32'd2048;
|
| 333 |
+
end
|
| 334 |
+
end else begin
|
| 335 |
+
reg_r_len[7:0] <= reg_r_len[7:0] -8'd1;
|
| 336 |
+
end
|
| 337 |
+
end
|
| 338 |
+
end
|
| 339 |
+
endcase
|
| 340 |
+
end
|
| 341 |
+
end
|
| 342 |
+
|
| 343 |
+
// Master Read Address
|
| 344 |
+
assign M_AXI_ARID = 1'b0;
|
| 345 |
+
assign M_AXI_ARADDR[31:0] = reg_rd_adrs[31:0];
|
| 346 |
+
assign M_AXI_ARLEN[7:0] = reg_r_len[7:0];
|
| 347 |
+
assign M_AXI_ARSIZE[2:0] = 3'b011;
|
| 348 |
+
assign M_AXI_ARBURST[1:0] = 2'b01;
|
| 349 |
+
assign M_AXI_ARLOCK = 1'b0;
|
| 350 |
+
assign M_AXI_ARCACHE[3:0] = 4'b0011;
|
| 351 |
+
assign M_AXI_ARPROT[2:0] = 3'b000;
|
| 352 |
+
assign M_AXI_ARQOS[3:0] = 4'b0000;
|
| 353 |
+
assign M_AXI_ARUSER[0] = 1'b1;
|
| 354 |
+
assign M_AXI_ARVALID = reg_arvalid;
|
| 355 |
+
|
| 356 |
+
assign M_AXI_RREADY = M_AXI_RVALID & ~RD_FIFO_FULL;
|
| 357 |
+
|
| 358 |
+
assign RD_READY = (rd_state == S_RD_IDLE)?1'b1:1'b0;
|
| 359 |
+
assign RD_FIFO_WE = M_AXI_RVALID;
|
| 360 |
+
assign RD_FIFO_DATA[63:0] = M_AXI_RDATA[63:0];
|
| 361 |
+
|
| 362 |
+
assign DEBUG[31:0] = {reg_wr_len[31:8],
|
| 363 |
+
1'd0, wr_state[2:0], 1'd0, rd_state[2:0]};
|
| 364 |
+
|
| 365 |
+
endmodule
|
| 366 |
+
|
aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/sources/aq_fifo.v
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
module aq_fifo(
|
| 20 |
+
input RST,
|
| 21 |
+
|
| 22 |
+
input WRCLK,
|
| 23 |
+
input WREN,
|
| 24 |
+
input [63:0] DI,
|
| 25 |
+
output FULL,
|
| 26 |
+
output AFULL,
|
| 27 |
+
output [12:0] WRCOUNT,
|
| 28 |
+
|
| 29 |
+
input RDCLK,
|
| 30 |
+
input RDEN,
|
| 31 |
+
output [63:0] DO,
|
| 32 |
+
output EMPTY,
|
| 33 |
+
output AEMPTY,
|
| 34 |
+
output [12:0] RDCOUNT
|
| 35 |
+
);
|
| 36 |
+
|
| 37 |
+
FIFO36E1
|
| 38 |
+
#(
|
| 39 |
+
.ALMOST_EMPTY_OFFSET ( 13'd128 ),
|
| 40 |
+
.ALMOST_FULL_OFFSET ( 13'd258 ),
|
| 41 |
+
.DATA_WIDTH ( 72 ),
|
| 42 |
+
.DO_REG ( 1 ),
|
| 43 |
+
.EN_ECC_READ ( "FALSE" ),
|
| 44 |
+
.EN_ECC_WRITE ( "FALSE" ),
|
| 45 |
+
.EN_SYN ( "FALSE" ),
|
| 46 |
+
.FIFO_MODE ( "FIFO36_72" ),
|
| 47 |
+
.FIRST_WORD_FALL_THROUGH ( "TRUE" ),
|
| 48 |
+
.INIT ( 72'h0 ),
|
| 49 |
+
.SIM_DEVICE ( "7SERIES" ),
|
| 50 |
+
.SRVAL ( 72'h0 )
|
| 51 |
+
)
|
| 52 |
+
u_FIFO(
|
| 53 |
+
.RST ( RST ),
|
| 54 |
+
|
| 55 |
+
.WRCLK ( WRCLK ),
|
| 56 |
+
.WREN ( WREN ),
|
| 57 |
+
.DI ( DI ),
|
| 58 |
+
.DIP ( 8'h00 ),
|
| 59 |
+
.WRCOUNT ( WRCOUNT ),
|
| 60 |
+
.WRERR (),
|
| 61 |
+
.FULL ( FULL ),
|
| 62 |
+
.ALMOSTFULL ( AFULL ),
|
| 63 |
+
|
| 64 |
+
.RDCLK ( RDCLK ),
|
| 65 |
+
.RDEN ( RDEN ),
|
| 66 |
+
.DO ( DO ),
|
| 67 |
+
.DOP (),
|
| 68 |
+
.RDCOUNT ( RDCOUNT ),
|
| 69 |
+
.RDERR (),
|
| 70 |
+
.EMPTY ( EMPTY ),
|
| 71 |
+
.ALMOSTEMPTY ( AEMPTY ),
|
| 72 |
+
|
| 73 |
+
.REGCE ( 1'b1 ),
|
| 74 |
+
.RSTREG ( RST ),
|
| 75 |
+
|
| 76 |
+
.ECCPARITY (),
|
| 77 |
+
|
| 78 |
+
.DBITERR (),
|
| 79 |
+
.SBITERR (),
|
| 80 |
+
|
| 81 |
+
.INJECTDBITERR ( 1'b0 ),
|
| 82 |
+
.INJECTSBITERR ( 1'b0 )
|
| 83 |
+
);
|
| 84 |
+
|
| 85 |
+
endmodule
|
| 86 |
+
|
aquaxis_IPCORE/aq_axi_fifo/aq_axi_fifo.srcs/xgui/aq_axi_fifo_v1_0.tcl
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Definitional proc to organize widgets for parameters.
|
| 2 |
+
proc init_gui { IPINST } {
|
| 3 |
+
set Page0 [ipgui::add_page $IPINST -name "Page 0" -layout vertical]
|
| 4 |
+
set Component_Name [ipgui::add_param $IPINST -parent $Page0 -name Component_Name]
|
| 5 |
+
set C_ADRSWIDTH [ipgui::add_param $IPINST -parent $Page0 -name C_ADRSWIDTH]
|
| 6 |
+
set C_BASEADRS [ipgui::add_param $IPINST -parent $Page0 -name C_BASEADRS]
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
proc update_PARAM_VALUE.C_ADRSWIDTH { PARAM_VALUE.C_ADRSWIDTH } {
|
| 10 |
+
# Procedure called to update C_ADRSWIDTH when any of the dependent parameters in the arguments change
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
proc validate_PARAM_VALUE.C_ADRSWIDTH { PARAM_VALUE.C_ADRSWIDTH } {
|
| 14 |
+
# Procedure called to validate C_ADRSWIDTH
|
| 15 |
+
return true
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
proc update_PARAM_VALUE.C_BASEADRS { PARAM_VALUE.C_BASEADRS } {
|
| 19 |
+
# Procedure called to update C_BASEADRS when any of the dependent parameters in the arguments change
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
proc validate_PARAM_VALUE.C_BASEADRS { PARAM_VALUE.C_BASEADRS } {
|
| 23 |
+
# Procedure called to validate C_BASEADRS
|
| 24 |
+
return true
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
proc update_MODELPARAM_VALUE.C_BASEADRS { MODELPARAM_VALUE.C_BASEADRS PARAM_VALUE.C_BASEADRS } {
|
| 29 |
+
# Procedure called to set VHDL generic/Verilog parameter value(s) based on TCL parameter value
|
| 30 |
+
set_property value [get_property value ${PARAM_VALUE.C_BASEADRS}] ${MODELPARAM_VALUE.C_BASEADRS}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
proc update_MODELPARAM_VALUE.C_ADRSWIDTH { MODELPARAM_VALUE.C_ADRSWIDTH PARAM_VALUE.C_ADRSWIDTH } {
|
| 34 |
+
# Procedure called to set VHDL generic/Verilog parameter value(s) based on TCL parameter value
|
| 35 |
+
set_property value [get_property value ${PARAM_VALUE.C_ADRSWIDTH}] ${MODELPARAM_VALUE.C_ADRSWIDTH}
|
| 36 |
+
}
|
| 37 |
+
|
aquaxis_IPCORE/aq_axi_i2c/aq_axi_i2c.srcs/sources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 2 |
+
* Copyright (C)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
`timescale 1ns / 1ps
|
| 20 |
+
module aq_axi_i2c(
|
| 21 |
+
input ARESETN,
|
| 22 |
+
|
| 23 |
+
// --------------------------------------------------
|
| 24 |
+
// AXI4 Lite Interface
|
| 25 |
+
// --------------------------------------------------
|
| 26 |
+
input S_AXI_ACLK,
|
| 27 |
+
|
| 28 |
+
// Write Address Channel
|
| 29 |
+
input [15:0] S_AXI_AWADDR,
|
| 30 |
+
input [3:0] S_AXI_AWCACHE, // 4'b0011
|
| 31 |
+
input [2:0] S_AXI_AWPROT, // 3'b000
|
| 32 |
+
input S_AXI_AWVALID,
|
| 33 |
+
output S_AXI_AWREADY,
|
| 34 |
+
|
| 35 |
+
// Write Data Channel
|
| 36 |
+
input [31:0] S_AXI_WDATA,
|
| 37 |
+
input [3:0] S_AXI_WSTRB,
|
| 38 |
+
input S_AXI_WVALID,
|
| 39 |
+
output S_AXI_WREADY,
|
| 40 |
+
|
| 41 |
+
// Write Response Channel
|
| 42 |
+
output S_AXI_BVALID,
|
| 43 |
+
input S_AXI_BREADY,
|
| 44 |
+
output [1:0] S_AXI_BRESP,
|
| 45 |
+
|
| 46 |
+
// Read Address Channel
|
| 47 |
+
input [15:0] S_AXI_ARADDR,
|
| 48 |
+
input [3:0] S_AXI_ARCACHE, // 4'b0011
|
| 49 |
+
input [2:0] S_AXI_ARPROT, // 3'b000
|
| 50 |
+
input S_AXI_ARVALID,
|
| 51 |
+
output S_AXI_ARREADY,
|
| 52 |
+
|
| 53 |
+
// Read Data Channel
|
| 54 |
+
output [31:0] S_AXI_RDATA,
|
| 55 |
+
output [1:0] S_AXI_RRESP,
|
| 56 |
+
output S_AXI_RVALID,
|
| 57 |
+
input S_AXI_RREADY,
|
| 58 |
+
|
| 59 |
+
// I2C
|
| 60 |
+
inout I2C_SDA,
|
| 61 |
+
inout I2C_SCL
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
wire local_cs;
|
| 65 |
+
wire local_rnw;
|
| 66 |
+
wire local_ack;
|
| 67 |
+
wire [31:0] local_addr;
|
| 68 |
+
wire [3:0] local_be;
|
| 69 |
+
wire [31:0] local_wdata;
|
| 70 |
+
wire [31:0] local_rdata;
|
| 71 |
+
|
| 72 |
+
aq_axi_lite_slave u_aq_axi_lite_slave
|
| 73 |
+
(
|
| 74 |
+
.ARESETN(ARESETN),
|
| 75 |
+
.ACLK(S_AXI_ACLK),
|
| 76 |
+
|
| 77 |
+
.S_AXI_AWADDR(S_AXI_AWADDR),
|
| 78 |
+
.S_AXI_AWCACHE(S_AXI_AWCACHE),
|
| 79 |
+
.S_AXI_AWPROT(S_AXI_AWPROT),
|
| 80 |
+
.S_AXI_AWVALID(S_AXI_AWVALID),
|
| 81 |
+
.S_AXI_AWREADY(S_AXI_AWREADY),
|
| 82 |
+
|
| 83 |
+
.S_AXI_WDATA(S_AXI_WDATA),
|
| 84 |
+
.S_AXI_WSTRB(S_AXI_WSTRB),
|
| 85 |
+
.S_AXI_WVALID(S_AXI_WVALID),
|
| 86 |
+
.S_AXI_WREADY(S_AXI_WREADY),
|
| 87 |
+
|
| 88 |
+
.S_AXI_BVALID(S_AXI_BVALID),
|
| 89 |
+
.S_AXI_BREADY(S_AXI_BREADY),
|
| 90 |
+
.S_AXI_BRESP(S_AXI_BRESP),
|
| 91 |
+
|
| 92 |
+
.S_AXI_ARADDR(S_AXI_ARADDR),
|
| 93 |
+
.S_AXI_ARCACHE(S_AXI_ARCACHE),
|
| 94 |
+
.S_AXI_ARPROT(S_AXI_ARPROT),
|
| 95 |
+
.S_AXI_ARVALID(S_AXI_ARVALID),
|
| 96 |
+
.S_AXI_ARREADY(S_AXI_ARREADY),
|
| 97 |
+
|
| 98 |
+
.S_AXI_RDATA(S_AXI_RDATA),
|
| 99 |
+
.S_AXI_RRESP(S_AXI_RRESP),
|
| 100 |
+
.S_AXI_RVALID(S_AXI_RVALID),
|
| 101 |
+
.S_AXI_RREADY(S_AXI_RREADY),
|
| 102 |
+
|
| 103 |
+
.LOCAL_CS(local_cs),
|
| 104 |
+
.LOCAL_RNW(local_rnw),
|
| 105 |
+
.LOCAL_ACK(local_ack),
|
| 106 |
+
.LOCAL_ADDR(local_addr),
|
| 107 |
+
.LOCAL_BE(local_be),
|
| 108 |
+
.LOCAL_WDATA(local_wdata),
|
| 109 |
+
.LOCAL_RDATA(local_rdata),
|
| 110 |
+
|
| 111 |
+
.DEBUG(debug_slave)
|
| 112 |
+
);
|
| 113 |
+
|
| 114 |
+
wire [3:0] i2c_cmd_wr, i2c_ram_wr;
|
| 115 |
+
wire [31:0] i2c_cmd_dout, i2c_sts_dout, i2c_rdata;
|
| 116 |
+
|
| 117 |
+
reg local_cs_d;
|
| 118 |
+
always @(posedge S_AXI_ACLK or negedge ARESETN) begin
|
| 119 |
+
if(!ARESETN) begin
|
| 120 |
+
local_cs_d <= 1'b0;
|
| 121 |
+
end else begin
|
| 122 |
+
local_cs_d <= local_cs;
|
| 123 |
+
end
|
| 124 |
+
end
|
| 125 |
+
|
| 126 |
+
assign local_ack = (local_cs & (~local_rnw)) | local_cs_d;
|
| 127 |
+
assign i2c_cmd_wr[3:0] = (local_cs & (~local_rnw) & (local_addr[15:0] == 16'h0400))?local_be[3:0]:4'd0;
|
| 128 |
+
assign i2c_ram_wr[3:0] = (local_cs & (~local_rnw) & (local_addr[15:10] == 6'd0))?local_be[3:0]:4'd0;
|
| 129 |
+
|
| 130 |
+
assign local_rdata[31:0] = ((local_addr[15:10] == 6'd0)?i2c_rdata[31:0]:32'd0) |
|
| 131 |
+
((local_addr[15:0] == 16'h0400)?i2c_cmd_dout[31:0]:32'd0) |
|
| 132 |
+
((local_addr[15:0] == 16'h0404)?i2c_sts_dout[31:0]:32'd0) |
|
| 133 |
+
((local_addr[15:0] == 16'h0408)?32'hAA55AA55:32'd0);
|
| 134 |
+
|
| 135 |
+
wire w_isda, w_osda, w_oscl;
|
| 136 |
+
|
| 137 |
+
aq_i2c_master u_aq_i2c_master(
|
| 138 |
+
.rst_n(ARESETN),
|
| 139 |
+
.clk(S_AXI_ACLK),
|
| 140 |
+
|
| 141 |
+
.cmd_wr(i2c_cmd_wr[3:0]),
|
| 142 |
+
.cmd_din(local_wdata[31:0]),
|
| 143 |
+
.cmd_dout(i2c_cmd_dout[31:0]),
|
| 144 |
+
|
| 145 |
+
.sts_dout(i2c_sts_dout[31:0]),
|
| 146 |
+
|
| 147 |
+
.adrs(local_addr[9:0]),
|
| 148 |
+
.wena(i2c_ram_wr[3:0]),
|
| 149 |
+
.wdata(local_wdata[31:0]),
|
| 150 |
+
.rdata(i2c_rdata[31:0]),
|
| 151 |
+
|
| 152 |
+
.osda(w_osda),
|
| 153 |
+
.isda(w_isda),
|
| 154 |
+
.osck(w_oscl)
|
| 155 |
+
);
|
| 156 |
+
|
| 157 |
+
assign I2C_SDA = (w_osda)?1'bZ:1'b0;
|
| 158 |
+
assign w_isda = I2C_SDA;
|
| 159 |
+
assign I2C_SCL = (w_oscl)?1'b1:1'b0;
|
| 160 |
+
|
| 161 |
+
endmodule
|
aquaxis_IPCORE/aq_axi_i2c/aq_axi_i2c.srcs/sources/aq_axi_lite_slave.v
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)2014-2015 AQUAXIS TECHNOLOGY.
|
| 3 |
+
* Don't remove this header.
|
| 4 |
+
* When you use this source, there is a need to inherit this header.
|
| 5 |
+
*
|
| 6 |
+
* License
|
| 7 |
+
* For no commercial -
|
| 8 |
+
* License: The Open Software License 3.0
|
| 9 |
+
* License URI: http://www.opensource.org/licenses/OSL-3.0
|
| 10 |
+
*
|
| 11 |
+
* For commmercial -
|
| 12 |
+
* License: AQUAXIS License 1.0
|
| 13 |
+
* License URI: http://www.aquaxis.com/licenses
|
| 14 |
+
*
|
| 15 |
+
* For further information please contact.
|
| 16 |
+
* URI: http://www.aquaxis.com/
|
| 17 |
+
* E-Mail: info(at)aquaxis.com
|
| 18 |
+
*/
|
| 19 |
+
module aq_axi_lite_slave
|
| 20 |
+
(
|
| 21 |
+
// AXI4 Lite Interface
|
| 22 |
+
input ARESETN,
|
| 23 |
+
input ACLK,
|
| 24 |
+
|
| 25 |
+
// Write Address Channel
|
| 26 |
+
input [31:0] S_AXI_AWADDR,
|
| 27 |
+
input [3:0] S_AXI_AWCACHE, // 4'b0011
|
| 28 |
+
input [2:0] S_AXI_AWPROT, // 3'b000
|
| 29 |
+
input S_AXI_AWVALID,
|
| 30 |
+
output S_AXI_AWREADY,
|
| 31 |
+
|
| 32 |
+
// Write Data Channel
|
| 33 |
+
input [31:0] S_AXI_WDATA,
|
| 34 |
+
input [3:0] S_AXI_WSTRB,
|
| 35 |
+
input S_AXI_WVALID,
|
| 36 |
+
output S_AXI_WREADY,
|
| 37 |
+
|
| 38 |
+
// Write Response Channel
|
| 39 |
+
output S_AXI_BVALID,
|
| 40 |
+
input S_AXI_BREADY,
|
| 41 |
+
output [1:0] S_AXI_BRESP,
|
| 42 |
+
|
| 43 |
+
// Read Address Channel
|
| 44 |
+
input [31:0] S_AXI_ARADDR,
|
| 45 |
+
input [3:0] S_AXI_ARCACHE, // 4'b0011
|
| 46 |
+
input [2:0] S_AXI_ARPROT, // 3'b000
|
| 47 |
+
input S_AXI_ARVALID,
|
| 48 |
+
output S_AXI_ARREADY,
|
| 49 |
+
|
| 50 |
+
// Read Data Channel
|
| 51 |
+
output [31:0] S_AXI_RDATA,
|
| 52 |
+
output [1:0] S_AXI_RRESP,
|
| 53 |
+
output S_AXI_RVALID,
|
| 54 |
+
input S_AXI_RREADY,
|
| 55 |
+
|
| 56 |
+
// Local Interface
|
| 57 |
+
output LOCAL_CS,
|
| 58 |
+
output LOCAL_RNW,
|
| 59 |
+
input LOCAL_ACK,
|
| 60 |
+
output [31:0] LOCAL_ADDR,
|
| 61 |
+
output [3:0] LOCAL_BE,
|
| 62 |
+
output [31:0] LOCAL_WDATA,
|
| 63 |
+
input [31:0] LOCAL_RDATA,
|
| 64 |
+
|
| 65 |
+
output [31:0] DEBUG
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
/*
|
| 69 |
+
CACHE[3:0]
|
| 70 |
+
WA RA C B
|
| 71 |
+
0 0 0 0 Noncacheable and nonbufferable
|
| 72 |
+
0 0 0 1 Bufferable only
|
| 73 |
+
0 0 1 0 Cacheable, but do not allocate
|
| 74 |
+
0 0 1 1 Cacheable and Bufferable, but do not allocate
|
| 75 |
+
0 1 1 0 Cacheable write-through, allocate on reads only
|
| 76 |
+
0 1 1 1 Cacheable write-back, allocate on reads only
|
| 77 |
+
1 0 1 0 Cacheable write-through, allocate on write only
|
| 78 |
+
1 0 1 1 Cacheable write-back, allocate on writes only
|
| 79 |
+
1 1 1 0 Cacheable write-through, allocate on both reads and writes
|
| 80 |
+
1 1 1 1 Cacheable write-back, allocate on both reads and writes
|
| 81 |
+
|
| 82 |
+
PROR
|
| 83 |
+
[2]:0:Data Access
|
| 84 |
+
1:Instruction Access
|
| 85 |
+
[1]:0:Secure Access
|
| 86 |
+
1:NoSecure Access
|
| 87 |
+
[0]:0:Privileged Access
|
| 88 |
+
1:Normal Access
|
| 89 |
+
|
| 90 |
+
RESP
|
| 91 |
+
00: OK
|
| 92 |
+
01: EXOK
|
| 93 |
+
10: SLVERR
|
| 94 |
+
11: DECERR
|
| 95 |
+
*/
|
| 96 |
+
|
| 97 |
+
localparam S_IDLE = 2'd0;
|
| 98 |
+
localparam S_WRITE = 2'd1;
|
| 99 |
+
localparam S_WRITE2 = 2'd2;
|
| 100 |
+
localparam S_READ = 2'd3;
|
| 101 |
+
|
| 102 |
+
reg [1:0] state;
|
| 103 |
+
reg reg_rnw;
|
| 104 |
+
reg [31:0] reg_addr, reg_wdata;
|
| 105 |
+
reg [3:0] reg_be;
|
| 106 |
+
|
| 107 |
+
always @( posedge ACLK or negedge ARESETN ) begin
|
| 108 |
+
if( !ARESETN ) begin
|
| 109 |
+
state <= S_IDLE;
|
| 110 |
+
reg_rnw <= 1'b0;
|
| 111 |
+
reg_addr <= 32'd0;
|
| 112 |
+
reg_wdata <= 32'd0;
|
| 113 |
+
reg_be <= 4'd0;
|
| 114 |
+
end else begin
|
| 115 |
+
case( state )
|
| 116 |
+
S_IDLE: begin
|
| 117 |
+
if( S_AXI_AWVALID ) begin
|
| 118 |
+
reg_rnw <= 1'b0;
|
| 119 |
+
reg_addr <= S_AXI_AWADDR;
|
| 120 |
+
state <= S_WRITE;
|
| 121 |
+
end else if( S_AXI_ARVALID ) begin
|
| 122 |
+
reg_rnw <= 1'b1;
|
| 123 |
+
reg_addr <= S_AXI_ARADDR;
|
| 124 |
+
state <= S_READ;
|
| 125 |
+
end
|
| 126 |
+
end
|
| 127 |
+
S_WRITE: begin
|
| 128 |
+
if( S_AXI_WVALID ) begin
|
| 129 |
+
state <= S_WRITE2;
|
| 130 |
+
reg_wdata <= S_AXI_WDATA;
|
| 131 |
+
reg_be <= S_AXI_WSTRB;
|
| 132 |
+
end
|
| 133 |
+
end
|
| 134 |
+
S_WRITE2: begin
|
| 135 |
+
if( LOCAL_ACK & S_AXI_BREADY ) begin
|
| 136 |
+
state <= S_IDLE;
|
| 137 |
+
end
|
| 138 |
+
end
|
| 139 |
+
S_READ: begin
|
| 140 |
+
if( LOCAL_ACK & S_AXI_RREADY ) begin
|
| 141 |
+
state <= S_IDLE;
|
| 142 |
+
end
|
| 143 |
+
end
|
| 144 |
+
default: begin
|
| 145 |
+
state <= S_IDLE;
|
| 146 |
+
end
|
| 147 |
+
endcase
|
| 148 |
+
end
|
| 149 |
+
end
|
| 150 |
+
|
| 151 |
+
// Local Interface
|
| 152 |
+
assign LOCAL_CS = (( state == S_WRITE2 )?1'b1:1'b0) | (( state == S_READ )?1'b1:1'b0) | 1'b0;
|
| 153 |
+
assign LOCAL_RNW = reg_rnw;
|
| 154 |
+
assign LOCAL_ADDR = reg_addr;
|
| 155 |
+
assign LOCAL_BE = reg_be;
|
| 156 |
+
assign LOCAL_WDATA = reg_wdata;
|
| 157 |
+
|
| 158 |
+
// Write Channel
|
| 159 |
+
assign S_AXI_AWREADY = ( state == S_WRITE )?S_AXI_AWVALID:1'b0;
|
| 160 |
+
assign S_AXI_WREADY = ( state == S_WRITE )?S_AXI_WVALID:1'b0;
|
| 161 |
+
assign S_AXI_BVALID = ( state == S_WRITE2 )?LOCAL_ACK:1'b0;
|
| 162 |
+
assign S_AXI_BRESP = 2'b00;
|
| 163 |
+
|
| 164 |
+
// Read Channel
|
| 165 |
+
// assign S_AXI_ARREADY = ( state == S_READ )?S_AXI_ARVALID:1'b0;
|
| 166 |
+
assign S_AXI_ARREADY = ( state == S_IDLE )?1'b1:1'b0;
|
| 167 |
+
assign S_AXI_RVALID = ( state == S_READ )?LOCAL_ACK:1'b0;
|
| 168 |
+
assign S_AXI_RRESP = 2'b00;
|
| 169 |
+
assign S_AXI_RDATA = ( state == S_READ )?LOCAL_RDATA:32'd0;
|
| 170 |
+
|
| 171 |
+
// Debug
|
| 172 |
+
assign DEBUG[31:0] = {24'd0, 1'd0, S_AXI_RVALID, S_AXI_ARREADY, LOCAL_ACK, LOCAL_RNW, LOCAL_CS, state[1:0]};
|
| 173 |
+
endmodule
|