| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2004-2010, 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: bastmlib_presenter.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/10 $ |
|---|
| 12 | * $brcm_Date: 7/14/10 7:44p $ |
|---|
| 13 | * |
|---|
| 14 | * Revision History: |
|---|
| 15 | * |
|---|
| 16 | * $brcm_Log: /magnum/syslib/astmlib/noarch/bastmlib_presenter.c $ |
|---|
| 17 | * |
|---|
| 18 | * Hydra_Software_Devel/10 7/14/10 7:44p bandrews |
|---|
| 19 | * SW3548-1161: expose default configs as public |
|---|
| 20 | * |
|---|
| 21 | * Hydra_Software_Devel/9 7/17/09 6:56p bandrews |
|---|
| 22 | * PR49215: playback support |
|---|
| 23 | * |
|---|
| 24 | * Hydra_Software_Devel/8 6/5/09 5:32p bandrews |
|---|
| 25 | * PR52503: Move singleton counter/idgen to astmlib struct |
|---|
| 26 | * |
|---|
| 27 | * Hydra_Software_Devel/7 11/24/08 5:56p katrep |
|---|
| 28 | * PR49568: Compiler warning |
|---|
| 29 | * |
|---|
| 30 | * Hydra_Software_Devel/6 11/21/08 8:35p bandrews |
|---|
| 31 | * PR49568: Fix presenter naming capability |
|---|
| 32 | * |
|---|
| 33 | * Hydra_Software_Devel/5 11/20/08 6:16p bandrews |
|---|
| 34 | * PR49489: Add debug messages; ensure no events are recorded if stopped; |
|---|
| 35 | * clear event queue on start; only schedule settling timers if started |
|---|
| 36 | * |
|---|
| 37 | * Hydra_Software_Devel/4 8/14/08 5:18p bandrews |
|---|
| 38 | * PR40090: Fixed warnings |
|---|
| 39 | * |
|---|
| 40 | * Hydra_Software_Devel/3 4/9/08 2:30p bandrews |
|---|
| 41 | * PR41523: Removed |
|---|
| 42 | * |
|---|
| 43 | * Hydra_Software_Devel/2 3/27/08 5:48p bandrews |
|---|
| 44 | * PR40090: Fixed display and storage of presenter names for debug |
|---|
| 45 | * |
|---|
| 46 | * Hydra_Software_Devel/1 3/24/08 3:08p bandrews |
|---|
| 47 | * PR40865: Fixed |
|---|
| 48 | * |
|---|
| 49 | * Hydra_Software_Devel/2 2/15/08 10:00p bandrews |
|---|
| 50 | * PR36148: Updated ASTM based on reviews |
|---|
| 51 | * |
|---|
| 52 | * Hydra_Software_Devel/1 1/25/08 9:22p bandrews |
|---|
| 53 | * PR36148: Updated based on simulation |
|---|
| 54 | ***************************************************************************/ |
|---|
| 55 | |
|---|
| 56 | #include "bstd.h" |
|---|
| 57 | #include "bastmlib_priv.h" |
|---|
| 58 | #include "bastmlib_presenter.h" |
|---|
| 59 | #include "bastmlib_presenter_priv.h" |
|---|
| 60 | |
|---|
| 61 | BDBG_MODULE(astmlib); |
|---|
| 62 | |
|---|
| 63 | #define BASTMLIB_DEBUG_QUEUE 0 |
|---|
| 64 | |
|---|
| 65 | #if BDBG_DEBUG_BUILD |
|---|
| 66 | static int BASTMlib_P_Strlen(const char * s) |
|---|
| 67 | { |
|---|
| 68 | int len = 0; |
|---|
| 69 | while (*s++) len++; |
|---|
| 70 | return len; |
|---|
| 71 | } |
|---|
| 72 | #endif |
|---|
| 73 | |
|---|
| 74 | void BASTMlib_Presenter_GetDefaultSettings( |
|---|
| 75 | BASTMlib_Presenter_Settings * psSettings /* [out] */ |
|---|
| 76 | ) |
|---|
| 77 | { |
|---|
| 78 | BDBG_ENTER(BASTMlib_Presenter_GetDefaultSettings); |
|---|
| 79 | |
|---|
| 80 | BDBG_ASSERT(psSettings); |
|---|
| 81 | |
|---|
| 82 | BKNI_Memset(psSettings, 0, sizeof(BASTMlib_Presenter_Settings)); |
|---|
| 83 | |
|---|
| 84 | BDBG_LEAVE(BASTMlib_Presenter_GetDefaultSettings); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | void BASTMlib_Presenter_Create(BASTMlib_Handle hAstm, BASTMlib_Presenter_Handle * phPresenter, const BASTMlib_Presenter_Settings * psSettings) |
|---|
| 88 | { |
|---|
| 89 | BASTMlib_Presenter_Handle hPresenter; |
|---|
| 90 | |
|---|
| 91 | BDBG_ENTER(BASTMlib_Presenter_Create); |
|---|
| 92 | |
|---|
| 93 | hPresenter = (BASTMlib_Presenter_Handle)BKNI_Malloc(sizeof(struct BASTMlib_Presenter_Impl)); |
|---|
| 94 | BDBG_ASSERT(hPresenter); |
|---|
| 95 | BKNI_Memset(hPresenter, 0, sizeof(struct BASTMlib_Presenter_Impl)); |
|---|
| 96 | hPresenter->uiId = hAstm->uiPresentersCreated++; |
|---|
| 97 | |
|---|
| 98 | BASTMlib_Presenter_GetDefaultConfig(&hPresenter->sConfig); |
|---|
| 99 | |
|---|
| 100 | BASTMlib_Presenter_SetSettings(hPresenter, psSettings); |
|---|
| 101 | |
|---|
| 102 | if (hPresenter->pcName) |
|---|
| 103 | { |
|---|
| 104 | BDBG_MSG(("Presenter %s initial configuration:", hPresenter->pcName)); |
|---|
| 105 | } |
|---|
| 106 | else |
|---|
| 107 | { |
|---|
| 108 | BDBG_MSG(("Presenter %d initial configuration:", hPresenter->uiId)); |
|---|
| 109 | } |
|---|
| 110 | BDBG_MSG((" min time between events: %u ms", hPresenter->sConfig.uiMinimumTimeBetweenEvents)); |
|---|
| 111 | BDBG_MSG((" pass event count threshold: %u events", hPresenter->sConfig.uiPassEventCountThreshold)); |
|---|
| 112 | BDBG_MSG((" fail event count threshold: %u events", hPresenter->sConfig.uiFailEventCountThreshold)); |
|---|
| 113 | |
|---|
| 114 | *phPresenter = hPresenter; |
|---|
| 115 | |
|---|
| 116 | BDBG_LEAVE(BASTMlib_Presenter_Create); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | void BASTMlib_Presenter_GetSettings( |
|---|
| 120 | const BASTMlib_Presenter_Handle hPresenter, |
|---|
| 121 | BASTMlib_Presenter_Settings * psSettings /* out */ |
|---|
| 122 | ) |
|---|
| 123 | { |
|---|
| 124 | BDBG_ENTER(BASTMlib_Presenter_GetSettings); |
|---|
| 125 | BDBG_ASSERT(hPresenter); |
|---|
| 126 | |
|---|
| 127 | if (psSettings) |
|---|
| 128 | { |
|---|
| 129 | *psSettings = hPresenter->sSettings; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | BDBG_LEAVE(BASTMlib_Presenter_GetSettings); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | void BASTMlib_Presenter_SetSettings( |
|---|
| 136 | BASTMlib_Presenter_Handle hPresenter, |
|---|
| 137 | const BASTMlib_Presenter_Settings * psSettings |
|---|
| 138 | ) |
|---|
| 139 | { |
|---|
| 140 | BDBG_ENTER(BASTMlib_Presenter_SetSettings); |
|---|
| 141 | BDBG_ASSERT(hPresenter); |
|---|
| 142 | |
|---|
| 143 | if (psSettings) |
|---|
| 144 | { |
|---|
| 145 | #if BDBG_DEBUG_BUILD |
|---|
| 146 | int len; |
|---|
| 147 | #endif |
|---|
| 148 | hPresenter->sSettings = *psSettings; |
|---|
| 149 | #if BDBG_DEBUG_BUILD |
|---|
| 150 | if (psSettings->pcName) |
|---|
| 151 | { |
|---|
| 152 | len = BASTMlib_P_Strlen(psSettings->pcName); |
|---|
| 153 | hPresenter->pcName = (char *)BKNI_Malloc(len + 1); |
|---|
| 154 | BKNI_Memset(hPresenter->pcName, 0, len + 1); |
|---|
| 155 | BKNI_Memcpy(hPresenter->pcName, psSettings->pcName, len); |
|---|
| 156 | } |
|---|
| 157 | else |
|---|
| 158 | { |
|---|
| 159 | if (hPresenter->pcName) |
|---|
| 160 | { |
|---|
| 161 | BKNI_Free(hPresenter->pcName); |
|---|
| 162 | hPresenter->pcName = NULL; |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | #else |
|---|
| 166 | hPresenter->sSettings.pcName = NULL; |
|---|
| 167 | #endif |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | BDBG_LEAVE(BASTMlib_Presenter_SetSettings); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | void BASTMlib_Presenter_Destroy(BASTMlib_Presenter_Handle hPresenter) |
|---|
| 174 | { |
|---|
| 175 | BDBG_ENTER(BASTMlib_Presenter_Destroy); |
|---|
| 176 | BDBG_ASSERT(hPresenter); |
|---|
| 177 | |
|---|
| 178 | if (hPresenter->sEventQueue.asEvents) |
|---|
| 179 | { |
|---|
| 180 | BKNI_Free(hPresenter->sEventQueue.asEvents); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | if (hPresenter->pcName) |
|---|
| 184 | { |
|---|
| 185 | BKNI_Free(hPresenter->pcName); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | BKNI_Free(hPresenter); |
|---|
| 189 | |
|---|
| 190 | BDBG_LEAVE(BASTMlib_Presenter_Destroy); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | void BASTMlib_Presenter_GetDefaultConfig(BASTMlib_Presenter_Config * psConfig) |
|---|
| 194 | { |
|---|
| 195 | BDBG_ENTER(BASTMlib_Presenter_P_GetDefaultConfig); |
|---|
| 196 | |
|---|
| 197 | BDBG_ASSERT(psConfig); |
|---|
| 198 | |
|---|
| 199 | BKNI_Memset(psConfig, 0, sizeof(BASTMlib_Presenter_Config)); |
|---|
| 200 | psConfig->uiPassEventCountThreshold = BASTMLIB_PRESENTER_P_DEFAULT_PASS_EVENT_COUNT_THRESHOLD; |
|---|
| 201 | psConfig->uiFailEventCountThreshold = BASTMLIB_PRESENTER_P_DEFAULT_FAIL_EVENT_COUNT_THRESHOLD; |
|---|
| 202 | |
|---|
| 203 | BDBG_LEAVE(BASTMlib_Presenter_P_GetDefaultConfig); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | void BASTMlib_Presenter_Reset_isr( |
|---|
| 207 | BASTMlib_Presenter_Handle hPresenter |
|---|
| 208 | ) |
|---|
| 209 | { |
|---|
| 210 | BDBG_ENTER(BASTMlib_Presenter_Reset_isr); |
|---|
| 211 | |
|---|
| 212 | BDBG_ASSERT(hPresenter); |
|---|
| 213 | |
|---|
| 214 | hPresenter->uiPassEventCount = 0; |
|---|
| 215 | hPresenter->uiFailEventCount = 0; |
|---|
| 216 | |
|---|
| 217 | hPresenter->sEventQueue.uiWrite = hPresenter->sEventQueue.uiCapacity / 2; |
|---|
| 218 | hPresenter->sEventQueue.uiRead = hPresenter->sEventQueue.uiWrite - 1; |
|---|
| 219 | hPresenter->sEventQueue.uiSize = 0; |
|---|
| 220 | |
|---|
| 221 | BDBG_LEAVE(BASTMlib_Presenter_Reset_isr); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | void BASTMlib_Presenter_GetConfig( |
|---|
| 225 | const BASTMlib_Presenter_Handle hPresenter, |
|---|
| 226 | BASTMlib_Presenter_Config * psConfig |
|---|
| 227 | ) |
|---|
| 228 | { |
|---|
| 229 | BDBG_ENTER(BASTMlib_Presenter_GetConfig); |
|---|
| 230 | |
|---|
| 231 | BDBG_ASSERT(hPresenter); |
|---|
| 232 | BDBG_ASSERT(psConfig); |
|---|
| 233 | |
|---|
| 234 | *psConfig = hPresenter->sConfig; |
|---|
| 235 | |
|---|
| 236 | BDBG_LEAVE(BASTMlib_Presenter_GetConfig); |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | void BASTMlib_Presenter_SetConfig( |
|---|
| 240 | BASTMlib_Presenter_Handle hPresenter, |
|---|
| 241 | const BASTMlib_Presenter_Config * psConfig |
|---|
| 242 | ) |
|---|
| 243 | { |
|---|
| 244 | BDBG_ENTER(BASTMlib_Presenter_SetConfig); |
|---|
| 245 | |
|---|
| 246 | BDBG_ASSERT(hPresenter); |
|---|
| 247 | BDBG_ASSERT(psConfig); |
|---|
| 248 | |
|---|
| 249 | hPresenter->sConfig = *psConfig; |
|---|
| 250 | |
|---|
| 251 | if (hPresenter->pcName) |
|---|
| 252 | { |
|---|
| 253 | BDBG_MSG(("Presenter %s reconfigured:", hPresenter->pcName)); |
|---|
| 254 | } |
|---|
| 255 | else |
|---|
| 256 | { |
|---|
| 257 | BDBG_MSG(("Presenter %d reconfigured:", hPresenter->uiId)); |
|---|
| 258 | } |
|---|
| 259 | BDBG_MSG((" min time between events: %u ms", hPresenter->sConfig.uiMinimumTimeBetweenEvents)); |
|---|
| 260 | BDBG_MSG((" pass event count threshold: %u events", hPresenter->sConfig.uiPassEventCountThreshold)); |
|---|
| 261 | BDBG_MSG((" fail event count threshold: %u events", hPresenter->sConfig.uiFailEventCountThreshold)); |
|---|
| 262 | |
|---|
| 263 | /* PR:50140 check for assignment before using hAstm */ |
|---|
| 264 | /* don't resize if already started, wait till next restart, or resize if unassigned */ |
|---|
| 265 | if ((hPresenter->hAstm && !hPresenter->hAstm->bStarted) || !hPresenter->hAstm) |
|---|
| 266 | { |
|---|
| 267 | BASTMlib_Presenter_ResizeEventQueue(hPresenter); |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | BDBG_LEAVE(BASTMlib_Presenter_SetConfig); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | void BASTMlib_Presenter_EventHandler_isr( |
|---|
| 274 | BASTMlib_Presenter_Handle hPresenter, |
|---|
| 275 | const BASTMlib_Presenter_Event * psEvent |
|---|
| 276 | ) |
|---|
| 277 | { |
|---|
| 278 | BSYSlib_List_IteratorHandle hIterator = NULL; |
|---|
| 279 | bool bFound = false; |
|---|
| 280 | BASTMlib_Handle hAstm = NULL; |
|---|
| 281 | |
|---|
| 282 | BDBG_ENTER(BASTMlib_Presenter_EventHandler_isr); |
|---|
| 283 | |
|---|
| 284 | BDBG_ASSERT(hPresenter); |
|---|
| 285 | BDBG_ASSERT(psEvent); |
|---|
| 286 | |
|---|
| 287 | hAstm = hPresenter->hAstm; |
|---|
| 288 | |
|---|
| 289 | if (hAstm) |
|---|
| 290 | { |
|---|
| 291 | if (hAstm->bStarted) |
|---|
| 292 | { |
|---|
| 293 | hIterator = BSYSlib_List_AcquireIterator_isr(hAstm->sPresentation.hPresenters); |
|---|
| 294 | while (BSYSlib_List_HasNext_isr(hIterator)) |
|---|
| 295 | { |
|---|
| 296 | BASTMlib_Presenter_Handle hTemp = NULL; |
|---|
| 297 | hTemp = (BASTMlib_Presenter_Handle)BSYSlib_List_Next_isr(hIterator); |
|---|
| 298 | |
|---|
| 299 | if (hTemp == hPresenter) |
|---|
| 300 | { |
|---|
| 301 | bFound = true; |
|---|
| 302 | break; |
|---|
| 303 | } |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | BSYSlib_List_ReleaseIterator_isr(hIterator); |
|---|
| 307 | |
|---|
| 308 | if (bFound) |
|---|
| 309 | { |
|---|
| 310 | if (hAstm->sPresentation.bAcquire) |
|---|
| 311 | { |
|---|
| 312 | if (hPresenter->sEventQueue.uiSize < hPresenter->sEventQueue.uiCapacity) |
|---|
| 313 | { |
|---|
| 314 | #if BASTMLIB_DEBUG_QUEUE |
|---|
| 315 | BDBG_MSG(("Adding event to presenter %p queue at %u", hPresenter, hPresenter->sEventQueue.uiWrite)); |
|---|
| 316 | #endif |
|---|
| 317 | hPresenter->sEventQueue.asEvents[hPresenter->sEventQueue.uiWrite] = *psEvent; |
|---|
| 318 | hPresenter->sEventQueue.uiWrite++; |
|---|
| 319 | hPresenter->sEventQueue.uiWrite %= hPresenter->sEventQueue.uiCapacity; |
|---|
| 320 | hPresenter->sEventQueue.uiSize++; |
|---|
| 321 | } |
|---|
| 322 | else |
|---|
| 323 | { |
|---|
| 324 | BDBG_MSG(("Presenter %p event queue full. Discarding events.", hPresenter)); |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| 327 | else |
|---|
| 328 | { |
|---|
| 329 | BDBG_MSG(("Presenter %p event received while not acquiring. Ignored", hPresenter)); |
|---|
| 330 | } |
|---|
| 331 | } |
|---|
| 332 | else |
|---|
| 333 | { |
|---|
| 334 | BDBG_MSG(("Unmanaged presenter (%p) event received", hPresenter)); |
|---|
| 335 | } |
|---|
| 336 | } |
|---|
| 337 | else |
|---|
| 338 | { |
|---|
| 339 | BDBG_MSG(("Presenter %p event received while stopped. Ignored", hPresenter)); |
|---|
| 340 | } |
|---|
| 341 | } |
|---|
| 342 | else |
|---|
| 343 | { |
|---|
| 344 | BDBG_MSG(("Unmanaged presenter (%p) event received", hPresenter)); |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | BDBG_LEAVE(BASTMlib_Presenter_EventHandler_isr); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | void BASTMlib_Presenter_ResizeEventQueue( |
|---|
| 351 | BASTMlib_Presenter_Handle hPresenter |
|---|
| 352 | ) |
|---|
| 353 | { |
|---|
| 354 | unsigned int uiMinimumTimeBetweenEvents; |
|---|
| 355 | unsigned int uiMaximumAcquisitionTime; |
|---|
| 356 | unsigned int uiCapacity; |
|---|
| 357 | |
|---|
| 358 | BDBG_ASSERT(hPresenter); |
|---|
| 359 | |
|---|
| 360 | BDBG_ENTER(BASTMlib_Presenter_ResizeEventQueue); |
|---|
| 361 | |
|---|
| 362 | uiMinimumTimeBetweenEvents = hPresenter->sConfig.uiMinimumTimeBetweenEvents; |
|---|
| 363 | uiMaximumAcquisitionTime = hPresenter->uiMaximumAcquisitionTime; |
|---|
| 364 | |
|---|
| 365 | if (uiMinimumTimeBetweenEvents && uiMaximumAcquisitionTime) |
|---|
| 366 | { |
|---|
| 367 | uiCapacity = uiMaximumAcquisitionTime / uiMinimumTimeBetweenEvents + 1; |
|---|
| 368 | uiCapacity += uiCapacity / 10; /* 10% bigger than required */ |
|---|
| 369 | } |
|---|
| 370 | else |
|---|
| 371 | { |
|---|
| 372 | uiCapacity = BASTMLIB_PRESENTER_P_DEFAULT_EVENT_QUEUE_CAPACITY; |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | if (hPresenter->sEventQueue.uiCapacity != uiCapacity) |
|---|
| 376 | { |
|---|
| 377 | if (hPresenter->sEventQueue.asEvents) |
|---|
| 378 | { |
|---|
| 379 | BKNI_Free(hPresenter->sEventQueue.asEvents); |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | hPresenter->sEventQueue.asEvents = (BASTMlib_Presenter_Event *)BKNI_Malloc(sizeof(BASTMlib_Presenter_Event) * uiCapacity); |
|---|
| 383 | BDBG_ASSERT(hPresenter->sEventQueue.asEvents); |
|---|
| 384 | BKNI_Memset(hPresenter->sEventQueue.asEvents, 0, sizeof(BASTMlib_Presenter_Event) * uiCapacity); |
|---|
| 385 | |
|---|
| 386 | hPresenter->sEventQueue.uiCapacity = uiCapacity; |
|---|
| 387 | |
|---|
| 388 | BKNI_EnterCriticalSection(); |
|---|
| 389 | BASTMlib_Presenter_Reset_isr(hPresenter); |
|---|
| 390 | BKNI_LeaveCriticalSection(); |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | BDBG_LEAVE(BASTMlib_Presenter_ResizeEventQueue); |
|---|
| 394 | } |
|---|
| 395 | |
|---|