Development and Design of System Device Driver Based on Embedded Linux Kernel

introduction

Linux is a free operating system that follows the POSIX standard. It has the extended features of BSD and SYSV. Compared with other operating systems, embedded Linux systems are being used as research hotspots for their excellent features such as being applicable to a variety of hardware platforms, high-efficiency and stable kernels, open source code, rich software, complete network communication and file management mechanisms, etc. More researchers use the Linux platform to develop their own products. Linux device drivers occupies a large proportion of the Linux kernel source code. From 2.0, 2.2 to 2.4 version of the kernel, the length of the source code is increasing day by day. In fact, the main reason is that the device drivers are increasing.

Development and Design of System Device Driver Based on Embedded Linux Kernel

The writing of device driver

The device driver is a part of the linux kernel and is the interface between the operating system kernel and the machine hardware. It consists of a set of functions and some private data, and is a bridge connecting the application and the specific hardware. A basic feature of Linux is that it abstracts the management of hardware devices. Each device in the system is represented by a special file. All hardware devices are treated like ordinary files and use the same standard system as the operating system to open, read, write, and close.

There are three main types of device files under the Linux operating system: block devices, character devices, and network devices. Character devices refer to devices that are not cached when accessed. The character device can be accessed like a file, and the character device driver is responsible for implementing these behaviors. The console and parallel port of the system are examples of character devices, and they can be described by "streaming". The block device is the host of the file system, such as a disk. Linux allows block devices to be read like character devices-allowing any number of bytes to be transferred at once. The result is that the character device and the block device read the same way. The network device is different from the character device and the block device. The upper layer it faces is not the file system but the network protocol layer, which accesses data through the BSD socket. Corresponding to devices are three types of device drivers, character device drivers, block device drivers, and network device drivers.

The structure of character device driver, block device driver and network device driver is different.

The file_operations structure that must be used in character device and block device drivers is defined in the linux source code linux/include/linux/fs.h. Each device driver implements some or all of the functions defined by this interface. As the kernel continues to upgrade, the file_operaTIons structure is getting bigger and bigger, and different versions of the kernel will be slightly different. file_operaTIons is defined as follows:

struct file_operaTIons{

int (* lseek) (struct inode *, struct file *, off_t, int); int (*release) (struct inode *, struct file *);

int (* read) (struct inode *, struct file *, char *, int); int (* fsync) (struct inode *, struct file *);

int (*write) (struct inode *, struct file *, const char *, int); int (* fasync) (struct inode *, struct file *, int);

int (* readdir) (struct inode, struct file, void *, dilldir); int (*check_media_change) (kdev_t dev);

int (*select) (struct inode *, struct file *, int, select_table *); int (* revalidate) (kdev_t dev); };

int (* ioctl) (struct inode *, struct file *, unsigned int, unsigned long);

int (*mmap) (struct inode *, struct file *, struct vm_area_struct *);

int (* open) (struct inode *, struct file *);

Only through open, release, read, write, ioctl, etc. of the device file, the application can access the character device and the block device. After the user defines the file_operaTIons structure, write the actual operation functions required by the device, and initialize the unnecessary operation functions with NULL. These operation functions will be registered to the kernel. When the application program performs file operations on the corresponding device files of the device When the time, the kernel will find the corresponding operation function and call it. If the operation function uses NULL, the operation function performs default processing.

For character devices, llseek (), read (), write (), ioctl (), open (), release () these functions are indispensable; for block devices, open (), release (), ioctl ( ), check_media_change(), revalidate() are indispensable.

The network device structure net_device is defined in includelinuxnetdevice.h, as shown below:

struct net_device

{

char name; int (*init) (struct

net_device *dev);

unsigned short flags; int (*open)

(Struct net_device *dev);

unsigned long base_addr; int

(*Stop) (struct net_device *dev)

unsigned int irq; int

(*Hard_start_xmit) (struct sk_buff *skb,

unsigned char dev_addr; struct

net_device *dev);

unsigned char addr_len; int

(*Set_mac_address) (struct net_device

unsigned long trans_start; *dev, void* addr);

...

}

After defining the net_device structure, write the operation function according to the actual situation. The hard_start_xmit() function is used to send data, and the set_mac_address() is used to set the network parameters.

When linux is initialized, the initialization function int device_init() will be called. This function includes the following:

Register the equipment used. Linux uses device numbers to identify character devices and block devices. The device number is divided into the main device number and the slave device number, and finally forms the device contact. The device node will be used when accessing the device drivers of character devices and block devices. Usually the major device number identifies the driver corresponding to the device, and most devices are "a major device number corresponds to a driver", such as: virtual console and serial port terminals are managed by driver 4. The minor device number is used by the kernel to determine the device pointed to by the device file. When registering character devices and block devices, the device number must be defined first.

The character device registration function is as follows:

int register_chrdev (unsigned int major, const char *name, struct file_oprations *fops);

