This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCSV 5.1.0_Unaligned_Byte_Access_Issue!

Hi,

I want to use  _mem4() intrinsic or related unoptimized c code  (*(unsigned int *)(ptr)) for omap4430 Arm 9 processor in CCSv5.1.0 .

(may be i can't use _mem4 for arm , but i can use (*(unsigned int *)(ptr)) in my code to unalligned load and store operation).

I am using CCS v5.1.0.

I checked there is one option in CCS v5.1.0 in Build ->Runtime model option->unaligned Access-> On (for arm processor).

But it is not helpful for me .

I raised same question in omap4430 forum but i didn't get proper answer ,so i think some setting of ccs v5.1.0 will help me.

The scenario is like this :-

#define _mem4(ptr)  (*(unsigned int *)(ptr))

Its use is to store/load 32 bit data .

As i mentioned before that am using the address (0x4 series) according to omap TRM only not according to my mind.

So the ptr is having the the value as 0x4 series address (which is according to TRM and can be usable )

As i mentioned some part of code in  my previous post :

,i want to do 4byte load.

unsigned short *ptr; //Let us say ptr is 0x4 series address according to TRM

unsigned int val;

val = *((unsigned int *)ptr); // this is giving problem

or

val = _mem4(ptr);

None of the above statement is executing..If I try to execute ,it will show " no source code avaliable ".

I am using the CCS v5.1.0 .I saw one option in CCS v5.1.0 proporties related to unalligned access.

I used this one too  but still i am facing the same problem.

Please tell the solution on this.

This is not trelated with normal /basic pointer error.

I think there is some allignment issue ( ARM9 Processor+ ccs V5.1.0 +Windows platform )

-Studinstru

  • The --unaligned_access build option is safe to use only for Cortex devices, not ARM9.

    studinstru sggs said:
    val = *((unsigned int *)ptr); // this is giving problem

    That should work provided ptr contains an address aligned on a 4 byte boundary.  If you have an example where ptr is aligned, but the code still doesn't work, then we need to see it.  If ptr is not aligned, this code will silently give you the wrong answer.

    Thanks and regards,

    -George

  • Thanks Georgem.

    The thing is that am using panda board with omap4430 processor.

    The problem that i mentioned above is alignment issue only.

    i tried with ___packed ,  __attribute__((packed)) ,__aligned but still the problem is there that is "No Source code is avaliable ".

    Can u please tell me the way how to align the pointer in ARM9 devices.

    (OMAP4430 having cortex A9).

    Am totally got stuck up.Not able to proceed.

    -Studinstru

  • On most architectures, you simply cannot dereference an unaligned pointer to directly access data, and there is no way to make the pointer "aligned" without changing the location it points to.

    Presumably you are trying to assemble an integer value from some buffer stored as some array of bytes obtained from an outside source.  The process of converting between outside data formats and native (properly aligned) ones is often called "marshalling".  For example:

    int i, svalue;
    unsigned uvalue;
    unsigned char buffer[1024];
    get_buffer(buffer);
    uvalue=0;
    for(i=0;i<4;++i) uvalue = (uvalue<<1) | buffer[51+i];
    svalue=(int)uvalue;

    The result is the value intended by a "big-endian" representation of a 32-bit value, unsigned in uvalue ir signed in svalue.

    For "little-endian" representation, assemble the bytes into uvalue in the opposite direction.

    You may want to put together a library for marshalling in both directions for a variety of data types, sizes, and representations.