| Mike Leach | 17610e5 | 2016-09-16 15:55:11 +0100 | [diff] [blame] | 1 | Attaching External Custom Decoders {#custom_decoders} |
| 2 | ================================== |
| 3 | |
| 4 | @brief A description of the C API external decoder interface. |
| 5 | |
| 6 | Introduction |
| 7 | ------------ |
| 8 | |
| 9 | An external custom decoder is one which decodes a CoreSight trace byte stream from a source other |
| 10 | than an ARM core which cannot be decoded by the standard builtin decoders within the library. |
| 11 | |
| 12 | An example of this may be a trace stream from a DSP device. |
| 13 | |
| 14 | The external decoder API allows a suitable decoder to be attached to the library and used in the |
| 15 | same way as the built-in decoders. This means that the external decoder can be created and destroyed |
| 16 | using the decode tree API, and will integrate seamlessly with any ARM processor decoders that are part |
| 17 | of the same tree. |
| 18 | |
| 19 | An external decoder will be required to provide two standard structures:- |
| 20 | |
| 21 | - `ocsd_extern_dcd_fact_t` : this is a decoder "factory" that allows the creation of the custom decoders. |
| 22 | - `ocsd_extern_dcd_inst_t` : one of these structures exists for each instance of the custom decoder that is created. |
| 23 | |
| 24 | These structures consist of data and function pointers to allow integration with the library infrastructure. |
| 25 | |
| 26 | Registering A Decoder |
| 27 | --------------------- |
| 28 | |
| 29 | A single API function is provided to allow a decoder to be registered with the library by name. |
| 30 | |
| 31 | ocsd_err_t ocsd_register_custom_decoder(const char *name, ocsd_extern_dcd_fact_t *p_dcd_fact); |
| 32 | |
| 33 | This registers the custom decoder with the libary using the supplied name and factory structure. |
| 34 | Once registered, the standard API functions used with the built-in decoders will work with the custom decoder. |
| 35 | |
| 36 | The Factory Structure |
| 37 | --------------------- |
| 38 | This structure contains the interface that is registered with the library to allow the creation of custom decoder instances. |
| 39 | |
| 40 | The mandatory functions that must be provided include: |
| 41 | - `fnCreateCustomDecoder` : Creates a decoder. This function will fill in a `ocsd_extern_dcd_inst_t` structure for the decoder instance. |
| 42 | - `fnDestroyCustomDecoder` : Destroys the decoder. Takes the `decoder_handle` attribute of the instance structure. |
| 43 | - `fnGetCSIDFromConfig` : Extracts the CoreSight Trace ID from the decoder configuration structure. |
| 44 | May be called before the create function. The CSID is used as part of the creation process to |
| 45 | attach the decoder to the correct trace byte stream. |
| 46 | |
| 47 | `fnPacketToString` : This optional function will provide a human readable string from a protocol specific packet structure. |
| 48 | |
| 49 | `protocol_id` : This is filled in when the decoder type is registered with the library. Used in some API |
| 50 | calls to specify the decoder protocol type. |
| 51 | |
| 52 | |
| 53 | |
| 54 | The Decoder Instance Structure |
| 55 | ------------------------------ |
| 56 | |
| 57 | This structure must be filled in by the `fnCreateCustomDecoder` function implmentation. |
| 58 | |
| 59 | There is a single mandatory function in this structure: |
| 60 | |
| 61 | `fnTraceDataIn` : the decoder must provide this as this is called by the library to provide the |
| 62 | raw trace data to the decoder. |
| 63 | |
| 64 | There are a number of optional callback functions. These allow the custom decoder to call into the library |
| 65 | and use the same infrastructure as the builting decoders. The callbacks are registed with the custom decoder |
| 66 | as the libary performs initialisation of connections. |
| 67 | |
| 68 | For example, the library will connect the error logging interface to all the decoders. The instance structure |
| 69 | contains the `fnRegisterErrLogCB` function pointer which will register two error logging callbacks with the custom |
| 70 | decoder, `fnLogErrorCB` and `fnLogMsgCB`. These can then be called by the custom decoder, and the errors and |
| 71 | messages will appear in the same place as for the built-in decoders. |
| 72 | |
| 73 | Where a custom decoder does not require or support the optional callbacks, then the registration function is set to |
| 74 | 0 in the structure. |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |