Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to store a value at the specified location in RAM.

how to store a value at the specified location in RAM.

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialhardwareperformance
11 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C chandu004

    hello all, this requirement is for an embedded device. i need to use the memory available at a predefined address, say for example, 0xe000 2828 in RAM. so i need to define a variable some thing like int *i=0xe000 2828; i mean, here, 'i' should be mapped to the desired memory location. but syntactically, the above statement is wrong. i remember, this can be achieved using a far pointer. but iam unable to do this, and my compiler does not accept if i use as follows. int far *i=0xe000 2828; please suggest me the mechanism to achieve this. thanks in advance.

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #2

    You should read the documentation of your (cross) compiler :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    In testa che avete, signor di Ceprano?

    C 1 Reply Last reply
    0
    • CPalliniC CPallini

      You should read the documentation of your (cross) compiler :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      C Offline
      C Offline
      chandu004
      wrote on last edited by
      #3

      hai pallini, thanks for your response. yes, i have gone through that, but this specific point is not addressed properly in that. can you please suggest me any other clue. let me explain the issue a bit detailed. the document says that, the RAM available from that particular location up to 2k is battery backed up RAM. means, though the device is powered off, as long as the battery lives, the data written into that memory will be un lost. right, i think now, you might give me some clue. thank you.

      CPalliniC 1 Reply Last reply
      0
      • C chandu004

        hello all, this requirement is for an embedded device. i need to use the memory available at a predefined address, say for example, 0xe000 2828 in RAM. so i need to define a variable some thing like int *i=0xe000 2828; i mean, here, 'i' should be mapped to the desired memory location. but syntactically, the above statement is wrong. i remember, this can be achieved using a far pointer. but iam unable to do this, and my compiler does not accept if i use as follows. int far *i=0xe000 2828; please suggest me the mechanism to achieve this. thanks in advance.

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #4

        Well, your compiler and package probably came with header files describing built in I/O ports - look at those for the syntax. But I'm sure what you wrote is wrong - I doubt the compiler will a space in the middle of a number. The last embedded work I did was on a 32bit processor, so it may be harder for you (in which case, read headers as above), but the following worked for me:

        unsigned int *pSomewhere = (unsigned int *)0x12341234;

        Obviously that's not the real name or number, but I hope you get the idea. You may just need the odd far. Iain.

        C 1 Reply Last reply
        0
        • C chandu004

          hai pallini, thanks for your response. yes, i have gone through that, but this specific point is not addressed properly in that. can you please suggest me any other clue. let me explain the issue a bit detailed. the document says that, the RAM available from that particular location up to 2k is battery backed up RAM. means, though the device is powered off, as long as the battery lives, the data written into that memory will be un lost. right, i think now, you might give me some clue. thank you.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #5

          Well, I suppose the compire manual will tell you how to access the device address space. What device are dealing with? What compiler are you using? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          C 1 Reply Last reply
          0
          • CPalliniC CPallini

            Well, I suppose the compire manual will tell you how to access the device address space. What device are dealing with? What compiler are you using? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            C Offline
            C Offline
            chandu004
            wrote on last edited by
            #6

            the device is arm controller. and the compiler is provided by him. any way, i got a clue to use volatile int. this i got from one of the macros provided by him. let me try this out and i will announce it here if it is solved. thanks again for your support.

            -------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.

            1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              Well, your compiler and package probably came with header files describing built in I/O ports - look at those for the syntax. But I'm sure what you wrote is wrong - I doubt the compiler will a space in the middle of a number. The last embedded work I did was on a 32bit processor, so it may be harder for you (in which case, read headers as above), but the following worked for me:

              unsigned int *pSomewhere = (unsigned int *)0x12341234;

              Obviously that's not the real name or number, but I hope you get the idea. You may just need the odd far. Iain.

              C Offline
              C Offline
              chandu004
              wrote on last edited by
              #7

              yes, thanks for your response. the space, which you are talking about, i would have given it like that in forums but i gave it as a single value in my code. but still it wasnt working. any ways, iam trying to implement it using volatile. thanks all for your suggestions.

              -------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.

              D 1 Reply Last reply
              0
              • C chandu004

                yes, thanks for your response. the space, which you are talking about, i would have given it like that in forums but i gave it as a single value in my code. but still it wasnt working. any ways, iam trying to implement it using volatile. thanks all for your suggestions.

                -------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #8

                chandu004 wrote:

                but still it wasnt working.

                Without seeing your code, how you are using it, and what you are expecting instead, this is less than helpful.

                chandu004 wrote:

                iam trying to implement it using volatile.

                Why?

                "Love people and use things, not love things and use people." - Unknown

                "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                N 1 Reply Last reply
                0
                • C chandu004

                  hello all, this requirement is for an embedded device. i need to use the memory available at a predefined address, say for example, 0xe000 2828 in RAM. so i need to define a variable some thing like int *i=0xe000 2828; i mean, here, 'i' should be mapped to the desired memory location. but syntactically, the above statement is wrong. i remember, this can be achieved using a far pointer. but iam unable to do this, and my compiler does not accept if i use as follows. int far *i=0xe000 2828; please suggest me the mechanism to achieve this. thanks in advance.

                  R Offline
                  R Offline
                  Roger Stoltz
                  wrote on last edited by
                  #9

                  chandu004 wrote:

                  i need to use the memory available at a predefined address, say for example, 0xe000 2828 in RAM.

                  This is most likely a physical address and depending on what ARM architecture you're developing for, you may have an MMU[^] that maps physical addresses to virtual. This means you have to check your documentation for the following:

                  1. Is your ARM architecture equipped with an MMU?
                  2. If so, is it enabled?
                  3. If 'yes', what API call are you supposed to make to read and write to and from physical addresses?

                  chandu004 wrote:

                  int *i=0xe000 2828;

                  Like Iain said, the compiler will swallow a type cast such as

                  int* pAddr = (int*)0xe0002828;

                  but depending on the MMU-stuff this will give you a virtual address which may not be what you need. The documentation for your compiler and your chip ought to have information about this. Finally: Your problem is very specific to your environment, so it's very hard to advise you to anything but reading the documentation for your compiler and the chipset you're using. You haven't even informed us what ARM architecture you are targeting. Also keep in mind that this forum is dedicated to developing windows applications with MFC and/or Win32 API, which is very different from developing for embedded systems. Of course you may be developing with Windows CE for embedded systems, but you haven't really said so clearly. If that's the case you may need to call ReadPhysical()[^] or WritePhysical()[^].

                  "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                  "High speed never compensates for wrong direction!" - unknown

                  1 Reply Last reply
                  0
                  • C chandu004

                    hello all, this requirement is for an embedded device. i need to use the memory available at a predefined address, say for example, 0xe000 2828 in RAM. so i need to define a variable some thing like int *i=0xe000 2828; i mean, here, 'i' should be mapped to the desired memory location. but syntactically, the above statement is wrong. i remember, this can be achieved using a far pointer. but iam unable to do this, and my compiler does not accept if i use as follows. int far *i=0xe000 2828; please suggest me the mechanism to achieve this. thanks in advance.

                    N Offline
                    N Offline
                    Nemanja Trifunovic
                    wrote on last edited by
                    #10

                    To add to the previous answers, some embedded compilers have a non-standard _at extension that would enable you to do something like:

                    int i _at(0xe0002828);

                    Otherwise, I would use something like:

                    int& i = *reinterpret_cast<int*> (0xe0002828);

                    Programming Blog utf8-cpp

                    1 Reply Last reply
                    0
                    • D David Crow

                      chandu004 wrote:

                      but still it wasnt working.

                      Without seeing your code, how you are using it, and what you are expecting instead, this is less than helpful.

                      chandu004 wrote:

                      iam trying to implement it using volatile.

                      Why?

                      "Love people and use things, not love things and use people." - Unknown

                      "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                      N Offline
                      N Offline
                      Nemanja Trifunovic
                      wrote on last edited by
                      #11

                      DavidCrow wrote:

                      Why?

                      It probably points to a memory-mapped io register that gets changed by some hardware event.

                      Programming Blog utf8-cpp

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups