hal_adi_bus.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _HAL_ADI_H_
  13. #define _HAL_ADI_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include "hal_config.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * mask indicates write rather than read-modify-write
  23. */
  24. #define HAL_ADI_BUS_OVERWITE(value) (0xffffffff), (value)
  25. /**
  26. * indicates end of variadic variables of \p halAdiBusBatchChange
  27. */
  28. #define HAL_ADI_BUS_CHANGE_END (0)
  29. /**
  30. * @brief initialize ADI bus
  31. */
  32. void halAdiBusInit(void);
  33. /**
  34. * @brief ADI bus resume after sleep
  35. *
  36. * ADI bus won't use suspend and resume callback mechanism. Otherwise,
  37. * it is tedious to check and avoid ADI access before ADI bus resume.
  38. */
  39. void halAdiBusResume(void);
  40. /**
  41. * @brief read register through ADI bus
  42. *
  43. * @param reg register physical address
  44. * @return read value
  45. */
  46. uint32_t halAdiBusRead(volatile uint32_t *reg);
  47. /**
  48. * @brief read register through ADI bus
  49. *
  50. * @param reg register physical address
  51. * @param value value to be written
  52. */
  53. void halAdiBusWrite(volatile uint32_t *reg, uint32_t value);
  54. /**
  55. * @brief change register
  56. *
  57. * When \p write_mask is not all 1s, the operation is read-modify-write.
  58. *
  59. * new_value = (old_value & ~writ_mask) | (write_value & write_mask)
  60. *
  61. * @param reg register physical address
  62. * @param write_mask mask for change, 1 for change, 0 for no change
  63. * @param write_value value to be changed
  64. * @return the value to be written
  65. */
  66. uint32_t halAdiBusChange(volatile uint32_t *reg, uint32_t write_mask, uint32_t write_value);
  67. /**
  68. * @brief batch change registers
  69. *
  70. * Batch change several registers through ADI bus. When \p write_mask is
  71. * not all 1s, the operation is read-modify-write.
  72. *
  73. * new_value = (old_value & ~writ_mask) | (write_value & write_mask)
  74. *
  75. * \p reg value of 0 indicates the end of variadic variables.
  76. *
  77. * @param reg register physical address
  78. * @param write_mask mask for change, 1 for change, 0 for no change
  79. * @param write_value value to be changed
  80. */
  81. void halAdiBusBatchChange(volatile uint32_t *reg, uint32_t write_mask, uint32_t write_value, ...);
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif