SlideShare a Scribd company logo
EMBEDDED C and C++ PROGRAMMING T S PRADEEPKUMAR, SCS
OVERVIEW Embedded C Programming (introduction) Preprocessor Directives Scope of Variables and Parameter passing Embedded C++ Embedded Software Development
Embedded C Embedded C is a subset of the C programming language which is intended for embedded systems programming. It excludes size and/or speed consuming C features that are not relevant for embedded systems.
Embedded C….. It is midlevel with high level features. It is very efficient Good, well proven compilers are available for every embedded processors.(8 bit to 32 bit or more)
Preprocessor Directives #define #pragma To describe specific resources of your target hardware Example: #pragma portrw PORTA @ 0x0000 #pragma portrw PORTB @ 0x0001; #pragma portw DDRB @ 0x0005;
Preprocessor Directives #ifdef checks for the existence of macro definitions.  Example: #ifdef EXTENDED #define MAX_LEN 74 #else #define MAX_LEN 50 #endif
Scope of Variables Local or Auto Global variables Volatile variables Register variables Static variables
Local and Global Auto or local variables Variables declared inside the function Stored in temporary memory location like Stack Extern variables The declaration is used to describe the variable that is externally defined.
Local Variables A temporary information used by only one software module or function Local variables usually stored in the Stack. To access local variables, the compiler use the stack pointer addressing mode.
Local Variables int a=100; void main() { int b=20; Printf(“%d”,b); }
Volatile  Volatile variables volatile keyword informs the compiler that it can not depend upon the value of a variable and should not perform any optimizations based on assigned values.
Volatile Example unsigned char data[100]; #define PORTA *(unsigned char volatile *)(0x0000) #define DDRA *(unsigned char volatile *)(0x0004) void main(void) {  short i; DDRA=0x00; /* make Port A an input */ for(i=0;i<100;i++){ /* collect 100 measurements */ data[i]=PORTA;  /* collect ith measurement */ }}
register Register variables To give a hint to the compiler that the variable should be allocated to a CPU register if possible. Some compilers allow global register variable declaration is helpful in case when there are more number of interrupt handlers
Static Variables Static variables Static local or static global, both are stored in the RAM File static and function static varibles are treated as global variables by most of the compilers
Parameter Passing Input parameter Data passed from the calling routine into the module during execution Output parameter Information returned from the module to the calling routine.
Parameter passing…. Pass by value Only passes the copies of the objects. Pass by reference  References to the actual arguments are passed instead of the copies of the actual arguments.
Example Void main() { Unsigned short angle=0; Stepper_init(); While(true){ Stepper_step(); Next(&angle); } } Void next (unsigned short *pt) { (*pt)++; If((*pt)==200) (*pt)=0; }
Embedded C++ It is a subset of full draft C++ standard These are omitted in EC++ Multiple inheritance and virtual base classes Runtime type identification (RTTI) Exception handling, Templates, namespaces
Optimizing C and C++ Code Minimize local variables  Declare local variables in the inner most scope  Reduce the number of parameters  Don't define a return value if not used  Prefer int over char. Prefer initialization over assignment  In-line 1 to 3 line functions
Some C Optimisations  Non Optimised code Optimised code Unsigned short int a; a /=8;  Unsigned short int a; a>>=3; a*=2; a+=a; for(i=0; i<10; i++) { b = k * c; p[i] = b; } b = k * c; /* constant code moved  outside the loop */ for(i=0; i<10; i++) { p[i] = b; }
Super Loop Architecture void main(void) { // Prepare run function X X_Init(); while(1) // ‘for ever’ (Super Loop) { X(); // Run function X() } }
ECU  Task: control injection time (3 sub-tasks) T S P compute air flow compute injection time drive actuators air flow injection time air temperature engine temperature engine speed throttle position look-up table PWM signals air pressure
Control Injection Time void main(void) { Control_ECU_Init(); while(1) // 'for ever' (Super Loop) { Control_ECU_Get_throttle_position(); Control_ECU_Get_Actual_speed(); Control_ECU_Get_Actual_temperature(); Control_ECU_Get_Actual_pressure(); Control_ECU_Control_airflow(); } }
Embedded Software Development
Embedded C Guidelines Comments Overall purpose of the software The names of the programmers Update dates Hardware/software configuration required to use the module Copyright information (if available)
Embedded C guidelines Included .h files Extern variables Preprocessor directives Struct, union, enum statements Global variables and constants Function prototypes Implementation of functions
Questions?
Ad

More Related Content

What's hot (20)

Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
Wondeson Emeye
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
Keroles karam khalil
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generator
vinithapanneer
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
Eelco Visser
 
C programming session10
C programming  session10C programming  session10
C programming session10
Keroles karam khalil
 
C programming part2
C programming part2C programming part2
C programming part2
Keroles karam khalil
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
rawan_z
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
Iffat Anjum
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
Education Front
 
Code Generation
Code GenerationCode Generation
Code Generation
PrabuPappuR
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programming
Makerere university
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
Brief introduction to the c programming language
Brief introduction to the c programming languageBrief introduction to the c programming language
Brief introduction to the c programming language
Kumar Gaurav
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
Stalongiles Philip
 
C language
C languageC language
C language
spatidar0
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
BBDITM LUCKNOW
 
Lec 01 basic concepts
Lec 01 basic conceptsLec 01 basic concepts
Lec 01 basic concepts
Abdul Khan
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
MalikaJoya
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
Darshan sai Reddy
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
Wondeson Emeye
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generator
vinithapanneer
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
Eelco Visser
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
rawan_z
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
Iffat Anjum
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
Education Front
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programming
Makerere university
 
Brief introduction to the c programming language
Brief introduction to the c programming languageBrief introduction to the c programming language
Brief introduction to the c programming language
Kumar Gaurav
 
Lec 01 basic concepts
Lec 01 basic conceptsLec 01 basic concepts
Lec 01 basic concepts
Abdul Khan
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
MalikaJoya
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
Darshan sai Reddy
 

Viewers also liked (19)

Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
Mohamed Abdallah
 
Embedded C
Embedded CEmbedded C
Embedded C
Krunal Siddhapathak
 
Embedded C workshop
Embedded C workshopEmbedded C workshop
Embedded C workshop
Mostafa El-koumy
 
C Programming For Embedded Systems
C Programming For Embedded SystemsC Programming For Embedded Systems
C Programming For Embedded Systems
Ganesh Samarthyam
 
Embedded c
Embedded cEmbedded c
Embedded c
Ami Prakash
 
Embedded C
Embedded CEmbedded C
Embedded C
Emertxe Information Technologies Pvt Ltd
 
2 Days FDP Programme on ARM LPC214x
2 Days FDP Programme on ARM LPC214x2 Days FDP Programme on ARM LPC214x
2 Days FDP Programme on ARM LPC214x
Pantech Tirunelveli
 
ECU Poster
ECU PosterECU Poster
ECU Poster
Navneet Roy
 
Ecu final
Ecu finalEcu final
Ecu final
karthikeyanswa
 
Roger Lanctot, Strategy Analytics, Managing the Accelerating Amount of Softwa...
Roger Lanctot, Strategy Analytics, Managing the Accelerating Amount of Softwa...Roger Lanctot, Strategy Analytics, Managing the Accelerating Amount of Softwa...
Roger Lanctot, Strategy Analytics, Managing the Accelerating Amount of Softwa...
Red Bend Software
 
Embedded system - embedded system programming
Embedded system - embedded system programmingEmbedded system - embedded system programming
Embedded system - embedded system programming
Vibrant Technologies & Computers
 
States & Capitals 111
States & Capitals 111States & Capitals 111
States & Capitals 111
Bermanburgh
 
C++ for Embedded Programming
C++ for Embedded ProgrammingC++ for Embedded Programming
C++ for Embedded Programming
Colin Walls
 
M b slides diagnostics 3-schmidgall_v7, 2010
M b slides diagnostics 3-schmidgall_v7, 2010M b slides diagnostics 3-schmidgall_v7, 2010
M b slides diagnostics 3-schmidgall_v7, 2010
goodgolier
 
Controller area network (can bus)
Controller area network (can bus)Controller area network (can bus)
Controller area network (can bus)
nassim unused
 
Parm
ParmParm
Parm
parmsidhu
 
Bitwise operators
Bitwise operatorsBitwise operators
Bitwise operators
Puneet Rajput
 
Array and string
Array and stringArray and string
Array and string
prashant chelani
 
C prog ppt
C prog pptC prog ppt
C prog ppt
xinoe
 
Ad

Similar to Embedded c programming22 for fdp (20)

Quiz 9
Quiz 9Quiz 9
Quiz 9
Keroles karam khalil
 
Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1
Ikhwan_Fakrudin
 
Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )
Ikhwan_Fakrudin
 
Embedded_C_1711824726engéiiiring_with_the_best.pdf
Embedded_C_1711824726engéiiiring_with_the_best.pdfEmbedded_C_1711824726engéiiiring_with_the_best.pdf
Embedded_C_1711824726engéiiiring_with_the_best.pdf
AliAbdelli
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
PRADEEP
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
Felipe Prado
 
Target updated track f
Target updated   track fTarget updated   track f
Target updated track f
Alona Gradman
 
Chip Ex2010 Gert Goossens
Chip Ex2010 Gert GoossensChip Ex2010 Gert Goossens
Chip Ex2010 Gert Goossens
Alona Gradman
 
Lecture Presentation 9.pdf fpga soc using c
Lecture Presentation 9.pdf fpga soc using cLecture Presentation 9.pdf fpga soc using c
Lecture Presentation 9.pdf fpga soc using c
minamelad457
 
cppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjj
cppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjjcppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjj
cppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjj
supriyaharlapur1
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
Keroles karam khalil
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
Hattori Sidek
 
ERTS UNIT 3.ppt
ERTS UNIT 3.pptERTS UNIT 3.ppt
ERTS UNIT 3.ppt
Pavithra525349
 
Advanced+pointers
Advanced+pointersAdvanced+pointers
Advanced+pointers
Rubal Bansal
 
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptxKMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
JessylyneSophia
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
Keroles karam khalil
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 
C++
C++C++
C++
VishalMishra313
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
somu rajesh
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015
Rodrigo Almeida
 
Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1
Ikhwan_Fakrudin
 
Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )
Ikhwan_Fakrudin
 
