EmbLogic's Blog

pointer

pointer-> pointer is a variable that store logical address.it is the only way to express som computation and produces compact and efficient cod.it povides a very powerful tool

Posted in Uncategorized | Leave a comment

Dynamic memory allocation

DETAILS

The task of fulfilling an allocation request consists of locating a block of unused memory of sufficient size. Memory requests are satisfied by allocating portions from a large pool of memory called the heap. At any given time, some parts of the heap are in use, while some are “free” (unused) and thus available for future allocations. Several issues complicate implementation, such as external fragmentation, which arises when there are many small gaps between allocated memory blocks, which invalidates their use for an allocation request. The allocator’s metadata can also inflate the size of (individually) small allocations. This is managed often by chunking. The memory management system must track outstanding allocations to ensure that they do not overlap and that no memory is ever “lost” as a memory leak.

Posted in Uncategorized | Leave a comment

Dynamic memory allocation

Malloc-> It is used to allocate memory at run time in to the RAM. The prototype function is used is in stdlib.h,
Syntax-> ptr=int * (malloc) (sizeof bytes)

Posted in Uncategorized | Leave a comment

RTOS

A Real-Time Operating System (RTOS) is a computing environment that reacts to input within a specific time period. A real-time deadline can be so small that system reaction appears instantaneous. The term real-time computing has also been used, however, to describe “slow real-time” output that has a longer, but fixed, time limit. Learning the difference between real-time and standard operating systems is as easy as imagining yourself in a computer game. Each of the actions you take in the game is like a program running in that environment. A game that has a real-time operating system for its environment can feel like an extension of your body because you can count on a specific “lag time:” the time between your request for action and the computer’s noticeable execution of your request. A standard operating system, however, may feel disjointed because the lag time is unreliable. To achieve time reliability, real-time programs and their operating system environment must prioritize deadline actualization before anything else. In the gaming example, this might result in dropped frames or lower visual quality when reaction time and visual effects conflict.

Methods

An operating system is considered real-time if it invariably enables its programs to perform tasks within specific time constraints, usually those expected by the user. To meet this definition, some or all of the following methods are employed:

  • The RTOS performs few tasks, thus ensuring that the tasks will always be executed before the deadline
  • The RTOS drops or reduces certain functions when they cannot be executed within the time constraints (“load shedding”)
  • The RTOS monitors input consistently and in a timely manner
  • The RTOS monitors resources and can interrupt background processes as needed to ensure real-time execution
  • The RTOS anticipates potential requests and frees enough of the system to allow timely reaction to the user’s request
  • The RTOS keeps track of how much of each resource (CPU time per timeslice, RAM, communications bandwidth, etc.) might possibly be used in the worst-case by the currently-running tasks, and refuses to accept a new task unless it “fits” in the remaining un-allocated resources.

Objectives

An RTOS must respond in a timely manner to changes, but that does not necessarily mean that an RTOS can handle a large throughput of data. In fact in an RTOS, small response times are valued much higher than computing power, or data speed. Sometimes an RTOS will even need to drop data to ensure that it meets its strict deadlines. In essence, that provides us with a perfect definition: an RTOS is an operating system designed to meet strict deadlines. Beyond that definition, there are few requirements as to what an RTOS must be, or what features it must have. Some RTOS implementations are very complete and very robust, while other implementations are very simple, and suited for only one particular purpose. An RTOS may be either event-driven or time-sharing. An event-driven RTOS is a system that changes state only in response to an incoming event. A time-sharing RTOS is a system that changes state as a function of time

The Fundamentals

To most people, embedded systems are not recognizable as computers. Instead, they are hidden inside everyday objects that surround us and help us in our lives. Embedded systems typically do not interface with the outside world through familiar personal computer interface devices such as a mouse, keyboard and graphic user interface. Instead, they interface with the outside world through unusual interfaces such as sensors, actuators and specialized communication links. Real-time and embedded systems operate in constrained environments in which computer memory and processing power are limited. They often need to provide their services within strict time deadlines to their users and to the surrounding world. It is these memory, speed and timing constraints that dictate the use of real-time operating systems in embedded software.

Real-Time Kernel

