08.

716 Embedded System

Module 2

S/W programming concept in embedded systems: 1. Assembly language programming Advantages:  Codes are sensitive to the processor, memory, ports and device hardware . It give precise control of the processor internal devices and complete usage of processor-specific features  Require only smaller memory. Program is not a compiler specific  Device driver by assembly code need only a few instructions  Suitable for bottom-up design approach 2. High level language programming Eg: C, C++ or Java Advantages:  Program development cycle is short even for complex systems because of the use of subroutines, std library functions etc.  Facilitates data-type declarations  Facilitates type checking  Facilitates use of control structures and conditional statements to specify program flow  Has probability of non-processor-specific codes  C as a high level language is a language b/w low and high level language C program elements:  Structural elements in C program are:  Pre-processor declarations, definitions and statements  Main function  Functions, exceptions and ISRs  Preprocessor structural elements has:  Include directive for file inclusion  Definitions for preprocessor global variables  Definitions of constants  Declarations for global data type, type declaration and data structures, macros and functions Include directive for inclusion files:  Include is a preprocessor directive to include the contents (code or data) of a file  The requirements for include files are:  Including code files (.c files)  Including constant data files (.const files)  Including strings data files (.strings or .str or .txt files)  Including initial data files (shadow of ROM, .init files)  Including basic variable files (local or global static variables, .bss files)  Including header files (contents of a set of source files, .h files)

Department of ECE, VKCET

Page 1

08.716 Embedded System

Module 2

 Some examples of include fles:

Source files:  Program files for the functions of application software  Need to be compiled  Will possess the preprocessor directives of the application and have first function where the processing will start and is called main, usually void main() Configuration files:  Files for configuring the system  If configuration codes are in the file named ‘serialLine_cfg’, then preprocessor directive is #include “serialLine_cfg.h” Preprocessor directives:  Preprocessor global variables: For example, in a program the IntrEnable, InterDisable may be global variables for disabling or enabling interrupts. Then preprocessor directive is #define volitile boolean InterEnable  Preprocessor constants: Example is #define false 0 means it is a directive before processing to assume false as 0 Another example is #define portA (volitle unsigned char *) 0x1000 is the address fixed for port A register Strings are constant and a directive example is #define welcome ‘Welcome to Kerala’ Program elements: Macros and functions  The use of these elements are:  Macros: Executes a named small collection of codes  Functions: Executes a named set of codes with values passed by calling program through it arguments. Also returns a data object Preprocessor macros:  Collection of code that is defined in a C program by a name  Compiler puts the corresponding codes for it every place where that macro name appears  An eg. ‘enable_Maskable_Intr( ) and ‘disable_Maskable_Intr’. When ever the name appear the compiler places the code designed for it  Test macros or test vectors are designed during programming and are used for debugging
Department of ECE, VKCET Page 2

08.716 Embedded System

Module 2

Difference between macros and functions:  Codes for function are compiled once only. On calling it save content, return nothing, or a type of data value  Code for macro compiled in every function wherever that macro name is used. On using it does not save the content, does not return data  Macros used for short codes only, but functions not Use of Data types:  Have address allocated at the memory. Number of address depends on data types  Primitive data types in C:  char (8 bits) for characters  byte (8 bits)  unsigned short (16 bits)  short (16 bits)  unsigned int (32 bits)  int (32 bits)  long double (64 bits)  float (32 bits)  double (64 bits)  typedef is used to create data type An eg: typedef unsigned character portAdata #define Pbyte portAdata 0xF0 Use of pointers and Null pointers:  Pointers are powerful tool  It is a reference to starting memory address  Can refer to variable, data structure or function  Eg: unsigned char *0x1100 means a character eight bit address 0x1100  NULL pointer declares:  #define NULL (void)*0x0000, we can assign any address instead of 0x0000 that is not in a given hardware  Exemplary uses of pointers are: 1. Consider ‘unsigned short *timer1’. The computer will reserve two memory addresses for the contents of timer1. Consider the statement timer1++, it adds 0x0002 in the address of timer1 (for a 16 bit timer address) 2. Consider ‘unsigned byte *portA’, means that there is a pointer and an unsigned byte for port A and the compiler will reserve one memory address for that byte 3. Consider the declaration, void *portAdata: the void is the undefined data type for portAdata, the compiler will allocate address for the *portAdata without any type check

Department of ECE, VKCET

