Path: blob/main/sys/contrib/ncsw/inc/etc/memcpy_ext.h
48378 views
/* Copyright (c) 2008-2012 Freescale Semiconductor, Inc1* All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5* * Redistributions of source code must retain the above copyright6* notice, this list of conditions and the following disclaimer.7* * Redistributions in binary form must reproduce the above copyright8* notice, this list of conditions and the following disclaimer in the9* documentation and/or other materials provided with the distribution.10* * Neither the name of Freescale Semiconductor nor the11* names of its contributors may be used to endorse or promote products12* derived from this software without specific prior written permission.13*14*15* ALTERNATIVELY, this software may be distributed under the terms of the16* GNU General Public License ("GPL") as published by the Free Software17* Foundation, either version 2 of that License or (at your option) any18* later version.19*20* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY21* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE23* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY24* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/313233/**************************************************************************//**3435@File memcpy_ext.h3637@Description Efficient functions for copying and setting blocks of memory.38*//***************************************************************************/3940#ifndef __MEMCPY_EXT_H41#define __MEMCPY_EXT_H4243#include "std_ext.h"444546/**************************************************************************//**47@Group etc_id Utility Library Application Programming Interface4849@Description External routines.5051@{52*//***************************************************************************/5354/**************************************************************************//**55@Group mem_cpy Memory Copy5657@Description Memory Copy module functions,definitions and enums.5859@{60*//***************************************************************************/6162/**************************************************************************//**63@Function MemCpy326465@Description Copies one memory buffer into another one in 4-byte chunks!66Which should be more efficient than byte by byte.6768For large buffers (over 60 bytes) this function is about 4 times69more efficient than the trivial memory copy. For short buffers70it is reduced to the trivial copy and may be a bit worse.7172@Param[in] pDst - The address of the destination buffer.73@Param[in] pSrc - The address of the source buffer.74@Param[in] size - The number of bytes that will be copied from pSrc to pDst.7576@Return pDst (the address of the destination buffer).7778@Cautions There is no parameter or boundary checking! It is up to the user79to supply non-null parameters as source & destination and size80that actually fits into the destination buffer.81*//***************************************************************************/82void * MemCpy32(void* pDst,void* pSrc, uint32_t size);83void * IO2IOCpy32(void* pDst,void* pSrc, uint32_t size);84void * IO2MemCpy32(void* pDst,void* pSrc, uint32_t size);85void * Mem2IOCpy32(void* pDst,void* pSrc, uint32_t size);8687/**************************************************************************//**88@Function MemCpy648990@Description Copies one memory buffer into another one in 8-byte chunks!91Which should be more efficient than byte by byte.9293For large buffers (over 60 bytes) this function is about 8 times94more efficient than the trivial memory copy. For short buffers95it is reduced to the trivial copy and may be a bit worse.9697Some testing suggests that MemCpy32() preforms better than98MemCpy64() over small buffers. On average they break even at99100 byte buffers. For buffers larger than that MemCpy64 is100superior.101102@Param[in] pDst - The address of the destination buffer.103@Param[in] pSrc - The address of the source buffer.104@Param[in] size - The number of bytes that will be copied from pSrc to pDst.105106@Return pDst (the address of the destination buffer).107108@Cautions There is no parameter or boundary checking! It is up to the user109to supply non null parameters as source & destination and size110that actually fits into their buffer.111112Do not use under Linux.113*//***************************************************************************/114void * MemCpy64(void* pDst,void* pSrc, uint32_t size);115116/**************************************************************************//**117@Function MemSet32118119@Description Sets all bytes of a memory buffer to a specific value, in1204-byte chunks.121122@Param[in] pDst - The address of the destination buffer.123@Param[in] val - Value to set destination bytes to.124@Param[in] size - The number of bytes that will be set to val.125126@Return pDst (the address of the destination buffer).127128@Cautions There is no parameter or boundary checking! It is up to the user129to supply non null parameter as destination and size130that actually fits into the destination buffer.131*//***************************************************************************/132void * MemSet32(void* pDst, uint8_t val, uint32_t size);133void * IOMemSet32(void* pDst, uint8_t val, uint32_t size);134135/**************************************************************************//**136@Function MemSet64137138@Description Sets all bytes of a memory buffer to a specific value, in1398-byte chunks.140141@Param[in] pDst - The address of the destination buffer.142@Param[in] val - Value to set destination bytes to.143@Param[in] size - The number of bytes that will be set to val.144145@Return pDst (the address of the destination buffer).146147@Cautions There is no parameter or boundary checking! It is up to the user148to supply non null parameter as destination and size149that actually fits into the destination buffer.150*//***************************************************************************/151void * MemSet64(void* pDst, uint8_t val, uint32_t size);152153/**************************************************************************//**154@Function MemDisp155156@Description Displays a block of memory in chunks of 32 bits.157158@Param[in] addr - The address of the memory to display.159@Param[in] size - The number of bytes that will be displayed.160161@Return None.162163@Cautions There is no parameter or boundary checking! It is up to the user164to supply non null parameter as destination and size165that actually fits into the destination buffer.166*//***************************************************************************/167void MemDisp(uint8_t *addr, int size);168169/**************************************************************************//**170@Function MemCpy8171172@Description Trivial copy one memory buffer into another byte by byte173174@Param[in] pDst - The address of the destination buffer.175@Param[in] pSrc - The address of the source buffer.176@Param[in] size - The number of bytes that will be copied from pSrc to pDst.177178@Return pDst (the address of the destination buffer).179180@Cautions There is no parameter or boundary checking! It is up to the user181to supply non-null parameters as source & destination and size182that actually fits into the destination buffer.183*//***************************************************************************/184void * MemCpy8(void* pDst,void* pSrc, uint32_t size);185186/**************************************************************************//**187@Function MemSet8188189@Description Sets all bytes of a memory buffer to a specific value byte by byte.190191@Param[in] pDst - The address of the destination buffer.192@Param[in] c - Value to set destination bytes to.193@Param[in] size - The number of bytes that will be set to val.194195@Return pDst (the address of the destination buffer).196197@Cautions There is no parameter or boundary checking! It is up to the user198to supply non null parameter as destination and size199that actually fits into the destination buffer.200*//***************************************************************************/201void * MemSet8(void* pDst, int c, uint32_t size);202203/** @} */ /* end of mem_cpy group */204/** @} */ /* end of etc_id group */205206207#endif /* __MEMCPY_EXT_H */208209210