Programming Embedded Systems in C++

Slides:



Advertisements
Similar presentations
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Advertisements

Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
TEMPLATES Lecture Presented By SHERY KHAN Object Orienting Programming.
Chapter 13 Embedded Systems Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Chapter 13 Embedded Systems
Introduction to Data Structures, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Object Oriented Programming Concepts.
Lecture 9 Concepts of Programming Languages
C++ fundamentals.
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Programming Languages and Paradigms Object-Oriented Programming.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Embedded Operating System Leo Philip 10/5/ Do we need an OS ?
C++ Programming Basic Learning Prepared By The Smartpath Information systems
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
CS170 ygao JAVA, C4Slide 1. CS170 ygao JAVA, C4Slide 2.
Copyright © 2002 W. A. Tucker1 Chapter 10 Lecture Notes Bill Tucker Austin Community College COSC 1315.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
1 2 2 Call The Project Dynamic-Memory 4 4 # include "Utilities.hpp" int main(int argc, char * argv[]) { short int *PtrNo; (*PtrNo) = 5; printf ("(*PtrNo)
Learners Support Publications Constructors and Destructors.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
LPC2148's RTOS Bruce Chhuon 4/10/07. What is a Real Time Operating System? ● A Real Time Operating System (RTOS) manages hardware and software resources.
Constructors and Destructors
Eine By: Avinash Reddy 09/29/2016.
Creating and Using Objects, Exceptions, Strings
REAL-TIME OPERATING SYSTEMS
Classes (Part 1) Lecture 3
Names and Attributes Names are a key programming language feature
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Encapsulation, Data Hiding and Static Data Members
Andy Wang Object Oriented Programming in C++ COP 3330
Object-Oriented Programming & Design Lecture 18 Martin van Bommel
Inheritance & Polymorphism
Review: Two Programming Paradigms
C++ Classes & Object Oriented Programming
Constructor & Destructor
Programming Embedded Systems in C++
Inheritance Often, software encapsulates multiple concepts for which some attributes/behaviors overlap E.g. A computer (role-playing) game has: Monsters:
Lecture 9 Concepts of Programming Languages
Object Based Programming
Inheritance Basics Programming with Inheritance
The Procedure Abstraction Part I: Basics
Memory Allocation CS 217.
Programming Embedded Systems in C++
Pointers C#, pointers can only be declared to hold the memory addresses of value types int i = 5; int *p; p = &i; *p = 10; // changes the value of i to.
Startup and Initialization
More Object-Oriented Programming
Constructors and Destructors
Computer Programming with JAVA
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
American History Unit: 1950s to Present Topic: Review
CISC/CMPE320 - Prof. McLeod
Introduction to Classes and Objects
Programming Embedded Systems in C++
CS703 - Advanced Operating Systems
NAME 436.
C++ Constructor Insanity CSE 333 Winter 2019
Lecture 10 Concepts of Programming Languages
Final Exam Review Inheritance Template Functions and Classes
Constructors and Deconstructor
Embedded System Development Lecture 10 3/21/2007
More C++ Classes Systems Programming.
(4 – 2) Introduction to Classes in C++
C++ Object Oriented 1.
Lecture 9 Concepts of Programming Languages
Introduction to Classes and Objects
Presentation transcript:

Programming Embedded Systems in C++ Day 3: C++ & a Real-Time Operating System   21 May 2014 Colin Walls, Mentor Graphics

[ # ] This is what a question slide will look like. Please answer in the chat. Also, questions to me start with ?

Agenda Monday: C++ for Embedded Programming Tuesday: C to C++ Migration Strategy Wednesday: C++ and a Real Time Operating System Thursday: Case study #1 Friday: Case Study #2

[ 1 ] Are you using an RTOS? If so, which one?

Today’s Topics Hiding the RTOS API Thread local data Paired operations Using classes to encapsulate the API Thread local data Paired operations Dynamic memory management

Today’s Topics Hiding the RTOS API Thread local data Paired operations Using classes to encapsulate the API Thread local data Paired operations Dynamic memory management

C++ and an RTOS Benefits: Wide range of possibilities application programmers do not need detailed knowledge of RTOS code portability Wide range of possibilities

Task/Object Creation Encapsulate API using classes Task example: have base class for generic task constructor/destructor – task creation empty virtual main() application task defined by deriving class instantiate to create tasks note separation of definition from creation

Task/Object Creation class task { unsigned taskID; public: virtual void main(); task() taskID = task_create(main); } ~task() task_delete(taskID); ... };

Task/Object Creation Same approach to other RTOS objects: Semaphores Mailboxes Queues Event flags Memory pools Timers ...

Today’s Topics Hiding the RTOS API Thread local data Paired operations Using classes to encapsulate the API Thread local data Paired operations Dynamic memory management

Thread Local Data C++, like C, has no concept of thread Using a class adds this facility Benefit is ability to have variables (class members) which are local to a thread new scope concept Can share by declaring static Maybe complex variables – e.g. RTOS objects Same idea could be applied to other objects

Thread Local Data class mytask : task { unsigned taskID; public: int tld[100]; static int state; void main(); ... }; mytask alpha, beta; alpha.tld and beta.tld are distinct [thread local] alpha.state and beta.state are the same variable

Today’s Topics Hiding the RTOS API Thread local data Paired operations Using classes to encapsulate the API Thread local data Paired operations Dynamic memory management

[ 2 ] Is dynamic memory an issue/problem for a real time system?

Paired Operations Common requirement for a pair of complementary operations e.g. disable/enable interrupts Problem can be ensuring that both are executed Object oriented “trick” solves the problem Constructor performs first, destructor performs second

Paired Operations <normal code> { object declaration (constructor disables interrupts) <critical code> (destructor re-enables interrupts) }

Paired Operations class Device_Locked { private: static Semaphore device; // NB static public: Device_Locked() { device.acquire(); }; ~ Device_Locked() { device.release(); }; };

Today’s Topics Hiding the RTOS API Thread local data Paired operations Using classes to encapsulate the API Thread local data Paired operations Dynamic memory management

Dynamic Memory Management Dynamic behavior is troublesome in real time embedded systems Issues: non-determinism key to real time is predictability resource exhaustion also fragmentation

Memory Fragmentation #define K (1024) ... char *p1, *p2; Heap [10K] Heap [10K] #define K (1024) ... char *p1, *p2; p1 = malloc(3*K); p2 = malloc(4*K); free(p1); p1 = malloc(4*K); //fails! [3K free] p2 4K [3K free]

Dynamic Memory Define series of partition pools Geometric series of sizes e.g. 16, 32, 64, 128, 256 bytes Write malloc() to select best fit can be deterministic

Dynamic Memory malloc(16); 16 byte pool malloc(9); 32 byte pool

Dynamic Memory In C++ new maps onto malloc() new is also used when an object is created Can create a pool for each class with blocks of exactly the right size Overload new to use this pool Or create a base class that does the work and derive all new classes from that

Agenda Monday: C++ for Embedded Programming Tuesday: C to C++ Migration Strategy Wednesday: C++ and a Real Time Operating System Thursday: Case study #1 Friday: Case Study #2

[ 3 ] What aspect of embedded systems programming is most challenging?

Question review ...

[ Review - 2 ] Is dynamic memory an issue/problem for a real time system?

Colin Walls colin_walls@mentor.com http://blogs.mentor.com/colinwalls