SlideShare a Scribd company logo
1 of 32
Download to read offline
Implementing a System-on-Chip using VHDL
Corrado Santoro
ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy
santoro@dmi.unict.it
S.D.R. Course
Corrado Santoro A VHDL SoC
Our SoC is made of ...
A clock generator, we use the built-in 50 MHz clock
provided in the Altera DE0 board
A CPU, we will use a 32-bit RISC architecture (not
pipelined)
A ROM, where we will place (statically) our code
A Parallel I/O Port, 32-bit, connected to the 4-digit hex
display and to switches and pushbuttons
Corrado Santoro A VHDL SoC
Part I
CPU Architecture
Corrado Santoro A VHDL SoC
Basic CPU Architecture
A 32-bits MIPS-like processor:
DATA BUS and ADDRESS BUS are 32-bits wide
Memory is organised in words 32-bits wide
Also CPU instructions are 32-bits wide
Registers:
32 general purpose registers R0-R31
R0 is read-only and contains always “0” (like the MIPS
processor)
Program Counter (PC), contains the memory address of
the next instruction
Instruction Register (IR), contains the current instruction to
be executed
Corrado Santoro A VHDL SoC
Instruction Set
Basic opcode structure
Opcode(6 bits) Additional parameters(26 bits)
Arithmetic/Logic Register-type opcodes
Opcode(6) Rs(5) Rt(5) Rd(5) p(11)
”010001”, MOV Rs → Rt (Rd is not used)
”010010”, ADD Rs + Rt → Rd
”010011”, SUB Rs - Rt → Rd
MOV R1, R2 010001 00001 00010 00000 00000000000
ADD R1, R4, R2 010010 00001 00100 00010 00000000000
SUB R0, R7, R3 010011 00000 00111 00011 00000000000
Corrado Santoro A VHDL SoC
Instruction Set
Immediate-type opcodes
Opcode(6) Rs(5) Rt(5) Immediate(16)
”001000”, ADD I Rs + Immediate → Rt
”001001”, SUB I Rs - Immediate → Rt
”000100”, BEQ, Jump to “Immediate” address if Rs = Rt
”000101”, BNE, Jump to “Immediate” address if Rs not = Rt
”100011”, LW, load word from location Rs + “Immediate” and store it into Rt
”100011”, SW, store word from Rt into location Rs + “Immediate”
ADD I R1, #5, R2 001000 00001 00010 0000000000000101
SUB I R0, #12, R7 001001 00000 00111 0000000000001100
Corrado Santoro A VHDL SoC
Instruction Set
Other instructions
Opcode(6 bits) parameter(26 bits)
”000000”, NOP
”010010”, JUMP, absolute jump to “parameter” address
”111111”, HALT
Corrado Santoro A VHDL SoC
Part II
Hardware Components
Corrado Santoro A VHDL SoC
CPU
clock, input, the main CPU clock
nRst, input, hardware RESET, active low
address bus, 32-bit, output
data bus, 32-bit, bidirectional
control bus:
nMemWr, output, active low when a memory write is executed
nMemRd, output, active low when a memory read is executed
nHalt, output, active low when the CPU is in the HALT state
Corrado Santoro A VHDL SoC
ROM
clock, input, the main clock
address bus, 32-bit, input, address to be read
data bus, 32-bit, output, data read
nMemRd, input, active low when a memory read is executed
The ROM is designed to contain the software to be executed
which is hard-coded in the VHDL file.
Corrado Santoro A VHDL SoC
Digital Output Port
clock, input, the main clock
nRst, input, RESET, active low
address bus, 32-bit, input, address to be written
data bus, 32-bit, bidirectional, data bus
nMemWr, input, active low when a memory write is executed
nMemRd, input, active low when a memory read is executed
data output, 32-bit, output, the data that has been written to the port
data input, 32-bit, input, the data that has been read from the port
The module reacts to memory address 0x8000
When a “store” instruction to address 0x8000 is executed, the written data
appears on data output pins.
When a “load” instruction from address 0x8000 is executed, the data
present on data input pins is read.
Corrado Santoro A VHDL SoC
Tri-state Outputs
Corrado Santoro A VHDL SoC
ROM Timings
ROM (and peripherals) synchronises on falling edge of the
clock
First the address to be read is set-up on the address bus (by the CPU)
Then the nMemRd signal is asserted (by the CPU)
At the next falling edge clock, the ROM recognises the nMemRd signal
and outputs, on the data bus, the word addressed (event “A”)
When the CPU has got the word from the data bus, the nMemRd signal is
de-asserted
At the next falling edge clock, the ROM recognises that nMemRd is no
more active and puts the data bus to high impedence (event “B”)
Corrado Santoro A VHDL SoC
The ROM in VHDL
§
library ieee;
...
entity rom is
port( data_bus_out: out std_logic_vector(31 downto 0);
address_bus: in std_logic_vector(31 downto 0);
nMemRd: in std_logic;
clock: in std_logic );
end rom;
architecture rom_arch of rom is
signal out_byte: std_logic_vector(31 downto 0);
begin
process(clock)
begin
if (clock’event and clock = ’0’) then -- falling edge
if nMemRd = ’0’ then
case address_bus is
when "00000000000000000000000000000000" => out_byte <= NOP;
when "00000000000000000000000000000001" => out_byte <= ADD_I & R0 & R1 & ...;
...
when others => out_byte <= HALT;
end case;
else
out_byte <= (others => ’Z’);
end if;
end if;
end process;
data_bus_out <= out_byte;
end architecture;
¦ ¥
Corrado Santoro A VHDL SoC
Parallel I/O Timings
Parallel Output Port synchronises on falling edge of the clock
First the CPU sets-up the address of the port (0x8000), on the address
bus, and the data to be written, on the data bus
Then the nMemWr signal is asserted (by the CPU)
At the next falling edge clock, the Port recognises the nMemWr signal and
copies data from the data bus to the output port (event “A”)
After some clock cycles the CPU de-asserts nMemWr signal
Corrado Santoro A VHDL SoC
The Parallel Output Port in VHDL
§
library ieee;
...
entity ParallelInOut is
port(address_bus: in std_logic_vector(31 downto 0);
data_bus: inout std_logic_vector(31 downto 0);
data_output : out std_logic_vector(31 downto 0);
data_input : in std_logic_vector(31 downto 0);
clock: in std_logic;
nMemWr: in std_logic;
nMemRd: in std_logic;
nRst: in std_logic );
end ParallelInOut;
architecture pInOut of ParallelInOut is
begin
process(clock,nRst)
begin
if nRst = ’0’ then
data_output = (others = ’1’);
data_bus = (others = ’Z’);
elsif (clock’event and clock = ’0’) then
if address_bus = x00008000 then -- address is 0x8000
if nMemWr = ’0’ then data_output = data_bus;
elsif nMemRd = ’0’ then data_bus = data_input;
else data_bus = (others = ’Z’);
end if;
end if;
end if;
end process;
end architecture;
¦ ¥
Corrado Santoro A VHDL SoC
Part III
The CPU in VHDL
Corrado Santoro A VHDL SoC
The CPU
It is implemented as a finite-state machine triggered by
the clock signal
While all peripherals react to falling edge of the clock, the
CPU reacts to rising edge
This is required to meet harware reaction times:
At the rising edge the CPU prepares the signals on
address/data/control bus to interact with a
peripheral/memory
At the (next) falling edge the peripheral/memory executes
the action on the basis of such prepared signals
States:
RESET: entered when nRst is ’0’
FETCH 0, FETCH 1: fetch phase, executed in two clock
cycles
EXEC: execute phase, with several sub-states on the basis
of the instruction of be executed
HALT: halt phase, the CPU is stopped
Corrado Santoro A VHDL SoC
The Fetch Phase
FETCH 0: The CPU (event “A”)
outputs the Program Counter to the Address Bus
puts the Data Bus to high impedence
asserts the nMemRd signal
sets the next state to FETCH 1
At the (next) falling edge the ROM (event “B”)
recognises the nMemRd signal
outputs the word data to the data bus
Corrado Santoro A VHDL SoC
The Fetch Phase
FETCH 1: The CPU (event “C”)
reads the word from the Data Bus and stores it into the
Instruction Register
de-asserts the nMemRd signal
sets the next state to EXEC
At the (next) falling edge the ROM (event “D”)
recognises de-activation of the nMemRd signal
puts the Data Bus in the high impedence state
Corrado Santoro A VHDL SoC
The CPU in VHDL (I)
§
library ieee;
...
entity CPU is
port(clock: in std_logic;
nRst: in std_logic;
data_bus: inout std_logic_vector(31 downto 0);
address_bus: out std_logic_vector(31 downto 0);
nMemRd: out std_logic;
nMemWr: out std_logic;
nHalt: out std_logic);
end CPU;
architecture my_CPU of CPU is
type state_type is (st_reset, st_fetch_0, st_fetch_1, st_exec, st_halt);
type sub_state_type is (exec_0, exec_1);
type register_array is array(0 to 7) of std_logic_vector(31 downto 0);
signal PC: std_logic_vector(31 downto 0) := (others = ’0’);
signal IR: std_logic_vector(31 downto 0) := (others = ’0’);
signal REGS: register_array;
signal state: state_type := st_halt;
signal sub_state: sub_state_type := exec_0;
begin
process(clock,nRst)
...
¦ ¥
Corrado Santoro A VHDL SoC
The CPU in VHDL (II)
§
...
process(clock,nRst)
variable op_code : std_logic_vector(5 downto 0);
variable rd, rs, rt : integer;
variable func : std_logic_vector(5 downto 0);
variable immediate_val : std_logic_vector(15 downto 0);
variable NextPC : std_logic_vector(31 downto 0);
begin
if (nRst = ’0’) then
state = st_reset;
elsif (clock’event and clock = ’1’) then -- rising edge
NextPC := PC + 1;
case state is
when st_reset = ... ;
when st_fetch_0 = ...;
when st_fetch_1 = ...;
when st_exec = ...;
when st_halt = ...;
end case;
if (state = st_exec and sub_state = exec_0) then
PC = NextPC;
end if;
end if;
end process;
end architecture;
¦ ¥
Corrado Santoro A VHDL SoC
The CPU in VHDL (III)
§
...
case state is
when st_reset =
PC = (others = ’0’);
REGS(0) = (others = ’0’);
REGS(1) = (others = ’0’);
REGS(2) = (others = ’0’);
REGS(3) = (others = ’0’);
REGS(4) = (others = ’0’);
REGS(5) = (others = ’0’);
REGS(6) = (others = ’0’);
REGS(7) = (others = ’0’);
nMemRd = ’1’;
nMemWr = ’1’;
data_bus = (others = ’Z’);
nHalt = ’1’;
state = st_fetch_0;
...
¦ ¥
Corrado Santoro A VHDL SoC
The CPU in VHDL (IV)
§
...
case state is
...
when st_fetch_0 =
address_bus = PC;
nMemRd = ’0’;
state = st_fetch_1;
when st_fetch_1 =
IR = data_bus;
nMemRd = ’1’;
sub_state = exec_0;
state = st_exec;
...
¦ ¥
Corrado Santoro A VHDL SoC
The CPU in VHDL (V)
§
...
case state is
when st_exec =
if IR = NOP then
state = st_fetch_0;
else
op_code := IR(31 downto 26);
rs := conv_integer(IR(25 downto 21));
rt := conv_integer(IR(20 downto 16));
rd := conv_integer(IR(15 downto 11));
immediate_val := IR(15 downto 0);
func := IR(5 downto 0);
case op_code is
when MOV = ...;
when ADD = ...;
...
end case;
end if;
...
¦ ¥
Basic structure: Opcode(6 bits) Additional parameters(26 bits)
Arithmetic/Logic Register-type: Opcode(6) Rs(5) Rt(5) Rd(5) p(11)
Immediate-type: Opcode(6) Rs(5) Rt(5) Immediate(16)
Corrado Santoro A VHDL SoC
The CPU in VHDL (VI)
§
...
case op_code is
when MOV =
if rt /= 0 then -- do not write into R0
REGS(rt) = REGS(rs); -- move from rs to rt
end if;
state = st_fetch_0;
when ADD =
if rd /= 0 then -- do not write into R0
REGS(rd) = REGS(rs) + REGS(rt); -- add rs + rt into rd
end if;
state = st_fetch_0;
when SUBT =
if rd /= 0 then -- do not write into R0
REGS(rd) = REGS(rs) - REGS(rt); -- sub rs - rt into rd
end if;
state = st_fetch_0;
...
end case;
...
¦ ¥
Arithmetic/Logic Register-type: Opcode(6) Rs(5) Rt(5) Rd(5) p(11)
”010001”, MOV Rs → Rt (Rd is not used)
”010010”, ADD Rs + Rt → Rd
”010011”, SUB Rs - Rt → Rd
Corrado Santoro A VHDL SoC
The CPU in VHDL (VII)
§
...
op_code := IR(31 downto 26);
rs := conv_integer(IR(25 downto 21));
rt := conv_integer(IR(20 downto 16));
rd := conv_integer(IR(15 downto 11));
immediate_val := IR(15 downto 0);
func := IR(5 downto 0);
case op_code is
...
when ADD_I = -- Add Immediate
if rt /= 0 then
REGS(rt) = REGS(rs) + immediate_val;
end if;
state = st_fetch_0;
when JUMP = -- jump
NextPC := 000000  IR(25 downto 0);
state = st_fetch_0;
...
end case;
...
¦ ¥
Basic structure: Opcode(6 bits) Additional parameters(26 bits)
Immediate-type: Opcode(6) Rs(5) Rt(5) Immediate(16)
”001000”, ADD I Rs + Immediate → Rt
”010010”, JUMP, absolute jump to “parameter” address
Corrado Santoro A VHDL SoC
The CPU in VHDL (VIII)
§
...
case op_code is
...
when SW = -- store word
case sub_state is
when exec_0 = address_bus = immediate_val + REGS(rs);
data_bus = REGS(rt);
nMemWr = ’0’;
state = st_exec;
sub_state = exec_1;
when exec_1 = address_bus = (others = ’Z’);
data_bus = (others = ’Z’);
nMemWr = ’1’;
state = st_fetch_0;
end case;
...
¦ ¥
Immediate-type: Opcode(6) Rs(5) Rt(5) Immediate(16)
”100011”, SW, store word from Rt into location Rs + “Immediate”
Corrado Santoro A VHDL SoC
A simple “counter” program
§
0000 0000: NOP
0000 0001: ADD_I R0, R1, #1 ; R1 - R0 + 1, eqv to R1 - 1
0000 0002: SW R0, R1, #0x8000 ; MEM(R0 + 0x8000) - R1, eqv to MEM(0x8000) - R1
0000 0003: ADD_I R1, R1, #1 ; R1 - R1 + 1
0000 0004: JUMP #2 ; go to address #2
¦ ¥
§
architecture rom_arch of rom is
signal out_byte: std_logic_vector(31 downto 0);
begin
process(clock)
begin
if (clock’event and clock = ’0’) then -- falling edge
if nMemRd = ’0’ then
case address_bus is
when ..0000 = out_byte = NOP;
when ..0001 = out_byte = ADD_I  R0  R1  0000000000000001;
when ..0010 = out_byte = SW  R0  R1  1000000000000000;
when ..0011 = out_byte = ADD_I  R1  R1  0000000000000001;
when ..0100 = out_byte = JUMP  00000000000000000000000010;
when others = out_byte = HALT;
end case;
else
out_byte = (others = ’Z’);
end if;
end if;
end process;
data_bus_out = out_byte;
end architecture;
¦ ¥
Corrado Santoro A VHDL SoC
Reading Input and display data
§
0000 0000: LW R0, R1, #0x8000 ; R1 - MEM(R0 + 0x8000), eqv to R1 - MEM(0x8000)
0000 0001: SW R0, R1, #0x8000 ; MEM(R0 + 0x8000) - R1, eqv to MEM(0x8000) - R1
0000 0004: JUMP #0 ; go to address #0
¦ ¥
§
architecture rom_arch of rom is
signal out_byte: std_logic_vector(31 downto 0);
begin
process(clock)
begin
if (clock’event and clock = ’0’) then -- falling edge
if nMemRd = ’0’ then
case address_bus is
when ..00 = out_byte = LW  R0  R1  1000000000000000;
when ..01 = out_byte = SW  R0  R1  1000000000000000;
when ..10 = out_byte = JUMP  00000000000000000000000000;
when others = out_byte = (others = ’Z’);
end case;
else
out_byte = (others = ’Z’);
end if;
end if;
end process;
data_bus_out = out_byte;
end architecture;
¦ ¥
Corrado Santoro A VHDL SoC
An “up/down counter” program
§
0000 0000: NOP
0000 0001: ADD_I R0, R1, #1 ; R1 - R0 + 1, eqv to R1 - 1
0000 0002: SW R0, R1, #0x8000 ; MEM(R0 + 0x8000) - R1, eqv to MEM(0x8000) - R1
0000 0003: LW R0, R2, #0x8000 ; R2 - MEM(R0 + 0x8000), eqv to R2 - MEM(0x8000)
0000 0004: AND_I R2, R2, #1 ; R2 - R2 and 1
0000 0005: BEQ R0, R2, #8 ; if R2 = 0 go to #8
0000 0006: ADD_I R1, R1, #1 ; R1 - R1 + 1
0000 0007: JUMP #2 ; go to address #2
0000 0008: SUB_I R1, R1, #1 ; R1 - R1 - 1
0000 0009: JUMP #2 ; go to address #2
¦ ¥
§
architecture rom_arch of rom is
signal out_byte: std_logic_vector(31 downto 0);
begin
process(clock)
begin
if (clock’event and clock = ’0’) then -- falling edge
if nMemRd = ’0’ then
case address_bus is
when ..0000 = out_byte = NOP;
when ..0001 = out_byte = ADD_I  R0  R1  0000000000000001;
when ..0010 = out_byte = SW  R0  R1  1000000000000000;
when ..0011 = out_byte = LW  R0  R2  1000000000000000;
when ..0100 = out_byte = AND_I  R2  R2  0000000000000001;
when ..0101 = out_byte = BEQ  R0  R2  0000000000001000;
when ..0110 = out_byte = ADD_I  R1  R1  0000000000000001;
when ..0111 = out_byte = JUMP  00000000000000000000000010;
when ..1000 = out_byte = SUB_I  R1  R1  0000000000000001;
when ..1001 = out_byte = JUMP  00000000000000000000000010;
when others = (others = ’Z’);
end case;
else
out_byte = (others = ’Z’);
Corrado Santoro A VHDL SoC
Implementing a System-on-Chip using VHDL
Corrado Santoro
ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy
santoro@dmi.unict.it
S.D.R. Course
Corrado Santoro A VHDL SoC