The heart of a real-time OS (and the heart of every OS, for that matter) is the kernel. A kernel is the central core of an operating system, and it takes care of all the OS jobs:

  1. Booting
  2. Task Scheduling
  3. Standard Function Libraries

Now, we will talk about booting and bootloaders later, and we will also devote several chapters to task scheduling. So we should mention at least one thing about standard function libraries: In an embedded system, there is rarely enough memory (if any) to maintain a large function library. If functions are going to be included, they must be small, and important.

In an embedded system, frequently the kernel will boot the system, initialize the ports and the global data items. Then, it will start the scheduler and instantiate any hardware timers that need to be started. After all that, the Kernel basically gets dumped out of memory (except for the library functions, if any), and the scheduler will start running the child tasks.

Basic Kernel Services

In the discussion below, we will focus on the “kernel” – the part of an operating system that provides the most basic services to application software running on a processor. The “kernel” of a real-time operating system (“RTOS”) provides an “abstraction layer” that hides from application software the hardware details of the processor (or set of processors) upon which the application software will run.

Posted in Uncategorized | Leave a comment

Memory-Mapped I/O v/s Port-Mapped I/O

Memory-mapped I/O (MMIO) and port-mapped I/O (PMIO) (which is also called isolated I/O) are two complementary methods of performing input/output between the CPU and peripheral devices in a computer. An alternative approach is using dedicated I/O processors—commonly known as channels on mainframe computers—that execute their own instructions.

Memory-Mapped I/O:- Memory-mapped I/O (not to be confused with memory-mapped file I/O) uses the same address bus to address both memory and I/O devices – the memory and registers of the I/O devices are mapped to (associated with) address values. So when an address is accessed by the CPU, it may refer to a portion of physical RAM, but it can also refer to memory of the I/O device. Thus, the CPU instructions used to access the memory can also be used for accessing devices. Each I/O device monitors the CPU’s address bus and responds to any CPU access of an address assigned to that device, connecting the data bus to the desired device’s hardware register. To accommodate the I/O devices, areas of the addresses used by the CPU must be reserved for I/O and must not be available for normal physical memory. The reservation might be temporary—the Commodore 64 could bank switch between its I/O devices and regular memory—or permanent.

Port-Mapped I/O:- Port-mapped I/O often uses a special class of CPU instructions specifically for performing I/O. This is found on Intel microprocessors, with the IN and OUT instructions. These instructions can read and write one to four bytes (outb, outw, outl) to an I/O device. I/O devices have a separate address space from general memory, either accomplished by an extra “I/O” pin on the CPU’s physical interface, or an entire bus dedicated to I/O. Because the address space for I/O is isolated from that for main memory, this is sometimes referred to as isolated I/O.

Posted in Parallel Port Driver | Leave a comment

linklist

I have used malloc function in linklist for allocating dynamic memory to the pointers.In linklist nodes are at random locations.

Posted in Uncategorized | Leave a comment

Serial Vs Parallel Port communication, which one is faster and better ?

The communication links across which computers—or parts of computers—talk to one another may be either serial or parallel. A parallel link transmits several streams of data (perhaps representing particular bits of a stream of bytes) along multiple channels (wires, printed circuit tracks, optical fibres, etc.); a serial link transmits a single stream of data.

At first sight it would seem that a serial link must be inferior to a parallel one, because it can transmit less data on each clock tick. However, it is often the case that serial links can be clocked considerably faster than parallel links, and achieve a higher data rate. A number of factors allow serial to be clocked at a greater rate:

Clock skew between different channels is not an issue (for unclocked asynchronous serial communication links)
A serial connection requires fewer interconnecting cables (e.g. wires/fibres) and hence occupies less space. The extra space allows for better isolation of the channel from its surroundings
Crosstalk is less of an issue, because there are fewer conductors in proximity.
In many cases, serial is a better option because it is cheaper to implement. Many ICs have serial interfaces, as opposed to parallel ones, so that they have fewer pins and are therefore less expensive

Posted in Uncategorized | Leave a comment

Version Control System

A version control system allows you to track the history of a collection of files and includes the functionality to revert the collection of files to another version. Each version captures a snapshot of the files at a certain point in time. The collection of files is usually source code for a programming language but a typical version control system can put any type of file under version control.

