FreeRTOS Hungarian Notation [duplicate]

北慕城南 提交于 2019-12-11 01:54:14

问题


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.


回答1:


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' denotes unsigned and the 'l' denotes long.

  • Variables of type uint16_t are prefixed us, where the 'u' denotes 'unsigned' and the 's' denotes short.

  • Variables of type uint8_t are prefixed uc, where the 'u' denotes 'unsigned' and the 'c' denotes char.

  • Variables of non stdint types are prefixed x. Examples include BaseType_t and TickType_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 type UBaseType_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 to ASCII 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 a void 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



来源:https://stackoverflow.com/questions/39851321/freertos-hungarian-notation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!