algo.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2021 Alibaba Group. All rights reserved.
  3. * License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. * not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <math.h>
  21. #include "algo.h"
  22. #include "ialgo.h"
  23. #include "xrp_api.h"
  24. #include "csi_dsp_post_process_defs.h"
  25. #include "dmaif.h"
  26. #if defined(DSP_TEST) || defined(DSP_IP_TEST) || !defined(USE_SUBFUNC_OBJ)
  27. #define LM_DRAM0(align)
  28. #define LM_DRAM1(align)
  29. #else
  30. #define LM_DRAM0(align) __attribute__((aligned(align), section(".dram0.data")))
  31. #define LM_DRAM1(align) __attribute__((aligned(align), section(".dram1.data")))
  32. #endif
  33. // 50K¿Õ¼ä
  34. #define BUFFER_SIZE (51200)
  35. static unsigned char image_in_char_tdma0[BUFFER_SIZE] LM_DRAM0(64);
  36. static unsigned char image_in_char_tdma1[BUFFER_SIZE] LM_DRAM1(64);
  37. static unsigned char image_out_char_tdma0[BUFFER_SIZE] LM_DRAM0(64);
  38. static unsigned char image_out_char_tdma1[BUFFER_SIZE] LM_DRAM1(64);
  39. #define LIB_NAME ("lib")
  40. typedef struct cb_args{
  41. char lib_name[8];
  42. char setting[16];
  43. uint32_t frame_id;
  44. uint64_t timestap;
  45. uint32_t temp_projector; //ͶÉäÆ÷ζÈ
  46. uint32_t temp_sensor; //sensor ζÈ
  47. }cb_args_t;
  48. int dsp_dummy_algo(csi_dsp_algo_param_t* param)
  49. {
  50. if(!param)
  51. {
  52. return -1;
  53. }
  54. struct csi_dsp_buffer *bufs = (struct csi_dsp_buffer *)param->buffer_struct_ptr;
  55. #if 0
  56. if(idma_copy_ext2ext(bufs[0].planes[0].buf_phy, bufs[1].planes[0].buf_phy,bufs[0].planes[0].size,
  57. image_in_char_tdma0,sizeof(image_in_char_tdma0)))
  58. {
  59. return -1;
  60. }
  61. #else
  62. int loop;
  63. TMDMA* idma_obj =dmaif_getDMACtrl();
  64. uint64_t src,dst;
  65. int tcm_size = sizeof(image_in_char_tdma0);
  66. int size = tcm_size;
  67. int index =0 ;
  68. int fragment_size ;
  69. int loop_num ;
  70. static uint64_t temp_buf=0;
  71. if(param->buffer_num < 2)
  72. {
  73. printf("buffer num %d is not expect %d\n",param->buffer_num,param->buf_desc_num);
  74. return -1;
  75. }
  76. for(index=0;index<bufs->plane_count;index++)
  77. {
  78. fragment_size = bufs[0].planes[index].size % tcm_size;
  79. loop_num = bufs[0].planes[index].size / tcm_size;
  80. loop_num = fragment_size ? loop_num + 1 : loop_num;
  81. src = bufs[0].planes[index].buf_phy;
  82. dst = bufs[1].planes[index].buf_phy;
  83. size = tcm_size;
  84. for (loop = 0; loop < loop_num; loop++) {
  85. uint64_t dst1_wide =
  86. ((uint64_t)0xffffffff) & ((uint64_t)image_in_char_tdma0);
  87. uint64_t src1_wide = (uint64_t)src + size * loop;
  88. uint64_t dst2_wide = (uint64_t)dst + size * loop;
  89. if (loop == (loop_num - 1) && fragment_size) {
  90. size = fragment_size;
  91. }
  92. idma_obj->load(NULL,dst1_wide,src1_wide,size,size,1,size,1);
  93. idma_obj->waitLoadDone(NULL);
  94. idma_obj->store(NULL,dst2_wide,dst1_wide,size,size,1,size,1);
  95. idma_obj->waitStoreDone(NULL);
  96. }
  97. }
  98. static frame_count =0;
  99. cb_args_t *report_data;
  100. if(param->extra_param_ptr!=NULL &&
  101. param->extra_param_ptr->report_buf!=NULL&&
  102. param->extra_param_ptr->report_buf_size>= sizeof(*report_data))
  103. {
  104. report_data = (cb_args_t *)param->extra_param_ptr->report_buf;
  105. // memcpy(param->extra_param_ptr->report_buf,&frame_count,sizeof(frame_count));
  106. report_data->frame_id = param->extra_param_ptr->frame_meta.frame_id;
  107. report_data->timestap = param->extra_param_ptr->frame_meta.timestap;
  108. report_data->temp_projector = param->extra_param_ptr->frame_meta.temp_projector;
  109. report_data->temp_sensor = param->extra_param_ptr->frame_meta.temp_sensor;
  110. /*loopback the setting*/
  111. if(param->set_buf_size!=0 && param->set_buf_ptr!=NULL)
  112. {
  113. memcpy(&report_data->setting[0],param->set_buf_ptr,16);
  114. }
  115. memcpy(&report_data->lib_name[0],LIB_NAME,8);
  116. param->extra_param_ptr->report_size = sizeof(*report_data);
  117. }
  118. frame_count++;
  119. #endif
  120. return 0;
  121. }
  122. algo_func dsp_dummy_algo_wrapper(csi_dsp_algo_param_t* param)
  123. {
  124. param->buf_desc_num =3;
  125. return dsp_dummy_algo;
  126. }