isp_hw.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "isp_hw.h"
  20. #include "isp_common.h"
  21. #include "dsp_ps_debug.h"
  22. #include <xtensa/config/core.h>
  23. #define ISP_INT_DEBUG
  24. #define XCHAL_ISP_INTERRUPT_MASK
  25. #define XCHAL_ISP_INTERRUPT_LEVEL 15
  26. static uint32_t isp_int_tick[1536];
  27. static uint32_t isp_int_cnt =0;
  28. extern Sisp_handler g_isp_handler;
  29. extern void set_post_isp_ae_remap();
  30. void isp_interrupt_handler(void *data) {
  31. uint32_t mi3= READ_ISP_MI3_INT(g_isp_handler.id);
  32. uint16_t line_entry = READ_ISP_N_COUNTER_REG(g_isp_handler.id);
  33. uint32_t mi = READ_ISP_MI_INT(g_isp_handler.id);
  34. uint32_t mi2 = READ_ISP_MI2_INT(g_isp_handler.id);
  35. #ifdef ISP_INT_DEBUG
  36. isp_int_tick[isp_int_cnt++%1536]=mi3;
  37. isp_int_tick[isp_int_cnt++%1536]=mi;
  38. isp_int_tick[isp_int_cnt++%1536]=READ_ISP_MI1_INT(g_isp_handler.id);
  39. isp_int_tick[isp_int_cnt++%1536]=mi2;//ps_l32((volatile void *)ISP_MI_MIS2);
  40. isp_int_tick[isp_int_cnt++%1536]=0xf0000000|line_entry;
  41. #endif
  42. // isp_int_tick[isp_int_cnt++]=line_entry;//READ_ISP_BUFFER_START_OFFSET_REG();
  43. if(mi3&ISP_N_LINES_INT_MASK)
  44. {
  45. // ps_s32((uint32_t)(0x8), (volatile void *)ISP_N_INTERRUPT_CLEAR_REG);
  46. CLEAR_ISP_MI3_INT(g_isp_handler.id,ISP_N_LINES_INT_MASK);
  47. ispc_push_new_line(&g_isp_handler,line_entry-ispc_get_pushed_line_num(&g_isp_handler));
  48. g_isp_handler.current_N_value = line_entry;
  49. }
  50. if(mi2&ISP_PPW_FRAME_DONE)
  51. {
  52. if((isp_get_status(g_isp_handler.id)==EHW_RECOVERY_DONE))
  53. {
  54. isp_recovery_state_update(g_isp_handler.id);
  55. }
  56. else if(isp_get_status(g_isp_handler.id)==EHW_RECOVERYING)
  57. {
  58. isp_fifo_reset(0);
  59. }
  60. CLEAR_ISP_MI2_INT(g_isp_handler.id,ISP_PPW_FRAME_DONE);
  61. }
  62. if(mi&ISP_AE_INT_MASK)
  63. {
  64. CLEAR_ISP_MI_INT(g_isp_handler.id,ISP_AE_INT_MASK);
  65. SET_ISP_ISP_INT(g_isp_handler.id,0x1<<8);
  66. set_post_isp_ae_remap();
  67. }
  68. else
  69. {
  70. WRITE_ISP_CLEAR_INTERRUPT_REG(g_isp_handler.id);
  71. }
  72. return;
  73. }
  74. int32_t isp_register_interrupt(uint16_t id) {
  75. int32_t ret = 0;
  76. uint32_t int_num = id==0?XCHAL_ISP0_INTERRUPT:XCHAL_ISP1_INTERRUPT;
  77. // Normally none of these calls should fail. We don't check them
  78. // individually, any one failing will cause this function to return failure.
  79. xthal_interrupt_sens_set(int_num, 1); //0~ eage 1~ level
  80. xthal_interrupt_pri_set(int_num,XCHAL_ISP_INTERRUPT_LEVEL);
  81. ret += xtos_set_interrupt_handler(int_num,
  82. isp_interrupt_handler, NULL, NULL);
  83. ret += xtos_interrupt_enable(int_num);
  84. ps_debug("register ISP interrupt %d %s,trace buf:0x%x\n",int_num,ret==0?"success":"fail",isp_int_tick);
  85. return ret;
  86. }
  87. int32_t isp_enable_inerrupt(uint16_t id){
  88. int32_t ret = 0;
  89. uint32_t int_num = id==0?XCHAL_ISP0_INTERRUPT:XCHAL_ISP1_INTERRUPT;
  90. ret = xtos_interrupt_enable(int_num);
  91. ps_debug("Enable ISP interrupt %s\n",ret==0?"success":"fail");
  92. return ret;
  93. }
  94. int32_t isp_disable_inerrupt(uint16_t id) {
  95. int32_t ret = 0;
  96. uint32_t int_num = id==0?XCHAL_ISP0_INTERRUPT:XCHAL_ISP1_INTERRUPT;
  97. ret = xtos_interrupt_disable(int_num);
  98. ps_debug("disable ISP interrupt %s\n",ret==0?"success":"fail");
  99. return ret;
  100. }
  101. int isp_get_irq_num(uint16_t id)
  102. {
  103. return id==0?XCHAL_ISP0_INTERRUPT:XCHAL_ISP1_INTERRUPT;
  104. }