More Related Content

What's hot (20)

Uart
UartUart
Uart
 
Interfacing with Atmega 16
Interfacing with Atmega 16Interfacing with Atmega 16
Interfacing with Atmega 16
 
Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUs
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Uart VHDL RTL design tutorial
Uart VHDL RTL design tutorialUart VHDL RTL design tutorial
Uart VHDL RTL design tutorial
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
Interrupts at AVR
Interrupts at AVRInterrupts at AVR
Interrupts at AVR
 
Microcontroller Instruction Set atmel
Microcontroller Instruction Set atmelMicrocontroller Instruction Set atmel
Microcontroller Instruction Set atmel
 
Lecture7
Lecture7Lecture7
Lecture7
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
Chapter5 dek3133
Chapter5 dek3133Chapter5 dek3133
Chapter5 dek3133
 
AVR Fundamentals
AVR FundamentalsAVR Fundamentals
AVR Fundamentals
 
Lecture 5 (system clock crossbar and gpio) rv012
Lecture 5 (system clock crossbar and gpio) rv012Lecture 5 (system clock crossbar and gpio) rv012
Lecture 5 (system clock crossbar and gpio) rv012
 
8051 Timers
8051 Timers8051 Timers
8051 Timers
 
I/O Ports
I/O Ports I/O Ports
I/O Ports
 
