<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EmbLogic &#187; mausam.devolia</title>
	<atom:link href="https://www.emblogic.com/blog/author/mausam-devolia/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Tue, 03 Mar 2020 13:00:06 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>An Introduction to Block Driver</title>
		<link>https://www.emblogic.com/blog/12/an-introduction-to-block-driver/</link>
		<comments>https://www.emblogic.com/blog/12/an-introduction-to-block-driver/#comments</comments>
		<pubDate>Mon, 30 Dec 2013 07:46:57 +0000</pubDate>
		<dc:creator><![CDATA[mausam.devolia]]></dc:creator>
				<category><![CDATA[Block Driver]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7919</guid>
		<description><![CDATA[An Introduction to Block Driver When Unix was written 25 years ago, its design was eclectic. One unusual design feature was that every physical device connected to the computer was represented as a file. This was a bold decision, because &#8230; <a href="https://www.emblogic.com/blog/12/an-introduction-to-block-driver/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p style="text-align: center" lang="en"><strong><span style="text-decoration: underline">An Introduction to Block Driver</span></strong></p>
<p lang="en">When Unix was written 25 years ago, its design was eclectic. One unusual design feature was that every physical device connected to the computer was represented as a file. This was a bold decision, because many devices are very different from one another, especially at first glance. Why use the same interface to talk to a printer as to talk to a disk drive?</p>
<p lang="en">The short answer is that while the devices are very much different, they can be thought of as having most of the same characteristics as files. The entire system is then kept smaller and simpler by only using one interface with a few extensions.</p>
<p lang="en">This is fine, except that it hides important differences between devices. For example, it is possible to read any byte on a disk at any time, but it is only possible to read the <strong>next</strong> byte from a terminal.</p>
<p lang="en">There are other differences, but this is the most fundamental one: Some devices (like disks) are <strong>random-access</strong>, and others (like terminals) are <strong>sequential-access</strong>. Of course, it is possible to pretend that a random-access device is a sequential-access device, but it doesn&#8217;t work the other way around.</p>
<p lang="en">A practical effect of the difference is that file systems can only be mounted on block devices, not on character ones. For example, most tapes are <strong>character</strong> devices. It is possible to copy the contents of a raw, quiescent (unmounted and not being modified) file system to a tape, but you will not be able to mount the tape, even though it contains the same information as the disk.</p>
<p>Most textbooks and tutorials start by explaining character devices, the sequential-access ones, because a minimal character device driver is easier to write than a minimal block device driver. My own <em>Linux Kernel Hackers&#8217; Guide</em> (the <em>KHG</em>) is written the same way.</p>
<p lang="en">My reason for starting this column with block devices, the random-access devices, is that the KHG explains simple character devices better than it does block devices, and I think that there is a greater need for information on block devices right now. Furthermore, <strong>real</strong> character device drivers can be quite complex, just as complex as block device drivers, and fewer people know how to write block device drivers.</p>
<p lang="en">I am not going to give a complete example of a device driver here. I am going to explain the important parts, and let you discover the rest by examining the Linux source code. Reading this article and the ramdisk driver (<strong>drivers/block/ramdisk.c</strong>), and possibly some parts of the KHG, should make it possible for you to write a simple, non-interrupt-driven block device driver, good enough to mount a filesystem on. To write an interrupt-driven driver, read <strong>drivers/block/hd.c</strong>, the AT hard disk driver, and follow along. I&#8217;ve included a few hints in this article, as well.</p>
<p lang="en"><a name="N0xa50890.0xb453b0"></a>The Heart of the Driver</p>
<p lang="en">Whereas character device drivers provide procedures for directly reading and writing data from and to the device they drive, block devices do not. Instead, they provide a single <strong>request()</strong> procedure which is used for both reading and writing. There are generic <strong>block_read()</strong> and <strong>block_write()</strong> procedures which know how to call the <strong>request()</strong> procedure, but all you need to know about those functions is to place a reference to them in the right place, and that will be covered later.</p>
<p lang="en">The <strong>request()</strong> procedure (perhaps surprisingly for a function designed to do I/O) takes no arguments and returns void. Instead of explicit input and return values, it looks at a queue of requests for I/O, and processes the requests one at a time, in order. (The requests have already been sorted by the time the <strong>request()</strong> function reads the queue.) When it is called, if it is not interrupt-driven, it processes requests for blocks to be read from the device, until it has exhausted all pending requests. (Normally, there will be only one request in the queue, but the <strong>request()</strong> procedure should check until it is empty. Note that other requests may be added to the queue by other processes while the current request is being processed.)</p>
<p lang="en">On the other hand, if the device is interrupt-driven, the <strong>request()</strong> procedure will usually schedule an interrupt to take place, and then let the interrupt handling procedure call <strong>end_request()</strong> (more on <strong>end_request()</strong> later) and then call the <strong>request()</strong> procedure again to schedule the next request (if any) to be processed.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/an-introduction-to-block-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>POINTERS IN C LANGUAGE</title>
		<link>https://www.emblogic.com/blog/12/7699/</link>
		<comments>https://www.emblogic.com/blog/12/7699/#comments</comments>
		<pubDate>Fri, 06 Dec 2013 10:39:17 +0000</pubDate>
		<dc:creator><![CDATA[mausam.devolia]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7699</guid>
		<description><![CDATA[POINTERS IN C LANGUAGE C is the most powerful programming language in the software development world. You can do whatever you want to do regarding development then go through the C language. You can&#8217;t even imagine the depth of C &#8230; <a href="https://www.emblogic.com/blog/12/7699/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p align="CENTER"><span style="text-decoration: underline"><strong>POINTERS IN C LANGUAGE</strong></span></p>
<p align="LEFT">C is the most powerful programming language in the software development world. You can do whatever you want to do regarding development then go through the C language. You can&#8217;t even imagine the depth of C language. And the most powerful tool of the C is Pointer. If you are master in the Pointer you can be the master of C language.</p>
<p align="LEFT">So, now your curiosity is some questions arising in your mind, like:</p>
<ol>
<li>
<p align="LEFT">Why Pointer are that much powerful tool?, When we can use the Pointers in our program?</p>
</li>
<li>
<p align="LEFT">How Pointer works?</p>
</li>
<li>
<p align="LEFT">How Pointers can increase the efficiency and decrease the length of our program?</p>
</li>
</ol>
<p align="LEFT"> Here are the answers of these question.</p>
<p align="LEFT"><span style="text-decoration: underline"><strong>Definition of Pointers</strong></span><strong>-: </strong>The simple definition of Pointer is the variable which holds the address in memory of some other variable. You can understand this like a arrow pointing towards your home and on the arrow your address is print means the arrow holding the address of your home, and your home is the variable. This Lehman definition will help you to understand what is pointer.</p>
<p align="LEFT"> The declaration of Pointer is as follows:</p>
<p align="LEFT">                   int <strong>*pointer</strong>;</p>
<p align="LEFT">Here&#8217;s the <strong>pointer</strong> is a variable which is integer type, and <strong>* </strong>sign is actually an operator to DE-reference a pointer. The only time it means &#8220;hey I&#8217;m a pointer&#8221; is during variable declaration.</p>
<p align="LEFT">And how it holds the address:</p>
<p align="LEFT">                int <strong>*pointer</strong>;</p>
<p style="text-align: left" align="LEFT">                int a;</p>
<p align="LEFT"><strong>             pointer </strong>= <strong>&amp;</strong>a;</p>
<p align="LEFT">Here, &amp; ampersand sign specify the address of the variable.</p>
<p align="LEFT">In the above expression, variable a is the integer type and <strong>pointer</strong> is holding the address of a with the help of <strong>&amp;</strong> sign. The data type int shows, 4 bytes of data the variable stored in.</p>
<p align="LEFT"><strong>Pointers in Array-:</strong></p>
<p align="LEFT">Arrays are continuous block of memory holds multiple objects and the type of objects are specified. An array variable is constant. You can’t assign a pointer to an array variable, even if the pointer variable actually points to the same or a different array. You also cannot assign one array variable to another. You can assign an array variable to a pointer though and that is where things get confusing. When assigning the array to the pointer we are actually assigning the address of the first element in the array to the pointer.</p>
<p align="LEFT"> int a[4] = {1,2,3};</p>
<p align="LEFT">int *pointer = a;</p>
<p align="LEFT">printf(&#8220;*pointer=%d\n&#8221;, *pointer);</p>
<p align="LEFT"> Firstly we initialize the array of integer type. After this we initialize the integer pointer and assign the array variable to it. Since the array variable actually is the memory address of the first element in the array, we have assigned the memory address of the first element in the array to the pointer. This is the same as doing int *pointer = &amp;a[0], explicitly stating the address-of the first element in the array.</p>
<p align="LEFT"> Notice the pointer has to be the same type as the elements of the array, unless the pointer is a void pointer.</p>
<p align="LEFT"><strong>Pointers to structure-:</strong></p>
<p align="LEFT">A pointer to a structure holds the memory address of the first memory of structures. And the pointers to structure must be declared to point to the structure type or be void type.</p>
<h2 align="LEFT"></h2>
<p align="LEFT">struct person {</p>
<p align="LEFT">int age;</p>
<p align="LEFT">   char *name;</p>
<p align="LEFT">};</p>
<p align="LEFT">struct person first;</p>
<p align="LEFT">struct person *ptr;</p>
<p align="LEFT"> first.age = 21;</p>
<p align="LEFT">char *fullname = &#8220;full name&#8221;;</p>
<p align="LEFT">first.name = fullname;</p>
<p align="LEFT">ptr = &amp;first;</p>
<p align="LEFT"> printf(&#8220;age=%d, name=%s\n&#8221;, first.age, ptr-&gt;name);</p>
<p align="LEFT"> On the first 6 lines we declare the struct person, a variable to hold a person struct, and a pointer to a person struct. Line 8 we assign a literal int to the age member. Line 9-10 we declare a char pointer to a literal char array and then assign that to the struct name member. Line 11 we assign a reference to the first person struct to our struct pointer variable.</p>
<p>Line 13 we print out the age and name of our struct instance. Notice the two different notations, the . and the -&gt;. With the age field we are accessing the struct instance directly and so we use the . notation. With the name field we are using our pointer to the struct instance and so we use the -&gt; notation. This would be the same as doing (*ptr).name where we first derefence the pointer and then access the name field.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/7699/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Character Driver</title>
		<link>https://www.emblogic.com/blog/11/character-driver-20/</link>
		<comments>https://www.emblogic.com/blog/11/character-driver-20/#comments</comments>
		<pubDate>Sat, 30 Nov 2013 08:44:16 +0000</pubDate>
		<dc:creator><![CDATA[mausam.devolia]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7605</guid>
		<description><![CDATA[CHARACTER DRIVER As we have seen always, there is a Driver which drives every machine automatically or manually. In the same way Driver plays most important role in LINUX. Before we move on to Character Driver lets talk a bit &#8230; <a href="https://www.emblogic.com/blog/11/character-driver-20/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p style="text-align: center"><span style="text-decoration: underline"><strong>CHARACTER DRIVER</strong></span></p>
<p>As we have seen always, there is a Driver which drives every machine automatically or manually. In the same way Driver plays most important role in LINUX. Before we move on to Character Driver lets talk a bit about Device Driver. Device driver is a computer program that simply controls the external devices like Mouse, Keyboard, Pen-drive, USB, Hard-disk, Printer, Scanner, Web-cam etc, Drivers basically depends on hardware and also the operating what you are using.</p>
<p>There are three types of Device Drivers in LINUX.<br />
1.Character Driver.<br />
2.Block Driver.<br />
3.Network Driver.</p>
<p>Character Driver: Character Driver simply means it Read or Write Character by Character only.<br />
There are some set of rules to write a Character Driver. Follow the rules and you can write a best Character Driver.</p>
<p><strong>Initialization</strong>: Firstly we have to initialize the kernel module, for which we have to use macro init_module(), this macro is use to initialize our kernel module. This function is called when the module is inserted into the kernel with help of command insmod. Now we have to end our module if we start it and for this we use at the end cleanup_module(). This function has called when module is remove from the kernel and the command is rmmod. These two are the most important part of kernel module. We are using some modules here which means we have to use header file #includethis header file needed by all kernel module. One more header file we use for the initialization of kernel loadable module is #includeand also we need to define two macros at the end of initialization and cleanup function are module_init(init_function); &amp; module_exit(cleanup_function); these are the macros that designates a module is initialization and clean up functions.</p>
<p>After written your first code now is the time to compile it, here in kernel module we need a Makefile for the compilation of our kernel module. After this write make and if you are lucky then you will see a successfully compiled module. After the compilation you can check the ko(Kernel object) file with the help of ls on the command line. Now enter into the modules with the help of command, cd modules.<br />
In the modules insert your kernel object file, write insmod filename.ko. To Check whether the file is insert successfully or not, give command dmesg by which you can see your inserted module. Once the module insert, now is the time to remove it with the help of command rmmod, and again enter dmesg to check whether the module removed successfully or not.</p>
<p>Make sure that there are no errors in your program, because when you work on the character driver is just like you are going to hack the kernel and one single mistake in your program may lead to reboot but reboot means you are lucky, because sometimes due to errors your system may crash. So its better to make your self good in system C.</p>
<p>The above process may have one alternate. Rather than go for that long you can do it by scripting as well. All you need to do just write a script and than change the mode of your scripting file into the executable file by giving command chmod called change mode.</p>
<p>Here the registration of your loadable kernel module is complete. We are making this module for a device, but now we are not using any physical hardware. In the place of this we will assign some memory inside our system which will act as device for our character driver and further testing we will do with the help of that created memory which will create with the help of scull(Simple Character Utility for Loading Localities). We are using scull because it isn&#8217;t hardware dependent. Scull using the space which is allocated by the kernel. And also the portability of scull is so easy across the computer architecture on which the linux runs. We allocate memory to to scull with the help of kmalloc.</p>
<p>Now once you allocate memory for scull you should check the major and minor number of your device. Major and Minor number are the most important part for any device access, to check the major and minor write ls -l. Here you can see the major &amp; minor number. Actually why these major and minor number concept we use, because the major number shows that which driver we have to use to acces particular hardware, because system already assign a unique major number for every device, all device files with same major number are controlled by same driver. Now the driver use minor number to distinguish between the various driver it controls. Driver may have same major number but have different minor number.</p>
<p>The command to check the major and minor number is-:<br />
printk(KERN_ALERT &#8220;Major no.:%d\n&#8221;, MAJOR(dev));<br />
printk(KERN_ALERT &#8220;Minor no.:%d\n&#8221;, MINOR(dev));</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/11/character-driver-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
