126
By : Monika N Module I Introducing Embedded Systems and the Microcontrollers

Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

By : Monika N

Module IIntroducing Embedded Systems

and the Microcontrollers

Page 2: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Outline

▪ Definition of Embedded Systems▪ Significance▪ Examples▪ Computer Essentials▪ What does Embedded System Comprise of?▪ Hardware Architecture of an Embedded System▪ Microprocessors and Microcontrollers

Page 3: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ PIC Microcontrollers▪ 12 Series PIC▪ Classification of Embedded Systems▪ Skills required for an embedded system designer

Page 4: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Definition of Embedded Systems

▪ Embedded system: is a system whose principal function is not computational, but which is controlled by a computer embedded within it.

▪ We can say that it is “A combination of computer hardware and software , and perhaps additional mechanical or other parts , designed to perform a dedicated function . In some cases, embedded systems are part of a larger system or product , as is the case of an antilock braking system in a car.”

Page 5: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Significance

▪ Due to their compact size, low cost and simple design aspects made embedded systems very popular and encroached into human lives and have become indispensable. They are found everywhere from kitchen to spacecraft . To emphasize this here are some illustrations such as

a) Biomedical Instrumentation-ECG Recorder , Blood Cell Recorder , Patient Monitor System etc.

b) Communication System-Pagers, cellular phones , cable television terminals , trans receivers etc.

c) Peripheral Controllers of a Computer – Keyboard controller, LAN Controller etc.

Page 6: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Example 1:Refrigerator

Page 7: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Example 2:car Door

Page 8: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Example 3:Electronic Ping-pong

Page 9: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Example 4: Derbot Autonomous Guided Vehicle

Page 10: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Derbot Autonomous Guided Vehicle(Schematic)

Page 11: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Computer Essentials

Page 12: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Instruction Sets• CISC: Complex Instruction Set Computer• RISC: Reduced Instruction Set Computer

▪ Memory Types• Volatile: Random Access Memory (RAM)• Non-volatile: Read Only Memory (ROM)

Page 13: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

What does Embedded System Comprise of?

▪ Every embedded system consists of a custom-built hardware built around a Central Processing Unit(CPU).

▪ This hardware also contains memory chips onto which the software is loaded. The software residing on chip is termed as ‘firmware’.

▪ The operating system runs above the hardware, and the application software runs above the operating system.

Page 14: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ This hardware also contains memory chips onto which the software is loaded.

Hardware

Operarting System

Application Software

Page 15: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Hardware Architecture of an Embedded System

Read-Only Memory

Random Access Memory

Central Processing Unit(CPU)

Application Specific Circuitry

Output Devices

Input Devices

Communication Interfaces

Page 16: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Microprocessors and Microcontrollers

▪ The microprocessor is a processor fabricated on one single silicon chip.

▪ Microprocessor , any of a type of miniature electronic device that contains the arithmetic, logic, and control circuitry necessary to perform the functions of a digital computer’s central processing unit.

▪ The microcontrollers are used in embedded computing.

▪ The microcontroller is a microprocessor with added circuitry.

Page 17: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Microcontrollers

Page 18: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Microcontroller Families

Page 19: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Microcontroller Packaging and Appearance

From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000

Page 20: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

PIC Microcontrollers

• Peripheral Interface Controller (PIC) was originally designed by General Instruments

• In the late 1970s, GI introduced PIC® 1650 and 1655 – RISC with 30 instructions.

• PIC was sold to Microchip• Features: low-cost, self-contained, 8-bit, Harvard

structure, pipelined, RISC, single accumulator, with fixed reset and interrupt vectors.

Page 21: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Von Neumann and Harvard Computers

Page 22: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

12 Series PIC

The small 12F508

Page 23: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

PIC 12F508/509 pin connection diagram

Page 24: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Classification of Embedded Systems

▪Embedded systems are classified as❑ Stand-alone Embedded Systems❑ Real-time Embedded Systems❑ Networked Information Appliances❑ Mobile Devices

Page 25: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Stand-alone Embedded SystemsAs the name implies, stand-alone systems work in stand-alone mode . They take inputs, process them and produce the desired output . The input can be electrical signals from transducers or commands from a human being such as the pressing of a button . The output can be electrical signals to drive another system, an LED display or LCD display for displaying of information to users. Embedded Systems used in process control , automobiles, consumer electronic items etc. fall into this category.

