Fundamentals of Compiler and Integrated Development Environment for Embedded Software Design

Max Mauro Dias Santos [email protected] Ponta Grossa, Paraná - Brazil January 23, 2021 What and where are the compiler and IDE?

January 23, 2021 2 January 23, 2021 3 Outline

1. Introduction 2. 3. Memory 4. Embedded Programmig Languages 5. Compiler 6. GCC – GNU Compiler Collection 7. Integrated Development Environment 8. Embedded Systems Software Development Tools 9. Integrated Development Environment Tools 10.IDE - CodeBlocks

Obs.: This material has been done based on several materials available and I reference the original owners throughout and in the end of this presentation.

January 23, 2021 4 What will you learn in the end of this Lesson?

1. about the features hardware: Central Processing Unit and Memory 2. The workflow for embedded programming languages 3. How works the compiler which is able to translate from source to machine code 4. Undertand about the compiler GCC – GNU Compiler Collection 5. Undestand, identify and how to use the IDE 6. Know the most used IDE tools 7. Build programs using CodeBlock. It’s not yet for embedded over a hardware 8. We have to know identify a compiler for IBM-PC and Microcontroller. Is it a tough task? 9. Understand to build a simple application and test it’s quality.

January 23, 2021 5 Introduction

We have as a goal, learn how to setup and use tools for develop an embedded software. We have to understand what are the difference between source and machine codes. Moreover, what is the CISC and RISC architecture and Anyway, let’s try to introduce the fundamentals memory. of Compiler, na example of GCC and well know IDE or Integrated Development Environment. Is there a guideline to develop embedded software for embedded systems? We will show some of them. I hope to show you some compilers and IDEs available which will help you to work on properly toward become a beginner developer of embedded system. I have a dream. My goal is teach you a little bit more about software tools to develop embedded software based on ARM architecture. ARM has a bunch of resources and support RTOS. Finally, in the end of this lesson you will be able to select and use the most suitable toolchain for build embedded systems – hardware & software

January 23, 2021 6 Computer Architecture

The computer architecture is the 's view of a computer. It is defined by the instruction set (language) and operand locations (registers and memory). There are many different architectures, such as ARM, x86, MIPS, SPARC, and PowerPC.

Question-1: What is the difference between architecture and organization? Question-2: Have you ever heard about RISC-V?

January 23, 2021 7 Central Processing Unit

Motivation On the right is a diagram representing the storage scheme for a generic computer. The main memory is divided into locations numbered from (row) 1: (column) 1 to (row) 6: (column) 4. The execution unit is responsible for carrying out all computations. However, the execution unit can only operate on data that has been loaded into one of the six registers (A, B, C, D, E, or F). Let's say we want to find the product of two numbers - one stored in location 2:3 and another stored in location 5:2 - and then store the product back in the location 2:3.

The CISC Approach The RISC Approach

MULT 2:3, 5:2 LOAD A, 2:3 LOAD B, 5:2 PROD A, B STORE 2:3, A

https://cs.stanford.edu/people/eroberts/courses/soco/projects/risc/risccisc/ January 23, 2021 8 Central Processing Unit

CISC x RISC Almost all modern CPU has different sorts of architecture. It utilizes the capacity to work from “Instruction Set Architecture”. There are two types of this architectural design. First one is RISC (Reduced instruction set computing). The second one is CISC (Complex instruction set computing). However, both differ in various ways. RISC is a design of Central Processing Unit that has the basis of instruction set. It gives good performance along with a system. In short, it has the ability to execute the commands with the help of some microprocessor cycles per command.

https://microcontrollerslab.com/difference-between-risc-and-cisc/ January 23, 2021 9 Central Processing Unit

RISC Architecture There are a lot of characteristics related to the RISC architecture, some of them are as follows: 1. Simple set of instructions which are easy to decode and implement. 2. The size of one instruction comes under the size of a single word. 3. Only one clock cycle is required to execute a single instruction, so it is a fast process. 4. The quantity of general purpose register is greater. 5. The addressing modes are quite simple. 6. The variable data types are very less. 7. Its main idea is to achieve pipelining.

https://microcontrollerslab.com/difference-between-risc-and-cisc/ January 23, 2021 10 Central Processing Unit

CISC Architecture There are a lot of characteristics related to the CISC architecture, some of them are as follows: 1. The instruction set is complex. Hence, it’s decoding. 2. Instructions are normally large due to their complexity. Instructions are normally bigger than one word size. 3. Usually, the compound instructions take greater time than a single clock cycle in their execution. 4. The number of general purpose registers are less. Because this, it performs most operations in the memory itself. 5. The addressing modes are normally complex. 6. The data types are numerous.

https://microcontrollerslab.com/difference-between-risc-and-cisc/ January 23, 2021 11 Central Processing Unit

RISC x CISC This equation is normally used to check the performance of any computer:

This formula clearly tells that the performance of a RISC based architecture is way better than the one operating using CISC architecture. CISC and RISC are two entirely different types of computer architectures. Some of their differences are as follows:

https://microcontrollerslab.com/difference-between-risc-and-cisc/ January 23, 2021 12 Central Processing Unit

RISC x CISC

CISC RISC ADD Ma,Mb LOAD Ra, Ma LOAD Rb, Mb ADD Ra, Rb STORE Ma, Ra Ra, Rb : Register, Ma, Mb : Memory Block

http://www.sharetechnote.com/html/EmbeddedSystem_CISC_RISC.html January 23, 2021 13 Central Processing Unit

RISC x CISC

https://medium.com/swlh/what-does-risc-and-cisc-mean-in-2020-7b4d42c9a9de January 23, 2021 14 Central Processing Unit

RISC x CISC

https://www.geekfail.net/2013/06/arquitetura-cisc-vs-risc.html January 23, 2021 15 Central Processing Unit

The importance of Mnemonic, Operation, Byte and Time

https://www.youtube.com/watch?app=desktop&v=xOCjCA3kNgc January 23, 2021 16 Central Processing Unit

High Tech Technology Artificial Neural Network to run over Neural Processing Unit

Artificial Neural Network Neural Processing Unit

https://www.researchgate.net/figure/The-hardware-architecture-of-the-neural-processing-engine-The-left-part-is-the-neural_fig4_336514386 January 23, 2021 17 Central Processing Unit

High Tech Technology

https://blogs.gartner.com/paul-debeasi/2019/02/14/training-versus-inference/ January 23, 2021 18 Central Processing Unit

FSD Chip - Tesla Full Self-Driving Chip (FSD Chip, previously Autopilot Hardware 3.0) is an autonomous driving chip designed by Tesla and introduced in early 2019 for their own cars. Tesla claims the chip is aimed at autonomous levels 4 and 5. Fabricated on Samsung's 14 nm process technology, the FSD Chip incorporates 3 quad-core Cortex-A72 clusters for a total of 12 CPUs operating at 2.2 GHz, a Mali G71 MP12 GPU operating 1 GHz, 2 neural processing units operating at 2 GHz, and various other hardware accelerators. The FSD supports up to 128-bit LPDDR4-4266 memory.

https://en.wikichip.org/wiki/tesla_(car_company)/fsd_chip January 23, 2021 19 Central Processing Unit

FSD Chip - Tesla The 14 nm process refers to the MOSFET technology node that is the successor to the 22 nm (or 20 nm) node. 14 nm process Timeline MOSFET scaling (process nodes) . 10 µm – 1971 . 6 µm – 1974 . 3 µm – 1977 . 1.5 µm – 1981 Semiconductor . 1 µm – 1984 NVIDIA is secretly device . 800 nm – 1987 . 600 nm – 1990 working on a 5 nm chip fabrication . 350 nm – 1993 . 250 nm – 1996 . 180 nm – 1999 . 130 nm – 2001 . 90 nm – 2003 . 65 nm – 2005 . 45 nm – 2007 . 32 nm – 2009 . 22 nm – 2012 . 14 nm – 2014 . 10 nm – 2016 Kirin 9010 3 nm will be . 7 nm – 2018 Huawei's next flagship . 5 nm – 2020 . Future processor . 3 nm – ~2022 . 2 nm – >2023 https://en.wikichip.org/wiki/tesla_(car_company)/fsd_chip January 23, 2021 20 Central Processing Unit

