Post on 08-Jan-2016
description
Engenharia de Sistemas Embarcados 2006.2Projeto de Sistemas Embarcados
2006.2 Engenharia de Sistemas Embarcados 2
Introdução
• Processador– Circuito digital que realiza
tarefas computacionais– Controlador e caminho de
dados– Propósito geral: variedade
tarefas computacionais– Uso específico: realiza uma
tarefa em particular– Customizado: tarefa não
padrão
• Um processaodr de propósito específico customizado pode ser:– Rápido, pequeno e de baixo
consumo– Mas, alto custo NRE, time-to-
market longo, pouco flexível
Microcontroller
CCD preprocessor
Pixel coprocessorA2D
D2A
JPEG codec
DMA controller
Memory controller ISA bus interface UART LCD ctrl
Display ctrl
Multiplier/Accum
Digital camera chip
lens
CCD
2006.2 Engenharia de Sistemas Embarcados 3
CMOS transistor on silicon
• Transistor– The basic electrical component in digital systems– Acts as an on/off switch– Voltage at “gate” controls whether current flows from
source to drain– Don’t confuse this “gate” with a logic gate
source drainoxidegate
IC package IC channel
Silicon substrate
gate
source
drain
Conductsif gate=1
1
2006.2 Engenharia de Sistemas Embarcados 4
Componentes combinacionais
With enable input e all O’s are 0 if e=0
With carry-in input Ci
sum = A + B + Ci
May have status outputs carry, zero, etc.
O =I0 if S=0..00I1 if S=0..01…I(m-1) if S=1..11
O0 =1 if I=0..00O1 =1 if I=0..01…O(n-1) =1 if I=1..11
sum = A+B (first n bits)carry = (n+1)’th bit of A+B
less = 1 if A<B equal =1 if A=Bgreater=1 if A>B
O = A op Bop determinedby S.
n-bit, m x 1 Multiplexor
O
…S0
S(log m)
n
n
I(m-1) I1 I0
…
log n x n Decoder
…
O1 O0O(n-1)
I0I(log n -1)
…
n-bitAdder
n
A B
n
sumcarry
n-bitComparator
n n
A B
less equal greater
n bit, m function
ALU
n n
A B
…S0
S(log m)
n
O
2006.2 Engenharia de Sistemas Embarcados 5
Componentes Sequenciais
Q = 0 if clear=1, I if load=1 and clock=1, Q(previous) otherwise.
Q = 0 if clear=1, Q(prev)+1 if count=1 and clock=1.
clear
n-bitRegister
n
n
load
I
Q
shift
I Q
n-bitShift register
n-bitCounter
n
Q
Q = lsb - Content shifted - I stored in msb
2006.2 Engenharia de Sistemas Embarcados 6
Modelo Básico de Processador Customizado de Propósito Específico
controller and datapath
controller datapath
…
…
externalcontrolinputs
externalcontrol outputs
…
externaldata
inputs
…
externaldata
outputs
datapathcontrolinputs
datapathcontroloutputs
… …
a view inside the controller and datapath
controller datapath
… …
stateregister
next-stateand
controllogic
registers
functionalunits
2006.2 Engenharia de Sistemas Embarcados 7
Exemplo: Máximo divisor comum
GCD
(a) black-box view
x_i y_i
d_o
go_i
0: int x, y;1: while (1) {2: while (!go_i);3: x = x_i; 4: y = y_i;5: while (x != y) {6: if (x < y) 7: y = y - x; else 8: x = x - y; }9: d_o = x; }
(b) desired functionality
y = y -x7: x = x - y8:
6-J:
x!=y
5: !(x!=y)
x<y !(x<y)
6:
5-J:
1:
1
!1
x = x_i3:
y = y_i4:
2:
2-J:
!go_i
!(!go_i)
d_o = x
1-J:
9:
(c) state diagram
• Primeiro crie o algorítmo• Converta o algorítmo para
uma máquina de estados “complexa”– FSMD: máquina de estados
finito com datapath– Templates podem ser
utilizados para a conversão
2006.2 Engenharia de Sistemas Embarcados 8
Criando o fluxo de dados
• Crie um registrador para cada variável declarada
• Crie uma unidade funcional para cada operação aritmética
• Conecte as portas, registradores e unidades funcionais– Baseado em leituras e
escritas– Uso de multiplexadores para
múltiplas fontes
• Crie um identificador único– Para cada entrada e saída de
controle dos componentes do datapath
y = y -x7: x = x - y8:
6-J:
x!=y
5: !(x!=y)
x<y !(x<y)
6:
5-J:
1:
1
!1
x = x_i3:
y = y_i4:
2:
2-J:
!go_i
!(!go_i)
d_o = x
1-J:
9:
subtractor subtractor
7: y-x8: x-y5: x!=y 6: x<y
x_i y_i
d_o
0: x 0: y
9: d
n-bit 2x1 n-bit 2x1x_sel
y_sel
x_ld
y_ld
x_neq_y
x_lt_y
d_ld
<
5: x!=y
!=
Datapath
2006.2 Engenharia de Sistemas Embarcados 9
Criando o controlador da FSM
• Mesma estrutura da FSMD• Substitua ações/condições
complexas por configurações do datapath
y = y -x7: x = x - y8:
6-J:
x!=y
5: !(x!=y)
x<y !(x<y)
6:
5-J:
1:
1
!1
x = x_i3:
y = y_i4:
2:
2-J:
!go_i
!(!go_i)
d_o = x
1-J:
9:
y_sel = 1y_ld = 1
7: x_sel = 1x_ld = 1
8:
6-J:
x_neq_y
5:!x_neq_y
x_lt_y !x_lt_y
6:
5-J:
d_ld = 1
1-J:
9:
x_sel = 0x_ld = 13:
y_sel = 0y_ld = 14:
1:1
!1
2:
2-J:
!go_i
!(!go_i)
go_i
0000
0001
0010
0011
0100
0101
0110
0111 1000
1001
1010
1011
1100
Controller
subtractor subtractor
7: y-x8: x-y5: x!=y 6: x<y
x_i y_i
d_o
0: x 0: y
9: d
n-bit 2x1 n-bit 2x1x_sel
y_sel
x_ld
y_ld
x_neq_y
x_lt_y
d_ld
<
5: x!=y
!=
Datapath
2006.2 Engenharia de Sistemas Embarcados 10
Quebrando em um controlador e datapath
y_sel = 1y_ld = 1
7: x_sel = 1x_ld = 1
8:
6-J:
x_neq_y=1
5:x_neq_y=0
x_lt_y=1 x_lt_y=0
6:
5-J:
d_ld = 1
1-J:
9:
x_sel = 0x_ld = 13:
y_sel = 0y_ld = 14:
1:1
!1
2:
2-J:
!go_i
!(!go_i)
go_i
0000
0001
0010
0011
0100
0101
0110
0111 1000
1001
1010
1011
1100
ControllerController implementation model
y_sel
x_selCombinational
logic
Q3 Q0
State register
go_i
x_neq_y
x_lt_y
x_ld
y_ld
d_ld
Q2 Q1
I3 I0I2 I1
subtractor subtractor
7: y-x8: x-y5: x!=y 6: x<y
x_i y_i
d_o
0: x 0: y
9: d
n-bit 2x1 n-bit 2x1x_sel
y_sel
x_ld
y_ld
x_neq_y
x_lt_y
d_ld
<
5: x!=y
!=
(b) Datapath
2006.2 Engenharia de Sistemas Embarcados 11
Processador de Propósito Geral
• Processador de Propósito Geral– Processador projetado para uma grande variedade
de tarefas computacionais– Baixo custo unitário, em parte porque o fabricante
divide o custo NRE pelo grande número de unidades
• Motorola vendeu meio bilhão de microcontroladores 68HC05 no ano de 1996
– Projetado com bastante cuidado uma vez que o alto custo NRE é aceitável
• Pode atingir um bom desempenho, tamanho e consumo de potência
– Baixo custo NRE do sistema, time-to-market/protótipo rápido, alta flexibilidade
• Usuário escreve apenas software; não é feito o projeto do processador
2006.2 Engenharia de Sistemas Embarcados 12
Arquitetura Básica
• Unidade de Controle de Caminho de dados– Similar a
processador de propósito específico
• Principais diferenças– Caminho de dados
genérico– Unidade de controle
não armazena o algorítimo – o algorítmo é “programado” na memória
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
2006.2 Engenharia de Sistemas Embarcados 13
Operações do Datapath
• Load– Lê da memória e
carrega em registrador
• Operação da ALU– Lê registradores para a
entrada da ALU e armazena o resultado de volta em registradores• Store
– Escreve conteúdo do registrador em posição de memória
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
10
+1
11
11
2006.2 Engenharia de Sistemas Embarcados 14
Unidade de Controle
• Unidade de Controle: configura as operações do datapath– “programa” – sequencia de
operações desejadas (“instruções”) armazenadas na memória
• Ciclo de Instrução – quebrado em várias sub-operações, cada uma ocorrendo em um ciclo de relógio:– Busca: buscar próxima instrução
em IR– Decodificação: determinar o
significado da instrução– Busca de operandos: mover
dados da memória para registrador do datapath
– Execução: mover dados através da ALU
– Escrita de restultados: escreve dados dos registradores para a memória
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
load R0, M[500] 500
501
100
inc R1, R0101
store M[501], R1102
R0 R1
2006.2 Engenharia de Sistemas Embarcados 15
Sub-operações da unidade de controle
• Busca– Busca próxima
instrução para IR– PC: contador de
programa, sempre aponta para a próxima instrução
– IR: contém a instrução buscada
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
load R0, M[500] 500
501
100
inc R1, R0101
store M[501], R1102
R0 R1100 load R0, M[500]
2006.2 Engenharia de Sistemas Embarcados 16
Sub-operações da unidade de controle
• Decodificação– Determina o
significado da instrução
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
load R0, M[500] 500
501
100
inc R1, R0101
store M[501], R1102
R0 R1100 load R0, M[500]
2006.2 Engenharia de Sistemas Embarcados 17
Sub-operações da unidade de controle
• Busca de operandos– Move dados da
memória para registrador do datapath
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
load R0, M[500] 500
501
100
inc R1, R0101
store M[501], R1102
R0 R1100 load R0, M[500]
10
2006.2 Engenharia de Sistemas Embarcados 18
Sub-operações da unidade de controle
• Execução– Move dados através
da ALU– Esta instrução em
particular não faz nada durante esta sub-operação
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
load R0, M[500] 500
501
100
inc R1, R0101
store M[501], R1102
R0 R1100 load R0, M[500]
10
2006.2 Engenharia de Sistemas Embarcados 19
Sub-operaçoes da unidade de controle
• Armazenagem de resultados– Escreve dados do
registrador para memória
– Esta instrução em particular não faz nada durante esta sub-operação
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
load R0, M[500] 500
501
100
inc R1, R0101
store M[501], R1102
R0 R1100 load R0, M[500]
10
2006.2 Engenharia de Sistemas Embarcados 20
Ciclos de Instrução
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
load R0, M[500] 500
501
100
inc R1, R0101
store M[501], R1102
R0 R1
PC=100
10
Busca ops
Exec. Armz.
Result.
clk
Busca
load R0, M[500]
Decod.
100
2006.2 Engenharia de Sistemas Embarcados 21
Ciclos de Instrução
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
load R0, M[500] 500
501
100
inc R1, R0101
store M[501], R1102
R0 R1
10
PC=100Busca Decod. Busca
opsExec. Armz
resultsclk
PC=101
inc R1, R0
Busca Busca ops
+1
11
Exec. Armz results
clk
101
Decod.
2006.2 Engenharia de Sistemas Embarcados 22
Ciclos de Instrução
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
10...
...
load R0, M[500] 500
501
100
inc R1, R0101
store M[501], R1102
R0 R1
1110
PC=100Busca Decod Busca
opsExec. Armz
resultsclk
PC=101Busca Decod Busca
opsExec. Armz
resultsclk
PC=102
store M[501], R1
Busca Busca ops
Exec.
11
Armz results
clk
Decod
102
2006.2 Engenharia de Sistemas Embarcados 23
Considerações de Arquitetura
• Processdor N-bit– N-bit ALU,
registradores, barramento, interface de dados da memória
– Embarcado: comuns 8-bit, 16-bit, 32-bit
– Desktop/servidores: 32-bit, 64-bit
• PC tamanho determina o espaço de endereçamento
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
2006.2 Engenharia de Sistemas Embarcados 24
Considerações de Arquitetura
• Frequencia de Clock– Inverso do período de
clock– Deve ser mais longo
que o atraso máximo entre registradores de todo o processador
– Acesso de memória é com freqüência o mais longo
Processor
Control unit Datapath
ALU
Registers
IRPC
Controller
Memory
I/O
Control/Status
2006.2 Engenharia de Sistemas Embarcados 25
Pipelining: Aumentando o Throughput de Instrução
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
Busca-instr.
Decodificação
Busca ops.
Execução
Armazenagem res.
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
Lavagem
Dia
Tempo
Sem pipeline Com pipeline
Tempo
Time
Com pipeline
Execução de instrução com pipeline
Sem pipeline Com pipeline
Instruction 1
2006.2 Engenharia de Sistemas Embarcados 26
Arquiteturas Superscalar e VLIW
• Desempenho pode ser melhorado por:– Clock mais rápido (mas tem um limite)– Pipeline: distribuir instrução em estágios, fazer overlap
dos estágios– Múltiplas ALUs para suportar mais de um fluxo de
instrução• Superescalar
– Scalar: operações não vetorizadas– Busca de instruções em blocos, executando
tantas quanto possível» Pode requerir hardware dedicado para
detectar instruções independentes– VLIW: cada palavra de memória contém
múltiplas instruções independentes» Depende do compilador para detectar e
escalonar as instruções» Crescendo em popularidade
2006.2 Engenharia de Sistemas Embarcados 27
Arquiteturas com Duas Memórias
Processor
Program memory
Data memory
Processor
Memory(program and data)
Harvard Princeton
• Princeton– Poucas conexões de
memórias
• Harvard– Acesso simultâneo
a dados e programas
2006.2 Engenharia de Sistemas Embarcados 28
Memória Cache
• Acesso a memória pode ser lento
• Cache é uma memória pequena mas é rápida e próxima ao processador – Contém cópia de parte
da memória– Hits e misses
Processor
Memory
Cache
Tecnologia cara e rápida, usualmente no mesmo CHIP
Tecnologia lenta e mais barata, usualmente em um chip diferente
2006.2 Engenharia de Sistemas Embarcados 29
Visão do Programador
• Programador não precisa de entendimento detalhado da arquitetura– Ao invés disso, precisa saber que instruções podem ser
executadas
• Dois níveis de instrução– Nível assembly– Linguagens estruturadas (C, C++, Java, etc.)
• Grande parte do desenvolvimento é feito usando linguagens estruturadas– Mas, algum nível de programação assembly ainda pode
ser necessário– Drivers: parte do programa que se comunica com e/ou
controla outro dispositivo• Com freqüência contém considerações detalhadas de
temporização, manipulação em larga escala de bits• Nível assembly pode ser melhor neste caso
2006.2 Engenharia de Sistemas Embarcados 30
Instruções de Nível Assembly
opcode operand1 operand2
opcode operand1 operand2
opcode operand1 operand2
opcode operand1 operand2
...
Instrução 1
Instrução 2
Instrução 3
Instrução 4
• Conjunto de Instruções– Define o conjunto válido de instruções para o processador
• Transferência de dados: memória/registrador, registrador/registrador, E/S, etc.
• Lógica/aritmética: mover registrador através da ALU e de volta para o registrador
• Desvios: determina o próximo valor do PC quando este não é apenas PC + 1
2006.2 Engenharia de Sistemas Embarcados 31
Um Conjunto Simples de Instruções
opcode operandos
MOV Rn, direto
MOV @Rn, Rm
ADD Rn, Rm
0000 Rn direto
0010 Rn
0100 RmRn
Rn = M(direto)
Rn = Rn + Rm
SUB Rn, Rm 0101 Rm Rn = Rn - Rm
MOV Rn, #immed. 0011 Rn imediato Rn = imediato
Assembly instruct. Primeiro byte segundo byte Operação
JZ Rn, relativo 0110 Rn relativo PC = PC+ relativo (somente se Rn é 0)
Rn
MOV direto, Rn 0001 Rn direto M(direto) = Rn
Rm M(Rn) = Rm
2006.2 Engenharia de Sistemas Embarcados 32
Modos de Enderaçamento
Dado
Imediato
Registrador-direto
Registradorindireto
Direto
Indireto
Dado
Campo do operando
Enderço do registrador
Endereço do registrador
Endereço de memória
Endereço de memória
Endereço de memória Dado
Dado
Endereço de memória
Dado
Modo deEndereçamento
Conteúdo do arquitvo de registradores
Conteúdo da Memória
2006.2 Engenharia de Sistemas Embarcados 33
Programas Exemplos
int total = 0;for (int i=10; i!=0; i--) total += i;// next instructions...
Programa em C
MOV R0, #0; // total = 0
MOV R1, #10; // i = 10
JZ R1, Next; // Done if i=0
ADD R0, R1; // total += i
MOV R2, #1; // constant 1
JZ R3, Loop; // Jump always
Loop:
Next: // next instructions...
SUB R1, R2; // i--
Programa equivalente em assembly
MOV R3, #0; // constant 0
0
1
2
3
5
6
7
• Tente alguns outros– Handshake: Wait until the value of M[254] is not 0,
set M[255] to 1, wait until M[254] is 0, set M[255] to 0 (assume those locations are ports).
– (Harder) Count the occurrences of zero in an array stored in memory locations 100 through 199.
2006.2 Engenharia de Sistemas Embarcados 34
Considerações do Programador
• Espaço de memória de dados e programa– Com freqüência é limitado em processadores
embarcados– Ex: 64 Kbytes p/ programa, 256 bytes dados
• Registradores: quantos são?– Preocupação direta para programadores assembly
• E/S– Como se comunicar com sinais externos?
• Interrupções
2006.2 Engenharia de Sistemas Embarcados 35
Exemplo: Driver da Porta Paralela
• Utilizando programação em linguagem assembly podemos configurar uma porta paralela do PC para realizar E/S digital– Exemplo: a porta paralela pode ser utilizada para monitorar a
entrada da chave e ligar ou desligar o LED de acordo com a entrada
PC Parallel port
Pin 13
Pin 2
Switch
LED
LPT Pino de conexão Direção de E/S Endereço do Registrador
1 saída 0th bit of register #2
2-9 saída 0th bit of register #2
14,16,17 saída 1,2,3th bit of register #2
10,11,12,13,15 entrada 6,7,5,4,3th bit of register #1
2006.2 Engenharia de Sistemas Embarcados 36
Exemplo de Programa para a Porta Paralela
; This program consists of a sub-routine that reads; the state of the input pin, determining the on/off state; of our switch and asserts the output pin, turning the LED; on/off accordingly
.386
CheckPort procpush ax ; save the content
push dx ; save the contentmov dx, 3BCh + 1 ; base + 1 for register #1in al, dx ; read register #1and al, 10h ; mask out all but bit # 4cmp al, 0 ; is it 0?jne SwitchOn ; if not, we need to turn the LED on
SwitchOff:mov dx, 3BCh + 0 ; base + 0 for register #0in al, dx ; read the current state of the portand al, f7h ; clear first bit (masking)out dx, al ; write it out to the portjmp Done ; we are done
SwitchOn:mov dx, 3BCh + 0 ; base + 0 for register #0in al, dx ; read the current state of the portor al, 01h ; set first bit (masking)out dx, al ; write it out to the port
Done: pop dx ; restore the contentpop ax ; restore the content
CheckPort endp
extern “C” CheckPort(void); // defined in // assembly
void main(void) {while( 1 ) {
CheckPort();}
}
LPT Pino de conexão Direção de E/S Endereço de Registrador
1 saída 0th bit of register #2
2-9 Saída 0th bit of register #2
14,16,17 saída 1,2,3th bit of register #2
10,11,12,13,15 entrada 6,7,5,4,3th bit of register #1
PC Parallel port
Pin 13
Pin 2
Switch
LED
2006.2 Engenharia de Sistemas Embarcados 37
Sistema Operacional
• Camada de software opcional que provê serviços de baixo nível para o programa (aplicação)– Gerenciamento de arquivos, acesso a disco– Interface com teclado e display– Escalonamento de múltiplos programas para
execução• Ou até múltiplo threads em um programa
– Programa realiza chamadas de sistema para o SODB file_name “out.txt” -- store file name
MOV R0, 1324 -- system call “open” idMOV R1, file_name -- address of file-nameINT 34 -- cause a system callJZ R0, L1 -- if zero -> error
. . . read the fileJMP L2 -- bypass error cond.L1: . . . handle the error
L2:
2006.2 Engenharia de Sistemas Embarcados 38
Ambiente de Desenvolvimento
• Processador de desenvolvimento– Processador no qual escrevemos e depuramos
nossos programas• Usualmente um PC
• Processador alvo– Processador no qual o programa será executado
em nosso sistema embarcado• Com freqüência diferente do processador de
desenvolvimento
Processador de desenvolvimento
Processador alvo
2006.2 Engenharia de Sistemas Embarcados 39
Processo de Desenvolvimento de Software
Compiler
Linker
C File C File Asm. File
Binary File
Binary File
Binary File
Exec. File
Assembler
Library
Implementation Phase
Debugger
Profiler
Verification Phase
• Compiladores– Cross compiler
• Roda em um processador mas gera código para outro
• Assemblers• Linkers• Debuggers• Profilers
2006.2 Engenharia de Sistemas Embarcados 40
Executando um programa
• Se o processador de desenvolvimento é diferente do processador alvo, como podemos executar o código compilado?– Carregar (download) para o processador alvo– simular
• Simulação– Método 1: Hardware description language
• lento, nem sempre disponível
– Método 2: Instruction set simulator (ISS)• Roda no processador de desenvolvimento, mas
executa instruções do processador alvo.
2006.2 Engenharia de Sistemas Embarcados 41
Instruction Set Simulator de um processador simples
#include <stdio.h>typedef struct { unsigned char first_byte, second_byte;} instruction;
instruction program[1024]; //instruction memoryunsigned char memory[256]; //data memory
void run_program(int num_bytes) {
int pc = -1; unsigned char reg[16], fb, sb; while( ++pc < (num_bytes / 2) ) { fb = program[pc].first_byte; sb = program[pc].second_byte; switch( fb >> 4 ) { case 0: reg[fb & 0x0f] = memory[sb]; break; case 1: memory[sb] = reg[fb & 0x0f]; break; case 2: memory[reg[fb & 0x0f]] = reg[sb >> 4]; break; case 3: reg[fb & 0x0f] = sb; break; case 4: reg[fb & 0x0f] += reg[sb >> 4]; break; case 5: reg[fb & 0x0f] -= reg[sb >> 4]; break; case 6: pc += sb; break; default: return –1;
} } return 0;}
int main(int argc, char *argv[]) {
FILE* ifs;
If( argc != 2 || (ifs = fopen(argv[1], “rb”) == NULL ) { return –1; } if (run_program(fread(program, sizeof(program) == 0) {
print_memory_contents();return(0);
} else return(-1);}
2006.2 Engenharia de Sistemas Embarcados 42
Testando e Depurando
Implementation Phase
Implementation Phase
Verification Phase
Verification Phase
Emulator
Debugger/ ISS
Programmer
Development processor
(a) (b)
External tools
• ISS – Gives us control over
time – set breakpoints, look at register values, set values, step-by-step execution, ...
– But, doesn’t interact with real environment
• Download to board– Use device programmer– Runs in real
environment, but not controllable
• Compromise: emulator– Runs in real
environment, at speed or near
– Supports some controllability from the PC
2006.2 Engenharia de Sistemas Embarcados 43
Application-Specific Instruction-Set Processors (ASIPs)
• Processadores de Propósito Geral– Sometimes too general to be effective in
demanding application• e.g., video processing – requires huge video buffers
and operations on large arrays of data, inefficient on a GPP
– But single-purpose processor has high NRE, not programmable
• ASIPs – targeted to a particular domain– Contain architectural features specific to that
domain• e.g., embedded control, digital signal processing,
video processing, network processing, telecommunications, etc.
– Still programmable
2006.2 Engenharia de Sistemas Embarcados 44
A Common ASIP: Microcontroller
• For embedded control applications– Reading sensors, setting actuators– Mostly dealing with events (bits): data is present, but
not in huge amounts– e.g., VCR, disk drive, digital camera (assuming SPP for
image compression), washing machine, microwave oven
• Microcontroller features– On-chip peripherals
• Timers, analog-digital converters, serial communication, etc.
• Tightly integrated for programmer, typically part of register space
– On-chip program and data memory– Direct programmer access to many of the chip’s pins– Specialized instructions for bit-manipulation and other
low-level operations
2006.2 Engenharia de Sistemas Embarcados 45
Another Common ASIP: Digital Signal Processors (DSP)
• For signal processing applications– Large amounts of digitized data, often streaming– Data transformations must be applied fast– e.g., cell-phone voice filter, digital TV, music
synthesizer
• DSP features– Several instruction execution units– Multiple-accumulate single-cycle instruction, other
instrs.– Efficient vector operations – e.g., add two arrays
• Vector ALUs, loop buffers, etc.
2006.2 Engenharia de Sistemas Embarcados 46
Trend: Even More Customized ASIPs
• In the past, microprocessors were acquired as chips• Today, we increasingly acquire a processor as
Intellectual Property (IP)– e.g., synthesizable VHDL model
• Opportunity to add a custom datapath hardware and a few custom instructions, or delete a few instructions– Can have significant performance, power and size
impacts– Problem: need compiler/debugger for customized ASIP
• Remember, most development uses structured languages
• One solution: automatic compiler/debugger generation
– e.g., www.tensillica.com• Another solution: retargettable compilers
– e.g., www.improvsys.com (customized VLIW architectures)
2006.2 Engenharia de Sistemas Embarcados 47
Selecting a Microprocessor
• Issues– Technical: speed, power, size, cost– Other: development environment, prior expertise, licensing,
etc.• Speed: how evaluate a processor’s speed?
– Clock speed – but instructions per cycle may differ– Instructions per second – but work per instr. may differ– Dhrystone: Synthetic benchmark, developed in 1984.
Dhrystones/sec.• MIPS: 1 MIPS = 1757 Dhrystones per second (based on Digital’s
VAX 11/780). A.k.a. Dhrystone MIPS. Commonly used today.
– So, 750 MIPS = 750*1757 = 1,317,750 Dhrystones per second
– SPEC: set of more realistic benchmarks, but oriented to desktops
– EEMBC – EDN Embedded Benchmark Consortium, www.eembc.org
• Suites of benchmarks: automotive, consumer electronics, networking, office automation, telecommunications
2006.2 Engenharia de Sistemas Embarcados 48
General Purpose Processors
Processor Clock speed Periph. Bus Width MIPS Power Trans. PriceGeneral Purpose Processors
Intel PIII 1GHz 2x16 KL1, 256KL2, MMX
32 ~900 97W ~7M $900
IBMPowerPC750X
550 MHz 2x32 KL1, 256KL2
32/64 ~1300 5W ~7M $900
MIPSR5000
250 MHz 2x32 K2 way set assoc.
32/64 NA NA 3.6M NA
StrongARMSA-110
233 MHz None 32 268 1W 2.1M NA
MicrocontrollerIntel8051
12 MHz 4K ROM, 128 RAM,32 I/O, Timer, UART
8 ~1 ~0.2W ~10K $7
Motorola68HC811
3 MHz 4K ROM, 192 RAM,32 I/O, Timer, WDT,SPI
8 ~.5 ~0.1W ~10K $5
Digital Signal Processors
TI C5416 160 MHz 128K, SRAM, 3 T1Ports, DMA, 13ADC, 9 DAC
16/32 ~600 NA NA $34
LucentDSP32C
80 MHz 16K Inst., 2K Data,Serial Ports, DMA
32 40 NA NA $75
Sources: Intel, Motorola, MIPS, ARM, TI, and IBM Website/Datasheet; Embedded Systems Programming, Nov. 1998
2006.2 Engenharia de Sistemas Embarcados 49
Designing a General Purpose Processor
• Not something an embedded system designer normally would do– But instructive to see
how simply we can build one top down
– Remember that real processors aren’t usually built this way
• Much more optimized, much more bottom-up design
Declarations: bit PC[16], IR[16]; bit M[64k][16], RF[16][16];
Aliases: op IR[15..12] rn IR[11..8] rm IR[7..4]
dir IR[7..0] imm IR[7..0] rel IR[7..0]
Reset
Fetch
Decode
IR=M[PC];PC=PC+1
Mov1 RF[rn] = M[dir]
Mov2
Mov3
Mov4
Add
Sub
Jz01100101
01000011
00100001
op = 0000
M[dir] = RF[rn]
M[rn] = RF[rm]
RF[rn]= imm
RF[rn] =RF[rn]+RF[rm]
RF[rn] = RF[rn]-RF[rm]
PC=(RF[rn]=0) ?rel :PC
to Fetch
to Fetch
to Fetch
to Fetch
to Fetch
to Fetch
to Fetch
PC=0;
from states below
FSMD
2006.2 Engenharia de Sistemas Embarcados 50
Architecture of a Simple Microprocessor
• Storage devices for each declared variable– register file holds each
of the variables• Functional units to
carry out the FSMD operations– One ALU carries out
every required operation
• Connections added among the components’ ports corresponding to the operations required by the FSM
• Unique identifiers created for every control signal
Datapath
IRPC
Controller(Next-state and
controllogic; state register)
Memory
RF (16)
RFwa
RFwe
RFr1a
RFr1e
RFr2a
RFr2eRFr1 RFr2
RFw
ALUALUs
2x1 mux
ALUz
RFs
PCld
PCinc
PCclr
3x1 muxMsMweMre
To all input control signals
From all output control signals
Control unit
16Irld
2
1
0
A D
1
0
2006.2 Engenharia de Sistemas Embarcados 51
A Simple Microprocessor
FSM operations that replace the FSMD operations after a datapath is created
RFwa=rn; RFwe=1; RFs=01;Ms=01; Mre=1;
RFr1a=rn; RFr1e=1; Ms=01; Mwe=1;
RFr1a=rn; RFr1e=1; Ms=10; Mwe=1;
RFwa=rn; RFwe=1; RFs=10;
RFwa=rn; RFwe=1; RFs=00;RFr1a=rn; RFr1e=1;RFr2a=rm; RFr2e=1; ALUs=00RFwa=rn; RFwe=1; RFs=00;RFr1a=rn; RFr1e=1;RFr2a=rm; RFr2e=1; ALUs=01PCld= ALUz;RFrla=rn;RFrle=1;
MS=10;Irld=1;Mre=1;PCinc=1;
PCclr=1;Reset
Fetch
Decode
IR=M[PC];PC=PC+1
Mov1 RF[rn] = M[dir]
Mov2
Mov3
Mov4
Add
Sub
Jz0110
0101
0100
0011
0010
0001
op = 0000
M[dir] = RF[rn]
M[rn] = RF[rm]
RF[rn]= imm
RF[rn] =RF[rn]+RF[rm]
RF[rn] = RF[rn]-RF[rm]
PC=(RF[rn]=0) ?rel :PC
to Fetch
to Fetch
to Fetch
to Fetch
to Fetch
to Fetch
to Fetch
PC=0;
from states below
FSMD
Datapath
IRPC
Controller(Next-state and
controllogic; state
register)
Memory
RF (16)
RFwa
RFwe
RFr1a
RFr1e
RFr2a
RFr2eRFr1 RFr2
RFw
ALUALUs
2x1 mux
ALUz
RFs
PCld
PCinc
PCclr
3x1 muxMsMweMre
To all input control signals
From all output control signals
Control unit
16Irld
2
1
0
A D
1
0
You just built a simple microprocessor!
2006.2 Engenharia de Sistemas Embarcados 52
Chapter Summary
• General-purpose processors– Good performance, low NRE, flexible
• Controller, datapath, and memory• Structured languages prevail
– But some assembly level programming still necessary
• Many tools available– Including instruction-set simulators, and in-circuit
emulators• ASIPs
– Microcontrollers, DSPs, network processors, more customized ASIPs
• Choosing among processors is an important step• Designing a general-purpose processor is
conceptually the same as designing a single-purpose processor