# FPGA開發流程與概念

## 名詞與概念簡介

* FPGA如其名，主要由邏輯閘(GATE)構成
* FPGA開發主要透過Verilog/VHDL，也就是HDL開發(HDL Hardware Description Language又稱為硬體描述語言)
* 一般的程式主要是將程式碼編譯後產生執行檔，交由CPU執行執行檔
* HDL則會產出數位邏輯電路，並在FPGA板上完成邏輯閘接線．
* 另一個常見名詞RTL為register-transfer level，意同HDL．

## 設計流程

整體的FPGA設計流程圖如下概括，並以詳述各項細節，下面一些開發流程也會圍繞著相同概念說明各項細節

<figure><img src="https://hardwarebee.com/wp-content/uploads/2019/10/FPGA-design-flow.png" alt=""><figcaption><p>FPGA Desgin flow</p></figcaption></figure>

## 1. Design source file

當設定好要開發的功能細節之後，首先第一步就是先撰寫HDL source code．以下為一個簡單的HDL 加法器範例：<br>

```verilog
module Full_Adder( A, B, Cin, Sum, Cout );

    input A, B, Cin;
    output Sum, Cout;
	
    wire W1, W2, W3;

    xor xor1( W1, A, B );
    and and1( W2, W1, Cin );
    and and2( W3, A, B );
    xor xor2( Sum, W1, Cin );
    or  or1( Cout, W2, W3 );

endmodule
```

## 2. Behavioral Simulation

寫完HDL之後通常會寫testbench觀察波形、驗證行為正確性．

<figure><img src="https://hackster.imgix.net/uploads/attachments/1256570/_EGQSM8oN3k.blob?auto=compress%2Cformat&#x26;w=900&#x26;h=675&#x26;fit=min" alt=""><figcaption><p>Behavior Simulation 參考例圖</p></figcaption></figure>

## 3. synthesis

完成HDL source file以及模擬後，開始合成(synthesis)，此動作會將HDL(也就是verilog/VHDL)轉換成**netlist** 形式(gate-level)，gate-level指的是把全部描述語言轉換成邏輯表示式，之後再做place & route時，就是以netlist為輸入檔．

<figure><img src="https://hardwarebee.com/wp-content/uploads/2019/10/design-synthesis-netlist.png" alt=""><figcaption><p>Netlist參考力圖</p></figcaption></figure>

## 4.Implementation

當產生完netlist檔之後，下一步就要決定各個module裡面擺放位置以及繞線

<figure><img src="https://ithelp.ithome.com.tw/upload/images/20180105/20107543mrdGe3U4hF.png" alt=""><figcaption><p>首先透過先前合成產生的Netlist進行module內部繞線</p></figcaption></figure>

<figure><img src="https://ithelp.ithome.com.tw/upload/images/20180105/20107543kEcKzSaYjn.png" alt=""><figcaption><p>接著決定各模組於FPGA上的位置</p></figcaption></figure>

<figure><img src="https://ithelp.ithome.com.tw/upload/images/20180105/20107543OKR0yVIiYE.png" alt=""><figcaption><p>最後將各模組連接起來</p></figcaption></figure>

## 5.Bitstream

當implement完成後，就可以使用Bitstream轉換成類似二進制的執行檔，讓FPGA可以按照這個xxx.bit檔案，產生預期的功能與系統．

> 本篇整理節錄與參考\
> <https://ithelp.ithome.com.tw/articles/10195959>\
> &#x20;<https://hardwarebee.com/understanding-fpga-programming-and-design-flow/>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://soups-misc.gitbook.io/fpga-training/fpga-kai-fa-liu-cheng-yu-gai-nian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
