Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robert_jw 0:b2805b6888dc 1 /* Copyright (C) 2013 - Adam Green (https://github.com/adamgreen)
robert_jw 0:b2805b6888dc 2
robert_jw 0:b2805b6888dc 3 Licensed under the Apache License, Version 2.0 (the "License");
robert_jw 0:b2805b6888dc 4 you may not use this file except in compliance with the License.
robert_jw 0:b2805b6888dc 5 You may obtain a copy of the License at
robert_jw 0:b2805b6888dc 6
robert_jw 0:b2805b6888dc 7 http://www.apache.org/licenses/LICENSE-2.0
robert_jw 0:b2805b6888dc 8
robert_jw 0:b2805b6888dc 9 Unless required by applicable law or agreed to in writing, software
robert_jw 0:b2805b6888dc 10 distributed under the License is distributed on an "AS IS" BASIS,
robert_jw 0:b2805b6888dc 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
robert_jw 0:b2805b6888dc 12 See the License for the specific language governing permissions and
robert_jw 0:b2805b6888dc 13 limitations under the License.
robert_jw 0:b2805b6888dc 14 */
robert_jw 0:b2805b6888dc 15 #if defined(TOOLCHAIN_GCC) && defined(__thumb2__)
robert_jw 0:b2805b6888dc 16
robert_jw 0:b2805b6888dc 17 #include <stdio.h>
robert_jw 0:b2805b6888dc 18
robert_jw 0:b2805b6888dc 19
robert_jw 0:b2805b6888dc 20 /* This is a hand written Thumb-2 assembly language version of the
robert_jw 0:b2805b6888dc 21 standard C memcpy() function that can be used by the lwIP networking
robert_jw 0:b2805b6888dc 22 stack to improve its performance. It copies 4 bytes at a time and
robert_jw 0:b2805b6888dc 23 unrolls the loop to perform 4 of these copies per loop iteration.
robert_jw 0:b2805b6888dc 24 */
robert_jw 0:b2805b6888dc 25 __attribute__((naked)) void thumb2_memcpy(void* pDest, const void* pSource, size_t length)
robert_jw 0:b2805b6888dc 26 {
robert_jw 0:b2805b6888dc 27 __asm (
robert_jw 0:b2805b6888dc 28 ".syntax unified\n"
robert_jw 0:b2805b6888dc 29 ".thumb\n"
robert_jw 0:b2805b6888dc 30
robert_jw 0:b2805b6888dc 31 // Copy 16 bytes at a time first.
robert_jw 0:b2805b6888dc 32 " lsrs r3, r2, #4\n"
robert_jw 0:b2805b6888dc 33 " beq.n 2$\n"
robert_jw 0:b2805b6888dc 34 "1$: ldr r12, [r1], #4\n"
robert_jw 0:b2805b6888dc 35 " str r12, [r0], #4\n"
robert_jw 0:b2805b6888dc 36 " ldr r12, [r1], #4\n"
robert_jw 0:b2805b6888dc 37 " str r12, [r0], #4\n"
robert_jw 0:b2805b6888dc 38 " ldr r12, [r1], #4\n"
robert_jw 0:b2805b6888dc 39 " str r12, [r0], #4\n"
robert_jw 0:b2805b6888dc 40 " ldr r12, [r1], #4\n"
robert_jw 0:b2805b6888dc 41 " str r12, [r0], #4\n"
robert_jw 0:b2805b6888dc 42 " subs r3, #1\n"
robert_jw 0:b2805b6888dc 43 " bne 1$\n"
robert_jw 0:b2805b6888dc 44
robert_jw 0:b2805b6888dc 45 // Copy byte by byte for what is left.
robert_jw 0:b2805b6888dc 46 "2$:\n"
robert_jw 0:b2805b6888dc 47 " ands r3, r2, #0xf\n"
robert_jw 0:b2805b6888dc 48 " beq.n 4$\n"
robert_jw 0:b2805b6888dc 49 "3$: ldrb r12, [r1], #1\n"
robert_jw 0:b2805b6888dc 50 " strb r12, [r0], #1\n"
robert_jw 0:b2805b6888dc 51 " subs r3, #1\n"
robert_jw 0:b2805b6888dc 52 " bne 3$\n"
robert_jw 0:b2805b6888dc 53
robert_jw 0:b2805b6888dc 54 // Return to caller.
robert_jw 0:b2805b6888dc 55 "4$: bx lr\n"
robert_jw 0:b2805b6888dc 56 );
robert_jw 0:b2805b6888dc 57 }
robert_jw 0:b2805b6888dc 58
robert_jw 0:b2805b6888dc 59 #endif