2

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.

4

1 回答 1

4

看着男人

命名约定

RTOS 内核和演示应用程序源代码使用以下约定:

变量

  • 类型变量以uluint32_t为前缀,其中“u”表示,“l”表示。unsignedlong

  • 类型变量以usuint16_t为前缀,其中'u'表示 'unsigned' 而 's' 表示。short

  • 类型变量以ucuint8_t为前缀,其中'u'表示 'unsigned' 而 'c' 表示。char

  • 非 stdint 类型的变量以 x 为前缀。示例包括 BaseType_tTickType_t,它们是可移植层定义的类型定义,用于架构的自然或最有效类型以及用于分别保存 RTOS 滴答计数的类型。

  • Unsigned非 stdint 类型的变量有一个额外的前缀u。例如,类型UBaseType_t( ) 的变量以uxunsigned BaseType_t为前缀。

  • 类型变量size_t也以x为前缀。

  • 枚举变量以e为前缀

  • 指针有一个额外的前缀p,例如指向 a 的指针uint16_t将有前缀pus

  • 根据 MISRA 指南,不合格的标准 char 类型只允许保存ASCII characters并带有前缀c

  • 根据 MISRA 指南,类型变量char *只允许保存指向 pc 的指针并以pcASCII strings为前缀。

强调我的

功能

  • 文件范围静态(私有)函数以 prv 为前缀。

  • 根据为变量定义的约定,API 函数以其返回类型为前缀,并为 . 添加前缀vvoid

  • API 函数名称以定义它们的文件的名称开头。例如vTaskDelete在tasks.c 中定义,并且有一个void返回类型。

强调我的

  • 宏以定义它们的文件为前缀。前缀是小写的。例如,configUSE_PREEMPTION在 FreeRTOSConfig.h 中定义。

  • 除前缀外,宏全部大写,并使用下划线分隔单词。

强调我的

于 2016-10-04T12:32:52.097 回答