arch/sim: Move the dummy foc driver to drivers/motor/foc

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-01-06 16:19:25 +08:00 committed by Xiang Xiao
parent d7ec3e30ae
commit b054bd9d37
13 changed files with 188 additions and 152 deletions

View File

@ -470,11 +470,4 @@ config SIM_UART3_NAME
default "/dev/ttySIM3" default "/dev/ttySIM3"
depends on SIM_UART_NUMBER >= 4 depends on SIM_UART_NUMBER >= 4
config SIM_MOTOR_FOC
bool "Simulated FOC device"
default n
depends on MOTOR_FOC
---help---
Build a simulated lower-half FOC device
endif # ARCH_SIM endif # ARCH_SIM

View File

@ -149,10 +149,6 @@ ifeq ($(CONFIG_ARCH_ROMGETC),y)
CSRCS += up_romgetc.c CSRCS += up_romgetc.c
endif endif
ifeq ($(CONFIG_SIM_MOTOR_FOC),y)
CSRCS += up_foc.c
endif
ifeq ($(CONFIG_SIM_NETDEV_TAP),y) ifeq ($(CONFIG_SIM_NETDEV_TAP),y)
CSRCS += up_netdriver.c CSRCS += up_netdriver.c
ifneq ($(CONFIG_WINDOWS_CYGWIN),y) ifneq ($(CONFIG_WINDOWS_CYGWIN),y)

View File

@ -26,6 +26,7 @@
#include <debug.h> #include <debug.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/power/pm.h> #include <nuttx/power/pm.h>
#include <nuttx/motor/foc/foc_dummy.h>
#include "up_internal.h" #include "up_internal.h"
@ -112,9 +113,9 @@ void up_idle(void)
up_timer_update(); up_timer_update();
#endif #endif
#ifdef CONFIG_SIM_MOTOR_FOC #ifdef CONFIG_MOTOR_FOC_DUMMY
/* Update simulated FOC device */ /* Update simulated FOC device */
sim_foc_update(); foc_dummy_update();
#endif #endif
} }

View File

@ -91,7 +91,6 @@
****************************************************************************/ ****************************************************************************/
struct tcb_s; struct tcb_s;
struct foc_dev_s;
struct ioexpander_dev_s; struct ioexpander_dev_s;
struct i2c_master_s; struct i2c_master_s;
@ -363,12 +362,5 @@ int sim_spi_uninitialize(struct spi_dev_s *dev);
void up_stack_color(void *stackbase, size_t nbytes); void up_stack_color(void *stackbase, size_t nbytes);
#endif #endif
/* up_foc.c *****************************************************************/
#ifdef CONFIG_MOTOR_FOC
struct foc_dev_s *sim_foc_initialize(int inst);
void sim_foc_update(void);
#endif
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __ARCH_SIM_SRC_UP_INTERNAL_H */ #endif /* __ARCH_SIM_SRC_UP_INTERNAL_H */

View File

@ -64,6 +64,7 @@ CONFIG_LIBC_FLOATINGPOINT=y
CONFIG_LIBM=y CONFIG_LIBM=y
CONFIG_MOTOR=y CONFIG_MOTOR=y
CONFIG_MOTOR_FOC=y CONFIG_MOTOR_FOC=y
CONFIG_MOTOR_FOC_DUMMY=y
CONFIG_MOTOR_FOC_INST=4 CONFIG_MOTOR_FOC_INST=4
CONFIG_NSH_ARCHINIT=y CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_ARCHROMFS=y CONFIG_NSH_ARCHROMFS=y
@ -84,7 +85,6 @@ CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_WAITPID=y CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_M32=y CONFIG_SIM_M32=y
CONFIG_SIM_MOTOR_FOC=y
CONFIG_START_MONTH=6 CONFIG_START_MONTH=6
CONFIG_START_YEAR=2008 CONFIG_START_YEAR=2008
CONFIG_SYSLOG_CONSOLE=y CONFIG_SYSLOG_CONSOLE=y

