일 worker "토요일 밤과 일요일 아침"

3808 단어 FPGAPython3Polyphony
알란 시리토가 그리는 worker는 월요일부터 토요일까지 일하고, 전월의 금은 가지지 않고 일요일 아침을 맞이한다. 「일한다」라고 하는 것은 아직도 핀과 오지 않는다. 어느 쪽인가 하면 눈앞의 일에 사고팔고고 있다. 그래서 금요일 밤도 토요일 밤도 PC 앞이다.

Polyphony의 worker는 불평하지 않고 상주한다. 작업자는 함수 (메소드)로 표현되며 init에서 append_worker로 작업자로 등록됩니다.



위 그림과 같이 이것만이라면 그냥 무한 루프로 아무것도 생산하지 않는다. Port 또는 Queue를 사용하여 외부 또는 다른 Worker와 통신합니다. 소프트웨어의 의미 적으로는 Port보다 Queue 쪽을 알기 쉽다. Port는 어떤 시점에서 어떤 정보가 오는지 디자이너가 파악해야 한다. HDL이 필요로하는 시계 개념에 묶여 있습니다. 고위 합성은 클럭으로부터의 해방을 향하고자 하는 기술이기 때문에, 이 손의 시간적 개념을 취급하는 인터페이스와 어울리는 궁합이 나쁘다.

여기에서는 간단한 평균 필터를 써 보자. Queue 를 사용해 입력과 출력을 하고 있다.

ave_filter.py
from polyphony import rule
import polyphony
from polyphony import is_worker_running
from polyphony.io import Port, Queue
from polyphony.typing import bit, int8, int16, int18
from polyphony.timing import clksleep, clkfence, wait_rising, wait_falling


@polyphony.module
class Filter:
    def __init__(self):
        self.q = Queue(int16, 'out', maxsize=10)
        self.din = Queue(int16, 'in', maxsize=10)
        self.append_worker(self.proc)

    def proc(self):
        a0:int18 = 0
        a1:int18 = 0
        a2:int18 = 0
        a3:int18 = 0

        while is_worker_running():
            self.q.wr(a0 >> 2)
            data:int16 = self.din.rd()
            a0 = a1 + data
            a1 = a2 + data
            a2 = a3 + data
            a3 =      data

@polyphony.testbench
def test(m):
    datas = (0x5ead, 0x3eef, 0x7fff, 0x0000, 0x800)
    for data in datas:
        m.din.wr(data)

    for i in range(5):
        print(m.q.rd())

    clksleep(10)

if __name__ == '__main__':
    filter = Filter()
    test(filter)



Polyphony의 코드는 Python이므로 Python에서 실행할 수 있습니다. 본래라면 Python으로 디버깅을 완료하고 시뮬레이션하기
$ python ave_filter.py
0
6059
10087
18278
18278

생성 된 Verilog-HDL은 조금 복잡합니다. 알기 쉽게 Vivado에 그림을 그려 달라고 하자.

Fitler_filter.v
module Filter_filter
  (
    input wire clk,
    input wire rst,
    input wire signed [15:0] din_dout,
    input wire din_empty,
    output reg din_read,
    input wire q_full,
    output reg signed [15:0] q_din,
    output reg q_write
  );

좋은 웹페이지 즐겨찾기