• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » C2000™ Microcontrollers » C2000 32-bit Microcontrollers Forum » Newbie question: HWREG and HWREGBITW, what they do?
Share
C2000™ Microcontrollers
  • Forums
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
C2000 Resources
  • Product Folder
  • C2000 Training Portal
  • C2000 Technical Training Catalog
  • C2000 Datasheets, App Notes, User Guides
  • C2000 Hardware Design Kits
  • controlSUITE for C2000 Software Library


  • InstaSPIN Resources
  • What is InstaSPIN?
  • Videos and Support


  • InstaSPIN-FOC and InstaSPIN-MOTION Resources
  • What is InstaSPIN-FOC?
  • What is InstaSPIN-MOTION?
  • Product Folder: F28069F, F28068F, F28062F, F28068M, F28069M
  • User’s Guide
  • Technical User’s Manual
  • Tools
  • Forums

    Newbie question: HWREG and HWREGBITW, what they do?

    This question is answered
    Ronaldo Pace
    Posted by Ronaldo Pace
    on Apr 05 2012 05:30 AM
    Intellectual875 points

    I know it's a very newbie question and I know the #define for them is in hw_types.h

    But I must admit my newbie level on C and say: I don't get it! It is a pointer, to a cast of a unsigned long pointer that masks the pointer to some bit of this long?

    Sorry, I was already lost on the casting to another pointer, I guess too much Java made me weak towards real low level programming languages and I bow down to the experts for help.

    I've been carelessly allowing all of those macros live in my code just copying them from the example, but until know I've been only setting up the stuff that is mostly API commands based. No registers.

    But the IPC is full of those and I have some issues to iron out on the uDMA (http://e2e.ti.com/support/microcontrollers/tms320c2000_32-bit_real-time_mcus/f/171/t/180339.aspx) too and a better understanding of those Macros will be very useful.

    Please (light)darkness;

    -----------------------

    EDIT:

    maybe I should elaborate a bit further:

     

    stuff like this:

     

        // Allow writes to protected registers.
        HWREG(SYSCTL_MWRALLOW) = 0xA5A5A5A5;

    I get it, there's a register named SYSCTL_MWRALLOW that you can find at address 0x400FB980 and I'm writting on it 0xA5A5A5A5. And it means that now I can write the protected registers, which I can see which ones are in the datasheet.

    but sometimes there's some HWREG(RAM_CONFIG_BASE + RAM_O_MSXRTESTINIT1) |= 0x1; which I barely pretend I understand, something about masking the first bit of RAM_O_MSXRTESTINIT1 into RAM_CONFIG_BASE  register, but then I see a HWREGBITW(&g_ulFlags, FLAG_SYSTICK) that doesn't seem to be much to do with any of the hardware registers or almost randomly in some examples there's a

        // Tells M3 Core the vector table is at the beginning of C0 now.
        HWREG(NVIC_VTABLE) = 0x20005000;

    why can't you leave the NVIC_VTABLE where it was? Was it doing any harm on the default place?

    again, any help will be appreciate to (light)darkness;  <- cast light into darkness.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Alvaro Prieto
      Posted by Alvaro Prieto
      on Apr 09 2012 10:46 AM
      Verified Answer
      Verified by Ronaldo Pace
      Intellectual1560 points

      Rondaldo,

      Hardware registers are just addresses in memory. Instead of having the actual address for each register as a #define, the base address for each peripheral is defined, along with the offsets from that base address for each register.

      For example, RAM_CONFIG_BASE is equal to address 0x400FB200. RAM_O_MSXRTESTINIT1 is located at 0x400FB250, but instead of storing that address, the offset of 0x50 from the RAM_CONFIG_BASE is used. HWREG(RAM_CONFIG_BASE + RAM_O_MSXRTESTINIT1) is just adding the offset for that specific register to the ram config base address.

      The |=0x1 is just 'setting' the first bit. (Get the contents of RAM_O_MSXRTESTINIT1 and OR them with 0x01)

      The HWREG macro is used to actually work with the addresses. It casts the address value to a volatile(it's a register, so it could change at any time) pointer that is then dereferenced (*) so it can be read/written to as a variable in c.

      HWREGBITW is used to manipulate individual bits on a register using 'bit banding'. This allows you to modify individual bits without having to read-modify-write the register. You can find more information on bit banding here: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/CHDJHIDF.html and http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/Behcjiic.html

      I hope this helps,

      Alvaro

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Ronaldo Pace
      Posted by Ronaldo Pace
      on Apr 11 2012 04:29 AM
      Intellectual875 points

      hi Alvaro,

      thanks for the reply, I had to re-read a few times and sleep on it to absorb the data but I guess my brain is starting to make sense of it.

      But two specific questions arise from it:

      1) On the enet_uip example it's used A LOT  the following the definition:

      #define FLAG_SYSTICK            0
      #define FLAG_RXPKT 1
      #define FLAG_TXPKT 2
      #define FLAG_RXPKTPEND 3
      static volatile unsigned long g_ulFlags;

      and then the macro HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 1 or while((HWREGBITW(&g_ulFlags, FLAG_TXPKT) == 1) .... is that just the programmer re-using the MACRO for his own needs with no real hardware register association?? Just using the MACRO to test the bits of his own status long?


      2) in some examples we see:

          // Tells M3 Core the vector table is at the beginning of C0 now.
          HWREG(NVIC_VTABLE) = 0x20005000;

      why moving the interrupts around? I noticed that it does on all DUAL core examples except blinky and flash and it's always moving to C0 (M3 core secure RAM) so I don't see the connection between C0 and the C28 core.

      thanks.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Alvaro Prieto
      Posted by Alvaro Prieto
      on Apr 11 2012 09:19 AM
      Verified Answer
      Verified by Ronaldo Pace
      Intellectual1560 points

      Ronaldo,

      1) Yes, the HWREGBITW is being used to manipulate individual bits on the g_ulFlags with a single instruction.  These macros don't have to be used only for registers. You could use any voltatile unsigned long address as the argument.

      2)  If you look at the linker command file, you will see that the INTVECS section is located at address 0x20005000. The  g_pfnVectors array, declared in startup_ccs.c is stored there. In the past, we would put in the ISR functions directly in this array. Now you can use the IntRegister() driverlib function in  driverlib/interrupt.c to do it. The first time this function is called, it copies the entire vector table to RAM and changes the NVIC_VTABLE to point to it. 

      As long as you use IntRegister before you enable interrupts, you shouldn't have to worry about setting NVIC_VTABLE in your code.

      Alvaro

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use