From 625d510fe9d8815fe244915e9386b9a14740f5ea Mon Sep 17 00:00:00 2001 From: vb6174 Date: Tue, 9 Nov 2021 18:41:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90Audio=E3=80=91code=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vb6174 --- include/audio/audio_accessory_if.h | 96 +++++-- include/audio/audio_codec_if.h | 129 +++++---- include/audio/audio_dai_if.h | 157 ++++++++-- include/audio/audio_dsp_if.h | 171 +++++++++-- include/audio/audio_platform_if.h | 270 ++++++++++++------ .../common/include/audio_platform_base.h | 31 +- model/audio/common/src/audio_accessory_base.c | 2 +- model/audio/common/src/audio_codec_base.c | 12 +- model/audio/common/src/audio_dai_base.c | 4 - model/audio/common/src/audio_dma_base.c | 2 - model/audio/common/src/audio_dsp_base.c | 1 - model/audio/common/src/audio_platform_base.c | 170 +++++------ model/audio/core/src/audio_parse.c | 16 +- .../dispatch/src/audio_stream_dispatch.c | 8 +- 14 files changed, 737 insertions(+), 332 deletions(-) diff --git a/include/audio/audio_accessory_if.h b/include/audio/audio_accessory_if.h index bd753a630..6f7ebaf38 100755 --- a/include/audio/audio_accessory_if.h +++ b/include/audio/audio_accessory_if.h @@ -18,37 +18,85 @@ extern "C" { #endif #endif /* __cplusplus */ +/** + * @brief Defines Accessory Codec device name and data. + * + * @since 1.0 + * @version 1.0 + */ struct AccessoryDevice { - const char *devAccessoryName; - struct AccessoryData *devData; - struct HdfDeviceObject *device; - struct DListHead list; - struct OsalMutex mutex; -}; - -struct AudioAccessoryOps { - const char *devAccessoryName; - struct AccessoryData *devData; - struct HdfDeviceObject *device; - struct DListHead list; + const char *devAccessoryName; /**< Accesssory device name */ + struct AccessoryData *devData; /**< Accesssory private data */ + struct HdfDeviceObject *device; /**< HDF device */ + struct DListHead list; /**< Accesssory list */ + struct OsalMutex mutex; /**< Accesssory mutex */ }; -/* Accessory host is defined in accessory driver */ +/** + * @brief Defines Accessory host in audio driver. + * + * @since 1.0 + * @version 1.0 + */ struct AccessoryHost { - struct IDeviceIoService service; // accessory service - struct HdfDeviceObject *device; // accessory deovce - void *priv; // accessory private data + struct IDeviceIoService service; /**< Services provided by Accesssory */ + struct HdfDeviceObject *device; /**< HDF device */ + void *priv; /**< Accesssory private data interface */ }; +/** + * @brief Defines Accesssory private data. + * + * @since 1.0 + * @version 1.0 + */ struct AccessoryData { - const char *drvAccessoryName; - /* Accessory driver callbacks */ - int32_t (*Init)(struct AudioCard *, const struct AccessoryDevice *device); - int32_t (*Read)(const struct AccessoryDevice *, uint32_t, uint32_t *); - int32_t (*Write)(const struct AccessoryDevice *, uint32_t, uint32_t); - const struct AudioKcontrol *controls; - int numControls; - struct AudioRegCfgData* regConfig; + const char *drvAccessoryName; /**< Accesssory driver name */ + + /** + * @brief Defines Accesssory device init. + * + * @param audioCard Indicates a audio card device. + * @param accesssory Indicates a Accesssory device. + * + * @return Returns 0 if Accesssory device init success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Init)(struct AudioCard *audioCard, const struct AccessoryDevice *accesssory); + + /** + * @brief Defines Accesssory device reg read. + * + * @param accesssory Indicates a accesssory device. + * @param reg Indicates read reg address. + * @param value Indicates read reg value. + * + * @return Returns 0 if accesssory device read reg success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Read)(const struct AccessoryDevice *accesssory, uint32_t reg, uint32_t *value); + + /** + * @brief Defines accesssory device reg write. + * + * @param accesssory Indicates a accesssory device. + * @param reg Indicates write reg address. + * @param value Indicates write reg value. + * + * @return Returns 0 if accesssory device write reg success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Write)(const struct AccessoryDevice *accesssory, uint32_t reg, uint32_t value); + + const struct AudioKcontrol *controls; /**< Accesssory control structure array pointer */ + int numControls; /**< Accesssory controls the number of structure array elements */ + struct AudioRegCfgData* regConfig; /**< Accesssory registers configured in HCS */ }; #ifdef __cplusplus diff --git a/include/audio/audio_codec_if.h b/include/audio/audio_codec_if.h index 3f6aee0ca..f8fc8be27 100755 --- a/include/audio/audio_codec_if.h +++ b/include/audio/audio_codec_if.h @@ -18,66 +18,91 @@ extern "C" { #endif #endif /* __cplusplus */ -#define AUDIODRV_CTL_ELEM_IFACE_DAC 0 /* virtual dac device */ -#define AUDIODRV_CTL_ELEM_IFACE_ADC 1 /* virtual adc device */ -#define AUDIODRV_CTL_ELEM_IFACE_GAIN 2 /* virtual adc device */ -#define AUDIODRV_CTL_ELEM_IFACE_MIXER 3 /* virtual mixer device */ -#define AUDIODRV_CTL_ELEM_IFACE_ACODEC 4 /* Acodec device */ -#define AUDIODRV_CTL_ELEM_IFACE_PGA 5 /* PGA device */ -#define AUDIODRV_CTL_ELEM_IFACE_AIAO 6 /* AIAO device */ - +/** + * @brief Defines Codec device name and data. + * + * @since 1.0 + * @version 1.0 + */ struct CodecDevice { - const char *devCodecName; - struct CodecData *devData; - struct HdfDeviceObject *device; - struct DListHead list; - struct OsalMutex mutex; + const char *devCodecName; /**< Codec device name */ + struct CodecData *devData; /**< Codec module private data */ + struct HdfDeviceObject *device; /**< HDF device */ + struct DListHead list; /**< Codec list */ + struct OsalMutex mutex; /**< Codec mutex */ }; -/* codec related definitions */ +/** + * @brief Defines Codec private data. + * + * @since 1.0 + * @version 1.0 + */ struct CodecData { - const char *drvCodecName; - /* Codec driver callbacks */ - int32_t (*Init)(struct AudioCard *, struct CodecDevice *); - int32_t (*Read)(unsigned long, uint32_t, uint32_t *); - int32_t (*Write)(unsigned long, uint32_t, uint32_t); - struct AudioKcontrol *controls; - int numControls; - struct AudioSapmComponent *sapmComponents; - int numSapmComponent; - const struct AudioSapmRoute *sapmRoutes; - int numSapmRoutes; - unsigned long virtualAddress; // IoRemap Address - struct AudioRegCfgData *regConfig; - struct AudioRegCfgGroupNode **regCfgGroup; -}; + const char *drvCodecName; /**< Codec driver name */ -/* Codec host is defined in codec driver */ -struct CodecHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - void *priv; -}; + /** + * @brief Defines Codec device init. + * + * @param audioCard Indicates a audio card device. + * @param codec Indicates a codec device. + * + * @return Returns 0 if codec device init success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Init)(struct AudioCard *audioCard, struct CodecDevice *codec); + + /** + * @brief Defines Codec device reg read. + * + * @param virtualAddress Indicates base reg IoRemap address. + * @param reg Indicates reg offset. + * @param value Indicates read reg value. + * + * @return Returns 0 if codec device read reg success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Read)(unsigned long virtualAddress, uint32_t reg, uint32_t *value); + + /** + * @brief Defines Codec device reg write. + * + * @param virtualAddress Indicates base reg IoRemap address. + * @param reg Indicates reg offset. + * @param value Indicates write reg value. + * + * @return Returns 0 if codec device write reg success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Write)(unsigned long virtualAddress, uint32_t reg, uint32_t value); -enum AudioRegParams { - PLAYBACK_VOLUME = 0, - CAPTURE_VOLUME, - PLAYBACK_MUTE, - CAPTURE_MUTE, - LEFT_GAIN, - RIGHT_GAIN, - EXTERNAL_CODEC_ENABLE, - INTERNALLY_CODEC_ENABLE, - RENDER_CHANNEL_MODE, - CAPTRUE_CHANNEL_MODE, - S_NORMAL_AP01_P_HIFI, + struct AudioKcontrol *controls; /**< Codec control structure array pointer */ + int numControls; /**< Number of array elements of Codec controls */ + struct AudioSapmComponent *sapmComponents; /**< Codec power management component array pointer */ + int numSapmComponent; /**< Number of array elements of codec power management component */ + const struct AudioSapmRoute *sapmRoutes; /**< Codec power management route array pointer */ + int numSapmRoutes; /**< Number of power management route array elements */ + unsigned long virtualAddress; /**< Codec base reg IoRemap address */ + struct AudioRegCfgData *regConfig; /**< Codec registers configured in HCS */ + struct AudioRegCfgGroupNode **regCfgGroup; /**< Codec register group configured in HCS */ }; -enum SapmRegParams { - LPGA_MIC = 0, - RPGA_MIC, - DACL2DACR, - DACR2DACL, +/** + * @brief Defines Codec host in audio driver. + * + * @since 1.0 + * @version 1.0 + */ +struct CodecHost { + struct IDeviceIoService service; /**< Services provided by codec */ + struct HdfDeviceObject *device; /**< HDF device */ + void *priv; /**< Codec private data interface */ }; #ifdef __cplusplus diff --git a/include/audio/audio_dai_if.h b/include/audio/audio_dai_if.h index a000c8a45..9863800be 100755 --- a/include/audio/audio_dai_if.h +++ b/include/audio/audio_dai_if.h @@ -9,53 +9,148 @@ #ifndef AUDIO_DAI_IF_H #define AUDIO_DAI_IF_H +#include "audio_host.h" +#include "audio_parse.h" +#include "audio_control.h" + #ifdef __cplusplus #if __cplusplus extern "C" { #endif #endif /* __cplusplus */ -#include "audio_host.h" -#include "audio_parse.h" -#include "audio_control.h" - +/** + * @brief Defines Dai device name and data. + * + * @since 1.0 + * @version 1.0 + */ struct DaiDevice { - const char *devDaiName; - struct DaiData *devData; - struct HdfDeviceObject *device; - struct DListHead list; + const char *devDaiName; /**< Dai device name */ + struct DaiData *devData; /**< Dai module private data */ + struct HdfDeviceObject *device; /**< HDF device */ + struct DListHead list; /**< Dai list */ }; +/** + * @brief Defines Dai operation function set. + * + * @since 1.0 + * @version 1.0 + */ struct AudioDaiOps { - int32_t (*Startup)(const struct AudioCard *, const struct DaiDevice *); - int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *); - int32_t (*Trigger)(const struct AudioCard *, int, const struct DaiDevice *); + /** + * @brief Defines Dai device start up function. + * + * @param audioCard Indicates a audio card device. + * @param dai Indicates a dai device. + * + * @return Returns 0 if dai device start up success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Startup)(const struct AudioCard *audioCard, const struct DaiDevice *dai); + + /** + * @brief Defines Dai device hardware param set function. + * + * @param audioCard Indicates a audio card device. + * @param param Indicates pcm param set. + * + * @return Returns 0 if dai pcm param set success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*HwParams)(const struct AudioCard *audioCard, const struct AudioPcmHwParams *param); + + /** + * @brief Defines Dai device trigger function. + * + * @param audioCard Indicates a audio card device. + * @param cmd Indicates a Command id. + * @param dai Indicates a dai device. + * + * @return Returns 0 if dai device trigger success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Trigger)(const struct AudioCard *audioCard, int cmd, const struct DaiDevice *dai); }; +/** + * @brief Defines dai private data. + * + * @since 1.0 + * @version 1.0 + */ struct DaiData { - const char *drvDaiName; - /* DAI driver callbacks */ - int32_t (*DaiInit)(struct AudioCard *, const struct DaiDevice *); - int32_t (*Read)(unsigned long, uint32_t, uint32_t *); - int32_t (*Write)(unsigned long, uint32_t, uint32_t); - /* ops */ - const struct AudioDaiOps *ops; - /* DAI DMA data */ - struct PcmInfo pcmInfo; - struct AudioKcontrol *controls; - int numControls; - bool daiInitFlag; - unsigned long regVirtualAddr; - struct AudioRegCfgData *regConfig; - struct AudioRegCfgGroupNode **regCfgGroup; - struct OsalMutex mutex; + const char *drvDaiName; /**< dai driver name */ + + /** + * @brief Defines Dai device init. + * + * @param audioCard Indicates a audio card device. + * @param dai Indicates a dai device. + * + * @return Returns 0 if dai device init success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DaiInit)(struct AudioCard *audioCard, const struct DaiDevice *dai); + + /** + * @brief Defines Dai device reg read. + * + * @param virtualAddress Indicates base reg IoRemap address. + * @param reg Indicates reg offset. + * @param value Indicates read reg value. + * + * @return Returns 0 if dai device read reg success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Read)(unsigned long virtualAddress, uint32_t reg, uint32_t * value); + + /** + * @brief Defines Dai device reg write. + * + * @param virtualAddress Indicates base reg IoRemap address. + * @param reg Indicates reg offset. + * @param value Indicates write reg value. + * + * @return Returns 0 if dai device write reg success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Write)(unsigned long virtualAddress, uint32_t reg, uint32_t value); + + const struct AudioDaiOps *ops; /**< dai set of operation functions */ + struct PcmInfo pcmInfo; /**< dai pcm info */ + struct AudioKcontrol *controls; /**< dai control structure array pointer */ + int numControls; /**< dai controls the number of structure array elements */ + bool daiInitFlag; /**< dai init flag */ + unsigned long regVirtualAddr; /**< dai base reg IoRemap address */ + struct AudioRegCfgData *regConfig; /**< dai registers configured in HCS */ + struct AudioRegCfgGroupNode **regCfgGroup; /**< dai register group configured in HCS */ + struct OsalMutex mutex; /**< dai mutex */ }; -/* Dai host is defined in dai driver */ +/** + * @brief Defines Dai host in audio driver. + * + * @since 1.0 + * @version 1.0 + */ struct DaiHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - void *priv; + struct IDeviceIoService service; /**< Services provided by dai */ + struct HdfDeviceObject *device; /**< HDF device */ + void *priv; /**< Dai private data interface */ }; #ifdef __cplusplus diff --git a/include/audio/audio_dsp_if.h b/include/audio/audio_dsp_if.h index 31d42a88e..acb695ef0 100755 --- a/include/audio/audio_dsp_if.h +++ b/include/audio/audio_dsp_if.h @@ -15,35 +15,168 @@ extern "C" { #endif #endif /* __cplusplus */ +/** + * @brief Defines Dsp device name and data. + * + * @since 1.0 + * @version 1.0 + */ struct DspDevice { - const char *devDspName; - struct DspData *devData; - struct HdfDeviceObject *device; - struct DListHead list; + const char *devDspName; /**< Dsp device name */ + struct DspData *devData; /**< Dsp module private data */ + struct HdfDeviceObject *device; /**< HDF device */ + struct DListHead list; /**< Dsp list */ }; +/** + * @brief Defines Dsp operation function set. + * + * @since 1.0 + * @version 1.0 + */ struct AudioDspOps { - int32_t (*Startup)(const struct AudioCard *, const struct DspDevice *); - int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *, const struct DspDevice *); - int32_t (*Trigger)(struct AudioCard *, int, struct DspDevice *); + /** + * @brief Defines Dsp device start up function. + * + * @param audioCard Indicates a audio card device. + * @param dsp Indicates a dsp device. + * + * @return Returns 0 if Dsp device start up success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Startup)(const struct AudioCard *audioCard, const struct DspDevice *dsp); + + /** + * @brief Defines Dsp device hardware param function. + * + * @param audioCard Indicates a audio card device. + * @param param Indicates pcm params set. + * + * @return Returns 0 if dsp param set success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*HwParams)(const struct AudioCard *audioCard, const struct AudioPcmHwParams *param); + + /** + * @brief Defines Dsp device trigger function. + * + * @param audioCard Indicates a audio card device. + * @param dsp Indicates a dsp device. + * + * @return Returns 0 if dsp device trigger success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Trigger)(struct AudioCard *audioCard, int, struct DspDevice *dsp); }; -/* Dsp host is defined in dsp driver */ +/** + * @brief Defines Dsp host in audio driver. + * + * @since 1.0 + * @version 1.0 + */ struct DspHost { - struct IDeviceIoService service; // dsp service - struct HdfDeviceObject *device; // dsp device - void *priv; // dsp private data + struct IDeviceIoService service; /**< Services provided by dsp */ + struct HdfDeviceObject *device; /**< HDF device */ + void *priv; /**< Dsp private data interface */ }; +/** + * @brief Defines dsp private data. + * + * @since 1.0 + * @version 1.0 + */ struct DspData { - const char *drvDspName; - /* dsp driver callbacks */ - int32_t (*DspInit)(const struct DspDevice *device); - int32_t (*Read)(const struct DspDevice *, uint8_t *, uint32_t); - int32_t (*Write)(const struct DspDevice *, uint8_t *, uint32_t); - int32_t (*decode)(const struct AudioCard *, const uint8_t *, const struct DspDevice *); - int32_t (*encode)(const struct AudioCard *, const uint8_t *, const struct DspDevice *); - int32_t (*Equalizer)(const struct AudioCard *, const uint8_t *, const struct DspDevice *); + const char *drvDspName; /**< Dsp driver name */ + + /** + * @brief Defines Dsp device init. + * + * @param dsp Indicates a Dsp device. + * + * @return Returns 0 if dsp device init success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DspInit)(const struct DspDevice *dsp); + + /** + * @brief Defines Dsp device msgs read. + * + * @param dsp Indicates a dsp device. + * @param msgs Indicates transfer msgs data. + * @param len Indicates msgs length. + * + * @return Returns 0 if dsp device read msgs success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Read)(const struct DspDevice *dsp, void *msgs, uint32_t len); + + /** + * @brief Defines Dsp device msgs write. + * + * @param dsp Indicates a dsp device. + * @param msgs Indicates transfer msgs data. + * @param len Indicates msgs length. + * + * @return Returns 0 if dsp device write msgs success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Write)(const struct DspDevice *dsp, void *msgs, uint32_t len); + + /** + * @brief Defines Dsp device decode. + * + * @param audioCard Indicates a audio card. + * @param buf Indicates decode pcm buffer data. + * @param dsp Indicates a dsp device. + * + * @return Returns 0 if Dsp device decode success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Decode)(const struct AudioCard *audioCard, const uint8_t *buf, const struct DspDevice *dsp); + + /** + * @brief Defines Dsp device encode. + * + * @param audioCard audioCard Indicates a audio card. + * @param buf Indicates encode pcm buffer data. + * @param dsp Indicates a dsp device. + * + * @return Returns 0 if Dsp device encode success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Encode)(const struct AudioCard *audioCard, const uint8_t *buf, const struct DspDevice *dsp); + + /** + * @brief Defines Dsp device equalizer. + * + * @param audioCard audioCard Indicates a audio card. + * @param buf Indicates equalizer pcm buffer data. + * @param dsp Indicates a dsp device. + * + * @return Returns 0 if Dsp device equalizer success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*Equalizer)(const struct AudioCard *audioCard, const uint8_t *buf, const struct DspDevice *dsp); }; #ifdef __cplusplus diff --git a/include/audio/audio_platform_if.h b/include/audio/audio_platform_if.h index 586a57cd9..c880672cb 100755 --- a/include/audio/audio_platform_if.h +++ b/include/audio/audio_platform_if.h @@ -10,6 +10,7 @@ #define AUDIO_PLATFORM_IF_H #include "audio_host.h" +#include "audio_platform_base.h" #ifdef __cplusplus #if __cplusplus @@ -17,111 +18,194 @@ extern "C" { #endif #endif /* __cplusplus */ -#define I2S_IOCFG2_BASE1 0x0020 -#define I2S_IOCFG2_BASE2 0x0024 -#define I2S_IOCFG2_BASE3 0x0028 -#define I2S_IOCFG2_BASE4 0x002C -#define I2S_IOCFG2_BASE5 0x0030 - -#define I2S_IOCFG2_BASE1_VAL 0x663 -#define I2S_IOCFG2_BASE2_VAL 0x673 -#define I2S_IOCFG2_BASE3_VAL 0x573 -#define I2S_IOCFG2_BASE4_VAL 0x473 -#define I2S_IOCFG2_BASE5_VAL 0x433 - -#define I2S_IOCFG3_BASE1 0x44 -#define I2S_IOCFG3_BASE1_VAL 0x0600 - -#define GPIO_BASE1 0x2010 -#define GPIO_BASE2 0x2400 -#define GPIO_BASE3 0x2010 - -#define GPIO_BASE2_VAL 0x000000ff -#define GPIO_BASE3_VAL 0x00000000 - -#define IOCFG2_BASE_ADDR 0x112F0000 -#define IOCFG3_BASE_ADDR 0x10FF0000 -#define GPIO_BASE_ADDR 0x120D0000 -#define BASE_ADDR_REMAP_SIZE 0x10000 - -enum PcmStatus { - PCM_STOP = 0, - PCM_PAUSE, - PCM_START, -}; - -struct CircleBufInfo { - uint32_t cirBufSize; - uint32_t trafBufSize; - uint32_t period; - uint32_t periodSize; - uint32_t periodCount; - unsigned long phyAddr; - uint32_t *virtAddr; - uint32_t wbufOffSet; - uint32_t wptrOffSet; - uint32_t rbufOffSet; - uint32_t rptrOffSet; - enum PcmStatus runStatus; - uint32_t chnId; - uint32_t enable; - struct OsalMutex buffMutex; - uint32_t framesPosition; - uint32_t pointer; - uint32_t periodsMax; - uint32_t periodsMin; - uint32_t cirBufMax; - uint32_t curTrafSize; -}; - +/** + * @brief Defines paltform private data. + * + * @since 1.0 + * @version 1.0 + */ struct PlatformData { - const char *drvPlatformName; - /* platform driver callbacks */ - int32_t (*PlatformInit)(const struct AudioCard *, const struct PlatformDevice *); - /* platform stream ops */ - struct AudioDmaOps *ops; - struct CircleBufInfo renderBufInfo; - struct CircleBufInfo captureBufInfo; - struct PcmInfo pcmInfo; - bool platformInitFlag; - struct AudioMmapData mmapData; - uint32_t mmapLoopCount; - void *dmaPrv; + const char *drvPlatformName; /**< Platform module name */ + + /** + * @brief Defines platform device init. + * + * @param audioCard Indicates a audio card device. + * @param platform Indicates a platform device. + * + * @return Returns 0 if Platform device init success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*PlatformInit)(const struct AudioCard *audioCard, const struct PlatformDevice *platform); + + struct AudioDmaOps *ops; /**< Platform module private data */ + struct CircleBufInfo renderBufInfo; /**< Render pcm stream transfer */ + struct CircleBufInfo captureBufInfo; /**< Capture pcm stream transfer */ + struct PcmInfo pcmInfo; /**< Pcm stream info */ + bool platformInitFlag; /**< Platform init flag */ + struct AudioMmapData mmapData; /**< Mmap mode transfer data */ + uint32_t mmapLoopCount; /**< Loop count for mmap mode pcm stream */ + void *dmaPrv; /**< Platform dma private data */ }; -/* dma related definitions */ +/** + * @brief Defines Dma operation function set. + * + * @since 1.0 + * @version 1.0 + */ struct AudioDmaOps { - int32_t (*DmaBufAlloc)(struct PlatformData *, enum AudioStreamType); - int32_t (*DmaBufFree)(struct PlatformData *, enum AudioStreamType); - int32_t (*DmaRequestChannel)(struct PlatformData *); - int32_t (*DmaConfigChannel)(struct PlatformData *); - int32_t (*DmaPrep)(struct PlatformData *); - int32_t (*DmaSubmit)(struct PlatformData *); - int32_t (*DmaPending)(struct PlatformData *); - int32_t (*DmaPause)(struct PlatformData *); - int32_t (*DmaResume)(struct PlatformData *); - int32_t (*DmaPointer)(struct PlatformData *, uint32_t *); + /** + * @brief Defines Dma buff alloc. + * + * @param platformData Indicates dma device. + * @param streamType Indicates capture or render. + * + * @return Returns 0 if dma buffer alloc success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaBufAlloc)(struct PlatformData *platformData, enum AudioStreamType streamType); + + /** + * @brief Defines dma buffer free. + * + * @param platformData Indicates dma device. + * @param streamType Indicates capture or render. + * + * @return Returns 0 if dma buffer free success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaBufFree)(struct PlatformData *platformData, enum AudioStreamType streamType); + + /** + * @brief Defines dma request channel. + * + * @param platformData Indicates dma device. + * + * @return Returns 0 if dma request channel success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaRequestChannel)(struct PlatformData *platformData); + + /** + * @brief Defines dma channel config. + * + * @param platformData Indicates dma device. + * + * @return Returns 0 if dma channel config set success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaConfigChannel)(struct PlatformData *platformData); + + /** + * @brief Defines dma prepare function. + * + * @param platformData Indicates dma device. + * + * @return Returns 0 if dma device prep set success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaPrep)(struct PlatformData *platformData); + + /** + * @brief Defines dma submit function. + * + * @param platformData Indicates dma device. + * + * @return Returns 0 if dma device submit succes; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaSubmit)(struct PlatformData *platformData); + + /** + * @brief Defines dma pending function. + * + * @param platformData Indicates dma device. + * + * @return Returns 0 if dma pending success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaPending)(struct PlatformData *platformData); + + /** + * @brief Defines pcm stream transfer pause. + * + * @param platformData Indicates dma device. + * + * @return Returns 0 if pcm stream transfer pause success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaPause)(struct PlatformData *platformData); + + /** + * @brief Defines pcm stream transfer resume. + * + * @param platformData Indicates dma device. + * + * @return Returns 0 if pcm stream transfer resume success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaResume)(struct PlatformData *platformData); + + /** + * @brief Defines Get the function of the current playback or recording position. + * + * @param platformData Indicates dma device. + * @param pointer Indicates dma pointer. + * + * @return Returns 0 if dma device pointer position get success; returns a non-zero value otherwise. + * + * @since 1.0 + * @version 1.0 + */ + int32_t (*DmaPointer)(struct PlatformData *platformData, uint32_t *pointer); }; +/** + * @brief Defines Dai device name and data. + * + * @since 1.0 + * @version 1.0 + */ struct PlatformDevice { - const char *devPlatformName; - struct PlatformData *devData; - struct HdfDeviceObject *device; - struct DListHead list; + const char *devPlatformName; /**< Platform device name */ + struct PlatformData *devData; /**< Platform module private data */ + struct HdfDeviceObject *device; /**< HDF device */ + struct DListHead list; /**< Platform list */ }; -/* Platform host is defined in platform driver */ +/** + * @brief Defines Platform host in audio driver. + * + * @since 1.0 + * @version 1.0 + */ struct PlatformHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - void *priv; + struct IDeviceIoService service; /**< Services provided by patform */ + struct HdfDeviceObject *device; /**< HDF device */ + void *priv; /**< Platform private data interface */ }; -static inline struct PlatformHost *PlatformHostFromDevice(struct HdfDeviceObject *device) -{ - return (device == NULL) ? NULL : (struct PlatformHost *)device->service; -} - #ifdef __cplusplus #if __cplusplus } diff --git a/model/audio/common/include/audio_platform_base.h b/model/audio/common/include/audio_platform_base.h index 0a6215ccd..b895710b8 100755 --- a/model/audio/common/include/audio_platform_base.h +++ b/model/audio/common/include/audio_platform_base.h @@ -9,7 +9,6 @@ #ifndef AUDIO_PLATFORM_BASE_H #define AUDIO_PLATFORM_BASE_H -#include "audio_platform_if.h" #include "audio_host.h" #ifdef __cplusplus @@ -31,6 +30,36 @@ enum DataBitWidth { DATA_BIT_WIDTH32 = 32, /* 32 bit witdth */ }; +enum PcmStatus { + PCM_STOP = 0, /* pcm stream stop flag */ + PCM_PAUSE, /* pcm stream pause flag */ + PCM_START, /* pcm stream start flag */ +}; + +struct CircleBufInfo { + uint32_t cirBufSize; /* Current DMA cache size */ + uint32_t trafBufSize; /* PCM data per transmission default size */ + uint32_t period; /* not used */ + uint32_t periodSize; /* DMA cache period size */ + uint32_t periodCount; /* Number of DMA cache periods */ + unsigned long phyAddr; /* DMA cache physical address */ + uint32_t *virtAddr; /* DMA cache virtual address */ + uint32_t wbufOffSet; /* DMA cache write address offset */ + uint32_t wptrOffSet; /* DMA cache write pointer offset */ + uint32_t rbufOffSet; /* DMA cache read address offset */ + uint32_t rptrOffSet; /* DMA cache read pointer offset */ + enum PcmStatus runStatus; /* PCM status */ + uint32_t chnId; /* Channel ID */ + uint32_t enable; /* Enable identification */ + struct OsalMutex buffMutex; /* mutex */ + uint32_t framesPosition; /* Frame position */ + uint32_t pointer; /* Read/write pointer position during playback and recording */ + uint32_t periodsMax; /* Maximum number of periods */ + uint32_t periodsMin; /* Minimum number of periods */ + uint32_t cirBufMax; /* Size of DMA cache requested */ + uint32_t curTrafSize; /* The size of each actual transmission of PCM data */ +}; + unsigned int SysReadl(unsigned long addr); void SysWritel(unsigned long addr, unsigned int value); diff --git a/model/audio/common/src/audio_accessory_base.c b/model/audio/common/src/audio_accessory_base.c index c52c65754..747c9d942 100755 --- a/model/audio/common/src/audio_accessory_base.c +++ b/model/audio/common/src/audio_accessory_base.c @@ -166,7 +166,7 @@ int32_t AccessoryRegBitsRead(struct AudioMixerControl *regAttr, uint32_t *regVal regAttr->value = regAttr->max - regAttr->value; } AUDIO_DRIVER_LOG_DEBUG("regAddr=0x%x, regValue=0x%x, currBitsValue=0x%x", - regAttr->reg, regVal.value,regAttr->value); + regAttr->reg, regVal.value, regAttr->value); AUDIO_DRIVER_LOG_DEBUG("mask=0x%x, shift=%d, max=0x%x,min=0x%x, invert=%d", regAttr->mask, regAttr->shift, regAttr->max, regAttr->min, regAttr->invert); AUDIO_DRIVER_LOG_DEBUG("success."); diff --git a/model/audio/common/src/audio_codec_base.c b/model/audio/common/src/audio_codec_base.c index 88f13a742..0666e7443 100755 --- a/model/audio/common/src/audio_codec_base.c +++ b/model/audio/common/src/audio_codec_base.c @@ -121,7 +121,7 @@ static int32_t SapmCtrlToSapmComp(struct AudioSapmComponent *sapmComponents, return HDF_SUCCESS; } -static int32_t CodecSetSapmConfigInfo(struct CodecData *codeData,struct AudioRegCfgGroupNode ** regCfgGroup) +static int32_t CodecSetSapmConfigInfo(struct CodecData *codeData, struct AudioRegCfgGroupNode **regCfgGroup) { uint16_t index; @@ -139,8 +139,8 @@ static int32_t CodecSetSapmConfigInfo(struct CodecData *codeData,struct AudioReg return HDF_FAILURE; } - struct AudioKcontrol *audioSapmControls = (struct AudioKcontrol *)OsalMemCalloc - (regCfgGroup[AUDIO_SAPM_CFG_GROUP]->itemNum * sizeof(struct AudioKcontrol)); + struct AudioKcontrol *audioSapmControls = (struct AudioKcontrol *)OsalMemCalloc( + regCfgGroup[AUDIO_SAPM_CFG_GROUP]->itemNum * sizeof(struct AudioKcontrol)); if (audioSapmControls == NULL) { AUDIO_DRIVER_LOG_ERR("OsalMemCalloc failed."); return HDF_FAILURE; @@ -164,10 +164,10 @@ static int32_t CodecSetSapmConfigInfo(struct CodecData *codeData,struct AudioReg } for (index = 0; index < codeData->numSapmComponent; index++) { - if (SapmCtrlToSapmComp(codeData->sapmComponents ,sapmCompItem, index)) { + if (SapmCtrlToSapmComp(codeData->sapmComponents, sapmCompItem, index)) { OsalMemFree(audioSapmControls); return HDF_FAILURE; - } + } if (sapmCompItem[index].kcontrolsNum) { codeData->sapmComponents[index].kcontrolNews = @@ -233,7 +233,7 @@ int32_t CodecSetConfigInfo(struct CodecData *codeData, struct DaiData *daiData) int32_t CodecSetCtlFunc(struct CodecData *codeData, void *aiaoGetCtrl, void *aiaoSetCtrl) { - uint32_t index = 0; + uint32_t index; if (codeData == NULL || codeData->regConfig == NULL || aiaoGetCtrl == NULL || aiaoSetCtrl == NULL) { AUDIO_DRIVER_LOG_ERR("input para is NULL."); diff --git a/model/audio/common/src/audio_dai_base.c b/model/audio/common/src/audio_dai_base.c index bdface250..240ba1121 100644 --- a/model/audio/common/src/audio_dai_base.c +++ b/model/audio/common/src/audio_dai_base.c @@ -6,12 +6,8 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include "audio_host.h" #include "audio_core.h" -#include "audio_parse.h" #include "audio_driver_log.h" -#include "audio_dai_if.h" -#include "osal_io.h" struct DaiData *DaiDataFromCard(const struct AudioCard *card) { diff --git a/model/audio/common/src/audio_dma_base.c b/model/audio/common/src/audio_dma_base.c index a1e77af48..214edc684 100644 --- a/model/audio/common/src/audio_dma_base.c +++ b/model/audio/common/src/audio_dma_base.c @@ -86,5 +86,3 @@ int32_t AudioDmaPointer(struct PlatformData *data, uint32_t *pointer) } return HDF_FAILURE; } - - diff --git a/model/audio/common/src/audio_dsp_base.c b/model/audio/common/src/audio_dsp_base.c index fde2f9b06..3fb0c38ca 100644 --- a/model/audio/common/src/audio_dsp_base.c +++ b/model/audio/common/src/audio_dsp_base.c @@ -7,7 +7,6 @@ */ #include "audio_dsp_base.h" -#include "osal_io.h" #include "audio_driver_log.h" #define HDF_LOG_TAG audio_dsp_base diff --git a/model/audio/common/src/audio_platform_base.c b/model/audio/common/src/audio_platform_base.c index 2289917e8..611f57480 100755 --- a/model/audio/common/src/audio_platform_base.c +++ b/model/audio/common/src/audio_platform_base.c @@ -361,7 +361,7 @@ static int32_t PcmReadData(struct PlatformData *data, struct AudioRxData *rxData if (!data->pcmInfo.isBigEndian) { if (rxData->buf == NULL || AudioDataBigEndianChange(rxData->buf, data->captureBufInfo.curTrafSize, - data->pcmInfo.bitWidth) != HDF_SUCCESS) { + data->pcmInfo.bitWidth) != HDF_SUCCESS) { AUDIO_DRIVER_LOG_ERR("AudioDataBigEndianChange: failed."); return HDF_FAILURE; } @@ -470,7 +470,8 @@ static int32_t AudioMmapWriteTransfer(const struct AudioCard *card) uint32_t totalSize = data->mmapData.totalBufferFrames * data->pcmInfo.frameSize; uint32_t lastBuffSize = ((totalSize % MIN_PERIOD_SIZE) == 0) ? MIN_PERIOD_SIZE : (totalSize % MIN_PERIOD_SIZE); - uint32_t loopTimes = (lastBuffSize == MIN_PERIOD_SIZE) ? (totalSize / MIN_PERIOD_SIZE) : (totalSize / MIN_PERIOD_SIZE + 1); + uint32_t loopTimes = (lastBuffSize == MIN_PERIOD_SIZE) ? + (totalSize / MIN_PERIOD_SIZE) : (totalSize / MIN_PERIOD_SIZE + 1); data->mmapLoopCount = 0; char *tmpBuf = OsalMemCalloc(MIN_PERIOD_SIZE); @@ -573,13 +574,13 @@ static int32_t MmapReadData(struct PlatformData *data, const struct AudioMmapDat return HDF_FAILURE; } } - + if (CopyToUser((char *)rxMmapData->memoryAddress + offset, - (char *)(data->captureBufInfo.virtAddr) + rPtr, data->captureBufInfo.curTrafSize) != 0) { - AUDIO_DRIVER_LOG_ERR("CopyToUser failed."); - return HDF_FAILURE; + (char *)(data->captureBufInfo.virtAddr) + rPtr, data->captureBufInfo.curTrafSize) != 0) { + AUDIO_DRIVER_LOG_ERR("CopyToUser failed."); + return HDF_FAILURE; } - + // 4. update rptr data->captureBufInfo.rptrOffSet += data->captureBufInfo.curTrafSize; if (data->captureBufInfo.rptrOffSet >= data->captureBufInfo.cirBufSize) { @@ -642,7 +643,6 @@ int32_t AudioMmapReadTransfer(const struct AudioCard *card, const struct AudioMm AUDIO_DRIVER_LOG_ERR("MmapReadData fail."); return HDF_FAILURE; } - offset += data->captureBufInfo.curTrafSize; } while (offset < totalSize && data->captureBufInfo.runStatus != 0); @@ -847,71 +847,109 @@ int32_t AudioCaptureClose(const struct AudioCard *card) return AudioCaptureBuffFree(platformData); } -int32_t AudioRenderTrigger(struct AudioCard *card, int cmd) +static int32_t AudioPcmPending(struct AudioCard *card) { - if (card == NULL) { - AUDIO_DRIVER_LOG_ERR("param is invalid."); - return HDF_ERR_INVALID_PARAM; + struct PlatformData *data = PlatformDataFromCard(card); + if (data == NULL) { + AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed."); + return HDF_FAILURE; } + if (AudioDmaSubmit(data) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("DmaPending fail."); + return HDF_FAILURE; + } + + if (AudioDmaPending(data) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("DmaPending fail."); + return HDF_FAILURE; + } + + if (AudioSampSetPowerMonitor(card, false) != HDF_SUCCESS) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t AudioPcmPause(struct AudioCard *card) +{ struct PlatformData *data = PlatformDataFromCard(card); if (data == NULL) { AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed."); return HDF_FAILURE; } - switch (cmd) { - case AUDIO_DRV_PCM_IOCTL_RENDER_START: - if (AudioDmaSubmit(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPending fail."); - return HDF_FAILURE; - } + if (AudioDmaPause(data) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("DmaPause fail."); + return HDF_FAILURE; + } - if (AudioDmaPending(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPending fail."); - return HDF_FAILURE; - } + if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t AudioPcmResume(struct AudioCard *card) +{ + struct PlatformData *data = PlatformDataFromCard(card); + if (data == NULL) { + AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed."); + return HDF_FAILURE; + } + + if (AudioDmaResume(data) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("DmaPause fail."); + return HDF_FAILURE; + } + + if (AudioSampPowerUp(card) != HDF_SUCCESS) { + return HDF_FAILURE; + } + if (AudioSampSetPowerMonitor(card, false) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} - if (AudioSampSetPowerMonitor(card, false) != HDF_SUCCESS) { +int32_t AudioRenderTrigger(struct AudioCard *card, int cmd) +{ + struct PlatformData *data = PlatformDataFromCard(card); + if (data == NULL) { + AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed."); + return HDF_FAILURE; + } + + switch (cmd) { + case AUDIO_DRV_PCM_IOCTL_RENDER_START: + if (AudioPcmPending(card) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("AudioPcmPending fail."); return HDF_FAILURE; } data->renderBufInfo.runStatus = PCM_START; break; case AUDIO_DRV_PCM_IOCTL_RENDER_STOP: - if (AudioDmaPause(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPause fail."); - return HDF_FAILURE; - } - - if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) { + if (AudioPcmPause(card) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("AudioPcmPause fail."); return HDF_FAILURE; } data->renderBufInfo.runStatus = PCM_STOP; break; case AUDIO_DRV_PCM_IOCTL_RENDER_PAUSE: - if (AudioDmaPause(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPause fail."); - return HDF_FAILURE; - } - - if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) { + if (AudioPcmPause(card) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("AudioPcmPause fail."); return HDF_FAILURE; } data->renderBufInfo.runStatus = PCM_PAUSE; break; case AUDIO_DRV_PCM_IOCTL_RENDER_RESUME: - if (AudioDmaResume(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPause fail."); - return HDF_FAILURE; - } - - if (AudioSampPowerUp(card) != HDF_SUCCESS) { - return HDF_FAILURE; - } - if (AudioSampSetPowerMonitor(card, false) != HDF_SUCCESS) { + if (AudioPcmResume(card) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("AudioPcmResume fail."); return HDF_FAILURE; } @@ -926,11 +964,6 @@ int32_t AudioRenderTrigger(struct AudioCard *card, int cmd) int32_t AudioCaptureTrigger(struct AudioCard *card, int cmd) { - if (card == NULL) { - AUDIO_DRIVER_LOG_ERR("param is invalid."); - return HDF_ERR_INVALID_PARAM; - } - struct PlatformData *data = PlatformDataFromCard(card); if (data == NULL) { AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed."); @@ -939,56 +972,35 @@ int32_t AudioCaptureTrigger(struct AudioCard *card, int cmd) switch (cmd) { case AUDIO_DRV_PCM_IOCTL_CAPTURE_START: - if (AudioDmaSubmit(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPending fail."); - return HDF_FAILURE; - } - if (AudioDmaPending(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPending fail."); - return HDF_FAILURE; - } - - if (AudioSampSetPowerMonitor(card, false) != HDF_SUCCESS) { + if (AudioPcmPending(card) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("AudioPcmPending fail."); return HDF_FAILURE; } data->captureBufInfo.runStatus = PCM_START; break; case AUDIO_DRV_PCM_IOCTL_CAPTURE_STOP: - if (AudioDmaPause(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPause fail."); + if (AudioPcmPause(card) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("AudioPcmPause fail."); return HDF_FAILURE; } - if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) { - return HDF_FAILURE; - } data->captureBufInfo.runStatus = PCM_STOP; break; case AUDIO_DRV_PCM_IOCTL_CAPTURE_PAUSE: - if (AudioDmaPause(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPause fail."); - return HDF_FAILURE; - } - - if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) { + if (AudioPcmPause(card) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("AudioPcmPause fail."); return HDF_FAILURE; } data->captureBufInfo.runStatus = PCM_PAUSE; break; case AUDIO_DRV_PCM_IOCTL_CAPTURE_RESUME: - if (AudioDmaResume(data) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("DmaPause fail."); + if (AudioPcmResume(card) != HDF_SUCCESS) { + AUDIO_DRIVER_LOG_ERR("AudioPcmResume fail."); return HDF_FAILURE; } - if (AudioSampPowerUp(card) != HDF_SUCCESS) { - return HDF_FAILURE; - } - if (AudioSampSetPowerMonitor(card, false) != HDF_SUCCESS) { - return HDF_FAILURE; - } data->captureBufInfo.runStatus = PCM_START; break; default: @@ -1136,5 +1148,3 @@ int32_t AudioPcmPointer(const struct AudioCard *card, uint32_t *pointer) return HDF_SUCCESS; } - - diff --git a/model/audio/core/src/audio_parse.c b/model/audio/core/src/audio_parse.c index 732990d70..6670cf42a 100755 --- a/model/audio/core/src/audio_parse.c +++ b/model/audio/core/src/audio_parse.c @@ -324,7 +324,7 @@ static int32_t ParseAudioAddrItem(struct DeviceResourceIface *parser, const stru } static int32_t ParseAudioRegGroup(struct DeviceResourceIface *parser, - const struct DeviceResourceNode *regCfgNode, struct AudioRegCfgGroupNode** groupNode, uint32_t index) + const struct DeviceResourceNode *regCfgNode, struct AudioRegCfgGroupNode **groupNode, uint32_t index) { int32_t ret = HDF_FAILURE; struct AudioRegCfgGroupNode *group = NULL; @@ -335,18 +335,6 @@ static int32_t ParseAudioRegGroup(struct DeviceResourceIface *parser, return HDF_FAILURE; } - group = *groupNode; - if (group != NULL) { - if (group->regCfgItem != NULL) { - OsalMemFree(group->regCfgItem); - } - - if (group->ctrlCfgItem != NULL) { - OsalMemFree(group->ctrlCfgItem); - } - OsalMemFree(group); - } - group = (struct AudioRegCfgGroupNode*)OsalMemCalloc(sizeof(*group)); if (group == NULL) { ADM_LOG_ERR("malloc audio reg config group failed"); @@ -355,7 +343,7 @@ static int32_t ParseAudioRegGroup(struct DeviceResourceIface *parser, *groupNode = group; (*groupNode)->groupIndex = index; - switch(index){ + switch (index) { case AUDIO_CTRL_CFG_GROUP: case AUDIO_SAPM_CFG_GROUP: ret = ParseAudioCtrlItem(parser, regCfgNode, group); diff --git a/model/audio/dispatch/src/audio_stream_dispatch.c b/model/audio/dispatch/src/audio_stream_dispatch.c index 504d0084e..bb4f135ae 100755 --- a/model/audio/dispatch/src/audio_stream_dispatch.c +++ b/model/audio/dispatch/src/audio_stream_dispatch.c @@ -1326,12 +1326,12 @@ static int32_t StreamHostDspDecode(const struct HdfDeviceIoClient *client, struc rtd = audioCard->rtd; dspDev = rtd->dsp; - if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->decode == NULL) { + if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->Decode == NULL) { ADM_LOG_ERR("audioCard rtd dsp is NULL."); return HDF_FAILURE; } - ret = dspDev->devData->decode(audioCard, (void*)data, dspDev); + ret = dspDev->devData->Decode(audioCard, (void*)data, dspDev); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("DeCode render pause failed ret=%d", ret); return HDF_ERR_IO; @@ -1365,12 +1365,12 @@ static int32_t StreamHostDspEncode(const struct HdfDeviceIoClient *client, struc rtd = audioCard->rtd; dspDev = rtd->dsp; - if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->encode == NULL) { + if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->Encode == NULL) { ADM_LOG_ERR("audioCard rtd dsp is NULL."); return HDF_FAILURE; } - ret = dspDev->devData->encode(audioCard, (void*)data, dspDev); + ret = dspDev->devData->Encode(audioCard, (void*)data, dspDev); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("EnCode render pause failed ret=%d", ret); return HDF_ERR_IO; -- Gitee From a786ef88b69c9108d9b234890531849413c1fe3b Mon Sep 17 00:00:00 2001 From: vb6174 Date: Wed, 10 Nov 2021 15:30:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90Audio=E3=80=91code=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vb6174 --- include/audio/audio_codec_if.h | 2 +- include/audio/audio_dsp_if.h | 4 +- include/audio/audio_platform_if.h | 14 +++---- model/audio/common/include/audio_codec_base.h | 2 +- model/audio/common/src/audio_accessory_base.c | 11 +++-- model/audio/common/src/audio_codec_base.c | 17 +++++--- model/audio/common/src/audio_dai_base.c | 4 ++ model/audio/common/src/audio_platform_base.c | 19 ++++----- model/audio/core/include/audio_core.h | 3 +- model/audio/core/include/audio_parse.h | 9 ++-- model/audio/core/src/audio_core.c | 2 +- model/audio/core/src/audio_parse.c | 23 +++++----- .../dispatch/src/audio_stream_dispatch.c | 42 ++++++++++++++----- model/audio/sapm/src/audio_sapm.c | 21 ++++++---- 14 files changed, 106 insertions(+), 67 deletions(-) diff --git a/include/audio/audio_codec_if.h b/include/audio/audio_codec_if.h index f8fc8be27..5ebe453bd 100755 --- a/include/audio/audio_codec_if.h +++ b/include/audio/audio_codec_if.h @@ -52,7 +52,7 @@ struct CodecData { * @since 1.0 * @version 1.0 */ - int32_t (*Init)(struct AudioCard *audioCard, struct CodecDevice *codec); + int32_t (*Init)(struct AudioCard *audioCard, const struct CodecDevice *codec); /** * @brief Defines Codec device reg read. diff --git a/include/audio/audio_dsp_if.h b/include/audio/audio_dsp_if.h index acb695ef0..8e39def5d 100755 --- a/include/audio/audio_dsp_if.h +++ b/include/audio/audio_dsp_if.h @@ -120,7 +120,7 @@ struct DspData { * @since 1.0 * @version 1.0 */ - int32_t (*Read)(const struct DspDevice *dsp, void *msgs, uint32_t len); + int32_t (*Read)(const struct DspDevice *dsp, const void *msgs, const uint32_t len); /** * @brief Defines Dsp device msgs write. @@ -134,7 +134,7 @@ struct DspData { * @since 1.0 * @version 1.0 */ - int32_t (*Write)(const struct DspDevice *dsp, void *msgs, uint32_t len); + int32_t (*Write)(const struct DspDevice *dsp, const void *msgs, const uint32_t len); /** * @brief Defines Dsp device decode. diff --git a/include/audio/audio_platform_if.h b/include/audio/audio_platform_if.h index c880672cb..bb6e09896 100755 --- a/include/audio/audio_platform_if.h +++ b/include/audio/audio_platform_if.h @@ -68,7 +68,7 @@ struct AudioDmaOps { * @since 1.0 * @version 1.0 */ - int32_t (*DmaBufAlloc)(struct PlatformData *platformData, enum AudioStreamType streamType); + int32_t (*DmaBufAlloc)(struct PlatformData *platformData, const enum AudioStreamType streamType); /** * @brief Defines dma buffer free. @@ -81,7 +81,7 @@ struct AudioDmaOps { * @since 1.0 * @version 1.0 */ - int32_t (*DmaBufFree)(struct PlatformData *platformData, enum AudioStreamType streamType); + int32_t (*DmaBufFree)(struct PlatformData *platformData, const enum AudioStreamType streamType); /** * @brief Defines dma request channel. @@ -93,7 +93,7 @@ struct AudioDmaOps { * @since 1.0 * @version 1.0 */ - int32_t (*DmaRequestChannel)(struct PlatformData *platformData); + int32_t (*DmaRequestChannel)(const struct PlatformData *platformData); /** * @brief Defines dma channel config. @@ -105,7 +105,7 @@ struct AudioDmaOps { * @since 1.0 * @version 1.0 */ - int32_t (*DmaConfigChannel)(struct PlatformData *platformData); + int32_t (*DmaConfigChannel)(const struct PlatformData *platformData); /** * @brief Defines dma prepare function. @@ -117,7 +117,7 @@ struct AudioDmaOps { * @since 1.0 * @version 1.0 */ - int32_t (*DmaPrep)(struct PlatformData *platformData); + int32_t (*DmaPrep)(const struct PlatformData *platformData); /** * @brief Defines dma submit function. @@ -129,7 +129,7 @@ struct AudioDmaOps { * @since 1.0 * @version 1.0 */ - int32_t (*DmaSubmit)(struct PlatformData *platformData); + int32_t (*DmaSubmit)(const struct PlatformData *platformData); /** * @brief Defines dma pending function. @@ -165,7 +165,7 @@ struct AudioDmaOps { * @since 1.0 * @version 1.0 */ - int32_t (*DmaResume)(struct PlatformData *platformData); + int32_t (*DmaResume)(const struct PlatformData *platformData); /** * @brief Defines Get the function of the current playback or recording position. diff --git a/model/audio/common/include/audio_codec_base.h b/model/audio/common/include/audio_codec_base.h index c89ce90ad..c404017fa 100755 --- a/model/audio/common/include/audio_codec_base.h +++ b/model/audio/common/include/audio_codec_base.h @@ -23,7 +23,7 @@ int32_t CodecGetServiceName(const struct HdfDeviceObject *device, const char **d int32_t CodecGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName); int32_t CodecGetConfigInfo(const struct HdfDeviceObject *device, struct CodecData *codecData); int32_t CodecSetConfigInfo(struct CodecData *codeData, struct DaiData *daiData); -int32_t CodecSetCtlFunc(struct CodecData *codeData, void *aiaoGetCtrl, void *aiaoSetCtrl); +int32_t CodecSetCtlFunc(struct CodecData *codeData,const void *aiaoGetCtrl,const void *aiaoSetCtrl); #ifdef __cplusplus #if __cplusplus diff --git a/model/audio/common/src/audio_accessory_base.c b/model/audio/common/src/audio_accessory_base.c index 747c9d942..6fcdd465a 100755 --- a/model/audio/common/src/audio_accessory_base.c +++ b/model/audio/common/src/audio_accessory_base.c @@ -108,6 +108,8 @@ int32_t AccessoryI2cReadWrite(struct AudioAddrConfig *regAttr, uint16_t rwFlag) int16_t transferMsgCount = 1; uint8_t regs[I2C_REG_LEN]; struct I2cMsg msgs[I2C_MSG_NUM]; + (void)memset_s(msgs, sizeof(struct I2cMsg) * I2C_MSG_NUM, 0, sizeof(struct I2cMsg) * I2C_MSG_NUM); + AUDIO_DRIVER_LOG_DEBUG("entry.\n"); if (regAttr == NULL || rwFlag < 0 || rwFlag > 1) { AUDIO_DRIVER_LOG_ERR("invalid parameter."); @@ -298,9 +300,10 @@ int32_t AcessoryDeviceFrequencyParse(uint32_t rate, uint16_t *freq) int32_t AccessoryDeviceCfgGet(struct AccessoryData *accessoryData, struct AccessoryTransferData *accessoryTransferData) { - int32_t ret, index; - struct AudioControlConfig *ctlcfgItem = NULL; - uint32_t audioCfgCtrlCount; + int32_t ret; + int32_t index; + int32_t audioCfgCtrlCount; + ret = (accessoryData == NULL || accessoryData->regConfig == NULL || accessoryTransferData == NULL); if (ret) { AUDIO_DRIVER_LOG_ERR("input para is NULL."); @@ -317,7 +320,7 @@ int32_t AccessoryDeviceCfgGet(struct AccessoryData *accessoryData, AUDIO_DRIVER_LOG_ERR("parsing params is NULL."); return HDF_FAILURE; } - ctlcfgItem = g_audioRegCfgGroupNode[AUDIO_CTRL_CFG_GROUP]->ctrlCfgItem; + struct AudioControlConfig *ctlcfgItem = g_audioRegCfgGroupNode[AUDIO_CTRL_CFG_GROUP]->ctrlCfgItem; audioCfgCtrlCount = g_audioRegCfgGroupNode[AUDIO_CTRL_CFG_GROUP]->itemNum; g_audioControls = (struct AudioKcontrol *)OsalMemCalloc(audioCfgCtrlCount * sizeof(struct AudioKcontrol)); accessoryTransferData->accessoryRegCfgGroupNode = g_audioRegCfgGroupNode; diff --git a/model/audio/common/src/audio_codec_base.c b/model/audio/common/src/audio_codec_base.c index 0666e7443..b247b2aaa 100755 --- a/model/audio/common/src/audio_codec_base.c +++ b/model/audio/common/src/audio_codec_base.c @@ -101,14 +101,14 @@ int32_t CodecGetConfigInfo(const struct HdfDeviceObject *device, struct CodecDat return HDF_SUCCESS; } -static int32_t SapmCtrlToSapmComp(struct AudioSapmComponent *sapmComponents, - struct AudioSapmCtrlConfig *sapmCompItem, uint16_t index) +static int32_t SapmCtrlToSapmComp(struct AudioSapmComponent *sapmComponents, + const struct AudioSapmCtrlConfig *sapmCompItem, uint16_t index) { if (sapmComponents == NULL || sapmCompItem == NULL) { AUDIO_DRIVER_LOG_ERR("input para is NULL."); return HDF_FAILURE; } - + sapmComponents[index].componentName = g_audioSapmCompNameList[sapmCompItem[index].compNameIndex]; sapmComponents[index].reg = sapmCompItem[index].reg; @@ -231,7 +231,7 @@ int32_t CodecSetConfigInfo(struct CodecData *codeData, struct DaiData *daiData) return HDF_SUCCESS; } -int32_t CodecSetCtlFunc(struct CodecData *codeData, void *aiaoGetCtrl, void *aiaoSetCtrl) +int32_t CodecSetCtlFunc(struct CodecData *codeData,const void *aiaoGetCtrl,const void *aiaoSetCtrl) { uint32_t index; if (codeData == NULL || codeData->regConfig == NULL || @@ -240,9 +240,14 @@ int32_t CodecSetCtlFunc(struct CodecData *codeData, void *aiaoGetCtrl, void *aia return HDF_FAILURE; } struct AudioRegCfgGroupNode **regCfgGroup = codeData->regConfig->audioRegParams; + if (regCfgGroup == NULL || regCfgGroup[AUDIO_CTRL_CFG_GROUP] == NULL) { + AUDIO_DRIVER_LOG_ERR("regCfgGroup or regCfgGroup[AUDIO_CTRL_CFG_GROUP] is NULL."); + return HDF_FAILURE; + } + struct AudioControlConfig *compItem = regCfgGroup[AUDIO_CTRL_CFG_GROUP]->ctrlCfgItem; - if (regCfgGroup == NULL || compItem == NULL) { - AUDIO_DRIVER_LOG_ERR("regCfgGroup or compItem is NULL."); + if (compItem == NULL) { + AUDIO_DRIVER_LOG_ERR("compItem is NULL."); return HDF_FAILURE; } diff --git a/model/audio/common/src/audio_dai_base.c b/model/audio/common/src/audio_dai_base.c index 240ba1121..3f470cfaf 100644 --- a/model/audio/common/src/audio_dai_base.c +++ b/model/audio/common/src/audio_dai_base.c @@ -98,6 +98,10 @@ int32_t DaiSetConfigInfo(struct DaiData *data) for (index = 0; index < data->numControls; index++) { data->controls[index].iface = item[index].iface; + if (item[index].arrayIndex >= AUDIO_CTRL_LIST_MAX) { + AUDIO_DRIVER_LOG_ERR("Array super index."); + return HDF_FAILURE; + } data->controls[index].name = g_audioControlsList[item[index].arrayIndex]; data->controls[index].Info = AudioInfoCtrlOps; data->controls[index].privateValue = (unsigned long)&patRegCfgItemTmp[index]; diff --git a/model/audio/common/src/audio_platform_base.c b/model/audio/common/src/audio_platform_base.c index 611f57480..ecaa409b4 100755 --- a/model/audio/common/src/audio_platform_base.c +++ b/model/audio/common/src/audio_platform_base.c @@ -207,14 +207,14 @@ int32_t AudioSetCaptureBufInfo(struct PlatformData *data, const struct AudioPcmH int32_t AudioWriteProcBigEndian(const struct PlatformData *data, struct AudioTxData *txData) { - uint64_t buffSize; + uint32_t buffSize; if (data == NULL || txData == NULL || txData->buf == NULL) { AUDIO_DRIVER_LOG_ERR("input param is null."); return HDF_FAILURE; } - buffSize = txData->frames * data->pcmInfo.frameSize; + buffSize = (uint32_t)txData->frames * data->pcmInfo.frameSize; if (data->pcmInfo.isBigEndian) { if (AudioDataBigEndianChange(txData->buf, buffSize, data->pcmInfo.bitWidth) != HDF_SUCCESS) { AUDIO_DRIVER_LOG_ERR("AudioDataBigEndianChange: failed."); @@ -228,12 +228,11 @@ static enum CriBuffStatus AudioDmaBuffStatus(const struct AudioCard *card) { uint32_t dataAvailable; uint32_t residual; - uint32_t pointer; - struct PlatformData *data = NULL; + uint32_t pointer = 0; uint32_t wptr; uint32_t rptr; - data = PlatformDataFromCard(card); + struct PlatformData *data = PlatformDataFromCard(card); if (data == NULL || data->ops == NULL) { AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed."); return HDF_FAILURE; @@ -468,7 +467,7 @@ static int32_t AudioMmapWriteTransfer(const struct AudioCard *card) return HDF_FAILURE; } - uint32_t totalSize = data->mmapData.totalBufferFrames * data->pcmInfo.frameSize; + uint32_t totalSize = (uint32_t)data->mmapData.totalBufferFrames * data->pcmInfo.frameSize; uint32_t lastBuffSize = ((totalSize % MIN_PERIOD_SIZE) == 0) ? MIN_PERIOD_SIZE : (totalSize % MIN_PERIOD_SIZE); uint32_t loopTimes = (lastBuffSize == MIN_PERIOD_SIZE) ? (totalSize / MIN_PERIOD_SIZE) : (totalSize / MIN_PERIOD_SIZE + 1); @@ -596,21 +595,21 @@ int32_t AudioMmapReadTransfer(const struct AudioCard *card, const struct AudioMm uint32_t offset = 0; enum CriBuffStatus status; uint32_t timeout = 0; - struct PlatformData *data = NULL; - if (!card || !rxMmapData || !rxMmapData->memoryAddress || rxMmapData->totalBufferFrames <= 0) { + if (card == NULL || rxMmapData == NULL || rxMmapData->memoryAddress == NULL || + rxMmapData->totalBufferFrames <= 0) { AUDIO_DRIVER_LOG_ERR("param is invalid."); return HDF_ERR_INVALID_PARAM; } - data = PlatformDataFromCard(card); + struct PlatformData *data = PlatformDataFromCard(card); if (data == NULL) { AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed."); return HDF_FAILURE; } uint32_t frameSize = data->pcmInfo.frameSize; - uint32_t totalSize = rxMmapData->totalBufferFrames * frameSize; + uint32_t totalSize = (uint32_t)rxMmapData->totalBufferFrames * frameSize; data->captureBufInfo.pointer = 0; data->captureBufInfo.curTrafSize = data->captureBufInfo.trafBufSize; if (data->captureBufInfo.virtAddr == NULL) { diff --git a/model/audio/core/include/audio_core.h b/model/audio/core/include/audio_core.h index aba914d87..30faa241d 100755 --- a/model/audio/core/include/audio_core.h +++ b/model/audio/core/include/audio_core.h @@ -39,7 +39,8 @@ int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec, const struct AudioMixerControl *mixerControl, uint32_t value); int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory, const struct AudioMixerControl *mixerControl, uint32_t value); -int32_t AudioUpdateDaiRegBits(const struct DaiDevice *dai, struct AudioMixerControl *mixerControl, uint32_t value); +int32_t AudioUpdateDaiRegBits(const struct DaiDevice *dai, const struct AudioMixerControl *mixerControl, + uint32_t value); struct DaiDevice *AudioKcontrolGetCpuDai(const struct AudioKcontrol *kcontrol); struct CodecDevice *AudioKcontrolGetCodec(const struct AudioKcontrol *kcontrol); diff --git a/model/audio/core/include/audio_parse.h b/model/audio/core/include/audio_parse.h index bba9a8279..e66b3b7e5 100755 --- a/model/audio/core/include/audio_parse.h +++ b/model/audio/core/include/audio_parse.h @@ -19,19 +19,22 @@ extern "C" { #endif /* __cplusplus */ #define AUDIO_CONFIG_MAX_ITEM 100 +#define AUDIO_CTRL_LIST_MAX 10 +#define AUDIO_SAPM_COMP_NAME_LIST_MAX 9 +#define AUDIO_SAPM_CFG_NAME_LIST_MAX 4 -static const char *g_audioControlsList[] = { +static const char *g_audioControlsList[AUDIO_CTRL_LIST_MAX] = { "Main Playback Volume", "Main Capture Volume", "Playback Mute", "Capture Mute", "Mic Left Gain", "Mic Right Gain", "External Codec Enable", "Internally Codec Enable", "Render Channel Mode", "Captrue Channel Mode" }; -static char *g_audioSapmCompNameList[] = { +static char *g_audioSapmCompNameList[AUDIO_SAPM_COMP_NAME_LIST_MAX] = { "ADCL", "ADCR", "DACL", "DACR", "LPGA", "RPGA", "SPKL", "SPKR", "MIC" }; -static char *g_audioSapmCfgNameList[] = { +static char *g_audioSapmCfgNameList[AUDIO_SAPM_CFG_NAME_LIST_MAX] = { "LPGA MIC Switch", "RPGA MIC Switch", "Dacl enable", "Dacr enable" }; diff --git a/model/audio/core/src/audio_core.c b/model/audio/core/src/audio_core.c index b1b4b53d5..6dc781861 100755 --- a/model/audio/core/src/audio_core.c +++ b/model/audio/core/src/audio_core.c @@ -439,7 +439,7 @@ int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory, return HDF_SUCCESS; } -int32_t AudioUpdateDaiRegBits(const struct DaiDevice *dai, struct AudioMixerControl *mixerControl, uint32_t value) +int32_t AudioUpdateDaiRegBits(const struct DaiDevice *dai, const struct AudioMixerControl *mixerControl, uint32_t value) { int32_t ret; uint32_t curValue = 0; diff --git a/model/audio/core/src/audio_parse.c b/model/audio/core/src/audio_parse.c index 6670cf42a..245140705 100755 --- a/model/audio/core/src/audio_parse.c +++ b/model/audio/core/src/audio_parse.c @@ -129,7 +129,7 @@ static uint32_t GetAudioRegGroupNameIndex(const char *name) return index; } -static uint32_t* GetRegArray(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, +static uint32_t* GetRegArray(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, struct AudioRegCfgGroupNode* group, uint32_t indexMax) { int32_t ret; @@ -151,7 +151,7 @@ static uint32_t* GetRegArray(struct DeviceResourceIface *parser, const struct De return NULL; } - group->itemNum = (num + 1) / indexMax; + group->itemNum = num / indexMax; uint32_t *buf = (uint32_t *)OsalMemCalloc(sizeof(uint32_t) * num); if (buf == NULL) { @@ -168,7 +168,7 @@ static uint32_t* GetRegArray(struct DeviceResourceIface *parser, const struct De return buf; } -static int32_t ParseAudioRegItem(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, +static int32_t ParseAudioRegItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, struct AudioRegCfgGroupNode* group) { int32_t step; @@ -211,7 +211,7 @@ static int32_t ParseAudioRegItem(struct DeviceResourceIface *parser, const struc return HDF_SUCCESS; } -static int32_t ParseAudioSapmItem(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, +static int32_t ParseAudioSapmItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, struct AudioRegCfgGroupNode* group) { int32_t step; @@ -253,7 +253,7 @@ static int32_t ParseAudioSapmItem(struct DeviceResourceIface *parser, const stru } -static int32_t ParseAudioCtrlItem(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, +static int32_t ParseAudioCtrlItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, struct AudioRegCfgGroupNode* group) { int32_t step; @@ -289,14 +289,14 @@ static int32_t ParseAudioCtrlItem(struct DeviceResourceIface *parser, const stru return HDF_SUCCESS; } -static int32_t ParseAudioAddrItem(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, +static int32_t ParseAudioAddrItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode, struct AudioRegCfgGroupNode* group) { int32_t step; - int32_t index = group->groupIndex; + int32_t index; - if (parser == NULL || regNode == NULL || g_audioRegGroupName[index] == NULL || group == NULL) { - ADM_LOG_ERR("Input para check error: groupName=%p", g_audioRegGroupName[index]); + if (parser == NULL || regNode == NULL || group == NULL) { + ADM_LOG_ERR("Input para check error."); return HDF_FAILURE; } @@ -315,7 +315,6 @@ static int32_t ParseAudioAddrItem(struct DeviceResourceIface *parser, const stru for (index = 0; index < group->itemNum; ++index) { step = AUDIO_ADDR_CFG_INDEX_MAX * index; - group->addrCfgItem[index].addr = buf[step + AUDIO_ADDR_CFG_REG_INDEX]; group->addrCfgItem[index].value = buf[step + AUDIO_ADDR_CFG_VALUE_INDEX]; } @@ -323,7 +322,7 @@ static int32_t ParseAudioAddrItem(struct DeviceResourceIface *parser, const stru return HDF_SUCCESS; } -static int32_t ParseAudioRegGroup(struct DeviceResourceIface *parser, +static int32_t ParseAudioRegGroup(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regCfgNode, struct AudioRegCfgGroupNode **groupNode, uint32_t index) { int32_t ret = HDF_FAILURE; @@ -394,7 +393,7 @@ static void ReleaseAudioAllRegConfig(struct AudioRegCfgData *config) } } -static int32_t ParseAudioAttr(struct DeviceResourceIface *parser, const struct DeviceResourceNode *attrNode, +static int32_t ParseAudioAttr(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *attrNode, struct AudioIdInfo *config) { int32_t ret; diff --git a/model/audio/dispatch/src/audio_stream_dispatch.c b/model/audio/dispatch/src/audio_stream_dispatch.c index bb4f135ae..68cfbdbe5 100755 --- a/model/audio/dispatch/src/audio_stream_dispatch.c +++ b/model/audio/dispatch/src/audio_stream_dispatch.c @@ -14,7 +14,7 @@ #define BUFF_SIZE_MAX 64 -static inline struct StreamHost *StreamHostFromDevice(struct HdfDeviceObject *device) +static inline struct StreamHost *StreamHostFromDevice(const struct HdfDeviceObject *device) { return (device == NULL) ? NULL : (struct StreamHost *)device->service; } @@ -169,9 +169,13 @@ static int32_t HwParamsDispatch(const struct AudioCard *audioCard, const struct return HDF_SUCCESS; } -static int32_t CpuDaiDevStartup(struct AudioCard *audioCard, struct DaiDevice *cpuDai) +static int32_t CpuDaiDevStartup(const struct AudioCard *audioCard, const struct DaiDevice *cpuDai) { int32_t ret; + if (audioCard == NULL || audioCard->rtd == NULL) { + ADM_LOG_ERR("audioCard is null."); + return HDF_FAILURE; + } if (cpuDai != NULL && cpuDai->devData != NULL && cpuDai->devData->ops != NULL && cpuDai->devData->ops->Startup != NULL) { ret = cpuDai->devData->ops->Startup(audioCard, cpuDai); @@ -185,7 +189,7 @@ static int32_t CpuDaiDevStartup(struct AudioCard *audioCard, struct DaiDevice *c return HDF_SUCCESS; } -static int32_t CodecDaiDevStartup(struct AudioCard *audioCard, struct DaiDevice *codecDai) +static int32_t CodecDaiDevStartup(const struct AudioCard *audioCard, const struct DaiDevice *codecDai) { int32_t ret; if (audioCard == NULL || audioCard->rtd == NULL) { @@ -206,7 +210,7 @@ static int32_t CodecDaiDevStartup(struct AudioCard *audioCard, struct DaiDevice return HDF_SUCCESS; } -static int32_t DspDaiDevStartup(struct AudioCard *audioCard, struct DaiDevice *dspDai) +static int32_t DspDaiDevStartup(const struct AudioCard *audioCard, const struct DaiDevice *dspDai) { int32_t ret; if (audioCard == NULL || audioCard->rtd == NULL) { @@ -226,7 +230,7 @@ static int32_t DspDaiDevStartup(struct AudioCard *audioCard, struct DaiDevice *d return HDF_SUCCESS; } -static int32_t AccessoryDaiDevStartup(struct AudioCard *audioCard, struct DaiDevice *accessoryDai) +static int32_t AccessoryDaiDevStartup(const struct AudioCard *audioCard, const struct DaiDevice *accessoryDai) { int32_t ret; if (audioCard == NULL || audioCard->rtd == NULL) { @@ -246,7 +250,7 @@ static int32_t AccessoryDaiDevStartup(struct AudioCard *audioCard, struct DaiDev return HDF_SUCCESS; } -static int32_t AudioDaiDeviceStartup(struct AudioCard *audioCard) +static int32_t AudioDaiDeviceStartup(const struct AudioCard *audioCard) { struct DaiDevice *cpuDai = NULL; struct DaiDevice *codecDai = NULL; @@ -779,6 +783,10 @@ static int32_t StreamHostMmapWrite(const struct HdfDeviceIoClient *client, struc } txMmapData.memoryAddress = (void *)((uintptr_t)mAddress); + if (txMmapData.memoryAddress == NULL) { + ADM_LOG_ERR("txMmapData.memoryAddress is NULL."); + return HDF_FAILURE; + } if (!HdfSbufReadInt32(data, (uint32_t *)&(txMmapData.memoryFd))) { ADM_LOG_ERR("render mmap read request memory fd failed!"); @@ -849,6 +857,10 @@ static int32_t StreamHostMmapRead(const struct HdfDeviceIoClient *client, struct return HDF_FAILURE; } rxMmapData.memoryAddress = (void *)((uintptr_t)mAddress); + if (rxMmapData.memoryAddress == NULL) { + ADM_LOG_ERR("rxMmapData.memoryAddress is NULL."); + return HDF_FAILURE; + } if (!HdfSbufReadInt32(data, (uint32_t *)&(rxMmapData.memoryFd))) { ADM_LOG_ERR("capture mmap read request memory fd failed!"); @@ -905,12 +917,13 @@ static int32_t StreamHostMmapPositionRead(const struct HdfDeviceIoClient *client return HDF_SUCCESS; } -static int32_t StreamTriggerRouteImpl(struct AudioCard *audioCard, struct AudioRuntimeDeivces *rtd, +static int32_t StreamTriggerRouteImpl(const struct AudioCard *audioCard, const struct AudioRuntimeDeivces *rtd, enum StreamDispMethodCmd methodCmd) { int32_t ret = HDF_SUCCESS; struct DaiDevice *cpuDai = NULL; struct DaiDevice *codecDai = NULL; + struct DaiDevice *accessoryDai = NULL; struct DaiDevice *dspDai = NULL; if (audioCard == NULL || rtd == NULL) { ADM_LOG_ERR("input param is NULL."); @@ -934,6 +947,15 @@ static int32_t StreamTriggerRouteImpl(struct AudioCard *audioCard, struct AudioR return HDF_FAILURE; } } + accessoryDai = rtd->accessoryDai; + if (accessoryDai != NULL && accessoryDai->devData != NULL && accessoryDai->devData->ops != NULL && + accessoryDai->devData->ops->Trigger != NULL) { + ret = accessoryDai->devData->ops->Trigger(audioCard, methodCmd, accessoryDai); + if (ret != HDF_SUCCESS) { + ADM_LOG_ERR("accessoryDai Trigger failed."); + return HDF_FAILURE; + } + } dspDai = rtd->dspDai; if (dspDai != NULL && dspDai->devData != NULL && dspDai->devData->ops != NULL && dspDai->devData->ops->Trigger != NULL) { @@ -943,11 +965,9 @@ static int32_t StreamTriggerRouteImpl(struct AudioCard *audioCard, struct AudioR return HDF_FAILURE; } } - ADM_LOG_DEBUG("success."); return HDF_SUCCESS; } - static int32_t StreamHostRenderStart(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { struct AudioRuntimeDeivces *rtd = NULL; @@ -1447,10 +1467,10 @@ static struct StreamDispCmdHandleList g_streamDispCmdHandle[] = { }; static int32_t StreamDispatch(struct HdfDeviceIoClient *client, int cmdId, - struct HdfSBuf *data, struct HdfSBuf *reply) + struct HdfSBuf *data, struct HdfSBuf *reply) { unsigned int count = sizeof(g_streamDispCmdHandle) / sizeof(g_streamDispCmdHandle[0]); - for (int i = 0; i < count; ++i) { + for (unsigned int i = 0; i < count; ++i) { if ((cmdId == (int)(g_streamDispCmdHandle[i].cmd)) && (g_streamDispCmdHandle[i].func != NULL)) { return g_streamDispCmdHandle[i].func(client, data, reply); } diff --git a/model/audio/sapm/src/audio_sapm.c b/model/audio/sapm/src/audio_sapm.c index da7f723bd..7d4fe632b 100755 --- a/model/audio/sapm/src/audio_sapm.c +++ b/model/audio/sapm/src/audio_sapm.c @@ -84,7 +84,7 @@ static int32_t ConnectedInputEndPoint(const struct AudioSapmComponent *sapmCompo { struct AudioSapmpath *path = NULL; int32_t count = 0; - int32_t endPointVal = 1; + const int32_t endPointVal = 1; if (sapmComponent == NULL) { ADM_LOG_ERR("input param sapmComponent is NULL."); @@ -114,7 +114,7 @@ static int32_t ConnectedOutputEndPoint(const struct AudioSapmComponent *sapmComp { struct AudioSapmpath *path = NULL; int32_t count = 0; - int32_t endPointVal = 1; + const int32_t endPointVal = 1; if (sapmComponent == NULL) { ADM_LOG_ERR("input param sapmComponent is NULL."); @@ -404,7 +404,7 @@ static void MuxSetPathStatus(const struct AudioSapmComponent *sapmComponent, str int32_t ret; uint32_t val = 0; int32_t item; - uint32_t reg = 0; + const uint32_t reg = 0; uint32_t shift; if ((sapmComponent == NULL || sapmComponent->codec == NULL) || (path == NULL || path->name == NULL) || @@ -443,7 +443,7 @@ static void MuxValueSetPathStatus(const struct AudioSapmComponent *sapmComponent int32_t ret; uint32_t val = 0; uint32_t item; - uint32_t reg = 0; + const uint32_t reg = 0; uint32_t shift; if ((sapmComponent == NULL || sapmComponent->codec == NULL) || (path == NULL || path->name == NULL) || (enumKtl == NULL || enumKtl->texts == NULL)) { @@ -756,7 +756,7 @@ int32_t AudioSapmAddRoutes(struct AudioCard *audioCard, const struct AudioSapmRo return HDF_SUCCESS; } -int32_t AudioSapmNewMixerControls(struct AudioSapmComponent *sapmComponent, struct AudioCard *audioCard) +int32_t AudioSapmNewMixerControls(const struct AudioSapmComponent *sapmComponent, struct AudioCard *audioCard) { struct AudioSapmpath *path = NULL; int32_t i; @@ -768,7 +768,8 @@ int32_t AudioSapmNewMixerControls(struct AudioSapmComponent *sapmComponent, stru for (i = 0; i < sapmComponent->kcontrolsNum; i++) { DLIST_FOR_EACH_ENTRY(path, &sapmComponent->sources, struct AudioSapmpath, listSink) { - if (path->name == NULL || sapmComponent->kcontrolNews[i].name == NULL) { + if (path->name == NULL || sapmComponent->kcontrolNews == NULL + || sapmComponent->kcontrolNews[i].name == NULL) { continue; } @@ -958,6 +959,7 @@ static void AudioSapmPowerDownSeqRun(const struct DListHead *list) static int AudioSapmPowerComponents(struct AudioCard *audioCard) { + int32_t ret; struct AudioSapmComponent *sapmComponent = NULL; struct DListHead upList; struct DListHead downList; @@ -978,7 +980,10 @@ static int AudioSapmPowerComponents(struct AudioCard *audioCard) } if (g_audioSapmIsStandby && sapmComponent->PowerClockOp != NULL) { - sapmComponent->PowerClockOp(sapmComponent); + ret = sapmComponent->PowerClockOp(sapmComponent); + if (ret != HDF_SUCCESS) { + continue; + } } AudioSapmSetPower(audioCard, sapmComponent, sapmComponent->newPower, &upList, &downList); @@ -1327,7 +1332,7 @@ int32_t AudioSampSetPowerMonitor(struct AudioCard *card, bool powerMonitorState) return HDF_SUCCESS; } -static void AudioSapmEnterSleepSub(uintptr_t para, struct AudioSapmComponent *sapmComponent) +static void AudioSapmEnterSleepSub(const uintptr_t para, struct AudioSapmComponent *sapmComponent) { struct DListHead downList; struct AudioCard *audioCard = (struct AudioCard *)para; -- Gitee