Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1003689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:01:03+00:00 2026-05-16T08:01:03+00:00

I have a #define PROT_EN_DAT 0x140 //(320 in decimal) Its loaded into 64 bit

  • 0

I have a

#define PROT_EN_DAT  0x140  
//(320 in decimal)

Its loaded into 64 bit value register(ex setup_data[39:8]=PROT_EN_DATA)

Now i want to put this value(0x140)into

 uint8_t    bRequest
 uint16_t   wValue
 uint16_t   wIndex

How can load the value so that i don’t have to manually do it for other values again.
I think we can do with shift operators but don know how.

EDIT:Ya its related to USB. bRequest(8:15),wValue(16:31),wIndex(32:47) but setup_data is 64 bit value.I want to know how can i load proper values into the these fields.

For example say next time i am using #define PROT_EN2_REG 0x1D8.
and say setup_data[39:8]=PROT_EN2_DATA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:01:04+00:00Added an answer on May 16, 2026 at 8:01 am

    General read form:

    aField = (aRegister >> kBitFieldLSBIndex) & ((1 << kBitFieldWidth) - 1)
    

    General write form:

    mask = ((1 << kBitFieldWidth) - 1) << kBitFieldLSBIndex;
    aRegister = (aRegister & ~mask) | ((aField << kBitFieldLSBIndex) & mask);
    

    where:

    • aRegister is the value you read from the bit-field-packed register,
    • kBitFieldLSBIndex is the index of the least significant bit of the bit field, and
    • kBitFieldWidth is the width of the bit field, and
    • aField is the value of the bit field

    These are generalized, and some operations (such as bit-masking) may be unnecessary in your case. Replace the 1 with 1L if the register is larger than 32 bits.

    EDIT: In your example case (setup_data[39:8]=PROT_EN_DATA):

    Read:

    aField = (setup_data >> 8) & ((1L << 32) - 1L)
    

    Write:

    #define PROT_EN_MASK = (((1L << 32) - 1L) << 8) // 0x0000000FFFFFFFF0
    setup_data = (setup_data & ~PROT_EN_MASK) | ((PROT_EN_DATA << 8) & PROT_EN_MASK);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have #define values in headers that I certainly want Doxygen to document but
i have define a rule with or operator but it return multiple true or
i have define a recursive rule but the result seems incorrect. customer(peter,bank(maybank),customertype(personal), citizen(malaysian),age(62),credit(50000), income(3000),property(car)
Suppose I have #define foo in various header files. It may expand to some
I want to have/define a unique id for each data row in my Excel
if for example i have : #define PRINT(x) fprintf(stderr, x); and in code i
I have a memory mapped file, from which I wish to parse the contents
Some standard C libraries that I want to access with Cython have a ton
My form validation works great, but the messages use the JSF component name and
I need to test code ported from 32bit to 64bit where pointers are cast

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.