/** * @brief Configures the analog watchdog. * @note Analog watchdog thresholds can be modified while ADC conversion is on going. * In this case, some constraints must be taken into account: the programmed threshold * values are effective from the next ADC EOC (end of unitary conversion). * Considering that registers write delay may happen due to bus activity, this might cause * an uncertainty on the effective timing of the new programmed threshold values. * @param hadc: pointer to a ADC_HandleTypeDef structure that contains * the configuration information for the specified ADC. * @param AnalogWDGConfig : pointer to an ADC_AnalogWDGConfTypeDef structure * that contains the configuration information of ADC analog watchdog. * @retval HAL status */ HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig) { #ifdef USE_FULL_ASSERT uint32_t tmp = 0; #endif /* USE_FULL_ASSERT */ /* Check the parameters */ assert_param(IS_ADC_ANALOG_WATCHDOG(AnalogWDGConfig->WatchdogMode)); assert_param(IS_ADC_CHANNEL(AnalogWDGConfig->Channel)); assert_param(IS_FUNCTIONAL_STATE(AnalogWDGConfig->ITMode)); #ifdef USE_FULL_ASSERT tmp = ADC_GET_RESOLUTION(hadc); assert_param(IS_ADC_RANGE(tmp, AnalogWDGConfig->HighThreshold)); assert_param(IS_ADC_RANGE(tmp, AnalogWDGConfig->LowThreshold)); #endif /* USE_FULL_ASSERT */ /* Process locked */ __HAL_LOCK(hadc); if(AnalogWDGConfig->ITMode == ENABLE) { /* Enable the ADC Analog watchdog interrupt */ __HAL_ADC_ENABLE_IT(hadc, ADC_IT_AWD); } else { /* Disable the ADC Analog watchdog interrupt */ __HAL_ADC_DISABLE_IT(hadc, ADC_IT_AWD); } /* Clear AWDEN, JAWDEN and AWDSGL bits */ hadc->Instance->CR1 &= ~(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN | ADC_CR1_AWDEN); /* Set the analog watchdog enable mode */ hadc->Instance->CR1 |= AnalogWDGConfig->WatchdogMode; /* Set the high threshold */ hadc->Instance->HTR = AnalogWDGConfig->HighThreshold; /* Set the low threshold */ hadc->Instance->LTR = AnalogWDGConfig->LowThreshold; /* Clear the Analog watchdog channel select bits */ hadc->Instance->CR1 &= ~ADC_CR1_AWDCH; /* Set the Analog watchdog channel */ hadc->Instance->CR1 |= (uint32_t)((uint16_t)(AnalogWDGConfig->Channel)); /* Process unlocked */ __HAL_UNLOCK(hadc); /* Return function status */ return HAL_OK; }
/** * @brief Enables or disables the analog watchdog on single/all regular * or injected channels * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. * @param ADC_AnalogWatchdog: the ADC analog watchdog configuration. * This parameter can be one of the following values: * @arg ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on a single regular channel * @arg ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on a single injected channel * @arg ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog watchdog on a single regular or injected channel * @arg ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on all regular channel * @arg ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on all injected channel * @arg ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog on all regular and injected channels * @arg ADC_AnalogWatchdog_None: No channel guarded by the analog watchdog * @retval None */ void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog) { uint32_t tmpreg = 0; /* Check the parameters */ assert_param(IS_ADC_ALL_PERIPH(ADCx)); assert_param(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog)); /* Get the old register value */ tmpreg = ADCx->CR1; /* Clear AWDEN, AWDENJ and AWDSGL bits */ tmpreg &= CR1_AWDMode_Reset; /* Set the analog watchdog enable mode */ tmpreg |= ADC_AnalogWatchdog; /* Store the new register value */ ADCx->CR1 = tmpreg; }
/******************************************************************************* * 函数名称: ADC_AnalogWatchdogCmd * 功能描述: 使能/禁止一个/所有常规信道或者注入信道的模拟看门狗。 * 输入参数: (1)ADCx:其中x可以是1、2或3,用来选择ADC外围模块. * (2)ADC_AnalogWatchdog: ADC模拟看门狗配置 * 该参数可能的取值: * - ADC_AnalogWatchdog_SingleRegEnable: 单常规信道上的模拟看门狗 * - ADC_AnalogWatchdog_SingleInjecEnable: 单注入信道上的模拟看门狗 * - ADC_AnalogWatchdog_SingleRegOrInjecEnable: 单常规信道或者注入信道的模拟看门狗 * - ADC_AnalogWatchdog_AllRegEnable: 所有常规信道上的模拟看门狗 * - ADC_AnalogWatchdog_AllInjecEnable: 所有注入信道上的模拟看门狗 * - ADC_AnalogWatchdog_AllRegAllInjecEnable: 所有常规信道和注入信道上的模拟看门狗 * - ADC_AnalogWatchdog_无: 没有信道需要模拟看门狗监视 * 输出参数: 无 * 返回参数: 无 *******************************************************************************/ void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, u32 ADC_AnalogWatchdog) { u32 tmpreg = 0; /* Check the parameters [检查参数] */ assert_param(IS_ADC_ALL_PERIPH(ADCx)); assert_param(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog)); /* Get the old register value [取得旧的寄存器值]*/ tmpreg = ADCx->CR1; /* Clear AWDEN, AWDENJ and AWDSGL bits [清除AWDEN,AWDENJ和AWDSGL位]*/ tmpreg &= CR1_AWDMode_Reset; /* Set the analog watchdog enable mode [置位模拟看门狗允许模式]*/ tmpreg |= ADC_AnalogWatchdog; /* Store the new register value [存储新的寄存器值]*/ ADCx->CR1 = tmpreg; }