Interrupt
InterruptInterrupt
Interrupt
 
89c5131datasheet
89c5131datasheet89c5131datasheet
89c5131datasheet
 
8051 archi
8051 archi8051 archi
8051 archi
 
Ii avr-basics(1)
Ii avr-basics(1)Ii avr-basics(1)
Ii avr-basics(1)
 
Class8
Class8Class8
Class8
 

Similar to Soc

Microcontroller
MicrocontrollerMicrocontroller
MicrocontrollerSpitiq
 
Computer Organization
Computer OrganizationComputer Organization
Computer OrganizationHaripritha
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051Sadiq Rahim
 
janakiraman egsp collage I msc 4 unit
janakiraman egsp collage  I msc 4 unitjanakiraman egsp collage  I msc 4 unit
janakiraman egsp collage I msc 4 unitjanakiramang6
 
janakiraman I msc 4 unit
janakiraman I msc 4 unitjanakiraman I msc 4 unit
janakiraman I msc 4 unitjanakiramang6
 
Embedded Application : An Autonomous Robot or Line Follower Bot
Embedded Application : An Autonomous Robot or Line Follower BotEmbedded Application : An Autonomous Robot or Line Follower Bot
Embedded Application : An Autonomous Robot or Line Follower BotEr. Raju Bhardwaj
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfSIGMATAX1
 
