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.
Previous article:Comparison between ARM interrupt mode (IRQ) and fast interrupt mode (FIQ)
Next article:Construction and implementation of AFDX-ES SoC verification platform
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Follow Guanguan to visit the Shenzhen ELEXCON Electronics Exhibition~~~
- Several issues on debugging program of MSP430 interrupt mechanism
- ADS designed VCO, the output is unstable.
- Why do chips need to be tested? You may not know the secret.
- Free application: Anxinke UWB indoor positioning module NodeMCU-BU01
- Analysis of weak optical signal amplification circuit, help needed! ! ! ! ! ! !
- Can someone show me what power module (SPM) this is?
- 39 "Wanli" Raspberry Pi car - ROS learning (ROS project file system structure introduction and import external software packages...
- Have you used digital RMB?
- RTT launches new BSP for stm32 series, and shares the production tutorial with you