Design of I2C Driver Based on WinCE

The embedded system is a "specialized computer system based on application-centric, computer-based technology, software and hardware that can be tailored to suit the application system's strict requirements on functionality, reliability, cost, size, and power consumption". Embedded hardware and embedded The software is composed of two parts. Embedded software includes an embedded operating system and embedded application software. Microsoft's desktop operating system has become familiar with and used by people. The embedded operating system Windows CE.net is also increasingly popular. Windows CE.net is a powerful, compact, efficient, and scalable 32-bit embedded operating system from Microsoft. It is mainly used for various embedded systems and products. The system's multithreading, multitasking, and full preemption features are designed for a variety of hardware systems with stringent resource constraints. In order to connect the operating system and hardware devices, it is important to contact the hardware and software drivers.

The following mainly analyzes the S3C2410 chip of Samsung ARM9 core, introduces the method of developing low-level device driver under the Windows CE.net system and provides examples of I2C communication.

1 I2C communication protocol and S3C2410 chip introduction

The I2C (Inter Integrated Circuit) bus was introduced by Philips in 1980. The I2C bus uses two lines (SDA and SCL) to transfer information between the bus and the device, serial communication between the microcontroller and the external device, or bidirectional data transfer between the master and the slave. Both communication lines are pulled up to +5 V through pull-up resistors. Each integrated circuit in the control system can read each line through a CMOS buffer, and can also pull down the level of each line through an open-gate FET. Therefore, for each chip, each line is both an input line and an output line.

The I2C bus complies with the synchronous serial transmission protocol, ie, each bit (single-by-one) is transmitted by the serial line, and the timing of the data line is indicated by the clock line. Each data packet is preceded by an address to indicate which device is to receive the data.

The S3C2410 is a 16/32-bit RISC microprocessor based on the ARM920T. It is mainly used in handheld devices. It has features such as high performance-to-price ratio and low power consumption. It is also one of the processors on the market with more embedded development boards. The chip has a 16 KB instruction and data buffer, storage management unit (MMU), LCD controller, 3 serial ports, 4 DMA, 4 clock timers, 8 10-bit A/D conversion, I2C support, I2S, SPI, master-slave USB interface, and SD/MMC card.

The I2C bus of the S3C2410 microprocessor can be in the following four modes: main receive mode, master transmit mode, slave receive mode, and slave transmit mode. The operation of the processor on I2C is mainly to read/write the following registers:

IIC control register, IICCON (physical address 0X54000000, memory mapped virtual address);
IIC Control/Status Register, IICSTAT (physical address 0X54000004);
IIC data register, IICDS (physical address 0X54000008);
The IIC address register, IICADD (physical address 0X5400000C).

This design is mainly that the CPU works in the main mode to communicate with the following I2C interface devices.

2 Windows CE system driver features

There are two models of the Windows CE.net driver: native device drivers and stream interface drivers. Native device drivers are suitable for integration into devices based on the Windows CE.net platform. These device drivers are required by some hardware and are created by original equipment manufacturers to drive such as keyboards, touch screens, audio devices, etc. They are often not replaced after the device is sold, such as general-purpose LED drivers and power supplies. Drivers, keyboard drivers, and display drivers are all native device drivers. For the native device driver, Platform Builder provides some sample drivers, in order to facilitate developers to quickly develop their own drivers. When the Win CE system starts up, the local device driver is loaded into the system's memory. Local driver development is divided into hierarchical drivers and monolithic drivers. Hierarchical drivers use Microsoft's upper layer of communication with applications, called the module driver (MDD). The MDD layer communicates with the application program through the device driver interface (DDI). The development driver usually does not modify the MDD layer. It is mainly concerned with the lower layers related to the specific hardware, and depends on the Platform Dependent Driver (PDD) of the platform. The PDD layer directly manages the hardware through a Device Driver Service Provider Interface. Streaming interface device drivers (referred to as installable startup programs) can be provided by third-party manufacturers to support devices added to the system. The device driver under Windows CE works at the same level of protection as the application. When the system starts up, most drivers are loaded by the device management process (DEVICE.EXE) and all of these drivers share the same process address space.

3 I2C bus bottom driver design

The I2C bus driver is a real driver in the OEM Adaptation Layer (OAL) layer, which is placed below the kernel of the Windows CE operating system.

3.1 Initializing I2C Interrupts and Writing ISR Routines

I2C communication is performed by operating I2C registers. In the I2C communication, the four registers described above are mainly read and written. By reading and writing the command status words in these registers, the behavior of the I2C bus can be detected and controlled. Under Windows CE.net, first add the macro definition of the I2C's interrupt number in the file oatintr.h:

#defineSYSINTR_I2C(SYSINTR_FIRMWARE+19)

Then add the initialization of I2C interrupt in the file of file cfw.c, disable and reset. The specific code is as follows:

Add case SYSINTR_IIC in OEMInterruptEnable function:
s2410INT->rSRCPND=BIT_IIC;
If (s2410INT->rINTPND & BIT_IIC) s2410INT->rINTPND = BIT_IIC;
s2410INT->rINTMSK&= BIT_IIC;
Break;