Page 26: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Real-time SystemsEmbedded Systems in which some specific work has to be done in a specific time period are called real-time systems . For example, consider a system that has to open a valve within 30 milliseconds when the humidity crosses a particular threshold. If the valve is not opened within 30 milliseconds, a catastrophe may occur. Such systems with strict deadlines are called real-time systems.Further classified as -Soft real-time systems-Hard real-time systems

Page 27: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Networked Information AppliancesEmbedded systems that are provide with network interfaces and

accessed by networks such as Local Area Network or the Internet are called Networked Information Appliances . Such embedded systems are connected to a network , typically a network running TCP/IP (Transmission Control Protocol/Internet Protocol) protocol suite, such as the Internet or a company’s intranet.

Examples of such system includes a network processed control system , web camera , door lock of your home etc.

Page 28: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Mobile Devices Mobile Devices such a s mobile phones , Personal Digital Assistants (PDAs) , smart phones etc. are a special category of embedded systems. Though the PDAs do many general purpose tasks , they need to be designed just like ‘conventional’ embedded systems.

Page 29: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Skills required for an embedded system designer

▪Embedded systems have come a long way since they were introduced, in the early 1960s. Applications of embedded systems are ever-increasing and the trend is growing in momentum with every year that passes. ▪Embedded systems and microelectronics have accentuated the importance of technology in our day-to-day lives. We are surrounded by intelligent systems without even realizing it. ▪However, in the world of dynamic technology, this could be a double-edged sword. In order to keep up with the overwhelming pace at which the industry is progressing, you need to make sure to evolve with technology.

Page 30: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Necessary skills include• Full understanding of a microcontroller with a basic

knowledge of computer architecture, digital electronic design, software engineering, data communication, control engineering, motors and actuators, sensors and measurements, analog electronic design and IC design and manufacture .

• Debugging the software and hardware bugs by using test vectors.

• Use of ICE (In-Circuit-Emulators), cross assemblers and testing equipment.

Page 31: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

By:Monika N

Module IICommunication Buses for

Device Networks

Page 32: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Contents

▪ Wireless devices▪ Timer and counting devices▪ Watchdog timer▪ Networked embedded systems▪ Serial bus communication protocols▪ Internet enabled systems▪ Wireless and mobile system protocols

Page 33: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Wireless devices

▪ A wireless system is any collection of elements (or subsystems) that operate interdependently and use unguided electromagnetic-wave propagation to perform some specified function(s).

▪ Wireless communication is the electromagnetic transfer of information between two or more points that are not connected by an electrical conductor.

Page 34: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ The most common wireless technologies use radio waves. With radio waves, intended distances can be short, such as a few meters for Bluetooth or as far as millions of kilometres for deep-space radio communications.

▪ It encompasses various types of fixed, mobile, and portable applications, including two-way radios, cellular telephones, personal digital assistants (PDAs), and wireless networking.

Page 35: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Other examples of applications of radio wireless technology include GPS units, garage door openers, wireless computer mouse, keyboards and headsets, headphones, radio receivers, satellite television, broadcast television and cordless telephones.

▪ Somewhat less common methods of achieving wireless communications include the use of other electromagnetic wireless technologies, such as light, magnetic, or electric fields or the use of sound

Page 36: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Some examples of wireless systems are• Systems that convey information between two or more

locations, such as personal communication systems (PCS), police and fire department radio systems, commercial broadcast systems, satellite broadcast systems, telemetry and remote monitoring systems

• Systems that sense the environment and/or objects in the environment, including radar systems that may be used for detecting the presence of objects in some region or volume of the environment and measuring their relative motion and/or position, systems for sensing or measuring atmospheric conditions, and systems for mapping the surface of the Earth or planets

• Systems that aid in navigation or determine the location of an object on the Earth or in space

Page 37: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Add an image depicting wireless systems

Page 38: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Timer and counting devices

▪ Counter/timer hardware is a crucial component of most embedded systems. In some cases a timer is needed to measure elapsed time; in others we want to count or time some external events. Here's a primer on the hardware.