Page 3

08.716 Embedded System

Module 2

4. Consider two preprocessor directives: ‘#define portA (volitle unsigned byte *) 0x1000’ and ‘#define PIOC (volitle unsigned byte *) 0x1001’. An instruction ‘portA++’ will make the portA pointer point to the next address which is POIC 5. Consider the statements ‘unsigned byte portAdata’ and ‘unsigned byte *portA = &portAdata’. The first statement directs compiler to allocate one memory address for portAdata and the & symbol means ‘at the address of’ and it declares the positive number of 8 bits pointed by portA is replaced by the byte at the address of portAdata Use of Function calls:  Executes a named set of codes with values passed by the calling program through its arguments. It returns a data object and has context-saving and retrieving overheads  Special function for starting the execution of a program is ‘void main(void)’  Steps to follow using a function: 1. Declaring a function: Example is ‘int run (int indexRTCSWT, unsigned int maxLength, unsigned int numTicks)’. The run is the function name, int specifies the returned data type, arguments are inside the brackets and data type of each arguments is also declared 2. Defining the statements in the function: It has the statements to perform the action of function. The last statement in a function is the return statement for returning an element or data structure or object 3. Call to a function: Call for fulfilling the condition and the call can occur several times and can be repeatedly made  Steps in transfer of values from the arguments of calling function: 1. Passing the values (elements): The values are copied from argument in calling to called function argument 2. Reentrant functions call: It is usable by several tasks and routines synchronously. A function is called re-entrant function when the following three conditions are satisfied. i) All the arguments pass the values and none of the argument is a pointer whenever a calling function call its ii) When an operation is not atomic, the function should not operate on any variable, which is declared outside the function or which an ISR uses or which is a global variable but passed by reference and not passed by value as an argument into the function iii) The function does not call any other function that is not itself re-entrant 3. Passing the references: When an argument value to a function passes through a pointer, the called function can change this value.

Department of ECE, VKCET

Page 4

08.716 Embedded System

Module 2

Multiple function calls in cyclic order:  One of the most common methods is multiple function calls made in a cyclic order in an infinite loop.  Programming model of multiple function calls:

 An example: while (true) { /*Codes for repeatedly execute*/ /*Functions call*/ while (charAFlag != true) checkPortAChar( ); inPortA (unsigned char *portAdata); outportB(unsigned char *portAdata); } Function pointers, function queues and ISR queues:  Consider a declaration, ‘boolean checkPortAChar ( );’ where the checkPortAChar is the function, which returns a boolean value. checkPortAChar is itself a pointer to the code’s starting address  Let put * sign before the function’s name, ‘*checkPortAChar’ will now refer to all compiled statements in the memory  Consider a declaration, ‘void inPortA (unsigned char*);’ 1. inPortA means a pointer to the statements of the function. Inside the bracket there is an unsigned character pointed by some pointer 2. *inPortA will refer to all the compiled statements of inPortA 3. (*inPortA) will refer to calling of statements of inPortA 4. The statement ‘void create (void (*inPortA) (unsigned char *portAdata), void *portAStack, unsigned char portApriority);’ means: a) First ‘void’ means create a function which does not return any thing b) ‘create’ is the function which can called after its declaration in the statement

Department of ECE, VKCET

Page 5

08.716 Embedded System

Module 2

c) The first argument ‘void (*inPortA) (unsigned char *portAdata)’, (*inPortA) means to call the statements of inPortA the argument of which is ‘unsigned char *portAdata’. d) The second argument of create function is a pointer for the portAstack at the memory e) The third argument of create function is a byte that defines the portApriority Queuing of functions on interrupts:  When there are multiple ISR, a high priority ISR is executed first and the lowest priority in the end.  Possible that function calls and statements in any of the higher priority interrupts may block the execution of low priority ISR and there may be deadline miss for the low priority ISR  Solution for the deadline problem for low priority ISR is by using function pointers in the routines and forming a queue (FIFO) for the function pointers. The queued functions are executed at a later stage  Queued functions are the deferred procedure calls (DPCs) and can be called ISRs when OS handles them as threads  The main function, function multiple calls calling the function queues and ISR is shown below:

where (a) Main () function, (b) Function queue operation, (c) Creation of a queue of the function pointers by the ISR and (d) Queue of the function pointers

Department of ECE, VKCET

Page 6

08.716 Embedded System

Module 2

Object-oriented programming:  Large programs, object-oriented language have advantages  OOP language provides: 1. Defining the object or set of objects and can be used in many programs 2. Defining the methods that manipulate the objects without modifying their definitions 3. Creation of multiple instances of the defined object or set of objects or new objects 4. Inheritance 5. Data encapsulation (Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding. Data encapsulation is a mechanism of bundling the data, and the functions that use them) Design of reusable components  An object can be characterized by: i) identity (a reference to a memory block), ii) state (its data, fields etc) and iii) behavior (methods that can manipulate the state of object  In procedural language programs are split into simpler functional groups and statements, but in OOP languages logical group (classes) are first made. Each group defines the data and the methods of using the data. A set of these groups then gives an application program Embedded programming in C++:  Advantages of C++: 1. C++ is an OOP language, supports procedural oriented codes of C, hence have all the advantages of C and in-line assembly 2. A class binds all the member functions together for creating objects. Let us assume that each software timer as an object. it gets count input from a real-time clock, it has a terminal count value after a software interrupt, it is initialized to a count value. Now consider the codes for a C++ class RTCSWT and a number of software timer objects can be created as the instances of RTCSWT. Each instances of that class have different values, but has identical methods to manipulate the count. 3. A class can inherit another class also 4. Methods (C functions) can have same name in the inherited class and is called method overloading. 5. Operators in C++ can be overloaded like method overloading  Disadvantages of C++: Program codes become lengthy due to: 1. Template 2. Multiple inheritance 3. Exceptional handling 4. Virtual base classes 5. Classes for IO stream

Department of ECE, VKCET

Page 7

08.716 Embedded System

Module 2

Optimization of codes in embedded C++ programs to eliminate the disadvantages:  Optimization can be done by: 1. Declare private as many classes as possible. It helps in optimizing the generated codes 2. Use char, int and boolean (scalar data types) in place of objects as arguments and use local variable as much as feasible 3. Recover memory already used once by changing the reference to an object to NULL  Embedded C++ is a version of C++ that provides selective disabling of features, so that there is less run-time overhead and less-run time library  Embedded C++ compilers or the special compilers make the C++ more powerful language than C for embedded system Cross-compilers:  Cross-compiling is to use some processor (HOST) to compile software for some other processor (TARGET) that uses different architecture.  The machine on which you are compiling the software cannot natively run the software it compiles.  The software is compiled for another processor.  GNU C/C++ is an example for cross-compiler  It has small run time library  Have selectively (de-configured) features Real time operating systems: Definition of Process:  Application program can be said to consists of a number of process and each process runs under the control of an OS

 Concept of process is as follows: 1. Process consists sequentially executable programs and state-control by an OS 2. State during running of a process is represented by the information of process state (created, running, blocked or finished), process structure - its data, objects and resources, process control blocks (PCB) 3. A process runs on scheduling by OS (kernel), which gives the control of CPU to the process. Process runs instructions and the continuous changes of its state takes place as the PC changes.
Department of ECE, VKCET Page 8

08.716 Embedded System

Module 2

 Process is that unit of computation, which is controlled by some process at the OS for scheduling Process Control Block:  It is a data structure having the information using which the OS controls the process state  PCB consists the following information about the process state: 1. Process ID, process priority, parent process, child process and address to the next process PCB, which will run next 2. Allocated program memory address blocks in physical memory and in secondary memory for the process codes 3. Allocated process-specific data address blocks 4. Allocated process heap (data generated during program run) address 5. Allocated process stack addresses for the functions called during running of the process 6. Allocated addresses of the CPU register-save memory as a process context represents by CPU registers, which include PC, SP etc. 7. Process state signal mask 8. Signals dispatch table 9. OS-allocated resources descriptors 10. Security restrictions and permissions Definition of thread:  Application process can be said to consist of number of threads or a number of process and threads as shown below.

 Thread consists of sequentially executable program under the state control by an OS  The state information of a thread is represented by thread-state (started, running, blocked or finished), thread structure- its data objects and subset of the process resources and thread stack  Thread is a high-weight entity. [Process is a heavy weight entry and kernel is a controlled entity]  Thread is a process or sub-process within a process that has its own PC, its own SP and stack, its own priority parameter scheduling by thread-scheduler  Thread has its own signal mask at kernel. When signal mask is masked, the thread is put into a queue of pending threads, otherwise thread to activate and run  Multi-process consists more than one process and a process consists multiple thread and is the process is called multithreaded process
Department of ECE, VKCET Page 9

08.716 Embedded System

Module 2

 A thread can be considered as daughter process and defines a minimum unit of a multithreaded process that an OS schedules into the CPU and allocates other system resources  Different thread of a process may share a common process structure. Multiple threads can share the data of the process  Thread need not process the data during memory mapping by process Difference between thread and task: Thread Can either be a sub-process within a process or a process within an application program Process controlled entity Not analogous to task Doesn’t call another thread to run Need an appropriate scheduler Multithreading needs a threadscheduler -

Task It is a process and OS does not multitasking Kernel controlled entity Analogous to thread Doesn’t directly call another task to run Need an appropriate scheduler Multitasking need a taskscheduler May or may not be task groups and task libraries in a given OS

 Example: In mobile phone service display_process have multiple threads: 1. Thread1: Display_Time_Date 2. Thread2: Display_Battery 3. Thread3: Display_Signal 4. Thread4: Display_Profile 5. Thread5: Display_Message 6. Thread6: Display_CallStatus 7. Thread7: Display_Menu  These threads share the common memory blocks and resource allocated to the Display_process  A display thread have minimum computational unit controlled by the RTOS, each thread has independent parameters – ID, priority, PC, SP, CPU registers and its present status. Definitions of Tasks:  Term used for process in the RTOS’s for the embedded system. Eg. VxWorks, μCOS-II, etc.  Similar to process or thread in an OS, some OS uses the term task and some other uses process  An application software consisting of a number of tasks is shown below:

Department of ECE, VKCET

Page 10

08.716 Embedded System

Module 2

 A task consists of sequentially executable code under a state-control by an OS  State information of a task is represented by task state (running, blocked or finished), task structure – its data, object and resources and TCB.  Application software consists of a number tasks and task behavior in the various states. The task states are controlled by some process at the OS  Embedded software consists of a number of tasks and each task run needs a control of the state by OS  A task is independent process and no task call another task  Example Automatic Coffee Vending Machine Its embedded software is highly complex and the OS schedules to run the application. The numbers of tasks are: i. Task User Keypad Input ii. Task Read-Amount iii. Chocolate delivery status iv. Display Task v. GUI task vi. Communication task Task states:  A task and its states is shown below:

 State includes the status of task at a given instance in the system. It can be one of the following state: idle, ready, running, blocked and deleted 1. Idle (created) state: Task has been created and memory allotted to its structure 2. Ready (active) state: The created task is ready and is schedulable by the kernel but not running at present 3. Running state: Executing the servicing codes and getting the system resources at this instance 4. Blocked (waiting) state: Execution of servicing code suspends after saving the needed parameters into its context 5. Deleted (finished) state: The created task has memory de-allotted to its structure. It frees the memory and task has to be re-created  An example: A smart card reader
Department of ECE, VKCET Page 11

08.716 Embedded System

Module 2

Step 1: Main program first run as OS_initiate( ), this enables RTOS function Step 2: Main program runs an OS function OS_task_Create( ) to create a task Step 3: OS_task_Create runs two more times to create two other tasks, Task_Send_Port_Output and Task_Read_Port_Input and both of them are in idle state. Let these tasks be middle and low priorities respectively Step 4: Functions starting OS_Start( ) and for initiating n system clock interrupts OS_Ticks_Per_Sec ( ) run. Then system switches from user mode to supervisory mode every 1/60 seconds, if n=60 Step 5: OS runs a function, which makes the Task_Send_Card_Info state is running and it runs an OS function mailbox_post(authentication_request), which sends the server identification request through IO port to the host using the task Task_Send_Port_Output. Step 6: Task_Send_Card_Info runs a function mailbox_wait( ), which makes the task state is blocked and the OS switches context to another task Task_Send_Port_Output and the to Task_Read_Port_Input for reading IO port input data. Step 7: When mailbox gets authentication message from the host, the OS switches context to Task_Send_Card_Info and the task comes to the running state again. The Task_Send_Card_Info states in different steps are shown below:

Task and data:  Task and its data including its context and TCB is shown below:

 Task has the following data specific to a task, which serves as the TCB 1. Each task has an ID just as a function name. The ID is of one byte and is called index of the task and OS assign each ID number between 0 and 255. 2. Each task may have a priority parameter. If the priory is between 0 and 255, higher the value have lower the priority 3. Each task has its independent values of the following instant: i) PC ii) SP
