目 次 1. はじめに... 1 2. パッケージ(PACKAGE)とコンポーネント(COMPONENT)... 1 2.1 VHDL の PACKAGE... 1 2.2 PACKAGE の 作 成... 1 2.3 COMPONENT... 2 2.4 GENERIC MAP... 5 2.5



Similar documents
if clear = 1 then Q <= " "; elsif we = 1 then Q <= D; end rtl; regs.vhdl clk 0 1 rst clear we Write Enable we 1 we 0 if clk 1 Q if rst =

VHDL VHDL VHDL i

スライド 1

フリップフロップ

VHDL

TECH_I Vol.25 改訂新版PCIデバイス設計入門

Microsoft Word - 実験4_FPGA実験2_2015


Microsoft PowerPoint LC_15.ppt

VBI VBI FM FM FM FM FM DARC DARC

Unconventional HDL Programming ( version) 1

- VHDL 演習 ( 組み合せ論理回路 ) 回路 半加算器 (half adder,fig.-) 全加算器を構成する要素である半加算器を作成する i) リスト - のコードを理解してから, コンパイル, ダウンロードする ii) 実験基板上のスイッチ W, が, の入力,LED, が, の出力とな

Microsoft PowerPoint - 集積回路工学_ ppt[読み取り専用]

問 2. タイミングチャート以下に示す VHDL コードで記述されている回路に関するタイミングチャートを完成させよ ) レジスタの動作 use IEEE.std_logic_64.all; entity RegN is generic (N : integer := 8 port ( CLK, EN

1 書 誌 作 成 機 能 (NACSIS-CAT)の 軽 量 化 合 理 化 電 子 情 報 資 源 への 適 切 な 対 応 のための 資 源 ( 人 的 資 源,システム 資 源, 経 費 を 含 む) の 確 保 のために, 書 誌 作 成 と 書 誌 管 理 作 業 の 軽 量 化 を 図

エンティティ : インタフェースを定義 entity HLFDD is port (, : in std_logic ;, : out std_logic ) ; end HLFDD ; アーキテクチャ : エンティティの実現 architecture RH1 of HLFDD is <= xor

Taro-1-14A記載例.jtd

論理設計の基礎

XML形式の電子報告書作成に当たっての留意事項

計算式の取り扱い

SXF 仕 様 実 装 規 約 版 ( 幾 何 検 定 編 ) 新 旧 対 照 表 2013/3/26 文 言 変 更 p.12(1. 基 本 事 項 ) (5)SXF 入 出 力 バージョン Ver.2 形 式 と Ver.3.0 形 式 および Ver.3.1 形 式 の 入 出 力 機 能 を

縦 計 横 計 をSUM 関 数 で 一 度 に 計 算 する 縦 横 の 合 計 を 表 示 するセルが 計 算 対 象 となる セルと 隣 接 している 場 合 は 一 度 に 合 計 を 求 め ることができます 1 計 算 対 象 となるセル 範 囲 と 合 計 を 表 示 する セル 範

POWER EGG V2.01 ユーザーズマニュアル ファイル管理編

2. 番 号 種 別 の 利 用 方 法 わが 国 の 番 号 方 式 に 照 らして INSネットでの 番 号 種 別 の 具 体 的 な 利 用 方 法 を 記 述 すると 以 下 のようにな ります (1) 番 号 種 別 (TON)= 不 定 電 話 サービスと 同 様 のダイヤル 手 順

[2] 控 除 限 度 額 繰 越 欠 損 金 を 有 する 法 人 において 欠 損 金 発 生 事 業 年 度 の 翌 事 業 年 度 以 後 の 欠 損 金 の 繰 越 控 除 にあ たっては 平 成 27 年 度 税 制 改 正 により 次 ページ 以 降 で 解 説 する の 特 例 (

Microsoft Word - CiNii看護大

Box-Jenkinsの方法

1. 表 から 値 を 抽 出 する 説 明 1.1. 表 から 値 を 抽 出 するための 関 数 について 説 明 します LOOKUP VLOOKUP HLOOKUP 関 数 は 検 索 値 に 対 応 する 値 を 検 索 値 を 含 む 一 覧 表 から 抽 出 し てくれる 関 数 です

Microsoft Word - 第3章.doc

1 変更の許可等(都市計画法第35条の2)

(2) 広 島 国 際 学 院 大 学 ( 以 下 大 学 という ) (3) 広 島 国 際 学 院 大 学 自 動 車 短 期 大 学 部 ( 以 下 短 大 という ) (4) 広 島 国 際 学 院 高 等 学 校 ( 以 下 高 校 という ) ( 学 納 金 の 種 類 ) 第 3 条

一 覧 表 ( 専 従 者 用 ) YES NOチャート( 専 従 月 額 単 価 用 ) (P.4)を 参 考 にしてください < 直 接 雇 用 者 > 一 覧 表 ( 専 従 者 用 )の 単 価 は 委 託 期 間 中 に 継 続 して 半 年 以 上 当 該 AMED 事 業

(Microsoft PowerPoint - Ver12\203o\201[\203W\203\207\203\223\203A\203b\203v\216\221\227\277.ppt)

デザインパフォーマンス向上のためのHDLコーディング法

   新潟市市税口座振替事務取扱要領

平成16年年金制度改正 ~年金の昔・今・未来を考える~

PowerPoint Presentation

スライド 1

<4D F736F F D208ED089EF95DB8CAF89C193FC8FF38BB CC8EC091D492B28DB88C8B89CA82C982C282A282C42E646F63>

入札公告 機動装備センター

回路 7 レジスタ ( 同期イネーブル及び非同期リセット付 ) 入力データを保持するのに用いる記憶素子 使用用途として, マイクロプロセッサ内部で演算や実行状態の保持に用いられる Fig4-2 のレジスタは, クロック信号の立ち上がり時かつ 信号が 1 のときに外部からの 1 ビットデータ R をレ

事前チェック提出用現況報告書作成ツール入力マニュアル(法人用)

Taro-2220(修正).jtd

入 札 参 加 資 格 申 請 システム 操 作 マニュアル 入 札 参 加 資 格 の 資 格 有 効 ( 変 更 ) 日 を 迎 えると 追 加 届 の 登 録 ができるようになります ( 入 札 参 加 資 格 申 請 の 定 時 受 付 では いずれかの 申 請 先 団 体 から 入 札 参

(2) 共 通 費 について 第 2 編 共 通 費 2 12 共 通 費 算 定 に 関 する 数 値 の 取 り 扱 い (1) 積 み 上 げによる 算 定 積 み 上 げによる 算 定 は 第 3 編 18に 準 ずる (2) 率 による 算 定 公 共 建 築 工 事 共 通 費 積 算

平 成 27 年 11 月 ~ 平 成 28 年 4 月 に 公 開 の 対 象 となった 専 門 協 議 等 における 各 専 門 委 員 等 の 寄 附 金 契 約 金 等 の 受 取 状 況 審 査 ( 別 紙 ) 専 門 協 議 等 の 件 数 専 門 委 員 数 500 万 円 超 の 受

目 次 1. 積 算 内 訳 書 に 関 する 留 意 事 項 1 ページ 2. 積 算 内 訳 書 のダウンロード 3 ページ 3. 積 算 内 訳 書 の 作 成 (Excel 2003の 場 合 ) 6 ページ 4. 積 算 内 訳 書 の 作 成 (Excel 2007の 場 合 ) 13

参加表明書・企画提案書様式

関数の構造

( 別 紙 ) 以 下 法 とあるのは 改 正 法 第 5 条 の 規 定 による 改 正 後 の 健 康 保 険 法 を 指 す ( 施 行 期 日 は 平 成 28 年 4 月 1 日 ) 1. 標 準 報 酬 月 額 の 等 級 区 分 の 追 加 について 問 1 法 改 正 により 追 加

することにより 便 名 が 重 複 しないように 入 力 する ( 入 力 例 ) 便 名 入 力 便 名 XY1 XY0001 XY23 XY0023 XY345 XY0345 XY4567 XY4567 プライベート 機 等 (1 便 目 ) プライベート 機 等 (2 便 目 )

4.5. < 参 加 表 明 書 を 提 出 する> 調 達 案 件 一 覧 の 表 示 対 象 となる 案 件 を 検 索 し 調 達 案 件 一 覧 に 表 示 させます 参 加 したい 案 件 の 調 達 案 件 名 称 行 - 入 札 参 加 資 格 確 認 申 請 / 技 術 資 料 /

容 積 率 制 限 の 概 要 1 容 積 率 制 限 の 目 的 地 域 で 行 われる 各 種 の 社 会 経 済 活 動 の 総 量 を 誘 導 することにより 建 築 物 と 道 路 等 の 公 共 施 設 とのバランスを 確 保 することを 目 的 として 行 われており 市 街 地 環

Microsoft Word - 構造振動特論-08回-2012.doc

2016 年 度 情 報 リテラシー 三 科 目 合 計 の 算 出 関 数 を 用 いて 各 教 科 の 平 均 点 と 最 高 点 を 求 めることにする この2つの 計 算 は [ホーム]タブのコマ ンドにも 用 意 されているが 今 回 は 関 数 として 作 成 する まず 表 に 三 科

FPGA と LUPO その1

2 一 般 行 政 職 給 料 表 の 状 況 ( 平 成 24 年 4 月 1 日 現 在 ) 1 級 2 級 3 級 4 級 5 級 ( 単 位 : ) 6 級 7 級 8 級 1 号 給 の 給 料 月 額 135,6 185,8 222,9 261,9 289,2 32,6 366,2 41

2 立 候 補 するには 次 に 掲 げる 条 件 を 満 たしていることとする (1) 理 事 又 は 評 議 員 2 名 以 上 の 推 薦 があること (2) 連 続 5 年 以 上 本 学 会 の 正 会 員 で 会 費 を 完 納 していること (3) 選 考 が 行 われる 前 年 の1

2011論稿_吉川宏之.indd

(Microsoft Word - Excel\211\236\227p2\217\315.docx)

前 年 度 に 比 べて 税 額 が 増 加 する 主 なケース < 土 地 > ア. 課 税 地 目 が 変 わった 前 年 中 に 農 地 から 雑 種 地 ( 駐 車 場 等 )や 宅 地 ( 住 宅 や 店 舗 )へ 変 わると 税 額 が 増 加 します イ. 家 屋 ( 住 宅 や 併

1. 業 務 概 要 貨 物 情 報 登 録 済 の 貨 物 に 対 して システムを 介 さずに 行 われた 税 関 手 続 きについて 税 関 が 許 可 承 認 等 を 行 った 旨 を 登 録 する また システムで 行 われた 以 下 の 税 関 手 続 き( 以 下 輸 出 申 告 等

Microsoft Word - FrontMatter.doc

企業結合ステップ2に関連するJICPA実務指針等の改正について③・資本連結実務指針(その2)

(1)1オールゼロ 記 録 ケース 厚 生 年 金 期 間 A B 及 びCに 係 る 旧 厚 生 年 金 保 険 法 の 老 齢 年 金 ( 以 下 旧 厚 老 という )の 受 給 者 に 時 効 特 例 法 施 行 後 厚 生 年 金 期 間 Dが 判 明 した Bは 事 業 所 記 号 が

Ver 改 訂 日 付 改 訂 内 容 1

している 5. これに 対 して 親 会 社 の 持 分 変 動 による 差 額 を 資 本 剰 余 金 として 処 理 した 結 果 資 本 剰 余 金 残 高 が 負 の 値 となるような 場 合 の 取 扱 いの 明 確 化 を 求 めるコメントが 複 数 寄 せられた 6. コメントでは 親

Prog1_14th

<4D F736F F D208DEC90AC837D836A B81698F4390B394C5816A2E646F63>

図 1 抱 合 株 式 がない 場 合 の 非 適 格 合 併 により 増 加 する 資 本 金 等 の 額 の 計 算 合 併 法 人 株 式 の 価 額 - 移 転 純 資 産 価 額 (2) 合 併 法 人 株 式 等 のみなし 株 式 割 当 等 会 社 法 上 抱 合 株 式 には 合 併

Taro-H19退職金(修正版).jtd

いう )は 警 告 をしたときは 速 やかに その 内 容 及 び 日 時 を 当 該 警 告 を 求 める 旨 の 申 出 をした 者 に 通 知 しなければならないこととされ また 警 告 をし なかったときは 速 やかに その 旨 及 び 理 由 を 当 該 警 告 を 求 める 旨 の 申

Sea-NACCS 利用者研修 【通関編】

1 林 地 台 帳 整 備 マニュアル( 案 )について 林 地 台 帳 整 備 マニュアル( 案 )の 構 成 構 成 記 載 内 容 第 1 章 はじめに 本 マニュアルの 目 的 記 載 内 容 について 説 明 しています 第 2 章 第 3 章 第 4 章 第 5 章 第 6 章 林 地

PATENTBOY/Netバージョンアップ説明書(Ver.1.92)

スライド 0

(別紙3)保険会社向けの総合的な監督指針の一部を改正する(案)

Microsoft PowerPoint 資料6 技術基準.ppt [互換モード]

事 業 概 要 利 用 時 間 休 館 日 使 用 方 法 使 用 料 施 設 を 取 り 巻 く 状 況 や 課 題 < 松 山 駅 前 駐 輪 場 > JR 松 山 駅 を 利 用 する 人 の 自 転 車 原 付 を 収 容 する 施 設 として 設 置 され 有 料 駐 輪 場 の 利 用

PowerPoint プレゼンテーション

H28記入説明書(納付金・調整金)8

RSA FA FA AND Booth FA FA RSA 3 4 5

外形標準課税に関するQ&A

3 地 震 保 険 の 割 引 地 震 保 険 に 加 入 されている 場 合 耐 震 改 修 後 保 険 料 の 割 引 (10%)が 受 けられる 場 合 があ ります ご 加 入 の 保 険 会 社 にお 問 合 せになり 宅 耐 震 改 修 証 明 書 の 写 し あるいは 固 定 資 産

長崎市民間建築物耐震化推進事業の概要

目 次 1. 論 理 関 数 IF IF の 概 要 論 理 式 の 種 類 等 号 不 等 号 具 体 的 な 使 い 方 ネスト 複 数 の 条 件 を 記 述...

スライド 1

<95CA8E86315F8A6D92E8905C8D908F9182C98AD682B782E B8B4C985E8D8096DA2E786C7378>

<4D F736F F F696E74202D208E9197BF322D31208C9A90DD B835E CC8A C982C282A282C4>

CENTNET 導 入 の 手 引 き 変 更 履 歴 No. 変 更 日 変 更 番 号 変 更 枚 数 備 考 /07/ 版 発 行 - システムリプレースにより 全 面 刷 新 //07/ 版 発 行 3 誤 字 等 の 修 正 /

目 次. WEB メールへのログイン.... メール 送 信 手 順.... メール 受 信 手 順 アドレス 帳 の 操 作 手 順 フォルダーの 操 作 手 順 メール 発 信 者 登 録 署 名 登 録 手 順 基 本 的 な 設 定

1.2. ご 利 用 環 境 推 奨 ブラウザ Internet Explorer Google Chrome(バージョン 32 時 点 で 動 作 確 認 済 み) Mozilla Firefox(バージョン 26 時 点 で 動 作 確 認 済 み) Safari 7

本 校 の 沿 革 昭 和 21 年 昭 和 49 年 昭 和 54 年 昭 和 60 年 平 成 9 年 平 成 11 年 平 成 18 年 北 海 道 庁 立 農 業 講 習 所 として 発 足 北 海 道 立 農 業 大 学 校 に 改 組 修 業 年 限 を1 年 制 から2 年 制 に 改

プログラミング基礎I(再)

佐渡市都市計画区域の見直し

2016 年 度 情 報 リテラシー 変 更 された 状 態 同 様 に 価 格 のセルを 書 式 設 定 する 場 合 は 金 額 のセルをすべて 選 択 し [ 書 式 ]のプルダウンメニューか ら[ 会 計 ]を 選 択 する すると が 追 加 され 金 額 としての 書 式 が 設 定 さ

COINS 5 2.1

積 載 せず かつ 燃 料 冷 却 水 及 び 潤 滑 油 の 全 量 を 搭 載 し 自 動 車 製 作 者 が 定 める 工 具 及 び 付 属 品 (スペアタイヤを 含 む )を 全 て 装 備 した 状 態 をいう この 場 合 に おいて 燃 料 の 全 量 を 搭 載 するとは 燃 料

Microsoft Word - ML_ListManager_10j.doc

< F2D91E A4A94AD8D7388D782CC8B9689C22E6A7464>

Transcription:

第 5 学 年 工 学 実 験 Ⅱ VHDL による 論 理 回 路 設 計 13.パッケージとコンポーネント, Function と Procedure 平 成 26 年 4 月 電 子 システム 工 学 科 香 川 高 等 専 門 学 校

目 次 1. はじめに... 1 2. パッケージ(PACKAGE)とコンポーネント(COMPONENT)... 1 2.1 VHDL の PACKAGE... 1 2.2 PACKAGE の 作 成... 1 2.3 COMPONENT... 2 2.4 GENERIC MAP... 5 2.5 GENERATE と PORT MAP... 6 2.6 CONFIGURATION... 8 2.7 BLOCK... 10 2.8 VHDL2008... 11 3. FUNCTION と PROCEDURE... 13 3.1 SUBPROGRAM... 13 3.2 ASSERT 文... 13 3.3 FUNCTION 文... 14 3.4 PROCEDURE 文... 18 参 考 文 献... 20 i

1. はじめに 文 献 [1]の 8 章 パッケージとコンポーネント,9 章 function と procedure の 抄 訳 を 提 供 する 2. パッケージ(package)とコンポーネント(component) 2.1 VHDL の package VHDL コードの 分 割, 共 有, 再 利 用 には package,component,function,procedure を 使 用 する これらは 主 コードの 外 側,すなわち,ライブラリにおかれるので,システムレベルの 参 照 になる ライブラリは,function, procedure と 定 義 文 を 含 む 複 数 の package から 構 成 される この 章 で は,ライブラリの 構 築 を 扱 う 2.2 package の 作 成 パッケージの 作 成 には,package と package body と 呼 ばれる 2 種 類 のコードが 必 要 である 以 下 に 構 文 を 示 す package package_name is declarative_part end [package][package_name]; -------------------------------- [package body package_name is [subprogram_body] [deferred_constant_specifications] end [package_body][package_name]]; 最 初 の package の 部 分 は 宣 言 のみである これには,subprogram 宣 言, 型 宣 言,subtype 宣 言, 定 数 宣 言, 信 号 宣 言,shared variable 宣 言,file 宣 言,alias 宣 言,コンポーネント 宣 言,グル ープ template 宣 言,グループ 宣 言 がある, 次 の package body 部 は,subprogram すなわち function と procedure や deferred constant ( 設 定 延 期 定 数 )がある 場 合 にのみ 必 要 とされる この 場 合 には,subprogram の 内 容 や 定 数 宣 言 がすべ て 規 定 されなければならない 例 ) my_package と 名 付 けた type,signal, 定 数 のみの 例 を 示 す この 例 では package body 部 は 不 要 である - 1 -

package my_package is type matrix is array(1 to 3, 1 to 3) of bit; signal x: matrix; constant max1, max2: integer := 255; end package; VHDL2008 では,package にも generic 定 数 宣 言 を 許 す 次 は,package body 部 が 必 要 な 例 である 例 )function と deferred constant をもつ package これは,"clk'event and clk='0'"と 同 等 である library ieee; use ieee.std_logic_1164.all; -------------------------------- package my_package is constant flag: std_logic; function down_edge(signal s: std_logic)return boolean; end my_package; -------------------------------- package body my_package is constant flag: std_logic := '1'; function down_edge(signal s: std_logic) return boolean is return (s'event and s='0'); end down_edge; end my_package; 2.3 component component は, 単 純 に,これまでのコード 構 成 と 同 じ 構 成 をとる,すなわち,library/package 宣 言 +entity 部 +architecture 部 である ただ,component として 再 利 用 性 や 階 層 設 計 を 意 図 して 宣 言 している 一 般 的 によく 使 用 する 加 算 器, 乗 算 器,マルチプレクサなどは component 化 される component を 用 いる 設 計 は 構 造 的 設 計 と 呼 ばれる component は,architecture, package, generate,block 内 で 定 義 できる component の 使 用 には, 宣 言 部 と 実 装 部 (instantiation)が 必 要 である 以 下 に component 宣 言 の 構 文 を 示 す component component_name [is] [ generic ( const_name: const_type := const_value; const_name: const_type := const_value;...);] port( port_name: portmode signal_type; port_name: portmode signal_type;...); end component [component name]; - 2 -

次 に component 実 装 宣 言 の 構 文 を 示 す label: [component] component_name [generic map (generic_list)] port map(port_list); component 宣 言 は, 設 計 回 路 の entity 部 の 正 確 なコピーである generic 部 は, 実 装 時 に generic map により 変 更 する generic list がある 場 合 に 記 述 する component 実 装 では,label が 必 須 である 例 ) 3 入 力 NAND --- component declaration ------- component nand3 is port(a1, a2, a3: in std_logic; b: out std_logic); end component; --- component instantiation ------ nand_gate: nand3 port map (x1, x2, x3, y); この 例 では,component のオリジナルの 信 号 a1, a2, a3, b と 回 路 の 信 号 x1, x2, x3, y の 関 連 付 けを 位 置 によって 行 っている (1) マッピングのオプション マッピングには, 位 置 による 関 連 付 けと 名 前 による 関 連 付 けがある VHDL2008 の 拡 張 も 含 めて 以 下 に 示 す ---- component instantiation ----- nand3_1: nand3 port map (x1, x2, x3, y); -- positional mapping nand3_2: nand3 port map (a1=>x1, a2=>x2, a3=>x3, b=>y); -- nominal mapping nand3_3: nand3 port map (x1, x2, x3, open); -- positional mapping nand3_4: nand3 port map (a1=>x1, a2=>x2, a3=>x3, b=>open); -- nominal mapping 上 の 2 行 と 下 の 2 行 は 同 等 である キーワード open は, 出 力 が 未 接 続 を 表 す (2) component 宣 言 のオプション 図 1は component の 一 般 的 な 使 用 法 を 示 す (a)は,library に component 宣 言 があり,main の 中 で,component 宣 言 と component 実 装 の 両 方 を 記 述 する 方 法 である (b)は,component がライ ブラリ 中 のパッケージにある 場 合 であり,この 場 合 には main 部 には component 実 装 のみを 記 述 する (3) File/Project Assembling オプション component を 使 用 するコードのコンパイル 法 にはいくつかの 方 法 がある (a) すべてのコードを entity と 同 じ 名 前 の 1 ファイルに 収 める この 場 合 は,component 宣 言 も main 部 の 中 に 入 れる( 図 1(a)) (b) component を 別 のプロジェクトでコンパイルしておき,main 部 では component 宣 言 をする work ライブラリが 異 なる 場 合 には,use 節 によりライブラリを 明 示 する( 図 1(b)) (c) (b)と 同 様 に component を 別 にコンパイルする component 宣 言 も package に 入 れる main 部 では use 節 が 必 要 である - 3 -

library component nand Main code component 宣 言 library component nand component xor component 実 装 component xor Main code package component 実 装 component 宣 言 (a)library 中 の component 図 1 component の 使 用 (b)component 宣 言 の package 化 例 )load 付 巡 回 シフトレジスタ マルチプレクサと DFF を component として 図 2 に 示 す 巡 回 シフトレジスタを 1 ファイルでコード 化 する d 0 d 1 d 2 d 3 1 0 D Q 1 0 D Q 1 0 D Q 1 0 D Q CK CK CK CK load clk q 0 q 1 q 2 q 3 図 2 load 付 巡 回 シフトレジスタ ---- Multiplexer ----------------------------- entity mux is port (a, b, sel: in bit; x:out bit); end entity; --------------------------------- architecture mux of mux is x <= a when sel='0' else b; end architecture; ---- flipflop ----------------------------- entity flipflop is port (d, clk: in bit; q:out bit); end entity; --------------------------------- architecture flipflop of flipflop is process(clk) if (clk'event and clk='1') then q <= d; end if; end process; end architecture; - 4 -

---- main code ----------------------------- entity circular_shift is port (clk, load: in bit; d: in bit_vector(0 to 3); q: buffer_bit_vector(0 to 3)); end entity; --------------------------------- architecture structural of circular_shift is signal i: bit_vector(0 to 3); ------------------------------- component mux is port (a, b, sel: in bit; x:out bit); snd component; ------------------------------- component flipflop is port (d, clk: in bit; q:out bit); snd component; ------------------------------- mux1: mux port map (q(3), d(0), load, i(0)); mux2: mux port map (q(0), d(1), load, i(1)); mux3: mux port map (q(1), d(2), load, i(2)); mux4: mux port map (q(2), d(3), load, i(3)); dff1: flipflop port map (i(0), clk, q(0)); dff2: flipflop port map (i(1), clk, q(1)); dff3: flipflop port map (i(2), clk, q(2)); dff4: flipflop port map (i(3), clk, q(3)); end architecture; 2.4 generic map component 文 に generic 文 が 含 まれている 場 合 には,port map 文 に generic map を 記 述 する 例 ) --- component 宣 言 ----- component and_gate is generic(inputs: positive :=8); port(a: in bit_vector(1 to inputs); b: out bit); end component; ---- component instantiation ---- a1: and_gate generic map(16) port map(x, y); a2: and_gate generic map (inputs=>16) port map (a=>x, b=>y); inputs と 名 付 けたデフォルト 定 数 を 8 として 実 装 時 に 16 に 変 更 する 上 の 2 例 a1,a2 は 同 等 である component 文 中 の generic ではデフォルト 値 がなくてもよいが,generic map 文 では 規 定 しなけ ればならない - 5 -

例 ) component と generic map を 用 いたプライオリティ 検 出 器 N ビット 入 力 x 中 の 1 の 数 が 奇 数 のとき 出 力 y=1 となるプライオリティ 検 出 器 の 例 である component 宣 言 では,デフォルト 値 のない 定 数 として bits を 宣 言 しておき, 実 装 時 に generic map により main 部 で 宣 言 した 定 数 N を 設 定 している --------- The component --------------- entity par_detector is generic (bits: positive); port (input: in bit_vector(bits-1 downto 0); output: out bit); end par_detector; ----------------------------------------- architecture behavior of par_detector is process(input) variable temp: bit: temp := '0'; for i in input'range loop temp := temp xor input(i); end loop; output <= temp; end process; end behavior; ----- main code ------------------- entity parity_detector is generic (N: positive := 8); port(x: in bit_vector(n-1 downto 0); y : out bit); end parity_detector; ----------------------------------------- architecture structural of parity_detector is ------------ component par_detector is generic (bits: positive); port (input: in bit_vector(bits-1 downto 0); output: out bit); end component; ---------------- det: par_detector generic map(bits=>n) port map(input=>x, output=>y); end structural; 2.5 generate と port map 同 じ component を 多 数 使 用 する 場 合 には,generate loop 中 に port map をおいて component を 実 装 すると 便 利 である 代 表 的 な 使 用 例 を 次 に 示 す - 6 -

gen: for ion 0 to max generate comp: my_component port map (x(i), y(i), z(i)); end generate gen; 図 2 の load 付 シフトレジスタで 段 数 M, 各 データのビット 幅 を N とする 場 合 の 例 を 以 下 に 示 す 例 )component と generate を 用 いたシフトレジスタ この 例 では, 巡 回 ではなく 初 段 のマルチプレクサには 入 力 x(ビット 幅 N)が 入 るものとする ---- package ------------------------------------- package my_declarations is type twod is array (natural range <>, natural range <>) of bit; -------------- component mux is port (a, b, sel: in bit; x: out bit); end component; -------------- component flipflop is port (d, clk: in bit; q: out bit); end component; -------------- end package; ---- main code ------------------------------------ use work.my_declarations.all; ----- entity shift_register is generic (M: positive := 4; N: positive := 8); port (clk, load: in bit; x: in bit_vector(n-1 downto 0); d: in twod(0 to M-1, N-1 downto 0); y: out bit_vector(n-1 downto 0)); end entity; ----- - 7 -

architecture structural of shift_register is signal u: twod(0 to M, N-1 downto 0); signal v: twod(0 to M-1, N-1 downto 0); ---- transfer x->u and u->y ------ gen1: for i in N-1 downto 0 generate u(0,i) <= x(i); y(i) <= u(m,i); end generate gen1; ---- update internal array ------- gen2: for i in 0 to M-1 generate gen3: for j in N-1 downto 0 generate mux1: mux port map (u(i,j),d(i,j),load,v(i,j)); dff1: flipflop port map (v(i,j), clk, u(i+1,j)); end generate gen3; end generate gen2; end architecture; 2.6 configuration configuration 文 は,entity と architecture を 結 びつける 文 である プロジェクト 内 に 複 数 の architecture がある 場 合 や 複 雑 な 階 層 設 計 に 使 用 される configuration 文 は,entity や architecture の 外 に 置 かれる 以 下 の 2 形 式 がある (1) ダイレクト 形 式 configuration config_name of entity_name is for arch_name end for; end [configuration][config_name]; (2)コンポーネントの 実 装 configuration config_name of entity_name is for arch_name for label: component_name -- or for others/all: component_name use entity entity_name[(arch_name)]; end for; end for; end [configuration][config_name]; 以 下 の 例 は,2つの architecture をもつ entity に arch1 を 設 定 する 例 である - 8 -

例 ) entity test... end test; ------------------------------- architecture arch1... end arch1; ------------------------------- architecture arch2... end arch2; ------------------------------- configuration config1 of test is for arch1 end for; end configuration; 例 ) 次 は,component と generic map を 用 いたプライオリティ 検 出 器 を configuration により 書 き 直 す 例 である main code 中 の component 名 には 仮 の 名 前 detector を 使 用 し,configuration の 中 で behavior の par_detector と 接 続 する project ディレクトリは work である --------- The component --------------- entity par_detector is (ここは, 前 述 のプライオリティ 検 出 器 のコードと 同 じ) end behavior; ----------------------------------------- ----- main code ------------------- entity parity_detector is generic (N: positive := 8); port(x: in bit_vector(n-1 downto 0); y : out bit); end parity_detector; ----------------------------------------- architecture structural of parity_detector is ------------ component detector is generic (bits: positive); port (input: in bit_vector(bits-1 downto 0); output: out bit); end component; ---------------- det: detector generic map (N) port map(x,y); end structural; ----------------------------------------- configuration my_config of parity_detector is for structural for det: detector use entity work.par_detector(behavior); end for; end for; end my_config; 通 常 のコードでは,1つの entity に1つの architecture が 記 述 されるため,configuration は - 9 -