Embedded_C_1711824726engéiiiring_with_the_best.pdf
Embedded_C_1711824726engéiiiring_with_the_best.pdfEmbedded_C_1711824726engéiiiring_with_the_best.pdf
Embedded_C_1711824726engéiiiring_with_the_best.pdf
AliAbdelli
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
PRADEEP
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
Felipe Prado
 
Target updated track f
Target updated   track fTarget updated   track f
Target updated track f
Alona Gradman
 
Chip Ex2010 Gert Goossens
Chip Ex2010 Gert GoossensChip Ex2010 Gert Goossens
Chip Ex2010 Gert Goossens
Alona Gradman
 
Lecture Presentation 9.pdf fpga soc using c
Lecture Presentation 9.pdf fpga soc using cLecture Presentation 9.pdf fpga soc using c
Lecture Presentation 9.pdf fpga soc using c
minamelad457
 
cppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjj
cppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjjcppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjj
cppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjj
supriyaharlapur1
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
Hattori Sidek
 
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptxKMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
JessylyneSophia
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
somu rajesh
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015
Rodrigo Almeida
 
Ad

More from Pradeep Kumar TS (20)

Digital Portfolio and Footprint
Digital Portfolio and FootprintDigital Portfolio and Footprint
Digital Portfolio and Footprint
Pradeep Kumar TS
 
