A library implementing IEEE 802.15.4 PHY functionality for the MCR20A transceiver. The PHY sublayer provides two services: the PHY data service and the PHY management service interfacing to the PHY sublayer management entity (PLME) service access point (SAP) (known as PLME-SAP). The PHY data service enables the transmission and reception of PHY protocol data units (PSDUs) over the media (radio).

Fork of fsl_phy_mcr20a by Freescale

The Freescale PHY Layer deals with the physical burst which is to be sent and/or received. It performs modulation and demodulation, transmitter and receiver switching, fragmentation, scrambling, interleaving, and error correction coding. The communication to the upper protocol layers is carried out through the Layer 1 Interface.

The PHY Layer is capable of executing the following sequences:

  • I (Idle)
  • R (Receive Sequence conditionally followed by a TxAck)
  • T (Transmit Sequence)
  • C (Standalone CCA)
  • CCCA (Continuous CCA)
  • TR (Transmit/Receive Sequence - transmit unconditionally followed by either an R or RxAck)

In addition to these sequences the PHY Layer also integrates a packet processor which determines whether the packet is MAC-compliant, and if it is, whether it is addressed to the end device. Another feature of the packet processor is Source Address Matching which can be viewed as an extension of packet filtering; however its function is very specific to its intended application (data-polling and indirect queue management by a PAN Coordinator).

Documentation

MCR20A PHY Reference Manual