8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.pptnotagain0712
 
Pin Description and Register Organization of 8086 Microprocessor
Pin Description and Register Organization of 8086 MicroprocessorPin Description and Register Organization of 8086 Microprocessor
Pin Description and Register Organization of 8086 MicroprocessorMuthusamy Arumugam
 

Similar to Soc (20)

Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
Assembler4
Assembler4Assembler4
Assembler4
 
lesson01.ppt
lesson01.pptlesson01.ppt
lesson01.ppt
 
Computer Organization
Computer OrganizationComputer Organization
Computer Organization
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Presentation
PresentationPresentation
Presentation
 
CAAL_CCSU_U1.pdf
CAAL_CCSU_U1.pdfCAAL_CCSU_U1.pdf
CAAL_CCSU_U1.pdf
 
Chp 2 and 3.pptx
Chp 2 and 3.pptxChp 2 and 3.pptx
Chp 2 and 3.pptx
 
Microcontroller 8051 gs
Microcontroller 8051 gsMicrocontroller 8051 gs
Microcontroller 8051 gs
 
Intel Quark HSUART
Intel Quark HSUARTIntel Quark HSUART
Intel Quark HSUART
 
janakiraman egsp collage I msc 4 unit
janakiraman egsp collage  I msc 4 unitjanakiraman egsp collage  I msc 4 unit
janakiraman egsp collage I msc 4 unit
 