不 要 となる 2.7 block block は,システムレベル 設 計 においてコードの 分 割 を 促 進 するための 同 時 処 理 文 である block は architecture 内 で 使 用 する これを 用 いることにより 可 読 性 と 管 理 性 が 高 まる block は 順 次 処 理 内 では 使 用 できない しかし,process も 同 時 処 理 であったから,block 内 で process 文 は 使 用 できる 次 に block の 構 文 を 示 す label は 必 須 であり,guard_expression はオプションである declarative_part には,generic,generic map,port,port map と architecture の 宣 言 部 で 使 用 できるすべての 宣 言 をおくことができる label: block [(guard_expression)] [is] [declarative_part] concurrent_statements_part end block [label]; block をネストにして 複 雑 な 構 造 にもできるが, 以 下 は 単 純 な 例 である architecture example of...... controller: block... end block controller;... end example; guard_expression を 含 む block は guard block と 呼 ばれ,guard_expression 部 が true の ときのみ block 部 が 評 価 される 次 の 例 はこの 例 を 示 す しかし,guard_expression の 目 的 はドライバの 接 続, 非 接 続 にあるため 実 用 回 路 では 推 奨 しない 例 )guard block を 用 いたラッチ - 10 -

library ieee; use ieee.std_logic_1164.all; entity latch is port (d, clk: in std_logic; q: out std_logic); end entity; architecture block_latch of latch is blk: block (clk='1') q <= guarded d; end block blk; end architecture; 2.8 VHDL2008 package と component に 関 して VHDL2008 では 次 の 拡 張 がなされた (1) package の 宣 言 部 で 以 下 の 宣 言 が 可 能 である subprogram 実 装 宣 言,package 宣 言,package 実 装 宣 言 (2) package のヘッダにおいて generic 宣 言 が 可 能 以 下 に, 構 文 と 例 を 示 す package package_name is [generic (generic_list);] declarative_part end [package][package_name]; 例 ) package generic_type is generic (constant words: natural; type: word_type); type gen_type is array 1 to words of word_type; end package; (3) generic_list をもつ package は, 以 下 の 構 文 により package 実 装 宣 言 をしなければならな い package package_name is new uninstantiated_package_name generic map (instantiation_list); 上 の 例 では, 次 のようになる - 11 -

