Disable Statement
CoddyのVerilogジャーニー「基礎」セクションの一部。レッスン 62/90。
disable 文は、named block(forever ループ、begin-end ブロック、またはタスクなど)の実行を停止します。これは、そのままでは永遠に実行され続けるループから抜け出すのに役立ちます。
構文:
disable block_name;ブロックには名前のラベルを付ける必要があります。
Disable と forever ループ
initial begin : counter // counter はブロックに counter という名前を付けます。
forever begin
#10 count = count + 1;
if (count == 5) begin
disable counter; // disable counter はその名前付きブロック全体を停止します。
end
end
endforever ループは named block counter の中にあります。disable counter 文はループの内側に配置されています。count が 5 に達すると、disable counter が実行され、entire block counter を停止します。その結果、forever ループも直ちに stops します。
別個の block で Disable
initial begin : counter
forever begin
#10 count = count + 1;
end
end
initial begin
#50;
disable counter; // 外側からcounterブロックを停止する
endここでは、forever ループが名前付きブロック counter 内で継続的に実行されます。disable counter ステートメントは別の initial ブロックに配置されています。50 time units 後、disable counter が実行されて counter ブロックを停止し、外部から forever ループを終了させます。
重要なルール
| ルール | 説明 |
|---|---|
| ブロックは named でなければならない | begin : block_name |
| Disable は直ちに実行を stops | その時点でコードが stops |
| どこからでも使用できる | module 内の任意の block から |
forever ループの停止に便利 | そうしないと決して停止しない |
チャレンジ
カウンターが無限に実行されるモジュールが与えられています。
行うこと:
各コメントを正しいコードに置き換えて、空の block を完成させてください:
#50;を追加して 50timeunits 待機するdisable counter;を追加してカウンターの block を停止する$display("Counter stopped");を追加してメッセージを表示する$finish;を追加して simulation を終了する
自分で試してみよう
module disable_challenge;
integer count;
initial begin
count = 0;
fork
begin : counter
forever begin
#10 count = count + 1;
$display("count = %d", count);
end
end
begin
// ステップ1: 50時間単位待つ
// ステップ2: counterブロックを無効にする
// ステップ3: "Counter stopped"を表示する
// ステップ4: シミュレーションを終了する
end
join
end
endmoduleこのレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。
基礎のすべてのレッスン
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic自分で練習してみよう: Verilogオンラインコンパイラ