| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2002, 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 | * original file: \SetTop\syslib\pvrlib\venom2\ringpbmgr.h@@Irvine_HDDemo_Devel\20 |
|---|
| 11 | * |
|---|
| 12 | * $brcm_Workfile: bpvrlib_p_ringmgr.h $ |
|---|
| 13 | * $brcm_Revision: Hydra_Software_Devel/5 $ |
|---|
| 14 | * $brcm_Date: 1/21/04 4:43p $ |
|---|
| 15 | * |
|---|
| 16 | * Module Description: |
|---|
| 17 | * |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: /vobs/magnum/syslib/pvrlib/bpvrlib_p_ringmgr.h $ |
|---|
| 21 | * |
|---|
| 22 | * Hydra_Software_Devel/5 1/21/04 4:43p marcusk |
|---|
| 23 | * PR8927: Fixed to work with latest version of XPT porting interface. |
|---|
| 24 | * Validate channel number. |
|---|
| 25 | * |
|---|
| 26 | * Hydra_Software_Devel/4 12/12/03 2:03p dlwin |
|---|
| 27 | * PR 8970: Change naming convention to conform to Magnum |
|---|
| 28 | * |
|---|
| 29 | * Hydra_Software_Devel/3 12/10/03 2:25p marcusk |
|---|
| 30 | * PR8927: Record syslib now compiles. |
|---|
| 31 | * |
|---|
| 32 | * Hydra_Software_Devel/2 12/10/03 11:07a marcusk |
|---|
| 33 | * PR 8927: Initial magnum version (not compiled yet) |
|---|
| 34 | * |
|---|
| 35 | ***************************************************************************/ |
|---|
| 36 | #ifndef __BPVRLIB_P_RINGMGR__ |
|---|
| 37 | #define __BPVRLIB_P_RINGMGR__ |
|---|
| 38 | |
|---|
| 39 | #include "bkni.h" |
|---|
| 40 | |
|---|
| 41 | #ifdef __cplusplus |
|---|
| 42 | extern "C" { |
|---|
| 43 | #endif |
|---|
| 44 | |
|---|
| 45 | typedef void (*BPVRlib_P_RingMgrCb)( uint32_t channel ); |
|---|
| 46 | |
|---|
| 47 | /* |
|---|
| 48 | * This structure is used to track all internal variables in the ring buffer |
|---|
| 49 | * manager |
|---|
| 50 | */ |
|---|
| 51 | typedef struct BPVRlib_P_RingMgr_Impl { |
|---|
| 52 | unsigned channel; /* this is returned by notify callback */ |
|---|
| 53 | uint8_t *p_bfr; /* ring buffer virtual (CPU) address */ |
|---|
| 54 | size_t bufferSize; /* size of ring buffer */ |
|---|
| 55 | uint32_t writeWrapCount; /* number of times the write count has wrapped */ |
|---|
| 56 | size_t writeOffset; /* write offset (end of valid data) */ |
|---|
| 57 | uint32_t hwWriteWrapCount; /* number of times the hwwrite count has wrapped */ |
|---|
| 58 | size_t hwWriteOffset; /* number of bytes loaded into hardware dma (optional use) */ |
|---|
| 59 | uint32_t readWrapCount; /* number of times the read count has wrapped */ |
|---|
| 60 | size_t readOffset; /* read offset (start of valid data) */ |
|---|
| 61 | volatile bool resetInProgress;/* set when the reset function is called until the next add request is called */ |
|---|
| 62 | volatile bool abortInProgress;/* set when the abort function is called until the next reset */ |
|---|
| 63 | BKNI_EventHandle notifyEvent; /* used to wake blocked calls when the read or write pointers are updated */ |
|---|
| 64 | BPVRlib_P_RingMgrCb emptyToNotEmptyCb; /* callback that is called when the buffer goes from empty to not empty */ |
|---|
| 65 | BPVRlib_P_RingMgrCb fullToNotFullCb; /* callback that is called when the buffer goes from full to not full */ |
|---|
| 66 | } BPVRlib_P_RingMgr_Impl, *BPVRlib_P_RingMgr_Handle; |
|---|
| 67 | |
|---|
| 68 | /**************************************************************** |
|---|
| 69 | Summary: |
|---|
| 70 | This function creates a ring buffer manager. It allocates |
|---|
| 71 | any resources required by the ring buffer manager. |
|---|
| 72 | When this call completes the ring buffer manager is |
|---|
| 73 | placed in the "reset" state. |
|---|
| 74 | the playback manager (NULL if error) |
|---|
| 75 | ****************************************************************/ |
|---|
| 76 | BERR_Code BPVRlib_P_RingMgr_Open( |
|---|
| 77 | BPVRlib_P_RingMgr_Handle *rbmgr, /* [out] returns context */ |
|---|
| 78 | uint32_t channel, /* returned as parameter by callback functions */ |
|---|
| 79 | BPVRlib_P_RingMgrCb emptyToNotEmptyCb, /* optional callback function to be called when the ring buffer transitions from empty to not empty */ |
|---|
| 80 | BPVRlib_P_RingMgrCb fullToNotFullCb, /* optional callback function to be called when the ring buffer transitions from full to not full */ |
|---|
| 81 | uint8_t *p_bfr, /* pointer to the buffer that the ring buffer manager should use */ |
|---|
| 82 | size_t bfrSize /* the size of the buffer described by the p_bfr pointer */ |
|---|
| 83 | ); |
|---|
| 84 | |
|---|
| 85 | /**************************************************************** |
|---|
| 86 | Summary: |
|---|
| 87 | This function resets a ring buffer manager. This includes |
|---|
| 88 | reseting any of the buffer offsets and wrap counts. |
|---|
| 89 | It also wakes any blocked call pending by the ring buffer manager. |
|---|
| 90 | After a reset, the rpbmgr_AddDataRequest() function |
|---|
| 91 | must be called to remove the reset condition. |
|---|
| 92 | ****************************************************************/ |
|---|
| 93 | void BPVRlib_P_RingMgr_Reset( |
|---|
| 94 | BPVRlib_P_RingMgr_Handle rbmgr /* handle of ring buffer manager */ |
|---|
| 95 | ); |
|---|
| 96 | |
|---|
| 97 | /**************************************************************** |
|---|
| 98 | Summary: |
|---|
| 99 | This function frees any resources used by a ring buffer |
|---|
| 100 | manager. |
|---|
| 101 | ****************************************************************/ |
|---|
| 102 | void BPVRlib_P_RingMgr_Close( |
|---|
| 103 | BPVRlib_P_RingMgr_Handle rbmgr /* handle of ring buffer manager */ |
|---|
| 104 | ); |
|---|
| 105 | |
|---|
| 106 | /**************************************************************** |
|---|
| 107 | Summary: |
|---|
| 108 | This function requests to add data into the ring buffer manager |
|---|
| 109 | If there is no free space available this function will |
|---|
| 110 | block (if required) until free space becomes available. |
|---|
| 111 | ****************************************************************/ |
|---|
| 112 | BERR_Code BPVRlib_P_RingMgr_AddDataRequest( |
|---|
| 113 | BPVRlib_P_RingMgr_Handle rbmgr, /* handle of ring buffer manager */ |
|---|
| 114 | uint8_t **pp_bfr, /* returns pointer of starting buffer address of free space */ |
|---|
| 115 | size_t *p_count, /* returns size of the free space (in bytes) */ |
|---|
| 116 | bool block, /* false (do not block), true (block until free space is available) */ |
|---|
| 117 | uint32_t timeout /* max num of msec to block */ |
|---|
| 118 | ); |
|---|
| 119 | |
|---|
| 120 | /**************************************************************** |
|---|
| 121 | Summary: |
|---|
| 122 | This function increments the ring buffer write pointer |
|---|
| 123 | It is used in conjuntion with the rpbmgr_AddDataRequest() |
|---|
| 124 | to add data into the ring buffer. |
|---|
| 125 | ****************************************************************/ |
|---|
| 126 | BERR_Code BPVRlib_P_RingMgr_UpdateWritePointer( |
|---|
| 127 | BPVRlib_P_RingMgr_Handle rbmgr, /* handle of ring buffer manager */ |
|---|
| 128 | size_t count /* number of bytes to increment the write pointer */ |
|---|
| 129 | ); |
|---|
| 130 | |
|---|
| 131 | /**************************************************************** |
|---|
| 132 | Summary: |
|---|
| 133 | This function requests to remove valid data from the ring buffer manager |
|---|
| 134 | If there is no valid data available this function will |
|---|
| 135 | block (if required) until valid data becomes available. |
|---|
| 136 | ****************************************************************/ |
|---|
| 137 | BERR_Code BPVRlib_P_RingMgr_RemoveDataRequest( |
|---|
| 138 | BPVRlib_P_RingMgr_Handle rbmgr, /* handle of ring buffer manager */ |
|---|
| 139 | uint8_t **pp_bfr, /* returns pointer of starting buffer address of valid data */ |
|---|
| 140 | size_t *p_count, /* returns size of the valid data (in bytes) */ |
|---|
| 141 | bool block, /* false (do not block), true (block until free space is available) */ |
|---|
| 142 | uint32_t timeout /* max num of msec to block */ |
|---|
| 143 | ); |
|---|
| 144 | |
|---|
| 145 | /**************************************************************** |
|---|
| 146 | Summary: |
|---|
| 147 | This function increments the ring buffer read pointer. |
|---|
| 148 | It is used in conjuntion with the rpbmgr_RemoveDataRequest() |
|---|
| 149 | to remove valid data from the ring buffer. |
|---|
| 150 | ****************************************************************/ |
|---|
| 151 | BERR_Code BPVRlib_P_RingMgr_UpdateReadPointer( |
|---|
| 152 | BPVRlib_P_RingMgr_Handle rbmgr, /* handle of ring buffer manager */ |
|---|
| 153 | size_t count /* number of bytes to increment the read pointer */ |
|---|
| 154 | ); |
|---|
| 155 | |
|---|
| 156 | /**************************************************************** |
|---|
| 157 | Summary: |
|---|
| 158 | This function gets the amount of data that has been |
|---|
| 159 | added into the ring buffer, but not placed in the |
|---|
| 160 | hardware dma engine. |
|---|
| 161 | ****************************************************************/ |
|---|
| 162 | void BPVRlib_P_RingMgr_GetHwWriteDifference( |
|---|
| 163 | BPVRlib_P_RingMgr_Handle rbmgr, /* handle of ring buffer manager */ |
|---|
| 164 | uint8_t **pp_bfr, /* returns pointer of starting buffer address of data that needs to be added into hardware */ |
|---|
| 165 | size_t *p_count /* returns size of the data that needs to be added into hardware */ |
|---|
| 166 | ); |
|---|
| 167 | |
|---|
| 168 | /**************************************************************** |
|---|
| 169 | Summary: |
|---|
| 170 | This function increments the ring buffer hardware write pointer. |
|---|
| 171 | It is used in conjuntion with the rpbmgr_GetHwWriteDifference() |
|---|
| 172 | to track what data from the ring buffer has |
|---|
| 173 | been added into the hardware. |
|---|
| 174 | ****************************************************************/ |
|---|
| 175 | void BPVRlib_P_RingMgr_UpdateHwWriteCount( |
|---|
| 176 | BPVRlib_P_RingMgr_Handle rbmgr, /* handle of ring buffer manager */ |
|---|
| 177 | size_t count /* number of bytes to increment the hw write pointer */ |
|---|
| 178 | ); |
|---|
| 179 | |
|---|
| 180 | /**************************************************************** |
|---|
| 181 | Summary: |
|---|
| 182 | This function returns the number of free bytes available |
|---|
| 183 | in the ring buffer. |
|---|
| 184 | ****************************************************************/ |
|---|
| 185 | void BPVRlib_P_RingMgr_GetNumFreeBytes( |
|---|
| 186 | BPVRlib_P_RingMgr_Handle rbmgr, /* handle of ring buffer manager */ |
|---|
| 187 | size_t *p_numFreeBytes /* returns number of bytes available in ring buffer */ |
|---|
| 188 | ); |
|---|
| 189 | |
|---|
| 190 | /**************************************************************** |
|---|
| 191 | Summary: |
|---|
| 192 | This function wakes any blocked call pending by the ring buffer manager. |
|---|
| 193 | ****************************************************************/ |
|---|
| 194 | void BPVRlib_P_RingMgr_Abort( |
|---|
| 195 | BPVRlib_P_RingMgr_Handle rbmgr /* handle of ring buffer manager */ |
|---|
| 196 | ); |
|---|
| 197 | |
|---|
| 198 | #ifdef __cplusplus |
|---|
| 199 | } |
|---|
| 200 | #endif |
|---|
| 201 | |
|---|
| 202 | #endif /* __PLAYBACKMGR_H__ */ |
|---|