<commit_before>/*
HydraBus/HydraNFC - Copyright (C) 2014 <NAME>
HydraBus/HydraNFC - Copyright (C) 2016 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "common.h"
#include "bsp_freq.h"
#include "bsp_freq_conf.h"
#include "stm32f405xx.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_rcc.h"

#define NB_FREQ (BSP_DEV_freq_END)


/** \brief FREQ GPIO HW DeInit.
 *
 * \param dev_num bsp_dev_freq_t: FREQ dev num
 * \return void
 *
 */
static void freq_gpio_hw_deinit(bsp_dev_freq_t dev_num)
{
	(void)dev_num;

	HAL_GPIO_DeInit((GPIO_TypeDef *)BSP_FREQ1_PORT, BSP_FREQ1_PIN);
}

/** \brief FREQ GPIO HW Init.
 *
 * \param dev_num bsp_dev_freq_t: FREQ dev num
 * \return void
 *
 */
static void freq_gpio_hw_init(bsp_dev_freq_t dev_num)
{
	GPIO_InitTypeDef gpio_init;

	if(dev_num == BSP_DEV_FREQ1) {
		/* BSP_FREQ1 pin configuration */
		gpio_init.Mode = GPIO_MODE_AF_PP;
		gpio_init.Pull  = GPIO_NOPULL;
		gpio_init.Speed = GPIO_SPEED_FAST; /* Max 50MHz */
		gpio_init.Alternate = BSP_FREQ1_AF;
		gpio_init.Pin = BSP_FREQ1_PIN;
		HAL_GPIO_Init((GPIO_TypeDef *)BSP_FREQ1_PORT, &gpio_init);
	}
}

/** \brief Init FREQ device.
 *
 * \param dev_num bsp_dev_freq_t: FREQ dev num.
 * \return bsp_status_t: status of the init.
 *
 */
bsp_status_t bsp_freq_init(bsp_dev_freq_t dev_num, uint16_t scale)
{
	TIM_HandleTypeDef htim;
	TIM_IC_InitTypeDef freq_conf;
	TIM_SlaveConfigTypeDef slave_conf;
	uint32_t channel;

	bsp_freq_deinit(dev_num);

	/* Configure the FREQ (TIM8) peripheral */
	__TIM8_CLK_ENABLE();

	/* Init the FREQ GPIO */
	freq_gpio_hw_init(dev_num);

	/* Init TIM */
	htim.Instance = BSP_FREQ1_TIMER;
	htim.Init.Period = 0xffff;
	htim.Init.Prescaler = scale-1;
	htim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
	htim.Init.CounterMode = TIM_COUNTERMODE_UP;

	if(HAL_TIM_Base_Init(&htim) != HAL_OK) {
		return BSP_ERROR;
	}

	if(HAL_TIM_IC_Init(&htim) != HAL_OK) {
		return BSP_ERROR;
	}

	/* TIMx FREQ configuration */
	channel = TIM_CHANNEL_1;
<commit_msg>bsp_freq_init() fix coverity scan bug "uninitialized value htim.State"<commit_after>/*
HydraBus/HydraNFC - Copyright (C) 2014 <NAME>
HydraBus/HydraNFC - Copyright (C) 2016 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "common.h"
#include "bsp_freq.h"
#include "bsp_freq_conf.h"
#include "stm32f405xx.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_rcc.h"

#define NB_FREQ (BSP_DEV_freq_END)


/** \brief FREQ GPIO HW DeInit.
 *
 * \param dev_num bsp_dev_freq_t: FREQ dev num
 * \return void
 *
 */
static void freq_gpio_hw_deinit(bsp_dev_freq_t dev_num)
{
	(void)dev_num;

	HAL_GPIO_DeInit((GPIO_TypeDef *)BSP_FREQ1_PORT, BSP_FREQ1_PIN);
}

/** \brief FREQ GPIO HW Init.
 *
 * \param dev_num bsp_dev_freq_t: FREQ dev num
 * \return void
 *
 */
static void freq_gpio_hw_init(bsp_dev_freq_t dev_num)
{
	GPIO_InitTypeDef gpio_init;

	if(dev_num == BSP_DEV_FREQ1) {
		/* BSP_FREQ1 pin configuration */
		gpio_init.Mode = GPIO_MODE_AF_PP;
		gpio_init.Pull  = GPIO_NOPULL;
		gpio_init.Speed = GPIO_SPEED_FAST; /* Max 50MHz */
		gpio_init.Alternate = BSP_FREQ1_AF;
		gpio_init.Pin = BSP_FREQ1_PIN;
		HAL_GPIO_Init((GPIO_TypeDef *)BSP_FREQ1_PORT, &gpio_init);
	}
}

/** \brief Init FREQ device.
 *
 * \param dev_num bsp_dev_freq_t: FREQ dev num.
 * \return bsp_status_t: status of the init.
 *
 */
bsp_status_t bsp_freq_init(bsp_dev_freq_t dev_num, uint16_t scale)
{
	TIM_HandleTypeDef htim;
	TIM_IC_InitTypeDef freq_conf;
	TIM_SlaveConfigTypeDef slave_conf;
	uint32_t channel;

	bsp_freq_deinit(dev_num);

	/* Configure the FREQ (TIM8) peripheral */
	__TIM8_CLK_ENABLE();

	/* Init the FREQ GPIO */
	freq_gpio_hw_init(dev_num);

	/* Init TIM */
	htim.Instance = BSP_FREQ1_TIMER;
	htim.State = HAL_TIM_STATE_RESET;
	htim.Init.Period = 0xffff;
	htim.Init.Prescaler = scale-1;
	htim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
	htim.Init.CounterMode = TIM_COUNTERMODE_UP;

	if(HAL_TIM_Base_Init(&htim) != HAL_OK) {
		return BSP_ERROR;
	}

	if(HAL_TIM_IC_Init(&htim) != HAL_OK) {
		return BSP_ERROR;
	}

	/* TIMx FREQ configuration */
	channel = TIM_CHANNEL_1;

{'fraction_non_alphanumeric': 0.10063897763578275, 'fraction_numerical': 0.017172523961661343, 'mean_word_length': 4.666289592760181, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7024142', 'n_tokens_mistral': 2098, 'n_tokens_neox': 1974, 'n_words': 469}