Driver Development of MISC Device AD7859L Based on Linux

Publisher:静默思考Latest update time:2018-02-26 Source: eefocusKeywords:Linux  MISC  AD7859L Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  1 Introduction

  In embedded systems, embedded processors based on ARM micro-core have become the mainstream of the market. With the widespread application of ARM technology, building an embedded operating system for ARM architecture has become a hot issue in the measurement industry. When adding a new external device in the LINUX operating system, you only need to add the corresponding driver for it. Introducing another way to write a driver, that is, using MISC class devices. In essence, it is also a character device. It can combine various types of user drive devices into one type, share a major device number, and distinguish them by different minor device numbers and device node names. It is convenient to manage these driver modules. Character-type driver device modules must allocate major device numbers, minor device numbers, and create device node names when mounting. When uninstalling the driver device, the device node name must also be deleted at the same time. By using MISC class devices, when mounting the device driver, there is no need to use the mknod command to allocate major device numbers, minor device numbers, and create device node names. After mounting with insmodl, only mdev-s can automatically assemble the device files in the /dev directory.

  2 AD7859L Pin Function Description and Registers

  The pin function description of AD7859L is shown in Table 1.

  

AD7859L pin function description www.elecfans.com


 

  AD7859L contains a control register, A/D conversion output register, status register, test register and 10-bit calibration register. The control register can only be written, the A/D conversion output register and status register can only be read, and the test register and calibration register are readable and writable.

  When writing data to the AD7859L, the data width must be 16 bits. When 16-bit data is written to the AD7859L, it can be written as a 16-bit word or as two 8-bit bytes, depending on the logic level on pin W/B. When W/B is connected to a high level, 16-bit data is transferred from DB0 to DB15, with DB0 being the lowest bit and DB15 being the highest bit. When W/B is connected to a low level, pin DB8/HBEN is enabled as the high byte, and two 8-bit bytes of data are transferred from DB0 to DB7, with DB0 being the lowest bit and DB7 being the highest bit. When writing data as two 8-bit bytes, the low byte must be written first, followed by the high byte. The highest two bits of the 16-bit data, ADDR1 and ADDR0, are encoded to determine which register to access, and the following 14 bits of data are written to that register. Table 2 shows the encoding distribution.

  When reading registers, you must first set the DB6 and DB7 bits of the control register, namely RDSLTO and RDSLTl. These two bits determine which register to access through encoding. At power-on, the initial value of these two bits is 00, so the register accessed by the read operation is the A/D converter output register. As with writing registers, either word mode or byte mode is possible. When reading the calibration register in byte mode, the low byte must be read first.

  3 AD7859L Driver

  The operating system generally provides device drivers to control specific hardware in order to establish an abstract interface between the application and the device, rather than the application directly operating the hardware. The device driver is actually the software that operates the hardware. It is a low-level hardware processing routine with the highest privilege level in the kernel, resident in memory, and shareable.

  Use MISC class devices to add AD7859L driver. The structure definition statement of AD7859L is as follows:

  

AD7859L structure definition statement www.elecfans.com

 

  

 

  The concept of platform was introduced in the 2.6 version of the kernel. When developing the underlying driver, the device address and interrupt vector number must be confirmed first. Add the address, interrupt number, and device node name of AD7859L in the kernel. When loading, the device driver first needs to call the entry function module_init(), which completes the initialization of the device driver, such as register setting, structure assignment, etc. The most important task is to register the device with the kernel. Open the device file in the application, and then use the ioctl() function to pass various control commands to the driver. After each A /D conversion is completed, an interrupt will be generated, and the interrupt response function will be called to write the converted data to the buffer. When the user needs to read the A/D converted data, the buffer data is read by calling the read() function. The driver structure is shown in Figure 1.

  

 

  3.1 Platform Resources

  In the 2.6 kernel, the resources of each device are described by the structure platform_dev IC e, which is defined in /include/linux/platform_device.h. The platform resources of the AD7859L driver are as follows. Add the following structure to the file /arch/arm/roach-s3c2410/devs.c.

  

 

  This macro is defined in the map.h file. The second group describes the interrupt vector number of the AD7859L device. Flags describes the resource type, and the device driver will obtain the corresponding resource information based on flags. Add the above s3c_device_ad7859ADC platform resource in the structure stat IC  struct platform_device* SMD k2410_devices[]__initdata. This structure is defined in the /arch/arm/mach—s3c2410/mach—smdk2410.C file.

  3.2 MISC equipment

  Create a miscdevice type device driver structure pointer in the AD7859L structure and add a misc type device. This structure is defined in /include/miscdevice.h.

  

Call misc_register(stmctmiscdev IC e*misc) function   in AD7859L driver's probe function to register misc type device. This function will register a misc type device for the kernel. If minor is set to MISCDYNAMIC_MINOR, the system will dynamically assign a minor device number to the device to distinguish other devices. The device registration and deregistration functions called by different types of devices are different. The deregistration function of misc type device is misc_deregister(struct miscdevice}misc). It returns zero if successful, otherwise it returns an error code.

 

  3.3 Application

  The application program under test is relatively simple. It uses the open function to open the device file and uses the ioctl function to set the sampling parameters of AD7859L, including which channels to select for sampling, the sampling time interval, the sampling method, etc. The read function is used to read the buffer data, and the close function is called to close the device file when the program exits.

  4 Conclusion

  AD7859L is a high-speed, low-power analog-to-digital converter with broad application prospects in the measurement industry. With the recognition of Linux, embedded Linux will be accepted by more and more people. By introducing the development of AD7859L device driver in MISC class device mode under Linux, everyone can understand the operation method of MISC type device more clearly.


Keywords:Linux  MISC  AD7859L Reference address:Driver Development of MISC Device AD7859L Based on Linux

Previous article:Visual safety reversing system based on embedded Linux operating system
Next article:Design of communication interface of measurement and control system based on ARM9S3C2440 processor

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号