FreeRTOS 的命名规则
文章目錄
- 變量
- 函數
- 宏定義
- 結語
如果是剛接觸 FreeRTOS,看到它的命名,簡直是匪夷所思,猶如天書。所以,還是有必要了解它的命名規則。
變量
uint32_t 定義的變量都加上前綴 ul。 u 代表 unsigned 無符號,l 代表 long 長整型。
例如:
static portFORCE_INLINE uint32_t Atomic_CompareAndSwap_u32( uint32_t volatile * pulDestination,uint32_t ulExchange,uint32_t ulComparand )ulExchange,ulComparand 就是這樣
uint16_t 定義的變量都加上前綴 us。 u 代表 unsigned 無符號,s 代表 short 短整型。
例如: const uint16_t usStackDepth
uint8_t 定義的變量都加上前綴 uc。 u 代表 unsigned 無符號,c 代表 char 字符型。
例如:
#if ( configUSE_TASK_NOTIFICATIONS == 1 )uint32_t ulDummy18[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];uint8_t ucDummy19[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];#endif#if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )uint8_t uxDummy20;#endifucDummy19 就是這樣;
但是我不明白,uxDiummy20 為啥就用的 ux 呢?
int 定義的變量加上前綴 i。i 代表 int
例如:int iTaskErrno;
stdint.h 文件中未定義的變量類型,在定義變量時需要加上前綴 x.
例如:
BaseType_t xCoRoutinePreviouslyWoken
MiniListItem_t xListEnd
stdint.h 文件中未定義的無符號變量類型,在定義變量時要加上前綴 u,比如 UBaseType_t 定義
的變量要加上前綴 ux。
例如:
typedef unsigned long UBaseType_t;
UBaseType_t uxPriority;
枚舉變量會加上前綴 e。
例如:
typedef enum {eRunning = 0, /* A task is querying the state of itself, so must be running. */eReady, /* The task being queried is in a ready or pending ready list. */eBlocked, /* The task being queried is in the Blocked state. */eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */eInvalid /* Used as an 'invalid state' value. */ } eTaskState;eTaskState eState;指針變量會加上前綴 p。
例如:
TCB_t * pxTCB;
uint8_t * pucQueueStorage; // 因為是無符號,所以是 pu
根據 MISRA (The Motor Industry Software Reliability Association,中文名稱為汽車工業軟件可靠性聯會)代碼規則,char 定義的變量只能用于 ASCII 字符,前綴使用 c。
例如:
char cRxedChar;
根據 MISRA 代碼規則,**char *** 定義的指針變量只能用于 ASCII 字符串,前綴使用 pc。
例如:
char *pcStringToSend;
函數
加上了 static 聲明的函數,定義時要加上前綴 prv(單詞 private 的縮寫)。
例如:
static void prvInitialiseCoRoutineLists( void );
帶有返回值的函數,根據返回值的數據類型,加上相應的前綴,如果沒有返回值,即 void 類型,函數的前綴加上字母 v。
例如:
BaseType_t xQueueGenericReset( QueueHandle_t xQueue,BaseType_t xNewQueue );#define configRUN_TIME_COUNTER_TYPE uint32_t configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void );StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,StackType_t * pxEndOfStack,TaskFunction_t pxCode,void * pvParameters,BaseType_t xRunPrivileged );const char * pcQueueGetName( QueueHandle_t xQueue );根據文件名,文件中相應的函數定義時可能會將文件名加到函數命名中,比如 tasks.c 文件中函數
vTaskDelete,函數中的 task 就是文件名中的 task。
宏定義
根據宏定義所在的文件,文件中的宏定義聲明時也將文件名加到宏定義中,比如宏定義
configUSE_PREEMPTION 是定義在文件 FreeRTOSConfig.h 里面。 宏定義中的 config 就是文
件名中的 config。 另外注意,前綴要小寫。
除了前綴,其余部分全部大寫,同時用下劃線分開。
例如:
// include\queue.h #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )// include\list.h #define listINSERT_END( pxList, pxNewListItem ) \{ \ListItem_t * const pxIndex = ( pxList )->pxIndex; \...// include\timers.h #define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )// include\croutine.h #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) \xQueueCRReceiveFromISR( ( pxQueue ), ( pvBuffer ), ( pxCoRoutineWoken ) )結語
如果你仔細研究 FreeRTOS 的命名,也會看到有些地方不符合上面的規則。
不知道作者是怎么想的,反正我是不喜歡這樣的命名。
參考資料
FreeRTOS的編碼標準和命名風格 - 菜鳥學院
總結
以上是生活随笔為你收集整理的FreeRTOS 的命名规则的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle12c 不添加host,Or
- 下一篇: sizeof 的结果取决于什么