Development of the ad7854 driver for Windows CE. net

Source: Internet
Author: User
Development of the AD7854 driver for Windows CE.net
[Date:] Source: MCU and Embedded System Application Author: Zhou yijunjin Zhenxing, Southeast University [Font:Large Medium Small]

 

Introduction
AD7854 is a high-speed, low-power 12-bit parallel interface analog-to-digital conversion chip. Its operating voltage range is 3 ~ 5 V, the sampling frequency is up to 200 kHz. Because the power consumption of AD7854 is 5.4 mW in normal working mode and 3.6 μW in power-saving mode, it is widely used in portable devices. The AD7854 features self-calibration and system calibration to ensure accurate operation. The AD7854 contains an on-chip sampling and holding circuit and an on-chip reference voltage (2.5 V), simplifying the peripheral circuit design. Currently, a large number of embedded operating systems are introduced in advanced portable devices to manage system resources. Therefore, the development of hardware device drivers has become an important task of building a portable system. In this paper, the AD7854 driver program based on Windows CE.net is developed with S3C2410 as the processor. The implementation process and related content of the A137854 stream interface driver program under Windows CE.net are described in detail.

Expansion Design of 1 AD7854 and S3C2410
To ensure that AD7854 completes sampling and modulus conversion under the control of S3C2410, the interface circuit must be properly designed. AD7854 is a 12-bit Parallel analog-to-digital conversion chip, and S3C2410 is a 32-bit microprocessor. Therefore, the AD7854 conversion result can be read in one read operation. However, read operations on the AD7854 calibration register and write operations on each register require two read or write operations. Therefore, use two read/write operations to complete the operation on AD7854, that is, use only the low 8-bit data line of AD7854 as the data transmission channel.
To improve the drive capability of S3C2410, a bidirectional data buffer 74LVCl6245 is added between S3C2410 and peripherals. The principle 1 of the designed A/D conversion interface circuit is shown in.

2 WindOWS CE. Ret Device Driver Introduction
Windows CE.net has two main device driver models: local device driver and streaming interface device driver. Different driver models can only be differentiated through their software interfaces, rather than the devices they apply. The driver model determines the software interface it outputs.
Local device drivers are suitable for devices integrated into Windows CE.net platforms, such as generic LED Drivers and power drivers. Each local device driver has specific requirements and special purposes. Microsoft provides a custom interface to support internal device drivers. Generally, only OEM developers are interested in the driver of the local device, while independent hardware vendors only develop additional hardware drivers. The Windows CE.net platform builder (platform builder) provides samples of local device drivers. You can consider applying samples of local device drivers to your own platform, you do not need to develop your own local driver from the ground up.
The stream interface device driver is a general type of device driver. It is a user-level dynamic DLL used to export a set of fixed functions, called "stream interface functions ". Applications can access these interface functions through file system interface functions (APIS) to call drivers and drive hardware devices. In the stream interface driver, the driver abstracts peripherals into a file, and the application uses the API provided by the operating system to access peripherals. The stream interface driver supports almost any type of external devices that can be connected to the Windows CE.net platform, such as printers and modems. The AD7854 driver introduced in this article also adopts the stream interface driver model, which belongs to the category of Stream interface driver. The architecture 2 of the stream interface device driver is shown in.

