diff --git a/Makefile.am b/Makefile.am index 701e8f24c181..d941047eefbb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,6 +33,11 @@ export ARCH_INCDIR = \ PLATFORM_INCDIR = -I $(SRC_DIR)/platform/$(PLATFORM)/include +if BUILD_CAVS +PLATFORM_INCDIR += \ + -I $(SRC_DIR)/platform/intel/include +endif + if XCC PLATFORM_INCDIR += \ -I $(ROOT_DIR)/arch/include diff --git a/configure.ac b/configure.ac index 65114f358299..be89fc1a9680 100644 --- a/configure.ac +++ b/configure.ac @@ -133,16 +133,16 @@ AC_ARG_WITH([cmocka-prefix], AS_HELP_STRING([--with-cmocka-prefix], [Path to cmocka]), [], [with_cmocka_prefix="no"]) +# in case of native build, cmocka may be installed +HAVE_CMOCKA_PKG=no +AC_CHECK_LIB(cmocka, _cmocka_run_group_tests, [HAVE_CMOCKA_PKG=yes]) + if test "x$with_arch" != "xno"; then if test "x$with_cmocka_prefix" = "xno"; then if test "$ARCH" = "xtensa"; then AC_MSG_WARN([Need cmocka to run unit tests. Path to cmocka not specified. Please use --with-cmocka-prefix option.]) - else - # in case of native build, cmocka may be installed - PKG_CHECK_EXISTS(cmocka, - [], - [AC_MSG_WARN([Need cmocka to run unit tests. No cmocka library found. Please install cmocka or use --with-cmocka-prefix option.])] - ) + elif test "x$HAVE_CMOCKA_PKG" = "xno"; then + AC_MSG_WARN([Need cmocka to run unit tests. No cmocka library found. Please install cmocka or use --with-cmocka-prefix option.]) fi else CMOCKA_PREFIX="$with_cmocka_prefix" @@ -283,6 +283,7 @@ AM_CONDITIONAL(BUILD_BROADWELL, test "$FW_NAME" = "bdw") AM_CONDITIONAL(BUILD_APOLLOLAKE, test "$FW_NAME" = "apl") AM_CONDITIONAL(BUILD_CANNONLAKE, test "$FW_NAME" = "cnl") AM_CONDITIONAL(BUILD_BOOTLOADER, test "$FW_NAME" = "apl" -o "$FW_NAME" = "cnl") +AM_CONDITIONAL(BUILD_CAVS, test "$FW_NAME" = "apl" -o "$FW_NAME" = "cnl") AM_CONDITIONAL(BUILD_MODULE, test "$FW_NAME" = "apl" -o "$FW_NAME" = "cnl") AM_CONDITIONAL(BUILD_APL_SSP, test "$FW_NAME" = "apl" -o "$FW_NAME" = "cnl") @@ -467,6 +468,10 @@ AC_CONFIG_FILES([ src/platform/cannonlake/include/arch/xtensa/Makefile src/platform/cannonlake/include/arch/xtensa/config/Makefile src/platform/cannonlake/include/platform/Makefile + src/platform/intel/Makefile + src/platform/intel/include/Makefile + src/platform/intel/include/platform/Makefile + src/platform/intel/include/platform/cavs/Makefile test/Makefile test/cmocka/Makefile ]) diff --git a/doc/sof_uapi.doxygen.in b/doc/sof_uapi.doxygen.in index 74052f1aa76c..18444c9a41cc 100644 --- a/doc/sof_uapi.doxygen.in +++ b/doc/sof_uapi.doxygen.in @@ -6,7 +6,8 @@ GENERATE_MAN = NO GENERATE_XML = YES CASE_SENSE_NAMES = NO -INPUT = @top_srcdir@/src/include/uapi +INPUT = @top_srcdir@/src/include/uapi \ + @top_srcdir@/src/include/sof EXCLUDE = RECURSIVE = YES FILE_PATTERNS = *.c *.h diff --git a/src/arch/xtensa/include/arch/spinlock.h b/src/arch/xtensa/include/arch/spinlock.h index 13bf4c1ad5d6..3bb6b15c355a 100644 --- a/src/arch/xtensa/include/arch/spinlock.h +++ b/src/arch/xtensa/include/arch/spinlock.h @@ -49,29 +49,29 @@ static inline void arch_spinlock_init(spinlock_t *lock) static inline void arch_spin_lock(spinlock_t *lock) { - uint32_t result; + uint32_t result, current; __asm__ __volatile__( - " movi %0, 0\n" - " wsr %0, scompare1\n" - "1: movi %0, 1\n" - " s32c1i %0, %1, 0\n" - " bnez %0, 1b\n" - : "=&a" (result) + "1: l32i %1, %2, 0\n" + " wsr %1, scompare1\n" + " movi %0, 1\n" + " s32c1i %0, %2, 0\n" + " bne %0, %1, 1b\n" + : "=&a" (result), "=&a" (current) : "a" (&lock->lock) : "memory"); } static inline int arch_try_lock(spinlock_t *lock) { - uint32_t result; + uint32_t result, current; __asm__ __volatile__( - " movi %0, 0\n" - " wsr %0, scompare1\n" + " l32i %1, %2, 0\n" + " wsr %1, scompare1\n" " movi %0, 1\n" - " s32c1i %0, %1, 0\n" - : "=&a" (result) + " s32c1i %0, %2, 0\n" + : "=&a" (result), "=&a" (current) : "a" (&lock->lock) : "memory"); diff --git a/src/audio/volume.c b/src/audio/volume.c index 9e2968d93f54..2ac3d6444e14 100644 --- a/src/audio/volume.c +++ b/src/audio/volume.c @@ -30,6 +30,14 @@ * Tomasz Lauda */ +/** + * \file audio/volume.c + * \brief Volume component implementation + * \authors Liam Girdwood \n + * Keyon Jie \n + * Tomasz Lauda + */ + #include #include #include @@ -41,7 +49,11 @@ #include #include "volume.h" -/* synchronise host mmap() volume with real value */ +/** + * \brief Synchronize host mmap() volume with real value. + * \param[in,out] cd Volume component private data. + * \param[in] chan Channel number. + */ static void vol_sync_host(struct comp_data *cd, uint32_t chan) { if (cd->hvol == NULL) @@ -55,13 +67,23 @@ static void vol_sync_host(struct comp_data *cd, uint32_t chan) } } +/** + * \brief Update volume with target value. + * \param[in,out] cd Volume component private data. + * \param[in] chan Channel number. + */ static void vol_update(struct comp_data *cd, uint32_t chan) { cd->volume[chan] = cd->tvolume[chan]; vol_sync_host(cd, chan); } -/* this ramps volume changes over time */ +/** + * \brief Ramps volume changes over time. + * \param[in,out] data Volume base component device. + * \param[in] delay Update time. + * \return Time until next work. + */ static uint64_t vol_work(void *data, uint64_t delay) { struct comp_dev *dev = (struct comp_dev *)data; @@ -119,6 +141,12 @@ static uint64_t vol_work(void *data, uint64_t delay) return 0; } +/** + * \brief Creates volume component. + * \param[in,out] data Volume base component device. + * \param[in] delay Update time. + * \return Pointer to volume base component device. + */ static struct comp_dev *volume_new(struct sof_ipc_comp *comp) { struct comp_dev *dev; @@ -157,6 +185,10 @@ static struct comp_dev *volume_new(struct sof_ipc_comp *comp) return dev; } +/** + * \brief Frees volume component. + * \param[in,out] dev Volume base component device. + */ static void volume_free(struct comp_dev *dev) { struct comp_data *cd = comp_get_drvdata(dev); @@ -167,9 +199,12 @@ static void volume_free(struct comp_dev *dev) rfree(dev); } -/* - * Set volume component audio stream parameters - All done in prepare() since - * we need to know source and sink component params. +/** + * \brief Sets volume component audio stream parameters. + * \param[in,out] dev Volume base component device. + * \return Error code. + * + * All done in prepare() since we need to know source and sink component params. */ static int volume_params(struct comp_dev *dev) { @@ -183,6 +218,12 @@ static int volume_params(struct comp_dev *dev) return 0; } +/** + * \brief Sets channel target volume. + * \param[in,out] dev Volume base component device. + * \param[in] chan Channel number. + * \param[in] vol Target volume. + */ static inline void volume_set_chan(struct comp_dev *dev, int chan, uint32_t vol) { struct comp_data *cd = comp_get_drvdata(dev); @@ -202,6 +243,11 @@ static inline void volume_set_chan(struct comp_dev *dev, int chan, uint32_t vol) cd->tvolume[chan] = v; } +/** + * \brief Mutes channel. + * \param[in,out] dev Volume base component device. + * \param[in] chan Channel number. + */ static inline void volume_set_chan_mute(struct comp_dev *dev, int chan) { struct comp_data *cd = comp_get_drvdata(dev); @@ -212,6 +258,11 @@ static inline void volume_set_chan_mute(struct comp_dev *dev, int chan) cd->tvolume[chan] = 0; } +/** + * \brief Unmutes channel. + * \param[in,out] dev Volume base component device. + * \param[in] chan Channel number. + */ static inline void volume_set_chan_unmute(struct comp_dev *dev, int chan) { struct comp_data *cd = comp_get_drvdata(dev); @@ -221,6 +272,12 @@ static inline void volume_set_chan_unmute(struct comp_dev *dev, int chan) cd->tvolume[chan] = cd->mvolume[chan]; } +/** + * \brief Sets volume control command. + * \param[in,out] dev Volume base component device. + * \param[in,out] cdata Control command data. + * \return Error code. + */ static int volume_ctrl_set_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata) { @@ -280,6 +337,12 @@ static int volume_ctrl_set_cmd(struct comp_dev *dev, return 0; } +/** + * \brief Gets volume control command. + * \param[in,out] dev Volume base component device. + * \param[in,out] cdata Control command data. + * \return Error code. + */ static int volume_ctrl_get_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata) { @@ -311,7 +374,13 @@ static int volume_ctrl_get_cmd(struct comp_dev *dev, return 0; } -/* used to pass standard and bespoke commands (with data) to component */ +/** + * \brief Used to pass standard and bespoke commands (with data) to component. + * \param[in,out] dev Volume base component device. + * \param[in] cmd Command type. + * \param[in,out] data Control command data. + * \return Error code. + */ static int volume_cmd(struct comp_dev *dev, int cmd, void *data) { struct sof_ipc_ctrl_data *cdata = data; @@ -328,6 +397,12 @@ static int volume_cmd(struct comp_dev *dev, int cmd, void *data) } } +/** + * \brief Sets volume component state. + * \param[in,out] dev Volume base component device. + * \param[in] cmd Command type. + * \return Error code. + */ static int volume_trigger(struct comp_dev *dev, int cmd) { trace_volume("trg"); @@ -335,7 +410,11 @@ static int volume_trigger(struct comp_dev *dev, int cmd) return comp_set_state(dev, cmd); } -/* copy and process stream data from source to sink buffers */ +/** + * \brief Copies and processes stream data. + * \param[in,out] dev Volume base component device. + * \return Error code. + */ static int volume_copy(struct comp_dev *dev) { struct comp_data *cd = comp_get_drvdata(dev); @@ -375,9 +454,13 @@ static int volume_copy(struct comp_dev *dev) return dev->frames; } -/* +/** + * \brief Prepares volume component for processing. + * \param[in,out] dev Volume base component device. + * \return Error code. + * * Volume component is usually first and last in pipelines so it makes sense - * to also do some type conversion too. + * to also do some type of conversion here. */ static int volume_prepare(struct comp_dev *dev) { @@ -489,6 +572,11 @@ static int volume_prepare(struct comp_dev *dev) return ret; } +/** + * \brief Resets volume component. + * \param[in,out] dev Volume base component device. + * \return Error code. + */ static int volume_reset(struct comp_dev *dev) { trace_volume("res"); @@ -497,6 +585,7 @@ static int volume_reset(struct comp_dev *dev) return 0; } +/** \brief Volume component definition. */ struct comp_driver comp_volume = { .type = SOF_COMP_VOLUME, .ops = { @@ -511,6 +600,9 @@ struct comp_driver comp_volume = { }, }; +/** + * \brief Initializes volume component. + */ void sys_comp_volume_init(void) { comp_register(&comp_volume); diff --git a/src/audio/volume.h b/src/audio/volume.h index f7c9b430e64f..d130fe4e2f4a 100644 --- a/src/audio/volume.h +++ b/src/audio/volume.h @@ -28,6 +28,14 @@ * Author: Tomasz Lauda */ +/** + * \file audio/volume.h + * \brief Volume component header file + * \authors Liam Girdwood \n + * Keyon Jie \n + * Tomasz Lauda + */ + #ifndef VOLUME_H #define VOLUME_H @@ -47,49 +55,70 @@ #endif +/** \brief Volume trace function. */ #define trace_volume(__e) trace_event(TRACE_CLASS_VOLUME, __e) + +/** \brief Volume trace value function. */ #define tracev_volume(__e) tracev_event(TRACE_CLASS_VOLUME, __e) + +/** \brief Volume trace error function. */ #define trace_volume_error(__e) trace_error(TRACE_CLASS_VOLUME, __e) -/* this should ramp from 0dB to mute in 64ms. - * i.e 2^16 -> 0 in 32 * 2048 steps each lasting 2ms +/** + * \brief Volume ramp time in microseconds. + * + * This should ramp from 0dB to mute in 64ms. + * i.e. 2^16 -> 0 in 32 * 2048 steps each lasting 2ms. */ #define VOL_RAMP_US 2000 + +/** \brief Volume ramp step. */ #define VOL_RAMP_STEP (1 << 11) + +/** \brief Volume maximum value. */ #define VOL_MAX (1 << 16) + +/** \brief Volume minimum value. */ #define VOL_MIN 0 -/* volume component private data */ +/** + * \brief Volume component private data. + * + * Gain amplitude value is between 0 (mute) ... 2^16 (0dB) ... 2^24 (~+48dB). + */ struct comp_data { - uint32_t source_period_bytes; - uint32_t sink_period_bytes; - enum sof_ipc_frame source_format; - enum sof_ipc_frame sink_format; - uint32_t volume[SOF_IPC_MAX_CHANNELS]; /* current volume */ - uint32_t tvolume[SOF_IPC_MAX_CHANNELS]; /* target volume */ - uint32_t mvolume[SOF_IPC_MAX_CHANNELS]; /* mute volume */ + uint32_t source_period_bytes; /**< source number of period bytes */ + uint32_t sink_period_bytes; /**< sink number of period bytes */ + enum sof_ipc_frame source_format; /**< source frame format */ + enum sof_ipc_frame sink_format; /**< sink frame format */ + uint32_t volume[SOF_IPC_MAX_CHANNELS]; /**< current volume */ + uint32_t tvolume[SOF_IPC_MAX_CHANNELS]; /**< target volume */ + uint32_t mvolume[SOF_IPC_MAX_CHANNELS]; /**< mute volume */ void (*scale_vol)(struct comp_dev *dev, struct comp_buffer *sink, - struct comp_buffer *source); - struct work volwork; - - /* host volume readback */ - struct sof_ipc_ctrl_value_chan *hvol; + struct comp_buffer *source); /**< volume processing function */ + struct work volwork; /**< volume scheduled work function */ + struct sof_ipc_ctrl_value_chan *hvol; /**< host volume readback */ }; +/** \brief Volume processing functions map. */ struct comp_func_map { - uint16_t source; /* source format */ - uint16_t sink; /* sink format */ - uint16_t channels; /* channel number for the stream */ + uint16_t source; /**< source frame format */ + uint16_t sink; /**< sink frame format */ + uint16_t channels; /**< number of stream channels */ void (*func)(struct comp_dev *dev, struct comp_buffer *sink, - struct comp_buffer *source); + struct comp_buffer *source); /**< volume processing function */ }; -/* map of source and sink buffer formats to volume function */ +/** \brief Map of formats with dedicated processing functions. */ extern const struct comp_func_map func_map[]; typedef void (*scale_vol)(struct comp_dev *, struct comp_buffer *, struct comp_buffer *); +/** + * \brief Retrievies volume processing function. + * \param[in,out] dev Volume base component device. + */ scale_vol vol_get_processing_function(struct comp_dev *dev); #endif /* VOLUME_H */ diff --git a/src/audio/volume_generic.c b/src/audio/volume_generic.c index d07fd30efacc..01172d74c5ad 100644 --- a/src/audio/volume_generic.c +++ b/src/audio/volume_generic.c @@ -30,13 +30,27 @@ * Tomasz Lauda */ +/** + * \file audio/volume_generic.c + * \brief Volume generic processing implementation + * \authors Liam Girdwood \n + * Keyon Jie \n + * Tomasz Lauda + */ + #include "volume.h" #ifdef CONFIG_GENERIC -/* volume scaling functions for stereo input */ - -/* copy and scale volume from 16 bit source buffer to 32 bit dest buffer */ +/** + * \brief Volume processing from 16 bit to 32 bit in 2 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 16 bit source buffer + * to 32 bit destination buffer for 2 channels. + */ static void vol_s16_to_s32_2ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -53,7 +67,15 @@ static void vol_s16_to_s32_2ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 32 bit source buffer to 16 bit dest buffer */ +/** + * \brief Volume processing from 32 bit to 16 bit in 2 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 32 bit source buffer + * to 16 bit destination buffer for 2 channels. + */ static void vol_s32_to_s16_2ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -72,7 +94,15 @@ static void vol_s32_to_s16_2ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 32 bit source buffer to 32 bit dest buffer */ +/** + * \brief Volume processing from 32 bit to 32 bit in 2 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 32 bit source buffer + * to 32 bit destination buffer for 2 channels. + */ static void vol_s32_to_s32_2ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -91,7 +121,15 @@ static void vol_s32_to_s32_2ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 16 bit source buffer to 16 bit dest buffer */ +/** + * \brief Volume processing from 16 bit to 16 bit in 2 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 16 bit source buffer + * to 16 bit destination buffer for 2 channels. + */ static void vol_s16_to_s16_2ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -110,8 +148,14 @@ static void vol_s16_to_s16_2ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 16 bit source buffer to 24 bit - * on 32 bit boundary dest buffer +/** + * \brief Volume processing from 16 bit to 24/32 bit in 2 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 16 bit source buffer + * to 24/32 bit destination buffer for 2 channels. */ static void vol_s16_to_s24_2ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) @@ -131,8 +175,14 @@ static void vol_s16_to_s24_2ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 16 bit source buffer to 24 bit - * on 32 bit boundary dest buffer +/** + * \brief Volume processing from 24/32 bit to 16 bit in 2 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 24/32 bit source buffer + * to 16 bit destination buffer for 2 channels. */ static void vol_s24_to_s16_2ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) @@ -154,8 +204,14 @@ static void vol_s24_to_s16_2ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 32 bit source buffer to 24 bit - * on 32 bit boundary dest buffer +/** + * \brief Volume processing from 32 bit to 24/32 bit in 2 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 32 bit source buffer + * to 24/32 bit destination buffer for 2 channels. */ static void vol_s32_to_s24_2ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) @@ -175,8 +231,14 @@ static void vol_s32_to_s24_2ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 16 bit source buffer to 24 bit - * on 32 bit boundary dest buffer +/** + * \brief Volume processing from 24/32 bit to 32 bit in 2 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 24/32 bit source buffer + * to 32 bit destination buffer for 2 channels. */ static void vol_s24_to_s32_2ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) @@ -198,8 +260,14 @@ static void vol_s24_to_s32_2ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 24 bit source buffer to 24 bit on 32 bit boundary - * dest buffer. +/** + * \brief Volume processing from 24/32 bit to 24/32 bit in 2 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 24/32 bit source buffer + * to 24/32 bit destination buffer for 2 channels. */ static void vol_s24_to_s24_2ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) @@ -221,9 +289,15 @@ static void vol_s24_to_s24_2ch(struct comp_dev *dev, struct comp_buffer *sink, } #if PLATFORM_MAX_CHANNELS >= 4 -/* volume scaling functions for 4-channel input */ - -/* copy and scale volume from 16 bit source buffer to 32 bit dest buffer */ +/** + * \brief Volume processing from 16 bit to 32 bit in 4 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 16 bit source buffer + * to 32 bit destination buffer for 4 channels. + */ static void vol_s16_to_s32_4ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -242,7 +316,15 @@ static void vol_s16_to_s32_4ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 32 bit source buffer to 16 bit dest buffer */ +/** + * \brief Volume processing from 32 bit to 16 bit in 4 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 32 bit source buffer + * to 16 bit destination buffer for 4 channels. + */ static void vol_s32_to_s16_4ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -275,7 +357,15 @@ static void vol_s32_to_s16_4ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 32 bit source buffer to 32 bit dest buffer */ +/** + * \brief Volume processing from 32 bit to 32 bit in 4 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 32 bit source buffer + * to 32 bit destination buffer for 4 channels. + */ static void vol_s32_to_s32_4ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -298,7 +388,15 @@ static void vol_s32_to_s32_4ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 16 bit source buffer to 16 bit dest buffer */ +/** + * \brief Volume processing from 16 bit to 16 bit in 4 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 16 bit source buffer + * to 16 bit destination buffer for 4 channels. + */ static void vol_s16_to_s16_4ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -321,8 +419,14 @@ static void vol_s16_to_s16_4ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 16 bit source buffer to 24 bit - * on 32 bit boundary buffer +/** + * \brief Volume processing from 16 bit to 24/32 bit in 4 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 16 bit source buffer + * to 24/32 bit destination buffer for 4 channels. */ static void vol_s16_to_s24_4ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) @@ -346,8 +450,14 @@ static void vol_s16_to_s24_4ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 16 bit source buffer to 24 bit - * on 32 bit boundary dest buffer +/** + * \brief Volume processing from 24/32 bit to 16 bit in 4 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 24/32 bit source buffer + * to 16 bit destination buffer for 4 channels. */ static void vol_s24_to_s16_4ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) @@ -385,8 +495,14 @@ static void vol_s24_to_s16_4ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 32 bit source buffer to 24 bit - * on 32 bit boundary dest buffer +/** + * \brief Volume processing from 32 bit to 24/32 bit in 4 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 32 bit source buffer + * to 24/32 bit destination buffer for 4 channels. */ static void vol_s32_to_s24_4ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) @@ -410,8 +526,14 @@ static void vol_s32_to_s24_4ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* copy and scale volume from 16 bit source buffer to 24 bit - * on 32 bit boundary dest buffer +/** + * \brief Volume processing from 24/32 bit to 32 bit in 4 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 24/32 bit source buffer + * to 32 bit destination buffer for 4 channels. */ static void vol_s24_to_s32_4ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) @@ -439,8 +561,14 @@ static void vol_s24_to_s32_4ch(struct comp_dev *dev, struct comp_buffer *sink, } } -/* Copy and scale volume from 24 bit source buffer to 24 bit on 32 bit boundary - * dest buffer. +/** + * \brief Volume processing from 24/32 bit to 24/32 bit in 4 channels. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + * + * Copy and scale volume from 24/32 bit source buffer + * to 24/32 bit destination buffer for 4 channels. */ static void vol_s24_to_s24_4ch(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) diff --git a/src/audio/volume_hifi3.c b/src/audio/volume_hifi3.c index e410de3b6704..48e164e4ce23 100644 --- a/src/audio/volume_hifi3.c +++ b/src/audio/volume_hifi3.c @@ -28,14 +28,27 @@ * Author: Tomasz Lauda */ +/** + * \file audio/volume_hifi3.c + * \brief Volume HiFi3 processing implementation + * \authors Tomasz Lauda + */ + #include "volume.h" #if defined(__XCC__) && XCHAL_HAVE_HIFI3 #include +/** \brief Volume scale ratio. */ #define VOL_SCALE (uint32_t)((double)INT32_MAX / VOL_MAX) +/** + * \brief HiFi3 enabled volume processing from 16 bit to 16 bit. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + */ static void vol_s16_to_s16(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -78,6 +91,12 @@ static void vol_s16_to_s16(struct comp_dev *dev, struct comp_buffer *sink, } } +/** + * \brief HiFi3 enabled volume processing from 16 bit to x bit. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + */ static void vol_s16_to_sX(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -129,6 +148,12 @@ static void vol_s16_to_sX(struct comp_dev *dev, struct comp_buffer *sink, } } +/** + * \brief HiFi3 enabled volume processing from x bit to 16 bit. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + */ static void vol_sX_to_s16(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -179,6 +204,12 @@ static void vol_sX_to_s16(struct comp_dev *dev, struct comp_buffer *sink, } } +/** + * \brief HiFi3 enabled volume processing from 24/32 bit to 24/32 or 32 bit. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + */ static void vol_s24_to_s24_s32(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { @@ -228,6 +259,12 @@ static void vol_s24_to_s24_s32(struct comp_dev *dev, struct comp_buffer *sink, } } +/** + * \brief HiFi3 enabled volume processing from 32 bit to 24/32 or 32 bit. + * \param[in,out] dev Volume base component device. + * \param[in,out] sink Destination buffer. + * \param[in,out] source Source buffer. + */ static void vol_s32_to_s24_s32(struct comp_dev *dev, struct comp_buffer *sink, struct comp_buffer *source) { diff --git a/src/drivers/hda-dma.c b/src/drivers/hda-dma.c index 974ee80d5f35..2d23576880b0 100644 --- a/src/drivers/hda-dma.c +++ b/src/drivers/hda-dma.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,9 @@ static int hda_dma_copy(struct dma *dma, int channel, int bytes) host_dma_reg_write(dma, channel, DGLLPI, bytes); host_dma_reg_write(dma, channel, DGLPIBI, bytes); + /* Force Host DMA to exit L1 */ + pm_runtime_put(PM_RUNTIME_HOST_DMA_L1); + return 0; } diff --git a/src/include/sof/Makefile.am b/src/include/sof/Makefile.am index b66745927df5..7eaba9a590b6 100644 --- a/src/include/sof/Makefile.am +++ b/src/include/sof/Makefile.am @@ -35,4 +35,5 @@ include_HEADERS = \ wait.h \ string.h \ hda-dma.h \ - work.h + work.h \ + pm_runtime.h diff --git a/src/include/sof/audio/buffer.h b/src/include/sof/audio/buffer.h index 9193a7827d0e..a8b98b6d15dc 100644 --- a/src/include/sof/audio/buffer.h +++ b/src/include/sof/audio/buffer.h @@ -164,7 +164,7 @@ static inline int comp_buffer_can_copy_bytes(struct comp_buffer *source, static inline uint32_t comp_buffer_get_copy_bytes(struct comp_buffer *source, struct comp_buffer *sink) { - if (source->avail < sink->free) + if (source->avail > sink->free) return sink->free; else return source->avail; diff --git a/src/include/sof/math/numbers.h b/src/include/sof/math/numbers.h index 5aacd8b339cc..4ba812aa3589 100644 --- a/src/include/sof/math/numbers.h +++ b/src/include/sof/math/numbers.h @@ -48,7 +48,15 @@ static inline int ceil_divide(int a, int b) int c; c = a / b; - if (c * b < a) + + /* First, we check whether the signs of the params are different. + * If they are, we already know the result is going to be negative and + * therefore, is going to be already rounded up (truncated). + * + * If the signs are the same, we check if there was any remainder in + * the division by multiplying the number back. + */ + if (!((a ^ b) & (1 << ((sizeof(int) * 8) - 1))) && c * b != a) c++; return c; diff --git a/src/include/sof/pm_runtime.h b/src/include/sof/pm_runtime.h new file mode 100644 index 000000000000..04e0fe1304df --- /dev/null +++ b/src/include/sof/pm_runtime.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +/** + * \file include/sof/pm_runtime.h + * \brief Runtime power management header file + * \author Tomasz Lauda + */ + +#ifndef __INCLUDE_PM_RUNTIME__ +#define __INCLUDE_PM_RUNTIME__ + +#include +#include + +/** \brief Power management trace function. */ +#define trace_pm(__e) trace_event_atomic(TRACE_CLASS_POWER, __e) + +/** \brief Power management trace value function. */ +#define trace_pm_value(__e) trace_value_atomic(__e) + +/** \brief Runtime power management context */ +enum pm_runtime_context { + PM_RUNTIME_HOST_DMA_L1 = 0, /**< Host DMA L1 Exit */ +}; + +/** \brief Runtime power management data. */ +struct pm_runtime_data { + spinlock_t lock; /**< lock mechanism */ + void *platform_data; /**< platform specific data */ +}; + +/** + * \brief Initializes runtime power management. + */ +void pm_runtime_init(void); + +/** + * \brief Retrieves power management resource. + * \param[in] context Type of power management context. + */ +void pm_runtime_get(enum pm_runtime_context context); + +/** + * \brief Releases power management resource. + * \param[in] context Type of power management context. + */ +void pm_runtime_put(enum pm_runtime_context context); + +#endif /* __INCLUDE_PM_RUNTIME__ */ diff --git a/src/include/sof/trace.h b/src/include/sof/trace.h index 0e339b59b81c..d72ef6880a2e 100644 --- a/src/include/sof/trace.h +++ b/src/include/sof/trace.h @@ -62,6 +62,7 @@ #define TRACE_BOOT_SYS_HEAP (TRACE_BOOT_SYS + 0x300) #define TRACE_BOOT_SYS_NOTE (TRACE_BOOT_SYS + 0x400) #define TRACE_BOOT_SYS_SCHED (TRACE_BOOT_SYS + 0x500) +#define TRACE_BOOT_SYS_POWER (TRACE_BOOT_SYS + 0x600) /* platform/device specific codes */ #define TRACE_BOOT_PLATFORM_ENTRY (TRACE_BOOT_PLATFORM + 0x100) @@ -99,6 +100,7 @@ #define TRACE_CLASS_EQ_IIR (20 << 24) #define TRACE_CLASS_SA (21 << 24) #define TRACE_CLASS_DMIC (22 << 24) +#define TRACE_CLASS_POWER (23 << 24) /* move to config.h */ #define TRACE 1 diff --git a/src/init/init.c b/src/init/init.c index 73ba3beefb63..b72fa1d4a74b 100644 --- a/src/init/init.c +++ b/src/init/init.c @@ -42,6 +42,7 @@ #include #include #include +#include #include /* main firmware context */ @@ -75,6 +76,9 @@ int main(int argc, char *argv[]) trace_point(TRACE_BOOT_SYS_SCHED); scheduler_init(&sof); + trace_point(TRACE_BOOT_SYS_POWER); + pm_runtime_init(); + /* init the platform */ err = platform_init(&sof); if (err < 0) diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 874d2fb5d1d2..31750790d43a 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -9,7 +9,8 @@ libcore_a_SOURCES = \ schedule.c \ agent.c \ interrupt.c \ - dma-trace.c + dma-trace.c \ + pm_runtime.c libcore_a_CFLAGS = \ $(ARCH_CFLAGS) \ diff --git a/src/lib/pm_runtime.c b/src/lib/pm_runtime.c new file mode 100644 index 000000000000..b165f5f03c67 --- /dev/null +++ b/src/lib/pm_runtime.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +/** + * \file lib/pm_runtime.c + * \brief Runtime power management implementation + * \author Tomasz Lauda + */ + +#include +#include +#include + +/** \brief Runtime power management data pointer. */ +static struct pm_runtime_data *prd; + +void pm_runtime_init(void) +{ + trace_pm("ini"); + + prd = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(*prd)); + spinlock_init(&prd->lock); + + platform_pm_runtime_init(prd); +} + +void pm_runtime_get(enum pm_runtime_context context) +{ + trace_pm("get"); + + switch (context) { + default: + platform_pm_runtime_get(context); + break; + } +} + +void pm_runtime_put(enum pm_runtime_context context) +{ + trace_pm("put"); + + switch (context) { + default: + platform_pm_runtime_put(context); + break; + } +} diff --git a/src/platform/Makefile.am b/src/platform/Makefile.am index 93742b067816..6a41c478b27a 100644 --- a/src/platform/Makefile.am +++ b/src/platform/Makefile.am @@ -1,23 +1,25 @@ +SUBDIRS = intel + if BUILD_BAYTRAIL -SUBDIRS = baytrail +SUBDIRS += baytrail endif if BUILD_CHERRYTRAIL -SUBDIRS = baytrail +SUBDIRS += baytrail endif if BUILD_APOLLOLAKE -SUBDIRS = apollolake +SUBDIRS += apollolake endif if BUILD_HASWELL -SUBDIRS = haswell +SUBDIRS += haswell endif if BUILD_BROADWELL -SUBDIRS = haswell +SUBDIRS += haswell endif if BUILD_CANNONLAKE -SUBDIRS = cannonlake +SUBDIRS += cannonlake endif diff --git a/src/platform/apollolake/Makefile.am b/src/platform/apollolake/Makefile.am index 417a13d03e97..1732a6d310c7 100644 --- a/src/platform/apollolake/Makefile.am +++ b/src/platform/apollolake/Makefile.am @@ -13,7 +13,8 @@ libplatform_a_SOURCES = \ clk.c \ timer.c \ interrupt.c \ - memory.c + memory.c \ + pm_runtime.c libplatform_a_CFLAGS = \ $(ARCH_CFLAGS) \ diff --git a/src/platform/apollolake/include/platform/Makefile.am b/src/platform/apollolake/include/platform/Makefile.am index 4e4e20dddbca..051a51ccf405 100644 --- a/src/platform/apollolake/include/platform/Makefile.am +++ b/src/platform/apollolake/include/platform/Makefile.am @@ -4,6 +4,8 @@ noinst_HEADERS = \ interrupt.h \ mailbox.h \ memory.h \ + platcfg.h \ platform.h \ + pm_runtime.h \ shim.h \ timer.h diff --git a/src/platform/apollolake/include/platform/platcfg.h b/src/platform/apollolake/include/platform/platcfg.h index 0875db3333fd..c0f1dfe16697 100644 --- a/src/platform/apollolake/include/platform/platcfg.h +++ b/src/platform/apollolake/include/platform/platcfg.h @@ -35,4 +35,6 @@ #define PLATFORM_DISABLE_L2CACHE_AT_BOOT 1 +#define PLATFORM_CORE_COUNT 2 + #endif diff --git a/src/platform/apollolake/include/platform/platform.h b/src/platform/apollolake/include/platform/platform.h index 1cce0c78c4ae..51e12f49dc51 100644 --- a/src/platform/apollolake/include/platform/platform.h +++ b/src/platform/apollolake/include/platform/platform.h @@ -41,8 +41,6 @@ struct sof; -#define MAX_CORE_COUNT 2 - /* Host page size */ #define HOST_PAGE_SIZE 4096 #define PLATFORM_PAGE_TABLE_SIZE 256 @@ -120,6 +118,9 @@ struct sof; /* DSP default delay in cycles */ #define PLATFORM_DEFAULT_DELAY 12 +/* minimal L1 exit time in cycles */ +#define PLATFORM_FORCE_L1_EXIT_TIME 12288 + /* Platform defined panic code */ static inline void platform_panic(uint32_t p) { diff --git a/src/platform/apollolake/include/platform/pm_runtime.h b/src/platform/apollolake/include/platform/pm_runtime.h new file mode 100644 index 000000000000..2758638e5ec2 --- /dev/null +++ b/src/platform/apollolake/include/platform/pm_runtime.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +/** + * \file platform/apollolake/include/platform/pm_runtime.h + * \brief Runtime power management header file for Apollolake + * \author Tomasz Lauda + */ + +#ifndef __INCLUDE_PLATFORM_PM_RUNTIME__ +#define __INCLUDE_PLATFORM_PM_RUNTIME__ + +#include + +/** \brief Platform specific runtime power management data. */ +struct platform_pm_runtime_data { + /* TBD */ +}; + +/** + * \brief Initializes platform specific runtime power management. + * \param[in,out] prd Runtime power management data. + */ +void platform_pm_runtime_init(struct pm_runtime_data *prd); + +/** + * \brief Retrieves platform specific power management resource. + * \param[in] context Type of power management context. + */ +void platform_pm_runtime_get(enum pm_runtime_context context); + +/** + * \brief Releases platform specific power management resource. + * \param[in] context Type of power management context. + */ +void platform_pm_runtime_put(enum pm_runtime_context context); + +#endif /* __INCLUDE_PLATFORM_PM_RUNTIME__ */ diff --git a/src/platform/apollolake/include/platform/shim.h b/src/platform/apollolake/include/platform/shim.h index 92b6cf36f83e..598f1c89973d 100644 --- a/src/platform/apollolake/include/platform/shim.h +++ b/src/platform/apollolake/include/platform/shim.h @@ -162,6 +162,9 @@ #define SHIM_L2_PREF_CFG (SHIM_BASE + 0x508) #define SHIM_L2_CACHE_PREF (SHIM_BASE + 0x510) +#define SHIM_SVCFG 0xF4 +#define SHIM_SVCFG_FORCE_L1_EXIT (0x1 << 1) + /* host windows */ #define DMWBA(x) (HOST_WIN_BASE(x) + 0x0) diff --git a/src/platform/apollolake/interrupt.c b/src/platform/apollolake/interrupt.c index 7d4d3640a504..d18373c2dff5 100644 --- a/src/platform/apollolake/interrupt.c +++ b/src/platform/apollolake/interrupt.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -122,7 +123,7 @@ static void irq_lvl2_level5_handler(void *data) } /* DSP internal interrupts */ -static struct irq_desc dsp_irq[MAX_CORE_COUNT][4] = { +static struct irq_desc dsp_irq[PLATFORM_CORE_COUNT][4] = { {{IRQ_NUM_EXT_LEVEL2, irq_lvl2_level2_handler, }, {IRQ_NUM_EXT_LEVEL3, irq_lvl2_level3_handler, }, {IRQ_NUM_EXT_LEVEL4, irq_lvl2_level4_handler, }, diff --git a/src/platform/apollolake/pm_runtime.c b/src/platform/apollolake/pm_runtime.c new file mode 100644 index 000000000000..00f902d68f50 --- /dev/null +++ b/src/platform/apollolake/pm_runtime.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +/** + * \file platform/apollolake/pm_runtime.c + * \brief Runtime power management implementation specific for Apollolake + * \author Tomasz Lauda + */ + +#include +#include +#include +#include + +/** \brief Runtime power management data pointer. */ +struct pm_runtime_data *_prd; + +void platform_pm_runtime_init(struct pm_runtime_data *prd) +{ + struct platform_pm_runtime_data *pprd; + + _prd = prd; + + pprd = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(*pprd)); + _prd->platform_data = pprd; +} + +void platform_pm_runtime_get(enum pm_runtime_context context) +{ + /* Action based on context */ +} + +void platform_pm_runtime_put(enum pm_runtime_context context) +{ + switch (context) { + case PM_RUNTIME_HOST_DMA_L1: + cavs_pm_runtime_force_host_dma_l1_exit(); + break; + } +} diff --git a/src/platform/baytrail/include/platform/Makefile.am b/src/platform/baytrail/include/platform/Makefile.am index 5775230c7907..5a6c224a6c35 100644 --- a/src/platform/baytrail/include/platform/Makefile.am +++ b/src/platform/baytrail/include/platform/Makefile.am @@ -4,8 +4,9 @@ noinst_HEADERS = \ interrupt.h \ mailbox.h \ memory.h \ + platcfg.h \ platform.h \ + pm_runtime.h \ pmc.h \ shim.h \ timer.h - diff --git a/src/platform/baytrail/include/platform/platcfg.h b/src/platform/baytrail/include/platform/platcfg.h new file mode 100644 index 000000000000..431277d70eaf --- /dev/null +++ b/src/platform/baytrail/include/platform/platcfg.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Marcin Maka + */ + +#ifndef __PLATFORM_PLATCFG_H__ +#define __PLATFORM_PLATCFG_H__ + +#define PLATFORM_CORE_COUNT 1 + +#endif diff --git a/src/platform/baytrail/include/platform/pm_runtime.h b/src/platform/baytrail/include/platform/pm_runtime.h new file mode 100644 index 000000000000..6757e3266567 --- /dev/null +++ b/src/platform/baytrail/include/platform/pm_runtime.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +/** + * \file platform/baytrail/include/platform/pm_runtime.h + * \brief Runtime power management header file for Baytrail + * \author Tomasz Lauda + */ + +#ifndef __INCLUDE_PLATFORM_PM_RUNTIME__ +#define __INCLUDE_PLATFORM_PM_RUNTIME__ + +#include + +/** + * \brief Initializes platform specific runtime power management. + * \param[in,out] prd Runtime power management data. + */ +static inline void platform_pm_runtime_init(struct pm_runtime_data *prd) { } + +/** + * \brief Retrieves platform specific power management resource. + * \param[in] context Type of power management context. + */ +static inline void platform_pm_runtime_get(enum pm_runtime_context context) { } + +/** + * \brief Releases platform specific power management resource. + * \param[in] context Type of power management context. + */ +static inline void platform_pm_runtime_put(enum pm_runtime_context context) { } + +#endif /* __INCLUDE_PLATFORM_PM_RUNTIME__ */ diff --git a/src/platform/cannonlake/Makefile.am b/src/platform/cannonlake/Makefile.am index 503271cabca7..da7b4e9aef56 100644 --- a/src/platform/cannonlake/Makefile.am +++ b/src/platform/cannonlake/Makefile.am @@ -13,7 +13,8 @@ libplatform_a_SOURCES = \ clk.c \ timer.c \ interrupt.c \ - memory.c + memory.c \ + pm_runtime.c libplatform_a_CFLAGS = \ $(ARCH_CFLAGS) \ diff --git a/src/platform/cannonlake/include/platform/Makefile.am b/src/platform/cannonlake/include/platform/Makefile.am index 4e4e20dddbca..051a51ccf405 100644 --- a/src/platform/cannonlake/include/platform/Makefile.am +++ b/src/platform/cannonlake/include/platform/Makefile.am @@ -4,6 +4,8 @@ noinst_HEADERS = \ interrupt.h \ mailbox.h \ memory.h \ + platcfg.h \ platform.h \ + pm_runtime.h \ shim.h \ timer.h diff --git a/src/platform/cannonlake/include/platform/platcfg.h b/src/platform/cannonlake/include/platform/platcfg.h index f51ee4f40f0d..cf95c29340cd 100644 --- a/src/platform/cannonlake/include/platform/platcfg.h +++ b/src/platform/cannonlake/include/platform/platcfg.h @@ -33,4 +33,6 @@ #define PLATFORM_RESET_MHE_AT_BOOT 1 +#define PLATFORM_CORE_COUNT 4 + #endif diff --git a/src/platform/cannonlake/include/platform/platform.h b/src/platform/cannonlake/include/platform/platform.h index 36e48680a451..1904bd5dc174 100644 --- a/src/platform/cannonlake/include/platform/platform.h +++ b/src/platform/cannonlake/include/platform/platform.h @@ -47,8 +47,6 @@ struct sof; #define PLATFORM_SSP_COUNT 3 #define MAX_GPDMA_COUNT 2 -#define MAX_CORE_COUNT 4 - /* Host page size */ #define HOST_PAGE_SIZE 4096 #define PLATFORM_PAGE_TABLE_SIZE 256 @@ -117,6 +115,9 @@ struct sof; /* DSP default delay in cycles */ #define PLATFORM_DEFAULT_DELAY 12 +/* minimal L1 exit time in cycles */ +#define PLATFORM_FORCE_L1_EXIT_TIME 8192 + /* Platform defined trace code */ static inline void platform_panic(uint32_t p) { diff --git a/src/platform/cannonlake/include/platform/pm_runtime.h b/src/platform/cannonlake/include/platform/pm_runtime.h new file mode 100644 index 000000000000..3cf113d39a41 --- /dev/null +++ b/src/platform/cannonlake/include/platform/pm_runtime.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +/** + * \file platform/cannonlake/include/platform/pm_runtime.h + * \brief Runtime power management header file for Cannonlake + * \author Tomasz Lauda + */ + +#ifndef __INCLUDE_PLATFORM_PM_RUNTIME__ +#define __INCLUDE_PLATFORM_PM_RUNTIME__ + +#include + +/** \brief Platform specific runtime power management data. */ +struct platform_pm_runtime_data { + /* TBD */ +}; + +/** + * \brief Initializes platform specific runtime power management. + * \param[in,out] prd Runtime power management data. + */ +void platform_pm_runtime_init(struct pm_runtime_data *prd); + +/** + * \brief Retrieves platform specific power management resource. + * \param[in] context Type of power management context. + */ +void platform_pm_runtime_get(enum pm_runtime_context context); + +/** + * \brief Releases platform specific power management resource. + * \param[in] context Type of power management context. + */ +void platform_pm_runtime_put(enum pm_runtime_context context); + +#endif /* __INCLUDE_PLATFORM_PM_RUNTIME__ */ diff --git a/src/platform/cannonlake/include/platform/shim.h b/src/platform/cannonlake/include/platform/shim.h index 82281f8de887..8615e7bdb452 100644 --- a/src/platform/cannonlake/include/platform/shim.h +++ b/src/platform/cannonlake/include/platform/shim.h @@ -191,6 +191,9 @@ #define ALHO_CSO_FLAG (1 << 1) #define ALHO_CFO_FLAG (1 << 2) +#define SHIM_SVCFG 0xF4 +#define SHIM_SVCFG_FORCE_L1_EXIT (0x1 << 1) + /* host windows */ #define DMWBA(x) (HOST_WIN_BASE(x) + 0x0) #define DMWLO(x) (HOST_WIN_BASE(x) + 0x4) diff --git a/src/platform/cannonlake/interrupt.c b/src/platform/cannonlake/interrupt.c index 949b923e29e3..6f5ef17e8a12 100644 --- a/src/platform/cannonlake/interrupt.c +++ b/src/platform/cannonlake/interrupt.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -122,7 +123,7 @@ static void irq_lvl2_level5_handler(void *data) } /* DSP internal interrupts */ -static struct irq_desc dsp_irq[MAX_CORE_COUNT][4] = { +static struct irq_desc dsp_irq[PLATFORM_CORE_COUNT][4] = { {{IRQ_NUM_EXT_LEVEL2, irq_lvl2_level2_handler, }, {IRQ_NUM_EXT_LEVEL3, irq_lvl2_level3_handler, }, {IRQ_NUM_EXT_LEVEL4, irq_lvl2_level4_handler, }, diff --git a/src/platform/cannonlake/pm_runtime.c b/src/platform/cannonlake/pm_runtime.c new file mode 100644 index 000000000000..e01c882bfcc4 --- /dev/null +++ b/src/platform/cannonlake/pm_runtime.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +/** + * \file platform/cannonlake/pm_runtime.c + * \brief Runtime power management implementation specific for Cannonlake + * \author Tomasz Lauda + */ + +#include +#include +#include +#include + +/** \brief Runtime power management data pointer. */ +struct pm_runtime_data *_prd; + +void platform_pm_runtime_init(struct pm_runtime_data *prd) +{ + struct platform_pm_runtime_data *pprd; + + _prd = prd; + + pprd = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(*pprd)); + _prd->platform_data = pprd; +} + +void platform_pm_runtime_get(enum pm_runtime_context context) +{ + /* Action based on context */ +} + +void platform_pm_runtime_put(enum pm_runtime_context context) +{ + switch (context) { + case PM_RUNTIME_HOST_DMA_L1: + cavs_pm_runtime_force_host_dma_l1_exit(); + break; + } +} diff --git a/src/platform/haswell/include/platform/Makefile.am b/src/platform/haswell/include/platform/Makefile.am index 8308e14bbaed..051a51ccf405 100644 --- a/src/platform/haswell/include/platform/Makefile.am +++ b/src/platform/haswell/include/platform/Makefile.am @@ -4,7 +4,8 @@ noinst_HEADERS = \ interrupt.h \ mailbox.h \ memory.h \ + platcfg.h \ platform.h \ + pm_runtime.h \ shim.h \ timer.h - diff --git a/src/platform/haswell/include/platform/platcfg.h b/src/platform/haswell/include/platform/platcfg.h new file mode 100644 index 000000000000..431277d70eaf --- /dev/null +++ b/src/platform/haswell/include/platform/platcfg.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Marcin Maka + */ + +#ifndef __PLATFORM_PLATCFG_H__ +#define __PLATFORM_PLATCFG_H__ + +#define PLATFORM_CORE_COUNT 1 + +#endif diff --git a/src/platform/haswell/include/platform/pm_runtime.h b/src/platform/haswell/include/platform/pm_runtime.h new file mode 100644 index 000000000000..1475838dee0f --- /dev/null +++ b/src/platform/haswell/include/platform/pm_runtime.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +/** + * \file platform/haswell/include/platform/pm_runtime.h + * \brief Runtime power management header file for Haswell + * \author Tomasz Lauda + */ + +#ifndef __INCLUDE_PLATFORM_PM_RUNTIME__ +#define __INCLUDE_PLATFORM_PM_RUNTIME__ + +#include + +/** + * \brief Initializes platform specific runtime power management. + * \param[in,out] prd Runtime power management data. + */ +static inline void platform_pm_runtime_init(struct pm_runtime_data *prd) { } + +/** + * \brief Retrieves platform specific power management resource. + * \param[in] context Type of power management context. + */ +static inline void platform_pm_runtime_get(enum pm_runtime_context context) { } + +/** + * \brief Releases platform specific power management resource. + * \param[in] context Type of power management context. + */ +static inline void platform_pm_runtime_put(enum pm_runtime_context context) { } + +#endif /* __INCLUDE_PLATFORM_PM_RUNTIME__ */ diff --git a/src/platform/intel/Makefile.am b/src/platform/intel/Makefile.am new file mode 100644 index 000000000000..7b92e00e596a --- /dev/null +++ b/src/platform/intel/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = include diff --git a/src/platform/intel/include/Makefile.am b/src/platform/intel/include/Makefile.am new file mode 100644 index 000000000000..912728c3a5d0 --- /dev/null +++ b/src/platform/intel/include/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = platform diff --git a/src/platform/intel/include/platform/Makefile.am b/src/platform/intel/include/platform/Makefile.am new file mode 100644 index 000000000000..13161e04979b --- /dev/null +++ b/src/platform/intel/include/platform/Makefile.am @@ -0,0 +1,3 @@ +if BUILD_CAVS +SUBDIRS = cavs +endif diff --git a/src/platform/intel/include/platform/cavs/Makefile.am b/src/platform/intel/include/platform/cavs/Makefile.am new file mode 100644 index 000000000000..712c19764b14 --- /dev/null +++ b/src/platform/intel/include/platform/cavs/Makefile.am @@ -0,0 +1,2 @@ +noinst_HEADERS = \ + pm_runtime.h diff --git a/src/platform/intel/include/platform/cavs/pm_runtime.h b/src/platform/intel/include/platform/cavs/pm_runtime.h new file mode 100644 index 000000000000..486c11972967 --- /dev/null +++ b/src/platform/intel/include/platform/cavs/pm_runtime.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Tomasz Lauda + */ + +/** + * \file platform/intel/platform/cavs/include/pm_runtime.h + * \brief Runtime power management header file for cAVS + * \author Tomasz Lauda + */ + +#ifndef __INCLUDE_CAVS_PM_RUNTIME__ +#define __INCLUDE_CAVS_PM_RUNTIME__ + +#include + +extern struct pm_runtime_data *_prd; + +/** + * \brief Forces Host DMAs to exit L1. + */ +static inline void cavs_pm_runtime_force_host_dma_l1_exit(void) +{ + uint32_t flags; + + spin_lock_irq(&_prd->lock, flags); + + if (!(shim_read(SHIM_SVCFG) & SHIM_SVCFG_FORCE_L1_EXIT)) { + shim_write(SHIM_SVCFG, + shim_read(SHIM_SVCFG) | SHIM_SVCFG_FORCE_L1_EXIT); + + wait_delay(PLATFORM_FORCE_L1_EXIT_TIME); + + shim_write(SHIM_SVCFG, + shim_read(SHIM_SVCFG) & ~(SHIM_SVCFG_FORCE_L1_EXIT)); + } + + spin_unlock_irq(&_prd->lock, flags); +} + +#endif /* __INCLUDE_CAVS_PM_RUNTIME__ */ diff --git a/test/cmocka/Makefile.am b/test/cmocka/Makefile.am index 565fb8082bf4..04376658d27e 100644 --- a/test/cmocka/Makefile.am +++ b/test/cmocka/Makefile.am @@ -16,11 +16,36 @@ AM_CFLAGS += -I$(CMOCKA_PREFIX)/include AM_LDFLAGS += -L$(CMOCKA_PREFIX)/lib endif +if BUILD_XTENSA +AM_CFLAGS += -I../../src/arch/xtensa/include +AM_CFLAGS += -I../../src/platform/apollolake/include +endif + +if BUILD_HOST +AM_CFLAGS += -I../../src/arch/host/include +endif + CFLAGS := $(filter-out -nostdlib,$(CFLAGS)) LDFLAGS := $(filter-out -nostdlib,$(LDFLAGS)) LDADD = -lcmocka +check_PROGRAMS += buffer_new +buffer_new_SOURCES = src/audio/buffer/buffer_new.c src/audio/buffer/mock.c +buffer_new_LDADD = ../../src/audio/libaudio.a $(LDADD) + +check_PROGRAMS += buffer_write +buffer_write_SOURCES = src/audio/buffer/buffer_write.c src/audio/buffer/mock.c +buffer_write_LDADD = ../../src/audio/libaudio.a $(LDADD) + +check_PROGRAMS += buffer_wrap +buffer_wrap_SOURCES = src/audio/buffer/buffer_wrap.c src/audio/buffer/mock.c +buffer_wrap_LDADD = ../../src/audio/libaudio.a $(LDADD) + +check_PROGRAMS += buffer_copy +buffer_copy_SOURCES = src/audio/buffer/buffer_copy.c src/audio/buffer/mock.c +buffer_copy_LDADD = ../../src/audio/libaudio.a $(LDADD) + # list tests check_PROGRAMS += list_init @@ -50,5 +75,29 @@ check_PROGRAMS += gcd gcd_SOURCES = src/math/numbers/gcd.c gcd_LDADD = ../../src/math/libsof_math.a $(LDADD) +check_PROGRAMS += ceil_divide +ceil_divide_SOURCES = src/math/numbers/ceil_divide.c +ceil_divide_LDADD = ../../src/math/libsof_math.a -lm $(LDADD) + +check_PROGRAMS += find_equal_int16 +find_equal_int16_SOURCES = src/math/numbers/find_equal_int16.c +find_equal_int16_LDADD = ../../src/math/libsof_math.a $(LDADD) + +check_PROGRAMS += find_min_int16 +find_min_int16_SOURCES = src/math/numbers/find_min_int16.c +find_min_int16_LDADD = ../../src/math/libsof_math.a $(LDADD) + +check_PROGRAMS += find_max_abs_int32 +find_max_abs_int32_SOURCES = src/math/numbers/find_max_abs_int32.c +find_max_abs_int32_LDADD = ../../src/math/libsof_math.a $(LDADD) + +check_PROGRAMS += norm_int32 +norm_int32_SOURCES = src/math/numbers/norm_int32.c +norm_int32_LDADD = ../../src/math/libsof_math.a $(LDADD) + +check_PROGRAMS += sin_fixed +sin_fixed_SOURCES = src/math/trig/sin_fixed.c +sin_fixed_LDADD = ../../src/math/libsof_math.a $(LDADD) + # all our binaries are test cases -TESTS = $(check_PROGRAMS) +TESTS = $(check_PROGRAMS) \ No newline at end of file diff --git a/test/cmocka/src/audio/buffer/buffer_copy.c b/test/cmocka/src/audio/buffer/buffer_copy.c new file mode 100644 index 000000000000..6a9dea367515 --- /dev/null +++ b/test/cmocka/src/audio/buffer/buffer_copy.c @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static void test_audio_buffer_copy_underrun(void **state) +{ + (void)state; + + struct sof_ipc_buffer test_buf_desc = { + .size = 256 + }; + + struct comp_buffer *src = buffer_new(&test_buf_desc); + struct comp_buffer *snk = buffer_new(&test_buf_desc); + + assert_non_null(src); + assert_non_null(snk); + + comp_update_buffer_produce(src, 10); + + assert_int_equal(src->avail, 10); + assert_int_equal(comp_buffer_can_copy_bytes(src, snk, 16), -1); + + buffer_free(src); + buffer_free(snk); +} + +static void test_audio_buffer_copy_overrun(void **state) +{ + (void)state; + + struct sof_ipc_buffer test_buf_desc = { + .size = 256 + }; + + struct comp_buffer *src = buffer_new(&test_buf_desc); + struct comp_buffer *snk = buffer_new(&test_buf_desc); + + assert_non_null(src); + assert_non_null(snk); + + comp_update_buffer_produce(src, 16); + comp_update_buffer_produce(snk, 246); + + assert_int_equal(src->avail, 16); + assert_int_equal(snk->free, 10); + assert_int_equal(comp_buffer_can_copy_bytes(src, snk, 16), 1); + + buffer_free(src); + buffer_free(snk); +} + +static void test_audio_buffer_copy_success(void **state) +{ + (void)state; + + struct sof_ipc_buffer test_buf_desc = { + .size = 256 + }; + + struct comp_buffer *src = buffer_new(&test_buf_desc); + struct comp_buffer *snk = buffer_new(&test_buf_desc); + + assert_non_null(src); + assert_non_null(snk); + + comp_update_buffer_produce(src, 10); + + assert_int_equal(src->avail, 10); + assert_int_equal(comp_buffer_can_copy_bytes(src, snk, 0), 0); + + buffer_free(src); + buffer_free(snk); +} + +static void test_audio_buffer_copy_fit_space_constraint(void **state) +{ + (void)state; + + struct sof_ipc_buffer test_buf_desc = { + .size = 256 + }; + + struct comp_buffer *src = buffer_new(&test_buf_desc); + struct comp_buffer *snk = buffer_new(&test_buf_desc); + + assert_non_null(src); + assert_non_null(snk); + + comp_update_buffer_produce(src, 16); + comp_update_buffer_produce(snk, 246); + + assert_int_equal(src->avail, 16); + assert_int_equal(snk->free, 10); + assert_int_equal(comp_buffer_get_copy_bytes(src, snk), 10); + + buffer_free(src); + buffer_free(snk); +} + +static void test_audio_buffer_copy_fit_no_space_constraint(void **state) +{ + (void)state; + + struct sof_ipc_buffer test_buf_desc = { + .size = 256 + }; + + struct comp_buffer *src = buffer_new(&test_buf_desc); + struct comp_buffer *snk = buffer_new(&test_buf_desc); + + assert_non_null(src); + assert_non_null(snk); + + comp_update_buffer_produce(src, 16); + + assert_int_equal(src->avail, 16); + assert_int_equal(comp_buffer_get_copy_bytes(src, snk), 16); + + buffer_free(src); + buffer_free(snk); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_audio_buffer_copy_underrun), + cmocka_unit_test(test_audio_buffer_copy_overrun), + cmocka_unit_test(test_audio_buffer_copy_success), + cmocka_unit_test(test_audio_buffer_copy_fit_space_constraint), + cmocka_unit_test(test_audio_buffer_copy_fit_no_space_constraint) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/audio/buffer/buffer_new.c b/test/cmocka/src/audio/buffer/buffer_new.c new file mode 100644 index 000000000000..4c5cb5b1d77b --- /dev/null +++ b/test/cmocka/src/audio/buffer/buffer_new.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static void test_audio_buffer_new(void **state) +{ + (void)state; + + struct sof_ipc_buffer test_buf_desc = { + .size = 256 + }; + + struct comp_buffer *buf = buffer_new(&test_buf_desc); + + assert_non_null(buf); + assert_int_equal(buf->avail, 0); + assert_int_equal(buf->free, 256); + assert_ptr_equal(buf->w_ptr, buf->r_ptr); + + buffer_free(buf); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_audio_buffer_new) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/audio/buffer/buffer_wrap.c b/test/cmocka/src/audio/buffer/buffer_wrap.c new file mode 100644 index 000000000000..aae5b030bd55 --- /dev/null +++ b/test/cmocka/src/audio/buffer/buffer_wrap.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static void test_audio_buffer_write_fill_10_bytes_and_write_5(void **state) +{ + (void)state; + + struct sof_ipc_buffer test_buf_desc = { + .size = 10 + }; + + struct comp_buffer *buf = buffer_new(&test_buf_desc); + + assert_non_null(buf); + assert_int_equal(buf->avail, 0); + assert_int_equal(buf->free, 10); + assert_ptr_equal(buf->w_ptr, buf->r_ptr); + + uint8_t bytes[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + memcpy(buf->w_ptr, &bytes, 10); + comp_update_buffer_produce(buf, 10); + + assert_int_equal(buf->avail, 10); + assert_int_equal(buf->free, 0); + assert_ptr_equal(buf->w_ptr, buf->r_ptr); + + uint8_t more_bytes[5] = {10, 11, 12, 13, 14}; + + memcpy(buf->w_ptr, &more_bytes, 5); + comp_update_buffer_produce(buf, 5); + + uint8_t ref[10] = {10, 11, 12, 13, 14, 5, 6, 7, 8, 9}; + + assert_int_equal(buf->avail, 5); + assert_int_equal(buf->free, 5); + assert_ptr_equal(buf->w_ptr, buf->r_ptr + 5); + assert_int_equal(memcmp(buf->r_ptr, &ref, 10), 0); + + buffer_free(buf); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test + (test_audio_buffer_write_fill_10_bytes_and_write_5) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/audio/buffer/buffer_write.c b/test/cmocka/src/audio/buffer/buffer_write.c new file mode 100644 index 000000000000..47e45c7e1ed8 --- /dev/null +++ b/test/cmocka/src/audio/buffer/buffer_write.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static void test_audio_buffer_write_10_bytes_out_of_256_and_read_back + (void **state) +{ + (void)state; + + struct sof_ipc_buffer test_buf_desc = { + .size = 256 + }; + + struct comp_buffer *buf = buffer_new(&test_buf_desc); + + assert_non_null(buf); + assert_int_equal(buf->avail, 0); + assert_int_equal(buf->free, 256); + assert_ptr_equal(buf->w_ptr, buf->r_ptr); + + uint8_t bytes[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + memcpy(buf->w_ptr, &bytes, 10); + comp_update_buffer_produce(buf, 10); + + assert_int_equal(buf->avail, 10); + assert_int_equal(buf->free, 246); + assert_ptr_equal(buf->w_ptr, buf->r_ptr + 10); + + assert_int_equal(memcmp(buf->r_ptr, &bytes, 10), 0); + + comp_update_buffer_consume(buf, 10); + + assert_int_equal(buf->avail, 0); + assert_int_equal(buf->free, 256); + assert_ptr_equal(buf->w_ptr, buf->r_ptr); + + buffer_free(buf); +} + +static void test_audio_buffer_fill_10_bytes(void **state) +{ + (void)state; + + struct sof_ipc_buffer test_buf_desc = { + .size = 10 + }; + + struct comp_buffer *buf = buffer_new(&test_buf_desc); + + assert_non_null(buf); + assert_int_equal(buf->avail, 0); + assert_int_equal(buf->free, 10); + assert_ptr_equal(buf->w_ptr, buf->r_ptr); + + uint8_t bytes[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + memcpy(buf->w_ptr, &bytes, 10); + comp_update_buffer_produce(buf, 10); + + assert_int_equal(buf->avail, 10); + assert_int_equal(buf->free, 0); + assert_ptr_equal(buf->w_ptr, buf->r_ptr); + + buffer_free(buf); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test + (test_audio_buffer_write_10_bytes_out_of_256_and_read_back), + cmocka_unit_test(test_audio_buffer_fill_10_bytes) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/audio/buffer/mock.c b/test/cmocka/src/audio/buffer/mock.c new file mode 100644 index 000000000000..e35d34e2f1e8 --- /dev/null +++ b/test/cmocka/src/audio/buffer/mock.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include +#include + +void _trace_event(uint32_t e) +{ + (void)e; +} + +void _trace_event_mbox_atomic(uint32_t e) +{ + (void)e; +} + +void *rzalloc(int zone, uint32_t caps, size_t bytes) +{ + (void)zone; + (void)caps; + + return malloc(bytes); +} + +void *rballoc(int zone, uint32_t caps, size_t bytes) +{ + (void)zone; + (void)caps; + + return malloc(bytes); +} + +void rfree(void *ptr) +{ + free(ptr); +} diff --git a/test/cmocka/src/math/numbers/ceil_divide.c b/test/cmocka/src/math/numbers/ceil_divide.c new file mode 100644 index 000000000000..f20514e6e425 --- /dev/null +++ b/test/cmocka/src/math/numbers/ceil_divide.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include + +#include +#include +#include +#include +#include +#include + +static void test_math_numbers_ceil_divide(void **state) +{ + (void)state; + + int params[8] = { + -1000, + 300, + 123, + -10, + 1337, + -6, + 999, + -2 + }; + + int i, j; + + for (i = 0; i < 8; ++i) { + for (j = 0; j < 8; ++j) { + int ref = ceilf((float)params[i] / (float)params[j]); + int r = ceil_divide(params[i], params[j]); + + if (r != ref) { + printf("%s: %d / %d = %d (ref: %d)\n", __func__, + params[i], params[j], r, ref); + } + + assert_int_equal(r, ref); + } + } + +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_math_numbers_ceil_divide) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/numbers/find_equal_int16.c b/test/cmocka/src/math/numbers/find_equal_int16.c new file mode 100644 index 000000000000..84e06de43f10 --- /dev/null +++ b/test/cmocka/src/math/numbers/find_equal_int16.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include + +#include +#include +#include +#include + +static void test_math_numbers_find_equal_int16_for_5_123_5_10_123_500_123_n_123_equals_1_4_and_6 + (void **state) +{ + (void)state; + + int16_t r[4]; + int16_t vec[] = {5, 123, 5, 10, 123, 500, 123}; + int16_t template[] = {1, 4, 6}; + + int r_num = find_equal_int16(r, vec, 123, 7, 4); + + assert_int_equal(r_num, 3); + assert_memory_equal(r, template, sizeof(int16_t) * 3); +} + +static void test_math_numbers_find_equal_int16_for_1_2_3_4_5_n_0_equals_nothing + (void **state) +{ + (void)state; + + int16_t r[4]; + int16_t vec[] = {1, 2, 3, 4, 5}; + + int r_num = find_equal_int16(r, vec, 0, 5, 4); + + assert_int_equal(r_num, 0); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test + (test_math_numbers_find_equal_int16_for_5_123_5_10_123_500_123_n_123_equals_1_4_and_6), + cmocka_unit_test + (test_math_numbers_find_equal_int16_for_1_2_3_4_5_n_0_equals_nothing) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/numbers/find_max_abs_int32.c b/test/cmocka/src/math/numbers/find_max_abs_int32.c new file mode 100644 index 000000000000..1a882634e0d8 --- /dev/null +++ b/test/cmocka/src/math/numbers/find_max_abs_int32.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include + +#include +#include +#include +#include + +static void test_math_numbers_find_max_abs_int32_for_neg100_99_98_50_equals_100 + (void **state) +{ + (void)state; + + int32_t vec[] = {-100, 99, 98, 50}; + int r = find_max_abs_int32(vec, sizeof(vec) / sizeof(int32_t)); + + assert_int_equal(r, 100); +} + +static void test_math_numbers_find_max_abs_int32_for_neg100_99_98_50_101_equals_101 + (void **state) +{ + (void)state; + + int32_t vec[] = {-100, 99, 98, 50, 101}; + int r = find_max_abs_int32(vec, sizeof(vec) / sizeof(int32_t)); + + assert_int_equal(r, 101); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test + (test_math_numbers_find_max_abs_int32_for_neg100_99_98_50_equals_100), + cmocka_unit_test + (test_math_numbers_find_max_abs_int32_for_neg100_99_98_50_101_equals_101) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/numbers/find_min_int16.c b/test/cmocka/src/math/numbers/find_min_int16.c new file mode 100644 index 000000000000..744ed12d3998 --- /dev/null +++ b/test/cmocka/src/math/numbers/find_min_int16.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include + +#include +#include +#include +#include + +static void test_math_numbers_find_min_int16_for_2_equals_2(void **state) +{ + (void)state; + + int16_t vec[] = {2}; + int r = find_min_int16(vec, sizeof(vec) / sizeof(int16_t)); + + assert_int_equal(r, 2); +} + +static void test_math_numbers_find_min_int16_for_5_2_3_4_1_equals_1 + (void **state) +{ + (void)state; + + int16_t vec[] = {5, 2, 3, 4, 1}; + int r = find_min_int16(vec, sizeof(vec) / sizeof(int16_t)); + + assert_int_equal(r, 1); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test + (test_math_numbers_find_min_int16_for_2_equals_2), + cmocka_unit_test + (test_math_numbers_find_min_int16_for_5_2_3_4_1_equals_1) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/numbers/gcd.c b/test/cmocka/src/math/numbers/gcd.c index 7a8329e4b137..dab9fa32881c 100644 --- a/test/cmocka/src/math/numbers/gcd.c +++ b/test/cmocka/src/math/numbers/gcd.c @@ -59,7 +59,8 @@ static void test_math_numbers_gcd_for_12_and_9_equals_3(void **state) int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(test_math_numbers_gcd_for_5083_and_391_equals_391), + cmocka_unit_test + (test_math_numbers_gcd_for_5083_and_391_equals_391), cmocka_unit_test(test_math_numbers_gcd_for_12_and_9_equals_3), }; diff --git a/test/cmocka/src/math/numbers/norm_int32.c b/test/cmocka/src/math/numbers/norm_int32.c new file mode 100644 index 000000000000..5ffe33ecf0dc --- /dev/null +++ b/test/cmocka/src/math/numbers/norm_int32.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include + +#include +#include +#include +#include + +static void test_math_numbers_norm_int32_for_0_equals_31(void **state) +{ + (void)state; + + int r = norm_int32(0); + + assert_int_equal(r, 31); +} + +static void test_math_numbers_norm_int32_for_35_equals_10(void **state) +{ + (void)state; + + int r = norm_int32(35); + + assert_int_equal(r, 25); +} + +static void test_math_numbers_norm_int32_for_2147483647_equals_0(void **state) +{ + (void)state; + + int r = norm_int32(2147483647); + + assert_int_equal(r, 0); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_math_numbers_norm_int32_for_0_equals_31), + cmocka_unit_test + (test_math_numbers_norm_int32_for_35_equals_10), + cmocka_unit_test + (test_math_numbers_norm_int32_for_2147483647_equals_0) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/trig/sin_fixed.c b/test/cmocka/src/math/trig/sin_fixed.c new file mode 100644 index 000000000000..de0bd41005c0 --- /dev/null +++ b/test/cmocka/src/math/trig/sin_fixed.c @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define CMP_TOLERANCE 0.000005 + +/* Reference table generated by sin(), gcc-4.3.2 */ +static const float sin_ref_table[] = { + 0.0000000000, 0.0174524064, 0.0348994967, 0.0523359562, + 0.0697564737, 0.0871557427, 0.1045284633, 0.1218693434, + 0.1391731010, 0.1564344650, 0.1736481777, 0.1908089954, + 0.2079116908, 0.2249510543, 0.2419218956, 0.2588190451, + 0.2756373558, 0.2923717047, 0.3090169944, 0.3255681545, + 0.3420201433, 0.3583679495, 0.3746065934, 0.3907311285, + 0.4067366431, 0.4226182617, 0.4383711468, 0.4539904997, + 0.4694715628, 0.4848096202, 0.5000000000, 0.5150380749, + 0.5299192642, 0.5446390350, 0.5591929035, 0.5735764364, + 0.5877852523, 0.6018150232, 0.6156614753, 0.6293203910, + 0.6427876097, 0.6560590290, 0.6691306064, 0.6819983601, + 0.6946583705, 0.7071067812, 0.7193398003, 0.7313537016, + 0.7431448255, 0.7547095802, 0.7660444431, 0.7771459615, + 0.7880107536, 0.7986355100, 0.8090169944, 0.8191520443, + 0.8290375726, 0.8386705679, 0.8480480962, 0.8571673007, + 0.8660254038, 0.8746197071, 0.8829475929, 0.8910065242, + 0.8987940463, 0.9063077870, 0.9135454576, 0.9205048535, + 0.9271838546, 0.9335804265, 0.9396926208, 0.9455185756, + 0.9510565163, 0.9563047560, 0.9612616959, 0.9659258263, + 0.9702957263, 0.9743700648, 0.9781476007, 0.9816271834, + 0.9848077530, 0.9876883406, 0.9902680687, 0.9925461516, + 0.9945218954, 0.9961946981, 0.9975640503, 0.9986295348, + 0.9993908270, 0.9998476952, 1.0000000000, 0.9998476952, + 0.9993908270, 0.9986295348, 0.9975640503, 0.9961946981, + 0.9945218954, 0.9925461516, 0.9902680687, 0.9876883406, + 0.9848077530, 0.9816271834, 0.9781476007, 0.9743700648, + 0.9702957263, 0.9659258263, 0.9612616959, 0.9563047560, + 0.9510565163, 0.9455185756, 0.9396926208, 0.9335804265, + 0.9271838546, 0.9205048535, 0.9135454576, 0.9063077870, + 0.8987940463, 0.8910065242, 0.8829475929, 0.8746197071, + 0.8660254038, 0.8571673007, 0.8480480962, 0.8386705679, + 0.8290375726, 0.8191520443, 0.8090169944, 0.7986355100, + 0.7880107536, 0.7771459615, 0.7660444431, 0.7547095802, + 0.7431448255, 0.7313537016, 0.7193398003, 0.7071067812, + 0.6946583705, 0.6819983601, 0.6691306064, 0.6560590290, + 0.6427876097, 0.6293203910, 0.6156614753, 0.6018150232, + 0.5877852523, 0.5735764364, 0.5591929035, 0.5446390350, + 0.5299192642, 0.5150380749, 0.5000000000, 0.4848096202, + 0.4694715628, 0.4539904997, 0.4383711468, 0.4226182617, + 0.4067366431, 0.3907311285, 0.3746065934, 0.3583679495, + 0.3420201433, 0.3255681545, 0.3090169944, 0.2923717047, + 0.2756373558, 0.2588190451, 0.2419218956, 0.2249510543, + 0.2079116908, 0.1908089954, 0.1736481777, 0.1564344650, + 0.1391731010, 0.1218693434, 0.1045284633, 0.0871557427, + 0.0697564737, 0.0523359562, 0.0348994967, 0.0174524064, + 0.0000000000, -0.0174524064, -0.0348994967, -0.0523359562, + -0.0697564737, -0.0871557427, -0.1045284633, -0.1218693434, + -0.1391731010, -0.1564344650, -0.1736481777, -0.1908089954, + -0.2079116908, -0.2249510543, -0.2419218956, -0.2588190451, + -0.2756373558, -0.2923717047, -0.3090169944, -0.3255681545, + -0.3420201433, -0.3583679495, -0.3746065934, -0.3907311285, + -0.4067366431, -0.4226182617, -0.4383711468, -0.4539904997, + -0.4694715628, -0.4848096202, -0.5000000000, -0.5150380749, + -0.5299192642, -0.5446390350, -0.5591929035, -0.5735764364, + -0.5877852523, -0.6018150232, -0.6156614753, -0.6293203910, + -0.6427876097, -0.6560590290, -0.6691306064, -0.6819983601, + -0.6946583705, -0.7071067812, -0.7193398003, -0.7313537016, + -0.7431448255, -0.7547095802, -0.7660444431, -0.7771459615, + -0.7880107536, -0.7986355100, -0.8090169944, -0.8191520443, + -0.8290375726, -0.8386705679, -0.8480480962, -0.8571673007, + -0.8660254038, -0.8746197071, -0.8829475929, -0.8910065242, + -0.8987940463, -0.9063077870, -0.9135454576, -0.9205048535, + -0.9271838546, -0.9335804265, -0.9396926208, -0.9455185756, + -0.9510565163, -0.9563047560, -0.9612616959, -0.9659258263, + -0.9702957263, -0.9743700648, -0.9781476007, -0.9816271834, + -0.9848077530, -0.9876883406, -0.9902680687, -0.9925461516, + -0.9945218954, -0.9961946981, -0.9975640503, -0.9986295348, + -0.9993908270, -0.9998476952, -1.0000000000, -0.9998476952, + -0.9993908270, -0.9986295348, -0.9975640503, -0.9961946981, + -0.9945218954, -0.9925461516, -0.9902680687, -0.9876883406, + -0.9848077530, -0.9816271834, -0.9781476007, -0.9743700648, + -0.9702957263, -0.9659258263, -0.9612616959, -0.9563047560, + -0.9510565163, -0.9455185756, -0.9396926208, -0.9335804265, + -0.9271838546, -0.9205048535, -0.9135454576, -0.9063077870, + -0.8987940463, -0.8910065242, -0.8829475929, -0.8746197071, + -0.8660254038, -0.8571673007, -0.8480480962, -0.8386705679, + -0.8290375726, -0.8191520443, -0.8090169944, -0.7986355100, + -0.7880107536, -0.7771459615, -0.7660444431, -0.7547095802, + -0.7431448255, -0.7313537016, -0.7193398003, -0.7071067812, + -0.6946583705, -0.6819983601, -0.6691306064, -0.6560590290, + -0.6427876097, -0.6293203910, -0.6156614753, -0.6018150232, + -0.5877852523, -0.5735764364, -0.5591929035, -0.5446390350, + -0.5299192642, -0.5150380749, -0.5000000000, -0.4848096202, + -0.4694715628, -0.4539904997, -0.4383711468, -0.4226182617, + -0.4067366431, -0.3907311285, -0.3746065934, -0.3583679495, + -0.3420201433, -0.3255681545, -0.3090169944, -0.2923717047, + -0.2756373558, -0.2588190451, -0.2419218956, -0.2249510543, + -0.2079116908, -0.1908089954, -0.1736481777, -0.1564344650, + -0.1391731010, -0.1218693434, -0.1045284633, -0.0871557427, + -0.0697564737, -0.0523359562, -0.0348994967, -0.0174524064 +}; + +static void test_math_trig_sin_fixed(void **state) +{ + (void)state; + + int theta; + + for (theta = 0; theta < 360; ++theta) { + double rad = M_PI / (180.0 / theta); + int32_t rad_q28 = Q_CONVERT_FLOAT(rad, 28); + + float r = Q_CONVERT_QTOF(sin_fixed(rad_q28), 31); + float diff = fabsf(sin_ref_table[theta] - r); + + if (diff > CMP_TOLERANCE) { + printf("%s: diff for %d deg = %.10f\n", __func__, + theta, diff); + } + + assert_true(diff <= CMP_TOLERANCE); + } +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_math_trig_sin_fixed) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +}