Adds in a "fake" decoder - a simple made up byte processor that will exercise the external C-API decoder infrastructure.
Attaches to any CS byte stream from the snapshot tests and will split into a simple made up protocol, generating protocol packets and generic packets per a real decoder. --- .../c_api_echo_test/ext_dcd_echo_test.c | 103 ++++++++++++++++++++ .../c_api_echo_test/ext_dcd_echo_test.h | 78 ++++++++++++++++ .../c_api_echo_test/ext_dcd_echo_test_fact.c | 104 +++++++++++++++++++++ .../c_api_echo_test/ext_dcd_echo_test_fact.h | 48 ++++++++++ 4 files changed, 333 insertions(+) create mode 100644 decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test.c create mode 100644 decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test.h create mode 100644 decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test_fact.c create mode 100644 decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test_fact.h
diff --git a/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test.c b/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test.c new file mode 100644 index 0000000..e05e7d2 --- /dev/null +++ b/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test.c @@ -0,0 +1,103 @@ +/* +* \file ext_dcd_echo_test_fact.c +* \brief OpenCSD : Echo test custom decoder factory +* +* \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. +*/ + +/* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its contributors +* may be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "c_api/ocsd_c_api_types.h" +#include "ext_dcd_echo_test_fact.h" +#include "ext_dcd_echo_test.h" + +/** The name of the decoder */ +#define DECODER_NAME "ECHO_TEST" + +/** Declare the trace data input function for the decoder - passed to library as call-back. */ +static ocsd_datapath_resp_t echo_dcd_trace_data_in(const void *decoder_handle, + const ocsd_datapath_op_t op, + const ocsd_trc_index_t index, + const uint32_t dataBlockSize, + const uint8_t *pDataBlock, + uint32_t *numBytesProcessed); + +/** Allow library to update the packet monitor / sink in use flags to allow decoder to call CB as appropriate.*/ +static void echo_dcd_update_mon_flags(const void *decoder_handle, const int flags); + +/** init decoder on creation, along with library instance structure */ +void echo_dcd_init(echo_decoder_t *decoder, ocsd_extern_dcd_inst_t *p_decoder_inst, const echo_dcd_cfg_t *p_config, const ocsd_extern_dcd_cb_fns *p_lib_callbacks) +{ + // initialise the decoder instance. + + // zero out the structure + memset(decoder, 0, sizeof(echo_decoder_t)); + + memcpy(&(decoder->reg_config), p_config, sizeof(echo_dcd_cfg_t)); // copy in the config structure. + memcpy(&(decoder->lib_fns), p_lib_callbacks, sizeof(p_lib_callbacks)); // copy in the the library callbacks. + + + // fill out the info to pass back to the library. + + // set up the decoder handle, name and CS Trace ID + p_decoder_inst->decoder_handle = decoder; + p_decoder_inst->p_decoder_name = DECODER_NAME; + p_decoder_inst->cs_id = p_config->cs_id; + + // set up the data input callback + p_decoder_inst->fn_data_in = echo_dcd_trace_data_in; + p_decoder_inst->fn_update_pkt_mon = echo_dcd_update_mon_flags; +} + +void echo_dcd_pkt_tostr(echo_dcd_pkt_t *pkt, char *buffer, const int buflen) +{ + snprintf(buffer, buflen, "ECHOTP[0x%02X] (0x%08X) \n", pkt->header, pkt->data); +} + +void echo_dcd_update_mon_flags(const void *decoder_handle, const int flags) +{ + ((echo_decoder_t *)decoder_handle)->lib_fns.packetCBFlags = flags; +} + +/**** Main decoder implementation ****/ + +ocsd_datapath_resp_t echo_dcd_trace_data_in(const void *decoder_handle, + const ocsd_datapath_op_t op, + const ocsd_trc_index_t index, + const uint32_t dataBlockSize, + const uint8_t *pDataBlock, + uint32_t *numBytesProcessed) +{ + ocsd_datapath_resp_t resp = OCSD_RESP_CONT; + + return resp; +} diff --git a/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test.h b/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test.h new file mode 100644 index 0000000..20453b5 --- /dev/null +++ b/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test.h @@ -0,0 +1,78 @@ +/* +* \file ext_dcd_echo_test_fact.h +* \brief OpenCSD : Echo test custom decoder +* +* \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. +*/ + +/* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its contributors +* may be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef ARM_EXT_DCD_ECHO_TEST_H_INCLUDED +#define ARM_EXT_DCD_ECHO_TEST_H_INCLUDED + +#include <inttypes.h> +#include "c_api/ocsd_c_api_custom.h" + +/* + Echo test decoder designed to test the external decoder C - API infrastructure. + Echo decoders can be attached to any CS byte stream and will mainly echo the data + back with a simple "protocol" decoded - not based on real protocol. + + Will test callback infrastructure and provide an implemntation example for a real external decoder. + +*/ + +/*** decoder types ***/ + +typedef struct _echo_dcd_cfg { + unsigned char cs_id; +} echo_dcd_cfg_t; + +typedef struct _echo_dcd_pkt { + uint8_t header; + uint32_t data; +} echo_dcd_pkt_t; + +typedef struct _echo_decoder { + uint8_t data_in[5]; /** input buffer for current packet */ + int data_in_count; /** 5 bytes per packet*/ + echo_dcd_pkt_t curr_pkt; /** current packet */ + echo_dcd_cfg_t reg_config; /** Decoder config "registers" - in this case just the CSID value */ + ocsd_extern_dcd_cb_fns lib_fns; /** Library Callback functions */ + int createFlags; /** creation / operational options -> packet only / full decode */ +} echo_decoder_t; + +/*** internal decoder API ***/ + +/** decoder will contain packet printing logic */ +void echo_dcd_pkt_tostr(echo_dcd_pkt_t *pkt, char *buffer, const int buflen); + +/** init decoder on creation, along with library instance structure */ +void echo_dcd_init(echo_decoder_t *decoder, ocsd_extern_dcd_inst_t *p_decoder_inst, const echo_dcd_cfg_t *p_config, const ocsd_extern_dcd_cb_fns *p_lib_callbacks); + +#endif /* ARM_EXT_DCD_ECHO_TEST_H_INCLUDED */ + diff --git a/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test_fact.c b/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test_fact.c new file mode 100644 index 0000000..ecf4583 --- /dev/null +++ b/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test_fact.c @@ -0,0 +1,104 @@ +/* +* \file ext_dcd_echo_test_fact.c +* \brief OpenCSD : Echo test custom decoder factory +* +* \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. +*/ + +/* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its contributors +* may be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "ext_dcd_echo_test_fact.h" +#include "ext_dcd_echo_test.h" + +/** Decoder factory implementation. + Permits registration of the decoder with the library. + + Provides creation and deletion functionality for decoder instances. +*/ + +/*-- functions meeting the ext decode factory structure requirements */ + +/** Required function to create a decoder instance - fills in the decoder struct supplied. */ +static ocsd_err_t ext_echo_create(const int create_flags, const void *decoder_cfg, const ocsd_extern_dcd_cb_fns *p_lib_callbacks, ocsd_extern_dcd_inst_t *p_decoder_inst); + +/** Required Function to destroy a decoder instance - indicated by decoder handle */ +static ocsd_err_t ext_echo_destroy(const void *decoder_handle); + +/** Required Function to extract the CoreSight Trace ID from the configuration structure */ +static ocsd_err_t ext_echo_csid_from_cfg(const void *decoder_cfg, unsigned char *p_csid); + +/** Optional Function to convert a protocol specific trace packet to human readable string */ +static ocsd_err_t ext_echo_pkt_to_str(const void *trc_pkt, char *buffer, const int buflen); + +static ocsd_extern_dcd_fact_t echo_test_decoder_fact; + +ocsd_extern_dcd_fact_t *ext_echo_get_dcd_fact() +{ + echo_test_decoder_fact.createDecoder = ext_echo_create; + echo_test_decoder_fact.destroyDecoder = ext_echo_destroy; + echo_test_decoder_fact.csidFromConfig = ext_echo_csid_from_cfg; + echo_test_decoder_fact.pktToString = ext_echo_pkt_to_str; + echo_test_decoder_fact.protocol_id = OCSD_PROTOCOL_END; + return &echo_test_decoder_fact; +} + +ocsd_err_t ext_echo_create(const int create_flags, const void *decoder_cfg, const ocsd_extern_dcd_cb_fns *p_lib_callbacks, ocsd_extern_dcd_inst_t *p_decoder_inst) +{ + echo_decoder_t *decoder = NULL; + + if ((decoder = (echo_decoder_t *)malloc(sizeof(echo_decoder_t))) == NULL) + return OCSD_ERR_MEM; + + echo_dcd_init(decoder,p_decoder_inst,(echo_dcd_cfg_t *)decoder_cfg, p_lib_callbacks); + + decoder->createFlags = create_flags; + + return OCSD_OK; +} + +ocsd_err_t ext_echo_destroy(const void *decoder_handle) +{ + free((echo_decoder_t *)decoder_handle); + return OCSD_OK; +} + +ocsd_err_t ext_echo_csid_from_cfg(const void *decoder_cfg, unsigned char *p_csid) +{ + *p_csid = ((echo_dcd_cfg_t *)decoder_cfg)->cs_id; + return OCSD_OK; +} + +ocsd_err_t ext_echo_pkt_to_str(const void *trc_pkt, char *buffer, const int buflen) +{ + echo_dcd_pkt_tostr((echo_dcd_pkt_t*)trc_pkt, buffer, buflen); + return OCSD_OK; +} diff --git a/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test_fact.h b/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test_fact.h new file mode 100644 index 0000000..b287c0c --- /dev/null +++ b/decoder/tests/ext_dcd_test_eg/c_api_echo_test/ext_dcd_echo_test_fact.h @@ -0,0 +1,48 @@ +/* +* \file ext_dcd_echo_test_fact.h +* \brief OpenCSD : Echo test custom decoder factory +* +* \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved. +*/ + +/* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its contributors +* may be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef ARM_EXT_DCD_ECHO_TEST_FACT_H_INCLUDED +#define ARM_EXT_DCD_ECHO_TEST_FACT_H_INCLUDED + +/* Creates echo test decoders to test the external decoder C-API infrastructure. + Echo decoders can be attached to any CS byte stream and will mainly echo the data + back with a simple "protocol" decoded - not based on real protocol. + */ + +#include "c_api/ocsd_c_api_custom.h" + +/* return an initialised structure with the factory functions */ +ocsd_extern_dcd_fact_t *ext_echo_get_dcd_fact(); + + +#endif /*ARM_EXT_DCD_ECHO_TEST_FACT_H_INCLUDED */