This action might not be possible to undo. Are you sure you want to continue?
• Verilog • VHDL
You will study by yourself!!!
Programming in C
Programming: An essential part of any embedded system design. Processor and memory-sensitive instructions: Program codes may be written in assembly Most of the codes written in a high level language (HLL): e.g., ‘C’, ‘C++’ or Java
Advantages of an HLL
1. Short Development Cycle:
Code reusability: A function or routine can be repeatedly used in a program Use of Standard library functions: For examples, the mathematical functions and delay ( ), wait ( ), sleep ( ) functions Use of the modular building blocks
Advantages of an HLL
1. Short Development Cycle: Bottom-up design: Sub-modules are designed first for specific and distinct set of actions, then the modules and finally integration into complete design. First code the basic functional modules and then build a bigger module and then integrate into the final system
This is most favored program design approach.Advantages of an HLL • Top-down Design: First design of main program (blue-print). then its modules and finally the sub-modules are designed for specific and distinct set of actions. .
unsigned int. Data type declaration: 4 types of integer int. long(64 bits) unsigned int : +ve values signed int : 32bits Char – to manipulate text & string Each data type is an abstraction for the methods. short(16 bits). . manipulating.Advantages of an HLL 2. representing and for defining a set of permissible operations on that data. which are permitted for using.
Advantages of an HLL 3. . Type checking: Type checking during compilation makes the program less prone to errors. multiplication and division. For example. type checking on a char data type variable (a character) does not permit subtraction.
Conditions and loops make the program-flow designing tasks simple. . if .if and switch .Advantages of an HLL 4. do-while. Control Structures. Examples of Control Structures: while.case. break and for Examples of Conditional Statements: if.else. else .
. p)’. p. ‘C’ an HLL with provision of inserting the assembly language codes in between (called in-line assembly) to obtain a direct hardware control. In the in-line assembly the complex part is in HLL codes. Example: Mov al. al are the in-line assembly codes of the ‘C’ function ‘outportb (q. out q.Uses of ‘C’ as an HLL ‘C’ is a language between low level(assembly) & high level language.
Definitions for pre-processor global variables 3.C Program Elements: Header. Declarations for global data type. Include : directive for file inclusion 2. Main function 3. Functions. type declaration and data structure. definitions & statements 2. exceptions and ISRs Pre-processor structural elements: 1. Pre-processor Directive Structural elements of C program: 1. Definitions of constants 4. macros and functions . Pre-processor declarations. Source Files.
str ’ or ‘. ‘. #include ‘prctHandlers. Including string data files: extension.txt’ e.‘C’ Program Elements 1.init’ (for ROM) .data’(for RAM) . ‘. ‘.g. Including constant data files: extension ‘.strings’ . #include ‘netDrvConfig. Preprocessor include Directive: to include the contents(data & code) of a file.const’ iii. ‘. Including initial data files: initial or default data for the shadow of ROM. Extension.g. i.txt’ iv.c’ ii. Including code files: files for which codes are already available e.
‘math. Including header files: includes the contents(code or data) of a set of source files e.h> .‘C’ Program Elements v.h> .h> #include <stdio.g: system real time clock (with extension ‘. #include <conio.bss’) vi.g: string manipulation function.h’ mathematical function.#include <string.h> #include <math. Including basic variables files : files for local or global static variables stored in RAM static variable: one instance having one variable address with a static memory allocation e.‘string.h’ Pre-processor directive.
h" /* Include multitasking functions Library */ .h" /* Include Semaphore functions Library */ # include "taskLib.‘C’ Program Elements 1.h" /* Include VxWorks functions */ # include "semLib. Preprocessor include Directive: # include "VxWorks.
txt" /* Include a text file that provides the 'Network Driver Configuration' */ • .c" /* Include system library for system functions */ # include "netDrvConfig. Preprocessor include Directive: • # include "sysLib.‘C’ Program Elements 1.
c" /* Include file for the codes for handling and actions as per the protocols used for driving streams to the network */ .‘C’ Program Elements 1. Preprocessor include Directive: • # include "prctlHandlers.
text files. configuration files. header files. variables. STAI “# define volatile boolean IntrEnable” (Volatile: a directive to the compiler not to take this variable into account while compacting & optimizing the code) .‘C’ Program Elements 2. IntrPortAEnable. library functions) a) Global Variables: IntrDisable. IntrPortBDisable. STAF. Preprocessor Directive: (pre-processor constants.
a) Constants: “# define false 0” #define portA(volatile unsigned char*) 0x1000 # define PIOC(volatile unsigned char*) 0x1001 0x1000 and 0x1001 are address for portA & PIOC(port input-output control register) are constants defined for the 68HC11 register address a) Strings: “# define welcome "Welcome To ABC Telecom" .
‘C’ Program Elements 2. Source Files .
g: “serialLine_cfg.‘C’ Program Elements 3. “os_cfg. Configuration files: For configuration of the system Device configuration code put in a file of basic variables e.h” .h” .
.A named collection of codes that is defined in a program as preprocessor directive.‘C’ Program Elements 3. It differs from a function in the sense that once a macro is defined by a name. the compiler puts the corresponding codes at the macro at every place where that macro-name appears. Preprocessor Macros: Macro .
Macros are used for short codes only. the processor has to save the context. On calling that function. Preprocessor Macros: Macro differs from a function as follows: The codes for a function are compiled once only. . and on return restore the context.‘C’ Program Elements 3.
the overheads (context saving and return) will take a time. Texec for execution of short codes within a function.‘C’ Program Elements 3. Preprocessor Macros: When a function call is used instead of macro. Toverheads that is the same order of magnitude as the time. and a macro when Toverheads ~= or > Texec. Use a function when the Toverheads << Texec. .
short – 16bits. unsigned int. long double. byte – 8 bits. float – 32bits. unsigned short. double -64 bits typedef: create a boolean type variable as a data type • To use unsigned character as a data type typedef unsigned character portAdata # define Pbyte portAdata 0xF1 . int.‘C’ Program Elements Data Types: Primitive Data types: Char.
data structure & function E. unsigned char *0x1000 – character of 8bit at address 0x1000 ‘#define NULL (void*) 0x0000’ ??? .reference to the starting address refers to variable.‘C’ Program Elements Pointers & Null pointers: Pointer.g.
’ • ‘timer1++’ =?? • ‘unsigned byte *portA’ .*means the ‘contents at’ (portA have a buffer register storing a byte) • void *portAdata – compiler allocate address for the *portAdata without type check • Pointer can be assigned a constant fixed address #define portA(volatile unsigned byte*)0x1000 • or ‘volatile unsigned byte*portA = (unsigned byte*) 0x1000’ • unsigned byte *portA = &portAdata .• ‘unsigned short *timer1.
Data Structures: Data structure .‘C’ Program Elements 4.A way of organising large amounts of data. A data elements collection can then be identified and accessed with the help of a few pointers and/or indices and/or functions. .
Standard Data Structure Examples: Queue Stack Array – one dimensional as a vector Multidimensional List Tree .‘C’ Program Elements 4. Data Structures: It a way of organizing several data elements of same types together at consecutive memory address.
Modifiers: auto.‘C’ Program Elements 5. volatile static • auto: no modifier ROM allocation if the variable is initialized in the program RAM allocation if the variable is not initialized in the program • Unsigned : to permit only +ve values for short(16 bits) . volatile. static. unsigned. extern. long(64 bits) data type. int(32 bits). . interrupt. register. const.
‘C’ Program Elements Modifiers • – • Static: declaration inside a function block. initialized by the program ROM allocation for this code #define const welcome_msg ‘good morning’ Extern : directs the compiler to look for the data type declaration or a function in the module other than the one in currently in use ‘extern long volatile time_value’ • . such that a variable can be accessible outside the function static variable has reserve memory for it Const: outside a function block.
g.variable should be accessible outside the function block with reserved memory volatile. e.cannot optimize e.‘C’ Program Elements • Volatile : outside a function block is a warning to the compiler that an event can change its value or that its change represents an event..‘volatile static boolean RTIEnable= true’ .g.volatile variable is not optimized . . • Volatile static : inside the function block static.
Infinite loops: Infinite loop – Never desired in usual programming. Infinite loop is a feature in embedded system programming! . Why? The program will never end and never exit or proceed further to the codes after the loop.‘C’ Program Elements 6.
– – Passing the Values (elements): The values are copied into the arguments of the functions. which calls new function. Functions: i. it does not change a variable's value at the function. . When the function is executed in this way.‘C’ Program Elements 8.
the called function can change this value. – .‘C’ Program Elements 8. the new value may be available in the calling program or another function called by this function. – Passing the References: When an argument value to a function passes through a pointer. Functions: ii. On returning from this function.
This is because all the values of its argument are retrievable from the stack. Reentrant Function: A function usable by the several tasks and routines synchronously (at the same time).‘C’ Program Elements 9. .
. All the arguments pass the values and none of the argument is a pointer (address) whenever a calling function calls that function.‘C’ Program Elements Three conditions for a function called as reentrant function : i.
which is declared outside the function or which an interrupt service routine uses or which is a global variable but passed by reference and not passed by value as an argument into the function.] . that function should not operate on any variable.‘C’ Program Elements ii. does not save on the stack when there is call to another program. which is not local. When an operation is not atomic. [The value of such a variable or variables.
That function does not call any other function that is not itself Reentrant. .‘C’ Program Elements iii. 10. Multiple function calls in Cyclic Order: One of the most common methods is the use of multiple function-calls in a cyclic order in an infinite loop of the main ( ).
‘C’ Program Elements .
.‘C’ Program Elements 11.Function Pointers: * sign when placed before the function name then it refers to all the compiled form of the statements in the memory that are specified within the curly braces when declaring the function.
void) followed by '(*functionName) (functionArguments)' calls the statements of the functionName using the functionArguments.‘C’ Program Elements A returning data type specification (for example. . it returns the specified data object. and on a return. We can thus use the function pointer for invoking a call to the function.
only when a precise control of the processors internal devices and full use of processor specific features in its instruction set and addressing modes needed.Summary We learnt i. An embedded system programming in the assembly language. It easily makes larger program development feasible. Therefore. ‘C’ or ‘C++’ or JAVA is used for embedded system development. ii. . Program in a high-level language features – A short development cycle for a complex system and portability to the system hardware modifications.
infinite loops. . source and configuration files. library functions.Summary We also learnt iii. the important programming elements in ‘C’ preprocessor directives. macros. data type declarations. reentrant functions. iv. data structures. pointers and function pointers. 'C' language supports in-line assembly (fragments of codes in assembly) gives the benefits of assembly as well as high-level language. header files. multiple function calls.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.