TL;DR

Hardware เป็นเรื่องยาก และการที่เราต้องบัดกรีทุกสิ่งทุกอย่างตามแนวคิดของเรา เพื่อแค่ลอง ก็เป็นเรื่องที่โหดร้ายเกินไป แต่อย่างน้อยโลกความเป็นจริงไม่ได้โหดร้ายมากนัก เพราะเรามี Verilog เป็นเครื่องมือให้เราจำลอง Hardware ในจินตนาการได้โดยไม่ต้องลงมือบัดกรีจริงๆ

แปปๆก็ผ่านชีวิต 4 ปีในมหาลัยมาอย่างรวดเร็ว #ปีหน้าฉันจะต้องทำงานละนะ ก็ผ่านการฝึกเป็น software guy มาเยอะน่าดู ทั้งวิชา ML, NLP, DataMining, Warehouse จนมาถึงปี4 อยู่ๆ Aj.ภารุจ บอกว่า “ภควัตครับ ครูอยากลองให้น้องปี2 ได้ฝึกลองสร้าง MIPS CPU เล่นๆเป็นโปรเจค#2 ภควัตคิดว่าไงครับ แต่ครูไม่แน่ใจว่าทำได้รึปล่าว ภควัตกับชิงชิง ลองดูให้หน่อยได้ปะครับ” พร้อมโยนลิงค์มาให้ 1 ea จะปฏิเสธก็กลัวน้องๆจะไม่ได้เจอความสนุกกับ MIPS เท่าที่ควร

ในที่สุด ก็เลยต้องมาปลี่ยนมาเป็น Hardware guy อยู่ 3 วัน #เยี่ยมจริงๆ #เยี่ยมจริงๆ #เยี่ยมจริงๆ

Verilog

จิงๆ จะพูดว่าเป็น hardware guy ได้ไม่เต็มปาก เพราะสุดท้ายก็ simulation อยู่บน software ;(

Verilog เป็น programming language ตระกูลที่เรียกว่า Hardware description languages หรือ ภาษาที่ใช้ในการอธิบายโครงสร้างทาง Hardware แล้วทำการ simulate/synthesis บลาๆๆ ซึ่งมีคู่แข่งสำคัญคือ ภาษา VHDL

What’s Different??

  • มันให้ความสำคัญ propagation time(เวลาที่สัญญาณใช้เดินทาง) and signal sensitivity(การเปลี่ยนแปลงของสัญญาณ) มากกว่า algorithm(ซึ่งส่วนใหญ่จะไม่ซับซ้อน)

  • มีทั้ง Blocking & NonBlocking operation ซึ่งเป็นหมายถึงการดำเนินการที่มีทั้งแบบที่ต้องรอคำสั่งอื่นๆ และ ไม่ต้องรอ

  • แต่ละบรรทัด รันเป็นแบบ parallel ไปพร้อมๆกัน เหมือนส่งกระแสไปในสายไฟที่จุดที่สายเชื่อมถึงกันจะไปถึงพร้อมกันละได้คำตอบพร้อมๆกัน #dataflowProgramming

  • debug จากการดู signal wave ซึ่งต้องใช้ tools อื่นๆมาช่วยอีกที(เหนื่อยมากๆ เพราะแม่งรันพร้อมกันหนิแหละ)

  • นิยม design เป็น ลำดับชั้นซ้อนไปเรื่อยๆ

Installation for Ubuntu

#1 Install Essential tools” open=”yes” style=”simple”]

sudo apt-get purge verilog

sudo apt-get install build-essential git-core autoconf gperf flex bison gtkwave

#2 Clone iverilog from git” open=”yes” style=”simple”]

git clone git://github.com/steveicarus/iverilog.git

cd verilog

#3 Makefile” open=”yes” style=”simple”]

source autoconf.sh

./configure

make

make install

** คำเตือน สิ่งที่ลงไปนั่นเป็น โปรแกรมที่ไม่มี GUI นะจ๊ะ ถ้ายังไง ลองไปใช้ “icarus verilog” หรือ Quartus II ก็ได้นะ

** เพิ่มเติม สำหรับใครที่มีแต่ window ลองดู #ฉันก็ไม่รู้ว่ามันใช้การได้รึปล่าวนะ !@#$%^& Getting started with Icarus Verilog on Windows

Write HelloWorld

ไอ้ HelloWorld กำลังจะกลายเป็นโปรแกรมมาตรฐานสำหรับแทบจะทุกภาษาซะแล้ว เพราะอย่างน้อยก็รับประกันได้ว่า มันง่ายสุดๆที่จะไม่ทำให้เกิดบั๊คแน่นอน #ถ้าเมิงไม่ซ่าเขียนไปด้วยภาษาBrainfuck

module hello_world ;

initial begin
  $display ("Hello World!");
  #10 $finish;
end

endmodule

ลองเปิด vi แล้ว สร้างไฟล์ helloworld.v ขึ่้นมาแล้วพิมโค้ดตามลงไป

แล้วก็ตามด้วยคำสั่งเพื่อ compile&run

iverilog testbench.v -o processor
vvp processor

ถ้าเห็นคำว่า Hello World! ก็แปลว่า iverilog ทำงานได้อย่างถูกต้องสมบูรณ์ >_<”

ไว้จะมาเขียนต่อ Sequential statements are placed inside a begin/end block and executed in sequential order within the block. However, the blocks themselves are executed concurrently, http://www.asic-world.com/verilog/verilog_one_day2.html The "<=" operator, This is known as a "non-blocking" assignment.แต่ละคำสั่งที่เป็นแบบนี้จะทำงานพร้อมกัน ทำให้ลำดับของคำสั่ง ไม่มีผล flop1 <= flop2; flop2 <= flop1; The other assignment operator, "=", is referred to as a blocking assignment. When "=" assignment is used, for the purposes of logic, the target variable is updated immediately A common convention is to write one moderate sized module per file (or group related tiny modules into a single file) then combine the files of the design together during compilation ------- % iverilog -o my_design -c file_list.txt % vvp my_design --------------