idma_wraper.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * idma_wraper.c
  3. *
  4. * Created on: 2021Äê5ÔÂ14ÈÕ
  5. * Author: DELL
  6. */
  7. #include <xtensa/hal.h>
  8. #include <xtensa/idma.h>
  9. #include "dsp_ps_debug.h"
  10. // Define this to enable the wide address API.
  11. #define IDMA_USE_WIDE_ADDRESS_COMPILE 1
  12. // Define this to enable the large Description API.
  13. #define IDMA_USE_64B_DESC 1
  14. //#define IDMA_DEBUG 1
  15. static IDMA_BUFFER_DEFINE(idma_copy, 2, IDMA_64B_DESC);
  16. static int do_cnt;
  17. static int trans_cnt=0;
  18. static uint64_t idma_hb[1536];
  19. static void
  20. idmaErrCB(const idma_error_details_t* data)
  21. {
  22. idma_error_details_t* error = idma_error_details(IDMA_CHAN_FUNC_ARG);
  23. uint32_t idma_status = (uint32_t) READ_IDMA_REG(0, IDMA_REG_STATUS);
  24. printf("COPY FAILED, status :0x%x,Error 0x%x at desc:%p, PIF src/dst=%x/%x\n", idma_status,error->err_type, (void*)error->currDesc, error->srcAddr, error->dstAddr);
  25. }
  26. static void
  27. idmaDoneCB(void* data)
  28. {
  29. do_cnt=1;
  30. }
  31. int idma_inition()
  32. {
  33. idma_init(0, MAX_BLOCK_16, 32, TICK_CYCLES_8, 100000, idmaErrCB);
  34. return 0;
  35. }
  36. int idma_copy_ext2ext(uint64_t src_addr, uint64_t dst_addr, uint32_t block_size,
  37. uint32_t temp_buffer,uint32_t buffer_size) {
  38. // Construct wide pointers for the 3 buffers. Note that the addresses for
  39. // the two buffers in local memory must not have any of the high bits set or
  40. // else they'll look like sysmem addresses.
  41. int loop;
  42. int fragment_size = block_size % buffer_size;
  43. int loop_num = block_size / buffer_size;
  44. int ret = 0;
  45. int size = buffer_size;
  46. loop_num = fragment_size ? loop_num + 1 : loop_num;
  47. uint32_t frame_counter = 0;
  48. uint32_t start,end;
  49. // src_addr = 0xcce06000;
  50. // idma_log_handler(idmaLogHander);
  51. // idma_init(0, MAX_BLOCK_16, 32, TICK_CYCLES_8, 100000, idmaErrCB);
  52. for (loop = 0; loop < loop_num; loop++) {
  53. uint64_t dst1_wide =
  54. ((uint64_t)0xffffffff) & ((uint64_t)temp_buffer);
  55. uint64_t src1_wide = src_addr + size * loop;
  56. uint64_t dst2_wide = dst_addr + size * loop;
  57. if (loop == (loop_num - 1) && fragment_size) {
  58. size = fragment_size;
  59. }
  60. idma_init_task(idma_copy, IDMA_64B_DESC, 2, idmaDoneCB, idma_copy);
  61. idma_add_desc64_wide(idma_copy, &dst1_wide, &src1_wide, size, 0);
  62. idma_add_desc64_wide(idma_copy, &dst2_wide, &dst1_wide, size,
  63. DESC_NOTIFY_W_INT);
  64. do_cnt=0;
  65. ret = idma_schedule_task(idma_copy);
  66. start = XT_RSR_CCOUNT();
  67. if (ret != IDMA_OK) {
  68. ps_debug("FAILED to schedule taskh: %d\n", ret);
  69. return -1;
  70. }
  71. idma_hw_wait_all();
  72. while(do_cnt==0)
  73. {
  74. ;
  75. }
  76. // idma_hb[trans_cnt++]=src_addr;
  77. // idma_hb[trans_cnt++]=dst_addr;
  78. end = XT_RSR_CCOUNT();
  79. }
  80. return 0;
  81. }