Open book Examination
Open book ExaminationOpen book Examination
Open book Examination
Pradeep Kumar TS
 
Software Define Networking (SDN)
Software Define Networking (SDN)Software Define Networking (SDN)
Software Define Networking (SDN)
Pradeep Kumar TS
 
What next - Career Enhancement of Graduates
What next - Career Enhancement of GraduatesWhat next - Career Enhancement of Graduates
What next - Career Enhancement of Graduates
Pradeep Kumar TS
 
Protothreads
ProtothreadsProtothreads
Protothreads
Pradeep Kumar TS
 
6LoWPAN
6LoWPAN 6LoWPAN
6LoWPAN
Pradeep Kumar TS
 
Software Defined Networks
Software Defined NetworksSoftware Defined Networks
Software Defined Networks
Pradeep Kumar TS
 
Higher Order Thinking - Question paper setting
Higher Order Thinking - Question paper settingHigher Order Thinking - Question paper setting
Higher Order Thinking - Question paper setting
Pradeep Kumar TS
 
IoT Communication Protocols
IoT Communication ProtocolsIoT Communication Protocols
IoT Communication Protocols
Pradeep Kumar TS
 
IoT Applications
IoT ApplicationsIoT Applications
IoT Applications
Pradeep Kumar TS
 
RPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy NetworksRPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy Networks
Pradeep Kumar TS
 
