Inout Ports
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 32번째.
inout 포트는 신호를 both send and receive할 수 있는 bidirectional 포트입니다. 서로 다른 시점에 input 또는 output으로 동작할 수 있습니다. 대부분의 포트는 input(데이터가 들어옴) 또는 output(데이터가 나감) 중 하나입니다. inout 포트는 두 가지 모두를 수행할 수 있습니다. 상황에 따라 데이터를 외부로 내보내거나 내부로 받을 수 있습니다.
일방통행 도로가 아니라 양방향 도로라고 생각해 보세요.
Inout 포트는 다음과 같은 용도로 사용됩니다:
- 공유 bus: 여러 장치가 동일한 전선에 연결됨
- 메모리 데이터 bus: 데이터를 읽거나 쓸 수 있음
- bidirectional 통신: I2C, SPI 등
한 번에 하나의 장치만 버스를 구동합니다. 다른 장치는 하이 임피던스 상태(Z)여야 합니다.
Inout 포트 선언
inout [7:0] data_bus; // 8비트 양방향 버스
inout ready; // 단일 비트 양방향 신호Inout의 작동 방식
inout port는 input 또는 output으로 작동할지 결정하기 위한 제어 signal이 필요합니다:
module bidir (
inout [7:0] bus,
input [7:0] data_out,
input enable,
output [7:0] data_in
);
assign bus = (enable) ? data_out : 8'bZ; // Drive bus when enabled, else Z
assign data_in = bus; // Always read the bus
endmodule- When
enable = 1, module은 bus를 drives합니다 (output 모드). - When
enable = 0, module은 bus를 해제합니다 (input 모드, high-Z).
Inout의 중요한 규칙
| 규칙 | 이유 |
|---|---|
wire로 선언해야 함 | reg일 수 없음 |
| 동시에 읽고 쓸 수 없음 | 충돌(X)이 발생할 수 있음 |
Z를 사용하여 bus를 해제 | 다른 장치가 bus를 구동할 수 있음 |
| 한 번에 하나의 드라이버만 허용 | bus 경합을 방지함 |
Inout 대 Input 대 Output
| 포트 유형 | 방향 | Drive 가능 여부 | Read 가능 여부 |
|---|---|---|---|
input | 단방향 (입력만) | 아니요 | 예 |
output | 단방향 (출력만) | 예 | 아니요 |
inout | 양방향 (둘 다) | 예 (enabled일 때) | 예 (always) |
흔한 실수
// WRONG: always 블록 안에서 inout에 할당할 수 없음
always @(posedge clk) begin
data_bus <= something; // Error! 조건과 함께 assign을 사용하세요
end
// CORRECT: enable 조건과 함께 assign을 사용하세요
assign data_bus = (enable) ? something : 8'bZ;챌린지
Add 누락된 inout port와 assign statement를 추가하여 이 양방향 버퍼가 작동하도록 하세요.
수행할 작업:
- 8비트
inoutport를 Add하고io_bus라고 called 지정하세요. send_enable이 1일 때send_value로io_bus를 drives하고, otherwiseZ로 drives하는assignstatement를 Add하세요.io_bus를receive_value로 reads하는assignstatement를 Add하세요.
직접 해보기
module bidir_buffer (
// Task 1: 여기에 io_bus라는 8비트 inout 포트를 추가하세요
input [7:0] send_value,
input send_enable,
output [7:0] receive_value
);
// Task 2: send_enable이 1일 때 send_value로 io_bus를 구동하고, 그렇지 않으면 Z로 하는 assign 문을 추가하세요
// Task 3: io_bus를 receive_value로 읽는 assign 문을 추가하세요
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 컴파일러