▪ Counter/timer hardware is a crucial component of most embedded systems. In some cases, a timer measures elapsed time (counting processor clock ticks). In others, we want to count or time external events. The names counter and timer can be used interchangeably when talking about the hardware.

▪ The difference in terminology has more to do with how the hardware is used in a given application.

Page 39: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Fig 1 :A simple counter/timer

Page 40: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Figure 1 shows a simple timer similar to those often included on-chip within a microcontroller. You could build something similar from a couple of 74HC161 counters or a programmable logic device.

▪ The timer shown consists of a loadable 8-bit count register, an input clock signal, and an output signal. Software loads the count register with an initial value between 0x00 and 0xFF. Each subsequent transition of the input clock signal increments that value.

Page 41: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ When the 8-bit count overflows, the output signal is asserted. The output signal may thereby trigger an interrupt at the processor or set a bit that the processor can read. To restart the timer, software reloads the count register with the same or a different initial value.

▪ If a counter is an up counter, it counts up from the initial value toward 0xFF. A down counter counts down, toward 0x00.

▪ A typical counter will have some means to start the counter running once it is loaded, usually by setting a bit in a control register. This is not shown in the figure.

▪ A real counter would generally also provide a way for the processor to read the current value of the count register at any time, over the data bus.

Page 42: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Real time clock

▪ Real time clock(RTCs) are designed for ultra-low power consumption as they usually continue running when the main system is powered down. This enables them to maintain current time against an absolute time reference, usually set by the microprocessor directly. Figure 1 depicts the typical internal workings of a simple RTC.

▪ RTCs are a very common element. They are present in everything from the instrument clusters and infotainment systems in automotive applications to house metering. RTCs frequently integrate into other devices—for example, the broadband communications ICs used in car radios.

Page 43: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Figure 1: The Internal Circuit Blocks of a PCA21125

Page 44: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ They usually interface to a microprocessor circuit by an SPI or I2C serial bus, and may contain a number of other functions like backup memory, a watchdog timer for supervising the microprocessor and countdown timers to generate real time event. Some RTCs include second or minute interrupt outputs and are even clever enough to account for leap years(see figure 2).

Page 45: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Figure 2: Data flow diagram of a time function

Page 46: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Networked embedded systems

▪ The OSI model itself is conceptual in nature - it does not include any actual specifications for network implementation. However, the OSI model does provide a framework for understanding the components of a complete network communication system. As we will see, many of today's most commonly implemented networking technologies use features and protocols that reflect parts of the OSI model.

▪ The OSI model defines a seven-layer architecture for a complete communication system:

Page 47: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Three Different Types of Embedded Networking1. Embedded Networking with CAN Bus

•The Control Area Network (CAN) protocol was developed to meet the embedded systems requirements of the automotive industry. CAN is a specification for a serial network that can be used to establish local connections between the microcontrollers in a motor vehicle. The CAN bus protocol is a two-wire, half-duplex system that works well for applications that demand a high-speed transfer of short messages.

•The specifications for the CAN bus protocol are described in the international standard ISO 11898:2003. The specification includes requirements for the physical layer and data link layers of the network, leaving individual engineers or manufacturers to implement other high-level protocols of their choosing to satisfy additional networking requirements.

Page 48: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

2. Embedded Networking with I2C Bus•The I2C communications protocol for embedded systems was invented by Philips Semiconductor in 1989. I2C is a two-wire, half-duplex serial communication protocol with a multi-master, multi-slave architecture whose primary application is short range, intra-board communication. Due to the limitations of the I2C protocol's 7-bit address space and the total bus capacitance of 400 pF, serial communication using the I2C protocol is only effective when the connected devices are less than a few meters apart.

Page 49: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

3. Embedded Networking with Ethernet•Embedded devices that connect to local area networks or the internet can be implemented using Ethernet technology. Ethernet connections are often implemented as part of a protocol stack known as the Internet Protocol Suite, sometimes referred to as TCP/IP. The TCP/IP protocol stack includes four layers that are closely analogous to the OSI network model:

•Application Layer - The application layer of the TCP/IP protocol stack combines functions that are represented in the application layer, presentation layer, and session layers of the OSI model. Communication protocols for the application layer include HTTP, FTP, DNS, SMTP, TELNET and others.

Page 50: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