Mannasim for NS2
Mannasim for NS2Mannasim for NS2
Mannasim for NS2
Pradeep Kumar TS
 
Recompiling network simulator 2
Recompiling network simulator 2Recompiling network simulator 2
Recompiling network simulator 2
Pradeep Kumar TS
 
OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2
Pradeep Kumar TS
 
Wired and Wireless Examples in ns2
Wired and Wireless Examples in ns2Wired and Wireless Examples in ns2
Wired and Wireless Examples in ns2
Pradeep Kumar TS
 
Installation of ns2
Installation of ns2Installation of ns2
Installation of ns2
Pradeep Kumar TS
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
Pradeep Kumar TS
 
Software Defined Networking - 1
Software Defined Networking - 1Software Defined Networking - 1
Software Defined Networking - 1
Pradeep Kumar TS
 
Software Defined Networking - 2
Software Defined Networking - 2Software Defined Networking - 2
Software Defined Networking - 2
Pradeep Kumar TS
 
Software Defined Networking - 3
Software Defined Networking - 3Software Defined Networking - 3
Software Defined Networking - 3
Pradeep Kumar TS
 
Digital Portfolio and Footprint
Digital Portfolio and FootprintDigital Portfolio and Footprint
Digital Portfolio and Footprint
Pradeep Kumar TS
 
Software Define Networking (SDN)
Software Define Networking (SDN)Software Define Networking (SDN)
Software Define Networking (SDN)
Pradeep Kumar TS
 
What next - Career Enhancement of Graduates
What next - Career Enhancement of GraduatesWhat next - Career Enhancement of Graduates
What next - Career Enhancement of Graduates
Pradeep Kumar TS
 
Higher Order Thinking - Question paper setting
Higher Order Thinking - Question paper settingHigher Order Thinking - Question paper setting
Higher Order Thinking - Question paper setting
Pradeep Kumar TS
 
IoT Communication Protocols
IoT Communication ProtocolsIoT Communication Protocols
IoT Communication Protocols
Pradeep Kumar TS
 
RPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy NetworksRPL - Routing Protocol for Low Power and Lossy Networks
RPL - Routing Protocol for Low Power and Lossy Networks
Pradeep Kumar TS
 
Recompiling network simulator 2
Recompiling network simulator 2Recompiling network simulator 2
Recompiling network simulator 2
Pradeep Kumar TS
 
OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2
Pradeep Kumar TS
 
Wired and Wireless Examples in ns2
Wired and Wireless Examples in ns2Wired and Wireless Examples in ns2
Wired and Wireless Examples in ns2
Pradeep Kumar TS
 
Software Defined Networking - 1
Software Defined Networking - 1Software Defined Networking - 1
Software Defined Networking - 1
Pradeep Kumar TS
 
Software Defined Networking - 2
Software Defined Networking - 2Software Defined Networking - 2
Software Defined Networking - 2
Pradeep Kumar TS
 
Software Defined Networking - 3
Software Defined Networking - 3Software Defined Networking - 3
Software Defined Networking - 3
Pradeep Kumar TS
 

Recently uploaded (20)

Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 