Where major is the major equipment number.

Since access to the network device driver does not require a device node, its registration function is as follows:

int register_netdev (struct net_device *dev)

The interrupt used to register the device. Interruption plays an important role in modern computer architecture, and the operating system must provide programs with the ability to respond to interruptions. Generally, an interrupt handler is registered in the system. The operating system calls the driver's handler after the hardware interrupt occurs.

The functions used to register interrupts are as follows:

int request_irq (unsigned irq, void (*handler) (int, void*, struct pt_regs*), unsigned long flags, const char*device, void* dev_id);

Among them, irq is an interrupt vector; handler is an interrupt processing function; flags is a mask in interrupt processing; devices is a device name; dev_id is an id used in interrupt sharing.

When Linux does not use the device, it is necessary to call the clear function void_devicie_exit (), which corresponds to the initialization function, mainly:

Log off the device, the log off function of the character device is as follows:

int unregister_chrdev (unsigned int major, const char *name, struct file_oprations *fops);

Log off interrupt, the function used to log off interrupt is as follows:

int free_irq (unsigned irq, void (*handler) (int, void*, struct pt_regs*), unsigned long flags, const char*device, void* dev_id);

Release resources, module initialization and clearing functions adopt the form of module_init (device_init) and module_exit (device_exit)

Writing service subroutines

The subroutine that serves the I/O request is also called the upper part of the driver. This part of the call is the result of a system call. When this part of the program is being executed. The system still considers it to belong to the same process as the calling process. It's just that the user mode has become the core mode, and there is a running environment for the user program to make this system call. Therefore, functions related to the operating environment of the process, such as sleep, can be called in it.

The interrupt service routine is also called the lower part of the driver. In the Linux system. The interrupt service subroutine of the device driver is not directly called from the interrupt vector table, but the hardware interrupt is received by the Linux system, and then the interrupt service subroutine is called by the system. Interrupts can be generated when any process is running, so when the interrupt service routine is called. Can not rely on the state of any process, and can not call any function related to the operating environment of the process. Because the device driver generally supports several devices of the same type, when the system calls the interrupt service routine, it usually carries one or more parameters to uniquely identify the device requesting the service.

Use of device drivers

Compile the driver directly into the linux kernel

Copy the device driver to the relevant subdirectory of linux/drivers, for example, put the character device driver under linux/drivers/char.

Modify the Makefile of the subdirectory related to linux/drivers,

For example, obj-$(config_dev_driver) +=dev_driver.o, so when compiling the kernel, dev_driver.c will be compiled to generate dev_driver.o.

When recompiling the kernel, perform related configuration. For example, if you want to use AT91RM9200 UART, you need to configure as follows:

Character devices-"Serial drivers-" AT91RM9200 serial port support

Compile the driver into a driver module

There are two important functions in the device driver:

module_init (dev_init), module_exit (dev_exit)

Compile the driver dev_driver.c into a dynamic drive module such as dev_driver.o using the corresponding cross-compiler and compilation commands. Use the insmod command to install the driver module to the system. If there is no corresponding device file in the /dev directory, you can use mknod to create a device file. Use the rmmod command to uninstall the driver module, and delete the device file with the rm command.

Conclusion

The development of device drivers is one of the most complex programming tasks in the Linux environment. It needs to deal with hardware, which can easily cause system crashes and is difficult to debug. Mastering the development technology of device drivers will make the development of embedded Linux systems more rapid and effective.

0.8mm Female Pin Header

