| 1 | /****************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright (c) 2009 |
|---|
| 4 | Infineon Technologies AG |
|---|
| 5 | Am Campeon 1-12; 81726 Munich, Germany |
|---|
| 6 | |
|---|
| 7 | For licensing information, see the file 'LICENSE' in the root folder of |
|---|
| 8 | this software module. |
|---|
| 9 | |
|---|
| 10 | ******************************************************************************/ |
|---|
| 11 | |
|---|
| 12 | #define DSL_INTERN |
|---|
| 13 | |
|---|
| 14 | #include "drv_dsl_cpe_api.h" |
|---|
| 15 | #include "drv_dsl_cpe_timeout.h" |
|---|
| 16 | |
|---|
| 17 | #undef DSL_DBG_BLOCK |
|---|
| 18 | #define DSL_DBG_BLOCK DSL_DBG_CPE_API |
|---|
| 19 | |
|---|
| 20 | #if defined(INCLUDE_DSL_CPE_API_VINAX) || (defined(INCLUDE_DSL_CPE_API_DANUBE) && defined(INCLUDE_DSL_G997_LINE_INVENTORY)) |
|---|
| 21 | |
|---|
| 22 | /** \file |
|---|
| 23 | Timeout support |
|---|
| 24 | */ |
|---|
| 25 | |
|---|
| 26 | /** \addtogroup DRV_DSL_CPE_COMMON |
|---|
| 27 | @{ */ |
|---|
| 28 | |
|---|
| 29 | /* |
|---|
| 30 | Initializes the timeout element lists with given number of max. init |
|---|
| 31 | elements. The number of lists that will be created is defined by |
|---|
| 32 | \ref DSL_MAX_TIMEOUT_LISTS. |
|---|
| 33 | |
|---|
| 34 | \param pContext Pointer to dsl cpe library context structure, [I] |
|---|
| 35 | \param nNrOfElements Specifies the number of init timeout elements for each |
|---|
| 36 | timeout list, [I] |
|---|
| 37 | \param bDynMemAlloc Specifies if the timout element list should be |
|---|
| 38 | dynamically extended (DSL_TRUE) if necessary or not |
|---|
| 39 | (DSL_FALSE), [I] |
|---|
| 40 | |
|---|
| 41 | \return |
|---|
| 42 | Return values are defined within the DSL_Error_t definition |
|---|
| 43 | - DSL_SUCCESS in case of success |
|---|
| 44 | - DSL_ERROR if operation failed |
|---|
| 45 | */ |
|---|
| 46 | DSL_Error_t DSL_DRV_Timeout_Init( |
|---|
| 47 | DSL_Context_t *pContext, |
|---|
| 48 | DSL_uint32_t nNrOfElements, |
|---|
| 49 | DSL_boolean_t bDynMemAlloc) |
|---|
| 50 | { |
|---|
| 51 | DSL_TimeoutContext_t *pTCtx = &pContext->TimeoutListsContext; |
|---|
| 52 | DSL_TimeoutElement_t *pListElement = DSL_NULL; |
|---|
| 53 | DSL_TimeoutElement_t *pPreListElement = DSL_NULL; |
|---|
| 54 | DSL_uint32_t j = 0; |
|---|
| 55 | DSL_char_t fname[64]; |
|---|
| 56 | |
|---|
| 57 | /* Allocate and initialize all defined timeout list */ |
|---|
| 58 | pPreListElement = DSL_NULL; |
|---|
| 59 | |
|---|
| 60 | DSL_DRV_snprintf(fname, sizeof(fname), "tmo_lst"); |
|---|
| 61 | |
|---|
| 62 | DSL_TIMEOUT_LIST_LOCK(); |
|---|
| 63 | for (j = 0; j < nNrOfElements; j++) |
|---|
| 64 | { |
|---|
| 65 | pListElement = DSL_DRV_Malloc(sizeof(DSL_TimeoutElement_t)); |
|---|
| 66 | if (pListElement == DSL_NULL) |
|---|
| 67 | { |
|---|
| 68 | DSL_DEBUG_SET_ERROR(DSL_ERROR); |
|---|
| 69 | DSL_DEBUG( DSL_DBG_ERR, (pContext, |
|---|
| 70 | "DSL[%02d]: Error during memory allocation for timeout element " |
|---|
| 71 | "(ElementIdx=%d)!" DSL_DRV_CRLF, DSL_DEV_NUM(pContext), j)); |
|---|
| 72 | |
|---|
| 73 | return DSL_ERROR; |
|---|
| 74 | } |
|---|
| 75 | else |
|---|
| 76 | { |
|---|
| 77 | memset((DSL_void_t *)pListElement, 0, sizeof(DSL_TimeoutElement_t)); |
|---|
| 78 | |
|---|
| 79 | if (j == 0) |
|---|
| 80 | { |
|---|
| 81 | pTCtx->TimeoutList.pListHead = pListElement; |
|---|
| 82 | } |
|---|
| 83 | else |
|---|
| 84 | { |
|---|
| 85 | if(pPreListElement) |
|---|
| 86 | { |
|---|
| 87 | pPreListElement->pNext = pListElement; |
|---|
| 88 | pListElement->pPrevious = pPreListElement; |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | if (j == (nNrOfElements - 1)) |
|---|
| 93 | { |
|---|
| 94 | pTCtx->TimeoutList.pListTail = pListElement; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | pPreListElement = pListElement; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 101 | |
|---|
| 102 | pTCtx->bDynMemAlloc = bDynMemAlloc; |
|---|
| 103 | pTCtx->nNrOfElements = nNrOfElements; |
|---|
| 104 | |
|---|
| 105 | return DSL_SUCCESS; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | /* |
|---|
| 109 | Deletes all allocated memory for timeout event handling. |
|---|
| 110 | |
|---|
| 111 | \param pContext Pointer to dsl library context structure, [I] |
|---|
| 112 | |
|---|
| 113 | \return |
|---|
| 114 | Return values are defined within the DSL_Error_t definition |
|---|
| 115 | - DSL_SUCCESS in case of success |
|---|
| 116 | - DSL_ERROR if operation failed |
|---|
| 117 | */ |
|---|
| 118 | DSL_Error_t DSL_DRV_Timeout_Shutdown( |
|---|
| 119 | DSL_Context_t *pContext) |
|---|
| 120 | { |
|---|
| 121 | DSL_TimeoutContext_t *pTCtx = &pContext->TimeoutListsContext; |
|---|
| 122 | DSL_TimeoutElement_t *pListElement = DSL_NULL; |
|---|
| 123 | DSL_TimeoutElement_t *pFreeListElement = DSL_NULL; |
|---|
| 124 | |
|---|
| 125 | pListElement = pTCtx->TimeoutList.pListHead; |
|---|
| 126 | |
|---|
| 127 | DSL_TIMEOUT_LIST_LOCK(); |
|---|
| 128 | while (pListElement != DSL_NULL) |
|---|
| 129 | { |
|---|
| 130 | pFreeListElement = pListElement; |
|---|
| 131 | pListElement = pListElement->pNext; |
|---|
| 132 | |
|---|
| 133 | if (pFreeListElement != DSL_NULL) |
|---|
| 134 | { |
|---|
| 135 | DSL_DRV_MemFree(pFreeListElement); |
|---|
| 136 | } |
|---|
| 137 | }; |
|---|
| 138 | |
|---|
| 139 | pTCtx->TimeoutList.pListHead = DSL_NULL; |
|---|
| 140 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 141 | |
|---|
| 142 | return DSL_SUCCESS; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | /* |
|---|
| 146 | This routine returns the actually memory size of all timeout events lists in |
|---|
| 147 | number of bytes. |
|---|
| 148 | \note The size of the management control structures are not included because |
|---|
| 149 | theay are already included within the size of the DSL API context |
|---|
| 150 | structure (statically allocated) |
|---|
| 151 | |
|---|
| 152 | \param pContext Pointer to dsl library context structure, [I] |
|---|
| 153 | |
|---|
| 154 | \return |
|---|
| 155 | Returns the size of the all timeout event lists in number of bytes. |
|---|
| 156 | In case of an error the size is equal to 0. |
|---|
| 157 | */ |
|---|
| 158 | DSL_uint32_t DSL_DRV_Timeout_GetTotalSizeOfLists( |
|---|
| 159 | DSL_Context_t *pContext) |
|---|
| 160 | { |
|---|
| 161 | DSL_uint32_t nSize = 0U; |
|---|
| 162 | DSL_TimeoutContext_t *pTCtx; |
|---|
| 163 | |
|---|
| 164 | if(pContext == DSL_NULL) |
|---|
| 165 | return 0; |
|---|
| 166 | |
|---|
| 167 | pTCtx = &pContext->TimeoutListsContext; |
|---|
| 168 | |
|---|
| 169 | nSize = pTCtx->nNrOfElements * |
|---|
| 170 | sizeof(DSL_TimeoutElement_t); |
|---|
| 171 | |
|---|
| 172 | return nSize; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | /* |
|---|
| 176 | This routine returns the next timeout element that has been timed out. |
|---|
| 177 | |
|---|
| 178 | \param pContext Pointer to dsl library context structure, [I] |
|---|
| 179 | \param nEventType Returns the timeout event ID which has been returned from |
|---|
| 180 | function \ref DSL_Timeout_AddEvent. If there is no timed out |
|---|
| 181 | event actually pending the value will be 0, [O] |
|---|
| 182 | \param nTimeoutID Returns the timeout element id. This unique value identifies |
|---|
| 183 | the timeout event. It might be used to remove the timeout |
|---|
| 184 | event later on (Note: this value was also returned from |
|---|
| 185 | function which adds this event formerly), [I] |
|---|
| 186 | |
|---|
| 187 | \return |
|---|
| 188 | - DSL_Success In case of timeout element has been timed out. In this case |
|---|
| 189 | the 'nEventType' value includes the type of the timed out event as |
|---|
| 190 | specified during adding of event. |
|---|
| 191 | - DSL_Error In case if there is actually no timed out element |
|---|
| 192 | */ |
|---|
| 193 | DSL_Error_t DSL_DRV_Timeout_GetNextActiveEvent( |
|---|
| 194 | DSL_Context_t *pContext, |
|---|
| 195 | DSL_int_t *nEventType, |
|---|
| 196 | DSL_uint32_t *nTimeoutID) |
|---|
| 197 | { |
|---|
| 198 | DSL_TimeoutContext_t *pTCtx = &pContext->TimeoutListsContext; |
|---|
| 199 | DSL_TimeoutElement_t *pListHead = DSL_NULL; |
|---|
| 200 | DSL_DRV_TimeVal_t nActTime; |
|---|
| 201 | |
|---|
| 202 | nActTime = DSL_DRV_TimeMSecGet(); |
|---|
| 203 | DSL_TIMEOUT_LIST_LOCK(); |
|---|
| 204 | pListHead = pTCtx->TimeoutList.pListHead; |
|---|
| 205 | |
|---|
| 206 | if (pListHead->bValid == DSL_TRUE) |
|---|
| 207 | { |
|---|
| 208 | if (pListHead->nStopTime <= nActTime) |
|---|
| 209 | { |
|---|
| 210 | *nEventType = pListHead->nEventType; |
|---|
| 211 | *nTimeoutID = (DSL_uint32_t)pListHead; |
|---|
| 212 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 213 | return DSL_SUCCESS; |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 218 | return DSL_ERROR; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | /* |
|---|
| 222 | This routine adjusts the timeout event time. |
|---|
| 223 | |
|---|
| 224 | \param pContext Pointer to dsl library context structure, [I] |
|---|
| 225 | \param nTimeoutID Returns the timeout element id. This unique value identifies |
|---|
| 226 | the timeout event. It might be used to remove the timeout |
|---|
| 227 | event later on (Note: this value was also returned from |
|---|
| 228 | function which adds this event formerly), [I] |
|---|
| 229 | \param nNewTimeout Specifies the timeout time in mili seconds. The actual system |
|---|
| 230 | time will be automatically requested, [I] |
|---|
| 231 | |
|---|
| 232 | \return |
|---|
| 233 | - DSL_Success In case of timeout element has been timed out. In this case |
|---|
| 234 | the 'nEventType' value includes the type of the timed out event as |
|---|
| 235 | specified during adding of event. |
|---|
| 236 | - DSL_Error In case if there is actually no timed out element |
|---|
| 237 | */ |
|---|
| 238 | DSL_Error_t DSL_DRV_Timeout_Reset( |
|---|
| 239 | DSL_Context_t *pContext, |
|---|
| 240 | DSL_uint32_t nTimeoutID, |
|---|
| 241 | DSL_uint32_t nNewTimeout) |
|---|
| 242 | { |
|---|
| 243 | DSL_TimeoutContext_t *pTCtx = &pContext->TimeoutListsContext; |
|---|
| 244 | DSL_TimeoutElement_t *pListElement = DSL_NULL, *pListResetElement = DSL_NULL; |
|---|
| 245 | DSL_uint32_t i = 0; |
|---|
| 246 | |
|---|
| 247 | DSL_TIMEOUT_LIST_LOCK(); |
|---|
| 248 | pListElement = pTCtx->TimeoutList.pListHead; |
|---|
| 249 | pListResetElement = (DSL_TimeoutElement_t *)nTimeoutID; |
|---|
| 250 | |
|---|
| 251 | if (nTimeoutID != 0) |
|---|
| 252 | { |
|---|
| 253 | for (i = 0; i < pTCtx->nNrOfElements; i++) |
|---|
| 254 | { |
|---|
| 255 | if (pListElement == pListResetElement) |
|---|
| 256 | break; |
|---|
| 257 | |
|---|
| 258 | pListElement = pListElement->pNext; |
|---|
| 259 | |
|---|
| 260 | if (pListElement == DSL_NULL) |
|---|
| 261 | { |
|---|
| 262 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 263 | DSL_DEBUG_SET_ERROR(DSL_ERROR); |
|---|
| 264 | DSL_DEBUG( DSL_DBG_ERR, (pContext, |
|---|
| 265 | "DSL[%02d]: Error in 'DSL_Timeout_Reset'- Element (" |
|---|
| 266 | "nTimeoutID=0x%08X) could not be reset (not found)!" DSL_DRV_CRLF, |
|---|
| 267 | DSL_DEV_NUM(pContext), nTimeoutID)); |
|---|
| 268 | |
|---|
| 269 | return DSL_ERROR; |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | pListElement->nStopTime = pListElement->nStartTime + nNewTimeout; |
|---|
| 275 | |
|---|
| 276 | DSL_DEBUG( DSL_DBG_MSG, (pContext, |
|---|
| 277 | "DSL[%02d]: Reset timeout event (nEventType=%d, " |
|---|
| 278 | "pListElement=0x%08X) successfully!" DSL_DRV_CRLF, |
|---|
| 279 | DSL_DEV_NUM(pContext), pListElement->nEventType, |
|---|
| 280 | (DSL_uint32_t)pListElement)); |
|---|
| 281 | |
|---|
| 282 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 283 | return DSL_SUCCESS; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | /* |
|---|
| 287 | This routine adds a timeout element to the list of avialable timeouts. |
|---|
| 288 | The timeout element will be taken from the available list of empty timeouts |
|---|
| 289 | (from tail of list) set with necessary values and added to the list of active |
|---|
| 290 | elements to have a list of increasing timeout values. |
|---|
| 291 | |
|---|
| 292 | \param pContext Pointer to dsl library context structure, [I] |
|---|
| 293 | \param nEventType Specifies the timeout event type which will be returned |
|---|
| 294 | later on in case of timeout has been timed out. The value |
|---|
| 295 | has to be unequal to 0, [I] |
|---|
| 296 | \param nTimeout Specifies the timeout time in mili seconds. The actual system |
|---|
| 297 | time will be automatically requested, [I] |
|---|
| 298 | |
|---|
| 299 | \return |
|---|
| 300 | returns the nTimeoutID of the element which has to be used for removing the |
|---|
| 301 | timeout event later on. In case of an error the ID is equal to 0. |
|---|
| 302 | */ |
|---|
| 303 | DSL_uint32_t DSL_DRV_Timeout_AddEvent( |
|---|
| 304 | DSL_Context_t *pContext, |
|---|
| 305 | DSL_int_t nEventType, |
|---|
| 306 | DSL_uint32_t nTimeout) |
|---|
| 307 | { |
|---|
| 308 | DSL_TimeoutContext_t *pTCtx = &pContext->TimeoutListsContext; |
|---|
| 309 | DSL_TimeoutElement_t *pListElement = DSL_NULL; |
|---|
| 310 | DSL_TimeoutElement_t *pListInsertElement = DSL_NULL; |
|---|
| 311 | DSL_TimeoutElement_t *pPreListElement = DSL_NULL; |
|---|
| 312 | /*DSL_TimeoutElement_t *pNextListElement = DSL_NULL;*/ |
|---|
| 313 | DSL_uint32_t nRetVal = 0; |
|---|
| 314 | DSL_boolean_t bInsert = DSL_FALSE; |
|---|
| 315 | DSL_boolean_t bFirst = DSL_FALSE, bLast = DSL_FALSE; |
|---|
| 316 | DSL_uint32_t i = 0; |
|---|
| 317 | DSL_DRV_TimeVal_t nActTime; |
|---|
| 318 | |
|---|
| 319 | nActTime = DSL_DRV_TimeMSecGet(); |
|---|
| 320 | |
|---|
| 321 | /* Lock Timeout list*/ |
|---|
| 322 | if( DSL_DRV_MUTEX_LOCK(pContext->bspMutex) ) |
|---|
| 323 | { |
|---|
| 324 | DSL_DEBUG_SET_ERROR(DSL_ERROR); |
|---|
| 325 | DSL_DEBUG(DSL_DBG_ERR, |
|---|
| 326 | (pContext, "DSL: ERROR: failed to lock access to the timeouts list!" |
|---|
| 327 | DSL_DRV_CRLF)); |
|---|
| 328 | return 0; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | /* Check if timeout elements are available by examining 'bValid' flag. |
|---|
| 332 | If the last element is also used, there are no more free elements |
|---|
| 333 | In case of choosing dynamic memory allocation in 'DSL_Timeout_Init' |
|---|
| 334 | a new element will be automatically allocated otherwise an error will |
|---|
| 335 | be returned. */ |
|---|
| 336 | if (pTCtx->TimeoutList.pListTail->bValid == DSL_TRUE) |
|---|
| 337 | { |
|---|
| 338 | if (pTCtx->bDynMemAlloc == DSL_FALSE) |
|---|
| 339 | { |
|---|
| 340 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 341 | DSL_DEBUG_SET_ERROR(DSL_ERROR); |
|---|
| 342 | DSL_DEBUG( DSL_DBG_ERR, (pContext, |
|---|
| 343 | "DSL[%02d]: Error in 'DSL_Timeout_AddEvent' (" |
|---|
| 344 | "nEventType=%d) - No free timeout elements available!" DSL_DRV_CRLF , |
|---|
| 345 | DSL_DEV_NUM(pContext), nEventType)); |
|---|
| 346 | |
|---|
| 347 | return 0; |
|---|
| 348 | } |
|---|
| 349 | else |
|---|
| 350 | { |
|---|
| 351 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 352 | DSL_DEBUG_SET_ERROR(DSL_ERROR); |
|---|
| 353 | DSL_DEBUG( DSL_DBG_ERR, (pContext, |
|---|
| 354 | "DSL[%02d]: Error in 'DSL_Timeout_AddEvent'- Dynamic memory allocation " |
|---|
| 355 | "not supported yet!" DSL_DRV_CRLF, DSL_DEV_NUM(pContext))); |
|---|
| 356 | |
|---|
| 357 | return 0; |
|---|
| 358 | } |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | pListElement = pTCtx->TimeoutList.pListTail; |
|---|
| 362 | pPreListElement = pListElement->pPrevious; |
|---|
| 363 | |
|---|
| 364 | /* if there is more than one element in the list, |
|---|
| 365 | remove last element from list */ |
|---|
| 366 | if (pPreListElement) |
|---|
| 367 | { |
|---|
| 368 | pPreListElement->pNext = DSL_NULL; |
|---|
| 369 | pTCtx->TimeoutList.pListTail = pPreListElement; |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | /* Set values in removed list element */ |
|---|
| 373 | pListElement->bValid = DSL_TRUE; |
|---|
| 374 | |
|---|
| 375 | pListElement->nStartTime = nActTime; |
|---|
| 376 | pListElement->nTimeout = nTimeout; |
|---|
| 377 | pListElement->nStopTime = nActTime + nTimeout; |
|---|
| 378 | pListElement->nEventType = nEventType; |
|---|
| 379 | nRetVal = (DSL_uint32_t)pListElement; |
|---|
| 380 | |
|---|
| 381 | /* if there is more than one element in the list, |
|---|
| 382 | add the removed element in place of ascending timeout order. |
|---|
| 383 | Otherwise no insert is needed at all. */ |
|---|
| 384 | if (pPreListElement) |
|---|
| 385 | { |
|---|
| 386 | pListInsertElement = pTCtx->TimeoutList.pListHead; |
|---|
| 387 | bInsert = DSL_FALSE; |
|---|
| 388 | for (i = 0; i < pTCtx->nNrOfElements; i++) |
|---|
| 389 | { |
|---|
| 390 | if (pListInsertElement->bValid == DSL_FALSE) |
|---|
| 391 | { |
|---|
| 392 | bInsert = DSL_TRUE; |
|---|
| 393 | if (pListInsertElement->pPrevious == DSL_NULL) |
|---|
| 394 | { |
|---|
| 395 | bFirst = DSL_TRUE; |
|---|
| 396 | } |
|---|
| 397 | } |
|---|
| 398 | else |
|---|
| 399 | { |
|---|
| 400 | if (pListElement->nStopTime < pListInsertElement->nStopTime) |
|---|
| 401 | { |
|---|
| 402 | bInsert = DSL_TRUE; |
|---|
| 403 | if (pListInsertElement->pPrevious == DSL_NULL) |
|---|
| 404 | { |
|---|
| 405 | bFirst = DSL_TRUE; |
|---|
| 406 | } |
|---|
| 407 | } |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | if ( (bInsert == DSL_FALSE) && (pListInsertElement->pNext == DSL_NULL) ) |
|---|
| 411 | { |
|---|
| 412 | bInsert = DSL_TRUE; |
|---|
| 413 | bLast = DSL_TRUE; |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | if (bInsert == DSL_FALSE) |
|---|
| 417 | { |
|---|
| 418 | /* check next element */ |
|---|
| 419 | pListInsertElement = pListInsertElement->pNext; |
|---|
| 420 | } |
|---|
| 421 | else |
|---|
| 422 | { |
|---|
| 423 | /* Found entry point */ |
|---|
| 424 | pPreListElement = pListInsertElement->pPrevious; |
|---|
| 425 | /*pNextListElement = pListInsertElement->pNext;*/ |
|---|
| 426 | |
|---|
| 427 | if (bFirst == DSL_TRUE) |
|---|
| 428 | { |
|---|
| 429 | pListInsertElement->pPrevious = pListElement; |
|---|
| 430 | pListElement->pNext = pListInsertElement; |
|---|
| 431 | pTCtx->TimeoutList.pListHead = pListElement; |
|---|
| 432 | pListElement->pPrevious = DSL_NULL; |
|---|
| 433 | } |
|---|
| 434 | else if (bLast == DSL_TRUE) |
|---|
| 435 | { |
|---|
| 436 | pListInsertElement->pNext = pListElement; |
|---|
| 437 | pListElement->pPrevious = pListInsertElement; |
|---|
| 438 | pTCtx->TimeoutList.pListTail = pListElement; |
|---|
| 439 | pListElement->pNext = DSL_NULL; |
|---|
| 440 | } |
|---|
| 441 | else |
|---|
| 442 | { |
|---|
| 443 | /* Intermediate */ |
|---|
| 444 | pPreListElement->pNext = pListElement; |
|---|
| 445 | pListElement->pPrevious = pPreListElement; |
|---|
| 446 | pListElement->pNext = pListInsertElement; |
|---|
| 447 | pListInsertElement->pPrevious = pListElement; |
|---|
| 448 | } |
|---|
| 449 | break; |
|---|
| 450 | } |
|---|
| 451 | } |
|---|
| 452 | } |
|---|
| 453 | else |
|---|
| 454 | { |
|---|
| 455 | bInsert = DSL_TRUE; |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | if (bInsert == DSL_FALSE) |
|---|
| 459 | { |
|---|
| 460 | DSL_DEBUG_SET_ERROR(DSL_ERROR); |
|---|
| 461 | DSL_DEBUG( DSL_DBG_ERR, (pContext, |
|---|
| 462 | "DSL[%02d]: Error in 'DSL_Timeout_AddEvent'- Element (" |
|---|
| 463 | "nEventType=%d)could not be added!" DSL_DRV_CRLF , |
|---|
| 464 | DSL_DEV_NUM(pContext), nEventType)); |
|---|
| 465 | |
|---|
| 466 | nRetVal = 0; |
|---|
| 467 | } |
|---|
| 468 | else |
|---|
| 469 | { |
|---|
| 470 | /*DSL_DEBUG( DSL_DBG_LOCAL, (pContext, |
|---|
| 471 | "DSL: Added timeout event (ListIdx=%d, nLine=%hu, nEventType=%d, " |
|---|
| 472 | "pListElement=0x%08X) successfully!" DSL_DRV_CRLF , nListIdx, nLine, nEventType, |
|---|
| 473 | (DSL_uint32_t)pListElement));*/ |
|---|
| 474 | } |
|---|
| 475 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 476 | |
|---|
| 477 | return nRetVal; |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | /* |
|---|
| 481 | This routine removes a given timeout element from the list of available |
|---|
| 482 | timeout elements and adds the (empty) element at the end of the list. |
|---|
| 483 | |
|---|
| 484 | \param pContext Pointer to dsl library context structure, [I] |
|---|
| 485 | \param nTimeoutID Identifies the timeout element ID. This unique value was |
|---|
| 486 | was also returned from the function |
|---|
| 487 | (\ref DSL_Timeout_AddEvent) which adds this event formerly. |
|---|
| 488 | If the first element from the list should be removed it is |
|---|
| 489 | also possible to set this value to 0, [I] |
|---|
| 490 | |
|---|
| 491 | \return |
|---|
| 492 | - DSL_Success Timeout event handled successfully |
|---|
| 493 | - DSL_Error Error during handling of timeout event |
|---|
| 494 | */ |
|---|
| 495 | DSL_Error_t DSL_DRV_Timeout_RemoveEvent( |
|---|
| 496 | DSL_Context_t *pContext, |
|---|
| 497 | DSL_uint32_t nTimeoutID) |
|---|
| 498 | { |
|---|
| 499 | DSL_TimeoutContext_t *pTCtx = &pContext->TimeoutListsContext; |
|---|
| 500 | DSL_TimeoutElement_t *pListElement = DSL_NULL; |
|---|
| 501 | DSL_TimeoutElement_t *pListTail = DSL_NULL; |
|---|
| 502 | DSL_TimeoutElement_t *pListRemoveElement = DSL_NULL; |
|---|
| 503 | DSL_TimeoutElement_t *pPreListElement = DSL_NULL; |
|---|
| 504 | DSL_TimeoutElement_t *pNextListElement = DSL_NULL; |
|---|
| 505 | DSL_boolean_t bFirst = DSL_FALSE, bLast = DSL_FALSE; |
|---|
| 506 | DSL_boolean_t bRemove = DSL_FALSE; |
|---|
| 507 | DSL_uint32_t i = 0; |
|---|
| 508 | |
|---|
| 509 | DSL_TIMEOUT_LIST_LOCK(); |
|---|
| 510 | pListElement = pTCtx->TimeoutList.pListHead; |
|---|
| 511 | pListRemoveElement = (DSL_TimeoutElement_t *)nTimeoutID; |
|---|
| 512 | |
|---|
| 513 | if (nTimeoutID == 0) |
|---|
| 514 | { |
|---|
| 515 | bFirst = DSL_TRUE; |
|---|
| 516 | bRemove = DSL_TRUE; |
|---|
| 517 | /* the first can also be the last */ |
|---|
| 518 | if (pTCtx->nNrOfElements == 1) |
|---|
| 519 | bLast = DSL_TRUE; |
|---|
| 520 | } |
|---|
| 521 | else |
|---|
| 522 | { |
|---|
| 523 | for (i = 0; i < pTCtx->nNrOfElements; i++) |
|---|
| 524 | { |
|---|
| 525 | if (pListElement == pListRemoveElement) |
|---|
| 526 | { |
|---|
| 527 | bRemove = DSL_TRUE; |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | if (bRemove == DSL_TRUE) |
|---|
| 531 | { |
|---|
| 532 | if (pListElement->pNext == DSL_NULL) |
|---|
| 533 | { |
|---|
| 534 | bLast = DSL_TRUE; |
|---|
| 535 | } |
|---|
| 536 | else if (pListElement->pPrevious == DSL_NULL) |
|---|
| 537 | { |
|---|
| 538 | bFirst = DSL_TRUE; |
|---|
| 539 | } |
|---|
| 540 | break; |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | pListElement = pListElement->pNext; |
|---|
| 544 | |
|---|
| 545 | if (pListElement == DSL_NULL) |
|---|
| 546 | { |
|---|
| 547 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 548 | DSL_DEBUG_SET_ERROR(DSL_ERROR); |
|---|
| 549 | DSL_DEBUG( DSL_DBG_ERR, (pContext, |
|---|
| 550 | "DSL[%02d]: Error in 'DSL_Timeout_RemoveEvent'- Element (" |
|---|
| 551 | "nTimeoutID=0x%08X) could not be removed (not found)!" DSL_DRV_CRLF , |
|---|
| 552 | DSL_DEV_NUM(pContext), nTimeoutID)); |
|---|
| 553 | |
|---|
| 554 | return DSL_ERROR; |
|---|
| 555 | } |
|---|
| 556 | } |
|---|
| 557 | } |
|---|
| 558 | |
|---|
| 559 | pListTail = pTCtx->TimeoutList.pListTail; |
|---|
| 560 | pPreListElement = pListElement->pPrevious; |
|---|
| 561 | pNextListElement = pListElement->pNext; |
|---|
| 562 | |
|---|
| 563 | if (bLast == DSL_TRUE) |
|---|
| 564 | { |
|---|
| 565 | /* Do nothing here because: |
|---|
| 566 | a) values will be reset afterwards |
|---|
| 567 | b) timeout element is already on right position (at the end) */ |
|---|
| 568 | } |
|---|
| 569 | else |
|---|
| 570 | { |
|---|
| 571 | if (bFirst == DSL_TRUE) |
|---|
| 572 | { |
|---|
| 573 | pTCtx->TimeoutList.pListHead = pNextListElement; |
|---|
| 574 | pNextListElement->pPrevious = DSL_NULL; |
|---|
| 575 | } |
|---|
| 576 | else |
|---|
| 577 | { |
|---|
| 578 | /* Intermediate */ |
|---|
| 579 | pPreListElement->pNext = pNextListElement; |
|---|
| 580 | pNextListElement->pPrevious = pPreListElement; |
|---|
| 581 | } |
|---|
| 582 | |
|---|
| 583 | pListTail->pNext = pListElement; |
|---|
| 584 | pListElement->pPrevious = pListTail; |
|---|
| 585 | pListElement->pNext = DSL_NULL; |
|---|
| 586 | pTCtx->TimeoutList.pListTail = pListElement; |
|---|
| 587 | } |
|---|
| 588 | |
|---|
| 589 | /*DSL_DEBUG( DSL_DBG_LOCAL, (pContext, |
|---|
| 590 | "DSL: Removed timeout event (ListIdx=%d, nLine=%hu, nEventType=%d, " |
|---|
| 591 | "pListElement=0x%08X) successfully!" DSL_DRV_CRLF , |
|---|
| 592 | nListIdx, pListElement->nLine, pListElement->nEventType, |
|---|
| 593 | (DSL_uint32_t)pListElement));*/ |
|---|
| 594 | |
|---|
| 595 | /* Reset content of timeout element */ |
|---|
| 596 | pListElement->bValid = DSL_FALSE; |
|---|
| 597 | |
|---|
| 598 | pListElement->nStartTime = 0x0; |
|---|
| 599 | pListElement->nTimeout = 0; |
|---|
| 600 | pListElement->nStopTime = 0x0; |
|---|
| 601 | pListElement->nEventType = 0; |
|---|
| 602 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 603 | |
|---|
| 604 | return DSL_SUCCESS; |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | /* |
|---|
| 608 | This routine removes valid element from the list of available |
|---|
| 609 | timeout elements. |
|---|
| 610 | |
|---|
| 611 | \param pContext Pointer to dsl library context structure, [I] |
|---|
| 612 | |
|---|
| 613 | \return |
|---|
| 614 | - DSL_Success in case of success |
|---|
| 615 | - DSL_Error if operation failed |
|---|
| 616 | */ |
|---|
| 617 | DSL_Error_t DSL_DRV_Timeout_RemoveAllEvents( DSL_Context_t *pContext ) |
|---|
| 618 | { |
|---|
| 619 | DSL_TimeoutContext_t *pTCtx = &pContext->TimeoutListsContext; |
|---|
| 620 | DSL_TimeoutElement_t *pListElement = DSL_NULL; |
|---|
| 621 | |
|---|
| 622 | pListElement = pTCtx->TimeoutList.pListHead; |
|---|
| 623 | |
|---|
| 624 | DSL_TIMEOUT_LIST_LOCK(); |
|---|
| 625 | while (pListElement != DSL_NULL) |
|---|
| 626 | { |
|---|
| 627 | /* skip not valid */ |
|---|
| 628 | if (pListElement->bValid == DSL_FALSE) |
|---|
| 629 | { |
|---|
| 630 | pListElement = pListElement->pNext; |
|---|
| 631 | continue; |
|---|
| 632 | } |
|---|
| 633 | /* Reset content of timeout element */ |
|---|
| 634 | pListElement->bValid = DSL_FALSE; |
|---|
| 635 | pListElement->nStartTime = 0x0; |
|---|
| 636 | pListElement->nTimeout = 0; |
|---|
| 637 | pListElement->nStopTime = 0x0; |
|---|
| 638 | pListElement->nEventType = 0; |
|---|
| 639 | |
|---|
| 640 | pListElement = pListElement->pNext; |
|---|
| 641 | }; |
|---|
| 642 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 643 | |
|---|
| 644 | return DSL_SUCCESS; |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 647 | #ifndef DSL_DEBUG_DISABLE |
|---|
| 648 | /* |
|---|
| 649 | Print out contents of timout context structure and all of its timeout element |
|---|
| 650 | list content. |
|---|
| 651 | \note This function is implemented for debug purpose only. |
|---|
| 652 | |
|---|
| 653 | \param pContext Pointer to dsl library context structure, [I] |
|---|
| 654 | |
|---|
| 655 | \return |
|---|
| 656 | Return values are defined within the DSL_Error_t definition |
|---|
| 657 | - DSL_SUCCESS in case of success |
|---|
| 658 | - DSL_ERROR if operation failed |
|---|
| 659 | */ |
|---|
| 660 | DSL_Error_t DSL_DRV_Timeout_Debug_PrintTimeoutList( |
|---|
| 661 | DSL_Context_t *pContext) |
|---|
| 662 | { |
|---|
| 663 | DSL_TimeoutContext_t *pTCtx = &pContext->TimeoutListsContext; |
|---|
| 664 | DSL_TimeoutElement_t *pListElement = DSL_NULL; |
|---|
| 665 | DSL_TimeoutElement_t *pNextListElement = DSL_NULL; |
|---|
| 666 | DSL_uint32_t j = 0; |
|---|
| 667 | DSL_boolean_t bEnd = DSL_FALSE; |
|---|
| 668 | |
|---|
| 669 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 670 | (pContext, "DSL[%02d]: ****** Content of timeout event list ******" DSL_DRV_CRLF, |
|---|
| 671 | DSL_DEV_NUM(pContext))); |
|---|
| 672 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 673 | (pContext, "DSL[%02d]: nNrOfElements=%d" DSL_DRV_CRLF, |
|---|
| 674 | DSL_DEV_NUM(pContext), pTCtx->nNrOfElements)); |
|---|
| 675 | |
|---|
| 676 | |
|---|
| 677 | DSL_TIMEOUT_LIST_LOCK(); |
|---|
| 678 | |
|---|
| 679 | pListElement = pTCtx->TimeoutList.pListHead; |
|---|
| 680 | |
|---|
| 681 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 682 | (pContext, "DSL[%02d]: Content of list" DSL_DRV_CRLF, DSL_DEV_NUM(pContext))); |
|---|
| 683 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 684 | (pContext, "DSL[%02d]: pListHead=0x%08X" DSL_DRV_CRLF, |
|---|
| 685 | DSL_DEV_NUM(pContext), (DSL_uint32_t)(pTCtx->TimeoutList.pListHead))); |
|---|
| 686 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 687 | (pContext, "DSL[%02d]: pListTail=0x%08X" DSL_DRV_CRLF, |
|---|
| 688 | DSL_DEV_NUM(pContext), (DSL_uint32_t)(pTCtx->TimeoutList.pListTail))); |
|---|
| 689 | |
|---|
| 690 | for (j = 0; j < pTCtx->nNrOfElements; j++) |
|---|
| 691 | { |
|---|
| 692 | pNextListElement = pListElement->pNext; |
|---|
| 693 | |
|---|
| 694 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 695 | (pContext, "DSL[%02d]: Content of element %d" DSL_DRV_CRLF, |
|---|
| 696 | DSL_DEV_NUM(pContext), j)); |
|---|
| 697 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 698 | (pContext, "DSL[%02d]: pList=0x%08X" DSL_DRV_CRLF, |
|---|
| 699 | DSL_DEV_NUM(pContext), (DSL_uint32_t)(pListElement))); |
|---|
| 700 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 701 | (pContext, "DSL[%02d]: pPrevious=0x%08X" DSL_DRV_CRLF, |
|---|
| 702 | DSL_DEV_NUM(pContext), (DSL_uint32_t)(pListElement->pPrevious))); |
|---|
| 703 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 704 | (pContext, "DSL[%02d]: pNext=0x%08X" DSL_DRV_CRLF, |
|---|
| 705 | DSL_DEV_NUM(pContext), (DSL_uint32_t)(pListElement->pNext))); |
|---|
| 706 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 707 | (pContext, "DSL[%02d]: bValid=%d" DSL_DRV_CRLF, |
|---|
| 708 | DSL_DEV_NUM(pContext), (DSL_int_t)(pListElement->bValid))); |
|---|
| 709 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 710 | (pContext, "DSL[%02d]: nStartTime=%u" DSL_DRV_CRLF, |
|---|
| 711 | DSL_DEV_NUM(pContext), pListElement->nStartTime)); |
|---|
| 712 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 713 | (pContext, "DSL[%02d]: nTimeout=%u" DSL_DRV_CRLF, |
|---|
| 714 | DSL_DEV_NUM(pContext), pListElement->nTimeout)); |
|---|
| 715 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 716 | (pContext, "DSL[%02d]: nStopTime=%u" DSL_DRV_CRLF, |
|---|
| 717 | DSL_DEV_NUM(pContext), pListElement->nStopTime)); |
|---|
| 718 | DSL_DEBUG(DSL_DBG_MSG, |
|---|
| 719 | (pContext, "DSL[%02d]: nEventType=%d" DSL_DRV_CRLF, |
|---|
| 720 | DSL_DEV_NUM(pContext), pListElement->nEventType)); |
|---|
| 721 | |
|---|
| 722 | if (bEnd == DSL_TRUE) |
|---|
| 723 | { |
|---|
| 724 | break; |
|---|
| 725 | } |
|---|
| 726 | |
|---|
| 727 | pListElement = pNextListElement; |
|---|
| 728 | |
|---|
| 729 | if (pListElement->pNext == DSL_NULL) |
|---|
| 730 | { |
|---|
| 731 | bEnd = DSL_TRUE; |
|---|
| 732 | } |
|---|
| 733 | } |
|---|
| 734 | |
|---|
| 735 | DSL_TIMEOUT_LIST_UNLOCK(); |
|---|
| 736 | |
|---|
| 737 | return DSL_SUCCESS; |
|---|
| 738 | } |
|---|
| 739 | #endif /* DSL_DEBUG_DISABLE*/ |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | /** @} DRV_DSL_CPE_COMMON */ |
|---|
| 743 | |
|---|
| 744 | #endif /* defined(INCLUDE_DSL_CPE_API_VINAX) || (defined(INCLUDE_DSL_CPE_API_DANUBE) && defined(INCLUDE_DSL_G997_LINE_INVENTORY))*/ |
|---|