Embedded c programming22 for fdp

  • 1. EMBEDDED C and C++ PROGRAMMING T S PRADEEPKUMAR, SCS
  • 2. OVERVIEW Embedded C Programming (introduction) Preprocessor Directives Scope of Variables and Parameter passing Embedded C++ Embedded Software Development
  • 3. Embedded C Embedded C is a subset of the C programming language which is intended for embedded systems programming. It excludes size and/or speed consuming C features that are not relevant for embedded systems.
  • 4. Embedded C….. It is midlevel with high level features. It is very efficient Good, well proven compilers are available for every embedded processors.(8 bit to 32 bit or more)
  • 5. Preprocessor Directives #define #pragma To describe specific resources of your target hardware Example: #pragma portrw PORTA @ 0x0000 #pragma portrw PORTB @ 0x0001; #pragma portw DDRB @ 0x0005;
  • 6. Preprocessor Directives #ifdef checks for the existence of macro definitions. Example: #ifdef EXTENDED #define MAX_LEN 74 #else #define MAX_LEN 50 #endif
  • 7. Scope of Variables Local or Auto Global variables Volatile variables Register variables Static variables
  • 8. Local and Global Auto or local variables Variables declared inside the function Stored in temporary memory location like Stack Extern variables The declaration is used to describe the variable that is externally defined.
  • 9. Local Variables A temporary information used by only one software module or function Local variables usually stored in the Stack. To access local variables, the compiler use the stack pointer addressing mode.
  • 10. Local Variables int a=100; void main() { int b=20; Printf(“%d”,b); }
  • 11. Volatile Volatile variables volatile keyword informs the compiler that it can not depend upon the value of a variable and should not perform any optimizations based on assigned values.
  • 12. Volatile Example unsigned char data[100]; #define PORTA *(unsigned char volatile *)(0x0000) #define DDRA *(unsigned char volatile *)(0x0004) void main(void) { short i; DDRA=0x00; /* make Port A an input */ for(i=0;i<100;i++){ /* collect 100 measurements */ data[i]=PORTA;  /* collect ith measurement */ }}
  • 13. register Register variables To give a hint to the compiler that the variable should be allocated to a CPU register if possible. Some compilers allow global register variable declaration is helpful in case when there are more number of interrupt handlers
  • 14. Static Variables Static variables Static local or static global, both are stored in the RAM File static and function static varibles are treated as global variables by most of the compilers
  • 15. Parameter Passing Input parameter Data passed from the calling routine into the module during execution Output parameter Information returned from the module to the calling routine.
  • 16. Parameter passing…. Pass by value Only passes the copies of the objects. Pass by reference References to the actual arguments are passed instead of the copies of the actual arguments.
  • 17. Example Void main() { Unsigned short angle=0; Stepper_init(); While(true){ Stepper_step(); Next(&angle); } } Void next (unsigned short *pt) { (*pt)++; If((*pt)==200) (*pt)=0; }
  • 18. Embedded C++ It is a subset of full draft C++ standard These are omitted in EC++ Multiple inheritance and virtual base classes Runtime type identification (RTTI) Exception handling, Templates, namespaces
  • 19. Optimizing C and C++ Code Minimize local variables Declare local variables in the inner most scope Reduce the number of parameters Don't define a return value if not used Prefer int over char. Prefer initialization over assignment In-line 1 to 3 line functions
  • 20. Some C Optimisations Non Optimised code Optimised code Unsigned short int a; a /=8; Unsigned short int a; a>>=3; a*=2; a+=a; for(i=0; i<10; i++) { b = k * c; p[i] = b; } b = k * c; /* constant code moved outside the loop */ for(i=0; i<10; i++) { p[i] = b; }
  • 21. Super Loop Architecture void main(void) { // Prepare run function X X_Init(); while(1) // ‘for ever’ (Super Loop) { X(); // Run function X() } }
  • 22. ECU Task: control injection time (3 sub-tasks) T S P compute air flow compute injection time drive actuators air flow injection time air temperature engine temperature engine speed throttle position look-up table PWM signals air pressure
  • 23. Control Injection Time void main(void) { Control_ECU_Init(); while(1) // 'for ever' (Super Loop) { Control_ECU_Get_throttle_position(); Control_ECU_Get_Actual_speed(); Control_ECU_Get_Actual_temperature(); Control_ECU_Get_Actual_pressure(); Control_ECU_Control_airflow(); } }
  • 25. Embedded C Guidelines Comments Overall purpose of the software The names of the programmers Update dates Hardware/software configuration required to use the module Copyright information (if available)
  • 26. Embedded C guidelines Included .h files Extern variables Preprocessor directives Struct, union, enum statements Global variables and constants Function prototypes Implementation of functions