|
從驅(qū)動(dòng)接口宏定義抽出來
第一個(gè)數(shù)據(jù)結(jié)構(gòu)
// Driver functions:驅(qū)動(dòng)函數(shù)
CYG_ADC_FUNCTIONS( lpc2xxx_adc_funs,
lpc2xxx_adc_enable,
lpc2xxx_adc_disable,
lpc2xxx_adc_set_rate );
//doc中的解釋說明
The macro CYG_ADC_FUNCTIONS() instantiates a function table called example_adc_funs and populates it with the ADC driver functions
//宏定義原型
#define CYG_ADC_FUNCTIONS( __name, __enable, __disable, __set_rate ) \
cyg_adc_functions __name = \
{ \
.enable = __enable, \
.disable = __disable, \
.set_rate = __set_rate \
};
//adc函數(shù)定義原型,一個(gè)結(jié)構(gòu)體包含了三個(gè)函數(shù)指針
struct cyg_adc_functions
{
void (*enable)( cyg_adc_channel *chan );
void (*disable)( cyg_adc_channel *chan );
void (*set_rate)( cyg_adc_channel *chan, cyg_uint32 rate );
};
/******************************************************************/
宏展開的結(jié)果:定義了一個(gè)cyg_adc_funtions包含了函數(shù)指針的結(jié)構(gòu)體
cyg_adc_functions lpc2xxx_adc_funs{
.enable = lpc2xxx_adc_enable,
.disable = lpc2xxx_adc_disable,
.set_rate = lpc2xxx_adc_set_rate
}
/********************************************************************/
//ADC信息的私有數(shù)據(jù)
static lpc2xxx_adc_info lpc2xxx_adc_info0 =
{
.base = CYGARC_HAL_LPC2XXX_REG_AD_BASE,
.vector = CYGNUM_HAL_INTERRUPT_TIMER1,
.intprio = CYGNUM_DEVS_ADC_ARM_LPC24XX_INTPRIO,
.int_handle = 0,
#if CYGPKG_DEVS_ADC_ARM_LPC24XX_DEBUG_LEVEL > 0
.isr_cnt = 0,
#endif
.chan_mask = 0
};
//ADC驅(qū)動(dòng)的總結(jié)構(gòu),包含了上述的兩部分驅(qū)動(dòng)函數(shù)和私有數(shù)據(jù)
CYG_ADC_DEVICE( lpc2xxx_adc_device, //名字
&lpc2xxx_adc_funs, //驅(qū)動(dòng)函數(shù)
&lpc2xxx_adc_info0, //驅(qū)動(dòng)信息私有數(shù)據(jù)
CYGNUM_DEVS_ADC_ARM_LPC24XX_DEFAULT_RATE); //默認(rèn)采樣率
宏定義
#define CYG_ADC_DEVICE(__name, __funs, __dev_priv, __rate ) \
cyg_adc_device __name = \
{ \
.funs = __funs, \
.dev_priv = __dev_priv, \
.config.rate = __rate, \
.init = false \
};
/********************************************************************************************/
展開宏定義的結(jié)果
cyg_adc_device lpc2xxx_adc_device = \
{ \
.funs = lpc2xxx_adc_funs, , \
.dev_priv = lpc2xxx_adc_info0,
.config.rate =CYGNUM_DEVS_ADC_ARM_LPC24XX_DEFAULT_RATE,
.init = false
};
/**********************************************************************************************/
//ADC0~7驅(qū)動(dòng)的注冊(cè)
LPC2XXX_ADC_CHANNEL(0~7)
//原型
#define LPC2XXX_ADC_CHANNEL( __chan ) \
CYG_ADC_CHANNEL( lpc2xxx_adc_channel##__chan, \
__chan, \
CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL##__chan##_BUFSIZE, \
&lpc2xxx_adc_device ); \
\
DEVTAB_ENTRY( lpc2xxx_adc_channel##__chan##_device, \
CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL##__chan##_NAME, \
0, \
&cyg_io_adc_devio, \
lpc2xxx_adc_init, \
lpc2xxx_adc_lookup, \
&lpc2xxx_adc_channel##__chan );
(1)第一步展開,將"##__chan"和"##_chan##"替換為__chan的數(shù)值,假設(shè)為0
CYG_ADC_CHANNEL( lpc2xxx_adc_channel0, \
0, \
CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL0_BUFSIZE, \
&lpc2xxx_adc_device ); \
\
DEVTAB_ENTRY( lpc2xxx_adc_channel0_device, \
CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL0_NAME, \
0, \
&cyg_io_adc_devio, \
lpc2xxx_adc_init, \
lpc2xxx_adc_lookup, \
&lpc2xxx_adc_channel0 );
//CYG_ADC_CHANNEL宏定義原型
#define CYG_ADC_CHANNEL( __name, __channel, __bufsize, __device )
static cyg_adc_sample_t __name##_buf[__bufsize];
cyg_adc_channel __name =
{
.channel = __channel, \
.buf = __name##_buf, \
.len = __bufsize, \
.put = 0, \
.get = 0, \
.device = __device, \
.init = false \
};
(2-1)CYG_ADC_CHANNLE再次展開后的結(jié)果:
static cyg_adc_sample_t lpc2xxx_adc_channel0_buf[CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL0_BUFSIZE]; \
cyg_adc_channel lpc2xxx_adc_channel0 = \
{ \
.channel = 0, \
.buf = lpc2xxx_adc_channel0_buf, \
.len = CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL0_BUFSIZE, \
.put = 0, \
.get = 0, \
.device = &lpc2xxx_adc_device, \
.init = false \
};
(2-2)DEVTAB_ENTRY宏定義的原型
#define DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_priv) \
CHAR_DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_priv)
#define CHAR_DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_priv)
cyg_devtab_entry_t _l CYG_HAL_TABLE_ENTRY(devtab) = {
_name,
_dep_name,
_handlers,
_init,
_lookup,
_priv,
CYG_DEVTAB_STATUS_CHAR
};
展開結(jié)果
cyg_devtab_entry_t _l CYG_HAL_TABLE_ENTRY(devtab) = {
lpc2xxx_adc_channel0_device,
CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL0_NAME,
0,
lpc2xxx_adc_init,
lpc2xxx_adc_lookup,
&lpc2xxx_adc_channel0,
CYG_DEVTAB_STATUS_CHAR
};
CYG_HAL_TABLE_ENTRY()原型
#define CYG_HAL_TABLE_ENTRY( _name ) \
CYGBLD_ATTRIB_SECTION(".ecos.table." __xstring(_name) ".data")
CYGBLD_ATTRIB_USED
展開結(jié)果
CYGBLD_ATTRIB_SECTION(".ecos.table.devtab.data")
CYGBLD_ATTRIB_USED
CYGBLD_ATTRIB_SECTION原型
#define CYGBLD_ATTRIB_SECTION(__sect__) __attribute__((section (__sect__)))
展開結(jié)果
__attribute__((section (".ecos.table.devtab.data")))
展開CYGBLD_ATTRIB_USED
__attribute__((used))
CYG_HAL_TABLE_ENTRY()的展開結(jié)果為
__attribute__((section (".ecos.table.devtab.data")))
__attribute__((used))
DEVTAB_ENTRY的展開結(jié)果為
cyg_devtab_entry_t _l __attribute__((section (".ecos.table.devtab.data"))) __attribute__((used)) = {
lpc2xxx_adc_channel0_device,
CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL0_NAME,
0,
lpc2xxx_adc_init,
lpc2xxx_adc_lookup,
&lpc2xxx_adc_channel0,
CYG_DEVTAB_STATUS_CHAR
};
總結(jié)LPC2XXX_ADC_CHANNEL(0)的宏定義結(jié)果為
static cyg_adc_sample_t lpc2xxx_adc_channel0_buf[CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL0_BUFSIZE];
cyg_adc_channel lpc2xxx_adc_channel0 =
{
.channel = 0,
.buf = lpc2xxx_adc_channel0_buf,
.len = CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL0_BUFSIZE,
.put = 0,
.get = 0,
.device = &lpc2xxx_adc_device,
.init = false
};
cyg_devtab_entry_t _l __attribute__((section (".ecos.table.devtab.data"))) __attribute__((used)) = {
lpc2xxx_adc_channel0_device,
CYGDAT_DEVS_ADC_ARM_LPC24XX_CHANNEL0_NAME,
0,
lpc2xxx_adc_init,
lpc2xxx_adc_lookup,
&lpc2xxx_adc_channel0,
CYG_DEVTAB_STATUS_CHAR
};
因?yàn)楣绲陌姹咎耍瑢?dǎo)致很多行都亂了,所以把一些還行符刪掉了~
看人家老外做的程序,專業(yè)~看不懂~
我要是分析的不對(duì)的,大家指正 |
|