Skip to content

Commit 51437bf

Browse files
chinglee-iotUbuntuaggarg
authored
Fix MISRA C 2012 rule 8.6 errors (FreeRTOS#862)
* Fix MISRA C 2012 rule 8.6 errors * Add suppression for hook function Signed-off-by: Gaurav Aggarwal <[email protected]> --------- Signed-off-by: Gaurav Aggarwal <[email protected]> Co-authored-by: Ubuntu <[email protected]> Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]> Co-authored-by: Gaurav Aggarwal <[email protected]>
1 parent 55094e2 commit 51437bf

File tree

5 files changed

+203
-89
lines changed

5 files changed

+203
-89
lines changed

MISRA.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ grep 'MISRA Ref 8.4.1' . -rI
2121
#### Rule 8.4
2222

2323
MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an
24-
object or function with external linkage is defined.
24+
object or function with external linkage is defined.
2525

2626
_Ref 8.4.1_
2727
- pxCurrentTCB(s) is defined with external linkage but it is only referenced
@@ -34,6 +34,17 @@ _Ref 8.4.2_
3434
kernel unit tests. It is not meant to be directly accessed by the application
3535
and therefore, not declared in a header file.
3636

37+
38+
#### Rule 8.6
39+
40+
MISRA C:2012 Rule 8.6: An identifier with external linkage shall have exactly
41+
one external definition.
42+
43+
_Ref 8.6.1_
44+
- This rule prohibits an identifier with external linkage to have multiple
45+
definitions or no definition. FreeRTOS hook functions are implemented in
46+
the application and therefore, have no definition in the Kernel code.
47+
3748
#### Rule 11.3
3849

3950
MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to

include/queue.h

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,8 @@ BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FU
14551455
BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
14561456
UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
14571457

1458+
#if ( configUSE_CO_ROUTINES == 1 )
1459+
14581460
/*
14591461
* The functions defined above are for passing data to and from tasks. The
14601462
* functions below are the equivalents for passing data to and from
@@ -1464,36 +1466,51 @@ UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEG
14641466
* should not be called directly from application code. Instead use the macro
14651467
* wrappers defined within croutine.h.
14661468
*/
1467-
BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue,
1468-
const void * pvItemToQueue,
1469-
BaseType_t xCoRoutinePreviouslyWoken );
1470-
BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue,
1471-
void * pvBuffer,
1472-
BaseType_t * pxTaskWoken );
1473-
BaseType_t xQueueCRSend( QueueHandle_t xQueue,
1474-
const void * pvItemToQueue,
1475-
TickType_t xTicksToWait );
1476-
BaseType_t xQueueCRReceive( QueueHandle_t xQueue,
1477-
void * pvBuffer,
1478-
TickType_t xTicksToWait );
1469+
BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue,
1470+
const void * pvItemToQueue,
1471+
BaseType_t xCoRoutinePreviouslyWoken );
1472+
BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue,
1473+
void * pvBuffer,
1474+
BaseType_t * pxTaskWoken );
1475+
BaseType_t xQueueCRSend( QueueHandle_t xQueue,
1476+
const void * pvItemToQueue,
1477+
TickType_t xTicksToWait );
1478+
BaseType_t xQueueCRReceive( QueueHandle_t xQueue,
1479+
void * pvBuffer,
1480+
TickType_t xTicksToWait );
1481+
1482+
#endif /* if ( configUSE_CO_ROUTINES == 1 ) */
14791483

14801484
/*
14811485
* For internal use only. Use xSemaphoreCreateMutex(),
14821486
* xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
14831487
* these functions directly.
14841488
*/
14851489
QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1486-
QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
1487-
StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1488-
QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
1489-
const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1490-
QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
1491-
const UBaseType_t uxInitialCount,
1492-
StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1490+
1491+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1492+
QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
1493+
StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1494+
#endif
1495+
1496+
#if ( configUSE_COUNTING_SEMAPHORES == 1 )
1497+
QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
1498+
const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1499+
#endif
1500+
1501+
#if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
1502+
QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
1503+
const UBaseType_t uxInitialCount,
1504+
StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
1505+
#endif
1506+
14931507
BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
14941508
TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1495-
TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1496-
TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1509+
1510+
#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
1511+
TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1512+
TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1513+
#endif
14971514

14981515
/*
14991516
* For internal use only. Use xSemaphoreTakeMutexRecursive() or
@@ -1653,7 +1670,9 @@ BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
16531670
* @return If the queue set is created successfully then a handle to the created
16541671
* queue set is returned. Otherwise NULL is returned.
16551672
*/
1656-
QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1673+
#if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
1674+
QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1675+
#endif
16571676

16581677
/*
16591678
* Adds a queue or semaphore to a queue set that was previously created by a
@@ -1677,8 +1696,10 @@ QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILE
16771696
* queue set because it is already a member of a different queue set then pdFAIL
16781697
* is returned.
16791698
*/
1680-
BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1681-
QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1699+
#if ( configUSE_QUEUE_SETS == 1 )
1700+
BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1701+
QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1702+
#endif
16821703

16831704
/*
16841705
* Removes a queue or semaphore from a queue set. A queue or semaphore can only
@@ -1697,8 +1718,10 @@ BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
16971718
* then pdPASS is returned. If the queue was not in the queue set, or the
16981719
* queue (or semaphore) was not empty, then pdFAIL is returned.
16991720
*/
1700-
BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1701-
QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1721+
#if ( configUSE_QUEUE_SETS == 1 )
1722+
BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
1723+
QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1724+
#endif
17021725

17031726
/*
17041727
* xQueueSelectFromSet() selects from the members of a queue set a queue or
@@ -1734,24 +1757,38 @@ BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
17341757
* in the queue set that is available, or NULL if no such queue or semaphore
17351758
* exists before before the specified block time expires.
17361759
*/
1737-
QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
1738-
const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1760+
#if ( configUSE_QUEUE_SETS == 1 )
1761+
QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
1762+
const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1763+
#endif
17391764

17401765
/*
17411766
* A version of xQueueSelectFromSet() that can be used from an ISR.
17421767
*/
1743-
QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1768+
#if ( configUSE_QUEUE_SETS == 1 )
1769+
QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1770+
#endif
17441771

17451772
/* Not public API functions. */
17461773
void vQueueWaitForMessageRestricted( QueueHandle_t xQueue,
17471774
TickType_t xTicksToWait,
17481775
const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
17491776
BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
17501777
BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1751-
void vQueueSetQueueNumber( QueueHandle_t xQueue,
1752-
UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1753-
UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1754-
uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1778+
1779+
#if ( configUSE_TRACE_FACILITY == 1 )
1780+
void vQueueSetQueueNumber( QueueHandle_t xQueue,
1781+
UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1782+
#endif
1783+
1784+
#if ( configUSE_TRACE_FACILITY == 1 )
1785+
UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1786+
#endif
1787+
1788+
#if ( configUSE_TRACE_FACILITY == 1 )
1789+
uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1790+
#endif
1791+
17551792
UBaseType_t uxQueueGetQueueItemSize( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
17561793
UBaseType_t uxQueueGetQueueLength( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
17571794

include/stream_buffer.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -918,14 +918,15 @@ StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes,
918918
StreamBufferCallbackFunction_t pxSendCompletedCallback,
919919
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
920920

921-
922-
StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
923-
size_t xTriggerLevelBytes,
924-
BaseType_t xIsMessageBuffer,
925-
uint8_t * const pucStreamBufferStorageArea,
926-
StaticStreamBuffer_t * const pxStaticStreamBuffer,
927-
StreamBufferCallbackFunction_t pxSendCompletedCallback,
928-
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
921+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
922+
StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
923+
size_t xTriggerLevelBytes,
924+
BaseType_t xIsMessageBuffer,
925+
uint8_t * const pucStreamBufferStorageArea,
926+
StaticStreamBuffer_t * const pxStaticStreamBuffer,
927+
StreamBufferCallbackFunction_t pxSendCompletedCallback,
928+
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
929+
#endif
929930

930931
size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
931932

0 commit comments

Comments
 (0)