/* 在 stm32f10x_conf.h 文件中,
第72行 #define assert_param(expr) ((void)0) // expr:1:返回(void)0,expr:0:返回什么?
*/
#ifdef USE_FULL_ASSERT //如果定义了USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function which reports
* the name of the source file and the source line number of the call
* that failed. If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) //定义这个宏,expr:1:返回(void)0,expr:0:调用assert_failed函数,返回源文件名,和引起错误的线号。
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else //否则,定义下面这个宏,
#define assert_param(expr) ((void)0) // expr:1:返回(void)0,expr:0:返回什么?
#endif /* USE_FULL_ASSERT */
/* 在 stm32f10x_gpio.h 文件中,
267行,是什么意思?
#define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
((PORTSOURCE) == GPIO_PortSourceGPIOE) || \
((PORTSOURCE) == GPIO_PortSourceGPIOF) || \
((PORTSOURCE) == GPIO_PortSourceGPIOG))
后面这么多赋值,相或,是什么意思?
*/
/* 在 stm32f10x_gpio.h 文件中,
50--56行,是什么意思?
typedef enum
{
EXTI_Mode_Interrupt = 0x00, //EXTI_IMR的偏移地址?
EXTI_Mode_Event = 0x04 //EXTI_EMR的偏移地址?
}EXTIMode_TypeDef;
#define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event))
//上面这句是?意思
*/
/* 在 stm32f10x_exti.h 文件中,
void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
{
uint32_t tmp = 0;
/* Check the parameters */
assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
tmp = (uint32_t)EXTI_BASE; //tmp 取 EXTI_BASE 基地址,
if (EXTI_InitStruct->EXTI_LineCmd != DISABLE) // EXTI_LineCmd 使能时,
{
/* Clear EXTI line configuration */
EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line; //EXTI_Line0 取反,再跟 EXTI->IMR 相与,那 EXTI->IMR 岂不是被屏蔽了?
EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line; //EXTI_Line0 取反,再跟 EXTI->EMR 相与,那 EXTI->EMR 岂不是被屏蔽了?
tmp += EXTI_InitStruct->EXTI_Mode; //tmp + 模式地址,
*(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; //tmp 与上 (uint32_t)0x00001 岂不是只有0X0000 0001了?
/* Clear Rising Falling edge configuration */
EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line; //EXTI->RTSR 线0的上升沿触发初岂不是被屏蔽了?
EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line; //EXTI->FTSR 线0的下降沿触发初岂不是被屏蔽了?
/* Select the trigger for the selected external interrupts */
if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) //EXTI_Trigger_Rising_Falling = 0x10 是 SWIER 的地址了?
{
/* Rising Falling edge */
EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;//上升沿可以触发
EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;//下降沿可以触发
}
else //如果不是上升沿/下降沿同时触发,
{
tmp = (uint32_t)EXTI_BASE; //指向基地址,
tmp += EXTI_InitStruct->EXTI_Trigger; //指向EXTI->RTSR地址,
*(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;//使 EXTI->RTSR 写入0X0000 0001,使线0可以上升沿触发。
}
}
else // EXTI_LineCmd 不能时,
{
tmp += EXTI_InitStruct->EXTI_Mode; //EXTI_BASE 基地址+0X00,是 EXTI_IMR地址,
/* Disable the selected external lines */
*(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line; // EXTI_IMR 与上 0XFFFF FFFE,b也就是把线0的中断屏蔽了。
}
} |