1*852ba100SJustin Hibbits /* Copyright (c) 2008-2012 Freescale Semiconductor, Inc 20aeed3e9SJustin Hibbits * All rights reserved. 30aeed3e9SJustin Hibbits * 40aeed3e9SJustin Hibbits * Redistribution and use in source and binary forms, with or without 50aeed3e9SJustin Hibbits * modification, are permitted provided that the following conditions are met: 60aeed3e9SJustin Hibbits * * Redistributions of source code must retain the above copyright 70aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer. 80aeed3e9SJustin Hibbits * * Redistributions in binary form must reproduce the above copyright 90aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer in the 100aeed3e9SJustin Hibbits * documentation and/or other materials provided with the distribution. 110aeed3e9SJustin Hibbits * * Neither the name of Freescale Semiconductor nor the 120aeed3e9SJustin Hibbits * names of its contributors may be used to endorse or promote products 130aeed3e9SJustin Hibbits * derived from this software without specific prior written permission. 140aeed3e9SJustin Hibbits * 150aeed3e9SJustin Hibbits * 160aeed3e9SJustin Hibbits * ALTERNATIVELY, this software may be distributed under the terms of the 170aeed3e9SJustin Hibbits * GNU General Public License ("GPL") as published by the Free Software 180aeed3e9SJustin Hibbits * Foundation, either version 2 of that License or (at your option) any 190aeed3e9SJustin Hibbits * later version. 200aeed3e9SJustin Hibbits * 210aeed3e9SJustin Hibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 220aeed3e9SJustin Hibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 230aeed3e9SJustin Hibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 240aeed3e9SJustin Hibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 250aeed3e9SJustin Hibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 260aeed3e9SJustin Hibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 270aeed3e9SJustin Hibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 280aeed3e9SJustin Hibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 290aeed3e9SJustin Hibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 300aeed3e9SJustin Hibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 310aeed3e9SJustin Hibbits */ 320aeed3e9SJustin Hibbits 33*852ba100SJustin Hibbits 340aeed3e9SJustin Hibbits /**************************************************************************//** 350aeed3e9SJustin Hibbits 360aeed3e9SJustin Hibbits @File memcpy_ext.h 370aeed3e9SJustin Hibbits 380aeed3e9SJustin Hibbits @Description Efficient functions for copying and setting blocks of memory. 390aeed3e9SJustin Hibbits *//***************************************************************************/ 400aeed3e9SJustin Hibbits 410aeed3e9SJustin Hibbits #ifndef __MEMCPY_EXT_H 420aeed3e9SJustin Hibbits #define __MEMCPY_EXT_H 430aeed3e9SJustin Hibbits 440aeed3e9SJustin Hibbits #include "std_ext.h" 450aeed3e9SJustin Hibbits 460aeed3e9SJustin Hibbits 470aeed3e9SJustin Hibbits /**************************************************************************//** 480aeed3e9SJustin Hibbits @Group etc_id Utility Library Application Programming Interface 490aeed3e9SJustin Hibbits 500aeed3e9SJustin Hibbits @Description External routines. 510aeed3e9SJustin Hibbits 520aeed3e9SJustin Hibbits @{ 530aeed3e9SJustin Hibbits *//***************************************************************************/ 540aeed3e9SJustin Hibbits 550aeed3e9SJustin Hibbits /**************************************************************************//** 560aeed3e9SJustin Hibbits @Group mem_cpy Memory Copy 570aeed3e9SJustin Hibbits 580aeed3e9SJustin Hibbits @Description Memory Copy module functions,definitions and enums. 590aeed3e9SJustin Hibbits 600aeed3e9SJustin Hibbits @{ 610aeed3e9SJustin Hibbits *//***************************************************************************/ 620aeed3e9SJustin Hibbits 630aeed3e9SJustin Hibbits /**************************************************************************//** 640aeed3e9SJustin Hibbits @Function MemCpy32 650aeed3e9SJustin Hibbits 660aeed3e9SJustin Hibbits @Description Copies one memory buffer into another one in 4-byte chunks! 670aeed3e9SJustin Hibbits Which should be more efficient than byte by byte. 680aeed3e9SJustin Hibbits 690aeed3e9SJustin Hibbits For large buffers (over 60 bytes) this function is about 4 times 700aeed3e9SJustin Hibbits more efficient than the trivial memory copy. For short buffers 710aeed3e9SJustin Hibbits it is reduced to the trivial copy and may be a bit worse. 720aeed3e9SJustin Hibbits 730aeed3e9SJustin Hibbits @Param[in] pDst - The address of the destination buffer. 740aeed3e9SJustin Hibbits @Param[in] pSrc - The address of the source buffer. 750aeed3e9SJustin Hibbits @Param[in] size - The number of bytes that will be copied from pSrc to pDst. 760aeed3e9SJustin Hibbits 770aeed3e9SJustin Hibbits @Return pDst (the address of the destination buffer). 780aeed3e9SJustin Hibbits 790aeed3e9SJustin Hibbits @Cautions There is no parameter or boundary checking! It is up to the user 800aeed3e9SJustin Hibbits to supply non-null parameters as source & destination and size 810aeed3e9SJustin Hibbits that actually fits into the destination buffer. 820aeed3e9SJustin Hibbits *//***************************************************************************/ 830aeed3e9SJustin Hibbits void * MemCpy32(void* pDst,void* pSrc, uint32_t size); 840aeed3e9SJustin Hibbits void * IO2IOCpy32(void* pDst,void* pSrc, uint32_t size); 850aeed3e9SJustin Hibbits void * IO2MemCpy32(void* pDst,void* pSrc, uint32_t size); 860aeed3e9SJustin Hibbits void * Mem2IOCpy32(void* pDst,void* pSrc, uint32_t size); 870aeed3e9SJustin Hibbits 880aeed3e9SJustin Hibbits /**************************************************************************//** 890aeed3e9SJustin Hibbits @Function MemCpy64 900aeed3e9SJustin Hibbits 910aeed3e9SJustin Hibbits @Description Copies one memory buffer into another one in 8-byte chunks! 920aeed3e9SJustin Hibbits Which should be more efficient than byte by byte. 930aeed3e9SJustin Hibbits 940aeed3e9SJustin Hibbits For large buffers (over 60 bytes) this function is about 8 times 950aeed3e9SJustin Hibbits more efficient than the trivial memory copy. For short buffers 960aeed3e9SJustin Hibbits it is reduced to the trivial copy and may be a bit worse. 970aeed3e9SJustin Hibbits 980aeed3e9SJustin Hibbits Some testing suggests that MemCpy32() preforms better than 990aeed3e9SJustin Hibbits MemCpy64() over small buffers. On average they break even at 1000aeed3e9SJustin Hibbits 100 byte buffers. For buffers larger than that MemCpy64 is 1010aeed3e9SJustin Hibbits superior. 1020aeed3e9SJustin Hibbits 1030aeed3e9SJustin Hibbits @Param[in] pDst - The address of the destination buffer. 1040aeed3e9SJustin Hibbits @Param[in] pSrc - The address of the source buffer. 1050aeed3e9SJustin Hibbits @Param[in] size - The number of bytes that will be copied from pSrc to pDst. 1060aeed3e9SJustin Hibbits 1070aeed3e9SJustin Hibbits @Return pDst (the address of the destination buffer). 1080aeed3e9SJustin Hibbits 1090aeed3e9SJustin Hibbits @Cautions There is no parameter or boundary checking! It is up to the user 1100aeed3e9SJustin Hibbits to supply non null parameters as source & destination and size 1110aeed3e9SJustin Hibbits that actually fits into their buffer. 1120aeed3e9SJustin Hibbits 1130aeed3e9SJustin Hibbits Do not use under Linux. 1140aeed3e9SJustin Hibbits *//***************************************************************************/ 1150aeed3e9SJustin Hibbits void * MemCpy64(void* pDst,void* pSrc, uint32_t size); 1160aeed3e9SJustin Hibbits 1170aeed3e9SJustin Hibbits /**************************************************************************//** 1180aeed3e9SJustin Hibbits @Function MemSet32 1190aeed3e9SJustin Hibbits 1200aeed3e9SJustin Hibbits @Description Sets all bytes of a memory buffer to a specific value, in 1210aeed3e9SJustin Hibbits 4-byte chunks. 1220aeed3e9SJustin Hibbits 1230aeed3e9SJustin Hibbits @Param[in] pDst - The address of the destination buffer. 1240aeed3e9SJustin Hibbits @Param[in] val - Value to set destination bytes to. 1250aeed3e9SJustin Hibbits @Param[in] size - The number of bytes that will be set to val. 1260aeed3e9SJustin Hibbits 1270aeed3e9SJustin Hibbits @Return pDst (the address of the destination buffer). 1280aeed3e9SJustin Hibbits 1290aeed3e9SJustin Hibbits @Cautions There is no parameter or boundary checking! It is up to the user 1300aeed3e9SJustin Hibbits to supply non null parameter as destination and size 1310aeed3e9SJustin Hibbits that actually fits into the destination buffer. 1320aeed3e9SJustin Hibbits *//***************************************************************************/ 1330aeed3e9SJustin Hibbits void * MemSet32(void* pDst, uint8_t val, uint32_t size); 1340aeed3e9SJustin Hibbits void * IOMemSet32(void* pDst, uint8_t val, uint32_t size); 1350aeed3e9SJustin Hibbits 1360aeed3e9SJustin Hibbits /**************************************************************************//** 1370aeed3e9SJustin Hibbits @Function MemSet64 1380aeed3e9SJustin Hibbits 1390aeed3e9SJustin Hibbits @Description Sets all bytes of a memory buffer to a specific value, in 1400aeed3e9SJustin Hibbits 8-byte chunks. 1410aeed3e9SJustin Hibbits 1420aeed3e9SJustin Hibbits @Param[in] pDst - The address of the destination buffer. 1430aeed3e9SJustin Hibbits @Param[in] val - Value to set destination bytes to. 1440aeed3e9SJustin Hibbits @Param[in] size - The number of bytes that will be set to val. 1450aeed3e9SJustin Hibbits 1460aeed3e9SJustin Hibbits @Return pDst (the address of the destination buffer). 1470aeed3e9SJustin Hibbits 1480aeed3e9SJustin Hibbits @Cautions There is no parameter or boundary checking! It is up to the user 1490aeed3e9SJustin Hibbits to supply non null parameter as destination and size 1500aeed3e9SJustin Hibbits that actually fits into the destination buffer. 1510aeed3e9SJustin Hibbits *//***************************************************************************/ 1520aeed3e9SJustin Hibbits void * MemSet64(void* pDst, uint8_t val, uint32_t size); 1530aeed3e9SJustin Hibbits 1540aeed3e9SJustin Hibbits /**************************************************************************//** 1550aeed3e9SJustin Hibbits @Function MemDisp 1560aeed3e9SJustin Hibbits 1570aeed3e9SJustin Hibbits @Description Displays a block of memory in chunks of 32 bits. 1580aeed3e9SJustin Hibbits 1590aeed3e9SJustin Hibbits @Param[in] addr - The address of the memory to display. 1600aeed3e9SJustin Hibbits @Param[in] size - The number of bytes that will be displayed. 1610aeed3e9SJustin Hibbits 1620aeed3e9SJustin Hibbits @Return None. 1630aeed3e9SJustin Hibbits 1640aeed3e9SJustin Hibbits @Cautions There is no parameter or boundary checking! It is up to the user 1650aeed3e9SJustin Hibbits to supply non null parameter as destination and size 1660aeed3e9SJustin Hibbits that actually fits into the destination buffer. 1670aeed3e9SJustin Hibbits *//***************************************************************************/ 1680aeed3e9SJustin Hibbits void MemDisp(uint8_t *addr, int size); 1690aeed3e9SJustin Hibbits 170*852ba100SJustin Hibbits /**************************************************************************//** 171*852ba100SJustin Hibbits @Function MemCpy8 172*852ba100SJustin Hibbits 173*852ba100SJustin Hibbits @Description Trivial copy one memory buffer into another byte by byte 174*852ba100SJustin Hibbits 175*852ba100SJustin Hibbits @Param[in] pDst - The address of the destination buffer. 176*852ba100SJustin Hibbits @Param[in] pSrc - The address of the source buffer. 177*852ba100SJustin Hibbits @Param[in] size - The number of bytes that will be copied from pSrc to pDst. 178*852ba100SJustin Hibbits 179*852ba100SJustin Hibbits @Return pDst (the address of the destination buffer). 180*852ba100SJustin Hibbits 181*852ba100SJustin Hibbits @Cautions There is no parameter or boundary checking! It is up to the user 182*852ba100SJustin Hibbits to supply non-null parameters as source & destination and size 183*852ba100SJustin Hibbits that actually fits into the destination buffer. 184*852ba100SJustin Hibbits *//***************************************************************************/ 185*852ba100SJustin Hibbits void * MemCpy8(void* pDst,void* pSrc, uint32_t size); 186*852ba100SJustin Hibbits 187*852ba100SJustin Hibbits /**************************************************************************//** 188*852ba100SJustin Hibbits @Function MemSet8 189*852ba100SJustin Hibbits 190*852ba100SJustin Hibbits @Description Sets all bytes of a memory buffer to a specific value byte by byte. 191*852ba100SJustin Hibbits 192*852ba100SJustin Hibbits @Param[in] pDst - The address of the destination buffer. 193*852ba100SJustin Hibbits @Param[in] c - Value to set destination bytes to. 194*852ba100SJustin Hibbits @Param[in] size - The number of bytes that will be set to val. 195*852ba100SJustin Hibbits 196*852ba100SJustin Hibbits @Return pDst (the address of the destination buffer). 197*852ba100SJustin Hibbits 198*852ba100SJustin Hibbits @Cautions There is no parameter or boundary checking! It is up to the user 199*852ba100SJustin Hibbits to supply non null parameter as destination and size 200*852ba100SJustin Hibbits that actually fits into the destination buffer. 201*852ba100SJustin Hibbits *//***************************************************************************/ 202*852ba100SJustin Hibbits void * MemSet8(void* pDst, int c, uint32_t size); 203*852ba100SJustin Hibbits 2040aeed3e9SJustin Hibbits /** @} */ /* end of mem_cpy group */ 2050aeed3e9SJustin Hibbits /** @} */ /* end of etc_id group */ 2060aeed3e9SJustin Hibbits 2070aeed3e9SJustin Hibbits 2080aeed3e9SJustin Hibbits #endif /* __MEMCPY_EXT_H */ 209