• Transport Layer - The transport layer of the TCP/IP protocol stack implements either the transmission control protocol (TCP) or the user datagram protocol (UDP). The TCP is ideal for applications that require reliable data streaming, whereas UDP can be implemented for embedded systems where reduced latency is valued over data transfer reliability.

• Internet - The internet layer of TCP/IP provides network layer functions from the OSI model. In the internet layer, each device is assigned an IP address according to the IPv4 or IPv6 standard. The internet layer transports network packets from a host device to a target device specified by its IP address. It supports processes and functions for sending and receiving packets, as well as detecting and diagnosing errors.

Page 51: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

• Network Interface - An Ethernet networking interface card allows an embedded system to connect to a network physically using a twisted-pair or fibre optic Ethernet cable. Ethernet provides networking capabilities that encompass the features of the physical layer and the data link layer of the OSI model.

Page 52: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Serial bus communication protocols

▪ The communication is very well known terminology which involves the exchange of information between two or more mediums.

▪ In embedded systems, the communication means the exchange of data between two microcontrollers in the form of bits. This exchange of data bits in microcontroller is done by some set of defined rules known as communication protocols.

▪ Now if the data is sent in series i.e. one after the other then the communication protocol is known as Serial Communication Protocol. More specifically, the data bits are transmitted one at a time in sequential manner over the data bus or communication channel in Serial Communication.

Page 53: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Types of Communication Protocols• There are different types of data transfer available in the

digital electronics such as serial communication and parallel communication. Similarly the protocols are divided into two types such as Serial Communication Protocol and Parallel Communication Protocols. Examples of Parallel Communication Protocols are ISA, ATA, SCSI, PCI and IEEE-488. Similarly there are several examples of Serial Communication Protocols such as CAN, ETHERNET, I2C, SPI, RS232, USB, 1-Wire, and SATA etc.

Page 54: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Serial Communication Protocol

Page 55: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Parallel Communication Protocol

Page 56: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Internet Enabled Network Protocols

▪ Communication to other system on the Internet. ▪ Use html (hyper text mark up language) or MIME

(Multipurpose Internet Mail Extension) type files ▪ Use TCP (transport control protocol) or UDP (user

datagram protocol) ▪ Addressed by an IP address ▪ Use IP (internet protocol) at network layer protocol as

transport layer protocol

Page 57: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Wireless and mobile system protocols

▪ Mobile communication protocols use multiplexing to send information. Multiplexing is a method to combine multiple digital or analog signals into one signal over the data channel. This ensures optimum utilization of expensive resource and time. At the destination these signals are de-multiplexed to recover individual signals.

▪ These are the types of multiplexing options available to communication channels −

• FDM (Frequency Division Multiplexing) − Here each user is assigned a different frequency from the complete spectrum. All the frequencies can then simultaneously travel on the data channel.

Page 58: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

• TDM (Time Division Multiplexing) − A single radio frequency is divided into multiple slots and each slot is assigned to a different user. So multiple users can be supported simultaneously.

▪ GSM• GSM stands for Global System for Mobile communications.

GSM is one of the most widely used digital wireless telephony system. It was developed in Europe in 1980s and is now international standard in Europe, Australia, Asia and Africa. Any GSM handset with a SIM (Subscriber Identity Module) card can be used in any country that uses this standard. Every SIM card has a unique identification number. It has memory to store applications and data like phone numbers, processor to carry out its functions and software to send and receive messages

Page 59: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

• GSM technology uses TDMA (Time Division Multiple Access) to support up to eight calls simultaneously. It also uses encryption to make the data more secure.

▪ CDMA• CDMA stands for Code Division Multiple Access. It was first

used by the British military during World War II. After the war its use spread to civilian areas due to high service quality. As each user gets the entire spectrum all the time, voice quality is very high. Also, it is automatically encrypted and hence provides high security against signal interception and eavesdropping.

▪ WLL• WLL stands for Wireless in Local Loop. It is a wireless local

telephone service that can be provided in homes or offices. The subscribers connect to their local exchange instead of the central exchange wirelessly.

Page 60: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Using wireless link eliminates last mile or first mile construction of network connection, thereby reducing cost and set up time. As data is transferred over very short range, it is more secure than wired networks.

