Kinetis memcpy to 32-bit memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Kinetis memcpy to 32-bit memory

Jump to solution
1,514 Views
brianmitchell
Contributor II

I am using a K61 with MQX 4.0.2, CW 10.5, GCC 4.7.3 and 32-bit Flexbus memory. I would like to use memcpy with this memory. My accesses are all aligned, however, I see that the EWL version of memcpy will always uses byte access (I was expecting some optimizations to be there for long accesses).

 

I found mem_funcs.h functions and tried them as well with various issues.

__copy_mem - has the exact same behavior as memcpy unless the size is > 32 bytes.

__copy_longs_aligned - seems to have some bugs as the addresses are predecremented and get the incorrect data. I can work around it by sending the wrong addresses into the function, but this is ugly.

 

Has anyone else worked with the memory functions to optimize for performance and long words?

 

-Brian

Labels (1)
Tags (2)
0 Kudos
1 Solution
953 Views
DavidS
NXP Employee
NXP Employee

Hi Brian,

I have not tried this but feel free to give it a go.

In the PSP mqx_cnfg.h header is the following comments and "#define".

/*

** When this option is defined as 1, private MQX implementation of memcpy is used instead

** the one from standard library.

** MGCT: <option type="bool"/>

*/

#ifndef MQXCFG_MEM_COPY

#define MQXCFG_MEM_COPY  0

#endif

So you could and add "#define MQXCFG_MEM_COPY 1" in your user_config.h header.

The mem_cpy() routine is also in PSP and in file mem_copy.c with following comments and initial function call:

/*FUNCTION*------------------------------------------------------------------- * * Function Name    : _mem_copy * Returned Value   : none * Comments         : *   This function copies the specified number of bytes from the * source address to the destination address.  No attempt is made * to handle overlapping copies to prevent loss of data. *   The copying is optimized to avoid alignment problems, and attempts * to copy 32bit numbers optimally * *END*----------------------------------------------------------------------*/

#if MQXCFG_MEM_COPY

void _mem_copy    (       /* [IN] address to copy data from */       pointer  from_ptr,

      /* [IN] address to copy data to */       pointer  to_ptr,

      /* [IN] number of bytes to copy */       register _mem_size number_of_bytes    ) { /* Body */ #if MQX_USE_SMALL_MEM_COPY    register uint_8_ptr from8_ptr = (uint_8_ptr) from_ptr;    register uint_8_ptr to8_ptr = (uint_8_ptr) to_ptr;

   if (number_of_bytes) {       while (number_of_bytes--) {          *to8_ptr++ = *from8_ptr++;       } /* Endwhile */         } /* Endif */ #else    uint_8_ptr from8_ptr = (uint_8_ptr) from_ptr;    uint_8_ptr to8_ptr = (uint_8_ptr) to_ptr;    uint_16_ptr from16_ptr = (uint_16_ptr) from_ptr;    uint_16_ptr to16_ptr = (uint_16_ptr) to_ptr;    register uint_32_ptr from32_ptr = (uint_32_ptr) from_ptr;

Regards,

David

View solution in original post

0 Kudos
3 Replies
953 Views
brianmitchell
Contributor II

Update: This has been fixed in Codewarrior 10.6!

0 Kudos
954 Views
DavidS
NXP Employee
NXP Employee

Hi Brian,

I have not tried this but feel free to give it a go.

In the PSP mqx_cnfg.h header is the following comments and "#define".

/*

** When this option is defined as 1, private MQX implementation of memcpy is used instead

** the one from standard library.

** MGCT: <option type="bool"/>

*/

#ifndef MQXCFG_MEM_COPY

#define MQXCFG_MEM_COPY  0

#endif

So you could and add "#define MQXCFG_MEM_COPY 1" in your user_config.h header.

The mem_cpy() routine is also in PSP and in file mem_copy.c with following comments and initial function call:

/*FUNCTION*------------------------------------------------------------------- * * Function Name    : _mem_copy * Returned Value   : none * Comments         : *   This function copies the specified number of bytes from the * source address to the destination address.  No attempt is made * to handle overlapping copies to prevent loss of data. *   The copying is optimized to avoid alignment problems, and attempts * to copy 32bit numbers optimally * *END*----------------------------------------------------------------------*/

#if MQXCFG_MEM_COPY

void _mem_copy    (       /* [IN] address to copy data from */       pointer  from_ptr,

      /* [IN] address to copy data to */       pointer  to_ptr,

      /* [IN] number of bytes to copy */       register _mem_size number_of_bytes    ) { /* Body */ #if MQX_USE_SMALL_MEM_COPY    register uint_8_ptr from8_ptr = (uint_8_ptr) from_ptr;    register uint_8_ptr to8_ptr = (uint_8_ptr) to_ptr;

   if (number_of_bytes) {       while (number_of_bytes--) {          *to8_ptr++ = *from8_ptr++;       } /* Endwhile */         } /* Endif */ #else    uint_8_ptr from8_ptr = (uint_8_ptr) from_ptr;    uint_8_ptr to8_ptr = (uint_8_ptr) to_ptr;    uint_16_ptr from16_ptr = (uint_16_ptr) from_ptr;    uint_16_ptr to16_ptr = (uint_16_ptr) to_ptr;    register uint_32_ptr from32_ptr = (uint_32_ptr) from_ptr;

Regards,

David

0 Kudos
953 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Brian,

A service request was created for you regarding this question. You will be contacted by technical support team.

Regards,

Carlos

0 Kudos