Department of ECE, VKCET Page 12

08.716 Embedded System

Module 2

 Context: Each task has a context (CPU registers and parameters, which includes registers for task PC and pointer to called function stack-top). This reflects the CPU state just before the OS blocks one task and initiates another task into running state. The context will continuously update during the running a task and the context is saved before switching occurs to another task.  Context switching: Only after saving context CPU control switch to any other process or task. The context must retrieve on transfer of program control to the CPU back for running the same task again.  Each task also have initial context, context_init, have the initial parameters of a task. The parameters are: i. Pointer to start-up function ii. Pointer to context data structure iii. Pointer to a new task object (function) iv. Pointer to the stack of a previous task object (function) Task Control Block:  Each task has a TCB and is a memory block  TCB is a data structure having information using which the OS controls the task state  TCB stores in the protected memory area of the kernel  TCB consists the following information about the task: i. Current PC information ii. Memory map iii. Signal dispatch table iv. Signal mask v. Task ID vi. CPU states (registers, task PC and task SP) vii. Kernel task (for executing system calls and so on) • TCB is similar to PCB but TCB data structure can vary from one OS to another Clear-cut distinction between functions, ISRs and tasks by their tasks: Task coding in endless event-waiting loop:  Each task is in endless event-waiting loop to start with  Event loop is one that keeps on waiting for an event to occur. On the start event, the loop starts from the first instruction of the loop and at the end the task returns to the start event waiting loop  An eg: Chocolate delivery task in an ACVM static void Task_Deliver (void *taskPointer) { /* Initial assignments of the variables and pre-infinite loop statements that execute once only*/ while(1) /*start an infinite while-loop*/ {
Department of ECE, VKCET Page 13

08.716 Embedded System

Module 2

/*wait for an event from task_Read_amount*/ /*Codes for delivering a chocolate into a bowl*/ /*send a message through an IPC signal for displaying “Collect the nice chocolate. Thank you, visit again”, the Display_Task*/ /*Resume delayed Task_Read_Amount*/ } } /*end of the Task_Deliver function*/ Distinction between function, ISR and task:  Embedded system with multiple devices have functions, ISRs and program objects and can be modeled by multiple tasks and each task is scheduled by the kernel schedule and uses IPCs for synchronization  Threads are used in embedded Linux or Unix based applications and are used in Java  Functions are subunits of the processes or tasks or ISRs  Functions and ISRs do not have analogue of PCB or TCB, they have only stack  Functions has no associated scheduler like task scheduler or thread scheduler at the kernel  ISR has associated interrupt handler at the kernel  Characteristics of function, ISR and task are: Function ISR Task Use: Can be used in any Used for running a specific Used for running specific set of codes for routine or process or task set of codes for performing performing a specific set of actions. Task for running specific set of a specific set of actions. code is in endless waiting statement. codes for performing a ISR runs once and for specific set of actions as servicing the interrupt-call per the arguments only. passing. Calling source: From From a hardware or From the OS. OS preemptive scheduler another function or software at any instance. can allow another higher priority task to process or thread or task. All interrupt source calls execute after blocking the present one. for running ISR are RTOS only control the task scheduling. independent. Context save: By Each ISR is event driven Task code run by change in PC function code run function code and code run instantaneous value. Each task has a changes PC instantaneous value changes in PC distinct task stack at the distinct memory value. There is a stack, instantaneous value. ISR block for the context (PC instantaneous top of it is PC value and have a stack for the PC values and other CPU register values in other values must save value and other values task) that must save when blocking from when calling another must save before allowing its running state due to an interrupt or function or start of ISR. another ISR to execute. preemption by another higher priority Return from a function to ISR stack is a common task. Each task has distinct TCB at the function called it, PC memory block when there distinct memory block. restores from the stack. is nesting.
Department of ECE, VKCET Page 14

08.716 Embedded System

Module 2

Response and synchronization: A function calls another function and there is a nesting. There is a h/w mechanism for sequential nested mode synchronization between functions without the control of OS scheduler. Structure: Functions are subunits of process or thread or task or ISR or subunit of another function or main function

There is a h/w mechanism for responding to an interrupt for interrupt source calls according to the given OS kernel feature and synchronizing mechanism for the ISR.

According to OS kernel feature, there is task-responding and synchronizing mechanism. Kernel functions are used for task synchronization. When task runs and when it blocks it is fully under the control of the OS.

Global variables use: Function can change the global variables. Interrupts must be disabled and after completing the use of global variable the interrupts are enabled. Posting and sending parameters: Can get parameters and messages through the arguments passed to it or global variables. Returns the results of operation through the references in the arguments.

ISR is independent and is considered as a function, which runs on an event due to an interrupting source. Pending interrupt is scheduled to run using an interrupt handling mechanism in OS Using global variable, the interrupt must be disabled and after completing the use of global variable the interrupts are enabled.

Task is independent and can be considered as function, which is called to run by the OS scheduler using a context switching and task-scheduling mechanism. Running of a task, can let another higher priority task run and kernel manages task scheduling Using a global variable, either interrupts are disabled or after completing the use of global variable the interrupts are enabled or semaphores are used.

ISR using IPC functions for post can send the signals and messages. ISR cannot use the mutex protection of the critical sections. ISR does not for signal or message during running.

Task can send the signals and messages and task can wait for signals and messages using IPC functions. Task can use the mutex protection of the code sections.

OS services: Goals: I. OS goals are perfection and correctness to achieve the following: 1. Facilitating easy sharing of resources as per schedule and allocations 2. Facilitating easy implementation of the application-program with the given systemhardware.
Department of ECE, VKCET Page 15

08.716 Embedded System

Module 2

3. Optimally scheduling the processes on one and providing an appropriate context-switching mechanism. 4. Maximizing the system performance to let different processes (tasks or threads) share the resources most efficiently with protection and without any security violation. 5. Providing management functions for the processes (tasks or threads), memory, devices and IOs and other functions. 6. Providing management functions for the functions for the devices, files and virtual devices and IOs. 7. Providing easy interfacing and management for network protocols and networks. 8. Providing probability of application on different hardware configurations 9. Provides interoperability of applications on different networks 10. Providing a common set of interfaces that integrates various devices and applications through the standard and open systems II. User and supervisory mode structure: Processor in a system runs in two modes 1. User mode: User processor permits to run and use only a subset of functions and instructions in OS. The use of hardware resources including memory is not permitted without making call to the OS functions. User function call is distinct from system function call and is not permitted to read or write into the protected memory allotted to the OS functions, data, stack and heap, and this protected memory space is also called kernel space. Hence the execution of the user functions is slower than the execution of OS functions. 2. Supervisory mode: OS runs privileged functions and instructions in the protected mode and the OS (kernel) only accesses the hardware resources and protected area memory. Only a system call is permitted to read and write into protected memory allotted to the OS functions, data, stack and heap. Kernel space functions executes faster than the user space functions. Structure:  A system have the following structure: Layer from Top-down structure layers Actions top Executes as per the applications, run on the 1 Application software given system hardware using the interfaces and the system software Provides interface between the application Application program software and system software so that it is able 2 interface (API) to run on the processor using the given system software The OS may not have the functions like System software other than network and device drivers, multimedia device 3 the one provided at the OS etc. This layer gives the system software services for that types
Department of ECE, VKCET Page 16

08.716 Embedded System

Module 2

4 5 6 7

OS interface OS Hardware-OS interface Hardware

Interface between the above and OS Kernel supervisory mode services, file management and other functions like usermode processing services Interfaces to let the functions be executed on the given hardware of the system Processors, memories, buses, interfacing circuits, ports, physical devices, timers and buses for device networking.

Kernel:  Middle layer between application software and hardware is OS and an OS includes some or all the following structural units: 1. Kernel with file management and device management as part of the kernel in the given OS 2. Kernel without file management and device management as part of the kernel in the given OS  Basic structural unit of any OS in which the memory space of the functions, data and stack are protected from access by any call other than the system call  The services (functions) in the kernel is: Functions Actions Enables process creation, activation, running, blocking, Process management: creation to resumption, deactivation and deletion and maintains process deletion structure at a PCB Process management: process Enables process structure maintenance and its information at structure maintenance PCB Process management: processing Processing resource requests by processes made either by resource requests making calls that are known as system calls Process management: scheduling For eg. cyclic scheduling or priority scheduling mode Processes synchronizing by sending messages from one task to Process management: IPC another Services memory management Memory allocation, de-allocation and management. It also allocation and de-allocation restricts the memory access region for a task Management of creation, deletion, read( ), write( ) to the files File management on the secondary memory disk Device manager components for physical devices are: i) device drivers and device ISRs ii) resource managers for the devices. Device management Management of virtual device like pipe and socket is also provided Facilitate the use of number of physical devices like keyboard, Device drivers display system, disk, parallel port, network interface cards, network devices and virtual devices
Department of ECE, VKCET Page 17