The collection of files and their complete history are stored in a repository.

The process of creating different versions (snapshots) in the repository is depicted in the following graphic. Please note that this picture fits primarily to Git, other version control systems like CVS don’t create snapshots but store file deltas.

Posted in Uncategorized | Leave a comment

driver of write from the application..

—————————-
revision 1.15    locked by: root;
date: 2014/03/01 11:19:07;  author: root;  state: Exp;  lines: +5 -0.
Testing……….
—————————-
revision 1.14
date: 2014/03/01 11:13:18;  author: root;  state: Exp;  lines: +15 -7
The copy_from_user() function is used to copy a block of data from user space into the kernel buffer.copy_from_user() function contains 3 arguments:
1.A destination buffer,
2.A source buffer,and
3.length in bytes.
—————————-
revision 1.13
date: 2014/03/01 11:06:21;  author: root;  state: Exp;  lines: +2 -1
Done memset().
Testing the code…..
—————————-
revision 1.12
date: 2014/03/01 11:01:16;  author: root;  state: Exp;  lines: +54 -5
create_quantums() function that will create the required number of quantums.
Kmalloc() is used to allocate memory for each quantum. No. of quantums are dependent on how many number of bytes we are writing from user space.
Filling the memory allocated using kmalloc() with memset() so that it does not contain any garbage.
—————————-
revision 1.11
date: 2014/03/01 10:39:39;  author: root;  state: Exp;  lines: +1 -0
memset() function is used to fill the memory allocated for the qset array to ”.
—————————-
revision 1.10
date: 2014/03/01 10:36:59;  author: root;  state: Exp;  lines: +14 -4
Using kmalloc() memory is allocated to the required number of qsets , The memory allocated for qset depends upon the architecture of the OS, if the architecture is of 64 bytes then each qset required 8 byte of memory . and 4 bytes for 32 bit OS.Checking whether it is working fine or not.
—————————-
revision 1.9
date: 2014/03/01 10:26:27;  author: root;  state: Exp;  lines: +36 -2
Implemented create_scullqset() function.Now checking the number of qsets that needs to created by using the size argument of the chardev_write().After determining the number of qsets that needs to be created create_qset() function is called.
—————————-
revision 1.8
date: 2014/03/01 10:07:44;  author: root;  state: Exp;  lines: +2 -1
memset() function to clear the garbage ” .
—————————-
revision 1.7
date: 2014/03/01 10:04:21;  author: root;  state: Exp;  lines: +10 -0
Allocating memory for 1 scullqset using kmalloc
—————————-
revision 1.6
date: 2014/03/01 09:56:22;  author: root;  state: Exp;  lines: +22 -2
After finding out the number of scullqsets,create_scullqset() function is called to create the specified number of scullqsets.

Posted in Uncategorized | Leave a comment

What is ELF file format

It is Extensible linking format.

It was chosen as standard binary file format for Unix like system .

It is extensible and flexible by design so it is used in many operating systems and on many different platform.

 

Posted in Uncategorized | Leave a comment

FUNCTIONS

A function is a self contained block of statements that have predefined meanings.you can  divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division usually is so each function performs a specific task.

A function declaration tells the compiler about a function’s name, return type, and parameters. A function definition provides the actual body of the function.

Defining a Function:

return_type function_name( parameter list )