FSD Chip - Tesla Jim Keller, Tesla’s former head of Autopilot hardware and the designer of Tesla’s Self-Driving Computer chip, says that he is confident about solving autonomous driving after working at Tesla.

Bio - James B. Keller (born 1958/1959) is a microprocessor engineer best known for his work at AMD and Apple. He was the lead architect of the AMD K8 (including the original 64) and was involved in designing the Athlon (K7) and /A5 processors. He was also the coauthor of the specifications for the x86-64 instruction set and HyperTransport interconnect. From 2012 to 2015, he returned to AMD to work on the AMD K12 and .

https://electrek.co/2020/02/07/tesla-self-driving-computer-designer-jim-keller-confident-solving-autonomous-driving/ January 23, 2021 21 Central Processing Unit

FSD Chip - Tesla

Component GPU NPU Amount 1 2 Model S, Model 3, and Model X 600 GFLOPS 36.86 TOPS Peak Performance (FP32, FP64) (Int8) Total Peak Performance 600 GFLOPS 73.73 TOPS

https://en.wikichip.org/wiki/tesla_(car_company)/fsd_chip January 23, 2021 22 Central Processing Unit

FSD Chip - Tesla

Where is the LIDAR?

https://www.quora.com/Why-did-Tesla-develop-their-own-chip-for-self-driving January 23, 2021 23 Central Processing Unit

RISC – Reduced Instruction Set Computing . Large instructions take longer to execute. . Solution: split into multiple, simpler instructions. . Excessive use of registers.

https://www.slideserve.com/clint/p-rocessadores-risc-sparc-powerpc-arm-mips January 23, 2021 24 Central Processing Unit

RISC – MIPS, ARM, SPARC and PowerPC An instruction set architecture (ISA) is an abstract model of a computer, also referred to as computer architecture. A realization of an ISA is called an implementation. An ISA permits multiple implementations that may vary in performance, physical size, and monetary cost (among other things); because the ISA serves as the interface between software and hardware

https://en.wikipedia.org/wiki/Comparison_of_instruction_set_architectures January 23, 2021 25 Central Processing Unit

RISC – MIPS . MIPS (Microprocessor without Interlocked Pipelined Stages) . First versions: 32 bits. . Current versions: 64 bits. . 5 mips implementation versions: MIPS I, MIPS II, MIPS III, MIPS IV, MIPS 32/64. . Features . Used for educational purposes: processor with clean design. . MIPS MT - multithreading features similar to . . MDMX - larger instruction set with 64 bits. . MIPS 3D - instructions dedicated to 3D processing. . Applications . Windows CE devices. • Cisco routers. . Video games like Nintendo 64 and PlayStation. . Used in supercomputers, mainly in Silicon Graphics.

https://www.slideserve.com/clint/p-rocessadores-risc-sparc-powerpc-arm-mips January 23, 2021 26 Central Processing Unit

RISC – ARM . ARM (Advanced RISC Machine) . Low energy consumption. . Dominant in the telecommunications market, mobile electronics. . 75% of embedded CPUs. . Features . Built-in conditionals. . Special register to store the return address of the procedure. . Interruption system with 2 priority levels. . It can operate in Thumb mode (16 bits). . Jazelle - extension that makes ARM capable of interpreting bytecode. . Applications . Composes several embedded systems. . It is used in several famous laptops: iPod, iPhone, Palm, Nokia.

https://www.slideserve.com/clint/p-rocessadores-risc-sparc-powerpc-arm-mips January 23, 2021 27 Central Processing Unit

RISC – SPARC . SPARC (Scalable Processor Architecture) . Developed by Sun in 1985. . Initially developed to be used in Sun-4 workstations. . Features . Scalable. . 32 and 64 bit versions. . Big-Endian. . They implement the register window method. . It supports several operating systems such as , Solaris, SunOS. . Register window . Applications . Used on Sun workstations and servers. . Used on SMP servers from several companies.

https://www.slideserve.com/clint/p-rocessadores-risc-sparc-powerpc-arm-mips January 23, 2021 28 Central Processing Unit

RISC – PowerPC . PowerPC . Created in the early 90s by the Apple, IBM, Motorola alliance. . High-performance embedded processor. . 1994-2006 processor from Apple's Macintosh line. . Features . Overclimb. . It works both big-endian and little-endian. . 64-bit processor, but that supports 32 bits. . Supports memory paging. . Supports multiple operating systems: Linux, MacOS, Windows NT. . Applications . Used as a high performance embedded processor. . Used in cars, as a CPU for automotive applications. . Used by consoles: GameClube, Wii, XBox 360, PlayStation 3.

https://www.slideserve.com/clint/p-rocessadores-risc-sparc-powerpc-arm-mips January 23, 2021 29 Memory

RTOS and Memory Footprint . Complex embedded systems usually work through operating systems. The problem is that the is an overhead. Since the embedded system has limited memory at its disposal, the embedded engineer has to carefully evaluate how much memory the real time operating system uses. . There are two kinds of memory in an embedded system- ROM memory or flash memory and RAM memory or read/write memory. The code and the constant data is stored in the ROM while the RAM is utilized for variables. However, flash memory is slow so usually the ROM code/data is copied to the RAM during boot up. This improves the embedded system’s performance drastically. . To determine the memory footprint of the RTOS system, you have to see what services the RTOS is using. RTOS services are scalable and this scalability changes from one embedded product to another. Depending on the type of embedded systems, a few of these services won’t be needed. In others, the entire service group is included/excluded.

http://gwentechembedded.com/rtos-and-memory-footprint/ January 23, 2021 30 Memory

Memory Layout of Embedded C Programs The memory layout of C programs consists of several segments. The segments accessible to a user program are shown in the figure below:

. Code Segment (.text) . Initialized Data Segment (.data) . Uninitialized Data Segment (.bss) . Heap . Stack . Footnotes

The C program memory layout

https://open4tech.com/memory-layout-embedded-c-programs/ January 23, 2021 31 Memory

Memory Footprint Memory footprint refers to the amount of main memory that a program uses or references while running. An application's footprint is the amount of memory (RAM) it requires. Writing programs that fit into these smaller amounts of memory is often quite challenging.

Memory Footprint for embedded systems Traditionally, low-memory-footprint programs were of importance to running applications on embedded platforms where memory would often be a constrained resource – so much so that developers typically sacrificed efficiency (processing speeds) just to make program footprints small enough to fit into the available RAM.

https://en.wikipedia.org/wiki/Memory_footprint January 23, 2021 32 Memory

Heap Memory A typical memory representation of a C language program consists of following segments: . Code (Text) segment – contains the program code (machine instructions) . Data segment – contains the static data (global/static variables) . Stack segment (see our article on the topic The Concept of Stack and Its Usage in ) . Heap segment.

Try to identify why MISRA-C standard doesn’t recommend the use of dynamic memory allocation • malloc() and calloc( ) – reserve space • realloc() – move a reserved block of memory to another allocation of different dimensions • free() – release allocated space

https://open4tech.com/concept-heap-usage-embedded-systems/ January 23, 2021 33 Memory

The Stack and Its Usage In general we can describe the stack as a temporary storage for data. The access to data in the stack is organized as Last In First Out (LIFO), which means that the last data stored in the stack is the first than can be retrieved and the first data stored in the stack is the last to be retrieved. The operation of adding data to the stack is called PUSH and the operation of retrieving data is called POP(PULL).

Push Operation Pop Operation