Committer:
andreikovacs
Date:
Tue Aug 18 12:41:42 2015 +0000
Revision:
0:764779eedf2d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andreikovacs 0:764779eedf2d 1 /*!
andreikovacs 0:764779eedf2d 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
andreikovacs 0:764779eedf2d 3 * All rights reserved.
andreikovacs 0:764779eedf2d 4 *
andreikovacs 0:764779eedf2d 5 * \file FunctionLib.c
andreikovacs 0:764779eedf2d 6 * This module contains various common functions like copy and compare routines.
andreikovacs 0:764779eedf2d 7 *
andreikovacs 0:764779eedf2d 8 * Redistribution and use in source and binary forms, with or without modification,
andreikovacs 0:764779eedf2d 9 * are permitted provided that the following conditions are met:
andreikovacs 0:764779eedf2d 10 *
andreikovacs 0:764779eedf2d 11 * o Redistributions of source code must retain the above copyright notice, this list
andreikovacs 0:764779eedf2d 12 * of conditions and the following disclaimer.
andreikovacs 0:764779eedf2d 13 *
andreikovacs 0:764779eedf2d 14 * o Redistributions in binary form must reproduce the above copyright notice, this
andreikovacs 0:764779eedf2d 15 * list of conditions and the following disclaimer in the documentation and/or
andreikovacs 0:764779eedf2d 16 * other materials provided with the distribution.
andreikovacs 0:764779eedf2d 17 *
andreikovacs 0:764779eedf2d 18 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
andreikovacs 0:764779eedf2d 19 * contributors may be used to endorse or promote products derived from this
andreikovacs 0:764779eedf2d 20 * software without specific prior written permission.
andreikovacs 0:764779eedf2d 21 *
andreikovacs 0:764779eedf2d 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
andreikovacs 0:764779eedf2d 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
andreikovacs 0:764779eedf2d 24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
andreikovacs 0:764779eedf2d 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
andreikovacs 0:764779eedf2d 26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
andreikovacs 0:764779eedf2d 27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
andreikovacs 0:764779eedf2d 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
andreikovacs 0:764779eedf2d 29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
andreikovacs 0:764779eedf2d 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
andreikovacs 0:764779eedf2d 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
andreikovacs 0:764779eedf2d 32 */
andreikovacs 0:764779eedf2d 33
andreikovacs 0:764779eedf2d 34 #include "FunctionLib.h"
andreikovacs 0:764779eedf2d 35
andreikovacs 0:764779eedf2d 36 #if gUseToolchainMemFunc_d
andreikovacs 0:764779eedf2d 37 #include <string.h>
andreikovacs 0:764779eedf2d 38 #endif
andreikovacs 0:764779eedf2d 39
andreikovacs 0:764779eedf2d 40 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 41 *************************************************************************************
andreikovacs 0:764779eedf2d 42 * Private macros
andreikovacs 0:764779eedf2d 43 *************************************************************************************
andreikovacs 0:764779eedf2d 44 ********************************************************************************** */
andreikovacs 0:764779eedf2d 45
andreikovacs 0:764779eedf2d 46 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 47 *************************************************************************************
andreikovacs 0:764779eedf2d 48 * Private prototypes
andreikovacs 0:764779eedf2d 49 *************************************************************************************
andreikovacs 0:764779eedf2d 50 ********************************************************************************** */
andreikovacs 0:764779eedf2d 51
andreikovacs 0:764779eedf2d 52 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 53 *************************************************************************************
andreikovacs 0:764779eedf2d 54 * Private type definitions
andreikovacs 0:764779eedf2d 55 *************************************************************************************
andreikovacs 0:764779eedf2d 56 ********************************************************************************** */
andreikovacs 0:764779eedf2d 57
andreikovacs 0:764779eedf2d 58 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 59 *************************************************************************************
andreikovacs 0:764779eedf2d 60 * Public memory declarations
andreikovacs 0:764779eedf2d 61 *************************************************************************************
andreikovacs 0:764779eedf2d 62 ********************************************************************************** */
andreikovacs 0:764779eedf2d 63
andreikovacs 0:764779eedf2d 64 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 65 *************************************************************************************
andreikovacs 0:764779eedf2d 66 * Private memory declarations
andreikovacs 0:764779eedf2d 67 *************************************************************************************
andreikovacs 0:764779eedf2d 68 ********************************************************************************** */
andreikovacs 0:764779eedf2d 69
andreikovacs 0:764779eedf2d 70 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 71 *************************************************************************************
andreikovacs 0:764779eedf2d 72 * Public functions
andreikovacs 0:764779eedf2d 73 *************************************************************************************
andreikovacs 0:764779eedf2d 74 ********************************************************************************** */
andreikovacs 0:764779eedf2d 75
andreikovacs 0:764779eedf2d 76 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 77 * \brief This function copies bytes from one buffer to another.
andreikovacs 0:764779eedf2d 78 * The buffers should not overlap.
andreikovacs 0:764779eedf2d 79 *
andreikovacs 0:764779eedf2d 80 * \param[in, out] pDst Pointer to the destination buffer.
andreikovacs 0:764779eedf2d 81 *
andreikovacs 0:764779eedf2d 82 * \param[in] pSrc Pointer to the source buffer.
andreikovacs 0:764779eedf2d 83 *
andreikovacs 0:764779eedf2d 84 * \param[in] cBytes Number of bytes to copy.
andreikovacs 0:764779eedf2d 85 *
andreikovacs 0:764779eedf2d 86 * \post The source and destination buffers must not overlap.
andreikovacs 0:764779eedf2d 87 *
andreikovacs 0:764779eedf2d 88 * \remarks
andreikovacs 0:764779eedf2d 89 *
andreikovacs 0:764779eedf2d 90 ********************************************************************************** */
andreikovacs 0:764779eedf2d 91 void FLib_MemCpy (void* pDst,
andreikovacs 0:764779eedf2d 92 void* pSrc,
andreikovacs 0:764779eedf2d 93 uint32_t cBytes)
andreikovacs 0:764779eedf2d 94 {
andreikovacs 0:764779eedf2d 95 #if gUseToolchainMemFunc_d
andreikovacs 0:764779eedf2d 96 memcpy(pDst, pSrc, cBytes);
andreikovacs 0:764779eedf2d 97 #else
andreikovacs 0:764779eedf2d 98 while (cBytes)
andreikovacs 0:764779eedf2d 99 {
andreikovacs 0:764779eedf2d 100 *((uint8_t*)pDst) = *((uint8_t*)pSrc);
andreikovacs 0:764779eedf2d 101 pDst = ((uint8_t*)pDst)+1;
andreikovacs 0:764779eedf2d 102 pSrc = ((uint8_t*)pSrc)+1;
andreikovacs 0:764779eedf2d 103 cBytes--;
andreikovacs 0:764779eedf2d 104 }
andreikovacs 0:764779eedf2d 105 #endif
andreikovacs 0:764779eedf2d 106 }
andreikovacs 0:764779eedf2d 107
andreikovacs 0:764779eedf2d 108 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 109 * \brief This function copies the specified number of bytes from the
andreikovacs 0:764779eedf2d 110 * source address to the destination address. No attempt is made
andreikovacs 0:764779eedf2d 111 * to handle overlapping copies to prevent loss of data.
andreikovacs 0:764779eedf2d 112 * The copying is optimized to avoid alignment problems, and attempts
andreikovacs 0:764779eedf2d 113 * to copy 32bit numbers optimally.
andreikovacs 0:764779eedf2d 114 *
andreikovacs 0:764779eedf2d 115 * \param[in] from_ptr Pointer to the source buffer.
andreikovacs 0:764779eedf2d 116 *
andreikovacs 0:764779eedf2d 117 * \param[in, out] to_ptr Pointer to the destination buffer.
andreikovacs 0:764779eedf2d 118 *
andreikovacs 0:764779eedf2d 119 * \param[in] number_of_bytes Number of bytes to copy (32 bit value).
andreikovacs 0:764779eedf2d 120 *
andreikovacs 0:764779eedf2d 121 * \post
andreikovacs 0:764779eedf2d 122 *
andreikovacs 0:764779eedf2d 123 * \remarks
andreikovacs 0:764779eedf2d 124 *
andreikovacs 0:764779eedf2d 125 ********************************************************************************** */
andreikovacs 0:764779eedf2d 126 void FLib_MemCpyAligned32bit (void* to_ptr,
andreikovacs 0:764779eedf2d 127 void* from_ptr,
andreikovacs 0:764779eedf2d 128 register uint32_t number_of_bytes)
andreikovacs 0:764779eedf2d 129 {
andreikovacs 0:764779eedf2d 130 uint8_t* from8_ptr = (uint8_t*)from_ptr;
andreikovacs 0:764779eedf2d 131 uint8_t* to8_ptr = (uint8_t*)to_ptr;
andreikovacs 0:764779eedf2d 132 uint16_t* from16_ptr = (uint16_t*)from_ptr;
andreikovacs 0:764779eedf2d 133 uint16_t* to16_ptr = (uint16_t*)to_ptr;
andreikovacs 0:764779eedf2d 134 register uint32_t* from32_ptr = (uint32_t*)from_ptr;
andreikovacs 0:764779eedf2d 135 register uint32_t* to32_ptr = (uint32_t*)to_ptr;
andreikovacs 0:764779eedf2d 136
andreikovacs 0:764779eedf2d 137 register uint32_t loops;
andreikovacs 0:764779eedf2d 138
andreikovacs 0:764779eedf2d 139 if (number_of_bytes > 3)
andreikovacs 0:764779eedf2d 140 {
andreikovacs 0:764779eedf2d 141 /* Try to align source on word */
andreikovacs 0:764779eedf2d 142 if ((uint32_t)from_ptr & 1)
andreikovacs 0:764779eedf2d 143 {
andreikovacs 0:764779eedf2d 144 from8_ptr = (uint8_t*)from_ptr;
andreikovacs 0:764779eedf2d 145 to8_ptr = (uint8_t*)to_ptr;
andreikovacs 0:764779eedf2d 146
andreikovacs 0:764779eedf2d 147 *to8_ptr++ = *from8_ptr++;
andreikovacs 0:764779eedf2d 148
andreikovacs 0:764779eedf2d 149 from_ptr = from8_ptr;
andreikovacs 0:764779eedf2d 150 to_ptr = to8_ptr;
andreikovacs 0:764779eedf2d 151 --number_of_bytes;
andreikovacs 0:764779eedf2d 152 }
andreikovacs 0:764779eedf2d 153
andreikovacs 0:764779eedf2d 154 /* Try to align source on longword */
andreikovacs 0:764779eedf2d 155 if ((uint32_t)from_ptr & 2)
andreikovacs 0:764779eedf2d 156 {
andreikovacs 0:764779eedf2d 157 from16_ptr = (uint16_t*)from_ptr;
andreikovacs 0:764779eedf2d 158 to16_ptr = (uint16_t*)to_ptr;
andreikovacs 0:764779eedf2d 159
andreikovacs 0:764779eedf2d 160 *to16_ptr++ = *from16_ptr++;
andreikovacs 0:764779eedf2d 161
andreikovacs 0:764779eedf2d 162 from_ptr = from16_ptr;
andreikovacs 0:764779eedf2d 163 to_ptr = to16_ptr;
andreikovacs 0:764779eedf2d 164 number_of_bytes -= 2;
andreikovacs 0:764779eedf2d 165 }
andreikovacs 0:764779eedf2d 166
andreikovacs 0:764779eedf2d 167 from32_ptr = (uint32_t*)from_ptr;
andreikovacs 0:764779eedf2d 168 to32_ptr = (uint32_t*)to_ptr;
andreikovacs 0:764779eedf2d 169
andreikovacs 0:764779eedf2d 170 for (loops = number_of_bytes >> 2; loops != 0; loops--)
andreikovacs 0:764779eedf2d 171 {
andreikovacs 0:764779eedf2d 172 *to32_ptr++ = *from32_ptr++;
andreikovacs 0:764779eedf2d 173 }
andreikovacs 0:764779eedf2d 174
andreikovacs 0:764779eedf2d 175 from_ptr = from32_ptr;
andreikovacs 0:764779eedf2d 176 to_ptr = to32_ptr;
andreikovacs 0:764779eedf2d 177 }
andreikovacs 0:764779eedf2d 178
andreikovacs 0:764779eedf2d 179 /* Copy all remaining bytes */
andreikovacs 0:764779eedf2d 180 if (number_of_bytes & 2)
andreikovacs 0:764779eedf2d 181 {
andreikovacs 0:764779eedf2d 182 from16_ptr = (uint16_t*)from_ptr;
andreikovacs 0:764779eedf2d 183 to16_ptr = (uint16_t*)to_ptr;
andreikovacs 0:764779eedf2d 184
andreikovacs 0:764779eedf2d 185 *to16_ptr++ = *from16_ptr++;
andreikovacs 0:764779eedf2d 186
andreikovacs 0:764779eedf2d 187 from_ptr = from16_ptr;
andreikovacs 0:764779eedf2d 188 to_ptr = to16_ptr;
andreikovacs 0:764779eedf2d 189 }
andreikovacs 0:764779eedf2d 190
andreikovacs 0:764779eedf2d 191 if (number_of_bytes & 1)
andreikovacs 0:764779eedf2d 192 {
andreikovacs 0:764779eedf2d 193 *(uint8_t*)to_ptr = *(uint8_t*)from_ptr;
andreikovacs 0:764779eedf2d 194 }
andreikovacs 0:764779eedf2d 195 }
andreikovacs 0:764779eedf2d 196
andreikovacs 0:764779eedf2d 197
andreikovacs 0:764779eedf2d 198 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 199 * \brief Copy bytes from one buffer to another. The buffers should not overlap.
andreikovacs 0:764779eedf2d 200 * The function can copy in either direction. If 'dir' is TRUE, then the function
andreikovacs 0:764779eedf2d 201 * works like FLib_MemCpy(). If FALSE, the function swaps the buffer pointers
andreikovacs 0:764779eedf2d 202 * before copying.
andreikovacs 0:764779eedf2d 203 *
andreikovacs 0:764779eedf2d 204 * \param[in, out] pBuf1 Pointer to the destination/source buffer.
andreikovacs 0:764779eedf2d 205 *
andreikovacs 0:764779eedf2d 206 * \param[in, out] pBuf2 Pointer to the source/destination buffer.
andreikovacs 0:764779eedf2d 207 *
andreikovacs 0:764779eedf2d 208 * \param[in] dir Direction to copy: pBuf2->pBuf1 if TRUE, pBuf1->pBuf2 if FALSE
andreikovacs 0:764779eedf2d 209 *
andreikovacs 0:764779eedf2d 210 * \param[in] n Number of bytes to copy.
andreikovacs 0:764779eedf2d 211 *
andreikovacs 0:764779eedf2d 212 * \post The source and destination buffers must not overlap.
andreikovacs 0:764779eedf2d 213 *
andreikovacs 0:764779eedf2d 214 * \remarks
andreikovacs 0:764779eedf2d 215 *
andreikovacs 0:764779eedf2d 216 ********************************************************************************** */
andreikovacs 0:764779eedf2d 217 void FLib_MemCpyDir (void* pBuf1,
andreikovacs 0:764779eedf2d 218 void* pBuf2,
andreikovacs 0:764779eedf2d 219 bool_t dir,
andreikovacs 0:764779eedf2d 220 uint32_t n)
andreikovacs 0:764779eedf2d 221 {
andreikovacs 0:764779eedf2d 222 if (dir)
andreikovacs 0:764779eedf2d 223 {
andreikovacs 0:764779eedf2d 224 FLib_MemCpy (pBuf1, pBuf2, n);
andreikovacs 0:764779eedf2d 225 }
andreikovacs 0:764779eedf2d 226 else
andreikovacs 0:764779eedf2d 227 {
andreikovacs 0:764779eedf2d 228 FLib_MemCpy (pBuf2, pBuf1, n);
andreikovacs 0:764779eedf2d 229 }
andreikovacs 0:764779eedf2d 230 }
andreikovacs 0:764779eedf2d 231
andreikovacs 0:764779eedf2d 232
andreikovacs 0:764779eedf2d 233 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 234 * \brief The byte at index i from the source buffer is copied to index ((n-1) - i)
andreikovacs 0:764779eedf2d 235 * in the destination buffer (and vice versa).
andreikovacs 0:764779eedf2d 236 *
andreikovacs 0:764779eedf2d 237 * \param[in, out] pDst Pointer to the destination buffer.
andreikovacs 0:764779eedf2d 238 *
andreikovacs 0:764779eedf2d 239 * \param[in] pSrc Pointer to the source buffer.
andreikovacs 0:764779eedf2d 240 *
andreikovacs 0:764779eedf2d 241 * \param[in] cBytes Number of bytes to copy.
andreikovacs 0:764779eedf2d 242 *
andreikovacs 0:764779eedf2d 243 * \post
andreikovacs 0:764779eedf2d 244 *
andreikovacs 0:764779eedf2d 245 * \remarks
andreikovacs 0:764779eedf2d 246 *
andreikovacs 0:764779eedf2d 247 ********************************************************************************** */
andreikovacs 0:764779eedf2d 248 void FLib_MemCpyReverseOrder (void* pDst,
andreikovacs 0:764779eedf2d 249 void* pSrc,
andreikovacs 0:764779eedf2d 250 uint32_t cBytes)
andreikovacs 0:764779eedf2d 251 {
andreikovacs 0:764779eedf2d 252 if(cBytes == 0)
andreikovacs 0:764779eedf2d 253 {
andreikovacs 0:764779eedf2d 254 return;
andreikovacs 0:764779eedf2d 255 }
andreikovacs 0:764779eedf2d 256 pDst = (uint8_t*)pDst + (uint32_t)(cBytes-1);
andreikovacs 0:764779eedf2d 257 while (cBytes)
andreikovacs 0:764779eedf2d 258 {
andreikovacs 0:764779eedf2d 259 *((uint8_t*)pDst) = *((uint8_t*)pSrc);
andreikovacs 0:764779eedf2d 260 pDst = (uint8_t*)pDst-1;
andreikovacs 0:764779eedf2d 261 pSrc = (uint8_t*)pSrc+1;
andreikovacs 0:764779eedf2d 262 cBytes--;
andreikovacs 0:764779eedf2d 263 }
andreikovacs 0:764779eedf2d 264 }
andreikovacs 0:764779eedf2d 265
andreikovacs 0:764779eedf2d 266
andreikovacs 0:764779eedf2d 267 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 268 * \brief This function compares two buffers.
andreikovacs 0:764779eedf2d 269 *
andreikovacs 0:764779eedf2d 270 * \param[in] pData1 First buffer to compare.
andreikovacs 0:764779eedf2d 271 *
andreikovacs 0:764779eedf2d 272 * \param[in] pData2 Second buffer to compare.
andreikovacs 0:764779eedf2d 273 *
andreikovacs 0:764779eedf2d 274 * \param[in] cBytes Number of bytes to compare.
andreikovacs 0:764779eedf2d 275 *
andreikovacs 0:764779eedf2d 276 * \return This function return TRUE if the buffers are equal and FALSE otherwise.
andreikovacs 0:764779eedf2d 277 *
andreikovacs 0:764779eedf2d 278 * \post
andreikovacs 0:764779eedf2d 279 *
andreikovacs 0:764779eedf2d 280 * \remarks
andreikovacs 0:764779eedf2d 281 *
andreikovacs 0:764779eedf2d 282 ********************************************************************************** */
andreikovacs 0:764779eedf2d 283 bool_t FLib_MemCmp (void* pData1, // IN: First memory block to compare
andreikovacs 0:764779eedf2d 284 void* pData2, // IN: Second memory block to compare
andreikovacs 0:764779eedf2d 285 uint32_t cBytes // IN: Number of bytes to compare.
andreikovacs 0:764779eedf2d 286 )
andreikovacs 0:764779eedf2d 287 {
andreikovacs 0:764779eedf2d 288 #if gUseToolchainMemFunc_d
andreikovacs 0:764779eedf2d 289 if( memcmp(pData1, pData2, cBytes) )
andreikovacs 0:764779eedf2d 290 return FALSE;
andreikovacs 0:764779eedf2d 291 #else
andreikovacs 0:764779eedf2d 292 while (cBytes)
andreikovacs 0:764779eedf2d 293 {
andreikovacs 0:764779eedf2d 294 if ( *((uint8_t *)pData1) != *((uint8_t *)pData2))
andreikovacs 0:764779eedf2d 295 {
andreikovacs 0:764779eedf2d 296 return FALSE;
andreikovacs 0:764779eedf2d 297 }
andreikovacs 0:764779eedf2d 298
andreikovacs 0:764779eedf2d 299 pData2 = (uint8_t* )pData2+1;
andreikovacs 0:764779eedf2d 300 pData1 = (uint8_t* )pData1+1;
andreikovacs 0:764779eedf2d 301 cBytes--;
andreikovacs 0:764779eedf2d 302 }
andreikovacs 0:764779eedf2d 303 #endif
andreikovacs 0:764779eedf2d 304 return TRUE;
andreikovacs 0:764779eedf2d 305 }
andreikovacs 0:764779eedf2d 306
andreikovacs 0:764779eedf2d 307
andreikovacs 0:764779eedf2d 308 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 309 * \brief This function resets all bytes in a specified buffer to a set value.
andreikovacs 0:764779eedf2d 310 *
andreikovacs 0:764779eedf2d 311 * \param[in,out] pDst Address of the buffer to set.
andreikovacs 0:764779eedf2d 312 *
andreikovacs 0:764779eedf2d 313 * \param[in] value Set value.
andreikovacs 0:764779eedf2d 314 *
andreikovacs 0:764779eedf2d 315 * \param[in] cBytes Number of bytes to set in the buffer (maximum 255 bytes).
andreikovacs 0:764779eedf2d 316 *
andreikovacs 0:764779eedf2d 317 * \post
andreikovacs 0:764779eedf2d 318 *
andreikovacs 0:764779eedf2d 319 * \remarks
andreikovacs 0:764779eedf2d 320 *
andreikovacs 0:764779eedf2d 321 ********************************************************************************** */
andreikovacs 0:764779eedf2d 322 void FLib_MemSet (void* pDst,
andreikovacs 0:764779eedf2d 323 uint8_t value,
andreikovacs 0:764779eedf2d 324 uint32_t cBytes)
andreikovacs 0:764779eedf2d 325 {
andreikovacs 0:764779eedf2d 326 #if gUseToolchainMemFunc_d
andreikovacs 0:764779eedf2d 327 memset(pDst, value, cBytes);
andreikovacs 0:764779eedf2d 328 #else
andreikovacs 0:764779eedf2d 329 while (cBytes)
andreikovacs 0:764779eedf2d 330 {
andreikovacs 0:764779eedf2d 331 ((uint8_t* )pDst)[--cBytes] = value;
andreikovacs 0:764779eedf2d 332 }
andreikovacs 0:764779eedf2d 333 #endif
andreikovacs 0:764779eedf2d 334 }
andreikovacs 0:764779eedf2d 335
andreikovacs 0:764779eedf2d 336
andreikovacs 0:764779eedf2d 337 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 338 * \brief This function copies a buffer,
andreikovacs 0:764779eedf2d 339 * possibly into the same overlapping memory as it is taken from
andreikovacs 0:764779eedf2d 340 *
andreikovacs 0:764779eedf2d 341 * \param[in, out] pDst Pointer to the destination buffer.
andreikovacs 0:764779eedf2d 342 *
andreikovacs 0:764779eedf2d 343 * \param[in] pSrc Pointer to the source buffer.
andreikovacs 0:764779eedf2d 344 *
andreikovacs 0:764779eedf2d 345 * \param[in] cBytes Number of bytes to copy.
andreikovacs 0:764779eedf2d 346 *
andreikovacs 0:764779eedf2d 347 * \post
andreikovacs 0:764779eedf2d 348 *
andreikovacs 0:764779eedf2d 349 * \remarks
andreikovacs 0:764779eedf2d 350 *
andreikovacs 0:764779eedf2d 351 ********************************************************************************** */
andreikovacs 0:764779eedf2d 352 void FLib_MemInPlaceCpy (void* pDst,
andreikovacs 0:764779eedf2d 353 void* pSrc,
andreikovacs 0:764779eedf2d 354 uint32_t cBytes)
andreikovacs 0:764779eedf2d 355 {
andreikovacs 0:764779eedf2d 356 if (pDst != pSrc)
andreikovacs 0:764779eedf2d 357 {
andreikovacs 0:764779eedf2d 358 /* Do nothing if copying to same position */
andreikovacs 0:764779eedf2d 359 if (pDst < pSrc)
andreikovacs 0:764779eedf2d 360 {
andreikovacs 0:764779eedf2d 361 /* If dst is before src in memory copy forward */
andreikovacs 0:764779eedf2d 362 #if gUseToolchainMemFunc_d
andreikovacs 0:764779eedf2d 363 memcpy(pDst, pSrc, cBytes);
andreikovacs 0:764779eedf2d 364 #else
andreikovacs 0:764779eedf2d 365 while (cBytes)
andreikovacs 0:764779eedf2d 366 {
andreikovacs 0:764779eedf2d 367 *((uint8_t*)pDst) = *((uint8_t*)pSrc);
andreikovacs 0:764779eedf2d 368 pDst = ((uint8_t*)pDst)+1;
andreikovacs 0:764779eedf2d 369 pSrc = ((uint8_t*)pSrc)+1;
andreikovacs 0:764779eedf2d 370 cBytes--;
andreikovacs 0:764779eedf2d 371 }
andreikovacs 0:764779eedf2d 372 #endif
andreikovacs 0:764779eedf2d 373 }
andreikovacs 0:764779eedf2d 374 else
andreikovacs 0:764779eedf2d 375 {
andreikovacs 0:764779eedf2d 376 /* If dst is after src in memory copy backward */
andreikovacs 0:764779eedf2d 377 while(cBytes)
andreikovacs 0:764779eedf2d 378 {
andreikovacs 0:764779eedf2d 379 cBytes--;
andreikovacs 0:764779eedf2d 380 ((uint8_t* )pDst)[cBytes] = ((uint8_t* )pSrc)[cBytes];
andreikovacs 0:764779eedf2d 381 }
andreikovacs 0:764779eedf2d 382 }
andreikovacs 0:764779eedf2d 383 }
andreikovacs 0:764779eedf2d 384 }
andreikovacs 0:764779eedf2d 385
andreikovacs 0:764779eedf2d 386 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 387 * \brief This function copies a 16bit value to an unaligned a memory block.
andreikovacs 0:764779eedf2d 388 *
andreikovacs 0:764779eedf2d 389 * \param[in, out] pDst Pointer to the destination memory block.
andreikovacs 0:764779eedf2d 390 *
andreikovacs 0:764779eedf2d 391 * \param[in] val16 The value to be copied.
andreikovacs 0:764779eedf2d 392 *
andreikovacs 0:764779eedf2d 393 ********************************************************************************** */
andreikovacs 0:764779eedf2d 394 void FLib_MemCopy16Unaligned (void* pDst,
andreikovacs 0:764779eedf2d 395 uint16_t val16)
andreikovacs 0:764779eedf2d 396 {
andreikovacs 0:764779eedf2d 397 uint8_t* pData = (uint8_t*)pDst;
andreikovacs 0:764779eedf2d 398
andreikovacs 0:764779eedf2d 399 *pData++ = (uint8_t)(val16);
andreikovacs 0:764779eedf2d 400 *pData = (uint8_t)(val16 >> 8);
andreikovacs 0:764779eedf2d 401
andreikovacs 0:764779eedf2d 402 return;
andreikovacs 0:764779eedf2d 403 }
andreikovacs 0:764779eedf2d 404
andreikovacs 0:764779eedf2d 405
andreikovacs 0:764779eedf2d 406 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 407 * \brief This function copies a 32bit value to an unaligned a memory block.
andreikovacs 0:764779eedf2d 408 *
andreikovacs 0:764779eedf2d 409 * \param[in, out] pDst Pointer to the destination memory block.
andreikovacs 0:764779eedf2d 410 *
andreikovacs 0:764779eedf2d 411 * \param[in] val32 The value to be copied.
andreikovacs 0:764779eedf2d 412 *
andreikovacs 0:764779eedf2d 413 ********************************************************************************** */
andreikovacs 0:764779eedf2d 414 void FLib_MemCopy32Unaligned (void* pDst,
andreikovacs 0:764779eedf2d 415 uint32_t val32)
andreikovacs 0:764779eedf2d 416 {
andreikovacs 0:764779eedf2d 417 uint8_t* pData = (uint8_t*)pDst;
andreikovacs 0:764779eedf2d 418
andreikovacs 0:764779eedf2d 419 *pData++ = (uint8_t)(val32);
andreikovacs 0:764779eedf2d 420 *pData++ = (uint8_t)(val32 >> 8);
andreikovacs 0:764779eedf2d 421 *pData++ = (uint8_t)(val32 >> 16);
andreikovacs 0:764779eedf2d 422 *pData++ = (uint8_t)(val32 >> 24);
andreikovacs 0:764779eedf2d 423
andreikovacs 0:764779eedf2d 424 return;
andreikovacs 0:764779eedf2d 425 }
andreikovacs 0:764779eedf2d 426
andreikovacs 0:764779eedf2d 427
andreikovacs 0:764779eedf2d 428 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 429 * \brief This function copies a 64bit value to an unaligned a memory block.
andreikovacs 0:764779eedf2d 430 *
andreikovacs 0:764779eedf2d 431 * \param[in, out] pDst Pointer to the destination memory block.
andreikovacs 0:764779eedf2d 432 *
andreikovacs 0:764779eedf2d 433 * \param[in] val64 The value to be copied.
andreikovacs 0:764779eedf2d 434 *
andreikovacs 0:764779eedf2d 435 ********************************************************************************** */
andreikovacs 0:764779eedf2d 436 void FLib_MemCopy64Unaligned (void* pDst,
andreikovacs 0:764779eedf2d 437 uint64_t val64)
andreikovacs 0:764779eedf2d 438 {
andreikovacs 0:764779eedf2d 439 uint8_t* pData = (uint8_t*)pDst;
andreikovacs 0:764779eedf2d 440
andreikovacs 0:764779eedf2d 441 *pData++ = (uint8_t)(val64);
andreikovacs 0:764779eedf2d 442 *pData++ = (uint8_t)(val64 >> 8);
andreikovacs 0:764779eedf2d 443 *pData++ = (uint8_t)(val64 >> 16);
andreikovacs 0:764779eedf2d 444 *pData++ = (uint8_t)(val64 >> 24);
andreikovacs 0:764779eedf2d 445 *pData++ = (uint8_t)(val64 >> 32);
andreikovacs 0:764779eedf2d 446 *pData++ = (uint8_t)(val64 >> 40);
andreikovacs 0:764779eedf2d 447 *pData++ = (uint8_t)(val64 >> 48);
andreikovacs 0:764779eedf2d 448 *pData = (uint8_t)(val64 >> 56);
andreikovacs 0:764779eedf2d 449
andreikovacs 0:764779eedf2d 450 return;
andreikovacs 0:764779eedf2d 451 }
andreikovacs 0:764779eedf2d 452
andreikovacs 0:764779eedf2d 453
andreikovacs 0:764779eedf2d 454 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 455 * \brief This function adds an offset to a pointer.
andreikovacs 0:764779eedf2d 456 *
andreikovacs 0:764779eedf2d 457 * \param[in,out] pPtr Pointer to the pointer to add the offset to
andreikovacs 0:764779eedf2d 458 *
andreikovacs 0:764779eedf2d 459 * \param[in] offset Offset to add to the specified pointer.
andreikovacs 0:764779eedf2d 460 *
andreikovacs 0:764779eedf2d 461 * \post
andreikovacs 0:764779eedf2d 462 *
andreikovacs 0:764779eedf2d 463 * \remarks
andreikovacs 0:764779eedf2d 464 *
andreikovacs 0:764779eedf2d 465 ********************************************************************************** */
andreikovacs 0:764779eedf2d 466 void FLib_AddOffsetToPointer (void** pPtr,
andreikovacs 0:764779eedf2d 467 uint32_t offset)
andreikovacs 0:764779eedf2d 468 {
andreikovacs 0:764779eedf2d 469 (*pPtr) = ((uint8_t* )*pPtr) + offset;
andreikovacs 0:764779eedf2d 470 }
andreikovacs 0:764779eedf2d 471
andreikovacs 0:764779eedf2d 472
andreikovacs 0:764779eedf2d 473 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 474 * \brief This function returns the length of a NULL terminated string.
andreikovacs 0:764779eedf2d 475 *
andreikovacs 0:764779eedf2d 476 * \param[in] str A NULL terminated string
andreikovacs 0:764779eedf2d 477 *
andreikovacs 0:764779eedf2d 478 * \return the size of string in bytes
andreikovacs 0:764779eedf2d 479 *
andreikovacs 0:764779eedf2d 480 ********************************************************************************** */
andreikovacs 0:764779eedf2d 481 uint32_t FLib_StrLen(char *str)
andreikovacs 0:764779eedf2d 482 {
andreikovacs 0:764779eedf2d 483 #if gUseToolchainMemFunc_d
andreikovacs 0:764779eedf2d 484 return strlen(str);
andreikovacs 0:764779eedf2d 485 #else
andreikovacs 0:764779eedf2d 486 register uint32_t len=0;
andreikovacs 0:764779eedf2d 487
andreikovacs 0:764779eedf2d 488 while(*str != '\0')
andreikovacs 0:764779eedf2d 489 {
andreikovacs 0:764779eedf2d 490 str++;
andreikovacs 0:764779eedf2d 491 len++;
andreikovacs 0:764779eedf2d 492 }
andreikovacs 0:764779eedf2d 493
andreikovacs 0:764779eedf2d 494 return len;
andreikovacs 0:764779eedf2d 495 #endif
andreikovacs 0:764779eedf2d 496 }