library ieee; use ieee.std_logic_1164; package memory_array is new work.generic_type generic map (instantiation_list); (4) port map の 指 定 では 以 下 のような 表 現 が 可 能 である cir: my_circuit port map I(inp=>a and b, outp => c); - 12 -

3. function と procedure 3.1 subprogram function と procedure は subprogram と 呼 ばれ, 順 次 に 処 理 されるため process とよく 似 てい る すなわち,これらでは 順 次 処 理 文 (if,wait,loop,case)のみが 使 用 可 能 である しかし,process は architecture 内 におかれるのに 対 して,subprogram は,package, entity, architecture, process のどこにおいてもよい 主 として subprogram は package におくため,システムレベルの1 ユニットと 解 釈 できる 3.2 assert 文 subprogram を 見 る 前 に 特 にシミュレーション 時 に 入 力 をチェックするのに 便 利 な assert 文 を 見 て おく assert 文 は 同 時 処 理 でも 順 次 処 理 でもある これは 論 理 合 成 には 関 係 がなくコンパイラまたはシ ミュレータへの 要 求 である assert 文 の 構 文 を 示 す [label:] assert boolean_expression [report string_expression] [severity severity_level]; string_expression は, 定 数 または string 型 の signal である 連 結 演 算 子 &が 使 える 例 ) s が"idle"であるとき report "Attention: s=" & s & "!" は,"Attention: s=idle!"というメッセージとしてスクリーンに 表 示 される severity_level は,note,warning,failure である このメッセージは 条 件 が false の 場 合 に 発 行 される error, failure が 発 生 するとコンパイラやシミュレータは 停 止 する 例 ) ある 関 数 が 2 個 の 同 一 サイズのベクトル a,b を 受 け 取 るとする assert (a'length=b'length) report "Signal a and b do not have the same length!" severity failure; このような 例 は 条 件 付 き assert 文 と 呼 ばれる, 無 条 件 assert 文 もあり, 次 の 構 文 をもつ - 13 -