▪ GPRS• GPRS stands for General Packet Radio Services. It is a

packet based wireless communication technology that charges users based on the volume of data they send rather than the time duration for which they are using the service.

• This is possible because GPRS sends data over the network in packets and its throughput depends on network traffic.

• As traffic increases, service quality may go down due to congestion, hence it is logical to charge the users as per data volume transmitted.

Page 61: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Module III & IVReal-Time Operating Systems

By : Monika N

Page 62: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

What’s an Operating System?

▪ Provides environment for executing programs▪ Process abstraction for multitasking/concurrency

• Scheduling▪ Hardware abstraction layer (device drivers)▪ Filesystems▪ Communication

▪ We will focus on concurrent, real-time issues

Page 63: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Do I Need One?

▪ Not always

▪ Simplest approach: cyclic executive

loop do part of task 1 do part of task 2 do part of task 3end loop

Page 64: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Cyclic Executive

▪ Advantages• Simple implementation• Low overhead• Very predictable

▪ Disadvantages• Can’t handle sporadic events• Everything must operate in lockstep• Code must be scheduled manually

Page 65: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Interrupts▪ Some events can’t wait for next loop iteration

• Communication channels• Transient events

▪ A solution: Cyclic executive plus interrupt routines

▪ Interrupt: environmental event that demands attention

• Example: “byte arrived” interrupt on serial channel

▪ Interrupt routine: piece of code executed in response to an interrupt

Page 66: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Handling an Interrupt

1. Normal program execution

2. Interrupt occurs

3. Processor state saved 4. Interrupt routine

runs

5. Interrupt routine terminates

6. Processor state restored

7. Normal program execution resumes

Page 67: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Interrupt Service Routines

▪ Most interrupt routines:

▪ Copy peripheral data into a buffer▪ Indicate to other code that data has arrived▪ Acknowledge the interrupt (tell hardware)

▪ Longer reaction to interrupt performed outside interrupt routine

▪ E.g., causes a process to start or resume running

Page 68: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Cyclic Executive Plus Interrupts

▪ Works fine for many signal processing applications

▪ 56001 has direct hardware support for this style

▪ Insanely cheap, predictable interrupt handler:

• When interrupt occurs, execute a single user-specified instruction

• This typically copies peripheral data into a circular buffer

• No context switch, no environment save, no delay

Page 69: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Drawbacks of CE + Interrupts

▪ Main loop still running in lockstep▪ Programmer responsible for scheduling▪ Scheduling static▪ Sporadic events handled slowly

Page 70: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Cooperative Multitasking

▪ A cheap alternative▪ Non-preemptive▪ Processes responsible for relinquishing control▪ Examples: Original Windows, Macintosh▪ A process had to periodically call get_next_event() to

let other processes proceed▪ Drawbacks:

• Programmer had to ensure this was called frequently• An errant program would lock up the whole system

▪ Alternative: preemptive multitasking

Page 71: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Concurrency Provided by OS

▪ Basic philosophy:

▪ Scheduling and function usually orthogonal▪ Changing the algorithm would require a change in

scheduling

▪ First, a little history

Let the operating system handle scheduling, and let the programmer handle function

Page 72: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Batch Operating Systems

▪ Original computers ran in batch mode:• Submit job & its input• Job runs to completion• Collect output• Submit next job

▪ Processor cycles very expensive at the time▪ Jobs involved reading, writing data to/from tapes▪ Cycles were being spent waiting for the tape!

Page 73: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Timesharing Operating Systems

▪ Solution• Store multiple batch jobs in memory at once• When one is waiting for the tape, run the other one

▪ Basic idea of timesharing systems

▪ Fairness primary goal of timesharing schedulers• Let no one process consume all the resources• Make sure every process gets “equal” running time

Page 74: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Real-Time Is Not Fair

▪ Main goal of an RTOS scheduler: meeting deadlines

▪ If you have five homework assignments and only one is due in an hour, you work on that one

▪ Fairness does not help you meet deadlines

Page 75: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Priority-based Scheduling

▪ Typical RTOS based on fixed-priority preemptive scheduler

▪ Assign each process a priority▪ At any time, scheduler runs highest priority

process ready to run

▪ Process runs to completion unless preempted

Page 76: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Typical RTOS Task Model

