<?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; puneet.bist</title>
	<atom:link href="https://www.emblogic.com/blog/author/puneet-bist/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>RS232 Connection &amp; Signals</title>
		<link>https://www.emblogic.com/blog/12/rs232-connection-signals/</link>
		<comments>https://www.emblogic.com/blog/12/rs232-connection-signals/#comments</comments>
		<pubDate>Tue, 31 Dec 2013 07:44:24 +0000</pubDate>
		<dc:creator><![CDATA[puneet.bist]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7978</guid>
		<description><![CDATA[Synchronous and Asynchronous Communications Synchronous Communication requires the sender and receiver to share the same clock. The sender provides a timing signal to the receiver so that the receiver knows when to &#8220;read&#8221; the data. Synchronous Communication generally has higher &#8230; <a href="https://www.emblogic.com/blog/12/rs232-connection-signals/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2></h2>
<h3>Synchronous and Asynchronous Communications</h3>
<p>Synchronous Communication requires the sender and receiver to share the same clock. The sender provides a timing signal to the receiver so that the receiver knows when to &#8220;read&#8221; the data. Synchronous Communication generally has higher data rates and greater error-checking capability. A printer is a form of Synchronous Communication.</p>
<p>Asynchronous Communication has no timing signal or clock. Instead, it inserts Start/Stop bits into each byte of data to &#8220;synchronize&#8221; the communication. As it uses less wires for communication (no clock signals), Asynchronous Communication is simpler and more cost-effective. RS-232/RS-485/RS-422/TTL are the forms of Asynchronous Communications.</p>
<p>RS-232C, EIA RS-232, or simply RS-232, refers to the same standard defined by the Electronic Industries Association in 1969 for serial communication.</p>
<p><strong>RS-232 Connections</strong></p>
<p>A straight-through cable is used to connect a DTE (e.g. computer) to a DCE (e.g. modem), all signals in one side connected to the corresponding signals in the other side in a one-to-one basis. A crossover (null-modem) cable is used to connect two DTE directly, without a modem in between. They cross transmit and receive data signals between the two sides and there are many variations on how the other control signals are wired.</p>
<p>The data transmission starts with a Start bit, followed by the data bits (LSB sent first and MSB sent last), and ends with a &#8220;Stop&#8221; bit.</p>
<p>The voltage of Logic &#8220;1&#8243; (Mark) is between -3VDC to -15VDC, while the Logic &#8220;0&#8243; (Space) is between +3VDC to +15VDC.</p>
<p>RS-232 connects the Ground of 2 different devices together, which is the so-called &#8220;Unbalanced&#8221; connection. An unbalanced connection is more susceptible to noise, and has a distance limitation of 50 ft (which is around 15 meters).</p>
<p>Handshaking is also called &#8220;Flow Control&#8221;. The main purpose of Handshaking is to prevent receiver overloading. By using Handshaking signals, receivers will be able to tell the sending device to pause data transmission if the receiver is overloaded. There are three types of handshaking: Software handshaking, Hardware handshaking and Both.</p>
<p>Software handshaking uses two control characters: XON and XOFF. The receiver sends these control characters to pause transmitter during communication. XON is decimal 17 and XOFF is decimal 19 in the ASCII chart. The drawback of Software handshaking is that these two control characters can not be used in data. This is quite important when you are transmitting Binary data as you might need to use these two codes in your data.</p>
<p>Hardware handshaking makes use of actual hardware lines, such as RTS/CTS, DTR/DSR, and DCD/RI (for modem).</p>
<p>The DTE 1 uses the DTR (Data Terminal Ready) signal to indicate it is ready for information exchange, whereas the DTE 2 uses the DSR signal for the same purpose. Before sending a data, the DTE 1 asks permission by setting its RTS output to high. No data will be sent until the DTE 2 grants permission by using the CTS line.  RTS/CTS are ON or OFF for each data transmission. DCD (Data Carrier Ready) is used by the modem when a connection has been established with remote equipment, while RI (Ring Indicator) is used by the modem to indicate a ring signal from telephone line.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/rs232-connection-signals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CHARACTER DRIVER</title>
		<link>https://www.emblogic.com/blog/12/character-driver-21/</link>
		<comments>https://www.emblogic.com/blog/12/character-driver-21/#comments</comments>
		<pubDate>Thu, 05 Dec 2013 16:17:02 +0000</pubDate>
		<dc:creator><![CDATA[puneet.bist]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7672</guid>
		<description><![CDATA[Kernel use the Driver to interact with hardware in an efficient manner. Driver is used as a module to support kernel functioning. Hence driver use kernel space. Each driver have an identical Major number range from 0-255 (8 bit number). &#8230; <a href="https://www.emblogic.com/blog/12/character-driver-21/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Kernel use the Driver to interact with hardware in an efficient manner. Driver is used as a module to support kernel functioning. Hence driver use kernel space. Each driver have an identical Major number range from 0-255 (8 bit number). However actual bits for major number is 12 bits. Each device attached to a driver have its own minor number. This major &amp; minor number constitute to a dev_t type variable which is unique for every device.</p>
<p>Since Driver are modules ,so they can be dynamically inserted &amp; removed from the kernel ,such driver are known as Loadable Kernel module. Character driver is used to transform data from user process . Character driver is able to transform 1 byte(character) thats why it&#8217;s called Character Driver.<br />
Each device is reprensented by a struct sculldev which has following members-<br />
struct scullqset sqset(used for making linked list )<br />
struct cdev (used for storing cdev structure)<br />
int quantum (number of bytes to be stored in each quantum)<br />
int qset (number of qset/linked list)<br />
int size (size of the device)</p>
<p>struct scullqset have two member -<br />
struct scullqset *next (for linking next scullqset)<br />
void ** data (for storing data)</p>
<p>For Module programming necessary header files needed to include are &lt;linux/kernel.h&gt; &amp; &lt;linux/module.h&gt; .Module is initialized by &#8216;module_init&#8217; macro which specifies the function for the initialization .Similarly &#8216;module_exit&#8217; macro specifies the exit of module. When a module is inserted using insmod &lt;module name&gt; ,function pointed by module_init() is executed &amp; rmmod &lt;module name&gt; executes the function pointed by module_exit(). Every operation performed in initialization function must be reversed in exit function.</p>
<p>For driver registration we may use one of the following functions:<br />
register_chrdev(unsigned int ,const char* ,const struct file_operations *)<br />
register_chrdev_region (dev_t ,unsigned ,const char * )<br />
alloc_chardev_region (dev_t * ,unsigned ,unsigned ,const char *)</p>
<p>In earlier version of linux module were inserted only by register_chrdev .In such case a driver is mapped with a file operations ,also minor no were not set by the developers. However register_chrdev_region &amp; alloc_chrdev_region were further used for driver registration. alloc_chrdev_region not only provide developer to assign starting minor no (2nd argument ) but also ,number of devices can be register with it (3rd argument). First argument stores the address of dev_t variable assigned by the function. Kernel search for the maximum major no which is free &amp; then assign for the major number. Successful registration of driver returns 0 .</p>
<p>A user defined struct sculldev is used to represent the device memory &amp; its metadata . In structure sculldev we have different members like int quantum,int size,int qset,int devsize ,struct cdev * &amp; struct scullqset * . Structure scullqset is used as a linked list for memory allocation &amp; then data storage for the device .So we allocate memory for this structure in kernel space ,using kmalloc . Memory allocated for structure depend on the size of structure &amp; also the number of devices. For kmalloc &lt;linux/slab.h&gt; must be included. As stated earlier , every operation in initialization must be reversed, hence we free the kernel space allocated for sculldev structure in cleanup function.</p>
<p>cdev_init is used to initialize device &amp; map it with the particular file operations routine . All the attributes for structure sculldev are set before cdev_add. cdev-add mapped the dev_t number (provided by alloc_chrdev_region) to the struct cdev type variable ,which is a member of structure sculldev . Each devices are removed using cdev_del function in cleanup function . For these function &lt;linux/cdev.h&gt; must be included.<br />
When a device is initialized we provide some routine operations mapped to struct file_operations f_ops . For eg., when application uses to open device using open call ,then driver execute the file operation routine mapped for the open .application open the device using a node made by mknod node c &lt;major no&gt; &lt;minor no&gt; &amp; they obtain a file descriptor for this particular node.<br />
While driver interacts with api using struct inode * &amp; struct file * . For each individual node there is unique inode * . For each api opening the node gets its individual file *.When Appplication opens a node it goes to an open routine,defined in module. In open routine struct sculldev pointer for particular devices is saved in the filep-&gt;private_data for further operations . This is implemented by container_of . In open routine f_flags in struct file &amp; Accessmode are checked,to see in which mode file is opened.<br />
Release routine is mapped to a function in module which is called when the application uses the close() call.<br />
When a application calls write () function, it calls a write routine of module( in struct file_operations). write routine is given as,<br />
ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);<br />
where first argument is file pointer ,second one is buffer to be write (given by the application in user space),third argument is number of bytes to be write &amp; last argument tells the current position of struct file ,i.e.,filep-&gt;f_pos. first of all strcut sculldev pointer is retrieved from filep-&gt;private_data , which was saved earlier in the open routine. After this struct scullqset is given memory using kmalloc.(first scullqset which is given the memory is mapped to the struct sculldev). Then the memory is allocated to void **data &amp; void *data[x]. (void **) data &amp; (void *)data[x] take the memory using kmalloc(sizeof(void *) * qset) &amp; kmalloc(sizeof(void *) * qunatum). Hence data[0...7] will be in sequence. Therefoe they can be accessed later. data[x] (quantum) stores number of bytes given in int quantum of struct sculldev. after qset*quantum bytes next scullqset is needed . Hence we use struct scullqset *next for the next scullqset &amp; the adderss of next scullqset is stored in the scullqset *next (member of the struct scullqset *sqset). Simillarly a linked list is formed with the base address of the list is stored in struct scullqset *sqset (member of struct sculldev). For user space buffer to store in kernel memory ,copy_from_user is used which is declared in &lt;linux/uaccess.h&gt; .<br />
Simillarly when read() is called by application ,module runs read routine,<br />
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);<br />
struct sculldev associated with the device is retieved by filep-&gt;private_data (as in write routine). as base address of struct scullqset is stored in member of strcut sculldev ,data can be retieved in the same way data was weittrn. copy_to_user is used to copy data from kernel space to user space.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/character-driver-21/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