3 AD7854 Driver Design and Implementation
According to the hardware circuit shown in Figure l, AD7854 is directly mapped to the system memory, and its physical address is Oxl0000000. Therefore, the driver of the device can be a single-chip stream interface device driver model. At the same time, S3C24lO uses an interrupted method to read the AD7854 Conversion Result and starts the next conversion. Therefore, the development of A/D driver consists of two parts: the kernel part and the stream interface function part. The kernel completes interrupt processing, including switching from physical interruptions to logical interruptions, enabling and disabling interruptions, and awakening interrupt service threads; the stream interface function implements the read and write operations on A137854 by implementing the interface functions provided by Windows CE.net.
3.1 AD7854 Interrupt Processing in WindOWS CE
The kernel mainly modifies the interrupt-related kernel files in Windows CE.net to map physical interruptions to logical interruptions. As shown in figure 1, AD7854 occupies External Interrupt 0 (EINTO ). To enable the operating system to handle external interrupt O, its kernel code for interrupt processing must be modified. The main modified Kernel File is as follows:
① Modify the % WIN (2ER () 0 T % \ PLATFORM \ SMDK2410 \ INC \ oalintr. h file;
② Modify the OEMInterrupt Han-dler () function in the % WINCEROOT % \ PLATFORM \ smdk2410 \ kernel \ hal \ arm \ armint. c file;
③ When the interrupt service thread (IST) calls functions such as InterruptEnable (), InterruptDisable (), and InterruptDone () to operate on the interrupt, the system kernel calls OEMInterTuptEnable (),() EMInter-ruptDisable () and () EMInterruptDone () are used to set the interrupt register to enable, disable, and complete interrupt operations. Modify the three OEM functions by modifying the % WINCERO0T % \ PLATFORM \ smdk2410 \ kernel \ hal \ cfw. c file.
To modify the Kernel File, refer to the specific implementation of the kernel file function. After modifying the Windows CE.net Kernel File, The ing from physical interruption EINTO logical interrupt number SYSINTR_ADC is completed. Now, you can use the API functions provided by Windows CE.net to perform zero physical interruption operations by processing the logical interrupt SYSINTR_ADC.
3.2 Implementation of the stream interface function of AD7854
The stream interface driver is essentially a dynamic link library. In Windows CE.net, there are 10 stream interface functions. These stream interface functions do not need to have specific implementation code. The key is to complete the corresponding interface functions according to the specific workflow of the device. The driver of AD7854 developed in this design mainly implements the following interface functions: XXX_Deinit, XXX_Init, XXX_Open, XXX_Close, XXX_Read, and XXX_Write. XXX is the prefix of the device file name.
The driver of the analog-to-digital conversion chip is used. Therefore, the prefix is named "ADC" here ". The following describes the development process of the AD7854 driver in the Platform Builder development environment.
First, in. In the development environment of Platform Builder4.2, a wce Dynamic-Link Library Project is created for the driver of AD7854. Then, the flow interface functions can be completed under this project. The implementation of Stream interface functions requires the establishment of the AD7854 data structure and the implementation of the code of each interface function.
(1) Data Structure of AD7854
Before writing a stream interface function, define the data structure of the device, which is an abstraction of the real device. According to the CPU-related memory involved in the operation of AD7854 and the needs of the internal operation of AD7854, the following structure types are abstracted:


The data structure of AD7854 can be seen as a logical body related to AD7854. Using the memory ing functions VirtualAl-loe () and VirtualCopy () provided by WindowsCE.net, You can associate the logical body with a specific physical address to complete physical memory settings.
(2) Development of Stream interface functions
Streaming interface functions provide unified interfaces for applications to operate on hardware and abstract hardware. A stream interface function is essentially a module that provides a specific function. The implementation of each interface function varies greatly depending on the hardware. Some interface functions require a lot of code, and some are an empty function body. In the AD7854-driven interface functions, initialization functions and read/write functions are the main interface functions. This article introduces the implementation process in combination with hardware:
① PADC_CONTEXT ADC_Init (LPCTSTR pCon-text, LPCVOID lpvBusContext ). This interface is called by the Device Manager when the driver is loaded. This function initializes the hardware, such as ing the physical memory of the device, configuring related registers, creating interrupt events, and interrupting service threads.
The ADC_Init function needs to initialize the driver in a certain order. The Calling sequence of the internal functions is shown in 3. After the successful ADC_Init call, the first address of the AD7854 struct, pADC, is returned, indicating that the driver is successfully loaded.
② DWORD ADC_Read (PADC_CONTEXT pADC, PUCHAR pBuffer, DWORD Count ). This interface function mainly completes the read operation on AD7854. the code is an abstraction of the operation. To better reflect the development process, first introduce the read operation process of AD7854. AD7854 outputs 16 bits of data at a time, which is divided into two outputs (8 bits in height and 8 bits in height ). In read/write time series, in addition to configuring the storage register of the CPU to meet the time requirements, it is also important to note that the high-byte enable output pin (HBEN) is met). Specifically, when the output is high bytes, the pin should input a high level. AD7854 outputs 16-bit data at a time in two ways: one is to output 8-bit first, and the other is to output 8-bit lower (correspondingly, in the read sequence of AD7854, the 1st bytes are high and the 2nd bytes are low. The second is the opposite.
As shown in figure 3, the HBEN level is determined by the address line O of S3C2410. Therefore, in an AD7854 read sequence, the address line O should change its status once. At the same time, the parts of AD7854 are connected to LnGCS2, which forms two read physical addresses of AD7854: 0x1000 0000 and 0x1000. In this design, it is required to read the low 8-bit data and then the high 8-bit data. Therefore, the address line should first send the Oxl000 0000 and then send the 0x1000 0001. The read cycle sequence 4 of AD7854 is shown in.

The AD7854 read interface function can be developed using the following code:

 

Write interface function DWORD ADC_Write (PADC_CON-TEXT pADC, PUCHAR pBuffer, DWORD Count), mainly to complete the write operation of. AD7854. The write operation process of AD7854 is similar to the read operation, and the code implementation process is basically the same.
Other interface functions mainly return the structure handle of AD7854 and release the memory space. Although necessary, the operation on AD7854 is not the main one and will not be detailed here.
Compile the export function and registry file, compile and generate the d11 file, and generate it into the CEC file through PB. You can add the driver to the operating system when customizing the operating system. In this way, the driver program is compiled and the connection between the operating system and the hardware is realized.

4 Conclusion
Windows CE.net is a real-time embedded multi-task operating system with good graphic interface, good real-time performance and powerful functions. It is suitable for industrial control. This article takes the driver development of AD7854 as an example to describe the process of processing external interruptions and the development method of Stream interface driver in Windows CE.net. The driver has been successfully applied in the developed operation environment monitoring and evaluation system, and has good application results in monitoring of various micro-climate indicators.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.