FreeRTOS匈牙利符号 [英] FreeRTOS Hungarian Notation
问题描述
我是RTOS和C编程领域的一名新手,但我仍然习惯于C的良好实践.因此,我打开了一个使用FreeRTOS的项目,并且我注意到OS文件使用匈牙利表示法.我对这种符号有点了解,但是在FreeRTOS.h
文件中遇到了一些新的标准",即:
#ifndef configASSERT
#define configASSERT( x )
#define configASSERT_DEFINED 0
#else
#define configASSERT_DEFINED 1
#endif
在此之下,
#ifndef INCLUDE_xTaskGetSchedulerState
#define INCLUDE_xTaskGetSchedulerState 0
#endif
#ifndef INCLUDE_xTaskGetCurrentTaskHandle
#define INCLUDE_xTaskGetCurrentTaskHandle 0
#endif
我在所有地方都看到过 x -在 x TaskGetCurrentTaskHandle 中.此外, v , pd 和类似的变量名,例如所讨论的标题的728
行:
#if configENABLE_BACKWARD_COMPATIBILITY == 1
#define eTaskStateGet eTaskGetState
#define portTickType TickType_t
#define xTaskHandle TaskHandle_t
#define xQueueHandle QueueHandle_t
#define xSemaphoreHandle SemaphoreHandle_t
#define xQueueSetHandle QueueSetHandle_t
#define xQueueSetMemberHandle QueueSetMemberHandle_t
#define xTimeOutType TimeOut_t
#define xMemoryRegion MemoryRegion_t
#define xTaskParameters TaskParameters_t
#define xTaskStatusType TaskStatus_t
#define xTimerHandle TimerHandle_t
#define xCoRoutineHandle CoRoutineHandle_t
#define pdTASK_HOOK_CODE TaskHookFunction_t
#define portTICK_RATE_MS portTICK_PERIOD_MS
/* Backward compatibility within the scheduler code only - these definitions
are not really required but are included for completeness. */
#define tmrTIMER_CALLBACK TimerCallbackFunction_t
#define pdTASK_CODE TaskFunction_t
#define xListItem ListItem_t
#define xList List_t
我到处都在搜索那些缩写"代表什么,但仍然无法弄清楚.
因此,如果有人可以帮助我理解这一点,或者向我展示一条道路或其他东西,我将非常感激.
查看那个人
命名约定
RTOS内核和演示应用程序源代码使用以下约定:
变量
类型为
uint32_t
的变量以 ul 为前缀,其中'u'表示unsigned
,而'l'表示long
.类型为
uint16_t
的变量以 us 为前缀,其中'u'表示'unsigned','s'表示short
.类型为
uint8_t
的变量带有前缀 uc ,其中'u'表示无符号",而"c"表示char
./p>- 非stdint类型的
非标准类型的变量以x 为前缀.示例包括
BaseType_t
和TickType_t
,它们是体系结构的自然或最有效类型的便携式层定义的typedef,以及分别用于保存RTOS滴答计数的类型.
Unsigned
变量具有附加的前缀 u .例如,类型UBaseType_t
(unsigned BaseType_t
)的变量前缀为 ux .类型为
size_t
的变量也以 x 为前缀.枚举变量的前缀为 e
指针有一个附加的前缀 p ,例如,指向
uint16_t
的指针将具有前缀 pus .与MISRA指南一致,不合格的标准字符类型仅允许保留
ASCII characters
并以 c 为前缀.与MISRA指南一致,类型
char *
的变量只允许保存指向ASCII strings
的指针,并以 pc 为前缀.
强调我的
功能
- 根据为变量定义的约定,
文件范围静态(私有)函数的前缀为prv.
API函数以返回类型为前缀,并为
void
添加前缀 v .API函数名称以定义它们的文件的名称开头.例如,
vTaskDelete
是在task.c中定义的,并且具有void
返回类型.
强调我的
宏
宏在定义它们的文件中预先固定. 前缀为小写.例如,
configUSE_PREEMPTION
是在FreeRTOSConfig.h中定义的.除前缀之外,宏均以大写形式书写,并使用下划线分隔单词.
强调我的
I'm a complete newbie in RTOS and C programming, and I'm still getting used to the C good practices yet. So I opened a project which uses FreeRTOS, and I notice that the OS files use the Hungarian Notation. I know the notation a little, but faced some new "standards" in the FreeRTOS.h
file, which are:
#ifndef configASSERT
#define configASSERT( x )
#define configASSERT_DEFINED 0
#else
#define configASSERT_DEFINED 1
#endif
And below that,
#ifndef INCLUDE_xTaskGetSchedulerState
#define INCLUDE_xTaskGetSchedulerState 0
#endif
#ifndef INCLUDE_xTaskGetCurrentTaskHandle
#define INCLUDE_xTaskGetCurrentTaskHandle 0
#endif
I've seen this x - as in xTaskGetCurrentTaskHandle - everywhere. Also, v, pd and variable names like that, like in line 728
of the header in question:
#if configENABLE_BACKWARD_COMPATIBILITY == 1
#define eTaskStateGet eTaskGetState
#define portTickType TickType_t
#define xTaskHandle TaskHandle_t
#define xQueueHandle QueueHandle_t
#define xSemaphoreHandle SemaphoreHandle_t
#define xQueueSetHandle QueueSetHandle_t
#define xQueueSetMemberHandle QueueSetMemberHandle_t
#define xTimeOutType TimeOut_t
#define xMemoryRegion MemoryRegion_t
#define xTaskParameters TaskParameters_t
#define xTaskStatusType TaskStatus_t
#define xTimerHandle TimerHandle_t
#define xCoRoutineHandle CoRoutineHandle_t
#define pdTASK_HOOK_CODE TaskHookFunction_t
#define portTICK_RATE_MS portTICK_PERIOD_MS
/* Backward compatibility within the scheduler code only - these definitions
are not really required but are included for completeness. */
#define tmrTIMER_CALLBACK TimerCallbackFunction_t
#define pdTASK_CODE TaskFunction_t
#define xListItem ListItem_t
#define xList List_t
I've searched everywhere what would those "initials" stand for, but still could not figure that out.
So, if anyone could help me to understand this, or could show me a path or something, I'd be really grateful.
Looking at the man
Naming Conventions
The RTOS kernel and demo application source code use the following conventions:
Variables
Variables of type
uint32_t
are prefixed ul, where the 'u' denotesunsigned
and the 'l' denoteslong
.Variables of type
uint16_t
are prefixed us, where the 'u' denotes 'unsigned' and the 's' denotesshort
.Variables of type
uint8_t
are prefixed uc, where the 'u' denotes 'unsigned' and the 'c' denoteschar
.Variables of non stdint types are prefixed x. Examples include
BaseType_t
andTickType_t
, which are portable layer defined typedefs for the natural or most efficient type for the architecture and the type used to hold the RTOS tick count respectively.
Unsigned
variables of non stdint types have an additional prefix u. For example variables of typeUBaseType_t
(unsigned BaseType_t
) are prefixed ux.Variables of type
size_t
are also prefixed x.Enumerated variables are prefixed e
Pointers have an additional prefixed p, for example a pointer to a
uint16_t
will have prefix pus.In line with MISRA guides, unqualified standard char types are only permitted to hold
ASCII characters
and are prefixed c.In line with MISRA guides, variables of type
char *
are only permitted to hold pointers toASCII strings
and are prefixed pc.
Emphasis mine
Functions
File scope static (private) functions are prefixed with prv.
API functions are prefixed with their return type, as per the convention defined for variables, with the addition of the prefix v for
void
.API function names start with the name of the file in which they are defined. For example
vTaskDelete
is defined in tasks.c, and has avoid
return type.
Emphasis mine
Macros
Macros are pre-fixed with the file in which they are defined. The pre-fix is lower case. For example,
configUSE_PREEMPTION
is defined in FreeRTOSConfig.h.Other than the pre-fix, macros are written in all upper case, and use an underscore to separate words.
Emphasis mine
这篇关于FreeRTOS匈牙利符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!