▪ Each task a triplet: (execution time, period, deadline)▪ Usually, deadline = period▪ Can be initiated any time during the period

Execution time

Period

Deadline

Time

Initiation

Page 77: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Example: Fly-by-wire Avionics

▪ Hard real-time system with multirate behavior

INU1kHz

GPS20 Hz

Air data

1 kHzJoystick

500 Hz

Pitch control500 Hz

Lateral Control250 Hz

Throttle Control250 Hz

Aileron 11 kHz

Aileron 21 kHz

Elevator1 kHz

Rudder1 kHz

gyros,accel.

GPS

Sensor

Stick

Aileron

Aileron

Elevator

Rudder

Sensors Signal Conditioning

Control laws Actuating Actuators

Page 78: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Priority-based Preemptive Scheduling▪ Always run the highest-priority runnable process

123

Page 79: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Priority-Based Preempting Scheduling▪ Multiple processes at the same priority level?

▪ A few solutions• Simply prohibit: Each process has unique priority

• Time-slice processes at the same priority▪ Extra context-switch overhead▪ No starvation dangers at that level

• Processes at the same priority never preempt the other▪ More efficient▪ Still meets deadlines if possible

Page 80: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Rate-Monotonic Scheduling

▪ Common way to assign priorities▪ Result from Liu & Layland, 1973 (JACM)▪ Simple to understand and implement:

▪ E.g.,

Processes with shorter period given higher priority

Period Priority10 1 (highest)12 215 320 4 (lowest)

Page 81: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Key RMS Result

▪ Rate-monotonic scheduling is optimal:

▪ Task sets do not always have a schedule▪ Simple example: P1 = (10, 20, 20) P2 = (5, 9, 9)

• Requires more than 100% processor utilization

If there is fixed-priority schedule that meets all deadlines, then RMS will

produce a feasible schedule

Page 82: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

RMS Missing a Deadline

▪ p1 = (10,20,20) p2 = (15,30,30) utilization is 100%

1

2

P2 misses first deadline

Would have met the deadline if p2 = (10,30,30), utilization reduced 83%

Page 83: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

When Is There an RMS Schedule?

▪ Key metric is processor utilization: sum of compute time divided by period for each process:

U = Σ ci / pi

▪ No schedule can possibly exist if U > 1• No processor can be running 110% of the time

▪ Fundamental result:• RMS schedule always exists if U < n (2 1/n – 1)

• Proof based on case analysis (P1 finishes before P2)

Page 84: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

When Is There an RMS Schedule?

n Bound for U1 100% Trivial: one process2 83% Two process case3 78%4 76%

∞ 69% Asymptotic bound

Page 85: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

When Is There an RMS Schedule?

▪ Asymptotic result:

▪ Converse is not true. Instead:

If the required processor utilization is under 69%, RMS will give a valid schedule

If the required processor utilization is over 69%, RMS might still give a valid schedule, but there

is no guarantee

Page 86: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

EDF Scheduling

▪ RMS assumes fixed priorities▪ Can you do better with dynamically-chosen

priorities?

▪ Earliest deadline first:

Processes with soonest deadline given highest priority

Page 87: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

EDF Meeting a Deadline

▪ p1 = (10,20,20) p2 = (15,30,30) utilization is 100%

1

2

P2 takes priority because its deadline is sooner

Page 88: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Key EDF Result

▪ Earliest deadline first scheduling is optimal:

▪ Earliest deadline first scheduling is efficient:

If a dynamic priority schedule exists, EDF will produce a feasible schedule

A dynamic priority schedule exists if and only if utilization is no greater than 100%

Page 89: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Static Scheduling More Prevalent

▪ RMA only guarantees feasibility at 69% utilization, EDF guarantees it at 100%

▪ EDF is complicated enough to have unacceptable overhead

▪ More complicated than RMA: harder to analyze

▪ Less predictable: can’t guarantee which process runs when

Page 90: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Priority Inversion

▪ RMS and EDF assume no process interaction▪ Often a gross oversimplification

▪ Consider the following scenario:

12

Process 2 begins runningProcess 2 acquires lock on resource

Process 1 preempts Process 2Process 1 tries to acquire lock for resource

Page 91: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Priority Inversion

