Professional Documents
Culture Documents
5
BITS Pilani, Pilani Campus
Performance Evaluation
• Response
• Throughput/(Speed of ES can process the input)
• Reliability – MTBF,MTTR
• Maintainability
• ISP & IAP
• Testability & Debug-ability
• Evolvability
• Portability
• Time-to-prototype and Market
Specifications
System Architecture
System Integration
System Validation
• ARM Characteristics
• Register windowing
• ARM Architecture
• ARM cores
• Flynn’s taxonomy
• ARMv7 core
• Comparison
• Register window
• Delayed branches
• Single cycle instructions
BITS Pilani, Pilani Campus
ARM characteristics
• Pipelined – 3 stage
• Fetch
• Decode
• Execute
• PC – points to instructions being fetched
• Von-Neumann Architecture
• Memory Access – only load/store/swap
• Data is aligned
• Two Instruction sets
• 32-bit ARM
• 16-bit THUMB – Instruction Compression
Data Bus A
Data Bus A
A B
15
RL 3.1.1 Embedded System Design © K.R.Anupama &
Meetha.V.shenoy
MISD
• Bi-endian
• Operating states
• Operating modes
• Registers
• Register organization in different modes
• Program status register in different versions
Most application programs execute in User mode. While the processor is in User
mode, the program being executed is unable to access some protected system
resources or to change mode, other than by causing an exception to occur.
This allows a suitably written operating system to control the use of system resources
Registers
• ARM has 37 registers
• 31 – GPRS, 6 SR
• Not all registers – available to programmers
• In ARM state – 16 GPR 1/2 SR are accessible
• In each of privileged modes – separate banks of
registers are accessible
• r0 - r15
• r15 – Program Counter –valid bits [31:2] –ARM state
• r14 – Link Register
• r13 – Stack Pointer
• CPSR – CCR/Flags
• In privileged modes – SPSR
Once the exception has been handled, the user task is normally
resumed. This requires the handler code to restore the user state exactly as it was
when the exception first arose:
❏ Any modified user registers must be restored from the handler’s stack.
❏ The CPSR must be restored from the appropriate SPSR.
❏ The PC must be changed back to relevant instruction address in the user instruction
stream.
If CPSR is restored first, the banked R14 holding the return address is no longer
accessible.
❏ If the PC is restored first, the exception handler loses control of the instruction
stream and can not cause the restoration of CPSR to take place.
❏ There is a need for an instruction that can perform both of these
tasks atomically as a single instruction.
• N, Z, C, V in CPSR
• Compare instructions change condition codes
• Data processing instructions can also change
condition codes if specified
• Example: 64 bit addition
• First number is stored in r0-r1
• Second number is stored in r2-r3
• ADDS r2, r2, r0; 32 bit carry out to C
• ADC r3, r3, r1;
• Used in conditional branch instructions
When CPU is executing a program that is part of the operating system, it is said to
be in
a) Interrupt mode
b) System mode
c) Half mode
d) Simplex mode
LDR R0, [R1, #4]! =>EA:R1 + 4 ; loads R0 with the word pointed LDR R0, [R1], #4=> EA:R1 ; loads R0 with the word pointed at
at by R1+4 ; then update the pointer by adding 4 to R1 by R1; then update the pointer by adding 4 to R1
Main Osc
PLL cpu
Int RC mux mux clk div
RTC clksrcreg
3.3
2.9
2.65
Int
Reset
Enable - PCON
The purpose of the WatchDog is to reset the microcontroller within a reasonable amount
of time if it enters an erroneous state (crashed program).When enabled, the WatchDog
will generate a system reset if the user program fails to "feed" (or reload) the Watchdog
within a predetermined amount of time.The minimum watchdog period at 60MHz is us
and the maximum is just under 5 minutes.I need feeding every 5 Hours
• Watchdog features
• Block diagram
• Watchdog related registers
• Programming watchdog timer
ADC features
◮ ADC function
◮ ADC programming
◮ ADC related interrupts sources
◮ DAC features and programming
void initTimer0(void)
{
/*Assuming that PLL0 has been setup with CCLK = 50Mhz
and PCLK also = 50Mhz.*/
T0CTCR = 0x0; // Select timer
T0PR = 50000-1; //(Value in Decimal!) - Increment T0TC at
every 50000
clock cycle
//count begins from zero hence subtracting 1
//50000 clock cycles @50Mhz = 1 mS
T0TCR = 0x02; //Reset Timer
}
void initClocks(void)
{
PLL0CON = 0x01; //Enable PLL
PLL0CFG = 0x24; //Multiplier and divider setup
PLL0FEED = 0xAA; //Feed sequence
PLL0FEED = 0x55;
while(!(PLL0STAT & 0x00000400)); //is locked?
PLL0CON = 0x03; //Connect PLL after PLL is locked
PLL0FEED = 0xAA; //Feed sequence
PLL0FEED = 0x55;
VPBDIV = 0x01; // PCLK is same as CCLK i.e.60
MHz
}
#include <LPC23xx.h>
#define MR0I (1<<0) //Interrupt When TC matches MR0
#define MR0R (1<<1) //Reset TC when TC matches MR0
#define DELAY_MS 500 //0.5 Seconds Delay
#define PRESCALE 50000 //50000 PCLK clock cycles to
increment TC by 1
void delayMS(unsigned int milliseconds);
void initClocks(void); // PLL Function
void initTimer0(void);
__irq void T0ISR(void); //Interrupt function ISR
• #define CLKDIV 6
• // Dividing PCLK by CLKDIV
• AD0CR = AD0CR|(0x0000FF00&(CLKDIV<<8));
STEP-3 Enable ADC
• Related Register - ADCR 21st Bit PDN
This signal function returns the SPI byte send plus 1 on the
next SPI transfer.
SPIx_OUT VTREG
• The SPIx_OUT VTREG (where x indicates the SPI port 0, 1, 2, and so
on) contains a byte output via the MCU SPI (Serial Peripheral
Interface) port. When your simulated program sends a byte via SPI,
the SPIx_OUT VTREG is set with the value output.
signal void spi_watcher (void) {
while (1) {
wwatch (SPI1_OUT);
printf ("SPI1_OUT: %2.2X\n", (unsigned)
SPI1_OUT);
}
}
Program for SPI Master (include necessary
header files)
#include <lpc214x.h>
#include <stdint.h>
#include <string.h>
#include "LCD-16x2-8bit.h“
#include <stdio.h>
Initialization for Master
•Using pin select register (PINSEL),
void SPI_Init() configure P0.4, P0.5, P0.6 and P0.7
{ as SCK0, MISO0, MOSI0 and GPIO
respectively. SSEL (P0.7) is
PINSEL0 = PINSEL0 | 0x00001500;
/* Select P0.4, P0.5, P0.6, P0.7 as SCK0, configured as general purpose
MISO0, MOSI0 and GPIO */ output pin in order to select slave
device.
S0SPCR = 0x0020; /* SPI Master
mode, 8-bit data, SPI0 mode */ •Using S0SPCR, SPI master mode
is selected with 8-bit data and CPOL
S0SPCCR = 0x10; /* Even number,
minimum value 8, pre scalar for SPI Clock = CPHA =0. S0SPCR value will
*/ change according to configuration
required.
}
•Select clock pre-scalar using
S0SPCCR.
SPI0 Master Write Mode
void SPI_Write(char data) • Make SSEL pin low (we have configured
{ SSEL pin as GPIO to select slave) using
IOCLR to select slave.
char flush; • Load data to be written into the data
IO0CLR = (1<<7); /* SSEL = 0, register.
enable SPI communication with slave */ • Wait till transmission is completed, i.e. till
S0SPDR = data; /* Load data to be the SPIF bit becomes 1.
written into the data register */ • Make SSEL pin high using IOSET to
while ( (S0SPSR & 0x80) == 0 ); /* deselect the slave and to disable SPI
Wait till data transmission is completed */ transmission to that device.
flush = S0SPDR;
IO0SET = (1<<7); /* SSEL = 1,
disable SPI communication with slave */
}
SPI0 Master Read Mode
char SPI_Master_Read() { • Make SSEL pin low (we have
IO0CLR = (1<<7); /* SSEL = 0, enable SPI configured SSEL pin as GPIO to select
communication with slave */ slave) using IOCLR to select slave.
S0SPDR = 0xFF; /* Transmit Flush byte • Transmit Flush Byte.
*/ • Wait till data transmission is
while ( (S0SPSR & 0x80) == 0 ); /* Wait completed. When data transmission is
till data transmission is completed */ completed, data sent by slave will be
received.
IO0SET = (1<<7); /* SSEL = 1, disable SPI • Make SSEL pin high using IOSET to
communication with slave */ deselect the slave and to disable SPI
return S0SPDR; /* Return the data transmission to that device.
received */ } • Read the data in the data register. This
is the received data.
Main function
int main(void) {
int i,j;
i = 0; j = 0;
uint16_t rx1;
char receive, transmit[7];
memset(transmit,0,7);
LCD_Init();
SPI_Init();
LCD_String("Master send");
SPI_Write(0x01);
for(i=0;i<16;i++) {
sprintf(transmit,"i = %d",i);
while(transmit[j] != 0) {
SPI_Write(transmit[j]);
delay_ms(100);
j++;
}
SPI_Write('\0');
LCD_Command(0xC0);
LCD_String(transmit);
memset(transmit,0,7);
j = 0;
} //for loop end
return 0;
}//main end
Program for SPI Slave (include necessary
header files)
#define F_CPU 8000000UL #define LCD_PORT PORTD
#include <avr/io.h> #define LCD_DATA_PORT_DIRECTION
#include <util/delay.h> DDRD
#define LCD_COMMAND_PORT PORTC
#include <string.h> #define
#define MOSI PB5 LCD_COMMAND_PORT_DIRECTION
#define MISO PB6 DDRC
#define SCK PB7 #define RS PC0
#define SS PB4 #define RW PC1
#define EN PC2
void LCD_CMD(char command) {
LCD_PORT = command;
LCD_COMMAND_PORT = (0<<RS)|(0<<RW)|(1<<EN); /* EN = 1,
RS = 0, RW = 0 */
_delay_ms(2);
LCD_COMMAND_PORT = (0<<RS)|(0<<RW)|(0<<EN); /* EN = 0, RS = 0,
RW = 0 */
_delay_ms(5);
}
void LCD_INIT(void) {
LCD_DATA_PORT_DIRECTION = 0xFF; LCD_COMMAND_PORT_DIRECTION =
0xFF;
_delay_ms(20); LCD_CMD(0x38); /* Initialize lcd */
LCD_CMD(0x0C); /* Display on cursor off */
LCD_CMD(0x06); /* Auto increment cursor */
LCD_CMD(0x01); /* Display clear */
LCD_CMD(0x80); /* First line first position */
}
void LCD_STRING (char* msg) {
int i=0;
while(msg[i]!=0) {
LCD_PORT = msg[i];
LCD_COMMAND_PORT = (1<<RS)|(0<<RW)|(1<<EN); /* EN = 1, RS = 1, RW = 0 */
_delay_ms(2);
LCD_COMMAND_PORT = (1<<RS)|(0<<RW)|(0<<EN); /* EN = 0, RS = 1, RW = 0 */
_delay_ms(5);
i++;
}
}
void LCD_CHAR (char msg) {
LCD_PORT = msg;
LCD_COMMAND_PORT = (1<<RS)|(0<<RW)|(1<<EN); /* EN = 1, RS = 1,
RW = 0 */
_delay_ms(2);
LCD_COMMAND_PORT = (1<<RS)|(0<<RW)|(0<<EN); /* EN = 0, RS = 1,
RW = 0 */
_delay_ms(5);
}
Initialization for Slave
void SPI0_INIT( void ) { •PB4, PB5, PB6 and PB7 are
DDRB = DDRB | (1<<MISO); /* Make the SS, MOSI, MISO and SCK
MISO output */ pins respectively.
DDRB &= ~( (1<<MOSI) | (1<<SCK) | •Using data direction register,
(1<<SS) ); /* Make MOSI, SCK and SS configure the MISO pin as
pins as inputs. */ output. Also configure MOSI,
SPCR = (1<<SPE); /* Enable SPI */ } SS and SCK pins as input pins.
•Enable SPI using SPCR
register.
SPI Slave Write Mode
• Load data to be written into
void the data register.
SPI_SLAVE_WRITE_CHAR(char ch) • Wait till transmission is
{ completed, i.e. till the SPIF
char flush; bit becomes 1.
SPDR = ch; /* Load data to be
written into the data register */
while(!(SPSR & (1<<SPIF))); /* Wait
till data transmission is completed */
flush = SPDR; /* Return the data
received */ }
SPI Slave Read Mode
unsigned char
SPI_SLAVE_READ_CHAR() {
while(!(SPSR & (1<<SPIF))); /* Wait
till data reception is completed */
return SPDR;
}
•Wait till SPIF bit becomes 1, i.e. till
data reception is completed.
•Read the data in the data register.
This is the received data.
Main function for slave
int main(void) {
int i = 0;
int j = 0;
int k = 0;
unsigned char receive[7], rx;
SPI0_INIT();
LCD_INIT();
LCD_STRING("Slave receive");
memset(receive,0,7);
while(SPI_SLAVE_READ_CHAR() != 0x01);
do {
do {
receive[j] = SPI_SLAVE_READ_CHAR();
rx = receive[j];
j++;
}
while (rx != 0);
LCD_CMD(0xC0);
for(i=0;i<j-1;i++)
LCD_CHAR(receive[i]);
memset(receive,0,7);
j = 0;
} while (k != 16);
return 0;
}
Summary: I2C and I2S Interfaces
◮ I 2C features
◮ I 2C communication protocol
◮ Data transfer modes in I 2C
◮ Operating modes in I 2C
◮ Transmission data frames
◮ Arbitration loss
◮ Frequency of communication
◮ I 2C block diagram
◮ I 2S interface
The important difference between I2C and SPI
( I2C vs SPI ) communication protocol
I2C SPI
I2C can be multi-master and multi-slave, which means there SPI can be multi-slave but does not a multi-master serial
can be more than one master and slave attached to the I2C protocol, which means there can be only one master
bus. attached to the SPI bus.
I2C has the feature of clock stretching, which means if the Clock stretching is not the feature of SPI.
slave cannot able to send fast data as fast enough then it
suppresses the clock to stop the communication.
I2C is used only two wire for the communication, one wire is SPI needs three or four-wire for communication ((depends on
used for the data and the second wire is used for the clock. requirement), MOSI, MISO, SCL, and Chip-select pin.
I2C draws more power than SPI. Draws less power as compared to I2C.
I2C is less susceptible to noise than SPI. SPI is more susceptible to noise than I2C.
I2C work on wire and logic and it has a pull-up resistor. There is no requirement of a pull-up resistor in the
case of the SPI.
In I2C communication we get the acknowledgment bit Acknowledgment bit is not supported by the SPI
after each byte. communication protocol.
I2C ensures that the data sent is received by the slave SPI does not verify that data is received correctly or
device. not.
I2C support multi-master communication. SPI does not support multi-master communication.
I2C is a multi-master communication protocol that’s SPI is not a multi-master communication protocol, so it
why it has the feature of arbitration. does not consist of the properties of arbitration.
I2C is the address base bus protocol, you have to send In the case of the SPI, you have to select the slave using
the address of the slave for the communication. the slave select pin for the communication.
I2C has some extra overhead due to start and stop SPI does not have a start and stop bits.
bits.
I2C supports multiple devices on the same bus SPI requires additional signal (slave select lines) lines to
without any additional select lines (work on the basis manage multiple devices on the same bus.
of device address).
I2C is better for long-distance. SPI is better for a short distance.