https://open4tech.com/the-concept-of-stack-and-its-usage-in-microprocessors/ January 23, 2021 34 Memory

The Stack and Its Usage Hardware Implementation of Stack The common hardware implementation of stack consists of reserved contiguous region of memory with a stack pointer into that memory. The stack has a fixed location in memory at which it begins. The stack pointer is a hardware register that points to the current extents of the stack. There are stacks that grow downwards and ones that grow upwards. The stack can technically be located anywhere in memory, depending on the system.

Stack Grow Direction

https://open4tech.com/the-concept-of-stack-and-its-usage-in-microprocessors/ January 23, 2021 35 Embedded Programmig Languages

Programming microcontrollers The microcontroller executes the program loaded in its Flash memory. This is the so called executable code comprised of seemingly meaningless sequence of zeros and ones. It is organized in 12-, 14- or 16-bit wide words, depending on the microcontroller’s architecture. Every word is considered by the CPU as a command being executed during the operation of the microcontroller.

All instructions that the microcontroller can recognize are together called the Instruction set. As for PIC microcontrollers the programming words of which are comprised of 14 bits, the instruction set has 35 different instructions in total.

https://www.mikroe.com/ebooks/pic-microcontrollers-programming-in-c/programming-languages January 23, 2021 36 Embedded Programmig Languages

Programming microcontrollers However, have always needed a close to the language being used in everyday life. As a result, the higher programming languages have been created. One of them is C. The main advantage of these languages is simplicity of program writing. It is no longer possible to know exactly how each command executes, but it is no longer of interest anyway. In case it is, a sequence written in assembly language can always be inserted in the program, thus enabling it.

Similar to assembly language, a specialized program in a PC called compiler is in charge of compiling program into machine language. Unlike assembly compilers, these create an executable code which is not always the shortest possible.

https://www.mikroe.com/ebooks/pic-microcontrollers-programming-in-c/programming-languages January 23, 2021 37 Embedded Programmig Languages

Programming microcontrollers Figures give a rough illustration of what is going on during the process of compiling the program from higher to lower programming language.

https://www.mikroe.com/ebooks/pic-microcontrollers-programming-in-c/programming-languages January 23, 2021 38 Embedded Programmig Languages

Programming microcontrollers Here is an example of a simple program written in C language:

https://www.mikroe.com/ebooks/pic-microcontrollers-programming-in-c/programming-languages January 23, 2021 39 Embedded Programmig Languages

Differences Between BIN, DAT and HEX Files Here are some brief details about these files : .BIN x .DAT x .HEX

.BIN File : The BIN file type is primarily associated with 'Binary File'. Binary files are used for a wide variety of content and can be associated with a great many different programs. In general, a .BIN file will look like garbage when viewed in a file editor.

.DAT File : The DAT file type is primarily associated with 'Data'. Can be just about anything: text, graphic, or general binary data. Data file in special format or ASCII.

.HEX File : The HEX file type is the format used to store machine language code in hexadecimal form. It is commonly used for programming microcontrollers, EPROMs, and other types of programmable logic devices.

So in a nutshell, .BIN file is binary file which contains binary data, .DAT file is Data File which can contain any type of data including binary data and .HEX file is the files which stores the data in hexadecimal form.

https://www.quora.com/What-is-the-difference-between-bin-file-dat-file-and-hex-file January 23, 2021 40 Embedded Programmig Languages

A simple example of C Programming

The structure of a simple program Actions to be done 1. Activate and set built-in A/D converter; 2. Measure analogue value; 3. Calculate temperature; and 4. Send data in the proper form to LCD display.

https://www.mikroe.com/ebooks/pic-microcontrollers-programming-in-c/programming-languages January 23, 2021 41 Embedded Programmig Languages

C language has certain features that is not accept for automotive embedded system . MISRA-C is a set of recommendations that for instance: . It doesn’t accept the memory dynamic allocation because can generate overflow of memory: malloc(), calloc( ), realloc() and free() . Programmer should define own variables to allow the portability: If you declare a certain variable with int 8, it isn’t possible migrate for a hardware with 16 bits . The simple function “if” is allowed without parentheses and for MISRA-C is mandatory to avoid errors . The static and dynamic tests should be considered: . Static test is made using a specific tool to verify whether all semantics, syntaxes and lexical where attended . Dynamic test is made with the code running and being instrumented . Software for safety critical system as in automotive, should have a certain level of maturity. This might be assessed through the following certifications: SPICE and CMMI.

These informations are from discussions with Mr. Jonatan Xavier at Vector Informatik January 23, 2021 42 Compiler

What is a compiler?

BiPOM ELECTRONICS - Embedded IAR Systems NetBurner - Embedded Networking Rowebots Embedded Training and Development Development Tools

Custom Computer Services Inc - PIC Keil Software, an ARM Phyton Microsystems and Tasking (division of Altium Ltd) - Compilers Company - Compilers Development Tools Compilers

Green Hills Software Mentor Graphics - GNU C Raisonance - Compilers Ultimate Solutions - Embedded Compilers Java Development

https://microcontroller.com/Embedded_Compilers/ January 23, 2021 43 Compiler

What is a compiler? A compiler is a software that takes a program written in a high level language and translates it into an equivalent program in a target language. Most specifically a compiler takes a computer program and translates it into an object program. Some other tools associated with the compiler are responsible for making an object program into executable form.

Source Target Compiler Program Program

In computing, a compiler is a computer program that translates computer code written in one programming language (the source Error language) into another language (the target language). The Messages name "compiler" is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language, object code, or machine code) to create an executable program.

https://en.wikipedia.org/wiki/Compiler G. De Micheli and . Gupta, “Hardware/Software Co-Design,” Proceedings of the IEEE, 85(3), March 1997, pp. 349-365 January 23, 2021 44 Compiler

Major function of a Compiler Source program – It is normally a program written in a high-level programming language. It contains a set of rules, symbols and special words used to construct a computer program. Target program – It is normally the equivalent program in machine code. It contains the binary representation of the instructions that the hardware of computer can perform. Error Message – A message issued by the compiler due to detection of syntax errors in the source program.

What do you understand for this flowchart? Would you mind to describe me?

January 23, 2021 45 Compiler

Major function of a Compiler Assembly Language – It is a middle-level programming language in which a mnemonics are used to represent each of the machine language instructions for a specific computer. Assembly language programs also allow the user to use text names for data rather than having to remember their memory addresses. An Assembler is a computer program that translates an assembly language Machine Language Assembly Language program into machine code. 100101 ADD

011001 SUB The machine and assembly language codes 001101 MPY 100111 CMP

100011 JMP

110011 JNZ

January 23, 2021 46 Compiler

Major function of a Compiler Most of the compilers are not a single tool. For example Turbo C/C++ compiler is a combination of five different but necessary tools, namely . Editor . . Compiler . Linker . Loader But in this course our scope is limited to debugging and compiling only.

January 23, 2021 47 Compiler

Life cycle of a computer program

General system development life cycle The workflow for life cycle of a computer OR program is...

Design  Built  Test  Fix

Will this practice should continue?

January 23, 2021 48 Compiler

Difference Between Source Code and Object Code Source code is generally understood to mean programming statements that are created by a programmer with a text editor or a visual programming tool and then saved in a file. Object code generally refers to the output, a compiled file, which is produced when the Source Code is compiled with a C compiler. The object code file contains a sequence of machine-readable instructions that is processed by the CPU in a computer. Operating system or application software is usually in the form of compiled object code.

January 23, 2021 49 Compiler

The processes for compile and link/loader a simple program We can see all the processes to be performed during running a C/C++ Program. There are various stage to be accomplished along the execution of a computer program. The artefacts are: Source Program, Object Code and Library Code according showed at the side figure.

https://www.researchgate.net/publication/332726973_Chapter_1_Introduction_to_Compiler January 23, 2021 50 Compiler