▪ Lower-priority process effectively blocks a higher-priority one

▪ Lower-priority process’s ownership of lock prevents higher-priority process from running

▪ Nasty: makes high-priority process runtime unpredictable

Page 92: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Nastier Example

▪ Higher priority process blocked indefinitely

1

Process 3 begins runningProcess 3 acquires lock on resource

Process 2 preempts Process 3

Process 1 tries to acquire lock and is blocked

3

2

Process 1 preempts Process 2

Process 2 delays process 3’s release of lock

Page 93: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Priority Inheritance

▪ Solution to priority inversion▪ Temporarily increase process’s priority when it

acquires a lock

▪ Level to increase: highest priority of any process that might want to acquire same lock

• I.e., high enough to prevent it from being preempted

▪ Danger: Low-priority process acquires lock, gets high priority and hogs the processor

• So much for RMS

Page 94: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Priority Inheritance

▪ Basic rule: low-priority processes should acquire high-priority locks only briefly

▪ An example of why concurrent systems are so hard to analyze

▪ RMS gives a strong result▪ No equivalent result when locks and priority

inheritance is used

Page 95: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Summary

▪ Cyclic executive• Way to avoid an RTOS• Adding interrupts helps somewhat

▪ Interrupt handlers• Gather data, acknowledge interrupt as quickly as

possible

▪ Cooperative multitasking• But programs don’t like to cooperate

Page 96: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Summary

▪ Preemptive Priority-Based Multitasking• Deadlines, not fairness, the goal of RTOSes

▪ Rate-monotonic analysis• Shorter periods get higher priorities• Guaranteed at 69% utilization, may work higher

▪ Earliest deadline first scheduling• Dynamic priority scheme• Optimal, guaranteed when utilization 100% or less

Page 97: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Summary

▪ Priority Inversion• Low-priority process acquires lock, blocks

higher-priority process

• Priority inheritance temporarily raises process priority

• Difficult to analyze

Page 98: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

By : Monika N

Module V Embedded Software Development Tools

Page 99: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Introduction

• Application programs are typically developed, compiled, and run on host system

• Embedded programs are targeted to a target processor (different from the development/host processor and operating environment) that drives a device or controls

• What tools are needed to develop, test, and locate embedded software into the target processor and its operating environment?

Page 100: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

• Distinction

• Host: Where the embedded software is developed, compiled, tested, debugged, optimized, and prior to its translation into target device. (Because the host has keyboards, editors, monitors, printers, more memory, etc. for development, while the target may have not of these capabilities for developing the software.)

• Target: After development, the code is cross-compiled, translated – cross-assembled, linked (into target processor instruction set) and located into the target

Page 101: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Introduction – 1▪ Cross-Compilers –

• Native tools are good for host, but to port/locate embedded code to target, the host must have a tool-chain that includes a cross-compiler, one which runs on the host but produces code for the target processor

• Cross-compiling doesn’t guarantee correct target code due to (e.g., differences in word sizes, instruction sizes, variable declarations, library functions)

▪ Cross-Assemblers and Tool Chain• Host uses cross-assembler to assemble code in

target’s instruction syntax for the target

Page 102: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

• Tool chain is a collection of compatible, translation tools, which are ‘pipelined’ to produce a complete binary/machine code that can be linked and located into the target processor

• (See Fig 9.1)

Page 103: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 104: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Linker/Locators for Embedded Software

▪ Native linkers are different from cross-linkers (or locators) that perform additional tasks to locate embedded binary code into target processors

▪ Address Resolution –• Native Linker: produces host machine code on the

hard-drive (in a named file), which the loader loads into RAM, and then schedules (under the OS control) the program to go to the CPU.

Page 105: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Locator: produces target machine code (which the locator glues into the RTOS) and the combined code (called map) gets copied into the target ROM. The locator doesn’t stay in the target environment, hence all addresses are resolved, guided by locating-tools and directives, prior to running the code (See Fig 9.3 and Fig 9.4)

Page 106: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

• In RAM, the application program/code’s logical addresses for, e.g., variable/operands and function calls, are ordered or organized by the linker. The loader then maps the logical addresses into physical addresses – a process called address resolution. The loader then loads the code accordingly into RAM (see Fig 9.2). In the process the loader also resolves the addresses for calls to the native OS routines

Page 107: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 108: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 109: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 110: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Locating Program Components – Segments▪ Unchanging embedded program (binary code) and

constants must be kept in ROM to be remembered even on power-off

▪ Changing program segments (e.g., variables) must be kept in RAM

▪ Chain tools separate program parts using segments concept

▪ Chain tools (for embedded systems) also require a ‘start-up’ code to be in a separate segment and ‘located’ at a microprocessor-defined location where the program starts execution

Page 111: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Some cross-compilers have default or allow programmer to specify segments for program parts, but cross-assemblers have no default behavior and programmer must specify segments for program parts

▪ (See Fig 9.5 - locating of object-code segments in ROM and RAM)

Page 112: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 113: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Locating Program Components – Segments – 1▪ Telling/directing the locator where (which segments) to

place parts▪ E.g., Fig 9.6

• The –Z tells which segments (list of segments) to use and the start-address of the first segment

• The first line tells which segments to use for the code parts, starting at address 0; and the second line tells which segments to use for the data parts, starting at x8000

• The proper names and address info for the directing the locator are usually in the cross-compiler documentation

Page 114: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 115: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Initialized Data and Constant Strings▪ Segments with initialized values in ROM are shadowed

(or copied into RAM) for correct reset of initialized variables, in RAM, each time the system comes up (esp. for initial values that are take #define constants, and which can be changed)

▪ In C programs, a host compiler may set all uninitialized variable to zero or null, but this is not generally the case for embedded software cross-compilers (unless the startup code in ROM does so

▪ If part(s) of a constant string is(are) expected to be changed during run-time, the cross-compiler must generate a code to allow ‘shadowing’ of the string from ROM

Page 116: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ Locator Maps and Executing Out of RAM▪ Output file of locators are Maps – list addresses of all

segments▪ Maps are useful for debugging▪ An ‘advanced’ locator is capable of running (albeit slowly)

a startup code in ROM, which (could decompress and) load the embedded code from ROM into RAM to execute quickly since RAM is faster, especially for RISC microprocessors

▪ (See Fig 9.7 – Maps)

Page 117: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 118: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 119: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Getting Embedded Software into Target System

▪ Moving maps into ROM or PROM, is to create a ROM using hardware tools or a PROM programmer (for small and changeable software, during debugging)

▪ If PROM programmer is used (for changing or debugging software), place PROM in a socket (which makes it erasable – for EPROM, or removable/replaceable) rather than ‘burnt’ into circuitry

▪ PROM’s can be pushed into sockets by hand, and pulled using a chip puller

Page 120: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ The PROM programmer must be compatible with the format (syntax/semantics) of the Map

▪ (See Fig 9.8)

Page 121: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 122: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Getting Embedded Software into Target System – 1

▪ ROM Emulators – Another approach is using a ROM emulator (hardware) which emulates the target system, has all the ROM circuitry, and a serial or network interface to the host system. The locator loads the Map into the emulator, especially, for debugging purposes.

▪ Software on the host that loads the Map file into the emulator must understand (be compatible with) the Map’s syntax/semantics

▪ (See Fig 9.9)

Page 123: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers
Page 124: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

Getting Embedded Software into Target System – 2

▪ Using Flash Memory• For debugging, a flash memory can be loaded with

target Map code using a software on the host over a serial port or network connection (just like using an EPROM)

• Advantages:▪ No need to pull the flash (unlike PROM) for

debugging different embedded code

▪ Transferring code into flash (over a network) is faster and hassle-free

Page 125: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

▪ New versions of embedded software (supplied by vendor) can be loaded into flash memory by customers over a network - Requires a) protecting the flash programmer, saving it in RAM and executing from there, and reloading into flash after new version is written and b) the ability to complete loading new version even if there are crashes and protecting the startup code as in (a)

▪ Modifying and/or debugging the flash programming software requires moving it into RAM, modify/debug, and reloading it into target flash memory using above methods

Page 126: Module I Introducing Embedded Systems and the ... - NCET · From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000. PIC Microcontrollers

• Other directives: range of RAM and ROM addresses, end of stack address (segment is placed below this address for stack to grow towards the end)

• Segments/parts can also be grouped, and the group is located as a unit