Home | | Embedded Systems | Concepts and Embedded Programming in C, C++

Chapter:

Concepts and Embedded Programming in C, C++

A class can be declared as public or private. The data and methods access is restricted when a class is declared private. Struct doesnot have these features.

CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++

 

Multitasking

 

Function main with a waiting loop

 

main ( ) passes the control to an RTOS

Each task controlled by RTOS and

 

Each task will also have the codes in an infinite loop

A waiting task is passed a signal by the RTOS to start.

main ( ) calling RTOS

# define false 0

 

# define true 1

/********************************************************************/

 

void main (void) {

/* Call RTOS run here */

 

Infinite loop in main ( )

while (1) {rtos.run ( );

/* Infinite while loops follows in each task.So never there is return from the RTOS. */

}

}

 

/********************************************************************/

 

Task 1

 

void task1 (....) { /* Declarations */

.

while (true) {

/* Codes that repeatedly execute */

.

 

/* Codes that execute on an event */

if (flag1) {....;}; flag1 =0;

 

/* Codes that execute for message to the kernel */

message1 ( );

 

} }

/*********************************************/

 

Task2 ( )

 

void task2 (....) { /* Declarations */

.

while (true) {

/* Codes that repeatedly execute */

.

 

/* Codes that execute on an event */

if (flag2) {....;}; flag2 =0;

 

/* Codes that execute for message to the kernel */

message2 ( );

 

} }

/*********************************************/

 

TaskN_1 ( )

 

void taskN_1 (....) { /* Declarations */

 

.

while (true) {

/* Codes that repeatedly execute */

.

 

/* Codes that execute on an event */

if (flagN_1) {....;}; flagN_1 =0;

 

/* Codes that execute for message to the kernel */

messageN_1 ( );

} }

/*********************************************/

 

TaskN

 

voidtaskN (....) { /* Declarations */

.

while (true) {

/* Codes that repeatedly execute */

.

 

/* Codes that execute on an event */

if (flagN) {....;}; flagN =0;

 

/* Codes that execute for message to the kernel */

messageN ( );

 

} }

/*********************************************/

 

2. Polling for events and messages

 

_ A Programming method is to facilitate execution of one of the multiple possible function calls and the function executes after polling

 

_ Polling example is polling for a screen state (or Window menu) j and for a message m from an

 

 

 

Mobile phone

 

_ Assume that screen state j is between 0 and K,among 0, 1, 2, ..or K – 1 possible states.(set of menus).

 

_ An interrupt is triggered from a touch screen GUIand an ISR posts an event-message m = 0, 1, 2,

 

…,or N – 1 as per the selected the menu choice 0, 1,2, …, N – 1 when there are N menu- choices for a mobile phone user to select from a screen in statej.

 

Polling for a menu selection from screen state

voidpoll_menuK {

/* Code for polling for choice from menu m for screen state K*/

}

 

}

/*********************************/

 

Object Oriented Language and C++

 

 

Object-oriented language features

 

_ defining of the object or set of objects, which are common to similar objects within a program and between the many programs,

 

_ defining the methods that manipulate the objects without modifying their definitions, and _ Creation of multiple instances of the defined object or set of objects or new objects

 

Object-oriented language

_ Inheritance

 

_ overloading of functions _ overriding of functions

_ Data encapsulation, and

_ Design of reusable components

 

Object Characteristics

1. An identity (a reference to a memory block that holds its state and behavior).

2. A state (its data, property, fields and attributes).

3. A behavior(method or methods that can manipulate the state of the object).

 

Procedure oriented language

 

Procedure oriented language  A large program in ‗C‘ splits into the simpler functional blocks and statements. ‗C‘ is called procedure oriented language.

 

Object Oriented Language Characteristics

 

   A large program in objected oriented language C++ or Java, splits into the logical groups (also known as classes).

 

Each class defines the data and functions (methods) of using data.

Each class can inherit another class element.

A set of these groups (classes) then gives an application program of the Embedded System

 

  Each group has internal user-level fields for data and has methods of processing that data at these fields

 

Each group can then create many objects by copying the group and making it functional.

Each object is functional. Each object can interact with other objects to process the user's data.

 

   The language provides for formation of classes by the definition of a group of objects having similar attributes and common behavior. A class creates the objects. An object is an instance of a class.

 

Embedded Programming in C++

 

      C++ is an object oriented Program(OOP) language, which in addition, supports the procedure oriented codes of C.

 

  Program coding in C++ codes provides the advantage of objected oriented programming as well asthe advantage of C and in-line assembly.

 

C++

 

_ struct that binds all the member functions together in C. But a C++ class has object features. It can be extended and child classes can be derived from it. A number of child classes can be derived from a common class. This feature is called polymorphism.

 

A class can be declared as public or private. The data and methods access is restricted when a class is declared private. Struct doesnot have these features.

 

_ A class binds all the member functions together for creating objects. The objects will have memory allocation as well as default assignments to its variables that are not declared static.

 

_ A class can derive (inherit) from another class also. Creating a child class from RTCSWT as a parent class creates a new application of the RTCSWT.

 

_ Methods (C functions) can have same name in the inherited class. This is called method overloading

 

_ Methods can have the same name as well as the same number and type of arguments in the inherited class. This is called method overriding. These are the two significant features that are extremely useful in a large program.

 

_ Operators in C++ can be overloaded like in method overloading.

_ For example, operators ++ and! Are overloaded to perform a set of operations.

Some disadvantages

 

• Lengthier Code when using Template, Multiple Inheritance (Deriving a class from many parents), Exceptional handling, Virtual base classes and classes for IO Streams.

 

Ways to overcome the disadvantages

1) Declare private as many classes as possible. It helps in optimising the generated codes.

 

2)   Use char, int and boolean(scalar data types) in place of the objects (reference data types) as arguments and use local variables as much as feasible.

 

3) Recover memory already used once by changing the reference to an object to NULL.

 

4)   A special compiler for an embedded system can facilitate the disabling of specific features provided in C++.Embedded C++ is a version of C++ that provides for a selective disabling of the above features

 

5) Use Embedded C++: It provides for less runtime overhead and less runtime library. The solutions for the library functions are available and ported in C directly.

 

6) The IO stream library functions in an embedded C++ compiler are also reentrant.

 

7)  Using embedded C++ compilers or the special compilers make the C++ more powerful coding language than C for embedded systems due to the OOP features of software re-usability, extendibility, polymorphism, function overriding and overloading along portability of C codes and in-line assembly codes.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
: Concepts and Embedded Programming in C, C++ |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.