Level of Program Code

https://www.techspot.com/article/1821-how-cpus-are-designed-and-built/

January 23, 2021 51 Compiler

Compiler x Interpreter 1. Execution of a compiled program Source Program

Target Compiler Input Output Program

Target Program 2. Execution of an interpreted program

Source Program Interpreter Output Input

January 23, 2021 52 Compiler

Compiler Phases

January 23, 2021 53 Compiler

Compiler Phases

https://www.researchgate.net/publication/332726973_Chapter_1_Introduction_to_Compiler January 23, 2021 54 Compiler

Major function of a Compiler There are two major parts of a compiler phases: Analysis and Synthesis. In analysis phase, an intermediate representation is created from the given source program that contains: . Lexical Analyzer, . Syntax Analyzer and . Semantic Analyzer In synthesis phase, the equivalent target program is created from this intermediate representation. This contains: . Intermediate Code Generator, Source Target . Code Optimizer, and Program Analysis Synthesis Program . Code Generator The compiler has a number of phases plus symbol table manager and an error handler.

Error Messages

January 23, 2021 55 Compiler

1. Lexical Analyzer Lexical analyzer takes the source program as an input and produces a long string of tokens. Lexical Analyzer reads the source program character by character and returns the tokens of the source program. The process of generation and returning the tokens is called lexical analysis. A token describes a pattern of characters having same meaning in the source program (such as identifiers, operators, keywords, numbers, delimiters and so on). Consider a high level language assignment statement

newval := old_val + 12

