Embedded System Lecture Notes PDF

Summary

These lecture notes cover embedded systems, focusing on topics such as computer architecture, memory types, and C preprocessor directives. The material provides an introduction to the fundamental concepts and is geared towards an undergraduate audience.

Full Transcript

BY DR. NARIMAN A. KHALIL Introduction Embedded System Lecture 2 Computer Architecture 16 Control and Status Registers ❖These are a set of essential registers for proper operation. They are usuall...

BY DR. NARIMAN A. KHALIL Introduction Embedded System Lecture 2 Computer Architecture 16 Control and Status Registers ❖These are a set of essential registers for proper operation. They are usually not visible to the programmer, although some of them are so. ❖Examples are: Program Counter (PC): Contains the address of the instruction to be fetched. Instruction Register (IR): Contains the instruction most recently fetched. Memory address register (MAR): Contains the address of the location in the memory to be fetched/stored Memory buffer register (MBR): Contains the data to be loaded/stored in the memory 20 Mircocomputer Performance ❖ Several measurements are needed to determine computer performance like: Latency: “How long does it take for my job to run ?” Throughput: “How many jobs can the machine execute at once ?” Elapsed time: “How long does it take the machine to finish a certain job ?” CPU time: “How much time did it take from the CPU to finish the job ? I.e. excluding I/O, memory, hard disk, … etc. ❖ We are basically focused on CPU time, and elapsed time throughout this course Build Process 22 The image you shared illustrates the steps involved in the compilation and execution process of a C program. Here's a breakdown of the process as shown in the diagram: 1.C Preprocessing: The source code (e.g., my_pattern.c) is preprocessed to generate the preprocessed code (my_pattern.i file). This step handles macros, includes header files, and prepares the code for compilation. 2.C Compiling: The preprocessed code is compiled into assembly code (my_pattern.s file). This step translates the high-level C code into assembly language, which is more closely tied to machine code. 3.Assembler: The assembler converts the assembly code into an object file (my_pattern.o). This file contains machine code but is not yet executable because it may have unresolved references to libraries or other modules. 4.Linker: The linker takes the object file (my_pattern.o) and other object files, library files, and relocation information to generate the executable file (my_pattern.exe) and additional files like.elf,.map, and.lst. The executable file is the final product that can be run on the system. 5.Hex File Generation: From the executable file (.exe or.elf), a hex file (my_pattern.hex) is generated. This file is often used for programming embedded systems, containing the binary data to be loaded into memory. 6.Memory Storage: The hex file is stored in the desired memory location (SRAM, flash, or GRAM) on the target system. 7.Execution: The core processor executes the hex file, and a stimulus (or specific behavior) is generated based on the instructions provided in the original C source code.This process is typical in compiling C programs, especially in embedded systems where hex files are used to program microcontrollers or other hardware components. C preprocessor directives  Macro substitution directives. example: #define  File inclusion directives. example: #include  Conditional compilation directive. example: #if, #else, #ifdef, #undef  Miscellaneous directive. example: #error, #line C preprocessor directives Pointers and Casting Pointers:  A pointer is a variable that stores the memory address of another variable. It allows you to indirectly access the data stored in the memory location pointed to by the pointer. Pointers are often used for dynamic memory allocation and data manipulation. Pointers and Casting Casting in Pointers:  Casting in pointers involves changing the data type associated with a pointer. It is used when you want to interpret the memory at a particular address as a different data type. Be cautious when casting pointers, as it can lead to undefined behaviour if not done correctly. Volatile keyword ❖ the volatile keyword is used to indicate to the compiler that a variable may change its value at any time, without any action being taken by the code the compiler finds nearby. ❖ The volatile keyword is often used for variables that can be modified by hardware, external events, or in multi-threaded programs where another thread might change the variable's value. Some common use cases for volatile include: ❖ Memory-Mapped Hardware Registers: In embedded systems programming, hardware registers that control devices (e.g., sensors, communication ports) are often declared as volatile because their values can change at any time due to external hardware events. ❖ Interrupt Service Routines: Variables shared between an interrupt service routine (ISR) and the main program should be declared as volatile to ensure that the compiler does not optimize away access to these variables.

Use Quizgecko on...
Browser
Browser