<?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; kamal babu</title>
	<atom:link href="https://www.emblogic.com/blog/author/kamal-babu/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>CHARACTER DEVICE DRIVER</title>
		<link>https://www.emblogic.com/blog/12/character-device-driver-6/</link>
		<comments>https://www.emblogic.com/blog/12/character-device-driver-6/#comments</comments>
		<pubDate>Fri, 06 Dec 2013 05:48:00 +0000</pubDate>
		<dc:creator><![CDATA[kamal babu]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7686</guid>
		<description><![CDATA[CHARACTER DEVICE DRIVER &#160; Device driver is a software implemented part of the kernel to provide a interface or interaction between hardware and file system , Device driver runs in kernel space as a part of kernel , which can &#8230; <a href="https://www.emblogic.com/blog/12/character-device-driver-6/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><span style="font-size: medium"><strong> CHARACTER DEVICE DRIVER</strong></span></p>
<p>&nbsp;</p>
<p><span style="font-size: small">Device driver is a software implemented part of the kernel to provide a interface or interaction between hardware and file system , Device driver runs in kernel space as a part of kernel , which can be load and unload on demand , so these type of device driver are known as dynamically loaded modules.</span></p>
<p><span style="font-size: small">Driver can be insert in kernel as a module using <strong>insmod </strong>and can be remove using <strong>rmmod</strong> these are two basic commands. Though in this article i am going to discuss about char driver that i have implemented.</span></p>
<p><span style="font-size: small"><strong>Implementation :</strong></span></p>
<p><span style="font-size: small">In my character driver first of all i registered my char driver using </span></p>
<p><span style="font-size: small"><strong>int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);</strong></span></p>
<p><span style="font-size: small">Unregistered using the follwing function &#8211; </span></p>
<p><span style="font-size: small"><strong>void unregister_chrdev_region(dev_t, unsigned); </strong></span></p>
<p><span style="font-size: small">Till here my driver got least available major number allocated by kernel you can see by doing</span></p>
<p><span style="font-size: small"><strong>cat /proc/devices</strong> after inserting the lkm. Now my next task was to add a number devices to my driver and provide them minor number i done this using macro called <strong>MKDEV(MAJOR, MINOR)</strong>. So till here i have allocated major and minor number and registered my char driver with my kernel .</span></p>
<p><span style="font-size: small">My next task was to create an application in user space and performing read write operation by that application at a specific node that was created by me in file system using node creating command .</span></p>
<p><span style="font-size: small"><strong>mknod node c mjorno minorno</strong></span></p>
<p><span style="font-size: small">this will create a character driver node in user space our application will be performing read and write operation on this node .</span></p>
<p><span style="font-size: small"><strong>Mapping System calls :</strong></span></p>
<p><span style="font-size: small"><strong>scull_open :</strong></span></p>
<p><span style="font-size: small">this was the main task to map the read and write operation of application to our driver so when the application gives a system call open() , then our mapped open starts and return a file descriptor to the application .</span></p>
<p><span style="font-size: small"><strong>int scull_open(struct inode *inodep, struct file *filep) ;</strong></span></p>
<p>&nbsp;</p>
<p><span style="font-size: small"><strong>scull_read : </strong></span></p>
<p><span style="font-size: small">After opening the device we need to perform read peration on that device so we need to map </span></p>
<p><span style="font-size: small">our read and write also by using this callback function.</span></p>
<p><span style="font-size: small"><strong>ssize_t scull_read(struct file *filep, char __user *ubuff, size_t size, loff _t *loff) ;</strong></span></p>
<p>&nbsp;</p>
<p><span style="font-size: small"><strong>scull_write : </strong></span></p>
<p><span style="font-size: small">After opening the device we need to perform write operation on that device so we need to map </span></p>
<p><span style="font-size: small">our read and write also by using this callback function.</span></p>
<p><span style="font-size: small"><strong>ssize_t scull_write(struct file *filep, char __user *ubuff, size_t size, loff _t *loff) ;</strong></span></p>
<p>&nbsp;</p>
<p><span style="font-size: small"><strong>scull_release :</strong></span></p>
<p><span style="font-size: small">When the application give the call to close the file descriptor then our mapped callback function starts.</span></p>
<p><span style="font-size: small"><strong>int scull_release(struct inode *inodep, struct file *filep) ;</strong></span></p>
<p>&nbsp;</p>
<p><span style="font-size: small"><strong>Other operations :</strong></span></p>
<p><span style="font-size: small">I implemented some more operations like ioctl operation used for debugging perpose :</span></p>
<p><span style="font-size: small"><strong>long scull_ioctl(struct file *, unsigned int, unsigned long) ;</strong></span></p>
<p><span style="font-size: small">And lseek opeartion were also implemented </span></p>
<p><span style="font-size: small"><strong>loff_t scull_llseek(struct file *, loff_t, int);</strong></span></p>
<p><span style="font-size: small"><strong>Device for operations :</strong></span></p>
<p><span style="font-size: small">Since we were not having any device so for that I have created a memory area on RAM that </span></p>
<p><span style="font-size: small">was tread as a device memory , I named it <strong>SCULL .</strong></span></p>
<p>Thank YOU</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/character-device-driver-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Client Server Communication using Linux and IPC</title>
		<link>https://www.emblogic.com/blog/11/client-server-communication-using-linux-and-ipc/</link>
		<comments>https://www.emblogic.com/blog/11/client-server-communication-using-linux-and-ipc/#comments</comments>
		<pubDate>Mon, 25 Nov 2013 11:55:57 +0000</pubDate>
		<dc:creator><![CDATA[kamal babu]]></dc:creator>
				<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7483</guid>
		<description><![CDATA[Project : Client Server Communication using Linux and IPC Overview : Hi all This project is regarding Inter-process Communication techniques in this project , Before explaining IPC i must let you know why we need these type of techniques . &#8230; <a href="https://www.emblogic.com/blog/11/client-server-communication-using-linux-and-ipc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong><span style="font-size: medium"> Project : Client Server Communication using Linux and IPC</span></strong></p>
<p><span style="font-size: medium">Overview : </span></p>
<p><span style="font-size: small">Hi all This project is regarding Inter-process Communication techniques in this project ,</span></p>
<p><span style="font-size: small">Before explaining IPC i must let you know why we need these type of techniques .</span></p>
<p><span style="font-size: small">In user space each process have its own separated address space. Suppose if any process wants to send any information or data to the another process which is running in different address space then we need these IPC techniques to communicate among the processes . </span></p>
<p><span style="font-size: small">I have learned following techniques and some of them was synchronization techniques .</span></p>
<p><span style="font-size: small">Like <span style="font-size: medium">Pipes , FIFO (known as named pipes also), message queues , shared memory </span>.</span></p>
<p><span style="font-size: small">And synchronization techniques was <span style="font-size: medium">Semaphore</span> and a little bit about <span style="font-size: medium">Mutex</span>.</span></p>
<p><span style="font-size: small">On the basis of these learned techniques I developed some projects , In my projects</span></p>
<p><span style="font-size: small">there was a main process that is i called Server program.</span></p>
<p><span style="font-size: small">To this main server there was three requesting clients and corresponding to these requesting clients there was three processing clients. Every requesting and every processing client was connected to the main server program .</span></p>
<p><span style="font-size: small">All the requesting clients was sending the request and data to the main server program for the request were very simple like to add ,subtract ,multiply the numbers . This data was getting by the server program continuously an the corresponding request sent to the processing clients .</span></p>
<p><span style="font-size: small">The processing was adding , subtracting, multiplying the data(numbers).</span></p>
<p><span style="font-size: small">And the corresponding results was sent to the server .the result sent by the processing clients further sent to requesting clients.</span></p>
<p><span style="font-size: small">For the communication between the process i used the techniques learned by me. As </span></p>
<p>i have explained in the beginning of my article , In my first project i used three pipes at requesting client and server side and same at server and processing clients side.</p>
<p>In my later projects i replaced pipes from FIFO and in the next projects FIFO was replaced by Message queues and shared memory .But when i was writing the code i faced some concurrency (synchronization) issues .To resolve these issues i used semaphores in all my projects .</p>
<p>Lets go inside my projects</p>
<p><strong><span style="font-size: medium">Project Internals :</span></strong></p>
<p><span style="font-size: small">First off all i created six pipe in server program for each child process these child process was created using a <span style="font-size: medium">process duplication</span> function that is <span style="font-size: medium">fork()</span> and now i was having six child process each having its own PID(process id ).Now my next task was to replace these child process from my own written requesting and processing clients .</span></p>
<p><span style="font-size: small">That i have done use process replacement system call <span style="font-size: medium">execv()</span> . In this call i passed read and write file descriptor obtained from <span style="font-size: medium">pipe(fd)</span> system call as an argument to the excev() call .</span></p>
<p><span style="font-size: small">I done the same for all clients by doing this my all requesting and processing clients was running independently .with the same PID of the child .</span></p>
<p><span style="font-size: small">Now my next task was to start communication between the processes .</span></p>
<p><span style="font-size: small">All the requesting clients were sending the data to the server using write file descriptor that was sent by the server ,to send data i used <span style="font-size: medium">write()</span> system call.</span></p>
<p><span style="font-size: small">Corresponding to this there was in the server a <span style="font-size: medium">read() </span>was waiting for the data.</span></p>
<p><span style="font-size: small">There was a condition of block on read ,until and unless writer writes the data on pipe.</span></p>
<p><span style="font-size: small">In the data writer was sending two operand and one operator .Server was checking the operand and in its data base maintained by the server and invoking the corresponding processing client .After invoking processing client the server was sending the data using write() system call .</span></p>
<p><span style="font-size: small">And was waiting for the result using read() system call .Here was also block on read condition.</span></p>
<p><span style="font-size: small">To prevent from <span style="font-size: medium">Zombies and oprphan</span> process and used a function <span style="font-size: medium">wait(pid)</span> .So the main server does not terminate until its child does not terminate properly.</span></p>
<p><strong><span style="font-size: medium">Issues faced :</span></strong></p>
<p><span style="font-size: small">I faced many issues some of them are listed below -</span></p>
<ul>
<li>I faced synchronization problem ,actually when ever i was sending the data from requesting clients it was reading back its first byte as the result , without waiting for the result .
<p>So in the server program i was getting only 2 byte of data as 1 byte we have lost .</p>
<p>So to block the requesting client until server read the requested data i used semaphores.</p>
<p>A famous synchronization technique.</li>
</ul>
<p>Thank You</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/11/client-server-communication-using-linux-and-ipc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