Add case SYSINTR_IIC in the OEMInterruptDisable function:
s2410INT->rINTMSK|= BIT_IIC;
Break;

Add the ISR program in the armint.c file and return the defined interrupt number after processing the interrupt. The specific code is as follows:

Add else if (IntPendVal == INTSRC_IIC) { in OEMInterruptHandler function {
s2410INT->rSRCPND= BIT_IIC; /* Clear interrupt*/
If (s2410INT->rINTPND & BIT_IIC) s2410INT->rINTPND= BIT_IIC;
s2410INT->rINTMSK|= BIT_IIC; /* I2C Interrupt Disable*/
Return (SYSINTR_RTC_ALARM);
}

3.2 Writing Stream Drivers

The I2C bus driver uses the standard form of the Win CE stream driver. In the IIC_Init function, the physical address for the I2C in the chip is first associated with the virtual memory space of the operating system through functions VirtualAlloc() and VirtualCopy(). The operation on the virtual address space is equivalent to the physical address of the chip. operating. The address mapping code is as follows:
Reg = (PVOID)VirtualAlloc(0, sz, MEM_RESERVE, PAGE_NOACCESS);
If (reg) {
If (!VirtualCopy(reg, addr, sz, PAGE_READWRITE | PAGE_NOCACHE )) {
RETAILMSG( DEBUGMODE,( TEXT( "Initializing interrupt \\" ) ) );
VirtualFree(reg, sz, MEM_RELEASE);
Reg = NULL;
}
}

Where sz is the length of the application, and addr is the mapped address of the actual physical address of the virtual address space in Win CE.

Then operate on the virtual address that is applied for, and install the flow-driven model in Windows to write the driver, which mainly includes the preparation of the following functions.

IIC_Init()

In the function, it is mainly to initialize I2C, the main statement is as follows:
v_pIICregs = (volatile IICreg *) IIC_RegAlloc((PVOID)IIC_BASE, sizeof(IICreg));
v_pIOPregs = (volatile IOPreg *) IOP_RegAlloc ((PVOID) IOP_BASE, sizeof(IOPreg));
v_pIOPregs->rGPEUP|= 0xc000;
v_pIOPregs->rGPECON |= 0xa00000;
v_pIICregs->rIICCON = (1<<7) | (0<<6) | (1<<5) | (0xf);
v_pIICregs->rIICADD= 0x10;
v_pIICregs->rIICSTAT = 0x10;
VirtualFree( (PVOID)v_pIOPregs,sizeof( IOPreg ),MEM_RELEASE );
v_pIOPregs = NULL;
If ( !StartDispatchThread( pIIcHead) )
{ IIC_Deinit( pIIcHead );return ( NULL );}

In the StartDispatchThread() function, we mainly create threads, associated events, and interrupts. The main statements are as follows:
InterruptInitialize( 36,pIicHead->hIicEvent,NULL,0 );//Associate time and interrupt CreateThread( NULL,0,IicDispatchThread,pIicHead,0,NULL );//Create thread waiting time

In the IicDispatchThread() function, it mainly waits for the generation of an interrupt, and then executes:
WaitReturn = WaitForSingleObject( pIicHead->hIicEvent,INFINITE );
IicEventHandler( pIicHead );//Event handler InterruptDone( 36 );

Finally, in the functions IIC_Open, IIC_Read, IIC_Write, each register is operated to perform data assignment to obtain I2C read data and send data.

4 I2C driver encapsulation and addition to Windows CE

Through the above work, you can compile a DLL function, but this can't be called streaming interface driver. Because its interface function has not yet been exported, you need to tell the linker what kind of function you need to output. To do this, you have to create your own def file. You can use Notepad to create a name, name mydrive.Def:

LIBRARY MyDriver
EXPORTS
IIC_Close
IIC_Deinit
IIC_Init
IIC_IOControl
IIC_Open
IIC_PowerDown
IIC_PowerUp
IIC_Read
IIC_Seek
IIC_Write

Then use a notepad to write a registry file named mydrive.reg:

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\STRINGS]
"Index"=dword:1
"Prefix"="IIC"
"Dll"="MyDriver.dll"
"Order"=dword:0

Finally write your own CEC file. Mainly to add a Build Method, the task is to copy the registry to the Win CE system directory below. Add a Bib File, its main function is to add the compiled mydrive.dll file to the system kernel. Save the written CEC file. Open Platform Builder, open the "File" menu, add the CEC features just written to the system options. When you build your system, add your own CEC features to include the I2C driver you just wrote.

The above introduces the driver structure of Win CE, and gives the source code of I2C driver based on Win CE. Experiments show that the design is feasible.

references

1 Chen Xiangqun, et al. Windows CE.NET System Analysis and Experimental Tutorial. Beijing: Mechanical Industry Press, 2003
2 Zhou Yulin, et al. Windows CE.net kernel customization and application development. Beijing: Electronic Industry Press, 2005
3 Microsoft.Windows CE Device Driver Development Guide. Beijing: Beijing Hope Electronics Press, 1999

Office Power

Office Power,Office Atx Power Supply,Office Mute Atx Power,Office Mute Power

Boluo Xurong Electronics Co., Ltd. , https://www.greenleaf-pc.com

This entry was posted in on