View File

@ -63,7 +63,7 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += sim_buttons.c CSRCS += sim_buttons.c
endif endif
ifeq ($(CONFIG_SIM_MOTOR_FOC),y) ifeq ($(CONFIG_MOTOR_FOC_DUMMY),y)
CSRCS += sim_foc.c CSRCS += sim_foc.c
endif endif

View File

@ -120,7 +120,7 @@ int sim_gpio_initialize(void);
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SIM_MOTOR_FOC #ifdef CONFIG_MOTOR_FOC_DUMMY
int sim_foc_setup(void); int sim_foc_setup(void);
#endif #endif

View File

@ -425,7 +425,7 @@ int sim_bringup(void)
} }
#endif #endif
#ifdef CONFIG_SIM_MOTOR_FOC #ifdef CONFIG_MOTOR_FOC_DUMMY
/* Setup FOC device */ /* Setup FOC device */
ret = sim_foc_setup(); ret = sim_foc_setup();

View File

@ -31,9 +31,7 @@
#include <arch/board/board.h> #include <arch/board/board.h>
#include <nuttx/motor/foc/foc_lower.h> #include <nuttx/motor/foc/foc_dummy.h>
#include "up_internal.h"
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
@ -76,7 +74,7 @@ int sim_foc_setup(void)
{ {
/* Initialize arch specific FOC lower-half */ /* Initialize arch specific FOC lower-half */
foc[i] = sim_foc_initialize(i); foc[i] = foc_dummy_initialize(i);
if (foc[i] == NULL) if (foc[i] == NULL)
{ {
ret = -errno; ret = -errno;

View File

@ -28,4 +28,10 @@ config MOTOR_FOC_TRACE
---help--- ---help---
Enables FOC driver trace interface. Enables FOC driver trace interface.
config MOTOR_FOC_DUMMY
bool "Simulated FOC device"
default n
---help---
Build a simulated lower-half FOC device
endif #MOTOR_FOC endif #MOTOR_FOC

View File

@ -22,6 +22,10 @@
CSRCS += foc_dev.c CSRCS += foc_dev.c
ifeq ($(CONFIG_MOTOR_FOC_DUMMY),y)
CSRCS += foc_dummy.c
endif
# Include FOC driver build support # Include FOC driver build support
DEPPATH += --dep-path motor$(DELIM)foc DEPPATH += --dep-path motor$(DELIM)foc

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* arch/sim/src/sim/up_foc.c * drivers/motor/foc/foc_dummy.c
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
@ -31,6 +31,7 @@
#include <assert.h> #include <assert.h>
#include <debug.h> #include <debug.h>
#include <nuttx/motor/foc/foc_dummy.h>
#include <nuttx/motor/foc/foc_lower.h> #include <nuttx/motor/foc/foc_lower.h>
/**************************************************************************** /****************************************************************************
@ -43,13 +44,13 @@
/* Board HW configuration */ /* Board HW configuration */
#define SIM_FOC_HW_PWM_NS (500) #define FOC_DUMMY_HW_PWM_NS (500)
#define SIM_FOC_HW_PWM_MAX (0.95f) #define FOC_DUMMY_HW_PWM_MAX (0.95f)
/* Helper macros ************************************************************/ /* Helper macros ************************************************************/
#define SIM_FOC_DATA_FROM_DEV_GET(d) \ #define FOC_DUMMY_DATA_FROM_DEV_GET(d) \
((FAR struct sim_foc_data_s *)(d)->lower->data) ((FAR struct foc_dummy_data_s *)(d)->lower->data)
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
@ -57,14 +58,14 @@
/* SIM FOC board data */ /* SIM FOC board data */
struct sim_foc_board_s struct foc_dummy_board_s
{ {
uint32_t reserved; uint32_t reserved;
}; };
/* SIM FOC specific data */ /* SIM FOC specific data */
struct sim_foc_data_s struct foc_dummy_data_s
{ {
/* Upper-half FOC controller callbacks */ /* Upper-half FOC controller callbacks */
@ -72,7 +73,7 @@ struct sim_foc_data_s
/* SIM FOC board data */ /* SIM FOC board data */
FAR struct sim_foc_board_s *board; FAR struct foc_dummy_board_s *board;
/* Phase currents */ /* Phase currents */
@ -93,34 +94,34 @@ struct sim_foc_data_s
/* Lower-half FOC operations */ /* Lower-half FOC operations */
static int sim_foc_configure(FAR struct foc_dev_s *dev, static int foc_dummy_configure(FAR struct foc_dev_s *dev,
FAR struct foc_cfg_s *cfg); FAR struct foc_cfg_s *cfg);
static int sim_foc_setup(FAR struct foc_dev_s *dev); static int foc_dummy_setup(FAR struct foc_dev_s *dev);
static int sim_foc_shutdown(FAR struct foc_dev_s *dev); static int foc_dummy_shutdown(FAR struct foc_dev_s *dev);
static int sim_foc_start(FAR struct foc_dev_s *dev, bool state); static int foc_dummy_start(FAR struct foc_dev_s *dev, bool state);
static int sim_foc_pwm_duty_set(FAR struct foc_dev_s *dev, static int foc_dummy_pwm_duty_set(FAR struct foc_dev_s *dev,
FAR foc_duty_t *duty); FAR foc_duty_t *duty);
static int sim_foc_ioctl(FAR struct foc_dev_s *dev, int cmd, static int foc_dummy_ioctl(FAR struct foc_dev_s *dev, int cmd,
unsigned long arg); unsigned long arg);
static int sim_foc_bind(FAR struct foc_dev_s *dev, static int foc_dummy_bind(FAR struct foc_dev_s *dev,
FAR struct foc_callbacks_s *cb); FAR struct foc_callbacks_s *cb);
static int sim_foc_fault_clear(FAR struct foc_dev_s *dev); static int foc_dummy_fault_clear(FAR struct foc_dev_s *dev);
#ifdef CONFIG_MOTOR_FOC_TRACE #ifdef CONFIG_MOTOR_FOC_TRACE
static void sim_foc_trace(FAR struct foc_dev_s *dev, int type, bool state); static void foc_dummy_trace(FAR struct foc_dev_s *dev, int type, bool state);
#endif #endif
/* Handlers */ /* Handlers */
static int sim_foc_notifier_handler(FAR struct foc_dev_s *dev); static void foc_dummy_notifier_handler(FAR struct foc_dev_s *dev);
/* Helpers */ /* Helpers */
static void sim_foc_hw_config_get(FAR struct foc_dev_s *dev); static void foc_dummy_hw_config_get(FAR struct foc_dev_s *dev);
static int sim_foc_notifier_cfg(FAR struct foc_dev_s *dev, uint32_t freq); static int foc_dummy_notifier_cfg(FAR struct foc_dev_s *dev, uint32_t freq);
static int sim_foc_pwm_setup(FAR struct foc_dev_s *dev, uint32_t freq); static int foc_dummy_pwm_setup(FAR struct foc_dev_s *dev, uint32_t freq);
static int sim_foc_pwm_start(FAR struct foc_dev_s *dev, bool state); static int foc_dummy_pwm_start(FAR struct foc_dev_s *dev, bool state);
static int sim_foc_adc_setup(FAR struct foc_dev_s *dev); static int foc_dummy_adc_setup(FAR struct foc_dev_s *dev);
static int sim_foc_adc_start(FAR struct foc_dev_s *dev, bool state); static int foc_dummy_adc_start(FAR struct foc_dev_s *dev, bool state);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@ -128,29 +129,29 @@ static int sim_foc_adc_start(FAR struct foc_dev_s *dev, bool state);
/* SIM FOC specific data */ /* SIM FOC specific data */
static struct sim_foc_data_s g_sim_foc_data[CONFIG_MOTOR_FOC_INST]; static struct foc_dummy_data_s g_foc_dummy_data[CONFIG_MOTOR_FOC_INST];
static struct sim_foc_board_s g_sim_foc_board[CONFIG_MOTOR_FOC_INST]; static struct foc_dummy_board_s g_foc_dummy_board[CONFIG_MOTOR_FOC_INST];
/* SIM specific FOC ops */ /* SIM specific FOC ops */
static struct foc_lower_ops_s g_sim_foc_ops = static struct foc_lower_ops_s g_foc_dummy_ops =
{ {
.configure = sim_foc_configure, foc_dummy_configure,
.setup = sim_foc_setup, foc_dummy_setup,
.shutdown = sim_foc_shutdown, foc_dummy_shutdown,
.start = sim_foc_start, foc_dummy_pwm_duty_set,
.pwm_duty_set = sim_foc_pwm_duty_set, foc_dummy_start,
.ioctl = sim_foc_ioctl, foc_dummy_ioctl,
.bind = sim_foc_bind, foc_dummy_bind,
.fault_clear = sim_foc_fault_clear, foc_dummy_fault_clear,
#ifdef CONFIG_MOTOR_FOC_TRACE #ifdef CONFIG_MOTOR_FOC_TRACE
.trace = sim_foc_trace foc_dummy_trace
#endif #endif
}; };
/* FOC lower-half */ /* FOC lower-half */
static struct foc_lower_s g_sim_foc_lower[CONFIG_MOTOR_FOC_INST]; static struct foc_lower_s g_foc_dummy_lower[CONFIG_MOTOR_FOC_INST];
/* FOC upper-half device data */ /* FOC upper-half device data */
@ -161,16 +162,16 @@ static struct foc_dev_s g_foc_dev[CONFIG_MOTOR_FOC_INST];
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: sim_foc_pwm_setup * Name: foc_dummy_pwm_setup
* *
* Description: * Description:
* Setup PWM for FOC controller * Setup PWM for FOC controller
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_pwm_setup(FAR struct foc_dev_s *dev, uint32_t freq) static int foc_dummy_pwm_setup(FAR struct foc_dev_s *dev, uint32_t freq)
{ {
FAR struct sim_foc_data_s *sim = SIM_FOC_DATA_FROM_DEV_GET(dev); FAR struct foc_dummy_data_s *sim = FOC_DUMMY_DATA_FROM_DEV_GET(dev);
DEBUGASSERT(dev); DEBUGASSERT(dev);
DEBUGASSERT(sim); DEBUGASSERT(sim);
@ -187,36 +188,36 @@ static int sim_foc_pwm_setup(FAR struct foc_dev_s *dev, uint32_t freq)
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_start * Name: foc_dummy_start
* *
* Description: * Description:
* Start/stop PWM for the FOC controller * Start/stop PWM for the FOC controller
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_start(FAR struct foc_dev_s *dev, bool state) static int foc_dummy_start(FAR struct foc_dev_s *dev, bool state)
{ {
FAR struct sim_foc_data_s *sim = SIM_FOC_DATA_FROM_DEV_GET(dev); FAR struct foc_dummy_data_s *sim = FOC_DUMMY_DATA_FROM_DEV_GET(dev);
irqstate_t flags; irqstate_t flags;
int ret = OK; int ret = OK;
mtrinfo("[FOC_START] state=%d\n", state); mtrinfo("[FOC_START] state=%d\n", state);
/* Start PWM */ /* Start PWM */
ret = sim_foc_pwm_start(dev, state); ret = foc_dummy_pwm_start(dev, state);
if (ret < 0) if (ret < 0)
{ {
mtrerr("sim_foc_pwm_start failed %d\n", ret); mtrerr("foc_dummy_pwm_start failed %d\n", ret);
goto errout; goto errout;
} }
/* Start ADC */ /* Start ADC */
ret = sim_foc_adc_start(dev, state); ret = foc_dummy_adc_start(dev, state);
if (ret < 0) if (ret < 0)
{ {
mtrerr("sim_foc_adc_start failed %d\n", ret); mtrerr("foc_dummy_adc_start failed %d\n", ret);
goto errout; goto errout;
} }
@ -231,14 +232,14 @@ errout:
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_pwm_start * Name: foc_dummy_pwm_start
* *
* Description: * Description:
* Start/stop PWM for the FOC controller * Start/stop PWM for the FOC controller
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_pwm_start(FAR struct foc_dev_s *dev, bool state) static int foc_dummy_pwm_start(FAR struct foc_dev_s *dev, bool state)
{ {
DEBUGASSERT(dev); DEBUGASSERT(dev);
@ -248,14 +249,14 @@ static int sim_foc_pwm_start(FAR struct foc_dev_s *dev, bool state)
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_adc_setup * Name: foc_dummy_adc_setup
* *
* Description: * Description:
* Setup ADC for the FOC controller * Setup ADC for the FOC controller
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_adc_setup(FAR struct foc_dev_s *dev) static int foc_dummy_adc_setup(FAR struct foc_dev_s *dev)
{ {
DEBUGASSERT(dev); DEBUGASSERT(dev);
@ -265,14 +266,14 @@ static int sim_foc_adc_setup(FAR struct foc_dev_s *dev)
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_adc_start * Name: foc_dummy_adc_start
* *
* Description: * Description:
* Start/stop ADC conversion for the FOC controller * Start/stop ADC conversion for the FOC controller
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_adc_start(FAR struct foc_dev_s *dev, bool state) static int foc_dummy_adc_start(FAR struct foc_dev_s *dev, bool state)
{ {
DEBUGASSERT(dev); DEBUGASSERT(dev);
@ -282,17 +283,17 @@ static int sim_foc_adc_start(FAR struct foc_dev_s *dev, bool state)
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_notifier_cfg * Name: foc_dummy_notifier_cfg
* *
* Description: * Description:
* Configure FOC notifier * Configure FOC notifier
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_notifier_cfg(FAR struct foc_dev_s *dev, uint32_t freq) static int foc_dummy_notifier_cfg(FAR struct foc_dev_s *dev, uint32_t freq)
{ {
FAR struct sim_foc_data_s *sim = SIM_FOC_DATA_FROM_DEV_GET(dev); FAR struct foc_dummy_data_s *sim = FOC_DUMMY_DATA_FROM_DEV_GET(dev);
int ret = OK; int ret = OK;
DEBUGASSERT(dev); DEBUGASSERT(dev);
DEBUGASSERT(sim); DEBUGASSERT(sim);
@ -317,18 +318,18 @@ errout:
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_configure * Name: foc_dummy_configure
* *
* Description: * Description:
* Arch-specific FOC controller configuration * Arch-specific FOC controller configuration
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_configure(FAR struct foc_dev_s *dev, static int foc_dummy_configure(FAR struct foc_dev_s *dev,
FAR struct foc_cfg_s *cfg) FAR struct foc_cfg_s *cfg)
{ {
FAR struct sim_foc_data_s *sim = SIM_FOC_DATA_FROM_DEV_GET(dev); FAR struct foc_dummy_data_s *sim = FOC_DUMMY_DATA_FROM_DEV_GET(dev);
int ret = OK; int ret = OK;
DEBUGASSERT(dev); DEBUGASSERT(dev);
DEBUGASSERT(sim); DEBUGASSERT(sim);
@ -340,28 +341,28 @@ static int sim_foc_configure(FAR struct foc_dev_s *dev,
/* Configure ADC */ /* Configure ADC */
ret = sim_foc_adc_setup(dev); ret = foc_dummy_adc_setup(dev);
if (ret < 0) if (ret < 0)
{ {
mtrerr("sim_foc_adc_setup failed %d\n", ret); mtrerr("foc_dummy_adc_setup failed %d\n", ret);
goto errout; goto errout;
} }
/* Configure PWM */ /* Configure PWM */
ret = sim_foc_pwm_setup(dev, cfg->pwm_freq); ret = foc_dummy_pwm_setup(dev, cfg->pwm_freq);
if (ret < 0) if (ret < 0)
{ {
mtrerr("sim_foc_pwm_setup failed %d\n", ret); mtrerr("foc_dummy_pwm_setup failed %d\n", ret);
goto errout; goto errout;
} }
/* Configure notifier */ /* Configure notifier */
ret = sim_foc_notifier_cfg(dev, cfg->notifier_freq); ret = foc_dummy_notifier_cfg(dev, cfg->notifier_freq);
if (ret < 0) if (ret < 0)
{ {
mtrerr("sim_foc_notifier_cfg failed %d\n", ret); mtrerr("foc_dummy_notifier_cfg failed %d\n", ret);
goto errout; goto errout;
} }
@ -374,14 +375,14 @@ errout:
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_setup * Name: foc_dummy_setup
* *
* Description: * Description:
* Arch-specific FOC controller setup * Arch-specific FOC controller setup
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_setup(FAR struct foc_dev_s *dev) static int foc_dummy_setup(FAR struct foc_dev_s *dev)
{ {
DEBUGASSERT(dev); DEBUGASSERT(dev);
@ -389,20 +390,20 @@ static int sim_foc_setup(FAR struct foc_dev_s *dev)
/* Get HW configuration */ /* Get HW configuration */
sim_foc_hw_config_get(dev); foc_dummy_hw_config_get(dev);
return OK; return OK;
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_shutdown * Name: foc_dummy_shutdown
* *
* Description: * Description:
* Arch-specific FOC controller shutdown * Arch-specific FOC controller shutdown
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_shutdown(FAR struct foc_dev_s *dev) static int foc_dummy_shutdown(FAR struct foc_dev_s *dev)
{ {
DEBUGASSERT(dev); DEBUGASSERT(dev);
@ -412,15 +413,15 @@ static int sim_foc_shutdown(FAR struct foc_dev_s *dev)
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_ioctl * Name: foc_dummy_ioctl
* *
* Description: * Description:
* Arch-specific FOC controller ioctl * Arch-specific FOC controller ioctl
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_ioctl(FAR struct foc_dev_s *dev, int cmd, static int foc_dummy_ioctl(FAR struct foc_dev_s *dev, int cmd,
unsigned long arg) unsigned long arg)
{ {
int ret = OK; int ret = OK;
@ -441,25 +442,22 @@ static int sim_foc_ioctl(FAR struct foc_dev_s *dev, int cmd,
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_notifier_handler * Name: foc_dummy_notifier_handler
* *
* Description: * Description:
* Handle ADC conversion and notofiy user-space * Handle ADC conversion and notofiy user-space
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_notifier_handler(FAR struct foc_dev_s *dev) static void foc_dummy_notifier_handler(FAR struct foc_dev_s *dev)
{ {
FAR struct sim_foc_data_s *sim = SIM_FOC_DATA_FROM_DEV_GET(dev); FAR struct foc_dummy_data_s *sim = FOC_DUMMY_DATA_FROM_DEV_GET(dev);
irqstate_t flags;
DEBUGASSERT(dev); DEBUGASSERT(dev);
DEBUGASSERT(sim); DEBUGASSERT(sim);
mtrinfo("[FOC_NOTIFIER_HANDLER] cntr=%d\n", sim->notifier_cntr); mtrinfo("[FOC_NOTIFIER_HANDLER] cntr=%d\n", sim->notifier_cntr);
flags = enter_critical_section();
/* Call FOC notifier handler */ /* Call FOC notifier handler */
if (sim->notifier_cntr % sim->notifier_div == 0) if (sim->notifier_cntr % sim->notifier_div == 0)
@ -472,10 +470,6 @@ static int sim_foc_notifier_handler(FAR struct foc_dev_s *dev)
/* Increase counter */ /* Increase counter */
sim->notifier_cntr += 1; sim->notifier_cntr += 1;
leave_critical_section(flags);
return OK;
} }
/**************************************************************************** /****************************************************************************
@ -486,8 +480,8 @@ static int sim_foc_notifier_handler(FAR struct foc_dev_s *dev)
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_pwm_duty_set(FAR struct foc_dev_s *dev, static int foc_dummy_pwm_duty_set(FAR struct foc_dev_s *dev,
FAR foc_duty_t *duty) FAR foc_duty_t *duty)
{ {
int i = 0; int i = 0;
@ -515,36 +509,36 @@ static int sim_foc_pwm_duty_set(FAR struct foc_dev_s *dev,
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_hw_config_get * Name: foc_dummy_hw_config_get
* *
* Description: * Description:
* Get HW configuration for FOC controller * Get HW configuration for FOC controller
* *
****************************************************************************/ ****************************************************************************/
static void sim_foc_hw_config_get(FAR struct foc_dev_s *dev) static void foc_dummy_hw_config_get(FAR struct foc_dev_s *dev)
{ {
DEBUGASSERT(dev); DEBUGASSERT(dev);
/* Get HW configuration */ /* Get HW configuration */
dev->info.hw_cfg.pwm_dt_ns = SIM_FOC_HW_PWM_NS; dev->info.hw_cfg.pwm_dt_ns = FOC_DUMMY_HW_PWM_NS;
dev->info.hw_cfg.pwm_max = ftob16(SIM_FOC_HW_PWM_MAX); dev->info.hw_cfg.pwm_max = ftob16(FOC_DUMMY_HW_PWM_MAX);
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_bind * Name: foc_dummy_bind
* *
* Description: * Description:
* Bind lower-half FOC controller with upper-half FOC logic * Bind lower-half FOC controller with upper-half FOC logic
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_bind(FAR struct foc_dev_s *dev, static int foc_dummy_bind(FAR struct foc_dev_s *dev,
FAR struct foc_callbacks_s *cb) FAR struct foc_callbacks_s *cb)
{ {
FAR struct sim_foc_data_s *sim = SIM_FOC_DATA_FROM_DEV_GET(dev); FAR struct foc_dummy_data_s *sim = FOC_DUMMY_DATA_FROM_DEV_GET(dev);
int ret = OK; int ret = OK;
DEBUGASSERT(dev); DEBUGASSERT(dev);
DEBUGASSERT(cb); DEBUGASSERT(cb);
@ -559,14 +553,14 @@ static int sim_foc_bind(FAR struct foc_dev_s *dev,
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_fault_clear * Name: foc_dummy_fault_clear
* *
* Description: * Description:
* Arch-specific fault clear * Arch-specific fault clear
* *
****************************************************************************/ ****************************************************************************/
static int sim_foc_fault_clear(FAR struct foc_dev_s *dev) static int foc_dummy_fault_clear(FAR struct foc_dev_s *dev)
{ {
DEBUGASSERT(dev); DEBUGASSERT(dev);
@ -577,14 +571,14 @@ static int sim_foc_fault_clear(FAR struct foc_dev_s *dev)
#ifdef CONFIG_MOTOR_FOC_TRACE #ifdef CONFIG_MOTOR_FOC_TRACE
/**************************************************************************** /****************************************************************************
* Name: sim_foc_trace * Name: foc_dummy_trace
* *
* Description: * Description:
* SIM FOC trace * SIM FOC trace
* *
****************************************************************************/ ****************************************************************************/
static void sim_foc_trace(FAR struct foc_dev_s *dev, int type, bool state) static void foc_dummy_trace(FAR struct foc_dev_s *dev, int type, bool state)
{ {
DEBUGASSERT(dev); DEBUGASSERT(dev);
@ -597,14 +591,14 @@ static void sim_foc_trace(FAR struct foc_dev_s *dev, int type, bool state)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: sim_foc_initialize * Name: foc_dummy_initialize
* *
* Description: * Description:
* Initialize the FOC controller lower-half support. * Initialize the FOC controller lower-half support.
* *
****************************************************************************/ ****************************************************************************/
FAR struct foc_dev_s *sim_foc_initialize(int inst) FAR struct foc_dev_s *foc_dummy_initialize(int inst)
{ {
FAR struct foc_lower_s *foc_lower = NULL; FAR struct foc_lower_s *foc_lower = NULL;
FAR struct foc_dev_s *dev = NULL; FAR struct foc_dev_s *dev = NULL;
@ -613,20 +607,20 @@ FAR struct foc_dev_s *sim_foc_initialize(int inst)
/* Reset data */ /* Reset data */
memset(&g_sim_foc_data[inst], 0, sizeof(struct sim_foc_data_s)); memset(&g_foc_dummy_data[inst], 0, sizeof(struct foc_dummy_data_s));
/* Get SIM FOC arch-specific driver */ /* Get SIM FOC arch-specific driver */
foc_lower = &g_sim_foc_lower[inst]; foc_lower = &g_foc_dummy_lower[inst];
/* Connect ops, data and dev with arch-specific FOC driver */ /* Connect ops, data and dev with arch-specific FOC driver */
foc_lower->data = &g_sim_foc_data[inst]; foc_lower->data = &g_foc_dummy_data[inst];
foc_lower->ops = &g_sim_foc_ops; foc_lower->ops = &g_foc_dummy_ops;
/* Connect board data */ /* Connect board data */
g_sim_foc_data[inst].board = &g_sim_foc_board[inst]; g_foc_dummy_data[inst].board = &g_foc_dummy_board[inst];
/* Get FOC device */ /* Get FOC device */
@ -642,20 +636,20 @@ FAR struct foc_dev_s *sim_foc_initialize(int inst)
} }
/**************************************************************************** /****************************************************************************
* Name: sim_foc_update * Name: foc_dummy_update
* *
* Description: * Description:
* Called periodically from the IDLE loop to simulate FOC driver interrupts * Called periodically from the IDLE loop to simulate FOC driver interrupts
* *
****************************************************************************/ ****************************************************************************/
void sim_foc_update(void) void foc_dummy_update(void)
{ {
FAR struct foc_dev_s *dev = NULL; FAR struct foc_dev_s *dev = NULL;
FAR struct sim_foc_data_s *sim = NULL; FAR struct foc_dummy_data_s *sim = NULL;
static uint32_t cntr = 0; static uint32_t cntr = 0;
int i = 0; int i = 0;
irqstate_t flags; irqstate_t flags;
/* Increase local counter */ /* Increase local counter */
@ -673,11 +667,11 @@ void sim_foc_update(void)
/* Get SIM data */ /* Get SIM data */
sim = SIM_FOC_DATA_FROM_DEV_GET(dev); sim = FOC_DUMMY_DATA_FROM_DEV_GET(dev);
if (sim->state == true) if (sim->state == true)
{ {
sim_foc_notifier_handler(dev); foc_dummy_notifier_handler(dev);
} }
} }

View File

@ -0,0 +1,52 @@
/****************************************************************************
* include/nuttx/motor/foc/foc_dummy.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_MOTOR_FOC_FOC_DUMMY_H
#define __INCLUDE_NUTTX_MOTOR_FOC_FOC_DUMMY_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/motor/foc/foc.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
#ifdef CONFIG_MOTOR_FOC_DUMMY
FAR struct foc_dev_s *foc_dummy_initialize(int inst);
void foc_dummy_update(void);
#endif
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_NUTTX_MOTOR_FOC_FOC_DUMMY_H */