The tokens identified by lexical analyzer are newval identifier The lexical analyser receives a stream of characters “if( x> 3.1 ) { := assignment operator ...” and produces a list of tokens that tells what the stream signifies. A first token tells that there was an if statement, the oldval identifier second token tells that there was an opening bracket, the third + add operator one tells that there was an identifier with the content x, and so on. 12 a number

January 23, 2021 56 Compiler

1. Lexical Analyzer

January 23, 2021 57 Compiler

2. Sintaxe Analyzer

A Syntax Analyzer creates the syntactic structure (generally The sentience “tim ate the big ball” is derived by the above a parse tree) of the given program. In other words, a grammar in following manner: Syntax Analyzer takes output of lexical analyzer (list of Sentence ::= Subject Verb Object tokens) and produces a parse tree. A syntax analyzer is also called as a parser. A parse tree describes a syntactic  Proper-noun Verb Object structure of the program. The syntax is defined as the  Proper-noun Verb Article Adjective Noun physical layout of the source program. The grammars  tim Verb Article Adjective Noun describe precisely the syntax of a language.  tim ate Article Adjective Noun Following is a set of productions of a free  tim ate the Adjective Noun grammar  tim ate the big Noun Sentence ::= Subject Verb Object  tim ate the big ball Subject ::= Proper-noun Object ::= Article Adjective Noun Verb ::= ate | saw | called Noun ::= cat | ball | dish Article ::= the | a Example sentence: tim ate the big ball Adjective ::= big | bad | pretty Proper-noun ::= tim | mary where, Start Symbol = Sentence

January 23, 2021 58 Compiler

2. Sintaxe Analyzer

Derivation tree for newval := old_val + 20 and tim ate the big ball

January 23, 2021 59 Compiler

2. Sintaxe Analyzer A parse tree is an entity which represents the structure of the derivation of a terminal string from some non- terminal (not necessarily the start symbol).

The parse tree is the entire structure, starting from S and ending in each of the leaf nodes (John, hit, the, ball). The following abbreviations are used in the tree: . S for sentence, the top-level structure in this example . NP for noun phrase. The first (leftmost) NP, a single noun "John", serves as the subject of the sentence. The second one is the object of the sentence. . VP for verb phrase, which serves as the predicate . V for verb. In this case, it's a transitive verb hit. . D for determiner, in this instance the definite article "the" . N for noun

https://en.wikipedia.org/wiki/Parse_tree

January 23, 2021 60 Compiler

3. Semantic Analyzer Semantic analyzer takes the output of syntax analyzer and produces another parse tree. Semantic analysis is very useful in writing compilers since they give a reference when trying to decide what the compiler should do in particular cases. A semantic analyzer checks the source program for semantic errors and collects the type information for the code generation. For example, The major components of semantic analysis are: newvalue := old_value + 20 . Creation of a symbol table The type of the identifier newvalue must match with type . Type checking of the expression old_val+20 . Type coercions The typical application of semantic analyzer the analyses pertaining to definitions and uses of variables though . Variable used without being declared . Variable declared multiple times . Variable declared but not used

January 23, 2021 61 Compiler

4. Intermediate Code Generator A compiler may produce an explicit intermediate codes representing the source program. Intermediate code generator takes a tree as an input produced by semantic analyzer and produces intermediate code (in assembly language). The level of intermediate codes is close to the level of machine codes. Translate from abstract-syntax trees to intermediate codes.

position := initial + rate * int-to-float ()

January 23, 2021 62 Compiler

5. Code Optimizer The code optimizer takes the code produced by the intermediate code generator. The code optimizer reduces the code (if the code is not already optimized) without changing the meaning of the code. The optimization of code is in terms of time and space. For example,

MULT id2, id3, temp1 ADD temp1, #1, id1

January 23, 2021 63 Compiler

6. Code Generator It produces the target language in a specific architecture. The target program is normally a object file containing the machine codes. Memory locations are selected for each of the variables used by the program. Then, intermediate instructions are each translated into a sequence of machine instructions that perform the same task. A crucial aspect is the assignment of variables to registers. For example, MOVE id2, R1 MULT id3, R1 ADD #1, R1 MOVE R1, id1 We are assuming that we have an architecture with instructions whose at least one of its operands is a machine register. http://www.brainkart.com/article/A-Simple-Code-Generator_8104/

January 23, 2021 64 Compiler

Why are performance metrics and optimization so important for embedded systems? First of all, an engineer need to compare thing and the simplest way to do this one among embedded system is measure the size of memory and stack and the execution time of them. Therefore, these have straight impact over performance and costs.

What do you understand for this one?

www.dspace.com

January 23, 2021 65 Compiler

A simple sample of modeling alternatives

What is the TargetLink? Try to find it...

Again, what do you understand for this one?

www.dspace.com January 23, 2021 66 Compiler

Cross List to Select a Compiler Target Processor - The first step in selecting a cross compiler is finding one that will produce code for your target processor.

Host Platform - The next step is to decide on a development platform. If there are several platforms available, you may want to check some of the other items in this list before making a decision about the host. RTOS Support - If you're planning to use an RTOS, does the compiler vendor have a working relationship with your RTOS vendor? This is important because part or all of the RTOS may be provided in object files or libraries. For compatibility, your compiler and linker must support that same object file format. Integration with Other Tools - Is the compiler compatible with any debugging environments? Is a make utility included? If the compiler is shipped with an IDE, is it extensible so that you can integrate your tool? Standard Libraries - Will you need functions from the standard C library, math library or C++ classes? If so, are they provided with the compiler? Are all of the functions in those libraries reentrant? Startup Code - Is startup code for embedded systems provided? Are the code and its use well documented? If you can't find any mention of startup code in the user's manuals for a potential cross compiler, consider that a bad sign. Execution Speed Optimizations - If your program is too slow, you'll want the compiler to try to speed it up. Will the compiler do this? If so, what specific optimizations are supported? Can they be individually enabled or disabled? Program Size Optimizations - If your program is too big for your target memory, you'll want the compiler to attempt to reduce the amount of code space used. Will the compiler do this? If so, what specific optimizations are supported? Support for Embedded C++ - The Embedded C++ (EC++) standard is a proper subset of the C++ language and libraries that reduces run-time overhead. In order to restrict yourself to EC++ functionality, you'll need a cross compiler that knows what features of the language it is not allowed to use. January 23, 2021 https://barrgroup.com/embedded-systems/how-to/c-cross-compilers 67 GCC – GNU Compiler Collection

The Operating System

January 23, 2021 68 GCC – GNU Compiler Collection

The GNU Compiler Collection (GCC) is an optimizing compiler produced by the GNU Project supporting various programming languages, hardware architectures and operating systems.

GCC is the GNU Compiler Collection that Basic steps in compilation provides the compilers for the following . Pre-Process directives like #include programming languages: . Compilation of the C Code to generate the . C assembly . C++ . Assembly Code to object file generation . Objective C . Link the object code to generate the . Fortran executable . ADA . Java The original GNU C Compiler (GCC) is developed by Richard Stallman, the founder of the GNU Project. Richard Stallman founded the GNU project in 1984 to create a complete Unix-like operating system as free software, to promote freedom and cooperation among computer users and programmers.

https://en.wikipedia.org/wiki/GNU_Compiler_Collection https://www.isical.ac.in/~pdslab/2015/

January 23, 2021 69 GCC – GNU Compiler Collection Step 1: Compiling a simple C Program From compiling to run the program Step 2: Compiling a simple C++ Program

Step 3: Providing the executable name

Step 4: Compiling a simple multi-file program

Step 5: Multi-step compilation and linking

Step 6: Including files from other directories

Step 7: Linking with external libraries

Step 8: Linking to a library at non-standard path

Step 9: Building Static libraries

Step 10: Building Dynamically linked libraries January 23, 2021 70 GCC – GNU Compiler Collection

Difference Between C and C++ As we know both C and C++ are programming languages and used for application development. The main difference between both these languages is C is a procedural programming language and does not support classes and objects, while C++ is a combination of both procedural and object-oriented programming languages. Sr. No. Key C C++ Introduction C was developed by Dennis Ritchie in C++ was developed by Bjarne Stroustrup in 1 around 1969 at AT&T Bell Labs. 1979.

Language Type As mentioned before C is procedural On the other hand, C++ supports both 2 programming. procedural and object-oriented programming paradigms. OOPs feature As C does not support the OOPs C++ has support for polymorphism, Support concept so it has no support for encapsulation, and inheritance as it is being 3 polymorphism, encapsulation, and an object-oriented programming language inheritance. Data Security As C does not support encapsulation On another hand in the case of C++ so data behave as a free entity and encapsulation hides the data to ensure that 4 can be manipulated by outside code. data structures and operators are used as intended. Driven type C in general known as function-driven On the other hand, C++ is known as object 5 language. driven language.

Feature C does not support function and On the other hand, C++ supports both supported operator overloading also do not have function and operator overloading also have 6 namespace feature and reference namespace feature and reference variable variable functionality. functionality.

January 23, 2021 71 GCC – GNU Compiler Collection

Difference Between C and C++

January 23, 2021 72 GCC – GNU Compiler Collection

Step 1: Compiling a simple C Program . Syntax: gcc

user@ws$ gcc HelloWorld.c

. Output: An executable called a.out . To run: ./a.out

user@ws$ ./a.out Hello World user@ws$

January 23, 2021 73 GCC – GNU Compiler Collection

Step 2: Compiling a simple C++ Program . Syntax: g++

user@ws$ g++ HelloWorld.cpp

. Output: An executable called a.out . To run: ./a.out

user@ws$ ./a.out Hello World user@ws$

January 23, 2021 74 GCC – GNU Compiler Collection

Step 3: Providing the executable name . Extra option: -o . Syntax: gcc -o

user@ws$ gcc HelloWorld.c -o myapp

. Output: An executable called outputname . To run: ./outputname

user@ws$ ./myapp Hello World user@ws$

January 23, 2021 75 GCC – GNU Compiler Collection

The Multi-File Programs Why create multi-file programs? . Manageability . Modularity . Re-usability . Abstraction

Components: . Header files . Implementation Source files . Application source file (contains the main function)

General abstraction used in Multi-file Programs

January 23, 2021 76 GCC – GNU Compiler Collection

Header Files In C programming, an enumeration type Contents: (also called enum) is a data type that . Pre-processor directives and macros consists of integral constants. . Constant declarations typedef is used to define new data type . Type declarations (enum, typedef, struct, union, etc) names to make a program more readable to the programmer. . Function prototype declarations Union is an user defined datatype in C . Global variable declarations programming language. . May also contain static function definitions In C programming, a struct (or structure) is a collection of variables (can be of different Example: HelloWorld.h types) under a single name.

#ifndef _HELLOWORLD_H_ #define _HELLOWORLD_H_ typedef unsigned int my_uint_t; extern void printHelloWorld(); extern int iMyGlobalVar; ... #endif

January 23, 2021 77 GCC – GNU Compiler Collection

Implementation Source Files Contents: . Function body for functions declared in corresponding header files . Statically defined and inlined functions . Global variable definitions

Example: HelloWorld.c

#include #include “HelloWorld.h” int iMyGlobalVar; Global variables are declared outside any function, and they can be accessed void printHelloWorld() (used) on any function in the { program. Local variables are declared iMyGlobalVar = 20; inside a function, and can be used only inside that function. printf(“Hello World\n”); return; }

January 23, 2021 78 GCC – GNU Compiler Collection

Application Source Files Contents: . Function body for the main function . Acts as client for the different modules

Example: app.c

#include #include “HelloWorld.h” int main() int main – 'int main' means that our function needs to return some integer at the end of the execution { and we do so by returning 0 at the end of iMyGlobalVar = 10; the program. 0 is the standard for the “successful printf(“%d\n”, iMyGlobalVar); execution of the program” printHelloWorld(); printf(“%d\n”, iMyGlobalVar); return 0; }

January 23, 2021 79 GCC – GNU Compiler Collection

The correlation between components for GCC compiler

January 23, 2021 80 GCC – GNU Compiler Collection

Step 4: Compiling a simple multi-file program . Syntax: gcc ... -o filename . Example:

user@ws$ gcc HelloWorld.c app.c -o my_app user@sw$ ./my_app 10 Hello World 20 user@ws$

January 23, 2021 81 GCC – GNU Compiler Collection

Step 5: Multi-step compilation and linking Steps: . Compile source files to object files . Link multiple object files into executables Compilation to object files . Special Option: -c . Syntax: gcc -c Link multiple files into the final executables . Syntax: gcc [-o output]

user@ws$ gcc -c HelloWorld.c . Example: user@ws$ gcc -c app.c user@ws$ gcc HelloWorld.o app.o -o my_app user@sw$ ./my_app 10 Hello World 20 user@ws$

January 23, 2021 82 GCC – GNU Compiler Collection

Step 6: Including files from other directories . Special Option: -I . Syntax: gcc -I -I . Example:

user@ws$ cd HelloWorld/src user@ws$ gcc -c -I../../HelloWorld/include HelloWorld.c user@ws$ cd ../../app/src user@ws$ gcc -c -I../../HelloWorld/include main.c user@ws$ cd ../../ user@ws$ gcc HelloWorld/src/HelloWorld.o app/src/main.o -o my_app user@ws$ ./my_app

January 23, 2021 83 GCC – GNU Compiler Collection

Object Libraries . Libraries contain pre-compiled object codes are of 2 types: . Statically Linked: Object codes are linked into and placed inside the executable during compilation. Name format: lib.a . Dynamically Linked: Object code is loaded dynamically into memory at runtime. Name format: lib.so

Statically Linked Libraries Dynamically Linked Libraries . Consists of a set of routines which are copied into . Contains position independent code for different a target application functions . An archive of object files . Executable code is loaded by the loader at runtime . Object code corresponding to the required functions . The symbol table in the library contains blank are copied directly into the executable addresses which are filled up later by the loader . Library format is dependent on linkers . Increases reuse . Increases executable size . Decreases program size and execution time

January 23, 2021 84 GCC – GNU Compiler Collection

Step 7: Linking with external libraries . Static linking: Link to libname.a . Special option: -static and -l . Syntax: gcc -static -lname

user@ws$ gcc -static math_test.c -lm

. Dynamic linking: Link to libname.so . Special option: -l . Syntax: gcc -lname

user@ws$ gcc math_test.c -lm

January 23, 2021 85 GCC – GNU Compiler Collection

Step 8: Linking to a library at non-standard path . Special option: -L . Syntax: gcc -l -L

user@ws$ gcc math_test.c -lm -L/usr/lib

January 23, 2021 86 GCC – GNU Compiler Collection

Step 9: Building Static libraries Required external tools: ar, ranlib 1. Create object files for the source codes 2. User ar to create the archives with names of the form: lib.a 3. Use ranlib to generate the index within the library

user@ws$ gcc -c HelloWorld.c user@ws$ ar rcs libHW.a HelloWorld.o user@ws$ ranlib libHW.a user@ws$ gcc app.c -lHW -L. -o my_app user@ws$ ./my_app 10 Hello World 20 user@ws$

January 23, 2021 87 GCC – GNU Compiler Collection

Step 10: Building Dynamically linked libraries Required external tools: ar, ranlib . Requirements: Object code needs to be position independent . Steps: 1.Compile sources in a Position Independent manner Option: -fPIC 2. Combine objects to create shared library: Option: -shared -W1, -soname,lib.so. user@ws$ gcc -c -fPIC HelloWorld.c user@ws$ gcc -shared -W1, -soname,libHW.so.1 -o libHW.so . LD_LIBRARY_PATH HelloWorld.o . Set to the directory containing the .so file user@ws$ gcc app.c -lHW -L. -o my_app user@ws$ export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH user@ws$ ./my_app Hello World 20 user@ws$ January 23, 2021 88 GCC – GNU Compiler Collection

Some more details about linking . If -static is specified, linking is always static . if lib.a is not found gcc errors out . Otherwise . If lib.so is found linking is dynamic . otherwise linking is static . In case of dynamic linking, lib.so should be placed in a standard location, otherwise LD_LIBRARY_PATH needs to be set

January 23, 2021 89 GCC – GNU Compiler Collection

Recommended organization of Multi-file Projects

January 23, 2021 90 GCC – GNU Compiler Collection

Example of Compiler Warnings . Special option: -Wall . Syntax : gcc -Wall ....

user@ws$ gcc warning.c user@ws$ gcc warning.c -Wall warning.c: In function ‘main’: warning.c:8: warning: suggest explicit braces to avoid ambiguous ‘else’ user@ws$

January 23, 2021 91 Integrated Development Environment

Software development steps In any environment, to develop executable software you need to create source file(s), compile the source files to produce machine code (object files), and link the object files with each other and any libraries or other resources required to produce an executable file. Source files contain the code statements to do the tasks your program is being created for. They contain program statements specific to the language you are using. If programming in c, the source files contain c code statements; java source files contain java statements. Usually source files names have extensions indicating the code they contain. A c source file may be named "myfile.c". Compilers translate the source files to appropriate machine level code for the target environment. Linkers take all the object files required for a program and link them together, assigning memory and registers to variables, setting up data. They also link in library files to support operating system tasks and any other files the program needs. Linkers output executable files.

https://relevant.software/blog/7-steps-for-effective-software-product-development/ January 23, 2021 92 Integrated Development Environment

Let’s list the main issues when you don’t use IDEs When not using an IDE, developers use an editor, compiler and linker installed on their development machine to create code files, compile and link them. Using the editor to create a source file, the code blocks, comments and program statements are entered and the file saved. There are no "corrective actions," taken as the editor doesn’t know this is supposed to be a "source file" as opposed to notes for class! If working in a position-dependent language like Python, the developer would have to be very careful about indenting. The file has to be saved with the correct file extension and in a directory where the compiler can find it. Each source file has to be compiled separately; if the program has a few source files, they all have to be named separately in the compiler. When invoking the compiler, it has to be directed to look in the correct directory for the source files and where the output files should be stored. If there is an error in the source file, the compiler will output messages and fail to complete. For any errors, the developer goes back and edits the source file, working from line numbers and compiler messages to fix the problems... and these steps continue until all the source files compile without errors. When linking, each object file is specified as being part of the build. Again, the locations for the object files and executable are given. There may be errors at this point because it isn’t until the entire program is linked that some errors can be detected. Assuming the linker finds all the variables and functions, it produces a file that can be run. If the program is run and it works, all's well! If it seems to do nothing.... that means it's debugging time! Since there is no insight to what the program is doing, the developer may go back and put in some brute force methods, like print statements to print messages out at certain points in the program or blink some LEDs at strategic places, which means back to the editor and the cycle continues. https://www.allaboutcircuits.com/technical-articles/what-are-integrated-development-environments/ January 23, 2021 93 Integrated Development Environment

Definition Integrated Development Environments (IDEs) are software applications that provide a programming environment to streamline developing and debugging software programs.

https://en.wikipedia.org/wiki/Integrated_development_environment January 23, 2021 94 Integrated Development Environment

The Top IDE Index The more an IDE is searched, the more popular the IDE is 11 Code::Blocks 2.28 % +0.4 % assumed to be. The raw data comes from Google Trends. 12 0.95 % +0.1 % 13 PhpStorm 0.71 % +0.0 % If you believe in collective wisdom, the Top IDE index can 14 Komodo 0.49 % +0.1 % help you decide which IDE to use for your software 15 0.48 % -0.2 % development project. 16 0.3 % +0.0 % Worldwide, Jan 2021 compared to a year ago: 17 0.29 % +0.0 % 18 Creator 0.29 % -0.0 % Rank 19 JDeveloper 0.14 % -0.1 % Change IDE Share Trend 20 MonoDevelop 0.09 % -0.0 % 1 Visual Studio 26.28 % +3.4 % 21 JCreator 0.08 % -0.1 % 2 16.1 % -1.4 % 22 0.06 % -0.0 % 3 10.75 % -8.6 % 23 0.05 % -0.0 % 4 9.3 % +3.4 % 24 RubyMine 0.05 % -0.0 % 5 pyCharm 7.98 % +2.4 % 25 DrJava 0.04 % -0.0 % 6 IntelliJ 5.91 % +0.8 % 26 SharpDevelop 0.04 % -0.0 % 7 NetBeans 5.51 % -0.2 % 27 Coda 2 0.03 % +0.0 % 8 4.31 % -0.2 % 28 Python 0.03 % -0.0 % 9 3.78 % +0.5 % 29 Monkey Studio 0.0 % -0.0 % 10 3.66 % -0.2 % © Pierre Carbonnelle, 2020

https://pypl.github.io/IDE.html January 23, 2021 95 Integrated Development Environment

Programming Languages Algorithms are designed to solve problems. Programming languages are used to implement algorithms. They create the programs (software) that communicate instructions to a computer. There are many different types of programming languages. But they all have the ability to: . input data from a device such as a keyboard . output data to a device such as a screen . process calculations like addition and subtraction . process decisions based on certain conditions being met . process repetition for a certain number of times or while a condition is met or until a condition is met

High-level languages include Java, JavaScript, C++, Ruby, BASIC or Python, while low-level languages include C, assembly language, and machine code.

https://www.bbc.co.uk/bitesize/guides/zgmpr82/revision/1 January 23, 2021 96 Integrated Development Environment

IDE An integrated development environment (IDE) is an application used to create software. An IDE can often support different languages. IDEs have a number of different tools and functions that assist a developer in the creation of software. Code editor The environment where the user can write code is called the shell. The code editor is a text edit area that allows developers to write, edit and save a document of code. It has features that assist with the writing and editing of code. These include: . Auto-completion (or code completion). This is designed to save time while writing code. As you start to type the first part of a function, it suggests or completes the function and any arguments or variables. . Bracket matching. This is used for languages that use pairs of to mark out blocks of code. It allows the code to be read and understood more quickly. If you forget to close a bracket while writing, coloured sections may help you to detect missing brackets. . Syntax checks. This recognizes incorrect use of syntax and highlights any errors. IDEs have a runtime environment. This means that you can execute the program one step at a time. This is useful to test that the code is working line by line before creating the final complete program.

https://www.bbc.co.uk/bitesize/guides/zgmpr82/revision/1 January 23, 2021 97 Embedded Systems Software Development Tools

Embedded Software Embedded Software is the software that controls an embedded system. All embedded systems need some software for their functioning. Embedded software or program is loaded in the microcontroller which then takes care of all the operations that are running. For developing this software, a number of different tools are needed which we will discuss further. These tools include editor, compiler, assembler and debugger. Let’s have a look on them.

1. Editor 2. Compiler 3. Assembler This is a recommendation provided on the 4. Debugger referenced link 5. Linker 6. Libraries 7. Simulator

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 98 Embedded Systems Software Development Tools

1. Editor . The first tool you need for Embedded Systems Software Development Tools is text editor. . This is where you write the code for your embedded system. . The code is written in some programming language. Most commonly used language is C or C++. . The code written in editor is also referred to source code.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 99 Embedded Systems Software Development Tools

2. Compiler . The second among Embedded Systems Software Development Tools is a compiler. . A compiler is used when you are done with the editing part and made a source code. . The function of compiler is to convert the source code in to object code. . Object code is understandable by computer as it in low level programming language. . So we can say that a compiler is used to convert a high level language code in to low level programming language.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 100 Embedded Systems Software Development Tools

3. Assembler . The third and an important one among Embedded Systems Software Development Tools is an assembler. . The function of an assembler is to convert a code written in assembly language into machine language. . All the mnemonics and data is converted in to op codes and bits by an assembler. . We all know that our computer understands binary and it works on 0 or 1, so it is important to convert the code into machine language. . That was the basic function of an assembler, now I am going to tell you about a debugger.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 101 Embedded Systems Software Development Tools

4. Debugger . As the name suggests, a debugger is a tool used to debug your code. . It is important to test whether the code you have written is free from errors or not. So, a debugger is used for this testing. . Debugger goes through the whole code and tests it for errors and bugs. . It tests your code for different types of errors for example a run time error or a syntax error and notifies you wherever it occurs. . The line number or location of error is shown by debugger so you can go ahead and rectify it. . So from the function, you can see how important tool a debugger is in the list of Embedded Systems Software Development Tools.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 102 Embedded Systems Software Development Tools

5. Linker . The next one in basic Embedded Systems Software Development Tools is a linker. . A linker is a computer program that combines one or more object code files and library files together in to executable program. . It is very common practice to write larger programs in to small parts and modules to make job easy and to use libraries in your program. . All these parts must be combined into a single file for execution, so this function requires a linker.

Linker is a computer system program that takes one or more object files (generated by a compiler or an assembler) and combines them into a single executable file, library file or another "object" file. A simpler version that writes its output directly to memory is called the loader, though loading is typically considered a separate process. https://en.wikipedia.org/wiki/Linker_(computing)

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 103 Embedded Systems Software Development Tools

5. Linker . The workflow showing all steps from source to executable program

https://www.sciencedirect.com/topics/engineering/linker-script January 23, 2021 104 Embedded Systems Software Development Tools

6. Libraries . A library is a pre written program that is ready to use and provides specific functionality. . For Embedded Systems Software Development Tools, libraries are very important and convenient. . Library is a file written in C or C++ and can be used by different programs and users. . For example, Arduino microcontroller comes with a number of different libraries that you can download and use while developing your software. . For instance, controlling LED or reading sensor like an encoder can be done with a library.

https://www.sciencedirect.com/topics/engineering/linker-script January 23, 2021 105 Embedded Systems Software Development Tools

7. Simulator . Among all embedded software tools, simulating software is also needed. . A simulator helps you to see how your code will work in real time. . You can see how sensors are interacting, you can change the input values from sensors, and you can see how the components are working and how changing certain values can change parameters. . These were the basic software tools required for embedded software development.

https://www.sciencedirect.com/topics/engineering/linker-script January 23, 2021 106 Integrated Development Environment Tools

IDE Tools An Integrated Development Environment is software that contains all the necessary tools required for embedded software development. An IDE normally consists of a code editor, compiler, debugger and also provides a user interface. An example of integrated development environment is Visual Studio that is used for developing computer programs and supports different programming languages. 1. MPLAB 2. Arduino Software 3. Keil 4. MATLAB This is a recommendation provided on the 5. LabView referenced link 6. Pspice 7. Proteus 8. Visual Studio 9. EasyEDA 10.Altium https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 107 Integrated Development Environment Tools

1. IDE Tools - MPLAB . If you are working with PIC Microcontroller, than you definitely need MPLAB. . MPLAB is an integrated development environment from Microchip technology. . It is a software that runs on your personal computer and is needed to create program for your pic microcontroller. . It helps in editing, debugging and programming of microchip microcontroller that you use in your embedded system. . The latest edition of MPLAB is MPLAB X. You can download this software free from microchip website. . For developing embedded software for your system using MPLAB, you have to go through some steps.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 108 Integrated Development Environment Tools

2. IDE Tools – Arduino Software . Arduino software helps you to create program for your microcontroller providing all the necessary embedded software tools. . The codes that you write on arduino software are referred to as sketches and have an extension .ino. . Integrated development environment of arduino is very user friendly and has a lot of features that make your job easy. For example, you can open multiple files with different extensions in one window. . With arduino you can make use of a number of different libraries for your functions and peripherals.

1. Ambiente de Trabalho 2. Barra de ferramentas 3. Menu 4. Console de feedback

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 109 Integrated Development Environment Tools

3. IDE Tools - Keil . Keil is an integrated development environment for a wide range of microcontrollers including 8051, 251, ARM7 and C16x/ST10 microcontrollers. . This software includes compiler, assembler, linker, debugger, simulator and etc. . This software is also easy to use and learn. . The software for 8051 is used by professional embedded system developers and beginners both. . Depending on the microcontroller that you are using, you can go for the right software.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 110 Integrated Development Environment Tools

4. IDE Tools - MATLAB . MATLAB is one of the very important tools for software developers. . It provides you with an environment where you can solve all of your computational problems. . You can work with matrices, graphs, vectors, functions, arrays, plots etc. You can make algorithms. Also you can create user interfaces. . With Matlab, you can also interface programs written in other programming languages. . Matlab comes with additional software, Simulink that enables you to create simulation. . It is really a helpful tool for embedded software developers, as you can work on sensors data, plot it and see response by changing certain variables.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 111 Integrated Development Environment Tools

4. IDE Tools – MATLAB PILS for Renesas MCUs

https://www.mathworks.com/products/connections/product_detail/embedded-target-renesas-cs.html January 23, 2021 112 Integrated Development Environment Tools

5. IDE Tools - Labview . LabVIEW stands for Laboratory Virtual Instrument Engineering Workbench. This software is also used for viewing output. . The main functions that can be performed using LabVIEW are data acquisition, industrial automation and instrument control. . This software is basically for visual programming language. . Some of the benefits of LabVIEW are: . Libraries . Interfacing to devices . Parallel programming . User community.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 113 Integrated Development Environment Tools

6. IDE Tools - PSpice . SPICE stands for Simulation Program for Integrated Circuits Emphasis, and PSpice is its version for personal computers. . PSpice is simulation software that is used for simulating circuits. . It helps in analyzing electronic circuitry, verifying circuit designs and predicting their behavior. . It has a number of libraries for digital and analog components. . The components that are available include . resistors, . capacitors, . voltage and current sources, . Inductances etc.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 114 Integrated Development Environment Tools

7. IDE Tools - Proteus . Proteus is kind of simulation software where you can create circuits, make model of your embedded system including microcontroller to see how it works, measure circuit parameters, change sensor values and much more. . It helps you to create PCB (printed circuit board) design for your embedded system. . Microcontroller simulation is an important feature of this software where you can load a hex file to your microcontroller in the design, connect all other components to it and see how it works. . This software runs only on Windows operating system.

The Proteus Design Suite is a tool suite used primarily for electronic design automation. The software is used mainly by electronic design engineers and technicians to create schematics and electronic prints for manufacturing printed circuit boards. https://en.wikipedia.org/wiki/Proteus_Design_Suite

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 115 Integrated Development Environment Tools

8. IDE Tools – Visual Studio . Visual Studio is also an integrated development environment provided by Microsoft. . It is used for developing computer programs for . . It can support different programming languages and basically consists of a code editor and a debugger. . With this software you can build different mobile apps, window apps, extensions, games etc. The choice of language is yours.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 116 Integrated Development Environment Tools

9. IDE Tools – EasyEDA . EasyEDA is an online tool that you can use to create schematics, PCB designs, and simulations. . Since it is an online tool that runs on web, there is no need for you to download and install it in your personal computer. Instead you can run it directly. . Also there is no need of updating your software or to remove bugs, as it is online tool and keeps updating itself. New features are added automatically. . Another advantage is that it runs on all types of OS (windows, linux etc.) as EasyEDA works on your web browser.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 117 Integrated Development Environment Tools

10. IDE Tools – Altium . The last one on my list of embedded software tools is Altium which is also PCB designing software. . PCB designing is very important part of developing an embedded system, so it is good to know all the available resources for PCB design. . The PCB designing module of altium has a lot of features including. . Adding hole tolerance . PDF 3D export . Live Drill Drawing . Supporting Embedded Components etc.

https://www.theengineeringprojects.com/2016/11/top-10-embedded-systems-software-development-tools.html January 23, 2021 118 IDE - CodeBlocks

IDE - CodeBlocks Code::Blocks is a free, open-source cross- platform IDE that supports multiple compilers including GCC, Clang and Visual C++. It is developed in C++ using wxWidgets as the GUI toolkit. Using a plugin architecture, its capabilities and features are defined by the provided plugins. Currently, Code::Blocks is oriented towards C, C++, and Fortran. It has a custom build system and optional Make support. The main features are: . Compilers . Code editor . Debugger . GUI designer . User migration . Project files and build system See also this link:

https://en.wikipedia.org/wiki/Code::Blocks https://en.wikipedia.org/wiki/Comparison_of_integrated_development_environments January 23, 2021 119 Activity 2

This task is to be carried out in group of three students and delivery at February 10th, 2021. The professor will teach in how to use an IDE for C Programming. Then, the activity 2 will be delivered to be carry out for a group of three students. You are advised to a) Understand the problem statements; b) Develop applications that allow and ensure the programs run according their purpose; c) Identify and update improvements according your perspectives d) Set up a date to show and delivery the runnable to professor This activity will have part of the whole score.