08.716 Embedded System

Module 2

IO management Interrupt control mechanism ISR

Character or block IO management Facilitate running of the ISR and ISTs

Process management Process creation  At reset, an OS is initiated first and then a process called initial process is created.  OS is started and runs initial process, and processes are created hierarchically  Creation of process means specifying the resources for process and address spaces for the crated process, stack, data and heap, and the placing process initial information at a PCB  Processor manager allocates a PCB when it crates the process and later manages it  The PCB describes the following:

 Processor manager is the entity responsible for controlling a process execution  It enables process creation, activation, running, blocking, resumption, deactivation and deletion  It makes process to sequentially or concurrently execute or block when r=needing a resource and to resume when it becomes available  It implements the logical link to the resource manager for resource management  It allows specific resource sharing between specified processes only  It allocates resource as per resource allocation mechanism  It manages the processes and resources Memory Management  When a process is created, memory manager allocates the memory addresses to it by mapping the process address space  Memory manager of the OS has to secure, robust and well protected  There must be a control for no memory leaks and stack overflow  Memory management strategy are:
Department of ECE, VKCET Page 18

08.716 Embedded System

Module 2

1. 2. 3. 4. 5. 6. 7. 8.

Fixed blocks allocation Dynamic blocks allocation Dynamic page allocation Dynamic data memory allocation Dynamic address relocation Multiprocessor memory allocation Memory protection to OS functions Memory protection among tasks

 Memory manager manages the followings: 1. Use of memory address space by a process 2. Specific mechanism to share the memory space 3. Specific mechanism to restrict sharing of a given memory space 4. Optimization of the access periods of a memory by using an hierarchy of memories Device management  There are number of device drive ISRs for each device in a system and each driver function of a device calls separate ISR  Device manager effectively operates and adopts appropriate strategy for obtaining optimal performance for the devices. The manager coordinates between application process, driver and device controller
Department of ECE, VKCET Page 19

08.716 Embedded System

Module 2

 A process send a request to driver function by an interrupt using SWI, and the device driver provides action on calling and executing the ISR. The device manager polls the requests at the devices and actions occur as per priorities  OS device manager: a) Manages the physical as well as virtual devices like pipes, sockets etc b) Has three standard approaches: i) Programmed IOs by polling the service need from each device ii) Interrupts from the device driver ISR iii) DMA operation used by the devices to access the memory a) Has the following functions: 1. Device detection and addition 2. Device detection 3. Device allocation and registration 4. Detaching and deregistration 5. Restricting device to a specific process 6. Device sharing 7. Device control 8. Device access management: Manages any of the following access: i) Sequential access ii) Random access iii)semi-random access iv) Serial communication v) serial bits in to parallel during IO operations 9. Device buffer management 10. Device queue, circular queue or blocks of queue management 11. Device driver 12. Device drivers updating and uploading of a new device functions 13. Backup and restoration  Some set of command functions for device management are: i) create and open : For creating and creating if not created earlier and configuring and initializing the device. ii) write: Write into the device buffer or send output from the device. iii) read: Read from the device buffer or read input from the device. iv) ioctl: Specified device configured for specific functions and given specific parameters. v) close and delete: For de-registering the device from the system and for close if not closed earlier and detaching the device.  A device driver ISR uses several OS functions: i) intLock( ): To disable interrupt system ii) intUnlock( ): To enable interrupts iii) intConnect( ): To connect a C function to an interrupt vector iv) intContext( ): Finds whatever interrupt is called when ISR was in execution.
Department of ECE, VKCET Page 20

08.716 Embedded System

Module 2

File System Organization and Implementation:  File is a named entity on magnetic disc, optical disk or system memory  File contains data, character and tests or a mix of these  The functions for POSIX file system are:

 Similar to processor descriptor, a file has a data structure called file descriptor and it differ from one file manager to another  A typical file descriptor is shown below:

Department of ECE, VKCET

Page 21

Sign up to vote on this title
UsefulNot useful