examples/foc/foc_thr: get controller type from controller ID

This commit is contained in:
raiden00pl 2023-05-17 12:31:07 +02:00 committed by Xiang Xiao
parent 54bcf3afdd
commit 55b296a5c6
2 changed files with 39 additions and 18 deletions

View File

@ -35,6 +35,17 @@
#include "industry/foc/foc_common.h" #include "industry/foc/foc_common.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef CONFIG_EXAMPLES_FOC_FLOAT_INST
# define CONFIG_EXAMPLES_FOC_FLOAT_INST (0)
#endif
#ifndef CONFIG_EXAMPLES_FOC_FIXED16_INST
# define CONFIG_EXAMPLES_FOC_FIXED16_INST (0)
#endif
/**************************************************************************** /****************************************************************************
* Extern Functions Prototypes * Extern Functions Prototypes
****************************************************************************/ ****************************************************************************/
@ -80,30 +91,14 @@ static FAR void *foc_control_thr(FAR void *arg)
/* Get controller type */ /* Get controller type */
pthread_mutex_lock(&g_cntr_lock); envp->type = foc_thread_type(envp->id);
if (envp->type == -1)
#ifdef CONFIG_INDUSTRY_FOC_FLOAT
if (g_float_thr_cntr < CONFIG_EXAMPLES_FOC_FLOAT_INST)
{
envp->type = FOC_NUMBER_TYPE_FLOAT;
}
else
#endif
#ifdef CONFIG_INDUSTRY_FOC_FIXED16
if (g_fixed16_thr_cntr < CONFIG_EXAMPLES_FOC_FIXED16_INST)
{
envp->type = FOC_NUMBER_TYPE_FIXED16;
}
else
#endif
{ {
/* Invalid configuration */ /* Invalid configuration */
ASSERT(0); ASSERT(0);
} }
pthread_mutex_unlock(&g_cntr_lock);
PRINTF("FOC device %d type = %d!\n", envp->id, envp->type); PRINTF("FOC device %d type = %d!\n", envp->id, envp->type);
/* Get queue name */ /* Get queue name */
@ -283,6 +278,31 @@ uint32_t foc_threads_get(void)
return ret; return ret;
} }
/****************************************************************************
* Name: foc_thread_type
****************************************************************************/
int foc_thread_type(int id)
{
int ret = -1;
#ifdef CONFIG_INDUSTRY_FOC_FLOAT
if (id < CONFIG_EXAMPLES_FOC_FLOAT_INST)
{
ret = FOC_NUMBER_TYPE_FLOAT;
}
#endif
#ifdef CONFIG_INDUSTRY_FOC_FIXED16
if (id < CONFIG_EXAMPLES_FOC_FLOAT_INST + CONFIG_EXAMPLES_FOC_FIXED16_INST)
{
ret = FOC_NUMBER_TYPE_FIXED16;
}
#endif
return ret;
}
/**************************************************************************** /****************************************************************************
* Name: foc_ctrlthr_init * Name: foc_ctrlthr_init
****************************************************************************/ ****************************************************************************/

View File

@ -126,6 +126,7 @@ int foc_threads_init(void);
void foc_threads_deinit(void); void foc_threads_deinit(void);
bool foc_threads_terminated(void); bool foc_threads_terminated(void);
uint32_t foc_threads_get(void); uint32_t foc_threads_get(void);
int foc_thread_type(int id);
int foc_ctrlthr_init(FAR struct foc_ctrl_env_s *foc, int i, FAR mqd_t *mqd, int foc_ctrlthr_init(FAR struct foc_ctrl_env_s *foc, int i, FAR mqd_t *mqd,
FAR pthread_t *thread); FAR pthread_t *thread);