0.8mm ( 0.031") Female Header Connector
Category:Board To Board Connectors
Sub-Category:Pin Header Female
Type:0.8mm

0.8mm ( 0.031") Female Headers Overview
Whenever there is a need for fitting small-sized connectors in compact devices, the 0.8mm pitch female header, or sometimes referred to as header connector, is ideally suited for this application. Not only does this female header space-savvy, but it is also designed for vacuum pick and place that makes it suitable for high volume automated manufacturing.

Antenk offers these low profile, easy-install, SMT or THM miniature female connector plugs at high quality and affordable China-quoted price, for board-to-board connection, snuggly fitting the pins of a male header and acting as a receptacle.

Assembly and service is simple with either vertical (straight), elevated or at a right angle configuration/orientation, which can dissipate current of about 1.0 A or less in a tape and reel packaging. The filleted corners can also remove shadowing allowing optimization of LED output.

Also, the 0.8mm pitch female headers are made to work in Arduino boards, Arduino Pro and Arduino Mega with either single or double-row female headers, facilitating connections for programming and incorporation into other circuits. They have the perfect height for clearing the USB-B connector and great for stacking multiple shields.

Female header always called as [Header connector", Antenk provide widely range of header connector, from 2.54mm (.100″ inch) pitch to 0.8mm (0.031 inch) pitch. The number of pins (contacts) is from 2 to 40 pins per orw. There are three type: Straight (Dip Vertical), Right angle, SMT (surface mount).

If you can not find the items you interest from above items, welcome to contact us, and you will always get fully responsive from us.

Applications of 0.8mm Pitch Female Headers
Its small size is most suitable for PCB connections of small equipment and devices such as:
Arduino Boards
Architectural and sign lighting
Retail and display lighting
Fluorescent LED retrofit lighting
Cabinet or furniture lighting
Commercial / residential cove lighting
WiFi equipment
Gaming consoles,
Measurement instruments
Medical Diagnostic and Monitoring equipment
Communications: Telecoms and Datacoms
Industrial and Automotive Control and Test


Mount Type: Through-hole vs Surface Mount
At one side of this female header is a series of pins which can either be mounted and soldered directly onto the surface of the PCB (SMT) or placed into drilled holes on the PCB (THM).

Through-Hole (Poke-In)
Best used for high-reliability products that require stronger connections between layers.
Aerospace and military products are most likely to require this type of mounting as these products experience extreme accelerations, collisions, or high temperatures.
Useful in test and prototyping applications that sometimes require manual adjustments and replacements.
0.8mm vertical single row female header, 0.8mm vertical dual row female header, 0.8mm Elevated single row female header, 0.8mm Elevated dual row female Header, 0.8mm right-angle single row female header and 0.8mm right-angle dual row female header are some examples of Antenk products with through-hole mount type.

Surface-Mount
The most common electronic hardware requirements are SMT.
Essential in PCB design and manufacturing, having improved the quality and performance of PCBs overall.
Cost of processing and handling is reduced.
SMT components can be mounted on both side of the board.
Ability to fit a high number of small components on a PCB has allowed for much denser, higher performing, and smaller PCBs.
0.8mm Right-angle Dual Row female header, 0.8mm SMT Single row female header, 0.8mm SMT Dual row female header and 0.8mm Elevated Dual Row female Header are Antenk`s SMT female headers.

Soldering Temperature for 0.8mm Pitch Female Headers
Soldering SMT female connectors can be done at a maximum peak temperature of 260°C for maximum 60 seconds.

Orientation/Pin-Type: Vertical (Straight) and Right-Angle
0.8mm pitch female headers may be further classified into pin orientation as well, such as vertical or straight male header or right-angle female header.

Vertical or Straight Female Header Orientation

One side of the series of pins is connected to PCB board in which the pins can be at a right-angle to the PCB surface (usually called "straight" or [vertical") or.

Right-Angle Female Header Orientation
Parallel to the board's surface (referred to as "right-angle" pins).
Each of these pin-types have different applications that fit with their specific configuration.

PCB Connector Stacking
Profile Above PCB
This type of configuration is the most common way of connecting board-to-board by a connector. First, the stacking height is calculated from one board to another and measured from the printed circuit board face to its highest insulator point above the PCB.

Elevated Sockets/Female Headers
Elevated Sockets aka Stacked sockets/receptacles or Mezzanine are simply stacked female headers providing an exact distance requirement between PCBs that optimizes electrical reliability and performance between PCB boards.

Choosing this type of stacking configuration promotes the following benefits:
Connector Isolation - the contacts are shrouded preventing cable connection mishaps and good guidance for the mating header connectors.
For off-the-shelf wireless PCB module, stacking height is optimized with elevated sockets.
Offers superior strength and rigidity.
Polarisation prevents users from inverted insertion.

Single, Dual or Multiple Number of Rows
For a 1.0mm straight or vertical female header, the standard number of rows that Antenk offers ranges from 1 to 2 rows. However, customization can be available if 3 ,4 or n number of rows is needed by the customer. Also, the number of contacts for the single row is about 2-40 pins while for dual row, the number contacts may vary from 2-80 pins.

Pin Material
The pins of the connector attached to the board have been designed with copper alloy. With customer`s demand the pins can be made gold plated.

Custom 1.0mm Pitch Female Headers
Customizable 1.0 mm pitch female headers are also available, making your manufacturing process way faster as the pins are already inserted in the headers, insulator height is made at the right size and the accurate pin length you require is followed.
Parts are made using semi-automated manufacturing processes that ensure both precision and delicacy in handling the headers before packaging on tape and reel.

Tape and Reel Packaging for SMT Components
Antenk's SMT headers are offered with customizable mating pin lengths, in which each series has multiple number of of circuits, summing up to a thousand individual part number combinations per connector series.

The tape and reel carrier strip ensures that the headers are packaged within accurately sized cavities for its height, width and depth, securing the headers from the environment and maintaining consistent position during transportation.

Antenk also offer a range of custom Tape and reel carrier strip packaging cavities.

Female Header Connector,0.8Mm Female Pin Header,0.8Mm Female Header,0.8Mm Pcb Header, Pitch 0.8mm Board to Board Connectors

ShenZhen Antenk Electronics Co,Ltd , https://www.pcbsocket.com

Posted on