janakiraman I msc 4 unit
janakiraman I msc 4 unitjanakiraman I msc 4 unit
janakiraman I msc 4 unit
 
W10: Interrupts
W10: InterruptsW10: Interrupts
W10: Interrupts
 
unit-2.pptx
unit-2.pptxunit-2.pptx
unit-2.pptx
 
Embedded Application : An Autonomous Robot or Line Follower Bot
Embedded Application : An Autonomous Robot or Line Follower BotEmbedded Application : An Autonomous Robot or Line Follower Bot
Embedded Application : An Autonomous Robot or Line Follower Bot
 
Avr microcontroller
Avr microcontrollerAvr microcontroller
Avr microcontroller
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt
 
Pin Description and Register Organization of 8086 Microprocessor
Pin Description and Register Organization of 8086 MicroprocessorPin Description and Register Organization of 8086 Microprocessor
Pin Description and Register Organization of 8086 Microprocessor
 
amba.ppt
amba.pptamba.ppt
amba.ppt
 

More from Corrado Santoro

Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Corrado Santoro
 
Pulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsPulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsCorrado Santoro
 
Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Corrado Santoro
 
Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015 Corrado Santoro
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scriptingCorrado Santoro
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converterCorrado Santoro
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersCorrado Santoro
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollersCorrado Santoro
 
How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...Corrado Santoro
 
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
Integrating Cloud Services in Behaviour  Programming for Autonomous RobotsIntegrating Cloud Services in Behaviour  Programming for Autonomous Robots
Integrating Cloud Services in Behaviour Programming for Autonomous RobotsCorrado Santoro
 
Reactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolReactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolCorrado Santoro
 

More from Corrado Santoro (14)

Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
 
The I2C Interface
The I2C InterfaceThe I2C Interface
The I2C Interface
 
Pulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsPulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUs
 
Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015
 
Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
Pillole di C++
Pillole di C++Pillole di C++
Pillole di C++
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converter
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F Microcontrollers
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
 
How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...
 
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
Integrating Cloud Services in Behaviour  Programming for Autonomous RobotsIntegrating Cloud Services in Behaviour  Programming for Autonomous Robots
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
 
Reactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolReactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA tool
 

Recently uploaded

THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 

Recently uploaded (20)

THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 

