Commit 572bacba authored by Clément Foucher's avatar Clément Foucher
Browse files

Reorganized Hrtim Module to prepare for two different modes.

Leg Module merged with Hrtim Module voltage mode.
parent e48bb87b
if(CONFIG_OWNTECH_HRTIM_DRIVER)
zephyr_include_directories(.)
# Select directory to add to the include path
zephyr_include_directories(./public_include)
# Define the current folder as a Zephyr library
zephyr_library()
# Select source files to be compiled
zephyr_library_sources(
owntech_hrtim_driver.c
./src/voltage_mode/hrtim_voltage_mode.c
./src/voltage_mode/owntech_leg_driver.cpp
./src/hrtim_common.c
)
endif()
config OWNTECH_HRTIM_DRIVER
bool "Enable OwnTech hrtim driver"
bool "Enable OwnTech High-resolution timer driver for STM32"
default y
/*
* Copyright (c) 2021 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGLPV2.1
*/
/**
* @author Clément Foucher <clement.foucher@laas.fr>
*/
#ifndef HRTIM_H_
#define HRTIM_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief HRTIM have 5 or 6 timing units
*/
#ifdef HRTIM_MCR_TFCEN
#define HRTIM_STU_NUMOF (6U) /**< number of slave timing units */
#else
#define HRTIM_STU_NUMOF (5U)
#endif
/**
* @brief Default HRTIM type definition
*/
#ifndef HAVE_HRTIM_T
typedef unsigned int hrtim_t;
#endif
/**
* @brief HRTIM timing units definition
*/
typedef enum {
TIMA,
TIMB,
TIMC,
TIMD,
TIME,
#if (HRTIM_STU_NUMOF == 6)
TIMF,
#endif
MSTR
} hrtim_tu_t;
/**
* @brief Set the duty-cycle, dead-time and phase shift for a given
* timing unit of a given HRTIM device
*
* @param[in] dev HRTIM device
* @param[in] tu Timing unit
* @param[in] value Duty cycle
* @param[in] shift Phase shifting
*/
void hrtim_pwm_set(hrtim_t dev, hrtim_tu_t tu, uint16_t value, uint16_t shift);
void hrtim_init_voltage();
#ifdef __cplusplus
}
#endif
#endif // HRTIM_H_
......@@ -31,10 +31,13 @@
* @author Antoine Boche <antoine.boche@laas.fr>
*/
#ifndef LEG_H
#define LEG_H
#ifndef LEG_H_
#define LEG_H_
#include <assert.h>
#include <stdint.h>
#include <zephyr.h>
#include "hrtim.h"
......@@ -114,5 +117,4 @@ uint16_t leg_get_freq(void);
}
#endif
#endif /* LEG_H */
/** @} */
#endif // LEG_H_
/*
* Copyright (c) 2021 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGLPV2.1
*/
/**
* @author Clément Foucher <clement.foucher@laas.fr>
*/
#include "voltage_mode/hrtim_voltage_mode.h"
#include "leg.h"
void hrtim_init_voltage()
{
leg_init(true);
hrtim_adc_trigger_en(0, ADC1R, AD13_TAC3);
hrtim_cmp_set(0, TIMA, CMP3xR, 1);
}
......@@ -29,7 +29,7 @@
* @author Antoine Boche <antoine.boche@laas.fr>
*/
#include "hrtim.h"
#include "hrtim_voltage_mode.h"
#include "assert.h"
static const struct soc_gpio_pinctrl tim_pinctrl[] = ST_STM32_DT_INST_PINCTRL(0, 0);
......
......@@ -30,26 +30,20 @@
* @author Antoine Boche <antoine.boche@laas.fr>
*/
#ifndef HRTIM_H
#define HRTIM_H
#ifndef HRTIM_VOLTAGE_MODE_H_
#define HRTIM_VOLTAGE_MODE_H_
#include <stdint.h>
#include <limits.h>
#include <pinmux/stm32/pinmux_stm32.h>
#include <hrtim.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief HRTIM have 5 or 6 timing units
*/
#ifdef HRTIM_MCR_TFCEN
#define HRTIM_STU_NUMOF (6U) /**< number of slave timing units */
#else
#define HRTIM_STU_NUMOF (5U)
#endif
#define DT_DRV_COMPAT hrtim
#define CLOCK_APB2 (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / CONFIG_CLOCK_STM32_APB2_PRESCALER)
......@@ -69,13 +63,6 @@ extern "C" {
#define HRTIM_UNDEF (UINT_MAX)
#endif
/**
* @brief Default HRTIM type definition
*/
#ifndef HAVE_HRTIM_T
typedef unsigned int hrtim_t;
#endif
/**
* @brief HRTIM Set/Reset trigger definition
*/
......@@ -115,21 +102,6 @@ typedef enum {
to active) */
} hrtim_cb_t;
/**
* @brief HRTIM timing units definition
*/
typedef enum {
TIMA,
TIMB,
TIMC,
TIMD,
TIME,
#if (HRTIM_STU_NUMOF == 6)
TIMF,
#endif
MSTR
} hrtim_tu_t;
/**
* @brief HRTIM comparators definition
*/
......@@ -370,17 +342,6 @@ typedef enum {
*/
uint16_t hrtim_init(hrtim_t dev, uint32_t *freq, uint16_t dt, uint8_t switch_convention);
/**
* @brief Set the duty-cycle, dead-time and phase shift for a given
* timing unit of a given HRTIM device
*
* @param[in] dev HRTIM device
* @param[in] tu Timing unit
* @param[in] value Duty cycle
* @param[in] shift Phase shifting
*/
void hrtim_pwm_set(hrtim_t dev, hrtim_tu_t tu, uint16_t value, uint16_t shift);
/**
* @brief Initialize an HRTIM device master timer
*
......@@ -562,4 +523,4 @@ void hrtim_adc_trigger_dis(hrtim_t dev, hrtim_adc_t adc, hrtim_adc_trigger_t evt
}
#endif
#endif /* HRTIM_H */
#endif // HRTIM_VOLTAGE_MODE_H_
......@@ -28,6 +28,7 @@
#include "leg.h"
#include "owntech_leg_driver.h"
#include "hrtim_voltage_mode.h"
static uint16_t period, min_pw, max_pw, dead_time;
......@@ -45,7 +46,7 @@ uint16_t leg_init(bool upper_switch_convention)
uint32_t freq = LEG_FREQ;
/* ensures that timing_unit can be used as leg identifier */
for (int i = 0; i < LEG_NUMOF; i++)
for (unsigned int i = 0; i < LEG_NUMOF; i++)
{
leg_conf[leg_config[i].timing_unit] = leg_config[i];
}
......
......@@ -29,8 +29,8 @@
* @note This must only be included in owntech_leg_driver.c
*/
#ifndef LEG_CONF_H_
#define LEG_CONF_H_
#ifndef OWNTECH_LEG_DRIVER_H_
#define OWNTECH_LEG_DRIVER_H_
/**
* @brief Inverter leg configuration
......@@ -72,4 +72,4 @@ static leg_conf_t leg_config[] = {
#define LEG_NUMOF ARRAY_SIZE(leg_config)
#endif /* LEG_CONF_H_ */
#endif // OWNTECH_LEG_DRIVER_H_
if(CONFIG_OWNTECH_LEG_DRIVER)
zephyr_include_directories(.)
zephyr_library()
zephyr_library_sources(
owntech_leg_driver.c
)
endif()
config OWNTECH_LEG_DRIVER
bool "Enable OwnTech leg driver"
default y
name: owntech_leg_driver
build:
cmake: zephyr
kconfig: zephyr/Kconfig
......@@ -42,7 +42,6 @@ CONFIG_ASSERT=y
# OwnTech modules: uncomment a line to exclude a module
#CONFIG_OWNTECH_TIMER_DRIVER=n
#CONFIG_OWNTECH_HRTIM_DRIVER=n
#CONFIG_OWNTECH_LEG_DRIVER=n
#CONFIG_OWNTECH_NGND_DRIVER=n
#CONFIG_OWNTECH_DATA_ACQUISITION=n
#CONFIG_OWNTECH_VREFBUF_DRIVER=n
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment