|
257 | 257 | configSTACK_DEPTH_TYPE uxTimerTaskStackSize; |
258 | 258 |
|
259 | 259 | vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &uxTimerTaskStackSize ); |
260 | | - xTimerTaskHandle = xTaskCreateStaticAffinitySet( prvTimerTask, |
| 260 | + xTimerTaskHandle = xTaskCreateStaticAffinitySet( &prvTimerTask, |
261 | 261 | configTIMER_SERVICE_TASK_NAME, |
262 | 262 | uxTimerTaskStackSize, |
263 | 263 | NULL, |
|
273 | 273 | } |
274 | 274 | #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ |
275 | 275 | { |
276 | | - xReturn = xTaskCreateAffinitySet( prvTimerTask, |
| 276 | + xReturn = xTaskCreateAffinitySet( &prvTimerTask, |
277 | 277 | configTIMER_SERVICE_TASK_NAME, |
278 | 278 | configTIMER_TASK_STACK_DEPTH, |
279 | 279 | NULL, |
|
292 | 292 | configSTACK_DEPTH_TYPE uxTimerTaskStackSize; |
293 | 293 |
|
294 | 294 | vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &uxTimerTaskStackSize ); |
295 | | - xTimerTaskHandle = xTaskCreateStatic( prvTimerTask, |
| 295 | + xTimerTaskHandle = xTaskCreateStatic( &prvTimerTask, |
296 | 296 | configTIMER_SERVICE_TASK_NAME, |
297 | 297 | uxTimerTaskStackSize, |
298 | 298 | NULL, |
|
307 | 307 | } |
308 | 308 | #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ |
309 | 309 | { |
310 | | - xReturn = xTaskCreate( prvTimerTask, |
| 310 | + xReturn = xTaskCreate( &prvTimerTask, |
311 | 311 | configTIMER_SERVICE_TASK_NAME, |
312 | 312 | configTIMER_TASK_STACK_DEPTH, |
313 | 313 | NULL, |
|
458 | 458 |
|
459 | 459 | traceENTER_xTimerGenericCommandFromTask( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); |
460 | 460 |
|
461 | | - configASSERT( xTimer ); |
462 | | - |
463 | 461 | /* Send a message to the timer service task to perform a particular action |
464 | 462 | * on a particular timer definition. */ |
465 | | - if( xTimerQueue != NULL ) |
| 463 | + if( ( xTimerQueue != NULL ) && ( xTimer != NULL ) ) |
466 | 464 | { |
467 | 465 | /* Send a command to the timer service task to start the xTimer timer. */ |
468 | 466 | xMessage.xMessageID = xCommandID; |
|
509 | 507 |
|
510 | 508 | traceENTER_xTimerGenericCommandFromISR( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); |
511 | 509 |
|
512 | | - configASSERT( xTimer ); |
513 | | - |
514 | 510 | /* Send a message to the timer service task to perform a particular action |
515 | 511 | * on a particular timer definition. */ |
516 | | - if( xTimerQueue != NULL ) |
| 512 | + if( ( xTimerQueue != NULL ) && ( xTimer != NULL ) ) |
517 | 513 | { |
518 | 514 | /* Send a command to the timer service task to start the xTimer timer. */ |
519 | 515 | xMessage.xMessageID = xCommandID; |
|
974 | 970 | * software timer. */ |
975 | 971 | pxTimer = xMessage.u.xTimerParameters.pxTimer; |
976 | 972 |
|
977 | | - if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) |
| 973 | + if( pxTimer != NULL ) |
978 | 974 | { |
979 | | - /* The timer is in a list, remove it. */ |
980 | | - ( void ) uxListRemove( &( pxTimer->xTimerListItem ) ); |
981 | | - } |
982 | | - else |
983 | | - { |
984 | | - mtCOVERAGE_TEST_MARKER(); |
985 | | - } |
| 975 | + if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) |
| 976 | + { |
| 977 | + /* The timer is in a list, remove it. */ |
| 978 | + ( void ) uxListRemove( &( pxTimer->xTimerListItem ) ); |
| 979 | + } |
| 980 | + else |
| 981 | + { |
| 982 | + mtCOVERAGE_TEST_MARKER(); |
| 983 | + } |
986 | 984 |
|
987 | | - traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue ); |
| 985 | + traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue ); |
988 | 986 |
|
989 | | - /* In this case the xTimerListsWereSwitched parameter is not used, but |
990 | | - * it must be present in the function call. prvSampleTimeNow() must be |
991 | | - * called after the message is received from xTimerQueue so there is no |
992 | | - * possibility of a higher priority task adding a message to the message |
993 | | - * queue with a time that is ahead of the timer daemon task (because it |
994 | | - * pre-empted the timer daemon task after the xTimeNow value was set). */ |
995 | | - xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); |
| 987 | + /* In this case the xTimerListsWereSwitched parameter is not used, but |
| 988 | + * it must be present in the function call. prvSampleTimeNow() must be |
| 989 | + * called after the message is received from xTimerQueue so there is no |
| 990 | + * possibility of a higher priority task adding a message to the message |
| 991 | + * queue with a time that is ahead of the timer daemon task (because it |
| 992 | + * pre-empted the timer daemon task after the xTimeNow value was set). */ |
| 993 | + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); |
996 | 994 |
|
997 | | - switch( xMessage.xMessageID ) |
998 | | - { |
999 | | - case tmrCOMMAND_START: |
1000 | | - case tmrCOMMAND_START_FROM_ISR: |
1001 | | - case tmrCOMMAND_RESET: |
1002 | | - case tmrCOMMAND_RESET_FROM_ISR: |
1003 | | - /* Start or restart a timer. */ |
1004 | | - pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_ACTIVE; |
1005 | | - |
1006 | | - if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE ) |
1007 | | - { |
1008 | | - /* The timer expired before it was added to the active |
1009 | | - * timer list. Process it now. */ |
1010 | | - if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0U ) |
| 995 | + switch( xMessage.xMessageID ) |
| 996 | + { |
| 997 | + case tmrCOMMAND_START: |
| 998 | + case tmrCOMMAND_START_FROM_ISR: |
| 999 | + case tmrCOMMAND_RESET: |
| 1000 | + case tmrCOMMAND_RESET_FROM_ISR: |
| 1001 | + /* Start or restart a timer. */ |
| 1002 | + pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_ACTIVE; |
| 1003 | + |
| 1004 | + if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE ) |
1011 | 1005 | { |
1012 | | - prvReloadTimer( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow ); |
| 1006 | + /* The timer expired before it was added to the active |
| 1007 | + * timer list. Process it now. */ |
| 1008 | + if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0U ) |
| 1009 | + { |
| 1010 | + prvReloadTimer( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow ); |
| 1011 | + } |
| 1012 | + else |
| 1013 | + { |
| 1014 | + pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE ); |
| 1015 | + } |
| 1016 | + |
| 1017 | + /* Call the timer callback. */ |
| 1018 | + traceTIMER_EXPIRED( pxTimer ); |
| 1019 | + pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); |
1013 | 1020 | } |
1014 | 1021 | else |
1015 | 1022 | { |
1016 | | - pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE ); |
| 1023 | + mtCOVERAGE_TEST_MARKER(); |
1017 | 1024 | } |
1018 | 1025 |
|
1019 | | - /* Call the timer callback. */ |
1020 | | - traceTIMER_EXPIRED( pxTimer ); |
1021 | | - pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); |
1022 | | - } |
1023 | | - else |
1024 | | - { |
1025 | | - mtCOVERAGE_TEST_MARKER(); |
1026 | | - } |
1027 | | - |
1028 | | - break; |
1029 | | - |
1030 | | - case tmrCOMMAND_STOP: |
1031 | | - case tmrCOMMAND_STOP_FROM_ISR: |
1032 | | - /* The timer has already been removed from the active list. */ |
1033 | | - pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE ); |
1034 | | - break; |
1035 | | - |
1036 | | - case tmrCOMMAND_CHANGE_PERIOD: |
1037 | | - case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR: |
1038 | | - pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_ACTIVE; |
1039 | | - pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue; |
1040 | | - configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) ); |
1041 | | - |
1042 | | - /* The new period does not really have a reference, and can |
1043 | | - * be longer or shorter than the old one. The command time is |
1044 | | - * therefore set to the current time, and as the period cannot |
1045 | | - * be zero the next expiry time can only be in the future, |
1046 | | - * meaning (unlike for the xTimerStart() case above) there is |
1047 | | - * no fail case that needs to be handled here. */ |
1048 | | - ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow ); |
1049 | | - break; |
1050 | | - |
1051 | | - case tmrCOMMAND_DELETE: |
1052 | | - #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) |
1053 | | - { |
1054 | | - /* The timer has already been removed from the active list, |
1055 | | - * just free up the memory if the memory was dynamically |
1056 | | - * allocated. */ |
1057 | | - if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0 ) |
| 1026 | + break; |
| 1027 | + |
| 1028 | + case tmrCOMMAND_STOP: |
| 1029 | + case tmrCOMMAND_STOP_FROM_ISR: |
| 1030 | + /* The timer has already been removed from the active list. */ |
| 1031 | + pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE ); |
| 1032 | + break; |
| 1033 | + |
| 1034 | + case tmrCOMMAND_CHANGE_PERIOD: |
| 1035 | + case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR: |
| 1036 | + pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_ACTIVE; |
| 1037 | + pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue; |
| 1038 | + configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) ); |
| 1039 | + |
| 1040 | + /* The new period does not really have a reference, and can |
| 1041 | + * be longer or shorter than the old one. The command time is |
| 1042 | + * therefore set to the current time, and as the period cannot |
| 1043 | + * be zero the next expiry time can only be in the future, |
| 1044 | + * meaning (unlike for the xTimerStart() case above) there is |
| 1045 | + * no fail case that needs to be handled here. */ |
| 1046 | + ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow ); |
| 1047 | + break; |
| 1048 | + |
| 1049 | + case tmrCOMMAND_DELETE: |
| 1050 | + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) |
1058 | 1051 | { |
1059 | | - vPortFree( pxTimer ); |
| 1052 | + /* The timer has already been removed from the active list, |
| 1053 | + * just free up the memory if the memory was dynamically |
| 1054 | + * allocated. */ |
| 1055 | + if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0 ) |
| 1056 | + { |
| 1057 | + vPortFree( pxTimer ); |
| 1058 | + } |
| 1059 | + else |
| 1060 | + { |
| 1061 | + pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE ); |
| 1062 | + } |
1060 | 1063 | } |
1061 | | - else |
| 1064 | + #else /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */ |
1062 | 1065 | { |
| 1066 | + /* If dynamic allocation is not enabled, the memory |
| 1067 | + * could not have been dynamically allocated. So there is |
| 1068 | + * no need to free the memory - just mark the timer as |
| 1069 | + * "not active". */ |
1063 | 1070 | pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE ); |
1064 | 1071 | } |
1065 | | - } |
1066 | | - #else /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */ |
1067 | | - { |
1068 | | - /* If dynamic allocation is not enabled, the memory |
1069 | | - * could not have been dynamically allocated. So there is |
1070 | | - * no need to free the memory - just mark the timer as |
1071 | | - * "not active". */ |
1072 | | - pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE ); |
1073 | | - } |
1074 | | - #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ |
1075 | | - break; |
| 1072 | + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ |
| 1073 | + break; |
1076 | 1074 |
|
1077 | | - default: |
1078 | | - /* Don't expect to get here. */ |
1079 | | - break; |
| 1075 | + default: |
| 1076 | + /* Don't expect to get here. */ |
| 1077 | + break; |
| 1078 | + } |
| 1079 | + } |
| 1080 | + else |
| 1081 | + { |
| 1082 | + mtCOVERAGE_TEST_MARKER(); |
1080 | 1083 | } |
1081 | 1084 | } |
1082 | 1085 | } |
|
0 commit comments