This lecture provides a brief overview of what distinguishes embedded systems programming from “ordinary programming.” It then touches upon facilities that become prominent or problems when working “close to the hardware” such as free store use, bit manipulation, and coding standards. Remember: not all computers are little grey boxes hiding under desks in offices.
Possibility of arbitrary code execution by Step-Oriented Programmingkozossakai
Step-Oriented Programming (SOP) allows executing arbitrary code on embedded systems by repeating step execution and changing the program counter value. A debugger communicates with a target system's stub using the Remote Serial Protocol to read/write memory and registers, enabling full control via simple commands if the connection is compromised. SOP constructs code by combining pieces of existing machine code and executes it without needing to directly inject new code. Therefore attacks are possible even if execution from data areas is prevented. The presentation will demonstrate this attack principle and results from actual experimentation.
Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...CODE BLUE
An embedded system has a stub to connect with a host PC and debug a program on the system remotely. A stub is an independent control program that controls a main program to enable debugging by a debugger. A stub is simplified by only processing the simple controls such as reading or writing of the register or of a memory, and a debugger processes a complicated analysis on the host PC.
Communication with a debugger on the host PC and a stub on the embedded system is performed by a protocol called Remote Serial Protocol (RSP) over a serial communication or TCP/IP communication. If this communication is taken away, it becomes possible to operate a stub arbitrarily. We considered what kind of attack possibility there was in that case, and identified that execution of arbitrary code constructed from pieces of machine code, combined with (SOP: Step-Oriented Programming) is possible by repeating step execution while changing the value of the program counter. Therefore it is possible to construct an arbitrary code and execute it from existing machine code, even if execution of the injected machine code is impossible because execution on data area is prevented by DEP or only machine code on the flash ROM are allowed execution.
I will explain about an attack principle by SOP and the results from constructed attack code and actual inspection.
This document contains an assignment for a Fundamentals of IT course with 10 multiple choice questions worth 6 marks each, for a total of 60 marks. The questions cover topics like how computers are useful for data generation, computer structure, converting binary to decimal, real-time operating systems, defining operating systems, explaining headers and footers, describing the formatting toolbar, explaining common Excel functions, discussing slide transitions, and defining various internet service providers. Students are instructed to answer all 10 questions.
The document provides an overview of a course on software engineering. It discusses key concepts like structured programming, object-oriented programming, design principles of abstraction and modularity. It also covers programming in languages like C and Matlab. The goals of the course are to understand basic program design techniques, produce well-structured programs, and have a basic understanding of object-oriented design.
The document describes a course on software engineering that covers basic design principles and techniques like structured programming, object-oriented programming, and data structures. It aims to give students an understanding of how to produce well-structured, maintainable code. Examples will be shown in MATLAB and C/C++. Key concepts covered include abstraction, modularity, procedural and object-oriented programming, functions, classes, and arrays.
The document provides an overview of operating systems, including definitions, components, functions, and types. It discusses what an operating system is, its main components, and its key roles such as managing hardware resources, providing user interfaces, running application programs, and protecting system resources from unauthorized access. Different types of operating systems are also covered, from early batch processing and time-sharing systems to modern desktop, real-time, distributed, and mobile systems.
Possibility of arbitrary code execution by Step-Oriented Programmingkozossakai
Step-Oriented Programming (SOP) allows executing arbitrary code on embedded systems by repeating step execution and changing the program counter value. A debugger communicates with a target system's stub using the Remote Serial Protocol to read/write memory and registers, enabling full control via simple commands if the connection is compromised. SOP constructs code by combining pieces of existing machine code and executes it without needing to directly inject new code. Therefore attacks are possible even if execution from data areas is prevented. The presentation will demonstrate this attack principle and results from actual experimentation.
Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...CODE BLUE
An embedded system has a stub to connect with a host PC and debug a program on the system remotely. A stub is an independent control program that controls a main program to enable debugging by a debugger. A stub is simplified by only processing the simple controls such as reading or writing of the register or of a memory, and a debugger processes a complicated analysis on the host PC.
Communication with a debugger on the host PC and a stub on the embedded system is performed by a protocol called Remote Serial Protocol (RSP) over a serial communication or TCP/IP communication. If this communication is taken away, it becomes possible to operate a stub arbitrarily. We considered what kind of attack possibility there was in that case, and identified that execution of arbitrary code constructed from pieces of machine code, combined with (SOP: Step-Oriented Programming) is possible by repeating step execution while changing the value of the program counter. Therefore it is possible to construct an arbitrary code and execute it from existing machine code, even if execution of the injected machine code is impossible because execution on data area is prevented by DEP or only machine code on the flash ROM are allowed execution.
I will explain about an attack principle by SOP and the results from constructed attack code and actual inspection.
This document contains an assignment for a Fundamentals of IT course with 10 multiple choice questions worth 6 marks each, for a total of 60 marks. The questions cover topics like how computers are useful for data generation, computer structure, converting binary to decimal, real-time operating systems, defining operating systems, explaining headers and footers, describing the formatting toolbar, explaining common Excel functions, discussing slide transitions, and defining various internet service providers. Students are instructed to answer all 10 questions.
The document provides an overview of a course on software engineering. It discusses key concepts like structured programming, object-oriented programming, design principles of abstraction and modularity. It also covers programming in languages like C and Matlab. The goals of the course are to understand basic program design techniques, produce well-structured programs, and have a basic understanding of object-oriented design.
The document describes a course on software engineering that covers basic design principles and techniques like structured programming, object-oriented programming, and data structures. It aims to give students an understanding of how to produce well-structured, maintainable code. Examples will be shown in MATLAB and C/C++. Key concepts covered include abstraction, modularity, procedural and object-oriented programming, functions, classes, and arrays.
The document provides an overview of operating systems, including definitions, components, functions, and types. It discusses what an operating system is, its main components, and its key roles such as managing hardware resources, providing user interfaces, running application programs, and protecting system resources from unauthorized access. Different types of operating systems are also covered, from early batch processing and time-sharing systems to modern desktop, real-time, distributed, and mobile systems.
The document discusses buffer overflows, which occur when data is added to a buffer that exceeds the allocated memory space for that buffer. This can allow attackers to control other values in a program. Common ways to exploit buffer overflows include stack smashing attacks, which overwrite return addresses on the stack. The document then discusses various techniques used to help prevent buffer overflows, such as canary-based defenses that insert check values, non-executable stack techniques, and approaches taken by different operating systems and languages. However, it notes that buffer overflows remain a problem and developers still need to write secure code to fully prevent exploits.
INTRODUCTION TO COMPUTER SYSTEMS ARCHITECTURE1_17 December 2023.pptMozammelHaque53
This is a lecture PowerPoint slide for the students of universities worldwide who desire to learn and advance his or her knowledge and expertise on Computer systems architecture.
This lecture introduces computer systems architecture and components. It discusses the Von Neumann architecture and its basic components: CPU, memory, input/output. It outlines the development of computing technology from mechanical to vacuum tube to transistor-based computers. It describes different types of computers from personal computers to mainframes and supercomputers. It explains the basic components of a computer system including the processor, memory, storage, and input/output devices.
This document provides an overview of static and dynamic analysis techniques for reversing software. It discusses static analysis techniques like disassembly and debugging tools. It also covers dynamic analysis techniques like tracing and debugging. The document is intended as a teaching aid for topics related to network, software, and hardware security including reversing.
Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/2J5O3XV.
Howard Chu gives tips and techniques for writing highly efficient and scalable software drawn from decades of experience. The guiding principle is a simple one, and can be applied nearly everywhere. The talk is focused on programming in C. Filmed at qconlondon.com.
Howard Chu founded Symas Corp. with 5 other partners and serves as its CTO. His work has spanned a wide range of computing topics, including most of the GNU utilities, networking protocols and tools, kernel and filesystem drivers, and focused on maximizing the useful work from a system. His current focus is database oriented, covering LDAP, LMDB, and other non-relational database technologies.
The document outlines the aims and structure of an introductory programming course in C++. It introduces programming and discusses why C++ is a good first language to learn. It presents a simple "Hello World" program and discusses how it works, including compilation and execution. The course will cover fundamental programming concepts, techniques, and basic C++ facilities to enable students to write simple programs and learn other languages.
Handling Exceptions In C & C++ [Part B] Ver 2ppd1961
This document discusses exception handling in C++. It provides an overview of how compilers manage exceptional control flow and how functions are instrumented to handle exceptions. It discusses normal vs exceptional function call flows, and the items involved in stack frames like context, finalization, and unwinding. It also summarizes Meyers' guidelines for exception safety, including using destructors to prevent leaks, handling exceptions in constructors, and preventing exceptions from leaving destructors.
This document discusses computer organization and architecture. It begins with an introduction that defines computer architecture as the attributes visible to a programmer, such as instruction sets, while computer organization deals with how features are implemented internally. It then covers several topics in computer architecture including the von Neumann model, levels of abstraction, number systems representation, and arithmetic in binary and hexadecimal. The document provides examples and diagrams to illustrate key concepts in computer organization and architecture.
The document describes the basic components and processes of a computer system. It explains that input involves entering data and instructions into the computer through input devices. The processor then receives the input, stores the information in memory, and processes the data. After processing, the computer outputs the results through output devices so users can see and access the processed data.
Presentation from DICE Coder's Day (2010 November) by Andreas Fredriksson in the Frostbite team.
Goes into detail about Scope Stacks, which are a systems programming tool for memory layout that provides
• Deterministic memory map behavior
• Single-cycle allocation speed
• Regular C++ object life cycle for objects that need it
This makes it very suitable for games.
This document provides an overview of CPU scheduling concepts including multiprogramming, multitasking, process creation, the short-term scheduler, process control blocks, the long-term scheduler, and the medium-term scheduler. It also discusses classifications of processes as interactive, batch, or real-time processes and as I/O-bound or CPU-bound processes. Finally, it introduces common CPU scheduling algorithms like first-come first-served (FCFS), shortest job first (SJF), and round-robin (RR).
This document discusses memory management techniques in computer systems including segmentation, paging, and virtual memory. It covers:
1. Segmentation divides memory into logical segments like code, data, stack, and heap and uses a segment table with base and limit registers to map logical to physical addresses.
2. Paging allows non-contiguous mapping of logical to physical addresses to avoid external fragmentation. It uses a page table and frame table to map virtual to physical pages.
3. Virtual memory uses both segmentation and paging to provide each process its own logical address space. The memory management unit (MMU) handles address translation from virtual to physical addresses.
This document discusses memory management techniques used in operating systems, including:
- Base and limit registers that define the logical address space and protect memory accesses.
- Address binding from source code to executable addresses at different stages.
- The memory management unit (MMU) that maps virtual to physical addresses using base/limit registers.
- Segmentation architecture that divides memory into logical segments like code, data, stack, heap.
This document discusses real-time operating systems for embedded systems. It begins by defining embedded systems as specialized computer systems designed to perform dedicated functions with real-time constraints. It then explains that real-time embedded systems must manage time-critical processes. Common real-time operating system (RTOS) functions include task management, inter-task communication, dynamic memory allocation, timers, and device I/O. RTOSs allow embedded systems to schedule tasks, communicate between processes, and interface with hardware in a timely manner. Examples of widely-used RTOSes are given.
This document provides information about a computer organization course, including the course outline, schedule, topics, textbooks, grading, and calendar. The course introduces computer architecture topics like addressing methods, CPU architecture, arithmetic, memory organization, and I/O organization. It will be taught on Thursdays from 10:00-12:00pm and include a midterm exam, lab assignments, and final exam. The course outline lists the topics to be covered in each week.
This document discusses user-level memory management in Linux programming. It describes the different memory segments of a Linux process including the code, data, BSS, heap and stack segments. It explains how programs can allocate and free dynamic memory at runtime using library calls like malloc(), calloc(), realloc() and free(), as well as system calls like brk() and sbrk(). Examples of allocating, changing the size, and freeing memory are also provided.
This document provides instructions for interpreting debug output on a Cisco router. The steps have a student configure debugging for IP routing on router R1. Interface Serial 0/0/0 between R1 and R2 is then configured with an IP address. Debug messages indicate the route is added but its state is initially false since the remote side is not yet configured. After fully configuring the local interface, debug output shows the interface state change to down until the remote side is also configured. The steps aim to demonstrate how debug output can provide insight into route states during router configuration.
The document discusses different tools for analyzing iOS code for bugs and performance issues. It describes the static analyzer as the first line of defense, which finds logic flaws and coding issues by analyzing code similar to a compiler. It then discusses using the Instruments tool on the simulator as the second line of defense for finding memory leaks and performance bottlenecks. Specific Instruments like Allocations, Leaks, and Time Profiler are described for analyzing different types of issues. Command line tools for configuring which static analyzer version is used are also overviewed.
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...IJECEIAES
Medical image analysis has witnessed significant advancements with deep learning techniques. In the domain of brain tumor segmentation, the ability to
precisely delineate tumor boundaries from magnetic resonance imaging (MRI)
scans holds profound implications for diagnosis. This study presents an ensemble convolutional neural network (CNN) with transfer learning, integrating
the state-of-the-art Deeplabv3+ architecture with the ResNet18 backbone. The
model is rigorously trained and evaluated, exhibiting remarkable performance
metrics, including an impressive global accuracy of 99.286%, a high-class accuracy of 82.191%, a mean intersection over union (IoU) of 79.900%, a weighted
IoU of 98.620%, and a Boundary F1 (BF) score of 83.303%. Notably, a detailed comparative analysis with existing methods showcases the superiority of
our proposed model. These findings underscore the model’s competence in precise brain tumor localization, underscoring its potential to revolutionize medical
image analysis and enhance healthcare outcomes. This research paves the way
for future exploration and optimization of advanced CNN models in medical
imaging, emphasizing addressing false positives and resource efficiency.
The document discusses buffer overflows, which occur when data is added to a buffer that exceeds the allocated memory space for that buffer. This can allow attackers to control other values in a program. Common ways to exploit buffer overflows include stack smashing attacks, which overwrite return addresses on the stack. The document then discusses various techniques used to help prevent buffer overflows, such as canary-based defenses that insert check values, non-executable stack techniques, and approaches taken by different operating systems and languages. However, it notes that buffer overflows remain a problem and developers still need to write secure code to fully prevent exploits.
INTRODUCTION TO COMPUTER SYSTEMS ARCHITECTURE1_17 December 2023.pptMozammelHaque53
This is a lecture PowerPoint slide for the students of universities worldwide who desire to learn and advance his or her knowledge and expertise on Computer systems architecture.
This lecture introduces computer systems architecture and components. It discusses the Von Neumann architecture and its basic components: CPU, memory, input/output. It outlines the development of computing technology from mechanical to vacuum tube to transistor-based computers. It describes different types of computers from personal computers to mainframes and supercomputers. It explains the basic components of a computer system including the processor, memory, storage, and input/output devices.
This document provides an overview of static and dynamic analysis techniques for reversing software. It discusses static analysis techniques like disassembly and debugging tools. It also covers dynamic analysis techniques like tracing and debugging. The document is intended as a teaching aid for topics related to network, software, and hardware security including reversing.
Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/2J5O3XV.
Howard Chu gives tips and techniques for writing highly efficient and scalable software drawn from decades of experience. The guiding principle is a simple one, and can be applied nearly everywhere. The talk is focused on programming in C. Filmed at qconlondon.com.
Howard Chu founded Symas Corp. with 5 other partners and serves as its CTO. His work has spanned a wide range of computing topics, including most of the GNU utilities, networking protocols and tools, kernel and filesystem drivers, and focused on maximizing the useful work from a system. His current focus is database oriented, covering LDAP, LMDB, and other non-relational database technologies.
The document outlines the aims and structure of an introductory programming course in C++. It introduces programming and discusses why C++ is a good first language to learn. It presents a simple "Hello World" program and discusses how it works, including compilation and execution. The course will cover fundamental programming concepts, techniques, and basic C++ facilities to enable students to write simple programs and learn other languages.
Handling Exceptions In C & C++ [Part B] Ver 2ppd1961
This document discusses exception handling in C++. It provides an overview of how compilers manage exceptional control flow and how functions are instrumented to handle exceptions. It discusses normal vs exceptional function call flows, and the items involved in stack frames like context, finalization, and unwinding. It also summarizes Meyers' guidelines for exception safety, including using destructors to prevent leaks, handling exceptions in constructors, and preventing exceptions from leaving destructors.
This document discusses computer organization and architecture. It begins with an introduction that defines computer architecture as the attributes visible to a programmer, such as instruction sets, while computer organization deals with how features are implemented internally. It then covers several topics in computer architecture including the von Neumann model, levels of abstraction, number systems representation, and arithmetic in binary and hexadecimal. The document provides examples and diagrams to illustrate key concepts in computer organization and architecture.
The document describes the basic components and processes of a computer system. It explains that input involves entering data and instructions into the computer through input devices. The processor then receives the input, stores the information in memory, and processes the data. After processing, the computer outputs the results through output devices so users can see and access the processed data.
Presentation from DICE Coder's Day (2010 November) by Andreas Fredriksson in the Frostbite team.
Goes into detail about Scope Stacks, which are a systems programming tool for memory layout that provides
• Deterministic memory map behavior
• Single-cycle allocation speed
• Regular C++ object life cycle for objects that need it
This makes it very suitable for games.
This document provides an overview of CPU scheduling concepts including multiprogramming, multitasking, process creation, the short-term scheduler, process control blocks, the long-term scheduler, and the medium-term scheduler. It also discusses classifications of processes as interactive, batch, or real-time processes and as I/O-bound or CPU-bound processes. Finally, it introduces common CPU scheduling algorithms like first-come first-served (FCFS), shortest job first (SJF), and round-robin (RR).
This document discusses memory management techniques in computer systems including segmentation, paging, and virtual memory. It covers:
1. Segmentation divides memory into logical segments like code, data, stack, and heap and uses a segment table with base and limit registers to map logical to physical addresses.
2. Paging allows non-contiguous mapping of logical to physical addresses to avoid external fragmentation. It uses a page table and frame table to map virtual to physical pages.
3. Virtual memory uses both segmentation and paging to provide each process its own logical address space. The memory management unit (MMU) handles address translation from virtual to physical addresses.
This document discusses memory management techniques used in operating systems, including:
- Base and limit registers that define the logical address space and protect memory accesses.
- Address binding from source code to executable addresses at different stages.
- The memory management unit (MMU) that maps virtual to physical addresses using base/limit registers.
- Segmentation architecture that divides memory into logical segments like code, data, stack, heap.
This document discusses real-time operating systems for embedded systems. It begins by defining embedded systems as specialized computer systems designed to perform dedicated functions with real-time constraints. It then explains that real-time embedded systems must manage time-critical processes. Common real-time operating system (RTOS) functions include task management, inter-task communication, dynamic memory allocation, timers, and device I/O. RTOSs allow embedded systems to schedule tasks, communicate between processes, and interface with hardware in a timely manner. Examples of widely-used RTOSes are given.
This document provides information about a computer organization course, including the course outline, schedule, topics, textbooks, grading, and calendar. The course introduces computer architecture topics like addressing methods, CPU architecture, arithmetic, memory organization, and I/O organization. It will be taught on Thursdays from 10:00-12:00pm and include a midterm exam, lab assignments, and final exam. The course outline lists the topics to be covered in each week.
This document discusses user-level memory management in Linux programming. It describes the different memory segments of a Linux process including the code, data, BSS, heap and stack segments. It explains how programs can allocate and free dynamic memory at runtime using library calls like malloc(), calloc(), realloc() and free(), as well as system calls like brk() and sbrk(). Examples of allocating, changing the size, and freeing memory are also provided.
This document provides instructions for interpreting debug output on a Cisco router. The steps have a student configure debugging for IP routing on router R1. Interface Serial 0/0/0 between R1 and R2 is then configured with an IP address. Debug messages indicate the route is added but its state is initially false since the remote side is not yet configured. After fully configuring the local interface, debug output shows the interface state change to down until the remote side is also configured. The steps aim to demonstrate how debug output can provide insight into route states during router configuration.
The document discusses different tools for analyzing iOS code for bugs and performance issues. It describes the static analyzer as the first line of defense, which finds logic flaws and coding issues by analyzing code similar to a compiler. It then discusses using the Instruments tool on the simulator as the second line of defense for finding memory leaks and performance bottlenecks. Specific Instruments like Allocations, Leaks, and Time Profiler are described for analyzing different types of issues. Command line tools for configuring which static analyzer version is used are also overviewed.
Semelhante a Embedded systems programming.ppt (20)
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...IJECEIAES
Medical image analysis has witnessed significant advancements with deep learning techniques. In the domain of brain tumor segmentation, the ability to
precisely delineate tumor boundaries from magnetic resonance imaging (MRI)
scans holds profound implications for diagnosis. This study presents an ensemble convolutional neural network (CNN) with transfer learning, integrating
the state-of-the-art Deeplabv3+ architecture with the ResNet18 backbone. The
model is rigorously trained and evaluated, exhibiting remarkable performance
metrics, including an impressive global accuracy of 99.286%, a high-class accuracy of 82.191%, a mean intersection over union (IoU) of 79.900%, a weighted
IoU of 98.620%, and a Boundary F1 (BF) score of 83.303%. Notably, a detailed comparative analysis with existing methods showcases the superiority of
our proposed model. These findings underscore the model’s competence in precise brain tumor localization, underscoring its potential to revolutionize medical
image analysis and enhance healthcare outcomes. This research paves the way
for future exploration and optimization of advanced CNN models in medical
imaging, emphasizing addressing false positives and resource efficiency.
The CBC machine is a common diagnostic tool used by doctors to measure a patient's red blood cell count, white blood cell count and platelet count. The machine uses a small sample of the patient's blood, which is then placed into special tubes and analyzed. The results of the analysis are then displayed on a screen for the doctor to review. The CBC machine is an important tool for diagnosing various conditions, such as anemia, infection and leukemia. It can also help to monitor a patient's response to treatment.
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsVictor Morales
K8sGPT is a tool that analyzes and diagnoses Kubernetes clusters. This presentation was used to share the requirements and dependencies to deploy K8sGPT in a local environment.
Batteries -Introduction – Types of Batteries – discharging and charging of battery - characteristics of battery –battery rating- various tests on battery- – Primary battery: silver button cell- Secondary battery :Ni-Cd battery-modern battery: lithium ion battery-maintenance of batteries-choices of batteries for electric vehicle applications.
Fuel Cells: Introduction- importance and classification of fuel cells - description, principle, components, applications of fuel cells: H2-O2 fuel cell, alkaline fuel cell, molten carbonate fuel cell and direct methanol fuel cells.
Introduction- e - waste – definition - sources of e-waste– hazardous substances in e-waste - effects of e-waste on environment and human health- need for e-waste management– e-waste handling rules - waste minimization techniques for managing e-waste – recycling of e-waste - disposal treatment methods of e- waste – mechanism of extraction of precious metal from leaching solution-global Scenario of E-waste – E-waste in India- case studies.
2. Abstract
This lecture provides a brief overview of what
distinguishes embedded systems programming
from “ordinary programming.” It then touches
upon facilities that become prominent or
problems when working “close to the
hardware” such as free store use, bit
manipulation, and coding standards.
Remember: not all computers are little grey
boxes hiding under desks in offices.
2
Stroustrup/Programming
4. Embedded systems
Hard real time
Response must occur before the deadline
Soft real time
Response should occur before the deadline most of the time
Often there are plenty of resources to handle the common cases
But crises happen and must be handled
Predictability is key
Correctness is even more important than usual
“correctness” is not an abstract concept
“but I assumed that the hardware worked correctly” is no excuse
Over a long time and over a large range of conditions, it simply doesn’t
4
Stroustrup/Programming
5. Embedded systems
Computers used as part of a larger system
That usually doesn’t look like a computer
That usually controls physical devices
Often reliability is critical
“Critical” as in “if the system fails someone might die”
Often resources (memory, processor capacity) are limited
Often real-time response is essential
5
Stroustrup/Programming
6. Embedded systems
What are we talking about?
Assembly line quality monitors
Bar code readers
Bread machines
Cameras
Car assembly robots
Cell phones
Centrifuge controllers
CD players
Disk drive controllers
“Smart card” processors
6
Fuel injector controls
Medical equipment monitors
PDAs
Printer controllers
Sound systems
Rice cookers
Telephone switches
Water pump controllers
Welding machines
Windmills
Wrist watches
…
Stroustrup/Programming
7. Do You Need to Know This Stuff ?
Computer Engineers – You will build and oversee the building
of these systems
All “close to he hardware” code resembles this
The concern for correctness and predictability of embedded systems
code is simply a more critical form of what we want for all code
Electrical Engineers – You will build and oversee the building
of these systems.
You have to work with the computer guys
You have to be able to talk to them
You may have to teach them
You may have to take over for them
Computer scientists – you’ll know to do this or only work on
web applications (and the like)
7
Stroustrup/Programming
8. Predictability
C++ operations execute in constant, measurable time
E.g., you can simply measure the time for an add operation or a virtual
function call and that’ll be the cost of every such add operation and every
virtual function call (pipelining, caching, implicit concurrency makes this
somewhat trickier on some modern processors)
With the exception of:
Free store allocation (new)
Exception throw
So throw and new are typically banned in hard real-time
applications
Today, I wouldn’t fly in a plane that used those
In 5 years, we’ll have solved the problem for throw
Each individual throw is predictable
Not just in C++ programs
Similar operations in other languages are similarly avoided
8
Stroustrup/Programming
9. Ideals/aims
Given the constraints
Keep the highest level of abstraction
Don’t write glorified assembler code
Represent your ideas directly in code
As always, try to write the clearest, cleanest, most
maintainable code
Don’t optimize until you have to
People far too often optimize prematurely
John Bentley's rules for optimization
First law: Don’t do it
Second law (for experts only): Don’t do it yet
9
Stroustrup/Programming
10. Embedded systems programming
You (usually) have to be much more aware of the resources
consumed in embedded systems programming than you have
to in “ordinary” programs
Time
Space
Communication channels
Files
ROM (Read-Only Memory)
Flash memory
…
You must take the time to learn about the way your language
features are implemented for a particular platform
Hardware
Operating system
Libraries
10
Stroustrup/Programming
11. Embedded systems programming
A lot of this kind of programming is
Looking at specialized features of an RTOS (Real Time
Operating System)
Using a “Non-hosted environment” (that’s one way of
saying “a language right on top of hardware without an
operating system”)
Involving (sometimes complex) device driver architectures
Dealing directly with hardware device interfaces
…
We won’t go into details here
That’s what specific courses and manuals are for
11
Stroustrup/Programming
12. How to live without new
What’s the problem
C++ code refers directly to memory
Once allocated, an object cannot be moved (or can it?)
Allocation delays
The effort needed to find a new free chunk of memory of a
given size depends on what has already been allocated
Fragmentation
If you have a “hole” (free space) of size N and you allocate an
object of size M where M<N in it, you now have a fragment of
size N-M to deal with
After a while, such fragments constitute much of the memory
12
Free space
New object
old object
old object
Stroustrup/Programming
13. How to live without new
Solution: pre-allocate
Global objects
Allocated at startup time
Sets aside a fixed amount of memory
Stacks
Grow and shrink only at the top
No fragmentation
Constant time operations
Pools of fixed sized objects
We can allocate and deallocate
No fragmentation
Constant time operations
13
Pool:
Stack:
Top of stack
Stroustrup/Programming
14. How to live without new
No new (of course)
And no malloc() (memory allocation during runtime) either (for those
of you who speak C)
No standard library containers (they use free store indirectly)
Instead
Define (or borrow) fixed-sized Pools
Define (or borrow) fixed-sized Stacks
Do not regress to using arrays and lots of pointers
14
Stroustrup/Programming
15. Pool example
// Note: element type known at compile time
// allocation times are completely predictable (and short)
// the user has to pre-calculate the maximum number of elements needed
template<class T, int N>class Pool {
public:
Pool(); // make pool of N Ts – construct pools only during startup
T* get(); // get a T from the pool; return 0 if no free Ts
void free(T*); // return a T given out by get() to the pool
private:
// keep track of T[N] array (e.g., a list of free objects)
};
Pool<Small_buffer,10> sb_pool;
Pool<Status_indicator,200> indicator_pool;
15
Stroustrup/Programming
16. Stack example
// Note: allocation times completely predictable (and short)
// the user has to pre-calculate the maximum number of elements needed
template<int N>class Stack {
public:
Stack(); // make an N byte stack – construct stacks only during startup
void* get(int N); // allocate n bytes from the stack; return 0 if no free space
void free(void* p); // return the last block returned by get() to the stack
private:
// keep track of an array of N bytes (e.g. a top of stack pointer)
};
Stack<50*1024> my_free_store; // 50K worth of storage to be used as a stack
void* pv1 = my_free_store.get(1024);
int* pi = static_cast<int*>(pv1); // you have to convert memory to objects
void* pv2 = my_free_store.get(50);
Pump_driver* pdriver = static_cast<Pump_driver*>(pv2);
16
Stroustrup/Programming
17. Templates
Excellent for embedded systems work
No runtime overhead for inline operations
Sometimes performance matters
No memory used for unused operations
In embedded systems memory is often critical (limited)
17
Stroustrup/Programming
18. How to live with failing hardware
Failing how?
In general, we cannot know
In practice, we can assume that some kinds of errors are more common than
others
But sometimes a memory bit just decides to change
Why?
Power surges/failure
The connector vibrated out of its socket
Falling debris
Falling computer
X-rays
…
Transient errors are the worst
E.g., only when the temperature exceeds 100° F. and the cabinet door is closed
Errors that occur away from the lab are the worst
E.g., on Mars
18
Stroustrup/Programming
19. How to live with failing hardware
Replicate
In emergency, use a spare
Self-check
Know when the program (or hardware) is misbehaving
Have a quick way out of misbehaving code
Make systems modular
Have some other module, computer, part of the system
responsible for serious errors
In the end, maybe a person i.e., manual override
Remember HAL ?
Monitor (sub)systems
In case they can’t/don’t notice problems themselves
19
Stroustrup/Programming
20. Absolute addresses
Physical resources (e.g., control registers for external devices)
and their most basic software controls typically exist at
specific addresses in a low-level system
We have to enter such addresses into our programs and give a
type to such data
For example
Device_driver* p = reinterpret_cast<Device_driver*>(0xffb8);
Serial_port_base *COM1 =
reinterpret_cast<Serial_port_base*>(0x3f8);
20
Stroustrup/Programming
21. Bit manipulation: Unsigned integers
How do you represent a set of bits in C++?
unsigned char uc; // 8 bits
unsigned short us; // typically 16 bits
unsigned int ui; // typically 16 bits or 32 bits
// (check before using)
// many embedded systems have 16-bit ints
unsigned long int ul; // typically 32 bits or 64 bits
std::vector<bool> vb(93); // 93 bits
Use only if you really need more than 32 bits
std::bitset bs(314); // 314 bits
Use only if you really need more than 32 bits
Typically efficient for multiples of sizeof(int)
21
Stroustrup/Programming
23. Bit manipulation
Bitwise operations
& (and)
| (or)
^ (exclusive or – xor)
<< (left shift)
>> (right shift)
~ (one's complement)
Basically, what the hardware provides right:
For example
void f(unsigned short val) // assume 16-bit, 2-byte short integer
{
unsigned char right = val & 0xff ; // rightmost (least significant) byte
unsigned char left = (val>>8) & 0xff ; // leftmost (most significant) byte
bool negative = val & 0x8000 ; // sign bit (if 2’s complement)
// …
}
23
1 1 0
0 1
0 1 0 1 1
0 0
1
1
0
Sign bit
1 1 1 1
1
1
1
1
0xff:
8 bits == 1 byte
0
1 0 0
1
0
val
0 1 1
false
true
Stroustrup/Programming
24. Bit manipulation
Or |
Set a bit
And &
Is a bit set? Select (mask) some bits
For example:
enum Flags { bit4=1<<4, bit3=1<<3, bit2=1<<2, bit1=1<<1, bit0=1 };
unsigned char x = bit3 | bit1; // x becomes 8+2
x |= bit2; // x becomes 8+4+2
if (x&bit3) { // is bit3 set? (yes, it is)
// …
}
unsigned char y = x &(bit4|bit2); // y becomes 4
Flags z = Flags(bit2|bit0); // the cast is necessary because the compiler
// doesn’t know that 5 is in the Flags range
24
1 1 1 1
1
1
1
1
0xff:
0 1 1
1
1
val 0 0 0
Stroustrup/Programming
25. Bit manipulation
Exclusive or (xor) ^
a^b means (a|b) & !(a&b) “either a or b but not both”
unsigned char a = 0xaa;
unsigned char b = 0x0f;
unsigned char c = a^b;
Immensely important in graphics and cryptography
25
0 1 0 0
1
0
1
1 0xaa
0 0 0 1
1
1
1
0 0x0f
0 1 0 1
0
1
0
1 0xa5
a:
a^b:
b:
Stroustrup/Programming
26. Unsigned integers
You can do ordinary arithmetic on unsigned integers
Avoid that when you can
Try never to use unsigned just to get another bit of precision
If you need one extra bit, soon, you’ll need another
Don’t mix signed and unsigned in an expression
You can’t completely avoid unsigned arithmetic
Indexing into standard library containers uses unsigned
(in my opinion, that’s a design error)
vector<int> v;
// …
for (int i = 0; i<v.size(); ++i) …
for (vector<int>::size_type i = 0; i<v.size(); ++i) …
for (vector<int>::iterator p = v.begin(); p!=v.end(); ++p) …
26
unsigned
correct, but pedantic
Yet another way
Stroustrup/Programming
signed
27. Complexity
One source of errors is complicated problems
Inherent complexity
Another source of errors is poorly-written code
Incidental complexity
Reasons for unnecessarily complicated code
Overly clever programmers
Who use features they don’t understand
Undereducated programmers
Who don’t use the most appropriate features
Large variations in programming style
27
Stroustrup/Programming
28. Coding standards
A coding standard is a set of rules for what code should
look like
Typically specifying naming and indentation rules
E.g., use “Stroustrup” layout
Typically specifying a subset of a language
E.g., don’t use new or throw to avoid predictability problems
Typically specifying rules for commenting
Every function must have a comment explaining what it does
Often requiring the use of certain libraries
E.g., use <iostream> rather than <stdio.h> to avoid safety problems
Organizations often try to manage complexity through
coding standards
Often they fail and create more complexity than they manage
28
Stroustrup/Programming
29. Coding standards
A good coding standard is better than no standard
I wouldn’t start a major (multi-person, multi-year) industrial project
without one
A poor coding standard can be worse than no standard
C++ coding standards that restrict programming to something like the C
subset do harm
They are not uncommon
All coding standards are disliked by programmers
Even the good ones
All programmers want to write their code exactly their own way
A good coding standard is prescriptive as well as restrictive
“Here is a good way of doing things” as well as
“Never do this”
A good coding standard gives rationales for its rules
And examples
29
Stroustrup/Programming
31. Some sample rules
No function shall have more than 200 lines (30 would be even better)
that is, 200 non-comment source lines
Each new statement starts on a new line
E.g., int a = 7; x = a+7; f(x,9); // violation!
No macros shall be used except for source control
using #ifdef and #ifndef
Identifiers should be given descriptive names
May contain common abbreviations and acronyms
When used conventionally, x, y, i, j, etc., are descriptive
Use the number_of_elements style rather than the numberOfElements style
Type names and constants start with a capital letter
E.g., Device_driver and Buffer_pool
Identifiers shall not differ only by case
E.g., Head and head // violation!
31
Stroustrup/Programming
32. Some more sample rules
Identifiers in an inner scope should not be identical to identifiers
in an outer scope
E.g., int var = 9; { int var = 7; ++var; } // violation: var hides var
Declarations shall be declared in the smallest possible scope
Variables shall be initialized
E.g., int var; // violation: var is not initialized
Casts should be used only when essential
Code should not depend on precedence rules below the level of
arithmetic expressions
E.g., x = a*b+c; // ok
if( a<b || c<=d) // violation: parenthesize (a<b) and (c<=d)
Increment and decrement operations shall not be used as
subexpressions
E.g., int x = v[++i]; // violation (that increment might be overlooked)
32
Stroustrup/Programming
33. An example of bit manipulation
The Tiny Encryption Algorithm (TEA)
Originally by David Wheeler
http://143.53.36.235:8080/tea.htm
Don’t look too hard at the code (unless you happen to need a
good simple encryption algorithm for an application); it’s
simply to give you the flavor of some bit manipulation code
It takes one word (4 bytes at a time)
E.g., 4 characters from a string or an image file
It assumes 4-byte long integers
Explanation is at the link (and in the book)
Without the explanation this is just an example of how bit manipulation
code can look. This code is not meant to be self-explanatory.
33
Stroustrup/Programming
34. TEA
void encipher(
const unsigned long *const v,
unsigned long *const w,
const unsigned long * const k)
{
unsigned long y = v[0];
unsigned long z = v[1];
unsigned long sum = 0;
unsigned long delta = 0x9E3779B9;
unsigned long n = 32;
while(n-->0) {
y += (z << 4 ^ z >> 5) + z ^ sum + k[sum&3];
sum += delta;
z += (y << 4 ^ y >> 5) + y ^ sum + k[sum>>11 & 3];
}
w[0]=y;
w[1]=z;
} 34
Stroustrup/Programming
35. TEA
void decipher(
const unsigned long *const v,
unsigned long *const w,
const unsigned long * const k)
{
unsigned long y = v[0];
unsigned long z = v[1];
unsigned long sum = 0xC6EF3720;
unsigned long delta = 0x9E3779B9;
unsigned long n = 32;
// sum = delta<<5; in general, sum = delta * n
while(n-->0) {
z -= (y << 4 ^ y >> 5) + y ^ sum + k[sum>>11 & 3];
sum -= delta;
y -= (z << 4 ^ z >> 5) + z ^ sum + k[sum&3];
}
w[0]=y;
w[1]=z;
} 35
Stroustrup/Programming