FreeRTOS学习笔记
今天在学习FreeRTOS操作系统的定时器功能时,分析源码时,发现C语言也可以进行模块参数的隐藏保护。
具体实现
源文件定义结构体,包含数据参数信息,在头文件内下声明,然后再使用。这样当源文件封装成库文件时,模块的参数被隐藏保护起来。
timer.c
/* The definition of the timers themselves. /
typedef struct tmrTimerControl / The old naming convention is used to prevent breaking kernel aware debuggers. */
{
const char pcTimerName; /<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. /
ListItem_t xTimerListItem; /<< Standard linked list item as used by all kernel features for event management. /
TickType_t xTimerPeriodInTicks;/<< How quickly and often the timer expires. /
UBaseType_t uxAutoReload; /<< Set to pdTRUE if the timer should be automatically restarted once expired. Set to pdFALSE if the timer is, in effect, a one-shot timer. */
void pvTimerID; /<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. /
TimerCallbackFunction_t pxCallbackFunction; /<< The function that will be called when the timer expires. /
#if( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxTimerNumber; /<< An ID assigned by trace tools such as FreeRTOS+Trace */
#endif
#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
uint8_t ucStaticallyAllocated; /*<< Set to pdTRUE if the timer was created statically so no attempt is made to free the memory again if the timer is later deleted. */
#endif
} xTIMER;
timer.h
struct tmrTimerControl; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
typedef struct tmrTimerControl * TimerHandle_t;