ps_xrp_wrapper.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <stdint.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <xtensa/corebits.h>
  23. #include <xtensa/xtruntime.h>
  24. #if HAVE_THREADS_XOS
  25. #include <xtensa/xos.h>
  26. #endif
  27. #include "dsp_ps_debug.h"
  28. #include "xrp_api.h"
  29. #include "xrp_dsp_hw.h"
  30. #include "xrp_dsp_user.h"
  31. #include "dsp_ps_ns.h"
  32. //#include "isp_api.h"
  33. #include "dsp_ps_ns.h"
  34. #include "ps_sched.h"
  35. #include "idma_if.h"
  36. typedef void (*kernel_func) (void* info);
  37. static struct xrp_device *device;
  38. struct xrp_device * ps_xrp_device_int(int idx)
  39. {
  40. enum xrp_status status;
  41. device = xrp_open_device(idx, &status);
  42. if (status != XRP_STATUS_SUCCESS)
  43. {
  44. return NULL;
  45. }
  46. return device;
  47. }
  48. int ps_register_cmd_handler(unsigned char *nsid,xrp_command_handler *cmd_handler,void * context)
  49. {
  50. enum xrp_status status;
  51. if(device==NULL)
  52. {
  53. ps_err("device not valid\n");
  54. return -1;
  55. }
  56. xrp_device_register_namespace(device,nsid,cmd_handler, context, &status);
  57. if(status != XRP_STATUS_SUCCESS)
  58. {
  59. ps_err("register name space fail%s\n ",nsid);
  60. return -1;
  61. }
  62. return 0;
  63. }
  64. int ps_wait_host_sync()
  65. {
  66. enum xrp_status status;
  67. ps_debug("wait to sync\n");
  68. for(;;){
  69. status=xrp_device_sync(device);
  70. if(status==XRP_STATUS_SUCCESS)
  71. {
  72. break;
  73. }
  74. else if(status == XRP_STATUS_PENDING)
  75. {
  76. continue;
  77. }
  78. else
  79. {
  80. return -1;
  81. }
  82. }
  83. ps_debug("sync done!\n");
  84. return 0;
  85. }
  86. void ps_dsp_init_done()
  87. {
  88. xrp_device_init_done(device);
  89. }
  90. int ps_send_report(uint32_t id)
  91. {
  92. return xrp_send_report(device,id)==XRP_STATUS_SUCCESS? 1:0;
  93. }
  94. int ps_report_avaiable()
  95. {
  96. return xrp_get_report_status(device)==XRP_STATUS_SUCCESS? 0:-1;
  97. }
  98. int ps_get_xrp_irq()
  99. {
  100. return xrp_get_irq();
  101. }
  102. enum task_result ps_process_xrp_task(void* context)
  103. {
  104. if(XRP_STATUS_SUCCESS!=xrp_device_command_dispatch(device)){
  105. ps_err("xrp command handler fail\n");
  106. return PS_TASK_FAILURE;
  107. }
  108. return PS_TASK_SUCCESS;
  109. }