Thursday, 30 October 2014

platform device driver

Your references are good but lack a definition of what is a platform device. There is one on LWN. What we can learn from this page:
  1. Platform devices are inherently not discoverable, i.e. the hardware cannot say "Hey! I'm present!" to the software. Typical examples are i2c devices, kernel/Documentation/i2c/instantiating-devices states:
    Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level (at run time). Instead, the software must know (at compile time) which devices are connected on each I2C bus segment. So USB and PCI are not platform devices.
  2. Platform devices are bound to drivers by matching names,
  3. Platform devices should be registered very early during system boot. Because they are often critical to the rest of the system (platform) and its drivers.
So basically, the question "is it a platform device or a standard device?" is more a question of which bus it uses. To work with a particular platform device, you have to:
  1. register a platform driver that will manage this device. It should define a unique name,
  2. register your platform device, defining the same name as the driver.
Platform driver is for those devices that are on chip.
Not true (in theory, but true in practice). i2c devices are not onChip, but are platform devices because they are not discoverable. Also we can think of onChip devices which are normal devices. Example: an integrated PCI GPU chip on a modern x86 processor. It is discoverable, thus not a platform device.
Normal device driver are for those that are interfaced to the processor chip. before coming across one i2c driver.
Not true. Many normal devices are interfaced to the processor, but not through an i2c bus. Example: a USB mouse.
[EDIT] In your case, have a look to drivers/usb/host/ohci-pnx4008.c, which is a USB host controller platform device (Here the USB host controller is not discoverable, whereas USB devices, which will connect to it, are). It is a platform device registered by the board file (arch/arm/mach-pnx4008/core.c:pnx4008_init). And within its probe function, it registers its i2c device to the bus with i2c_register_driver. We can infer that the USB Host controller chipset talks to the CPU through an i2c bus.
Why that architecture? Because on one hand, this device can be considered a bare i2c device providing some functionalities to the system. On the other hand, it is a USB Host capable device. It needs to register to the USB stack (usb_create_hcd). So probing only i2c will be insufficient. Have a look to Documentation/i2c/instantiating-devices.

Wednesday, 29 October 2014

Difference between instance and object

I was wondering what is difference between instance and object?

ans.

An instance, in object-oriented programming (OOP), is a specific realization of any object. An object may be varied in a number of ways. Each realized variation of that object is an instance. The creation of a realized instance is called instantiation.

Each time a program runs, it is an instance of that program. In languages that create objects from classes, an object is an instantiation of a class. That is, it is a member of a given class that has specified values rather than variables. In a non-programming context, you could think of "dog" as a class and your particular dog as an instance of that class.




It is very simple but very important
Take a general example: what is the general meaning of object? its nothing but which occupies some space right....keep that in mind we now talk about Object in java or C++

example: here I am creating Object     Student std=new Student();
where Student is a Class and std is a Object because we Created a memory for std with the help of new keyWord it means it internally occupies some space in memory right thats y we call std as Object
if you won`t create memory for an object so we call that object as instance.

example: Student std;
here Student is a class and std is a instance(means a just a copy that class),with this we won`t do anything untill unless we create a memory for that.
Thats all about object and Instance :)

make: ****** empty variable name. Stop.

This is make file for rtdm

obj-m           := tut01-skeleton-drv.o
KDIR            := /lib/modules/$(shell uname -r)/build
PWD             := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
EXTRA_CFLAGS := -I$(KDIR)/include/xenomai -I$(KDIR)/include/xenomai/posix           $(ADD_CFLAGS)

all:     
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean

Note

-I had kept space between = and $ that caused this error. Remove the space and error would be solved

Make file
$=means value
#=number of

Sunday, 5 October 2014

UART drivers and application programming

Hello Friends,
                      Today is sunday I have got time to Hack UART and make my driver and application with linux.So lets start

Interfacing the Serial/RS232 Port

Introduction
-The Serial Port is harder to interface than the Parallel Port.

Advantages of serial communication over parallel communication
- Serial Cables can be longer than Parallel cables. The serial port transmits a '1'
as -3 to -25 volts and a '0' as +3 to +25 volts where as a parallel port
transmits a '0' as 0v and a '1' as 5v. Therefore cable loss is not going to be as much of a problem for serial cables than they are for parallel.
- You don't need as many wires than parallel transmission
-Microcontroller have built in serial communication interface.Hence it reduces the number for pin.In serial communication there are only transmitter and recevier.

PART-1
Hardware(PC) Properties:
-Devices which use serial cables for their communication have two categories
1)DCE(data communication equipment)e.g modem, TA adapter, plotter etc
2)DTE(data terminal equipment)e.g  Computer or Terminal.

