drivers/foc: add support for FOC power-stage driver

There are ICs available on the market that integrate various power inverter
features. The driver for such a device must be tightly coupled to a FOC device
as using it as a separate device doesn't make sense.
This commit is contained in:
raiden00pl 2023-11-07 13:41:55 +01:00 committed by Xiang Xiao
parent f4b77f078b
commit 4bad6048f0
8 changed files with 176 additions and 0 deletions

View File

@ -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

View File

@ -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()

View File

@ -38,4 +38,7 @@ config MOTOR_FOC_DUMMY
---help---
Build a simulated lower-half FOC device
config MOTOR_FOC_FOCPWR
bool
endif #MOTOR_FOC

View File

@ -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

View File

@ -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 <nuttx/config.h>
#include <assert.h>
#include <nuttx/motor/foc/foc_pwr.h>
/****************************************************************************
* 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;
}

View File

@ -30,6 +30,8 @@
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/motor/foc/foc_pwr.h>
#include <stdbool.h>
#include <fixedmath.h>
@ -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 */
};
/****************************************************************************

View File

@ -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 <nuttx/config.h>
#include <nuttx/motor/foc/foc.h>
/****************************************************************************
* 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 */

View File

@ -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 */