diff options
-rw-r--r-- | Android.mk | 35 | ||||
-rw-r--r-- | adnc_strm.c | 12 | ||||
-rw-r--r-- | cvq_ioctl.h | 110 | ||||
-rw-r--r-- | cvq_util.c | 1137 | ||||
-rw-r--r-- | iaxxx-debug-intf.h | 159 | ||||
-rw-r--r-- | iaxxx-odsp.h | 68 | ||||
-rw-r--r-- | iaxxx-sysid-defs.h | 117 | ||||
-rw-r--r-- | iaxxx-system-identifiers.h | 23 | ||||
-rw-r--r-- | iaxxx-systemids.h | 39 | ||||
-rw-r--r-- | iaxxx-tunnel-intf.h | 1 | ||||
-rw-r--r-- | iaxxx_odsp_hw.c | 535 | ||||
-rw-r--r-- | iaxxx_odsp_hw.h | 174 | ||||
-rw-r--r-- | sound_trigger_hw_iaxxx.c | 800 | ||||
-rwxr-xr-x | tests/crash_event_logger.c | 270 | ||||
-rwxr-xr-x | tests/dump_debug_info.c | 496 | ||||
-rw-r--r-- | tests/odsp_api_test.c | 125 | ||||
-rw-r--r-- | tests/oslo_package_test.c | 4 | ||||
-rwxr-xr-x | tests/setparamblk_test.c | 283 | ||||
-rw-r--r-- | tests/tunnel_test_sensor.c | 1 | ||||
-rw-r--r-- | tunnel.c | 19 | ||||
-rw-r--r-- | tunnel.h | 10 |
21 files changed, 3769 insertions, 649 deletions
@@ -168,4 +168,37 @@ LOCAL_SHARED_LIBRARIES := liblog \ libodsp include $(BUILD_EXECUTABLE) -endif + +include $(CLEAR_VARS) + +LOCAL_PRELINK_MODULE := false +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE := dump_debug_info +LOCAL_SRC_FILES := tests/dump_debug_info.c +LOCAL_32_BIT_ONLY := true +LOCAL_SHARED_LIBRARIES := liblog + +include $(BUILD_EXECUTABLE) + +include $(CLEAR_VARS) + +LOCAL_PRELINK_MODULE := false +LOCAL_MODULE := crash_event_logger +LOCAL_SRC_FILES := tests/crash_event_logger.c +LOCAL_32_BIT_ONLY := true +LOCAL_SHARED_LIBRARIES := liblog libcutils + +include $(BUILD_EXECUTABLE) + +include $(CLEAR_VARS) +LOCAL_PRELINK_MODULE := false +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE := setparamblk_test +LOCAL_SRC_FILES := tests/setparamblk_test.c +LOCAL_32_BIT_ONLY := true +LOCAL_SHARED_LIBRARIES := libcutils \ + libodsp + +include $(BUILD_EXECUTABLE) + +endif
\ No newline at end of file diff --git a/adnc_strm.c b/adnc_strm.c index 2d364d1..728463c 100644 --- a/adnc_strm.c +++ b/adnc_strm.c @@ -26,15 +26,14 @@ //#define LOG_NDEBUG 0 //#define LOG_NDDEBUG 0 -#include <cutils/log.h> +#include <log/log.h> #include "iaxxx-system-identifiers.h" #include "adnc_strm.h" #include "tunnel.h" #define MAX_TUNNELS (32) #define BUF_SIZE (8192) -#define CVQ_ENDPOINT (IAXXX_SYSID_PLUGIN_1_OUT_EP_0) -#define AMBIENT_ENDPOINT (IAXXX_SYSID_PLUGIN_4_OUT_EP_0) + #define CVQ_TUNNEL_ID (1) #define TNL_Q15 (0xF) @@ -403,7 +402,7 @@ exit: __attribute__ ((visibility ("default"))) long adnc_strm_open(bool enable_stripping, unsigned int kw_start_frame, - int keyword_model_type) + int stream_end_point) { int ret = 0, err; struct adnc_strm_device *adnc_strm_dev = NULL; @@ -416,10 +415,7 @@ long adnc_strm_open(bool enable_stripping, goto exit_on_error; } - if (keyword_model_type == HOTWORD_MODEL) - adnc_strm_dev->end_point = CVQ_ENDPOINT; - else - adnc_strm_dev->end_point = AMBIENT_ENDPOINT; + adnc_strm_dev->end_point = stream_end_point; adnc_strm_dev->idx = 0; adnc_strm_dev->mode = 0; adnc_strm_dev->encode = TNL_Q15; diff --git a/cvq_ioctl.h b/cvq_ioctl.h index 265adbf..a4a0e3c 100644 --- a/cvq_ioctl.h +++ b/cvq_ioctl.h @@ -26,21 +26,23 @@ #define ENTITY_MASK 0x4 #define PLUGIN1_MASK (HOTWORD_MASK) #define PLUGIN2_MASK (AMBIENT_MASK | ENTITY_MASK) +#define CHRE_MASK 0x8 +#define OSLO_MASK 0x10 #define HOTWORD_EVT_SRC_ID IAXXX_SYSID_PLUGIN_INSTANCE_0 #define OSLO_EVT_SRC_ID IAXXX_SYSID_PLUGIN_INSTANCE_3 #define CHRE_EVT_SRC_ID IAXXX_SYSID_PLUGIN_INSTANCE_6 -#define AMBIENT_ENTITY_EVT_SRC_ID IAXXX_SYSID_PLUGIN_INSTANCE_5 +#define AMBIENT_EVT_SRC_ID IAXXX_SYSID_PLUGIN_INSTANCE_5 #define HOTWORD_PKG_ID 11 #define HOTWORD_PLUGIN_IDX 0 #define HOTWORD_INSTANCE_ID 0 #define HOTWORD_PRIORITY 1 -#define AMBIENT_ENTITY_PKG_ID 12 -#define AMBIENT_ENTITY_PLUGIN_IDX 0 -#define AMBIENT_ENTITY_INSTANCE_ID 5 -#define AMBIENT_ENTITY_PRIORITY 1 +#define AMBIENT_PKG_ID 12 +#define AMBIENT_PLUGIN_IDX 0 +#define AMBIENT_INSTANCE_ID 5 +#define AMBIENT_PRIORITY 1 #define SENSOR_PKG_ID 0 #define SENSOR_PLUGIN_IDX 0 @@ -49,10 +51,12 @@ #define SENSOR_PRESENCE_MODE 0 #define SENSOR_DETECTED_MODE 1 #define SENSOR_MAX_MODE 2 +#define OSLO_CONFIGURED (0x201) +#define OSLO_DESTROYED (0x202) +#define OSLO_BUF_INSTANCE_ID 2 #define AEC_PKG_ID 7 #define AEC_PLUGIN_IDX 0 -#define AEC_BLOCK_ID 1 #define AEC_INSTANCE_ID 7 #define AEC_PRIORITY 1 @@ -60,15 +64,21 @@ #define CHRE_INSTANCE_ID 6 #define CHRE_EVT_ID 3 #define CHRE_EVT_PARAM_ID 8 +#define CHRE_BUF_SIZE 60480 +#define CHRE_CONFIGURED (0x203) +#define CHRE_DESTROYED (0x204) +#define CHRE_EVT_MASK 7 -#define BUF_PACKAGE_ID 4 +#define MIXER_PKG_ID 5 +#define MIXER_PLUGIN_IDX 0 +#define MIXER_INSTANCE_ID 10 +#define MIXER_PRIORITY 1 + +#define BUF_PKG_ID 4 #define BUF_PLUGIN_IDX 0 +#define BUF_INSTANCE_ID 1 #define BUF_PRIORITY 1 -#define HOTWORD_BUF_INSTANCE_ID 1 -#define OSLO_BUF_INSTANCE_ID 2 -#define AMBIENT_BUF_INSTANCE_ID 4 - #define HOTWORD_DETECTION 0 #define AMBIENT_DETECTION 1 #define ENTITY_DETECTION 2 @@ -77,15 +87,10 @@ #define AMBIENT_SLOT_ID 3 #define ENTITY_SLOT_ID 5 -#define HOTWORD_UNLOAD_PARAM_ID 1 -#define AMBIENT_ENTITY_UNLOAD_PARAM_ID 1 -#define AMBIENT_ENTITY_RESET_PARAM_ID 2 -#define AMBIENT_ENTITY_GET_MODEL_STATE_PARAM_ID 7 - -#define HOTWORD_UNLOAD_PARAM_VAL 1 -#define AMBIENT_UNLOAD_PARAM_VAL 3 -#define ENTITY_UNLOAD_PARAM_VAL 5 -#define AMBIENT_ENTITY_RESET_PARAM_VAL 3 +#define HOTWORD_UNLOAD_PARAM_ID 1 +#define AMBIENT_UNLOAD_PARAM_ID 1 +#define AMBIENT_RESET_PARAM_ID 2 +#define AMBIENT_GET_MODEL_STATE_PARAM_ID 7 #define BUFFER_PACKAGE "BufferPackage.bin" #define BUFFER_CONFIG_VAL "BufferConfigVal.bin" @@ -97,18 +102,30 @@ #define SENSOR_PACKAGE "OsloSensorPackage.bin" #define SENSOR_CONFIG_VAL "OsloSensorConfig.bin" #define AEC_PASSTHROUGH_PACKAGE "PassthruPackage.bin" +#define MIXER_PACKAGE "AScalarSimpleMixerPackage.bin" #define MIC_ROUTE "mic1-route" +#define MIC_ROUTE_EXT_CLK "mic-route-external-clock" +#define MIC_ROUTE_INT_CLK "mic-route-internal-clock" #define BARGEIN_ROUTE "bargein-route" +#define DOWNLINK_AUDIO_ROUTE "downlink-audio-route" #define SENSOR_ROTUE "oslo-route" #define HOTWORD_WITH_BARGEIN_ROUTE "hotword-route-with-bargein" #define HOTWORD_WITHOUT_BARGEIN_ROUTE "hotword-route-without-bargein" #define CHRE_WITH_BARGEIN_ROUTE "chre-route-with-bargein" #define CHRE_WITHOUT_BARGEIN_ROUTE "chre-route-without-bargein" -#define AMBIENT_ENTITY_WITH_BARGEIN_ROUTE "ambient-entity-route-with-bargein" -#define AMBIENT_ENTITY_WITHOUT_BARGEIN_ROUTE "ambient-entity-route-without-bargein" +#define AMBIENT_WITH_BARGEIN_ROUTE "ambient-route-with-bargein" +#define AMBIENT_WITHOUT_BARGEIN_ROUTE "ambient-route-without-bargein" +#define BUFFER_WITH_BARGEIN_ROUTE "buffer-route-with-bargein" +#define BUFFER_WITHOUT_BARGEIN_ROUTE "buffer-route-without-bargein" + +enum clock_type { + INTERNAL_OSCILLATOR, + EXTERNAL_OSCILLATOR +}; + +#define PLUGIN_DEF_CONFIG_ID 0 -int force_set_sensor_route(bool enable); int write_model(struct iaxxx_odsp_hw *odsp_hdl, unsigned char *data, int length, int kw_type); int get_model_state(struct iaxxx_odsp_hw *odsp_hdl, const uint32_t inst_id, @@ -116,23 +133,44 @@ int get_model_state(struct iaxxx_odsp_hw *odsp_hdl, const uint32_t inst_id, int get_event(struct iaxxx_odsp_hw *odsp_hdl, struct iaxxx_get_event_info *ge); int setup_chip(struct iaxxx_odsp_hw *odsp_hdl); -int enable_mic_route(struct audio_route *route_hdl, int enable); +int setup_buffer_package(struct iaxxx_odsp_hw *odsp_hdl); +int destroy_buffer_package(struct iaxxx_odsp_hw *odsp_hdl); +int setup_hotword_package(struct iaxxx_odsp_hw *odsp_hdl); +int destroy_hotword_package(struct iaxxx_odsp_hw *odsp_hdl); +int setup_ambient_package(struct iaxxx_odsp_hw *odsp_hdl); +int destroy_ambient_package(struct iaxxx_odsp_hw *odsp_hdl); +int setup_aec_package(struct iaxxx_odsp_hw *odsp_hdl); +int destroy_aec_package(struct iaxxx_odsp_hw *odsp_hdl); +int setup_chre_package(struct iaxxx_odsp_hw *odsp_hdl); +int destroy_chre_package(struct iaxxx_odsp_hw *odsp_hdl); +int setup_sensor_package(struct iaxxx_odsp_hw *odsp_hdl); +int destroy_sensor_package(struct iaxxx_odsp_hw *odsp_hdl); +int setup_mixer_package(struct iaxxx_odsp_hw *odsp_hdl); +int destroy_mixer_package(struct iaxxx_odsp_hw *odsp_hdl); + +int setup_mic_buffer(struct iaxxx_odsp_hw *odsp_hdl); +int destroy_mic_buffer(struct iaxxx_odsp_hw *odsp_hdl); +int set_buffer_route(struct audio_route *route_hdl, bool bargein); +int tear_buffer_route(struct audio_route *route_hdl, bool bargein); +int enable_mic_route(struct audio_route *route_hdl, bool enable, + enum clock_type ct); int set_sensor_route(struct audio_route *route_hdl, bool enable); -int set_ambient_entity_state(struct iaxxx_odsp_hw *odsp_hdl, - unsigned int current); -int tear_ambient_entity_state(struct iaxxx_odsp_hw *odsp_hdl, - unsigned int current); -int set_ambient_entity_route(struct audio_route *route_hdl, bool bargein); -int tear_ambient_entity_route(struct audio_route *route_hdl, bool bargein); -int set_hotword_route(struct iaxxx_odsp_hw *odsp_hdl, - struct audio_route *route_hdl, bool bargein); -int tear_hotword_route(struct iaxxx_odsp_hw *odsp_hdl, - struct audio_route *route_hdl, bool bargein); +int set_ambient_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current); +int tear_ambient_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current); +int set_ambient_route(struct audio_route *route_hdl, bool bargein); +int tear_ambient_route(struct audio_route *route_hdl, bool bargein); +int set_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current); +int tear_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current); +int set_hotword_route(struct audio_route *route_hdl, bool bargein); +int tear_hotword_route(struct audio_route *route_hdl, bool bargein); int set_chre_audio_route(struct audio_route *route_hdl, bool bargein); int tear_chre_audio_route(struct audio_route *route_hdl, bool bargein); int reset_ambient_plugin(struct iaxxx_odsp_hw *odsp_hdl); int enable_bargein_route(struct audio_route *route_hdl, bool enable); +int enable_downlink_audio_route(struct audio_route *route_hdl, bool enable); + int flush_model(struct iaxxx_odsp_hw *odsp_hdl, int kw_type); int get_entity_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload, unsigned int payload_size); - -#endif /* _CVQ_IOCTL_H */
\ No newline at end of file +int setup_mpll_clock_source(struct iaxxx_odsp_hw *odsp_hdl, + const int clk_source, const uint32_t clk_value); +#endif /* _CVQ_IOCTL_H */ @@ -24,7 +24,7 @@ #include <string.h> #include <signal.h> #include <sys/stat.h> -#include <cutils/log.h> +#include <log/log.h> #include <errno.h> #include <linux/errno.h> @@ -41,14 +41,6 @@ int write_model(struct iaxxx_odsp_hw *odsp_hdl, unsigned char *data, { case 0: //HOTWORD ALOGV("+%s+ OK_GOOGLE_KW_ID", __func__); - err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, - HOTWORD_INSTANCE_ID, 0, - 0, IAXXX_HMD_BLOCK_ID); - if (err < 0) { - ALOGE("%s: Failed to set hotword plgin reset param %s\n", - __func__, strerror(errno)); - goto exit; - } err = iaxxx_odsp_plugin_set_parameter_blk(odsp_hdl, HOTWORD_INSTANCE_ID, HOTWORD_SLOT_ID, @@ -56,46 +48,32 @@ int write_model(struct iaxxx_odsp_hw *odsp_hdl, unsigned char *data, break; case 1: //AMBIENT ALOGV("+%s+ AMBIENT_KW_ID", __func__); - err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, 0, - 0, IAXXX_HMD_BLOCK_ID); - if (err < 0) { - ALOGE("%s: Failed to set ambient plgin reset param %s\n", - __func__, strerror(errno)); - goto exit; - } err = iaxxx_odsp_plugin_set_parameter_blk(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, AMBIENT_SLOT_ID, + AMBIENT_INSTANCE_ID, AMBIENT_SLOT_ID, IAXXX_HMD_BLOCK_ID, data, length); break; case 2: //ENTITY ALOGV("+%s+ Entity_KW_ID", __func__); - err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, 0, - 0, IAXXX_HMD_BLOCK_ID); - if (err < 0) { - ALOGE("%s: Failed to set entity plgin reset param %s\n", - __func__, strerror(errno)); - goto exit; - } + err = iaxxx_odsp_plugin_set_parameter_blk(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, ENTITY_SLOT_ID, + AMBIENT_INSTANCE_ID, ENTITY_SLOT_ID, IAXXX_HMD_BLOCK_ID, data, length); break; default: ALOGE("%s: Unknown KW_ID\n", __func__); - err = -1; - errno = -EINVAL; - break; + err = -EINVAL; + goto exit; } if (err < 0) { ALOGE("%s: Failed to load the keyword with error %s\n", __func__, strerror(errno)); + goto exit; } -exit: + ALOGV("-%s-", __func__); +exit: return err; } @@ -103,7 +81,7 @@ int get_model_state(struct iaxxx_odsp_hw *odsp_hdl, const uint32_t inst_id, const uint32_t param_val) { int err = 0; - const uint32_t param_id = AMBIENT_ENTITY_GET_MODEL_STATE_PARAM_ID; + const uint32_t param_id = AMBIENT_GET_MODEL_STATE_PARAM_ID; const uint32_t block_id = IAXXX_HMD_BLOCK_ID; err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, inst_id, param_id, @@ -121,7 +99,7 @@ int get_event(struct iaxxx_odsp_hw *odsp_hdl, struct iaxxx_get_event_info *ge) ALOGV("+%s+", __func__); err = iaxxx_odsp_evt_getevent(odsp_hdl, ge); - if (err == -1) { + if (err != 0) { ALOGE("%s: ERROR Failed to get event with error %d(%s)", __func__, errno, strerror(errno)); } @@ -136,123 +114,15 @@ int reset_ambient_plugin(struct iaxxx_odsp_hw *odsp_hdl) ALOGV("+%s+", __func__); err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, - AMBIENT_ENTITY_RESET_PARAM_ID, - AMBIENT_ENTITY_RESET_PARAM_VAL, + AMBIENT_INSTANCE_ID, + AMBIENT_RESET_PARAM_ID, + AMBIENT_SLOT_ID, IAXXX_HMD_BLOCK_ID); if (err != 0) { - ALOGE("%s: ERROR: Set param for ambient lib reset failed %d(%s)", - __func__, errno, strerror(errno)); - } - ALOGV("-%s-", __func__); - return err; -} - -/* - * Provide an interface for Testing binary - * to control route. - */ -static struct mixer* open_mixer_ctl() -{ - return mixer_open(0); -} - -static void close_mixer_ctl(struct mixer *mixer) -{ - if (mixer) { - mixer_close(mixer); - } -} - -static int set_mixer_ctl_val(struct mixer *mixer, char *id, int value) -{ - struct mixer_ctl *ctl = NULL; - int err = 0; - - if ((mixer == NULL) || (id == NULL)) { - ALOGE("%s: ERROR Null argument passed", __func__); - err = -EINVAL; - goto exit; - } - - ctl = mixer_get_ctl_by_name(mixer, id); - if (ctl == NULL) { - ALOGE("%s: ERROR Invalid control name: %s", __func__, id); - err = -1; - goto exit; - } - - if (mixer_ctl_set_value(ctl, 0, value)) { - ALOGE("%s: ERROR Invalid value for %s", __func__, id); - err = -1; - goto exit; - } - -exit: - return err; -} - -static int set_mixer_ctl_string(struct mixer *mixer, - char *id, const char *string) -{ - struct mixer_ctl *ctl = NULL; - int err = 0; - - if ((mixer == NULL) || (id == NULL)) { - ALOGE("%s: ERROR Null argument passed", __func__); - err = -EINVAL; - goto exit; - } - - ctl = mixer_get_ctl_by_name(mixer, id); - if (ctl == NULL) { - ALOGE("%s: ERROR Invalid control name: %s", __func__, id); - err = -1; - goto exit; - } - - if (mixer_ctl_set_enum_by_string(ctl, string)) { - ALOGE("%s: ERROR Invalid string for %s", __func__, id); - err = -1; - goto exit; - } - -exit: - return err; -} - -/* - * Provide an interface for Oslo binary - * to control route. - */ -int force_set_sensor_route(bool enable) -{ - int err = 0; - - ALOGV("+%s+", __func__); - struct mixer *mixer = open_mixer_ctl(); - if (mixer == NULL) { - ALOGE("%s: ERROR: Failed to open the mixer control", __func__); - err = -1; - goto exit; - } - - if (enable) { - set_mixer_ctl_string(mixer, "sensor0 Ip Conf", "plugin3Out1"); - set_mixer_ctl_val(mixer, "sensor0 En", 1); - set_mixer_ctl_string(mixer, "Plgin2Ip Ep0 Conf", "SensorOut0"); - set_mixer_ctl_string(mixer, "Plgin3Ip Ep0 Conf", "plugin2Out0"); - set_mixer_ctl_val(mixer, "Plgin2Blk1En", 1); - set_mixer_ctl_val(mixer, "Plgin3Blk1En", 1); - } else { - set_mixer_ctl_val(mixer, "Plgin3Blk1En", 0); - set_mixer_ctl_val(mixer, "Plgin2Blk1En", 0); - set_mixer_ctl_val(mixer, "sensor0 En", 0); - set_mixer_ctl_string(mixer, "sensor0 Ip Conf", "UNKNOWN"); + ALOGE("%s: ERROR: Set param for ambient lib reset failed %d(%s)", + __func__, errno, strerror(errno)); } -exit: - close_mixer_ctl(mixer); ALOGV("-%s-", __func__); return err; } @@ -273,21 +143,21 @@ int set_sensor_route(struct audio_route *route_hdl, bool enable) return err; } -int set_ambient_entity_state(struct iaxxx_odsp_hw *odsp_hdl, +int set_ambient_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current) { int err = 0; ALOGV("+%s+ enable models %x", __func__, current & PLUGIN2_MASK); - err = iaxxx_odsp_plugin_setevent(odsp_hdl, AMBIENT_ENTITY_INSTANCE_ID, + err = iaxxx_odsp_plugin_setevent(odsp_hdl, AMBIENT_INSTANCE_ID, current & PLUGIN2_MASK, IAXXX_HMD_BLOCK_ID); if (err < 0) { - ALOGE("%s: ERROR: ambient_entity set event failed with error %d(%s)", + ALOGE("%s: ERROR: ambient set event failed with error %d(%s)", __func__, errno, strerror(errno)); goto exit; } if (current & AMBIENT_MASK) { - err = iaxxx_odsp_evt_subscribe(odsp_hdl, AMBIENT_ENTITY_EVT_SRC_ID, + err = iaxxx_odsp_evt_subscribe(odsp_hdl, AMBIENT_EVT_SRC_ID, AMBIENT_DETECTION, IAXXX_SYSID_HOST, 0); if (err < 0) { ALOGE("%s: ERROR: Ambient subscrive event failed" @@ -298,7 +168,7 @@ int set_ambient_entity_state(struct iaxxx_odsp_hw *odsp_hdl, } if (current & ENTITY_MASK) { - err = iaxxx_odsp_evt_subscribe(odsp_hdl, AMBIENT_ENTITY_EVT_SRC_ID, + err = iaxxx_odsp_evt_subscribe(odsp_hdl, AMBIENT_EVT_SRC_ID, ENTITY_DETECTION, IAXXX_SYSID_HOST, 0); if (err < 0) { ALOGE("%s: ERROR: Entity subscrive event failed" @@ -313,13 +183,13 @@ exit: return err; } -int tear_ambient_entity_state(struct iaxxx_odsp_hw *odsp_hdl, +int tear_ambient_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current) { int err = 0; ALOGV("+%s+ current %x", __func__, current & PLUGIN2_MASK); if (current & AMBIENT_MASK) { - err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, AMBIENT_ENTITY_EVT_SRC_ID, + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, AMBIENT_EVT_SRC_ID, AMBIENT_DETECTION, IAXXX_SYSID_HOST); if (err < 0) { ALOGE("%s: ERROR: Ambient unsubscrive event failed" @@ -328,9 +198,9 @@ int tear_ambient_entity_state(struct iaxxx_odsp_hw *odsp_hdl, goto exit; } err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, - AMBIENT_ENTITY_UNLOAD_PARAM_ID, - AMBIENT_UNLOAD_PARAM_VAL, + AMBIENT_INSTANCE_ID, + AMBIENT_UNLOAD_PARAM_ID, + AMBIENT_SLOT_ID, IAXXX_HMD_BLOCK_ID); if (err < 0) { ALOGE("%s: ERROR: Ambient model unload failed with error %d(%s)", @@ -339,7 +209,7 @@ int tear_ambient_entity_state(struct iaxxx_odsp_hw *odsp_hdl, } } if (current & ENTITY_MASK) { - err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, AMBIENT_ENTITY_EVT_SRC_ID, + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, AMBIENT_EVT_SRC_ID, ENTITY_DETECTION, IAXXX_SYSID_HOST); if (err < 0) { ALOGE("%s: ERROR: Entity unsubscrive event failed" @@ -348,9 +218,9 @@ int tear_ambient_entity_state(struct iaxxx_odsp_hw *odsp_hdl, goto exit; } err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, - AMBIENT_ENTITY_UNLOAD_PARAM_ID, - ENTITY_UNLOAD_PARAM_VAL, + AMBIENT_INSTANCE_ID, + AMBIENT_UNLOAD_PARAM_ID, + ENTITY_SLOT_ID, IAXXX_HMD_BLOCK_ID); if (err < 0) { ALOGE("%s: ERROR: Entity model unload failed with error %d(%s)", @@ -364,7 +234,7 @@ exit: return err; } -int set_ambient_entity_route(struct audio_route *route_hdl, bool bargein) +int set_ambient_route(struct audio_route *route_hdl, bool bargein) { int err = 0; @@ -372,10 +242,10 @@ int set_ambient_entity_route(struct audio_route *route_hdl, bool bargein) if (bargein == true) err = audio_route_apply_and_update_path(route_hdl, - AMBIENT_ENTITY_WITH_BARGEIN_ROUTE); + AMBIENT_WITH_BARGEIN_ROUTE); else err = audio_route_apply_and_update_path(route_hdl, - AMBIENT_ENTITY_WITHOUT_BARGEIN_ROUTE); + AMBIENT_WITHOUT_BARGEIN_ROUTE); if (err) ALOGE("%s: route apply fail %d", __func__, err); @@ -383,7 +253,7 @@ int set_ambient_entity_route(struct audio_route *route_hdl, bool bargein) return err; } -int tear_ambient_entity_route(struct audio_route *route_hdl, bool bargein) +int tear_ambient_route(struct audio_route *route_hdl, bool bargein) { int err = 0; @@ -391,10 +261,10 @@ int tear_ambient_entity_route(struct audio_route *route_hdl, bool bargein) /* check cvq node to send ioctl */ if (bargein == true) err = audio_route_reset_and_update_path(route_hdl, - AMBIENT_ENTITY_WITH_BARGEIN_ROUTE); + AMBIENT_WITH_BARGEIN_ROUTE); else err = audio_route_reset_and_update_path(route_hdl, - AMBIENT_ENTITY_WITHOUT_BARGEIN_ROUTE); + AMBIENT_WITHOUT_BARGEIN_ROUTE); if (err) ALOGE("%s: route reset fail %d", __func__, err); @@ -402,16 +272,15 @@ int tear_ambient_entity_route(struct audio_route *route_hdl, bool bargein) return err; } -int set_hotword_route(struct iaxxx_odsp_hw *odsp_hdl, - struct audio_route *route_hdl, bool bargein) +int set_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current) { int err = 0; - ALOGV("+%s bargein %d+", __func__, bargein); + ALOGV("+%s+ current %x", __func__, current & PLUGIN1_MASK); // Set the events and params err = iaxxx_odsp_plugin_setevent(odsp_hdl, HOTWORD_INSTANCE_ID, - 0x1, IAXXX_HMD_BLOCK_ID); - if (err == -1) { + current & PLUGIN1_MASK, IAXXX_HMD_BLOCK_ID); + if (err != 0) { ALOGE("%s: ERROR: Hotword set event failed with error %d(%s)", __func__, errno, strerror(errno)); goto exit; @@ -422,12 +291,40 @@ int set_hotword_route(struct iaxxx_odsp_hw *odsp_hdl, // Subscribe for events err = iaxxx_odsp_evt_subscribe(odsp_hdl, HOTWORD_EVT_SRC_ID, HOTWORD_DETECTION, IAXXX_SYSID_HOST, 0); - if (err == -1) { + if (err != 0) { ALOGE("%s: ERROR: Hotword subscribe event failed with error %d(%s)", __func__, errno, strerror(errno)); goto exit; } +exit: + ALOGV("-%s-", __func__); + return err; +} + +int tear_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current) +{ + int err = 0; + + ALOGV("+%s+ current %x", __func__, current & PLUGIN1_MASK); + + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, HOTWORD_EVT_SRC_ID, + HOTWORD_DETECTION, IAXXX_SYSID_HOST); + if (err != 0) { + ALOGE("%s: ERROR: Hotword unsubscrive event failed with error %d(%s)", + __func__, errno, strerror(errno)); + } + + ALOGV("-%s-", __func__); + return err; +} + +int set_hotword_route(struct audio_route *route_hdl, bool bargein) +{ + int err = 0; + + ALOGV("+%s bargein %d+", __func__, bargein); + if (bargein == true) err = audio_route_apply_and_update_path(route_hdl, HOTWORD_WITH_BARGEIN_ROUTE); @@ -437,14 +334,11 @@ int set_hotword_route(struct iaxxx_odsp_hw *odsp_hdl, if (err) ALOGE("%s: route apply fail %d", __func__, err); -exit: ALOGV("-%s-", __func__); return err; } -int tear_hotword_route(struct iaxxx_odsp_hw *odsp_hdl, - struct audio_route *route_hdl, - bool bargein) +int tear_hotword_route(struct audio_route *route_hdl, bool bargein) { int err = 0; @@ -459,13 +353,6 @@ int tear_hotword_route(struct iaxxx_odsp_hw *odsp_hdl, if (err) ALOGE("%s: route reset fail %d", __func__, err); - err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, HOTWORD_EVT_SRC_ID, - HOTWORD_DETECTION, IAXXX_SYSID_HOST); - if (err == -1) { - ALOGE("%s: ERROR: Hotword unsubscrive event failed with error %d(%s)", - __func__, errno, strerror(errno)); - } - ALOGV("-%s-", __func__); return err; } @@ -512,12 +399,12 @@ int sensor_event_init_params(struct iaxxx_odsp_hw *odsp_hdl) ALOGV("+%s+", __func__); // Set the events and params - err = iaxxx_odsp_plugin_setevent(odsp_hdl, SENSOR_INSTANCE_ID, 0x7, + err = iaxxx_odsp_plugin_setevent(odsp_hdl, SENSOR_INSTANCE_ID, 0x1F, IAXXX_HMD_BLOCK_ID); - if (err == -1) { + if (err != 0) { ALOGE("%s: ERROR: Sensor set event with error %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } ALOGD("Registering for 3 sensor mode switch events\n"); @@ -526,31 +413,122 @@ int sensor_event_init_params(struct iaxxx_odsp_hw *odsp_hdl) err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID, SENSOR_PRESENCE_MODE, IAXXX_SYSID_SCRIPT_MGR, 0x1201); - if (err == -1) { - ALOGE("%s: ERROR: Oslo event subscription (presence mode) failed with" - " error %d(%s)", __func__, errno, strerror(errno)); - return err; + if (err != 0) { + ALOGE("%s: ERROR: Sensor subscribe (presence mode) failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; } // Subscribe for events err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID, SENSOR_DETECTED_MODE, IAXXX_SYSID_SCRIPT_MGR, 0x1202); - if (err == -1) { - ALOGE("%s: ERROR: Oslo event subscription (detection mode) failed with" - " error %d(%s)", __func__, errno, strerror(errno)); - return err; + if (err != 0) { + ALOGE("%s: ERROR: Sensor subscribe (detection mode) failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; } // Subscribe for events err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID, SENSOR_MAX_MODE, IAXXX_SYSID_HOST, 0); - if (err == -1) { - ALOGE("%s: ERROR: Oslo event subscription (max mode) failed with" - " error %d(%s)", __func__, errno, strerror(errno)); + if (err != 0) { + ALOGE("%s: ERROR: Sensor subscribe (max mode) failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + + err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID, + OSLO_CONFIGURED, IAXXX_SYSID_HOST_1, 0); + if (err != 0) { + ALOGE("%s: ERROR: Sensor subscribe (oslo configured) failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID, + OSLO_DESTROYED, IAXXX_SYSID_HOST_1, 0); + if (err != 0) { + ALOGE("%s: ERROR: Sensor subscribe (oslo destroyed) %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_trigger(odsp_hdl, OSLO_EVT_SRC_ID, OSLO_CONFIGURED, 0); + if (err != 0) { + ALOGE("%s: ERROR: olso event trigger (oslo configured) failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; } ALOGV("-%s-", __func__); + +exit: + return err; +} + +static int sensor_event_deinit_params(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + err = iaxxx_odsp_evt_trigger(odsp_hdl, OSLO_EVT_SRC_ID, OSLO_DESTROYED, 0); + if (err != 0) { + ALOGE("%s: ERROR: Oslo event trigger (oslo destroyed) failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID, SENSOR_MAX_MODE, + IAXXX_SYSID_HOST); + if (err != 0) { + ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)" + " error %d(%s)", __func__, OSLO_EVT_SRC_ID, + SENSOR_MAX_MODE, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID, + SENSOR_DETECTED_MODE, IAXXX_SYSID_SCRIPT_MGR); + if (err != 0) { + ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)" + " error %d(%s)", __func__, OSLO_EVT_SRC_ID, + SENSOR_DETECTED_MODE, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID, + SENSOR_PRESENCE_MODE, IAXXX_SYSID_SCRIPT_MGR); + if (err != 0) { + ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)" + " error %d(%s)", __func__, OSLO_EVT_SRC_ID, + SENSOR_PRESENCE_MODE, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID, + OSLO_CONFIGURED, IAXXX_SYSID_HOST_1); + if (err != 0) { + ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)" + " from host %d error %d(%s)", __func__, OSLO_EVT_SRC_ID, + OSLO_CONFIGURED, IAXXX_SYSID_HOST_1, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID, + OSLO_DESTROYED, IAXXX_SYSID_HOST_1); + if (err != 0) { + ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)" + " from host %d error %d(%s)", __func__, OSLO_EVT_SRC_ID, + OSLO_DESTROYED, IAXXX_SYSID_HOST_1, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: return err; } @@ -566,21 +544,21 @@ int flush_model(struct iaxxx_odsp_hw *odsp_hdl, int kw_type) err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, HOTWORD_INSTANCE_ID, HOTWORD_UNLOAD_PARAM_ID, - HOTWORD_UNLOAD_PARAM_VAL, + HOTWORD_SLOT_ID, IAXXX_HMD_BLOCK_ID); break; case 1: //AMBIENT err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, - AMBIENT_ENTITY_UNLOAD_PARAM_ID, - AMBIENT_UNLOAD_PARAM_VAL, + AMBIENT_INSTANCE_ID, + AMBIENT_UNLOAD_PARAM_ID, + AMBIENT_SLOT_ID, IAXXX_HMD_BLOCK_ID); break; case 2: //ENTITY err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, - AMBIENT_ENTITY_UNLOAD_PARAM_ID, - ENTITY_UNLOAD_PARAM_VAL, + AMBIENT_INSTANCE_ID, + AMBIENT_UNLOAD_PARAM_ID, + ENTITY_SLOT_ID, IAXXX_HMD_BLOCK_ID); break; default: @@ -599,101 +577,393 @@ int flush_model(struct iaxxx_odsp_hw *odsp_hdl, int kw_type) return err; } +int setup_buffer_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); -int setup_chip(struct iaxxx_odsp_hw *odsp_hdl) + err = iaxxx_odsp_package_load(odsp_hdl, BUFFER_PACKAGE, BUF_PKG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to load Buffer package %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int destroy_buffer_package(struct iaxxx_odsp_hw *odsp_hdl) { int err = 0; - struct iaxxx_create_config_data cdata; - ALOGV("+%s+", __func__); - /* AMBIENT_EC_PACKAGE */ + ALOGD("+%s+", __func__); + + err = iaxxx_odsp_package_unload(odsp_hdl, BUF_PKG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to unload Buffer package %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int setup_hotword_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + // Download packages for ok google err = iaxxx_odsp_package_load(odsp_hdl, AMBIENT_EC_PACKAGE, HOTWORD_PKG_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to load SoundTrigger %d(%s)", + if (err != 0) { + ALOGE("%s: ERROR: Failed to load Hotword package %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; + } + + // Create Hotword plugin + err = iaxxx_odsp_plugin_create(odsp_hdl, HOTWORD_INSTANCE_ID, HOTWORD_PRIORITY, + HOTWORD_PKG_ID, HOTWORD_PLUGIN_IDX, + IAXXX_HMD_BLOCK_ID, PLUGIN_DEF_CONFIG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to create Hotword plugin %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, HOTWORD_INSTANCE_ID, 0, + 0, IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Hotword init frontend failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int destroy_hotword_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + err = iaxxx_odsp_plugin_destroy(odsp_hdl, HOTWORD_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to destroy Hotword plugin %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + // Unload hotword package + err = iaxxx_odsp_package_unload(odsp_hdl, HOTWORD_PKG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to unload Hotword package %d(%s)", + __func__, errno, strerror(errno)); + goto exit; } - /* AMBIENT_DA_PACKAGE */ - // Download packages for ambient & entity + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int setup_ambient_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + // Download packages for ambient err = iaxxx_odsp_package_load(odsp_hdl, AMBIENT_DA_PACKAGE, - AMBIENT_ENTITY_PKG_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to load ENTITY %d(%s)", + AMBIENT_PKG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to load Ambient package %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } + // Create Ambient plugin + err = iaxxx_odsp_plugin_create(odsp_hdl, AMBIENT_INSTANCE_ID, + AMBIENT_PRIORITY, AMBIENT_PKG_ID, + AMBIENT_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID, + PLUGIN_DEF_CONFIG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to create Ambient plugin %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, AMBIENT_INSTANCE_ID, + 0, 0, IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Ambient init frontend failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int destroy_ambient_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + err = iaxxx_odsp_plugin_destroy(odsp_hdl, AMBIENT_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to destroy Ambient plugin %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_package_unload(odsp_hdl, AMBIENT_PKG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to unload Ambient package %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int setup_aec_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + err = iaxxx_odsp_package_load(odsp_hdl, AEC_PASSTHROUGH_PACKAGE, AEC_PKG_ID); - if (-1 == err && EEXIST != errno) { - ALOGE("%s: ERROR: Failed to load AEC %d(%s)", + if (err != 0) { + ALOGE("%s: ERROR: Failed to load AEC passthrough package %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - err = iaxxx_odsp_package_load(odsp_hdl, BUFFER_PACKAGE, BUF_PACKAGE_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to load Buffer %d(%s)", + // AEC PT Plugin Create + err = iaxxx_odsp_plugin_create(odsp_hdl, AEC_INSTANCE_ID, AEC_PRIORITY, + AEC_PKG_ID, AEC_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID, + PLUGIN_DEF_CONFIG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to create AEC plugin %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - /* Create plugins */ + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int destroy_aec_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + err = iaxxx_odsp_plugin_destroy(odsp_hdl, AEC_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to destroy AEC plugin %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_package_unload(odsp_hdl, AEC_PKG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to unload AEC package %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int setup_chre_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + struct iaxxx_create_config_data cdata; + + ALOGD("+%s+", __func__); + + /* Create CHRE plugins */ cdata.type = CONFIG_FILE; cdata.data.fdata.filename = BUFFER_CONFIG_VAL; err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl, - HOTWORD_BUF_INSTANCE_ID, + CHRE_INSTANCE_ID, IAXXX_HMD_BLOCK_ID, cdata); - if (err == -1) { - ALOGE("%s: ERROR: Hotword buffer configuration %d(%s)", + if (err != 0) { + ALOGE("%s: ERROR: CHRE Buffer configuration failed %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - // Create Buffer plugin - err = iaxxx_odsp_plugin_create(odsp_hdl, HOTWORD_BUF_INSTANCE_ID, - BUF_PRIORITY, BUF_PACKAGE_ID, BUF_PLUGIN_IDX, + // Create CHRE Buffer plugin + err = iaxxx_odsp_plugin_create(odsp_hdl, CHRE_INSTANCE_ID, BUF_PRIORITY, + BUF_PKG_ID, CHRE_PLUGIN_IDX, + IAXXX_HMD_BLOCK_ID, PLUGIN_DEF_CONFIG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to create CHRE buffer %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, CHRE_INSTANCE_ID, + CHRE_EVT_PARAM_ID, CHRE_BUF_SIZE, IAXXX_HMD_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to create Hotword Buffer%d(%s)", + if (err != 0) { + ALOGE("%s: ERROR: CHRE buffer set param failed %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - // Create Hotword plugin - err = iaxxx_odsp_plugin_create(odsp_hdl, HOTWORD_INSTANCE_ID, HOTWORD_PRIORITY, - HOTWORD_PKG_ID, HOTWORD_PLUGIN_IDX, - IAXXX_HMD_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to create Hotword plugin%d(%s)", + err = iaxxx_odsp_plugin_setevent(odsp_hdl, CHRE_INSTANCE_ID, + CHRE_EVT_MASK, IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: CHRE set event failed %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; + } + + // Subscribe for events + err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID, + CHRE_EVT_ID, IAXXX_SYSID_HOST_1, 0); + if (err != 0) { + ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)" + " IOCTL failed %d(%s)", __func__, CHRE_EVT_ID, CHRE_EVT_SRC_ID, + errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID, + CHRE_CONFIGURED, IAXXX_SYSID_HOST_1, 0); + if (err != 0) { + ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)" + " IOCTL failed %d(%s)", __func__, CHRE_CONFIGURED, CHRE_EVT_SRC_ID, + errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID, + CHRE_DESTROYED, IAXXX_SYSID_HOST_1, 0); + if (err != 0) { + ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)" + " IOCTL failed %d(%s)", __func__, CHRE_DESTROYED, CHRE_EVT_SRC_ID, + errno, strerror(errno)); + goto exit; } - // Create Ambient & Entity plugin - err = iaxxx_odsp_plugin_create(odsp_hdl, AMBIENT_ENTITY_INSTANCE_ID, - AMBIENT_ENTITY_PRIORITY, AMBIENT_ENTITY_PKG_ID, - AMBIENT_ENTITY_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to create Entity plugin%d(%s)", + err = iaxxx_odsp_evt_trigger(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_CONFIGURED, 0); + if (err != 0) { + ALOGE("%s: ERROR: Oslo event trigger (chre configured) failed %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int destroy_chre_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + err = iaxxx_odsp_evt_trigger(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_DESTROYED, 0); + if (err != 0) { + ALOGE("%s: ERROR: Oslo event trigger (chre destroyed) failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; } - /* SENSOR MANAGER PACKAGE LOAD AND ROUTE SETUP */ - // Download packages + + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_EVT_ID, + IAXXX_SYSID_HOST_1); + if (err != 0) { + ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)" + " IOCTL failed %d(%s)", __func__, CHRE_EVT_ID, CHRE_EVT_SRC_ID, + errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_CONFIGURED, + IAXXX_SYSID_HOST_1); + if (err != 0) { + ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)" + " IOCTL failed %d(%s)", __func__, CHRE_CONFIGURED, CHRE_EVT_SRC_ID, + errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_DESTROYED, + IAXXX_SYSID_HOST_1); + if (err != 0) { + ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)" + " IOCTL failed %d(%s)", __func__, CHRE_DESTROYED, CHRE_EVT_SRC_ID, + errno, strerror(errno)); + goto exit; + } + + err = iaxxx_odsp_plugin_destroy(odsp_hdl, CHRE_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to destroy buffer plugin for CHRE %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int setup_sensor_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + struct iaxxx_create_config_data cdata; + + ALOGD("+%s+", __func__); + + // Download sensor packages err = iaxxx_odsp_package_load(odsp_hdl, SENSOR_PACKAGE, SENSOR_PKG_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to load Oslo %d(%s)", + if (err != 0) { + ALOGE("%s: ERROR: Failed to load Sensor package %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - /* TODO Need to have a check if buffer package is not loaded then we have to load it here */ - /* if buffer plugin Loaded */ /* Create plugins */ cdata.type = CONFIG_FILE; cdata.data.fdata.filename = BUFFER_CONFIG_OSLO_VAL; @@ -701,145 +971,238 @@ int setup_chip(struct iaxxx_odsp_hw *odsp_hdl) OSLO_BUF_INSTANCE_ID, IAXXX_HMD_BLOCK_ID, cdata); - if (err == -1) { - ALOGE("%s: ERROR: Oslo buffer configuration %d(%s)", - __func__, errno, strerror(errno)); - return err; - } - - cdata.type = CONFIG_FILE; - cdata.data.fdata.filename = SENSOR_CONFIG_VAL; - err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl, - SENSOR_INSTANCE_ID, - IAXXX_HMD_BLOCK_ID, - cdata); - if (err == -1) { - ALOGE("%s: ERROR: Sensor configuration %d(%s)", + if (err != 0) { + ALOGE("%s: ERROR: Sensor buffer configuration failed %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } // Create Buffer plugin err = iaxxx_odsp_plugin_create(odsp_hdl, OSLO_BUF_INSTANCE_ID, BUF_PRIORITY, - BUF_PACKAGE_ID, BUF_PLUGIN_IDX, - IAXXX_HMD_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to create Oslo Buffer %d(%s)", + BUF_PKG_ID, BUF_PLUGIN_IDX, + IAXXX_HMD_BLOCK_ID, PLUGIN_DEF_CONFIG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to create Sensor Buffer %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } // Create Dummy sensor plugin err = iaxxx_odsp_plugin_create(odsp_hdl, SENSOR_INSTANCE_ID, - SENSOR_PRIORITY, SENSOR_PKG_ID, - SENSOR_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to create Oslo Plugin %d(%s)", + SENSOR_PRIORITY, SENSOR_PKG_ID, + SENSOR_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID, + PLUGIN_DEF_CONFIG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to create Sensor plugin %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } err = sensor_event_init_params(odsp_hdl); if (err) { ALOGE("%s: ERROR: Sensor event init failed %d", __func__, err); - return err; + goto exit; } - /* SENSOR MANAGER ROUTE END */ + ALOGD("-%s-", __func__); - /* Ambient & Entity 10 sec Q15 buffer plugin */ - /* TODO Need to have a check if buffer package is not - * loaded then we have to load it here - */ - /* if buffer plugin Loaded */ - /* Create plugins */ - cdata.type = CONFIG_FILE; - cdata.data.fdata.filename = BUFFER_CONFIG_AMBIENT_VAL; - err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl, - AMBIENT_BUF_INSTANCE_ID, - IAXXX_HMD_BLOCK_ID, - cdata); - if (err == -1) { - ALOGE("%s: ERROR: Ambient buffer configuration %d(%s)", +exit: + return err; +} + +int destroy_sensor_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + err = sensor_event_deinit_params(odsp_hdl); + if (err != 0) { + ALOGE("%s: ERROR: Sensor event uninit failed %d", __func__, err); + goto exit; + } + + err = iaxxx_odsp_plugin_destroy(odsp_hdl, SENSOR_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to destroy sensor plugin %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - // Create Buffer plugin - err = iaxxx_odsp_plugin_create(odsp_hdl, AMBIENT_BUF_INSTANCE_ID, - BUF_PRIORITY, BUF_PACKAGE_ID, BUF_PLUGIN_IDX, - IAXXX_HMD_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to create Ambient Buffer %d(%s)", + err = iaxxx_odsp_plugin_destroy(odsp_hdl, OSLO_BUF_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to destroy sensor buffer plugin %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - // AEC PT Plugin Create - err = iaxxx_odsp_plugin_create(odsp_hdl, AEC_INSTANCE_ID, AEC_PRIORITY, - AEC_PKG_ID, AEC_PLUGIN_IDX, AEC_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to create AEC Plugin %d(%s)", + err = iaxxx_odsp_package_unload(odsp_hdl, SENSOR_PKG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to unload sensor package %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - /* Create CHRE plugins */ + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int setup_mixer_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + // Load package for Mixer + err = iaxxx_odsp_package_load(odsp_hdl, MIXER_PACKAGE, MIXER_PKG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to load Mixer package %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + // Create Mixer Plugin + err = iaxxx_odsp_plugin_create(odsp_hdl, MIXER_INSTANCE_ID, + MIXER_PRIORITY, MIXER_PKG_ID, + MIXER_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID, + PLUGIN_DEF_CONFIG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to create Mixer plugin %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; + +} + +int destroy_mixer_package(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + // Destroy Mixer Plugin + err = iaxxx_odsp_plugin_destroy(odsp_hdl, MIXER_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to destroy Mixer buffer plugin %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + // Unload package for Mixer + err = iaxxx_odsp_package_unload(odsp_hdl, MIXER_PKG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to unload sensor package error %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int setup_mic_buffer(struct iaxxx_odsp_hw *odsp_hdl) +{ + struct iaxxx_create_config_data cdata; + int err = 0; + + ALOGD("+%s+", __func__); + cdata.type = CONFIG_FILE; - cdata.data.fdata.filename = BUFFER_CONFIG_VAL; + cdata.data.fdata.filename = BUFFER_CONFIG_AMBIENT_VAL; err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl, - CHRE_INSTANCE_ID, + BUF_INSTANCE_ID, IAXXX_HMD_BLOCK_ID, cdata); - if (err == -1) { - ALOGE("%s: ERROR: CHRE Buffer configuration %d(%s)", + if (err != 0) { + ALOGE("%s: ERROR: 8 sec buffer configuration failed %d(%s)", __func__, errno, strerror(errno)); - return err; - } - - // Create CHRE Buffer plugin - err = iaxxx_odsp_plugin_create(odsp_hdl, CHRE_INSTANCE_ID, BUF_PRIORITY, - BUF_PACKAGE_ID, CHRE_PLUGIN_IDX, - IAXXX_HMD_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: Failed to create CHRE Buffer %d(%s)", - __func__, errno, strerror(errno)); - return err; + goto exit; } - /* Param ID is 8 for Buffer package - * 60480 is in bytes calculated for 1.8sec buffer threshold - * 640/2 = 320 for 10ms frame in Q15 format. - * 320+16 = 336 is each frame plus tunnel header - * 336 * 180 = 60480 which is 1.8 sec buffer in bytes - */ - err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, CHRE_INSTANCE_ID, - CHRE_EVT_PARAM_ID, 60480, - IAXXX_HMD_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: CHRE buffer set param failed with error %d(%s)", + // Create Buffer plugin + err = iaxxx_odsp_plugin_create(odsp_hdl, BUF_INSTANCE_ID, + BUF_PRIORITY, BUF_PKG_ID, BUF_PLUGIN_IDX, + IAXXX_HMD_BLOCK_ID, PLUGIN_DEF_CONFIG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to create Buffer Plugin %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - err = iaxxx_odsp_plugin_setevent(odsp_hdl, CHRE_INSTANCE_ID, - CHRE_EVT_PARAM_ID, IAXXX_HMD_BLOCK_ID); - if (err == -1) { - ALOGE("%s: ERROR: CHRE set event failed with error %d(%s)", + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int destroy_mic_buffer(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + + // Destroy Buffer plugin + err = iaxxx_odsp_plugin_destroy(odsp_hdl, BUF_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to destroy 8 sec buffer %d(%s)", __func__, errno, strerror(errno)); - return err; + goto exit; } - // Subscribe for events - err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID, - CHRE_EVT_ID, IAXXX_SYSID_HOST_1, 0); - if (err == -1) { - ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)" - " IOCTL failed with error %d(%s)", __func__, CHRE_EVT_ID, - CHRE_EVT_SRC_ID, errno, strerror(errno)); - } + ALOGD("-%s-", __func__); - ALOGV("-%s-", __func__); +exit: + return err; +} + +int set_buffer_route(struct audio_route *route_hdl, bool bargein) +{ + int err = 0; + + ALOGD("+%s %d+", __func__, bargein); + + if (bargein == true) + err = audio_route_apply_and_update_path(route_hdl, + BUFFER_WITH_BARGEIN_ROUTE); + else + err = audio_route_apply_and_update_path(route_hdl, + BUFFER_WITHOUT_BARGEIN_ROUTE); + if (err) + ALOGE("%s: route fail %d", __func__, err); + + ALOGD("-%s-", __func__); + return err; +} + +int tear_buffer_route(struct audio_route *route_hdl, bool bargein) +{ + int err = 0; + + ALOGD("+%s %d+", __func__, bargein); + + if (bargein == true) + err = audio_route_reset_and_update_path(route_hdl, + BUFFER_WITH_BARGEIN_ROUTE); + else + err = audio_route_reset_and_update_path(route_hdl, + BUFFER_WITHOUT_BARGEIN_ROUTE); + if (err) + ALOGE("%s: route fail %d", __func__, err); + + ALOGD("-%s-", __func__); return err; } @@ -853,22 +1216,59 @@ int enable_bargein_route(struct audio_route *route_hdl, bool enable) else err = audio_route_reset_and_update_path(route_hdl, BARGEIN_ROUTE); if (err) - ALOGE("%s: route fail %d", __func__, err);; + ALOGE("%s: route fail %d", __func__, err); ALOGD("-%s-", __func__); - return 0; + return err; } -int enable_mic_route(struct audio_route *route_hdl, int enable) +int enable_downlink_audio_route(struct audio_route *route_hdl, bool enable) { int err = 0; - ALOGD("+%s+ %d ", __func__, enable); + ALOGD("+%s+ %d", __func__, enable); if (enable) - err = audio_route_apply_and_update_path(route_hdl, MIC_ROUTE); + err = audio_route_apply_and_update_path(route_hdl, + DOWNLINK_AUDIO_ROUTE); else - err = audio_route_reset_and_update_path(route_hdl, MIC_ROUTE); + err = audio_route_reset_and_update_path(route_hdl, + DOWNLINK_AUDIO_ROUTE); + if (err) + ALOGE("%s: route fail %d", __func__, err); + + ALOGD("-%s-", __func__); + return err; +} + +int enable_mic_route(struct audio_route *route_hdl, bool enable, + enum clock_type ct) +{ + int err = 0; + + ALOGD("+%s+ %d clock type %d", __func__, enable, ct); + + if (ct == EXTERNAL_OSCILLATOR) { + if (enable) { + err = audio_route_apply_and_update_path(route_hdl, + MIC_ROUTE_EXT_CLK); + } else { + err = audio_route_reset_and_update_path(route_hdl, + MIC_ROUTE_EXT_CLK); + } + } else if (ct == INTERNAL_OSCILLATOR) { + if (enable) { + err = audio_route_apply_and_update_path(route_hdl, + MIC_ROUTE_INT_CLK); + } else { + err = audio_route_reset_and_update_path(route_hdl, + MIC_ROUTE_INT_CLK); + } + } else { + ALOGE("%s: ERROR: Invalid clock type", __func__); + err = -EINVAL; + } + if (err) ALOGE("%s: route fail %d", __func__, err); @@ -881,7 +1281,7 @@ int get_entity_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload, { int err = 0; err = iaxxx_odsp_plugin_get_parameter_blk(odsp_hdl, - AMBIENT_ENTITY_INSTANCE_ID, + AMBIENT_INSTANCE_ID, IAXXX_HMD_BLOCK_ID, 100, payload, payload_size); @@ -892,3 +1292,20 @@ int get_entity_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload, } return err; } + +int setup_mpll_clock_source(struct iaxxx_odsp_hw *odsp_hdl, + const int clk_source, const uint32_t clk_value) +{ + int err; + ALOGD("+%s+ clk_src:%d", __func__, clk_source); + + err = iaxxx_odsp_set_mpll_src(odsp_hdl, + clk_source, clk_value); + if (err != 0) { + ALOGE("%s: ERROR Failed to set internal oscillator", + __func__); + return err; + } + ALOGD("-%s-", __func__); + return err; +} diff --git a/iaxxx-debug-intf.h b/iaxxx-debug-intf.h new file mode 100644 index 0000000..14dd018 --- /dev/null +++ b/iaxxx-debug-intf.h @@ -0,0 +1,159 @@ +/* + * iaxxx-debug-intf.h - iaxxx debug Interface + * + * Copyright 2018 Knowles Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _IAXXX_DEBUG_INTF_H +#define _IAXXX_DEBUG_INTF_H + +#include <linux/types.h> +#include <linux/ioctl.h> + +#define IAXXX_SRB_SZ_TO_ARB (0x16c) +#define IAXXX_SRB_REGS_NUM (IAXXX_SRB_SZ_TO_ARB / sizeof(uint32_t)) +#define IAXXX_ARB_SZ (0x100) +#define IAXXX_ARB_REGS_NUM (IAXXX_ARB_SZ / sizeof(uint32_t)) +#define IAXXX_ARB_BLOCK_NUM (IAXXX_ARB_REGS_NUM / 2) +#define IAXXX_MAX_CIRC_BUFS (3) +#define IAXXX_MAX_REGS_NUM (0xc00) + +struct iaxxx_srb_info { + uint32_t reg_start_addr; + int reg_num; + uint32_t reg_vals[IAXXX_SRB_REGS_NUM]; +}; + +struct iaxxx_arb_block { + uint32_t reg_start_addr; + int reg_num; + uint32_t reg_vals[IAXXX_MAX_REGS_NUM]; + + /* For pretty formatted display */ + char name[15]; /* name of this arb block */ +}; + +struct iaxxx_arb_info { + uint32_t reg_start_addr; + int reg_num; + uint32_t reg_vals[IAXXX_ARB_REGS_NUM]; + struct iaxxx_arb_block blocks[IAXXX_ARB_BLOCK_NUM]; +}; + +struct iaxxx_circ_buffer { + uint32_t reg_start_addr; + int reg_num; + uint32_t reg_vals[IAXXX_MAX_REGS_NUM]; + + /* For pretty formatted display */ + char name[15]; /* name of this circular buffer */ +}; + +struct iaxxx_circ_buffer_info { + int buf_num; + struct iaxxx_circ_buffer bufs[IAXXX_MAX_CIRC_BUFS]; +}; + +struct iaxxx_registers_dump { + struct iaxxx_srb_info srb_info; + struct iaxxx_arb_info arb_info; + struct iaxxx_circ_buffer_info circ_buffer_info; +}; + +struct iaxxx_log_level_info { + uint32_t module_id; + uint32_t log_level; +}; + +struct iaxxx_log_mode_info { + bool mode; + uint8_t proc_id; +}; + +enum iaxxx_fw_debug_log_mode { + IAXXX_FROM_MEMORY, + IAXXX_FROM_ENDPOINT, +}; + +enum iaxxx_fw_debug_log_level { + IAXXX_DBG_LOG_LVL_OFF, + IAXXX_DBG_LOG_LVL_CUSTOM, + IAXXX_DBG_LOG_LVL_FATAL, + IAXXX_DBG_LOG_LVL_ERROR, + IAXXX_DBG_LOG_LVL_WARN, + IAXXX_DBG_LOG_LVL_INFO, + IAXXX_DBG_LOG_LVL_DEBUG, + IAXXX_DBG_LOG_LVL_TRACE, +}; + +enum iaxxx_debug_module_ids { + IAXXX_DBG_MODULE_ID_ASSERT_LOG, + IAXXX_DBG_MODULE_ID_ACCDETMGR_LOG, + IAXXX_DBG_MODULE_ID_BATTERYMGR_LOG, + IAXXX_DBG_MODULE_ID_BLUETOOTHMGR_LOG, + IAXXX_DBG_MODULE_ID_BUTTONMGR_LOG, + IAXXX_DBG_MODULE_ID_CODECMGR_LOG, + IAXXX_DBG_MODULE_ID_CTRLMGR_LOG, + IAXXX_DBG_MODULE_ID_DMAMGR_LOG, + IAXXX_DBG_MODULE_ID_EVTMGR_LOG, + IAXXX_DBG_MODULE_ID_FLASHMGR_LOG, + IAXXX_DBG_MODULE_ID_LEDMGR_LOG, + IAXXX_DBG_MODULE_ID_POWERMGR_LOG, + IAXXX_DBG_MODULE_ID_STREAMMGR_LOG, + IAXXX_DBG_MODULE_ID_SENSORMGR_LOG, + IAXXX_DBG_MODULE_ID_TUNNELMGR_LOG, + IAXXX_DBG_MODULE_ID_USBMGR_LOG, + IAXXX_DBG_MODULE_ID_PLUGINMGR_LOG, + IAXXX_DBG_MODULE_ID_PLUGINVM_LOG, + IAXXX_DBG_MODULE_ID_PACKAGEUTILS_LOG, + IAXXX_DBG_MODULE_ID_ENDPOINT_LOG, + IAXXX_DBG_MODULE_ID_PUTMSG_LOG, + IAXXX_DBG_MODULE_ID_CONTROLLER_LOG, + IAXXX_DBG_MODULE_ID_MIPSPROFILER_LOG, + IAXXX_DBG_MODULE_ID_DEBUGMONITOR_LOG, + IAXXX_DBG_MODULE_ID_SSPDRV_LOG, + IAXXX_DBG_MODULE_ID_AFDRV_LOG, + IAXXX_DBG_MODULE_ID_SPIDRV_LOG, + IAXXX_DBG_MODULE_ID_I2CDRV_LOG, + IAXXX_DBG_MODULE_ID_A400DRV_LOG, + IAXXX_DBG_MODULE_ID_ADAU1361DRV_LOG, + IAXXX_DBG_MODULE_ID_MAX98090DRV_LOG, + IAXXX_DBG_MODULE_ID_BQ27425DRV_LOG, + IAXXX_DBG_MODULE_ID_USBDRV_LOG, + IAXXX_DBG_MODULE_ID_CSR8811_LOG, + IAXXX_DBG_MODULE_ID_CYW20707DRV_LOG, + IAXXX_DBG_MODULE_ID_BUTTONDRV_LOG, + IAXXX_DBG_MODULE_ID_LEDDRV_LOG, + IAXXX_DBG_MODULE_ID_TIMERDRV_LOG, + IAXXX_DBG_MODULE_ID_UARTDRV_LOG, + IAXXX_DBG_MODULE_ID_FLASHDRV_LOG, + IAXXX_DBG_MODULE_ID_DMADRV_LOG, + IAXXX_DBG_MODULE_ID_GPIODRV_LOG, + IAXXX_DBG_MODULE_ID_MACDRV_LOG, + IAXXX_DBG_MODULE_ID_STMRDRV_LOG, + IAXXX_DBG_MODULE_ID_STMRPTDRV_LOG, + IAXXX_DBG_MODULE_ID_SLIMBUSDRV_LOG, + IAXXX_DBG_MODULE_ID_SSENSORDRV_LOG, + IAXXX_DBG_MODULE_ID_STRMDRV_LOG, + IAXXX_DBG_MODULE_ID_CPUSTRMDRV_LOG, + IAXXX_DBG_MODULE_ID_CLKTREEUTILS_LOG, + IAXXX_DBG_MODULE_ID_SCRIPTMGR_LOG, +}; + +#define IAXXX_BUS_CONFIG _IO('R', 0x011) +#define IAXXX_IOCTL_GET_REGISTERS_DUMP _IO('R', 0x012) +#define IAXXX_SET_DBG_LOG_LEVEL _IO('R', 0x021) +#define IAXXX_GET_DBG_LOG_LEVEL _IO('R', 0x022) +#define IAXXX_SET_DBG_LOG_MODE _IO('R', 0x023) +#define IAXXX_GET_DBG_LOG_MODE _IO('R', 0x024) + +#endif
\ No newline at end of file diff --git a/iaxxx-odsp.h b/iaxxx-odsp.h index 7ecdc18..31c7716 100644 --- a/iaxxx-odsp.h +++ b/iaxxx-odsp.h @@ -20,6 +20,15 @@ #define __IAXXX_ODSP_H__ #define NAME_MAX_SIZE 256 +#define IAXXX_PACKAGE_VER_STR_SIZE_MAX (100) +#define IAXXX_PLUGIN_VER_STR_SIZE_MAX (100) +#define IAXXX_MAX_PLUGIN_ENDPOINTS (16) +#define IAXXX_MAX_VER_STR_SIZE (20) +enum iaxxx_pll_source { + IAXXX_SRC_SYSCLK = 0, + IAXXX_INT_OSC = 9, + IAXXX_EXT_OSC = 11, +}; struct iaxxx_plugin_info { uint32_t plg_idx; @@ -27,6 +36,7 @@ struct iaxxx_plugin_info { uint32_t block_id; uint32_t inst_id; uint32_t priority; + uint32_t config_id; }; struct iaxxx_plugin_param { uint32_t inst_id; @@ -54,6 +64,23 @@ struct iaxxx_set_event { uint32_t event_enable_mask; uint32_t block_id; }; +struct iaxxx_evt_trigger { + uint16_t src_id; + uint16_t evt_id; + uint32_t src_opaque; +}; +struct iaxxx_evt_read_subscription { + uint16_t src_id; + uint16_t evt_id; + uint16_t dst_id; + uint32_t dst_opaque; +}; +struct iaxxx_evt_retrieve_notification { + uint16_t src_id; + uint16_t evt_id; + uint32_t src_opaque; + uint32_t dst_opaque; +}; struct iaxxx_evt_info { uint16_t src_id; uint16_t event_id; @@ -64,6 +91,10 @@ struct iaxxx_get_event { uint16_t event_id; uint32_t data; }; +struct iaxxx_pll_clk_data { + uint32_t clk_src; + uint32_t clk_val; +}; struct iaxxx_pkg_mgmt_info { char pkg_name[NAME_MAX_SIZE]; uint32_t pkg_id; @@ -118,6 +149,32 @@ struct iaxxx_plugin_endpoint_status_info { uint8_t op_sample_rate; uint16_t op_frame_length; }; +struct iaxxx_plugin_get_package_version { + uint8_t inst_id; + char version[IAXXX_PACKAGE_VER_STR_SIZE_MAX]; + uint32_t len; +}; +struct iaxxx_plugin_get_plugin_version { + uint8_t inst_id; + char version[IAXXX_PLUGIN_VER_STR_SIZE_MAX]; + uint32_t len; +}; +struct iaxxx_plugin_endpoint_timestamps { + uint8_t proc_id; + uint64_t timestamps[IAXXX_MAX_PLUGIN_ENDPOINTS]; +}; +struct iaxxx_proc_execution_status { + uint8_t proc_id; + uint32_t status; +}; +struct iaxxx_sys_versions { + uint32_t app_ver_num; + char app_ver_str[IAXXX_MAX_VER_STR_SIZE]; + uint32_t app_ver_str_len; + uint32_t rom_ver_num; + char rom_ver_str[IAXXX_MAX_VER_STR_SIZE]; + uint32_t rom_ver_str_len; +}; #define IAXXX_IOCTL_MAGIC 'I' #define ODSP_PLG_CREATE _IO(IAXXX_IOCTL_MAGIC, 0x11) #define ODSP_PLG_RESET _IO(IAXXX_IOCTL_MAGIC, 0x12) @@ -141,4 +198,15 @@ struct iaxxx_plugin_endpoint_status_info { #define ODSP_PLG_SET_PARAM_BLK_WITH_ACK _IO(IAXXX_IOCTL_MAGIC, 0x24) #define ODSP_PLG_GET_STATUS_INFO _IO(IAXXX_IOCTL_MAGIC, 0x25) #define ODSP_PLG_GET_ENDPOINT_STATUS _IO(IAXXX_IOCTL_MAGIC, 0x26) +#define ODSP_EVENT_TRIGGER _IO(IAXXX_IOCTL_MAGIC, 0x27) +#define ODSP_EVENT_READ_SUBSCRIPTION _IO(IAXXX_IOCTL_MAGIC, 0x28) +#define ODSP_EVENT_RETRIEVE_NOTIFICATION _IO(IAXXX_IOCTL_MAGIC, 0x29) +#define ODSP_PLG_GET_PACKAGE_VERSION _IO(IAXXX_IOCTL_MAGIC, 0x2A) +#define ODSP_PLG_GET_PLUGIN_VERSION _IO(IAXXX_IOCTL_MAGIC, 0x2B) +#define ODSP_SET_MPLL_SRC _IO(IAXXX_IOCTL_MAGIC, 0x2C) +#define ODSP_EVENT_RESET_READ_INDEX _IO(IAXXX_IOCTL_MAGIC, 0x2D) +#define ODSP_PLG_GET_ENDPOINT_TIMESTAMPS _IO(IAXXX_IOCTL_MAGIC, 0x2E) +#define ODSP_GET_PROC_EXECUTION_STATUS _IO(IAXXX_IOCTL_MAGIC, 0x2F) +#define ODSP_GET_SYS_VERSIONS _IO(IAXXX_IOCTL_MAGIC, 0x30) +#define ODSP_GET_SYS_DEVICE_ID _IO(IAXXX_IOCTL_MAGIC, 0x31) #endif diff --git a/iaxxx-sysid-defs.h b/iaxxx-sysid-defs.h index 69858c6..3cbb7d0 100644 --- a/iaxxx-sysid-defs.h +++ b/iaxxx-sysid-defs.h @@ -76,6 +76,7 @@ enum sysid_driver_type_e { IAXXX_SYSID_DRIVER_TYPE_MAC, IAXXX_SYSID_DRIVER_TYPE_BQ27425, IAXXX_SYSID_DRIVER_TYPE_SENSOR, + IAXXX_SYSID_DRIVER_TYPE_FLICKER, IAXXX_SYSID_DRIVER_TYPE_DMA_STRM, IAXXX_SYSID_DRIVER_TYPE_CPUSTRMDRV, IAXXX_SYSID_DRIVER_TYPE_NUM, @@ -164,8 +165,8 @@ enum sysid_dir_e { #define IAXXX_SYSID_MASK_SENSOR_EP_INDEX (0x001F) #define IAXXX_SYSID_POS_DEBUG_PROC_ID (9) #define IAXXX_SYSID_MASK_DEBUG_PROC_ID (0x0E00) -#define IAXXX_SYSID_POS_DEBUG_TYPE_DIR (6) -#define IAXXX_SYSID_MASK_DEBUG_TYPE_DIR (0x01C0) +#define IAXXX_SYSID_POS_DEBUG_TYPE (6) +#define IAXXX_SYSID_MASK_DEBUG_TYPE (0x01C0) #define IAXXX_SYSID_POS_DEBUG_EP_DIR (5) #define IAXXX_SYSID_MASK_DEBUG_EP_DIR (0x0020) #define IAXXX_SYSID_POS_DEBUG_EP_INDEX (0) @@ -176,7 +177,8 @@ enum sysid_dir_e { #define IAXXX_SYSID_MASK_DEVICE_ID (0x0FC0) #define IAXXX_SYSID_POS_DEVICE_INST (0) #define IAXXX_SYSID_MASK_DEVICE_INST (0x003F) -#define IAXXX_SYSID_GET_RESOURCE_TYPE(id) (((id) & IAXXX_SYSID_MASK_RESOURCE_TYPE) >> IAXXX_SYSID_POS_RESOURCE_TYPE) +#define IAXXX_SYSID_GET_RESOURCE_TYPE(id) \ +(((id) & IAXXX_SYSID_MASK_RESOURCE_TYPE) >> IAXXX_SYSID_POS_RESOURCE_TYPE) #define IAXXX_SYSID_IS_SPECIAL(id) (IAXXX_SYSID_GET_RESOURCE_TYPE(id) == IAXXX_SYSID_RESOURCE_TYPE_SPECIAL) #define IAXXX_SYSID_IS_DRIVER(id) (IAXXX_SYSID_GET_RESOURCE_TYPE(id) == IAXXX_SYSID_RESOURCE_TYPE_DRIVER) #define IAXXX_SYSID_IS_DEVICE(id) (IAXXX_SYSID_GET_RESOURCE_TYPE(id) == IAXXX_SYSID_RESOURCE_TYPE_DEVICE) @@ -190,70 +192,103 @@ enum sysid_dir_e { #define IAXXX_SYSID_IS_DEBUG(id) (IAXXX_SYSID_GET_RESOURCE_TYPE(id) == IAXXX_SYSID_RESOURCE_TYPE_DEBUG) #define IAXXX_SYSID_IS_HOST(id) ((IAXXX_SYSID_IS_SPECIAL(id)) && (IAXXX_SYSID_GET_SPECIAL_TYPE(id) == IAXXX_SYSID_SPECIAL_TYPE_HOST)) #define IAXXX_SYSID_IS_FILE(id) (IAXXX_SYSID_GET_RESOURCE_TYPE(id) == IAXXX_SYSID_RESOURCE_TYPE_FILE) -#define IAXXX_SYSID_GEN_SPECIAL_SYSID(type,index) (((IAXXX_SYSID_RESOURCE_TYPE_SPECIAL << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((type) << IAXXX_SYSID_POS_SPECIAL_TYPE) & IAXXX_SYSID_MASK_SPECIAL_TYPE) | (((index) << IAXXX_SYSID_POS_SPECIAL_INST_INDEX) & IAXXX_SYSID_MASK_SPECIAL_INST_INDEX)) -#define IAXXX_SYSID_GET_SPECIAL_TYPE(sysId) (((sysId) & IAXXX_SYSID_MASK_SPECIAL_TYPE) >> IAXXX_SYSID_POS_SPECIAL_TYPE) +#define IAXXX_SYSID_GEN_SPECIAL_SYSID(type,index) \ +(((IAXXX_SYSID_RESOURCE_TYPE_SPECIAL << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | \ +(((type) << IAXXX_SYSID_POS_SPECIAL_TYPE) & IAXXX_SYSID_MASK_SPECIAL_TYPE) | \ +(((index) << IAXXX_SYSID_POS_SPECIAL_INST_INDEX) & IAXXX_SYSID_MASK_SPECIAL_INST_INDEX)) +#define IAXXX_SYSID_GET_SPECIAL_TYPE(sysId) \ +(((sysId) & IAXXX_SYSID_MASK_SPECIAL_TYPE) >> IAXXX_SYSID_POS_SPECIAL_TYPE) #define IAXXX_SYSID_GET_SPECIAL_INST_INDEX(sysId) (((sysId) & IAXXX_SYSID_MASK_SPECIAL_INST_INDEX) >> IAXXX_SYSID_POS_SPECIAL_INST_INDEX) #define IAXXX_SYSID_GET_HOST_ID(sysId) IAXXX_SYSID_GET_SPECIAL_INST_INDEX(sysId) -#define IAXXX_SYSID_GEN_DRIVER_SYSID(type,index) (((IAXXX_SYSID_RESOURCE_TYPE_DRIVER << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((type) << IAXXX_SYSID_POS_DRIVER_TYPE) & IAXXX_SYSID_MASK_DRIVER_TYPE) | (((index) << IAXXX_SYSID_POS_DRIVER_INST_INDEX) & IAXXX_SYSID_MASK_DRIVER_INST_INDEX)) -#define IAXXX_SYSID_GET_DRIVER_TYPE(sysId) (((sysId) & IAXXX_SYSID_MASK_DRIVER_TYPE) >> IAXXX_SYSID_POS_DRIVER_TYPE) +#define IAXXX_SYSID_GEN_DRIVER_SYSID(type,index) \ +(((IAXXX_SYSID_RESOURCE_TYPE_DRIVER << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | \ +(((type) << IAXXX_SYSID_POS_DRIVER_TYPE) & IAXXX_SYSID_MASK_DRIVER_TYPE) | \ +(((index) << IAXXX_SYSID_POS_DRIVER_INST_INDEX) & IAXXX_SYSID_MASK_DRIVER_INST_INDEX)) +#define IAXXX_SYSID_GET_DRIVER_TYPE(sysId) \ +(((sysId) & IAXXX_SYSID_MASK_DRIVER_TYPE) >> IAXXX_SYSID_POS_DRIVER_TYPE) #define IAXXX_SYSID_GET_DRIVER_INST_INDEX(sysId) (((sysId) & IAXXX_SYSID_MASK_DRIVER_INST_INDEX) >> IAXXX_SYSID_POS_DRIVER_INST_INDEX) -#define IAXXX_SYSID_GEN_MODULE_SYSID(procId,modType,modInst) (((IAXXX_SYSID_RESOURCE_TYPE_MODULE << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((procId) << IAXXX_SYSID_POS_MODULE_PROC_ID) & IAXXX_SYSID_MASK_MODULE_PROC_ID) | (((modType) << IAXXX_SYSID_POS_MODULE_TYPE) & IAXXX_SYSID_MASK_MODULE_TYPE) | (((modInst) << IAXXX_SYSID_POS_MODULE_INST) & IAXXX_SYSID_MASK_MODULE_INST)) -#define IAXXX_SYSID_GET_MODULE_PROC_ID(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_MODULE_PROC_ID) >> IAXXX_SYSID_POS_MODULE_PROC_ID) +#define IAXXX_SYSID_GEN_MODULE_SYSID(procId,modType,modInst) \ +(((IAXXX_SYSID_RESOURCE_TYPE_MODULE << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | \ +(((procId) << IAXXX_SYSID_POS_MODULE_PROC_ID) & IAXXX_SYSID_MASK_MODULE_PROC_ID) | \ +(((modType) << IAXXX_SYSID_POS_MODULE_TYPE) & IAXXX_SYSID_MASK_MODULE_TYPE) | \ +(((modInst) << IAXXX_SYSID_POS_MODULE_INST) & IAXXX_SYSID_MASK_MODULE_INST)) +#define IAXXX_SYSID_GET_MODULE_PROC_ID(sysId) (((sysId) & IAXXX_SYSID_MASK_MODULE_PROC_ID) >> IAXXX_SYSID_POS_MODULE_PROC_ID) #define IAXXX_SYSID_GET_MODULE_TYPE(sysId) \ (((sysId) & IAXXX_SYSID_MASK_MODULE_TYPE) >> IAXXX_SYSID_POS_MODULE_TYPE) #define IAXXX_SYSID_GET_MODULE_INST(sysId) \ (((sysId) & IAXXX_SYSID_MASK_MODULE_INST) >> IAXXX_SYSID_POS_MODULE_INST) #define IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST (0x001F) -#define IAXXX_SYSID_GEN_PLUGIN_SYSID(pluginId,dir,index) (((IAXXX_SYSID_RESOURCE_TYPE_PLUGIN << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((pluginId) << IAXXX_SYSID_POS_PLUGIN_ID) & IAXXX_SYSID_MASK_PLUGIN_ID) | (((dir) << IAXXX_SYSID_POS_PLUGIN_EP_DIR) & IAXXX_SYSID_MASK_PLUGIN_EP_DIR) | (((index) << IAXXX_SYSID_POS_PLUGIN_EP_INDEX) & IAXXX_SYSID_MASK_PLUGIN_EP_INDEX)) +#define IAXXX_SYSID_GEN_PLUGIN_SYSID(pluginId,dir,index) \ +(((IAXXX_SYSID_RESOURCE_TYPE_PLUGIN << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | \ +(((pluginId) << IAXXX_SYSID_POS_PLUGIN_ID) & IAXXX_SYSID_MASK_PLUGIN_ID) | \ +(((dir) << IAXXX_SYSID_POS_PLUGIN_EP_DIR) & IAXXX_SYSID_MASK_PLUGIN_EP_DIR) | \ +(((index) << IAXXX_SYSID_POS_PLUGIN_EP_INDEX) & IAXXX_SYSID_MASK_PLUGIN_EP_INDEX)) #define IAXXX_SYSID_GET_PLUGIN_ID(sysId) (((sysId) & IAXXX_SYSID_MASK_PLUGIN_ID) >> IAXXX_SYSID_POS_PLUGIN_ID) -#define IAXXX_SYSID_GET_PLUGIN_EP_DIR(sysId) (((sysId) & IAXXX_SYSID_MASK_PLUGIN_EP_DIR) >> IAXXX_SYSID_POS_PLUGIN_EP_DIR) +#define IAXXX_SYSID_GET_PLUGIN_EP_DIR(sysId) \ +(((sysId) & IAXXX_SYSID_MASK_PLUGIN_EP_DIR) >> IAXXX_SYSID_POS_PLUGIN_EP_DIR) #define IAXXX_SYSID_GET_PLUGIN_EP_INDEX(sysId) (((sysId) & IAXXX_SYSID_MASK_PLUGIN_EP_INDEX) >> IAXXX_SYSID_POS_PLUGIN_EP_INDEX) #define IAXXX_SYSID_INDEX_VALUE_CHANNEL (0x001F) -#define IAXXX_SYSID_GEN_CHANNEL_SYSID(channelId,dir,index) (((IAXXX_SYSID_RESOURCE_TYPE_CHANNEL << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((channelId) << IAXXX_SYSID_POS_CHANNEL_ID) & IAXXX_SYSID_MASK_CHANNEL_ID) | (((dir) << IAXXX_SYSID_POS_CHANNEL_EP_DIR) & IAXXX_SYSID_MASK_CHANNEL_EP_DIR) | (((index) << IAXXX_SYSID_POS_CHANNEL_EP_INDEX) & IAXXX_SYSID_MASK_CHANNEL_EP_INDEX)) -#define IAXXX_SYSID_GET_CHANNEL_ID(sysId) (((sysId) & IAXXX_SYSID_MASK_CHANNEL_ID) >> IAXXX_SYSID_POS_CHANNEL_ID) -#define IAXXX_SYSID_GET_CHANNEL_EP_DIR(sysId) (((sysId) & IAXXX_SYSID_MASK_CHANNEL_EP_DIR) >> IAXXX_SYSID_POS_CHANNEL_EP_DIR) -#define IAXXX_SYSID_GET_CHANNEL_EP_INDEX(sysId) (((sysId) & IAXXX_SYSID_MASK_CHANNEL_EP_INDEX) >> IAXXX_SYSID_POS_CHANNEL_EP_INDEX) +#define IAXXX_SYSID_GEN_CHANNEL_SYSID(channelId,dir,index) \ +(((IAXXX_SYSID_RESOURCE_TYPE_CHANNEL << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | \ +(((channelId) << IAXXX_SYSID_POS_CHANNEL_ID) & IAXXX_SYSID_MASK_CHANNEL_ID) | \ +(((dir) << IAXXX_SYSID_POS_CHANNEL_EP_DIR) & IAXXX_SYSID_MASK_CHANNEL_EP_DIR) | \ +(((index) << IAXXX_SYSID_POS_CHANNEL_EP_INDEX) & IAXXX_SYSID_MASK_CHANNEL_EP_INDEX)) +#define IAXXX_SYSID_GET_CHANNEL_ID(sysId) \ +(((sysId) & IAXXX_SYSID_MASK_CHANNEL_ID) >> IAXXX_SYSID_POS_CHANNEL_ID) +#define IAXXX_SYSID_GET_CHANNEL_EP_DIR(sysId) \ +(((sysId) & IAXXX_SYSID_MASK_CHANNEL_EP_DIR) >> IAXXX_SYSID_POS_CHANNEL_EP_DIR) +#define IAXXX_SYSID_GET_CHANNEL_EP_INDEX(sysId) \ +(((sysId) & IAXXX_SYSID_MASK_CHANNEL_EP_INDEX) >> IAXXX_SYSID_POS_CHANNEL_EP_INDEX) #define IAXXX_SYSID_INDEX_VALUE_TUNNEL (0x001F) -#define IAXXX_SYSID_GEN_TUNNEL_SYSID(tunnelId,dir,index) (((IAXXX_SYSID_RESOURCE_TYPE_TUNNEL << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((tunnelId) << IAXXX_SYSID_POS_TUNNEL_ID) & IAXXX_SYSID_MASK_TUNNEL_ID) | (((dir) << IAXXX_SYSID_POS_TUNNEL_EP_DIR) & IAXXX_SYSID_MASK_TUNNEL_EP_DIR) | (((index) << IAXXX_SYSID_POS_TUNNEL_EP_INDEX) & IAXXX_SYSID_MASK_TUNNEL_EP_INDEX)) +#define IAXXX_SYSID_GEN_TUNNEL_SYSID(tunnelId,dir,index) \ +(((IAXXX_SYSID_RESOURCE_TYPE_TUNNEL << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | \ +(((tunnelId) << IAXXX_SYSID_POS_TUNNEL_ID) & IAXXX_SYSID_MASK_TUNNEL_ID) | \ +(((dir) << IAXXX_SYSID_POS_TUNNEL_EP_DIR) & IAXXX_SYSID_MASK_TUNNEL_EP_DIR) | \ +(((index) << IAXXX_SYSID_POS_TUNNEL_EP_INDEX) & IAXXX_SYSID_MASK_TUNNEL_EP_INDEX)) #define IAXXX_SYSID_GET_TUNNEL_ID(sysId) \ (((sysId) & IAXXX_SYSID_MASK_TUNNEL_ID) >> IAXXX_SYSID_POS_TUNNEL_ID) -#define IAXXX_SYSID_GET_TUNNEL_EP_DIR(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_TUNNEL_EP_DIR) >> IAXXX_SYSID_POS_TUNNEL_EP_DIR) +#define IAXXX_SYSID_GET_TUNNEL_EP_DIR(sysId) (((sysId) & IAXXX_SYSID_MASK_TUNNEL_EP_DIR) >> IAXXX_SYSID_POS_TUNNEL_EP_DIR) #define IAXXX_SYSID_GET_TUNNEL_EP_INDEX(sysId) (((sysId) & IAXXX_SYSID_MASK_TUNNEL_EP_INDEX) >> IAXXX_SYSID_POS_TUNNEL_EP_INDEX) #define IAXXX_SYSID_GEN_BT_SYSID(btId,dir,index) (((IAXXX_SYSID_RESOURCE_TYPE_BT << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((btId) << IAXXX_SYSID_POS_BT_ID) & IAXXX_SYSID_MASK_BT_ID) | (((dir) << IAXXX_SYSID_POS_BT_EP_DIR) & IAXXX_SYSID_MASK_BT_EP_DIR) | (((index) << IAXXX_SYSID_POS_BT_EP_INDEX) & IAXXX_SYSID_MASK_BT_EP_INDEX)) -#define IAXXX_SYSID_GET_BT_ID(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_BT_ID) >> IAXXX_SYSID_POS_BT_ID) +#define IAXXX_SYSID_GET_BT_ID(sysId) (((sysId) & IAXXX_SYSID_MASK_BT_ID) >> IAXXX_SYSID_POS_BT_ID) #define IAXXX_SYSID_GET_BT_EP_DIR(sysId) \ (((sysId) & IAXXX_SYSID_MASK_BT_EP_DIR) >> IAXXX_SYSID_POS_BT_EP_DIR) #define IAXXX_SYSID_GET_BT_EP_INDEX(sysId) \ -{ ((sysId) & IAXXX_SYSID_MASK_BT_EP_INDEX) >> IAXXX_SYSID_POS_BT_EP_INDEX) } -#define IAXXX_SYSID_GEN_FILE_SYSID(fileId,dir,index) (((IAXXX_SYSID_RESOURCE_TYPE_FILE << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((fileId) << IAXXX_SYSID_POS_FILE_ID) & IAXXX_SYSID_MASK_FILE_ID) | (((dir) << IAXXX_SYSID_POS_FILE_EP_DIR) & IAXXX_SYSID_MASK_FILE_EP_DIR) | (((index) << IAXXX_SYSID_POS_FILE_EP_INDEX) & IAXXX_SYSID_MASK_FILE_EP_INDEX)) +(((sysId) & IAXXX_SYSID_MASK_BT_EP_INDEX) >> IAXXX_SYSID_POS_BT_EP_INDEX) +#define IAXXX_SYSID_GEN_FILE_SYSID(fileId,dir,index) \ +(((IAXXX_SYSID_RESOURCE_TYPE_FILE << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | \ +(((fileId) << IAXXX_SYSID_POS_FILE_ID) & IAXXX_SYSID_MASK_FILE_ID) | \ +(((dir) << IAXXX_SYSID_POS_FILE_EP_DIR) & IAXXX_SYSID_MASK_FILE_EP_DIR) | \ +(((index) << IAXXX_SYSID_POS_FILE_EP_INDEX) & IAXXX_SYSID_MASK_FILE_EP_INDEX)) #define IAXXX_SYSID_GET_FILE_ID(sysId) (((sysId) & IAXXX_SYSID_MASK_FILE_ID) >> IAXXX_SYSID_POS_FILE_ID) -#define IAXXX_SYSID_GET_FILE_EP_DIR(sysId) (((sysId) & IAXXX_SYSID_MASK_FILE_EP_DIR) >> IAXXX_SYSID_POS_FILE_EP_DIR) -#define IAXXX_SYSID_GET_FILE_EP_INDEX(sysId) (((sysId) & IAXXX_SYSID_MASK_FILE_EP_INDEX) >> IAXXX_SYSID_POS_FILE_EP_INDEX) -#define IAXXX_SYSID_GEN_SENSOR_SYSID(sensorId,dir,index) (((IAXXX_SYSID_RESOURCE_TYPE_SENSOR << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((sensorId) << IAXXX_SYSID_POS_SENSOR_ID) & IAXXX_SYSID_MASK_SENSOR_ID) | (((dir) << IAXXX_SYSID_POS_SENSOR_EP_DIR) & IAXXX_SYSID_MASK_SENSOR_EP_DIR) | (((index) << IAXXX_SYSID_POS_SENSOR_EP_INDEX) & IAXXX_SYSID_MASK_SENSOR_EP_INDEX)) -#define IAXXX_SYSID_GET_SENSOR_ID(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_SENSOR_ID) >> IAXXX_SYSID_POS_SENSOR_ID) -#define IAXXX_SYSID_GET_SENSOR_EP_DIR(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_SENSOR_EP_DIR) >> IAXXX_SYSID_POS_SENSOR_EP_DIR) +#define IAXXX_SYSID_GET_FILE_EP_DIR(sysId) \ +(((sysId) & IAXXX_SYSID_MASK_FILE_EP_DIR) >> IAXXX_SYSID_POS_FILE_EP_DIR) +#define IAXXX_SYSID_GET_FILE_EP_INDEX(sysId) \ +(((sysId) & IAXXX_SYSID_MASK_FILE_EP_INDEX) >> IAXXX_SYSID_POS_FILE_EP_INDEX) +#define IAXXX_SYSID_GEN_SENSOR_SYSID(sensorId,dir,index) \ +(((IAXXX_SYSID_RESOURCE_TYPE_SENSOR << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | \ +(((sensorId) << IAXXX_SYSID_POS_SENSOR_ID) & IAXXX_SYSID_MASK_SENSOR_ID) | \ +(((dir) << IAXXX_SYSID_POS_SENSOR_EP_DIR) & IAXXX_SYSID_MASK_SENSOR_EP_DIR) | \ +(((index) << IAXXX_SYSID_POS_SENSOR_EP_INDEX) & IAXXX_SYSID_MASK_SENSOR_EP_INDEX)) +#define IAXXX_SYSID_GET_SENSOR_ID(sysId) (((sysId) & IAXXX_SYSID_MASK_SENSOR_ID) >> IAXXX_SYSID_POS_SENSOR_ID) +#define IAXXX_SYSID_GET_SENSOR_EP_DIR(sysId) (((sysId) & IAXXX_SYSID_MASK_SENSOR_EP_DIR) >> IAXXX_SYSID_POS_SENSOR_EP_DIR) #define IAXXX_SYSID_GET_SENSOR_EP_INDEX(sysId) (((sysId) & IAXXX_SYSID_MASK_SENSOR_EP_INDEX) >> IAXXX_SYSID_POS_SENSOR_EP_INDEX) -#define IAXXX_SYSID_GEN_DEBUG_SYSID(procId,type,dir,index) (((IAXXX_SYSID_RESOURCE_TYPE_DEBUG << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((procId) << IAXXX_SYSID_POS_DEBUG_PROC_ID) & IAXXX_SYSID_MASK_DEBUG_PROC_ID) | (((type) << IAXXX_SYSID_POS_DEBUG_TYPE_DIR) & IAXXX_SYSID_MASK_DEBUG_TYPE_DIR) | (((dir) << IAXXX_SYSID_POS_DEBUG_EP_DIR) & IAXXX_SYSID_MASK_DEBUG_EP_DIR) | (((index) << IAXXX_SYSID_POS_DEBUG_EP_INDEX) & IAXXX_SYSID_MASK_DEBUG_EP_INDEX)) -#define IAXXX_SYSID_GET_DEBUG_CORE(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_DEBUG_PROC_ID) >> IAXXX_SYSID_POS_DEBUG_PROC_ID) -#define IAXXX_SYSID_GET_DEBUG_TYPE(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_DEBUG_TYPE_DIR) >> IAXXX_SYSID_POS_DEBUG_TYPE_DIR) +#define IAXXX_SYSID_GEN_DEBUG_SYSID(procId,type,dir,index) \ +(((IAXXX_SYSID_RESOURCE_TYPE_DEBUG << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | \ +(((procId) << IAXXX_SYSID_POS_DEBUG_PROC_ID) & IAXXX_SYSID_MASK_DEBUG_PROC_ID) | \ +(((type) << IAXXX_SYSID_POS_DEBUG_TYPE) & IAXXX_SYSID_MASK_DEBUG_TYPE) | \ +(((dir) << IAXXX_SYSID_POS_DEBUG_EP_DIR) & IAXXX_SYSID_MASK_DEBUG_EP_DIR) | \ +(((index) << IAXXX_SYSID_POS_DEBUG_EP_INDEX) & IAXXX_SYSID_MASK_DEBUG_EP_INDEX)) +#define IAXXX_SYSID_GET_DEBUG_CORE(sysId) (((sysId) & IAXXX_SYSID_MASK_DEBUG_PROC_ID) >> IAXXX_SYSID_POS_DEBUG_PROC_ID) +#define IAXXX_SYSID_GET_DEBUG_TYPE(sysId) (((sysId) & IAXXX_SYSID_MASK_DEBUG_TYPE) >> IAXXX_SYSID_POS_DEBUG_TYPE) #define IAXXX_SYSID_GET_DEBUG_EP_DIR(sysId) \ (((sysId) & IAXXX_SYSID_MASK_DEBUG_EP_DIR) >> IAXXX_SYSID_POS_DEBUG_EP_DIR) -#define IAXXX_SYSID_GET_DEBUG_EP_INDEX(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_DEBUG_EP_INDEX) >> IAXXX_SYSID_POS_DEBUG_EP_INDEX) +#define IAXXX_SYSID_GET_DEBUG_EP_INDEX(sysId) (((sysId) & IAXXX_SYSID_MASK_DEBUG_EP_INDEX) >> IAXXX_SYSID_POS_DEBUG_EP_INDEX) #define IAXXX_SYSID_GEN_STREAM_SYSID(streamId) (((IAXXX_SYSID_RESOURCE_TYPE_STREAM << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((streamId) << IAXXX_SYSID_POS_STREAM_ID) & IAXXX_SYSID_MASK_STREAM_ID)) #define IAXXX_SYSID_GET_STREAM_ID(sysId) (((sysId) & IAXXX_SYSID_MASK_STREAM_ID) >> IAXXX_SYSID_POS_STREAM_ID) #define IAXXX_SYSID_GEN_DEVICE_SYSID(deviceId,inst) (((IAXXX_SYSID_RESOURCE_TYPE_DEVICE << IAXXX_SYSID_POS_RESOURCE_TYPE) & IAXXX_SYSID_MASK_RESOURCE_TYPE) | (((deviceId) << IAXXX_SYSID_POS_DEVICE_ID) & IAXXX_SYSID_MASK_DEVICE_ID) | (((inst) << IAXXX_SYSID_POS_DEVICE_INST) & IAXXX_SYSID_MASK_DEVICE_INST)) -#define IAXXX_SYSID_GET_DEVICE_ID(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_DEVICE_ID) >> IAXXX_SYSID_POS_DEVICE_ID) -#define IAXXX_SYSID_GET_DEVICE_INST(sysId) \ -(((sysId) & IAXXX_SYSID_MASK_DEVICE_INST) >> IAXXX_SYSID_POS_DEVICE_INST) +#define IAXXX_SYSID_GET_DEVICE_ID(sysId) (((sysId) & IAXXX_SYSID_MASK_DEVICE_ID) >> IAXXX_SYSID_POS_DEVICE_ID) +#define IAXXX_SYSID_GET_DEVICE_INST(sysId) (((sysId) & IAXXX_SYSID_MASK_DEVICE_INST) >> IAXXX_SYSID_POS_DEVICE_INST) #define IAXXX_SYSID_INVALID IAXXX_SYSID_GEN_SPECIAL_SYSID(IAXXX_SYSID_SPECIAL_TYPE_INVALID, 0) #define IAXXX_SYSID_HOST IAXXX_SYSID_GEN_SPECIAL_SYSID(IAXXX_SYSID_SPECIAL_TYPE_HOST, 0) #define IAXXX_SYSID_HOST_0 IAXXX_SYSID_GEN_SPECIAL_SYSID(IAXXX_SYSID_SPECIAL_TYPE_HOST, 0) diff --git a/iaxxx-system-identifiers.h b/iaxxx-system-identifiers.h index 6477742..f4e4269 100644 --- a/iaxxx-system-identifiers.h +++ b/iaxxx-system-identifiers.h @@ -291,16 +291,19 @@ #define IAXXX_SYSID_PLUGIN_15_OUT_EP_13 IAXXX_SYSID_GEN_PLUGIN_SYSID(15, IAXXX_SYSID_DIR_OUT, 13) #define IAXXX_SYSID_PLUGIN_15_OUT_EP_14 IAXXX_SYSID_GEN_PLUGIN_SYSID(15, IAXXX_SYSID_DIR_OUT, 14) #define IAXXX_SYSID_PLUGIN_15_OUT_EP_15 IAXXX_SYSID_GEN_PLUGIN_SYSID(15, IAXXX_SYSID_DIR_OUT, 15) -#define IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE (31) -#define IAXXX_SYSID_PLUGIN_INSTANCE_0 IAXXX_SYSID_GEN_PLUGIN_SYSID(0, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE) -#define IAXXX_SYSID_PLUGIN_INSTANCE_1 IAXXX_SYSID_GEN_PLUGIN_SYSID(1, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE) -#define IAXXX_SYSID_PLUGIN_INSTANCE_2 IAXXX_SYSID_GEN_PLUGIN_SYSID(2, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE) -#define IAXXX_SYSID_PLUGIN_INSTANCE_3 IAXXX_SYSID_GEN_PLUGIN_SYSID(3, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE) -#define IAXXX_SYSID_PLUGIN_INSTANCE_4 IAXXX_SYSID_GEN_PLUGIN_SYSID(4, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE) -#define IAXXX_SYSID_PLUGIN_INSTANCE_5 IAXXX_SYSID_GEN_PLUGIN_SYSID(5, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE) -#define IAXXX_SYSID_PLUGIN_INSTANCE_6 IAXXX_SYSID_GEN_PLUGIN_SYSID(6, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE) -#define IAXXX_SYSID_PLUGIN_INSTANCE_7 IAXXX_SYSID_GEN_PLUGIN_SYSID(7, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE) -#define IAXXX_SYSID_PLUGIN_INSTANCE_8 IAXXX_SYSID_GEN_PLUGIN_SYSID(8, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_EP_INDEX_PLUGIN_INSTANCE) +#define IAXXX_SYSID_PLUGIN_INSTANCE_0 IAXXX_SYSID_GEN_PLUGIN_SYSID(0, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_1 IAXXX_SYSID_GEN_PLUGIN_SYSID(1, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_2 IAXXX_SYSID_GEN_PLUGIN_SYSID(2, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_3 IAXXX_SYSID_GEN_PLUGIN_SYSID(3, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_4 IAXXX_SYSID_GEN_PLUGIN_SYSID(4, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_5 IAXXX_SYSID_GEN_PLUGIN_SYSID(5, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_6 IAXXX_SYSID_GEN_PLUGIN_SYSID(6, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_7 IAXXX_SYSID_GEN_PLUGIN_SYSID(7, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_8 IAXXX_SYSID_GEN_PLUGIN_SYSID(8, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_9 IAXXX_SYSID_GEN_PLUGIN_SYSID(9, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_10 IAXXX_SYSID_GEN_PLUGIN_SYSID(10, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_11 IAXXX_SYSID_GEN_PLUGIN_SYSID(11, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) +#define IAXXX_SYSID_PLUGIN_INSTANCE_12 IAXXX_SYSID_GEN_PLUGIN_SYSID(12, IAXXX_SYSID_DIR_OUT, IAXXX_SYSID_INDEX_VALUE_PLUGIN_INST) enum iaxxx_proc_id_e { IAXXX_NO_PROC, IAXXX_BOSS_ID, diff --git a/iaxxx-systemids.h b/iaxxx-systemids.h index c0f5bb3..e3c3c8d 100644 --- a/iaxxx-systemids.h +++ b/iaxxx-systemids.h @@ -245,10 +245,9 @@ enum iaxxx_device_instance_timer_e { IAXXX_DEV_INSTANCE_TIMER7, IAXXX_DEV_INSTANCE_TIMER_FORCE_SIZE = INT_MAX, }; -enum iaxxx_module_type_e { +enum { IAXXX_MODULE_TYPE_PWR_MGR = 0, IAXXX_MODULE_TYPE_CTRL_MGR, - IAXXX_MODULE_TYPE_SCRIPT_MGR, IAXXX_MODULE_TYPE_EVT_MGR, IAXXX_MODULE_TYPE_PLUGIN_MGR, IAXXX_MODULE_TYPE_FLASH_MGR, @@ -271,15 +270,18 @@ enum iaxxx_module_type_e { IAXXX_MODULE_TYPE_NOTIFY_SERVICE, IAXXX_MODULE_TYPE_SYSTEM_APP, IAXXX_MODULE_TYPE_DEBUG_MONITOR, + IAXXX_MODULE_TYPE_SCRIPT_MGR, IAXXX_MODULE_TYPE_TEMPLATE, IAXXX_MODULE_TYPE_NUM, IAXXX_MODULE_TYPE_MAX = 32, - IAXXX_MODULE_TYPE_FORCE_SIZE = INT_MAX + IAXXX_MODULE_TYPE_FORCE_SIZE = INT_MAX, }; -#define IAXXX_SYSID_MODULE_PWR_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_PWR_MGR, 0)) +#define IAXXX_SYSID_MODULE_PWR_MGR \ +(IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_PWR_MGR, 0)) #define IAXXX_SYSID_MODULE_CTRL_MGR(proc) (IAXXX_SYSID_GEN_MODULE_SYSID(proc, IAXXX_MODULE_TYPE_CTRL_MGR, 0)) #define IAXXX_SYSID_MODULE_SCRIPT_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_SCRIPT_MGR, 0)) -#define IAXXX_SYSID_MODULE_EVT_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_EVT_MGR, 0)) +#define IAXXX_SYSID_MODULE_EVT_MGR \ +(IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_EVT_MGR, 0)) #define IAXXX_SYSID_MODULE_PLUGIN_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_PLUGIN_MGR, 0)) #define IAXXX_SYSID_MODULE_FLASHMGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_FLASH_MGR, 0)) #define IAXXX_SYSID_MODULE_BATTERYMGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_BATTERY_MGR, 0)) @@ -288,20 +290,27 @@ enum iaxxx_module_type_e { #define IAXXX_SYSID_MODULE_PLUGIN_VM(proc,inst) (IAXXX_SYSID_GEN_MODULE_SYSID(proc, IAXXX_MODULE_TYPE_PLUGIN_VM, inst)) #define IAXXX_SYSID_MODULE_CONTROLLER (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_CONTROLLER, 0)) #define IAXXX_SYSID_MODULE_BUTTON_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_BUTTON_MGR, 0)) -#define IAXXX_SYSID_MODULE_LED_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_LED_MGR, 0)) +#define IAXXX_SYSID_MODULE_LED_MGR \ +(IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_LED_MGR, 0)) #define IAXXX_SYSID_MODULE_ROUTES_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_ROUTES_MGR, 0)) -#define IAXXX_SYSID_MODULE_USB_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_USB_MGR, 0)) -#define IAXXX_SYSID_MODULE_BT_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(LOCAL_PROC_ID, IAXXX_MODULE_TYPE_BT_MGR, 0)) -#define IAXXX_SYSID_MODULE_BT_CORE (IAXXX_SYSID_GEN_MODULE_SYSID(LOCAL_PROC_ID, IAXXX_MODULE_TYPE_BT_CORE, 0)) -#define IAXXX_SYSID_MODULE_MIPS_PROFILER(proc) (IAXXX_SYSID_GEN_MODULE_SYSID(proc, IAXXX_MODULE_TYPE_MIPS_PROFILER, 0)) +#define IAXXX_SYSID_MODULE_USB_MGR \ +(IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_USB_MGR, 0)) +#define IAXXX_SYSID_MODULE_BT_MGR \ +(IAXXX_SYSID_GEN_MODULE_SYSID(LOCAL_PROC_ID, IAXXX_MODULE_TYPE_BT_MGR, 0)) +#define IAXXX_SYSID_MODULE_BT_CORE \ +(IAXXX_SYSID_GEN_MODULE_SYSID(LOCAL_PROC_ID, IAXXX_MODULE_TYPE_BT_CORE, 0)) +#define IAXXX_SYSID_MODULE_MIPS_PROFILER(proc) \ +(IAXXX_SYSID_GEN_MODULE_SYSID(proc, IAXXX_MODULE_TYPE_MIPS_PROFILER, 0)) #define IAXXX_SYSID_MODULE_SENSOR_MGR (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_SENSOR_MGR, 0)) #define IAXXX_SYSID_MODULE_SYSTEM_SERVICE (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_SYSTEM_SERVICE, 0)) #define IAXXX_SYSID_MODULE_USB_SERVICE (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_USB_SERVICE, 0)) #define IAXXX_SYSID_MODULE_UI_SERVICE (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_UI_SERVICE, 0)) #define IAXXX_SYSID_MODULE_NOTIFY_SERVICE (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_NOTIFY_SERVICE, 0)) #define IAXXX_SYSID_MODULE_SYSTEM_APP (IAXXX_SYSID_GEN_MODULE_SYSID(LOCAL_PROC_ID, IAXXX_MODULE_TYPE_SYSTEM_APP, 0)) -#define IAXXX_SYSID_MODULE_TEMPLATE (IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_TEMPLATE, 0)) -#define IAXXX_SYSID_MODULE_DEBUG(proc) (IAXXX_SYSID_GEN_MODULE_SYSID(proc, IAXXX_MODULE_TYPE_DEBUG_MONITOR, 0)) +#define IAXXX_SYSID_MODULE_TEMPLATE \ +(IAXXX_SYSID_GEN_MODULE_SYSID(CTRL_PROC_ID, IAXXX_MODULE_TYPE_TEMPLATE, 0)) +#define IAXXX_SYSID_MODULE_DEBUG(proc) \ +(IAXXX_SYSID_GEN_MODULE_SYSID(proc, IAXXX_MODULE_TYPE_DEBUG_MONITOR, 0)) #define IAXXX_SYSID_I2C0 (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_I2C, IAXXX_DEV_INSTANCE_I2C0)) #define IAXXX_SYSID_I2C1 (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_I2C, IAXXX_DEV_INSTANCE_I2C1)) #define IAXXX_SYSID_I2C2 (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_I2C, IAXXX_DEV_INSTANCE_I2C2)) @@ -338,7 +347,8 @@ enum iaxxx_module_type_e { #define IAXXX_SYSID_PCM3 (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_PCM, IAXXX_DEV_INSTANCE_PCM3)) #define IAXXX_SYSID_PCM4 (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_PCM, IAXXX_DEV_INSTANCE_PCM4)) #define IAXXX_SYSID_PCM5 (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_PCM, IAXXX_DEV_INSTANCE_PCM5)) -#define IAXXX_SYSID_SLBUS_D (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_SLIMBUS_DATA, IAXXX_DEV_INSTANCE_SLBUS0)) +#define IAXXX_SYSID_SLBUS_D (IAXXX_SYSID_GEN_DRIVER_SYSID \ +(IAXXX_SYSID_DRIVER_TYPE_SLIMBUS_DATA, IAXXX_DEV_INSTANCE_SLBUS0)) #define IAXXX_SYSID_PDMI0 (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_PDM_IN, IAXXX_DEV_INSTANCE_PDMI0)) #define IAXXX_SYSID_PDMI1 (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_PDM_IN, IAXXX_DEV_INSTANCE_PDMI1)) #define IAXXX_SYSID_PDMI2 (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_PDM_IN, IAXXX_DEV_INSTANCE_PDMI2)) @@ -372,6 +382,7 @@ enum iaxxx_module_type_e { #define IAXXX_SYSID_MAC (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_MAC, IAXXX_DEV_SINGLE_INSTANCE)) #define IAXXX_SYSID_BQ27425DRV (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_BQ27425, IAXXX_DEV_SINGLE_INSTANCE)) #define IAXXX_SYSID_SENSORDRV (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_SENSOR, IAXXX_DEV_SINGLE_INSTANCE)) +#define IAXXX_SYSID_FLICKERDRV (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_FLICKER, IAXXX_DEV_SINGLE_INSTANCE)) #define IAXXX_SYSID_CPUSTRMDRV (IAXXX_SYSID_GEN_DRIVER_SYSID(IAXXX_SYSID_DRIVER_TYPE_CPUSTRMDRV, IAXXX_DEV_SINGLE_INSTANCE)) #define IAXXX_PORT_NUM_INSTANCES (IAXXX_DEV_NUM_INSTANCE_PCM + IAXXX_DEV_NUM_INSTANCE_SLBUS + IAXXX_DEV_NUM_INSTANCE_PDMI + IAXXX_DEV_NUM_INSTANCE_PDMO + IAXXX_DEV_NUM_INSTANCE_DAC + IAXXX_DEV_NUM_INSTANCE_I2S) enum iaxxx_device_instance_button_e { @@ -782,7 +793,7 @@ enum iaxxx_device_instance_input_pin_e { IAXXX_DEV_NUM_INSTANCE_INPUT_PIN, IAXXX_DEV_INSTANCE_INPUT_PIN_FORCE_SIZE = INT_MAX, }; -enum iaxxx_device_instance_output_pin_e { +enum iaxxx_device_instance_output_pin_t { IAXXX_DEV_INSTANCE_OUTPUT_PIN0 = 0, IAXXX_DEV_INSTANCE_OUTPUT_PIN1, IAXXX_DEV_INSTANCE_OUTPUT_PIN2, diff --git a/iaxxx-tunnel-intf.h b/iaxxx-tunnel-intf.h index d7082da..f2f25bc 100644 --- a/iaxxx-tunnel-intf.h +++ b/iaxxx-tunnel-intf.h @@ -69,4 +69,5 @@ enum iaxxx_tunnel_dir_type { #define TUNNEL_UNSUBSCRIBE_META_VQ _IO('K', 0x01c) #define TUNNEL_EVENT_SUBSCRIBE _IOWR('K', 0x01d, struct iaxxx_tnl_evt_info) #define TUNNEL_EVENT_UNSUBSCRIBE _IOWR('K', 0x01e, struct iaxxx_tnl_evt_info) +#define TUNNEL_SET_EVENT_THRESHOLD _IOW('K', 0x021, uint32_t) #endif diff --git a/iaxxx_odsp_hw.c b/iaxxx_odsp_hw.c index 2ac3dad..cece7c4 100644 --- a/iaxxx_odsp_hw.c +++ b/iaxxx_odsp_hw.c @@ -19,7 +19,7 @@ #include <stdlib.h> #include <string.h> #include <errno.h> -#include <cutils/log.h> +#include <log/log.h> #include <sys/ioctl.h> #include <inttypes.h> @@ -29,6 +29,11 @@ #define FUNCTION_ENTRY_LOG ALOGV("Entering %s", __func__); #define FUNCTION_EXIT_LOG ALOGV("Exiting %s", __func__); +#define IAXXX_DEBUG_BLOCK_0_EXEC_STATUS_IDENTIFIER_MASK 0x0000ffff +#define IAXXX_DEBUG_BLOCK_0_EXEC_STATUS_IDENTIFIER_POS 0 +#define IAXXX_DEBUG_BLOCK_0_EXEC_STATUS_TYPE_MASK 0x00070000 +#define IAXXX_DEBUG_BLOCK_0_EXEC_STATUS_TYPE_POS 16 + struct iaxxx_odsp_hw { FILE *dev_node; }; @@ -175,6 +180,102 @@ func_exit: } /** + * Get package version + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * inst_id - Instance ID + * version - Package version string buffer + * len - String buffer size + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_plugin_get_package_version(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint8_t inst_id, char *version, + uint32_t len) +{ + int err = 0; + struct iaxxx_plugin_get_package_version v; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + if (len > sizeof(v.version)) { + ALOGW("%s: WARNING: Too large len %u, limit it to %zu", __func__, len, + sizeof(v.version)); + len = sizeof(v.version); + } + + ALOGV("%s: inst_id %u", __func__, inst_id); + + v.inst_id = inst_id; + v.len = len; + err = ioctl(fileno(odsp_hw_hdl->dev_node), + ODSP_PLG_GET_PACKAGE_VERSION, (unsigned long)&v); + if (err < 0) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } else { + memcpy(version, v.version, len); + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} + +/** + * Get plugin version + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * inst_id - Instance ID + * version - Plugin version string buffer + * len - String buffer size + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_plugin_get_plugin_version(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint8_t inst_id, char *version, + uint32_t len) +{ + int err = 0; + struct iaxxx_plugin_get_plugin_version v; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + if (len > sizeof(v.version)) { + ALOGW("%s: WARNING: Too large len %u, limit it to %zu", __func__, len, + sizeof(v.version)); + len = sizeof(v.version); + } + + ALOGV("%s: inst_id %u", __func__, inst_id); + + v.inst_id = inst_id; + v.len = len; + err = ioctl(fileno(odsp_hw_hdl->dev_node), + ODSP_PLG_GET_PLUGIN_VERSION, (unsigned long)&v); + if (err < 0) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } else { + memcpy(version, v.version, len); + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} + +/** * Create a plugin * * Input - odsp_hw_hdl - Handle to odsp hw structure @@ -183,6 +284,7 @@ func_exit: * pkg_id - Package ID * plg_idx - Plugin Index* * block_id - Block ID + * config_id - Config ID * * Output - 0 on success, on failure < 0 */ @@ -191,7 +293,8 @@ int iaxxx_odsp_plugin_create(struct iaxxx_odsp_hw *odsp_hw_hdl, const uint32_t priority, const uint32_t pkg_id, const uint32_t plg_idx, - const uint32_t block_id) + const uint32_t block_id, + const uint32_t config_id) { int err = 0; struct iaxxx_plugin_info pi; @@ -212,6 +315,7 @@ int iaxxx_odsp_plugin_create(struct iaxxx_odsp_hw *odsp_hw_hdl, pi.block_id = block_id; pi.inst_id = inst_id; pi.priority = priority; + pi.config_id = config_id; err = ioctl(fileno(odsp_hw_hdl->dev_node), ODSP_PLG_CREATE, (unsigned long)&pi); if (err < 0) { @@ -308,7 +412,7 @@ int iaxxx_odsp_plugin_destroy(struct iaxxx_odsp_hw *odsp_hw_hdl, ALOGV("%s: instance id %u, block id %u", __func__, inst_id, block_id); pi.block_id = block_id; - pi.inst_id = inst_id; + pi.inst_id = inst_id; err = ioctl(fileno(odsp_hw_hdl->dev_node), ODSP_PLG_DESTROY, (unsigned long) &pi); if (err < 0) { @@ -424,7 +528,7 @@ int iaxxx_odsp_plugin_reset(struct iaxxx_odsp_hw *odsp_hw_hdl, pi.block_id = block_id; pi.inst_id = inst_id; err = ioctl(fileno(odsp_hw_hdl->dev_node), - ODSP_PLG_DISABLE, (unsigned long)&pi); + ODSP_PLG_RESET, (unsigned long)&pi); if (err < 0) { ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); } @@ -817,6 +921,7 @@ func_exit: * pkg_id - Package ID * plg_idx - Plugin Index* * block_id - Block ID + * config_id - Config ID * * Output - 0 on success, on failure < 0 */ @@ -825,7 +930,8 @@ int iaxxx_odsp_plugin_create_static_package(struct iaxxx_odsp_hw *odsp_hw_hdl, const uint32_t priority, const uint32_t pkg_id, const uint32_t plg_idx, - const uint32_t block_id) + const uint32_t block_id, + const uint32_t config_id) { int err = 0; struct iaxxx_plugin_info pi; @@ -846,6 +952,7 @@ int iaxxx_odsp_plugin_create_static_package(struct iaxxx_odsp_hw *odsp_hw_hdl, pi.block_id = block_id; pi.inst_id = inst_id; pi.priority = priority; + pi.config_id = config_id; err = ioctl(fileno(odsp_hw_hdl->dev_node), ODSP_PLG_CREATE_STATIC_PACKAGE, (unsigned long)&pi); if (err < 0) { @@ -938,7 +1045,7 @@ int iaxxx_odsp_plugin_setevent(struct iaxxx_odsp_hw *odsp_hw_hdl, se.block_id = block_id; se.event_enable_mask = eventEnableMask; - se.inst_id = inst_id; + se.inst_id = inst_id; err = ioctl(fileno(odsp_hw_hdl->dev_node), ODSP_PLG_SET_EVENT, (unsigned long)&se); if (err == -1) { @@ -951,6 +1058,179 @@ func_exit: return err; } +/** + * Trigger an event. This may be most useful when debugging the system, + * but can also be used to trigger simultaneous behavior in entities which + * have subscribed, or to simply provide notifications regarding host status: + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * src_id - SystemId of event source + * evt_id - Id of event + * src_opaque - Source opaque to pass with event notification + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_evt_trigger(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint16_t src_id, + uint16_t evt_id, + uint32_t src_opaque) +{ + int err = 0; + struct iaxxx_evt_trigger et; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + ALOGV("%s: src_id=%u, evt_id=%u, src_opaque=%u", __func__, src_id, evt_id, + src_opaque); + + et.src_id = src_id; + et.evt_id = evt_id; + et.src_opaque = src_opaque; + err = ioctl(fileno(odsp_hw_hdl->dev_node), ODSP_EVENT_TRIGGER, + (unsigned long)&et); + if (err == -1) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} + +/** + * Fetches next event subscription entry from the last read position + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * src_id - System Id of event source + * evt_id - Event Id + * dst_id - System Id of event destination + * dst_opaque - Destination opaque data + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_evt_read_subscription(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint16_t *src_id, + uint16_t *evt_id, + uint16_t *dst_id, + uint32_t *dst_opaque) +{ + int err = 0; + struct iaxxx_evt_read_subscription ers; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + err = ioctl(fileno(odsp_hw_hdl->dev_node), ODSP_EVENT_READ_SUBSCRIPTION, + (unsigned long) &ers); + if (err == -1) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } else { + ALOGV("%s: src_id=%u, evt_id=%u, dst_id=%u, dst_opaque=%u", __func__, + ers.src_id, ers.evt_id, ers.dst_id, ers.dst_opaque); + + *src_id = ers.src_id; + *evt_id = ers.evt_id; + *dst_id = ers.dst_id; + *dst_opaque = ers.dst_opaque; + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} + +/** + * Reset index for retrieving subscription entries + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_evt_reset_read_index(struct iaxxx_odsp_hw *odsp_hw_hdl) +{ + int err = 0; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + err = ioctl(fileno(odsp_hw_hdl->dev_node), ODSP_EVENT_RESET_READ_INDEX, + NULL); + if (err == -1) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} + +/** + * Retrieve an event notification + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * src_id - pointer to uint16_t for reporting SystemId of + * event source + * evt_dd - pointer to uint16_t for reporting Id of event + * src_opaque - pointer to the first parameter of event + * dst_opaque - pointer to the second parameter of event + * This will be destOpaque in case if event is + * subscribed with valid destOpaque otherwise + * it will be used as second parameter. + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_evt_retrieve_notification(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint16_t *src_id, + uint16_t *evt_id, + uint32_t *src_opaque, + uint32_t *dst_opaque) +{ + int err = 0; + struct iaxxx_evt_retrieve_notification ern; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + err = ioctl(fileno(odsp_hw_hdl->dev_node), + ODSP_EVENT_RETRIEVE_NOTIFICATION, (unsigned long)&ern); + if (err == -1) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } else { + ALOGV("%s: src_id=%u, evt_id=%u, src_opaque=%u, dst_opaque=%u", + __func__, ern.src_id, ern.evt_id, ern.src_opaque, ern.dst_opaque); + + *src_id = ern.src_id; + *evt_id = ern.evt_id; + *src_opaque = ern.src_opaque; + *dst_opaque = ern.dst_opaque; + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} + /* Read Plugin Error Info * * Input - odsp_hw_hdl - Handle to odsp hw structure @@ -984,13 +1264,51 @@ int iaxxx_odsp_plugin_read_error(struct iaxxx_odsp_hw *odsp_hw_hdl, ODSP_PLG_READ_PLUGIN_ERROR, (unsigned long)&pei); if (err < 0) { ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } else { + *error_code = pei.error_code; + *error_instance = pei.error_instance; + ALOGV("%s: Plugin error code:%x instance=%d", __func__, + pei.error_code, pei.error_instance); + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} + +/* Read the timestamps of all output endpoint + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * proc_id - Proc id + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_plugin_get_ep_timestamps(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint64_t *timestamps, + uint8_t proc_id) +{ + int err = 0; + struct iaxxx_plugin_endpoint_timestamps pet = { + .proc_id = proc_id + }; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; goto func_exit; } - *error_code = pei.error_code; - *error_instance = pei.error_instance; - ALOGV("%s: Plugin error code:%x instance=%d", - __func__, pei.error_code, pei.error_instance); + ALOGV("%s: Proc id %u", __func__, proc_id); + + err = ioctl(fileno(odsp_hw_hdl->dev_node), + ODSP_PLG_GET_ENDPOINT_TIMESTAMPS, (unsigned long)&pet); + if (err < 0) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } else { + memcpy(timestamps, pet.timestamps, sizeof(pet.timestamps)); + } func_exit: FUNCTION_EXIT_LOG; @@ -1210,3 +1528,200 @@ func_exit: return err; } + +/** + * Set the MPLL clock source and value + * + * Input - odsp_hd_hdl - Handle to odsp hw structure + * clk_source - Clock source, internal or external + * clk_value - Clock value + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_set_mpll_src(struct iaxxx_odsp_hw *odsp_hw_hdl, + const enum iaxxx_pll_source clk_source, + const uint32_t clk_value) +{ + int err = 0; + struct iaxxx_pll_clk_data pll_clk_data; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + pll_clk_data.clk_src = clk_source; + pll_clk_data.clk_val = clk_value; + + err = ioctl(fileno(odsp_hw_hdl->dev_node), ODSP_SET_MPLL_SRC, + (unsigned long)&pll_clk_data); + if (err != 0) { + ALOGE("%s: ERROR: Failed to set the MPLL source with error %s", + __func__, strerror(errno)); + } +func_exit: + FUNCTION_EXIT_LOG; + return err; + +} + +/** + * Returns the execution status of given processor + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * proc_id - Proc id + * status - Execution status of the processor + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_get_proc_execution_status(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint8_t proc_id, + uint32_t *status) +{ + int err = 0; + struct iaxxx_proc_execution_status s = { + .proc_id = proc_id + }; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + ALOGV("%s: Proc id %u", __func__, proc_id); + + err = ioctl(fileno(odsp_hw_hdl->dev_node), + ODSP_GET_PROC_EXECUTION_STATUS, (unsigned long)&s); + if (err < 0) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } else { + uint32_t id, type; + + *status = s.status; + + id = ((*status & IAXXX_DEBUG_BLOCK_0_EXEC_STATUS_IDENTIFIER_MASK) + >> IAXXX_DEBUG_BLOCK_0_EXEC_STATUS_IDENTIFIER_POS); + type = ((*status & IAXXX_DEBUG_BLOCK_0_EXEC_STATUS_TYPE_MASK) + >> IAXXX_DEBUG_BLOCK_0_EXEC_STATUS_TYPE_POS); + switch (type) { + case 0: + ALOGI("%s() Proc %d is running Firmware\n", + __func__, s.proc_id); + break; + case 1: + ALOGI("%s() Proc %d is running ISR %d\n", + __func__, s.proc_id, id); + break; + case 2: + ALOGI("%s() Proc %d is running Package ID %d\n", + __func__, s.proc_id, id); + break; + case 3: + ALOGI("%s() Proc %d is running Plugin inst ID %d\n", + __func__, s.proc_id, id); + break; + default: + break; + } + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} + +/** + * Returns Rom version number, Rom version string + * Application version number, Application version string + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * rom_ver_num - Rom version number + * rom_ver_str - Rom version string + * rom_ver_str_len - Rom version string length + * app_ver_num - App version number + * app_ver_str - App version string + * app_ver_str_len - App version string length + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_get_sys_versions(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint32_t *rom_ver_num, + char *rom_ver_str, + uint32_t rom_ver_str_len, + uint32_t *app_ver_num, + char *app_ver_str, + uint32_t app_ver_str_len) +{ + int err = 0; + struct iaxxx_sys_versions v = { + .app_ver_str_len = + (app_ver_str ? app_ver_str_len : IAXXX_MAX_VER_STR_SIZE), + .rom_ver_str_len = + (rom_ver_str ? rom_ver_str_len : IAXXX_MAX_VER_STR_SIZE) + }; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + err = ioctl(fileno(odsp_hw_hdl->dev_node), + ODSP_GET_SYS_VERSIONS, (unsigned long)&v); + if (err < 0) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } else { + if (rom_ver_num) + *rom_ver_num = v.rom_ver_num; + if (rom_ver_str) + memcpy(rom_ver_str, v.rom_ver_str, v.rom_ver_str_len); + if (app_ver_num) + *app_ver_num = v.app_ver_num; + if (app_ver_str) + memcpy(app_ver_str, v.app_ver_str, v.app_ver_str_len); + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} + +/** + * Returns Device ID + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * device_id - Returned Device ID + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_get_device_id(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint32_t *device_id) +{ + int err = 0; + + FUNCTION_ENTRY_LOG; + + if (odsp_hw_hdl == NULL) { + ALOGE("%s: ERROR: Invalid handle to iaxxx_odsp_hw", __func__); + err = -1; + goto func_exit; + } + + err = ioctl(fileno(odsp_hw_hdl->dev_node), + ODSP_GET_SYS_DEVICE_ID, (unsigned long)device_id); + if (err < 0) { + ALOGE("%s: ERROR: Failed with error %s", __func__, strerror(errno)); + } + +func_exit: + FUNCTION_EXIT_LOG; + return err; +} diff --git a/iaxxx_odsp_hw.h b/iaxxx_odsp_hw.h index 43b0fb8..31840b3 100644 --- a/iaxxx_odsp_hw.h +++ b/iaxxx_odsp_hw.h @@ -81,6 +81,12 @@ struct iaxxx_get_event_info { uint32_t data; }; +enum clock_source { + SYSCLK, + INT_OSC, + EXT_OSC, +}; + /** * Initialize the ODSP HAL * @@ -121,6 +127,32 @@ int iaxxx_odsp_package_unload(struct iaxxx_odsp_hw *odsp_hw_hdl, const uint32_t pkg_id); /** + * Get package version + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * inst_id - Instance ID + * version - Package version string buffer + * len - String buffer size + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_plugin_get_package_version(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint8_t inst_id, char *version, uint32_t len); + +/** + * Get plugin version + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * inst_id - Instance ID + * version - Plugin version string buffer + * len - String buffer size + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_plugin_get_plugin_version(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint8_t inst_id, char *version, uint32_t len); + +/** * Create a plugin * * Input - odsp_hw_hdl - Handle to odsp hw structure @@ -129,6 +161,7 @@ int iaxxx_odsp_package_unload(struct iaxxx_odsp_hw *odsp_hw_hdl, * pkg_id - Package ID * plg_idx - Plugin Index* * block_id - Block ID + * config_id - Config ID * * Output - 0 on success, on failure < 0 */ @@ -137,7 +170,8 @@ int iaxxx_odsp_plugin_create(struct iaxxx_odsp_hw *odsp_hw_hdl, const uint32_t priority, const uint32_t pkg_id, const uint32_t plg_idx, - const uint32_t block_id); + const uint32_t block_id, + const uint32_t config_id); /** * Set the creation configuration on a plugin @@ -321,6 +355,71 @@ int iaxxx_odsp_evt_unsubscribe(struct iaxxx_odsp_hw *odsp_hw_hdl, const uint16_t src_id, const uint16_t event_id, const uint16_t dst_id); + +/** + * Trigger an event. This may be most useful when debugging the system, + * but can also be used to trigger simultaneous behavior in entities which + * have subscribed, or to simply provide notifications regarding host status: + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * src_id - SystemId of event source + * evt_id - Id of event + * src_opaque - Source opaque to pass with event notification + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_evt_trigger(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint16_t src_id, + uint16_t evt_id, + uint32_t src_opaque); + +/** + * Fetches next event subscription entry from the last read position + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * src_id - System Id of event source + * evt_id - Event Id + * dst_id - System Id of event destination + * dst_opaque - Destination opaque data + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_evt_read_subscription(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint16_t *src_id, + uint16_t *evt_id, + uint16_t *dst_id, + uint32_t *dst_opaque); + +/** + * Reset index for retrieving subscription entries + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_evt_reset_read_index(struct iaxxx_odsp_hw *odsp_hw_hdl); + +/** + * Retrieve an event notification + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * src_id - pointer to uint16_t for reporting SystemId of + * event source + * evt_dd - pointer to uint16_t for reporting Id of event + * src_opaque - pointer to the first parameter of event + * dst_opaque - pointer to the second parameter of event + * This will be destOpaque in case if event is + * subscribed with valid destOpaque otherwise + * it will be used as second parameter. + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_evt_retrieve_notification(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint16_t *src_id, + uint16_t *evt_id, + uint32_t *src_opaque, + uint32_t *dst_opaque); + /** * Retrieve an event * @@ -341,6 +440,7 @@ int iaxxx_odsp_evt_getevent(struct iaxxx_odsp_hw *odsp_hw_hdl, * pkg_id - Package ID * plg_idx - Plugin Index* * block_id - Block ID + * config_id - Config ID * * Output - 0 on success, on failure < 0 */ @@ -349,7 +449,8 @@ int iaxxx_odsp_plugin_create_static_package(struct iaxxx_odsp_hw *odsp_hw_hdl, const uint32_t priority, const uint32_t pkg_id, const uint32_t plg_idx, - const uint32_t block_id); + const uint32_t block_id, + const uint32_t config_id); /** * Get a parameter block from a plugin @@ -399,6 +500,17 @@ int iaxxx_odsp_plugin_read_error(struct iaxxx_odsp_hw *odsp_hw_hdl, uint32_t *error_code, uint8_t *error_instance); +/* Read the timestamps of all output endpoint + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * proc_id - Proc ID + * timestamps - The timestamps array(with 16 elements count) + * to be filled. + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_plugin_get_ep_timestamps(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint64_t *timestamps, uint8_t proc_id); /** * Set a parameter block on a plugin and get ack to @@ -463,6 +575,64 @@ int iaxxx_odsp_plugin_get_endpoint_status( const uint8_t direction, struct iaxxx_plugin_endpoint_status_data *plugin_ep_status_data); +/** + * Set the MPLL clock source and value + * + * Input - odsp_hd_hdl - Handle to odsp hw structure + * clk_source - Clock source, internal or external + * clk_value - Clock value + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_set_mpll_src(struct iaxxx_odsp_hw *odsp_hw_hdl, + const enum iaxxx_pll_source clk_source, + const uint32_t clk_value); + +/** + * Returns the execution status of given processor + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * proc_id - Proc id + * status - Execution status of the processor + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_get_proc_execution_status(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint8_t proc_id, uint32_t *status); + +/** + * Returns Rom version number, Rom version string + * Application version number, Application version string + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * rom_ver_num - Rom version number + * rom_ver_str - Rom version string + * rom_ver_str_len - Rom version string length + * app_ver_num - App version number + * app_ver_str - App version string + * app_ver_str_len - App version string length + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_get_sys_versions(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint32_t *rom_ver_num, + char *rom_ver_str, + uint32_t rom_ver_str_len, + uint32_t *app_ver_num, + char *app_ver_str, + uint32_t app_ver_str_len); + +/** + * Returns Device ID + * + * Input - odsp_hw_hdl - Handle to odsp hw structure + * device_id - Returned Device ID + * + * Output - 0 on success, on failure < 0 + */ +int iaxxx_odsp_get_device_id(struct iaxxx_odsp_hw *odsp_hw_hdl, + uint32_t *device_id); + #if __cplusplus } // extern "C" #endif diff --git a/sound_trigger_hw_iaxxx.c b/sound_trigger_hw_iaxxx.c index c1c2eb1..e08886a 100644 --- a/sound_trigger_hw_iaxxx.c +++ b/sound_trigger_hw_iaxxx.c @@ -24,7 +24,7 @@ #include <pthread.h> #include <sys/ioctl.h> #include <sys/prctl.h> -#include <cutils/log.h> +#include <log/log.h> #include <cutils/uevent.h> #include <cutils/properties.h> #include <math.h> @@ -56,9 +56,14 @@ #define ENTITY_KW_ID (2) #define USELESS_KW_ID (999) +#define CVQ_ENDPOINT (IAXXX_SYSID_PLUGIN_1_OUT_EP_0) +#define COMMON_8SEC_BUF_ENDPOINT (IAXXX_SYSID_PLUGIN_1_OUT_EP_1) +//#define NEWSIQ_MUSICIQ_BUF_ENDPOINT (IAXXX_SYSID_PLUGIN_11_OUT_EP_0) + #define IAXXX_VQ_EVENT_STR "IAXXX_VQ_EVENT" #define IAXXX_RECOVERY_EVENT_STR "IAXXX_RECOVERY_EVENT" #define IAXXX_FW_DWNLD_SUCCESS_STR "IAXXX_FW_DWNLD_SUCCESS" +#define IAXXX_FW_CRASH_EVENT_STR "IAXXX_CRASH_EVENT" #define CARD_NAME "iaxxx" #define SOUND_TRIGGER_MIXER_PATH_BASE "/vendor/etc/sound_trigger_mixer_paths" @@ -74,10 +79,6 @@ #define ADNC_STRM_LIBRARY_PATH "/vendor/lib/hw/adnc_strm.primary.default.so" #endif -#define HOTWORD_MODEL (0) -#define AMBIENT_MODEL (1) -#define ENTITY_MODEL (2) - static const struct sound_trigger_properties hw_properties = { "Knowles Electronics", // implementor "Continous VoiceQ", // description @@ -143,6 +144,9 @@ struct knowles_sound_trigger_device { bool is_mic_route_enabled; bool is_music_playing; bool is_bargein_route_enabled; + bool is_internal_osc_switched; + bool is_buffer_package_loaded; + bool is_st_hal_ready; unsigned int current_enable; @@ -249,6 +253,19 @@ static bool is_any_model_active(struct knowles_sound_trigger_device *stdev) { return true; } +static bool is_any_model_loaded(struct knowles_sound_trigger_device *stdev) { + int i = 0; + for (i = 0; i < MAX_MODELS; i++) { + if (stdev->models[i].is_loaded == true) { + break; + } + } + if (i == MAX_MODELS) { + return false; + } else + return true; +} + static void reg_hal_event_session( struct sound_trigger_recognition_config *config, sound_model_handle_t handle) @@ -394,6 +411,200 @@ static void stdev_close_term_sock(struct knowles_sound_trigger_device *stdev) } } +static int switch_internal_osc(struct knowles_sound_trigger_device *stdev) +{ + int err = 0; + if (stdev->is_internal_osc_switched == false) { + err = setup_mpll_clock_source(stdev->odsp_hdl, + IAXXX_INT_OSC, 0); + if (err != 0) { + ALOGE("%s: ERROR Failed to set internal oscillator", + __func__); + return err; + } + stdev->is_internal_osc_switched = true; + } + return err; +} + +static int setup_package(struct knowles_sound_trigger_device *stdev, + struct model_info *model) +{ + int err = 0; + + if (check_uuid_equality(model->uuid, stdev->chre_model_uuid)) { + if (!(stdev->current_enable & CHRE_MASK)) { + err = setup_chre_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to load CHRE package"); + goto exit; + } + } + stdev->current_enable = stdev->current_enable | CHRE_MASK; + } else if (check_uuid_equality(model->uuid, stdev->hotword_model_uuid)) { + if (!(stdev->current_enable & PLUGIN1_MASK)) { + err = setup_hotword_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to load Hotword package"); + goto exit; + } + } + err = write_model(stdev->odsp_hdl, model->data, model->data_sz, + model->kw_id); + if (err != 0) { + ALOGE("Failed to write Hotword model"); + goto exit; + } + + //setup model state. + stdev->current_enable = stdev->current_enable | HOTWORD_MASK; + err = set_hotword_state(stdev->odsp_hdl, stdev->current_enable); + if (err != 0) { + ALOGE("Failed to set Hotword state"); + goto exit; + } + } else if (check_uuid_equality(model->uuid, stdev->ambient_model_uuid)) { + if (!(stdev->current_enable & PLUGIN2_MASK)) { + err = setup_ambient_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to load Ambient package"); + goto exit; + } + } else { + // tear down plugin2 for writing new model data. + err = tear_ambient_state(stdev->odsp_hdl, + stdev->current_enable); + } + err = write_model(stdev->odsp_hdl, model->data, + model->data_sz, model->kw_id); + if (err != 0) { + ALOGE("Failed to write Ambient model"); + goto exit; + } + + //setup model state. + stdev->current_enable = stdev->current_enable | AMBIENT_MASK; + err = set_ambient_state(stdev->odsp_hdl, stdev->current_enable); + if (err != 0) { + ALOGE("Failed to set Ambient state"); + goto exit; + } + + } else if (check_uuid_equality(model->uuid, stdev->entity_model_uuid)) { + if (!(stdev->current_enable & PLUGIN2_MASK)) { + err = setup_ambient_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to load Ambient package"); + goto exit; + } + } else { + // tear down plugin2 for writing new model data. + err = tear_ambient_state(stdev->odsp_hdl, + stdev->current_enable); + } + err = write_model(stdev->odsp_hdl, model->data, + model->data_sz, model->kw_id); + if (err != 0) { + ALOGE("Failed to write Entity model"); + goto exit; + } + + //setup model state. + stdev->current_enable = stdev->current_enable | ENTITY_MASK; + err = set_ambient_state(stdev->odsp_hdl, stdev->current_enable); + if (err != 0) { + ALOGE("Failed to set Entity state"); + goto exit; + } + } + +exit: + return err; +} + +static int destroy_package(struct knowles_sound_trigger_device *stdev, + struct model_info *model) +{ + int err = 0; + + if (check_uuid_equality(model->uuid, stdev->chre_model_uuid)) { + stdev->current_enable = stdev->current_enable & ~CHRE_MASK; + if (!(stdev->current_enable & CHRE_MASK)) { + err = destroy_chre_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to destroy CHRE package"); + goto exit; + } + } + } else if (check_uuid_equality(model->uuid, stdev->hotword_model_uuid)) { + err = tear_hotword_state(stdev->odsp_hdl, HOTWORD_MASK); + if (err != 0) { + ALOGE("Failed to tear Hotword state"); + goto exit; + } + + err = flush_model(stdev->odsp_hdl, model->kw_id); + if (err != 0) { + ALOGE("Failed to flush Hotword model"); + goto exit; + } + stdev->current_enable = stdev->current_enable & ~HOTWORD_MASK; + + if (!(stdev->current_enable & PLUGIN1_MASK)) { + err = destroy_hotword_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to destroy Hotword package"); + goto exit; + } + } + + } else if (check_uuid_equality(model->uuid, stdev->ambient_model_uuid)) { + err = tear_ambient_state(stdev->odsp_hdl, AMBIENT_MASK); + if (err != 0) { + ALOGE("Failed to tear Ambient state"); + goto exit; + } + + err = flush_model(stdev->odsp_hdl, model->kw_id); + if (err != 0) { + ALOGE("Failed to flush Ambient model"); + goto exit; + } + stdev->current_enable = stdev->current_enable & ~AMBIENT_MASK; + + if (!(stdev->current_enable & PLUGIN2_MASK)) { + err = destroy_ambient_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to destroy Ambient package"); + goto exit; + } + } + } else if (check_uuid_equality(model->uuid, stdev->entity_model_uuid)) { + err = tear_ambient_state(stdev->odsp_hdl, ENTITY_MASK); + if (err != 0) { + ALOGE("Failed to tear Entity state"); + goto exit; + } + + err = flush_model(stdev->odsp_hdl, model->kw_id); + if (err != 0) { + ALOGE("Failed to flush Entity model"); + goto exit; + } + stdev->current_enable = stdev->current_enable & ~ENTITY_MASK; + + if (!(stdev->current_enable & PLUGIN2_MASK)) { + err = destroy_ambient_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to destroy Ambient package"); + goto exit; + } + } + } +exit: + return err; +} + static int set_package_route(struct knowles_sound_trigger_device *stdev, sound_trigger_uuid_t uuid, bool bargein) @@ -406,18 +617,14 @@ static int set_package_route(struct knowles_sound_trigger_device *stdev, if (check_uuid_equality(uuid, stdev->chre_model_uuid)) set_chre_audio_route(stdev->route_hdl, bargein); else if (check_uuid_equality(uuid, stdev->hotword_model_uuid)) - set_hotword_route(stdev->odsp_hdl, stdev->route_hdl, bargein); + set_hotword_route(stdev->route_hdl, bargein); else if (check_uuid_equality(uuid, stdev->ambient_model_uuid)) { - stdev->current_enable = stdev->current_enable | AMBIENT_MASK; - set_ambient_entity_state(stdev->odsp_hdl, stdev->current_enable); if (!((stdev->current_enable & PLUGIN2_MASK) & ~AMBIENT_MASK)) { - set_ambient_entity_route(stdev->route_hdl, bargein); + set_ambient_route(stdev->route_hdl, bargein); } } else if (check_uuid_equality(uuid, stdev->entity_model_uuid)) { - stdev->current_enable = stdev->current_enable | ENTITY_MASK; - set_ambient_entity_state(stdev->odsp_hdl, stdev->current_enable); if (!((stdev->current_enable & PLUGIN2_MASK) & ~ENTITY_MASK)) { - set_ambient_entity_route(stdev->route_hdl, bargein); + set_ambient_route(stdev->route_hdl, bargein); } } @@ -436,17 +643,13 @@ static int tear_package_route(struct knowles_sound_trigger_device *stdev, if (check_uuid_equality(uuid, stdev->chre_model_uuid)) tear_chre_audio_route(stdev->route_hdl, bargein); else if (check_uuid_equality(uuid, stdev->hotword_model_uuid)) - tear_hotword_route(stdev->odsp_hdl, stdev->route_hdl, bargein); + tear_hotword_route(stdev->route_hdl, bargein); else if (check_uuid_equality(uuid, stdev->ambient_model_uuid)) { if (!((stdev->current_enable & PLUGIN2_MASK) & ~AMBIENT_MASK)) - tear_ambient_entity_route(stdev->route_hdl, bargein); - tear_ambient_entity_state(stdev->odsp_hdl, AMBIENT_MASK); - stdev->current_enable = stdev->current_enable & ~AMBIENT_MASK; + tear_ambient_route(stdev->route_hdl, bargein); } else if (check_uuid_equality(uuid, stdev->entity_model_uuid)) { if (!((stdev->current_enable & PLUGIN2_MASK) & ~ENTITY_MASK)) - tear_ambient_entity_route(stdev->route_hdl, bargein); - tear_ambient_entity_state(stdev->odsp_hdl, ENTITY_MASK); - stdev->current_enable = stdev->current_enable & ~ENTITY_MASK; + tear_ambient_route(stdev->route_hdl, bargein); } return ret; @@ -455,50 +658,128 @@ static int tear_package_route(struct knowles_sound_trigger_device *stdev, static int handle_input_source(struct knowles_sound_trigger_device *stdev, bool enable) { - int ret = 0; + int err = 0; + enum clock_type ct = INTERNAL_OSCILLATOR; + + if (stdev->is_music_playing == true) { + ct = EXTERNAL_OSCILLATOR; + } + /* *[TODO] Add correct error return value for input source route * b/119390722 for tracing. */ if (enable) { if (stdev->is_mic_route_enabled == false) { + switch_internal_osc(stdev); stdev->is_mic_route_enabled = true; - if (enable_mic_route(stdev->route_hdl, true)) { - ALOGE("failed to enable mic route"); + err = enable_mic_route(stdev->route_hdl, true, ct); + if (err != 0) { + ALOGE("Failed to enable mic route"); stdev->is_mic_route_enabled = false; + goto exit; + } + if (stdev->is_buffer_package_loaded == true) { + err = setup_mic_buffer(stdev->odsp_hdl); + if (err != 0) { + ALOGE("%s: Failed to load Buffer package", __func__); + goto exit; + } + err = set_buffer_route(stdev->route_hdl, + stdev->is_bargein_route_enabled); + if (err != 0) { + ALOGE("%s: Failed to enable buffer route", __func__); + goto exit; + } } } if (stdev->is_music_playing == true && stdev->is_bargein_route_enabled == false) { + err = setup_aec_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to load AEC package"); + // We didn't load AEC package so don't setup the routes + goto exit; + } // Enable the bargein route if not enabled - ALOGD("Enabling bargein route"); stdev->is_bargein_route_enabled = true; - enable_bargein_route(stdev->route_hdl, + err = enable_bargein_route(stdev->route_hdl, + stdev->is_bargein_route_enabled); + if (err != 0) { + ALOGE("Failed to enable bargein route"); + stdev->is_bargein_route_enabled = false; + goto exit; + } + //Switch buffer input source + err = tear_buffer_route(stdev->route_hdl, + !stdev->is_bargein_route_enabled); + if (err != 0) { + ALOGE("Failed to tear old buffer route"); + goto exit; + } + + err = set_buffer_route(stdev->route_hdl, stdev->is_bargein_route_enabled); + if (err != 0) { + ALOGE("Failed to enable buffer route"); + goto exit; + } } } else { if (!is_any_model_active(stdev)) { ALOGD("None of keywords are active"); + if (stdev->is_buffer_package_loaded == true) { + err = tear_buffer_route(stdev->route_hdl, + stdev->is_bargein_route_enabled); + if (err != 0) { + ALOGE("%s: Failed to enable buffer route", __func__); + goto exit; + } + err = destroy_mic_buffer(stdev->odsp_hdl); + if (err != 0) { + ALOGE("%s: Failed to load Buffer package", __func__); + goto exit; + } + } if (stdev->is_music_playing == true && stdev->is_bargein_route_enabled == true) { // Just disable the route and update the route status but retain // bargein status stdev->is_bargein_route_enabled = false; - enable_bargein_route(stdev->route_hdl, + err = enable_bargein_route(stdev->route_hdl, stdev->is_bargein_route_enabled); + if (err != 0) { + ALOGE("Failed to disable bargein route"); + stdev->is_bargein_route_enabled = true; + goto exit; + } + err = destroy_aec_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to unload AEC package"); + goto exit; + } } - if (stdev->is_mic_route_enabled == true) { stdev->is_mic_route_enabled = false; - if (enable_mic_route(stdev->route_hdl, false)) { - ALOGE("failed to disable mic route"); + err = enable_mic_route(stdev->route_hdl, false, ct); + if (err != 0) { + ALOGE("Failed to disable mic route"); stdev->is_mic_route_enabled = true; + goto exit; + } + if (stdev->is_internal_osc_switched == true && + !(stdev->current_enable & OSLO_MASK) && + stdev->is_mic_route_enabled == false) { + // Mic disable, Sensor disable, internal osc = false + ALOGD("external osc switch happens in driver runtime pm"); + stdev->is_internal_osc_switched = false; } } } } - return ret; +exit: + return err; } // stdev needs to be locked before calling this function @@ -506,45 +787,103 @@ static int restart_recognition(struct knowles_sound_trigger_device *stdev) { int err = 0; int i = 0; + enum clock_type ct = INTERNAL_OSCILLATOR; + /* + * The libaudioroute library doesn't set the mixer controls if previously + * applied values are the same, so we need to teardown the route so that + * libaudio_route can clear up its internal memory and then we can setup + * the routes again. + */ + audio_route_reset(stdev->route_hdl); + stdev->current_enable = 0; + + if (stdev->is_music_playing == true && + stdev->is_bargein_route_enabled == true) { + ct = EXTERNAL_OSCILLATOR; + } + + if (stdev->is_buffer_package_loaded == true) { + err = setup_buffer_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("%s: Failed to restart Buffer package", __func__); + } + } if (stdev->is_mic_route_enabled == true) { - if (enable_mic_route(stdev->route_hdl, true)) { - ALOGE("failed to enable mic route"); + //TBD + switch_internal_osc(stdev); + err = enable_mic_route(stdev->route_hdl, true, ct); + if (err != 0) { + ALOGE("failed to restart mic route"); + } + if (stdev->is_buffer_package_loaded == true) { + err = setup_mic_buffer(stdev->odsp_hdl); + if (err != 0) { + ALOGE("%s: Failed to load Buffer package", __func__); + goto exit; + } + err = set_buffer_route(stdev->route_hdl, false); + if (err != 0) { + ALOGE("%s: Failed to restart buffer route", __func__); + } } } if (stdev->is_music_playing == true && stdev->is_bargein_route_enabled == true) { - enable_bargein_route(stdev->route_hdl, stdev->is_music_playing); + err = setup_aec_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to restart AEC package"); + } + err = enable_bargein_route(stdev->route_hdl, + stdev->is_bargein_route_enabled); + if (err != 0) { + ALOGE("Failed to restart bargein route"); + } + if (stdev->is_buffer_package_loaded == true) { + //Switch buffer input source + err = tear_buffer_route(stdev->route_hdl, + !stdev->is_bargein_route_enabled); + if (err != 0) { + ALOGE("Failed to tear old buffer route"); + } + err = set_buffer_route(stdev->route_hdl, + stdev->is_bargein_route_enabled); + if (err != 0) { + ALOGE("Failed to enable buffer route"); + } + } } + // [TODO] Recovery function still TBD. // Download all the keyword models files that were previously loaded for (i = 0; i < MAX_MODELS; i++) { if (stdev->models[i].is_loaded == true) { if (check_uuid_equality(stdev->models[i].uuid, stdev->sensor_model_uuid)) { - set_sensor_route(stdev->route_hdl, true); - } else if (check_uuid_equality(stdev->models[i].uuid, - stdev->ambient_model_uuid) || - check_uuid_equality(stdev->models[i].uuid, - stdev->hotword_model_uuid) || - check_uuid_equality(stdev->models[i].uuid, - stdev->entity_model_uuid)) { - err = write_model(stdev->odsp_hdl, - stdev->models[i].data, - stdev->models[i].data_sz, - stdev->models[i].kw_id); - if (err == -1) { - ALOGE("%s: Failed to load the keyword model error - %d(%s)", - __func__, errno, strerror(errno)); - // How do we handle error during a recovery? + // setup the sensor route + switch_internal_osc(stdev); + err = setup_sensor_package(stdev->odsp_hdl); + if (err != 0) { + ALOGE("%s: setup Sensor package failed", __func__); + goto exit; + } + + err = set_sensor_route(stdev->route_hdl, true); + if (err != 0) { + ALOGE("%s: Sensor route fail", __func__); + goto exit; } } } - if (stdev->models[i].is_active == true) - set_package_route(stdev, stdev->models[i].uuid, stdev->is_music_playing); + if (stdev->models[i].is_active == true) { + setup_package(stdev, &stdev->models[i]); + set_package_route(stdev, stdev->models[i].uuid, + stdev->is_bargein_route_enabled); + } } +exit: return err; } @@ -553,11 +892,10 @@ static int fw_crash_recovery(struct knowles_sound_trigger_device *stdev) { int err = 0; - err = setup_chip(stdev->odsp_hdl); + err = iaxxx_odsp_set_mpll_src(stdev->odsp_hdl, IAXXX_INT_OSC, 0); if (err != 0) { - ALOGE("%s: ERROR: Failed to download packages and setup routes", + ALOGE("%s: ERROR Failed to set internal oscillator", __func__); - goto exit; } // Redownload the keyword model files and start recognition @@ -568,6 +906,9 @@ static int fw_crash_recovery(struct knowles_sound_trigger_device *stdev) goto exit; } + // Reset the flag only after successful recovery + stdev->is_st_hal_ready = true; + exit: return err; } @@ -612,23 +953,12 @@ static void *callback_thread_loop(void *context) fds[1].events = POLLIN; fds[1].fd = stdev->recv_sock; - /* - * if startup of uevent listener is delayed then uevent - * IAXXX_FW_DWNLD_SUCCESS event will not be delivered. - * Try once initial setup and if it fails then - * start waiting for uevent IAXXX_FW_DWNLD_SUCCESS in loop. - */ - err = setup_chip(stdev->odsp_hdl); - if (err != 0) { - ALOGW("Firmware and algo setup not ready will wait for uevent"); - } - ge.event_id = -1; pthread_mutex_unlock(&stdev->lock); while (1) { - poll (fds, 2, timeout); + err = poll(fds, 2, timeout); pthread_mutex_lock(&stdev->lock); if (err < 0) { @@ -653,41 +983,36 @@ static void *callback_thread_loop(void *context) ALOGD("Eventid received is OK_GOOGLE_KW_ID %d", OK_GOOGLE_KW_ID); kwid = OK_GOOGLE_KW_ID; - stdev->last_detected_model_type = HOTWORD_MODEL; - break; } else if (ge.event_id == AMBIENT_KW_ID) { ALOGD("Eventid received is AMBIENT_KW_ID %d", AMBIENT_KW_ID); kwid = AMBIENT_KW_ID; - stdev->last_detected_model_type = AMBIENT_MODEL; reset_ambient_plugin(stdev->odsp_hdl); - break; } else if (ge.event_id == ENTITY_KW_ID) { ALOGD("Eventid received is ENTITY_KW_ID %d", ENTITY_KW_ID); kwid = ENTITY_KW_ID; - //get same buffer data - stdev->last_detected_model_type = AMBIENT_MODEL; - break; } else { ALOGE("Unknown event id received, ignoring %d", ge.event_id); } + stdev->last_detected_model_type = kwid; + break; } else { ALOGE("get_event failed with error %d", err); } } else if (strstr(msg + i, IAXXX_RECOVERY_EVENT_STR)) { - ALOGD("Firmware has crashed, start the recovery"); + ALOGD("Firmware has redownloaded, start the recovery"); int err = fw_crash_recovery(stdev); if (err != 0) { ALOGE("Firmware crash recovery failed"); } } else if (strstr(msg + i, IAXXX_FW_DWNLD_SUCCESS_STR)) { ALOGD("Firmware downloaded successfully"); - int err = setup_chip(stdev->odsp_hdl); - if (err != 0) { - ALOGE("FW and ALGO setup failed on uevent receive"); - } + } else if (strstr(msg + i, IAXXX_FW_CRASH_EVENT_STR)) { + ALOGD("Firmware has crashed"); + // Don't allow any op on ST HAL until recovery is complete + stdev->is_st_hal_ready = false; } i += strlen(msg + i) + 1; @@ -752,7 +1077,7 @@ static void *callback_thread_loop(void *context) } else if (stdev->models[idx].type == SOUND_MODEL_TYPE_GENERIC) { struct sound_trigger_generic_recognition_event *event; event = (struct sound_trigger_generic_recognition_event*) - stdev_generic_event_alloc( + stdev_generic_event_alloc( stdev->models[idx].model_handle, payload, payload_size, @@ -777,7 +1102,10 @@ static void *callback_thread_loop(void *context) } else { ALOGE("Invalid id or keyword is not active, Subsume the event"); } + // Reset all event related data ge.event_id = -1; + ge.data = 0; + kwid = -1; } // Free the payload data if (payload) { @@ -823,16 +1151,21 @@ static int stdev_load_sound_model(const struct sound_trigger_hw_device *dev, { struct knowles_sound_trigger_device *stdev = (struct knowles_sound_trigger_device *)dev; - int ret = 0, err = 0; + int ret = 0; int kw_model_sz = 0; int i = 0; unsigned char *kw_buffer = NULL; - ALOGD("+%s+", __func__); pthread_mutex_lock(&stdev->lock); + if (stdev->is_st_hal_ready == false) { + ALOGE("%s: ST HAL is not ready yet", __func__); + ret = -EAGAIN; + goto exit; + } + if (handle == NULL || sound_model == NULL) { ALOGE("%s: handle/sound_model is NULL", __func__); ret = -EINVAL; @@ -881,68 +1214,71 @@ static int stdev_load_sound_model(const struct sound_trigger_hw_device *dev, stdev->models[i].data_sz = kw_model_sz; } + if (stdev->is_buffer_package_loaded == false) { + ret = setup_buffer_package(stdev->odsp_hdl); + if (ret != 0) { + ALOGE("%s: ERROR: Failed to load the buffer package", __func__); + if (stdev->models[i].data) { + free(stdev->models[i].data); + stdev->models[i].data = NULL; + stdev->models[i].data_sz = 0; + } + goto exit; + } + stdev->is_buffer_package_loaded = true; + } + // Send the keyword model to the chip only for hotword and ambient audio if (check_uuid_equality(stdev->models[i].uuid, stdev->hotword_model_uuid)) { - err = write_model(stdev->odsp_hdl, kw_buffer, - kw_model_sz, OK_GOOGLE_KW_ID); stdev->models[i].kw_id = OK_GOOGLE_KW_ID; } else if (check_uuid_equality(stdev->models[i].uuid, stdev->ambient_model_uuid)) { - if (stdev->current_enable & PLUGIN2_MASK) { - // tear down plugin2 for writing new model data. - tear_ambient_entity_state(stdev->odsp_hdl, stdev->current_enable); - } - err = write_model(stdev->odsp_hdl, kw_buffer, - kw_model_sz, AMBIENT_KW_ID); stdev->models[i].kw_id = AMBIENT_KW_ID; - //resume teat down model state. - if (stdev->current_enable & PLUGIN2_MASK) - set_ambient_entity_state(stdev->odsp_hdl, stdev->current_enable); } else if (check_uuid_equality(stdev->models[i].uuid, stdev->entity_model_uuid)) { - if (stdev->current_enable & PLUGIN2_MASK) { - // tear down plugin2 for writing new model data. - tear_ambient_entity_state(stdev->odsp_hdl, stdev->current_enable); - } - err = write_model(stdev->odsp_hdl, kw_buffer, - kw_model_sz, ENTITY_KW_ID); stdev->models[i].kw_id = ENTITY_KW_ID; - //resume teat down model state. - if (stdev->current_enable & PLUGIN2_MASK) - set_ambient_entity_state(stdev->odsp_hdl, stdev->current_enable); - } else if (check_uuid_equality(stdev->models[i].uuid, + } else if (check_uuid_equality(stdev->models[i].uuid, stdev->sensor_model_uuid)) { // setup the sensor route - set_sensor_route(stdev->route_hdl, true); + switch_internal_osc(stdev); + stdev->current_enable = stdev->current_enable | OSLO_MASK; + ret = setup_sensor_package(stdev->odsp_hdl); + if (ret != 0) { + ALOGE("%s: setup Sensor package failed", __func__); + goto exit; + } + + ret = set_sensor_route(stdev->route_hdl, true); + if (ret != 0) { + ALOGE("%s: Sensor route fail", __func__); + goto exit; + } stdev->models[i].kw_id = USELESS_KW_ID; } else if (check_uuid_equality(stdev->models[i].uuid, stdev->chre_model_uuid)) { // setup the CHRE route and Mic route. stdev->models[i].is_active = true; handle_input_source(stdev, true); - set_chre_audio_route(stdev->route_hdl, stdev->is_music_playing); + setup_package(stdev, &stdev->models[i]); + set_chre_audio_route(stdev->route_hdl, stdev->is_bargein_route_enabled); stdev->models[i].kw_id = USELESS_KW_ID; } else { ALOGE("%s: ERROR: unknown keyword model file", __func__); - err = -1; - errno = -EINVAL; + ret = -EINVAL; + goto exit; } - if (err == -1) { - ALOGE("%s: Failed to load the keyword model error - %d (%s)", - __func__, errno, strerror(errno)); - ret = errno; + + stdev->models[i].is_loaded = true; + +exit: + if (ret != 0) { if (stdev->models[i].data) { free(stdev->models[i].data); stdev->models[i].data = NULL; stdev->models[i].data_sz = 0; } - goto exit; } - - stdev->models[i].is_loaded = true; - -exit: pthread_mutex_unlock(&stdev->lock); ALOGD("-%s handle %d-", __func__, *handle); return ret; @@ -957,6 +1293,12 @@ static int stdev_unload_sound_model(const struct sound_trigger_hw_device *dev, ALOGD("+%s handle %d+", __func__, handle); pthread_mutex_lock(&stdev->lock); + if (stdev->is_st_hal_ready == false) { + ALOGE("%s: ST HAL is not ready yet", __func__); + ret = -EAGAIN; + goto exit; + } + // Just confirm the model was previously loaded if (stdev->models[handle].is_loaded == false) { ALOGE("%s: Invalid model(%d) being called for unload", @@ -965,29 +1307,30 @@ static int stdev_unload_sound_model(const struct sound_trigger_hw_device *dev, goto exit; } if (check_uuid_equality(stdev->models[handle].uuid, - stdev->hotword_model_uuid)) { - ret = flush_model(stdev->odsp_hdl, OK_GOOGLE_KW_ID); - if (ret) - goto exit; - } else if (check_uuid_equality(stdev->models[handle].uuid, - stdev->ambient_model_uuid)) { - ret = flush_model(stdev->odsp_hdl, AMBIENT_KW_ID); - if (ret) - goto exit; - } else if (check_uuid_equality(stdev->models[handle].uuid, - stdev->entity_model_uuid)) { - ret = flush_model(stdev->odsp_hdl, ENTITY_KW_ID); - if (ret) - goto exit; - } else if (check_uuid_equality(stdev->models[handle].uuid, stdev->sensor_model_uuid)) { // Disable the sensor route - set_sensor_route(stdev->route_hdl, false); + ret = set_sensor_route(stdev->route_hdl, false); + if (ret != 0) { + ALOGE("%s: disable Sensor route failed", __func__); + } + + ret = destroy_sensor_package(stdev->odsp_hdl); + if (ret != 0) { + ALOGE("%s: destroy Sensor package failed", __func__); + } + stdev->current_enable = stdev->current_enable & ~OSLO_MASK; + + if (stdev->is_internal_osc_switched == true && + stdev->is_mic_route_enabled == false) { + ALOGD("external osc switch happens in driver runtime pm"); + stdev->is_internal_osc_switched = false; + } } else if (check_uuid_equality(stdev->models[handle].uuid, stdev->chre_model_uuid)) { // Disable the CHRE route stdev->models[handle].is_active = false; - tear_chre_audio_route(stdev->route_hdl, stdev->is_music_playing); + tear_chre_audio_route(stdev->route_hdl, stdev->is_bargein_route_enabled); + destroy_package(stdev, &stdev->models[handle]); handle_input_source(stdev, false); } @@ -1000,6 +1343,11 @@ static int stdev_unload_sound_model(const struct sound_trigger_hw_device *dev, stdev->models[handle].data_sz = 0; } + if (!is_any_model_loaded(stdev) && stdev->is_buffer_package_loaded) { + destroy_buffer_package(stdev->odsp_hdl); + stdev->is_buffer_package_loaded = false; + } + ALOGD("%s: Successfully unloaded the model, handle - %d", __func__, handle); exit: @@ -1024,6 +1372,12 @@ static int stdev_start_recognition( pthread_mutex_lock(&stdev->lock); + if (stdev->is_st_hal_ready == false) { + ALOGE("%s: ST HAL is not ready yet", __func__); + status = -EAGAIN; + goto exit; + } + if (callback == NULL) { ALOGE("%s: recognition_callback is null", __func__); status = -EINVAL; @@ -1071,6 +1425,8 @@ static int stdev_start_recognition( handle_input_source(stdev, true); + setup_package(stdev, model); + set_package_route(stdev, model->uuid, stdev->is_music_playing); exit: @@ -1090,6 +1446,12 @@ static int stdev_stop_recognition( ALOGD("+%s sound model %d+", __func__, handle); pthread_mutex_lock(&stdev->lock); + if (stdev->is_st_hal_ready == false) { + ALOGE("%s: ST HAL is not ready yet", __func__); + status = -EAGAIN; + goto exit; + } + if (model->config != NULL) { dereg_hal_event_session(model->config, handle); free(model->config); @@ -1107,6 +1469,8 @@ static int stdev_stop_recognition( tear_package_route(stdev, model->uuid, stdev->is_music_playing); + destroy_package(stdev, model); + handle_input_source(stdev, false); exit: @@ -1143,6 +1507,12 @@ static int stdev_get_model_state(const struct sound_trigger_hw_device *dev, goto exit; } + if (stdev->is_st_hal_ready == false) { + ALOGE("%s: ST HAL is not ready yet", __func__); + ret = -ENODEV; + goto exit; + } + if (model->is_active == false) { ALOGE("%s: ERROR: %d model is not active", __func__, sound_model_handle); @@ -1163,10 +1533,10 @@ static int stdev_get_model_state(const struct sound_trigger_hw_device *dev, ret = get_model_state(stdev->odsp_hdl, HOTWORD_INSTANCE_ID, HOTWORD_SLOT_ID); else if (check_uuid_equality(model->uuid, stdev->ambient_model_uuid)) - ret = get_model_state(stdev->odsp_hdl, AMBIENT_ENTITY_INSTANCE_ID, + ret = get_model_state(stdev->odsp_hdl, AMBIENT_INSTANCE_ID, AMBIENT_SLOT_ID); else if (check_uuid_equality(model->uuid, stdev->entity_model_uuid)) { - ret = get_model_state(stdev->odsp_hdl, AMBIENT_ENTITY_INSTANCE_ID, + ret = get_model_state(stdev->odsp_hdl, AMBIENT_INSTANCE_ID, ENTITY_SLOT_ID); } else { ALOGE("%s: ERROR: %d model is not supported", @@ -1198,6 +1568,13 @@ static int stdev_close(hw_device_t *device) ret = -EFAULT; goto exit; } + + if (stdev->is_st_hal_ready == false) { + ALOGE("%s: ST HAL is not ready yet", __func__); + ret = -EAGAIN; + goto exit; + } + stdev->opened = false; if (stdev->send_sock >= 0) @@ -1501,6 +1878,8 @@ static int stdev_open(const hw_module_t *module, const char *name, stdev->is_mic_route_enabled = false; stdev->is_music_playing = false; stdev->is_bargein_route_enabled = false; + stdev->is_internal_osc_switched = false; + stdev->is_buffer_package_loaded = false; stdev->current_enable = 0; str_to_uuid(HOTWORD_AUDIO_MODEL, &stdev->hotword_model_uuid); @@ -1528,6 +1907,8 @@ static int stdev_open(const hw_module_t *module, const char *name, pthread_create(&stdev->callback_thread, (const pthread_attr_t *) NULL, callback_thread_loop, stdev); + stdev->is_st_hal_ready = true; + *device = &stdev->device.common; /* same address as stdev */ exit: pthread_mutex_unlock(&stdev->lock); @@ -1562,6 +1943,14 @@ int sound_trigger_hw_call_back(audio_event_type_t event, return -EINVAL; } + pthread_mutex_lock(&stdev->lock); + + if (stdev->is_st_hal_ready == false) { + ALOGE("%s: ST HAL is not ready yet", __func__); + ret = -EINVAL; + goto exit; + } + switch (event) { case AUDIO_EVENT_CAPTURE_DEVICE_INACTIVE: case AUDIO_EVENT_CAPTURE_DEVICE_ACTIVE: @@ -1585,24 +1974,19 @@ int sound_trigger_hw_call_back(audio_event_type_t event, * That stop all recognition in codec */ ALOGD("%s: handle capture stream active", __func__); - pthread_mutex_lock(&stdev->lock); // Disable mic route. for (i = 0; i < MAX_MODELS; i++) { if (stdev->models[i].is_active == true) { tear_package_route(stdev, stdev->models[i].uuid, - stdev->is_music_playing); + stdev->is_mic_route_enabled); stdev->models[i].is_active = false; } } handle_input_source(stdev, false); - - pthread_mutex_unlock(&stdev->lock); - break; case AUDIO_EVENT_PLAYBACK_STREAM_INACTIVE: ALOGD("%s: handle playback stream inactive", __func__); - pthread_mutex_lock(&stdev->lock); if (stdev->is_music_playing != false) { stdev->is_music_playing = false; @@ -1612,31 +1996,75 @@ int sound_trigger_hw_call_back(audio_event_type_t event, // Check each model, if it is active then update it's route if (stdev->is_bargein_route_enabled != false) { ALOGD("Bargein disable"); + stdev->is_bargein_route_enabled = false; // Check each model, if it is active then update it's route // Disable the bargein route for (i = 0; i < MAX_MODELS; i++) { if (stdev->models[i].is_active == true) { // teardown the package route with bargein - tear_package_route(stdev, stdev->models[i].uuid, - !stdev->is_music_playing); + ret = tear_package_route(stdev, + stdev->models[i].uuid, + !stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to tear old package route"); + goto exit; + } // resetup the package route with out bargein - set_package_route(stdev, stdev->models[i].uuid, - stdev->is_music_playing); + ret = set_package_route(stdev, + stdev->models[i].uuid, + stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to enable package route"); + goto exit; + } } } - stdev->is_bargein_route_enabled = false; - enable_bargein_route(stdev->route_hdl, + //Switch buffer input source + ret = tear_buffer_route(stdev->route_hdl, + !stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to tear old buffer route"); + goto exit; + } + + ret = set_buffer_route(stdev->route_hdl, stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to enable buffer route"); + goto exit; + } + + ret = enable_bargein_route(stdev->route_hdl, + stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to disable bargein route"); + goto exit; + } + ret = destroy_aec_package(stdev->odsp_hdl); + if (ret != 0) { + ALOGE("Failed to unload AEC package"); + goto exit; + } + ret = enable_mic_route(stdev->route_hdl, false, + EXTERNAL_OSCILLATOR); + if (ret != 0) { + ALOGE("Failed to disable mic route with INT OSC"); + goto exit; + } + ret = enable_mic_route(stdev->route_hdl, true, + INTERNAL_OSCILLATOR); + if (ret != 0) { + ALOGE("Failed to enable mic route with EXT OSC"); + goto exit; + } } } } else { ALOGD("%s: STHAL setup playback Inactive alrealy", __func__); } - pthread_mutex_unlock(&stdev->lock); break; case AUDIO_EVENT_PLAYBACK_STREAM_ACTIVE: ALOGD("%s: handle playback stream active", __func__); - pthread_mutex_lock(&stdev->lock); if (stdev->is_music_playing != true) { stdev->is_music_playing = true; if (stdev->is_mic_route_enabled != false) { @@ -1645,18 +2073,65 @@ int sound_trigger_hw_call_back(audio_event_type_t event, // Check each model, if it is active then update it's route if (stdev->is_bargein_route_enabled != true) { ALOGD("Bargein enable"); + ret = enable_mic_route(stdev->route_hdl, false, + INTERNAL_OSCILLATOR); + if (ret != 0) { + ALOGE("Failed to disable mic route with INT OSC"); + goto exit; + } + ret = enable_mic_route(stdev->route_hdl, true, + EXTERNAL_OSCILLATOR); + if (ret != 0) { + ALOGE("Failed to enable mic route with EXT OSC"); + goto exit; + } + ret = setup_aec_package(stdev->odsp_hdl); + if (ret != 0) { + ALOGE("Failed to load AEC package"); + goto exit; + } stdev->is_bargein_route_enabled = true; - enable_bargein_route(stdev->route_hdl, + ret = enable_bargein_route(stdev->route_hdl, + stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to enable bargein route"); + goto exit; + } + //Switch buffer input source + ret = tear_buffer_route(stdev->route_hdl, + !stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to tear old buffer route"); + goto exit; + } + + ret = set_buffer_route(stdev->route_hdl, stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to enable buffer route"); + goto exit; + } + //[Todo] add downlink audio buffer handler + // Check each model, if it is active then update it's route for (i = 0; i < MAX_MODELS; i++) { if (stdev->models[i].is_active == true) { // teardown the package route without bargein - tear_package_route(stdev, stdev->models[i].uuid, - !stdev->is_music_playing); + ret = tear_package_route(stdev, + stdev->models[i].uuid, + !stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to tear old package route"); + goto exit; + } // resetup the package route with bargein - set_package_route(stdev, stdev->models[i].uuid, - stdev->is_music_playing); + ret = set_package_route(stdev, + stdev->models[i].uuid, + stdev->is_bargein_route_enabled); + if (ret != 0) { + ALOGE("Failed to enable package route"); + goto exit; + } } } } @@ -1664,18 +2139,15 @@ int sound_trigger_hw_call_back(audio_event_type_t event, } else { ALOGD("%s: STHAL setup playback active alrealy", __func__); } - pthread_mutex_unlock(&stdev->lock); break; case AUDIO_EVENT_STOP_LAB: /* Close Stream Driver */ ALOGD("%s: close streaming %d", __func__, event); - pthread_mutex_lock(&stdev->lock); if (stdev->adnc_strm_handle) { stdev->adnc_strm_close(stdev->adnc_strm_handle); stdev->adnc_strm_handle = 0; stdev->is_streaming = 0; } - pthread_mutex_unlock(&stdev->lock); break; @@ -1686,15 +2158,28 @@ int sound_trigger_hw_call_back(audio_event_type_t event, case AUDIO_EVENT_READ_SAMPLES: /* Open Stream Driver */ - pthread_mutex_lock(&stdev->lock); if (stdev->is_streaming == false) { if (stdev->adnc_strm_open == NULL) { ALOGE("%s: Error adnc streaming not supported", __func__); } else { bool keyword_stripping_enabled = false; + int stream_end_point; + switch (stdev->last_detected_model_type) { + case OK_GOOGLE_KW_ID: + stream_end_point = CVQ_ENDPOINT; + break; + case AMBIENT_KW_ID: + case ENTITY_KW_ID: + stream_end_point = COMMON_8SEC_BUF_ENDPOINT; + //if downlink audio using another endpoint + break; + default: + stream_end_point = COMMON_8SEC_BUF_ENDPOINT; + break; + }; stdev->adnc_strm_handle = stdev->adnc_strm_open( keyword_stripping_enabled, 0, - stdev->last_detected_model_type); + stream_end_point); if (stdev->adnc_strm_handle) { ALOGD("Successfully opened adnc streaming"); stdev->is_streaming = true; @@ -1712,7 +2197,6 @@ int sound_trigger_hw_call_back(audio_event_type_t event, } else { ALOGE("%s: soundtrigger is not streaming", __func__); } - pthread_mutex_unlock(&stdev->lock); break; @@ -1729,6 +2213,8 @@ int sound_trigger_hw_call_back(audio_event_type_t event, break; } +exit: + pthread_mutex_unlock(&stdev->lock); return ret; } diff --git a/tests/crash_event_logger.c b/tests/crash_event_logger.c new file mode 100755 index 0000000..947cd43 --- /dev/null +++ b/tests/crash_event_logger.c @@ -0,0 +1,270 @@ +/* + * Copyright (C) 2018 Knowles Electronics + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <poll.h> +#include <string.h> +#include <errno.h> +#include <time.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#define LOG_TAG "ia_crash_event_logger" +#include <cutils/log.h> +#include <cutils/uevent.h> + +#define UEVENT_MSG_LEN (1024) +#define BUF_SIZE (4096) +#define CRASH_LOGGER_DEV "/dev/crashdump" +#define CRASH_DUMP_FILE_PREFIX "/data/data/crash_dump_" +#define BIN_EXTN ".bin" +#define MAX_FILENAME_LEN 512 +#define MAX_TIMESTR_LEN 64 + +int g_exit_socket[2]; + +void sigint_handler(int sig __unused) { + ALOGE("Interrupted, setting the exit condition"); + if (g_exit_socket[0] >= 0) + write(g_exit_socket[0], "T", 1); +} + +char *crash_dump_split_file_names[] = + {"/data/data/dump_debug_CM4_", + "/data/data/dump_debug_HMD_", + "/data/data/dump_debug_DMX_", + "/data/data/dump_crash_CM4_", + "/data/data/dump_crash_HMD_", + "/data/data/dump_crash_DMX_" + }; + +int split_bin(unsigned char *buf, int len, const char* time_stamp) +{ + unsigned int header, size, tot_len, flen; + int fcount = 0; + unsigned char *ptr; + FILE *fp; + char file_name[MAX_FILENAME_LEN]; + int no_crashdump_files = sizeof(crash_dump_split_file_names) / + sizeof(crash_dump_split_file_names[0]); + + tot_len = 0; + while ((tot_len < len) && (fcount++ < no_crashdump_files)) + { + header = buf[tot_len] ; + + size = buf[tot_len+8] | + buf[tot_len+9] << 8 | + buf[tot_len+10] << 16 | + buf[tot_len+11] << 24 ; + + tot_len += 12; + + strcpy(file_name, crash_dump_split_file_names[header & 0xf]); + strcat(file_name, time_stamp); + strcat(file_name, BIN_EXTN); + + fp = fopen (file_name, "w+"); + + ptr = buf + tot_len; + flen = fwrite(ptr , 1, size, fp); + tot_len += size; + fclose(fp); + ALOGI("Crash logs saved to %s", file_name); + } + return 0; +} + +int split_crash_dump_file (const char* crash_dump_filename, + const char* time_stamp) +{ + int fd, fil_len; + FILE *fp; + struct stat st; + unsigned char *buf; + int len,ret ; + + fp = fopen(crash_dump_filename, "r"); + if (!fp) + { + ALOGE("File open error %s \n", crash_dump_filename); + return -1; + } + + fd = fileno(fp); + fstat(fd, &st); + fil_len = st.st_size; + buf = (unsigned char*) malloc(fil_len); + + if (NULL == buf) { + ALOGE("Failed to allocate buffer exiting"); + ret = -1; + goto exit; + } + + len = fread(buf,1, fil_len, fp); + if (len <=0) { + ALOGE("file reading error %s\n", crash_dump_filename); + ret = -1; + goto exit; + } + ret = split_bin(buf, len, time_stamp); + +exit: + if (fp) + fclose (fp); + if (buf) + free(buf); + return ret; +} + +void dump_crash_log() { + void *buf = NULL; + int inp_fp = -1, out_fp = -1; + int bytes_read = 0; + int err = 0; + time_t t; + struct tm *tm; + char file_name[MAX_FILENAME_LEN]; + char curr_time[MAX_TIMESTR_LEN]; + + buf = malloc(BUF_SIZE); + if (NULL == buf) { + ALOGE("Failed to allocate buffer exiting"); + err = -1; + goto exit; + } + + inp_fp = open(CRASH_LOGGER_DEV, O_RDONLY); + if (inp_fp == -1) { + ALOGE("Failed to open %s with error %d(%s)", + CRASH_LOGGER_DEV, errno, strerror(errno)); + goto exit; + } + + strcpy(file_name, CRASH_DUMP_FILE_PREFIX); + t = time(NULL); + tm = localtime(&t); + strftime(curr_time, 64, "%F_%H_%M_%S", tm); + strcat(file_name, curr_time); + strcat(file_name, BIN_EXTN); + + out_fp = open(file_name, O_WRONLY | O_CREAT, 0644); + if (out_fp == -1) { + ALOGE("Failed to open %s for writing", file_name); + goto exit; + } + + do { + bytes_read = read(inp_fp, buf, BUF_SIZE); + if (bytes_read > 0) + write(out_fp, buf, bytes_read); + } while (bytes_read > 0); + + ALOGI("Crash logs has been dumped to %s", file_name); + close(out_fp); + out_fp = -1; + close(inp_fp); + inp_fp = -1; + free(buf); + buf = NULL; + split_crash_dump_file(file_name, curr_time); + +exit: + if (out_fp != -1) { + close(out_fp); + } + + if (inp_fp != -1) { + close(inp_fp); + } + + if (buf) { + free(buf); + } +} + +int main(int argc, char** argv) { + int err = 0; + int timeout = -1; // Wait for event indefinitely + struct pollfd fds[2]; + char msg[UEVENT_MSG_LEN]; + int i, n; + + signal(SIGINT, sigint_handler); + + if ( (argc == 2) && !strcmp(argv[1], "-f")) { + ALOGD("Read to get the crash logs"); + dump_crash_log(); + return 0; + } + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, g_exit_socket) == -1) { + ALOGE("%s: Failed to create termination socket", __func__); + err = -1; + goto exit; + } + + + fds[0].events = POLLIN; + fds[0].fd = uevent_open_socket(64*1024, true); + if (fds[0].fd == -1) { + ALOGE("Error opening socket for hotplug uevent errno %d(%s)", + errno, strerror(errno)); + goto exit; + } + fds[1].events = POLLIN; + fds[1].fd = g_exit_socket[1]; + + while (1) { + err = poll (fds, 2, timeout); + + if (fds[0].revents & POLLIN) { + n = uevent_kernel_multicast_recv(fds[0].fd, msg, UEVENT_MSG_LEN); + if (n <= 0) { + continue; + } + + for (i = 0; i < n;) { + if (strstr(msg + i, "IAXXX_CRASH_EVENT")) { + ALOGD("IAXXX_CRASH_EVENT received trying to get the crash logs"); + dump_crash_log(); + } + + i += strlen(msg + i) + 1; + } + } else if (fds[1].revents & POLLIN) { + read(fds[1].fd, &n, sizeof(n)); /* clear the socket */ + ALOGE("Interrupt received, exiting"); + break; + } else { + ALOGI("Message ignored"); + } + } + +exit: + if (g_exit_socket[0] >= 0) { + close(g_exit_socket[0]); + } + + if (g_exit_socket[1] >= 0) { + close(g_exit_socket[1]); + } + + return err; +} diff --git a/tests/dump_debug_info.c b/tests/dump_debug_info.c new file mode 100755 index 0000000..54e15d7 --- /dev/null +++ b/tests/dump_debug_info.c @@ -0,0 +1,496 @@ +/* + * Copyright (C) 2018 Knowles Electronics + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <getopt.h> +#include <stdbool.h> +#include <arpa/inet.h> +#include <limits.h> +#include <unistd.h> +#include <iaxxx-debug-intf.h> + +#define LOG_TAG "ia_dump_registers" + +#include <log/log.h> + +#define DEBUG_DEV "/dev/debug0" +#define GETOPT_HELP_CHAR (CHAR_MIN - 2) +#define REG_ADDR "Register Address" +#define REG_VAL "Register Value" +#define SRB_REG "SRB Registers" +#define ARB_REG "ARB Registers" +#define REG_OUT_FILE "/data/data/reg_dump.txt" +#define CIRC_OUT_FILE_CM4 "/data/data/circular_buf_cm4.bin" +#define CIRC_OUT_FILE_DMX "/data/data/circular_buf_dmx.bin" +#define CIRC_OUT_FILE_HMD "/data/data/circular_buf_hmd.bin" + +//#define ENABLE_DEBUG_PRINTS + +static struct option const long_options[] = { + {"stdout", no_argument, NULL, 'o'}, + {"regdump", no_argument, NULL, 'r'}, + {"circbuf", no_argument, NULL, 'c'}, + {"help", no_argument, NULL, GETOPT_HELP_CHAR}, + {NULL, 0, NULL, 0} +}; + +void usage(void) +{ + fputs("\ + USAGE -\n\ + -------\n\ + 1) dump_debug_info -c\n\ + 2) dump_debug_info -r\n\ + 3) dump_debug_info -l <module id> <log level>\n\ + 4) dump_debug_info -l <module id>\n\ + 5) dump_debug_info -m <processor id> <mode>\n\ + 6) dump_debug_info -m <processor id>\n\ + \n\ + In the first form, it dumps the circular buffer logging for Rome, the output is\n\ + dumped to the file /data/data/circular_buf_(cm4/dmx/hmd).bin\n\ + In the second form, it dumps all the SRB and ARB registers, the output is\n\ + dumped to the file /data/data/reg_dump.txt\n\ + In the third form, it sets the log level to a particular module id\n\ + In the fourth form, it gets the log level for the requested modele id\n\ + In the fifth form, it sets the mode to a particular processor id\n\ + In the sixth form, it gets the mode for the requested processor id\n\ + ", stdout); + + fputs("\ + Options -\n\ + ---------\n\ + -c Dump the circular buffer\n\ + -r Dump all SRB and ARB registers\n\ + -o Dump to stdout (Works only with -r option)\n\ + -l Set/Get the log level for a particular module\n\ + -m Set/Get the mode for a particular processor id\n\ +\n\ + Module ids -\n\ + -----------\n\ + enum iaxxx_debug_module_ids {\n\ + IAXXX_DBG_MODULE_ID_ASSERT_LOG = 0,\n\ + IAXXX_DBG_MODULE_ID_ACCDETMGR_LOG = 1,\n\ + IAXXX_DBG_MODULE_ID_BATTERYMGR_LOG = 2,\n\ + IAXXX_DBG_MODULE_ID_BLUETOOTHMGR_LOG = 3,\n\ + IAXXX_DBG_MODULE_ID_BUTTONMGR_LOG = 4,\n\ + IAXXX_DBG_MODULE_ID_CODECMGR_LOG = 5,\n\ + IAXXX_DBG_MODULE_ID_CTRLMGR_LOG = 6,\n\ + IAXXX_DBG_MODULE_ID_DMAMGR_LOG = 7,\n\ + IAXXX_DBG_MODULE_ID_EVTMGR_LOG = 8,\n\ + IAXXX_DBG_MODULE_ID_FLASHMGR_LOG = 9,\n\ + IAXXX_DBG_MODULE_ID_LEDMGR_LOG = 10,\n\ + IAXXX_DBG_MODULE_ID_POWERMGR_LOG = 11,\n\ + IAXXX_DBG_MODULE_ID_STREAMMGR_LOG = 12,\n\ + IAXXX_DBG_MODULE_ID_SENSORMGR_LOG = 13,\n\ + IAXXX_DBG_MODULE_ID_TUNNELMGR_LOG = 14,\n\ + IAXXX_DBG_MODULE_ID_USBMGR_LOG = 15,\n\ + IAXXX_DBG_MODULE_ID_PLUGINMGR_LOG = 16,\n\ + IAXXX_DBG_MODULE_ID_PLUGINVM_LOG = 17,\n\ + IAXXX_DBG_MODULE_ID_PACKAGEUTILS_LOG = 18,\n\ + IAXXX_DBG_MODULE_ID_ENDPOINT_LOG = 19,\n\ + IAXXX_DBG_MODULE_ID_PUTMSG_LOG = 20,\n\ + IAXXX_DBG_MODULE_ID_CONTROLLER_LOG = 21,\n\ + IAXXX_DBG_MODULE_ID_MIPSPROFILER_LOG = 22,\n\ + IAXXX_DBG_MODULE_ID_DEBUGMONITOR_LOG = 23,\n\ + IAXXX_DBG_MODULE_ID_SSPDRV_LOG = 24,\n\ + IAXXX_DBG_MODULE_ID_AFDRV_LOG = 25,\n\ + IAXXX_DBG_MODULE_ID_SPIDRV_LOG = 26,\n\ + IAXXX_DBG_MODULE_ID_I2CDRV_LOG = 27,\n\ + IAXXX_DBG_MODULE_ID_A400DRV_LOG = 28,\n\ + IAXXX_DBG_MODULE_ID_ADAU1361DRV_LOG = 29,\n\ + IAXXX_DBG_MODULE_ID_MAX98090DRV_LOG = 30,\n\ + IAXXX_DBG_MODULE_ID_BQ27425DRV_LOG = 31,\n\ + IAXXX_DBG_MODULE_ID_USBDRV_LOG = 32,\n\ + IAXXX_DBG_MODULE_ID_CSR8811_LOG = 33,\n\ + IAXXX_DBG_MODULE_ID_CYW20707DRV_LOG = 34,\n\ + IAXXX_DBG_MODULE_ID_BUTTONDRV_LOG = 35,\n\ + IAXXX_DBG_MODULE_ID_LEDDRV_LOG = 36,\n\ + IAXXX_DBG_MODULE_ID_TIMERDRV_LOG = 37,\n\ + IAXXX_DBG_MODULE_ID_UARTDRV_LOG = 38,\n\ + IAXXX_DBG_MODULE_ID_FLASHDRV_LOG = 39,\n\ + IAXXX_DBG_MODULE_ID_DMADRV_LOG = 40,\n\ + IAXXX_DBG_MODULE_ID_GPIODRV_LOG = 41,\n\ + IAXXX_DBG_MODULE_ID_MACDRV_LOG = 42,\n\ + IAXXX_DBG_MODULE_ID_STMRDRV_LOG = 43,\n\ + IAXXX_DBG_MODULE_ID_STMRPTDRV_LOG = 44,\n\ + IAXXX_DBG_MODULE_ID_SLIMBUSDRV_LOG = 45,\n\ + IAXXX_DBG_MODULE_ID_SSENSORDRV_LOG = 46,\n\ + IAXXX_DBG_MODULE_ID_STRMDRV_LOG = 47,\n\ + IAXXX_DBG_MODULE_ID_CPUSTRMDRV_LOG = 48,\n\ + IAXXX_DBG_MODULE_ID_CLKTREEUTILS_LOG = 49,\n\ + IAXXX_DBG_MODULE_ID_SCRIPTMGR_LOG = 50,\n\ + };\n\ +\n\ + Log Levels -\n\ + ------------\n\ + enum iaxxx_fw_debug_log_level {\n\ + IAXXX_DBG_LOG_LVL_OFF = 0,\n\ + IAXXX_DBG_LOG_LVL_CUSTOM = 1,\n\ + IAXXX_DBG_LOG_LVL_FATAL = 2,\n\ + IAXXX_DBG_LOG_LVL_ERROR = 3,\n\ + IAXXX_DBG_LOG_LVL_WARN = 4,\n\ + IAXXX_DBG_LOG_LVL_INFO = 5,\n\ + IAXXX_DBG_LOG_LVL_DEBUG = 6,\n\ + IAXXX_DBG_LOG_LVL_TRACE = 7,\n\ + };\n\ +\n\ + Modes -\n\ + -------\n\ + enum iaxxx_fw_debug_log_mode {\n\ + IAXXX_FROM_MEMORY = 0,\n\ + IAXXX_FROM_ENDPOINT = 1,\n\ + };\n\ +\n\ + Processor ids -\n\ + ---------------\n\ + enum iaxxx_proc_id_e {\n\ + IAXXX_NO_PROC = 0,\n\ + IAXXX_BOSS_ID = 1,\n\ + IAXXX_SSP_ID = 2,\n\ + IAXXX_CM4_ID = 3,\n\ + IAXXX_HMD_ID = 4,\n\ + IAXXX_DMX_ID = 5,\n\ + };\n\ + ", stdout); + + exit(EXIT_FAILURE); +} + +void log_lvl(int fd, int module_id, int log_level) { + int err = 0; + struct iaxxx_log_level_info log_level_info; + + log_level_info.module_id = module_id; + + if (log_level == -1) { + // We need to get the log level for the module id + log_level_info.log_level = 0; + err = ioctl(fd, IAXXX_GET_DBG_LOG_LEVEL, + (unsigned long) &log_level_info); + if (err == -1) { + ALOGE("%s: ERROR: IAXXX_GET_DBG_LOG_LEVEL failed %d(%s)", __func__, + errno, strerror(errno)); + return; + } + + ALOGD("%s: Module level %d Log level %u", __func__, module_id, + log_level_info.log_level); + } else { + // We need to set the Log level for the module id + log_level_info.log_level = log_level; + err = ioctl(fd, IAXXX_SET_DBG_LOG_LEVEL, + (unsigned long) &log_level_info); + if (err == -1) { + ALOGE("%s: ERROR: IAXXX_SET_DBG_LOG_LEVEL failed %d(%s)", __func__, + errno, strerror(errno)); + return; + } + } +} + +void pmode(int fd, int proc_id, int mode) { + int err = 0; + struct iaxxx_log_mode_info log_mode_info; + + log_mode_info.proc_id = proc_id; + + if (mode == -1) { + // We need to get the mode for the processor id + log_mode_info.mode = 0; + err = ioctl(fd, IAXXX_GET_DBG_LOG_MODE, + (unsigned long) &log_mode_info); + if (err == -1) { + ALOGE("%s: ERROR: IAXXX_GET_DBG_LOG_MODE failed %d(%s)", __func__, + errno, strerror(errno)); + return; + } + + ALOGD("%s: Processor ID %d Mode %u", __func__, proc_id, + log_mode_info.mode); + } else { + // We need to set the mode for the processor id + log_mode_info.mode = mode; + err = ioctl(fd, IAXXX_SET_DBG_LOG_MODE, + (unsigned long) &log_mode_info); + if (err == -1) { + ALOGE("%s: ERROR: IAXXX_SET_DBG_LOG_MODE failed %d(%s)", __func__, + errno, strerror(errno)); + return; + } + } +} + +void dump_all_regs(const struct iaxxx_registers_dump *info, bool use_stdout) +{ + uint32_t addr; + int i, j; + FILE *out_fp = NULL; + const struct iaxxx_srb_info *srb_info = &info->srb_info; + const struct iaxxx_arb_info *arb_info = &info->arb_info; + + if (use_stdout) { + out_fp = stdout; + } else { + out_fp = fopen(REG_OUT_FILE, "w"); + if (NULL == out_fp) { + ALOGE("Couldn't open the file %s for writing", REG_OUT_FILE); + return; + } + } + + /* SRB */ +#ifdef ENABLE_DEBUG_PRINTS + ALOGD("%s", SRB_REG); + ALOGD("%s\t%s", REG_ADDR, REG_VAL); +#endif + fprintf(out_fp, "%s\n", SRB_REG); + fprintf(out_fp, "%s\t%s\n", REG_ADDR, REG_VAL); + + addr = srb_info->reg_start_addr; + for (i = 0; i < srb_info->reg_num; ++i) { + uint32_t val = srb_info->reg_vals[i]; + +#ifdef ENABLE_DEBUG_PRINTS + ALOGD("0x%X\t\t\t0x%08X", addr, val); +#endif + fprintf(out_fp, "0x%X\t\t\t0x%08X\n", addr, val); + + addr += sizeof(uint32_t); + } + + /* ARB */ + addr = arb_info->reg_start_addr; + /* Dump all the ARB start address and the size at the beginning + * before dumping all the ARB information + */ + for (i = 0, j = 0; i < arb_info->reg_num; i += 2, j++) { + uint32_t arb_phy_addr = arb_info->reg_vals[i]; + uint32_t arb_sz = arb_info->reg_vals[i + 1]; + +#ifdef ENABLE_DEBUG_PRINTS + ALOGD("0x%X\t\t\t0x%08X", addr, arb_phy_addr); + ALOGD("0x%X\t\t\t0x%08X", (addr + 4), arb_sz); +#endif + fprintf(out_fp, "0x%X\t\t\t0x%08X\n", addr, arb_phy_addr); + fprintf(out_fp, "0x%X\t\t\t0x%08X\n", (addr + sizeof(uint32_t)), arb_sz); + addr += (sizeof(uint32_t) * 2); + } + + addr = arb_info->reg_start_addr; + for (i = 0, j = 0; i < arb_info->reg_num; i += 2, j++) { + const struct iaxxx_arb_block *block = &arb_info->blocks[j]; + uint32_t k; + uint32_t temp_arb_addr; +#ifdef ENABLE_DEBUG_PRINTS + uint32_t arb_phy_addr = arb_info->reg_vals[i]; + uint32_t arb_sz = arb_info->reg_vals[i + 1]; + + ALOGD("0x%X \t\t arb phy addr 0x%08X arb size 0x%08X", addr, arb_phy_addr, arb_sz); + ALOGD("%s %d", ARB_REG, j); + ALOGD("%s\t%s", REG_ADDR, REG_VAL); +#endif + addr += (sizeof(uint32_t) * 2); + + fprintf(out_fp, "%s %d\n", ARB_REG, j); + fprintf(out_fp, "%s\t%s\n", REG_ADDR, REG_VAL); + + if (0 == block->reg_start_addr || 0 == block->reg_num) { + ALOGD("------------- NA -------------"); + fprintf(out_fp, "------------- NA -------------\n"); + continue; + } + + temp_arb_addr = block->reg_start_addr; + for (k = 0; k < block->reg_num; k++) { + uint32_t temp_val = block->reg_vals[k]; +#ifdef ENABLE_DEBUG_PRINTS + ALOGD("0x%X\t\t\t0x%08X", temp_arb_addr, temp_val); +#endif + fprintf(out_fp, "0x%X\t\t\t0x%08X\n", temp_arb_addr, temp_val); + + temp_arb_addr += sizeof(uint32_t); + } + } + + fflush(out_fp); + if (!use_stdout) + fclose(out_fp); +} + +/* + * Register Information - + * All circular buffers start address and size is stored in ARB10 + * ARB10 - physical address in SRB is 0x580001bc + * Start Address location Size location + * CM4 ARB10 + 0 ARB10 + 4 + * HMD ARB10 + 8 ARB10 + C + * DMX ARB10 + 10 ARB10 + 14 + */ +void dump_circ_buf(const struct iaxxx_circ_buffer_info *circ_buffer_info) +{ + uint32_t i = 0, j = 0; + const char *out_file_names[IAXXX_MAX_CIRC_BUFS] = {CIRC_OUT_FILE_CM4, CIRC_OUT_FILE_HMD, CIRC_OUT_FILE_DMX}; + + if (circ_buffer_info->buf_num > IAXXX_MAX_CIRC_BUFS) { + ALOGE("Too large buf_num: %d", circ_buffer_info->buf_num); + return; + } + + for (i = 0, j = 0; j < circ_buffer_info->buf_num; i += 2, j++) { + const struct iaxxx_circ_buffer *buf = &circ_buffer_info->bufs[j]; + FILE *fp = NULL; + uint32_t k = 0; + + // Get the physical address and size for each of the circular buffers + if (0 == buf->reg_start_addr || 0 == buf->reg_num) { + ALOGE("Couldn't find physical address and size"); + ALOGE("phy_addr 0x%X size 0x%X", buf->reg_start_addr, buf->reg_num); + continue; + } + + fp = fopen(out_file_names[j], "wb"); + if (NULL == fp) { + ALOGE("Couldn't open the file for writing"); + continue; + } + + for (k = 0; k < buf->reg_num; k++) + fwrite(buf->reg_vals + k, sizeof(uint32_t), 1, fp); + + fflush(fp); + fclose(fp); + } +} + +int main(int argc, char *argv[]) +{ + int fd = 0, ret = 0; + int c; + bool dump_all_registers = false; + bool dump_circ_buffer = false; + bool log_mode = false; + bool use_stdout = false; + static struct iaxxx_registers_dump dump; + bool proc_mode = false; + // Log level set will require 2 arguments while get needs one + const int log_lvl_req_arg_get = 1; + const int log_lvl_req_arg_set = 2; + // Mode level set will required 2 arguments while set needs one + const int mode_req_arg_get = 1; + const int mode_req_arg_set = 2; + int module_id = 0, log_level = -1; + int proc_id = 0, mode = -1; + + if (argc <= 1) { + usage(); + return 0; + } + + + while ((c = getopt_long (argc, argv, "rcol:m:", long_options, NULL)) != -1) { + switch (c) { + case 'r': + dump_all_registers = true; + break; + case 'c': + dump_circ_buffer = true; + break; + case 'o': + use_stdout = true; + break; + case 'l': + log_mode = true; + // reset optind by 1 + --optind; + if ((optind + log_lvl_req_arg_get) != argc && + (optind + log_lvl_req_arg_set) != argc) { + usage(); + } + + module_id = strtol(argv[optind], NULL, 0); + + if ((optind + log_lvl_req_arg_set) == argc) { + // Move to the next before fetching the value + optind++; + log_level = strtol(argv[optind], NULL, 0); + optind++; + } + break; + case 'm': + proc_mode = true; + // reset optind by 1 + --optind; + if ((optind + mode_req_arg_get) != argc && + (optind + mode_req_arg_set) != argc) { + usage(); + } + + proc_id = strtol(argv[optind], NULL, 0); + + if ((optind + mode_req_arg_set) == argc) { + // Move to the next before fetching the value + optind++; + mode = strtol(argv[optind], NULL, 0); + optind++; + } + break; + default: + // Do nothing + break; + } + } + + fd = open(DEBUG_DEV, O_RDONLY); + if (-1 == fd) { + ALOGE("Failed to open %s", DEBUG_DEV); + ret = errno; + goto exit; + } + + memset(&dump, 0, sizeof(dump)); + + if(log_mode == true) { + log_lvl(fd, module_id, log_level); + } + + if (proc_mode == true) { + pmode(fd, proc_id, mode); + } + + if ((ret = ioctl(fd, IAXXX_IOCTL_GET_REGISTERS_DUMP, &dump)) != 0) { + ALOGE("Failed to ioctl %s IAXXX_IOCTL_GET_REGISTERS_DUMP, ret=%d", DEBUG_DEV, ret); + ret = errno; + goto exit; + } + + if (dump_all_registers) + dump_all_regs(&dump, use_stdout); + + if (dump_circ_buffer) + dump_circ_buf(&dump.circ_buffer_info); + +exit: + if (-1 != fd) + close(fd); + + return ret; +} diff --git a/tests/odsp_api_test.c b/tests/odsp_api_test.c index 1c7f39d..177d108 100644 --- a/tests/odsp_api_test.c +++ b/tests/odsp_api_test.c @@ -33,6 +33,8 @@ static struct option const long_options[] = { {"setparamid", required_argument, NULL, 's'}, {"getparamid", required_argument, NULL, 'g'}, + {"enableplugin", required_argument, NULL, 'e'}, + {"disableplugin", required_argument, NULL, 'd'}, {"help", no_argument, NULL, GETOPT_HELP_CHAR}, {NULL, 0, NULL, 0} }; @@ -43,10 +45,14 @@ void usage() { -------\n\ 1) odsp_api_test -s <param_id> <param_val> <inst_id> <block_id>\n\ 2) odsp_api_test -g <param_id> <inst_id> <block_id>\n\ + 3) odsp_api_test -e <inst_id> <block_id>\n\ + 4) odsp_api_test -d <inst_id> <block_id>\n\ + 5) odsp_api_test -t <src_id> <event_id> <src_opaque>\n\ \n\ In the first form, set a parameter with a value, needs instance and block id.\n\ In the second form, get a parameters value, needs instance and block id.\n\ - ", stdout); + In the third & fourth form, needs instance and block id.\n\ + In the fifth form, manually trigger an event, needs src id, event id and src_opaque\n", stdout); exit(EXIT_FAILURE); } @@ -78,21 +84,59 @@ void get_param(struct iaxxx_odsp_hw *ioh, unsigned int param_id, } } +void plugin_control(struct iaxxx_odsp_hw *ioh, unsigned int inst_id, + unsigned int block_id, int control) { + int err = 0; + + if (control) + err = iaxxx_odsp_plugin_enable(ioh, inst_id, block_id); + else + err = iaxxx_odsp_plugin_disable(ioh, inst_id, block_id); + + if (err != 0) { + ALOGE("Failed to enable/disable the plugin. Error %d", err); + } else { + if (control) { + ALOGD("Plugin enabled!!"); + } else { + ALOGD("Plugin disbled!!"); + } + } +} + +void trigger_event(struct iaxxx_odsp_hw *ioh, unsigned int src_id, + unsigned int event_id, unsigned int src_opaque) +{ + int err = 0; + + err = iaxxx_odsp_evt_trigger(ioh, src_id, event_id, src_opaque); + + if (err != 0) { + ALOGE("Failed to trigger event! Error:%d", err); + } +} + + int main(int argc, char *argv[]) { struct iaxxx_odsp_hw *ioh = NULL; char use_case; unsigned int param_id, param_val, inst_id, block_id; + unsigned int src_id, event_id, src_opaque; int c, err = 0; // Set param option needs 4 arguments const int set_param_req_arg = 4; // Get param option needs 3 arguments const int get_param_req_arg = 3; + // Plugin control needs 2 arguments + const int plugin_control_arg = 2; + // Trigger event needs 3 args + const int trigger_event_req_arg = 3; if (argc <= 1) { usage(); } - while ((c = getopt_long (argc, argv, "s:g:", long_options, NULL)) != -1) { + while ((c = getopt_long (argc, argv, "s:g:e:d:t:", long_options, NULL)) != -1) { switch (c) { case 's': use_case = 's'; @@ -132,6 +176,58 @@ int main(int argc, char *argv[]) { ALOGE("Get parameter - param_id %d inst_id %d block_id %d", param_id, inst_id, block_id); break; + + case 'e': + use_case = 'e'; + // reset optind by 1 + --optind; + if (optind + plugin_control_arg > argc) { + usage(); + } + + inst_id = strtol(argv[optind], NULL, 0); + optind++; + block_id = strtol(argv[optind], NULL, 0); + optind++; + + ALOGE("Enable plugin - inst_id %d block_id %d", inst_id, block_id); + break; + + case 'd': + use_case = 'd'; + // reset optind by 1 + --optind; + if (optind + plugin_control_arg > argc) { + usage(); + } + + inst_id = strtol(argv[optind], NULL, 0); + optind++; + block_id = strtol(argv[optind], NULL, 0); + optind++; + + ALOGE("Disable plugin - inst_id %d block_id %d", inst_id, block_id); + break; + + case 't': + use_case = 't'; + // reset optind by 1 + --optind; + if (optind + trigger_event_req_arg > argc) { + usage(); + } + + src_id = strtol(argv[optind], NULL, 0); + optind++; + event_id = strtol(argv[optind], NULL, 0); + optind++; + src_opaque = strtol(argv[optind], NULL, 0); + optind++; + + ALOGE("Trigger Event - src_id %d event_id %d src_opaque %d", + src_id, event_id, src_opaque); + break; + default: usage(); break; @@ -145,12 +241,27 @@ int main(int argc, char *argv[]) { goto exit; } - if (use_case == 's') { - set_param(ioh, param_id, param_val, inst_id, block_id); - } else if (use_case == 'g') { - get_param(ioh, param_id, inst_id, block_id); - } + switch(use_case) { + case 's': + set_param(ioh, param_id, param_val, inst_id, block_id); + break; + case 'g': + get_param(ioh, param_id, inst_id, block_id); + break; + case 'e': + plugin_control(ioh, inst_id, block_id, 1); + break; + case 'd': + plugin_control(ioh, inst_id, block_id, 0); + break; + case 't': + trigger_event(ioh, src_id, event_id, src_opaque); + break; + default: + ALOGE("Invalid usecase"); + break; + } exit: if (ioh) { err = iaxxx_odsp_deinit(ioh); diff --git a/tests/oslo_package_test.c b/tests/oslo_package_test.c index ba21388..04f28ca 100644 --- a/tests/oslo_package_test.c +++ b/tests/oslo_package_test.c @@ -345,7 +345,7 @@ int main(int argc, char *argv[]) goto exit; } - /* Destory Dummy sensor plugin */ + /* destroy Dummy sensor plugin */ pi.block_id = 1; pi.inst_id = 3; err = ioctl(fileno(odsp_node), ODSP_PLG_DESTROY, (unsigned long)&pi); @@ -355,7 +355,7 @@ int main(int argc, char *argv[]) goto exit; } - /* Destory Buffer plugin */ + /* destroy Buffer plugin */ pi.block_id = 1; pi.inst_id = 2; err = ioctl(fileno(odsp_node), ODSP_PLG_DESTROY, (unsigned long)&pi); diff --git a/tests/setparamblk_test.c b/tests/setparamblk_test.c new file mode 100755 index 0000000..f3ddb04 --- /dev/null +++ b/tests/setparamblk_test.c @@ -0,0 +1,283 @@ +/* + * Copyright (C) 2018 Knowles Electronics + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <errno.h> +#include <getopt.h> +#include <string.h> +#include "iaxxx_odsp_hw.h" + + +#define MAX_FILE_PATH_SIZE (512) + +enum { + SETPARAMBLK_TEST_OPTION_FROMFILE, + SETPARAMBLK_TEST_OPTION_CUSTOM, + SETPARAMBLK_TEST_OPTION_WITHACK +}; + + +static struct option const long_options[] = +{ + {"setparamblkfromfile", no_argument, NULL, 's'}, + {"customsetparamblk", no_argument, NULL, 'c'}, + {"setparamblkwithack", no_argument, NULL, 'k'}, + {"filename", required_argument, NULL, 'f'}, + {"plugininstanceid", required_argument, NULL, 'i'}, + {"paramblkid", required_argument, NULL, 'p'}, + {"procblockid", required_argument, NULL, 'b'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} +}; + + +static int setparamblk_with_ack_test(struct iaxxx_odsp_hw *odsp_hw, + const uint32_t inst_id, + const uint32_t block_id, + const uint32_t param_blk_id, + const uint32_t max_retries, + uint32_t* response_data, + const uint32_t response_data_size_in_words, + const char *file) +{ + int ret = -1; + uint32_t *data = NULL; + FILE *fp = NULL; + long file_len, bytes_read; + + fp = fopen(file, "rb"); + if (NULL == fp) { + fprintf(stderr,"Failed to find the file at the location %s", file); + goto setparamblk_with_ack_test; + } + + fseek(fp, 0, SEEK_END); + file_len = ftell(fp); + fseek(fp, 0, SEEK_SET); + data = malloc(file_len); + if (!data) { + fprintf(stderr,"Error allocating memory"); + goto setparamblk_with_ack_test; + } + + + bytes_read = fread(data, 1, file_len, fp); + if (bytes_read != file_len) { + fprintf(stderr,"Failed to read the complete file"); + fclose(fp); + goto setparamblk_with_ack_test; + } + fclose(fp); + + ret = iaxxx_odsp_plugin_set_parameter_blk_with_ack(odsp_hw, inst_id, + param_blk_id, block_id, data, + file_len * sizeof(uint32_t), + response_data, + response_data_size_in_words, + max_retries); + +setparamblk_with_ack_test: + if (data) + free(data); + return ret; +} + +void usage() { + fprintf(stdout, "\ + USAGE -\n\ + -------\n\ + 1) setparamblk_test -s -f <file_name> -i <plugin-instance-id> -p <param-blk-id> -b <proc-block-id> \n\ + 2) setparamblk_test -k -f <file_name> -i <plugin-instance-id> -p <param-blk-id> -b <proc-block-id> -m <max-retries> -r <response-size-in-words> \n\ + 3) setparamblk_test -c -f <file_name> -i <plugin-instance-id> -p <param-blk-id> -b <proc-block-id> \n\ + \n\ + In the first form, test setparamblk from a file.\n\ + In the second form, test setparamblk from a file with retry and acknowledgement\n\ + In the second form, test setparamblk from a file for custom configuration of plugin.\n\n"); + + exit(0); +} + + +int main(int argc, char **argv) +{ + struct iaxxx_odsp_hw* odsp_hw = NULL; + int err = 0; + + int plugin_instance_id = -1; + int proc_block_id = -1; + int param_blk_id = -1; + int max_retries = -1; + int response_data_size_in_words = -1; + uint32_t *response_data = NULL; + char file_path[MAX_FILE_PATH_SIZE]; + int setparamblk_test_option = -1; + int index = 0; + + /* getopt_long stores the option index here. */ + int option_index = 0; + int ch; + + file_path[0] = '\0'; + + if (argc <= 1) { + usage(); + } + + while (1) { + ch = getopt_long(argc, argv, "sckhf:p:i:b:m:r:", + long_options, &option_index); + + /* Detect the end of the options. */ + if (ch == -1) + break; + + switch (ch) { + case 's': + setparamblk_test_option = SETPARAMBLK_TEST_OPTION_FROMFILE; + break; + + case 'c': + setparamblk_test_option = SETPARAMBLK_TEST_OPTION_CUSTOM; + break; + + case 'k': + setparamblk_test_option = SETPARAMBLK_TEST_OPTION_WITHACK; + break; + + case 'f': + strcpy(file_path, optarg); + break; + + case 'p': + param_blk_id = atoi(optarg); + break; + + case 'i': + plugin_instance_id = atoi(optarg); + break; + + case 'b': + proc_block_id = atoi(optarg); + break; + + case 'm': + max_retries = atoi(optarg); + break; + + case 'r': + response_data_size_in_words = atoi(optarg); + break; + + case 'h': + default: + usage(); + } + } + + if (setparamblk_test_option == -1) { + fprintf(stderr,"\n No Test Option Parameter! \n"); + usage(); + } + + if (file_path[0] == '\0') { + fprintf(stderr,"\n No File Name Parameter! \n"); + usage(); + } + + if (plugin_instance_id == -1) { + fprintf(stderr,"\n No Plugin_instance_id Parameter! \n"); + usage(); + } + + if (param_blk_id == -1) { + fprintf(stderr,"\n No Param_blk_id Parameter! \n"); + usage(); + } + + if (proc_block_id == -1) { + fprintf(stderr,"\n No proc_block_id Parameter! \n"); + usage(); + } + if (setparamblk_test_option == SETPARAMBLK_TEST_OPTION_WITHACK) { + + if (max_retries == -1) { + fprintf(stderr,"\n No max retries Parameter! \n"); + usage(); + } + + if (response_data_size_in_words <= 0) { + fprintf(stderr,"\n No or Invalid Response data size Parameter! \n"); + usage(); + } + + response_data = (uint32_t*) malloc(sizeof(uint32_t) * response_data_size_in_words); + + if (!response_data) { + fprintf(stderr,"\n malloc failed! \n", stdout); + exit(0); + } + + memset(response_data, 0, sizeof(uint32_t) * response_data_size_in_words); + } + + if ((odsp_hw = iaxxx_odsp_init()) == NULL) { + fprintf(stderr,"\n ODSP Init Failed! \n"); + return 0; + } + + if (setparamblk_test_option == SETPARAMBLK_TEST_OPTION_FROMFILE) { + fprintf(stdout, "\n## Setparamblk_test from file.. ##\n"); + err = iaxxx_odsp_plugin_set_parameter_blk_from_file(odsp_hw, + plugin_instance_id, + param_blk_id, + proc_block_id, + file_path); + } else if (setparamblk_test_option == SETPARAMBLK_TEST_OPTION_CUSTOM) { + fprintf(stdout, "\n## Setparamblk_test custom configuration.. ##\n"); + err = iaxxx_odsp_plugin_set_custom_cfg(odsp_hw, plugin_instance_id, + proc_block_id, param_blk_id, 0, + file_path); + } else if (setparamblk_test_option == SETPARAMBLK_TEST_OPTION_WITHACK) { + + fprintf(stdout, "\n## Setparamblk_test with ack and retry.. ##\n"); + err = setparamblk_with_ack_test(odsp_hw, plugin_instance_id, + proc_block_id, param_blk_id, + max_retries, response_data, + response_data_size_in_words, file_path); + if (!err) { + // Print the response data + fprintf(stdout,"\nResponse Data::"); + for (index = 0; index < response_data_size_in_words; index++) { + if (!(index % 8)) + fprintf(stdout, "\n0x%04x: ", index); + + fprintf(stdout, "0x%08x ", response_data[index]); + } + fprintf(stdout, "\n"); + } + free(response_data); + } + + iaxxx_odsp_deinit(odsp_hw); + if (err) + fprintf(stdout, "\n## Setparamblk_test failed!! ##\n\n"); + else + fprintf(stdout, "\n## Setparamblk_test done. ##\n\n"); + + return 0; +}
\ No newline at end of file diff --git a/tests/tunnel_test_sensor.c b/tests/tunnel_test_sensor.c index 8d648e3..46b4b02 100644 --- a/tests/tunnel_test_sensor.c +++ b/tests/tunnel_test_sensor.c @@ -21,6 +21,7 @@ #include <stdbool.h> #include <errno.h> #include <sys/ioctl.h> +#include <unistd.h> #define LOG_TAG "ia_tunneling_sensor_test" @@ -24,7 +24,7 @@ #include <sys/ioctl.h> #include <unistd.h> -#include <cutils/log.h> +#include <log/log.h> #include "iaxxx-tunnel-intf.h" #include "iaxxx-system-identifiers.h" #include "tunnel.h" @@ -150,3 +150,20 @@ int ia_read_tunnel_data(struct ia_tunneling_hal *thdl, return read_bytes; } + +int ia_set_tunnel_out_buf_threshold(struct ia_tunneling_hal *thdl, + uint32_t threshold) +{ + int err; + + FUNCTION_ENTRY_LOG; + + err = ioctl(thdl->tunnel_dev, TUNNEL_SET_EVENT_THRESHOLD, + threshold); + if (err == -1) { + ALOGE("%s: ERROR Tunnel terminate failed %s", + __func__, strerror(errno)); + } + + return err; +} @@ -77,6 +77,16 @@ int ia_disable_tunneling_source(struct ia_tunneling_hal *tun_hdl, int ia_read_tunnel_data(struct ia_tunneling_hal *tun_hdl, void *buf, int buf_size); /** + * Set the output buffer threshold for the event generation. + * + * Input - threshold + * + * Output - Zero on success, errno on failure. + */ +int ia_set_tunnel_out_buf_threshold(struct ia_tunneling_hal *thdl, + uint32_t threshold); + +/** * Closes tunneling port * * Input - tun_hdl - Handle to the Tunneling HAL. |