<?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; Ashish Mishra</title>
	<atom:link href="https://www.emblogic.com/blog/author/ashish-mishra/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>Serial Port Communication</title>
		<link>https://www.emblogic.com/blog/12/serial-port-communication/</link>
		<comments>https://www.emblogic.com/blog/12/serial-port-communication/#comments</comments>
		<pubDate>Mon, 30 Dec 2013 08:32:42 +0000</pubDate>
		<dc:creator><![CDATA[Ashish Mishra]]></dc:creator>
				<category><![CDATA[Device Drivers]]></category>
		<category><![CDATA[Serial Port Driver]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7934</guid>
		<description><![CDATA[Serial Port Communication &#160; Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus where as in case of parallel communication, where several bits are sent as a whole, &#8230; <a href="https://www.emblogic.com/blog/12/serial-port-communication/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p align="CENTER"><span style="font-size: medium"><strong>Serial Port Communication</strong></span></p>
<p>&nbsp;</p>
<p align="JUSTIFY">Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus where as in case of parallel communication, where several bits are sent as a whole, on a link with several parallel channels. Serial communication is used for all long distance communication and most computer networks, where the difficulties like cost and synchronization make parallel communication difficult. Serial communication mostly refers to the RS-232 communication protocol where 9 pin connectors used for communication between 2 devices.</p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-size: medium"><strong>RS-232 Protocol:</strong></span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> RS-232 is the name for a standards for serial binary single-ended data and control signals connecting between </span><span style="font-family: Liberation Serif,serif"><span style="font-size: small">data terminal equipment and data circuit-terminating equipment. It is commonly used in computer serial ports. T</span></span><span style="font-size: small">he standard defines the electrical characteristics and signals timing, size and pin-out of connectors. This protocol defines the maximum open-circuit voltage of +/- 25 volts. Valid signals are in the range of +3 to +15 volts or the range ?3 to ?15 volts with respect to the ground. The range between ?3 to +3 volts is not a valid RS-232 level. For data transmission lines (TxD, RxD etc.) logic one is defined as a negative voltage and the condition is called </span><span style="font-size: small"><strong>mark</strong></span><span style="font-size: small">. Logic zero is +ve and the signal condition is termed space. Control signals have the opposite polarity: the active state is positive voltage and the inactive state is negative voltage.</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><a name="cite_ref-9"></a><span style="font-size: small">The following is commonly used RS-232 signals and pin:</span></p>
<ul>
<li>
<p align="JUSTIFY"><span style="font-size: small">Pin 1 = CT (Carrier Detect)</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-size: small">Pin 2 = RxD (Received Data)</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-size: small">Pin 3 = TxD (Transmitted Data)</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-size: small">Pin 4 = DTR (Data Terminal Ready)</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-size: small">Pin 5 = Ground</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-size: small">Pin 6 = DSR (Data Set Ready)</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-size: small">Pin 7 = RTS (Request To Send)</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-size: small">Pin 8 = CTS (Clear To Send)</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-size: small">Pin 9 = RI (Ring Indicator)</span></p>
</li>
</ul>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif">Serial Port base Address and IRQ Number:</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Serial Port has following base addresses and IRQ number associated with it:</span></p>
<ol>
<ol>
<ol>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif">3F8 4</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif">2F8 3</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif">3E8 4</span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif">2E8 3</span></p>
</li>
</ol>
</ol>
</ol>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif">The most commonly used UART IC in personal computers is pc16550D. It has 8 registers which are used for controlling the data transmission. They are:</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Register 0: Receiver Buffer Register(Read Only) &amp; Transmitter Register(Write Only). </span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> These buffer are used for receiving and transmitting data between two devices.</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Register 1: Interrupt Enable register</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> This register is used to enabling the interrupts. Setting bit 0-3 will enable Receive Data Available, Transmitter empty, Line Status Interrupt and Modem Status Interrupt.</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Register 2 : Interrupts Identification Register(R/O) &amp; FIFO Control Register (W/O)</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> IIR : If any interrupt has occurred, reading out this register will give the corresponding interrupt value.</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> FCR : This will enable the FIFO mode for UART i.e. it will store up-to 14 bytes of data before transmission.</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Register 3 : Line Control Register :</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> This register controls the transmission pattern of data. It is also used to set the baud rate of the UART by setting bit 7 and writing value in Divisor latch buffers.</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Register 4 : Modem Control Register:</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Used to start the handshaking mechanism between host and peripheral.</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Register 5: Line status Register :</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> This register is used to get the line status and if data is available. It is a read only register.</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Register 6: Modem Status Register:</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> This register shows the current state of data line when read.</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Register 7: Scratch Register</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> Divisor Latch (LS) &amp; (MS) : </span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> These register together forms a 16bit register when the bit7 of LCR register is set. They hold the multiplier value, to set the baud rate of the UART at desired rate.</span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif">Data Transmission:</span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"> First the transmitter will indicate the receiver by setting is MCR bit0 which will notify the receiver at MSR bit5 as pin 4 of transmitter is connected to pin 6 of receiver. After receiving the signal DSR, receiver will set its MCR bit1 which is connected to transmitter&#8217;s RTS pin and will notify the transmitter that he is ready to receive data. Then transmitter will put the data in Transmitter buffer and receiver will receive the data in receiver buffer.</span></p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/serial-port-communication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PARALLEL PORT</title>
		<link>https://www.emblogic.com/blog/12/parallel-port-7/</link>
		<comments>https://www.emblogic.com/blog/12/parallel-port-7/#comments</comments>
		<pubDate>Fri, 20 Dec 2013 08:18:38 +0000</pubDate>
		<dc:creator><![CDATA[Ashish Mishra]]></dc:creator>
				<category><![CDATA[Device Drivers]]></category>
		<category><![CDATA[Parallel Port Driver]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7769</guid>
		<description><![CDATA[PARALLEL PORT Parallel port is the mostly used for interfacing line printers. It was introduced by IBM in early 1980&#8242;s. Earlier there was no standard defined for parallel port interfacing. Every company has their own standards for interfacing parallel port. &#8230; <a href="https://www.emblogic.com/blog/12/parallel-port-7/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p align="CENTER"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"><span style="font-size: medium"><strong>PARALLEL PORT</strong></span></span></span></p>
<p align="LEFT">
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">Parallel port is the mostly used for interfacing line printers. It was introduced by IBM in early 1980&#8242;s. Earlier there was no standard defined for parallel port interfacing. Every company has their own standards for interfacing parallel port. Then came the IEEE 1284 standard (<strong>Standard Signaling Method for bi-directional parallel peripheral interface for personal computers</strong>)<strong>. </strong></span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">There are three base addresses defined for parallel port which can be used for interfacing parallel port. Those addresses are</span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"> 0&#215;378-0x37A</span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"> 0&#215;278-0x27A</span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"> 0x3BC-0x3BF</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">A parallel port is a 25 pin connector having 8 data pins, 5 status pins and 4 control pins and rest of the pins are connected to ground.</span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"> 2 &#8211; 9 = 8 Data Pins</span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"> 10,11,12,13,15 = Status Pins</span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"> 1, 14, 16,17 = Control Pins</span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"> 18 – 25 = Ground Pins </span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">This port will allow the input of up to 9 bits or the output of 12 bits at any one given time. </span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">There are 5 data transfer mode in parallel communication:</span></span></p>
<ol>
<ol>
<ol>
<li>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">Compatibility Mode: Data can be transferred only in one direction using data register.</span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">Nibble mode: Data can be transferred in both direction in half-duplex manner (only four bit at a time).</span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">Byte Mode: 8bit data can be transferred in both direction in half-duplex manner.</span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">EPP Mode. </span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">ECP Mode.</span></span></p>
</li>
</ol>
</ol>
</ol>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif">Compatibility, Nibble &amp; Byte modes use just the standard hardware available on the original Parallel Port cards while EPP &amp; ECP modes require additional hardware which can run at faster speeds, while still being compatible with the Standard Parallel Port. </span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><strong>Compatibility Mode:</strong></span></span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">This mode defines the protocol used by most PCs to transfer data to a printer. It is commonly called the Centronics mode and is the method utilized with the standard parallel port. In this mode, data is placed on the port&#8217;s data lines, the printer status is checked for that it is not Busy, and then a data Strobe is generated by the software to send the data to the printer</span></span></span></p>
<p align="JUSTIFY"><span style="color: #000000"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><br />
</span></span></span><strong><span style="color: #000000"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">Compatibility Mode steps:</span></span></span></strong></p>
<p align="JUSTIFY">
<ol>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><span style="color: #000000">Write the data to the data register</span> </span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><span style="color: #000000">Program reads the status register to check that the printer is not BUSY</span> </span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><span style="color: #000000">If not BUSY, then Write to the Control Register to assert the STROBE line</span> </span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><span style="color: #000000">Write to the Control register to de-assert the STROBE line</span> </span></span></p>
</li>
</ol>
<p align="JUSTIFY">To transfer one byte of data it requires four operation and at least as many additional instructions. The data transfer rate in this protocol is 150K bytes per second. This mode is for the forward channel only. This mode was included as a way to provide backward compatibility with the huge base of installed printers and peripherals. The other modes are used to provide the reverse channel and high performance communication links. Many of the integrated 1284 I/O controllers have implemented a mode that uses a FIFO buffer to transfer data with the Compatibility mode protocol. This mode is referred to as Fast Centronics or Parallel Port FIFO Mode. When this mode is enabled, data written to the FIFO port will be transferred to the printer using hardware generated strobes for the handshaking.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/parallel-port-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Threads</title>
		<link>https://www.emblogic.com/blog/12/introduction-to-threads/</link>
		<comments>https://www.emblogic.com/blog/12/introduction-to-threads/#comments</comments>
		<pubDate>Fri, 06 Dec 2013 05:47:46 +0000</pubDate>
		<dc:creator><![CDATA[Ashish Mishra]]></dc:creator>
				<category><![CDATA[Project 04: FTP based Client Server using Threads and Sockets]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7684</guid>
		<description><![CDATA[Introduction To THREADS Threads, like processes are a mechanism to allow a program to do more than one thing at a time. In Linux when a process is created, it already contains a thread, used to execute the main() function. &#8230; <a href="https://www.emblogic.com/blog/12/introduction-to-threads/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p align="CENTER"><strong>Introduction To THREADS</strong></p>
<p align="JUSTIFY">
<p align="JUSTIFY">Threads, like processes are a mechanism to allow a program to do more than one thing at a time. In Linux when a process is created, it already contains a thread, used to execute the main() function. Threads are implemented as lightweight process. <span style="font-size: small">A </span>process can have multiple threads of execution and they all share the same process address space and system state information. When a thread is created in a process, the new thread of execution gets its own stack but shares global variables, file descriptors, signal states. <span style="font-family: Liberation Serif,serif"><span style="font-size: small">When a program creates another thread, nothing is copied. The creating and the created thread share the same memory </span></span><span style="font-family: Liberation Serif,serif"><span style="font-size: small">space, file descriptors, and other system resources as the original. If one thread changes the value of a variable, for instance, the other thread will see the modified </span></span><span style="font-family: Liberation Serif,serif"><span style="font-size: small">value. Similarly, if one thread closes a file descriptor, other threads may not read from or write to that file descriptor. Because a process and all its threads can be executing </span></span><span style="font-family: Liberation Serif,serif"><span style="font-size: small">only one program at a time, if any thread inside a process calls one of the </span></span><span style="font-family: Liberation Serif,serif"><span style="font-size: small">exec </span></span><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> functions, all the other threads are ended.</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">Linux implements the POSIX thread api. All thread functions and data types are declared in the header file &lt;pthread.h&gt;. to use these library calls link the program with the threads library using -lpthread, as they are not included in standard C library.</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><strong>Thread Creation:</strong></span></span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> Each process is identified by a thread id of type pthread_t. Upon creation each thread executes a thread function. When this function returns, thread ends. Function to create a thread is </span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> pthread_create(pthread_t* thread, pthread_attr_t * attr, void *(*routine), (void *), void *arg);</span></span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> thread is a pointer to a pthread_t structure that will be initialized by the function. Later, this structure can be used to reference the thread.</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> Attr is a pointer to an optional structure pthread_attr_t. This structure can be manipulated using pthread_attr_*() functions. It can be used to set various attributes of the threads (detach policy, scheduling policy, etc.)</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> start_routine is the function that will be executed by the thread </span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> arg is the private data passed as argument to the start_routine function</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><strong>Thread Exit :</strong> </span></span></p>
<p align="JUSTIFY"><span><span style="font-size: x-small">A<span style="font-family: Liberation Serif,serif"><span style="font-size: small"> thread can exit by calling </span></span><span style="font-family: Liberation Serif,serif"><span style="font-size: small">pthread_exit</span></span><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> .This function may be called from within the thread function or from some other function called directly or indirectly by the thread function. The argument to </span></span><span style="font-family: Liberation Serif,serif"><span style="font-size: small">pthread_exit </span></span><span style="font-family: Liberation Serif,serif"><span style="font-size: small">is the thread’s return value. Syntax of pthread_exit is</span></span></span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> void pthread_exit(void *retval).</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><strong>Thread Joining :</strong></span></span></p>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">When the main() function exits, all threads of the application are destroyed. The pthread_join() function call can be used to suspend the execution of a thread until another thread terminates. This function must be called in order to release the resources used by the thread, otherwise it remains as zombie. Syntax of pthread_join is</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> int pthread_join(pthread_t thread, void **thread_return);</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"> where thread the thread for which to wait, that was filled by the pthread_create function call. Second argument point to the return value of the thread.</span></span></p>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><strong>Advantages of using threads:</strong></span></span></p>
<ul>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">Improves program performance.</span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">Reduce system overheads.</span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">Enables the better utilization of hardware in multi-core cpu&#8217;s.</span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">Less demanding on resources as compared to multiple processes.</span></span></p>
</li>
</ul>
<p align="JUSTIFY">
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small"><strong>Disadvantages :</strong></span></span></p>
<ul>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">Program complexity and requires very careful design.</span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">Debugging a multi-threaded application is a difficult task.</span></span></p>
</li>
<li>
<p align="JUSTIFY"><span style="font-family: Liberation Serif,serif"><span style="font-size: small">Deadlocks.</span></span></p>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/introduction-to-threads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Character Device Driver</title>
		<link>https://www.emblogic.com/blog/11/character-device-driver-5/</link>
		<comments>https://www.emblogic.com/blog/11/character-device-driver-5/#comments</comments>
		<pubDate>Mon, 25 Nov 2013 12:09:48 +0000</pubDate>
		<dc:creator><![CDATA[Ashish Mishra]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7521</guid>
		<description><![CDATA[Character Driver &#160; Device drivers are building blocks of a OS. In Linux there are three types of device driver i.e. Character Driver Block Driver Pipes Driver Device driver are used to make hardware do a specific job with some &#8230; <a href="https://www.emblogic.com/blog/11/character-device-driver-5/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p align="CENTER"><strong>Character Driver</strong></p>
<p>&nbsp;</p>
<p align="JUSTIFY">Device drivers are building blocks of a OS. In Linux there are three types of device driver i.e.</p>
<ul>
<li>
<p align="JUSTIFY">Character Driver</p>
</li>
<li>
<p align="JUSTIFY">Block Driver</p>
</li>
<li>
<p align="JUSTIFY">Pipes Driver</p>
</li>
</ul>
<p align="JUSTIFY">Device driver are used to make hardware do a specific job with some defined set of rules and they hide the working procedure of hardware from the outside world. Device drivers as implemented as loadable kernel module means you can add a drive at any instance of time.</p>
<p align="JUSTIFY">Character drivers are used to access streams of byte at one by one. Some example of char driver are text console, serial port, USB keyboard etc. Before working with driver, driver must be registered with kernel so that driver can be inserted as lkm module. Driver communicate using node in file-system.</p>
<p align="JUSTIFY">For using the char device, there should be one entry point which will start the driver and there should be one exit point which will be used to remove the driver from the list of installed modules. For this there are two macro&#8217;s defined in kernel for char driver. They are <strong>module_init()</strong> and <strong>module_exit()</strong>. They take the <strong>__init</strong> and <strong>__exit</strong> functions as there arguments. After this the lkm is inserted using the insmod command and lkm is removed using the rmmod command.</p>
<p align="JUSTIFY">To access the device using node,system provides the Major and Minor numbers. To get the Major and Minor numbers, the driver for lkm is registered with kernel using <strong>alloc_chrdev_region</strong>(if no major number is allocated) and <strong>register_chrdev_region</strong>(if major number for the device driver is already obtained). It takes the <strong>dev_t</strong> type variable, no of device, module name and starting minor number as argument and fills the dev_t type variable with the major number allocated to the device. dev_t is a 32 bit variable who&#8217;s <strong>upper 12 bit represents the major number</strong> and <strong>lower 20 bits represents the minor</strong> number. To get major and minor number separately kernel symbol table provides the two macro&#8217;s i.e. <strong>MAJOR()</strong> and <strong>MINOR()</strong> which takes the dev_t as argument. The major number is number provided to the device driver and the minor number is used to specify the specific device using the the driver. Device can be freed using the unregistered_chrdev_region which take the dev_t type as argument.</p>
<p align="JUSTIFY">Char device memory is accessed using the scull. Scull stands for simply character utility for loading localities. Scull is implemented as a link list. Scull is represents as</p>
<p align="JUSTIFY">struct scullqset</p>
<p align="JUSTIFY">{</p>
<p align="JUSTIFY">void **;</p>
<p align="JUSTIFY">struct scullqset *next</p>
<p align="JUSTIFY">};</p>
<p align="JUSTIFY">struct sculldev</p>
<p align="JUSTIFY">{</p>
<p align="JUSTIFY">struct scullqset *qset;</p>
<p align="JUSTIFY">//data</p>
<p align="JUSTIFY">};</p>
<p align="JUSTIFY">Sculldev contains the attribute of the devices like quantum size, qset size, device size, date size and some flag etc where as scullqset contains the data present in device. It has a void ** which is used to save data.</p>
<p align="JUSTIFY">Scull device is added to the modules using the <strong>cdev_init</strong> and <strong>cdev_add</strong>. cdev_init initialize the file operation that are gonna work on the device and cdev_add adds them into the module. cdev_add creates the node in file-system for the device. Every device, who uses driver is registered and added to kernel modules before any other operations. Modules are removed using <strong>cdev_del.</strong></p>
<p align="JUSTIFY">Every device provides some basic operations like open, close, read, write etc&#8230; these function are mapped to the standard functions in file_operation structure and are already added at the time cdev_add.</p>
<p align="JUSTIFY">When a device is opened, a special micro is used called CONTAINER_OF which creates a mapping for the outside memory device in form of scull. The obtained scull pointer is stored into private_data variable of the file_operation structure. After that the mode of open is checked, if opened in write-only mode, then previous mapping of the device is removed and cleaned.</p>
<p align="JUSTIFY">In write operation, sculldev is loaded from the file stream&#8217;s private_data. memory is allocated for the amount of data to be written. The write function uses the micro provided by the kernel to copy data from the user application using copy_from_user function. This function copies the data from user space to kernel space and put it into the device memory using scull. copy_from_user return the numbers of bytes not copied. After successful copy, the device attributes is updated.</p>
<p align="JUSTIFY">Read operation is also similar like write operation with difference is it uses copy_to_user function for reading the data from scull memory to user application.</p>
<p align="JUSTIFY">llseek operation is used to set the offset from where read or write operation is to be performed by updating the f_pos value.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/11/character-device-driver-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
