A Brief Discussion on the Portability of Win CE Application Programs

Publisher:WhisperingRainLatest update time:2021-07-01 Source: eefocusKeywords:Win  application Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Since desktop Windows runs on the X86 platform in most cases, there is no portability issue between different platforms. However, Windows CE runs on CPUs of four major architectures (X86, SHx, MIPS, ARM), so its portability needs to be considered when writing applications.


The following will look at how to write an application with better portability by accessing the physical address under the Windows CE system.


First of all, two concepts must be clarified.



1. I/O addresses only exist on the X86 platform. There are no I/O ports on other CPU systems (such as ARM/MIPS). This is because X86 addresses I/O and memory separately, resulting in two addresses; other CPUs address both uniformly, i.e., mapping I/O to memory.



2. WinCE's storage management is implemented through MMU. After the system starts, we can only access the virtual storage space, which must go through MMU. However, under X86, the address buses used to access the I/O port and the memory are different, and do not need to go through MMU.


For example, if we want to access the port with physical address 360h on a bus, for the X86 platform we can directly embed the assembly to operate the physical address, or use the address pointer to access the physical address. But for other platforms, we must first map the physical address to the virtual address, and then operate the virtual address. This obviously makes the program less portable, so we need to define #ifdef __x86....#elif defined __arm so that the program can run smoothly on different platforms.



If we use the following code, we don't have to go through so much trouble to define different platforms:


First define

inIoSpace = 1;

ioPhysicalBase.QuadPart = 0x360;


if( HalTranslateBusAddress( Isa, //This function maps the physical address on the ISA bus to the system physical address

0,

ioPhysicalBase,

&inIoSpace, //This parameter = 1 means the conversion is the I/O space address, = 0 means the memory address

&ioPhysicalBase ) )

{

if( !inIoSpace ) ////If it is a memory address, for non-X86 platforms


{

ioPortBase = (PUCHAR) MmMapIoSpace( //This function converts the system physical address into a virtual address

ioPhysicalBase,

IoLen,

FALSE );

if( ioPortBase == NULL )

{

//TODO: Error handling

}

}

else //If it is I/O, that is, under X86, no address mapping is required

{

ioPortBase = ( PUCHAR ) ioPhysicalBase.LowPart;

}

}

else

{

//TODO: Error Handling

}


Then, for the port operation (ioPortBase), we can also fully explore its portability. By using READ_PORT_UCHAR,

WRITE_PORT_UCHAR and other wince macros are used to implement port reading and writing. Instead of using pointer operations under X86 (which is not only poor in portability but also prone to problems). The macros under CE are encapsulated API functions internally. For example, the WRITE_PORT_UCHAR macro is converted into an OUT assembly instruction on the X86 processor; and it is converted into a write instruction to the virtual address on the ARM processor.


In WinCE5.0, you can use CreateBusAccessHandle (bus registry path) + BusTransBusAddrToVirtual to achieve direct conversion from bus physical address to system virtual address. This method is more portable to different platforms than using OEMAddressTable+VirtualAlloc+VirtualCopy.


Keywords:Win  application Reference address:A Brief Discussion on the Portability of Win CE Application Programs

Previous article:Comparison between ARM interrupt mode (IRQ) and fast interrupt mode (FIQ)
Next article:Construction and implementation of AFDX-ES SoC verification platform

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号