source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/xpt/7552/bxpt_mesg.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 88.2 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2011, 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: bxpt_mesg.c $
11 * $brcm_Revision: Hydra_Software_Devel/16 $
12 * $brcm_Date: 12/20/11 4:27p $
13 *
14 * Porting interface code for the data transport core.
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/xpt/base2/bxpt_mesg.c $
19 *
20 * Hydra_Software_Devel/16   12/20/11 4:27p gmullen
21 * SW7425-1868: Merged to Hydra
22 *
23 * Hydra_Software_Devel/SW7425-1868/1   12/20/11 4:24p gmullen
24 * SW7425-1868: Added filter offset support
25 *
26 * Hydra_Software_Devel/15   12/15/11 2:32p gmullen
27 * SW7425-1952: Merged changes to mainline
28 *
29 * Hydra_Software_Devel/SW7425-1952/1   12/14/11 4:16p gmullen
30 * SW7425-1952: Do not change SPECIAL_TYPE field. BXPT_SAM_* uses it
31 *
32 * Hydra_Software_Devel/14   11/15/11 2:54p gmullen
33 * SW7346-562: Fixed addresses calculation bug
34 *
35 * Hydra_Software_Devel/13   10/28/11 4:15p jtna
36 * SW7425-1486: remove BXPT_GetMesgBufferErrorStatus() in favor of
37 * BXPT_Mesg_GetErrorStatus()
38 *
39 * Hydra_Software_Devel/12   10/28/11 4:03p jtna
40 * SW7425-1486: added BXPT_Mesg_GetErrorStatus()
41 *
42 * Hydra_Software_Devel/11   10/26/11 11:41a gmullen
43 * SW7231-403: Merged to Hydra
44 *
45 * Hydra_Software_Devel/SW7231-403/1   10/26/11 11:35a gmullen
46 * SW7231-403: Original PID channel to buffer mapping interfered with
47 * subsequent mappings
48 *
49 * Hydra_Software_Devel/10   8/4/11 11:04a gmullen
50 * SW7346-398: Fixed coverity warning
51 *
52 * Hydra_Software_Devel/9   7/15/11 9:05a gmullen
53 * SW7346-308: Merged fix to Hydra
54 *
55 * Hydra_Software_Devel/SW7346-308/1   7/14/11 4:59p gmullen
56 * SW7346-308: Added BXPT_RemoveFilterFromGroupAndBuffer() and
57 * BXPT_Mesg_GetPidChannelFromBufferNum(), editted comments in bxpt.h
58 *
59 * Hydra_Software_Devel/8   7/13/11 1:37p gmullen
60 * SW7346-317: Merged fix to Hydra branch
61 *
62 * Hydra_Software_Devel/SW7346-317/1   7/13/11 11:47a gmullen
63 * SW7346-317: Added message buffer counting
64 *
65 * Hydra_Software_Devel/7   12/17/10 4:08p gmullen
66 * SW7425-60: Set PID2BUF mapping when starting message capture and PID
67 * channel recording
68 *
69 * Hydra_Software_Devel/6   12/9/10 11:28a gmullen
70 * SW7422-20: Fixed incorrect calc of PID2BUF register address
71 *
72 * Hydra_Software_Devel/5   12/3/10 5:22p gmullen
73 * SW7422-87: Added per-PID channel R-pipe support for mesg filters
74 *
75 * Hydra_Software_Devel/4   11/15/10 5:17p gmullen
76 * SW7422-20: Removed restriction that a PID channel must be allocated
77 * before a message filter can be attached to it's buffer
78 *
79 * Hydra_Software_Devel/3   11/6/10 4:57p gmullen
80 * SW7422-20: Fixed incorrect register address calc
81 *
82 * Hydra_Software_Devel/2   10/28/10 2:08p gmullen
83 * SW7422-20: Checkin ported files
84 *
85 * Hydra_Software_Devel/70   9/3/10 3:58p gmullen
86 * SW35230-1172: Fixed message size calcs in BXPT_CheckBufferWithWrap()
87 *
88 * Hydra_Software_Devel/69   8/30/10 5:24p gmullen
89 * SW7403-924: Protected access to the PID and SPID table from other
90 * modules in the PI
91 *
92 * Hydra_Software_Devel/68   8/27/10 3:46p gmullen
93 * SW35230-1172: Merged to mainline
94 *
95 * Hydra_Software_Devel/SW35230-1172/2   8/27/10 3:35p gmullen
96 * SW35230-1172: Removed old implementation of BXPT_CheckBuffer()
97 *
98 * Hydra_Software_Devel/SW35230-1172/1   8/27/10 2:16p gmullen
99 * SW35230-1172: Added BXPT_CheckBufferWithWrap()
100 *
101 * Hydra_Software_Devel/67   5/25/10 8:27a gmullen
102 * SW3548-2589: BXPT_Mesg_StartPidChannelRecord now checks reference count
103 * before enabling PID channel
104 *
105 * Hydra_Software_Devel/66   4/2/10 5:11p gmullen
106 * SW7405-4165: Fixed inconsistent API descriptions
107 *
108 * Hydra_Software_Devel/65   11/2/09 10:53a gmullen
109 * SW3548-2589: Use reference counting when deciding to disable PID
110 * channels
111 *
112 * Hydra_Software_Devel/64   10/27/09 9:07a gmullen
113 * SW7405-3301: Changed index from per-PID channel to per-message buffer
114 *
115 * Hydra_Software_Devel/63   9/24/09 5:27p gmullen
116 * SWDEPRECATED-3717: Added BXPT_GetDefaultPsiSettings() and
117 * BXPT_GetDefaultPidChannelRecordSettings()
118 *
119 * Hydra_Software_Devel/62   9/24/09 1:22p gmullen
120 * SW7325-574: Backed out vers 57 change.
121 *
122 * Hydra_Software_Devel/61   9/22/09 4:27p gmullen
123 * SWDEPRECATED-3717: BXPT_Mesg_SetPid2Buff() needs to check for
124 * transitions between enable and disable
125 *
126 * Hydra_Software_Devel/60   9/16/09 2:55p piyushg
127 * SW3548-2479: Added new API BXPT_GetBuffer_isr which directly calls
128 * BXPT_UpdateReadOffset_isr() to avoid entering into critical section.
129 *
130 * Hydra_Software_Devel/59   9/14/09 11:58a piyushg
131 * SW3548-2470: Enable PID2BUF mapping API's for 3548.
132 *
133 * Hydra_Software_Devel/58   9/2/09 2:07p piyushg
134 * SW7325-582: Added API in bxpt_mesg.c to disable the pid channel
135 * to message buffer association that is created after calling the
136 * ConfigPid2BufferMap.
137 *
138 * Hydra_Software_Devel/57   8/25/09 3:18p piyushg
139 * SW7325-574: MessageSize calculation changed for wrap
140 * around condition.
141 *
142 * Hydra_Software_Devel/56   8/11/09 10:39a piyushg
143 * PR55216: Added initial 7340 XPT support.
144 *
145 * Hydra_Software_Devel/55   8/5/09 4:52p piyushg
146 * PR55545: Add 7125 XPT PI support
147 * Added file element "bxpt_rave_ihex.c".
148 * Added file element "bxpt_rave_ihex.h".
149 *
150 * Hydra_Software_Devel/54   7/31/09 2:44p gmullen
151 * PR54331: Added 35130 to XPT support.
152 *
153 * Hydra_Software_Devel/53   7/14/09 10:21a piyushg
154 * PR56771: Add XPT PI code for 7342.
155 *
156 * Hydra_Software_Devel/52   6/8/09 3:41p gmullen
157 * PR55813: Fixed message buffer index usage.
158 *
159 * Hydra_Software_Devel/51   6/5/09 3:43p gmullen
160 * PR55761: Added BufferSize param check to BXPT_SetPidChannelBuffer()
161 *
162 * Hydra_Software_Devel/50   4/29/09 1:51p gmullen
163 * PR54710: Added requested features to debug mesg.
164 *
165 * Hydra_Software_Devel/49   1/27/09 1:09p gmullen
166 * PR51625: Added 7336 support
167 *
168 * Hydra_Software_Devel/48   1/5/09 10:03a gmullen
169 * PR50811: Added _isr version of BXPT_UpdateReadOffset().
170 *
171 * Hydra_Software_Devel/47   10/28/08 8:21a gmullen
172 * PR48291: Checked return value.
173 *
174 * Hydra_Software_Devel/46   9/30/08 4:45p gmullen
175 * PR34473: Don't drop messages that the CDI driver doesn't have room for.
176 *
177 * Hydra_Software_Devel/45   9/30/08 11:29a gmullen
178 * PR34473: Removed patch from mainline code.
179 *
180 * Hydra_Software_Devel/44   9/19/08 3:50p gmullen
181 * PR47147: Wrapped _isr() calls with critical sections.
182 *
183 * Hydra_Software_Devel/43   7/17/08 4:47p gmullen
184 * PR44849: Fixed compilation errors for 7335B0
185 *
186 * Hydra_Software_Devel/42   7/16/08 3:43p gmullen
187 * PR37867: Merged playback mux code to Hydra_Software_Devel
188 *
189 * Hydra_Software_Devel/41   7/10/08 7:49p gmullen
190 * PR44734: Fixed compilation warnings.
191 *
192 * Hydra_Software_Devel/40   6/18/08 4:10p piyushg
193 * PR39234: Change some comments and API names for setting up
194 * multiple message buffers for same PID channel.
195 *
196 * Hydra_Software_Devel/39   6/16/08 11:55a piyushg
197 * PR39234: Change some comments and API names for setting up
198 * multiple message buffers for same PID channel.
199 *
200 * Hydra_Software_Devel/38   5/15/08 2:49p gmullen
201 * PR42718: Changed bounds check.
202 *
203 * Hydra_Software_Devel/37   5/6/08 1:46p gmullen
204 * PR42471: Check that PID channel has been configured AND is mapped to
205 * the same parser.
206 *
207 * Hydra_Software_Devel/36   4/1/08 6:55p gmullen
208 * PR40496: Added bounds check for ParserNum index.
209 *
210 * Hydra_Software_Devel/35   3/17/08 1:03p gmullen
211 * PR40675: Added support to route all mesg filter data on R-pipe.
212 *
213 * Hydra_Software_Devel/34   3/11/08 3:02p mward
214 * PR38618: Fix typo to fix 7118[A0|B0] support.
215 *
216 * Hydra_Software_Devel/33   3/7/08 4:54p gmullen
217 * PR38618: Added 7118C0 support
218 *
219 * Hydra_Software_Devel/32   3/7/08 11:00a piyushg
220 * PR39234: Fix compilation error for Chips that do not support
221 * PID Duplication.
222 *
223 * Hydra_Software_Devel/31   3/6/08 3:47p piyushg
224 * PR39234: Initial checkin for API's to support PID Duplication.
225 *
226 * Hydra_Software_Devel/30   2/19/08 2:58p gmullen
227 * PR39609: Fixed writes of DATA_OUTPUT_MODE to wrong register.
228 *
229 * Hydra_Software_Devel/29   10/1/07 4:30p gmullen
230 * PR35528: GetPidChannelByFilter() iterates over number of mesg buffers,
231 * not PID channels.
232 *
233 * Hydra_Software_Devel/28   9/19/07 9:20a gmullen
234 * PR35049: Passed return value from BXPT_UpdateReadOffset() to caller.
235 *
236 * Hydra_Software_Devel/27   9/13/07 1:36p gmullen
237 * PR32868: Changes to support bmsglib
238 *
239 * Hydra_Software_Devel/26   5/17/07 2:39p katrep
240 * PR29057: 29057
241 *
242 * Hydra_Software_Devel/25   4/27/07 8:31a katrep
243 * PR25533: Changed the warning message to debug message
244 *
245 * Hydra_Software_Devel/24   3/16/07 11:59a gmullen
246 * PR28828: Added check for bad BytesRead to BXPT_UpdateReadOffset
247 *
248 * Hydra_Software_Devel/23   2/20/07 5:30p gmullen
249 * PR27998: BXPT_P_ApplyParserPsiSettings needs to clear PB flag from
250 * parser number before checking.
251 *
252 * Hydra_Software_Devel/22   12/20/06 10:34a katrep
253 * PR25431: Downgraded the error message to debug message when the missed
254 * data ready interrupt condition is hit.
255 *
256 * Hydra_Software_Devel/21   12/6/06 3:22p katrep
257 * PR26127: Also covers PR 26358,Fixed BXPT_RemoveFilterFromGroup Api
258 *
259 * Hydra_Software_Devel/20   12/5/06 3:00p gmullen
260 * PR26325: Added support for CAP filtering.
261 *
262 * Hydra_Software_Devel/19   12/5/06 2:04p gmullen
263 * PR26278: Allow user to configure byte alignment of data in message
264 * buffer.
265 *
266 * Hydra_Software_Devel/18   12/4/06 6:33p katrep
267 * PR25533: Fixed broken psi scanning due to read of buffer when the
268 * packet received is incomplete.
269 *
270 * Hydra_Software_Devel/17   12/1/06 3:26p katrep
271 * PR25533: Due to HW bug data ready flag is not reliable. Use the Read
272 * and valid pointers to determine if the data is available.
273 *
274 * Hydra_Software_Devel/16   11/27/06 4:24p katrep
275 * PR25431: Added code to detect the lost data ready interrupt and
276 * generate sw callback
277 *
278 * Hydra_Software_Devel/15   11/2/06 3:06p katrep
279 * PR25278: Added PidChannelNum argument to BXPT_AddFilterToGroup API.
280 *
281 * Hydra_Software_Devel/14   11/1/06 3:34p gmullen
282 * PR23189: Added support for 3563
283 *
284 * Hydra_Software_Devel/13   9/25/06 12:40p katrep
285 * PR24466: Diabled Sanity check for parser band argument.
286 *
287 * Hydra_Software_Devel/12   9/21/06 6:31p katrep
288 * PR24466: Fixed the bug in BXPT_AddFilterToGroup API.
289 *
290 * Hydra_Software_Devel/11   8/18/06 5:20p gmullen
291 * PR23679: Removed workaround. Its only needed on 7401A0.
292 *
293 * Hydra_Software_Devel/10   8/7/06 2:02p gmullen
294 * PR18998: BXPT_StopPidChannelRecord() will disable PID channel
295 * destination fieldm , not the channel itself.
296 *
297 * Hydra_Software_Devel/9   7/27/06 10:59a gmullen
298 * PR15309: BXPT_ConfigurePidChannel() now checks for duplicated PID
299 * channels
300 *
301 * Hydra_Software_Devel/8   7/21/06 12:17p katrep
302 * PR21525: Added support for 128,16 byte filters across 4 banks or
303 * 64,32byte filters across 2 banks.
304 *
305 * Hydra_Software_Devel/7   7/17/06 5:19p gmullen
306 * PR20624: Added code for 7118.
307 *
308 * Hydra_Software_Devel/6   7/13/06 11:37a katrep
309 * PR20316: Added support to set/unset PSI setting per pid channel basis
310 * as it's supported by new HW arch.PR20315:Also added support for 32
311 * byte filters.Default filter size is 16 bytes.32 Bytes filters can be
312 * enabled at compile time by -DBXPT_FILTER_32
313 *
314 * Hydra_Software_Devel/5   7/10/06 9:33a gmullen
315 * PR18998: Fixed void * dereference warning.
316 *
317 * Hydra_Software_Devel/4   7/5/06 12:13p katrep
318 * PR22320: Fixed some logical errors. Enabled Filetr Bank 1
319 *
320 * Hydra_Software_Devel/3   4/24/06 5:48p gmullen
321 * PR18998: Set GEN_OFFSET to 3 for AUX messages, 0 for all others.
322 *
323 * Hydra_Software_Devel/2   3/31/06 4:11p gmullen
324 * PR 20314: 7400 PI also had this problem
325 *
326 * Hydra_Software_Devel/12   1/9/06 9:40a gmullen
327 * PR15039: Removed static define for DisableFilter() and PauseFilter()
328 *
329 * Hydra_Software_Devel/11   1/6/06 4:41p gmullen
330 * PR18489: Changes to other modules to support fix for PR 18489.
331 *
332 * Hydra_Software_Devel/10   1/4/06 9:57a gmullen
333 * PR15309: Filter mode is now Generic OR Special Filter when capturing
334 * DirecTV messages.
335 *
336 * Hydra_Software_Devel/9   1/3/06 10:22a gmullen
337 * PR18796: Fixed un-initialized variable "Reg" .
338 *
339 * Hydra_Software_Devel/8   12/16/05 10:06a gmullen
340 * PR18228: Added this API to the 7401.
341 *
342 * Hydra_Software_Devel/7   9/26/05 2:22p gmullen
343 * PR17303: Feature to use byte 2 of PSI message in filter match was
344 * enabled. This must be disabled for backward compatability.
345 *
346 * Hydra_Software_Devel/6   9/21/05 2:17p gmullen
347 * PR15309: Added support for AAC HE and AC3+ audio, fixed bug in playback
348 * PI, modified RAVE PI to support channel change and reset.
349 *
350 * Hydra_Software_Devel/5   8/31/05 10:58a gmullen
351 * PR15309: Fixed bugs in PSI extraction and MPEG audio support.
352 *
353 * Hydra_Software_Devel/4   8/26/05 2:01p gmullen
354 * PR15309: Added DirecTV support, RAVE video support, cleaned up RS and
355 * XC buffer code.
356 *
357 * Hydra_Software_Devel/3   8/18/05 9:59a gmullen
358 * PR15309: Added more DirecTV support.
359 *
360 * Hydra_Software_Devel/2   7/19/05 1:27p gmullen
361 * PR15309: Fixed buffer alloc bugs.
362 *
363 * Hydra_Software_Devel/1   7/15/05 9:03a gmullen
364 * PR15309: Inita i
365 *
366 *
367 ***************************************************************************/
368
369#include "bstd.h"
370#include "bxpt_priv.h"
371#include "bxpt.h"
372#include "bkni.h"
373#include "bmem.h"
374
375#include "bchp_xpt_msg.h"
376#include "bchp_xpt_fe.h"
377
378#if BXPT_HAS_PACKETSUB
379#include "bchp_xpt_psub.h"
380#include "bxpt_packetsub.h"
381#endif
382
383/* Message buffers sizes must be multiples of BXPT_P_MESSAGE_BUFFER_BLOCK_SIZE */
384#define BXPT_P_MESSAGE_BUFFER_BLOCK_SIZE 1024
385#define SPID_CHNL_STEPSIZE      ( 4 )
386
387#if( BDBG_DEBUG_BUILD == 1 )
388BDBG_MODULE( xpt_mesg );
389#endif
390
391static BERR_Code ConfigMessageBufferRegs( BXPT_Handle hXpt, unsigned int PidChannelNum, uint32_t CpuAddr, BXPT_MessageBufferSize BufferSize); 
392static void GetFilterAddrs( unsigned int Bank, unsigned int FilterNum, uint32_t *CoefAddr, uint32_t *MaskAddr, uint32_t *ExclAddr );
393static BERR_Code ChangeFilterByte( BXPT_Handle hXpt, uint32_t FilterBaseAddr, unsigned int FilterNum, unsigned int ByteOffset, uint8_t FilterByte );
394static unsigned GetPidChannelByFilter( BXPT_Handle hXpt, unsigned int Bank, unsigned int FilterNum );
395static BERR_Code EnableFilter( BXPT_Handle hXpt, unsigned int FilterNum, unsigned int PidChannelNum );
396static int AdjustChanAndAddr( BXPT_Handle hXpt, uint32_t PidChannelNum, uint32_t FlagBaseRegister, uint32_t *AdjustedPidChannel, uint32_t *AdjustedRegisterAddr );
397static int GetPidChannelFlag( BXPT_Handle hXpt, int PidChannelNum, int FlagBaseRegister );
398static void GetBufferPointers( BXPT_Handle hXpt, unsigned int PidChannelNum, uint32_t *ReadPtr, uint32_t *ValidPtr, size_t *MesgSize, size_t *BufferSizeInBytes );
399static uint32_t GetRegArrayAddr( BXPT_Handle hXpt, uint32_t PidChannelNum, uint32_t BaseRegister );
400static void CopyDmaDataToUser( BXPT_Handle hXpt, unsigned int PidChannelNum, uint32_t ReadPtr, uint8_t *UserBufferAddr, size_t NumBytesToCopy, size_t DmaBufferSize );
401
402static void ResetPid2BuffMap(BXPT_Handle hXpt);
403void ConfigPid2BufferMap( BXPT_Handle hXpt, unsigned int PidChannelNum, unsigned int BufferNumber, bool enableIt);
404
405void BXPT_Mesg_SetPid2Buff(
406        BXPT_Handle hXpt,
407        bool SetPid2Buff
408    )
409{
410    BDBG_ASSERT( hXpt );
411
412        ResetPid2BuffMap(hXpt);
413    hXpt->Pid2BuffMappingOn = SetPid2Buff;
414
415    return;
416}
417
418void ResetPid2BuffMap(
419        BXPT_Handle hXpt
420        )
421{
422    uint32_t RegAddr;
423        int i;
424
425        RegAddr = BCHP_XPT_MSG_PID2BUF_MAP_i_ARRAY_BASE;
426
427        for (i=0; i<(BXPT_NUM_MESG_BUFFERS * 4); i++) 
428                BREG_Write32( hXpt->hRegister, RegAddr + (i*4), 0x00000000 );
429
430        return;
431}
432
433BERR_Code BXPT_Mesg_SetPidChannelBuffer( 
434    BXPT_Handle hXpt,                   /* [in] Handle for this transport */
435    unsigned int PidChannelNum,             /* [in] Which PID channel buffer we want. */
436    unsigned int MesgBufferNum,             /* [in] Which Buffer number we want . */
437    void *CpuAddr,                  /* [in] Caller allocated memory, or NULL. */
438    BXPT_MessageBufferSize BufferSize   /* [in] Size, in bytes, of the buffer. */
439    )
440{
441
442    BERR_Code ExitCode = BERR_SUCCESS;
443
444    BDBG_ASSERT( hXpt );
445
446    /* Sanity check on the arguments. */
447    if( PidChannelNum >= hXpt->MaxPidChannels )
448    {
449        /* Bad PID channel number. Complain. */
450        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
451        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
452        goto Done;
453    }
454        else if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) 
455    {
456        /* Bad Message Buffer number. Complain. */
457        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
458        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
459        goto Done;
460        }
461
462    /* Is the caller allocating memory, or are we? */
463    if( CpuAddr == NULL )
464    {   
465        /* We are. */
466        uint32_t Reg, RegAddr;
467        BXPT_MessageBufferSize OldBufferSize;
468         
469        MessageBufferEntry *Buffer = &hXpt->MessageBufferTable[ MesgBufferNum ];
470
471        RegAddr = BCHP_XPT_MSG_DMA_BP_TABLE_i_ARRAY_BASE + ( MesgBufferNum * BP_TABLE_STEP );
472
473        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
474        OldBufferSize = ( BXPT_MessageBufferSize ) BCHP_GET_FIELD_DATA( Reg, XPT_MSG_DMA_BP_TABLE_i, BP_BUFFER_SIZE );
475
476        /* Allocate under 2 cases: The buffer size is changing, or if no buffer was ever allocated */
477        if( ( Buffer->IsAllocated == true && BufferSize != OldBufferSize ) 
478        || Buffer->IsAllocated == false )
479        {
480            unsigned int i;
481
482            unsigned long SizeInBytes = BXPT_P_MESSAGE_BUFFER_BLOCK_SIZE;
483
484            /* Free the old buffer, if there is one. */
485            if( Buffer->IsAllocated == true )
486                BMEM_Free( hXpt->hMemory, ( void * ) Buffer->Address );
487
488            /* Convert from the enum to a byte count. */
489            for( i = 0; i < ( unsigned int ) BufferSize; i++ )
490                SizeInBytes *= 2;
491
492            /*
493            ** Alloc some memory. Must use the Memory Manager, since this buffer
494            ** must be visible to both the transport hardware and the CPU. We also
495            ** have some alignment requirements.
496            */
497            Buffer->Address = ( uint32_t ) BMEM_AllocAligned( hXpt->hMemory, SizeInBytes, 10, 0 ); 
498            if( Buffer->Address )
499            {
500                Buffer->IsAllocated = true;
501
502                ConfigPid2BufferMap( hXpt, PidChannelNum, MesgBufferNum, true);
503                /* Load the buffer address and size into the transport registers. */
504                ExitCode = ConfigMessageBufferRegs( hXpt, MesgBufferNum, Buffer->Address, BufferSize );
505            }
506            else
507            {
508                BDBG_ERR(( "Message buffer alloc failed! MesgBufferNum %lu", ( unsigned long ) MesgBufferNum ));
509                ExitCode = BERR_TRACE( BERR_OUT_OF_DEVICE_MEMORY );
510            }
511        }
512    }
513    else
514    {
515        /* We are not, the caller is. */
516
517        ConfigPid2BufferMap( hXpt, PidChannelNum, MesgBufferNum, true);
518
519        /* Load the buffer address and size into the transport registers. */
520        ExitCode = ConfigMessageBufferRegs( hXpt, MesgBufferNum, ( uint32_t ) CpuAddr, BufferSize );
521    }
522
523    /* Note that the buffer is now configured. */
524    hXpt->MesgBufferIsInitialized[ MesgBufferNum ] = true;
525
526    Done:
527    return( ExitCode );
528}
529
530void ConfigPid2BufferMap(
531    BXPT_Handle hXpt,
532    unsigned int PidChannelNum,
533    unsigned int BufferNumber,
534        bool             enableIt               
535    )
536{
537    uint32_t Reg, RegAddr;
538    uint32_t tempReg;
539
540    /* Set the PID to BUFF map for new PID channel*/
541    RegAddr = BCHP_XPT_MSG_PID2BUF_MAP_i_ARRAY_BASE + (PidChannelNum * 4 + (int)(BufferNumber/32)) * PID2BUF_TABLE_STEP;
542    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
543    tempReg = 0x00000001;
544
545    if ( BufferNumber < 32 ) {
546        tempReg <<= BufferNumber;
547    }
548    else if ( BufferNumber < 64 ) {
549        tempReg <<= (BufferNumber - 32);
550    }
551    else if ( BufferNumber < 96 ) {
552        tempReg <<= (BufferNumber - 64);
553    }
554    else if ( BufferNumber < 128 ) {
555        tempReg <<= (BufferNumber - 96);
556    }
557
558        if (enableIt)
559        Reg |= tempReg;
560        else
561                Reg &= (~tempReg);
562    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
563}
564
565
566BERR_Code BXPT_AllocPSIFilter( 
567    BXPT_Handle hXpt,           /* [in] Handle for this transport */
568    unsigned int Bank,          /* [in] Which bank to allocate from. */
569    unsigned int *FilterNum     /* [out] Number for the allocated filter. */
570    )
571{
572    unsigned int i;
573
574    BERR_Code ExitCode = BXPT_ERR_NO_AVAILABLE_RESOURCES;
575
576    BDBG_ASSERT( hXpt );
577   
578    /* Sanity check on the arguments. */
579    if( Bank >= hXpt->MaxFilterBanks )     
580    {
581        /* Bad parser band number. Complain. */
582        BDBG_ERR(( "Bank %lu is out of range!", ( unsigned long ) Bank ));
583        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
584    }
585    else
586    {
587        for( i = 0; i < BXPT_NUM_FILTERS_PER_BANK; i++ )
588        {
589            if( hXpt->FilterTable[ Bank ][ i ].IsAllocated == false )
590            {
591                hXpt->FilterTable[ Bank ][ i ].IsAllocated = true;
592                *FilterNum = i;
593                ExitCode = BERR_SUCCESS;
594                break; 
595            }
596        }
597    }
598
599    return( ExitCode );
600}
601
602BERR_Code BXPT_FreePSIFilter( 
603    BXPT_Handle hXpt,           /* [in] Handle for this transport */
604    unsigned int Bank,          /* [in] Which bank to free the filter from. */
605    unsigned int FilterNum      /* [in] Which filter to free up. */
606    )
607{
608    BERR_Code ExitCode = BERR_SUCCESS;
609
610    BDBG_ASSERT( hXpt );
611   
612    /* Sanity check on the arguments. */
613    if( Bank >= hXpt->MaxFilterBanks )     
614    {
615        /* Bad parser band number. Complain. */
616        BDBG_ERR(( "Bank %lu is out of range!", ( unsigned long ) Bank ));
617        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
618    }
619    else if( FilterNum >= BXPT_P_FILTER_TABLE_SIZE )       
620    {
621        /* Bad filter number. Complain. */
622        BDBG_ERR(( "FilterNum %lu is out of range!", ( unsigned long ) FilterNum ));
623        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
624    }
625    else
626    {
627        hXpt->FilterTable[ Bank ][ FilterNum ].IsAllocated = false;
628    }
629
630    return( ExitCode );
631}
632
633BERR_Code BXPT_GetFilter( 
634    BXPT_Handle hXpt,           /* [in] Handle for this transport */
635    unsigned int Bank,              /* [in] Which bank the filter belongs to. */
636    unsigned int FilterNum,         /* [in] Which filter to get data from. */
637    BXPT_Filter *Filter         /* [out] Filter data */
638    )
639{
640    BERR_Code ExitCode = BERR_SUCCESS;
641
642    BDBG_ASSERT( hXpt );
643    BDBG_ASSERT( Filter );
644
645    /* Sanity check on the arguments. */
646    if( Bank >= hXpt->MaxFilterBanks )     
647    {
648        /* Bad parser band number. Complain. */
649        BDBG_ERR(( "Bank %lu is out of range!", ( unsigned long ) Bank ));
650        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
651    }
652    else if( FilterNum >= BXPT_P_FILTER_TABLE_SIZE )       
653    {
654        /* Bad filter number. Complain. */
655        BDBG_ERR(( "FilterNum %lu is out of range!", ( unsigned long ) FilterNum ));
656        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
657    }
658    else
659    {
660        unsigned int i, GroupSel;
661
662        uint32_t CoefRegAddr = 0, MaskRegAddr = 0, ExclRegAddr = 0;
663       
664        if (BXPT_FILTER_SIZE == 32)
665        {
666            /*
667            ** Logical bank 0 maps to filter group 8B0.
668            ** Logical bank 1 maps to filter grouo 4B8.
669            */
670            GroupSel = Bank * 256;
671        }
672        else
673        {
674            /*
675            ** Logical bank 0 maps to filter group 4B0.
676            ** Logical bank 1 maps to filter grouo 4B4.
677            */
678            GroupSel = Bank * 128;
679        }
680        for( i = 0; i < BXPT_FILTER_SIZE; i += 4 )
681        {
682            uint32_t Reg;
683
684            GetFilterAddrs( GroupSel, FilterNum, &CoefRegAddr, &MaskRegAddr, &ExclRegAddr );
685            GroupSel += 32; /* Step to the next bank in the cascade */
686
687            Reg = BREG_Read32( hXpt->hRegister, CoefRegAddr );
688            Filter->Coeficient[ i ] = ( uint8_t ) (( Reg >> 24 ) & 0xFF );                 
689            Filter->Coeficient[ i + 1 ] = ( uint8_t ) (( Reg >> 16 ) & 0xFF );                 
690            Filter->Coeficient[ i + 2 ] = ( uint8_t ) (( Reg >> 8 ) & 0xFF );                   
691            Filter->Coeficient[ i + 3 ] = ( uint8_t ) ( Reg & 0xFF );                   
692
693            Reg = BREG_Read32( hXpt->hRegister, MaskRegAddr );
694            Filter->Mask[ i ] = ( uint8_t ) (( Reg >> 24 ) & 0xFF );                   
695            Filter->Mask[ i + 1 ] = ( uint8_t ) (( Reg >> 16 ) & 0xFF );                   
696            Filter->Mask[ i + 2 ] = ( uint8_t ) (( Reg >> 8 ) & 0xFF );                 
697            Filter->Mask[ i + 3 ] = ( uint8_t ) ( Reg & 0xFF );                 
698
699            Reg = BREG_Read32( hXpt->hRegister, ExclRegAddr );
700            Filter->Exclusion[ i ] = ( uint8_t ) (( Reg >> 24 ) & 0xFF );                   
701            Filter->Exclusion[ i + 1 ] = ( uint8_t ) (( Reg >> 16 ) & 0xFF );                   
702            Filter->Exclusion[ i + 2 ] = ( uint8_t ) (( Reg >> 8 ) & 0xFF );                   
703            Filter->Exclusion[ i + 3 ] = ( uint8_t ) ( Reg & 0xFF );                   
704        }
705    }
706
707    return( ExitCode );
708}
709
710BERR_Code BXPT_SetFilter( 
711    BXPT_Handle hXpt,           /* [in] Handle for this transport */
712    unsigned int Bank,              /* [in] Which bank the filter belongs to. */
713    unsigned int FilterNum,         /* [in] Which filter to get data from. */
714    const BXPT_Filter *Filter   /* [in] Filter data to be loaded */
715    )
716{
717    BERR_Code ExitCode = BERR_SUCCESS;
718
719    BDBG_ASSERT( hXpt );
720    BDBG_ASSERT( Filter );
721
722    /* Sanity check on the arguments. */
723    if( Bank >= hXpt->MaxFilterBanks )     
724    {
725        /* Bad parser band number. Complain. */
726        BDBG_ERR(( "Bank %lu is out of range!", ( unsigned long ) Bank ));
727        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
728    }
729    else if( FilterNum >= BXPT_P_FILTER_TABLE_SIZE )       
730    {
731        /* Bad filter number. Complain. */
732        BDBG_ERR(( "FilterNum %lu is out of range!", ( unsigned long ) FilterNum ));
733        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
734    }
735    else
736    {
737        unsigned int i, GroupSel;
738
739        uint32_t CoefRegAddr = 0, MaskRegAddr = 0, ExclRegAddr = 0;
740       
741        if (BXPT_FILTER_SIZE == 32)
742        {
743            /*
744            ** Logical bank 0 maps to filter group 8B0.
745            ** Logical bank 1 maps to filter grouo 4B8.
746            */
747            GroupSel = Bank * 256;
748        }
749        else
750        {
751            /*
752            ** Logical bank 0 maps to filter group 4B0.
753            ** Logical bank 1 maps to filter grouo 4B4.
754            */
755            GroupSel = Bank * 128;
756        }
757
758        for( i = 0; i < BXPT_FILTER_SIZE; i += 4 )
759        {
760            uint32_t Reg;
761
762            GetFilterAddrs( GroupSel, FilterNum, &CoefRegAddr, &MaskRegAddr, &ExclRegAddr );
763            GroupSel += 32; /* Step to the next bank in the cascade */
764
765            Reg = ( Filter->Coeficient[ i ] << 24 );
766            Reg |= ( Filter->Coeficient[ i + 1 ] << 16 );
767            Reg |= ( Filter->Coeficient[ i + 2 ] << 8 );
768            Reg |= Filter->Coeficient[ i + 3 ];
769            BREG_Write32( hXpt->hRegister, CoefRegAddr, Reg );
770
771            Reg = ( Filter->Mask[ i ] << 24 );
772            Reg |= ( Filter->Mask[ i + 1 ] << 16 );
773            Reg |= ( Filter->Mask[ i + 2 ] << 8 );
774            Reg |= Filter->Mask[ i + 3 ];
775            BREG_Write32( hXpt->hRegister, MaskRegAddr, Reg );
776
777            Reg = ( Filter->Exclusion[ i ] << 24 );
778            Reg |= ( Filter->Exclusion[ i + 1 ] << 16 );
779            Reg |= ( Filter->Exclusion[ i + 2 ] << 8 );
780            Reg |= Filter->Exclusion[ i + 3 ];
781            BREG_Write32( hXpt->hRegister, ExclRegAddr, Reg );
782        }
783    }
784
785    return( ExitCode );
786}
787
788BERR_Code BXPT_ChangeFilterCoefficientByte( 
789    BXPT_Handle hXpt,       /* [in] Handle for this transport */
790    unsigned int Bank,          /* [in] Which bank the filter belongs to. */
791    unsigned int FilterNum,     /* [in] Which filter to change. */
792    unsigned int ByteOffset,        /* [in] Which byte in the array to change */
793    uint8_t FilterByte      /* [in] New filter byte to be written. */
794    )
795{
796    BERR_Code ExitCode = BERR_SUCCESS;
797
798    BDBG_ASSERT( hXpt );
799
800    /* Sanity check on the arguments. */
801    if( Bank >= hXpt->MaxFilterBanks )     
802    {
803        /* Bad parser band number. Complain. */
804        BDBG_ERR(( "Bank %lu is out of range!", ( unsigned long ) Bank ));
805        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
806    }
807    else
808    {
809        unsigned int GroupSel;
810
811        uint32_t RegAddr = 0;
812        unsigned PidChnlNum = GetPidChannelByFilter( hXpt, Bank, FilterNum );
813
814        if (BXPT_FILTER_SIZE == 32)
815        {
816            /*
817            ** Logical bank 0 maps to filter group 8B0.
818            ** Logical bank 1 maps to filter grouo 4B8.
819            */
820            GroupSel = Bank * 256;
821        }
822        else
823        {
824            /*
825            ** Logical bank 0 maps to filter group 4B0.
826            ** Logical bank 1 maps to filter grouo 4B4.
827            */
828            GroupSel = Bank * 128;
829        }
830   
831        if( PidChnlNum < BXPT_NUM_PID_CHANNELS )
832            BXPT_P_DisableFilter( hXpt, FilterNum, PidChnlNum );
833
834        GetFilterAddrs( GroupSel, FilterNum, &RegAddr, NULL, NULL );
835        ExitCode = BERR_TRACE( ChangeFilterByte( hXpt, RegAddr, FilterNum, ByteOffset, FilterByte ) );
836
837        if( PidChnlNum < BXPT_NUM_PID_CHANNELS )
838            EnableFilter( hXpt, FilterNum, PidChnlNum );
839    }
840       
841    return( ExitCode );
842}
843
844BERR_Code BXPT_ChangeFilterMaskByte( 
845    BXPT_Handle hXpt,       /* [in] Handle for this transport */
846    unsigned int Bank,          /* [in] Which bank the filter belongs to. */
847    unsigned int FilterNum,     /* [in] Which filter to change. */
848    unsigned int ByteOffset,        /* [in] Which byte in the array to change */
849    uint8_t MaskByte        /* [in] New mask byte to be written. */
850    )
851{
852    BERR_Code ExitCode = BERR_SUCCESS;
853
854    BDBG_ASSERT( hXpt );
855
856    /* Sanity check on the arguments. */
857    if( Bank >= hXpt->MaxFilterBanks )     
858    {
859        /* Bad parser band number. Complain. */
860        BDBG_ERR(( "Bank %lu is out of range!", ( unsigned long ) Bank ));
861        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
862    }
863    else
864    {
865        unsigned int GroupSel;
866
867        uint32_t RegAddr = 0;
868        unsigned PidChnlNum = GetPidChannelByFilter( hXpt, Bank,  FilterNum );
869
870        if (BXPT_FILTER_SIZE == 32)
871        {
872            /*
873            ** Logical bank 0 maps to filter group 8B0.
874            ** Logical bank 1 maps to filter grouo 4B8.
875            */
876            GroupSel = Bank * 256;
877        }
878        else
879        {
880            /*
881            ** Logical bank 0 maps to filter group 4B0.
882            ** Logical bank 1 maps to filter grouo 4B4.
883            */
884            GroupSel = Bank * 128;
885        }
886        if( PidChnlNum < BXPT_NUM_PID_CHANNELS )
887            BXPT_P_DisableFilter( hXpt, FilterNum, PidChnlNum );
888
889        GetFilterAddrs( GroupSel, FilterNum, NULL, &RegAddr, NULL );
890        ExitCode = BERR_TRACE( ChangeFilterByte( hXpt, RegAddr, FilterNum, ByteOffset, MaskByte ) );
891
892        if( PidChnlNum < BXPT_NUM_PID_CHANNELS )
893            EnableFilter( hXpt, FilterNum, PidChnlNum );
894    }
895       
896    return( ExitCode );
897}
898
899BERR_Code BXPT_ChangeFilterExclusionByte( 
900    BXPT_Handle hXpt,       /* [in] Handle for this transport */
901    unsigned int Bank,          /* [in] Which bank the filter belongs to. */
902    unsigned int FilterNum,     /* [in] Which filter to change. */
903    unsigned int ByteOffset,        /* [in] Which byte in the array to change */
904    uint8_t ExclusionByte       /* [in] New exclusion byte to be written. */
905    )
906{
907    BERR_Code ExitCode = BERR_SUCCESS;
908
909    BDBG_ASSERT( hXpt );
910
911    /* Sanity check on the arguments. */
912    if( Bank >= hXpt->MaxFilterBanks )     
913    {
914        /* Bad parser band number. Complain. */
915        BDBG_ERR(( "Bank %lu is out of range!", ( unsigned long ) Bank ));
916        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
917    }
918    else
919    {
920        unsigned int GroupSel;
921
922        uint32_t RegAddr = 0;
923        unsigned PidChnlNum = GetPidChannelByFilter( hXpt, Bank,  FilterNum );
924
925        if (BXPT_FILTER_SIZE == 32)
926        {
927            /*
928            ** Logical bank 0 maps to filter group 8B0.
929            ** Logical bank 1 maps to filter grouo 4B8.
930            */
931            GroupSel = Bank * 256;
932        }
933        else
934        {
935            /*
936            ** Logical bank 0 maps to filter group 4B0.
937            ** Logical bank 1 maps to filter grouo 4B4.
938            */
939            GroupSel = Bank * 128;
940        }
941   
942        if( PidChnlNum < BXPT_NUM_PID_CHANNELS )
943            BXPT_P_DisableFilter( hXpt, FilterNum, PidChnlNum );
944
945        GetFilterAddrs( GroupSel, FilterNum, NULL, NULL, &RegAddr );
946        ExitCode = BERR_TRACE( ChangeFilterByte( hXpt, RegAddr, FilterNum, ByteOffset, ExclusionByte ) );
947
948        if( PidChnlNum < BXPT_NUM_PID_CHANNELS )
949            EnableFilter( hXpt, FilterNum, PidChnlNum );
950    }
951       
952    return( ExitCode );
953}
954
955BERR_Code BXPT_Mesg_AddFilterToGroup(
956    BXPT_Handle hXpt,                   /* [in] Handle for this transport */
957    unsigned int PidChannelNum,         /* [in] Pid channel number */
958    unsigned int MesgBufferNum,         /* [in] Message Buffer number */
959    unsigned int FilterNum,             /* [in] Which filter to add. */
960    BXPT_PsiMessageSettings *Settings   /* [in] Filter group to add to. */
961    )
962{
963    uint32_t RegAddr;
964    BERR_Code ExitCode = BERR_SUCCESS;
965
966    BDBG_ASSERT( hXpt );
967    BDBG_ASSERT( Settings );
968
969    /* Sanity check on the arguments. */
970    if( PidChannelNum >= hXpt->MaxPidChannels )
971    {
972        /* Bad PID channel number. Complain. */
973        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
974        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
975    }
976        else if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) {
977        /* Bad Message Buffer number. Complain. */
978        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
979        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
980        }
981    else
982    {
983        Settings->FilterEnableMask |= ( 1ul << FilterNum );
984
985        RegAddr = BCHP_XPT_MSG_GEN_FILT_EN_i_ARRAY_BASE + ( MesgBufferNum * GEN_FILT_EN_STEP );
986
987        BXPT_P_DisableFilter( hXpt, FilterNum, MesgBufferNum );
988
989        BREG_Write32( hXpt->hRegister, RegAddr, Settings->FilterEnableMask );
990    }
991
992    return( ExitCode );
993}
994
995BERR_Code BXPT_RemoveFilterFromGroup(
996    BXPT_Handle hXpt,               /* [in] Handle for this transport */
997    unsigned int FilterNum,                 /* [in] Which filter to remove. */
998    BXPT_PsiMessageSettings *Settings   /* [in] Filter group to add to. */
999    )
1000{
1001    BERR_Code ExitCode = BERR_SUCCESS;
1002
1003    uint32_t RegAddr;
1004    unsigned int PidChannelNum;
1005   
1006    BDBG_ASSERT( hXpt );
1007    BDBG_ASSERT( Settings );
1008
1009    PidChannelNum = GetPidChannelByFilter( hXpt, Settings->Bank, FilterNum );
1010
1011    if( PidChannelNum < BXPT_NUM_PID_CHANNELS )
1012    {
1013        Settings->FilterEnableMask &= ~( 1ul << FilterNum );
1014        RegAddr = BCHP_XPT_MSG_GEN_FILT_EN_i_ARRAY_BASE + ( PidChannelNum * GEN_FILT_EN_STEP );
1015
1016        BXPT_P_DisableFilter( hXpt, FilterNum, PidChannelNum );
1017
1018        BREG_Write32( hXpt->hRegister, RegAddr, Settings->FilterEnableMask );
1019    }
1020    else
1021    {
1022        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1023        BDBG_ERR(("Incorrect PidChannelNumber (%d)\n", PidChannelNum ));
1024    }
1025
1026    return( ExitCode );
1027}
1028
1029BERR_Code BXPT_RemoveFilterFromGroupAndBuffer(
1030    BXPT_Handle hXpt,               /* [in] Handle for this transport */
1031    unsigned int FilterNum,                 /* [in] Which filter to remove. */
1032    unsigned int BufferNum,                 /* [in] Which message buffer is using this filter. */
1033    BXPT_PsiMessageSettings *Settings   /* [in] Filter group to add to. */
1034    )
1035{
1036    BERR_Code ExitCode = BERR_SUCCESS;
1037
1038    BDBG_ASSERT( hXpt );
1039    BDBG_ASSERT( Settings );
1040
1041    /* Sanity check on the arguments. */
1042        if ( BufferNum >= BXPT_NUM_MESG_BUFFERS ) 
1043    {
1044        /* Bad Message Buffer number. Complain. */
1045        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) BufferNum ));
1046        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1047        }
1048    else
1049    {
1050        Settings->FilterEnableMask &= ~( 1ul << FilterNum );
1051        BXPT_P_DisableFilter( hXpt, FilterNum, BufferNum );
1052    }
1053
1054    return( ExitCode );
1055}
1056
1057BERR_Code BXPT_Mesg_StartPidChannelRecord( 
1058    BXPT_Handle hXpt,                               /* [in] Handle for this transport */
1059    unsigned int PidChannelNum,                         /* [in] Which PID channel. */
1060    unsigned int MesgBufferNum,                         /* [in] Which Buffer Number. */
1061    const BXPT_PidChannelRecordSettings *Settings   /* [in] Record settings. */
1062    )
1063{
1064    BERR_Code ExitCode = BERR_SUCCESS;
1065
1066    BDBG_ASSERT( hXpt );
1067    BDBG_ASSERT( Settings );
1068
1069    /* Sanity check on the arguments. */
1070    if( PidChannelNum >= hXpt->MaxPidChannels )
1071    {
1072        /* Bad PID channel number. Complain. */
1073        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
1074        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1075    }
1076        else if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) {
1077        /* Bad Message Buffer number. Complain. */
1078        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
1079        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1080        }
1081        else if( hXpt->MesgBufferIsInitialized[ MesgBufferNum ] == false )
1082        {
1083                BDBG_ERR(( "Message buffer for this channel not configured!" ));
1084                ExitCode = BERR_TRACE( BXPT_ERR_MESG_BUFFER_NOT_CONFIGURED );
1085        }
1086
1087    {
1088                uint32_t Reg;
1089
1090                uint32_t DataOutputMode = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_DATA_OUTPUT_MODE_NO_OUTPUT;
1091                uint32_t RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( MesgBufferNum * PID_CTRL1_TABLE_STEP );
1092
1093                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1094                Reg &= ~(
1095                        BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, SPECIAL_SEL ) |
1096                        BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, ALIGN_MODE ) |
1097                        BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE ) 
1098                );
1099
1100                /* Disable the PSI filters for this PID channel. Older chip didn't allow PSI filtering of PES or PacketSaveAll data. */
1101                BREG_Write32( hXpt->hRegister, BCHP_XPT_MSG_GEN_FILT_EN_i_ARRAY_BASE + ( MesgBufferNum * GEN_FILT_EN_STEP ), 0 );       
1102
1103                /* Configure the message buffer for the type of recording. */
1104                switch( Settings->RecordType )
1105                {
1106                        case BXPT_SingleChannelRecordType_ePes:   
1107                        DataOutputMode = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_DATA_OUTPUT_MODE_MPEG_PES;
1108                        break;
1109
1110                        case BXPT_SingleChannelRecordType_ePacketSaveAll:
1111                        DataOutputMode = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_DATA_OUTPUT_MODE_MPEG_TS;
1112                        break;
1113
1114                        case BXPT_SingleChannelRecordType_ePesSaveAll:
1115                        DataOutputMode = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_DATA_OUTPUT_MODE_MPEG_PAYLOAD;
1116                        break;
1117
1118                        default:
1119                        BDBG_ERR(( "Unsupported/illegal RecordType: %u!", ( unsigned ) Settings->RecordType ));
1120                        goto Done;
1121                }
1122
1123                Reg |= (
1124                        BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, ALIGN_MODE, Settings->ByteAlign == true ? 0 : 1 ) |
1125                        BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE, DataOutputMode ) 
1126                );
1127                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1128                if(hXpt->PidChannelTable[ PidChannelNum ].MessageBuffercount == 0)
1129                {
1130                    /* Enable data from the PID channel to the mesg block. */
1131            if( hXpt->MesgDataOnRPipe || Settings->UseRPipe ) 
1132                BXPT_P_SetPidChannelDestination( hXpt, PidChannelNum, 7, true );
1133            else
1134                BXPT_P_SetPidChannelDestination( hXpt, PidChannelNum, 6, true );
1135
1136                    /* Set this PID channel as allocated, in case they forced the channel assignment. */
1137                    hXpt->PidChannelTable[ PidChannelNum ].IsAllocated = true;
1138
1139                    /* Configure the PID channel.  */
1140                    ExitCode = BXPT_ConfigurePidChannel( hXpt, PidChannelNum, Settings->Pid, Settings->Band );
1141                    if( ExitCode != BERR_SUCCESS )
1142                            goto Done;
1143
1144            /* Enable the PID channel. */ 
1145            ExitCode = BERR_TRACE( BXPT_EnablePidChannel( hXpt, PidChannelNum ) );
1146                }
1147
1148        ConfigPid2BufferMap( hXpt, PidChannelNum, MesgBufferNum, true);
1149                hXpt->PidChannelTable[ PidChannelNum ].MessageBuffercount++;
1150    }
1151
1152    Done:
1153    return( ExitCode );
1154}
1155
1156BERR_Code BXPT_Mesg_StopPidChannelRecord( 
1157    BXPT_Handle hXpt,                               /* [in] Handle for this transport */
1158    unsigned int PidChannelNum,                      /* [in] Which PID channel. */
1159    unsigned int MesgBufferNum                      /* [in] Which Buffer Number. */
1160    )
1161{
1162    BERR_Code ExitCode = BERR_SUCCESS;
1163
1164    BDBG_ASSERT( hXpt );
1165
1166    /* Sanity check on the arguments. */
1167    if( PidChannelNum >= hXpt->MaxPidChannels )
1168    {
1169        /* Bad PID channel number. Complain. */
1170        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
1171        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1172    }
1173        else if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) {
1174        /* Bad Message Buffer number. Complain. */
1175        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
1176        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1177        }
1178
1179    {
1180
1181        uint32_t Reg, RegAddr;
1182
1183        /* Disable data from the PID channel to the mesg block. */
1184        hXpt->PidChannelTable[ PidChannelNum ].MessageBuffercount--;
1185        if(hXpt->PidChannelTable[ PidChannelNum ].MessageBuffercount == 0)
1186        {
1187            BXPT_P_SetPidChannelDestination( hXpt, PidChannelNum, 7, false );
1188            BXPT_P_SetPidChannelDestination( hXpt, PidChannelNum, 6, false );
1189        }
1190
1191        /* Disable message buffer output */
1192        RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( MesgBufferNum * PID_CTRL1_TABLE_STEP );
1193        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1194        Reg &= ~(
1195            BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE ) 
1196        );
1197        Reg |= (
1198            BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE, BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_DATA_OUTPUT_MODE_NO_OUTPUT )
1199        );
1200        BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1201
1202        RegAddr = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_ARRAY_BASE + ( MesgBufferNum * PID_CTRL2_TABLE_STEP );
1203        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1204        Reg &= ~(
1205            BCHP_MASK( XPT_MSG_BUF_CTRL2_TABLE_i, FILTER_MODE ) 
1206        );
1207        Reg |= (
1208            BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL2_TABLE_i, FILTER_MODE, 0 )
1209        );
1210        BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1211   
1212        /* Write the PID channel number to the buffer reset register. Writes trigger the reset. */
1213        BREG_Write32( hXpt->hRegister, BCHP_XPT_MSG_DMA_BUFFER_INIT, MesgBufferNum );
1214
1215        /** Clear the read pointer. **/
1216        RegAddr = BCHP_XPT_MSG_DMA_RP_TABLE_i_ARRAY_BASE + ( MesgBufferNum * RP_TABLE_STEP );
1217        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1218        Reg &= ~BCHP_MASK( XPT_MSG_DMA_RP_TABLE_i, READ_POINTER ); 
1219        BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1220
1221                /* Clear the pid2buf mapping */
1222                ConfigPid2BufferMap(hXpt, PidChannelNum, MesgBufferNum, false);
1223    }
1224
1225    return( ExitCode );
1226}
1227
1228BERR_Code BXPT_Mesg_StartPsiMessageCapture( 
1229    BXPT_Handle hXpt,                           /* [in] Handle for this transport */
1230    unsigned int PidChannelNum,                     /* [in] Which PID channel. */
1231    unsigned int MesgBufferNum,                     /* [in] Which Message Buffer. */
1232    const BXPT_PsiMessageSettings *Settings     /* [in] PID, band, and filters to use. */
1233    )
1234{
1235    BERR_Code ExitCode = BERR_SUCCESS;
1236
1237    BDBG_ASSERT( hXpt );
1238    BDBG_ASSERT( Settings );
1239
1240    /* Sanity check on the arguments. */
1241    if( PidChannelNum >= hXpt->MaxPidChannels )
1242    {
1243        /* Bad PID channel number. Complain. */
1244        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
1245        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1246    }
1247    else if( hXpt->MesgBufferIsInitialized[ MesgBufferNum ] == false )
1248    {
1249        BDBG_ERR(( "Message buffer for this channel not configured!" ));
1250        ExitCode = BERR_TRACE( BXPT_ERR_MESG_BUFFER_NOT_CONFIGURED );
1251    }
1252        else if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) {
1253        /* Bad Message Buffer number. Complain. */
1254        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
1255        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1256        }
1257        else if ( Settings->StartingOffset > 255 ) 
1258    {
1259        BDBG_ERR(( "StartingOffset %lu is out of range!", ( unsigned long ) Settings->StartingOffset ));
1260        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1261        }
1262    else
1263    {
1264        uint32_t Reg, RegAddr;
1265        unsigned int GroupSel = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_GEN_GRP_SEL_G8_B0;
1266
1267        ExitCode = BXPT_P_GetGroupSelect( Settings->Bank, &GroupSel );
1268        if( ExitCode != BERR_SUCCESS )
1269            goto Done;
1270
1271        /* Select the bank the filters are in. */
1272        RegAddr = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_ARRAY_BASE + ( MesgBufferNum * PID_CTRL2_TABLE_STEP );
1273        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1274        Reg &= ~(
1275            BCHP_MASK( XPT_MSG_BUF_CTRL2_TABLE_i, GEN_OFFSET ) |
1276            BCHP_MASK( XPT_MSG_BUF_CTRL2_TABLE_i, SKIP_BYTE2 ) |
1277            BCHP_MASK( XPT_MSG_BUF_CTRL2_TABLE_i, GEN_GRP_SEL ) 
1278        );
1279        Reg |= (
1280            BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL2_TABLE_i, GEN_OFFSET, Settings->StartingOffset ) |
1281            BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL2_TABLE_i, SKIP_BYTE2, Settings->SkipByte2 == true ? 1 : 0 ) |
1282            BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL2_TABLE_i, GEN_GRP_SEL, GroupSel )
1283        );
1284        BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1285
1286        /* Enable the filters for this PID channel. */
1287        BREG_Write32( hXpt->hRegister, BCHP_XPT_MSG_GEN_FILT_EN_i_ARRAY_BASE + ( MesgBufferNum * GEN_FILT_EN_STEP ), Settings->FilterEnableMask );     
1288
1289        RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( MesgBufferNum * PID_CTRL1_TABLE_STEP );
1290        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1291        Reg &= ~(
1292            BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, ERR_CK_MODE ) |
1293            BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, ERR_CK_DIS ) |
1294            BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, ALIGN_MODE ) |
1295            BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE ) 
1296        );
1297   
1298        /* Configure the message buffer for capturing PSI messages. */
1299        Reg |= (
1300            BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, ALIGN_MODE, Settings->ByteAlign == true ? 0 : 1 ) |
1301            BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE, BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_DATA_OUTPUT_MODE_MPEG_PSI ) 
1302        );
1303
1304        /* CRC checks can be disabled on a per-PID channel basis. Do this here if requested in the settings struct. */
1305        Reg |= (
1306            BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, ERR_CK_MODE, 0 ) |
1307            BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, ERR_CK_DIS, Settings->CrcDisable == true ? 1 : 0 ) 
1308        );
1309        BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1310
1311        /* Enable data from the PID channel to the mesg block. */
1312        if(hXpt->PidChannelTable[ PidChannelNum ].MessageBuffercount == 0)
1313        {
1314            if( hXpt->MesgDataOnRPipe || Settings->UseRPipe ) 
1315                BXPT_P_SetPidChannelDestination( hXpt, PidChannelNum, 7, true );
1316            else
1317                BXPT_P_SetPidChannelDestination( hXpt, PidChannelNum, 6, true );
1318       
1319            /* Set this PID channel as allocated, in case they forced the channel assignment. */
1320            hXpt->PidChannelTable[ PidChannelNum ].IsAllocated = true;
1321   
1322            /* Configure the PID channel. */
1323            ExitCode = BXPT_ConfigurePidChannel( hXpt, PidChannelNum, Settings->Pid, Settings->Band );
1324            if( ExitCode != BERR_SUCCESS )
1325                goto Done;
1326        }
1327
1328        /*
1329        ** Some filtering configs were done in the parser band on older chips. Now, those
1330        ** configs are done per-PID channel.
1331        */
1332        BXPT_P_ApplyParserPsiSettings( hXpt, Settings->Band, false );   /* Check IB parsers */
1333
1334        BXPT_P_ApplyParserPsiSettings( hXpt, Settings->Band, true );    /* Check playback parsers */
1335
1336        ConfigPid2BufferMap( hXpt, PidChannelNum, MesgBufferNum, true);
1337
1338        /* Enable the PID channel. */ 
1339        if(hXpt->PidChannelTable[ PidChannelNum ].MessageBuffercount == 0)
1340        {
1341            ExitCode = BERR_TRACE( BXPT_EnablePidChannel( hXpt, PidChannelNum ) );
1342        }
1343
1344        hXpt->PidChannelTable[ PidChannelNum ].MessageBuffercount++;
1345    }
1346
1347        Done:
1348    return( ExitCode );
1349}
1350
1351BERR_Code BXPT_Mesg_StopPsiMessageCapture( 
1352    BXPT_Handle hXpt,                           /* [in] Handle for this transport */
1353    unsigned int PidChannelNum,                  /* [in] Which PID channel. */
1354    unsigned int MesgBufferNum                  /* [in] Which PID channel. */
1355    )
1356{
1357    /* Turns out this is really easy.. */
1358    return( BERR_TRACE( BXPT_Mesg_StopPidChannelRecord( hXpt, PidChannelNum, MesgBufferNum )));
1359}
1360
1361BERR_Code BXPT_CheckBufferWithWrap( 
1362    BXPT_Handle hXpt,           /* [in] Handle for this transport */
1363    unsigned int MesgBufferNum, /* [in] buffer to check.*/
1364    uint8_t **BufferAddr,       /* [out] Address of the buffer. */
1365    size_t *MessageSizeBeforeWrap,        /* [out] Total size of new messages before the buffer wrapped. */
1366    uint8_t **WrapBufferAddr,    /* [out] Address of the wraparound data. 0 if no wrap */
1367    size_t *MessageSizeAfterWrap    /* Total size of message starting at the base. NULL if no wrap */
1368    )
1369{
1370    BERR_Code ExitCode = BERR_SUCCESS;
1371
1372    BDBG_ASSERT( hXpt );
1373    BDBG_ASSERT( BufferAddr );
1374    BDBG_ASSERT( MessageSizeBeforeWrap );
1375    BDBG_ASSERT( WrapBufferAddr );
1376    BDBG_ASSERT( MessageSizeAfterWrap );
1377
1378    *BufferAddr = *WrapBufferAddr = ( uint8_t * ) NULL;
1379    *MessageSizeBeforeWrap = *MessageSizeAfterWrap = 0;
1380
1381        if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) {
1382        /* Bad Message Buffer number. Complain. */
1383        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
1384        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1385        }
1386    else
1387    {
1388        uint32_t DataReady;
1389
1390        uint32_t RegAddr = 0;
1391        uint32_t BitShift = 0;
1392
1393        /* Interrupt registers are 32 bits wide, so step to the next one if needed. */
1394        AdjustChanAndAddr( hXpt, MesgBufferNum, BCHP_XPT_MSG_BUF_DAT_RDY_INTR_00_31, &BitShift, &RegAddr ); 
1395        DataReady = BREG_Read32( hXpt->hRegister, RegAddr );
1396        DataReady &= 1ul << BitShift;
1397
1398        /* Is there any new data in the buffer? */
1399        if ( DataReady )
1400        {
1401            uint32_t Reg, ReadPtr, ValidPtr, BufferStart, BufferSizeInBytes;
1402            size_t Dummy;
1403
1404            /* Yes, there is data */
1405
1406            GetBufferPointers( hXpt, MesgBufferNum, &ReadPtr, &ValidPtr, &Dummy, &BufferSizeInBytes );
1407            Reg = BREG_Read32( hXpt->hRegister, GetRegArrayAddr( hXpt, MesgBufferNum, BCHP_XPT_MSG_DMA_BP_TABLE_i_ARRAY_BASE ) );
1408            BufferStart = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_DMA_BP_TABLE_i, BP_BUFFER_BASE_ADDR );
1409            BufferStart *= BXPT_P_MESSAGE_BUFFER_BLOCK_SIZE;
1410
1411            /* On the new chip arch Read==Valid is always empty */
1412            if ( ReadPtr == ValidPtr )
1413            {
1414                BDBG_MSG(( "(PR25533)Data Ready set,but buffer empty" ));
1415                Dummy = 0;   /* Placate the compiler. We've already set the pointers to NULL above. */
1416            }
1417
1418            /* Did it wrap around? */
1419            else if ( ValidPtr < ReadPtr )
1420            {
1421                /* It wrapped, but its not full. */
1422                *MessageSizeBeforeWrap = (size_t) BufferSizeInBytes - ReadPtr;
1423                BERR_TRACE( BMEM_ConvertOffsetToAddress( hXpt->hMemory, BufferStart + ReadPtr, ( void ** ) BufferAddr ));
1424
1425                *MessageSizeAfterWrap = ( size_t ) ValidPtr;
1426                if( *MessageSizeAfterWrap )
1427                {
1428                    BERR_TRACE( BMEM_ConvertOffsetToAddress( hXpt->hMemory, BufferStart, ( void ** ) WrapBufferAddr ));
1429                }
1430            }
1431
1432            /* Not full or wrapped. */
1433            else
1434            {
1435                /* No wrap and not full. */
1436                *MessageSizeBeforeWrap =  ( size_t ) ( ValidPtr - ReadPtr );
1437                BERR_TRACE( BMEM_ConvertOffsetToAddress( hXpt->hMemory, BufferStart + ReadPtr, ( void ** ) BufferAddr ));
1438            }
1439        }
1440    }
1441
1442    return( ExitCode );
1443}
1444
1445BERR_Code BXPT_CheckBuffer( 
1446    BXPT_Handle hXpt,           /* [in] Handle for this transport */
1447    unsigned int MesgBufferNum, /* [in] buffer to check.*/
1448    uint8_t **BufferAddr,       /* [out] Address of the buffer. */
1449    size_t *MessageSize,        /* [out] Total size of new messages. */
1450    bool *MoreDataAvailable     /* [out] TRUE if the buffer wrapped. */
1451    )
1452{
1453    uint8_t *WrapBufferAddr = NULL;
1454    size_t MessageSizeAfterWrap = 0;
1455    BERR_Code ExitCode = BERR_SUCCESS;
1456
1457    BDBG_ASSERT( hXpt );
1458    BDBG_ASSERT( BufferAddr );
1459    BDBG_ASSERT( MessageSize );
1460    BDBG_ASSERT( MoreDataAvailable );
1461
1462    ExitCode = BXPT_CheckBufferWithWrap( hXpt, MesgBufferNum, BufferAddr, MessageSize, &WrapBufferAddr, &MessageSizeAfterWrap );
1463    if( WrapBufferAddr )
1464        *MoreDataAvailable = true;
1465    else
1466        *MoreDataAvailable = false;
1467
1468    return ExitCode;
1469}
1470
1471BERR_Code BXPT_GetBuffer( 
1472    BXPT_Handle hXpt,           /* [in] Handle for this transport */
1473    unsigned int MesgBuffNum, /* [in] Message buffer to check. */
1474    uint8_t *BufferAddr,        /* [out] Address of the buffer. */
1475    size_t *UserBufferSize      /* [in,out] Size of message buffer (on input), size of new messages (on putput). */
1476    )
1477{
1478    BERR_Code ExitCode = BERR_SUCCESS;
1479
1480    BKNI_EnterCriticalSection();
1481    ExitCode = BXPT_GetBuffer_isr( hXpt, MesgBuffNum, BufferAddr, UserBufferSize );
1482    BKNI_LeaveCriticalSection();
1483
1484    return( ExitCode );
1485}
1486
1487BERR_Code BXPT_GetBuffer_isr(
1488    BXPT_Handle hXpt,           /* [in] Handle for this transport */
1489    unsigned int MesgBuffNum, /* [in] Message buffer to check. */
1490    uint8_t *BufferAddr,        /* [out] Address of the buffer. */
1491    size_t *UserBufferSize      /* [in,out] Size of message buffer (on input), size of new messages (on putput). */
1492    )
1493{
1494    uint32_t ReadPtr, ValidPtr;
1495
1496    BERR_Code ExitCode = BERR_SUCCESS;
1497    size_t MessageSize = 0;     /* Init to no messages. */
1498    size_t DmaBufferSize = 0;
1499
1500    BDBG_ASSERT( hXpt );
1501    BDBG_ASSERT( BufferAddr );
1502    BDBG_ASSERT( UserBufferSize );
1503
1504    GetBufferPointers( hXpt, MesgBuffNum, &ReadPtr, &ValidPtr, &MessageSize, &DmaBufferSize );
1505
1506    /* Copy over as much data as will fit in the buffer.  */
1507    *UserBufferSize = ( *UserBufferSize < MessageSize ) ? *UserBufferSize : MessageSize;
1508    CopyDmaDataToUser( hXpt, MesgBuffNum, ReadPtr, BufferAddr, *UserBufferSize, DmaBufferSize );
1509
1510    /*
1511    ** The CDI driver uses buffers that are too small for the messages they want to capture, so don't update
1512    ** the READ pointer past the end of the data they can take. They'll have to call this API again. See
1513    ** PR 34473 for details
1514    */
1515    ExitCode = BXPT_UpdateReadOffset_isr( hXpt, MesgBuffNum, *UserBufferSize );
1516
1517    return( ExitCode );
1518}
1519
1520BERR_Code BXPT_UpdateReadOffset( 
1521    BXPT_Handle hXpt,           /* [in] Handle for this transport */
1522    unsigned int MesgBuffNum,     /* [in] Which mesg buffer to update. */
1523    size_t BytesRead            /* [in] Number of bytes read. */
1524    )
1525{
1526    BERR_Code ErrCode;
1527
1528    BKNI_EnterCriticalSection();
1529    ErrCode = BXPT_UpdateReadOffset_isr( hXpt, MesgBuffNum, BytesRead ) ;
1530    BKNI_LeaveCriticalSection();
1531    return ErrCode;
1532}
1533
1534BERR_Code BXPT_UpdateReadOffset_isr( 
1535    BXPT_Handle hXpt,           /* [in] Handle for this transport */
1536    unsigned int MesgBuffNum,     /* [in] Which mesg buffer to update. */
1537    size_t BytesRead            /* [in] Number of bytes read. */
1538    )
1539{
1540    BERR_Code ExitCode = BERR_SUCCESS;
1541
1542    BDBG_ASSERT( hXpt );
1543
1544
1545    /* Sanity check on the arguments. */
1546        if ( MesgBuffNum >= BXPT_NUM_MESG_BUFFERS ) {
1547        /* Bad Message Buffer number. Complain. */
1548        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBuffNum ));
1549        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1550        }
1551    else
1552    {
1553        uint32_t Reg, ReadPtr, SizeField, i;
1554
1555        uint32_t BufferSizeInBytes = 1024;
1556        uint32_t RpRegAddr = GetRegArrayAddr( hXpt, MesgBuffNum, BCHP_XPT_MSG_DMA_RP_TABLE_i_ARRAY_BASE );
1557
1558        /* Get the read pointer. */
1559        Reg = BREG_Read32( hXpt->hRegister, RpRegAddr );
1560        ReadPtr = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_DMA_RP_TABLE_i, READ_POINTER );
1561
1562        /* Compute the size of the buffer, in bytes. */
1563        Reg = BREG_Read32( hXpt->hRegister, GetRegArrayAddr( hXpt, MesgBuffNum, BCHP_XPT_MSG_DMA_BP_TABLE_i_ARRAY_BASE ) );
1564        SizeField = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_DMA_BP_TABLE_i, BP_BUFFER_SIZE );
1565        for( i = 0; i < SizeField; i++ )
1566            BufferSizeInBytes *= 2;
1567           
1568        if( BytesRead > BufferSizeInBytes )
1569        {
1570            BDBG_ERR(( "BytesRead %d is larger than the buffer %d for MesgBuffNum %lu!", BytesRead, BufferSizeInBytes, ( unsigned long ) MesgBuffNum )); 
1571            ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1572        }
1573                       
1574        /* Add number of bytes we read to the pointer. */
1575        ReadPtr += BytesRead;
1576
1577        /* Now check if that caused a wrap. */
1578        if( ReadPtr >= BufferSizeInBytes )
1579        {
1580            /* It did, so adjust the ReadPtr to be an offset from the start of the buffer. */
1581            ReadPtr -= BufferSizeInBytes;
1582        }
1583       
1584        /* Now write out the new ReadPtr. */
1585        Reg = BREG_Read32( hXpt->hRegister, RpRegAddr );
1586        Reg &= ~( BCHP_MASK( XPT_MSG_DMA_RP_TABLE_i, READ_POINTER ) );
1587        Reg |= ( BCHP_FIELD_DATA( XPT_MSG_DMA_RP_TABLE_i, READ_POINTER, ReadPtr ) );
1588        BREG_Write32( hXpt->hRegister, RpRegAddr, Reg );
1589
1590
1591        /* Due to current HW limitation the data ready interrupt data ready irpts are missed
1592           if the valid pointer is updated within one clock cycle of the data read 
1593           pointer update. We need to check for this condition and force the cb */
1594        {
1595            uint32_t ReadPtr, ValidPtr;
1596            size_t BytesInBuffer, BufferSizeInBytes;
1597            bool DataReady = GetPidChannelFlag( hXpt, MesgBuffNum, BCHP_XPT_MSG_BUF_DAT_RDY_INTR_00_31 );
1598            GetBufferPointers( hXpt, MesgBuffNum, &ReadPtr, &ValidPtr, &BytesInBuffer, &BufferSizeInBytes );
1599            if( !DataReady && BytesInBuffer)
1600            {
1601                /* we have the hw error, trigger the interrupt */
1602                BDBG_MSG(( "Data ready irpt lost,generating irpt cb in sw" ));
1603                BXPT_P_Interrupt_MsgSw_isr(hXpt,MesgBuffNum);
1604            }
1605        }
1606    }
1607
1608    return( ExitCode );
1609}
1610
1611BERR_Code BXPT_PausePesRecord(
1612    BXPT_Handle hXpt,                       /* [in] Handle for this transport */
1613    unsigned int MesgBuffNum,     /* [in] Which message buffer. */
1614    bool Pause                                /* [in] Enable or disable pause */
1615    )
1616{
1617    BDBG_ASSERT( hXpt );
1618
1619    return( BXPT_P_PauseFilters( hXpt, MesgBuffNum, BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_DATA_OUTPUT_MODE_MPEG_PES, Pause ));
1620}
1621
1622BERR_Code BXPT_PausePsiCapture(
1623    BXPT_Handle hXpt,                       /* [in] Handle for this transport */
1624    unsigned int MesgBuffNum,             /* [in] Which message buffer. */
1625    bool Pause                                /* [in] Enable or disable pause */
1626    )
1627{
1628    BDBG_ASSERT( hXpt );
1629
1630    return( BXPT_P_PauseFilters( hXpt, MesgBuffNum, BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_DATA_OUTPUT_MODE_MPEG_PSI, Pause ));
1631}
1632
1633BERR_Code BXPT_Mesg_SetPidChannelPsiSettings(
1634        BXPT_Handle hXpt,                  /* [In] Handle for this transport */
1635        unsigned int PidChannelNum,        /* [In] The pid channel to configure. */
1636        unsigned int MesgBufferNum,        /* [In] The Mesg Buffer NUmber to configure. */
1637        bool OverrideParserSettings,       /* [In] If set true the PSI settings for
1638                                                   this pid channel will be changed to Config
1639                                                   else restored to the paser band to which
1640                                                   this pid channel is allocated */
1641        const BXPT_PidPsiConfig *Config    /* [In] Message mode setting for pid channel. */
1642        )                           
1643{
1644
1645    uint32_t Reg, RegAddr, PlaybackFeSel, ChnlParserNum;
1646    ParserConfig *PcPtr;
1647    BERR_Code ExitCode = BERR_SUCCESS;
1648
1649    BDBG_ASSERT( hXpt );
1650    BDBG_ASSERT( Config );
1651
1652    /* Sanity check on the arguments. */
1653    if( PidChannelNum >= hXpt->MaxPidChannels )
1654    {
1655        /* Bad PID channel number. Complain. */
1656        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
1657        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1658    }
1659        else if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) 
1660    {
1661        /* Bad Message Buffer number. Complain. */
1662        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
1663        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1664        }
1665    else
1666    {
1667        RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_TABLE_STEP );
1668        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1669        PlaybackFeSel = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL );
1670        ChnlParserNum = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT );
1671
1672        if( PlaybackFeSel )
1673            PcPtr = &( hXpt->PbParserTable[ ChnlParserNum ] );
1674        else
1675            PcPtr = &( hXpt->IbParserTable[ ChnlParserNum ] );
1676
1677        /* Yes, update the PSI config members in the PID channel. */                       
1678        RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( MesgBufferNum * PID_CTRL1_TABLE_STEP );
1679        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1680
1681        Reg &= ~(
1682                 BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_SHORT_PSI_EN ) |
1683                 BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_LONG_PSI_EN ) |
1684                 BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, PSF_CRC_DIS ) |
1685                 BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i,  MSG_MOD_MODE )
1686        );
1687
1688        if(OverrideParserSettings)
1689        {
1690            /* reserve this pid channel to have PSI setting different from the
1691               pid parser */
1692            hXpt->PidChannelParserConfigOverride[MesgBufferNum] = true;
1693            Reg |= (
1694              BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_SHORT_PSI_EN, Config->SaveShortPsiMsg == true ? 1 : 0 )  |
1695              BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_LONG_PSI_EN, Config->SaveLongPsiMsg == true ? 1 : 0 ) |
1696              BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, PSF_CRC_DIS, Config->PsfCrcDis == true ? 1 : 0 )  |
1697              BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, MSG_MOD_MODE, Config->PsiMsgMod ) 
1698            );
1699        }
1700        else
1701        {
1702            /* release the pid channel to the pool */
1703            hXpt->PidChannelParserConfigOverride[MesgBufferNum] = false;
1704            Reg |= (
1705              BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_SHORT_PSI_EN, PcPtr->SaveShortPsiMsg == true ? 1 : 0 )  |
1706              BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_LONG_PSI_EN, PcPtr->SaveLongPsiMsg == true ? 1 : 0 ) |
1707              BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, PSF_CRC_DIS, PcPtr->PsfCrcDis == true ? 1 : 0 )  |
1708             BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, MSG_MOD_MODE, PcPtr->PsiMsgMod ) 
1709            );
1710        }
1711        BREG_Write32( hXpt->hRegister, RegAddr, Reg ); 
1712    }
1713
1714    return( ExitCode );
1715}
1716
1717BERR_Code BXPT_Mesg_GetPidChannelPsiSettings(
1718        BXPT_Handle hXpt,                  /* [In] Handle for this transport */
1719        unsigned int PidChannelNum,        /* [In] The pid channel to configure. */
1720        unsigned int MesgBufferNum,        /* [In] The pid channel to configure. */
1721        bool *OverrideParserSettings,       /* [Out]  */
1722        BXPT_PidPsiConfig *Config    /* [Out] Message mode setting for pid channel. */
1723        )                           
1724{
1725
1726    uint32_t Reg, RegAddr;
1727    BERR_Code ExitCode = BERR_SUCCESS;
1728
1729    BDBG_ASSERT( hXpt );
1730    BDBG_ASSERT( Config );
1731
1732    /* Sanity check on the arguments. */
1733    if( PidChannelNum >= hXpt->MaxPidChannels )
1734    {
1735        /* Bad PID channel number. Complain. */
1736        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
1737        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1738    }
1739        else if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) 
1740    {
1741        /* Bad Message Buffer number. Complain. */
1742        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
1743        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1744        }
1745    else
1746    {
1747        *OverrideParserSettings = hXpt->PidChannelParserConfigOverride[MesgBufferNum];
1748        RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( MesgBufferNum * PID_CTRL1_TABLE_STEP );
1749        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1750
1751        Config->PsfCrcDis = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_BUF_CTRL1_TABLE_i, PSF_CRC_DIS ) ? true : false;
1752        Config->SaveLongPsiMsg = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_LONG_PSI_EN ) ? true : false; 
1753        Config->SaveShortPsiMsg = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_SHORT_PSI_EN ) ? true : false; 
1754        Config->PsiMsgMod =  BCHP_GET_FIELD_DATA( Reg, XPT_MSG_BUF_CTRL1_TABLE_i, MSG_MOD_MODE );
1755    }
1756
1757    return( ExitCode );
1758}
1759 
1760BERR_Code BXPT_P_ApplyParserPsiSettings(
1761    BXPT_Handle hXpt,                     
1762    unsigned int ParserNum,
1763    bool IsPbParser             
1764    )
1765{
1766    unsigned PidChannelNum;
1767
1768    BERR_Code ExitCode = BERR_SUCCESS;
1769
1770    BDBG_ASSERT( hXpt );
1771    BSTD_UNUSED( IsPbParser );
1772
1773    for( PidChannelNum = 0; PidChannelNum < BXPT_NUM_MESG_BUFFERS/*(BXPT_NUM_PID_CHANNELS/2)*/; PidChannelNum++ )
1774    {
1775        uint32_t Reg, RegAddr, PlaybackFeSel, ChnlParserNum;
1776        ParserConfig *PcPtr;
1777
1778        /* if this pid channel is reserved for per pid psi configuration
1779           leave it alone */ 
1780        if(hXpt->PidChannelParserConfigOverride[PidChannelNum])
1781            continue; 
1782
1783        RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_TABLE_STEP );
1784        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1785        PlaybackFeSel = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL );
1786        ChnlParserNum = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT );
1787
1788        /* Is this PID channel mapped to the parser code who called it? */
1789        /* The ParserNum passed in my have the MSB set, which is our internal indication that the band is a playback parser */
1790        if( BXPT_P_CLEAR_PB_FLAG( ParserNum ) == ChnlParserNum && hXpt->PidChannelTable[ PidChannelNum ].IsPidChannelConfigured )
1791        {
1792            if( PlaybackFeSel )
1793            {
1794                if( ParserNum >= BXPT_NUM_PLAYBACKS )
1795                {
1796                    BDBG_ERR(( "Playback ParserNum %u out of range", ParserNum ));
1797                    ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1798                    goto Done;
1799                }
1800       
1801                PcPtr = &( hXpt->PbParserTable[ ParserNum ] );
1802            }
1803            else
1804            {
1805                if( ParserNum >= BXPT_NUM_PID_PARSERS )
1806                {
1807                    BDBG_ERR(( "Input ParserNum %u out of range", ParserNum ));
1808                    ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1809                    goto Done;
1810                }
1811       
1812                PcPtr = &( hXpt->IbParserTable[ ParserNum ] );
1813            }
1814
1815            /* Yes, update the PSI config members in the PID channel. */                       
1816            RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CTRL1_TABLE_STEP );
1817            Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1818
1819            Reg &= ~(
1820                BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_SHORT_PSI_EN ) |
1821                BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_LONG_PSI_EN ) |
1822                BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, PSF_CRC_DIS ) |
1823                BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i,  MSG_MOD_MODE )
1824            );
1825
1826            Reg |= (
1827                BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_SHORT_PSI_EN, PcPtr->SaveShortPsiMsg == true ? 1 : 0 )  |
1828                BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, SAVE_LONG_PSI_EN, PcPtr->SaveLongPsiMsg == true ? 1 : 0 ) |
1829                BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, PSF_CRC_DIS, PcPtr->PsfCrcDis == true ? 1 : 0 )  |
1830                BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, MSG_MOD_MODE, PcPtr->PsiMsgMod ) 
1831            );
1832            BREG_Write32( hXpt->hRegister, RegAddr, Reg ); 
1833        }
1834    }
1835
1836    Done:
1837    return( ExitCode );
1838}
1839
1840BERR_Code ConfigMessageBufferRegs( 
1841    BXPT_Handle hXpt,                   /* [Input] Handle for this transport */
1842    unsigned int PidChannelNum,             /* [Input] Which PID channel buffer we want. */
1843    uint32_t CpuAddr,                   /* [Input] Caller allocated memory, or NULL. */
1844    BXPT_MessageBufferSize BufferSize   /* [Input] Size, in bytes, of the buffer. */
1845    )
1846{                   
1847    uint32_t Reg, RegAddr, Offset, OutputMode;
1848
1849    BERR_Code ExitCode = BERR_SUCCESS;
1850
1851    /** Reset the Valid Pointer. **/
1852    /* Set the PID channel message output mode to NO_OUTPUT ( == 0 ) first. */
1853    RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CTRL1_TABLE_STEP );
1854    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1855    OutputMode = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE );
1856    Reg &= ~BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE );
1857    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1858
1859    /* Write the PID channel number to the buffer reset register. Writes trigger the reset. */
1860    BREG_Write32( hXpt->hRegister, BCHP_XPT_MSG_DMA_BUFFER_INIT, PidChannelNum );
1861
1862    /** Clear the read pointer. **/
1863    RegAddr = BCHP_XPT_MSG_DMA_RP_TABLE_i_ARRAY_BASE + ( PidChannelNum * RP_TABLE_STEP );
1864    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1865    Reg &= ~BCHP_MASK( XPT_MSG_DMA_RP_TABLE_i, READ_POINTER ); 
1866    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1867
1868    BMEM_ConvertAddressToOffset( hXpt->hMemory, ( void * ) CpuAddr, &Offset );
1869
1870    /*
1871    ** The buffer address passed in is still a byte-based address.
1872    ** Convert this to an address based on blocks the size of
1873    ** BXPT_P_MESSAGE_BUFFER_BLOCK_SIZE .
1874    */
1875    Offset /= BXPT_P_MESSAGE_BUFFER_BLOCK_SIZE;
1876
1877    /** Set the buffer address and size. **/
1878    RegAddr = BCHP_XPT_MSG_DMA_BP_TABLE_i_ARRAY_BASE + ( PidChannelNum * BP_TABLE_STEP );
1879    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1880
1881    Reg &= ~( 
1882        BCHP_MASK( XPT_MSG_DMA_BP_TABLE_i, BP_BUFFER_SIZE ) |
1883        BCHP_MASK( XPT_MSG_DMA_BP_TABLE_i, BP_BUFFER_BASE_ADDR )
1884        );
1885
1886    Reg |= ( 
1887        BCHP_FIELD_DATA( XPT_MSG_DMA_BP_TABLE_i, BP_BUFFER_SIZE, ( uint32_t ) BufferSize ) |
1888        BCHP_FIELD_DATA( XPT_MSG_DMA_BP_TABLE_i, BP_BUFFER_BASE_ADDR, Offset )
1889        );
1890
1891    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1892
1893    /* Restore the old output mode */
1894    RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CTRL1_TABLE_STEP );
1895    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1896    Reg |= BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE, OutputMode );
1897    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1898   
1899    return( ExitCode );
1900}
1901
1902BERR_Code BXPT_GetMesgBufferDepth(
1903    BXPT_Handle hXpt,
1904    unsigned int PidChannelNum,
1905    size_t *BufferDepth
1906    )
1907{
1908    BERR_Code ExitCode = BERR_SUCCESS;
1909
1910    BDBG_ASSERT( hXpt );
1911    BDBG_ASSERT( BufferDepth );
1912
1913    /* Sanity check on the arguments. */
1914    if( PidChannelNum >= hXpt->MaxPidChannels )   
1915    {
1916        /* Bad parser band number. Complain. */
1917        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
1918        *BufferDepth = 0;
1919        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1920    }
1921    else
1922    {
1923        uint32_t Read, Valid;
1924        size_t BufferSize;
1925
1926        GetBufferPointers( hXpt, PidChannelNum, &Read, &Valid, BufferDepth, &BufferSize );
1927    }
1928
1929    return ExitCode;
1930}
1931
1932void GetFilterAddrs(
1933    unsigned int GroupSel,         
1934    unsigned int FilterNum,     
1935    uint32_t *CoefAddr,
1936    uint32_t *MaskAddr,
1937    uint32_t *ExclAddr
1938    )
1939{
1940    FilterNum *= 4; /* Since each filter register is 4 bytes wide. */
1941    GroupSel *= 4;
1942
1943    if( CoefAddr )
1944        *CoefAddr = BCHP_XPT_MSG_GEN_FILT_COEF_i_ARRAY_BASE + GroupSel + FilterNum;
1945    if( MaskAddr )
1946        *MaskAddr = BCHP_XPT_MSG_GEN_FILT_MASK_i_ARRAY_BASE + GroupSel + FilterNum;
1947    if( ExclAddr )
1948        *ExclAddr = BCHP_XPT_MSG_GEN_FILT_EXCL_i_ARRAY_BASE + GroupSel + FilterNum;
1949}
1950
1951BERR_Code ChangeFilterByte( 
1952    BXPT_Handle hXpt,       
1953    uint32_t FilterBaseAddr,   
1954    unsigned int FilterNum,     
1955    unsigned int ByteOffset,       
1956    uint8_t FilterByte     
1957    )
1958{
1959    BERR_Code ExitCode = BERR_SUCCESS;
1960
1961    BDBG_ASSERT( hXpt );
1962
1963    /* Sanity check on the arguments. */
1964    if( FilterNum >= BXPT_P_FILTER_TABLE_SIZE )   
1965    {
1966        /* Bad parser band number. Complain. */
1967        BDBG_ERR(( "FilterNum %lu is out of range!", ( unsigned long ) FilterNum ));
1968        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1969    }
1970    else if( ByteOffset >= BXPT_FILTER_SIZE )     
1971    {
1972        /* Bad parser band number. Complain. */
1973        BDBG_ERR(( "ByteOffset %lu is out of range!", ( unsigned long ) ByteOffset ));
1974        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1975    }
1976    else
1977    {
1978        uint32_t Reg, ShiftVal;
1979
1980        /*
1981        ** The filter bytes are organized as 1 or more 4-byte registers. The registers
1982        ** themselves are NOT located sequentially in memory: Bytes 0-3 of the filter
1983        ** are in a register at address X, but bytes 4-7 are in a register at address
1984        ** X + 32. The rest of the register addresses increment in the same way.
1985        */
1986        FilterBaseAddr += ( ByteOffset / 4 ) * FILTER_WORD_STEP;
1987        ShiftVal = 3 - ( ByteOffset % 4 );      /* ShiftVal expressed as bytes */
1988        ShiftVal *= 8;                          /* ShiftVal expressed as bits */
1989       
1990        Reg = BREG_Read32( hXpt->hRegister, FilterBaseAddr );
1991        Reg &= ~( 0xFF << ShiftVal );
1992        Reg |= ( FilterByte << ShiftVal );
1993        BREG_Write32( hXpt->hRegister, FilterBaseAddr, Reg );
1994    }
1995
1996    return( ExitCode );
1997}
1998
1999BERR_Code BXPT_P_GetGroupSelect(
2000                               unsigned int Bank,
2001                               unsigned int *GenGrpSel
2002                               )
2003{
2004    BERR_Code ExitCode = BERR_SUCCESS;
2005
2006    if(BXPT_FILTER_SIZE == 32)
2007    {
2008        switch ( Bank )
2009        {
2010        case 0:
2011            *GenGrpSel = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_GEN_GRP_SEL_G8_B0;
2012            break;
2013
2014        case 1:
2015            *GenGrpSel = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_GEN_GRP_SEL_G8_B8;
2016            break;
2017
2018        default:
2019            BDBG_ERR(( "Bank %lu is out of range!", ( unsigned long ) Bank ));
2020        }
2021    }
2022    else
2023    {
2024        switch ( Bank)
2025        {
2026        case 0:
2027            *GenGrpSel = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_GEN_GRP_SEL_G4_B0;
2028            break;
2029
2030        case 1:
2031            *GenGrpSel = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_GEN_GRP_SEL_G4_B4;
2032            break;
2033
2034        case 2:
2035            *GenGrpSel = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_GEN_GRP_SEL_G4_B8;
2036            break;
2037        case 3:
2038            *GenGrpSel = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_GEN_GRP_SEL_G4_B12;
2039            break;
2040
2041        default:
2042            BDBG_ERR(( "Bank %lu is out of range!", ( unsigned long ) Bank ));
2043        }
2044       
2045    }
2046    return ExitCode;
2047}
2048
2049BERR_Code BXPT_Mesg_GetPidChannelFromBufferNum(
2050    BXPT_Handle hXpt,                               /* [in] Handle for this transport */
2051    unsigned int MesgBufferNum,                         /* [in] Which Buffer Number. */
2052    unsigned int *PidChannelNum                         /* [out] Which PID channel. */
2053    )
2054{
2055    BERR_Code ExitCode = BERR_SUCCESS;
2056
2057    BDBG_ASSERT( hXpt );
2058    BDBG_ASSERT( PidChannelNum );
2059
2060    *PidChannelNum = BXPT_NUM_PID_CHANNELS;
2061        if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) 
2062    {
2063        /* Bad Message Buffer number. Complain. */
2064        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
2065        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2066        }
2067    else
2068    {
2069        unsigned Index;
2070        uint32_t RegAddr;
2071
2072        unsigned Mask = 1 << (MesgBufferNum % 32);
2073        unsigned RegOffset = (MesgBufferNum / 32);   
2074
2075        for( Index = 0; Index < BXPT_NUM_MESG_BUFFERS; Index++ ) 
2076        {
2077            uint32_t Reg;
2078            RegAddr = BCHP_XPT_MSG_PID2BUF_MAP_i_ARRAY_BASE + (Index * 16) + (RegOffset * 4);
2079
2080            Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2081            if( Reg & Mask) 
2082            {
2083                *PidChannelNum = Index;
2084                break;
2085            }
2086        }
2087    }
2088
2089    return ExitCode;
2090}
2091
2092unsigned GetPidChannelByFilter( 
2093    BXPT_Handle hXpt, 
2094    unsigned int Bank, 
2095    unsigned int FilterNum
2096    )
2097{
2098    unsigned GenGrpSel = BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_GEN_GRP_SEL_G8_B0;
2099    unsigned Index = BXPT_NUM_PID_CHANNELS;
2100
2101    BDBG_ASSERT( hXpt );
2102
2103    if( BXPT_P_GetGroupSelect( Bank, &GenGrpSel ) != BERR_SUCCESS )
2104        goto Done;
2105
2106    for( Index = 0; Index < BXPT_NUM_MESG_BUFFERS; Index++ )
2107    {
2108        uint32_t Reg, ShiftVal;
2109
2110        /* Is this PID channel using the bank we're worried about? */
2111        Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_ARRAY_BASE + ( Index * PID_CTRL2_TABLE_STEP ) );
2112        if( BCHP_GET_FIELD_DATA( Reg, XPT_MSG_BUF_CTRL2_TABLE_i, GEN_GRP_SEL ) != GenGrpSel )
2113            continue;       /* This channel isn't using the filter bank we're after. */
2114
2115        ShiftVal = 1ul << FilterNum;
2116        Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_MSG_GEN_FILT_EN_i_ARRAY_BASE + ( Index * GEN_FILT_EN_STEP ) );
2117        if( Reg & ShiftVal )
2118            break;          /* Found it. */ 
2119    }
2120
2121    if(Index == BXPT_NUM_MESG_BUFFERS)
2122        Index = BXPT_NUM_PID_CHANNELS;
2123     
2124    Done:
2125    return Index;
2126}
2127
2128BERR_Code BXPT_P_DisableFilter( 
2129    BXPT_Handle hXpt,       
2130    unsigned int FilterNum,     
2131    unsigned int PidChannelNum
2132    )
2133{
2134    uint32_t Reg, RegAddr, OutputMode;
2135
2136    BERR_Code ExitCode = BERR_SUCCESS;
2137   
2138    BDBG_ASSERT( hXpt );
2139
2140    /* PR 16986 requires a workaround for modifying a PSI filter. */
2141    /* Old method. */
2142    BSTD_UNUSED( OutputMode );
2143    RegAddr = BCHP_XPT_MSG_GEN_FILT_EN_i_ARRAY_BASE + ( PidChannelNum * GEN_FILT_EN_STEP );
2144    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2145    Reg &= ~( 1ul << FilterNum );
2146    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2147    return( ExitCode );
2148}
2149
2150BERR_Code BXPT_Mesg_GetErrorStatus(
2151    BXPT_Handle hXpt,         /* [in]  Handle for this transport */
2152    unsigned MesgBufferNum,   /* [in]  Which buffer to get the status of */
2153    bool *ErrorStatus         /* [out] Error status for the message buffer */ 
2154)
2155{
2156    BERR_Code ExitCode = BERR_SUCCESS;
2157    uint32_t RegAddr, Reg;
2158
2159    BDBG_ASSERT( hXpt );
2160    BDBG_ASSERT( ErrorStatus );
2161
2162    if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) 
2163    {
2164        /* Bad Message Buffer number. Complain. */
2165        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
2166        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2167    }
2168    else
2169    {
2170        switch (MesgBufferNum / 32) 
2171        {
2172            case 0: RegAddr = BCHP_XPT_MSG_BUF_ERR_00_31; break;
2173            case 1: RegAddr = BCHP_XPT_MSG_BUF_ERR_32_63; break;
2174            case 2: RegAddr = BCHP_XPT_MSG_BUF_ERR_64_95; break;
2175            case 3: RegAddr = BCHP_XPT_MSG_BUF_ERR_96_127; break;
2176            default:
2177                BDBG_ASSERT(0);
2178        }
2179
2180        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2181        *ErrorStatus = ( Reg >> (MesgBufferNum%32) ) & 0x1;
2182
2183        /* clear error status */
2184        Reg &= ~( 0x1 << (MesgBufferNum%32) );
2185        BREG_Write32( hXpt->hRegister, RegAddr, Reg);
2186    }
2187
2188    return ExitCode;
2189}
2190
2191BERR_Code EnableFilter( 
2192    BXPT_Handle hXpt,       
2193    unsigned int FilterNum,     
2194    unsigned int PidChannelNum
2195    )
2196{
2197    uint32_t Reg, RegAddr;
2198
2199    BERR_Code ExitCode = BERR_SUCCESS;
2200   
2201    BDBG_ASSERT( hXpt );
2202   
2203    /* PR 16986 requires a workaround for modifying a PSI filter. */
2204    RegAddr = BCHP_XPT_MSG_GEN_FILT_EN_i_ARRAY_BASE + ( PidChannelNum * GEN_FILT_EN_STEP );
2205    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2206    Reg |= ( 1ul << FilterNum );
2207    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2208
2209    return( ExitCode );
2210}
2211
2212int AdjustChanAndAddr( 
2213    BXPT_Handle hXpt,           /* [Input] Handle for this transport */
2214    uint32_t PidChannelNum,
2215    uint32_t FlagBaseRegister,
2216    uint32_t *AdjustedPidChannel,
2217    uint32_t *AdjustedRegisterAddr
2218    )
2219{           
2220    BSTD_UNUSED( hXpt );
2221
2222    *AdjustedPidChannel = PidChannelNum % XPT_REG_SIZE_BITS;
2223    *AdjustedRegisterAddr = FlagBaseRegister + (( PidChannelNum / XPT_REG_SIZE_BITS ) * XPT_REG_SIZE_BYTES );
2224    return 0;
2225}
2226
2227void GetBufferPointers( 
2228    BXPT_Handle hXpt,
2229    unsigned int PidChannelNum,
2230    uint32_t *ReadPtr,
2231    uint32_t *ValidPtr,
2232    size_t *MesgSize,
2233    size_t *BufferSizeInBytes
2234    )
2235{
2236    uint32_t Reg, SizeField, i;
2237
2238    uint32_t BufferSize = 1024;
2239    /*bool DataReady = GetPidChannelFlag( hXpt, PidChannelNum, BCHP_XPT_MSG_BUF_DAT_RDY_INTR_00_31 );*/
2240   
2241    /* Get the read and valid pointers, coverting to byte-addressing in the process. */
2242    Reg = BREG_Read32( hXpt->hRegister, GetRegArrayAddr( hXpt, PidChannelNum, BCHP_XPT_MSG_DMA_RP_TABLE_i_ARRAY_BASE ) );
2243    *ReadPtr = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_DMA_RP_TABLE_i, READ_POINTER );
2244
2245    Reg = BREG_Read32( hXpt->hRegister, GetRegArrayAddr( hXpt, PidChannelNum, BCHP_XPT_MSG_DMA_VP_TABLE_i_ARRAY_BASE ) );
2246    *ValidPtr = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_DMA_VP_TABLE_i, VALID_POINTER );
2247
2248    /* Compute the size of the buffer, in bytes. */
2249    Reg = BREG_Read32( hXpt->hRegister, GetRegArrayAddr( hXpt, PidChannelNum, BCHP_XPT_MSG_DMA_BP_TABLE_i_ARRAY_BASE) );
2250    SizeField = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_DMA_BP_TABLE_i, BP_BUFFER_SIZE );
2251    for( i = 0; i < SizeField; i++ )
2252        BufferSize *= 2;
2253    *BufferSizeInBytes = BufferSize;
2254
2255    /* How much data is in this buffer? */
2256    if( *ReadPtr == *ValidPtr )
2257    {
2258        *MesgSize = 0;
2259    }
2260    else if( *ValidPtr < *ReadPtr )
2261    {
2262        /* It wrapped, but its not full. */
2263        *MesgSize = BufferSize - *ReadPtr + *ValidPtr;
2264    }
2265    else
2266    {
2267        /* No wrap and not full. */
2268        *MesgSize = *ValidPtr - *ReadPtr;
2269    }
2270}
2271
2272uint32_t GetRegArrayAddr( 
2273    BXPT_Handle hXpt,           /* [Input] Handle for this transport */
2274    uint32_t PidChannelNum,
2275    uint32_t BaseRegister
2276    )
2277{
2278    BSTD_UNUSED( hXpt );
2279
2280    return BaseRegister + ( XPT_REG_SIZE_BYTES * PidChannelNum );
2281}
2282
2283int GetPidChannelFlag(
2284    BXPT_Handle hXpt,           /* [Input] Handle for this transport */
2285    int PidChannelNum,
2286    int FlagBaseRegister
2287    )
2288{
2289    uint32_t Reg;
2290
2291    uint32_t BitShift = 0;
2292    uint32_t RegAddr = 0;
2293
2294    AdjustChanAndAddr( hXpt, PidChannelNum, FlagBaseRegister, &BitShift, &RegAddr );
2295
2296    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2297    Reg &= ( 0x01 << BitShift );
2298    Reg >>= BitShift;
2299    return Reg;
2300}
2301
2302void CopyDmaDataToUser(
2303    BXPT_Handle hXpt,
2304    unsigned int PidChannelNum,
2305    uint32_t ReadPtr,
2306    uint8_t *UserBufferAddr,
2307    size_t NumBytesToCopy,
2308    size_t DmaBufferSize
2309    )
2310{
2311    uint32_t Reg, DmaBaseOffset;
2312    void *DmaBaseAddr;
2313    size_t SpaceUntilEndOfBuffer, ByteCount;
2314
2315    /* Just in case... */
2316    if( NumBytesToCopy > DmaBufferSize )
2317    {
2318        BDBG_ERR(( "CopyDmaDataToUser(): NumBytesToCopy out of range!\n" ));
2319        NumBytesToCopy = DmaBufferSize;
2320    }
2321
2322    Reg = BREG_Read32( hXpt->hRegister, GetRegArrayAddr( hXpt, PidChannelNum, BCHP_XPT_MSG_DMA_BP_TABLE_i_ARRAY_BASE ) );
2323    DmaBaseOffset = BCHP_GET_FIELD_DATA( Reg, XPT_MSG_DMA_BP_TABLE_i, BP_BUFFER_BASE_ADDR );
2324    DmaBaseOffset *= BXPT_P_MESSAGE_BUFFER_BLOCK_SIZE;
2325
2326    /* Number of bytes between ReadPtr and the end of the DMA buffer. */
2327    SpaceUntilEndOfBuffer = DmaBufferSize - ReadPtr;
2328
2329    /* The number of bytes we are asked to copy may be less than the ByteCount above. */
2330    ByteCount = NumBytesToCopy < SpaceUntilEndOfBuffer ? NumBytesToCopy : SpaceUntilEndOfBuffer;
2331
2332    BMEM_ConvertOffsetToAddress( hXpt->hMemory, ( DmaBaseOffset + ReadPtr ), ( void ** ) &DmaBaseAddr );
2333    BKNI_Memcpy( ( void * ) UserBufferAddr, ( void * ) DmaBaseAddr, ByteCount );
2334
2335    NumBytesToCopy -= ByteCount;
2336    UserBufferAddr += ByteCount;
2337   
2338    /* If there's still bytes left to copy, the data must have wrapped around the end of the buffer. */
2339    if( NumBytesToCopy )
2340    {
2341        BMEM_ConvertOffsetToAddress( hXpt->hMemory, ( DmaBaseOffset ), ( void ** ) &DmaBaseAddr );
2342        BKNI_Memcpy( ( void * ) UserBufferAddr, ( void * ) DmaBaseAddr, NumBytesToCopy );
2343    }
2344}
2345
2346BERR_Code BXPT_P_PauseFilters(
2347    BXPT_Handle hXpt,                       
2348    unsigned int PidChannelNum,     
2349    unsigned FilteringOp,     
2350    bool Pause                               
2351    )
2352{
2353    uint32_t Reg, RegAddr;
2354
2355    BERR_Code ExitCode = BERR_SUCCESS;
2356
2357    BDBG_ASSERT( hXpt );
2358
2359    /* Sanity check on the arguments. */
2360    if( PidChannelNum >= hXpt->MaxPidChannels )   
2361    {
2362        /* Bad parser band number. Complain. */
2363        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2364        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2365    }
2366    else
2367    {
2368        if( Pause == true )
2369        {
2370            /* Just turn off the filter. */
2371            RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CTRL1_TABLE_STEP );
2372            Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2373            Reg &= ~(
2374                BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE ) 
2375            );
2376            Reg |= (
2377                BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE, BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_DATA_OUTPUT_MODE_NO_OUTPUT ) 
2378            );
2379            BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2380        }
2381        else
2382        {
2383            /* Write the PID channel number to the buffer reset register. Writes trigger the reset. */
2384            BREG_Write32( hXpt->hRegister, BCHP_XPT_MSG_DMA_BUFFER_INIT, PidChannelNum );
2385
2386            /** Clear the read pointer. **/
2387            RegAddr = BCHP_XPT_MSG_DMA_RP_TABLE_i_ARRAY_BASE + ( PidChannelNum * RP_TABLE_STEP );
2388            Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2389            Reg &= ~BCHP_MASK( XPT_MSG_DMA_RP_TABLE_i, READ_POINTER ); 
2390            BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2391
2392            /* Turn the filter back on. */
2393            RegAddr = BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CTRL1_TABLE_STEP );
2394            Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2395            Reg &= ~(
2396                BCHP_MASK( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE ) 
2397            );
2398            Reg |= (
2399                BCHP_FIELD_DATA( XPT_MSG_BUF_CTRL1_TABLE_i, DATA_OUTPUT_MODE, FilteringOp ) 
2400            );
2401            BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2402        }
2403    }
2404
2405    return( ExitCode );
2406}
2407
2408BERR_Code BXPT_Mesg_ClearPidChannelBuffer( 
2409    BXPT_Handle hXpt,                   /* [in] Handle for this transport */
2410    unsigned int PidChannelNum,             /* [in] Which PID channel buffer we want. */
2411    unsigned int MesgBufferNum             /* [in] Which Buffer number we want . */
2412        )
2413{
2414    BERR_Code ExitCode = BERR_SUCCESS;
2415
2416    /* Sanity check on the arguments. */
2417    if( PidChannelNum >= hXpt->MaxPidChannels )
2418    {
2419        /* Bad PID channel number. Complain. */
2420        BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2421        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2422    }
2423        else if ( MesgBufferNum >= BXPT_NUM_MESG_BUFFERS ) {
2424        /* Bad Message Buffer number. Complain. */
2425        BDBG_ERR(( "Message Buffer Number %lu is out of range!", ( unsigned long ) MesgBufferNum ));
2426        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2427        }
2428        else
2429        {
2430                ConfigPid2BufferMap(hXpt, PidChannelNum, MesgBufferNum, false);
2431        }
2432        return ExitCode;
2433}
2434
2435void BXPT_GetDefaultPsiSettings( 
2436    BXPT_PsiMessageSettings *Settings     /*  */
2437    )
2438{
2439    BKNI_Memset( (void *) Settings, 0, sizeof( BXPT_PsiMessageSettings ) );
2440}
2441
2442void BXPT_GetDefaultPidChannelRecordSettings( 
2443    BXPT_PidChannelRecordSettings *Settings     /*  */
2444    )
2445{
2446    BKNI_Memset( (void *) Settings, 0, sizeof( BXPT_PidChannelRecordSettings ) );
2447}
2448
2449
Note: See TracBrowser for help on using the repository browser.