Common macro definitions for Windows CE driver development (updated at any time. You are welcome to add them !)

Source: Internet
Author: User

Macros are indeed a good weapon. In the CE-driven development process, correct and accurate use of appropriate macros can make the code very refined, the book wonderful, and enjoy reading. I have summarized some macros that are frequently used in development.

Register operation

8bit
# Define inreg8 (x) read_register_uchar (uchar *) (x ))
# Define outreg8 (x, y) write_register_uchar (uchar *) (x), (uchar) (y ))
# Define setreg8 (x, y) outreg8 (x, inreg8 (x) | (y ))
# Define clrreg8 (x, y) outreg8 (x, inreg8 (x )&~ (Y ))
# Define insreg8 (ADDR, mask, Val) outreg8 (ADDR, (inreg8 (ADDR )&(~ (Mask) | Val ))
# Define extreg8 (ADDR, mask, lsh) (inreg8 (ADDR) & Mask)> lsh)

16bit
# Define inreg16 (x) read_register_ushort (ushort *) (x ))
# Define outreg16 (x, y) write_register_ushort (ushort *) (x), (ushort) (y ))
# Define setreg16 (x, y) outreg16 (x, inreg16 (x) | (y ))
# Define clrreg16 (x, y) outreg16 (x, inreg16 (x )&~ (Y ))
# Define insreg16 (ADDR, mask, Val) outreg16 (ADDR, (inreg16 (ADDR )&(~ (Mask) | Val ))
# Define extreg16 (ADDR, mask, lsh) (inreg16 (ADDR) & Mask)> lsh)

32bit
# Define inreg32 (x) read_register_ulong (ulong *) (x ))
# Define outreg32 (x, y) write_register_ulong (ulong *) (x), (ulong) (y ))
# Define setreg32 (x, y) outreg32 (x, inreg32 (x) | (y ))
# Define clrreg32 (x, y) outreg32 (x, inreg32 (x )&~ (Y ))
# Define insreg32 (ADDR, mask, Val) outreg32 (ADDR, (inreg32 (ADDR )&(~ (Mask) | Val ))
# Define extreg32 (ADDR, mask, lsh) (inreg32 (ADDR) & Mask)> lsh)

 

 

Bit domain operations

# Define extreg8bf (ADDR, bit) (extreg8 (ADDR, csp_bitfmask (BIT), (bit ##_ lsh )))
# Define insreg8bf (ADDR, bit, Val) (insreg8 (ADDR, csp_bitfmask (BIT), csp_bitfval (bit, Val )))
# Define extreg16bf (ADDR, bit) (extreg16 (ADDR, csp_bitfmask (BIT), (bit ##_ lsh )))
# Define insreg16bf (ADDR, bit, Val) (insreg16 (ADDR, csp_bitfmask (BIT), csp_bitfval (bit, Val )))
# Define extreg32bf (ADDR, bit) (extreg32 (ADDR, csp_bitfmask (BIT), (bit ##_ lsh )))
# Define insreg32bf (ADDR, bit, Val) (insreg32 (ADDR, csp_bitfmask (BIT), csp_bitfval (bit, Val )))

 

# Define csp_bitfext (VAR, bit) (VAR & csp_bitfmask (BIT)> (bit ##_ lsh ))
# Define csp_bitfclr (VAR, bit) (VAR & = (~ Csp_bitfmask (BIT )))

# Define csp_bitfins (VAR, bit, Val )\
(Csp_bitfclr (VAR, bit); (VAR | = csp_bitfval (bit, Val ))

# Define csp_bitfmask (BIT) (1u <(bit # _ WID)-1) <(bit ##_ lsh ))
# Define csp_bitfval (bit, Val) (VAL) <(bit # _ lsh ))

 

 

Function

# Define widen2 (x) L # x
# Define widen (x) widen2 (X)
# DEFINE _ wfunction _ widen (_ function __)

# Define csp_func_trace_entry ()\
Debugmsg (1, (text ("+ % s \ r \ n"), _ wfunction __))

# Define csp_func_trace_exit ()\
Debugmsg (1, (text ("-% s \ r \ n"), _ wfunction __))


# Define dllexport _ declspec (dllexport)

 

Other useful information
If you reproduce the repeatedly defined warning, you can use the following method to remove the previous definition.

# UNDEF inreg8
# UNDEF outreg8
# UNDEF setreg8
# UNDEF clrreg8
# UNDEF inreg16
# UNDEF outreg16
# UNDEF setreg16
# UNDEF clrreg16
# UNDEF inreg32
# UNDEF outreg32
# UNDEF setreg32
# UNDEF clrreg32

 

 

 

 

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.