| 1 | /*************************************************************************** |
|---|
| 2 | * (c)2007-2011 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: nexus_message.c $ |
|---|
| 39 | * $brcm_Revision: 32 $ |
|---|
| 40 | * $brcm_Date: 12/15/11 2:32p $ |
|---|
| 41 | * |
|---|
| 42 | * Module Description: |
|---|
| 43 | * |
|---|
| 44 | * Revision History: |
|---|
| 45 | * |
|---|
| 46 | * $brcm_Log: /nexus/modules/transport/7400/src/nexus_message.c $ |
|---|
| 47 | * |
|---|
| 48 | * 32 12/15/11 2:32p gmullen |
|---|
| 49 | * SW7425-1952: Merged changes to mainline |
|---|
| 50 | * |
|---|
| 51 | * SW7425-1952/1 12/14/11 4:08p gmullen |
|---|
| 52 | * SW7425-1952: Moved NEXUS_Message structure to nexus_transport_module.h |
|---|
| 53 | * |
|---|
| 54 | * 31 2/10/11 11:02a erickson |
|---|
| 55 | * SW7420-1120: refactor NEXUS_PidChannel_Open so it returns separate |
|---|
| 56 | * handles even if underlying HW pid channel is shared |
|---|
| 57 | * |
|---|
| 58 | * 30 9/8/10 4:41p erickson |
|---|
| 59 | * SW3548-3073: moved definition of struct NEXUS_Message into each |
|---|
| 60 | * implementation |
|---|
| 61 | * |
|---|
| 62 | * 29 9/3/10 11:56a erickson |
|---|
| 63 | * SW35230-1172: add NEXUS_Message_GetBufferWithWrap |
|---|
| 64 | * |
|---|
| 65 | * 28 4/19/10 2:52p erickson |
|---|
| 66 | * SW7420-624: add NEXUS_Message_UpdateFilter |
|---|
| 67 | * |
|---|
| 68 | * 27 4/19/10 2:02p erickson |
|---|
| 69 | * SW7420-624: add NEXUS_Message_GetDefaultFilter and |
|---|
| 70 | * AddFilter/RemoveFilter stubs |
|---|
| 71 | * |
|---|
| 72 | * 26 3/8/10 1:03p erickson |
|---|
| 73 | * SW7405-4008: null pidChannel setting on Stop. it may no longer be |
|---|
| 74 | * valid. |
|---|
| 75 | * |
|---|
| 76 | * 25 2/26/10 2:15p erickson |
|---|
| 77 | * SW7325-655: refactor NEXUS_Core_P_AddressToHeap |
|---|
| 78 | * |
|---|
| 79 | * 24 11/12/09 4:44p jhaberf |
|---|
| 80 | * SW35230-1: Put #ifdef's around DSS functions so the drivers for chips |
|---|
| 81 | * which don't support DSS build. |
|---|
| 82 | * |
|---|
| 83 | * 23 11/6/09 1:57p erickson |
|---|
| 84 | * SW7400-2559: added NEXUS_Message_SetDssCapPattern |
|---|
| 85 | * |
|---|
| 86 | * 22 10/15/09 1:53p erickson |
|---|
| 87 | * SWDEPRECATED-3717: allow NEXUS_Message_GetDefaultStartSettings to be |
|---|
| 88 | * called without a NEXUS_MessageHandle |
|---|
| 89 | * |
|---|
| 90 | * 21 8/19/09 2:53p erickson |
|---|
| 91 | * PR57800: turn off transport message interrupts before destroying |
|---|
| 92 | * NEXUS_IsrCallbacks. |
|---|
| 93 | * |
|---|
| 94 | * 20 6/11/09 4:23p erickson |
|---|
| 95 | * PR55511: XPT will automatically enable a pid channel used for message |
|---|
| 96 | * filtering. Nexus status should reflect this. |
|---|
| 97 | * |
|---|
| 98 | * 19 3/24/09 10:01a erickson |
|---|
| 99 | * PR53516: added NEXUS_Message_GetStatus |
|---|
| 100 | * |
|---|
| 101 | * 18 11/20/08 5:01p erickson |
|---|
| 102 | * PR48848: asserts |
|---|
| 103 | * |
|---|
| 104 | * 17 11/11/08 2:55a erickson |
|---|
| 105 | * PR 48847: added NEXUS_Message_SetSettings |
|---|
| 106 | * |
|---|
| 107 | * 16 9/11/08 3:13p erickson |
|---|
| 108 | * PR46646: added crcError, pesLengthError, pesStartCodeError |
|---|
| 109 | * |
|---|
| 110 | * 14 8/14/08 5:25p katrep |
|---|
| 111 | * PR45674: Fix compiiler warning in kernel mode non debug builds |
|---|
| 112 | * |
|---|
| 113 | * 13 5/14/08 12:30p erickson |
|---|
| 114 | * PR41730: translate the cached address to an uncached adderss before |
|---|
| 115 | * handing to MSGlib |
|---|
| 116 | * |
|---|
| 117 | * 12 5/9/08 1:29p erickson |
|---|
| 118 | * PR42456: added NEXUS_MessageFormat_ePesSaveAll. clarified that |
|---|
| 119 | * maxContiguousMessageSize only applies for PSI messages. |
|---|
| 120 | * |
|---|
| 121 | * 11 4/14/08 1:17p erickson |
|---|
| 122 | * PR41730: move user buffer override from Open time to Start time to give |
|---|
| 123 | * maximum flexibility |
|---|
| 124 | * |
|---|
| 125 | * 10 4/11/08 9:53a erickson |
|---|
| 126 | * PR41246: convert BDBG_OBJECT_UNSET to BDBG_OBJECT_DESTROY if freeing |
|---|
| 127 | * memory |
|---|
| 128 | * |
|---|
| 129 | * 9 3/24/08 10:19a erickson |
|---|
| 130 | * PR40813: added bank param |
|---|
| 131 | * |
|---|
| 132 | * 8 3/10/08 11:32a erickson |
|---|
| 133 | * PR39836: set up Nexus callbacks before calling BMSGlib_OpenSession |
|---|
| 134 | * |
|---|
| 135 | * 7 3/4/08 3:31p erickson |
|---|
| 136 | * PR40080: add transport error callbacks |
|---|
| 137 | * |
|---|
| 138 | * 6 2/28/08 10:42p vsilyaev |
|---|
| 139 | * PR 40103: Added interfaceHandle and settings for the |
|---|
| 140 | * NEXUS_IsrCallbackCreate |
|---|
| 141 | * |
|---|
| 142 | * 5 2/26/08 10:30p erickson |
|---|
| 143 | * PR39781: allow maxContiguousMessageSize == 0 for no data copy on wrap |
|---|
| 144 | * around |
|---|
| 145 | * |
|---|
| 146 | * 4 2/26/08 9:54p erickson |
|---|
| 147 | * PR39836: added asserts |
|---|
| 148 | * |
|---|
| 149 | * 3 2/19/08 2:57p erickson |
|---|
| 150 | * PR39735: assert malloc |
|---|
| 151 | * |
|---|
| 152 | * 2 1/31/08 12:55p erickson |
|---|
| 153 | * PR34925: clarify comments, remove unsupported enums |
|---|
| 154 | * |
|---|
| 155 | * 1 1/18/08 2:20p jgarrett |
|---|
| 156 | * PR 38808: Merging to main branch |
|---|
| 157 | * |
|---|
| 158 | * Nexus_Devel/10 11/6/07 3:43p erickson |
|---|
| 159 | * PR34925: added BDBG_OBJECT checking |
|---|
| 160 | * |
|---|
| 161 | * Nexus_Devel/9 11/2/07 10:04a erickson |
|---|
| 162 | * PR36633: fix coding convention |
|---|
| 163 | * |
|---|
| 164 | * Nexus_Devel/8 10/17/07 11:06a erickson |
|---|
| 165 | * PR36068: close MSGlib before the IsrCallbacks |
|---|
| 166 | * |
|---|
| 167 | * Nexus_Devel/7 10/9/07 3:49p erickson |
|---|
| 168 | * PR34925: change Params to StartSettings |
|---|
| 169 | * |
|---|
| 170 | * Nexus_Devel/6 10/4/07 12:54p erickson |
|---|
| 171 | * PR34925: use standard NEXUS_Error values |
|---|
| 172 | * |
|---|
| 173 | * Nexus_Devel/5 10/3/07 1:41p erickson |
|---|
| 174 | * PR34925: converted to more efficient NEXUS_IsrCallback_Fire_isr |
|---|
| 175 | * |
|---|
| 176 | * Nexus_Devel/4 9/25/07 3:07p erickson |
|---|
| 177 | * PR34925: update |
|---|
| 178 | * |
|---|
| 179 | * Nexus_Devel/3 9/25/07 2:01p erickson |
|---|
| 180 | * PR34925: convert to task before QueueCallback |
|---|
| 181 | * |
|---|
| 182 | * Nexus_Devel/2 9/25/07 1:46p erickson |
|---|
| 183 | * PR34925: fix warnings |
|---|
| 184 | * |
|---|
| 185 | * Nexus_Devel/1 9/24/07 2:36p erickson |
|---|
| 186 | * PR34925: added Message |
|---|
| 187 | * |
|---|
| 188 | **************************************************************************/ |
|---|
| 189 | #include "nexus_transport_module.h" |
|---|
| 190 | |
|---|
| 191 | BDBG_MODULE(nexus_message); |
|---|
| 192 | |
|---|
| 193 | BDBG_OBJECT_ID(NEXUS_Message); |
|---|
| 194 | |
|---|
| 195 | #if 0 |
|---|
| 196 | /* Moved to nexus_transport_module.h */ |
|---|
| 197 | /* this is the impl of NEXUS_MessageHandle */ |
|---|
| 198 | struct NEXUS_Message { |
|---|
| 199 | BDBG_OBJECT(NEXUS_Message) |
|---|
| 200 | NEXUS_MessageSettings settings; |
|---|
| 201 | NEXUS_MessageStartSettings startSettings; |
|---|
| 202 | NEXUS_MessageStatus status; |
|---|
| 203 | BMSGlib_Session_Handle session; |
|---|
| 204 | bool started; |
|---|
| 205 | unsigned noReadCompleteCount; |
|---|
| 206 | NEXUS_TimerHandle checkTimer; |
|---|
| 207 | NEXUS_IsrCallbackHandle dataReady, overflow, psiLengthError, crcError, pesLengthError, pesStartCodeError; |
|---|
| 208 | |
|---|
| 209 | }; |
|---|
| 210 | #endif |
|---|
| 211 | |
|---|
| 212 | void NEXUS_Message_GetDefaultSettings(NEXUS_MessageSettings *pSettings) |
|---|
| 213 | { |
|---|
| 214 | BKNI_Memset(pSettings, 0, sizeof(*pSettings)); |
|---|
| 215 | pSettings->bufferSize = 4 * 1024; |
|---|
| 216 | pSettings->maxContiguousMessageSize = 4 * 1024; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | static void NEXUS_message_p_dataready_callback_isr(void *data) |
|---|
| 220 | { |
|---|
| 221 | NEXUS_MessageHandle msg = (NEXUS_MessageHandle)data; |
|---|
| 222 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 223 | NEXUS_IsrCallback_Fire_isr(msg->dataReady); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | static void NEXUS_message_p_overflow_callback_isr(void *data) |
|---|
| 227 | { |
|---|
| 228 | NEXUS_MessageHandle msg = (NEXUS_MessageHandle)data; |
|---|
| 229 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 230 | NEXUS_IsrCallback_Fire_isr(msg->overflow); |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | NEXUS_MessageHandle NEXUS_Message_Open(const NEXUS_MessageSettings *pSettings) |
|---|
| 234 | { |
|---|
| 235 | BMSGlib_SessionSettings sessionSettings; |
|---|
| 236 | BERR_Code rc; |
|---|
| 237 | NEXUS_MessageSettings settings; |
|---|
| 238 | NEXUS_MessageHandle msg; |
|---|
| 239 | unsigned i; |
|---|
| 240 | |
|---|
| 241 | if (!pSettings) { |
|---|
| 242 | NEXUS_Message_GetDefaultSettings(&settings); |
|---|
| 243 | pSettings = &settings; |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | msg = BKNI_Malloc(sizeof(*msg)); |
|---|
| 247 | if(!msg) { rc = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);return NULL; } |
|---|
| 248 | |
|---|
| 249 | BKNI_Memset(msg, 0, sizeof(*msg)); |
|---|
| 250 | BDBG_OBJECT_SET(msg, NEXUS_Message); |
|---|
| 251 | msg->settings = *pSettings; |
|---|
| 252 | |
|---|
| 253 | /* must keep track of Message handles in order to route interrupts back out to Message handles */ |
|---|
| 254 | for (i=0;i<NEXUS_TRANSPORT_MAX_MESSAGE_HANDLES;i++) { |
|---|
| 255 | if (!pTransport->message.handle[i]) { |
|---|
| 256 | pTransport->message.handle[i] = msg; |
|---|
| 257 | break; |
|---|
| 258 | } |
|---|
| 259 | } |
|---|
| 260 | if (i == NEXUS_TRANSPORT_MAX_MESSAGE_HANDLES) { |
|---|
| 261 | BDBG_ERR(("You must increase NEXUS_TRANSPORT_MAX_MESSAGE_HANDLES")); |
|---|
| 262 | goto error; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | msg->dataReady = NEXUS_IsrCallback_Create(msg, NULL); |
|---|
| 266 | if(!msg->dataReady) { rc = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);goto error;} |
|---|
| 267 | |
|---|
| 268 | msg->overflow = NEXUS_IsrCallback_Create(msg, NULL); |
|---|
| 269 | if(!msg->overflow) { rc = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);goto error;} |
|---|
| 270 | |
|---|
| 271 | msg->psiLengthError = NEXUS_IsrCallback_Create(msg, NULL); |
|---|
| 272 | if(!msg->psiLengthError) { rc = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);goto error;} |
|---|
| 273 | |
|---|
| 274 | msg->crcError = NEXUS_IsrCallback_Create(msg, NULL); |
|---|
| 275 | if(!msg->crcError) { rc = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);goto error;} |
|---|
| 276 | |
|---|
| 277 | msg->pesLengthError = NEXUS_IsrCallback_Create(msg, NULL); |
|---|
| 278 | if(!msg->pesLengthError) { rc = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);goto error;} |
|---|
| 279 | |
|---|
| 280 | msg->pesStartCodeError = NEXUS_IsrCallback_Create(msg, NULL); |
|---|
| 281 | if(!msg->pesStartCodeError) { rc = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);goto error;} |
|---|
| 282 | |
|---|
| 283 | /* set the interrupts */ |
|---|
| 284 | (void)NEXUS_Message_SetSettings(msg, pSettings); |
|---|
| 285 | |
|---|
| 286 | /* open MSGlib after setting up Nexus callbacks */ |
|---|
| 287 | BMSGlib_GetDefaultSessionSettings(pTransport->msglib, &sessionSettings); |
|---|
| 288 | sessionSettings.bufferSize = pSettings->bufferSize; |
|---|
| 289 | sessionSettings.maxContiguousMessageSize = pSettings->maxContiguousMessageSize; |
|---|
| 290 | sessionSettings.callbackContext = msg; |
|---|
| 291 | sessionSettings.dataReadyCallback_isr = NEXUS_message_p_dataready_callback_isr; |
|---|
| 292 | sessionSettings.overflowCallback_isr = pSettings->overflow.callback ? NEXUS_message_p_overflow_callback_isr : NULL; |
|---|
| 293 | rc = BMSGlib_OpenSession(pTransport->msglib, &msg->session, &sessionSettings); |
|---|
| 294 | if (rc!=BERR_SUCCESS) {rc=BERR_TRACE(rc); goto error;} |
|---|
| 295 | |
|---|
| 296 | return msg; |
|---|
| 297 | |
|---|
| 298 | error: |
|---|
| 299 | NEXUS_Message_Close(msg); |
|---|
| 300 | return NULL; |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | void NEXUS_Message_Close(NEXUS_MessageHandle msg) |
|---|
| 304 | { |
|---|
| 305 | unsigned i; |
|---|
| 306 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 307 | |
|---|
| 308 | /* Must close MSGlib before the IsrCallbacks */ |
|---|
| 309 | if (msg->session) { |
|---|
| 310 | BMSGlib_CloseSession(msg->session); |
|---|
| 311 | } |
|---|
| 312 | /* Guaranteed no callbacks now */ |
|---|
| 313 | |
|---|
| 314 | BKNI_EnterCriticalSection(); |
|---|
| 315 | for (i=0;i<NEXUS_TRANSPORT_MAX_MESSAGE_HANDLES;i++) { |
|---|
| 316 | if (pTransport->message.handle[i] == msg) { |
|---|
| 317 | pTransport->message.handle[i] = NULL; |
|---|
| 318 | break; |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | BDBG_ASSERT(i < NEXUS_TRANSPORT_MAX_MESSAGE_HANDLES); |
|---|
| 322 | BKNI_LeaveCriticalSection(); |
|---|
| 323 | /* call this after message.handle[] is cleared */ |
|---|
| 324 | NEXUS_Transport_P_SetInterrupts(); |
|---|
| 325 | |
|---|
| 326 | if (msg->dataReady) { |
|---|
| 327 | NEXUS_IsrCallback_Destroy(msg->dataReady); |
|---|
| 328 | } |
|---|
| 329 | if (msg->overflow) { |
|---|
| 330 | NEXUS_IsrCallback_Destroy(msg->overflow); |
|---|
| 331 | } |
|---|
| 332 | if (msg->psiLengthError) { |
|---|
| 333 | NEXUS_IsrCallback_Destroy(msg->psiLengthError); |
|---|
| 334 | } |
|---|
| 335 | if (msg->crcError) { |
|---|
| 336 | NEXUS_IsrCallback_Destroy(msg->crcError); |
|---|
| 337 | } |
|---|
| 338 | if (msg->pesLengthError) { |
|---|
| 339 | NEXUS_IsrCallback_Destroy(msg->pesLengthError); |
|---|
| 340 | } |
|---|
| 341 | if (msg->pesStartCodeError) { |
|---|
| 342 | NEXUS_IsrCallback_Destroy(msg->pesStartCodeError); |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | BDBG_OBJECT_DESTROY(msg, NEXUS_Message); |
|---|
| 346 | BKNI_Free(msg); |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | void NEXUS_Message_GetSettings( NEXUS_MessageHandle msg, NEXUS_MessageSettings *pSettings ) |
|---|
| 350 | { |
|---|
| 351 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 352 | *pSettings = msg->settings; |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | NEXUS_Error NEXUS_Message_SetSettings( NEXUS_MessageHandle msg, const NEXUS_MessageSettings *pSettings ) |
|---|
| 356 | { |
|---|
| 357 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 358 | |
|---|
| 359 | NEXUS_IsrCallback_Set(msg->dataReady, &pSettings->dataReady); |
|---|
| 360 | NEXUS_IsrCallback_Set(msg->overflow, &pSettings->overflow); |
|---|
| 361 | NEXUS_IsrCallback_Set(msg->psiLengthError, &pSettings->psiLengthError); |
|---|
| 362 | NEXUS_IsrCallback_Set(msg->crcError, &pSettings->crcError); |
|---|
| 363 | NEXUS_IsrCallback_Set(msg->pesLengthError, &pSettings->pesLengthError); |
|---|
| 364 | NEXUS_IsrCallback_Set(msg->pesStartCodeError, &pSettings->pesStartCodeError); |
|---|
| 365 | NEXUS_Transport_P_SetInterrupts(); |
|---|
| 366 | |
|---|
| 367 | msg->settings = *pSettings; |
|---|
| 368 | |
|---|
| 369 | return 0; |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | |
|---|
| 373 | void NEXUS_Message_GetDefaultStartSettings(NEXUS_MessageHandle msg, NEXUS_MessageStartSettings *pStartSettings) |
|---|
| 374 | { |
|---|
| 375 | /* allow NULL msg handle to retrieve defaults w/o a handle */ |
|---|
| 376 | BSTD_UNUSED(msg); |
|---|
| 377 | |
|---|
| 378 | BKNI_Memset(pStartSettings, 0, sizeof(*pStartSettings)); |
|---|
| 379 | pStartSettings->format = NEXUS_MessageFormat_ePsi; |
|---|
| 380 | pStartSettings->bufferMode = NEXUS_MessageBufferMode_eContinuous; |
|---|
| 381 | pStartSettings->bank = -1; |
|---|
| 382 | NEXUS_Message_GetDefaultFilter(&pStartSettings->filter); |
|---|
| 383 | #if NEXUS_NUM_RAVE_CONTEXTS |
|---|
| 384 | pStartSettings->filterGroup = true; |
|---|
| 385 | #endif |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | NEXUS_Error NEXUS_Message_Start(NEXUS_MessageHandle msg, const NEXUS_MessageStartSettings *pStartSettings) |
|---|
| 389 | { |
|---|
| 390 | BERR_Code rc; |
|---|
| 391 | BMSGlib_SessionParams sessionParams; |
|---|
| 392 | |
|---|
| 393 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 394 | if (msg->started) { |
|---|
| 395 | BDBG_ERR(("already started")); |
|---|
| 396 | return NEXUS_NOT_SUPPORTED; |
|---|
| 397 | } |
|---|
| 398 | if (!pStartSettings || !pStartSettings->pidChannel) { |
|---|
| 399 | BDBG_ERR(("pidChannel required")); |
|---|
| 400 | return NEXUS_INVALID_PARAMETER; |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | msg->startSettings = *pStartSettings; |
|---|
| 404 | |
|---|
| 405 | BMSGlib_GetDefaultSessionParams(msg->session, &sessionParams); |
|---|
| 406 | switch (pStartSettings->format) { |
|---|
| 407 | case NEXUS_MessageFormat_eTs: sessionParams.format = BMSGlib_Format_eTS; break; |
|---|
| 408 | case NEXUS_MessageFormat_ePes: sessionParams.format = BMSGlib_Format_ePES; break; |
|---|
| 409 | case NEXUS_MessageFormat_ePesSaveAll: sessionParams.format = BMSGlib_Format_ePES_SAVE_ALL; break; |
|---|
| 410 | case NEXUS_MessageFormat_ePsi: sessionParams.format = BMSGlib_Format_ePSI; break; |
|---|
| 411 | default: BDBG_ERR(("invalid format")); return NEXUS_INVALID_PARAMETER; |
|---|
| 412 | } |
|---|
| 413 | sessionParams.PidChannel = pStartSettings->pidChannel->status.pidChannelIndex; |
|---|
| 414 | sessionParams.filterGroup = pStartSettings->filterGroup; |
|---|
| 415 | sessionParams.bank = pStartSettings->bank; |
|---|
| 416 | sessionParams.psiCrcDisabled = pStartSettings->psiCrcDisabled; |
|---|
| 417 | sessionParams.psfCrcDisabled = pStartSettings->psfCrcDisabled; |
|---|
| 418 | if (pStartSettings->buffer) { |
|---|
| 419 | if (!NEXUS_Core_P_AddressToHeap(pStartSettings->buffer, &sessionParams.buffer)) { |
|---|
| 420 | BDBG_ERR(("A user-provided buffer must be allocated with NEXUS_Memory_Allocate in order to be properly translated for HW use.")); |
|---|
| 421 | return BERR_TRACE(NEXUS_INVALID_PARAMETER); |
|---|
| 422 | } |
|---|
| 423 | BDBG_ASSERT(sessionParams.buffer); |
|---|
| 424 | } |
|---|
| 425 | sessionParams.bufferSize = pStartSettings->bufferSize; |
|---|
| 426 | BDBG_CASSERT(sizeof(sessionParams.filter) == sizeof(pStartSettings->filter)); |
|---|
| 427 | BKNI_Memcpy(&sessionParams.filter, &pStartSettings->filter, sizeof(sessionParams.filter)); |
|---|
| 428 | |
|---|
| 429 | /* NOTE: XPT PI will automatically enable the pid channel inside BXPT_StartPsiMessageCapture or BXPT_StartPidChannelRecord. */ |
|---|
| 430 | pStartSettings->pidChannel->status.enabled = true; |
|---|
| 431 | |
|---|
| 432 | rc = BMSGlib_StartSession(msg->session, &sessionParams); |
|---|
| 433 | if (rc) {return BERR_TRACE(rc);} |
|---|
| 434 | |
|---|
| 435 | NEXUS_PidChannel_ConsumerStarted(pStartSettings->pidChannel); |
|---|
| 436 | |
|---|
| 437 | msg->started = true; |
|---|
| 438 | return 0; |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | void NEXUS_Message_Stop(NEXUS_MessageHandle msg) |
|---|
| 442 | { |
|---|
| 443 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 444 | if (!msg->started) { |
|---|
| 445 | return; |
|---|
| 446 | } |
|---|
| 447 | BMSGlib_StopSession(msg->session); |
|---|
| 448 | msg->startSettings.pidChannel = NULL; /* let go of this handle. it could be closed after Stop returns. */ |
|---|
| 449 | msg->started = false; |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | NEXUS_Error NEXUS_Message_GetBuffer(NEXUS_MessageHandle msg, const void **buffer, size_t *length) |
|---|
| 453 | { |
|---|
| 454 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 455 | return BMSGlib_GetBuffer(msg->session, buffer, length); |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | NEXUS_Error NEXUS_Message_GetBufferWithWrap( NEXUS_MessageHandle msg, const void **pBuffer, size_t *pLength, const void **pBuffer2, size_t *pLength2 ) |
|---|
| 459 | { |
|---|
| 460 | /* not supported, but we can help app compatibility by just mapping to NEXUS_Message_GetBuffer */ |
|---|
| 461 | *pBuffer2 = NULL; |
|---|
| 462 | *pLength2 = 0; |
|---|
| 463 | return NEXUS_Message_GetBuffer(msg, pBuffer, pLength); |
|---|
| 464 | } |
|---|
| 465 | |
|---|
| 466 | NEXUS_Error NEXUS_Message_ReadComplete(NEXUS_MessageHandle msg, size_t amount_consumed) |
|---|
| 467 | { |
|---|
| 468 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 469 | return BMSGlib_ReadComplete(msg->session, amount_consumed); |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | NEXUS_Error NEXUS_Message_GetStatus( NEXUS_MessageHandle msg, NEXUS_MessageStatus *pStatus ) |
|---|
| 473 | { |
|---|
| 474 | BMSGlib_Status status; |
|---|
| 475 | BERR_Code rc; |
|---|
| 476 | |
|---|
| 477 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 478 | |
|---|
| 479 | rc = BMSGlib_GetStatus(msg->session, &status); |
|---|
| 480 | if (rc) return BERR_TRACE(rc); |
|---|
| 481 | |
|---|
| 482 | pStatus->groupMembers = status.groupMembers; |
|---|
| 483 | pStatus->isGroupMaster = status.isGroupMaster; |
|---|
| 484 | |
|---|
| 485 | return 0; |
|---|
| 486 | } |
|---|
| 487 | |
|---|
| 488 | NEXUS_Error NEXUS_Message_SetDssCapPattern( unsigned capFilterIndex, uint32_t pattern) |
|---|
| 489 | { |
|---|
| 490 | #if B_HAS_DSS |
|---|
| 491 | return BXPT_DirecTv_SetCapPattern(pTransport->xpt, capFilterIndex, pattern); |
|---|
| 492 | #else |
|---|
| 493 | return BERR_SUCCESS; |
|---|
| 494 | #endif |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | void NEXUS_Message_GetDefaultFilter(NEXUS_MessageFilter *pFilter) |
|---|
| 498 | { |
|---|
| 499 | BKNI_Memset(pFilter, 0, sizeof(*pFilter)); |
|---|
| 500 | BKNI_Memset(pFilter->mask, 0xFF, sizeof(pFilter->mask)); |
|---|
| 501 | BKNI_Memset(pFilter->exclusion, 0xFF, sizeof(pFilter->exclusion)); |
|---|
| 502 | } |
|---|
| 503 | |
|---|
| 504 | NEXUS_Error NEXUS_Message_AddFilter( NEXUS_MessageHandle msg, const NEXUS_MessageFilter *pFilter, unsigned *pFilterNum ) |
|---|
| 505 | { |
|---|
| 506 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 507 | BSTD_UNUSED(pFilter); |
|---|
| 508 | BSTD_UNUSED(pFilterNum); |
|---|
| 509 | return BERR_TRACE(NEXUS_NOT_SUPPORTED); |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | NEXUS_Error NEXUS_Message_RemoveFilter( NEXUS_MessageHandle msg, unsigned filterNum ) |
|---|
| 513 | { |
|---|
| 514 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 515 | BSTD_UNUSED(filterNum); |
|---|
| 516 | return BERR_TRACE(NEXUS_NOT_SUPPORTED); |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | NEXUS_Error NEXUS_Message_UpdateFilter( NEXUS_MessageHandle msg, unsigned filterNum, const NEXUS_MessageFilter *pFilter ) |
|---|
| 520 | { |
|---|
| 521 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 522 | BSTD_UNUSED(filterNum); |
|---|
| 523 | BSTD_UNUSED(pFilter); |
|---|
| 524 | return BERR_TRACE(NEXUS_NOT_SUPPORTED); |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | void NEXUS_Message_P_FireInterrupt_isr(NEXUS_MessageHandle msg, unsigned pidChannelIndex, NEXUS_XptDataInterrupt xptDataInterrupt) |
|---|
| 528 | { |
|---|
| 529 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 530 | |
|---|
| 531 | if (msg->startSettings.pidChannel->status.pidChannelIndex == pidChannelIndex) { |
|---|
| 532 | switch (xptDataInterrupt) { |
|---|
| 533 | case NEXUS_XptDataInterrupt_ePsiLengthError: |
|---|
| 534 | NEXUS_IsrCallback_Fire_isr(msg->psiLengthError); |
|---|
| 535 | break; |
|---|
| 536 | case NEXUS_XptDataInterrupt_eCrcError: |
|---|
| 537 | NEXUS_IsrCallback_Fire_isr(msg->crcError); |
|---|
| 538 | break; |
|---|
| 539 | case NEXUS_XptDataInterrupt_ePesLengthError: |
|---|
| 540 | NEXUS_IsrCallback_Fire_isr(msg->pesLengthError); |
|---|
| 541 | break; |
|---|
| 542 | case NEXUS_XptDataInterrupt_ePesStartCodeError: |
|---|
| 543 | NEXUS_IsrCallback_Fire_isr(msg->pesStartCodeError); |
|---|
| 544 | break; |
|---|
| 545 | default: |
|---|
| 546 | break; |
|---|
| 547 | } |
|---|
| 548 | } |
|---|
| 549 | } |
|---|
| 550 | |
|---|
| 551 | bool NEXUS_Message_P_HasCallback(NEXUS_MessageHandle msg, NEXUS_XptDataInterrupt xptDataInterrupt) |
|---|
| 552 | { |
|---|
| 553 | BDBG_OBJECT_ASSERT(msg, NEXUS_Message); |
|---|
| 554 | switch (xptDataInterrupt) { |
|---|
| 555 | case NEXUS_XptDataInterrupt_ePsiLengthError: return (msg->settings.psiLengthError.callback != NULL); |
|---|
| 556 | case NEXUS_XptDataInterrupt_eCrcError: return (msg->settings.crcError.callback != NULL); |
|---|
| 557 | case NEXUS_XptDataInterrupt_ePesLengthError: return (msg->settings.pesLengthError.callback != NULL); |
|---|
| 558 | case NEXUS_XptDataInterrupt_ePesStartCodeError: return (msg->settings.pesStartCodeError.callback != NULL); |
|---|
| 559 | default: return false; |
|---|
| 560 | } |
|---|
| 561 | } |
|---|