source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/xpt/7552/bxpt_wakeup.h

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

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 15.6 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_wakeup.h $
11 * $brcm_Revision: Hydra_Software_Devel/2 $
12 * $brcm_Date: 9/30/11 4:21p $
13 *
14 * Porting interface code for the data transport wakeup feature.
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/xpt/base2/bxpt_wakeup.h $
19 *
20 * Hydra_Software_Devel/2   9/30/11 4:21p gmullen
21 * SW7425-1183: Removed bitfield usage from structs
22 *
23 * Hydra_Software_Devel/1   9/30/11 3:10p gmullen
24 * SW7425-1183: Merged to Hydra
25 *
26 * Hydra_Software_Devel/SW7425-1183/1   8/26/11 10:08a gmullen
27 * SW7425-1183: Interrupt the power managment unit when a wakeup packet is
28 * seen
29 *
30 **************************************************************************/
31
32/***************************************************************************
33Overview:
34 
35The wakeup module within XPT allows the chip to be brought out of a
36powerdown/standby state when a special "wakeup" transport packet is received
37at the XPT front-end. Two independent interrupts can be triggered when such
38a packet is captured: one interrupt to Power Mangement Unit and another to
39the host MIPS.
40 
41Note that the interrupt to the PMU is a level type, and will stay asserted
42until the MIPS clears it. The interrupt is
43 
44Almost any packet can serve as a "wakeup". The hardware implements a bit-wise
45filter, against which all incoming packets are compared. The filter allows
46for both individual bit-wise matches and for sequences of bits that must
47match. Up to 4 indepedent filters can used simulatenously. A status API
48allows the MIPS to determine which of the filters successfully matched.
49 
50The filter matching is done completely in the XPT_WAKEUP hardware block,
51which allows the rest of XPT to be powered down. This also means that
52it's not necessary to allocate or configure a PID channel or parser.
53 
54The type of wake-up packet to be detected is fully configurable by
55through the PI, according to the following settings:
56-       Packet length - defines the number of bytes to be compared.
57-       Compare byte - 8-bit value to compare against.
58-       Compare mask - 8-bit mask to define which bits to compare.
59-       Compare mask type - 2-bit value to define how to compare a
60    series of bytes.
61
62The compare mask is defined as:
63-       0: bit will be ignored and treated as always matching.
64-       1: bit will be matched against corresponding compare bit value.
65
66The compare mask_type is defined as:
67-       00b ("0"): ignore byte. No byte comparison will be done.
68-       01b ("1"): byte must be matched. Byte comparison will be done
69    against 8-bit mask.
70-       10b ("2") and 11b ("3"):
71-       All bytes within a contiguous series of 2s or 3s must match
72    ("logical AND") in order for a partial match, for that series,
73    to be generated;
74-       Partial results from all independent "2" and "3" series are ORed
75    together. The result is then ANDed with the result from matching
76    all the "1" bytes.
77
78"2" and "3" mean the same thing. Two levels are used to identify
79consecutive independent series of 2s or 3s. Of course, a "0", "1" or
80the end of the packet can also indicate the end of a series of 2s
81or 3s.
82
83Example of byte matching:
84                                        0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2
85Array index:            0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
86
87Array content:      1 1 1 1 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 0 0 1 1
88
89-       Bytes 0, 1, 2, 3, 21, 22 must all match (mask_type == 1 for each
90    byte)
91-       There are 3 series of 2s and 3s. 3 partial results are defined:
92-       Bytes 4, 5, 6, 7, 8 are tested for a match (all must match 0 AND)
93    partial result 1
94-       Bytes 9, 10, 11, 12, 13 are tested for a match partial result 2
95-       Bytes 14, 15, 16, 17, 18 are tested for a match partial result 3
96    IF (partial_result1 == match OR partial_result2 == match OR
97    partial_result3 == match) THEN result (all 2s and 3s) = match
98-       Bytes 19, 20 are ignored.
99-       Final result: result(all 1s) and result(all 2s and 3s)
100 
101Sample Code:
102 
103#include "bstd.h"
104#include "bxpt_priv.h"
105#include "bxpt_wakeup.h"
106#include "bint.h"
107#include "wakeup_tests.h"
108#include "bchp_xpt_wakeup.h"
109#include "bchp_int_id_xpt_wakeup.h"
110#include "bkni.h"
111#include "bkni_multi.h"
112
113#include <stdio.h>
114
115static void PacketFoundHostIsr(
116        void *Parm1,
117        int Parm2
118        )
119{                               
120        BSTD_UNUSED( Parm2 );
121    BKNI_SetEvent( (BKNI_EventHandle) Parm1 );
122}
123
124static unsigned char CapturedPacket[ BXPT_WAKEUP_PACKET_SIZE ];
125
126/ *
127This is the pattern in wakeup_packet.ts (streamer version of ib0.dat)
128Offset Bytes
129------ -----------------------------------------------
1300002f0 47 12 34 15 12 34 03 46 66 4f 31 00 88 77 66 55
131000300 44 33 ff ff ff ff ff ff ff ff ff ff ff ff ff ff
132* /
133static BXPT_Wakeup_PacketFilter Filter[ BXPT_WAKEUP_PACKET_SIZE ] =
134{
135    { 0x47, 0xFF, 1 },      / * The packet header, including PID. * /
136    { 0x12, 0xFF, 1 },
137    { 0x34, 0xFF, 1 },
138    { 0x15, 0xFF, 1 },     
139
140    { 0x12, 0xFF, 2 },
141    { 0x34, 0xFF, 2 },
142    { 0x03, 0xFF, 2 },
143    { 0x46, 0xFF, 2 },
144    { 0x66, 0xFF, 2 },
145
146    { 0x4F, 0xFF, 3 },
147    { 0x31, 0xFF, 3 },
148    { 0x00, 0xFF, 3 },
149
150    { 0x88, 0xFF, 2 },
151    { 0x77, 0xFF, 2 },
152    { 0x66, 0xFF, 2 },
153    { 0x55, 0xFF, 2 },
154    { 0x44, 0xFF, 2 },
155    { 0x33, 0xFF, 2 }
156};
157
158void WakeupTest(
159    BXPT_Handle hXpt
160    )
161{
162    BXPT_Wakeup_Settings Settings;
163    BINT_CallbackHandle hPacketFoundHostIsrCb;
164        BKNI_EventHandle hPacketFoundEvent;     
165    BXPT_Wakeup_Status Status;
166
167        BKNI_CreateEvent( &hPacketFoundEvent );
168
169    / * Host will need a callback to clear the interrupt to the PMU. * /
170    BINT_CreateCallback(
171        &hPacketFoundHostIsrCb,
172        hXpt->hInt,
173        BCHP_INT_ID_PKT_DETECT,
174        PacketFoundHostIsr,
175        ( void * ) hPacketFoundEvent,
176        0 );
177    BINT_EnableCallback( hPacketFoundHostIsrCb );
178     
179    / * Set the filter criterion. Should be done before calling
180    BXPT_Wakeup_SetSettings() * /
181    BXPT_Wakeup_SetPacketFilterBytes( hXpt, 0, Filter );
182
183    / *
184    The interrupt to the PMU is a level type, and will stay asserted until the
185    source in XPT is cleared. This done by a call to BXPT_Wakeup_ClearInterruptToPMU().
186    For that reason, the host interrupt will normally be enabled.
187    * /
188    BXPT_Wakeup_GetDefaults( &Settings );
189    Settings.InputBand = 5;                 / * 97425 SV board uses IB5 * /
190    BXPT_Wakeup_SetSettings( hXpt, &Settings );
191    BXPT_Wakeup_Armed( hXpt, true );
192
193        BKNI_WaitForEvent( hPacketFoundEvent, BKNI_INFINITE );
194
195    BXPT_Wakeup_Armed( hXpt, false );
196    BXPT_Wakeup_GetStatus( hXpt, &Status );
197    printf( "Status: Found %s, Type %u, Count %u\n", Status.Found ? "TRUE" : "FALSE", Status.Type, Status.Count );
198
199    BXPT_Wakeup_ClearInterruptToPMU( hXpt );
200    BXPT_Wakeup_GetCapturedPacket( hXpt, CapturedPacket );
201    printf( "Captured packet: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
202            CapturedPacket[ 0 ], CapturedPacket[ 1 ], CapturedPacket[ 2 ], CapturedPacket[ 3 ],
203            CapturedPacket[ 4 ], CapturedPacket[ 5 ], CapturedPacket[ 6 ], CapturedPacket[ 7 ],
204            CapturedPacket[ 8 ], CapturedPacket[ 9 ], CapturedPacket[ 10 ], CapturedPacket[ 11 ]
205            );
206
207    BINT_DisableCallback( hPacketFoundHostIsrCb );
208    BINT_DestroyCallback( hPacketFoundHostIsrCb );
209        BKNI_DestroyEvent( hPacketFoundEvent );
210}
211 
212***************************************************************************/
213
214#ifndef BXPT_WAKEUP_H__
215#define BXPT_WAKEUP_H__
216
217#include "bxpt.h"
218
219#ifdef __cplusplus
220extern "C" {
221#endif
222
223/***************************************************************************
224Summary:
225Miscellaneous constants used by this module. 
226****************************************************************************/
227#define BXPT_WAKEUP_PACKET_SIZE         (200)   /* Each filter is 200 bytes. */
228#define BXPT_WAKEUP_MAX_PACKET_TYPE     (3)     /* Up to 4 packet types are supported (0 through 3) */
229
230/***************************************************************************
231Summary:
232These settings affect all 4 of the packet filters. The default values given
233are returned by BXPT_Wakeup_GetDefaults()
234****************************************************************************/
235typedef struct 
236{
237    /* Which input band to scan for the wakeup packet. */
238    unsigned InputBand;         /* Defaults to 0. */
239
240    /* The length of the transport packet. */
241    unsigned PacketLength;      /* Defaults to 188. Max is BXPT_WAKEUP_PACKET_SIZE.*/
242
243    /* Wakeip ignores the error input signal and TEI bit */
244    bool ErrorInputIgnore;      /* Defaults to false. */
245}
246BXPT_Wakeup_Settings;
247
248/***************************************************************************
249Summary:
250Returns the default values, as described in the BXPT_Wakeup_Settings comment
251block.
252 
253Returns:
254    void
255****************************************************************************/
256void BXPT_Wakeup_GetDefaults(
257    BXPT_Wakeup_Settings *Settings  /* [out] The defaults */
258    );
259
260/***************************************************************************
261Summary:
262Returns the actual settings currently used by the hardware.
263 
264Returns:
265    void
266****************************************************************************/
267void BXPT_Wakeup_GetSettings(
268        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
269    BXPT_Wakeup_Settings *Settings      /* [out] Current hardware values */
270    );
271
272/***************************************************************************
273Summary:
274Write the given settings out to the hardware.
275 
276Returns:
277    BERR_SUCCESS                - New settings are being used.
278    BERR_INVALID_PARAMETER      - One of the Settings values is invalid.
279****************************************************************************/
280BERR_Code BXPT_Wakeup_SetSettings(
281        BXPT_Handle hXpt,                           /* [in] Handle for this transport */
282    const BXPT_Wakeup_Settings *Settings
283    );
284
285/***************************************************************************
286Summary:
287Status of the wakeup block. Note that the Type field should be ignored if
288Found is false. Found will be reset to false when the wakeup block is
289re-armed.
290 
291Note that calling BXPT_Wakeup_ClearInterruptToPMU() will also clear Found. 
292****************************************************************************/
293typedef struct 
294{
295    bool Found;         /* true if a wakeup packet was received. */
296    unsigned Type;      /* Which packet type filter matched */
297    unsigned Count;     /* How many packets that have been scanned. */
298}
299BXPT_Wakeup_Status;
300
301/***************************************************************************
302Summary:
303Return the current status values from hardware. 
304 
305Returns:
306    void
307****************************************************************************/
308void BXPT_Wakeup_GetStatus(
309        BXPT_Handle hXpt,                           /* [in] Handle for this transport */
310    BXPT_Wakeup_Status *Status
311    );
312
313/***************************************************************************
314Summary:
315Clear the wakeup interrupt to the Power Management Unit. This interrupt is
316set when an incoming packet matches one of the filters. The interrupt remains
317asserted until this API is called. 
318 
319Note that calling BXPT_Wakeup_ClearInterruptToPMU() will also clear the
320Found bool in the status register and BXPT_Wakeup_GetStatus() structure.
321 
322Returns:
323    void
324****************************************************************************/
325void BXPT_Wakeup_ClearInterruptToPMU(
326        BXPT_Handle hXpt                            /* [in] Handle for this transport */
327    );
328
329/***************************************************************************
330Summary:
331This struct defines the packet filtering config for a single byte of a
332transport packet. The full filter is an array of (up to) BXPT_WAKEUP_PACKET_SIZE
333of these structs. See the discussion and example in the module Overview
334(above) for more information on how to use create a filter config. 
335****************************************************************************/
336typedef struct 
337{
338    /* Bit pattern to compare the incoming packet against.  */
339    unsigned CompareByte;
340
341    /*
342    Defines which bits in the CompareByte are used in the wakeup packet detection.
343    0 = Corresponding bit will be ignored and treated as always matching.
344    1 = Corresponding bit will be matched against compare bit value. 
345    */
346    unsigned Mask;
347
348    /*
349    Mask type defines how a series of bytes are matched.
350    0 = Ignore byte. No byte comparison will be done.
351    1 = All bytes with mask-type of 1 must match, whether they are contiguous or not.                                                                      .
352        Byte comparison will be done against 8-bit mask.
353    2 = All bytes with mask-type of 2 must match, but only within a contiguous series of 2's,                                                             .
354        in order for a partial match for that series to be generated.
355    3 = All bytes with mask-type of 3 must match, but only within a contiguous series of 3's,                                                             .
356        in order for a partial match for that series to be generated.
357    */ 
358    unsigned MaskType;   
359}
360BXPT_Wakeup_PacketFilter;
361
362/***************************************************************************
363Summary:
364Copy the current filter config to user memory. The caller must allocate the
365memory into which the config will be copied. For example,
366 
367BXPT_Wakeup_PacketFilter Filter[ BXPT_WAKEUP_PACKET_SIZE ];
368 
369Returns:
370    BERR_SUCCESS                - Filter config copied to user memory.
371    BERR_INVALID_PARAMETER      - WhichPacketType is out-of-range.
372****************************************************************************/
373BERR_Code BXPT_Wakeup_GetPacketFilterBytes(
374        BXPT_Handle hXpt,                           /* [in] Handle for this transport */
375    unsigned WhichPacketType,
376    BXPT_Wakeup_PacketFilter *Filter
377    );
378
379/***************************************************************************
380Summary:
381Load the given filter config into hardware. The change will take effect
382immediately.
383 
384Returns:
385    BERR_SUCCESS                - New filter config is being used.
386    BERR_INVALID_PARAMETER      - WhichPacketType is out-of-range.
387****************************************************************************/
388BERR_Code BXPT_Wakeup_SetPacketFilterBytes(
389        BXPT_Handle hXpt,                           /* [in] Handle for this transport */
390    unsigned WhichPacketType,
391    const BXPT_Wakeup_PacketFilter *Filter
392    );
393
394/***************************************************************************
395Summary:
396Copy out the packet that matched the wakeup filter. The caller must allocate
397memory to receive the packet. For example,
398 
399unsigned char CapturedPacket[ BXPT_WAKEUP_PACKET_SIZE ];
400 
401Returns:
402    void
403****************************************************************************/
404void BXPT_Wakeup_GetCapturedPacket(
405        BXPT_Handle hXpt,                           /* [in] Handle for this transport */
406    unsigned char *PacketBuffer
407    );
408
409/***************************************************************************
410Summary:
411Arm/disarm the wakeup block. When armed, the block will begin scanning the
412input band data. When disarmed, no interrupts to the PMU or MIPS will be
413generated if wakeup packets are seen in the input.
414 
415Returns:
416    void
417****************************************************************************/
418void BXPT_Wakeup_Armed(
419        BXPT_Handle hXpt,           /* [in] Handle for this transport */
420    bool Armed              /* [in] true if wakeup should be enabled, false otherwise. */
421    );
422
423#ifdef __cplusplus
424}
425#endif
426
427#endif /* #ifndef BXPT_WAKEUP_H__ */
428
429/* end of file */
Note: See TracBrowser for help on using the repository browser.