STM32库函数中,有一个函数是这样的
FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)
{
uint32_t tmp = 0;
uint32_t statusreg = 0;
FlagStatus bitstatus = RESET;
/* Check the parameters */
assert_param(IS_RCC_FLAG(RCC_FLAG));
/* Get the RCC register index */
tmp = RCC_FLAG >> 5;
if (tmp == 1) /* The flag to check is in CR register */ //为什么?
{
statusreg = RCC->CR;
}
else if (tmp == 2) /* The flag to check is in BDCR register */ // 为什么?
{
statusreg = RCC->BDCR;
}
else /* The flag to check is in CSR register */ //为什么?
{
statusreg = RCC->CSR;
}
/* Get the flag posi
tion */
tmp = RCC_FLAG & FLAG_MASK;
if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
/* Return the flag status */
return bitstatus;
}
为什么(tmp == 1)就可以判断/* The flag to check is in CR register */ ??
为什么(tmp == 2)就可以判断 /* The flag to check is in BDCR register */ ??
为什么其它的就可以判断 /* The flag to check is in CSR register */ ??
另外 if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
这是为什么?
0