1 /*
2 * \file ext_dcd_echo_test_fact.c
3 * \brief OpenCSD : Echo test custom decoder factory
4 *
5 * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved.
6 */
7
8 /*
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include "ext_dcd_echo_test_fact.h"
40 #include "ext_dcd_echo_test.h"
41
42 /** Decoder factory implementation.
43 Permits registration of the decoder with the library.
44
45 Provides creation and deletion functionality for decoder instances.
46 */
47
48 /*-- functions meeting the ext decode factory structure requirements */
49
50 /** Required function to create a decoder instance - fills in the decoder struct supplied. */
51 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);
52
53 /** Required Function to destroy a decoder instance - indicated by decoder handle */
54 static ocsd_err_t ext_echo_destroy(const void *decoder_handle);
55
56 /** Required Function to extract the CoreSight Trace ID from the configuration structure */
57 static ocsd_err_t ext_echo_csid_from_cfg(const void *decoder_cfg, unsigned char *p_csid);
58
59 /** Optional Function to convert a protocol specific trace packet to human readable string */
60 static ocsd_err_t ext_echo_pkt_to_str(const void *trc_pkt, char *buffer, const int buflen);
61
62 static ocsd_extern_dcd_fact_t echo_test_decoder_fact;
63
ext_echo_get_dcd_fact()64 ocsd_extern_dcd_fact_t *ext_echo_get_dcd_fact()
65 {
66 echo_test_decoder_fact.createDecoder = ext_echo_create;
67 echo_test_decoder_fact.destroyDecoder = ext_echo_destroy;
68 echo_test_decoder_fact.csidFromConfig = ext_echo_csid_from_cfg;
69 echo_test_decoder_fact.pktToString = ext_echo_pkt_to_str;
70 echo_test_decoder_fact.protocol_id = OCSD_PROTOCOL_END;
71 return &echo_test_decoder_fact;
72 }
73
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)74 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)
75 {
76 echo_decoder_t *decoder = NULL;
77
78 if ((decoder = (echo_decoder_t *)malloc(sizeof(echo_decoder_t))) == NULL)
79 return OCSD_ERR_MEM;
80
81 echo_dcd_init(decoder,p_decoder_inst,(echo_dcd_cfg_t *)decoder_cfg, p_lib_callbacks);
82
83 decoder->createFlags = create_flags;
84
85 return OCSD_OK;
86 }
87
ext_echo_destroy(const void * decoder_handle)88 ocsd_err_t ext_echo_destroy(const void *decoder_handle)
89 {
90 free((echo_decoder_t *)decoder_handle);
91 return OCSD_OK;
92 }
93
ext_echo_csid_from_cfg(const void * decoder_cfg,unsigned char * p_csid)94 ocsd_err_t ext_echo_csid_from_cfg(const void *decoder_cfg, unsigned char *p_csid)
95 {
96 *p_csid = ((echo_dcd_cfg_t *)decoder_cfg)->cs_id;
97 return OCSD_OK;
98 }
99
ext_echo_pkt_to_str(const void * trc_pkt,char * buffer,const int buflen)100 ocsd_err_t ext_echo_pkt_to_str(const void *trc_pkt, char *buffer, const int buflen)
101 {
102 echo_dcd_pkt_tostr((echo_dcd_pkt_t*)trc_pkt, buffer, buflen);
103 return OCSD_OK;
104 }
105