typedef struct _ADC_Obj_
{
volatile uint16_t ADCRESULT[16]; //!< ADC result registers
volatile uint16_t resvd_1[26096]; //!< Reserved
volatile uint16_t ADCCTL1; //!< ADC Control Register 1
volatile uint16_t rsvd_2[3]; //!< Reserved
volatile uint16_t ADCINTFLG; //!< ADC Interrupt Flag Register
volatile uint16_t ADCINTFLGCLR; //!< ADC Interrupt Flag Clear Register
volatile uint16_t ADCINTOVF; //!< ADC Interrupt Overflow Register
volatile uint16_t ADCINTOVFCLR; //!< ADC Interrupt Overflow Clear Register
volatile uint16_t INTSELxNy[5]; //!< ADC Interrupt Select x and y Register
volatile uint16_t rsvd_3[3]; //!< Reserved
volatile uint16_t SOCPRICTRL; //!< ADC Start Of Conversion Priority Control Register
volatile uint16_t rsvd_4; //!< Reserved
volatile uint16_t ADCSAMPLEMODE; //!< ADC Sample Mode Register
volatile uint16_t rsvd_5; //!< Reserved
volatile uint16_t ADCINTSOCSEL1; //!< ADC Interrupt Trigger SOC Select 1 Register
volatile uint16_t ADCINTSOCSEL2; //!< ADC Interrupt Trigger SOC Select 2 Register
volatile uint16_t rsvd_6[2]; //!< Reserved
volatile uint16_t ADCSOCFLG1; //!< ADC SOC Flag 1 Register
volatile uint16_t rsvd_7; //!< Reserved
volatile uint16_t ADCSOCFRC1; //!< ADC SOC Force 1 Register
volatile uint16_t rsvd_8; //!< Reserved
volatile uint16_t ADCSOCOVF1; //!< ADC SOC Overflow 1 Register
volatile uint16_t rsvd_9; //!< Reserved
volatile uint16_t ADCSOCOVFCLR1; //!< ADC SOC Overflow Clear 1 Register
volatile uint16_t rsvd_10; //!< Reserved
volatile uint16_t ADCSOCxCTL[16]; //!< ADC SOCx Control Registers
volatile uint16_t rsvd_11[16]; //!< Reserved
volatile uint16_t ADCREFTRIM; //!< ADC Reference/Gain Trim Register
volatile uint16_t ADCOFFTRIM; //!< ADC Offset Trim Register
volatile uint16_t resvd_12[13]; //!< Reserved
volatile uint16_t ADCREV; //!< ADC Revision Register
} ADC_Obj;
//! \brief Defines the analog-to-digital converter (ADC) handle
//!
typedef struct ADC_Obj *ADC_Handle;
inline void ADC_clearIntFlag(ADC_Handle adcHandle, const ADC_IntNumber_e intNumber)
{
ADC_Obj *adc = (ADC_Obj *)adcHandle;
// clear the bit
adc->ADCINTFLGCLR = 1 << intNumber;
return;
} // end of ADC_clearIntFlag() function
Young Hu:
这是新的C2000的编程风格,采用类似面向对象的风格,定义了一段ADC的结构体,把所有的寄存器都封装在这个结构体中。
typedef struct ADC_Obj *ADC_Handle;
是定义一个指针,通过指针对ADC这个结构体进行操作。
ADC_Obj *adc = (ADC_Obj *)adcHandle;
定义一个局部变量指针,通过函数定义,可以将ADC结构体复制给这个局部指针。
这样保证了函数的可复用性。
inline,自己去网上查吧
typedef struct _ADC_Obj_
{
volatile uint16_t ADCRESULT[16]; //!< ADC result registers
volatile uint16_t resvd_1[26096]; //!< Reserved
volatile uint16_t ADCCTL1; //!< ADC Control Register 1
volatile uint16_t rsvd_2[3]; //!< Reserved
volatile uint16_t ADCINTFLG; //!< ADC Interrupt Flag Register
volatile uint16_t ADCINTFLGCLR; //!< ADC Interrupt Flag Clear Register
volatile uint16_t ADCINTOVF; //!< ADC Interrupt Overflow Register
volatile uint16_t ADCINTOVFCLR; //!< ADC Interrupt Overflow Clear Register
volatile uint16_t INTSELxNy[5]; //!< ADC Interrupt Select x and y Register
volatile uint16_t rsvd_3[3]; //!< Reserved
volatile uint16_t SOCPRICTRL; //!< ADC Start Of Conversion Priority Control Register
volatile uint16_t rsvd_4; //!< Reserved
volatile uint16_t ADCSAMPLEMODE; //!< ADC Sample Mode Register
volatile uint16_t rsvd_5; //!< Reserved
volatile uint16_t ADCINTSOCSEL1; //!< ADC Interrupt Trigger SOC Select 1 Register
volatile uint16_t ADCINTSOCSEL2; //!< ADC Interrupt Trigger SOC Select 2 Register
volatile uint16_t rsvd_6[2]; //!< Reserved
volatile uint16_t ADCSOCFLG1; //!< ADC SOC Flag 1 Register
volatile uint16_t rsvd_7; //!< Reserved
volatile uint16_t ADCSOCFRC1; //!< ADC SOC Force 1 Register
volatile uint16_t rsvd_8; //!< Reserved
volatile uint16_t ADCSOCOVF1; //!< ADC SOC Overflow 1 Register
volatile uint16_t rsvd_9; //!< Reserved
volatile uint16_t ADCSOCOVFCLR1; //!< ADC SOC Overflow Clear 1 Register
volatile uint16_t rsvd_10; //!< Reserved
volatile uint16_t ADCSOCxCTL[16]; //!< ADC SOCx Control Registers
volatile uint16_t rsvd_11[16]; //!< Reserved
volatile uint16_t ADCREFTRIM; //!< ADC Reference/Gain Trim Register
volatile uint16_t ADCOFFTRIM; //!< ADC Offset Trim Register
volatile uint16_t resvd_12[13]; //!< Reserved
volatile uint16_t ADCREV; //!< ADC Revision Register
} ADC_Obj;
//! \brief Defines the analog-to-digital converter (ADC) handle
//!
typedef struct ADC_Obj *ADC_Handle;
inline void ADC_clearIntFlag(ADC_Handle adcHandle, const ADC_IntNumber_e intNumber)
{
ADC_Obj *adc = (ADC_Obj *)adcHandle;
// clear the bit
adc->ADCINTFLGCLR = 1 << intNumber;
return;
} // end of ADC_clearIntFlag() function
重新开始:
回复 Young Hu:
谢谢您的解答
我还是有些不太懂
typedef struct _ADC_Obj_
{
····
}ADC_Obj;这已经声明了一个新结构体类型名ADC_Obj
而typedef struct ADC_Obj *ADC_Handle;这条语句怎么理解?我感觉按C语言应该是这样的typedef ADC_Obj *ADC_Handle;或者是
typedef struct _ADC_Obj_ *ADC_Handle;
typedef struct _ADC_Obj_
{
volatile uint16_t ADCRESULT[16]; //!< ADC result registers
volatile uint16_t resvd_1[26096]; //!< Reserved
volatile uint16_t ADCCTL1; //!< ADC Control Register 1
volatile uint16_t rsvd_2[3]; //!< Reserved
volatile uint16_t ADCINTFLG; //!< ADC Interrupt Flag Register
volatile uint16_t ADCINTFLGCLR; //!< ADC Interrupt Flag Clear Register
volatile uint16_t ADCINTOVF; //!< ADC Interrupt Overflow Register
volatile uint16_t ADCINTOVFCLR; //!< ADC Interrupt Overflow Clear Register
volatile uint16_t INTSELxNy[5]; //!< ADC Interrupt Select x and y Register
volatile uint16_t rsvd_3[3]; //!< Reserved
volatile uint16_t SOCPRICTRL; //!< ADC Start Of Conversion Priority Control Register
volatile uint16_t rsvd_4; //!< Reserved
volatile uint16_t ADCSAMPLEMODE; //!< ADC Sample Mode Register
volatile uint16_t rsvd_5; //!< Reserved
volatile uint16_t ADCINTSOCSEL1; //!< ADC Interrupt Trigger SOC Select 1 Register
volatile uint16_t ADCINTSOCSEL2; //!< ADC Interrupt Trigger SOC Select 2 Register
volatile uint16_t rsvd_6[2]; //!< Reserved
volatile uint16_t ADCSOCFLG1; //!< ADC SOC Flag 1 Register
volatile uint16_t rsvd_7; //!< Reserved
volatile uint16_t ADCSOCFRC1; //!< ADC SOC Force 1 Register
volatile uint16_t rsvd_8; //!< Reserved
volatile uint16_t ADCSOCOVF1; //!< ADC SOC Overflow 1 Register
volatile uint16_t rsvd_9; //!< Reserved
volatile uint16_t ADCSOCOVFCLR1; //!< ADC SOC Overflow Clear 1 Register
volatile uint16_t rsvd_10; //!< Reserved
volatile uint16_t ADCSOCxCTL[16]; //!< ADC SOCx Control Registers
volatile uint16_t rsvd_11[16]; //!< Reserved
volatile uint16_t ADCREFTRIM; //!< ADC Reference/Gain Trim Register
volatile uint16_t ADCOFFTRIM; //!< ADC Offset Trim Register
volatile uint16_t resvd_12[13]; //!< Reserved
volatile uint16_t ADCREV; //!< ADC Revision Register
} ADC_Obj;
//! \brief Defines the analog-to-digital converter (ADC) handle
//!
typedef struct ADC_Obj *ADC_Handle;
inline void ADC_clearIntFlag(ADC_Handle adcHandle, const ADC_IntNumber_e intNumber)
{
ADC_Obj *adc = (ADC_Obj *)adcHandle;
// clear the bit
adc->ADCINTFLGCLR = 1 << intNumber;
return;
} // end of ADC_clearIntFlag() function
10#:
回复 重新开始:
通过typedef定义一个数据类型,再用同样的方式定义该类型的一个变量(这里是个指针)。
后面你列出的写法应该也是正确的,建议阅读一下C语言中关于typedef的使用说明确认一下。