How to operate gpio in Windows CE

Source: Internet
Author: User
Gpio is the most basic input and output channel of the ARM chip. In ads, operations are performed by a single-chip microcomputer and its registers are directly read and written. On the arm9-7 platform, the Windows CE system maps the real IP address of gpio (for example, the base IP address of gpio 2410 is 0x56000000) to the virtual IP address space (the gpio corresponds to 0xb1600000, by performing operations on this virtual address space, you can control, input, and output gpio or other on-chip resources.
To operate the gpio of a platform, find the virtual address in the corresponding BSP according to the base address, and find the data structure that facilitates the operation of this address. The key functions are virtualalloc and virtualcopy. The convenience of CE is that user-Mode Applications can still use these two functions to access all these virtual spaces. for less complex programs, the write driver can even be omitted and operated directly in the application. In fact, before ce6, these drivers also work in the user State.
The following describes how to operate gpio of Samsung S3C2410:
1. First, in the s2410.h file of the BSP, find the virtual address ing and the register structure that operates the gpio (this will be changed as needed when you create some special device BSP)
//
// Registers: I/O port
//

# Define iop_base 0xb1600000 // 0x56000000
Typedef struct {
Unsigned int rgpacon; // 00
Unsigned int rgpadat;
Unsigned int rpad1 [2];

Unsigned int rgpbcon; // 10
Unsigned int rgpbdat;
Unsigned int rgpbup;
Unsigned int rpad2;

Unsigned int rgpccon; // 20
Unsigned int rgpcdat;
Unsigned int rgpcup;
Unsigned int rpad3;

Unsigned int rgpdcon; // 30
Unsigned int rgpddat;
Unsigned int rgpdup;
Unsigned int rpad4;

Unsigned int rgpecon; // 40
Unsigned int rgpedat;
Unsigned int rgpeup;
Unsigned int rpad5;

Unsigned int rgpfcon; // 50
Unsigned int rgpfdat;
Unsigned int rgpfup;
Unsigned int rpad6;

Unsigned int rgpgcon; // 60
Unsigned int rgpgdat;
Unsigned int rgpgup;
Unsigned int rpad7;

Unsigned int rgphcon; // 70
Unsigned int rgphdat;
Unsigned int rgphup;
Unsigned int rpad8;

Unsigned int rmiscr; // 80
Unsigned int rdckcon;
Unsigned int rextint0;
Unsigned int rextint1;
Unsigned int rextint2; // 90
Unsigned int reintflt0;
Unsigned int reintflt1;
Unsigned int reintflt2;
Unsigned int reintflt3; // A0
Unsigned int reintmask;
Unsigned int reintpend;
Unsigned int rgstatus0; // AC
Unsigned int rgstatus1; // B0
Unsigned int rgstatus2; // B4
Unsigned int rgstatus3; // B8
Unsigned int rgstatus4; // BC

} Iopreg;
Replace these copies.

2. create an application project in EVC, because the virtualcopy function is not defined in the header file, but in coredll. the LIB provides symbolic connections, so we can simply add a function definition here.
# Ifdef _ cplusplus
Extern "C"
{
# Endif

Bool virtualcopy (lpvoid, lpvoid, DWORD, DWORD );

# Ifdef _ cplusplus
}
# Endif
At the same time, copy the definition in step 1 here.

3. Write the gpio operation function in the application according to the operation method in the driver.
(1) define a register struct variable
Volatile iopreg * v_piopregs;
(2) Allocate space for this variable and map it to the register space.
V_piopregs = (volatile iopreg *) virtualalloc (0, sizeof (iopreg), mem_reserve, page_noaccess );
If (v_piopregs = NULL)
{
Debugmsg (1, (text ("v_piopregs is not allocated/n/R ")));
Return true;
}
If (! Virtualcopy (pvoid) v_piopregs, (pvoid) iop_base, sizeof (iopreg), page_readwrite | page_nocache )){
Debugmsg (1, (text ("v_piopregs is not mapped/n/R ")));
Return true;
}
Debugmsg (1, (text ("v_piopregs is mapped to % x/n/R"), v_piopregs ));
After these three steps, the v_piopregs operation will be directly associated with the gpio register
For example, set the GPB control register to all output
V_piopregs-> rgpbcon = 0x155555;
Set GPB data register output high level
V_piopregs-> rgpbdat = 0x3ff;

For more operations, you need to check the datasheet of arm and the source code of BSP of wince.

For non-arm platforms, you can refer to this idea for CE operations.

//************************************** **************************************** ************************************
Source: http://www.gd-emb.org/detail/id-36867.html

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.