diff --git a/Documentation/components/drivers/character/motor/foc.rst b/Documentation/components/drivers/character/motor/foc.rst index e694cc06e6d..a1f04bc965b 100644 --- a/Documentation/components/drivers/character/motor/foc.rst +++ b/Documentation/components/drivers/character/motor/foc.rst @@ -28,6 +28,8 @@ Files supporting FOC can be found in the following locations: "Lower-half" FOC interface. - ``drivers/motor/foc/foc_dev.c``. The generic "upper half" FOC driver. +- ``drivers/motor/foc/foc_pwr.c``. + The generic power stage for FOC. The majority of the functionality available to the application is implemented in driver ioctl calls. Supported ioctl commands: @@ -46,3 +48,8 @@ is implemented in driver ioctl calls. Supported ioctl commands: arg: ``struct foc_cfg_s`` pointer. - ``MTRIOC_GET_INFO`` - Get the FOC device info, arg: ``struct foc_info_s`` pointer. + +Additionally, board logic can implement: + +- ``MTRIOC_SET_BOARDCFG`` - which returns the board specific FOC configuration +- ``MTRIOC_GET_BOARDCFG`` - which sets the board-specific FOC configuration diff --git a/drivers/motor/foc/CMakeLists.txt b/drivers/motor/foc/CMakeLists.txt index 9f5c8f323b5..733252e0cdb 100644 --- a/drivers/motor/foc/CMakeLists.txt +++ b/drivers/motor/foc/CMakeLists.txt @@ -24,6 +24,10 @@ if(CONFIG_MOTOR_FOC) list(APPEND SRCS foc_dummy.c) endif() + if(CONFIG_MOTOR_FOC_FOCPWR) + list(APPEND SRCS foc_pwr.c) + endif() + target_include_directories(drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_sources(drivers PRIVATE ${SRCS}) endif() diff --git a/drivers/motor/foc/Kconfig b/drivers/motor/foc/Kconfig index 3a363010537..82cd9af3a7a 100644 --- a/drivers/motor/foc/Kconfig +++ b/drivers/motor/foc/Kconfig @@ -38,4 +38,7 @@ config MOTOR_FOC_DUMMY ---help--- Build a simulated lower-half FOC device +config MOTOR_FOC_FOCPWR + bool + endif #MOTOR_FOC diff --git a/drivers/motor/foc/Make.defs b/drivers/motor/foc/Make.defs index 0a78c0ef877..ae29d7e982f 100644 --- a/drivers/motor/foc/Make.defs +++ b/drivers/motor/foc/Make.defs @@ -26,6 +26,10 @@ ifeq ($(CONFIG_MOTOR_FOC_DUMMY),y) CSRCS += foc_dummy.c endif +ifeq ($(CONFIG_MOTOR_FOC_FOCPWR),y) +CSRCS += foc_pwr.c +endif + # Include FOC driver build support DEPPATH += --dep-path motor$(DELIM)foc diff --git a/drivers/motor/foc/foc_pwr.c b/drivers/motor/foc/foc_pwr.c new file mode 100644 index 00000000000..521c78ffd1e --- /dev/null +++ b/drivers/motor/foc/foc_pwr.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * drivers/motor/foc/foc_pwr.c + * Power-stage FOC logic + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: focpwr_initialize + * + * Description: + * Initialize the FOC common power-stage data + * + * Input Parameters: + * pwr - An instance of the FOC power-stage device + * devno - An instance number + * dev - An instance of the FOC device + * ops - power stage ops + * + ****************************************************************************/ + +int focpwr_initialize(FAR struct focpwr_dev_s *pwr, + int devno, + FAR struct foc_dev_s *dev, + FAR struct focpwr_ops_s *ops) +{ + DEBUGASSERT(ops->setup); + DEBUGASSERT(ops->shutdown); + DEBUGASSERT(ops->calibration); + DEBUGASSERT(ops->ioctl); + + pwr->dev = dev; + pwr->devno = devno; + pwr->ops = ops; + + /* Connet to FOC device */ + + dev->pwr = pwr; + + return OK; +} diff --git a/include/nuttx/motor/foc/foc.h b/include/nuttx/motor/foc/foc.h index 497992f0910..293a14ec6ce 100644 --- a/include/nuttx/motor/foc/foc.h +++ b/include/nuttx/motor/foc/foc.h @@ -30,6 +30,8 @@ #include #include +#include + #include #include @@ -46,6 +48,8 @@ #define FOCDUTY_TO_FLOAT(d) (b16tof(d)) #define FOCDUTY_TO_FIXED16(d) (d) +#define FOC_BOARDCFG_GAINLIST_LEN 4 + /**************************************************************************** * Public Types ****************************************************************************/ @@ -133,6 +137,19 @@ struct foc_info_s struct foc_info_hw_s hw_cfg; /* Hardware specific informations */ }; +/* FOC board-specific configuration */ + +struct foc_set_boardcfg_s +{ + int gain; +}; + +struct foc_get_boardcfg_s +{ + int gain; + int gain_list[FOC_BOARDCFG_GAINLIST_LEN]; +}; + /* FOC device upper-half */ struct foc_lower_s; @@ -160,6 +177,10 @@ struct foc_dev_s /* FOC device input/output data *******************************************/ struct foc_state_s state; /* FOC device state */ + + /* (Optional) FOC power-stage driver *************************************/ + + FAR struct focpwr_dev_s *pwr; /* FOC power-stage driver */ }; /**************************************************************************** diff --git a/include/nuttx/motor/foc/foc_pwr.h b/include/nuttx/motor/foc/foc_pwr.h new file mode 100644 index 00000000000..730847ea5d3 --- /dev/null +++ b/include/nuttx/motor/foc/foc_pwr.h @@ -0,0 +1,66 @@ +/**************************************************************************** + * include/nuttx/motor/foc/foc_pwr.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_PWR_H +#define __INCLUDE_NUTTX_MOTOR_FOC_FOC_PWR_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* FOC power-stage driver operations */ + +struct focpwr_dev_s; +struct focpwr_ops_s +{ + CODE int (*setup)(FAR struct focpwr_dev_s *dev); + CODE int (*shutdown)(FAR struct focpwr_dev_s *dev); + CODE int (*calibration)(FAR struct focpwr_dev_s *dev, bool state); + CODE int (*ioctl)(FAR struct focpwr_dev_s *dev, int cmd, + unsigned long arg); +}; + +/* FOC power-stage driver */ + +struct focpwr_dev_s +{ + FAR struct foc_dev_s *dev; + FAR struct focpwr_ops_s *ops; + int devno; +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int focpwr_initialize(FAR struct focpwr_dev_s *pwr, + int devno, + FAR struct foc_dev_s *dev, + FAR struct focpwr_ops_s *ops); + +#endif /* __INCLUDE_NUTTX_MOTOR_FOC_FOC_PWR_H */ diff --git a/include/nuttx/motor/motor_ioctl.h b/include/nuttx/motor/motor_ioctl.h index abf9c5b9309..c5c01df90d4 100644 --- a/include/nuttx/motor/motor_ioctl.h +++ b/include/nuttx/motor/motor_ioctl.h @@ -53,5 +53,7 @@ #define MTRIOC_CALIBRATE _MTRIOC(13) #define MTRIOC_SELFTEST _MTRIOC(14) #define MTRIOC_SET_CALIBDATA _MTRIOC(15) +#define MTRIOC_SET_BOARDCFG _MTRIOC(16) +#define MTRIOC_GET_BOARDCFG _MTRIOC(17) #endif /* __INCLUDE_NUTTX_MOTOR_MOTOR_IOCTL_H */