| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2006, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bsettop_smessage.h $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * Message filtering and raw ts capture api. Note inconsistent naming of |
|---|
| 16 | * types and members in the structures. It was done in attempt to preserve |
|---|
| 17 | * similarity with bsettop_message.h api. |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: $ |
|---|
| 21 | * |
|---|
| 22 | * |
|---|
| 23 | ***************************************************************************/ |
|---|
| 24 | |
|---|
| 25 | #ifndef __BSETTOP_SMESSAGE_H__ |
|---|
| 26 | #define __BSETTOP_SMESSAGE_H__ |
|---|
| 27 | |
|---|
| 28 | #include "bapp_types.h" |
|---|
| 29 | |
|---|
| 30 | /*************************************************************************** |
|---|
| 31 | Summary: |
|---|
| 32 | message stream handle. |
|---|
| 33 | SeeAlso: |
|---|
| 34 | None |
|---|
| 35 | ***************************************************************************/ |
|---|
| 36 | typedef struct smessage_stream * smessage_stream_t; |
|---|
| 37 | /*************************************************************************** |
|---|
| 38 | Summary: |
|---|
| 39 | Section filter structure, See register reference for typical use with |
|---|
| 40 | Broadcom chips. |
|---|
| 41 | ***************************************************************************/ |
|---|
| 42 | typedef struct smessage_filter { |
|---|
| 43 | uint8_t mask[16]; /* Bits to be ignored. See Description. */ |
|---|
| 44 | uint8_t coef[16]; /* Bits to be included. See Description. */ |
|---|
| 45 | uint8_t excl[16]; /* Bits to be excluded. Doesn't apply to Venom2 platforms. See Description. */ |
|---|
| 46 | } smessage_filter; |
|---|
| 47 | |
|---|
| 48 | /*************************************************************************** |
|---|
| 49 | Summary: |
|---|
| 50 | Message capture format enumeration. Following formats are supported: |
|---|
| 51 | |
|---|
| 52 | smessage_format_ts - capture raw ts data in to circular buffer |
|---|
| 53 | smessage_format_tsc - capture ts data in to provided buffer with callback |
|---|
| 54 | smessage_format_psi - capture psi sections in to provided buffer with callback |
|---|
| 55 | |
|---|
| 56 | Circular buffer for raw ts capture is allocated internaly by the module, in |
|---|
| 57 | case of smessage_format_tsc and smessage_format_psi buffer must be allocated by |
|---|
| 58 | caller and pointer provided as part of smessage_stream_params_t structure. |
|---|
| 59 | SeeAlso: |
|---|
| 60 | smessage_open |
|---|
| 61 | ***************************************************************************/ |
|---|
| 62 | typedef enum smessage_format_t { |
|---|
| 63 | smessage_format_ts, |
|---|
| 64 | smessage_format_tsc, |
|---|
| 65 | smessage_format_psi |
|---|
| 66 | } smessage_format; |
|---|
| 67 | |
|---|
| 68 | /*************************************************************************** |
|---|
| 69 | Summary: |
|---|
| 70 | Message callback type. |
|---|
| 71 | Description: |
|---|
| 72 | Application must provide function of this type to be called when message is |
|---|
| 73 | captured by message filters. This is the only way for application to obtain |
|---|
| 74 | the message. |
|---|
| 75 | After this call is called messages no longer will be captured by this filter |
|---|
| 76 | unless callback returns non NULL pointer. User must stop and restart |
|---|
| 77 | filter to resume message capture. |
|---|
| 78 | User can not call any smessage_* api from this callback or deadlock will |
|---|
| 79 | result. This callback is called directly from the filter task and it must |
|---|
| 80 | return fast. Delaying return from callback will adversly impact message filter |
|---|
| 81 | performance and may result in overflow for all other filters. If user has to |
|---|
| 82 | do substantial work he must convey the information to another task and do the |
|---|
| 83 | work in another context. If NULL is returned by callback message filtering |
|---|
| 84 | will stop for this filter. If non NULL pointer is returned filtering will |
|---|
| 85 | continue in to the buffer pointed by this pointed. |
|---|
| 86 | Input: |
|---|
| 87 | context - user context provided when message capture is started. |
|---|
| 88 | data_size - size of message captured in the provided buffer. |
|---|
| 89 | Returns: |
|---|
| 90 | New buffer pointer to use for next message capture or NULL if no more messages |
|---|
| 91 | should be captured and operation of filter should be suspended. If filter |
|---|
| 92 | should continue to capture messages in to old buffer, callback should return |
|---|
| 93 | same pointer that was originally passed to the start function. Size of the new |
|---|
| 94 | buffer must be same or larger than the size of the buffer passed in to the |
|---|
| 95 | smessage_start function. |
|---|
| 96 | SeeAlso: |
|---|
| 97 | smessage_stream_params_t |
|---|
| 98 | ***************************************************************************/ |
|---|
| 99 | typedef void * (*smessage_callback)(void * context, size_t data_size); |
|---|
| 100 | |
|---|
| 101 | /*************************************************************************** |
|---|
| 102 | Summary: |
|---|
| 103 | Invalid pid channel definition. |
|---|
| 104 | Description: |
|---|
| 105 | Constant signifying that this pid channel is invalid and defaul algorithm |
|---|
| 106 | for choosing pid channel should be used by mesage filter. |
|---|
| 107 | ***************************************************************************/ |
|---|
| 108 | #define SMESSAGE_INVALID_CHANNEL (0xffff) |
|---|
| 109 | |
|---|
| 110 | /*************************************************************************** |
|---|
| 111 | Summary: |
|---|
| 112 | Parameters for smessage_start function |
|---|
| 113 | Description: |
|---|
| 114 | Structure providing parameters for the smessage_start function. |
|---|
| 115 | |
|---|
| 116 | band - parser band |
|---|
| 117 | pid - pid to filter on |
|---|
| 118 | pid_channel - optional pid channel supplied by the caller. This field is set |
|---|
| 119 | to SMESSAGE_INVALID_CHANNEL by smessage_stream_params_init function. If |
|---|
| 120 | user does not chage this field, message filter will allocate pid channel |
|---|
| 121 | internally, else it will use value provided in this field. |
|---|
| 122 | filter - message filter |
|---|
| 123 | buffer - buffer for complete message |
|---|
| 124 | buffer_size - size of the buffer |
|---|
| 125 | crc_disabled - disable crc checking, crc checking enabled by default. |
|---|
| 126 | data_ready_callback - notification callback invoked when message is captured. |
|---|
| 127 | overflow - notification callback invoked when overflow happens. |
|---|
| 128 | |
|---|
| 129 | Only following parameters are used when stream is captured in to circular |
|---|
| 130 | buffer - band, pid, pid_channel, buffer_size. All other parameters are ignored. |
|---|
| 131 | |
|---|
| 132 | SeeAlso: |
|---|
| 133 | smessage_stream_params_init, smessage_start |
|---|
| 134 | ***************************************************************************/ |
|---|
| 135 | typedef struct smessage_stream_params_tag { |
|---|
| 136 | bband_t band; |
|---|
| 137 | uint16_t pid; |
|---|
| 138 | uint16_t pid_channel; |
|---|
| 139 | smessage_filter filter; |
|---|
| 140 | void * buffer; |
|---|
| 141 | size_t buffer_size; |
|---|
| 142 | bool crc_disabled; |
|---|
| 143 | smessage_callback data_ready_callback; |
|---|
| 144 | smessage_callback overflow; |
|---|
| 145 | void * callback_context; |
|---|
| 146 | void * priv; |
|---|
| 147 | } smessage_stream_params_t; |
|---|
| 148 | |
|---|
| 149 | /*************************************************************************** |
|---|
| 150 | Summary: |
|---|
| 151 | Initialize message subsystem. |
|---|
| 152 | Description: |
|---|
| 153 | Initialize message subsystem. No other funtions can be called before this |
|---|
| 154 | function is called or results of other function calls are undefined. |
|---|
| 155 | Input: |
|---|
| 156 | decode_cfgs - decoder configuration. |
|---|
| 157 | Returns: |
|---|
| 158 | b_ok if success, error code otherwise. |
|---|
| 159 | SeeAlso: |
|---|
| 160 | None |
|---|
| 161 | ***************************************************************************/ |
|---|
| 162 | bresult smessage_init(void *ctx); |
|---|
| 163 | |
|---|
| 164 | /*************************************************************************** |
|---|
| 165 | Summary: |
|---|
| 166 | Initialise parameters with default values. |
|---|
| 167 | Description: |
|---|
| 168 | Initialise parameters with default values. |
|---|
| 169 | Input: |
|---|
| 170 | params - parameter structure to fill with default values. |
|---|
| 171 | stream - stream for which to fill the structure. |
|---|
| 172 | Returns: |
|---|
| 173 | None |
|---|
| 174 | SeeAlso: |
|---|
| 175 | None |
|---|
| 176 | ***************************************************************************/ |
|---|
| 177 | void smessage_stream_params_init( smessage_stream_params_t *params, smessage_stream_t stream); |
|---|
| 178 | |
|---|
| 179 | /*************************************************************************** |
|---|
| 180 | Summary: |
|---|
| 181 | Open message with desired format. |
|---|
| 182 | Description: |
|---|
| 183 | This call returns message handle which obtained from internal list. Be sure to |
|---|
| 184 | call smessage_close after handle is no longer needed. Failing to do so will |
|---|
| 185 | result in memory leak and running out of handles. |
|---|
| 186 | Input: |
|---|
| 187 | format - desired format for the message capture. |
|---|
| 188 | Returns: |
|---|
| 189 | smessage_stream_t handle or NULL if the call fails. |
|---|
| 190 | SeeAlso: |
|---|
| 191 | smessage_close |
|---|
| 192 | ***************************************************************************/ |
|---|
| 193 | smessage_stream_t smessage_open(smessage_format format); |
|---|
| 194 | |
|---|
| 195 | /*************************************************************************** |
|---|
| 196 | Summary: |
|---|
| 197 | Start message capture. |
|---|
| 198 | Description: |
|---|
| 199 | This call will start message filtering. When message is captured it will be |
|---|
| 200 | copied in to the provided buffer and callback will be called. After message is |
|---|
| 201 | captured this filter will be disabled if NULL is returned by callback. If |
|---|
| 202 | caller desires to continue message filtering, callback should return a pointer |
|---|
| 203 | to the buffer in which to capture next message. |
|---|
| 204 | If message callback returns NULL and user wants to resume filtering, message |
|---|
| 205 | filter should be stopped and restarted with new parameters by calling this |
|---|
| 206 | api again. |
|---|
| 207 | This call will start capture and immediately return. |
|---|
| 208 | Input: |
|---|
| 209 | params - parameters for message capture |
|---|
| 210 | stream - stream handle for which to start capture. |
|---|
| 211 | Returns: |
|---|
| 212 | b_ok if capture was started, error code otherwise. |
|---|
| 213 | SeeAlso: |
|---|
| 214 | smessage_stop, smessage_stream_params_init |
|---|
| 215 | ***************************************************************************/ |
|---|
| 216 | bresult smessage_start(const smessage_stream_params_t * params, smessage_stream_t stream); |
|---|
| 217 | |
|---|
| 218 | /*************************************************************************** |
|---|
| 219 | Summary: |
|---|
| 220 | Stop message capture. |
|---|
| 221 | Description: |
|---|
| 222 | Stop message capture and if possible free internal hardware and software |
|---|
| 223 | resources. |
|---|
| 224 | Input: |
|---|
| 225 | stream - stream for which to stop message capture. |
|---|
| 226 | Returns: |
|---|
| 227 | b_ok if capture was stopped, error code otherwise. |
|---|
| 228 | SeeAlso: |
|---|
| 229 | smessage_stop |
|---|
| 230 | ***************************************************************************/ |
|---|
| 231 | bresult smessage_stop(smessage_stream_t stream); |
|---|
| 232 | |
|---|
| 233 | /*************************************************************************** |
|---|
| 234 | Summary: |
|---|
| 235 | Close message capture for given stream. |
|---|
| 236 | Description: |
|---|
| 237 | Close message capture for given stream and return stream to the list of free |
|---|
| 238 | streams. Usaer must call smessage_stop before calling this api and user must |
|---|
| 239 | call this api if he no longer needs stream handle. If this api is not called |
|---|
| 240 | stream handle will be leaked and eventually system will run out of stream |
|---|
| 241 | handles as they are limited. |
|---|
| 242 | Input: |
|---|
| 243 | stream - stream handle to free. |
|---|
| 244 | Returns: |
|---|
| 245 | None |
|---|
| 246 | SeeAlso: |
|---|
| 247 | smessage_open |
|---|
| 248 | ***************************************************************************/ |
|---|
| 249 | void smessage_close(smessage_stream_t stream); |
|---|
| 250 | |
|---|
| 251 | /*************************************************************************** |
|---|
| 252 | Summary: |
|---|
| 253 | Get circular buffer pointer for the stream capture buffer. |
|---|
| 254 | Description: |
|---|
| 255 | Get circular buffer pointer for the stream capture buffer. This call is valid |
|---|
| 256 | only for some types of message capture and using it for any other type will |
|---|
| 257 | result in error. |
|---|
| 258 | Input: |
|---|
| 259 | stream - desired stream handle |
|---|
| 260 | pbuffer - pointer to the pointer to buffer. After function returns this |
|---|
| 261 | variable will contain pointer to the start of avaiable data. |
|---|
| 262 | plength - pointer to the length of the data. After function returns this |
|---|
| 263 | variable will contain lenth of the valid data in the buffer. |
|---|
| 264 | Returns: |
|---|
| 265 | b_ok if call was successful error otherwise. If error is retured values of |
|---|
| 266 | *pbuffer and *plength are not defined and should be discarded. |
|---|
| 267 | SeeAlso: |
|---|
| 268 | smessage_read_complete, smessage_start |
|---|
| 269 | ***************************************************************************/ |
|---|
| 270 | bresult smessage_get_buffer(smessage_stream_t stream, const void ** pbuffer, size_t * plength); |
|---|
| 271 | |
|---|
| 272 | /*************************************************************************** |
|---|
| 273 | Summary: |
|---|
| 274 | Notify circular buffer about amount of comsumed data. |
|---|
| 275 | Description: |
|---|
| 276 | Notify circular buffer about amount of consumed data and advance read pointer. |
|---|
| 277 | This call is valid only for some types of message capture and using it for any |
|---|
| 278 | other type will result in error. Attempt to consume more data that is avalable |
|---|
| 279 | in the circular buffer will result in error. |
|---|
| 280 | Input: |
|---|
| 281 | stream - desired stream handle |
|---|
| 282 | consumed - amount of data that was consumed. Read pointer will be advanced by |
|---|
| 283 | that amount. |
|---|
| 284 | Returns: |
|---|
| 285 | b_ok if call was successful error otherwise. |
|---|
| 286 | SeeAlso: |
|---|
| 287 | smessage_get_buffer, smessage_start |
|---|
| 288 | ***************************************************************************/ |
|---|
| 289 | bresult smessage_read_complete(smessage_stream_t stream, size_t consumed); |
|---|
| 290 | |
|---|
| 291 | #endif /*__BSETTOP_SMESSAGE_H__*/ |
|---|