[label:] assert false [report string_expression] [severity severity_level]; メッセージは 条 件 が false の 場 合 に 発 行 されるため,この 場 合 は, 強 制 発 行 になる 無 条 件 assert は,コンパイラやシミュレータがどの 時 点 まで 実 行 したかを 知 るための 有 効 な 手 段 で ある 複 雑 な assert 文 でよく 用 いられる 属 性 として,t'image(x)がある これは 型 t の 値 x を string に 変 換 する 属 性 である ただし, 元 の 型 は, 数, 列 挙 子, 物 理 型 でなければならない 例 を 示 す use ieee.std_logic_unsigned.all;... signal x, y: std_logic_vector(3 downto 0); signal n: integer range 0 to 255; signal t: time range 0ns to 200ns;... assert (x=y and n=ref) report "Mismatch at t=" & time'image(t) & "(for n=" & integer'image(n) & ", x=" & integer'image(conv_integer(x)) & ", y=" & integer'image(conv_integer(y)) & ")." severity failure;... 3.3 function 文 function は,signal と 同 様 に 順 次 処 理 文 であるから,if,wait,loop,case のみが 使 用 できる VHDL2008 拡 張 では,when と select も 使 用 できる 宣 言 部 も process 文 と 同 様 であり,signal の 宣 言 はできない 以 下 に function の 構 文 を 示 す [pure impure] function function_name [(input_list)] return return_value_type is [declarative part] statement_part [label:] return expression; end [function] [function_name]; 構 文 の 最 初 は, 後 述 の pure,impure である 指 定 がなければ pure がデフォルトである input_list は, 入 力 パラメータである これには constant,signal,file が 適 用 され,variable は 不 可 である function の 出 力 は return 文 で 示 される 1 つの 変 数 である - 14 -

例 ) function positive_edge (signal s: std_logic) return boolean is return (s'event and s='1'); end function positive_edge; function は,package,entity,architecture,process,block におくことができるが,package が 最 も 一 般 的 である 例 を 示 す ---- package ------------------------------- package my_subprograms is function positive_edge (signal s: std_logic) return boolean; end package; ---- package body ---------------------------- package body my_subprograms is function positive_edge (signal s: std_logic) return boolean is return (s'event and s='1'); end function positive_edge; end package body; (1) function call function はどこからでも 呼 び 出 すことができる 例 に 見 るように function 呼 び 出 しは expression の 1 つである 例 ) 以 下 の 2 行 は 同 等 である if positive_edge(clk) then... if clk'event and clk='1' then... (2) 位 置 による 関 連 付 け map と 名 前 による 関 連 付 け component の port map と 同 様 に function と function call の 関 連 付 けには 2 種 類 がある 例 ) ---- function declaration ------------------ function my_function (signal a, b: bit) return bit; ---- equivalent function calls ------------ y <= my_function(x1, x2); -- positional mapping y <= my_function(a=>x1, b=>x2); -- nominal mapping y <= my_function(b=>x2, a=>x1); -- nominal mapping (3) Pure と impure function function は 自 身 の 変 数 だけを 変 更 するとき,pure であると 言 われる この 場 合 は,どの 時 点 での function call も 結 果 は 同 じである これに 対 して,architecture,process,subprogram から - 15 -