{ body of the function }

  • Return Type: A function may return a value. The return_type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.
  • Function Name: This is the actual name of the function. The function name and the parameter list together constitute the function signature.
  • Parameters: A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.
  • Function Body:The function body contains a collection of statements that define what the function does.
  • example of function
  • #include <stdio.h>
    
    int mult ( int x, int y );
    
    int main()
    {
      int x;
      int y;
    
      printf( "Please input two numbers to be multiplied: " );
      scanf( "%d", &x );
      scanf( "%d", &y );
      printf( "The product of your two numbers is %d\n", mult( x, y ) );
      getchar(); 
    }
    
    int mult (int x, int y)
    {
      return x * y;

 

 

Posted in Uncategorized | Leave a comment

how c convert program into executable

After writing the programme it is saved with .c name. During its execution code file gets converted into executable in four different steps.Firstly c code is preprocessed and get converted into .i file. Then .i file is compiled and get converted into .s file. This .s file is assembled and converted into .o file which is our object code. Finally linker convert the .o file into .c file , then loader loads all the executable files with it and our output as ./a.out is generated.

Posted in Uncategorized | Leave a comment

link_list using pop up menu

RCS file: linklist.c,v
Working file: linklist.c
head: 1.2
branch:
locks: strict
root: 1.2
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;    selected revisions: 2
description:
created linklist
inserted nodes at the end
inserted nodes at the beginning
—————————-
revision 1.2    locked by: root;
date: 2014/03/03 05:55:57;  author: root;  state: Exp;  lines: +2 -2
created a function for deleting a node.
—————————-
revision 1.1
date: 2014/03/03 05:54:43;  author: root;  state: Exp;
Initial revision

Posted in Data Structures with C, Uncategorized | Leave a comment

how to interpret complex declarations in C

Complicated declarations in C

Most of the times declarations are simple to read, but it is hard to read some declarations which involve pointer to functions. For example, consider the following declaration from “signal.h”.

void (*bsd_signal(int, void (*)(int)))(int);

Let us see the steps to read complicated declarations.

1) Convert C declaration to postfix format and read from left to right.
2) To convert experssion to postfix, start from innermost parenthesis, If innermost parenthesis is not present then start from declarations name and go right first. When first ending parenthesis encounters then go left. Once whole parenthesis is parsed then come out from parenthesis.
3) Continue until complete declaration has been parsed.

Let us start with simple example. Below examples are from “K & R” book.

1)  int (*fp) ();

Let us convert above expression to postfix format. For the above example, there is no innermost parenthesis, that’s why, we will print declaration name i.e. “fp”. Next step is, go to right side of expression, but there is nothing on right side of “fp” to parse, that’s why go to left side. On left side we found “*”, now print “*” and come out of parenthesis. We will get postfix expression as below.

  fp  *  ()  int

Now read postfix expression from left to right. e.g. fp is pointer to function returning int

Let us see some more examples.

2) int (*daytab)[13]

Postfix : daytab * [13] int
Meaning : daytab is pointer to array of 13 integers.

3) void (*f[10]) (int, int)

Postfix : f[10] * (int, int) void
Meaning : f is an array of 10 of pointer to function(which takes 2 arguments of type int) returning void

4) char (*(*x())[]) ()

Postfix : x () * [] * () char
Meaning : x is a function returning pointer to array of pointers to function returnging char

5) char (*(*x[3])())[5]

Postfix : x[3] * () * [5] char
Meaning : x is an array of 3 pointers to function returning pointer to array of 5 char’s

6) int *(*(*arr[5])()) ()

Postfix : arr[5] * () * () * int
Meaning : arr is an array of 5 pointers to functions returning pointer to function returning pointer to integer

7) void (*bsd_signal(int sig, void (*func)(int)))(int);

Postfix : bsd_signal(int sig, void(*func)(int)) * (int) void
Meaning : bsd_signal is a function that takes integer & a pointer to a function(that takes integer as argument and returns void) and returns pointer to a function(that take integer as argument and returns void)

Posted in Data Structures with C | Leave a comment

Linklist using pop-up menu to create new linklist and inserting nodes at the end ,beginning of linklist

RCS file: linklist28_2.c,v
Working file: linklist28_2.c
head: 1.3
branch:
locks: strict
	root: 1.3
access list:
symbolic names:
keyword substitution: kv
total revisions: 3;	selected revisions: 3
description:
created linklist using functions.
created insert at the end of linklist function.
----------------------------
revision 1.3	locked by: root;
date: 2014/03/01 23:04:11;  author: root;  state: Exp;  lines: +16 -0
created delete function.
----------------------------
revision 1.2
date: 2014/03/01 19:54:09;  author: root;  state: Exp;  lines: +15 -5
entered insert node at beginning function.
----------------------------
revision 1.1
date: 2014/03/01 19:24:20;  author: root;  state: Exp;
Initial revision
=============================================================================
Posted in Data Structures with C, Uncategorized | Tagged | Leave a comment