1 /* 2 * Copyright 2017-2018, NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __SRTM_AUDIO_SERVICE_H__ 10 #define __SRTM_AUDIO_SERVICE_H__ 11 12 #include "srtm_service.h" 13 14 /*! 15 * @addtogroup srtm_service 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 /** @brief Switch to disable Audio service debugging messages. */ 23 #ifndef SRTM_AUDIO_SERVICE_DEBUG_OFF 24 #define SRTM_AUDIO_SERVICE_DEBUG_OFF (0) 25 #endif 26 27 #if SRTM_AUDIO_SERVICE_DEBUG_OFF 28 #undef SRTM_DEBUG_VERBOSE_LEVEL 29 #define SRTM_DEBUG_VERBOSE_LEVEL SRTM_DEBUG_VERBOSE_NONE 30 #endif 31 32 /* The preallocated prcedure messages for use in ISR. */ 33 #ifndef SRTM_AUDIO_SERVICE_CONFIG_PROC_NUMBER 34 #define SRTM_AUDIO_SERVICE_CONFIG_PROC_NUMBER (4U) 35 #endif 36 37 typedef enum 38 { 39 SRTM_AudioDirRx = 0U, 40 SRTM_AudioDirTx = 1U, 41 } srtm_audio_dir_t; 42 43 typedef enum 44 { 45 SRTM_AudioStateClosed = 0U, 46 SRTM_AudioStateOpened = 1U, 47 SRTM_AudioStateStarted = 2U, 48 } srtm_audio_state_t; 49 50 /*!@brief Define the format info which aligned with Linux side in the SRTM Audio service. */ 51 typedef enum 52 { 53 SRTM_Audio_Stereo16Bits = 0U, 54 SRTM_Audio_Stereo24Bits = 1U, 55 SRTM_Audio_Stereo32Bits = 2U, 56 SRTM_Audio_DSD8bits = 48U, 57 SRTM_Audio_DSD16bits = 49U, 58 SRTM_Audio_DSD32bits = 50U, 59 } srtm_audio_format_type_t; 60 61 typedef struct _audio_format 62 { 63 srtm_audio_format_type_t format; 64 uint8_t bitwidth; 65 } srtm_audio_format_map_t; 66 67 /*!@brief Define the format numbers used in the SRTM Audio service. */ 68 #define FORMAT_NUM_USED (6) 69 70 extern srtm_audio_format_map_t saiFormatMap[FORMAT_NUM_USED]; 71 /** 72 * @brief SRTM SAI adapter structure pointer. 73 */ 74 typedef struct _srtm_sai_adapter *srtm_sai_adapter_t; 75 76 /** 77 * @brief SRTM Audio Codec adapter structure pointer. 78 */ 79 typedef struct _srtm_codec_adapter *srtm_codec_adapter_t; 80 81 /** 82 * @brief SRTM SAI adapter structure 83 */ 84 struct _srtm_sai_adapter 85 { 86 /* Bound service */ 87 srtm_service_t service; 88 89 /* Interfaces implemented by Audio service. */ 90 srtm_status_t (*periodDone)(srtm_service_t service, srtm_audio_dir_t dir, uint8_t index, uint32_t periodIdx); 91 92 /* Interfaces implemented by SAI adapter. */ 93 srtm_status_t (*open)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index); 94 srtm_status_t (*start)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index); 95 srtm_status_t (*pause)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index); 96 srtm_status_t (*restart)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index); 97 srtm_status_t (*stop)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index); 98 srtm_status_t (*close)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index); 99 srtm_status_t (*setParam)(srtm_sai_adapter_t adapter, 100 srtm_audio_dir_t dir, 101 uint8_t index, 102 uint8_t format, 103 uint8_t channels, 104 uint32_t srate); 105 srtm_status_t (*setBuf)(srtm_sai_adapter_t adapter, 106 srtm_audio_dir_t dir, 107 uint8_t index, 108 uint8_t *bufAddr, 109 uint32_t bufSize, 110 uint32_t periodSize, 111 uint32_t periodIdx); 112 srtm_status_t (*suspend)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index); 113 srtm_status_t (*resume)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index); 114 srtm_status_t (*getBufOffset)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index, uint32_t *pOffset); 115 srtm_status_t (*periodReady)(srtm_sai_adapter_t adapter, srtm_audio_dir_t dir, uint8_t index, uint32_t periodIdx); 116 }; 117 118 /** 119 * @brief SRTM Audio Codec adapter structure 120 */ 121 struct _srtm_codec_adapter 122 { 123 /* Interfaces implemented by Audio Codec adapter. */ 124 srtm_status_t (*setParam)(srtm_codec_adapter_t adapter, uint8_t index, uint8_t format, uint32_t srate); 125 srtm_status_t (*setReg)(srtm_codec_adapter_t adapter, uint32_t reg, uint32_t regVal); 126 srtm_status_t (*getReg)(srtm_codec_adapter_t adapter, uint32_t reg, uint32_t *pRegVal); 127 }; 128 129 /** 130 * @brief SRTM Audio payload structure 131 */ 132 SRTM_ANON_DEC_BEGIN 133 SRTM_PACKED_BEGIN struct _srtm_audio_payload 134 { 135 uint8_t index; 136 union 137 { 138 uint8_t format; 139 uint8_t retCode; 140 }; 141 uint8_t channels; 142 union 143 { 144 uint32_t bufOffset; 145 uint32_t srate; 146 }; 147 union 148 { 149 uint32_t bufAddr; 150 uint32_t reg; 151 }; 152 union 153 { 154 uint32_t bufSize; 155 uint32_t regVal; 156 }; 157 uint32_t periodSize; 158 uint32_t periodIdx; 159 } SRTM_PACKED_END; 160 SRTM_ANON_DEC_END 161 162 /******************************************************************************* 163 * API 164 ******************************************************************************/ 165 #ifdef __cplusplus 166 extern "C" { 167 #endif 168 169 /*! 170 * @brief Create audio service and register sai/codec adapters as index 0 audio interface. 171 * 172 * @param sai digital audio driver adapter. 173 * @param codec analog audio codec adapter. 174 * @return SRTM service handle on success and NULL on failure. 175 */ 176 srtm_service_t SRTM_AudioService_Create(srtm_sai_adapter_t sai, srtm_codec_adapter_t codec); 177 178 /*! 179 * @brief Destroy audio service. 180 * 181 * @param service SRTM service to destroy. 182 */ 183 void SRTM_AudioService_Destroy(srtm_service_t service); 184 185 /*! 186 * @brief Reset audio service. This is used to stop all audio operations and return to initial state 187 * for corresponding core. 188 * 189 * @param service SRTM service to reset. 190 * @param core Identify which core is to be reset 191 */ 192 void SRTM_AudioService_Reset(srtm_service_t service, srtm_peercore_t core); 193 194 /*! 195 * @brief Bind SRTM channel to audio adapter. The messages from the channel will be delivered to the adapter. 196 * @param service SRTM service to set audio interface. 197 * @param sai digital audio driver adapter. 198 * @param channel SRTM channel to be bound to the adapters. 199 * @return SRTM_Status_Success on success and others on failure. 200 */ 201 srtm_status_t SRTM_AudioService_BindChannel(srtm_service_t service, srtm_sai_adapter_t sai, srtm_channel_t channel); 202 203 /*! 204 * @brief Add audio adapters to audio service. 205 * @param service SRTM service to set audio interface. 206 * @param sai digital audio driver adapter. 207 * @return SRTM_Status_Success on success and others on failure. 208 */ 209 srtm_status_t SRTM_AudioService_AddAudioInterface(srtm_service_t service, srtm_sai_adapter_t sai); 210 211 #ifdef __cplusplus 212 } 213 #endif 214 215 /*! @} */ 216 217 #endif /* __SRTM_AUDIO_SERVICE_H__ */ 218