se.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2017 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <kernel.h>
  7. #include <init.h>
  8. #include <device.h>
  9. #include <stdint.h>
  10. #include <stdbool.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <drivers/se/se.h>
  15. K_MUTEX_DEFINE(se_lock);
  16. /****************************************************************************
  17. * Name: se_memcpy
  18. *
  19. * Description:
  20. * copy data from src to dst according to memory type.
  21. *
  22. ****************************************************************************/
  23. void se_memcpy(void *out, const void *in,
  24. size_t size, uint8_t direct)
  25. {
  26. size_t i;
  27. size_t wcount = size / 4;
  28. if (direct == CPY_MEMU8_TO_FIFO) {
  29. for (i = 0; i < size; i++) {
  30. *(uint32_t *)out = *(uint8_t *)in;
  31. in = (uint8_t *)in + 1;
  32. }
  33. }
  34. else if (direct == CPY_MEM_TO_FIFO) {
  35. for (i = 0; i < wcount; i++) {
  36. *(uint32_t *)out = *(uint32_t *)in;
  37. in = (uint8_t *)in + 4;
  38. }
  39. } else if (direct == CPY_FIFO_TO_MEM) {
  40. for (i = 0; i < wcount; i++) {
  41. *(uint32_t *)out = *(uint32_t *)in;
  42. out = (uint8_t *)out + 4;
  43. }
  44. } else {
  45. for (i = 0; i < wcount; i++) {
  46. *(uint32_t *)out = *(uint32_t *)in;
  47. in = (uint8_t *)in + 4;
  48. out = (uint8_t *)out + 4;
  49. }
  50. }
  51. }