summaryrefslogtreecommitdiffstats
path: root/bsps/arm/atsam/start/iocopy.c
blob: 53ef606cd912f56b6391ac9175833a256218dc4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (c) 2018 embedded brains GmbH.  All rights reserved.
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#include <bsp/iocopy.h>

static void atsam_do_copy(
  uint8_t *dst,
  const uint8_t *src,
  size_t n,
  bool aligned
)
{
  if (aligned) {
    while (n > 3) {
      *(uint32_t *)dst = *(uint32_t *)src;
      dst += 4;
      src += 4;
      n -= 4;
    }
  }

  while (n > 0) {
    *dst = *src;
    ++dst;
    ++src;
    --n;
  }
}

void atsam_copy_to_io(void *dst, const void *src, size_t n)
{
  atsam_do_copy(dst, src, n, ((uintptr_t)dst) % 4 == 0);
}

void atsam_copy_from_io(void *dst, const void *src, size_t n)
{
  atsam_do_copy(dst, src, n, ((uintptr_t)src) % 4 == 0);
}