Soc

  • 1. Implementing a System-on-Chip using VHDL Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy santoro@dmi.unict.it S.D.R. Course Corrado Santoro A VHDL SoC
  • 2. Our SoC is made of ... A clock generator, we use the built-in 50 MHz clock provided in the Altera DE0 board A CPU, we will use a 32-bit RISC architecture (not pipelined) A ROM, where we will place (statically) our code A Parallel I/O Port, 32-bit, connected to the 4-digit hex display and to switches and pushbuttons Corrado Santoro A VHDL SoC
  • 3. Part I CPU Architecture Corrado Santoro A VHDL SoC
  • 4. Basic CPU Architecture A 32-bits MIPS-like processor: DATA BUS and ADDRESS BUS are 32-bits wide Memory is organised in words 32-bits wide Also CPU instructions are 32-bits wide Registers: 32 general purpose registers R0-R31 R0 is read-only and contains always “0” (like the MIPS processor) Program Counter (PC), contains the memory address of the next instruction Instruction Register (IR), contains the current instruction to be executed Corrado Santoro A VHDL SoC
  • 5. Instruction Set Basic opcode structure Opcode(6 bits) Additional parameters(26 bits) Arithmetic/Logic Register-type opcodes Opcode(6) Rs(5) Rt(5) Rd(5) p(11) ”010001”, MOV Rs → Rt (Rd is not used) ”010010”, ADD Rs + Rt → Rd ”010011”, SUB Rs - Rt → Rd MOV R1, R2 010001 00001 00010 00000 00000000000 ADD R1, R4, R2 010010 00001 00100 00010 00000000000 SUB R0, R7, R3 010011 00000 00111 00011 00000000000 Corrado Santoro A VHDL SoC
  • 6. Instruction Set Immediate-type opcodes Opcode(6) Rs(5) Rt(5) Immediate(16) ”001000”, ADD I Rs + Immediate → Rt ”001001”, SUB I Rs - Immediate → Rt ”000100”, BEQ, Jump to “Immediate” address if Rs = Rt ”000101”, BNE, Jump to “Immediate” address if Rs not = Rt ”100011”, LW, load word from location Rs + “Immediate” and store it into Rt ”100011”, SW, store word from Rt into location Rs + “Immediate” ADD I R1, #5, R2 001000 00001 00010 0000000000000101 SUB I R0, #12, R7 001001 00000 00111 0000000000001100 Corrado Santoro A VHDL SoC
  • 7. Instruction Set Other instructions Opcode(6 bits) parameter(26 bits) ”000000”, NOP ”010010”, JUMP, absolute jump to “parameter” address ”111111”, HALT Corrado Santoro A VHDL SoC
  • 9. CPU clock, input, the main CPU clock nRst, input, hardware RESET, active low address bus, 32-bit, output data bus, 32-bit, bidirectional control bus: nMemWr, output, active low when a memory write is executed nMemRd, output, active low when a memory read is executed nHalt, output, active low when the CPU is in the HALT state Corrado Santoro A VHDL SoC
  • 10. ROM clock, input, the main clock address bus, 32-bit, input, address to be read data bus, 32-bit, output, data read nMemRd, input, active low when a memory read is executed The ROM is designed to contain the software to be executed which is hard-coded in the VHDL file. Corrado Santoro A VHDL SoC
  • 11. Digital Output Port clock, input, the main clock nRst, input, RESET, active low address bus, 32-bit, input, address to be written data bus, 32-bit, bidirectional, data bus nMemWr, input, active low when a memory write is executed nMemRd, input, active low when a memory read is executed data output, 32-bit, output, the data that has been written to the port data input, 32-bit, input, the data that has been read from the port The module reacts to memory address 0x8000 When a “store” instruction to address 0x8000 is executed, the written data appears on data output pins. When a “load” instruction from address 0x8000 is executed, the data present on data input pins is read. Corrado Santoro A VHDL SoC
  • 13. ROM Timings ROM (and peripherals) synchronises on falling edge of the clock First the address to be read is set-up on the address bus (by the CPU) Then the nMemRd signal is asserted (by the CPU) At the next falling edge clock, the ROM recognises the nMemRd signal and outputs, on the data bus, the word addressed (event “A”) When the CPU has got the word from the data bus, the nMemRd signal is de-asserted At the next falling edge clock, the ROM recognises that nMemRd is no more active and puts the data bus to high impedence (event “B”) Corrado Santoro A VHDL SoC
  • 14. The ROM in VHDL § library ieee; ... entity rom is port( data_bus_out: out std_logic_vector(31 downto 0); address_bus: in std_logic_vector(31 downto 0); nMemRd: in std_logic; clock: in std_logic ); end rom; architecture rom_arch of rom is signal out_byte: std_logic_vector(31 downto 0); begin process(clock) begin if (clock’event and clock = ’0’) then -- falling edge if nMemRd = ’0’ then case address_bus is when "00000000000000000000000000000000" => out_byte <= NOP; when "00000000000000000000000000000001" => out_byte <= ADD_I & R0 & R1 & ...; ... when others => out_byte <= HALT; end case; else out_byte <= (others => ’Z’); end if; end if; end process; data_bus_out <= out_byte; end architecture; ¦ ¥ Corrado Santoro A VHDL SoC
  • 15. Parallel I/O Timings Parallel Output Port synchronises on falling edge of the clock First the CPU sets-up the address of the port (0x8000), on the address bus, and the data to be written, on the data bus Then the nMemWr signal is asserted (by the CPU) At the next falling edge clock, the Port recognises the nMemWr signal and copies data from the data bus to the output port (event “A”) After some clock cycles the CPU de-asserts nMemWr signal Corrado Santoro A VHDL SoC
  • 16. The Parallel Output Port in VHDL § library ieee; ... entity ParallelInOut is port(address_bus: in std_logic_vector(31 downto 0); data_bus: inout std_logic_vector(31 downto 0); data_output : out std_logic_vector(31 downto 0); data_input : in std_logic_vector(31 downto 0); clock: in std_logic; nMemWr: in std_logic; nMemRd: in std_logic; nRst: in std_logic ); end ParallelInOut; architecture pInOut of ParallelInOut is begin process(clock,nRst) begin if nRst = ’0’ then data_output = (others = ’1’); data_bus = (others = ’Z’); elsif (clock’event and clock = ’0’) then if address_bus = x00008000 then -- address is 0x8000 if nMemWr = ’0’ then data_output = data_bus; elsif nMemRd = ’0’ then data_bus = data_input; else data_bus = (others = ’Z’); end if; end if; end if; end process; end architecture; ¦ ¥ Corrado Santoro A VHDL SoC
  • 17. Part III The CPU in VHDL Corrado Santoro A VHDL SoC
  • 18. The CPU It is implemented as a finite-state machine triggered by the clock signal While all peripherals react to falling edge of the clock, the CPU reacts to rising edge This is required to meet harware reaction times: At the rising edge the CPU prepares the signals on address/data/control bus to interact with a peripheral/memory At the (next) falling edge the peripheral/memory executes the action on the basis of such prepared signals States: RESET: entered when nRst is ’0’ FETCH 0, FETCH 1: fetch phase, executed in two clock cycles EXEC: execute phase, with several sub-states on the basis of the instruction of be executed HALT: halt phase, the CPU is stopped Corrado Santoro A VHDL SoC
  • 19. The Fetch Phase FETCH 0: The CPU (event “A”) outputs the Program Counter to the Address Bus puts the Data Bus to high impedence asserts the nMemRd signal sets the next state to FETCH 1 At the (next) falling edge the ROM (event “B”) recognises the nMemRd signal outputs the word data to the data bus Corrado Santoro A VHDL SoC
  • 20. The Fetch Phase FETCH 1: The CPU (event “C”) reads the word from the Data Bus and stores it into the Instruction Register de-asserts the nMemRd signal sets the next state to EXEC At the (next) falling edge the ROM (event “D”) recognises de-activation of the nMemRd signal puts the Data Bus in the high impedence state Corrado Santoro A VHDL SoC
  • 21. The CPU in VHDL (I) § library ieee; ... entity CPU is port(clock: in std_logic; nRst: in std_logic; data_bus: inout std_logic_vector(31 downto 0); address_bus: out std_logic_vector(31 downto 0); nMemRd: out std_logic; nMemWr: out std_logic; nHalt: out std_logic); end CPU; architecture my_CPU of CPU is type state_type is (st_reset, st_fetch_0, st_fetch_1, st_exec, st_halt); type sub_state_type is (exec_0, exec_1); type register_array is array(0 to 7) of std_logic_vector(31 downto 0); signal PC: std_logic_vector(31 downto 0) := (others = ’0’); signal IR: std_logic_vector(31 downto 0) := (others = ’0’); signal REGS: register_array; signal state: state_type := st_halt; signal sub_state: sub_state_type := exec_0; begin process(clock,nRst) ... ¦ ¥ Corrado Santoro A VHDL SoC
  • 22. The CPU in VHDL (II) § ... process(clock,nRst) variable op_code : std_logic_vector(5 downto 0); variable rd, rs, rt : integer; variable func : std_logic_vector(5 downto 0); variable immediate_val : std_logic_vector(15 downto 0); variable NextPC : std_logic_vector(31 downto 0); begin if (nRst = ’0’) then state = st_reset; elsif (clock’event and clock = ’1’) then -- rising edge NextPC := PC + 1; case state is when st_reset = ... ; when st_fetch_0 = ...; when st_fetch_1 = ...; when st_exec = ...; when st_halt = ...; end case; if (state = st_exec and sub_state = exec_0) then PC = NextPC; end if; end if; end process; end architecture; ¦ ¥ Corrado Santoro A VHDL SoC
  • 23. The CPU in VHDL (III) § ... case state is when st_reset = PC = (others = ’0’); REGS(0) = (others = ’0’); REGS(1) = (others = ’0’); REGS(2) = (others = ’0’); REGS(3) = (others = ’0’); REGS(4) = (others = ’0’); REGS(5) = (others = ’0’); REGS(6) = (others = ’0’); REGS(7) = (others = ’0’); nMemRd = ’1’; nMemWr = ’1’; data_bus = (others = ’Z’); nHalt = ’1’; state = st_fetch_0; ... ¦ ¥ Corrado Santoro A VHDL SoC
  • 24. The CPU in VHDL (IV) § ... case state is ... when st_fetch_0 = address_bus = PC; nMemRd = ’0’; state = st_fetch_1; when st_fetch_1 = IR = data_bus; nMemRd = ’1’; sub_state = exec_0; state = st_exec; ... ¦ ¥ Corrado Santoro A VHDL SoC
  • 25. The CPU in VHDL (V) § ... case state is when st_exec = if IR = NOP then state = st_fetch_0; else op_code := IR(31 downto 26); rs := conv_integer(IR(25 downto 21)); rt := conv_integer(IR(20 downto 16)); rd := conv_integer(IR(15 downto 11)); immediate_val := IR(15 downto 0); func := IR(5 downto 0); case op_code is when MOV = ...; when ADD = ...; ... end case; end if; ... ¦ ¥ Basic structure: Opcode(6 bits) Additional parameters(26 bits) Arithmetic/Logic Register-type: Opcode(6) Rs(5) Rt(5) Rd(5) p(11) Immediate-type: Opcode(6) Rs(5) Rt(5) Immediate(16) Corrado Santoro A VHDL SoC
  • 26. The CPU in VHDL (VI) § ... case op_code is when MOV = if rt /= 0 then -- do not write into R0 REGS(rt) = REGS(rs); -- move from rs to rt end if; state = st_fetch_0; when ADD = if rd /= 0 then -- do not write into R0 REGS(rd) = REGS(rs) + REGS(rt); -- add rs + rt into rd end if; state = st_fetch_0; when SUBT = if rd /= 0 then -- do not write into R0 REGS(rd) = REGS(rs) - REGS(rt); -- sub rs - rt into rd end if; state = st_fetch_0; ... end case; ... ¦ ¥ Arithmetic/Logic Register-type: Opcode(6) Rs(5) Rt(5) Rd(5) p(11) ”010001”, MOV Rs → Rt (Rd is not used) ”010010”, ADD Rs + Rt → Rd ”010011”, SUB Rs - Rt → Rd Corrado Santoro A VHDL SoC
  • 27. The CPU in VHDL (VII) § ... op_code := IR(31 downto 26); rs := conv_integer(IR(25 downto 21)); rt := conv_integer(IR(20 downto 16)); rd := conv_integer(IR(15 downto 11)); immediate_val := IR(15 downto 0); func := IR(5 downto 0); case op_code is ... when ADD_I = -- Add Immediate if rt /= 0 then REGS(rt) = REGS(rs) + immediate_val; end if; state = st_fetch_0; when JUMP = -- jump NextPC := 000000 IR(25 downto 0); state = st_fetch_0; ... end case; ... ¦ ¥ Basic structure: Opcode(6 bits) Additional parameters(26 bits) Immediate-type: Opcode(6) Rs(5) Rt(5) Immediate(16) ”001000”, ADD I Rs + Immediate → Rt ”010010”, JUMP, absolute jump to “parameter” address Corrado Santoro A VHDL SoC
  • 28. The CPU in VHDL (VIII) § ... case op_code is ... when SW = -- store word case sub_state is when exec_0 = address_bus = immediate_val + REGS(rs); data_bus = REGS(rt); nMemWr = ’0’; state = st_exec; sub_state = exec_1; when exec_1 = address_bus = (others = ’Z’); data_bus = (others = ’Z’); nMemWr = ’1’; state = st_fetch_0; end case; ... ¦ ¥ Immediate-type: Opcode(6) Rs(5) Rt(5) Immediate(16) ”100011”, SW, store word from Rt into location Rs + “Immediate” Corrado Santoro A VHDL SoC
  • 29. A simple “counter” program § 0000 0000: NOP 0000 0001: ADD_I R0, R1, #1 ; R1 - R0 + 1, eqv to R1 - 1 0000 0002: SW R0, R1, #0x8000 ; MEM(R0 + 0x8000) - R1, eqv to MEM(0x8000) - R1 0000 0003: ADD_I R1, R1, #1 ; R1 - R1 + 1 0000 0004: JUMP #2 ; go to address #2 ¦ ¥ § architecture rom_arch of rom is signal out_byte: std_logic_vector(31 downto 0); begin process(clock) begin if (clock’event and clock = ’0’) then -- falling edge if nMemRd = ’0’ then case address_bus is when ..0000 = out_byte = NOP; when ..0001 = out_byte = ADD_I R0 R1 0000000000000001; when ..0010 = out_byte = SW R0 R1 1000000000000000; when ..0011 = out_byte = ADD_I R1 R1 0000000000000001; when ..0100 = out_byte = JUMP 00000000000000000000000010; when others = out_byte = HALT; end case; else out_byte = (others = ’Z’); end if; end if; end process; data_bus_out = out_byte; end architecture; ¦ ¥ Corrado Santoro A VHDL SoC
  • 30. Reading Input and display data § 0000 0000: LW R0, R1, #0x8000 ; R1 - MEM(R0 + 0x8000), eqv to R1 - MEM(0x8000) 0000 0001: SW R0, R1, #0x8000 ; MEM(R0 + 0x8000) - R1, eqv to MEM(0x8000) - R1 0000 0004: JUMP #0 ; go to address #0 ¦ ¥ § architecture rom_arch of rom is signal out_byte: std_logic_vector(31 downto 0); begin process(clock) begin if (clock’event and clock = ’0’) then -- falling edge if nMemRd = ’0’ then case address_bus is when ..00 = out_byte = LW R0 R1 1000000000000000; when ..01 = out_byte = SW R0 R1 1000000000000000; when ..10 = out_byte = JUMP 00000000000000000000000000; when others = out_byte = (others = ’Z’); end case; else out_byte = (others = ’Z’); end if; end if; end process; data_bus_out = out_byte; end architecture; ¦ ¥ Corrado Santoro A VHDL SoC
  • 31. An “up/down counter” program § 0000 0000: NOP 0000 0001: ADD_I R0, R1, #1 ; R1 - R0 + 1, eqv to R1 - 1 0000 0002: SW R0, R1, #0x8000 ; MEM(R0 + 0x8000) - R1, eqv to MEM(0x8000) - R1 0000 0003: LW R0, R2, #0x8000 ; R2 - MEM(R0 + 0x8000), eqv to R2 - MEM(0x8000) 0000 0004: AND_I R2, R2, #1 ; R2 - R2 and 1 0000 0005: BEQ R0, R2, #8 ; if R2 = 0 go to #8 0000 0006: ADD_I R1, R1, #1 ; R1 - R1 + 1 0000 0007: JUMP #2 ; go to address #2 0000 0008: SUB_I R1, R1, #1 ; R1 - R1 - 1 0000 0009: JUMP #2 ; go to address #2 ¦ ¥ § architecture rom_arch of rom is signal out_byte: std_logic_vector(31 downto 0); begin process(clock) begin if (clock’event and clock = ’0’) then -- falling edge if nMemRd = ’0’ then case address_bus is when ..0000 = out_byte = NOP; when ..0001 = out_byte = ADD_I R0 R1 0000000000000001; when ..0010 = out_byte = SW R0 R1 1000000000000000; when ..0011 = out_byte = LW R0 R2 1000000000000000; when ..0100 = out_byte = AND_I R2 R2 0000000000000001; when ..0101 = out_byte = BEQ R0 R2 0000000000001000; when ..0110 = out_byte = ADD_I R1 R1 0000000000000001; when ..0111 = out_byte = JUMP 00000000000000000000000010; when ..1000 = out_byte = SUB_I R1 R1 0000000000000001; when ..1001 = out_byte = JUMP 00000000000000000000000010; when others = (others = ’Z’); end case; else out_byte = (others = ’Z’); Corrado Santoro A VHDL SoC
  • 32. Implementing a System-on-Chip using VHDL Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy santoro@dmi.unict.it S.D.R. Course Corrado Santoro A VHDL SoC