呼 ばれ,signal や variable を 変 更 する 場 合 は impure であると 言 われ, 呼 び 出 すタイミングにより 同 じパラメータでも 結 果 が 異 なることがある impure 呼 び 出 しには 注 意 を 要 する VHDL2008 では function 内 で generic list が 可 能 となった 例 )architecture 内 の function max entity comparator is port (a, b, c: in integer range 0 to 255); y: out integer range 0 to 255); end entity; architecture comparator of comparator is function max (in1, in2, in3: integer) return integer is --- check in-out signal ------- assert (y'left=a'left and y'left=b'left and y'left=c'left and y'right = a'right and y'right=b'right and y'right=c'right) report "Signal sizes are not all equal!" severity failure; ---- Find maximum ------------ if (in1>=in2 and in1>=in3) then return in1; elsif (in2>=in1 and in2>=in3) then return in2; else return in3; end if; end function; y <= max(a, b, c)-- positional mapping -- y <= max(in1=> a, in2 => b; in3 => c) -- hominal mapping; eng architectute 例 )package 中 の function 入 力 の 添 え 字 を 降 順 に 並 べて, 最 後 の 数 を 0 にする 並 べ 替 えを 行 う library ieee; use ieee.numeric_std.all; package my_package is function order_and_fill (input: unsigned; bits: natural) return unsigned; end package; package body my_package is function order_and_fill (input: unsigned; bits: natural) return unsigned is variable a: unsigned (input'length-1 downto 0); variable result: unsigned (bits-1 downto 0); - 16 -

---- check input size ---- assert (input'length <= bits) report "Improper input size!" severity failure; ---- organize input ------ if (input'left > input'right) then a:= input; else for i in a'range loop a(i) := input(input'left+i); end loop; end if; ---- fill with zeros ------ if (a'length < bits) then result(bits-1 downto s'length) := (others =>'0'); result(a'length-1 sownto 0):= a; else result := a; end if; return result; end function; end package body; ---- main code --------------- library ieee; use ieee.numeric_std.all; use work.my_package.all; entity organizer is generic(size: natural :=5); port (x: in unsigned(2 to 5); y: out unsigned(size-1 downto 0)); end entity; architecture organizer of organizer is y <= order_and_fill(x, size) end architecture; - 17 -

例 )entity 内 の function std_logic_vector から integer への 変 換 library ieee; use ieee.std_logic_1164.all; entity... port (...) function slv_to_integer (signal s: std_logic_vector) return integer is alias ss: std_logic_vector(1 to s'length) is s; variable result: integer range 0 to 2**s'length-1; result := 0; for i in 1 to s'length loop result := result * 2; if (ss(i)='1' or ss(i)='h') then result := result + 1; elsif (ss(i)/='0' and ss(i)/='l') then assert false report "There is a invalid input!" severity failure; end if; end loop; return result; end function slv_to_integer; architecture... 3.4 procedure 文 procedure は,function とほとんど 同 じであるが, 返 り 値 が 複 数 になる 点 が 異 なる procedure の 構 文 を 示 す prodcedure procedure_name (input_output_list) is [declarative_part] statement_part end [procedure] [procedure_name]; input_output_list には,constant,signal,variable が 入 る モードは in,out,inout である in の 場 合 のデフォルトは constant となり,out,または,inout の 場 合 は variable がデ フォルトである 宣 言 は 次 の 形 式 をもつ constant constant_name: mode constant_type; signal signal_name: mode signal_type; variable variable_name: mode variable_type; - 18 -

function も procedure も 順 次 処 理 であるから, 順 次 処 理 文 のみが 許 される 例 )package 中 の procedure min_max ------- package ----------------------------- package my_package is procedure min_max (signal a, b, c: in integer; signal min, max: out integer); end package; package body my_package is procedure min_max (signal a, b, c: in integer range 0 to 255; signal min, max: out integer range 0 to 255) is if (a>=b) then if (a>=c) then max <= a; if (b>=c) then min <= c; else min <= b; end if; else max <= c; min <= b; end if; else if (b>=c) then max <= b; if (a>=c) then min <= c; else min <= a; end if; else max <= c; min <= a; end if; end if; end procedure; end package body; - ------- main code --------------------------- use work.my_package.all; entity comparator is port (a, b, c: in integer range -256 to 255); min, max: out integer range -256 to 255); end entity; architecture comparator of comparator is min_max(a,b,c,min,max); end architecture; - 19 -

文 献 [1] Volnei A. Pedroni:Circuit Design and Simulation with VHDL 2 nd ed., MIT Press, 2010. - 20 -