Electrical specification of serial port in RS232C standard
1)A "Space" (logic 0) will be between +3 and +25 Volts.
2.A "Mark" (Logic 1) will be between -3 and -25 Volts.
3.The region between +3 and -3 volts is undefined.
4.An open circuit voltage should never exceed 25 volts. (In Reference to
GND)
5.A short circuit current should not exceed 500mA. The driver should be
able to handle this without damage. (Take note of this one!)

 -serial port comes in 2 sizes 9 and 25 pin


D-type-25 pin no.              D-type-9 Pin No.      Abbreviation
pin2                                     pin3                            TD                            transmit data
pin3                                     pin2                             RD                           receive data
pin4                                     pin7                             RTS                          request to send
pin5                                     pin8                             CTS                          clear to send
pin6                                     pin6                             DSR                         data set ready
pin7                                     pin5                             SG                           signal ground
pin8                                     pin1                             CD                          carrier detect
pin20                                   pin4                             DTR                        data terminal ready
pin22                                   pin9                             RI                             ring indicator


TD-serial data output
RD-serial data input
CTS-this line indiacates that modem is ready to exchange data
DCD-when modem detects a "carrier" from  the modem at the other end of phone line, this line becomes active
DSR-this tell the UART that the modem is ready to establish a link.
DTR-this tell the modem that the UART is ready to establish a link.
RTS- this informs the modem  that  the UART is ready to exchange data
RI-goes active when modem detects a ringing signal  from  the PSTN.

Null Modem:







DTE / DCE Speeds:
-People may talk about DTE-DTE speed and DCE-DTE speed
DCE-DTE speed between your modem and computer,sometimes refereed to as your terminal speed
-This runs faster than DCE-DCE speed is link between between modem knows as line speed
-Today most of modem should have data compression build into them .This has compression ratio of 1:4.
Thus this is why the DCE-DTE should be much higher than your modem's connection speed.

Flow Control
-Software flow control, sometimes expressed as Xon/Xoff uses two characters Xon and Xoff
-This type of flow control has the advantage that it doesn't require any more wires as the characters are sent via the TD/RD lines.
-However on slow links each character requires 10 bits which can slow communications down.
-Hardware flow control is also known as RTS/CTS flow control.
-Thus hardware flow control will not slow down transmission times like Xon-Xoff does. When the computer wishes to send data it takes active the Request to Send line. If the modem has room for this data, then the modem will reply by taking active the Clear to Send line and the computer starts sending data.

Types of UARTS (For PC's)
8250First UART in this series. It contains no scratch register. The 8250A was an
improved version of the 8250 which operates faster on the bus side.
8250A
This UART is faster than the 8250 on the bus side. Looks exactly the same to
software than 16450.
8250B
Very similar to that of the 8250 UART.
16450
Used in AT's (Improved bus speed over 8250's). Operates comfortably at
38.4KBPS. Still quite common today.
16550
This was the first generation of buffered UART. It has a 16 byte buffer, however it
doesn't work and is replaced with the 16550A.
16550A

Is the most common UART use for high speed communications eg 14.4K &
28.8K Modems. They made sure the FIFO buffers worked on this UART.
16650
Very recent breed of UART. Contains a 32 byte FIFO, Programmable X-On / X-
Off characters and supports power management.
16750
Produced by Texas Instruments. Contains a 64 byte FIFO.


Part-2:Serial Port's Register(PC's)
Name                       Address                   IRQ
COM 1                     3F8                           4
COM 2                     2F8                           3
COM 3                     3E8                           4
COM 4                     2E8                           3

-Just like the LPT ports, the base addresses for the COM ports can be read from the BIOS Data Area.

Start Address                          Function
0000:0400                              COM1's Base Address
0000:0402                              COM2's Base Address
0000:0404                              COM3's Base Address
0000:0406                              COM4's Base Address


Transmitter Holding Buffer
Receiver Buffer
Interrupt Enable Register
Divisor Latch High Byte
Interrupt Identification Register
FIFO Control Register
Line Control Register
Modem Control Register
Line Status Register
Modem Status Register
Scratch Register


 Communication
You can always make a user space program for communication of two computer with each other via UART cable.
Two commands are used for configuring UART in computer
1]setserial 
 2]stty
Study both command with man pages

Some command
$setserial -g /dev/ttys0
$setserial /dev/ttys0 uart 16550A
$echo "hello" > /dev/ttys0
$cat /dev/ttys0

stty -F /dev/ttys0 cstopb -cs8 raw -parenb ispeed 9600