January 23, 2021 120 Activity 2

Description of this activity Boundary testing: mortgage example Program specification

Specification: Write a program that takes three inputs: gender (boolean), age([18-55]), salary ([0-10000]) and outputs the total mortgage for one person Mortgage = salary * factor, where factor is given by the following table.

Category Male Female Young (18-35 years) 75 (18-30 years) 70 Middle (36-45 years) 55 (31-40 years) 50 Old (46-55 years) 30 (41-50 years) 35

January 23, 2021 121 Activity 2

Description of this activity Identify the 12 bugs on Boundary testing: mortgage example the program below

Write this program solution and identify the 12 bugs inside inside it.

int mortgage (bool male, int age, int salary) { if (male) then return ((18 age < 35)?(75 salary) : (31 age < 40)?(55 salary) : (30 salary)) else // female return ((18 age < 30)?(75 salary) : (31 age < 40)?(50 salary) : (35 salary)); }

January 23, 2021 122 Activity 2

Description of this activity Implement and test the Boundary testing: mortgage example right solution

Specification: Write a program that takes three inputs: gender (boolean), age([18-55]), salary ([0-10000]) and outputs the total mortgage for one person Mortgage = salary * factor, where factor is given by the following table. int mortgage (bool male, int age, int salary) { if (male) then return ((18 age < 35)?(75 salary) : (31 age < 40)?(55 salary) : (30 salary)) else // female return ((18 age < 30)?(75 salary) : (31 age < 40)?(50 salary) : (35 salary)); }

age: extremes: 18, 55(?). near extremes: 19, 54. nominal: 25. salary: extremes: 0, 10000. near extremes: 1, 9999. nominal: 5000. male: true, false. nominal: true. No boundaries: define type-specific boundaries (e.g., 0 and MAXINT for integers).

January 23, 2021 123 Activity 2

Description of this activity Boundary testing: mortgage example

Finally, delivery all the steps done using the IDE tool and the test procedure used to certify whether your solution attend the specification/requirement Charles Barkley was really amazing

Michael Jordan is truly considered Nate Robinson Tyrone Bogues and recognized such had just 1.75 and could dunk had just 1.60 and the best basketball player of all time in the basketball hoop was worldchampion with the USA Team January 23, 2021 124 References

• Philip Koopmann. Better Embedded System Software. Drumnadrochit Education (January 1, 2010). ISBN-10: 0984449000 and ISBN-13: 978-0984449002. • Edward A. Lee and Sanjit A. Seshia, Introduction to Embedded Systems, A CyberPhysical Systems Approach. Second Edition, MIT Press, 2017. (ISBN: 978-0-262- 53381-2) • Manuel Jimenez, Rogelio Palomera and Isidoro Couvertier. Introduction to Embedded Systems: Using Microcontrollers and the MSP430. Springer, 2014ª edição (11 setembro 2013). MSP430. 672 páginas. • Hermann Kopetz. Real-Time Systems: Designs Principles for Distributed Embedded Applications. Kluwer Academic Publishers, Norwell, MA, USA, 1997. • Giorgio Buttazzo. Hard Real-Time Computing Systems. Kluwer Academic Publishers, Norwell, MA, USA, 1998 5. • Alan Burns. Real-time Systems and Programming Languages. Addison-Wesley, Boston, MA, USA, 1997 3. • Edited by Richard Zurawski. The Embedded Systems Handbook. CRC Press – Industrial Information Technology Series, 2005. ISBN 084932241. 1160 pages. • Edited by Nicolas Navet and Francoise Simonot-Lion. Automotive Embedded Systems Handbook. CRC Press / Taylor & Fancis – Industrial Information Technology Series, 2008. ISBN 978-0849380266. 488 pages. • Edited by Richard Zurawski. Embedded Systems Design and Verification, vol. 1 – Embedded Systems Handbook 2nd edition. CRC Press – Industrial Information Technology Series, 2009. Catalog no. K10385, ISBN 978-1-4398-0755-2. 636 pages. • Edited by Richard Zurawski. Networked Embedded Systems, vol. 2 – Embedded Systems Handbook 2nd edition. CRC Press – Industrial Information Technology Series, 2009. Catalog no. K10386, ISBN 978-1-4398-0761-3. 808 pages. • Raj Kamal. Embedded Systems: Architecture Programming and Design - 2nd edition. Tata MCcGraw-Hil, 2008. ISBN 978- 0-07-066764-8. 668 pages. • Gabriela Nicolescu and Pieter J. Mosterman. Model-Based Design for Embedded Systems – 1st Edition. CRC Press / Taylor & Fancis, 2009. ISBN-10: 1420067842 | ISBN-13: 978-1420067842. 719 pages.

January 23, 2021 125