csi_dsp_helper.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <signal.h>
  6. #include <time.h>
  7. #include <sys/time.h>
  8. #include "../include/xrp_api.h"
  9. #include "../include/dsp_ps_ns.h"
  10. #include "../include/csi_dsp_api.h"
  11. #include "csi_dsp_core.h"
  12. #include "csi_dsp_task_defs.h"
  13. #include "dsp_common.h"
  14. // #include "../xrp-host/xrp_host_common.h"
  15. struct csi_dsp_instance *instance = NULL;
  16. void csi_dsp_heartbeak_polling()
  17. {
  18. dsp_handler_item_t *task_item =NULL;
  19. struct itimerval val,oval;
  20. struct csi_dsp_task_handler *task;
  21. // static counter =0;
  22. DSP_PRINT(INFO,"heartbeat checking\n");
  23. if(instance == NULL)
  24. {
  25. DSP_PRINT(WARNING,"dsp instance is NULL\n");
  26. return;
  27. }
  28. // counter++;
  29. /*close timer*/
  30. val.it_value.tv_sec = 0;
  31. val.it_value.tv_usec =0;
  32. val.it_interval.tv_sec = 0;
  33. val.it_interval.tv_usec =0;
  34. setitimer(ITIMER_REAL,&val,&oval);
  35. if(csi_dsp_cmd_send(instance->comm_queue,PS_CMD_HEART_BEAT_REQ,NULL,0,NULL,0,NULL))
  36. {
  37. DSP_PRINT(WARNING,"PS_CMD_TASK_ALLOC fail\n");
  38. s_cmd_t cmd =
  39. {
  40. .cmd=CSI_DSP_REPORT_HEARTBEAT_ERR,
  41. };
  42. list_for_each_entry(task_item,&instance->task_list,head)
  43. {
  44. task = task_item->handler;
  45. if(task->mode & CSI_DSP_TASK_HW)
  46. {
  47. if(task->cb)
  48. task->cb(task->context,&cmd);
  49. }
  50. }
  51. }
  52. /*restore timer*/
  53. setitimer(ITIMER_REAL,&oval,NULL);
  54. return;
  55. }
  56. int csi_dsp_enable_heartbeat_check(struct csi_dsp_instance *dsp ,int secs)
  57. {
  58. struct itimerval val,oval;
  59. signal(SIGALRM,csi_dsp_heartbeak_polling);
  60. val.it_value.tv_sec = secs;
  61. val.it_value.tv_usec =0;
  62. val.it_interval.tv_sec = secs;
  63. val.it_interval.tv_usec =0;
  64. instance = dsp;
  65. DSP_PRINT(DEBUG,"period:%d sec hearbeat working\n",secs);
  66. return setitimer(ITIMER_REAL,&val,&oval);
  67. }
  68. int csi_dsp_disable_heartbeat_check()
  69. {
  70. struct itimerval val;
  71. val.it_value.tv_sec = 0;
  72. val.it_value.tv_usec =0;
  73. val.it_interval.tv_sec = 0;
  74. val.it_interval.tv_usec =0;
  75. instance = NULL;
  76. DSP_PRINT(INFO,"sec hearbeat disable\n");
  77. return setitimer(ITIMER_REAL,&val,NULL);
  78. }
  79. void isp_algo_result_handler(void *context,void *data)
  80. {
  81. s_cmd_t *msg=(s_cmd_t *)data;
  82. printf("report recived:%x\n",msg->cmd);
  83. switch(msg->cmd)
  84. {
  85. case CSI_DSP_REPORT_ISP_ERR:
  86. printf("ISP error:%d\n",msg->data[0]);
  87. break;
  88. case CSI_DSP_REPORT_RY_ERR:
  89. printf("Post ISP error\n",msg->data[0]);
  90. break;
  91. case CSI_DSP_REPORT_ALGO_ERR:
  92. printf("algo err\n");
  93. break;
  94. case CSI_DSP_REPORT_VI_PRE_ERR:
  95. break;
  96. case CSI_DSP_REPORT_RESULT:
  97. break;
  98. case CSI_DSP_REPORT_HEARTBEAT_ERR:
  99. printf("heartbeat not detect\n");
  100. break;
  101. default:
  102. break;
  103. }
  104. }
  105. int csi_dsp_buf_flush( struct xrp_device *device,struct csi_dsp_buffer *buffers)
  106. {
  107. int loop;
  108. enum xrp_status status;
  109. int flag = buffers->dir == CSI_DSP_BUFFER_IN ?XRP_READ:XRP_WRITE;
  110. if(buffers->type == CSI_DSP_BUF_TYPE_DMA_BUF_IMPORT ||
  111. buffers->type == CSI_DSP_BUF_TYPE_DMA_BUF_IMPORT )
  112. {
  113. for(loop=0;loop<buffers->plane_count;loop++)
  114. {
  115. xrp_flush_dma_buf(device, buffers->planes[loop].fd,flag,&status);
  116. }
  117. }
  118. }
  119. // void hw_task_result_handler(void *context,void *data)
  120. // {
  121. // s_cmd_t *msg=(s_cmd_t *)data;
  122. // struct csi_dsp_task_handler * task = (struct csi_dsp_task_handler *)context;
  123. // printf("report recived:%x\n",msg->cmd);
  124. // switch(msg->cmd)
  125. // {
  126. // case VI_SYS_REPORT_ISP_ERR:
  127. // printf("ISP error:%d\n",msg->data[0]);
  128. // break;
  129. // case VI_SYS_REPORT_RY_ERR:
  130. // printf("Post ISP error\n",msg->data[0]);
  131. // break;
  132. // case VI_SYS_REPORT_ALGO_ERR:
  133. // printf("algo err\n");
  134. // break;
  135. // case VI_SYS_REPORT_RESULT:
  136. // if(task->cb)
  137. // {
  138. // task->cb(task->context,)
  139. // }
  140. // break;
  141. // default:
  142. // break;
  143. // }
  144. // }