目次
前
次
VHDLエンティティ作成(AWK)
CPLD/FPGAを利用する場合、VHDLで回路情報を記述します。
VHDLでは、外部とのインタフェースと内部の回路を
完全に分けて記述します。
外部とのインタフェースは、エンティティ(実体)として
信号名を定義します。
例は以下。
entity ??? is
port(
nRESET : in std_logic ;
CLOCK : in std_logic ;
ENABLE : in std_logic ;
SEL : in std_logic_vector(2 downto 0);
DOUT : out std_logic --;
);
end ??? ;
信号名、入出力指定、ビット数をテキスト
ファイルに入力後、スクリプトで目的のVHDL
コードに変換。
テキストファイルに入力する情報フォーマットは以下。
- 信号名、入出力指定、ビット数をスペースで区切る
- 入力、出力、入出力は、各々0、1、2と指定
- ビット数は、1以上とする
このフォーマットによるテキストファイルの情報は
次のように指定します。
nRESET 0 1
CLOCK 0 1
ENABLE 0 1
SEL 0 3
DOUT 1 1
AWKでは、1行をフィールドで区別し、フィールドは$1
から始まります。
スクリプトの大まかな動作を考えます。
- 第1フィールドは、信号名なので加工せず文字列で出力
- 第2フィールドを利用し、in、out、inoutを指定
- 入出力は、std_logicで表現
- 第3フィールドを利用し、vectorにするか判定
- entity、port等は固定文字列を出力
エンティティは、次のフォーマットを取ります。
entity Entity_name is
port(
:
:
:
);
end Entity_name ;
エンティティのヘッダ、フッターをBEGIN、ENDに
含めるとし、スクリプトは次のように定義。
BEGIN {
printf("entity ??? is \n port(\n")
}
{
# signal name
printf(" %s : ",$1)
# judge direction
if ( $2 == "0" ) {
printf("in std_logic")
}
if ( $2 == "1" ) {
printf("out std_logic")
}
if ( $2 == "2" ) {
printf("inout std_logic")
}
# judge bus size
if ( $3 > 1 ) {
printf("_vector(%d downto 0)",$3-1)
}
printf(";\n")
}
END {
printf(" );\nend ??? ;\n")
}
実際の使い方は、以下。
I/Oリダイレクトで、ファイルに保存すると
何度でも使いまわせます。
VHDLで、PORTの中にあるリストは、最後に「;」をつけないので
手で「--」を入れなければなりません。ただし、開発環境が指摘
してくれるので、神経質になることはないと考えてます。
C言語のprintfに慣れていなければ、printを利用する
ことでも記述できます。
BEGIN {
print "entity ??? is "
print " port("
}
{
# signal name
print " " $1 " : "
# judge direction
if ( $2 == "0" ) {
printf("in std_logic")
}
if ( $2 == "1" ) {
printf("out std_logic")
}
if ( $2 == "2" ) {
printf("inout std_logic")
}
# judge bus size
if ( $3 > 1 ) {
printf("_vector(%d downto 0)",$3-1)
}
print ";"
}
END {
print " );"
print "end ??? ;"
}
目次
前
次