dsp_common.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2022 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. #ifndef _DSP_COMMON_H_
  19. #define _DSP_COMMON_H_
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <memory.h>
  24. #define DSP_MIN(a, b) ((a) < (b) ? (a) : (b))
  25. #define DSP_MAX(a, b) ((a) > (b) ? (a) : (b))
  26. #define DSP_ALIGN_UP(num, bits) (((num) + (1 << (bits)) - 1) & ~((1 << (bits)) - 1))
  27. #define DSP_ZERO_MEMORY(data) \
  28. { \
  29. memset(data, 0, sizeof(*(data))); \
  30. }
  31. #define DSP_MEMCPY(dst, src, size) \
  32. { \
  33. memcpy(dst, src, size); \
  34. }
  35. #define DSP_SAFE_FREE(buf) \
  36. { \
  37. if (buf != NULL) \
  38. { \
  39. free(buf); \
  40. buf = NULL; \
  41. } \
  42. }
  43. #define DSP_PRINT(level, ...) \
  44. { \
  45. if (log_level >= CSI_DSP_LOG_##level) \
  46. { \
  47. printf("CSI_DSP[%d] %s,(%s,%d): ", pid, #level,__FUNCTION__,__LINE__); \
  48. printf(__VA_ARGS__); \
  49. } \
  50. }
  51. #define DSP_PRINT_RETURN(retcode, level, ...) \
  52. { \
  53. DSP_PRINT(level, __VA_ARGS__) \
  54. return retcode; \
  55. }
  56. #define DSP_CHECK_CONDITION(cond, retcode, ...) \
  57. if (cond) \
  58. { \
  59. DSP_PRINT(ERROR, __VA_ARGS__) \
  60. return retcode; \
  61. }
  62. typedef enum log_level
  63. {
  64. CSI_DSP_LOG_QUIET = 0,
  65. CSI_DSP_LOG_ERROR,
  66. CSI_DSP_LOG_WARNING,
  67. CSI_DSP_LOG_INFO,
  68. CSI_DSP_LOG_DEBUG,
  69. CSI_DSP_LOG_TRACE,
  70. CSI_DSP_LOG_MAX
  71. } csi_dsp_log_level;
  72. extern int log_level;
  73. extern int pid;
  74. void dsp_InitEnv();
  75. #endif