Professional Documents
Culture Documents
ESD Full
ESD Full
ESD Full
Embedded Systems
Design Dept. of Electrical & Devesh Samaiya
BITS Pilani Electronics Engg
Pilani Campus Pilani Campus
BITS Pilani
Pilani Campus
EEE ZG512
Contact Session – I
Purpose of Contact Session
● Performance Evaluation.
A small computing system embedded inside a bigger electro-mechanical system, doing a specific
job, often with real time constraints.
16-bit Microcontrollers
MSP430 by Texas Instruments
32-bit Microcontrollers
AVR32, PIC32, ARM7, ARM Cortex M0, M4, M0+ etc.
Requirement
Analysis
Requirement Definitions
Specifications
Functional Specifications
System
Hardware Design Hardware Architecture Architecture Software Architecture
Software Design
Hardware Software
Implementation Implementation
System Integration
System Validation
WHY?
EEE ZG512
Contact Session – 2
Pre Contact Hour Content
Source - http://www.arachnidlabs.com/blog/2013/02/05/introducing-re-load/
● STM8S003F3P6
● N76E003AT20
● ATmega8A-PU
● and many more…
● Power
○ Voltage ranges in ES.
○ Power Saving Schemes. (Frequency, Idle and Sleep Modes)
● Clock Source
○ Crystal
○ Ceramic Resonators
○ External IC clock generator
● Reset
○ Power on Reset (H/W), External Reset
○ Invalid instructions
○ Clock Monitor
○ Watchdog Timer
libraries
User Level
Kernel Level
system call interface
Hardware Level
actual hardware
● Challenges in ESD
● Application Specific System on Chip
○ Network Connectivity
○ Encryption Requirements
○ Bluetooth / NFC requirements
○
EEE ZG512
Contact Session – 3
ARM Architecture
Comparisons 13%
Logical operations 5%
Other 1%
http://infocenter.arm.com/help/topic/com.arm.doc.ddi0210c/DDI0210B.pdf
BITS Pilani, Pilani Campus
Datapath Activities during Data Processing Instructions
All ARM instructions are four bytes long (one 32-bit word) and are
always aligned on a word boundary. This means that the bottom two
bits of the PC are always zero, and therefore the PC contains only
30 non-constant bits.
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
EEE ZG512
Contact Session – 4
ARM assembly Language Programming
ARM instruction types
n = i ROR ( 2* r)
AND r0, r1, r2 implies r0[i] = r1[i] AND r2[i] for i ranging from 0 to 31.
Register Movement Operations
Register Movement Operations
Comparison Operations
LSL - Logical Shift Left; fill the vacated bits with zeros
LSR - Logical Shift Right; fill the vacated bits with zeros
ASR - Arithmetic Shift Right; fill the vacated bits with 0 if operand was positive else with 1
ROR - Rotate Right by 0 to 32 places; the bit which falls off the LSB will fill the vacated bits
RRX - Rotate Right extended by 1 place; the vacated bit (bit 31) is filled with the old value of
the C flag and the operand is shifted one place to the right. With appropriate use of the
condition codes (see below) a 33-bit rotate of the operand and the C flag is performed.
Data Transfer Instructions
Restoring context
LDMFD r13!, {r0 - r2, pc}
Block Data Transfer
Rn tmp
2 3
Rm
Rd
Binary Semaphore Using SWP
spin
mov r1, =semaphore
mov r2, #1
swp r3, r2, [r1] ; hold the bus until complete
cmp r3, #1
beq spin
Exceptions
The ARM architecture supports a range of interrupts, traps and supervisor calls,
all grouped under the general heading of exceptions. They are all handled in
similar way :
1. The current state is saved by copying the PC into R14_exc and the CPSR into
SPSR_exc (where exc stands for the exception type).
2. The processor operating mode is changed to the appropriate mode. ARM
processor mode can also be changed by changing the CPSR.
3. The PC is forced to a value between 0x00 to 0x1C, the particular value
depending on the type of exception. Usually the address of an exception
handler will be located into those values.
4. It disables IRQs by setting bit 7 of the CPSR and if it’s FIQ, disables further
FIQs by setting bit 6 of CPSR.
When an exception occurs the ARM processor always switches to ARM state.
VECTOR TABLE
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:
EEE ZG512
Contact Session – 5
Keil ARM MDK Demo for ARM assembly
Language Programming
ASM Example Code
One should use 32-bit data type and avoid using char or short
wherever possible. If you requires modulo arithmetic of the form
255+1 = 0, then use the char type.
Compiler Output with ‘i’ as char
Compiler output with ‘i’ as integer
Expressions in C
EEE ZG512
Contact Session – 5
LPC2xxx
Analog to Digital Demo
ADC in LPC2xxx Series
#define CLKDIV 6
return(val>>6);
Timer Demo -1 Accurate Delay Function
◆ Toggle on match.
◆ Do nothing on match
STEP- 1 Understanding Timer Modes
EEE ZG512
Contact Session – 6
Serial Peripheral Interface
LPC2xxx SoC
Introduction
SPI is a full duplex serial interface.
It can handle multiple masters and slaves being connected to a given bus.
Only a single master and a single slave can communicate on the interface during a given
data transfer.
During a data transfer the master always sends 8 to 16 bits of data to the slave, and the
slave always sends a byte of data to the master.
Ring Buffer
SPI data to CPOL, CPHA relationship
SPI CPOL, CPHA Significance (AT93C46 EEPROM)
http://ww1.microchip.com/downloads/en/DeviceDoc/doc5140.pdf
The Read (READ) instruction contains the address code for the memory location to be read.
After the instruction and address are decoded, data from the selected memory location is
available at the serial output pin DO. Output data changes are synchronized with the rising
edges of serial clock SK.
SPI CPOL, CPHA Significance (W25Q64 FLASH)
https://www.winbond.com/resource-files/w25q64fw_revk%2007012
READ instruction (03h) is initiated by driving the CS pin low and shifting out instruction (03h)
and 24-bit address (A23-A0) on DI pin.The instruction code and address bits are latched on the
rising edge of the CLK input. Data is shifted out on DO at falling edge of the CLK pin.
016%20sfdp.pdf
SPI0 Registers in LPC2148
MASTER OPERATION
The following sequence describes how one should process a data transfer with the SPI block when it
is set up to be the master. This process assumes that any prior data transfer has already completed
1. Set the SPI clock counter register to the desired clock rate.
2. Set the SPI control register to the desired settings.
3. Write the data to transmitted to the SPI data register. This write starts the SPI data
transfer.
4. Wait for the SPIF bit in the SPI status register to be set to 1. The SPIF bit will be set
after the last cycle of the SPI data transfer.
5. Read the SPI status register.
6. Read the received data from the SPI data register (optional).
7. Go to step 3 if more data is required to transmit.
SLAVE OPERATION
The following sequence describes how one should process a data transfer with the SPI block when it
is set up to be a slave. This process assumes that any prior data transfer has already completed. It is
required that the system clock driving the SPI logic be at least 8X faster than the SPI.
Source - https://www.diodes.com/assets/Datasheets/74HC595.pdf
2
I C Protocol
devesh.samaiya@pilani.bits-pilani.ac.in
I2C
Developed by Philips Semiconductor (now NXP) as a simple bidirectional two wire bus
protocol for efficient inter-IC data communication. Originally, the I2 C bus was designed to
link a small number of devices on a single card, such as to manage the tuning of a car radio
or TV.
This bus is called the Inter IC or I2C-bus. All I2C-bus compatible devices incorporate an
on-chip interface which allows them to communicate directly with each other via the
I2C-bus.
Features
➔ Only two bus lines are required; a serial data line (SDA) and a serial clock line (SCL).
➔ Each device connected to the bus is software addressable by a unique address and
simple master/slave relationships exist at all times; masters can operate as
master-transmitters or as master-receivers.
➔ It is a true multi-master bus including collision detection and arbitration to prevent
data corruption if two or more masters simultaneously initiate data transfer.
➔ Serial, 8-bit oriented, bidirectional data transfers can be made at up to 100 kbit/s in
the Standard-mode, up to 400 kbit/s in the Fast-mode, up to 1 Mbit/s in Fast-mode
Plus, or up to 3.4 Mbit/s in the High-speed mode.
Pg. 4 https://www.nxp.com/docs/en/user-guide/UM10204.pdf
SDA & SCL Signals
Both SDA and SCL are bidirectional lines, connected to a positive supply voltage via a
current-source or pull-up resistor. When the bus is free, both lines are HIGH.
SDA & SCL Signal Levels
➔ Due to the variety of different technology devices (CMOS, NMOS, bipolar)
that can be connected to the I2C-bus, the levels of the logical ‘0’ (LOW) and
‘1’ (HIGH) are not fixed and depend on the associated level of VDD.
➔ Input reference levels are set as 30 % and 70 % of VDD; VIL is 0.3VDD and
VIH is 0.7VDD.
START & STOP conditions
➔ All transactions begin with a START (S) and are terminated by a STOP (P).
➔ A HIGH to LOW transition on the SDA line while SCL is HIGH defines a START
condition.
➔ A LOW to HIGH transition on the SDA line while SCL is HIGH defines a STOP
condition.
DATA Validity
➔ The data on the SDA line must be stable during the HIGH period of the clock.
➔ The HIGH or LOW state of the data line can only change when the clock signal on
the SCL line is LOW .
➔ One clock pulse is generated for each data bit transferred.
Byte format
➔ Every byte put on the SDA line must be eight bits long.
➔ The number of bytes that can be transmitted per transfer is unrestricted.
➔ Each byte must be followed by an Acknowledge bit.
➔ Data is transferred with the Most Significant Bit (MSB) first.
➔ If a slave cannot receive or transmit another complete byte of data until it has
performed some other function, for example servicing an internal interrupt, it can
hold the clock line SCL LOW to force the master into a wait state. Data transfer then
continues when the slave is ready for another byte of data and releases clock line
SCL.
ACK / NACK
➔ The acknowledge takes place after every byte. The acknowledge bit allows the
receiver to signal the transmitter that the byte was successfully received and another
byte may be sent. The master generates all clock pulses, including the acknowledge
ninth clock pulse.
➔ The transmitter releases the SDA line during the acknowledge clock pulse so the
receiver can pull the SDA line LOW and it remains stable LOW during the HIGH
period of this clock pulse.
➔ When SDA remains HIGH during this ninth clock pulse, this is defined as the Not
Acknowledge signal. The master can then generate either a STOP condition to abort
the transfer, or a repeated START condition to start a new transfer.
ACK / NACK
There are five conditions that lead to the generation of a NACK:
1. No receiver is present on the bus with the transmitted address so there is no device to
respond with an acknowledge.
3. During the transfer, the receiver gets data or commands that it does not understand.
4. During the transfer, the receiver cannot receive any more data bytes.
5. A master-receiver must signal the end of the transfer to the slave transmitter.
Slave address and R/W’ bit
After the START condition (S), a slave address is sent. This address is seven bits long
followed by an eighth bit which is a data direction bit (R/W) — a ‘zero’ indicates a
transmission (WRITE), a ‘one’ indicates a request for data (READ).
Master Transmitter
Master Receiver
Master Transceiver
Arbitration
Arbitration, refers to a portion of the protocol required only if more than one master is
used in the system.
A master may start a transfer only if the bus is free. Two masters may generate a START
condition on the bus at the same time. Arbitration is then required to determine which
master will complete its transmission.
Arbitration
Arbitration proceeds bit by bit. During every bit, while SCL is HIGH, each master checks
to see if the SDA level matches what it has sent.
This process may take many bits. Two masters can actually complete an entire transaction
without error, as long as the transmissions are identical.
The first time a master tries to send a HIGH, but detects that the SDA level is LOW, the
master knows that it has lost the arbitration and turns off its SDA output driver. The other
master goes on to complete its transaction.
I2C Protocol Summary
I2C in LPC2xxx
➔ Standard I2C compliant bus interfaces that may be configured as Master or Slave.
➔ Arbitration between simultaneously transmitting masters without corruption of serial
data on the bus.
➔ Programmable clock to allow adjustment of I2C transfer rates.
➔ Serial clock synchronization allows devices with different bit rates to communicate
via one serial bus.
I2C Bus configuration
I2C Operating Modes
➔ In a given application, the I2C block may operate as a master, a slave or both.
➔ If processor wishes to become the bus master, the hardware waits until the bus is free
before the master mode is entered so that a possible slave operation is not interrupted.
➔ If bus arbitration is lost in the master mode, the I2C block switches to the slave mode
immediately and can detect its own slave address or general call address in the same
serial transfer.
Master Transmitter Mode
http://www.usb.org/developers/defined_class
Master Slave
➔ USB is a master slave protocol.
➔ Host is the master and all the communication on the bus is initiated by the Host.
➔ There can be no communication directly between 2 USB devices.
➔ A device cannot initiate a transfer, but must wait to be asked to transfer data by the
host. The only exception to this is when a device has been put into 'suspend' (a low
power state) by the host then the device can signal a 'remote wakeup'.
Bus enumeration
➔ The host regularly polls hubs for their status.
➔ When a new device is plugged into a hub, the hub advises the host of its
change of state.
➔ The host controller in turn issues a command to enable and reset the port.
➔ Device responds and host collects information about the device.
➔ Based on the retrieved information, the host operating system determines the
device driver to be used for the device.
➔ The process of detection and identification of USB devices by a host is called
bus enumeration.
Transactions
REF : http://www.usbmadesimple.co.uk/ums_3.htm
Packet Formats 1/4
Packet ID (PID) : The first byte in every
packet is a Packet Identifier (PID) byte.
This byte needs to be recognised quickly
by the USB engine and so is not included
in any CRC checks. It therefore has its
own validity check. The PID itself is 4
bits long, and the 4 bits are repeated in an
complimented form.
Packet Formats 2/4
Token Packet : Used for SETUP, OUT and IN packets. They are always the first packet in
a transaction, identifying the targeted endpoint, and the purpose of the transaction
8 bits
CONTROL
INTERRUPT
BULK
ISOCHRONOUS
CONTROL ENDPOINT
➔ Control endpoints are used to allow access to different parts of the USB
device.
➔ They are commonly used for configuring the device, retrieving information
about the device, sending commands to the device, or retrieving status reports
about the device.
➔ Every USB device has a control endpoint called "endpoint 0" that is used by
the USB core to configure the device at insertion time.
➔ These transfers are guaranteed by the USB protocol to always have enough
reserved bandwidth to make it through to the device.
CONTROL TRANSFER
It is divided into three stages.
1. The SETUP stage carries 8 bytes called the Setup packet. This defines the request,
and specifies whether and how much data should be transferred in the DATA stage.
2. The DATA stage is optional. If present, it always starts with a transaction containing a
DATA1. The type of transaction then alternates between DATA0 and DATA1 until all
the required data has been transferred.
3. The STATUS stage is a transaction containing a zero-length DATA1 packet. If the
DATA stage was IN then the STATUS stage is OUT, and vice versa.
Control transfers are used for initial configuration of the device by the host, using Endpoint 0 OUT and Endpoint 0
IN, which are reserved for this purpose. They may be used (on the same endpoints) after configuration as part of the
device-specific control protocol, if required.
CONTROL TRANSFER
REF : http://www.usbmadesimple.co.uk/ums_3.htm
SETUP PACKET
Possible bRequest types in control transaction
INTERRUPT ENDPOINT
➔ They have nothing to do with interrupts.
➔ Interrupt endpoints transfer small amounts of data at a fixed rate every time the
USB host asks the device for data.
➔ These endpoints are the primary transport method for USB keyboards and
mice.
➔ They are also commonly used to send data to USB devices to control the
device, but are not generally used to transfer large amounts of data.
➔ These transfers are guaranteed by the USB protocol to always have enough
reserved bandwidth to make it through.
BULK ENDPOINTS
➔ Bulk endpoints transfer large amounts of data.
➔ These endpoints are usually much larger (they can hold more characters at
once) than interrupt endpoints.
➔ They are common for devices that need to transfer any data that must get
through with no data loss. These transfers are not guaranteed by the USB
protocol to always make it through in a specific amount of time.
➔ If there is not enough room on the bus to send the whole BULK packet, it is
split up across multiple transfers to or from the device. These endpoints are
common on printers, storage, and network devices.
ISOCHRONOUS ENDPOINT
➔ Interfaces usually have one or more settings which are specified in the
Interface descriptor.
➔ Finally Interfaces have zero or more endpoint and each endpoint is described
using Endpoint descriptor structure.
USB
DEVICE DESCRIPTOR
STRUCTURE
USB Configuration Descriptor Format
USB Interface Descriptor
USB
ENDPOINT
DESCRIPTOR
FORMAT
USB Frames and Microframes
➔ USB defines a full-speed 1 ms frame time indicated by a Start Of Frame (SOF)
packet each and every 1ms period.
➔ USB also defines a high-speed microframe with a 125 μs frame time
➔ SOF packets are generated (by the host controller) every 1ms for full-speed
links.
USB is a host controlled protocol. Irrespective of whether the data transfer is from device
to host or host to device, transfer sequence is always initiated by the host.
During data transfer from device to the host, the host sends an IN token to the device,
following which the device responds with the data.
USB device peripheral in LPC2148
• Fully compliant with USB 2.0 Full Speed specification
• Supports 32 physical (16 logical) endpoints
• Supports Control, Bulk, Interrupt and Isochronous endpoints
• Endpoint Maximum packet size selection (up to USB maximum specification) by software at run time
• RAM message buffer size based on endpoint realization and maximum packet size
• Supports Soft Connect feature and Good Link LED indicator
• Supports bus-powered capability with low suspend current
• Support DMA transfer with the DMA RAM of 8 kB on all non-control endpoints (LPC2146/8 only)
• One Duplex DMA channel serves all endpoints
• Allows dynamic switching between CPU controlled and DMA modes
• Double buffer implementation for Bulk & Isochronous endpoints
LPC2148: USB Device Controller
➔ The device controller enables 12 Mb/s data exchange with a USB host controller.
➔ It consists of register interface, serial interface engine, endpoint buffer memory and
DMA controller.
➔ The serial interface engine decodes the USB data stream and writes data to the
appropriate endpoint buffer memory.
➔ The status of a completed USB transfer or error condition is indicated via status
registers. An interrupt is also generated if enabled.
➔ The DMA controller when enabled transfers data between the endpoint buffer and the
USB RAM.
Pre-fixed Endpoint Configuration
Pre-fixed Endpoint Configuration
USB Peripheral Device Block
Data flow from Host to Device
➔ The USB device protocol engine receives the serial data from the USB analog
transceiver and converts it into a parallel data stream.
➔ The parallel data is sent to the RAM interface which in turn transfers the data to the
endpoint buffer.
➔ The endpoint buffer is implemented as an SRAM based FIFO. Each realized endpoint
will have a reserved space in the RAM.
➔ So the total RAM space required depends on the number of realized endpoints,
maximum packet size of the endpoint and whether the endpoint supports double
buffering.
Data Flow
➔ For non-isochronous endpoints, when a full data packet is received without any
errors, the endpoint generates a request for data transfer from its FIFO by generating
an interrupt to the system.
➔ Isochronous endpoint will have one packet of data to be transferred in every frame. So
the data transfer has to be synchronized to the USB frame rather than packet arrival.
So, for every 1 ms there will be an interrupt to the system.
➔ The data transfer follows the little endian format. The first byte received from the
USB bus will be available in the least significant byte of the receive data register.
Data Flow from Device to Host
➔ For data transfer from an endpoint to the host, the host will send an IN token to that
endpoint. If the FIFO corresponding to the endpoint is empty, the device will return a
NAK and will raise an interrupt to the system.
➔ On this interrupt the CPU fills a packet of data in the endpoint FIFO. The next IN
token that comes after filling this packet will transfer this packet to the host.
➔ The data transfer follows the little endian format. The first byte sent on the USB bus
will be the least significant byte of the transmit data register.
Software Interface
Software interface of the USB device block consists of a register view and the format
definitions for the endpoint descriptors.
A few important registers
USB Endpoint Interrupt Status register (USBEpIntSt - 0xE009 0030)
Each physical non-isochronous endpoint is represented by one bit in this register to
indicate that it has generated the interrupt.
USB Endpoint Interrupt Status register (USBEpIntSt - 0xE009 0030)
➔ All non-isochronous OUT endpoints give an interrupt when they receive a packet
without any error.
➔ All non-isochronous IN endpoints will give an interrupt when a packet is successfully
transmitted or a NAK handshake is sent on the bus provided that the interrupt on
NAK feature is enabled.
➔ Isochronous endpoint transfer takes place with respect to frame interrupt. The
USBEpIntSt is a read only register.
➔ All these interrupts can be enabled or disabled using USBEpIntEn and USBEpIntClr
registers respectively
USB Realize Endpoint register (USBReEp - 0xE009 0044)
➔ Though fixed-endpoint configuration implements 32 endpoints, it is not a must that all
have to be used. If the endpoint has to be used, it should have buffer space in the
EP_RAM.
➔ The EP_RAM space can be optimized by realizing a subset of endpoints.
➔ This is done through programming the Realize Endpoint register. Each physical
endpoint has one bit as shown below. The USBReEp is a read/write register
Virtual COM Port Device (Vendor Specific)
Virtual COM port driver allows your PC to recognize and communicate with the remote
target as a COM port regardless the under-layer hardware connection between the PC and
target system.
For example, if the LPC2148 is programmed as a COM port device, actual connection is
through USB but it will appear to the PC as a COM port. When the USB cable is
connected, the target looks like a real serial port communicating with the PC Hyper
Terminal Software on the Windows platform.
1. Reset,
2. Enumeration, and
3. Operation phase.
USB reset phase
➔ The USB device will be in the reset phase after power-on reset.
➔ When the USB device is attached to the PC USB host, the host will issue a reset
signal.
➔ When a USB reset signal is detected on the bus, on the device side, the DEV_STAT
bit in the Device Interrupt Register is set and a USB interrupt will be generated.
➔ The USB device will process the RESET interrupt and set itself to the default
configuration state. The initial address of the USB device is set to zero at reset phase.
➔ After the reset signal is released and RESET interrupt has been processed, the device
will enter the enumeration phase.
USB enumeration and standard requests
➔ During the enumeration phase, the host performs a bus enumeration to identify the
attached devices by sending a series of requests on the control pipe (endpoint 0 OUT)
using standard device request to get the device information and configuration, and
then, assign a unique address to it.
➔ Based on the information it gets, if necessary, send SET_FEATURE,
SET_CONFIGURATION, and/or SET_INTERFACE requests to reconfigure the
device.
➔ The device responds to the host requests on its default control pipe (endpoint 0 IN).
Endpoint configuration for virtual COM port
In the virtual COM port device driver implementation, more than one interface descriptors
can be created to accommodate multiple virtual COM ports.
Under each interface descriptor, vendor specific class code (0xFF) has been chosen.
Endpoint configuration for virtual COM port
Interface number EP Number (Physical Description
Endpoint, type)
As seen in the second column of above table, 0x41 indicates the direction of the setup
request is from host to device (bit 7 is 0), the type is “vendor” (bit 6 and 5 is 10b), and the
recipient is “interface” (bit 4 through 0 is 00001b). Finally, the SETUP request is to set the
baud rate of the COM port 0 at 9600.
The index and length fields in the vendor specific interface request table are defined but not
used. They are reserved for future expansion.
Initialization
➔ After the power up, the USB initialization should include below steps:
➔ Turn on USB PCLK
➔ Configure 48Mhz PLL1 for USB clock
➔ Setup Vectored Interrupt Controller (VIC) for USB
➔ Set up minimum numbers of USB registers including index and packet size register
for Control OUT (0) and Control IN (1) endpoints.
➔ Set USB Device Interrupt Enable register
➔ Use protocol engine commands SET_ADDRESS to reset device address to zero, and
SET_DEVICE_STATUS to make a soft connection
LPC2148 USB Command Code register (USBCmdCode - 0xE009 0010)
➔ This is a read-only register which will carry the data retrieved after executing a
command.
➔ When this register is ready, the “CD_FULL” bit of the Device Interrupt Status register
is set. The CPU can poll this bit or enable an interrupt corresponding to this to sense
the arrival of the data.The data is always one-byte wide
LPC2148 Protocol Engine Commands
➔ The protocol engine operates based on the commands issued from the CPU.
➔ These commands have to be written into the Command Code register
➔ The read data when present will be available in the Command Data register after the
successful execution of the command.
When the CPU has written data into an IN buffer, it should set the buffer full flag by
the Validate Buffer command. This indicates that the data in the buffer is valid and
can be sent to the host when the next IN token is received
Set Address (Command: 0xD0, Data: write 1 byte)
➔ The Set Address command is used to set the USB assigned address and enable the
(embedded) function.
➔ The address set in the device will take effect after the status phase of the setup token.
(Alternately, issuing the Set Address command twice will set the address in the
device).
➔ At power on reset, the DEV_EN is set to 0. After bus reset, the address is reset to
0x00. The enable bit is set to 1. The device will respond on packets for function
address 0x00, endpoint 0 (default endpoint).
Configure Device (Command: 0xD8, Data: write 1 byte)
A value of 1 written to the register indicates that the device is configured and all the
enabled non-control endpoints will respond. Control endpoints are always enabled and
respond even if the device is not configured, in the default state.
Refer to section 14.9 in UM10139 document for all the different command codes and their purposes.
LPC2148 USB LAB Demo :Class Specific Drivers
➔ To implement a CDC (Communication Device Class) with subclass 0x02
device.
➔ Windows has inbuilt USB Serial driver called USBSer.sys.
➔ USBSer.sys enumerates with the attached device as per the USB CDC
subclass 2 protocol.
➔ Our device must be programmed to respond to those requests.
So, for class specific device drivers, our device must respond to both standard requests and
class specific requests. It must provide class specific descriptors when asked to and
respond to class specific request coming via setup packet.
USB CDC Class
The Communication Device Class (CDC) supports a wide range
of devices that can perform telecommunications and networking
functions. Examples for communications equipment are:
● Telecommunications devices, such as analog phones and
modems, ISDN terminal adapters, digital phones, as well as
COM-port devices
● Networking devices, such as ADSL and cable modems, as well
as Ethernet adapters and hubs
CDC Subclasses
Class Specific Descriptors
Class-Specific Device Descriptor
This descriptor contains information applying to the entire communication device. The
Communication Device Class does not currently use any class-specific descriptor
information at the Device level.
➔ The host sends and receives data by sending and requesting reports in control or
interrupt transfers. The report format is flexible and can handle just about any type of
data.
➔ A HID must have an interrupt IN endpoint for sending Input reports.
➔ A HID can have at most one interrupt IN endpoint and one interrupt OUT endpoint. A
device that requires more interrupt endpoints can be a composite device with multiple
HID interfaces. An application obtains separate handles for each HID in the device
➔ The interrupt IN endpoint enables the HID to send information to the host at
unpredictable times. For example, there’s no way for the host computer to
know when a user will press a key on the keyboard, so the host’s driver uses
interrupt transactions to poll the device periodically to obtain new data.
HID Class Descriptor
HID Report Descriptor 1/3
A report descriptor is a class-specific descriptor. The host
retrieves the descriptor by sending a Get Descriptor request
to the interface with the wValue field containing 22h in the
high byte.
● The Report Size item indicates how many bits are in each
reported data item. In the example, each data item is eight
bits. The Report Count item indicates how many data
items the report contains. In the example, each report
contains two data items
HID Report Descriptor 3/3
● In the final item, the first byte specifies whether the report
is an Input report (81h), Output report (91h), or Feature
report (B1h). The second byte contains additional
information about the report data, such as whether the
values are relative or absolute.
Table below shows supported values for Input, Output, and Feature items. Each
item has a 1-byte prefix followed by 1 or 2 bytes that describe the report data.
Similar tables
are there for
output and
feature report
data.
Data | Constant. Data means that the contents of the item are modifiable (read/write).
Constant means the contents are not modifiable (read-only).
Array | Variable. This bit specifies whether the data reports the state of every control
(Variable) or just reports the states of controls that are asserted, or active (Array).
Reporting only the asserted controls results in a more compact report for devices such as
keyboards that have many controls (keys) but where only one or a few controls are
asserted at the same time.
Absolute | Relative. Absolute means that the value is based on a fixed origin. Relative
means that the data indicates the change from the last reading. A joystick normally reports
absolute data (the joystick’s current position), while a mouse reports relative data (how far
the mouse has moved since the last report).
Example from USB Lab
HID Specific Requests
That’s all !
Motion, Mechanisms &
Human Interface Devices
Interfacing Motion Related Devices
➔ Linear
➔ Rotational
Linear motion can be generated using rotational motion using arrangement of gears.
Solenoid based magnetic devices can also be used to generate short range linear motion.
Linear Motor
Kind of Motors usually found in electronic systems
DC Motors
Useful when continuous rotation at high torque, high RPM is required.
Stepper Motors
Useful for applications where precise angular motion is required in equal size steps.
Comes in variety of torque and step angles.
Servo Motors
Feedback based motor control, used to design highly accurate movements.
DC Motor Interfacing
➔ Works on DC voltages with RPM proportional to applied voltage.
➔ Direction can be controlled by changing the polarity of applied voltage.
➔ Require high current to drive and act as inductive load.
DC Motor Interfacing
➔ Microcontroller pins can not supply current required to drive different variety of DC
motors. Depending on the RPM and torque of the motor it may require current of up
to 10s of Amps to drive.
➔ Special motor driver circuits are required to drive these motors.
➔ Driver can control direction and speed of the motor.
➔ How to design motor drivers?
Direction Control
Speed control using PWM
Stepper Motor
Translates electrical pulses into mechanical movement. Provides precise motion control
but no awareness of shaft position. Open loop control. You can control how many step you
want to rotate but you can not control the absolute angle of the shaft from where the
rotation will begin.
Servo Motor
➔ DC motor with shaft position feedback.
➔ Closed loop control.
Typical Servo control PWM pulse
Human Interface Devices
Touch Panels
● Single touch (resistive) or multitouch (capacitive)
● Resistive touch screen are easy to interface. Can be driven using 2 or more
ADC channels.
● Capacitive touch panels are more complex to interface and often required
specialized driver ICs for integration into the system.
● Validation Algorithm
● Validation Algorithm
● Validation Algorithm
● Communication
● LCD display
● User Buttons
● Dial Wheel
● Remote Control IR
● Bluetooth App control
Design Example - 2 Customized MP3 players
● Music Selection
● Music Selection
Example - JQ6500
WTV020-SD etc.
Example - JQ6500
Specifications
System Architecture
System Integration
System Validation
Software
Embedded System Design - RL1.1.2 © K.R.Anupama & Meetha.V.Shenoy 8
M1: Introduction to Embedded Systems
FPGA/ASIC Memory
Software
Embedded System Design - RL1.2.1 © K.R.Anupama & Meetha.V.Shenoy 2
Processors
Timers
SCI
Interrupt Controller
Parallel Ports
Memory
Data
Program
Power supply
Reset- Oscillator circuits
Application Specific Circuits
Performance
/ Power DSP, ASIPs Flexibility
Efficiency
FPGA
ASIC
x,,+,-
RISC CISC
Decode
Execute
1. ADD R2,R1,R3
2. SBR R2,R3,R2
3. STR R2,b
9 cycles
5 cycles
Pipeline Hazards
Embedded System Design - RL1.2.1 © K.R.Anupama & Meetha.V.Shenoy 11
c
Processor has limited capability
Enhanced i/o Functions
Appln Specific units [DTMF/MODEM]
Stream 1 – 68HC11xx, HC12xx, HC16xx
Stream 2 - 8051
Stream 3 – PIC16F84 – Microchip
Stream 4 – ARM based Microcontrollers
µp
used when program is large/ large no. of computations have to be
carried out
RISC – used when intensive computations have to be done
Inc value
Write value
Read value
Inc value
Restore
Task1
Write value
Write value
Software
Embedded System Design - RL1.2.3 © K.R.Anupama & Meetha.V.Shenoy 2
RAM
Internal/External
Flash Memory/EEPROM
External/Internal
System Ports
ROM/PROM
Cache
Data Memory
CPU
Inst/Data
Control
IDATA Inst
Memory
ICONTROL
CPU
DADDR
DDATA Data
Memory
DCONTROL
SODIMMs
PCMIA
Instructions
RAM
NVRAM
Stack
System
Cache
Cntlr
Cache hit/miss
L2 Cache
L1 Cache
CPU
Cache
Cntlr
Cache hit/miss
L2 Cache
L1 Cache
CPU
Cache
MAR
Block N
cache block 1
cache block 2
cache block 3
cache block 4
cache block 5
Address
00 -1 1000
-
01 0
-1 0001
1111
-
10 -0 0110
-
11 - -
0 10
- 1000
- -01 -0000
1 -00 0101
- -10 -0001
Main Memory
256 K x 32
512 Blocks - m
64 Groups –n
Group No m mod n
0 1 2 3 4 5 6 7
Tag
bank select
data
ADC
VDD VSS AGnd, AREF, AIP
Run
10 µs 90 µs
10 µs
160ms
Idle Sleep
90 µs
50 mW 0.16 mW
Sources of reset
Power on reset
Reset
RC
IC
10ms
t
Control
Priority
Latency
Default Priorities
COP Watchdog
External Interrupts
Timer
Serial I/f
ADC
DAC- PWM
Asynchronous
Peer- to- Peer
Clock Implicit
Software
Embedded System Design - RL1.2.6 © K.R.Anupama & Meetha.V.Shenoy 8
M1: Introduction to Embedded Systems
FPGA/ASIC Memory
Software
Embedded System Design - RL1.3.1 © K.R.Anupama & Meetha.V.Shenoy 2
Appln Layer
RTOS
Hardware
c
.s19/hex
Architecture
Components
Sys Integration
ASIP
FSK Mod
DESIGN PROCESS
Requirements Every step
Analyze
Architecture
Components
Sys Integration
Rotating Plate
Microwave Vents
Weight Sensor
DESIGN PROCESS
Requirements Every step
Analyze
Architecture
Components
Sys Integration
Turn Table
Open/Close
Door
Magnetron Control
Memory
Door Control
Hardware Architecture
DESIGN PROCESS
Requirements
Architecture
Components
Sys Integration
Keys Ports
Start/Stop INT0/INT1
Auto cook -3 keys P1.0- P1.2
Weight -2 P1.3 – P1.4
Power Level P1.5
Timer P1.6
10 Min
P2.0- 2.2
1 Min
10 sec
P1.2
P1.3
P1.4
KBD
P1.5
IE1
P1.6
P1.7
R
10
S1 A
EMBEDDED SYSTEM DESIGN – RL2.3.1 © K.R.ANUPAMA & MEETHA.V.SHENOY 8
MODULE 1 - DISPLAY
LT a
RBO
RBI
5V h
A
B
C Vcc Port4, Port 5, Port 2.4-2.7, Port 3.4,3.5
D
GND
7447
P3.6
DESIGN PROCESS
Requirements
Architecture
Components
Sys Integration
Rotating Plate
Microwave Vents
Weight Sensor
TRx (TCON)
EMBEDDED SYSTEM DESIGN – RL2.3.2 © K.R.ANUPAMA & MEETHA.V.SHENOY 6
TIMER0
TMOD
TCON
P2.4
DESIGN PROCESS
Requirements
Architecture
Components
Sys Integration
TX
Enable
T2CON
T2CON
T2CON
T2MOD
T2OE DCEN
DESIGN PROCESS
Requirements
Architecture
Components
Sys Integration
supply 8051RE2
EMBEDDED SYSTEM DESIGN – RL2.3.4 © K.R.ANUPAMA & MEETHA.V.SHENOY 4
INTERRUPTS
INT0,INT1 INT0, INT1
KBE Timer2
TIMER0 Timer0
TIMER2 KBE
SCI SCI
IE1
IPH0
IPL2
DESIGN PROCESS
MICROWAVE OVEN
8051RE2 – Software
supply 8051RE2
EMBEDDED SYSTEM DESIGN – RL2.3.45 © K.R.ANUPAMA & MEETHA.V.SHENOY 3
MAIN ROUTINE
Initialise the following data parameters to the default value
Power Level 10
Weight 0
Auto Weight 1
Timer 0
10 MIN 0
1 MIN 0
10 SEC 0
Start 0
Stop 0
Cook Time 0
Count 100
Magnetron 0
EMBEDDED SYSTEM DESIGN – RL2.3.45 © K.R.ANUPAMA & MEETHA.V.SHENOY 4
PowerLevel’ 0
MAIN ROUTINE
Enable Port 1 for Input with Interrupt with Low Select
Enable INT0 and INT1
Initialise Timer 2 for Auto Reload and enable interrupt but do not
start the timer
WAI
Meetha.V.shenoy
• Register window
• Delayed branches
• Single cycle instructions
2
Register Windowing
Input
Registers
Meetha.V.shenoy
Registers Registers
Sub1 Local
Registers
Output
Registers
3
ARM- Characteristics
• 32- bit RISC
• Pipelined – 3 stage
Meetha.V.shenoy
• Two Instruction sets
32-bit ARM
16-bit THUMB – Instruction Compression
4
ARM Cores
Meetha.V.shenoy
next 5
•
•
•
•
SISD
MISD
SIMD
MIMD
Flynn’s Taxonomy
Meetha.V.shenoy
SISD
Meetha.V.shenoy
SIMD
Meetha.V.shenoy
A: I1 A,B
SIMD B: I1 C,D
Data Bus A
Meetha.V.shenoy
A B
9
MISD
back
Int-Latency 24-42 24
Memory No Yes
Protection
Speed 0.95 DMIPS/MHz (A) 1.25 DMIPS/MHz
0.74 DMIPS/MHz (T)
Power 0.28mW/MHz 0.19mW/MHz
Meetha.V.shenoy
12
ARM- Programmer’s
Model & Operating
Modes
M3: Embedded Architectures- 1: RISC Architecture -
ARM
ARM- Characteristics
• 32- bit RISC
• Pipelined – 3 stage
Fetch
Meetha.V.shenoy
• Two Instruction sets
32-bit ARM
16-bit THUMB – Instruction Compression
• Bi-Endian
2
•
•
•
ARM
Thumb
Switching - BX
Operating States
Meetha.V.shenoy
Operating Modes
• 7 modes of operation
Privileged
• User Mode – default – executes applns
modes
Meetha.V.shenoy
• Undefined Mode
4
Registers
• ARM has 37 registers
31 – GPRS, 6 SR
Meetha.V.shenoy
• r13 – Stack Pointer
• CPSR – CCR/Flags
• In privileged modes – SPSR
5
r0 r0 r0 r0 r0 r0
r1 r1 r1 r1 r1 r1
r2 r2 r2 r2 r2 r2
r3 r3 r3 r3 r3 r3
r4 r4 r4 r4 r4 r4
r5 r5 r5 r5 r5 r5
r6 r6 r6 r6 r6 r6
Meetha.V.shenoy
r14 r14_fiq r14_svc r14_abt r14_irq r14_und
r15(PC) r15(PC) r15(PC) r15(PC) r15(PC) r15(PC)
Meetha.V.shenoy
Thumb State Registers
7
r0 r0
r1 r1
r2 r2
r3 r3
r4 r4
r5 r5
r6 r6
Meetha.V.shenoy
r14 r14
r15(PC) r15(PC)
CPSR CPSR
SPSR SPSR
8
Program Status Registers
7 0
I F T M4 M3 M2 M1 M0
A3 A2
- A1- A0 - - - - E A
B3 B2 B1 B0
- GE1- GE0
GE3 GE2 - - GE3 GE2 GE1 GE0
Meetha.V.shenoy
10011 Supervisor
10111 Abort
11011 Undefined
11111 System 9
ARM- Instruction Set
-1
M3: Embedded Architectures- 1: RISC Architecture -
ARM
Addressing Modes
• Mode 1: Shifter operands for data processing inst
• Mode 2: Load/Store word/unsigned byte
Meetha.V.shenoy
2
31-28 27 26 25 24-21 20 19-16 15-12 11-0
Meetha.V.shenoy
LS Rm ASR Rs
GE Rm ROR Rs
LT
LE No Condition Taken as AL
AL 3
ADD R2, R2,#1
ADD R4,R5, R5, LSL #2
ADD R10,R15,#8
ADDS R4,R5,R6, LSR R7
R6 = 00 00 00 02
Meetha.V.shenoy
R7 = 00 00 00 03
4
Arithmetic & Logical
Instructions
Arithmetic Logical
• ADC • ORR
• SUB • EOR
• SBC • BIC
• RSB
Meetha.V.shenoy
• RSC
5
31-28 27 26 25 24 23 22 21 20 19- 15- 11-0
16 12
Cond 0 1 1 P U B W L Rn Rd Addr mode
PL
0 x post
VS
1 0 pre
VC
1 1 Pre+W
HI
Meetha.V.shenoy
LS
GE
LT
LE
AL 6
LDR R1, [R0]
Address in R0
LDR R8, [R3, #4]
Address = [R3]
LDR R12, [R13, #-4] R3 = R3 +4
STR R2, [R1, #0x100] Address = [R13]
R13 = R13 -4
LDRB R5, [R9]
Address = [R1]
STRB R4, [R10, #0x200] R1 = R1 +0100H
Meetha.V.shenoy
7
Address = [R1]
LDR R11, [R1, R2] R1 = R1 + R2
STRB R10, [R7, -R4] Address = [R7]
R7 = R7 + R4
LDR R11, [R3, R5, LSL #2]
Address = [R13]
LDR R1, [R0, #4]! R13 = R13 + R5 * 4
LDR R3, [R9], #4 R0 = R0 +4
Address = [R0]+4
STR R2, [R5], #8
Meetha.V.shenoy
8
Transfer btwn memory & reg
LDR/LDRB/LDRH/LDRSH
STR/STRB/STRH/STRSH
ADR
Meetha.V.shenoy
2
x = (a+b)-c;
ADR r4,a
LDR r0,[r4]
Meetha.V.shenoy
ADR r4,x
STR r3,[r4]
3
31-28 27 26 25 24 23 22 21 20 19-16 15-0
Examples
Meetha.V.shenoy
Addressing Mode – IA, IB, DA, DB, FD, FA, EA,ED
4
0x204 20304050
0x200 21314151
0x1fc 22324252
0x1f8 23334353
0x1f4 24344454
Meetha.V.shenoy
Stack Empty
Fully Descending
Descending
5
0x204
0x200
0x1fc
0x1f8
0x1f4
0x1f0 24344454
Meetha.V.shenoy
Stack Empty
Fully Ascending
Ascending
6
Branch instructions
conditional branch forwards /backwards up to 32MB
branch /jump can also be generated by writing a value to R15
31-28 27 26 25 24 23-0
Meetha.V.shenoy
BL func
MOV PC, LR
LDR PC, #func
7
Pipeline in ARM
• 3 stages of pipeline
• Fetch-Decode-Execute
Meetha.V.shenoy
8
add r0,r1,r2 fetch decode execute
sub r2,r3,r6 fetch decode execute
cmp r2,r4 fetch decode execute
Meetha.V.shenoy
10
stall
2 holes
Meetha.V.shenoy
11
bne nxt fetch decode execute
nop fetch decode execute
nop fetch decode execute
sub r2,r3,r6
Delayed Branching
Meetha.V.shenoy
12
ARM- Exceptions
M3: Embedded Architectures- 1: RISC Architecture -
ARM
ARM-Exceptions
• Handled by entering into different operating modes
• Exception Entry
Meetha.V.shenoy
2
Interrupts/ Address Entry F I
Exceptions Mode
Reset 0x 0000 0000 Supervisor 1 1
Undefined 0x 0000 0004 Undefined U 1
SWI 0x 0000 0008 Supervisor U 1
Meetha.V.shenoy
3
Main Program
ADR r4,a
LDR r0,[r4]
LDR r4,[r2] FIQ
LDR r1,[r4]
ADD r3,r0,r1
r15 r14_fiq
CPSR SPSR_fiq
r14_fiq - 4 r15
SPSR_fiq CPSR
Meetha.V.shenoy
4
r0
r1
r2
r3
r4
r5
r6
Meetha.V.shenoy
r14 back-up
r14_fiq
r15(PC)
CPSR
back-up
SPSR_FIQ SPSR_fiq
User FIQ 5
FIQ
• nFIQ pin –low
Meetha.V.shenoy
6
FIQ - actions
• Actions Taken on FIQ
Meetha.V.shenoy
• Exit From FIQ
7
IRQ
• nIRQ pin –low
Meetha.V.shenoy
• Exit From IRQ
• SUBS PC, R14,#4
8
Supervisor Mode
• Entry-SWI
• Actions Taken on SWI
Meetha.V.shenoy
• Exit From Supervisor
• MOVS PC, R14
9
Undefined
• Inst than cannot be handled by ARM/co-processor
• Actions Taken on Undefined
Meetha.V.shenoy
• Exit From Undefined
• MOVS PC, R14
10
ARM- Exceptions -
Abort
M3: Embedded Architectures- 1: RISC Architecture -
ARM
ARM-Exceptions
• handled by entering into different operating modes
• Exception Entry
Meetha.V.shenoy
2
Abort- Prefetch
• Current inst cannot be completed
Meetha.V.shenoy
3
1
5
4
3
2
0
7
4
2
i
i
i
v
v
v
Page Table
7
2
0
F
A
Physical Memory
A
D
E
B
Disk
F
C
Meetha.V.shenoy
40 ADR R1,A A: ADR R1,A
ADR R2,B
44 ADR R2,B
LDR R0,[R1]
48 LDR R0,[R1]
LDR R1,[R2]
4C LDR R1,[R2]
B: ADD R2,R1,R0
50 ADR R7,D
ADD R2,R1,R0
ADR R1,C
Meetha.V.shenoy
Physical Memory
5
Abort handler
• Works out the causes of abort
Meetha.V.shenoy
Data
6
Pre-fetch Abort
• ARM marks it
Meetha.V.shenoy
7
Prefetch Abort
• Actions Taken on Pre-fetch Abort
• T bit = 0 I=1
Meetha.V.shenoy
• Exit From Pre-fetch Abort
8
Data Abort
• Action depends on inst type
• LDM/STM
Meetha.V.shenoy
original state
9
00 FE
00 ADR R0,0
CA
04 ADR R1,B DE
08 LDMIA R0!, {R1,R2,R3} 45
0C ADD R1,R1,R2 04 11
78
0F ADD R3,R1,R3 12
Meetha.V.shenoy
MMU
Abort
10
How does it distinguish between
Pre-fetch & Data Abort?
• Pre-fetch abort occurs in fetch stage
• Data abort occurs in execute state
• T bit = 0 I=1
Meetha.V.shenoy
• Exit From Data Abort
12
AMBA
M4: Embedded Architectures- 2: ARM based LPC23xx
Some Common Bus Terminologies
• Bundle
• Handshake
• Timing Diagram
• Changing States
• Stable States
• Timing Constraints
• Wait states
• Burst transfer
• Disconnected/Split Transfers
Split Yes No
Transaction
Clocking Synch Asynch
Bridge
High Speed Bus
Low-Speed
Device
High-Speed
Memory
Device
10
DRAM Speed
Bridge
AHB/ASB APB
Timer
Memory DMAC
• 2 CAN channels
• 1 SPI interface
• 3 I2C interfaces
• 1 I2S interface,
• 1 MiniBus
• LPC2388
Main Osc
PLL cpu
Int RC mux mux clk div
RTC clksrcreg
• 4 external
interrupt inputs- In addition every PORT0/2 pin can be
configured as an edge sensing interrupt
• Any of the ext ints along with USB,CAN or Ethernet BOD, RTC can
wake up the processor from power down
3.3
2.9
2.65
Int
Reset
Enable - PCON
16 KB Ethern 8 KB USB+4k
SRAM et AHB-AHB Bridge SRAM SRAM+DMA
MAC+
DMA GP DMAC
AHB-APB Bridge
Reserved(512M)
Reserved
Bank(1) 64kb
Bank(0) 64kb
8K Boot Block
Reserved
Memory Map
16kb Ethernet RAM
8kb USB RAM
Reserved
32K SRAM
Reserved Memory
Space
512RL4.1.2
KBEmbedded
NV Memory
System Design © K.R.Anupama &
Meetha.V.shenoy
9
LPC 23XX- GPIO
M3: Embedded Architectures- 2: ARM based LPC23xx
Features
• GPIO PORT0 & PORT1
• accessible
• group of reg providing enhanced features accelerated port access
• legacy group of reg
• PORT2/3/4 are accessed as fast ports only.
• Accelerated GPIO functions
• GPIO regs are relocated to the ARM local bus so that the fastest possible
I/O timing can be achieved
• Pin 8-22 NA
• Pin 27-31 NA
• Port 4
• Pin 16-23 NA
• Pin 26-27 NA
• IOxPIN
• IOxSET
• IOxCLR
• IOxDIR
• IntEnF
• IntStatR
• IntStatF
• IntClr
• IntStatus
Int2S Int0S
Channel 1 CAP0.1
Channel 2
Channel 3
Timer 0
CF
CI Interrupt Logic
Interrupt Request
PINSEL Registers
Bit12-13 :PCLK_TIMER2
1 1 CCLK/8
Bit14-15 :PCLK_TIMER3
1/2/4/8 Pre-Scale+1
CCLK
Counter
CAP
CCR
TR TE
Ack Interrupt
Match
0005Reg
CI INT
Logic
EMC3 EMC2
Feed Ok
WDFEED
Feed Error
RTC Osc 32-bit down cntr
PCLK 4
Internal
RC OSC
Feed Ok
AA
55HH
Feed Error
RTC Osc 00
FFH
PCLK 4
Internal
RC OSC
WDINT
1 WDTOF
1 WDRESET WDEN
Int
Reset
CLK Select
PCLKSELREG0 0:1
WDCLKSELECT Reg WDSEL
WDTCReg
Minimum value = 256
32 Int . Vectored
sources Int Controller
.
.
IRQ
Bit 23 22 21 20 19 18 17 16
Bit 15 14 13 12 11 10 9 8
FIQ
Soft Int Int Enable FIQ Status
Int 0-31
IRQ Status
Raw Int
Int Select
Vector Address 0
Vector
Select
IRQ
Status 1
Vect Addr
or
Addr
IRQ ess
Status 31
RL4.2.1 Embedded System Design © K.R.Anupama &
6
Meetha.V.shenoy
VIC Interrupt Selection Registers
(32-bit Reg)
Classifies each Interrupt as IRQ/FIQ
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 9 8 7 6 5 4 3 2 1 0
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
ORED
Peripheral interrupts
VICSoftIntClr
Clearing S/w Interrupt bits
VICIntEnClr
RL4.2.1 Embedded System Design © K.R.Anupama &
8
Meetha.V.shenoy
Vector Address Registers
VICVR0 – VICVR31
P3 P2 P1 P0
ADC clock
10-bit data
PCLKSEL0: 25-24
PINSEL
CLKDIV
EDGE START
000 No Start ADC clock < 4.5 MHz
001 SOC
010 SOC – EINT0
011 SOC-CAP0.1
100 SOC-MAT0.1
101 SOC-MAT0.3
110 SOC-MAT1.0
111 SOC-MAT1.1
RL4.2.2 Embedded System Design © K.R.Anupama &
7
Meetha.V.shenoy
AD0STAT
ADINT
Ack Interrupt
VDDA
VSSA
10-bit data
RL4.2.2 Embedded System Design © K.R.Anupama &
11
Meetha.V.shenoy
DAC always on
PCLKSEL0 23:22
PINSEL1, PINMODE1
DATA
BIAS
0 - 1s
1 - 2.5s
MISO
Master
Slave SPI
SPI
SCLK
SS
SCLK
CPOL =1
SS
CPHA =0
MOSI
Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7
CPHA =1
MOSI
Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7
1 0 1 0 0 0 1 0 0 0 0 0
BITS BITS
X X X X X X X X
2 1
3
SPDR
MOSI
Shift Reg Shift Reg
SPICLK(0:7) 1 SPDR 3
SPSR
SPF WCOL ROVR MODF ABRT
SPSR
SPICLK(0:7)
SPIR
SPIF SPF WCOL ROVR MODF ABRT
4 SPIR
RL4.2.3 Embedded System Design © K.R.Anupama &
6
2
Meetha.V.shenoy
SPIF
PCONP: 12 – Default on
PCLKSEL0: 16-17
PINSEL
SPCR
SPDR
SPSR
MISO/DR/SI
Master
Slave SPI
SPI
SCLK/CLK/SK
CS/FS/SS
FS
DX/DR
Bit4 Bit3 Bit2 Bit1
FS
TI Format
SS
SO
Microwire Format
SSPxCR1
SOD MS SSPE LBM
SSPxMISR INT
TXMIS RXMIS RTMIS RORMIS
SSPxICR
RTIC RORIC
TDMAE RDMAE
PE 1 Data
(Master)
Clock
PE 3
(Slave)
Master Mode
Slave
Bus No
free?
Yes
Master
Yes Arbit
lost?
No
RL4.2.4 Embedded System Design © K.R.Anupama &
8
Meetha.V.shenoy
I2C Operating Modes
Appln – I2C may operate - master/ slave/ both
Slave Mode
Addr
=mine
Yes
?
No
No Addr
=bcas
t?
Yes
Int
RL4.2.4 Embedded System Design © K.R.Anupama &
9
Meetha.V.shenoy
Master Transmission
Master Receive
M2
Bus
Arbitration Loss
Arbitration
RL4.2.4 Embedded System Design © K.R.Anupama &
12
Meetha.V.shenoy
CL1
CL2
SCL
Synchronization Process
APB Bus
Bit cntr/ PCLK
I/p Timing
SCL Filter Arbt/
Sync &
O/p
Stage
Control INTR
Serial
Clock
Generato
I2CONSET
r
I2CONCLR Control/CLK Reg 16
I2SCH:I2SCL
Status Status Decoder 8
Reg RL4.2.4 Embedded System Design © K.R.Anupama &
Meetha.V.shenoy I2STAT 14
2
IS
WS
SD
SD
SCK Audio i/p
WS
Rx Unit
Mono-16bit
data2 data2 data1 data1
Stereo-16bit
data2r data2l data1l data1r
Mono-32bit
data1 data1 data1 data1
RL4.2.4 Embedded System Design © K.R.Anupama &
20
Meetha.V.shenoy
Digital Audio Output/Input Register
Mute WS_Size
TxFIFO Reg
RxFIFO Reg
TxCLK Reg/ RxCLK Reg – 0:9
Sample Rate – 48 KHz
Then value of clock - 48KHz x 2x16
Object Layer
•Message Filtering
•Message & Status Handling
Transport Layer
•Fault Confinement
•Error Detection & Signaling
•Message Validation
•Ack
•Arbitration
•Message Framing
•T/f rate & Timing
Physical Layer
•Signal level & Bit Repsn
•Tx medium
RL4.3.1 Embedded System Design © K.R.Anupama &
3
Meetha.V.shenoy
Message Transfer is done in frames
Frame Types
Data Frame
Remote Frame
Error Frame
Overload Frame
Frames are separated by IFS
Bit – Dominant/Recessive
CRC
SOF de-limiter
I10 I9 I8 I7 I6 I5 I4 I3 I2 I1 I0 RTR
Control Field
R R DL3 DL2 DL1 DL0
Bit
Acceptan Rx Buffers stream
ce Filter 1,2 processor
Device Device
Host/ D+ D+
Device
Hub D- D-
Full Speed
Host/ D+ D+
Device
Hub D- D-
Low Speed
Host Controller
Logic Pipes
End Points
Devices
RL4.3.2 Embedded System Design © K.R.Anupama &
13
Meetha.V.shenoy
Pipes & Endpoints
• A USB device can have - 32 active pipes- 16 into/ 16 out of host
cntlr
• Endpoint can t/f data in one direction only- each pipe is uni-
directional
• Endpoints grouped into i/fs - each i/f is associated with a single
device func
• Exception - endpoint zero- used for device config - not associated
with any i/f
USB ATX
EP_RAM D+
AHB Bus
Serial I/f
Reg I/f Access
Engine D-
Control
USB Up
LED
EP_RAM
(4k)
AHB Control
AHB Bus Slave Reg &
I/f Logic
16 KB Ethern 8 KB USB+4k
SRAM et AHB-AHB Bridge SRAM SRAM+DMA
MAC+
DMA GP DMAC
AHB-APB Bridge
Create
Course Info Course
Catalog
Use Case - Relationships
General Browse
<<extends>> <<extends>>
Specialized Search
Use Case - Relationships
case2 Give Price
<<uses> <<uses>
Locate
case1
Book
Actors & Use Cases
Gives
money
ATM Customer
Data Acquisition System
Measures Voltage
Measure Temp
Data – Initial Analysis done and sent for further processing
Analysis result sent back
UML
Measure
Volts
Data
Analysis
Measure Data
Actor0 Temp Processing
Textual Description – Measure Volts
User
Select measure volts mode
Select measurement range
System
If range specified
Configure to specified gain
Make Measurement
If in range – display results
If exceed range – display largest value & flash display
If auto range
Configure to midrange gain
Make Measurements
If In range- display result
If above/below range – adjust gain repeat measurement
If exceed range – display largest value & flash display
Textual Description
Normal Activity
Exceptional Conditions
Class Diagram
Help Indentify/Formulate – Modules
Describe object/modules
Relationship between objects
Public i/f to object
Properties – op that instances of the object can perform
Indentifies any constraints the appln imposes on these op
Class Diagram
Object Name
- Properties
+ Operations()
Class Relationships
Parent – Child/ Inheritance/Generalization
Interface
Wrapper around one piece of functionality
Allows to present diff set of capabilities to public view
Containment
One object made up of several others
Whole part relationship
Aggregation
Owned module may be used out of aggregation
Composition
Ownership is very strong
Inheritance/Generalization
Driver
+port number: unsigned char
+buffer address: int
+status: unsigned char
+ Read(): Boolean
+Write(): Boolean
Serial Parallel
action()
return()
Create & Destroy
:Task i :Task j
<<create>>
<<destroy>>
Send
:Task i :Task j
action()
Sequence Diagrams
Objects
Lifeline
Focus of Control
Messages
Sequence Diagram – Time Interval
Measurement
Measur Get Exec
Convert Display
e Task Attrib Meas
measure ()
get range ()
range()
get edge ()
edge()
send data ()
result()
send data ()
formatted data()
Display data ()
ok()
done()
Fork& Join
Parent
Child 0
Child 2
Child 1
Parent
Branch & Merge
Activity 0
When:[guard codn]
Activity 1
Activity 2
Activity 3
Activity 4
Activity Diagram
Activity 0
Activity 1
When:[guard codn]
Activity 5 Activity 3
Activity 2
Activity 4
Activity 6
Activity 7
Activity 8
Measure
Time
Get range
Get edge
Open meas
window
Close meas Update
window Display
Read count
Flash Flash
State Chart Diagrams
Same as state diagrams with some extensions
Transitions
event
State2 State7
State2
State2 State7
Guard Condition
State2 State9
Event [guard]
State10
Composite States
Substate0 Substate1
Event [guard]
Substate 3 Substate 2
astate
Concurrent States
astate
State8 State9
State10 State11
Control & Data Graphs
Program Model - CDFG
Data Operations
Control Operations
a b c d e
w=a+b
x= a–c
+ + -
y= x+d x1
x= a+c +
z= y+e x2 w y
Single assignment form
w = a+b
x1 = a – c +
y = x1 + d
x2 = a + c z
z = y+e
if (codn1)
basic_block1();
else
basic_block2(); T basic_block1()
cond1
basic_block3();
switch(test1){
case c1:basic_block4();break; F
case c2:basic_block5();break; basic_block2()
case c3:basic_block6();break;
}
basic_block3()
test1
Measurement Range
3 for signals
2 for events
Pwr Reset
Use Case – Local Mode
Measure
Freq
Measure
Period
Measure
Interval
Count
User Events
Reset
Use Case – Remote Mode
Measure
Freq
Measure
Period
Measure
Interval
Count
User Events
Reset
Measure Frequency
Frequency measured continuously
Start Trigger
Exceeds allowable maximum – flash maximum
Exceeds allowable minimum – display ‘0’ and flash
Within bounds – display
Use Case – Measure Freq
Select
Mode
Select
Range
Select
User Trigger
Textual Description – Measure Freq
User
Select measure freq mode
Select measurement range
Select measurement Trigger
System
Configure to specified range and trigger
Make Measurement
If in range – display results
If exceed range – display largest value & flash display
If below range – display zero value & flash display
Measure Period
Period measured continuously
Start Trigger
Exceeds allowable maximum – flash maximum
Exceeds allowable minimum – display ‘0’ and flash
Within bounds – display
Use Case – Measure Period
Select
Mode
Select
Range
Select
User Trigger
Measure Interval
Interval measured within a window
Start Trigger
Stop Trigger
Exceeds allowable maximum – flash maximum
Exceeds allowable minimum – display ‘0’ and flash
Within bounds – display
Use Case – Measure Interval
Select
Mode
Select
Range
Select Start
User Trigger
Select Stop
Trigger
Count Events
Event done continuously
Start Trigger
Exceeds allowable maximum – flash maximum
Exceeds allowable minimum – display ‘0’ and flash
Within bounds – display
Use Case – Count Events
Select
Mode
Select
Range
Select Edge
User
Other Specifications
Automatic Power Line Voltage Regulation
Temperature Staability 0 -50C
< 6 x10-6
Aging Rate
90 day
< 3x10-8
6 month
<6 x10-7
1 year
<25 x10-6
Other Specifications
Safety : IEC-1010
MTBF : 10,000 hrs
Measure Frequency
Get range
Get edge
Open meas
window
Close meas
window Update Display
Read count
Flash Flash
Measure Period
Get range
Get edge
Read count
Flash Flash
Measure Interval
Get range
Read count
Flash Flash
Compilers,
Assemblers &
Debuggers
M7: Embedded Software Design
Embedded Code
Rich functionality
Run at the required rate
Fit within a certain amount of memory
Meet power consumption requirements
Robust, Reliable and Maintainable
Source
code
Pre-
processor Compiler Assembler
Object
code
Linker
.s19/ hex
Loader
Preprocessor
Builds Temporary File – Translation unit
Header File - # include
# define, #ndef
Unresolved external references
Compiler
Cross compiler
a*b + 5*(c - d)
Flow Graph for Statement
Translation
a b c d
1 - 2
* w 5
x
* 3
y
4 +
z
Register Allocation
w=a+b
x= c+w
y= c+d
1 2 3
w=a+b
x= c+w
y= c+d
Color Graphs
Smallest no. of colors to represent all variables
a b
w
d
x
c
y
w=a+b
x= c+w
y= c+d
Compiler
Optimization Tech
Dead Code Elimination
Procedure Inlining
Expression Simplification
a * b + a*c = a*(b+c)
Instruction Selection
Scheduling
ORG $1000
PLC -1000
LABEL1 ADR r4,c
PLC -1004 LDR r0,[r4]
LABEL2 ADR r4,b
LDR r1,[r4]
LABEL3 SUB r0,r0,r1
Linker
Allows program to be stitched together from smaller pieces
Lib - preassembled
Labels
defined and used in same file
defined and used in different files
Entry Point
External Reference
Proceeds in two steps
absolute address of start of each obj file
specified by user
merges all symbol tables relative address – absolute address
DLL
Makefiles
Files to compile
Standard and custom lib
Name of executable
Whether debug info
hw:hw.o
gcc hw.o –o hw
hw.o:hw.c
gcc –c hw.c
Debug & Release Builds
Debugging tool
Larger Executable
Tasks & Task Management
Exchange/share data
Synchronization
Sharing resources (processor)
Schedule
Adv – Backup
Producer T0 T1 Consumer
Bool Full()
Bool Empty()
B0
T0 T1
B1
16
RL8.1.1 Embedded System Design © K.R.Anupama & Meetha.V.Shenoy
Ring Buffers T0 - head
T1- Tail
T0 T1
post pend
send receive
B0 B1
Network Network
T0 T1
send recieve
B0 B1
• Data Inconsistency
• Aberrant/unexpected behavior
3
Co-operating Tasks
Producer Consumer
while(1) while(1)
if not full if not empty
add item get item
inc count dec count
else else
wait for space wait for item
endwhile endwhile
4
Problem ??
• Simultaneous access of count
• 3 different values at any instant of time
• Critical Section – Mutually exclusive access
5
Non-CS
Synchronization
Entry Section
• Mutually exclusive Critical Section
• Condition
Exit Section
Non-CS
6
Requirements – Soln
• Mutual exclusion
• Deadlock
• Bounded Waiting
7
Soln 1: Flags
• Each Task has a flag
• Atomic procedure await
await (codn)
{
statements
} variable
8
Flags
Producer Consumer
While(1) While(1)
if not full if not empty
add item get item
await(!T1Flag) {T0 await(!T0Flag) {T1
Flag= true} Flag = true}
inc count dec count
T0Flag = False T1Flag = False
else else
wait for space wait for item
endwhile endwhile
9
Problems
• Task process not wanting to co-operate can hold
token forever
• Task/Process with token crashes
• Token corrupted/lost
• Task with token terminates without giving up token
• Task added/removed
11
Solution
• Add Task for token management
• Every time a task enters/leaves – registers with
token management
• Disadvantages
▫ No. of tasks increase
▫ IPC reqd for new task
12
Soln 4: Semaphores
• Semaphores: Introduced by Dijkstra in 1960s
Semaphores
• Variables that can be accessed only thro’ atomic op
• wait – p(s)
• signal – v(s)
• p(s) – test & set
• v(s) - reset
15
Semaphores
wait(s) signal(s)
{ {
while(s); s = false;
s = true; }
}
17
Semaphores – Counting
• Takes value 0 – N-1
• List of associated processes
• Process executes wait instruction – semaphore not available
• Task blocks itself
▫ Block – waiting queue of semaphore (task waiting)
▫ Control Transferred to scheduler
• Restarted when signal op is executed
▫ Wake –up
▫ Task in ready state – ready queue
19
Semaphores
wait(s) signal(s)
{ {
s = s+1; s = s -1;
if(s >1) if (s>1)
{ {
add process to waiting remove process from
queue; waiting queue;
block; wakeup(p);
} }
} }
20
Semaphore implementation
typedef struct {
int value;
queue tlist;
} semaphore;
21
Buffer 0
Buffer 1
Buffer n-2
Buffer n-1
23
Requirements
• Imaging System – Producer
• Satellite System – Consumer
• Count no. of free/full buffers
• Controlled access to individual buffers for read/write
24
Algorithm - Producer
• Producer checks if any buffer is empty
• If empty – waits for exclusive access to buffer pool.
• Access gained – data added – then exit
25
Algorithm - Consumer
• Consumer checks whether any buffer has data
available
• If yes waits for exclusive access
• Buffer pool – available consumer gets data and
exits
26
Semaphores
• mutex (1)
• empty (n-1)
• full (0)
27
Camera Satellite
while(1) while(1)
…. wait(full);
produce an item wait(mutex);
…. ….
wait(empty); remove item from
wait(mutex); buffer;
…. ….
add item to buffer; signal(mutex);
…. signal(empty);
signal(mutex); ….
signal(full); consume item
…. ….
endwhile
endwhile
28
Semaphores
wait(empty) signal(empty)
sem_wait (semaphore *S) sem_signal (semaphore *S) {
{ S->value++;
S->value--; if (S->value <= 0) {
if (S->value < 0) { remove thread t from
add this process to S->tlist;
S->tlist;
wakeup(t);
block();
}
}
}
29
Modified Rover
• Imaging System can gather data simultaneously
• Data can be uploaded using several links
• Data object shared by several concurrent processes
▫ Readers – Writers
Readers access data simultaneously
Writer and reader try simultaneously
▫ Reader – Writer Problem
• No Reader waits unless a writer is accessing the buffer
31
Semaphores
• wrtSem (1)
• mutex (1)
• numReaders (0)
32
writer Reader
wait(wrtSem); while(1)
…. wait(mutex);
numReaders++;
perform writing;
if(numReaders==1)
…. wait(wrtSem);
signal(wrtSem); endif
signal(mutex);
….
Perform reading;
…
wait(mutex);
numReaders--;
if(numReaders==0)
signal(wrtSem);
endif
signal(mutex);
endwhile
33
Soln 5: Monitors
• Monitors provide control by allowing only one process to access a
critical resource at a time
▫ A class/module/package
▫ Contains procedures and data
Data – object state
• Data abstraction mechanism that encapsulates a repsn of an
abstract object
34
An Abstract Monitor
monitor monName
{
… some local declarations
… initialize local data
procedure name(…arguments)
… other procedures
permanent variables (static)
}
35
Monitor Rules
• Only procedure names are visible – Public interface
• Permanent variables can be changed only thro’ one of the
procedures
• Any process can access any monitor procedure at any time
• Only one process may enter a monitor procedure
▫ Simultaneous access of two different proc
▫ Two invocations of same proc
• No process may directly access a monitor’s local variables
• A monitor may only access it’s local variables
36
• “wait” operation
▫ Forces running process to sleep
• “signal” operation
▫ Wakes up a sleeping process
• Condition
▫ Synchronisation
37
Monitor - implementation
Monitor boundBuffer
bufferPool;
count = 0;
cond notEmpty;
cond not Full;
39
Monitor - implementation
put(anItem)
{
while(count==n)wait(notFull);
put an item into buffer;
signal(notEmpty);
}
40
Monitor - implementation
get(anItem)
{
while(count==0)wait(notEmpty);
get an item from buffer;
signal(notFull);
}
41
Producer Consumer
while(1) while(1)
…. ….
produce an item boundBuffer.get(anItem)
…. ….
boundBuffer.put(anItem) produce an item
…. ….
endwhile endwhile
42
Problems
• Starvation
▫ Block one process from running – while a
processor is waiting – other process are added and
removed in LIFO
• Deadlock
RTS
Executing
needs data
gets data
& CPU
Pre-empted ready
Chosen to run
Rxd data
Ready Waiting
needs data
P2 P1 P2 P3
0 10 20 30 40 50 60
Deadline
Initiating event
Periodic Process
P1
period
Deadline
Initiating event
Periodic Process
P1
period
Deadline
Initiating event
Periodic Process
P1
period
Deadline
Initiating event
i=1n ci/pi 1
utilization – 100 %
T1 T2 T3 T4
0 5 10 16 20 24 34
T1 T2 T3 T4
0 5 11 15 25