函数内检查参数实现

the assert_param macro(宏) 
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line);

  void assert_failed(u8* file, u32 line)
  {
    rt_kprintf("\n\r Wrong parameter value detected on\r\n");
    rt_kprintf(" file %s\r\n", file);
    rt_kprintf(" line %d\r\n", line);

    while (1) ;
  }

 ----------------------------------------------------------------------------

void ADC_DeInit(ADC_TypeDef* ADCx)
{
  /* Check the parameters */
  assert_param(IS_ADC_ALL_PERIPH(ADCx));

  // 后面省略
}

#define IS_ADC_ALL_PERIPH(PERIPH) (((PERIPH) == ADC1) || ((PERIPH) == ADC2) || ((PERIPH) == ADC3))




  

posted @ 2021-10-20 13:57  我爱茜茜公主  阅读(45)  评论(0)    收藏  举报