file_path
stringlengths 20
207
| content
stringlengths 5
3.85M
| size
int64 5
3.85M
| lang
stringclasses 9
values | avg_line_length
float64 1.33
100
| max_line_length
int64 4
993
| alphanum_fraction
float64 0.26
0.93
|
---|---|---|---|---|---|---|
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Src/unit_conversions.c | /**
******************************************************************************
* @file unit_conversions.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the features
* of units conversion of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "unit_conversions.h"
#include "arm_math.h"
#define RAD3DIV3 0.577350269f
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
int16_t Convert_Rad_to16bit(float fAngle_rad)
{
int16_t hElAngle;
hElAngle = (int16_t) ((fAngle_rad*32767.0f)/(float)PI);
return (hElAngle);
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
Signal_Components Convert_s16_to_A(qd_t hIqd)
{
float fConvfactor = (float)ADC_REFERENCE_VOLTAGE/(65536.0f*(float)RSHUNT*(float)AMPLIFICATION_GAIN);
Signal_Components fIqdA;
fIqdA.fS_Component1 = (float)hIqd.q*fConvfactor;
fIqdA.fS_Component2 = (float)hIqd.d*fConvfactor;
return fIqdA;
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
qd_t Convert_A_to_s16(Signal_Components fIqdA)
{
float fConvfactor = (float)ADC_REFERENCE_VOLTAGE/(65536.0f*(float)RSHUNT*(float)AMPLIFICATION_GAIN);
qd_t hIqd;
hIqd.q = (int16_t)(fIqdA.fS_Component1/fConvfactor);
hIqd.d = (int16_t)(fIqdA.fS_Component2/fConvfactor);
return hIqd;
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
Signal_Components Convert_s16_to_V(BusVoltageSensor_Handle_t *pBVS, qd_t hVqd)
{
float fConvfactor = ((float)RAD3DIV3* (float)VBS_GetAvBusVoltage_V(pBVS))/32767.0f;
Signal_Components fVqd_V;
fVqd_V.fS_Component1 = (float)hVqd.q*fConvfactor;
fVqd_V.fS_Component2 = (float)hVqd.d*fConvfactor;
return fVqd_V;
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
qd_t Convert_V_to_s16(BusVoltageSensor_Handle_t *pBVS, Signal_Components fVqd_V)
{
float fConvfactor = 32767.0f/((float)RAD3DIV3* (float)VBS_GetAvBusVoltage_V(pBVS));
qd_t hVqd;
float ftempVq = (fVqd_V.fS_Component1*fConvfactor);
float ftempVd = (fVqd_V.fS_Component2*fConvfactor);
if(ftempVq >32767.0f)
{
ftempVq = 32767.0f;
}
if(ftempVd >32767.0f)
{
ftempVd = 32767.0f;
}
hVqd.q = (int16_t)ftempVq;
hVqd.d = (int16_t)ftempVd;
return hVqd;
}
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 3,954 | C | 23.41358 | 102 | 0.606474 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Src/pi_float_regulator.c | /**
******************************************************************************
* @file pi_float_regulator.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides the implementation of the floating point version
* of the PI regulator component of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup PIFloatRegulator
*/
/* Includes ------------------------------------------------------------------*/
#include "pi_float_regulator.h"
/** @addtogroup MCSDK
* @{
*/
/**
* @defgroup PIFloatRegulator PI Float Regulator
* @brief PI Float regulator component of the Motor Control SDK
*
* The PI float regulator component implements the following control function:
*
* @f[
* u(t) = K_{p} e(t) + K_{i} \int_0^t e(\tau) \,d\tau
* @f]
*
*
* @{
*/
/**
* @brief It initializes the handle
* @param pHandle: handler of the current instance of the PID component
* @retval None
*/
void PI_Float_HandleInit(PI_Float_Handle_t *pHandle)
{
pHandle->fKpGain = pHandle->fDefKpGain;
pHandle->fKiGain = pHandle->fDefKiGain;
pHandle->fIntegralTerm = 0.0f;
pHandle->fAntiWindTerm = 0.0f;
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
/**
* @brief This function computes the output of a PI regulator sum of its
* proportional and integral terms
* @param Float_PIReg PI regulator object
* @param float Actual process variable error, intended as the reference
* value minus the actual process variable value
* @retval float PI output
*/
float PI_Float_Calc(PI_Float_Handle_t *pHandle, float fProcessVarError)
{
float fProportional_Term, fOutput,fOutputSat;
/* Proportional term computation*/
fProportional_Term = pHandle->fKpGain * fProcessVarError;
fOutput = fProportional_Term;
/* Integral term computation */
if (pHandle->fKiGain == 0.0f)
{
pHandle->fIntegralTerm = 0.0f;
}
else
{
// pHandle->fIntegralTerm+= ((pHandle->fKiGain *(fProcessVarError)) - (pHandle->fKiGain*pHandle->fAntiWindTerm));
pHandle->fIntegralTerm+= ((pHandle->fKiGain *(fProcessVarError))/pHandle->fExecFrequencyHz);
if(pHandle->fIntegralTerm > pHandle->fUpperIntegralLimit)
{
pHandle->fIntegralTerm = pHandle->fUpperIntegralLimit;
}
else if(pHandle->fIntegralTerm < pHandle->fLowerIntegralLimit)
{
pHandle->fIntegralTerm = pHandle->fLowerIntegralLimit;
}
fOutput += pHandle->fIntegralTerm;
}
fOutputSat = fOutput;
/* Saturation */
if (fOutput > pHandle->fUpperLimit)
{
fOutputSat = pHandle->fUpperLimit;
}
if (fOutput < pHandle->fLowerLimit)
{
fOutputSat = pHandle->fLowerLimit;
}
if(pHandle->bAntiWindUpActivation == ((FunctionalState)ENABLE))
{
pHandle->fAntiWindTerm = (fOutput - fOutputSat) * pHandle->fKs;
}
else
{
pHandle->fAntiWindTerm =0.0f;
}
fOutput = fOutputSat;
return(fOutput);
}
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 3,768 | C | 25.921428 | 116 | 0.604565 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Src/acim_vf_control.c | /**
******************************************************************************
* @file acim_vf_control.c
* @author STMicroelectronics - SRA - System Development Unit - MC Team
* @brief This file provides firmware functions that implement the features
* of the V/f control of Induction Motor of the Motor Control SDK
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "mc_math.h"
#include "acim_vf_control.h"
#include "math.h"
#include "arm_math.h"
/**
* @brief Software initialization of V/F component
* @param pHandle: handler of the current instance of the V/F component
* @retval none
*/
void ACIM_VF_Init(ACIM_VF_Handle_t *pHandle)
{
REMNG_Init(pHandle->pRMNGR);
// Only for Closed loop V/F control
PI_Float_HandleInit(pHandle->fPI);
#if defined(MAIN_VF_OL)
pHandle->bVF_Mode = VF_OL;
#elif defined(MAIN_VF_CL)
pHandle->bVF_Mode = VF_CL;
#endif
}
/**
* @brief Software initialization of V/F object to be performed at each restart
* of the motor.
* @param pHandle: handler of the current instance of the V/F component
* @retval none
*/
void ACIM_VF_Clear(ACIM_VF_Handle_t *pHandle, BusVoltageSensor_Handle_t *pBVS)
{
pHandle->fFlux_Angle_rad = 0;
pHandle->fFlux_Freq_rads = 0;
pHandle->fFlux_Freq_Hz = 0;
pHandle->fSlipFrequency_rads = 0;
pHandle->hElAngle = 0;
pHandle->VoltageAmpl = 0;
REMNG_Init(pHandle->pRMNGR);
if(pHandle->bVF_Mode==VF_CL)
{
pHandle->fPI->fIntegralTerm = 0;
}
uint16_t hVbus_V = VBS_GetAvBusVoltage_V(pBVS);
if(hVbus_V != 0)
{
pHandle->fVoutMax_PWM_Mod_V = (float)hVbus_V/2.0f;
}
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
/**
* @brief Update the rotor electrical angle integrating the last setled
* instantaneous electrical speed.
* @param pHandle: handler of the current instance of the V/F component
* @retval none
*/
void ACIM_VF_CalcAngle(ACIM_VF_Handle_t *pHandle)
{
pHandle->fFlux_Angle_rad += (pHandle->fFlux_Freq_rads*pHandle->fCalcAngleExecTime_s);
pHandle->fFlux_Angle_rad = (float) fmod((double)pHandle->fFlux_Angle_rad , (double) (2.0f*(float)PI));
pHandle->hElAngle = Convert_Rad_to16bit(pHandle->fFlux_Angle_rad);
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
/**
* @brief Get the electrical angle for the sinusoidal voltage signals
* @param pHandle: handler of the current instance of the V/F component
* @retval float fElAngle
*/
float ACIM_VF_GetElAngle(ACIM_VF_Handle_t *pHandle)
{
return pHandle->fFlux_Angle_rad;
}
__weak int16_t ACIM_VF_GetMecSpeedRefUnit( ACIM_VF_Handle_t * pHandle ) {
return (REMNG_GetValue(pHandle->pRMNGR) / pHandle->pACIM_MotorParams->bPP);
}
/**
* @brief It configures the frequency ramp allowing rotor speed variation
* @param pHandle: handler of the current instance of the ACIM_VF component
* @param hTargetFinal: is the value of mechanical rotor speed reference at the
* end of the ramp expressed in tenths of HZ.
* @retval bool It returns true is command is valid, false otherwise
*/
bool ACIM_VF_ExecRamp(ACIM_VF_Handle_t *pHandle, int16_t hTargetFinal, uint32_t Durationms)
{
return REMNG_ExecRamp(pHandle->pRMNGR, (hTargetFinal)*pHandle->pACIM_MotorParams->bPP,Durationms);
}
/**
* @brief Check if the settled ramp has been completed.
* @param pHandle handler of the current instance of the ACIM_VF component.
* @retval bool It returns true if the ramp is completed, false otherwise.
*/
bool ACIM_VF_RampCompleted( ACIM_VF_Handle_t *pHandle )
{
return REMNG_RampCompleted(pHandle->pRMNGR);
}
/**
* @brief Stop the execution of the ramp keeping the last reached value.
* @param pHandle handler of the current instance of the ACIM_VF component.
* @retval none
*/
void ACIM_VF_StopRamp( ACIM_VF_Handle_t *pHandle )
{
REMNG_StopRamp(pHandle->pRMNGR);
}
/**
* @brief It calculates the flux frequency according to the V/f mode selected
* @param pHandle: handler of the current instance of the ACIM_VF component
* @retval float CodeError
*/
float ACIM_VF_FluxFreqCalc(ACIM_VF_Handle_t *pHandle)
{
if(pHandle->bVF_Mode == VF_OL)
{
pHandle->fFlux_Freq_Hz = (float)REMNG_Calc(pHandle->pRMNGR)/SPEED_UNIT;
pHandle->fFlux_Freq_rads = pHandle->fFlux_Freq_Hz*2.0f*(float)PI;
}
else // It's is CL
{
float fSpeedError_rads = 0.0;
float fMeasSpeed_rads = (2.0f*(float)PI*(float)pHandle->SPD_real->hAvrMecSpeedUnit)/SPEED_UNIT;
pHandle->fRotorFreqRef_rads = (2.0f*(float)PI*(float)REMNG_Calc(pHandle->pRMNGR))/SPEED_UNIT;
pHandle->fRotorFreqRef_RPM = (pHandle->fRotorFreqRef_rads*60.0f)/(2.0f*PI);
fSpeedError_rads = pHandle->fRotorFreqRef_rads - fMeasSpeed_rads;
pHandle->fSlipFrequency_rads = PI_Float_Calc(pHandle->fPI, fSpeedError_rads);
pHandle->fFlux_Freq_rads = pHandle->fSlipFrequency_rads + fMeasSpeed_rads;
pHandle->fFlux_Freq_Hz = pHandle->fFlux_Freq_rads/(2.0f*(float)PI);
}
return pHandle->fFlux_Freq_rads;
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
/**
* @brief It computes the voltage amplitude according to the constant ratio Vn/fn
* and the configured frequency. It generates the sinusoidal voltages and
* the duty cycles used for sine-triangle modulation performed by PWM component
* @param pHandle: handler of the current instance of the ACIM_VF component
* @retval uint16_t It returns #MC_NO_FAULTS if the V/f has been ended before
* next PWM Update event, #MC_DURATION otherwise
*/
uint16_t ACIM_VF_Controller(ACIM_VF_Handle_t *pHandle)
{
float vas, vbs, vcs;
float fdutyA, fdutyB, fdutyC;
uint16_t hCodeError;
float fFreqHzAbs = pHandle->fFlux_Freq_Hz;
if(fFreqHzAbs<0.0f)
{
fFreqHzAbs = -fFreqHzAbs;
}
if(fFreqHzAbs >= pHandle->fMinFreq_TH_Hz)
{
pHandle->VoltageAmpl = 2.0f*PI*fFreqHzAbs * pHandle->fFlux_K;
}
else
{
pHandle->VoltageAmpl = pHandle->fVoltage_Offset;
}
float fDeg = ((pHandle->fFlux_Angle_rad)*180.0f)/PI;
if(pHandle->VoltageAmpl>pHandle->fNominalPhaseVoltagePeak_V)
{
pHandle->VoltageAmpl = pHandle->fNominalPhaseVoltagePeak_V;
}
if(pHandle->VoltageAmpl > pHandle->fVoutMax_PWM_Mod_V)
{
pHandle->VoltageAmpl = pHandle->fVoutMax_PWM_Mod_V;
}
/* Voltage reference generator */
vas = pHandle->VoltageAmpl * MCM_floatTrig_Functions(fDeg).fSin;
vbs = pHandle->VoltageAmpl * MCM_floatTrig_Functions(fDeg+240.0f).fSin;
vcs = pHandle->VoltageAmpl * MCM_floatTrig_Functions(fDeg+120.0f).fSin;
/* Normalization between 0 and 1 considering the maximum voltage available
at the output of inverter using the sin-tri PWM modulation */
fdutyA = ((vas/pHandle->fVoutMax_PWM_Mod_V)+1.0f)/2.0f;
fdutyB = ((vbs/pHandle->fVoutMax_PWM_Mod_V)+1.0f)/2.0f;
fdutyC = ((vcs/pHandle->fVoutMax_PWM_Mod_V)+1.0f)/2.0f;
float fMax = 1.0f;
if(fdutyA > fMax)
{
fdutyA = fMax;
}
if(fdutyB > fMax)
{
fdutyB = fMax;
}
if(fdutyC > fMax)
{
fdutyC = fMax;
}
hCodeError = PWM_SetPhasePWMOutputs(pHandle->pPWM,fdutyA,fdutyB,fdutyC);
return(hCodeError);
}
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 10,235 | C | 31.290221 | 104 | 0.676404 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Src/hall_speed_pos_fdbk.c | /**
******************************************************************************
* @file hall_speed_pos_fdbk.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the features of
* the Hall Speed & Position Feedback component of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "speed_pos_fdbk.h"
#include "hall_speed_pos_fdbk.h"
#include "mc_type.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup SpeednPosFdbk
* @{
*/
/**
* @defgroup hall_speed_pos_fdbk Hall Speed & Position Feedback
*
* @brief Hall Sensor based Speed & Position Feedback implementation
*
* This component is used in applications controlling a motor equipped with Hall effect sensors.
*
* This component uses the output of two Hall effects sensors to provide a measure of the speed
* and the position of the rotor of the motor.
*
* @todo Document the Hall Speed & Position Feedback "module".
*
* @{
*/
/* Private defines -----------------------------------------------------------*/
/* Lower threshold to reques a decrease of clock prescaler */
#define LOW_RES_THRESHOLD ((uint16_t)0x5500u)
#define HALL_COUNTER_RESET ((uint16_t) 0u)
#define S16_120_PHASE_SHIFT (int16_t)(65536/3)
#define S16_60_PHASE_SHIFT (int16_t)(65536/6)
#define STATE_0 (uint8_t)0
#define STATE_1 (uint8_t)1
#define STATE_2 (uint8_t)2
#define STATE_3 (uint8_t)3
#define STATE_4 (uint8_t)4
#define STATE_5 (uint8_t)5
#define STATE_6 (uint8_t)6
#define STATE_7 (uint8_t)7
#define NEGATIVE (int8_t)-1
#define POSITIVE (int8_t)1
/* With digit-per-PWM unit (here 2*PI rad = 0xFFFF): */
#define HALL_MAX_PSEUDO_SPEED ((int16_t)0x7FFF)
#define CCER_CC1E_Set ((uint16_t)0x0001)
#define CCER_CC1E_Reset ((uint16_t)0xFFFE)
static void HALL_Init_Electrical_Angle( HALL_Handle_t * pHandle );
/**
* @brief It initializes the hardware peripherals (TIMx, GPIO and NVIC)
required for the speed position sensor management using HALL
sensors.
* @param pHandle: handler of the current instance of the hall_speed_pos_fdbk component
* @retval none
*/
__weak void HALL_Init( HALL_Handle_t * pHandle )
{
TIM_TypeDef * TIMx = pHandle->TIMx;
uint16_t hMinReliableElSpeedUnit = pHandle->_Super.hMinReliableMecSpeedUnit *
pHandle->_Super.bElToMecRatio;
uint16_t hMaxReliableElSpeedUnit = pHandle->_Super.hMaxReliableMecSpeedUnit *
pHandle->_Super.bElToMecRatio;
uint8_t bSpeedBufferSize;
uint8_t bIndex;
/* Adjustment factor: minimum measurable speed is x time less than the minimum
reliable speed */
hMinReliableElSpeedUnit /= 4u;
/* Adjustment factor: maximum measurable speed is x time greater than the
maximum reliable speed */
hMaxReliableElSpeedUnit *= 2u;
pHandle->OvfFreq = ( uint16_t )( pHandle->TIMClockFreq / 65536u );
/* SW Init */
if ( hMinReliableElSpeedUnit == 0u )
{
/* Set fixed to 150 ms */
pHandle->HallTimeout = 150u;
}
else
{
/* Set accordingly the min reliable speed */
/* 1000 comes from mS
* 6 comes from the fact that sensors are toggling each 60 deg = 360/6 deg */
pHandle->HallTimeout = 1000*SPEED_UNIT / ( 6u * hMinReliableElSpeedUnit );
}
/* Compute the prescaler to the closet value of the TimeOut (in mS )*/
pHandle->HALLMaxRatio = ( pHandle->HallTimeout * pHandle->OvfFreq ) / 1000 ;
/* Align MaxPeriod to a multiple of Overflow.*/
pHandle->MaxPeriod = ( pHandle->HALLMaxRatio ) * 65536uL;
pHandle->SatSpeed = hMaxReliableElSpeedUnit;
pHandle->PseudoFreqConv = ( ( pHandle->TIMClockFreq / 6u )
/ ( pHandle->_Super.hMeasurementFrequency ) ) * ( pHandle->_Super.DPPConvFactor);
pHandle->MinPeriod = ( ( SPEED_UNIT * ( pHandle->TIMClockFreq /6uL) )
/ hMaxReliableElSpeedUnit);
pHandle->PWMNbrPSamplingFreq = ( (pHandle->_Super.hMeasurementFrequency * pHandle->PWMFreqScaling) /
pHandle->SpeedSamplingFreqHz ) - 1u;
/* Reset speed reliability */
pHandle->SensorIsReliable = true;
/* Set IC filter for Channel 1 (ICF1) */
LL_TIM_IC_SetFilter(TIMx, LL_TIM_CHANNEL_CH1, ( uint32_t )(pHandle->ICx_Filter) << 20);
/* Force the TIMx prescaler with immediate access (gen update event)
*/
LL_TIM_SetPrescaler ( TIMx, pHandle->HALLMaxRatio );
LL_TIM_GenerateEvent_UPDATE ( TIMx );
/* Clear the TIMx's pending flags */
WRITE_REG (TIMx->SR, 0);
/* Selected input capture and Update (overflow) events generate interrupt */
/* Source of Update event is only counter overflow/underflow */
LL_TIM_SetUpdateSource ( TIMx, LL_TIM_UPDATESOURCE_COUNTER );
LL_TIM_EnableIT_CC1 ( TIMx );
LL_TIM_EnableIT_UPDATE ( TIMx );
LL_TIM_SetCounter ( TIMx, HALL_COUNTER_RESET );
LL_TIM_CC_EnableChannel ( TIMx, LL_TIM_CHANNEL_CH1 );
LL_TIM_EnableCounter ( TIMx );
/* Erase speed buffer */
bSpeedBufferSize = pHandle->SpeedBufferSize;
for ( bIndex = 0u; bIndex < bSpeedBufferSize; bIndex++ )
{
pHandle->SensorPeriod[bIndex] = pHandle->MaxPeriod;
}
}
/**
* @brief Clear software FIFO where are "pushed" latest speed information
* This function must be called before starting the motor to initialize
* the speed measurement process.
* @param pHandle: handler of the current instance of the hall_speed_pos_fdbk component*
* @retval none
*/
__weak void HALL_Clear( HALL_Handle_t * pHandle )
{
TIM_TypeDef * TIMx = pHandle->TIMx;
/* Mask interrupts to insure a clean intialization */
LL_TIM_DisableIT_CC1 ( TIMx );
pHandle->RatioDec = false;
pHandle->RatioInc = false;
/* Reset speed reliability */
pHandle->SensorIsReliable = true;
/* Acceleration measurement not implemented.*/
pHandle->_Super.hMecAccelUnitP = 0;
pHandle->FirstCapt = 0u;
pHandle->BufferFilled = 0u;
pHandle->OVFCounter = 0u;
pHandle->CompSpeed = 0;
pHandle->Direction = POSITIVE;
/* Initialize speed buffer index */
pHandle->SpeedFIFOIdx = 0u;
/* Clear speed error counter */
pHandle->_Super.bSpeedErrorNumber = 0;
/* Re-initialize partly the timer */
LL_TIM_SetPrescaler ( TIMx, pHandle->HALLMaxRatio );
LL_TIM_SetCounter ( TIMx, HALL_COUNTER_RESET );
LL_TIM_EnableCounter ( TIMx );
LL_TIM_EnableIT_CC1 ( TIMx );
HALL_Init_Electrical_Angle( pHandle );
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief Update the rotor electrical angle integrating the last measured
* instantaneous electrical speed express in dpp.
* @param pHandle: handler of the current instance of the hall_speed_pos_fdbk component
* @retval int16_t Measured electrical angle in s16degree format.
*/
__weak int16_t HALL_CalcElAngle( HALL_Handle_t * pHandle )
{
if ( pHandle->_Super.hElSpeedDpp != HALL_MAX_PSEUDO_SPEED )
{
pHandle->MeasuredElAngle += pHandle->_Super.hElSpeedDpp;
pHandle->_Super.hElAngle += pHandle->_Super.hElSpeedDpp + pHandle->CompSpeed;
pHandle->PrevRotorFreq = pHandle->_Super.hElSpeedDpp;
}
else
{
pHandle->_Super.hElAngle += pHandle->PrevRotorFreq;
}
return pHandle->_Super.hElAngle;
}
/**
* @brief This method must be called - at least - with the same periodicity
* on which speed control is executed.
* This method compute and store rotor istantaneous el speed (express
* in dpp considering the measurement frequency) in order to provide it
* to HALL_CalcElAngle function and SPD_GetElAngle.
* Then compute rotor average el speed (express in dpp considering the
* measurement frequency) based on the buffer filled by IRQ, then - as
* a consequence - compute, store and return - through parameter
* hMecSpeedUnit - the rotor average mech speed, expressed in Unit.
* Then check, store and return the reliability state of
* the sensor; in this function the reliability is measured with
* reference to specific parameters of the derived
* sensor (HALL) through internal variables managed by IRQ.
* @param pHandle: handler of the current instance of the hall_speed_pos_fdbk component
* @param hMecSpeedUnit pointer to int16_t, used to return the rotor average
* mechanical speed (expressed in the unit defined by #SPEED_UNIT)
* @retval true = sensor information is reliable
* false = sensor information is not reliable
*/
__weak bool HALL_CalcAvrgMecSpeedUnit( HALL_Handle_t * pHandle, int16_t * hMecSpeedUnit )
{
TIM_TypeDef * TIMx = pHandle->TIMx;
bool bReliability;
if ( pHandle->SensorIsReliable )
{
/* No errors have been detected during rotor speed information
extrapolation */
if ( LL_TIM_GetPrescaler ( TIMx ) >= pHandle->HALLMaxRatio )
{
/* At start-up or very low freq */
/* Based on current prescaler value only */
pHandle->_Super.hElSpeedDpp = 0;
*hMecSpeedUnit = 0;
}
else
{
pHandle->_Super.hElSpeedDpp = pHandle->AvrElSpeedDpp;
if ( pHandle->AvrElSpeedDpp == 0 )
{
/* Speed is too low */
*hMecSpeedUnit = 0;
}
else
{
/* Check if speed is not to fast */
if ( pHandle->AvrElSpeedDpp != HALL_MAX_PSEUDO_SPEED )
{
if (pHandle->HallMtpa == true)
{
pHandle->CompSpeed = 0;
}
else
{
pHandle->DeltaAngle = pHandle->MeasuredElAngle - pHandle->_Super.hElAngle;
pHandle->CompSpeed = ( int16_t )
( ( int32_t )( pHandle->DeltaAngle ) /
( int32_t )( pHandle->PWMNbrPSamplingFreq ) );
}
/* Convert el_dpp to MecUnit */
*hMecSpeedUnit = ( int16_t )( ( pHandle->AvrElSpeedDpp *
( int32_t )pHandle->_Super.hMeasurementFrequency * (int32_t) SPEED_UNIT ) /
(( int32_t ) pHandle->_Super.DPPConvFactor * ( int32_t )pHandle->_Super.bElToMecRatio ) );
}
else
{
*hMecSpeedUnit = ( int16_t )pHandle->SatSpeed;
}
}
}
bReliability = SPD_IsMecSpeedReliable( &pHandle->_Super, hMecSpeedUnit );
}
else
{
bReliability = false;
pHandle->_Super.bSpeedErrorNumber = pHandle->_Super.bMaximumSpeedErrorsNumber;
/* If speed is not reliable the El and Mec speed is set to 0 */
pHandle->_Super.hElSpeedDpp = 0;
*hMecSpeedUnit = 0;
}
pHandle->_Super.hAvrMecSpeedUnit = *hMecSpeedUnit;
return ( bReliability );
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief Example of private method of the class HALL to implement an MC IRQ function
* to be called when TIMx capture event occurs
* @param pHandle: handler of the current instance of the hall_speed_pos_fdbk component
* @retval none
*/
__weak void * HALL_TIMx_CC_IRQHandler( void * pHandleVoid )
{
HALL_Handle_t * pHandle = ( HALL_Handle_t * ) pHandleVoid;
TIM_TypeDef * TIMx = pHandle->TIMx;
uint8_t bPrevHallState;
int8_t PrevDirection;
uint32_t wCaptBuf;
uint16_t hPrscBuf;
uint16_t hHighSpeedCapture;
if ( pHandle->SensorIsReliable )
{
/* A capture event generated this interrupt */
bPrevHallState = pHandle->HallState;
PrevDirection = pHandle->Direction;
if ( pHandle->SensorPlacement == DEGREES_120 )
{
pHandle->HallState =(uint8_t) ((LL_GPIO_IsInputPinSet( pHandle->H3Port, pHandle->H3Pin ) << 2)
| (LL_GPIO_IsInputPinSet( pHandle->H2Port, pHandle->H2Pin ) << 1)
| LL_GPIO_IsInputPinSet( pHandle->H1Port, pHandle->H1Pin ) );
}
else
{
pHandle->HallState = (uint8_t) ((( LL_GPIO_IsInputPinSet( pHandle->H2Port, pHandle->H2Pin ) ^ 1 ) << 2)
| (LL_GPIO_IsInputPinSet( pHandle->H3Port, pHandle->H3Pin ) << 1)
| LL_GPIO_IsInputPinSet( pHandle->H1Port, pHandle->H1Pin ) );
}
switch ( pHandle->HallState )
{
case STATE_5:
if ( bPrevHallState == STATE_4 )
{
pHandle->Direction = POSITIVE;
pHandle->MeasuredElAngle = pHandle->PhaseShift;
}
else if ( bPrevHallState == STATE_1 )
{
pHandle->Direction = NEGATIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift + S16_60_PHASE_SHIFT );
}
else
{
}
break;
case STATE_1:
if ( bPrevHallState == STATE_5 )
{
pHandle->Direction = POSITIVE;
pHandle->MeasuredElAngle = pHandle->PhaseShift + S16_60_PHASE_SHIFT;
}
else if ( bPrevHallState == STATE_3 )
{
pHandle->Direction = NEGATIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift + S16_120_PHASE_SHIFT );
}
else
{
}
break;
case STATE_3:
if ( bPrevHallState == STATE_1 )
{
pHandle->Direction = POSITIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift + S16_120_PHASE_SHIFT );
}
else if ( bPrevHallState == STATE_2 )
{
pHandle->Direction = NEGATIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift + S16_120_PHASE_SHIFT +
S16_60_PHASE_SHIFT );
}
else
{
}
break;
case STATE_2:
if ( bPrevHallState == STATE_3 )
{
pHandle->Direction = POSITIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift + S16_120_PHASE_SHIFT
+ S16_60_PHASE_SHIFT );
}
else if ( bPrevHallState == STATE_6 )
{
pHandle->Direction = NEGATIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift - S16_120_PHASE_SHIFT );
}
else
{
}
break;
case STATE_6:
if ( bPrevHallState == STATE_2 )
{
pHandle->Direction = POSITIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift - S16_120_PHASE_SHIFT );
}
else if ( bPrevHallState == STATE_4 )
{
pHandle->Direction = NEGATIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift - S16_60_PHASE_SHIFT );
}
else
{
}
break;
case STATE_4:
if ( bPrevHallState == STATE_6 )
{
pHandle->Direction = POSITIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift - S16_60_PHASE_SHIFT );
}
else if ( bPrevHallState == STATE_5 )
{
pHandle->Direction = NEGATIVE;
pHandle->MeasuredElAngle = ( int16_t )( pHandle->PhaseShift );
}
else
{
}
break;
default:
/* Bad hall sensor configutarion so update the speed reliability */
pHandle->SensorIsReliable = false;
break;
}
/* We need to check that the direction has not changed.
If it is the case, the sign of the current speed can be the opposite of the
average speed, and the average time can be close to 0 which lead to a
computed speed close to the infinite, and bring instability. */
if (pHandle->Direction != PrevDirection)
{
/* Setting BufferFilled to 0 will prevent to compute the average speed based
on the SpeedPeriod buffer values */
pHandle->BufferFilled = 0 ;
pHandle->SpeedFIFOIdx = 0;
}
if (pHandle->HallMtpa == true)
{
pHandle->_Super.hElAngle = pHandle->MeasuredElAngle;
}
else
{
/* Nothing to do */
}
/* Discard first capture */
if ( pHandle->FirstCapt == 0u )
{
pHandle->FirstCapt++;
LL_TIM_IC_GetCaptureCH1( TIMx );
}
else
{
/* used to validate the average speed measurement */
if ( pHandle->BufferFilled < pHandle->SpeedBufferSize )
{
pHandle->BufferFilled++;
}
/* Store the latest speed acquisition */
hHighSpeedCapture = LL_TIM_IC_GetCaptureCH1( TIMx );
wCaptBuf = ( uint32_t )hHighSpeedCapture;
hPrscBuf = LL_TIM_GetPrescaler ( TIMx );
/* Add the numbers of overflow to the counter */
wCaptBuf += ( uint32_t )pHandle->OVFCounter * 0x10000uL;
if ( pHandle->OVFCounter != 0u )
{
/* Adjust the capture using prescaler */
uint16_t hAux;
hAux = hPrscBuf + 1u;
wCaptBuf *= hAux;
if ( pHandle->RatioInc )
{
pHandle->RatioInc = false; /* Previous capture caused overflow */
/* Don't change prescaler (delay due to preload/update mechanism) */
}
else
{
if ( LL_TIM_GetPrescaler ( TIMx ) < pHandle->HALLMaxRatio ) /* Avoid OVF w/ very low freq */
{
LL_TIM_SetPrescaler ( TIMx, LL_TIM_GetPrescaler ( TIMx ) + 1 ); /* To avoid OVF during speed decrease */
pHandle->RatioInc = true; /* new prsc value updated at next capture only */
}
}
}
else
{
/* If prsc preload reduced in last capture, store current register + 1 */
if ( pHandle->RatioDec ) /* and don't decrease it again */
{
/* Adjust the capture using prescaler */
uint16_t hAux;
hAux = hPrscBuf + 2u;
wCaptBuf *= hAux;
pHandle->RatioDec = false;
}
else /* If prescaler was not modified on previous capture */
{
/* Adjust the capture using prescaler */
uint16_t hAux = hPrscBuf + 1u;
wCaptBuf *= hAux;
if ( hHighSpeedCapture < LOW_RES_THRESHOLD ) /* If capture range correct */
{
if ( LL_TIM_GetPrescaler ( TIMx ) > 0u ) /* or prescaler cannot be further reduced */
{
LL_TIM_SetPrescaler ( TIMx, LL_TIM_GetPrescaler ( TIMx ) - 1 ); /* Increase accuracy by decreasing prsc */
/* Avoid decrementing again in next capt.(register preload delay) */
pHandle->RatioDec = true;
}
}
}
}
/* Filtering to fast speed... could be a glitch ? */
/* the HALL_MAX_PSEUDO_SPEED is temporary in the buffer, and never included in average computation*/
if ( wCaptBuf < pHandle->MinPeriod )
{
/* pHandle->AvrElSpeedDpp = HALL_MAX_PSEUDO_SPEED; */
}
else
{
pHandle->ElPeriodSum -= pHandle->SensorPeriod[pHandle->SpeedFIFOIdx]; /* value we gonna removed from the accumulator */
if ( wCaptBuf >= pHandle->MaxPeriod )
{
pHandle->SensorPeriod[pHandle->SpeedFIFOIdx] = pHandle->MaxPeriod*pHandle->Direction;
}
else
{
pHandle->SensorPeriod[pHandle->SpeedFIFOIdx] = wCaptBuf ;
pHandle->SensorPeriod[pHandle->SpeedFIFOIdx] *= pHandle->Direction;
pHandle->ElPeriodSum += pHandle->SensorPeriod[pHandle->SpeedFIFOIdx];
}
/* Update pointers to speed buffer */
pHandle->SpeedFIFOIdx++;
if ( pHandle->SpeedFIFOIdx == pHandle->SpeedBufferSize )
{
pHandle->SpeedFIFOIdx = 0u;
}
if ( pHandle->SensorIsReliable)
{
if ( pHandle->BufferFilled < pHandle->SpeedBufferSize )
{
pHandle->AvrElSpeedDpp = ( int16_t ) (( pHandle->PseudoFreqConv / wCaptBuf )*pHandle->Direction);
}
else
{ /* Average speed allow to smooth the mechanical sensors misalignement */
pHandle->AvrElSpeedDpp = ( int16_t )((int32_t) pHandle->PseudoFreqConv / ( pHandle->ElPeriodSum / pHandle->SpeedBufferSize )); /* Average value */
}
}
else /* Sensor is not reliable */
{
pHandle->AvrElSpeedDpp = 0;
}
}
/* Reset the number of overflow occurred */
pHandle->OVFCounter = 0u;
}
}
return MC_NULL;
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief Example of private method of the class HALL to implement an MC IRQ function
* to be called when TIMx update event occurs
* @param pHandle: handler of the current instance of the hall_speed_pos_fdbk component
* @retval none
*/
__weak void * HALL_TIMx_UP_IRQHandler( void * pHandleVoid )
{
HALL_Handle_t * pHandle = ( HALL_Handle_t * ) pHandleVoid;
TIM_TypeDef * TIMx = pHandle->TIMx;
if ( pHandle->SensorIsReliable )
{
uint16_t hMaxTimerOverflow;
/* an update event occured for this interrupt request generation */
pHandle->OVFCounter++;
hMaxTimerOverflow = ( uint16_t )( ( ( uint32_t )pHandle->HallTimeout * pHandle->OvfFreq )
/ ( ( LL_TIM_GetPrescaler ( TIMx ) + 1 ) * 1000u ) );
if ( pHandle->OVFCounter >= hMaxTimerOverflow )
{
/* Set rotor speed to zero */
pHandle->_Super.hElSpeedDpp = 0;
/* Reset the electrical angle according the hall sensor configuration */
HALL_Init_Electrical_Angle( pHandle );
/* Reset the overflow counter */
pHandle->OVFCounter = 0u;
/* Reset first capture flag */
pHandle->FirstCapt = 0u;
/* Reset the SensorSpeed buffer*/
uint8_t bIndex;
for ( bIndex = 0u; bIndex < pHandle->SpeedBufferSize; bIndex++ )
{
pHandle->SensorPeriod[bIndex] = pHandle->MaxPeriod;
}
pHandle->BufferFilled = 0 ;
pHandle->AvrElSpeedDpp = 0;
pHandle->SpeedFIFOIdx = 0;
pHandle->ElPeriodSum =pHandle->MaxPeriod * pHandle->SpeedBufferSize;
}
}
return MC_NULL;
}
/**
* @brief Read the logic level of the three Hall sensor and individuates in this
* way the position of the rotor (+/- 30�). Electrical angle is then
* initialized.
* @param pHandle: handler of the current instance of the hall_speed_pos_fdbk component
* @retval none
*/
static void HALL_Init_Electrical_Angle( HALL_Handle_t * pHandle )
{
if ( pHandle->SensorPlacement == DEGREES_120 )
{
pHandle->HallState = LL_GPIO_IsInputPinSet( pHandle->H3Port, pHandle->H3Pin ) << 2
| LL_GPIO_IsInputPinSet( pHandle->H2Port, pHandle->H2Pin ) << 1
| LL_GPIO_IsInputPinSet( pHandle->H1Port, pHandle->H1Pin );
}
else
{
pHandle->HallState = ( LL_GPIO_IsInputPinSet( pHandle->H2Port, pHandle->H2Pin ) ^ 1 ) << 2
| LL_GPIO_IsInputPinSet( pHandle->H3Port, pHandle->H3Pin ) << 1
| LL_GPIO_IsInputPinSet( pHandle->H1Port, pHandle->H1Pin );
}
switch ( pHandle->HallState )
{
case STATE_5:
pHandle->_Super.hElAngle = ( int16_t )( pHandle->PhaseShift + S16_60_PHASE_SHIFT / 2 );
break;
case STATE_1:
pHandle->_Super.hElAngle = ( int16_t )( pHandle->PhaseShift + S16_60_PHASE_SHIFT +
S16_60_PHASE_SHIFT / 2 );
break;
case STATE_3:
pHandle->_Super.hElAngle = ( int16_t )( pHandle->PhaseShift + S16_120_PHASE_SHIFT +
S16_60_PHASE_SHIFT / 2 );
break;
case STATE_2:
pHandle->_Super.hElAngle = ( int16_t )( pHandle->PhaseShift - S16_120_PHASE_SHIFT -
S16_60_PHASE_SHIFT / 2 );
break;
case STATE_6:
pHandle->_Super.hElAngle = ( int16_t )( pHandle->PhaseShift - S16_60_PHASE_SHIFT -
S16_60_PHASE_SHIFT / 2 );
break;
case STATE_4:
pHandle->_Super.hElAngle = ( int16_t )( pHandle->PhaseShift - S16_60_PHASE_SHIFT / 2 );
break;
default:
/* Bad hall sensor configutarion so update the speed reliability */
pHandle->SensorIsReliable = false;
break;
}
/* Initialize the measured angle */
pHandle->MeasuredElAngle = pHandle->_Super.hElAngle;
}
/**
* @brief It could be used to set istantaneous information on rotor mechanical
* angle.
* Note: Mechanical angle management is not implemented in this
* version of Hall sensor class.
* @param pHandle pointer on related component instance
* @param hMecAngle istantaneous measure of rotor mechanical angle
* @retval none
*/
__weak void HALL_SetMecAngle( HALL_Handle_t * pHandle, int16_t hMecAngle )
{
}
/**
* @}
*/
/**
* @}
*/
/** @} */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 25,695 | C | 32.241915 | 160 | 0.593267 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Src/acim_ifoc.c | /**
******************************************************************************
* @file acim_ifoc.c
* @author STMicroelectronics - SRA - System Development Unit - MC Team
* @brief This file provides firmware functions that implement the features
* of the Rotor Flux Position Feedback component of the Motor Control SDK.
* - estimates the rotor flux electrical angle
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "acim_ifoc.h"
#include "math.h"
#include "arm_math.h"
/**
* @brief It initializes the variables required for the rotor flux angle estimation.
* @param pHandle: handler of the current instance of the ACIM_IFOC component
* @retval none
*/
void ACIM_IFOC_Init(ACIM_IFOC_Handle_t *pHandle , SpeednPosFdbk_Handle_t * SPD_Handle)
{
pHandle->SPD = SPD_Handle;
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
/**
* @brief It performs the rotor flux angle estimation.
* @param pHandle: handler of the current instance of the ACIM_IFOC component
* @retval none
*/
void ACIM_IFOC_CalcAngle(ACIM_IFOC_Handle_t *pHandle)
{
float fSlipFreq_rads = 0.0f;
float fRotorFluxFreq_rads = 0.0f;
float fRotorElSpeed_meas_rads = 0.0f;
/* Conversion factor for conversion 01Hz to rad/s */
float SpeedConvFactor = (2.0f*(float)PI)/10.0f;
/* Conversion of measured current from s16A to Ampere unit */
Signal_Components fIqdA;
fIqdA = Convert_s16_to_A(pHandle->pFOCVars[M1].Iqdref);
float fids_A_tmp = fIqdA.fS_Component2;
/* It avoids division by zero*/
if(fids_A_tmp == 0.0f)
{
fids_A_tmp = pHandle->pACIM_MotorParams->fImagn_A;
}
/* Slip Frequency estimation (rad/s) - Iq/(Id*taur) */
fSlipFreq_rads = fIqdA.fS_Component1/(fids_A_tmp*pHandle->pACIM_MotorParams->ftaur);
/* Get and convert the measured meach. rotor speed from the speed/position sensor */
fRotorElSpeed_meas_rads = (float)SPD_GetAvrgMecSpeedUnit(pHandle->SPD)*SpeedConvFactor*(float)pHandle->pACIM_MotorParams->bPP*(10.0f/SPEED_UNIT);
/* Rotor Flux Frequency calculation (rad/s) */
fRotorFluxFreq_rads = fSlipFreq_rads + fRotorElSpeed_meas_rads;
pHandle->fRotorFluxFreq_rads = fRotorFluxFreq_rads;
/* Rotor Flux angle discrete integration */
pHandle->fRotorFlux_Angle_rad += fRotorFluxFreq_rads * pHandle->fCalcAngleExecTime_s;
/* Rotor Flux angle between [0, 2pi] */
pHandle->fRotorFlux_Angle_rad = (float) fmod((double) pHandle->fRotorFlux_Angle_rad, (double)((float)(2.0f*(float)PI)));
pHandle->hElAngle = Convert_Rad_to16bit(pHandle->fRotorFlux_Angle_rad);
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
/**/
/**
* @brief It returns the flux electrical angle in digital format
* @param pHandle: handler of the current instance of the ACIM_IFOC component
* @retval none
*/
int16_t ACIM_IFOC_GetElAngle(ACIM_IFOC_Handle_t *pHandle)
{
return pHandle->hElAngle;
}
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 3,982 | C | 32.191666 | 147 | 0.626067 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Src/pwm.c | /**
******************************************************************************
* @file pwm.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the following features
* of the PWM & Analog Feedback component of the Motor Control SDK:
*
* * regular ADC conversion execution
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "pwm.h"
#include "mc_type.h"
/** @addtogroup MCSDK
* @{
*/
/** @defgroup pwm PWM
*
* @brief PWM components of the Motor Control SDK
*
* These components fulfill two functions in a Motor Control subsystem:
*
* - The generation of the Pulse Width Modulation on the motor's phases
*
* See PWMC_Handle for more details on this mechanism.
* @{
*/
/**
* @brief It initializes the PWM Timer capture compare channels to 50% of duty cycle
* and enables the PWM Timer capture compare channels.
* @param pHandle: handler of the current instance of the PWMC component
* @retval none
*
*/
void PWM_Init(PWM_Handle_t *pHandle)
{
/* Duty cycle initialized to 50% */
pHandle->TIMx->CCR1 = pHandle->TIMx->ARR/2;
pHandle->TIMx->CCR2 = pHandle->TIMx->ARR/2;
pHandle->TIMx->CCR3 = pHandle->TIMx->ARR/2;
/* Enable of TIMx capture compare channels: Ch1, Ch2 Ch3 */
pHandle->TIMx->CCER |= TIMxCCER_MASK_CH123;
}
#if (defined (CCMRAM) || defined(CCMRAM_ENABLED))
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM)
__attribute__((section ("ccmram")))
#elif defined (__GNUC__)
__attribute__((section ("ccmram")))
#endif
#endif
/**
* @brief It converts the duty cycles between (0 and 1) to digital format for
* PWM Timer capture compare channels setting
* @param pHandle: handler of the current instance of the PWMC component
* @param float fDutyX: Duty cycle of inverter leg X:
* X can be: 1 for phase A, 2 for phase B, 3 for phase C
*
* @retval uint16_t It returns #MC_NO_FAULTS if the V/f has been ended before
* next PWM Update event, #MC_DURATION otherwise
*/
uint16_t PWM_SetPhasePWMOutputs(PWM_Handle_t *pHandle, float fDuty1, float fDuty2, float fDuty3)
{
uint16_t hAux;
uint16_t hCCR1, hCCR2, hCCR3;
/* Timer capture compare register values computation */
hCCR1 = (uint16_t)(fDuty1*(float)(pHandle->TIMx->ARR-1));
hCCR2 = (uint16_t)(fDuty2*(float)(pHandle->TIMx->ARR-1));
hCCR3 = (uint16_t)(fDuty3*(float)(pHandle->TIMx->ARR-1));
/* Store */
pHandle->fDuty1 = fDuty1;
pHandle->fDuty2 = fDuty2;
pHandle->fDuty3 = fDuty3;
pHandle->hCCR1 = hCCR1;
pHandle->hCCR2 = hCCR2;
pHandle->hCCR3 = hCCR3;
LL_TIM_OC_SetCompareCH1 (pHandle->TIMx,hCCR1);
LL_TIM_OC_SetCompareCH2 (pHandle->TIMx,hCCR2);
LL_TIM_OC_SetCompareCH3 (pHandle->TIMx,hCCR3);
if (LL_TIM_IsActiveFlag_UPDATE(pHandle->TIMx))
{
hAux = MC_DURATION;
}
else
{
hAux = MC_NO_ERROR;
}
return hAux;
}
/**
* @brief It enables the output of the PWM Timer channels
* @param pHandle: handler of the current instance of the PWMC component
* @retval none
*/
void PWM_SwitchOnPWM(PWM_Handle_t *pHandle)
{
/* Clear the TIMx Update */
LL_TIM_ClearFlag_UPDATE(pHandle->TIMx);
/* Enable the TIMx Update - it is used as HFT time base to perform the V/F conntrol */
LL_TIM_EnableIT_UPDATE(pHandle->TIMx);
/* Main PWM Output Enable */
pHandle->TIMx->BDTR |= LL_TIM_OSSI_ENABLE;
LL_TIM_EnableAllOutputs (pHandle->TIMx);
}
/**
* @brief It disable the output of the PWM Timer channels
* @param pHandle: handler of the current instance of the PWMC component
* @retval none
*/
void PWM_SwitchOffPWM(PWM_Handle_t *pHandle)
{
/* Main PWM Output Disable */
pHandle->TIMx->BDTR &= ~((uint32_t)(LL_TIM_OSSI_ENABLE));
LL_TIM_DisableAllOutputs(pHandle->TIMx);
/* Disable the TIMx Update - it is used as HFT time base to perform the V/F conntrol */
LL_TIM_DisableIT_UPDATE(pHandle->TIMx);
}
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 6,605 | C | 31.865671 | 96 | 0.652233 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Src/circle_limitation.c | /**
******************************************************************************
* @file circle_limitation.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides the functions that implement the circle
* limitation feature of the STM32 Motor Control SDK.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "circle_limitation.h"
#include "mc_math.h"
#include "mc_type.h"
/** @addtogroup MCSDK
* @{
*/
/** @defgroup CircleLimitation Circle Limitation
* @brief Circle Limitation component of the Motor Control SDK
*
* @todo Document the Circle Limitation "module".
*
* @{
*/
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section (".ccmram")))
#endif
#endif
__weak qd_t Circle_Limitation(const CircleLimitation_Handle_t * pHandle, qd_t Vqd)
{
int32_t MaxModule;
int32_t square_q;
int32_t square_temp;
int32_t square_d;
int32_t square_sum;
int32_t square_limit;
int32_t vd_square_limit;
int32_t new_q;
int32_t new_d;
qd_t Local_Vqd=Vqd;
MaxModule = pHandle->MaxModule;
square_q = (int32_t)(Vqd.q) * Vqd.q;
square_d = (int32_t)(Vqd.d) * Vqd.d;
square_limit = MaxModule * MaxModule;
vd_square_limit = pHandle->MaxVd * pHandle->MaxVd;
square_sum = square_q + square_d;
if (square_sum > square_limit)
{
if(square_d <= vd_square_limit)
{
square_temp = square_limit - square_d;
new_q = MCM_Sqrt(square_temp);
if(Vqd.q < 0)
{
new_q = -new_q;
}
new_d = Vqd.d;
}
else
{
new_d = pHandle->MaxVd;
if(Vqd.d < 0)
{
new_d = -new_d;
}
square_temp = square_limit - vd_square_limit;
new_q = MCM_Sqrt(square_temp);
if(Vqd.q < 0)
{
new_q = - new_q;
}
}
Local_Vqd.q = new_q;
Local_Vqd.d = new_d;
}
return(Local_Vqd);
}
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 2,677 | C | 22.910714 | 85 | 0.519612 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/hall_speed_pos_fdbk.h | /**
******************************************************************************
* @file hall_speed_pos_fdbk.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains all definitions and functions prototypes for the
* Hall Speed & Position Feedback component of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup hall_speed_pos_fdbk
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HALL_SPEEDNPOSFDBK_H
#define __HALL_SPEEDNPOSFDBK_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "speed_pos_fdbk.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup SpeednPosFdbk
* @{
*/
/** @addtogroup hall_speed_pos_fdbk
* @{
*/
#define HALL_SPEED_FIFO_SIZE ((uint8_t)18)
/* HALL SENSORS PLACEMENT ----------------------------------------------------*/
#define DEGREES_120 0u
#define DEGREES_60 1u
/* Exported types ------------------------------------------------------------*/
/**
* @brief HALL component parameters definition
*
* <Type @p type represents a thing that needs to be detailed more. Additional details
* are provided in the detailed section of the doxygen comment block.
*
* The brief line should be brief and light. It should avoid useless repetitions and expression such as
* "the CCC_Type_t type...". Expressions like "This type ..." are tolerated especially for key types
* (usually structures) where we may want ot be more formal.
*
* In general: be direct, avoid the obvious, tell the hidden.>
*/
typedef struct
{
SpeednPosFdbk_Handle_t _Super;
/* SW Settings */
uint8_t SensorPlacement; /*!< Define here the mechanical position of the sensors
with reference to an electrical cycle.
Allowed values are: DEGREES_120 or DEGREES_60.*/
int16_t PhaseShift; /*!< Define here in s16degree the electrical phase shift
between the low to high transition of signal H1 and
the maximum of the Bemf induced on phase A.*/
uint16_t SpeedSamplingFreqHz; /*!< Frequency (Hz) at which motor speed is to
be computed. It must be equal to the frequency
at which function SPD_CalcAvrgMecSpeedUnit
is called.*/
uint8_t SpeedBufferSize; /*!< Size of the buffer used to calculate the average
speed. It must be less than 18.*/
/* HW Settings */
uint32_t TIMClockFreq; /*!< Timer clock frequency express in Hz.*/
TIM_TypeDef * TIMx; /*!< Timer used for HALL sensor management.*/
GPIO_TypeDef * H1Port;
/*!< HALL sensor H1 channel GPIO input port (if used,
after re-mapping). It must be GPIOx x= A, B, ...*/
uint32_t H1Pin; /*!< HALL sensor H1 channel GPIO output pin (if used,
after re-mapping). It must be GPIO_Pin_x x= 0, 1,
...*/
GPIO_TypeDef * H2Port;
/*!< HALL sensor H2 channel GPIO input port (if used,
after re-mapping). It must be GPIOx x= A, B, ...*/
uint32_t H2Pin; /*!< HALL sensor H2 channel GPIO output pin (if used,
after re-mapping). It must be GPIO_Pin_x x= 0, 1,
...*/
GPIO_TypeDef * H3Port;
/*!< HALL sensor H3 channel GPIO input port (if used,
after re-mapping). It must be GPIOx x= A, B, ...*/
uint32_t H3Pin; /*!< HALL sensor H3 channel GPIO output pin (if used,
after re-mapping). It must be GPIO_Pin_x x= 0, 1,
...*/
uint32_t ICx_Filter; /*!< Input Capture filter selection */
bool SensorIsReliable; /*!< Flag to indicate a wrong configuration
of the Hall sensor signanls.*/
volatile bool RatioDec; /*!< Flag to avoid consecutive prescaler
decrement.*/
volatile bool RatioInc; /*!< Flag to avoid consecutive prescaler
increment.*/
volatile uint8_t FirstCapt; /*!< Flag used to discard first capture for
the speed measurement*/
volatile uint8_t BufferFilled; /*!< Indicate the number of speed measuremt
present in the buffer from the start.
It will be max bSpeedBufferSize and it
is used to validate the start of speed
averaging. If bBufferFilled is below
bSpeedBufferSize the instantaneous
measured speed is returned as average
speed.*/
volatile uint8_t OVFCounter; /*!< Count overflows if prescaler is too low
*/
int32_t SensorPeriod[HALL_SPEED_FIFO_SIZE];/*!< Holding the last
period captures */
uint8_t SpeedFIFOIdx;/*!< Pointer of next element to be stored in
the speed sensor buffer*/
int32_t ElPeriodSum; /* Period accumulator used to speed up the average speed computation*/
int16_t PrevRotorFreq; /*!< Used to store the last valid rotor electrical
speed in dpp used when HALL_MAX_PSEUDO_SPEED
is detected */
int8_t Direction; /*!< Instantaneous direction of rotor between two
captures*/
int16_t AvrElSpeedDpp; /*!< It is the averaged rotor electrical speed express
in s16degree per current control period.*/
uint8_t HallState; /*!< Current HALL state configuration */
int16_t DeltaAngle; /*!< Delta angle at the Hall sensor signal edge between
current electrical rotor angle of synchronism.
It is in s16degrees.*/
int16_t MeasuredElAngle;/*!< This is the electrical angle measured at each
Hall sensor signal edge. It is considered the
best measurement of electrical rotor angle.*/
int16_t CompSpeed; /*!< Speed compensation factor used to syncronize
the current electrical angle with the target
electrical angle. */
uint16_t HALLMaxRatio; /*!< Max TIM prescaler ratio defining the lowest
expected speed feedback.*/
uint16_t SatSpeed; /*!< Returned value if the measured speed is above the
maximum realistic.*/
uint32_t PseudoFreqConv;/*!< Conversion factor between time interval Delta T
between HALL sensors captures, express in timer
counts, and electrical rotor speed express in dpp.
Ex. Rotor speed (dpp) = wPseudoFreqConv / Delta T
It will be ((CKTIM / 6) / (SAMPLING_FREQ)) * 65536.*/
uint32_t MaxPeriod; /*!< Time delay between two sensor edges when the speed
of the rotor is the minimum realistic in the
application: this allows to discriminate too low
freq for instance.
This period shoud be expressed in timer counts and
it will be:
wMaxPeriod = ((10 * CKTIM) / 6) / MinElFreq(0.1Hz).*/
uint32_t MinPeriod;
/*!< Time delay between two sensor edges when the speed
of the rotor is the maximum realistic in the
application: this allows discriminating glitches
for instance.
This period shoud be expressed in timer counts and
it will be:
wSpeedOverflow = ((10 * CKTIM) / 6) / MaxElFreq(0.1Hz).*/
uint16_t HallTimeout;/*!< Max delay between two Hall sensor signal to assert
zero speed express in milliseconds.*/
uint16_t OvfFreq; /*!< Frequency of timer overflow (from 0 to 0x10000)
it will be: hOvfFreq = CKTIM /65536.*/
uint16_t PWMNbrPSamplingFreq; /*!< Number of current control periods inside
each speed control periods it will be:
(hMeasurementFrequency / hSpeedSamplingFreqHz) - 1.*/
uint8_t PWMFreqScaling; /*!< Scaling factor to allow to store a PWMFrequency greater than 16 bits */
bool HallMtpa; /* if true at each sensor toggling, the true angle is set without ramp*/
} HALL_Handle_t;
/**
* @}
*/
void * HALL_TIMx_UP_IRQHandler( void * pHandleVoid );
void * HALL_TIMx_CC_IRQHandler( void * pHandleVoid );
void HALL_Init( HALL_Handle_t * pHandle );
void HALL_Clear( HALL_Handle_t * pHandle );
int16_t HALL_CalcElAngle( HALL_Handle_t * pHandle );
bool HALL_CalcAvrgMecSpeedUnit( HALL_Handle_t * pHandle, int16_t * hMecSpeedUnit );
void HALL_SetMecAngle( HALL_Handle_t * pHandle, int16_t hMecAngle );
/**
* @}
*/
/**
* @}
*/
/** @} */
#endif /*__HALL_SPEEDNPOSFDBK_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 10,110 | C | 41.84322 | 104 | 0.538477 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/pwm.h | /**
******************************************************************************
* @file pwm.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the following features
* of the PWM & Current Feedback component of the Motor Control SDK
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PWM_H
#define __PWM_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define TIMxCCER_MASK_CH123 ((uint32_t) 0x00000555u)
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
#include "pwm_curr_fdbk.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup pwm PWM
* @{
*/
typedef struct
{
PWMC_Handle_t _Super; /*!< Offset of current sensing network */
TIM_TypeDef* TIMx; /*!< It contains the pointer to the timer
used for PWM generation. It must
equal to TIM1 if bInstanceNbr is
equal to 1, to TIM8 otherwise */
/* Regular conversion --------------------------------------------------------*/
ADC_TypeDef * regconvADCx; /*!< ADC peripheral used for regular
conversion.*/
uint8_t bRepetitionCounter; /*!< It expresses the number of PWM
periods to be elapsed before compare
registers are updated again. In
particular:
RepetitionCounter= (2* #PWM periods)-1*/
float fDuty1;
float fDuty2;
float fDuty3;
uint16_t hCCR1;
uint16_t hCCR2;
uint16_t hCCR3;
}PWM_Handle_t;
/**
* @brief It initializes the PWM Timer capture compare channels to 50% of duty cycle
* and enables the PWM Timer capture compare channels.
* @param pHandle: handler of the current instance of the PWMC component
* @retval none
*
*/
void PWM_Init(PWM_Handle_t *pHandle);
/**
* @brief It converts the duty cycles between (0 and 1) to digital format for
* PWM Timer capture compare channels setting
* @param pHandle: handler of the current instance of the PWMC component
* @param float fDutyX: Duty cycle of inverter leg X:
* X can be: 1 for phase A, 2 for phase B, 3 for phase C
*
* @retval uint16_t It returns #MC_NO_FAULTS if the V/f has been ended before
* next PWM Update event, #MC_DURATION otherwise
*/
uint16_t PWM_SetPhasePWMOutputs(PWM_Handle_t *pHandle, float fDuty1, float fDuty2, float fDuty3);
/**
* @brief It enables the output of the PWM Timer channels
* @param pHandle: handler of the current instance of the PWMC component
* @retval none
*/
void PWM_SwitchOnPWM(PWM_Handle_t *pHandle);
/**
* @brief It disable the output of the PWM Timer channels
* @param pHandle: handler of the current instance of the PWMC component
* @retval none
*/
void PWM_SwitchOffPWM(PWM_Handle_t *pHandle);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* __PWMNCURRFDBK_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 5,816 | C | 36.288461 | 97 | 0.603336 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/pwm_common.h | /**
******************************************************************************
* @file pwm_curr_fdbk.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains all definitions and functions prototypes for the
* PWM & Current Feedback component of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup pwm_curr_fdbk
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PWMNCOMMON_H
#define __PWMNCOMMON_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
#define NB_CONVERSIONS 16u
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup pwm_curr_fdbk
* @{
*/
/* Exported defines ----------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/**
* @brief It perform the start of all the timers required by the control.
* It utilizes TIM2 as temporary timer to achieve synchronization between
* PWM signals.
* When this function is called, TIM1 and/or TIM8 must be in frozen state
* with CNT, ARR, REP RATE and trigger correctly set (these setting are
* usually performed in the Init method accordingly with the configuration)
*/
void startTimers( void );
/**
* @brief It waits for the end of the polarization. If the polarization exceeds the
* the number of needed PWM cycles, it reports an error.
*/
void waitForPolarizationEnd( TIM_TypeDef* TIMx, uint16_t *SWerror, uint8_t repCnt, volatile uint8_t *cnt );
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* __PWMNCOMMON_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 2,476 | C | 31.592105 | 109 | 0.509289 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/mc_tuning.h | /**
******************************************************************************
* @file mc_tuning.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains all definitions and functions prototypes for the
* motor control tuning component of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCTuning
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MC_TUNING_H
#define __MC_TUNING_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
#include "pid_regulator.h"
#include "revup_ctrl.h"
#include "sto_pll_speed_pos_fdbk.h"
#include "sto_cordic_speed_pos_fdbk.h"
#include "virtual_speed_sensor.h"
#include "speed_torq_ctrl.h"
#include "digital_output.h"
#ifdef HFINJECTION
#include "hifreqinj_fpu_ctrl.h"
#endif /* HFINJECTION */
#include "motor_power_measurement.h"
#include "pqd_motor_power_measurement.h"
#include "open_loop.h"
#include "ntc_temperature_sensor.h"
#include "bus_voltage_sensor.h"
#include "feed_forward_ctrl.h"
#include "flux_weakening_ctrl.h"
#include "mp_self_com_ctrl.h"
#include "trajectory_ctrl.h"
/**
* @addtogroup MCSDK
* @{
*/
/**
* @defgroup MCTuning Motor Control Fine Tuning interface
*
* @brief This interface provides access to the internals of the Motor Control Subsystem
*
* @todo Complete documentation
* @{
*/
/**
* @internal
* @brief Public DigitalOutput class definition
*/
#ifndef __DIGITALOUTPUTCLASS_H
typedef struct CDOUT_t * CDOUT;
#endif
/**
* @brief MC tuning internal objects initialization structure type;
*/
typedef struct
{
PID_Handle_t * pPIDSpeed;
PID_Handle_t * pPIDIq;
PID_Handle_t * pPIDId;
PID_Handle_t * pPIDFluxWeakening;
PWMC_Handle_t * pPWMnCurrFdbk;
RevUpCtrl_Handle_t * pRevupCtrl;
SpeednPosFdbk_Handle_t * pSpeedSensorMain;
SpeednPosFdbk_Handle_t * pSpeedSensorAux;
VirtualSpeedSensor_Handle_t * pSpeedSensorVirtual;
SpeednTorqCtrl_Handle_t * pSpeednTorqueCtrl;
STM_Handle_t * pStateMachine;
NTC_Handle_t * pTemperatureSensor;
BusVoltageSensor_Handle_t * pBusVoltageSensor;
DOUT_handle_t * pBrakeDigitalOutput;
DOUT_handle_t * pNTCRelay;
MotorPowMeas_Handle_t * pMPM;
FW_Handle_t * pFW;
FF_Handle_t * pFF;
PosCtrl_Handle_t * pPosCtrl;
#ifdef HFINJECTION
HFI_FP_Ctrl_Handle_t * pHFI;
#endif /* HFINJECTION */
SCC_Handle_t * pSCC;
OTT_Handle_t * pOTT;
} MCT_Handle_t;
/**
* @brief Use this method to set a new value for the voltage reference used by
* flux weakening algorithm.
* @param pHandle Flux weakening init strutcture.
* @param uint16_t New target voltage value, expressend in tenth of percentage
* points of available voltage.
* @retval none
*/
void FW_SetVref( FW_Handle_t * pHandle, uint16_t hNewVref );
/**
* @brief It returns the present value of target voltage used by flux
* weakening algorihtm.
* @param pHandle Flux weakening init strutcture.
* @retval int16_t Present target voltage value expressed in tenth of
* percentage points of available voltage.
*/
uint16_t FW_GetVref( FW_Handle_t * pHandle );
/**
* @brief It returns the present value of voltage actually used by flux
* weakening algorihtm.
* @param pHandle Flux weakening init strutcture.
* @retval int16_t Present averaged phase stator voltage value, expressed
* in s16V (0-to-peak), where
* PhaseVoltage(V) = [PhaseVoltage(s16A) * Vbus(V)] /[sqrt(3) *32767].
*/
int16_t FW_GetAvVAmplitude( FW_Handle_t * pHandle );
/**
* @brief It returns the measure of present voltage actually used by flux
* weakening algorihtm as percentage of available voltage.
* @param pHandle Flux weakening init strutcture.
* @retval uint16_t Present averaged phase stator voltage value, expressed in
* tenth of percentage points of available voltage.
*/
uint16_t FW_GetAvVPercentage( FW_Handle_t * pHandle );
#if 0
/**
* @brief Use this method to set new values for the constants utilized by
* feed-forward algorithm.
* @param pHandle Feed forward strutcture.
* @param sNewConstants The FF_TuningStruct_t containing constants utilized by
* feed-forward algorithm.
* @retval none
*/
void FF_SetFFConstants( FF_Handle_t * pHandle, FF_TuningStruct_t sNewConstants );
/**
* @brief Use this method to get present values for the constants utilized by
* feed-forward algorithm.
* @param pHandle Feed forward strutcture.
* @retval FF_TuningStruct_t Values of the constants utilized by
* feed-forward algorithm.
*/
FF_TuningStruct_t FF_GetFFConstants( FF_Handle_t * pHandle );
/**
* @brief Use this method to get present values for the Vqd feed-forward
* components.
* @param pHandle Feed forward strutcture.
* @retval qd_t Vqd feed-forward components.
*/
qd_t FF_GetVqdff( FF_Handle_t * pHandle );
/**
* @brief Use this method to get values of the averaged output of qd axes
* currents PI regulators.
* @param pHandle Feed forward strutcture.
* @retval qd_t Averaged output of qd axes currents PI regulators.
*/
qd_t FF_GetVqdAvPIout( FF_Handle_t * pHandle );
#endif
#ifdef HFINJECTION
/**
* @brief It returns the rotor angle lock value
* @param pHandle related HFI_FP_Ctrl_Handle
* @retval int16_t Rotor angle lock value
*/
int16_t HFI_FP_GetRotorAngleLock( HFI_FP_Ctrl_Handle_t * pHandle );
/**
* @brief It returns the saturation difference measured during the last
* north/south identification stage.
* @param pHandle related HFI_FP_Ctrl_Handle
* @retval int16_t Saturation difference measured during the last north/south
* identification stage.
*/
int16_t HFI_FP_GetSaturationDifference( HFI_FP_Ctrl_Handle_t * pHandle );
/**
* @brief It return the quantity that shall be put in the DAC to tune the HFI
* @param pHandle related HFI_FP_Ctrl_Handle
* @retval int16_t HFI current
*/
int16_t HFI_FP_GetCurrent( HFI_FP_Ctrl_Handle_t * pHandle );
/**
* @brief It returns the Track PI
* @param pHandle related HFI_FP_Ctrl_Handle
* @retval CPI Track PI
*/
PID_Handle_t * HFI_FP_GetPITrack( HFI_FP_Ctrl_Handle_t * pHandle );
/**
* @brief It set the min saturation difference used to validate the
* north/south identification stage.
* @param pHandle related HFI_FP_Ctrl_Handle
* @param hMinSaturationDifference Min Saturation difference used to validate
* the north/south identification stage.
* identification stage.
* @retval none
*/
void HFI_FP_SetMinSaturationDifference( HFI_FP_Ctrl_Handle_t * pHandle, int16_t MinSaturationDifference );
#endif /* HFINJECTION */
/**
* @brief It allows changing applied open loop phase voltage.
* @param pHandle related object of class COL
* @param hNewVoltage New voltage value to be applied by the open loop.
* @retval None
*/
void OL_UpdateVoltage( OpenLoop_Handle_t * pHandle, int16_t hNewVoltage );
/**
* @brief It updates the Kp gain
* @param CPI PI object
* @param int16_t New Kp gain
* @retval None
*/
void PID_SetKP( PID_Handle_t * pHandle, int16_t hKpGain );
/**
* @brief It updates the Ki gain
* @param CPI PI object
* @param int16_t New Ki gain
* @retval None
*/
void PID_SetKI( PID_Handle_t * pHandle, int16_t hKiGain );
/**
* @brief It returns the Kp gain of the passed PI object
* @param CPI PI regulator object
* @retval int16_t Kp gain
*/
int16_t PID_GetKP( PID_Handle_t * pHandle );
/**
* @brief It returns the Kp gain divisor of the passed PI object
* @param CPI PI regulator object
* @retval int16_t Kp gain
*/
uint16_t PID_GetKPDivisor( PID_Handle_t * pHandle );
/**
* @brief It returns the Ki gain of the passed PI object
* @param CPI PI regulator object
* @retval int16_t Ki gain
*/
int16_t PID_GetKI( PID_Handle_t * pHandle );
/**
* @brief It returns the Ki gain divisor of the passed PI object
* @param CPI PI regulator object
* @retval int16_t Ki gain
*/
uint16_t PID_GetKIDivisor( PID_Handle_t * pHandle );
/**
* @brief It returns the Default Kp gain of the passed PI object
* @param CPI PI regulator object
* @retval int16_t Kp gain
*/
int16_t PID_GetDefaultKP( PID_Handle_t * pHandle );
/**
* @brief It returns the Default Ki gain of the passed PI object
* @param CPI PI regulator object
* @retval int16_t Ki gain
*/
int16_t PID_GetDefaultKI( PID_Handle_t * pHandle );
/**
* @brief It set a new value into the PI integral term
* @param CPI PI regulator object
* @param int32_t New integral term value
* @retval None
*/
void PID_SetIntegralTerm( PID_Handle_t * pHandle, int32_t wIntegralTermValue );
/**
* @brief It set a new value into the PID Previous error variable required to
* compute derivative term
* @param pHandle regulator object
* @param wPrevProcessVarError New integral term value
* @retval None
*/
void PID_SetPrevError( PID_Handle_t * pHandle, int32_t wPrevProcessVarError );
/**
* @brief It updates the Kd gain
* @param pHandle PID regulator object
* @param hKdGain New Kd gain
* @retval None
*/
void PID_SetKD( PID_Handle_t * pHandle, int16_t hKdGain );
/**
* @brief It returns the Kd gain of the PID object passed
* @param pHandle PID regulator object
* @retval int16_t Kd gain
*/
int16_t PID_GetKD( PID_Handle_t * pHandle );
/**
* @brief Execute a regular conversion using ADC1.
* The function is not re-entrant (can't executed twice at the same time)
* It returns 0xFFFF in case of conversion error.
* @param pHandle PWM component handler
* @param bChannel ADC channel used for the regular conversion
* @retval It returns converted value or oxFFFF for conversion error
*/
uint16_t PWMC_ExecRegularConv( PWMC_Handle_t * pHandle, uint8_t bChannel );
/**
* @brief It sets the specified sampling time for the specified ADC channel
* on ADC1. It must be called once for each channel utilized by user
* @param pHandle PWM component handler
* @param ADConv_struct struct containing ADC channel and sampling time
* @retval none
*/
void PWMC_ADC_SetSamplingTime( PWMC_Handle_t * pHandle, ADConv_t ADConv_struct );
/**
* @brief It is used to modify the default value of duration of a specific
* rev up phase.
* Note: The module can be also compiled commenting the
* define RUC_ALLOWS_TUNING to optimize the flash memory occupation
* and the RAM usage if the tuning is not required in this case this
* function has no effect.
* @param pHandle related object of class CRUC.
* @param bPhase is the rev up phase, zero based, to be modified.
* @param hDurationms is the new value of duration for that phase.
* @retval none.
*/
void RUC_SetPhaseDurationms( RevUpCtrl_Handle_t * pHandle, uint8_t bPhase, uint16_t hDurationms );
/* Function used to set the targeted motor speed at the end of a specific phase. */
void RUC_SetPhaseFinalMecSpeedUnit( RevUpCtrl_Handle_t * pHandle, uint8_t bPhase,
int16_t hFinalMecSpeedUnit );
/**
* @brief It is used to modify the default value of motor torque at the end of
* a specific rev up phase.
* Note: The module can be also compiled commenting the
* define RUC_ALLOWS_TUNING to optimize the flash memory occupation
* and the RAM usage if the tuning is not required in this case this
* function has no effect.
* @param pHandle related object of class CRUC.
* @param bPhase is the rev up phase, zero based, to be modified.
* @param hFinalTorque is the new value of motor torque at the end of that
* phase. This value represents actually the Iq current expressed in
* digit.
* @retval none.
*/
void RUC_SetPhaseFinalTorque( RevUpCtrl_Handle_t * pHandle, uint8_t bPhase, int16_t hFinalTorque );
/**
* @brief It is used to read the current value of duration of a specific rev
* up phase.
* Note: The module can be also compiled commenting the
* define RUC_ALLOWS_TUNING to optimize the flash memory occupation
* and the RAM usage if the tuning is not required in this case this
* function has no effect.
* @param pHandle related object of class CRUC.
* @param bPhase is the rev up phase, zero based, to be read.
* @retval uint16_t The current value of duration for that phase expressed in
* milliseconds.
*/
uint16_t RUC_GetPhaseDurationms( RevUpCtrl_Handle_t * pHandle, uint8_t bPhase );
/* Function used to read the targeted mechanical speed of a specific RevUp phase */
int16_t RUC_GetPhaseFinalMecSpeedUnit( RevUpCtrl_Handle_t * pHandle, uint8_t bPhase );
/**
* @brief It is used to read the current value of motor torque at the end of a
* specific rev up phase.
* Note: The module can be also compiled commenting the
* define RUC_ALLOWS_TUNING to optimize the flash memory occupation
* and the RAM usage if the tuning is not required in this case this
* function has no effect.
* @param pHandle related object of class CRUC.
* @param bPhase is the rev up phase, zero based, to be read.
* @retval int16_t The current value of motor torque at the end of that phase.
* This value represents actually the Iq current expressed in digit.
*/
int16_t RUC_GetPhaseFinalTorque( RevUpCtrl_Handle_t * pHandle, uint8_t bPhase );
/**
* @brief It is used to get information about the number of phases relative to
* the programmed rev up.
* Note: The module can be also compiled commenting the
* define RUC_ALLOWS_TUNING to optimize the flash memory occupation
* and the RAM usage if the tuning is not required in this case this
* function has no effect.
* @param pHandle related object of class CRUC.
* @retval uint8_t The number of phases relative to the programmed rev up.
*/
uint8_t RUC_GetNumberOfPhases( RevUpCtrl_Handle_t * pHandle );
/**
* @brief Returns latest averaged temperature measurement expressed in Celsius degrees
*
* @param pHandle: Pointer on Handle structure of TemperatureSensor component
*
* @retval Latest averaged temperature measurement in Celsius degrees
*/
int16_t NTC_GetAvTemp_C( NTC_Handle_t * pHandle );
/**
* @brief Returns Temperature mesurement fault status
* Fault can be either #MC_OVER_TEMP or #MC_NO_ERROR according on protection threshold values set
*
* @param pHandle: Pointer on Handle structure of TemperatureSensor component.
*
* @retval Fault code error
*/
uint16_t NTC_CheckTemp( NTC_Handle_t * pHandle );
/**
* @brief It returns the state of the digital output
* @param this object of class DOUT
* @retval OutputState_t Digital output state (ACTIVE or INACTIVE)
*/
DOutputState_t DOUT_GetOutputState( DOUT_handle_t * pHandle );
/**
* @brief It returns the state of Selfcommissioning procedure.
* @param this related object of class CSCC.
* @retval uint8_t It returns the state of Selfcommissioning procedure.
*/
uint8_t SCC_GetState( SCC_Handle_t * pHandle );
/**
* @brief It returns the number of states of Selfcommissioning procedure.
* @param this related object of class CSCC.
* @retval uint8_t It returns the number of states of Selfcommissioning procedure.
*/
uint8_t SCC_GetSteps( SCC_Handle_t * pHandle );
/**
* @brief It returns the measured Rs.
* @param this related object of class CSCC.
* @retval uint32_t It returns the measured Rs, it is a floating point number
* codified into a 32bit integer.
*/
uint32_t SCC_GetRs( SCC_Handle_t * pHandle );
/**
* @brief It returns the measured Ls.
* @param this related object of class CSCC.
* @retval uint32_t It returns the measured Ls, it is a floating point number
* codified into a 32bit integer.
*/
uint32_t SCC_GetLs( SCC_Handle_t * pHandle );
/**
* @brief It returns the measured Ke.
* @param this related object of class CSCC.
* @retval uint32_t It returns the measured Ke, it is a floating point number
* codified into a 32bit integer.
*/
uint32_t SCC_GetKe( SCC_Handle_t * pHandle );
/**
* @brief It returns the measured VBus.
* @param this related object of class CSCC.
* @retval uint32_t It returns the measured Vbus, it is a floating point number
* codified into a 32bit integer.
*/
uint32_t SCC_GetVbus( SCC_Handle_t * pHandle );
/**
* @brief It returns the nominal speed estimated from Ke.
* @param this related object of class CSCC.
* @retval uint32_t It returns the nominal speed estimated from Ke, it is a
* floating point number codified into a 32bit integer.
*/
uint32_t SCC_GetEstNominalSpeed( SCC_Handle_t * pHandle );
/**
* @brief Call this method before start motor to force new motor profile.
* @param this related object of class CSCC.
* @retval none
*/
void SCC_ForceProfile( SCC_Handle_t * pHandle );
/**
* @brief Call this method to force end of motor profile.
* @param this related object of class CSCC.
* @retval none
**/
void SCC_StopProfile( SCC_Handle_t * pHandle );
/**
* @brief Sets the number of motor poles pairs.
* This function shall be called before the start
* of the MP procedure.
* @param this related object of class CSCC.
* @param bPP Number of motor poles pairs to be set.
* @retval none
*/
void SCC_SetPolesPairs( SCC_Handle_t * pHandle, uint8_t bPP );
/**
* @brief Change the current used for RL determination.
Usually is the nominal current of the motor.
* This function shall be called before the start
* of the MP procedure.
* @param this related object of class CSCC.
* @param fCurrent Current used for RL determination.
* @retval none
*/
void SCC_SetNominalCurrent( SCC_Handle_t * pHandle, float fCurrent );
/**
* @brief Get the nominal current used for RL determination.
* @param this related object of class CSCC.
* @retval float Nominal current used for RL determination.
*/
float SCC_GetNominalCurrent( SCC_Handle_t * pHandle );
/**
* @brief Set the Ld/Lq ratio.
* This function shall be called before the start
* of the MP procedure.
* @param this related object of class CSCC.
* @param fLdLqRatio New value of Lq/Lq ratio used by MP for tuning of
current regulators.
* @retval none
*/
void SCC_SetLdLqRatio( SCC_Handle_t * pHandle, float fLdLqRatio );
/**
* @brief Get the Ld/Lq ratio.
* @param this related object of class CSCC.
* @retval float New value of Lq/Lq ratio used by MP for tuning of
current regulators.
*/
float SCC_GetLdLqRatio( SCC_Handle_t * pHandle );
/**
* @brief Set the nominal speed according motor datasheet.
* This function shall be called before the start
* of the MP procedure.
* @param this related object of class CSCC.
* @param wNominalSpeed Nominal speed expressed in RPM.
* @retval none
*/
void SCC_SetNominalSpeed( SCC_Handle_t * pHandle, int32_t wNominalSpeed );
/**
* @brief Get the last nominal speed set by SCC_SetNominalSpeed.
* Note that this is not the estimated one.
* @param this related object of class CSCC.
* @retval int32_t Nominal speed expressed in RPM.
*/
int32_t SCC_GetNominalSpeed( SCC_Handle_t * pHandle );
/**
* @brief Get the estimated maximum speed that can be
* sustatined in the startup open loop acceleration.
* This function must be called only after that the
* MP procedure is completed succesfully.
* @param this related object of class CSCC.
* @retval int32_t Estimated maximum open loop speed expressed in RPM.
*/
int32_t SCC_GetEstMaxOLSpeed( SCC_Handle_t * pHandle );
/**
* @brief Get the estimated maximum acceleration that can be
* sustatined in the startup using the estimated
* startup current. You can retireve the max startup
* current using the SCC_GetStartupCurrentX function.
* This function must be called only after that the
* MP procedure is completed succesfully.
* @param this related object of class CSCC.
* @retval int32_t Estimated maximum open loop acceleration
* espressed in RPM/s.
*/
int32_t SCC_GetEstMaxAcceleration( SCC_Handle_t * pHandle );
/**
* @brief Get the estimated maximum statup current that
* can be applied to the selected motor.
* This function must be called only after that the
* MP procedure is completed succesfully.
* @param this related object of class CSCC.
* @retval int16_t Estimated maximum open loop current
* espressed in s16int.
*/
int16_t SCC_GetStartupCurrentS16( SCC_Handle_t * pHandle );
/**
* @brief Get the estimated maximum statup current that
* can be applied to the selected motor.
* This function must be called only after that the
* MP procedure is completed succesfully.
* @param this related object of class CSCC.
* @retval int16_t Estimated maximum open loop current
* espressed in Ampere.
*/
float SCC_GetStartupCurrentAmp( SCC_Handle_t * pHandle );
/**
* @brief Set the bandwidth used to tune the current regulators.
* This function shall be called before the start
* of the MP procedure.
* @param this related object of class CSCC.
* @param fCurrentBW Bandwidth used to tune the current regulators expressed in rad/s.
* @retval none
*/
void SCC_SetCurrentBandwidth( SCC_Handle_t * pHandle, float fCurrentBW );
/**
* @brief Get the bandwidth used to tune the current regulators.
* @param this related object of class CSCC.
* This function must be called only after that the
* MP procedure is completed succesfully.
* @retval float Bandwidth used to tune the current regulators expressed in
* rad/s.
*/
float SCC_GetCurrentBandwidth( SCC_Handle_t * pHandle );
/**
* @brief Get the PWM frequency used by the test.
* @param this related object of class CSCC.
* @retval uint16_t PWM frequency used by the test expressed in Hz.
*/
uint16_t SCC_GetPWMFrequencyHz( SCC_Handle_t * pHandle );
/**
* @brief Get the FOC repetition rate. It is the number of PWM
* periods elapsed before executing one FOC control cycle.
* @param this related object of class CSCC.
* @retval uint8_t FOC repetition used by the test.
*/
uint8_t SCC_GetFOCRepRate( SCC_Handle_t * pHandle );
/**
* @brief Call this method before start motor to force new OTT procedure.
* @param this related object of class COTT.
* @retval none.
*/
void OTT_ForceTuning( OTT_Handle_t * pHandle );
/**
* @brief It returns the nominal speed estimated by OTT.
* @param this related object of class COTT.
* @retval uint32_t It returns the nominal speed estimated by OTT, it is a
* floating point number codified into a 32bit integer.
*/
uint32_t OTT_GetNominalSpeed( OTT_Handle_t * pHandle );
/**
* @brief It returns the number of states of OTT.
* @param this related object of class COTT.
* @retval uint8_t It returns the number of states of Selfcommissioning procedure.
*/
uint8_t OTT_GetSteps( OTT_Handle_t * pHandle );
/**
* @brief It returns the state of OTT.
* @param this related object of class COTT.
* @retval uint8_t It returns the state of OTT.
*/
uint8_t OTT_GetState( OTT_Handle_t * pHandle );
/**
* @brief It returns true if OTT procedure has been completed, false otherwise.
* @param this related object of class COTT.
* @retval bool It returns true if OTT procedure has been completed, false otherwise.
*/
bool OTT_IsSpeedPITuned( OTT_Handle_t * pHandle );
/**
* @brief It returns the nominal speed estimated by OTT in RPM.
* @param this related object of class COTT.
* @retval float It returns the nominal speed estimated by OTT in RPM.
*/
float OTT_fGetNominalSpeedRPM( OTT_Handle_t * pHandle );
/**
* @brief Sets the number of motor poles pairs.
* @param this related object of class COTT.
* @param bPP Number of motor poles pairs to be set.
* @retval none
*/
void OTT_SetPolesPairs( OTT_Handle_t * pHandle , uint8_t bPP );
/**
* @brief Change the nominal current .
* @param this related object of class COTT.
* @param hNominalCurrent This value represents actually the maximum Iq current
expressed in digit.
* @retval none
*/
void OTT_SetNominalCurrent( OTT_Handle_t * pHandle , uint16_t hNominalCurrent );
/**
* @brief Change the speed regulator bandwidth.
* @param this related object of class COTT.
* @param fBW Current regulator bandwidth espressed in rad/s.
* @retval none
*/
void OTT_SetSpeedRegulatorBandwidth( OTT_Handle_t * pHandle , float fBW );
/**
* @brief Get the speed regulator bandwidth.
* @param this related object of class COTT.
* @retval float Current regulator bandwidth espressed in rad/s.
*/
float OTT_GetSpeedRegulatorBandwidth( OTT_Handle_t * pHandle );
/**
* @brief Get the measured inertia of the motor.
* @param this related object of class COTT.
* @retval float Measured inertia of the motor expressed in Kgm^2.
*/
float OTT_GetJ( OTT_Handle_t * pHandle );
/**
* @brief Get the measured friction of the motor.
* @param this related object of class COTT.
* @retval float Measured friction of the motor expressed in Nms.
*/
float OTT_GetF( OTT_Handle_t * pHandle );
/**
* @brief Return true if the motor has been already profiled.
* @param this related object of class COTT.
* @retval bool true if the if the motor has been already profiled,
* false otherwise.
*/
bool OTT_IsMotorAlreadyProfiled( OTT_Handle_t * pHandle );
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* __MC_TUNING_H */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 26,706 | C | 33.59456 | 106 | 0.677488 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/flux_weakening_ctrl.h | /**
******************************************************************************
* @file flux_weakening_ctrl.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the FLUX WEAKENING
* CTRL component of the Motor Control SDK.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup FluxWeakeningCtrl
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FLUXWEAKENINGCTRL_H
#define __FLUXWEAKENINGCTRL_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
#include "pid_regulator.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup FluxWeakeningCtrl
* @{
*/
/**
* @brief Flux Weakening Control Component handle structure
*/
typedef struct
{
PID_Handle_t * pFluxWeakeningPID; /**< PI object used for flux weakening */
PID_Handle_t * pSpeedPID; /**< PI object used for speed control */
uint16_t hFW_V_Ref; /**< Voltage reference, tenth of
percentage points */
qd_t AvVolt_qd; /**< Average stator voltage in qd
reference frame */
int16_t AvVoltAmpl; /**< Average stator voltage amplitude */
int16_t hIdRefOffset; /**< Id reference offset */
uint16_t hMaxModule; /**< Circle limitation maximum allowed module */
uint16_t hDefaultFW_V_Ref; /**< Default flux weakening voltage reference,
tenth of percentage points*/
int16_t hDemagCurrent; /**< Demagnetization current in s16A:
Current(Amp) = [Current(s16A) * Vdd micro]/
[65536 * Rshunt * Aop] */
int32_t wNominalSqCurr; /**< Squared motor nominal current in (s16A)^2
where:
Current(Amp) = [Current(s16A) * Vdd micro]/
[65536 * Rshunt * Aop] */
uint16_t hVqdLowPassFilterBW; /**< Use this parameter to configure the Vqd
first order software filter bandwidth.
hVqdLowPassFilterBW = FOC_CurrController
call rate [Hz]/ FilterBandwidth[Hz] in
case FULL_MISRA_COMPLIANCY is defined.
On the contrary, if FULL_MISRA_COMPLIANCY
is not defined, hVqdLowPassFilterBW is
equal to log with base two of previous
definition */
uint16_t hVqdLowPassFilterBWLOG; /**< hVqdLowPassFilterBW expressed as power of 2.
E.g. if gain divisor is 512 the value
must be 9 because 2^9 = 512 */
} FW_Handle_t;
/**
* @}
*/
/* Exported functions ------------------------------------------------------- */
/**
* @brief Initializes all the object variables, usually it has to be called
* once right after object creation.
* @param pHandle Flux weakening init strutcture.
* @param pPIDSpeed Speed PID structure.
* @param pPIDFluxWeakeningHandle FW PID structure.
* @retval none.
*/
void FW_Init( FW_Handle_t * pHandle, PID_Handle_t * pPIDSpeed, PID_Handle_t * pPIDFluxWeakeningHandle );
/**
* @brief It should be called before each motor restart and clears the Flux
* weakening internal variables with the exception of the target
* voltage (hFW_V_Ref).
* @param pHandle Flux weakening init strutcture.
* @retval none
*/
void FW_Clear( FW_Handle_t * pHandle );
/**
* @brief It computes Iqdref according the flux weakening algorithm. Inputs
* are the starting Iqref components.
* As soon as the speed increases beyond the nominal one, fluxweakening
* algorithm take place and handles Idref value. Finally, accordingly
* with new Idref, a new Iqref saturation value is also computed and
* put into speed PI.
* @param pHandle Flux weakening init strutcture.
* @param Iqdref The starting current components that have to be
* manipulated by the flux weakening algorithm.
* @retval qd_t Computed Iqdref.
*/
qd_t FW_CalcCurrRef( FW_Handle_t * pHandle, qd_t Iqdref );
/**
* @brief It low-pass filters both the Vqd voltage components. Filter
* bandwidth depends on hVqdLowPassFilterBW parameter
* @param pHandle Flux weakening init strutcture.
* @param Vqd Voltage componets to be averaged.
* @retval none
*/
void FW_DataProcess( FW_Handle_t * pHandle, qd_t Vqd );
/**
* @brief Use this method to set a new value for the voltage reference used by
* flux weakening algorithm.
* @param pHandle Flux weakening init strutcture.
* @param uint16_t New target voltage value, expressend in tenth of percentage
* points of available voltage.
* @retval none
*/
void FW_SetVref( FW_Handle_t * pHandle, uint16_t hNewVref );
/**
* @brief It returns the present value of target voltage used by flux
* weakening algorihtm.
* @param pHandle Flux weakening init strutcture.
* @retval int16_t Present target voltage value expressed in tenth of
* percentage points of available voltage.
*/
uint16_t FW_GetVref( FW_Handle_t * pHandle );
/**
* @brief It returns the present value of voltage actually used by flux
* weakening algorihtm.
* @param pHandle Flux weakening init strutcture.
* @retval int16_t Present averaged phase stator voltage value, expressed
* in s16V (0-to-peak), where
* PhaseVoltage(V) = [PhaseVoltage(s16A) * Vbus(V)] /[sqrt(3) *32767].
*/
int16_t FW_GetAvVAmplitude( FW_Handle_t * pHandle );
/**
* @brief It returns the measure of present voltage actually used by flux
* weakening algorihtm as percentage of available voltage.
* @param pHandle Flux weakening init strutcture.
* @retval uint16_t Present averaged phase stator voltage value, expressed in
* tenth of percentage points of available voltage.
*/
uint16_t FW_GetAvVPercentage( FW_Handle_t * pHandle );
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* __FLUXWEAKENINGCTRL_H */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 7,403 | C | 40.133333 | 104 | 0.549912 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/acim_ifoc.h | /**
******************************************************************************
* @file acim_ifoc.h
* @author STMicroelectronics - SRA - System Development Unit - MC Team
* @brief This file provides firmware functions that implement the features
* of the Rotor Flux Position Feedback component of the Motor Control SDK.
* - estimates the rotor flux electrical angle (IFOC)
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ACIM_IFOC_H
#define __ACIM_IFOC_H
#include "mc_type.h"
#include "parameters_conversion.h"
#include "speed_pos_fdbk.h"
#include "unit_conversions.h"
#include "acim_motor.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup ACIM_IFOC ACIM IFOC
* @{
*/
/* Exported types ------------------------------------------------------------*/
/**
* @brief This structure is used to handle the ACIM_IFOC component
*
*/
typedef struct
{
SpeednPosFdbk_Handle_t * SPD; /*!< The speed sensor used to perform the speed
regulation.*/
pFOCVars_t pFOCVars; /*!< Pointer to FOC vars */
ACIM_MotorParams_Handle_t *pACIM_MotorParams; /*!< Pointer to ACIM Motor Params Handle */
float fRotorFluxFreq_rads; /*!< Observed electrical rotor Flux pulsation (rad/s)*/
float fRotorFlux_Angle_rad; /*!< Observed electrical rotor Flux angle (rad) */
float fCalcAngleExecFreqHz; /*!< Execution frequency expressed in Hz*/
float fCalcAngleExecTime_s; /*!< Execution time expressed in seconds */
int16_t hElAngle; /*!< Electrical angle used by FOC transormations */
} ACIM_IFOC_Handle_t;
/* Exported Functions ------------------------------------------------------- */
/**
* @brief It initializes the variables required for the rotor flux angle estimation.
* @param pHandle: handler of the current instance of the ACIM_IFOC component
* @retval none
*/
void ACIM_IFOC_Init(ACIM_IFOC_Handle_t *pHandle , SpeednPosFdbk_Handle_t * oSPD);
/**
* @brief It performs the rotor flux angle estimation.
* @param pHandle: handler of the current instance of the ACIM_IFOC component
* @retval none
*/
void ACIM_IFOC_CalcAngle(ACIM_IFOC_Handle_t *pHandle);
/**
* @brief It returns the flux electrical angle in digital format
* @param pHandle: handler of the current instance of the ACIM_IFOC component
* @retval int16_t hElAngle
*/
int16_t ACIM_IFOC_GetElAngle(ACIM_IFOC_Handle_t *pHandle);
/**
* @}
*/
/** @} */
#endif /*__ACIM_IFOC_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 5,089 | C | 38.765625 | 101 | 0.64099 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/pi_float_regulator.h | /**
******************************************************************************
* @file pi_float_regulator.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains all definitions and functions prototypes for the
* floating point version of the PI regulator component of the Motor
* Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup PIFloatRegulator
*/
#ifndef __PI_FLOAT_REGULATOR_H
#define __PI_FLOAT_REGULATOR_H
#include "mc_type.h"
typedef struct
{
float fDefKpGain; /**< Default @f$K_{pg}@f$ gain */
float fDefKiGain; /**< Default @f$K_{ig}@f$ gain */
float fKpGain;
float fKiGain;
float fIntegralTerm;
float fUpperIntegralLimit;
float fLowerIntegralLimit;
float fLowerLimit;
float fUpperLimit;
float fKs;
float fAntiWindTerm;
FunctionalState bAntiWindUpActivation;
float fExecFrequencyHz;
} PI_Float_Handle_t;
//typedef struct
//{
// float fKp;
// float fKi;
// float fKs;
// FunctionalState AntiWindupEnable;
// float fLowerLimit;
// float fUpperLimit;
// float fExecFrequencyHz;
//}FloatPI_StructInit_t;
void PI_Float_HandleInit(PI_Float_Handle_t *pHandle);
float PI_Float_Calc(PI_Float_Handle_t *pHandle, float fProcessVarError);
#endif /* __PI_FLOAT_REGULATOR_H */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 1,952 | C | 26.125 | 85 | 0.576844 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/acim_lso_foc.h | /**
******************************************************************************
* @file acim_lso_foc.h
* @author STMicroelectronics - SRA - System Development Unit - MC Team
* @brief This file provides firmware functions that implement the features
* of the Rotor Flux Position Feedback component of the Motor Control SDK.
* - estimates the rotor flux electrical angle and mechanical rotor speed
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef ACIM_LSO_FOC_H
#define ACIM_LSO_FOC_H
#include "mc_type.h"
#include "parameters_conversion.h"
#include "speed_pos_fdbk.h"
#include "bus_voltage_sensor.h"
#include "pi_float_regulator.h"
#include "unit_conversions.h"
#include "acim_motor.h"
#define MAX_SPEED_RPM_MARGIN 1.5f /* LSO PI regulator Output saturation margin (50% Max Application Speed) */
#define PI_LSO_MAX_OUT (((float)MOTOR_MAX_SPEED_RPM*MAX_SPEED_RPM_MARGIN*2.0f*PI*POLE_PAIR_NUM)/60.0f) //rad/s
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup ACIM_LSO-FOC ACIM LSO FOC
* @{
*/
/* Exported types ------------------------------------------------------------*/
/**
* @brief This structure is used to handle the ACIM_LSO-FOC component
*
*/
typedef struct
{
SpeednPosFdbk_Handle_t _SpeedEstimator; /*!< The speed sensor used to perform the speed
regulation.*/
BusVoltageSensor_Handle_t *pBVS; /*!< Pointer to BusVoltageSensor Handle */
pFOCVars_t pFOCVars; /*!< Pointer to FOC vars */
ACIM_MotorParams_Handle_t *pACIM_MotorParams; /*!< Pointer to ACIM Motor Params Handle */
PI_Float_Handle_t* fPI; /*!< The PI regulator used to perfom the rotor speed estimation */
Signal_Components fIqds_error_A; /*!< Current error. Iqds_error_A = Iqd_meas_A - Iqds_obs_A [A]*/
Signal_Components fIqds_obs_A; /*!< Observed quantities - States of State Model */
Signal_Components fFlux_qdr_obs; /*!< Rotor flux observed divided by magnetizing inductance, LM. [Vs/H]
It corresponds to the magnetizing rotor current [A] */
float fRotorFluxFreq_rads; /*!< Observed Electrical Rotor Flux speed (rad/s)*/
float fRotorFlux_Angle_rad; /*!< Observed electrical rotor Flux angle [rad]*/
int16_t hElAngle; /*!< Electrical angle used by MCLib to perform the FOC transormations [s16 degrees]*/
float fRotorElSpeed_obs_rads; /*!< Observed electrical Rotor speed (rad/s) */
float fRotorSpeed_RPM; /*!< Observed mechanical Rotor speed (rpm) */
float fMaxObsRotorSpeed_RPM; /*!< Maximum Observed mechanical Rotor speed (rpm) */
float k; /*!< Common parameter for Luenberger's Matrix coeffients computation*/
float fCalcAngleExecFreqHz; /*!< Execution frequency expressed in Hz */
float fCalcAngleExecTime_s; /*!< Execution time expressed in seconds */
/* LSO debug variables */
float fdbg_ElAngle_rad; /*!< Angle used for performing V/f open loop control (rad)*/
int16_t hdbg_ElAngle; /*!< Angle used for performing V/f open loop control (s16)*/
float fdbg_Frequency_rads; /*!< Forced flux frequency (rad/s) */
float fdbg_Flux_K; /*!< Flux constant value Vs,rate/fe,rate (Wb) */
float fdbg_Vampl; /*!< Voltage amplitude computed by V/f (Vpeak) */
float fdbg_VoltageOffset_V; /*!< */
float fdbg_MinFreqTH_rads; /*!< */
} ACIM_LSO_Handle_t;
/* Exported Functions ------------------------------------------------------- */
/**
* @brief It initializes the variables required for the rotor flux angle and rotor speed estimation.
* @param pHandle: handler of the current instance of the ACIM_LSO component
* @retval none
*/
void ACIM_LSO_Init(ACIM_LSO_Handle_t *pHandle, BusVoltageSensor_Handle_t *pBVS);
/**
* @brief It clears State Observer object by re-initializing private variables.
* @param pHandle: handler of the current instance of the ACIM_LSO component
* @retval none
*/
void ACIM_LSO_Clear(ACIM_LSO_Handle_t *pHandle);
/**
* @brief It executes Luenberger state observer and computes a new speed
* estimation and update the estimated electrical angle.
* @param pHandle: handler of the current instance of the ACIM_LSO component
* @retval none
*/
void ACIM_LSO_CalcAngle(ACIM_LSO_Handle_t *pHandle);
/**
* @brief It returns the flux electrical angle in digital format
* @param pHandle: handler of the current instance of the ACIM_LSO component
* @retval int16_t hElAngle
*/
int16_t ACIM_LSO_GetElAngle(ACIM_LSO_Handle_t *pHandle);
/**
* @brief It checks the validity of LSO variables
* @param pHandle: handler of the current instance of the ACIM_LSO component
* @retval bool: true or false
*/
bool ACIM_LSO_CheckIntegrity(ACIM_LSO_Handle_t *pHandle);
/**
* @brief It performs the voltage calculation used by LSO-Debug V/f control
* @param pHandle: handler of the current instance of the ACIM_LSO component
* @retval Volt_Components Vqd
*/
qd_t ACIM_DBG_LSO_CalcVoltage(ACIM_LSO_Handle_t *pHandle);
/**
* @brief It returns the flux electrical angle in digital format computed by
* LSO-Debug V/f control
* @param pHandle: handler of the current instance of the ACIM_LSO component
* @retval int16_t hElAngle
*/
int16_t ACIM_DBG_LSO_GetdbgElAngle(ACIM_LSO_Handle_t *pHandle);
/**
* @brief It calculates the angle to perform the LSO-Debug V/f control
* @param pHandle: handler of the current instance of the ACIM_LSO component
* @retval none
*/
void ACIM_DBG_LSO_CalcAngle(ACIM_LSO_Handle_t *pHandle, float fFrequency_Hz);
/**
* @}
*/
/** @} */
#endif /*ACIM_LSO_FOC_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 8,635 | C | 43.287179 | 134 | 0.630689 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/acim_motor.h | /**
******************************************************************************
* @file acim_motor.h
* @author Motion Control Team, ST Microelectronics
* @brief This file provides definition and functions related to a generic
* AC induction motor
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ACIM_MOTOR_H
#define __ACIM_MOTOR_H
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup ACIM_MOTOR ACIM Motor
* @{
*/
/* Exported types ------------------------------------------------------------*/
/**
* @brief This structure is used to handle the ACIM_MOTOR component
*
*/
typedef struct
{
/* Motor parameters - Steady state model */
float fRs; /*!< Stator resistance, (Ohm) */
float fRr; /*!< Rotor resistance referred to stator equivalent circuit, (Ohm)*/
float fLls; /*!< Stator leakage inductance, (H)*/
float fLlr; /*!< Rotor leakage inductance referred to the stator equivalent circuit, (H)*/
float fLms; /*!< Motor Magnetizing inductance ((Steady-state model), (H) */
uint8_t bPP; /*!< Motor Pole Pairs*/
/* Dynamic model's parameters after applying the
Reference Frame Theory transformation */
float fLM; /*!< Motor Magnetizing inductance (Dynamic model), (H) */
float fLr; /*!< Global rotor inductance (Dynamic model), Lr = Llr + LM, (H)*/
float fLs; /*!< Global stator inductance (Dynamic model), Ls = Lls + LM, (H)*/
float ftaur; /*!< Rotor Time constant, Lr/Rr, (s) */
float ftaus; /*!< Statot Time constant, Ls/Rs, (s) */
float fsigma; /*!< Total leakage factor, (dimensionless)*/
float fImagn_A; /*!< Magnetizing Current (No-Load current) expressed in Ampere */
float fNominalFrequency_rads;
} ACIM_MotorParams_Handle_t;
/**
* @}
*/
/** @} */
#endif /*__ACIM_MOTOR_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 4,521 | C | 44.22 | 111 | 0.614023 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/unit_conversions.h | /**
******************************************************************************
* @file unit_conversions.h
* @author STMicroelectronics - SRA - System Development Unit - MC Team
* @brief This file contains definitions and functions prototypes
* related to unit conversion in the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef UNIT_CONVERSIONS_H
#define UNIT_CONVERSIONS_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes --------------------------------------------------*/
#include "mc_type.h"
#include "parameters_conversion.h"
#include "bus_voltage_sensor.h"
/* Exported type definition --------------------------------------------------*/
/* Functions prototype -------------------------------------------------------*/
Signal_Components Convert_s16_to_A(qd_t hIqd);
Signal_Components Convert_s16_to_V(BusVoltageSensor_Handle_t *pBVS, qd_t hVqd);
qd_t Convert_V_to_s16(BusVoltageSensor_Handle_t *pBVS, Signal_Components fVqdV);
qd_t Convert_A_to_s16(Signal_Components fIqdA);
int16_t Convert_Rad_to16bit(float fAngle_rad);
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 1,870 | C | 32.410714 | 85 | 0.514439 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/acim_vf_control.h | /**
******************************************************************************
* @file acim_vf_control.h
* @author STMicroelectronics - SRA - System Development Unit - MC Team
* @brief This file provides firmware functions that implement the features
* of the V/f control of Induction Motor of the Motor Control SDK.
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef ACIM_VF_CONTROL_H
#define ACIM_VF_CONTROL_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "mc_type.h"
#include "parameters_conversion.h"
#include "speed_pos_fdbk.h"
#include "bus_voltage_sensor.h"
#include "pi_float_regulator.h"
#include "ramp_ext_mngr.h"
#include "pwm.h"
#include "unit_conversions.h"
#include "acim_motor.h"
/* Exported type definition -----------------------------------------------------------------------------------------------*/
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup ACIM_VF
* @{
*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
VF_OL = 1, /*!< Open Loop control */
VF_CL = 2 /*!< Closed Loop control */
}ACIM_VF_Mode_t;
/**
* @brief This structure is used to handle the instance of the ACIM_VF component
*
*/
typedef struct
{
ACIM_MotorParams_Handle_t *pACIM_MotorParams;
PWM_Handle_t *pPWM;
/* Control quantities */
float fNominalPhaseVoltagePeak_V;
float VoltageAmpl;
float fFlux_K; /*!< Flux constant value Vs,rate/fe,rate (Wb) */
float fVoltage_Offset; /*!< Voltage offset used for frequencies lower than the fMinFreq_TH_Hz (Wb)
to compensate the stator voltage drop */
float fMinFreq_TH_Hz; /*!< Threshold to fix the Voltage offset (Hz) */
float fFlux_Freq_Hz; /*!< Electrical Flux frequency (Hz)*/
float fFlux_Freq_rads; /*!< Electrical Flux speed (rad/s)*/
float fFlux_Angle_rad; /*!< Electrical Flux angle (rad)*/
int16_t hElAngle; /*!< Electrical angle used by MCLib to perform the FOC transormations [s16 degrees]*/
float fCalcAngleExecFreqHz; /*!< Execution frequency [Hz] */
float fCalcAngleExecTime_s; /*!< Execution time [s] */
RampExtMngr_Handle_t* pRMNGR;
ACIM_VF_Mode_t bVF_Mode;
/* Closed Loop control */
PI_Float_Handle_t* fPI; /*!< The PI regulatore used to perfom the rotor speed estimation */
float fSlipFrequency_rads;
SpeednPosFdbk_Handle_t* SPD_real; /*!< The speed sensor used to perform the speed
regulation.*/
float fRotorFreqRef_rads; /*!< Reference rotor speed - Speed Loop (rad/s) */
float fRotorFreqRef_RPM; /*!< Reference rotor speed - Speed Loop (rpm) */
float fVoutMax_PWM_Mod_V; /*!< Maximum inverter output voltage using sin-tri PWM modulation */
}ACIM_VF_Handle_t;
/* Exported Functions ------------------------------------------------------- */
/**
* @brief It initializes the variables required for V/f control execution.
* @param pHandle: handler of the current instance of the ACIM_VF component
* @retval none
*/
void ACIM_VF_Init(ACIM_VF_Handle_t *pHandle);
/**
* @brief It resets the variables required for V/f control execution.
* @param pHandle: handler of the current instance of the ACIM_VF component
* @param pBVS: handler of the bus voltage sensor component
* @retval none
*/
void ACIM_VF_Clear(ACIM_VF_Handle_t *pHandle, BusVoltageSensor_Handle_t *pBVS);
/**
* @brief It calculates the angle of the sinusoidal electromagnetic field.
* @param pHandle: handler of the current instance of the ACIM_VF component
* @retval none
*/
void ACIM_VF_CalcAngle(ACIM_VF_Handle_t *pHandle);
/**
* @brief Get the electrical angle of the sinusoidal electromagnetic field
* @param pHandle: handler of the current instance of the ACIM_VF component
* @retval float fElAngle
*/
float ACIM_VF_GetElAngle(ACIM_VF_Handle_t *pHandle);
/**
* @brief It configures the frequency ramp
* @param pHandle: handler of the current instance of the ACIM_VF component
* @retval float fElAngle
*/
bool ACIM_VF_ExecRamp(ACIM_VF_Handle_t *pHandle, int16_t hTargetFinal, uint32_t Durationms);
/**
* @brief Check if the settled ramp has been completed.
* @param pHandle handler of the current instance of the ACIM_VF component.
* @retval bool It returns true if the ramp is completed, false otherwise.
*/
bool ACIM_VF_RampCompleted( ACIM_VF_Handle_t *pHandle );
/**
* @brief Stop the execution of the ramp keeping the last reached value.
* @param pHandle handler of the current instance of the ACIM_VF component.
* @retval none
*/
void ACIM_VF_StopRamp( ACIM_VF_Handle_t *pHandle );
float ACIM_VF_FluxFreqCalc(ACIM_VF_Handle_t *pHandle);
uint16_t ACIM_VF_Controller(ACIM_VF_Handle_t *pHandle);
int16_t ACIM_VF_GetMecSpeedRefUnit( ACIM_VF_Handle_t * pHandle );
/**
* @}
*/
/** @} */
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /*__ACIM_VF_CONTROl_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 7,869 | C | 35.775701 | 134 | 0.62168 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/MCSDK/MCLibACIM/Any/Inc/circle_limitation.h | /**
******************************************************************************
* @file circle_limitation.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains all definitions and functions prototypes for the
* Circle Limitation component of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup CircleLimitation
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef CIRCLELIMITATION_H
#define CIRCLELIMITATION_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup CircleLimitation
* @{
*/
/**
* @brief CircleLimitation component parameters definition
*/
typedef struct
{
uint16_t MaxModule; /**< Circle limitation maximum allowed
module */
uint16_t MaxVd; /**< Circle limitation maximum allowed
module */
} CircleLimitation_Handle_t;
/* Exported functions ------------------------------------------------------- */
qd_t Circle_Limitation(const CircleLimitation_Handle_t *pHandle, qd_t Vqd);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* CIRCLELIMITATION_H */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 2,023 | C | 27.111111 | 85 | 0.484429 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/libHSO/impedcorr.h | /* impedcorr.h */
#ifndef _IMPEDCORR_H_
#define _IMPEDCORR_H_
#include "fixpmath.h"
#include <stddef.h>
typedef struct _IMPEDCORR_Params_
{
float_t voltageFilterPole_rps;
float_t cycleFreq_Hz;
float_t fullScaleFreq_Hz;
float_t KsampleDelay;
float_t fullScaleCurrent_A;
float_t fullScaleVoltage_V;
} IMPEDCORR_Params;
#define IMPEDCORR_SIZE_WORDS (50) /* Size in words, plus a margin */
typedef struct _IMPEDCORR_Obj_
{
/* Contents of this structure is not public */
uint16_t reserved[IMPEDCORR_SIZE_WORDS];
} IMPEDCORR_Obj;
typedef IMPEDCORR_Obj* IMPEDCORR_Handle;
/* Initialization */
extern IMPEDCORR_Handle IMPEDCORR_init(void *pMemory, const size_t size);
extern void IMPEDCORR_setParams(IMPEDCORR_Handle pHandle, const IMPEDCORR_Params *pParams);
/* Functional */
extern Voltages_Uab_t IMPEDCORR_run(IMPEDCORR_Handle pHandle,
const Currents_Iab_t* pIab_pu,
const Voltages_Uab_t* pUab_pu,
const fixp30_t Fe_pu
);
/* Accessors */
extern void IMPEDCORR_getEmf_ab_pu(const IMPEDCORR_Handle handle, Voltages_Uab_t* pEmf_ab);
extern void IMPEDCORR_getEmf_ab_filt_pu(const IMPEDCORR_Handle handle, Voltages_Uab_t* pE_ab);
extern Voltages_Uab_t IMPEDCORR_getEmf_ab_filt(const IMPEDCORR_Handle handle);
extern void IMPEDCORR_getIab_filt_pu(const IMPEDCORR_Handle handle, Currents_Iab_t* pIab_filt);
extern Currents_Iab_t IMPEDCORR_getIab_filt(const IMPEDCORR_Handle handle);
extern float_t IMPEDCORR_getKSampleDelay(const IMPEDCORR_Handle handle);
extern float_t IMPEDCORR_getLs_si(const IMPEDCORR_Handle pHandle);
extern FIXP_scaled_t IMPEDCORR_getRs_pu_fps(const IMPEDCORR_Handle handle);
extern float_t IMPEDCORR_getRs_si(const IMPEDCORR_Handle pHandle);
extern void IMPEDCORR_setKSampleDelay(IMPEDCORR_Handle handle, const float_t value);
extern void IMPEDCORR_setLs(IMPEDCORR_Handle handle, const fixp_t Ls_pu, const fixpFmt_t fmt);
extern void IMPEDCORR_setRs(IMPEDCORR_Handle handle, const fixp_t Rs_pu, const fixpFmt_t fmt);
extern void IMPEDCORR_setLs_si(IMPEDCORR_Handle pHandle, const float_t Ls_H);
extern void IMPEDCORR_setRs_si(IMPEDCORR_Handle pHandle, const float_t Rs_Ohm);
#endif /* _IMPEDCORR_H_ */
/* end of impedcorr.h */
| 2,208 | C | 34.063492 | 95 | 0.759058 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/libHSO/rsest.h | /* rsest.h */
#ifndef _RSEST_H_
#define _RSEST_H_
#include "fixpmath.h"
#include <stddef.h>
#include <stdbool.h>
typedef struct _RSEST_Params_
{
float_t FullScaleCurrent_A;
float_t FullScaleVoltage_V;
float_t RatedCelcius; /* Temperature @ Rated resistance value (deg C) */
float_t AmbientCelcius; /* Ambient Temperature (deg C) */
float_t RsRatedOhm;
float_t MotorSkinFactor; /* Motor skin-factor at choosen injection frequency */
float_t F_calculate_Hz;
float_t m_copper_kg; /* Total copper mass for heating estimation */
float_t coolingTau_s;
float_t correctionGain;
float_t injectGain;
} RSEST_Params;
typedef struct _RSEST_Obj_
{
float_t Tbackground; /* s */
float_t FullScaleImpedance_OHM; /* FullScaleVoltage/FullScaleCurrent */
float_t FullScaleAdmittance_MHO; /* FullScaleCurrent/FullScaleVoltage */
float_t FullScalePower_3ph_W; /* 1.5 * FullScaleCurrent * FullScaleVoltage */
float_t oneoverRs_rated_Mho; /* updated when rated value is changed */
uint16_t decimationCounter;
bool update_on;
bool current_is_low;
bool doBackground; // go command to achieve decimation
float_t rs_rated_ohm; //
float_t rs_ohm; // read/write in _runBackground
FIXP_scaled_t Rs_pu_fps; /* output in pu_fps format */
float_t rs_inject_ohm; // read/write in _runBackground
fixp30_t rs_inject_pur; // relative to Rrated
fixp_t correctionGain;
fixp_t injectGain;
/* Skin factor */
fixp_t SkinFactor; // Skinfactor Rac/Rdc normally slightly larger than 1.
fixp30_t T_calc; // 1/fBackground = backgroundinterval in seconds, used by _setRsBandwidth_Hz()
fixp30_t incRateLimit;
fixp30_t incRfactor;
uint16_t lpShiftVI; // Low pass filter bitshift for 'VI', voltage x current, used in power calculation
uint16_t lpShiftI2t;
/* Power-based resistance estimation */
// PowerLP and IsquaredLP are calculated in the interrupt and used in the background to
// calculate rs_power_ohm/rs_power_pu_fps. Both are updated only when current is above IsquaredThreshold_pu
fixp30_t PowerLP; // Power, low pass filtered (two phase: 2/3 of total power)
fixp30_t IsquaredLP; // Squared current, Low pass filtered, required for R = P/I^2 estimation.
fixp30_t IsquaredLPt; // faster version of squared current filtered
float_t TerminalPowerWatt; // total Terminal Power for all three phases
float_t rs_power_ohm; // power-based resistance
/* */
fixp20_t ratCelcius_pu; // ambiant temperature (deg C) this is where Rs=Rrated.
fixp20_t ambCelcius_pu;
fixp30_t ambRfactor;
fixp30_t deltaRfactor; /* TempRfactor increment */
fixp30_t maxRfactor; /* Limit outside ZEST operation */
fixp30_t TempRfactor; /* Active Rs/Rrated value */
fixp20_t TempCelcius; // approximate temperature guess
fixp30_t Thermal_K;
fixp30_t Thermal_Leak;
fixp30_t dither;
uint32_t debugTestCounter; /* should increase by 1000 counts per second (when flag_debug=true)*/
bool flag_debug;
bool synchTemp;
fixp20_t debug_TempCelcius;
fixp30_t debug_deltaRfactor;
fixp30_t debug_TempRfactor;
fixp30_t incRfactor_LP;
} RSEST_Obj;
typedef RSEST_Obj* RSEST_Handle;
extern RSEST_Handle RSEST_init(void *pMemory, const size_t size);
extern void RSEST_setParams(RSEST_Handle handle, const RSEST_Params *pParams);
/* Interrupt function (synchronous with sensorless algorithm) */
extern void RSEST_run(RSEST_Handle handle, const Currents_Iab_t *pIab_pu, const Voltages_Uab_t *pUab_pu);
/* Background function (~1 kHz) now spread out in mainloop */
extern void RSEST_runBackground(RSEST_Handle handle);
extern void RSEST_runBackSlowed(RSEST_Handle handle, const bool injectActive, const fixp30_t CheckRs, const float_t Rsdelta);
/* Getters */
extern bool RSEST_getCurrentIsLow(const RSEST_Handle handle);
extern bool RSEST_getDoBackGround(const RSEST_Handle handle);
extern fixp30_t RSEST_getRsInjectGainTs(const RSEST_Handle handle);
extern float RSEST_getRsInjectOhm(const RSEST_Handle handle);
extern float RSEST_getRsOhm(const RSEST_Handle handle);
extern float RSEST_getRsPowerOhm(const RSEST_Handle handle);
extern FIXP_scaled_t RSEST_getRsRated_fps(const RSEST_Handle handle);
extern FIXP_scaled_t RSEST_getRs_pu_fps(const RSEST_Handle handle);
extern fixp_t RSEST_getSkinFactor(const RSEST_Handle handle);
extern fixp20_t RSEST_getTempCelcius_pu(const RSEST_Handle handle);
/* Setters */
extern void RSEST_setAmbientCelcius_pu(RSEST_Handle handle, const fixp20_t value);
extern void RSEST_setInjectGain(RSEST_Handle handle, const fixp_t value);
extern void RSEST_setRsOhm(RSEST_Handle handle, const float_t rs_ohm);
extern void RSEST_setRsRatedOhm(RSEST_Handle handle, const float_t value);
extern void RSEST_setRsToRated(RSEST_Handle handle);
extern void RSEST_setRs_pu_fps(RSEST_Handle handle, const FIXP_scaled_t rs_pu_fps);
extern void RSEST_setSkinFactor(RSEST_Handle handle, const float_t value);
extern void RSEST_setTempRfactor(RSEST_Handle handle, const float_t value);
extern void RSEST_setUpdate_ON(RSEST_Handle handle, const bool value);
#endif /* _RSEST_H_ */
/* end of rsest.h */
| 6,100 | C | 40.222973 | 160 | 0.62541 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/libHSO/hso.h | /* hso.h */
#ifndef _HSO_H_
#define _HSO_H_
#include "fixpmath.h"
#include <stdbool.h>
#include <stddef.h>
#include <string.h> /* memset */
#define HSO_setflag_TrackAngle HSO_setFlag_TrackAngle /* HSO_setflag_TrackAngle is deprecated */
typedef struct _HSO_Params_
{
float_t Flux_Wb;
float_t CrossOver_Hz;
float_t isrTime_s;
float_t FullScaleVoltage_V;
float_t FullScaleFreq_Hz;
float_t speedPole_rps;
bool flag_FilterAdaptive;
float_t Filter_adapt_fmin_Hz;
float_t Filter_adapt_fmax_Hz;
float_t CheckDirBW_Hz;
} HSO_Params;
#define HSO_SIZE_WORDS (120) /* Size in words, plus a margin */
typedef struct _HSO_Obj_
{
/* Contents of this structure is not public */
uint16_t reserved[HSO_SIZE_WORDS];
} HSO_Obj;
typedef HSO_Obj* HSO_Handle;
/* initialization */
static inline HSO_Handle HSO_init(void *pMemory, const size_t size)
{
HSO_Handle handle = (HSO_Handle) NULL;
if (size >= sizeof(HSO_Obj))
{
handle = (HSO_Handle) pMemory;
memset(pMemory, 0, size);
}
return (handle);
}
extern void HSO_setParams(HSO_Handle handle, const HSO_Params *pParams);
/* functional */
extern void HSO_run(HSO_Handle handle, Voltages_Uab_t *pVback_ab, const fixp30_t Correction);
extern void HSO_adjustAngle_pu(HSO_Handle handle, const fixp30_t rotation_pu);
extern void HSO_clear(HSO_Handle handle);
extern void HSO_flip_angle(HSO_Handle handle);
/* accessors */
extern fixp30_t HSO_getAngle_pu(const HSO_Handle handle);
extern fixp30_t HSO_getCheckDir(const HSO_Handle handle);
extern void HSO_getCosSinTh_ab(const HSO_Handle handle, FIXP_CosSin_t *pCosSinTh);
extern FIXP_CosSin_t HSO_getCosSin(const HSO_Handle handle);
extern fixp30_t HSO_getDelta_theta_pu(const HSO_Handle handle);
extern fixp30_t HSO_getEmfSpeed_pu(const HSO_Handle handle);
extern Vector_ab_t HSO_getFlux_ab_Wb(const HSO_Handle handle);
extern fixp30_t HSO_getFluxAmpl_Wb(const HSO_Handle handle);
extern fixp30_t HSO_getFluxRef_Wb(const HSO_Handle handle);
extern fixp30_t HSO_getKoffset(const HSO_Handle handle);
extern fixp30_t HSO_getSpeedLP_pu(const HSO_Handle handle);
extern float_t HSO_getSpeedPole_rps(const HSO_Handle handle);
extern void HSO_setAngle_pu(HSO_Handle handle, const fixp30_t theta);
extern void HSO_setCrossOver_Hz(HSO_Handle handle, const float_t CrossOver_Hz);
extern void HSO_setCrossOver_pu(HSO_Handle handle, const fixp30_t CrossOver_pu);
extern void HSO_setFlag_TrackAngle(HSO_Handle handle, const bool value);
extern void HSO_setFluxPolar_pu(HSO_Handle handle, const fixp30_t angle_pu, const fixp30_t magn_pu);
extern void HSO_setFluxRef_Wb(HSO_Handle handle, const fixp30_t FluxWb);
extern void HSO_setKoffset(HSO_Handle handle, const fixp30_t value);
extern void HSO_setMaxCrossOver_Hz(HSO_Handle handle, const float_t value);
extern void HSO_setMinCrossOver_Hz(HSO_Handle handle, const float_t value);
extern void HSO_setObserverRatio(HSO_Handle handle, const float_t value);
extern void HSO_setSpeedPole_rps(HSO_Handle handle, const float_t value);
#endif /* _HSO_H_ */
/* end of hso.h */
| 3,192 | C | 26.765217 | 100 | 0.714286 |
Tbarkin121/GuardDog/stm32/MotorDrive/MCSDK_v6.2.0-Full/MotorControl/libHSO/polpulse.h | /* polpulse.h */
#ifndef _POLPULSE_H_
#define _POLPULSE_H_
#include "fixpmath.h"
#include <stddef.h>
#define POLPULSE_NUMSAMPLES 6
typedef enum _POLPULSE_State_e_
{
POLPULSE_STATE_Idle,
POLPULSE_STATE_Clear,
POLPULSE_STATE_Precalcs,
POLPULSE_STATE_WaitDecay,
POLPULSE_STATE_WaitPulse,
POLPULSE_STATE_Postcalcs,
POLPULSE_STATE_PostcalcsComplete,
} POLPULSE_State_e;
typedef struct _POLPULSE_Params_
{
float_t VoltageScale;
float_t Ts;
float_t Lsd;
float_t PulseCurrentGoal_A;
uint16_t N; /* Number of pulse-periods */
uint16_t Nd; /* Number of decay-periods */
uint16_t N_Angles; /* Number of directions to pulse in */
} POLPULSE_Params;
typedef struct _POLPULSE_Angles_
{
/* Planned pulse angle, in per-unit and cos/sin */
FIXP_CosSin_t Phasor;
fixp30_t PulseAngle;
} POLPULSE_Angles;
typedef struct _POLPULSE_Data_
{
/* Sampled data */
Currents_Iab_t IabSample; /* Iab at end of pulse */
} POLPULSE_Data;
#define POLPULSE_SIZE_WORDS (120) /* Size in words, plus a margin */
typedef struct _POLPULSE_Obj_
{
/* Contents of this structure is not public */
uint16_t reserved[POLPULSE_SIZE_WORDS];
} POLPULSE_Obj;
typedef POLPULSE_Obj* POLPULSE_Handle;
/* Initialization */
POLPULSE_Handle POLPULSE_init(void *pMemory, const size_t size);
void POLPULSE_setParams(POLPULSE_Obj *obj, const POLPULSE_Params *pParams);
/* Functional */
void POLPULSE_run(POLPULSE_Obj *obj, const Currents_Iab_t *pIab_pu, const Voltages_Uab_t *pUab_pu, const fixp30_t angle);
void POLPULSE_runBackground(POLPULSE_Obj *obj, const fixp_t oneoverUdc_pu, const fixp30_t Udc_pu);
void POLPULSE_clearTriggerPulse(POLPULSE_Obj *obj);
bool POLPULSE_isBusy(POLPULSE_Obj *obj);
void POLPULSE_resetState(POLPULSE_Obj *obj);
void POLPULSE_stopPulse(POLPULSE_Obj *obj);
void POLPULSE_trigger(POLPULSE_Obj *obj);
/* Accessors */
fixp30_t POLPULSE_getAngleEstimated(const POLPULSE_Obj *obj);
float_t POLPULSE_getCurrentGoal(const POLPULSE_Obj *obj);
uint16_t POLPULSE_getDecayPeriods(const POLPULSE_Obj *obj);
Duty_Dab_t POLPULSE_getDutyAB(const POLPULSE_Obj *obj);
uint16_t POLPULSE_getNumAngles(const POLPULSE_Obj *obj);
bool POLPULSE_getOverruleDuty(const POLPULSE_Obj *obj);
fixp30_t POLPULSE_getPulseDuty(const POLPULSE_Obj *obj);
uint16_t POLPULSE_getPulsePeriods(const POLPULSE_Obj *obj);
POLPULSE_State_e POLPULSE_getState(const POLPULSE_Obj *obj);
bool POLPULSE_getTriggerPulse(const POLPULSE_Obj *obj);
void POLPULSE_setCurrentGoal(POLPULSE_Obj *obj, const float_t currentgoal);
void POLPULSE_setDecayPeriods(POLPULSE_Obj *obj, const uint16_t periods);
void POLPULSE_setLsd(POLPULSE_Obj *obj, const float_t Lsd);
void POLPULSE_setNumAngles(POLPULSE_Obj *obj, const uint16_t angles);
void POLPULSE_setPulseDone(POLPULSE_Obj *obj);
void POLPULSE_setPulsePeriods(POLPULSE_Obj *obj, const uint16_t periods);
#endif /* _POLPULSE_H_ */
/* end of polpulse.h */
| 3,156 | C | 31.546391 | 121 | 0.688847 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mc_tasks.c |
/**
******************************************************************************
* @file mc_tasks.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file implements tasks definition
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
//cstat -MISRAC2012-Rule-21.1
#include "main.h"
//cstat +MISRAC2012-Rule-21.1
#include "mc_type.h"
#include "mc_math.h"
#include "motorcontrol.h"
#include "regular_conversion_manager.h"
#include "mc_interface.h"
#include "digital_output.h"
#include "pwm_common.h"
#include "mc_tasks.h"
#include "parameters_conversion.h"
#include "mcp_config.h"
#include "mc_app_hooks.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private define */
/* Private define ------------------------------------------------------------*/
/* Un-Comment this macro define in order to activate the smooth
braking action on over voltage */
/* #define MC.SMOOTH_BRAKING_ACTION_ON_OVERVOLTAGE */
#define STOPPERMANENCY_MS ((uint16_t)400)
#define STOPPERMANENCY_MS2 ((uint16_t)400)
#define STOPPERMANENCY_TICKS (uint16_t)((SYS_TICK_FREQUENCY * STOPPERMANENCY_MS) / ((uint16_t)1000))
#define STOPPERMANENCY_TICKS2 (uint16_t)((SYS_TICK_FREQUENCY * STOPPERMANENCY_MS2) / ((uint16_t)1000))
/* USER CODE END Private define */
#define VBUS_TEMP_ERR_MASK ~(0 | 0 | MC_OVER_TEMP)
/* Private variables----------------------------------------------------------*/
static FOCVars_t FOCVars[NBR_OF_MOTORS];
static EncAlign_Handle_t *pEAC[NBR_OF_MOTORS];
static PWMC_Handle_t *pwmcHandle[NBR_OF_MOTORS];
//cstat !MISRAC2012-Rule-8.9_a
static RampExtMngr_Handle_t *pREMNG[NBR_OF_MOTORS]; /*!< Ramp manager used to modify the Iq ref
during the start-up switch over. */
static uint16_t hMFTaskCounterM1 = 0; //cstat !MISRAC2012-Rule-8.9_a
static volatile uint16_t hBootCapDelayCounterM1 = ((uint16_t)0);
static volatile uint16_t hStopPermanencyCounterM1 = ((uint16_t)0);
static volatile uint8_t bMCBootCompleted = ((uint8_t)0);
#define M1_CHARGE_BOOT_CAP_TICKS (((uint16_t)SYS_TICK_FREQUENCY * (uint16_t)10) / 1000U)
#define M1_CHARGE_BOOT_CAP_DUTY_CYCLES ((uint32_t)0.000\
* ((uint32_t)PWM_PERIOD_CYCLES / 2U))
#define M2_CHARGE_BOOT_CAP_TICKS (((uint16_t)SYS_TICK_FREQUENCY * (uint16_t)10) / 1000U)
#define M2_CHARGE_BOOT_CAP_DUTY_CYCLES ((uint32_t)0\
* ((uint32_t)PWM_PERIOD_CYCLES2 / 2U))
/* USER CODE BEGIN Private Variables */
/* USER CODE END Private Variables */
/* Private functions ---------------------------------------------------------*/
void TSK_MediumFrequencyTaskM1(void);
void FOC_Clear(uint8_t bMotor);
void FOC_InitAdditionalMethods(uint8_t bMotor);
void FOC_CalcCurrRef(uint8_t bMotor);
void TSK_MF_StopProcessing(uint8_t motor);
MCI_Handle_t *GetMCI(uint8_t bMotor);
static uint16_t FOC_CurrControllerM1(void);
void TSK_SetChargeBootCapDelayM1(uint16_t hTickCount);
bool TSK_ChargeBootCapDelayHasElapsedM1(void);
void TSK_SetStopPermanencyTimeM1(uint16_t hTickCount);
bool TSK_StopPermanencyTimeHasElapsedM1(void);
void TSK_SafetyTask_PWMOFF(uint8_t motor);
/* USER CODE BEGIN Private Functions */
/* USER CODE END Private Functions */
/**
* @brief It initializes the whole MC core according to user defined
* parameters.
* @param pMCIList pointer to the vector of MCInterface objects that will be
* created and initialized. The vector must have length equal to the
* number of motor drives.
*/
__weak void MCboot( MCI_Handle_t* pMCIList[NBR_OF_MOTORS] )
{
/* USER CODE BEGIN MCboot 0 */
/* USER CODE END MCboot 0 */
if (MC_NULL == pMCIList)
{
/* Nothing to do */
}
else
{
bMCBootCompleted = (uint8_t )0;
/**********************************************************/
/* PWM and current sensing component initialization */
/**********************************************************/
pwmcHandle[M1] = &PWM_Handle_M1._Super;
R3_1_Init(&PWM_Handle_M1);
ASPEP_start(&aspepOverUartA);
/* USER CODE BEGIN MCboot 1 */
/* USER CODE END MCboot 1 */
/**************************************/
/* Start timers synchronously */
/**************************************/
startTimers();
/******************************************************/
/* PID component initialization: speed regulation */
/******************************************************/
PID_HandleInit(&PIDSpeedHandle_M1);
/******************************************************/
/* Main speed sensor component initialization */
/******************************************************/
ENC_Init (&ENCODER_M1);
/******************************************************/
/* Main encoder alignment component initialization */
/******************************************************/
EAC_Init(&EncAlignCtrlM1,pSTC[M1],&VirtualSpeedSensorM1,&ENCODER_M1);
pEAC[M1] = &EncAlignCtrlM1;
/******************************************************/
/* Speed & torque component initialization */
/******************************************************/
STC_Init(pSTC[M1],&PIDSpeedHandle_M1, &ENCODER_M1._Super);
/******************************************************/
/* Auxiliary speed sensor component initialization */
/******************************************************/
STO_PLL_Init (&STO_PLL_M1);
/****************************************************/
/* Virtual speed sensor component initialization */
/****************************************************/
VSS_Init(&VirtualSpeedSensorM1);
/********************************************************/
/* PID component initialization: current regulation */
/********************************************************/
PID_HandleInit(&PIDIqHandle_M1);
PID_HandleInit(&PIDIdHandle_M1);
/********************************************************/
/* Bus voltage sensor component initialization */
/********************************************************/
(void)RCM_RegisterRegConv(&VbusRegConv_M1);
RVBS_Init(&BusVoltageSensor_M1);
/*************************************************/
/* Power measurement component initialization */
/*************************************************/
pMPM[M1]->pVBS = &(BusVoltageSensor_M1._Super);
pMPM[M1]->pFOCVars = &FOCVars[M1];
/*******************************************************/
/* Temperature measurement component initialization */
/*******************************************************/
NTC_Init(&TempSensor_M1);
pREMNG[M1] = &RampExtMngrHFParamsM1;
REMNG_Init(pREMNG[M1]);
FOC_Clear(M1);
FOCVars[M1].bDriveInput = EXTERNAL;
FOCVars[M1].Iqdref = STC_GetDefaultIqdref(pSTC[M1]);
FOCVars[M1].UserIdref = STC_GetDefaultIqdref(pSTC[M1]).d;
MCI_Init(&Mci[M1], pSTC[M1], &FOCVars[M1],pwmcHandle[M1] );
Mci[M1].pScale = &scaleParams_M1;
MCI_ExecSpeedRamp(&Mci[M1],
STC_GetMecSpeedRefUnitDefault(pSTC[M1]),0); /* First command to STC */
pMCIList[M1] = &Mci[M1];
/* Applicative hook in MCBoot() */
MC_APP_BootHook();
/* USER CODE BEGIN MCboot 2 */
/* USER CODE END MCboot 2 */
bMCBootCompleted = 1U;
}
}
/**
* @brief Runs all the Tasks of the Motor Control cockpit
*
* This function is to be called periodically at least at the Medium Frequency task
* rate (It is typically called on the Systick interrupt). Exact invokation rate is
* the Speed regulator execution rate set in the Motor Contorl Workbench.
*
* The following tasks are executed in this order:
*
* - Medium Frequency Tasks of each motors.
* - Safety Task.
* - Power Factor Correction Task (if enabled).
* - User Interface task.
*/
__weak void MC_RunMotorControlTasks(void)
{
if (0U == bMCBootCompleted)
{
/* Nothing to do */
}
else
{
/* ** Medium Frequency Tasks ** */
MC_Scheduler();
/* Safety task is run after Medium Frequency task so that
* it can overcome actions they initiated if needed */
TSK_SafetyTask();
}
}
/**
* @brief Performs stop process and update the state machine.This function
* shall be called only during medium frequency task.
*/
void TSK_MF_StopProcessing(uint8_t motor)
{
R3_1_SwitchOffPWM(pwmcHandle[motor]);
FOC_Clear(motor);
PQD_Clear(pMPM[motor]);
TSK_SetStopPermanencyTimeM1(STOPPERMANENCY_TICKS);
Mci[motor].State = STOP;
}
/**
* @brief Executes the Medium Frequency Task functions for each drive instance.
*
* It is to be clocked at the Systick frequency.
*/
__weak void MC_Scheduler(void)
{
/* USER CODE BEGIN MC_Scheduler 0 */
/* USER CODE END MC_Scheduler 0 */
if (((uint8_t)1) == bMCBootCompleted)
{
if(hMFTaskCounterM1 > 0u)
{
hMFTaskCounterM1--;
}
else
{
TSK_MediumFrequencyTaskM1();
/* Applicative hook at end of Medium Frequency for Motor 1 */
MC_APP_PostMediumFrequencyHook_M1();
MCP_Over_UartA.rxBuffer = MCP_Over_UartA.pTransportLayer->fRXPacketProcess(MCP_Over_UartA.pTransportLayer,
&MCP_Over_UartA.rxLength);
if ( 0U == MCP_Over_UartA.rxBuffer)
{
/* Nothing to do */
}
else
{
/* Synchronous answer */
if (0U == MCP_Over_UartA.pTransportLayer->fGetBuffer(MCP_Over_UartA.pTransportLayer,
(void **) &MCP_Over_UartA.txBuffer, //cstat !MISRAC2012-Rule-11.3
MCTL_SYNC))
{
/* No buffer available to build the answer ... should not occur */
}
else
{
MCP_ReceivedPacket(&MCP_Over_UartA);
MCP_Over_UartA.pTransportLayer->fSendPacket(MCP_Over_UartA.pTransportLayer, MCP_Over_UartA.txBuffer,
MCP_Over_UartA.txLength, MCTL_SYNC);
/* No buffer available to build the answer ... should not occur */
}
}
/* USER CODE BEGIN MC_Scheduler 1 */
/* USER CODE END MC_Scheduler 1 */
hMFTaskCounterM1 = (uint16_t)MF_TASK_OCCURENCE_TICKS;
}
if(hBootCapDelayCounterM1 > 0U)
{
hBootCapDelayCounterM1--;
}
else
{
/* Nothing to do */
}
if(hStopPermanencyCounterM1 > 0U)
{
hStopPermanencyCounterM1--;
}
else
{
/* Nothing to do */
}
}
else
{
/* Nothing to do */
}
/* USER CODE BEGIN MC_Scheduler 2 */
/* USER CODE END MC_Scheduler 2 */
}
/**
* @brief Executes medium frequency periodic Motor Control tasks
*
* This function performs some of the control duties on Motor 1 according to the
* present state of its state machine. In particular, duties requiring a periodic
* execution at a medium frequency rate (such as the speed controller for instance)
* are executed here.
*/
__weak void TSK_MediumFrequencyTaskM1(void)
{
/* USER CODE BEGIN MediumFrequencyTask M1 0 */
/* USER CODE END MediumFrequencyTask M1 0 */
int16_t wAux = 0;
(void)STO_PLL_CalcAvrgMecSpeedUnit(&STO_PLL_M1, &wAux);
(void)ENC_CalcAvrgMecSpeedUnit(&ENCODER_M1, &wAux);
PQD_CalcElMotorPower(pMPM[M1]);
if (MCI_GetCurrentFaults(&Mci[M1]) == MC_NO_FAULTS)
{
if (MCI_GetOccurredFaults(&Mci[M1]) == MC_NO_FAULTS)
{
switch (Mci[M1].State)
{
case IDLE:
{
if ((MCI_START == Mci[M1].DirectCommand) || (MCI_MEASURE_OFFSETS == Mci[M1].DirectCommand))
{
if (pwmcHandle[M1]->offsetCalibStatus == false)
{
(void)PWMC_CurrentReadingCalibr(pwmcHandle[M1], CRC_START);
Mci[M1].State = OFFSET_CALIB;
}
else
{
/* Calibration already done. Enables only TIM channels */
pwmcHandle[M1]->OffCalibrWaitTimeCounter = 1u;
(void)PWMC_CurrentReadingCalibr(pwmcHandle[M1], CRC_EXEC);
R3_1_TurnOnLowSides(pwmcHandle[M1],M1_CHARGE_BOOT_CAP_DUTY_CYCLES);
TSK_SetChargeBootCapDelayM1(M1_CHARGE_BOOT_CAP_TICKS);
Mci[M1].State = CHARGE_BOOT_CAP;
}
}
else
{
/* Nothing to be done, FW stays in IDLE state */
}
break;
}
case OFFSET_CALIB:
{
if (MCI_STOP == Mci[M1].DirectCommand)
{
TSK_MF_StopProcessing(M1);
}
else
{
if (PWMC_CurrentReadingCalibr(pwmcHandle[M1], CRC_EXEC))
{
if (MCI_MEASURE_OFFSETS == Mci[M1].DirectCommand)
{
FOC_Clear(M1);
PQD_Clear(pMPM[M1]);
Mci[M1].DirectCommand = MCI_NO_COMMAND;
Mci[M1].State = IDLE;
}
else
{
R3_1_TurnOnLowSides(pwmcHandle[M1],M1_CHARGE_BOOT_CAP_DUTY_CYCLES);
TSK_SetChargeBootCapDelayM1(M1_CHARGE_BOOT_CAP_TICKS);
Mci[M1].State = CHARGE_BOOT_CAP;
}
}
else
{
/* Nothing to be done, FW waits for offset calibration to finish */
}
}
break;
}
case CHARGE_BOOT_CAP:
{
if (MCI_STOP == Mci[M1].DirectCommand)
{
TSK_MF_StopProcessing(M1);
}
else
{
if (TSK_ChargeBootCapDelayHasElapsedM1())
{
R3_1_SwitchOffPWM(pwmcHandle[M1]);
FOCVars[M1].bDriveInput = EXTERNAL;
STC_SetSpeedSensor( pSTC[M1], &VirtualSpeedSensorM1._Super );
ENC_Clear(&ENCODER_M1);
STO_PLL_Clear(&STO_PLL_M1);
FOC_Clear( M1 );
if (EAC_IsAligned(&EncAlignCtrlM1) == false)
{
EAC_StartAlignment(&EncAlignCtrlM1);
Mci[M1].State = ALIGNMENT;
}
else
{
STC_SetControlMode(pSTC[M1], MCM_SPEED_MODE);
STC_SetSpeedSensor(pSTC[M1], &ENCODER_M1._Super);
FOC_InitAdditionalMethods(M1);
FOC_CalcCurrRef(M1);
STC_ForceSpeedReferenceToCurrentSpeed(pSTC[M1]); /* Init the reference speed to current speed */
MCI_ExecBufferedCommands(&Mci[M1]); /* Exec the speed ramp after changing of the speed sensor */
Mci[M1].State = RUN;
}
PWMC_SwitchOnPWM(pwmcHandle[M1]);
}
else
{
/* Nothing to be done, FW waits for bootstrap capacitor to charge */
}
}
break;
}
case ALIGNMENT:
{
if (MCI_STOP == Mci[M1].DirectCommand)
{
TSK_MF_StopProcessing(M1);
}
else
{
bool isAligned = EAC_IsAligned(&EncAlignCtrlM1);
bool EACDone = EAC_Exec(&EncAlignCtrlM1);
if ((isAligned == false) && (EACDone == false))
{
qd_t IqdRef;
IqdRef.q = 0;
IqdRef.d = STC_CalcTorqueReference(pSTC[M1]);
FOCVars[M1].Iqdref = IqdRef;
}
else
{
R3_1_SwitchOffPWM( pwmcHandle[M1] );
STC_SetControlMode(pSTC[M1], MCM_SPEED_MODE);
STC_SetSpeedSensor(pSTC[M1], &ENCODER_M1._Super);
FOC_Clear(M1);
R3_1_TurnOnLowSides(pwmcHandle[M1],M1_CHARGE_BOOT_CAP_DUTY_CYCLES);
TSK_SetStopPermanencyTimeM1(STOPPERMANENCY_TICKS);
Mci[M1].State = WAIT_STOP_MOTOR;
/* USER CODE BEGIN MediumFrequencyTask M1 EndOfEncAlignment */
/* USER CODE END MediumFrequencyTask M1 EndOfEncAlignment */
}
}
break;
}
case RUN:
{
if (MCI_STOP == Mci[M1].DirectCommand)
{
TSK_MF_StopProcessing(M1);
}
else
{
/* USER CODE BEGIN MediumFrequencyTask M1 2 */
/* USER CODE END MediumFrequencyTask M1 2 */
MCI_ExecBufferedCommands(&Mci[M1]);
FOC_CalcCurrRef(M1);
}
break;
}
case STOP:
{
if (TSK_StopPermanencyTimeHasElapsedM1())
{
/* USER CODE BEGIN MediumFrequencyTask M1 5 */
/* USER CODE END MediumFrequencyTask M1 5 */
Mci[M1].DirectCommand = MCI_NO_COMMAND;
Mci[M1].State = IDLE;
}
else
{
/* Nothing to do, FW waits for to stop */
}
break;
}
case FAULT_OVER:
{
if (MCI_ACK_FAULTS == Mci[M1].DirectCommand)
{
Mci[M1].DirectCommand = MCI_NO_COMMAND;
Mci[M1].State = IDLE;
}
else
{
/* Nothing to do, FW stays in FAULT_OVER state until acknowledgement */
}
break;
}
case FAULT_NOW:
{
Mci[M1].State = FAULT_OVER;
break;
}
case WAIT_STOP_MOTOR:
{
if (MCI_STOP == Mci[M1].DirectCommand)
{
TSK_MF_StopProcessing(M1);
}
else
{
if (TSK_StopPermanencyTimeHasElapsedM1())
{
ENC_Clear(&ENCODER_M1);
R3_1_SwitchOnPWM(pwmcHandle[M1]);
FOC_InitAdditionalMethods(M1);
STC_ForceSpeedReferenceToCurrentSpeed(pSTC[M1]); /* Init the reference speed to current speed */
MCI_ExecBufferedCommands(&Mci[M1]); /* Exec the speed ramp after changing of the speed sensor */
FOC_CalcCurrRef(M1);
Mci[M1].State = RUN;
}
else
{
/* Nothing to do */
}
}
break;
}
default:
break;
}
}
else
{
Mci[M1].State = FAULT_OVER;
}
}
else
{
Mci[M1].State = FAULT_NOW;
}
/* USER CODE BEGIN MediumFrequencyTask M1 6 */
/* USER CODE END MediumFrequencyTask M1 6 */
}
/**
* @brief It re-initializes the current and voltage variables. Moreover
* it clears qd currents PI controllers, voltage sensor and SpeednTorque
* controller. It must be called before each motor restart.
* It does not clear speed sensor.
* @param bMotor related motor it can be M1 or M2.
*/
__weak void FOC_Clear(uint8_t bMotor)
{
/* USER CODE BEGIN FOC_Clear 0 */
/* USER CODE END FOC_Clear 0 */
ab_t NULL_ab = {((int16_t)0), ((int16_t)0)};
qd_t NULL_qd = {((int16_t)0), ((int16_t)0)};
alphabeta_t NULL_alphabeta = {((int16_t)0), ((int16_t)0)};
FOCVars[bMotor].Iab = NULL_ab;
FOCVars[bMotor].Ialphabeta = NULL_alphabeta;
FOCVars[bMotor].Iqd = NULL_qd;
FOCVars[bMotor].Iqdref = NULL_qd;
FOCVars[bMotor].hTeref = (int16_t)0;
FOCVars[bMotor].Vqd = NULL_qd;
FOCVars[bMotor].Valphabeta = NULL_alphabeta;
FOCVars[bMotor].hElAngle = (int16_t)0;
PID_SetIntegralTerm(pPIDIq[bMotor], ((int32_t)0));
PID_SetIntegralTerm(pPIDId[bMotor], ((int32_t)0));
STC_Clear(pSTC[bMotor]);
PWMC_SwitchOffPWM(pwmcHandle[bMotor]);
/* USER CODE BEGIN FOC_Clear 1 */
/* USER CODE END FOC_Clear 1 */
}
/**
* @brief Use this method to initialize additional methods (if any) in
* START_TO_RUN state.
* @param bMotor related motor it can be M1 or M2.
*/
__weak void FOC_InitAdditionalMethods(uint8_t bMotor) //cstat !RED-func-no-effect
{
if (M_NONE == bMotor)
{
/* Nothing to do */
}
else
{
/* USER CODE BEGIN FOC_InitAdditionalMethods 0 */
/* USER CODE END FOC_InitAdditionalMethods 0 */
}
}
/**
* @brief It computes the new values of Iqdref (current references on qd
* reference frame) based on the required electrical torque information
* provided by oTSC object (internally clocked).
* If implemented in the derived class it executes flux weakening and/or
* MTPA algorithm(s). It must be called with the periodicity specified
* in oTSC parameters.
* @param bMotor related motor it can be M1 or M2.
*/
__weak void FOC_CalcCurrRef(uint8_t bMotor)
{
/* USER CODE BEGIN FOC_CalcCurrRef 0 */
/* USER CODE END FOC_CalcCurrRef 0 */
if (INTERNAL == FOCVars[bMotor].bDriveInput)
{
FOCVars[bMotor].hTeref = STC_CalcTorqueReference(pSTC[bMotor]);
FOCVars[bMotor].Iqdref.q = FOCVars[bMotor].hTeref;
}
else
{
/* Nothing to do */
}
/* USER CODE BEGIN FOC_CalcCurrRef 1 */
/* USER CODE END FOC_CalcCurrRef 1 */
}
/**
* @brief It set a counter intended to be used for counting the delay required
* for drivers boot capacitors charging of motor 1.
* @param hTickCount number of ticks to be counted.
* @retval void
*/
__weak void TSK_SetChargeBootCapDelayM1(uint16_t hTickCount)
{
hBootCapDelayCounterM1 = hTickCount;
}
/**
* @brief Use this function to know whether the time required to charge boot
* capacitors of motor 1 has elapsed.
* @param none
* @retval bool true if time has elapsed, false otherwise.
*/
__weak bool TSK_ChargeBootCapDelayHasElapsedM1(void)
{
bool retVal = false;
if (((uint16_t)0) == hBootCapDelayCounterM1)
{
retVal = true;
}
return (retVal);
}
/**
* @brief It set a counter intended to be used for counting the permanency
* time in STOP state of motor 1.
* @param hTickCount number of ticks to be counted.
* @retval void
*/
__weak void TSK_SetStopPermanencyTimeM1(uint16_t hTickCount)
{
hStopPermanencyCounterM1 = hTickCount;
}
/**
* @brief Use this function to know whether the permanency time in STOP state
* of motor 1 has elapsed.
* @param none
* @retval bool true if time is elapsed, false otherwise.
*/
__weak bool TSK_StopPermanencyTimeHasElapsedM1(void)
{
bool retVal = false;
if (((uint16_t)0) == hStopPermanencyCounterM1)
{
retVal = true;
}
return (retVal);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section (".ccmram")))
#endif
#endif
/**
* @brief Executes the Motor Control duties that require a high frequency rate and a precise timing.
*
* This is mainly the FOC current control loop. It is executed depending on the state of the Motor Control
* subsystem (see the state machine(s)).
*
* @retval Number of the motor instance which FOC loop was executed.
*/
__weak uint8_t TSK_HighFrequencyTask(void)
{
uint16_t hFOCreturn;
uint8_t bMotorNbr = 0;
/* USER CODE BEGIN HighFrequencyTask 0 */
/* USER CODE END HighFrequencyTask 0 */
Observer_Inputs_t STO_aux_Inputs; /* Only if sensorless aux */
STO_aux_Inputs.Valfa_beta = FOCVars[M1].Valphabeta; /* Only if sensorless */
(void)ENC_CalcAngle(&ENCODER_M1); /* If not sensorless then 2nd parameter is MC_NULL */
/* USER CODE BEGIN HighFrequencyTask SINGLEDRIVE_1 */
/* USER CODE END HighFrequencyTask SINGLEDRIVE_1 */
hFOCreturn = FOC_CurrControllerM1();
/* USER CODE BEGIN HighFrequencyTask SINGLEDRIVE_2 */
/* USER CODE END HighFrequencyTask SINGLEDRIVE_2 */
if(hFOCreturn == MC_DURATION)
{
MCI_FaultProcessing(&Mci[M1], MC_DURATION, 0);
}
else
{
STO_aux_Inputs.Ialfa_beta = FOCVars[M1].Ialphabeta; /* Only if sensorless */
STO_aux_Inputs.Vbus = VBS_GetAvBusVoltage_d(&(BusVoltageSensor_M1._Super)); /* Only for sensorless */
(void)( void )STO_PLL_CalcElAngle (&STO_PLL_M1, &STO_aux_Inputs);
STO_PLL_CalcAvrgElSpeedDpp (&STO_PLL_M1);
/* USER CODE BEGIN HighFrequencyTask SINGLEDRIVE_3 */
/* USER CODE END HighFrequencyTask SINGLEDRIVE_3 */
}
/* USER CODE BEGIN HighFrequencyTask 1 */
/* USER CODE END HighFrequencyTask 1 */
GLOBAL_TIMESTAMP++;
if (0U == MCPA_UART_A.Mark)
{
/* Nothing to do */
}
else
{
MCPA_dataLog (&MCPA_UART_A);
}
return (bMotorNbr);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section (".ccmram")))
#endif
#endif
/**
* @brief It executes the core of FOC drive that is the controllers for Iqd
* currents regulation. Reference frame transformations are carried out
* accordingly to the active speed sensor. It must be called periodically
* when new motor currents have been converted
* @param this related object of class CFOC.
* @retval int16_t It returns MC_NO_FAULTS if the FOC has been ended before
* next PWM Update event, MC_DURATION otherwise
*/
inline uint16_t FOC_CurrControllerM1(void)
{
qd_t Iqd, Vqd;
ab_t Iab;
alphabeta_t Ialphabeta, Valphabeta;
int16_t hElAngle;
uint16_t hCodeError;
SpeednPosFdbk_Handle_t *speedHandle;
speedHandle = STC_GetSpeedSensor(pSTC[M1]);
hElAngle = SPD_GetElAngle(speedHandle);
PWMC_GetPhaseCurrents(pwmcHandle[M1], &Iab);
RCM_ReadOngoingConv();
RCM_ExecNextConv();
Ialphabeta = MCM_Clarke(Iab);
Iqd = MCM_Park(Ialphabeta, hElAngle);
Vqd.q = PI_Controller(pPIDIq[M1], (int32_t)(FOCVars[M1].Iqdref.q) - Iqd.q);
Vqd.d = PI_Controller(pPIDId[M1], (int32_t)(FOCVars[M1].Iqdref.d) - Iqd.d);
Vqd = Circle_Limitation(&CircleLimitationM1, Vqd);
hElAngle += SPD_GetInstElSpeedDpp(speedHandle)*REV_PARK_ANGLE_COMPENSATION_FACTOR;
Valphabeta = MCM_Rev_Park(Vqd, hElAngle);
hCodeError = PWMC_SetPhaseVoltage(pwmcHandle[M1], Valphabeta);
FOCVars[M1].Vqd = Vqd;
FOCVars[M1].Iab = Iab;
FOCVars[M1].Ialphabeta = Ialphabeta;
FOCVars[M1].Iqd = Iqd;
FOCVars[M1].Valphabeta = Valphabeta;
FOCVars[M1].hElAngle = hElAngle;
return (hCodeError);
}
/**
* @brief Executes safety checks (e.g. bus voltage and temperature) for all drive instances.
*
* Faults flags are updated here.
*/
__weak void TSK_SafetyTask(void)
{
/* USER CODE BEGIN TSK_SafetyTask 0 */
/* USER CODE END TSK_SafetyTask 0 */
if (1U == bMCBootCompleted)
{
TSK_SafetyTask_PWMOFF(M1);
/* User conversion execution */
RCM_ExecUserConv();
/* USER CODE BEGIN TSK_SafetyTask 1 */
/* USER CODE END TSK_SafetyTask 1 */
}
else
{
/* Nothing to do */
}
}
/**
* @brief Safety task implementation if MC.M1_ON_OVER_VOLTAGE == TURN_OFF_PWM.
* @param bMotor Motor reference number defined
* \link Motors_reference_number here \endlink.
*/
__weak void TSK_SafetyTask_PWMOFF(uint8_t bMotor)
{
/* USER CODE BEGIN TSK_SafetyTask_PWMOFF 0 */
/* USER CODE END TSK_SafetyTask_PWMOFF 0 */
uint16_t CodeReturn = MC_NO_ERROR;
const uint16_t errMask[NBR_OF_MOTORS] = {VBUS_TEMP_ERR_MASK};
/* Check for fault if FW protection is activated. It returns MC_OVER_TEMP or MC_NO_ERROR */
CodeReturn |= PWMC_IsFaultOccurred(pwmcHandle[bMotor]); /* check for fault. It return MC_OVER_CURR or MC_NO_FAULTS
(for STM32F30x can return MC_OVER_VOLT in case of HW Overvoltage) */
if (M1 == bMotor)
{
uint16_t rawValueM1 = RCM_ExecRegularConv(&VbusRegConv_M1);
CodeReturn |= errMask[bMotor] & RVBS_CalcAvVbus(&BusVoltageSensor_M1, rawValueM1);
}
else
{
/* Nothing to do */
}
MCI_FaultProcessing(&Mci[bMotor], CodeReturn, ~CodeReturn); /* Process faults */
if (MCI_GetFaultState(&Mci[bMotor]) != (uint32_t)MC_NO_FAULTS)
{
/* Reset Encoder state */
if (pEAC[bMotor] != MC_NULL)
{
EAC_SetRestartState(pEAC[bMotor], false);
}
else
{
/* Nothing to do */
}
PWMC_SwitchOffPWM(pwmcHandle[bMotor]);
if (MCPA_UART_A.Mark != 0U)
{
MCPA_flushDataLog (&MCPA_UART_A);
}
else
{
/* Nothing to do */
}
FOC_Clear(bMotor);
PQD_Clear(pMPM[bMotor]); //cstat !MISRAC2012-Rule-11.3
/* USER CODE BEGIN TSK_SafetyTask_PWMOFF 1 */
/* USER CODE END TSK_SafetyTask_PWMOFF 1 */
}
else
{
/* No errors */
}
/* USER CODE BEGIN TSK_SafetyTask_PWMOFF 3 */
/* USER CODE END TSK_SafetyTask_PWMOFF 3 */
}
/**
* @brief This function returns the reference of the MCInterface relative to
* the selected drive.
* @param bMotor Motor reference number defined
* \link Motors_reference_number here \endlink.
* @retval MCI_Handle_t * Reference to MCInterface relative to the selected drive.
* Note: it can be MC_NULL if MCInterface of selected drive is not
* allocated.
*/
__weak MCI_Handle_t *GetMCI(uint8_t bMotor)
{
MCI_Handle_t *retVal = MC_NULL; //cstat !MISRAC2012-Rule-8.13
if (bMotor < (uint8_t)NBR_OF_MOTORS)
{
retVal = &Mci[bMotor];
}
else
{
/* Nothing to do */
}
return (retVal);
}
/**
* @brief Puts the Motor Control subsystem in in safety conditions on a Hard Fault
*
* This function is to be executed when a general hardware failure has been detected
* by the microcontroller and is used to put the system in safety condition.
*/
__weak void TSK_HardwareFaultTask(void)
{
/* USER CODE BEGIN TSK_HardwareFaultTask 0 */
/* USER CODE END TSK_HardwareFaultTask 0 */
R3_1_SwitchOffPWM(pwmcHandle[M1]);
MCI_FaultProcessing(&Mci[M1], MC_SW_ERROR, 0);
/* USER CODE BEGIN TSK_HardwareFaultTask 1 */
/* USER CODE END TSK_HardwareFaultTask 1 */
}
__weak void UI_HandleStartStopButton_cb (void)
{
/* USER CODE BEGIN START_STOP_BTN */
if (IDLE == MC_GetSTMStateMotor1())
{
/* Ramp parameters should be tuned for the actual motor */
(void)MC_StartMotor1();
}
else
{
(void)MC_StopMotor1();
}
/* USER CODE END START_STOP_BTN */
}
/**
* @brief Locks GPIO pins used for Motor Control to prevent accidental reconfiguration.
*/
__weak void mc_lock_pins (void)
{
LL_GPIO_LockPin(M1_CURR_AMPL_V_GPIO_Port, M1_CURR_AMPL_V_Pin);
LL_GPIO_LockPin(M1_CURR_AMPL_W_GPIO_Port, M1_CURR_AMPL_W_Pin);
LL_GPIO_LockPin(M1_BUS_VOLTAGE_GPIO_Port, M1_BUS_VOLTAGE_Pin);
LL_GPIO_LockPin(M1_CURR_AMPL_U_GPIO_Port, M1_CURR_AMPL_U_Pin);
LL_GPIO_LockPin(M1_ENCODER_A_GPIO_Port, M1_ENCODER_A_Pin);
LL_GPIO_LockPin(M1_ENCODER_B_GPIO_Port, M1_ENCODER_B_Pin);
LL_GPIO_LockPin(M1_PWM_UH_GPIO_Port, M1_PWM_UH_Pin);
LL_GPIO_LockPin(M1_PWM_VH_GPIO_Port, M1_PWM_VH_Pin);
LL_GPIO_LockPin(M1_PWM_VL_GPIO_Port, M1_PWM_VL_Pin);
LL_GPIO_LockPin(M1_PWM_WH_GPIO_Port, M1_PWM_WH_Pin);
LL_GPIO_LockPin(M1_PWM_WL_GPIO_Port, M1_PWM_WL_Pin);
LL_GPIO_LockPin(M1_PWM_UL_GPIO_Port, M1_PWM_UL_Pin);
}
/* USER CODE BEGIN mc_task 0 */
/* USER CODE END mc_task 0 */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 31,549 | C | 29.720545 | 120 | 0.573933 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/aspep.c |
/**
******************************************************************************
* @file aspep.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the aspep protocol
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#include <stdint.h>
#include "aspep.h"
/* Local definition */
#define MIN(a,b) ( ((a) < (b)) ? (a) : (b) )
/* Local functions */
static bool ASPEP_CheckBeacon (ASPEP_Handle_t *pHandle);
static uint8_t ASPEP_TXframeProcess(ASPEP_Handle_t *pHandle, uint8_t packetType, void *txBuffer, uint16_t bufferLength);
void ASPEP_sendBeacon(ASPEP_Handle_t *pHandle, ASPEP_Capabilities_def *capabilities);
void ASPEP_sendPing(ASPEP_Handle_t *pHandle, uint8_t state, uint16_t PacketNumber);
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MCP
* @{
*/
#ifndef CRC4_PER_NIBBLE
/**
* @brief CRC-4 lookup table with 256 entries
*
* Computes and checks the CRC on the header with the BYTE granularity.
*
* When computing the CRC, the 7th nibble must to be processed with the CRC_Lookup4
* table. Indeed, the header contains 7 nibbles (28 bits) of data on which the CRC is
* to be computed. Hence, the CRC4_Lookup8 table cannot be used for the last nibble.
*
* Using only this lookup table requires that the amount of input data is a multiple of
* 8 bits.
*/
static uint8_t const CRC4_Lookup8[] =
{
/* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F */
/* 0 */ 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x07, 0x05, 0x03, 0x01, 0x0f, 0x0d, 0x0b, 0x09,
/* 1 */ 0x07, 0x05, 0x03, 0x01, 0x0f, 0x0d, 0x0b, 0x09, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
/* 2 */ 0x0e, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x00, 0x09, 0x0b, 0x0d, 0x0f, 0x01, 0x03, 0x05, 0x07,
/* 3 */ 0x09, 0x0b, 0x0d, 0x0f, 0x01, 0x03, 0x05, 0x07, 0x0e, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x00,
/* 4 */ 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05, 0x0c, 0x0e, 0x08, 0x0a, 0x04, 0x06, 0x00, 0x02,
/* 5 */ 0x0c, 0x0e, 0x08, 0x0a, 0x04, 0x06, 0x00, 0x02, 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05,
/* 6 */ 0x05, 0x07, 0x01, 0x03, 0x0d, 0x0f, 0x09, 0x0b, 0x02, 0x00, 0x06, 0x04, 0x0a, 0x08, 0x0e, 0x0c,
/* 7 */ 0x02, 0x00, 0x06, 0x04, 0x0a, 0x08, 0x0e, 0x0c, 0x05, 0x07, 0x01, 0x03, 0x0d, 0x0f, 0x09, 0x0b,
/* 8 */ 0x01, 0x03, 0x05, 0x07, 0x09, 0x0b, 0x0d, 0x0f, 0x06, 0x04, 0x02, 0x00, 0x0e, 0x0c, 0x0a, 0x08,
/* 9 */ 0x06, 0x04, 0x02, 0x00, 0x0e, 0x0c, 0x0a, 0x08, 0x01, 0x03, 0x05, 0x07, 0x09, 0x0b, 0x0d, 0x0f,
/* A */ 0x0f, 0x0d, 0x0b, 0x09, 0x07, 0x05, 0x03, 0x01, 0x08, 0x0a, 0x0c, 0x0e, 0x00, 0x02, 0x04, 0x06,
/* B */ 0x08, 0x0a, 0x0c, 0x0e, 0x00, 0x02, 0x04, 0x06, 0x0f, 0x0d, 0x0b, 0x09, 0x07, 0x05, 0x03, 0x01,
/* C */ 0x0a, 0x08, 0x0e, 0x0c, 0x02, 0x00, 0x06, 0x04, 0x0d, 0x0f, 0x09, 0x0b, 0x05, 0x07, 0x01, 0x03,
/* D */ 0x0d, 0x0f, 0x09, 0x0b, 0x05, 0x07, 0x01, 0x03, 0x0a, 0x08, 0x0e, 0x0c, 0x02, 0x00, 0x06, 0x04,
/* E */ 0x04, 0x06, 0x00, 0x02, 0x0c, 0x0e, 0x08, 0x0a, 0x03, 0x01, 0x07, 0x05, 0x0b, 0x09, 0x0f, 0x0d,
/* F */ 0x03, 0x01, 0x07, 0x05, 0x0b, 0x09, 0x0f, 0x0d, 0x04, 0x06, 0x00, 0x02, 0x0c, 0x0e, 0x08, 0x0a
};
/**
* @brief CRC-4 lookup table with 16 entries
*
* Used to compute and check the CRC on the header with either the BYTE or NIBBLE granularity
* In case the BYTE granularity is used, the table is used only with the 7th nibble of the header
* (bits 24 to 27) when computing the CRC.
*/
//cstat !MISRAC2012-Rule-8.9_a
static uint8_t const CRC4_Lookup4[] =
{
/* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F */
0x00, 0x07, 0x0e, 0x09, 0x0b, 0x0c, 0x05, 0x02, 0x01, 0x06, 0x0f, 0x08, 0x0a, 0x0d, 0x04, 0x03
};
#endif /* CRC4_PER_NIBBLE */
/**
* @brief Computes a 4-bit CRC on the 28 LSBs of @p header and returns it in the 4 MSB of the header
*
* The generator polynomial used for the CRC is x^4+x+1 (ref. CCITT-G704).
*
* The 28 input bits are split into 7 nibbles that are processed from the least significant to the
* most significant one as follows:
*
* - the least significant (4-bit) nibble is processed first as if it were the most significant part
* of the divident;
* - the order of bits in each nibble is unchanged for processing which would leads to the following
* bit processing sequence: 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 19, 18, 17, 16,
* 23, 22, 21, 20, 27, 26, 25, 24.
*
* Two lookup tables based implementations are proposed: one solely relying on a 16 entries lookup
* table and another one that also uses a 256 entries lookup table. This last one is the default. It
* requires 256 more bytes than the first but is also roughly two times faster.
*
* The 16 entries lookup table based implementation is enabled when the CRC4_PER_NIBBLE preprocessor
* flag is defined.
*
* Note that the default, 256 entries lookup table based implementation also uses the 16 entries lookup
* table because the amount of input data is not a multiple of 8 bits.
*
* The resulting CRC is written in bits 28 to 31 of @p header and the whole header is returned.
*/
static void ASPEP_ComputeHeaderCRC(uint32_t *headerPtr)
{
uint8_t crc = 0;
uint32_t header = *headerPtr;
#ifndef CRC4_PER_NIBBLE
header &= 0x0fffffffU;
crc = CRC4_Lookup8[crc ^ (uint8_t)(header & 0xffU)];
crc = CRC4_Lookup8[crc ^ (uint8_t)((header >> 8U) & 0xffU)];
crc = CRC4_Lookup8[crc ^ (uint8_t)((header >> 16U) & 0xffU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 24U) & 0x0fU)];
#else /* CRC4_PER_NIBBLE */
crc = CRC4_Lookup4[crc ^ (uint8_t)(header & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 4U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 8U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 12U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 16U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 20U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 24U) & 0xfU)];
#endif /* CRC4_PER_NIBBLE */
*headerPtr |= (uint32_t)crc << 28;
}
/**
* @brief Checks if @p header contains a valid 4-bit CRC and return true if this is the case and false otherwise
*
* The CRC is computed over the 32 bits of the @p header. If the result is 0, the CRC is considered valid
* and true is returned. If the result is not 0, false is returned.
*
* @sa ASPEP_ComputeHeaderCRC
*/
static bool ASPEP_CheckHeaderCRC(uint32_t header)
{
uint8_t crc = 0;
#ifndef CRC4_PER_NIBBLE
crc = CRC4_Lookup8[crc ^ (uint8_t)(header & 0xffU)];
crc = CRC4_Lookup8[crc ^ (uint8_t)((header >> 8U) & 0xffU)];
crc = CRC4_Lookup8[crc ^ (uint8_t)((header >> 16U) & 0xffU)];
crc = CRC4_Lookup8[crc ^ (uint8_t)((header >> 24U) & 0xffU)];
#else /* CRC4_PER_NIBBLE */
crc = CRC4_Lookup4[crc ^ (uint8_t)(header & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 4U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 8U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 12U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 16U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 20U) & 0xfU)];
crc = CRC4_Lookup4[crc ^ (uint8_t)((header >> 24U) & 0xfU)];
crc = crc ^ (uint8_t)((header >> 28) & 0xf);
#endif /* CRC4_PER_NIBBLE */
return (crc == 0U);
}
/**
* @brief Starts ASPEP communication by configuring UART.
*
* @param *pHandle Handler of the current instance of the ASPEP component
*/
void ASPEP_start(ASPEP_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_ASP
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->fASPEP_HWInit(pHandle->HWIp);
pHandle->ASPEP_State = ASPEP_IDLE;
pHandle->ASPEP_TL_State = WAITING_PACKET;
pHandle->syncPacketCount = 0; /* Sync packet counter is reset only at startup*/
/* Configure UART to receive first packet*/
pHandle->fASPEP_receive(pHandle->HWIp, pHandle->rxHeader, ASPEP_HEADER_SIZE);
#ifdef NULL_PTR_CHECK_ASP
}
#endif
}
/**
* @brief Sends BEACON to controller containing matched capabilities between controller and performer.
*
* @param *pHandle Handler of the current instance of the ASPEP component
* @param *capabilities Matched capabilities between controller and performer
*/
void ASPEP_sendBeacon(ASPEP_Handle_t *pHandle, ASPEP_Capabilities_def *capabilities)
{
#ifdef NULL_PTR_CHECK_ASP
if ((MC_NULL == pHandle) || (NULL == capabilities))
{
/* Nothing to do */
}
else
{
#endif
uint32_t *packet = (uint32_t *)pHandle->ctrlBuffer.buffer; //cstat !MISRAC2012-Rule-11.3
*packet = (BEACON
| (((uint32_t)capabilities->version) << 4U)
| (((uint32_t)capabilities->DATA_CRC) << 7U)
| (((uint32_t)capabilities->RX_maxSize) << 8U)
| (((uint32_t)capabilities->TXS_maxSize) << 14U)
| (((uint32_t)capabilities->TXA_maxSize) << 21U));
(void)ASPEP_TXframeProcess(pHandle, ASPEP_CTRL, &pHandle->ctrlBuffer, ASPEP_CTRL_SIZE);
#ifdef NULL_PTR_CHECK_ASP
}
#endif
}
/**
* @brief Sends back to controller a NOT_ACKNOWLEDGED message.
*
* @param *pHandle Handler of the current instance of the ASPEP component
* @param errorInfo Information on the encountered error
*/
static void ASPEP_sendNack(ASPEP_Handle_t *pHandle, uint8_t errorInfo)
{
uint32_t *packet = (uint32_t *)pHandle->ctrlBuffer.buffer; //cstat !MISRAC2012-Rule-11.3
*packet = NACK | (uint32_t)(((uint32_t) errorInfo) << 8U) | (uint32_t)(((uint32_t) errorInfo) << 16U);
(void)ASPEP_TXframeProcess(pHandle, ASPEP_CTRL, &pHandle->ctrlBuffer, ASPEP_CTRL_SIZE);
}
/**
* @brief Sends back ping to controller once connection has been established.
*
* @param *pHandle Handler of the current instance of the ASPEP component
* @param cBit Set to 1 if Performer has not been reset during communication
* @param packetNumber Number of requested packet incremented throughout the entire communication process, reset when communication is aborted or lost
*/
void ASPEP_sendPing(ASPEP_Handle_t *pHandle, uint8_t cBit, uint16_t packetNumber)
{
#ifdef NULL_PTR_CHECK_ASP
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
uint32_t *packet = (uint32_t *)pHandle->ctrlBuffer.buffer; //cstat !MISRAC2012-Rule-11.3
uint8_t Nbit = pHandle->syncPacketCount & 0x1U; /* Keep only LSB */
uint8_t ipID = pHandle->liid & 0xFU;
*packet = PING | (uint32_t)((uint32_t)cBit << 4U)
| (uint32_t)((uint32_t)cBit << 5U)
| (uint32_t)((uint32_t)Nbit << 6U)
| (uint32_t)((uint32_t)Nbit << 7U)
| (uint32_t)((uint32_t)ipID << 8U)
| (uint32_t)(((uint32_t) packetNumber) << 12U);
(void)ASPEP_TXframeProcess(pHandle, ASPEP_CTRL, &pHandle->ctrlBuffer, ASPEP_CTRL_SIZE);
#ifdef NULL_PTR_CHECK_ASP
}
#endif
}
/**
* @brief Assigns new buffer depending on buffer type request and prevents overwriting.
*
* @param *pSupHandle Handler of the current instance of the MCTL component
* @param **buffer Pointer to the buffer to be assigned
* @param syncAsync Type of requested buffer, can be synchronous or asynchronous
*
* @return Returns true if there is a writable buffer. False otherwise.
*/
bool ASPEP_getBuffer(MCTL_Handle_t *pSupHandle, void **buffer, uint8_t syncAsync)
{
bool result = true;
#ifdef NULL_PTR_CHECK_ASP
if (MC_NULL == buffer)
{
result = false;
}
else
{
#endif
ASPEP_Handle_t *pHandle = (ASPEP_Handle_t *)pSupHandle; //cstat !MISRAC2012-Rule-11.3
if (MCTL_SYNC == syncAsync)
{
if (pHandle->syncBuffer.state <= writeLock) /* Possible values are free or writeLock*/
{
*buffer = &pHandle->syncBuffer.buffer[ASPEP_HEADER_SIZE];
pHandle->syncBuffer.state = writeLock;
}
else
{
result = false;
}
}
else /* Asynchronous buffer request */
{
if ((pHandle->asyncBufferA.state > writeLock) && (pHandle->asyncBufferB.state > writeLock))
{
result = false;
}
else
{
if (pHandle->asyncBufferA.state <= writeLock)
{
pHandle->asyncBufferA.state = writeLock;
pHandle->lastRequestedAsyncBuff = &pHandle->asyncBufferA;
*buffer = &pHandle->asyncBufferA.buffer[ASPEP_HEADER_SIZE];
#ifdef MCP_DEBUG_METRICS
pHandle->asyncBufferA.RequestedNumber++;
#endif
}
else if (pHandle->asyncBufferB.state <= writeLock)
{
pHandle->asyncBufferB.state = writeLock;
pHandle->lastRequestedAsyncBuff = &pHandle->asyncBufferB;
*buffer = &pHandle->asyncBufferB.buffer[ASPEP_HEADER_SIZE];
#ifdef MCP_DEBUG_METRICS
pHandle->asyncBufferB.RequestedNumber++;
#endif
}
else
{
/* Nothing to do */
}
}
}
#ifdef NULL_PTR_CHECK_ASP
}
#endif
return (result);
}
/**
* @brief Checks controller's capabilities and compare them to performer's capabilities.
*
* @param *pHandle Handler of the current instance of the ASPEP component
*
* @return Returns true if controller's capabilities match performer's one. False otherwise.
*/
bool ASPEP_CheckBeacon (ASPEP_Handle_t *pHandle)
{
bool result = true;
uint32_t packetHeader = *((uint32_t *)pHandle->rxHeader); //cstat !MISRAC2012-Rule-11.3
ASPEP_Capabilities_def MasterCapabilities;
MasterCapabilities.version = (uint8_t)((packetHeader &0x70U)>> 4U); /*Bits 4 to 6*/
MasterCapabilities.DATA_CRC = pHandle->rxHeader[0] >> 7U ; /*Bit 7 */
MasterCapabilities.RX_maxSize = pHandle->rxHeader[1] &0x3FU; /*Bits 8 to 13*/
MasterCapabilities.TXS_maxSize = (uint8_t)((packetHeader&0x01FC000U) >> 14); /*Bits 14 to 20 */
MasterCapabilities.TXA_maxSize = (uint8_t)((packetHeader&0xFE00000U) >> 21); /*Bits 21 to 27 */
pHandle->Capabilities.DATA_CRC = MIN(pHandle->Capabilities.DATA_CRC ,MasterCapabilities.DATA_CRC);
pHandle->Capabilities.RX_maxSize = MIN(pHandle->Capabilities.RX_maxSize, MasterCapabilities.RX_maxSize);
pHandle->Capabilities.TXS_maxSize = MIN(pHandle->Capabilities.TXS_maxSize, MasterCapabilities.TXS_maxSize);
pHandle->Capabilities.TXA_maxSize = MIN(pHandle->Capabilities.TXA_maxSize, MasterCapabilities.TXA_maxSize);
if ((MasterCapabilities.DATA_CRC != pHandle->Capabilities.DATA_CRC)
/* Data packet the controller can send is bigger than performer can receive */
|| (MasterCapabilities.RX_maxSize > pHandle->Capabilities.RX_maxSize)
/* Sync packet size alignement is required in order for the controller to be able to store it, and to not request a
* response bigger than performer capability */
|| (pHandle->Capabilities.TXS_maxSize != MasterCapabilities.TXS_maxSize )
/* Async packet the performer can send is bigger than the controller can receive (but controller must not request a bigger
* packet than performer can transmit) */
|| (pHandle->Capabilities.TXA_maxSize != MasterCapabilities.TXA_maxSize )
/* For the time being, controller version has to match performer version */
|| (MasterCapabilities.version != pHandle->Capabilities.version) )
{
result = false;
}
else
{
/* Nothing to do */
}
return (result);
}
/**
* @brief Checks if any error has occurred and calls the ASPEP_TXframeProcess function.
*
* @param *pSupHandle Handler of the current instance of the MCTL component
* @param *txBuffer can be 8, 16 or 32 bits, but must be 32 bits aligned
* @param txDataLength Size of useful data in byte
* @param syncAsync nature of the communication : synchronous or asynchronous
*
* @return Returns an ASPEP response defined in aspep.h
*/
uint8_t ASPEP_sendPacket(MCTL_Handle_t *pSupHandle, void *txBuffer, uint16_t txDataLength, uint8_t syncAsync)
{
uint8_t result = ASPEP_OK;
#ifdef NULL_PTR_CHECK_ASP
if ((MC_NULL == pSupHandle) || (MC_NULL == txBuffer))
{
result = ASPEP_BUFFER_ERROR;
}
else
{
#endif
uint32_t *header;
uint32_t tmpHeader;
uint16_t txDataLengthTemp;
uint8_t *packet;
txDataLengthTemp = txDataLength;
ASPEP_Handle_t *pHandle = (ASPEP_Handle_t *)pSupHandle; //cstat !MISRAC2012-Rule-11.3
if (ASPEP_CONNECTED == pHandle-> ASPEP_State)
{
/*We must add packet header on */
/* | [0101|0011] | Length 13b | Reserved |CRCH 4b| */
packet = (uint8_t *)txBuffer; //cstat !MISRAC2012-Rule-11.5
header = (uint32_t *)txBuffer; //cstat !MISRAC2012-Rule-11.5
header--; /* Header ues 4*8 bits on top of txBuffer*/
tmpHeader = ((uint32_t)((uint32_t)txDataLengthTemp << (uint32_t)4) | (uint32_t)syncAsync);
*header = tmpHeader;
if (1U == pHandle->Capabilities.DATA_CRC)
{
/* TODO : Compute real CRC*/
packet[txDataLengthTemp] = (uint8_t)0xCA; /* Dummy CRC */
packet[txDataLengthTemp + 1U] = (uint8_t)0xFE; /* Dummy CRC */
txDataLengthTemp += (uint16_t)ASPEP_DATACRC_SIZE;
}
if (MCTL_SYNC == syncAsync)
{
if (pSupHandle->MCP_PacketAvailable)
{
pSupHandle->MCP_PacketAvailable = false; /* CMD from controller is processed*/
}
else
{
result = MCTL_SYNC_NOT_EXPECTED;
}
}
if (ASPEP_OK == result) /* Send packet only if no error detected so far*/
{
result = ASPEP_TXframeProcess(pHandle, syncAsync, header, txDataLengthTemp + (uint16_t)ASPEP_HEADER_SIZE);
}
}
else
{
result = ASPEP_NOT_CONNECTED;
}
#ifdef NULL_PTR_CHECK_ASP
}
#endif
return (result);
}
/**
* @brief Checks if HW resource is busy before sending packet. Otherwise saves packet for next opportunity to send.
*
* This function contains a critical section.
* It can be accessed concurently under High frequency task (by MCPA_datalog)
* and under Medium frequency task (MC_Scheduler -> ASPEP_RxFrameProcess ).
*
* @param *pHandle Handler of the current instance of the ASPEP component
* @param dataType Nature of the communication : synchronous, asynchronous or a CTL packet
* @param *txBuffer CRC Header to be computed in sent packet
* @param bufferLength Size of the packet to be sent : Header + Data
*
* @return Returns an ASPEP response defined in aspep.h
*/
uint8_t ASPEP_TXframeProcess(ASPEP_Handle_t *pHandle, uint8_t dataType, void *txBuffer, uint16_t bufferLength)
{
uint8_t result = ASPEP_OK;
#ifdef NULL_PTR_CHECK_ASP
if (MC_NULL == txBuffer)
{
result = ASPEP_BUFFER_ERROR;
}
else
{
#endif
/* Insert CRC header in the packet to send */
ASPEP_ComputeHeaderCRC((uint32_t *)txBuffer); //cstat !MISRAC2012-Rule-11.5
__disable_irq(); /*TODO: Disable High frequency task is enough */
if (NULL == pHandle->lockBuffer) /* Communication Ip free to send data*/
{
if (MCTL_ASYNC == dataType)
{
/* In ASYNC, two flipflop buffers are used, the txBuffer points always to lastRequestedAsyncBuff->buffer */
pHandle->lastRequestedAsyncBuff->state = readLock;
pHandle->lockBuffer = (void *)pHandle->lastRequestedAsyncBuff;
#ifdef MCP_DEBUG_METRICS
pHandle->lastRequestedAsyncBuff->SentNumber++;
#endif
}
else if (MCTL_SYNC == dataType)
{
pHandle->syncBuffer.state = readLock;
pHandle->lockBuffer = (void *)&pHandle->syncBuffer;
}
else
{
pHandle->ctrlBuffer.state = readLock;
pHandle->lockBuffer = (void *)&pHandle->ctrlBuffer;
}
/* Enable HF task It */
__enable_irq(); /*TODO: Enable High frequency task is enough */
pHandle->fASPEP_send(pHandle->HWIp, txBuffer, bufferLength);
}
else /* HW resource busy, saving packet to sent it once resource will be freed*/
{
__enable_irq(); /*TODO: Enable High frequency task is enough */
/* Lock buffer can be freed here */
if (MCTL_ASYNC == dataType)
{
/* Check that the buffer received is the one expected - probably useless */
if (txBuffer != (uint8_t *)pHandle->lastRequestedAsyncBuff->buffer)
{
result = ASPEP_BUFFER_ERROR;
}
else
{
/* Nothing to do */
}
if (NULL == pHandle->asyncNextBuffer)
{
/* Required to keep the right sending order */
pHandle->asyncNextBuffer = pHandle->lastRequestedAsyncBuff;
}
else
{
/* Nothing to do */
}
pHandle->lastRequestedAsyncBuff->state = pending;
pHandle->lastRequestedAsyncBuff->length = bufferLength;
#ifdef MCP_DEBUG_METRICS
pHandle->lastRequestedAsyncBuff->PendingNumber++;
#endif
}
else if (MCTL_SYNC == dataType)
{
if (pHandle -> syncBuffer.state != writeLock)
{
result = ASPEP_BUFFER_ERROR;
}
else
{
pHandle->syncBuffer.state = pending;
pHandle->syncBuffer.length = bufferLength;
}
}
else if(ASPEP_CTRL == dataType)
{
if (pHandle->ctrlBuffer.state != available)
{
result = ASPEP_BUFFER_ERROR;
}
else
{
pHandle->ctrlBuffer.state = pending;
}
}
else
{
/* Nothing to do */
}
}
#ifdef NULL_PTR_CHECK_ASP
}
#endif
return (result);
}
/**
* @brief Frees previously locked buffer and/or locks the next pending buffer. Once locked, sends the buffer.
*
* Called as soon as previous packet transfer is completed, pHandle->lockBuffer is set before packet transmission and ensures packet won't be read anymore.
* Therefore, there is no need to protect this ISR against another higher priority ISR (HF Task).
*
* @param *pHandle Handler of the current instance of the ASPEP component
*/
void ASPEP_HWDataTransmittedIT(ASPEP_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_ASP
if (NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
/* First free previous readLock buffer */
if (pHandle->ctrlBuffer.state == readLock)
{
pHandle->ctrlBuffer.state = available;
}
else /* if previous buffer was not ASPEP_CTRL, then the buffer locked is a MCTL_Buff_t */
{
MCTL_Buff_t *tempBuff = (MCTL_Buff_t *)pHandle->lockBuffer; //cstat !MISRAC2012-Rule-11.5
tempBuff->state = available;
}
if (pHandle->syncBuffer.state == pending)
{
pHandle->lockBuffer = (void *)&pHandle->syncBuffer;
pHandle->fASPEP_send(pHandle->HWIp, pHandle->syncBuffer.buffer, pHandle->syncBuffer.length);
pHandle->syncBuffer.state = readLock;
}
/* Second prepare transfer of pending buffer */
else if (pHandle->ctrlBuffer.state == pending)
{
pHandle->lockBuffer = (void *)(&pHandle ->ctrlBuffer);
pHandle->fASPEP_send(pHandle ->HWIp, pHandle->ctrlBuffer.buffer, ASPEP_CTRL_SIZE);
pHandle->ctrlBuffer.state = readLock;
}
else
{
__disable_irq();
if (pHandle->asyncNextBuffer != NULL)
{
pHandle->lockBuffer = (void *)pHandle->asyncNextBuffer;
pHandle->asyncNextBuffer->state = readLock;
#ifdef MCP_DEBUG_METRICS
pHandle->asyncNextBuffer->SentNumber++;
#endif
pHandle->fASPEP_send(pHandle ->HWIp, pHandle->asyncNextBuffer->buffer, pHandle->asyncNextBuffer->length);
/* If one Async buffer is still pending, assign it to the asyncNextBuffer pointer*/
if ((pHandle->asyncBufferA.state == pending) || (pHandle->asyncBufferB.state == pending))
{
//cstat !MISRAC2012-Rule-11.4
uint32_t temp = (uint32_t)&pHandle->asyncBufferA + (uint32_t)&pHandle->asyncBufferB
- (uint32_t) pHandle->asyncNextBuffer; //cstat !MISRAC2012-Rule-11.4
pHandle->asyncNextBuffer = (MCTL_Buff_t *) temp; //cstat !MISRAC2012-Rule-11.4
}
else
{
pHandle->asyncNextBuffer = NULL;
}
}
else /* No TX packet are pending, HW resource is free*/
{
pHandle->lockBuffer = NULL;
}
__enable_irq();
}
#ifdef NULL_PTR_CHECK_ASP
}
#endif
}
/**
* @brief Updates ASPEP state depending on received packet from Controller and sends a response according to ASPEP protocol
*
* ASPEP protocol defined in section 4.4.1 Connection Procedure of Motor Control Protocol Suite of User Manual
*
* @param *pSupHandle Handler of the current instance of the MCTL component
* @param *packetLength Length of the packet to be processed
*
* @return Returns the buffer of data transmitted by the MCP controller device
*/
uint8_t *ASPEP_RXframeProcess(MCTL_Handle_t *pSupHandle, uint16_t *packetLength)
{
uint8_t *result = NULL; //cstat !MISRAC2012-Rule-8.13
#ifdef NULL_PTR_CHECK_ASP
if ((NULL == pSupHandle) || (NULL == packetLength))
{
/* Nothing to do */
}
else
{
#endif
ASPEP_Handle_t *pHandle = (ASPEP_Handle_t *)pSupHandle; //cstat !MISRAC2012-Rule-11.3
uint32_t packetHeader = *((uint32_t *)pHandle->rxHeader); //cstat !MISRAC2012-Rule-11.3
uint16_t packetNumber;
#if VALID_CRC_DATA
bool validCRCData = true;
#endif
*packetLength = 0;
if (pHandle->NewPacketAvailable)
{
pHandle->NewPacketAvailable = false; /* Consumes new packet*/
switch (pHandle->ASPEP_State)
{
case ASPEP_IDLE:
{
if (BEACON == pHandle->rxPacketType)
{
if (ASPEP_CheckBeacon(pHandle) == true)
{
/* Controller capabilities match performer capabilities.*/
pSupHandle->txSyncMaxPayload = (pHandle->Capabilities.TXS_maxSize + (uint16_t)1U) * (uint16_t)32U;
pSupHandle->txAsyncMaxPayload = (pHandle->Capabilities.TXA_maxSize) * (uint16_t)64U;
pHandle->maxRXPayload = (pHandle->Capabilities.RX_maxSize + (uint16_t)1U) * (uint16_t)32U;
pHandle->ASPEP_State = ASPEP_CONFIGURED;
}
else
{
/* Nothing to do, controller has to send back new beacon with matching capabilities */
}
/* Beacon Packet must be answered*/
ASPEP_sendBeacon(pHandle, &pHandle->Capabilities);
}
else if (PING == pHandle->rxPacketType)
{
/* In Listening for controller performer, */
packetNumber = (uint16_t)((packetHeader & 0x0FFFF000U) >> (uint16_t)12U);
ASPEP_sendPing(pHandle, ASPEP_PING_RESET, packetNumber);
}
else
{
/* Nothing to do */
}
break;
}
case ASPEP_CONFIGURED:
{
if (BEACON == pHandle->rxPacketType)
{
if (ASPEP_CheckBeacon(pHandle) == false)
{
pHandle->ASPEP_State = ASPEP_IDLE;
}
else
{
/* Nothing to do */
}
ASPEP_sendBeacon (pHandle, &pHandle->Capabilities);
}
else if (PING == pHandle->rxPacketType)
{
/* In Listening for controller performer, */
packetNumber = (uint16_t)((packetHeader & 0x0FFFF000U) >> (uint16_t)12U);
ASPEP_sendPing(pHandle, ASPEP_PING_CFG, packetNumber);
pHandle->ASPEP_State = ASPEP_CONNECTED;
}
else
{
/* Nothing to do */
}
break;
}
case ASPEP_CONNECTED:
{
if (BEACON == pHandle->rxPacketType)
{
if (ASPEP_CheckBeacon(pHandle) == false)
{
pHandle->ASPEP_State = ASPEP_IDLE;
}
else
{
pHandle->ASPEP_State = ASPEP_CONFIGURED;
}
ASPEP_sendBeacon(pHandle, &pHandle->Capabilities);
}
else if (PING == pHandle->rxPacketType)
{
packetNumber = pHandle->rxHeader[1];
ASPEP_sendPing(pHandle, ASPEP_PING_CFG, packetNumber);
}
else if (DATA_PACKET == pHandle->rxPacketType)
{
#if VALID_CRC_DATA
if (validCRCData)
{
#endif
pHandle->syncPacketCount++; /* this counter is incremented at each valid data packet received from controller */
pSupHandle->MCP_PacketAvailable = true; /* Will be consumed in ASPEP_sendPacket */
*packetLength = pHandle->rxLength;
result = pHandle->rxBuffer;
#if VALID_CRC_DATA
}
else
{
ASPEP_sendNack (pHandle, ASPEP_BAD_CRC_DATA);
}
#endif
}
else
{
/* This condition is not reachable because already filtred by NewPacketAvailable */
/* ASPEP_sendNack (pHandle, ASPEP_BAD_PACKET_TYPE) */
}
break;
}
default:
break;
}
/* The valid received packet is now safely consumes, we are ready to receive a new packet */
pHandle->fASPEP_receive(pHandle->HWIp, pHandle->rxHeader, ASPEP_HEADER_SIZE);
}
else if (pHandle->badPacketFlag > ASPEP_OK)
{
ASPEP_sendNack(pHandle, pHandle->badPacketFlag);
/* ASPEP_RXframeProcess can be called before reception of another packet */
pHandle->badPacketFlag = ASPEP_OK;
/* As we received a packet with a bad header, we need to be sure that the HW IP is well Synchronised
* DMA will be configured to receive next packet as soon as HW IP RX line is free to receive new packet
* It is important to note that we will detect only the NEXT free line transition, it means the next packet will
* be lost but the end of this lost packet will generate the IDLE interrupt
* the IDLE interrupt will call ASPEP_HWDMAReset (in charge of the IP_aspep driver to call it at the appropriate
* time)*/
pHandle->fASPEP_HWSync(pHandle->HWIp);
}
else
{
/* Nothing to do, no response is due to the controller */
}
#ifdef NULL_PTR_CHECK_ASP
}
#endif
return (result);
}
/**
* @brief Processes the received data packet.
*
* This function is called once DMA has transfered the configure number of byte.
* Upon reception of a new packet the DMA will be re-configured only once the answer has been sent.
* This is mandatory to avoid a race condition in case of a new packet is received while executing ASPEP_RXframeProcess.
* If the packet received contains an error in the header, the HW IP will be re-synchronised first, and DMA will be configured after.
*
* @param *pHandle Handler of the current instance of the ASPEP component
*/
void ASPEP_HWDataReceivedIT(ASPEP_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_ASP
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
switch (pHandle->ASPEP_TL_State)
{
case WAITING_PACKET:
{
if (ASPEP_CheckHeaderCRC(*(uint32_t *)pHandle->rxHeader) == true) //cstat !MISRAC2012-Rule-11.3
{
pHandle->rxPacketType = (ASPEP_packetType)(((uint32_t)pHandle->rxHeader[0]) & ID_MASK);
switch (pHandle->rxPacketType)
{
case DATA_PACKET:
{
//cstat !MISRAC2012-Rule-11.3
pHandle->rxLength = (uint16_t)((*((uint16_t *)pHandle->rxHeader) & 0x1FFF0U) >> (uint16_t)4);
if (0U == pHandle->rxLength) /* data packet with length 0 is a valid packet */
{
pHandle->NewPacketAvailable = true;
/* The receiver is not reconfigure right now on purpose to avoid race condition when the packet will be
* processed in ASPEP_RXframeProcess */
}
else if (pHandle->rxLength <= pHandle->maxRXPayload)
{
pHandle->fASPEP_receive(pHandle->HWIp, pHandle->rxBuffer, /* need to read + 2 bytes CRC*/
(pHandle->rxLength + ((uint16_t)ASPEP_DATACRC_SIZE * (uint16_t)pHandle->Capabilities.DATA_CRC)));
pHandle->ASPEP_TL_State = WAITING_PAYLOAD;
}
else
{
pHandle->badPacketFlag = ASPEP_BAD_PACKET_SIZE;
}
break;
}
case BEACON:
case PING:
{
pHandle->NewPacketAvailable = true;
/* The receiver is not reconfigure right now on purpose to avoid race condition when the packet will be
* processed in ASPEP_RXframeProcess */
break;
}
default:
{
pHandle->badPacketFlag = ASPEP_BAD_PACKET_TYPE;
break;
}
}
}
else
{
pHandle->badPacketFlag = ASPEP_BAD_CRC_HEADER;
}
break;
}
case WAITING_PAYLOAD:
{
pHandle->ASPEP_TL_State = WAITING_PACKET;
/* Payload received, */
pHandle->NewPacketAvailable = true;
/* The receiver is not reconfigure right now on purpose to avoid race condition when the packet will be
* processed in ASPEP_RXframeProcess */
break;
}
default:
break;
}
#ifdef NULL_PTR_CHECK_ASP
}
#endif
}
/**
* @brief Resets DMA after debugger has stopped the MCU.
*
* @param *pHandle Handler of the current instance of the ASPEP component
*/
void ASPEP_HWDMAReset(ASPEP_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_ASP
if (NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
/* We must reset the RX state machine to be sure to not be in Waiting packet state */
/* Otherwise the arrival of a new packet will trigger a NewPacketAvailable despite */
/* the fact that bytes have been lost because of overrun (debugger paused for instance) */
pHandle->ASPEP_TL_State = WAITING_PACKET;
pHandle->fASPEP_receive(pHandle->HWIp, pHandle->rxHeader, ASPEP_HEADER_SIZE);
#ifdef NULL_PTR_CHECK_ASP
}
#endif
}
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 34,799 | C | 35.516264 | 156 | 0.616512 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/pwm_curr_fdbk.c | /**
******************************************************************************
* @file pwm_curr_fdbk.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the following features
* of the PWM & Current Feedback component of the Motor Control SDK:
*
* * current sensing
* * regular ADC conversion execution
* * space vector modulation
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup pwm_curr_fdbk
*/
/* Includes ------------------------------------------------------------------*/
#include "pwm_curr_fdbk.h"
#include "mc_math.h"
#include "mc_type.h"
/** @addtogroup MCSDK
* @{
*/
/** @defgroup pwm_curr_fdbk PWM & Current Feedback
*
* @brief PWM & Current Feedback components of the Motor Control SDK.
*
* These components fulfill two functions in a Motor Control subsystem:
*
* - The generation of the Space Vector Pulse Width Modulation on the motor's phases
* - The sampling of the actual motor's phases current
*
* Both these features are closely related as the instants when the values of the phase currents
* should be sampled by the ADC channels are basically triggered by the timers used to generate
* the duty cycles for the PWM.
*
* Several implementation of PWM and Current Feedback components are provided by the Motor Control
* SDK to account for the specificities of the application:
*
* - The selected MCU: the number of ADCs available on a given MCU, the presence of internal
* comparators or OpAmps, for instance, lead to different implementation of this feature
* - The Current sensing topology also has an impact on the firmware: implementations are provided
* for Insulated Current Sensors, Single Shunt and Three Shunt resistors current sensing topologies
*
* The choice of the implementation mostly depend on these two factors and is performed by the
* Motor Control Workbench tool.
*
* All these implementations are built on a base PWM & Current Feedback component that they extend
* and that provides the functions and data that are common to all of them. This base component is
* never used directly as it does not provide a complete implementation of the features. Rather,
* its handle structure (PWMC_Handle) is reused by all the PWM & Current Feedback specific
* implementations and the functions it provides form the API of the PWM and Current feedback feature.
* Calling them results in calling functions of the component that actually implement the feature.
* See PWMC_Handle for more details on this mechanism.
* @{
*/
/**
* @brief Used to clear variables in CPWMC.
*
* @param pHandle: Handler of the current instance of the PWM component.
*/
void PWMC_Clear(PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->IaEst = 0;
pHandle->IbEst = 0;
pHandle->IcEst = 0;
pHandle->LPFIdBuf = 0;
pHandle->LPFIqBuf = 0;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the calibrated @p offsets for each of the phases in the @p pHandle handler. In case of single shunt only phase A is relevant.
*
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_SetOffsetCalib(PWMC_Handle_t *pHandle, PolarizationOffsets_t *offsets)
{
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
pHandle->pFctSetOffsetCalib(pHandle, offsets);
}
}
/**
* @brief Gets the calibrated @p offsets for each of the phases in the @p pHandle handler. In case of single shunt only phase A is relevant.
*
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_GetOffsetCalib(PWMC_Handle_t *pHandle, PolarizationOffsets_t *offsets)
{
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
pHandle->pFctGetOffsetCalib(pHandle, offsets);
}
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief Returns the phase current of the motor as read by the ADC (in s16A unit).
*
* Returns the current values of phases A & B. Phase C current
* can be deduced thanks to the formula:
*
* @f[
* I_{C} = -I_{A} - I_{B}
* @f]
*
* @param pHandle: Handler of the current instance of the PWM component.
* @param Iab: Pointer to the structure that will receive motor current
* of phases A & B in ElectricalValue format.
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_GetPhaseCurrents(PWMC_Handle_t *pHandle, ab_t *Iab)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctGetPhaseCurrents(pHandle, Iab);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief Converts input voltages @f$ V_{\alpha} @f$ and @f$ V_{\beta} @f$ into PWM duty cycles
* and feed them to the inverter.
*
* This function computes the time during which the transistors of each phase are to be switched on in
* a PWM cycle in order to achieve the reference phase voltage set by @p Valfa_beta. The function then
* programs the resulting duty cycles in the related timer channels. It also sets the phase current
* sampling point for the next PWM cycle accordingly.
*
* This function is used in the FOC frequency loop and needs to complete itself before the next PWM cycle starts
* in order for the duty cycles it computes to be taken into account. Failing to do so (for instance because
* the PWM Frequency is too high) results in the function returning #MC_DURATION which entails a
* Motor Control Fault that stops the motor.
*
* @param pHandle: Handler of the current instance of the PWM component.
* @param Valfa_beta: Voltage Components expressed in the @f$(\alpha, \beta)@f$ reference frame.
* @retval #MC_NO_ERROR if no error occurred or #MC_DURATION if the duty cycles were
* set too late for being taken into account in the next PWM cycle.
*/
__weak uint16_t PWMC_SetPhaseVoltage(PWMC_Handle_t *pHandle, alphabeta_t Valfa_beta)
{
uint16_t returnValue;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
returnValue = 0U;
}
else
{
#endif
int32_t wX;
int32_t wY;
int32_t wZ;
int32_t wUAlpha;
int32_t wUBeta;
int32_t wTimePhA;
int32_t wTimePhB;
int32_t wTimePhC;
wUAlpha = Valfa_beta.alpha * (int32_t)pHandle->hT_Sqrt3;
wUBeta = -(Valfa_beta.beta * ((int32_t)pHandle->PWMperiod)) * 2;
wX = wUBeta;
wY = (wUBeta + wUAlpha) / 2;
wZ = (wUBeta - wUAlpha) / 2;
/* Sector calculation from wX, wY, wZ */
if (wY < 0)
{
if (wZ < 0)
{
pHandle->Sector = SECTOR_5;
wTimePhA = (((int32_t)pHandle->PWMperiod) / 4) + ((wY - wZ) / (int32_t)262144);
wTimePhB = wTimePhA + (wZ / 131072);
wTimePhC = wTimePhA - (wY / 131072) ;
if(true == pHandle->SingleShuntTopology)
{
pHandle->lowDuty = 1U;
pHandle->midDuty = 0U;
pHandle->highDuty = 2U;
}
else
{
pHandle->lowDuty = (uint16_t)wTimePhC;
pHandle->midDuty = (uint16_t)wTimePhA;
pHandle->highDuty = (uint16_t)wTimePhB;
}
}
else /* wZ >= 0 */
if (wX <= 0)
{
pHandle->Sector = SECTOR_4;
wTimePhA = (((int32_t)pHandle->PWMperiod) / 4) + ((wX - wZ) / (int32_t)262144);
wTimePhB = wTimePhA + (wZ / 131072);
wTimePhC = wTimePhB - (wX / 131072);
if(true == pHandle->SingleShuntTopology)
{
pHandle->lowDuty = 0U;
pHandle->midDuty = 1U;
pHandle->highDuty = 2U;
}
else
{
pHandle->lowDuty = (uint16_t)wTimePhC;
pHandle->midDuty = (uint16_t)wTimePhB;
pHandle->highDuty = (uint16_t)wTimePhA;
}
}
else /* wX > 0 */
{
pHandle->Sector = SECTOR_3;
wTimePhA = (((int32_t )pHandle->PWMperiod) / 4)+ ((wY - wX) / (int32_t)262144);
wTimePhC = wTimePhA - (wY / 131072);
wTimePhB = wTimePhC + (wX / 131072);
if(true == pHandle->SingleShuntTopology)
{
pHandle->lowDuty = 0U;
pHandle->midDuty = 2U;
pHandle->highDuty = 1U;
}
else
{
pHandle->lowDuty = (uint16_t)wTimePhB;
pHandle->midDuty = (uint16_t)wTimePhC;
pHandle->highDuty = (uint16_t)wTimePhA;
}
}
}
else /* wY > 0 */
{
if (wZ >= 0)
{
pHandle->Sector = SECTOR_2;
wTimePhA = (((int32_t)pHandle->PWMperiod) / 4) + ((wY - wZ) / (int32_t)262144);
wTimePhB = wTimePhA + (wZ / 131072);
wTimePhC = wTimePhA - (wY / 131072);
if(true == pHandle->SingleShuntTopology)
{
pHandle->lowDuty = 2U;
pHandle->midDuty = 0U;
pHandle->highDuty = 1U;
}
else
{
pHandle->lowDuty = (uint16_t)wTimePhB;
pHandle->midDuty = (uint16_t)wTimePhA;
pHandle->highDuty = (uint16_t)wTimePhC;
}
}
else /* wZ < 0 */
if ( wX <= 0 )
{
pHandle->Sector = SECTOR_6;
wTimePhA = (((int32_t )pHandle->PWMperiod) / 4) + ((wY - wX) / (int32_t)262144);
wTimePhC = wTimePhA - (wY / 131072);
wTimePhB = wTimePhC + (wX / 131072);
if(true == pHandle->SingleShuntTopology)
{
pHandle->lowDuty = 1U;
pHandle->midDuty = 2U;
pHandle->highDuty = 0U;
}
else
{
pHandle->lowDuty = (uint16_t)wTimePhA;
pHandle->midDuty = (uint16_t)wTimePhC;
pHandle->highDuty = (uint16_t)wTimePhB;
}
}
else /* wX > 0 */
{
pHandle->Sector = SECTOR_1;
wTimePhA = (((int32_t)pHandle->PWMperiod) / 4)+ ((wX - wZ) / (int32_t)262144);
wTimePhB = wTimePhA + (wZ / 131072);
wTimePhC = wTimePhB - (wX / 131072);
if((pHandle->DPWM_Mode == true) || (pHandle->SingleShuntTopology == true))
{
pHandle->lowDuty = 2U;
pHandle->midDuty = 1U;
pHandle->highDuty = 0U;
}
else
{
pHandle->lowDuty = (uint16_t)wTimePhA;
pHandle->midDuty = (uint16_t)wTimePhB;
pHandle->highDuty = (uint16_t)wTimePhC;
}
}
}
pHandle->CntPhA = (uint16_t)(MAX(wTimePhA, 0));
pHandle->CntPhB = (uint16_t)(MAX(wTimePhB, 0));
pHandle->CntPhC = (uint16_t)(MAX(wTimePhC, 0));
if (1U == pHandle->DTTest)
{
/* Dead time compensation */
if (pHandle->Ia > 0)
{
pHandle->CntPhA += pHandle->DTCompCnt;
}
else
{
pHandle->CntPhA -= pHandle->DTCompCnt;
}
if (pHandle->Ib > 0)
{
pHandle->CntPhB += pHandle->DTCompCnt;
}
else
{
pHandle->CntPhB -= pHandle->DTCompCnt;
}
if (pHandle->Ic > 0)
{
pHandle->CntPhC += pHandle->DTCompCnt;
}
else
{
pHandle->CntPhC -= pHandle->DTCompCnt;
}
}
returnValue = pHandle->pFctSetADCSampPointSectX(pHandle);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
return (returnValue);
}
/**
* @brief Switches PWM generation off, inactivating the outputs.
*
* @param pHandle: Handler of the current instance of the PWM component.
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_SwitchOffPWM(PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctSwitchOffPwm(pHandle);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Enables PWM generation on the proper Timer peripheral.
*
* @param pHandle: Handler of the current instance of the PWM component.
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_SwitchOnPWM(PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctSwitchOnPwm(pHandle);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Calibrates ADC current conversions by reading the offset voltage
* present on ADC pins when no motor current is flowing in.
*
* This function should be called before each motor start-up.
*
* @param pHandle: Handler of the current instance of the PWM component.
* @param action: Can be #CRC_START to initialize the offset calibration or
* #CRC_EXEC to execute the offset calibration.
* @retval true if the current calibration has been completed, **false** if it is
* still ongoing.
*/
__weak bool PWMC_CurrentReadingCalibr(PWMC_Handle_t *pHandle, CRCAction_t action)
{
bool retVal = false;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if (CRC_START == action)
{
PWMC_SwitchOffPWM(pHandle);
pHandle->pFctCurrReadingCalib(pHandle);
retVal = true;
}
else if (CRC_EXEC == action)
{
if (pHandle->OffCalibrWaitTimeCounter > 0u)
{
pHandle->OffCalibrWaitTimeCounter--;
if (0U == pHandle->OffCalibrWaitTimeCounter)
{
pHandle->pFctCurrReadingCalib(pHandle);
retVal = true;
}
}
else
{
retVal = true;
}
}
else
{
/* Nothing to do */
}
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
return (retVal);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief Sets a low pass filter.
*
* This function is called for setting low pass filter on Iq and Id, before getting
* transformed in Ia and Ib by the Reverse Park function.
*
* @param in: Value needing to be passed through the filter (Iq and Id).
* @param out_buf: LPF buffer.
* @param t: Low pass filter constant.
* @retval New value after the low pass filter.
*/
static inline int32_t PWMC_LowPassFilter(int32_t in, int32_t *out_buf, int32_t t)
{
int32_t x;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == out_buf)
{
x = 0;
}
else
{
#endif
#ifndef FULL_MISRA_C_COMPLIANCY_PWM_CURR
//cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6
*out_buf = (*out_buf) + ((in - ((*out_buf) >> 15)) * t);
x = (*out_buf) >> 15; //cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6
#else
*out_buf = (*out_buf) + ((in - ((*out_buf) / 32768)) * t);
x = (*out_buf) / 32768;
#endif
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
return (x);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief Converts input currents components Iqd into estimated
* currents Ia, Ib and Ic.
*
* @param pHandle: Handler of the current instance of the PWM component.
* @param Iqd: Structure that will receive Iq and Id currents.
* @param hElAngledpp: Electrical angle.
*/
void PWMC_CalcPhaseCurrentsEst(PWMC_Handle_t *pHandle, qd_t Iqd, int16_t hElAngledpp)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
qd_t idq_ave;
alphabeta_t ialpha_beta;
int32_t temp1, temp2;
idq_ave.q = (int16_t)PWMC_LowPassFilter(Iqd.q, &(pHandle->LPFIqBuf), pHandle->LPFIqd_const);
idq_ave.d = (int16_t)PWMC_LowPassFilter(Iqd.d, &(pHandle->LPFIdBuf), pHandle->LPFIqd_const);
ialpha_beta = MCM_Rev_Park(idq_ave, hElAngledpp);
/* Reverse Clarke */
/*Ia*/
pHandle->IaEst = ialpha_beta.alpha;
temp1 = - ialpha_beta.alpha;
#ifndef FULL_MISRA_C_COMPLIANCY_PWM_CURR
//cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6
temp2 = (int32_t)(ialpha_beta.beta) * ((int32_t)SQRT3FACTOR >> 15);
#else
temp2 = (int32_t)(ialpha_beta.beta) * (int32_t)SQRT3FACTOR / 32768;
#endif
/* Ib */
pHandle->IbEst = (int16_t)(temp1 - temp2)/2;
/* Ic */
pHandle->IcEst = (int16_t)(temp1 + temp2)/2;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Switches power stage Low Sides transistors on.
*
* This function is meant for charging boot capacitors of the driving
* section. It has to be called on each motor start-up when using high
* voltage drivers.
*
* @param pHandle: Handler of the current instance of the PWM component.
* @param ticks: Timer ticks value to be applied.
* Min value: 0 (low sides ON)
* Max value: PWM_PERIOD_CYCLES/2 (low sides OFF)
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_TurnOnLowSides(PWMC_Handle_t *pHandle, uint32_t ticks)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctTurnOnLowSides(pHandle, ticks);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section(".ccmram")))
#endif
#endif
/*
* @brief Manages HW overcurrent protection.
*
* @param pHandle: Handler of the current instance of the PWM component.
*/
__weak void *PWMC_OCP_Handler(PWMC_Handle_t *pHandle)
{
void *tempPointer; //cstat !MISRAC2012-Rule-8.13
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
tempPointer = MC_NULL;
}
else
{
#endif
if (false == pHandle->BrakeActionLock)
{
if (ES_GPIO == pHandle->LowSideOutputs)
{
LL_GPIO_ResetOutputPin(pHandle->pwm_en_u_port, pHandle->pwm_en_u_pin);
LL_GPIO_ResetOutputPin(pHandle->pwm_en_v_port, pHandle->pwm_en_v_pin);
LL_GPIO_ResetOutputPin(pHandle->pwm_en_w_port, pHandle->pwm_en_w_pin);
}
else
{
/* Nothing to do */
}
}
else
{
/* Nothing to do */
}
pHandle->OverCurrentFlag = true;
tempPointer = &(pHandle->Motor);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
return (tempPointer);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section(".ccmram")))
#endif
#endif
/*
* @brief manages driver protection.
*
* @param pHandle: Handler of the current instance of the PWM component.
*/
__weak void *PWMC_DP_Handler(PWMC_Handle_t *pHandle)
{
void *tempPointer; //cstat !MISRAC2012-Rule-8.13
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
tempPointer = MC_NULL;
}
else
{
#endif
if (false == pHandle->BrakeActionLock)
{
if (ES_GPIO == pHandle->LowSideOutputs)
{
LL_GPIO_ResetOutputPin(pHandle->pwm_en_u_port, pHandle->pwm_en_u_pin);
LL_GPIO_ResetOutputPin(pHandle->pwm_en_v_port, pHandle->pwm_en_v_pin);
LL_GPIO_ResetOutputPin(pHandle->pwm_en_w_port, pHandle->pwm_en_w_pin);
}
else
{
/* Nothing to do */
}
}
else
{
/* Nothing to do */
}
pHandle->driverProtectionFlag = true;
tempPointer = &(pHandle->Motor);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
return (tempPointer);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section(".ccmram")))
#endif
#endif
/*
* @brief Manages HW overvoltage protection.
*
* @param pHandle: Handler of the current instance of the PWM component.
* TIMx: timer used for PWM generation
*/
__weak void *PWMC_OVP_Handler(PWMC_Handle_t *pHandle, TIM_TypeDef *TIMx)
{
void *tempPointer; //cstat !MISRAC2012-Rule-8.13
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
tempPointer = MC_NULL;
}
else
{
#endif
TIMx->BDTR |= LL_TIM_OSSI_ENABLE;
pHandle->OverVoltageFlag = true;
pHandle->BrakeActionLock = true;
tempPointer = &(pHandle->Motor);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
return (tempPointer);
}
/*
* @brief Checks if an overcurrent occurred since last call.
*
* @param pHdl: Handler of the current instance of the PWM component.
* @retval uint16_t Returns #MC_OVER_CURR if an overcurrent has been
* detected since last method call, #MC_NO_FAULTS otherwise.
*/
__weak uint16_t PWMC_IsFaultOccurred(PWMC_Handle_t *pHandle)
{
uint16_t retVal = MC_NO_FAULTS;
if (true == pHandle->OverVoltageFlag)
{
retVal = MC_OVER_VOLT;
pHandle->OverVoltageFlag = false;
}
else
{
/* Nothing to do */
}
if (true == pHandle->OverCurrentFlag)
{
retVal |= MC_OVER_CURR;
pHandle->OverCurrentFlag = false;
}
else
{
/* Nothing to do */
}
if (true == pHandle->driverProtectionFlag)
{
retVal |= MC_DP_FAULT;
pHandle->driverProtectionFlag = false;
}
else
{
/* Nothing to do */
}
return (retVal);
}
/**
* @brief Sets the over current threshold through the DAC reference voltage.
*
* @param pHandle: Handler of the current instance of the PWM component.
* @param hDACVref: Value of DAC reference voltage to be applied expressed as a 16bit unsigned integer.
* Min value: 0 (0 V)
* Max value: 65536 (VDD_DAC)
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_OCPSetReferenceVoltage(PWMC_Handle_t *pHandle, uint16_t hDACVref)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if ((MC_NULL == pHandle) || (MC_NULL == pHandle->pFctOCPSetReferenceVoltage))
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctOCPSetReferenceVoltage(pHandle, hDACVref);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Retrieves the satus of TurnOnLowSides action.
*
* @param pHandle: Handler of the current instance of the PWMC component.
* @retval bool State of TurnOnLowSides action:
* **true** if TurnOnLowSides action is active, **false** otherwise.
*/
__weak bool PWMC_GetTurnOnLowSidesAction(const PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
return ((MC_NULL == pHandle) ? false : pHandle->TurnOnLowSidesAction);
#else
return (pHandle->TurnOnLowSidesAction);
#endif
}
/** @brief Enables Discontinuous PWM mode using the @p pHandle PWMC component.
*
*/
__weak void PWMC_DPWM_ModeEnable(PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->DPWM_Mode = true;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/** @brief Disables Discontinuous PWM mode using the @p pHandle PWMC component.
*
*/
__weak void PWMC_DPWM_ModeDisable(PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->DPWM_Mode = false;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/** @brief Returns the status of the Discontinuous PWM Mode stored in the @p pHandle PWMC component.
*
* @retval true if DPWM Mode is enabled, **false** otherwise.
*/
//cstat !MISRAC2012-Rule-8.13
__weak bool PWMC_GetDPWM_Mode(PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
return ((MC_NULL == pHandle) ? false : pHandle->DPWM_Mode);
#else
return (pHandle->DPWM_Mode);
#endif
}
/** @brief Enables the RL detection mode by calling the function in @p pHandle PWMC component.
*
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_RLDetectionModeEnable(PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if ((MC_NULL == pHandle) || ( MC_NULL == pHandle->pFctRLDetectionModeEnable))
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctRLDetectionModeEnable(pHandle);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/** @brief Disables the RL detection mode by calling the function in @p pHandle PWMC component.
*
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_RLDetectionModeDisable(PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if ((MC_NULL == pHandle) || ( MC_NULL == pHandle->pFctRLDetectionModeDisable))
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctRLDetectionModeDisable(pHandle);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the PWM duty cycle to apply in the RL Detection mode.
*
* @param pHandle: Handler of the current instance of the PWMC component.
* @param hDuty: Duty cycle to apply, written in uint16_t.
* @retval #MC_NO_ERROR if the Duty Cycle could be applied on time for the next PWM period.
* Returns #MC_DURATION otherwise.
*/
__weak uint16_t PWMC_RLDetectionModeSetDuty(PWMC_Handle_t *pHandle, uint16_t hDuty) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
uint16_t retVal = MC_DURATION;
if ((MC_NULL == pHandle) || ( MC_NULL == pHandle->pFctRLDetectionModeSetDuty))
{
/* Nothing to do */
}
else
{
retVal = pHandle->pFctRLDetectionModeSetDuty(pHandle, hDuty);
}
return (retVal);
#else
return (pHandle->pFctRLDetectionModeSetDuty(pHandle, hDuty));
#endif
}
/** @brief Turns on low sides switches and starts ADC triggerin.
*
*/
//cstat !MISRAC2012-Rule-8.13 !RED-func-no-effect
__weak void PWMC_RLTurnOnLowSidesAndStart(PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if ((MC_NULL == pHandle) || ( MC_NULL == pHandle->pFctRLTurnOnLowSidesAndStart))
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctRLTurnOnLowSidesAndStart(pHandle);
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the aligned motor flag.
*
* @param pHandle: Handler of the current instance of the PWMC component.
* @param flag: Value to be applied as an 8 bit unsigned integer.
* 1: motor is in aligned stage.
* 2: motor is not in aligned stage.
*/
void PWMC_SetAlignFlag(PWMC_Handle_t *pHandle, uint8_t flag)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->AlignFlag = flag;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to get phases current.
*
* @param pCallBack: Pointer on the callback to get the phase current.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterGetPhaseCurrentsCallBack(PWMC_GetPhaseCurr_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctGetPhaseCurrents = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to switch PWM
* generation off.
*
* @param pCallBack: Pointer on the generic callback.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterSwitchOffPwmCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctSwitchOffPwm = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to switch PWM
* generation on.
*
* @param pCallBack: Pointer on the generic callback.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterSwitchonPwmCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctSwitchOnPwm = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to execute a calibration
* of the current sensing system.
*
* @param pCallBack: Pointer on the generic callback.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterReadingCalibrationCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctCurrReadingCalib = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to turn low sides on.
*
* @param pCallBack: Pointer on the callback which turns low sides on.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterTurnOnLowSidesCallBack(PWMC_TurnOnLowSides_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctTurnOnLowSides = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to compute ADC sampling point.
*
* @param pCallBack: Pointer on the callback which sets the sampling point depending on the sector.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterSampPointSectXCallBack(PWMC_SetSampPointSectX_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctSetADCSampPointSectX = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to set the reference
* voltage for the overcurrent protection.
*
* @param pCallBack: Pointer on the callback which sets the reference voltage.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterOCPSetRefVoltageCallBack(PWMC_SetOcpRefVolt_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctOCPSetReferenceVoltage = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to enable the R/L detection mode.
*
* @param pCallBack: Pointer on the generic callback.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterRLDetectionModeEnableCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctRLDetectionModeEnable = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to disable the R/L detection mode.
*
* @param pCallBack: Pointer on the generic callback.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterRLDetectionModeDisableCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctRLDetectionModeDisable = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @brief Sets the Callback that the PWMC component shall invoke to set the duty cycle
* for the R/L detection mode.
*
* @param pCallBack: Pointer on the callback which sets the duty cycle.
* @param pHandle: Handler of the current instance of the PWMC component.
*/
__weak void PWMC_RegisterRLDetectionModeSetDutyCallBack(PWMC_RLDetectSetDuty_Cb_t pCallBack, PWMC_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFctRLDetectionModeSetDuty = pCallBack;
#ifdef NULL_PTR_CHECK_PWR_CUR_FDB
}
#endif
}
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 33,050 | C | 25.82711 | 142 | 0.634221 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/network_data.c | /**
******************************************************************************
* @file network_data.c
* @author AST Embedded Analytics Research Platform
* @date Tue Jan 16 16:02:48 2024
* @brief AI Tool Automatic Code Generator for Embedded NN computing
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
******************************************************************************
*/
#include "network_data.h"
#include "ai_platform_interface.h"
AI_API_DECLARE_BEGIN
ai_buffer g_network_data_map_activations[AI_NETWORK_DATA_ACTIVATIONS_COUNT] = {
AI_BUFFER_INIT(AI_FLAG_NONE, AI_BUFFER_FORMAT_U8,
AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, 1048, 1, 1),
1048, NULL, NULL), /* heap_overlay_pool */
};
ai_buffer g_network_data_map_weights[AI_NETWORK_DATA_WEIGHTS_COUNT] = {
AI_BUFFER_INIT(AI_FLAG_NONE, AI_BUFFER_FORMAT_U8,
AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, 44840, 1, 1),
44840, NULL, s_network_weights_array_u64), /* weights_array */
};
/*!
* @brief Get network activations buffer initialized struct.
* @ingroup network_data
* @param[in] ptr a pointer to the activations array storage area
* @return an ai_buffer initialized struct
*/
AI_DEPRECATED
AI_API_ENTRY
ai_buffer ai_network_data_activations_buffer_get(const ai_handle ptr)
{
ai_buffer buf = AI_BUFFER_INIT(
AI_FLAG_NONE, AI_BUFFER_FORMAT_U8,
AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, AI_NETWORK_DATA_ACTIVATIONS_SIZE, 1, AI_NETWORK_DATA_ACTIVATIONS_COUNT),
AI_NETWORK_DATA_ACTIVATIONS_SIZE,
NULL, ptr);
return buf;
}
/*!
* @brief Get network weights buffer initialized struct.
* @ingroup network_data
* @param[in] ptr a pointer to the weights array storage area
* @return an ai_buffer initialized struct
*/
AI_DEPRECATED
AI_API_ENTRY
ai_buffer ai_network_data_weights_buffer_get(const ai_handle ptr)
{
ai_buffer buf = AI_BUFFER_INIT(
AI_FLAG_NONE, AI_BUFFER_FORMAT_U8|AI_BUFFER_FMT_FLAG_CONST,
AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, AI_NETWORK_DATA_WEIGHTS_SIZE, 1, AI_NETWORK_DATA_WEIGHTS_COUNT),
AI_NETWORK_DATA_WEIGHTS_SIZE,
NULL, ptr);
return buf;
}
/*!
* @brief Get network weights array pointer as a handle ptr.
* @ingroup network_data
* @return a ai_handle pointer to the weights array
*/
AI_DEPRECATED
AI_API_ENTRY
ai_handle ai_network_data_weights_get(void)
{
return AI_HANDLE_PTR(g_network_weights_table);
}
/*!
* @brief Get network params configuration data structure.
* @ingroup network_data
* @return true if a valid configuration is present, false otherwise
*/
AI_API_ENTRY
ai_bool ai_network_data_params_get(ai_network_params* params)
{
if (!params) return false;
const ai_buffer_array map_activations =
AI_BUFFER_ARRAY_OBJ_INIT(AI_FLAG_NONE, AI_NETWORK_DATA_ACTIVATIONS_COUNT, g_network_data_map_activations);
const ai_buffer_array map_weights =
AI_BUFFER_ARRAY_OBJ_INIT(AI_FLAG_NONE, AI_NETWORK_DATA_WEIGHTS_COUNT, g_network_data_map_weights);
return ai_platform_bind_network_params(params, &map_weights, &map_activations);
}
AI_API_DECLARE_END
| 3,411 | C | 31.188679 | 118 | 0.662269 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/system_stm32g4xx.c | /**
******************************************************************************
* @file system_stm32g4xx.c
* @author MCD Application Team
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File
*
* This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32g4xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* After each device reset the HSI (16 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32g4xx.s" file, to
* configure the system clock before to branch to main program.
*
* This file configures the system clock as follows:
*=============================================================================
*-----------------------------------------------------------------------------
* System Clock source | HSI
*-----------------------------------------------------------------------------
* SYSCLK(Hz) | 16000000
*-----------------------------------------------------------------------------
* HCLK(Hz) | 16000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 1
*-----------------------------------------------------------------------------
* APB2 Prescaler | 1
*-----------------------------------------------------------------------------
* PLL_M | 1
*-----------------------------------------------------------------------------
* PLL_N | 16
*-----------------------------------------------------------------------------
* PLL_P | 7
*-----------------------------------------------------------------------------
* PLL_Q | 2
*-----------------------------------------------------------------------------
* PLL_R | 2
*-----------------------------------------------------------------------------
* Require 48MHz for RNG | Disabled
*-----------------------------------------------------------------------------
*=============================================================================
******************************************************************************
* @attention
*
* Copyright (c) 2019 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32g4xx_system
* @{
*/
/** @addtogroup STM32G4xx_System_Private_Includes
* @{
*/
#include "stm32g4xx.h"
#if !defined (HSE_VALUE)
#define HSE_VALUE 24000000U /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @}
*/
/** @addtogroup STM32G4xx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32G4xx_System_Private_Defines
* @{
*/
/************************* Miscellaneous Configuration ************************/
/* Note: Following vector table addresses must be defined in line with linker
configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
anywhere in Flash or Sram, else the vector table is kept at the automatic
remap of boot address selected */
/* #define USER_VECT_TAB_ADDRESS */
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
/******************************************************************************/
/**
* @}
*/
/** @addtogroup STM32G4xx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32G4xx_System_Private_Variables
* @{
*/
/* The SystemCoreClock variable is updated in three ways:
1) by calling CMSIS function SystemCoreClockUpdate()
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
Note: If you use this function to configure the system clock; then there
is no need to call the 2 first functions listed above, since SystemCoreClock
variable is updated automatically.
*/
uint32_t SystemCoreClock = HSI_VALUE;
const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
/**
* @}
*/
/** @addtogroup STM32G4xx_System_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @addtogroup STM32G4xx_System_Private_Functions
* @{
*/
/**
* @brief Setup the microcontroller system.
* @param None
* @retval None
*/
void SystemInit(void)
{
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */
#endif
/* Configure the Vector Table location add offset address ------------------*/
#if defined(USER_VECT_TAB_ADDRESS)
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
}
/**
* @brief Update SystemCoreClock variable according to Clock Register Values.
* The SystemCoreClock variable contains the core clock (HCLK), it can
* be used by the user application to setup the SysTick timer or configure
* other parameters.
*
* @note Each time the core clock (HCLK) changes, this function must be called
* to update SystemCoreClock variable value. Otherwise, any configuration
* based on this variable will be incorrect.
*
* @note - The system frequency computed by this function is not the real
* frequency in the chip. It is calculated based on the predefined
* constant and the selected clock source:
*
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
*
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
*
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
* or HSI_VALUE(*) multiplied/divided by the PLL factors.
*
* (**) HSI_VALUE is a constant defined in stm32g4xx_hal.h file (default value
* 16 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (***) HSE_VALUE is a constant defined in stm32g4xx_hal.h file (default value
* 24 MHz), user has to ensure that HSE_VALUE is same as the real
* frequency of the crystal used. Otherwise, this function may
* have wrong result.
*
* - The result of this function could be not correct when using fractional
* value for HSE crystal.
*
* @param None
* @retval None
*/
void SystemCoreClockUpdate(void)
{
uint32_t tmp, pllvco, pllr, pllsource, pllm;
/* Get SYSCLK source -------------------------------------------------------*/
switch (RCC->CFGR & RCC_CFGR_SWS)
{
case 0x04: /* HSI used as system clock source */
SystemCoreClock = HSI_VALUE;
break;
case 0x08: /* HSE used as system clock source */
SystemCoreClock = HSE_VALUE;
break;
case 0x0C: /* PLL used as system clock source */
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
SYSCLK = PLL_VCO / PLLR
*/
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4) + 1U ;
if (pllsource == 0x02UL) /* HSI used as PLL clock source */
{
pllvco = (HSI_VALUE / pllm);
}
else /* HSE used as PLL clock source */
{
pllvco = (HSE_VALUE / pllm);
}
pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8);
pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25) + 1U) * 2U;
SystemCoreClock = pllvco/pllr;
break;
default:
break;
}
/* Compute HCLK clock frequency --------------------------------------------*/
/* Get HCLK prescaler */
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
/* HCLK clock frequency */
SystemCoreClock >>= tmp;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
| 10,571 | C | 35.965035 | 101 | 0.4781 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mc_perf.c | /**
******************************************************************************
* @file mc_perf.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief Execution time measurement
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#include "parameters_conversion.h"
#include "mc_perf.h"
void MC_Perf_Measure_Init(MC_Perf_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_MC_PERF
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
uint8_t i;
Perf_Handle_t *pHdl;
/* Set Debug mod for DWT IP Enabling */
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
if (DWT->CTRL != 0U)
{ /* Check if DWT is present. */
DWT->CYCCNT = 0;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; /* Enable Cycle Counter. */
}
else
{
/* Nothing to do */
}
for (i = 0U; i < MC_PERF_NB_TRACES; i++)
{
pHdl = &pHandle->MC_Perf_TraceLog[i];
pHdl->StartMeasure = 0;
pHdl->DeltaTimeInCycle = 0;
pHdl->min = UINT32_MAX;
pHdl->max = 0;
}
pHandle->BG_Task_OnGoing = false;
pHandle->AccHighFreqTasksCnt = 0;
#ifdef NULL_PTR_CHECK_MC_PERF
}
#endif
}
void MC_Perf_Clear(MC_Perf_Handle_t *pHandle,uint8_t bMotor)
{
#ifdef NULL_PTR_CHECK_MC_PERF
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
uint8_t i;
Perf_Handle_t *pHdl;
for (i = 0U; i < 2; i++)
{
pHdl = &pHandle->MC_Perf_TraceLog[2*bMotor+i];
pHdl->DeltaTimeInCycle = 0;
pHdl->min = UINT32_MAX;
pHdl->max = 0;
}
#ifdef NULL_PTR_CHECK_MC_PERF
}
#endif
}
/**
* @brief Start the measure of a code section called in foreground.
* @param pHandle: handler of the performance measurement component.
* @param CodeSection: code section to measure.
*/
void MC_Perf_Measure_Start(MC_Perf_Handle_t *pHandle, uint8_t CodeSection)
{
#ifdef NULL_PTR_CHECK_MC_PERF
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
uint32_t StartMeasure = DWT->CYCCNT;
pHandle->MC_Perf_TraceLog[CodeSection].StartMeasure = StartMeasure;
#ifdef NULL_PTR_CHECK_MC_PERF
}
#endif
}
/**
* @brief Start the measure of a code section called in background.
* @param pHandle: handler of the performance measurement component.
* @param CodeSection: code section to measure.
*/
void MC_BG_Perf_Measure_Start(MC_Perf_Handle_t *pHandle, uint8_t CodeSection)
{
#ifdef NULL_PTR_CHECK_MC_PERF
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->BG_Task_OnGoing = true;
pHandle->AccHighFreqTasksCnt = 0;
uint32_t StartMeasure = DWT->CYCCNT;
pHandle->MC_Perf_TraceLog[CodeSection].StartMeasure = StartMeasure;
#ifdef NULL_PTR_CHECK_MC_PERF
}
#endif
}
/**
* @brief Stop the measurement of a code section and compute elapse time.
* @param pHandle: handler of the performance measurement component.
* @param CodeSection: code section to measure.
*/
void MC_Perf_Measure_Stop(MC_Perf_Handle_t *pHandle, uint8_t CodeSection)
{
#ifdef NULL_PTR_CHECK_MC_PERF
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
uint32_t StopMeasure;
Perf_Handle_t *pHdl;
StopMeasure = DWT->CYCCNT;
pHdl = &pHandle->MC_Perf_TraceLog[CodeSection];
/* Check Overflow cases */
if (StopMeasure < pHdl->StartMeasure)
{
pHdl->DeltaTimeInCycle = (UINT32_MAX - pHdl->StartMeasure) + StopMeasure;
}
else
{
pHdl->DeltaTimeInCycle = StopMeasure - pHdl->StartMeasure;
}
if(pHandle->BG_Task_OnGoing)
{
pHandle->AccHighFreqTasksCnt += pHdl->DeltaTimeInCycle;
}
else
{
/* Nothing to do */
}
if (pHdl->max < pHdl->DeltaTimeInCycle)
{
pHdl->max = pHdl->DeltaTimeInCycle;
}
else
{
/* Nothing to do */
}
if (pHdl->min > pHdl->DeltaTimeInCycle)
{
pHdl->min = pHdl->DeltaTimeInCycle;
}
else
{
/* Nothing to do */
}
#ifdef NULL_PTR_CHECK_MC_PERF
}
#endif
}
/**
* @brief Stop the measurement of a code section in BG and compute elapse time.
* @param pHandle: handler of the performance measurement component.
* @param CodeSection: code section to measure.
*/
void MC_BG_Perf_Measure_Stop(MC_Perf_Handle_t *pHandle, uint8_t CodeSection)
{
#ifdef NULL_PTR_CHECK_MC_PERF
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
Perf_Handle_t *pHdl;
uint32_t StopMeasure = DWT->CYCCNT;
pHandle->BG_Task_OnGoing = false;
pHdl = &pHandle->MC_Perf_TraceLog[CodeSection];
/* Check Overflow cases */
if (StopMeasure < pHdl->StartMeasure)
{
pHdl->DeltaTimeInCycle = (UINT32_MAX - pHdl->StartMeasure) + StopMeasure;
}
else
{
pHdl->DeltaTimeInCycle = StopMeasure - pHdl->StartMeasure;
}
if (pHdl->DeltaTimeInCycle > pHandle->AccHighFreqTasksCnt)
{
pHdl->DeltaTimeInCycle -= pHandle->AccHighFreqTasksCnt;
}
else
{
/* Nothing to do */
}
if (pHdl->max < pHdl->DeltaTimeInCycle)
{
pHdl->max = pHdl->DeltaTimeInCycle;
}
else
{
/* Nothing to do */
}
if (pHdl->min > pHdl->DeltaTimeInCycle)
{
pHdl->min = pHdl->DeltaTimeInCycle;
}
else
{
/* Nothing to do */
}
#ifdef NULL_PTR_CHECK_MC_PERF
}
#endif
}
/**
* @brief It returns the current CPU load of both High and Medium frequency tasks.
* @param pHandle: handler of the performance measurement component.
* @retval CPU load.
*/
float_t MC_Perf_GetCPU_Load(const MC_Perf_Handle_t *pHandle)
{
float_t cpuLoad = 0.0f;
#ifdef NULL_PTR_CHECK_MC_PERF
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
float_t MFT_cpu_loadM1;
float_t HFT_cpu_loadM1;
MFT_cpu_loadM1 = (((float_t)pHandle->MC_Perf_TraceLog[MEASURE_TSK_MediumFrequencyTaskM1].DeltaTimeInCycle\
/ (float_t)SYSCLK_FREQ ) * (float_t)MEDIUM_FREQUENCY_TASK_RATE);
HFT_cpu_loadM1 = (((float_t)pHandle->MC_Perf_TraceLog[MEASURE_TSK_HighFrequencyTaskM1].DeltaTimeInCycle\
/ (float_t)SYSCLK_FREQ ) * (float_t)(PWM_FREQUENCY/REGULATION_EXECUTION_RATE));
cpuLoad = MFT_cpu_loadM1 + HFT_cpu_loadM1;
cpuLoad = (cpuLoad > 1.0f) ? 1.0f : cpuLoad;
cpuLoad *= 100.0f;
#ifdef NULL_PTR_CHECK_MC_PERF
}
#endif
return (cpuLoad);
}
/**
* @brief It returns the maximum CPU load of both High and Medium frequency tasks.
* @param pHandle: handler of the performance measurement component.
* @retval Max CPU load measured.
*/
float_t MC_Perf_GetMaxCPU_Load(const MC_Perf_Handle_t *pHandle)
{
float_t cpuLoad = 0.0f;
#ifdef NULL_PTR_CHECK_MC_PERF
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
cpuLoad += (((float_t)pHandle->MC_Perf_TraceLog[MEASURE_TSK_MediumFrequencyTaskM1].max / (float_t)SYSCLK_FREQ )\
* (float_t)MEDIUM_FREQUENCY_TASK_RATE);
cpuLoad += (((float_t)pHandle->MC_Perf_TraceLog[MEASURE_TSK_HighFrequencyTaskM1].max / (float_t)SYSCLK_FREQ )\
* (float_t)(PWM_FREQUENCY/REGULATION_EXECUTION_RATE));
cpuLoad = (cpuLoad > 1.0f) ? 1.0f : cpuLoad;
cpuLoad *= 100.0f;
#ifdef NULL_PTR_CHECK_MC_PERF
}
#endif
return (cpuLoad);
}
/**
* @brief It returns the minimum CPU load of both High and Medium frequency tasks.
* @param pHandle: handler of the performance measurement component.
* @retval Min CPU load measured.
*/
float_t MC_Perf_GetMinCPU_Load(const MC_Perf_Handle_t *pHandle)
{
float_t cpu_load_acc = 0.0f;
#ifdef NULL_PTR_CHECK_MC_PERF
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if (pHandle->MC_Perf_TraceLog[MEASURE_TSK_MediumFrequencyTaskM1].min != UINT32_MAX)
{
cpu_load_acc += (((float_t)pHandle->MC_Perf_TraceLog[MEASURE_TSK_MediumFrequencyTaskM1].min / (float_t)SYSCLK_FREQ )\
* (float_t)MEDIUM_FREQUENCY_TASK_RATE);
}
if (pHandle->MC_Perf_TraceLog[MEASURE_TSK_HighFrequencyTaskM1].min != UINT32_MAX)
{
cpu_load_acc += (((float_t)pHandle->MC_Perf_TraceLog[MEASURE_TSK_HighFrequencyTaskM1].min / (float_t)SYSCLK_FREQ )\
* (float_t)(PWM_FREQUENCY/REGULATION_EXECUTION_RATE));
}
cpu_load_acc = (cpu_load_acc > 1.0f) ? 1.0f : cpu_load_acc;
cpu_load_acc *= 100.0f;
#ifdef NULL_PTR_CHECK_MC_PERF
}
#endif
return (cpu_load_acc);
}
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 9,002 | C | 24.289326 | 123 | 0.610087 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/motorcontrol.c | /**
******************************************************************************
* @file motorcontrol.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief Motor Control Subsystem initialization functions.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCInterface
*/
//cstat -MISRAC2012-Rule-21.1
#include "main.h"
//cstat +MISRAC2012-Rule-21.1
#include "mc_interface.h"
#include "mc_tasks.h"
#include "motorcontrol.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MCInterface
* @{
*/
MCI_Handle_t* pMCI[NBR_OF_MOTORS];
/**
* @brief Initializes and configures the Motor Control Subsystem
*
* This function initializes and configures all the structures and components needed
* for the Motor Control subsystem required by the Application. It expects that
* all the peripherals needed for Motor Control purposes are already configured but
* that their interrupts are not enabled yet.
*
* CubeMX calls this function after all peripherals initializations and
* before the NVIC is configured
*/
__weak void MX_MotorControl_Init(void)
{
/* Reconfigure the SysTick interrupt to fire every 500 us. */
(void)HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / SYS_TICK_FREQUENCY);
HAL_NVIC_SetPriority(SysTick_IRQn, uwTickPrio, 0U);
/* Initialize the Motor Control Subsystem */
MCboot(pMCI);
mc_lock_pins();
}
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 1,996 | C | 27.942029 | 85 | 0.598697 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/stm32g4xx_hal_msp.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g4xx_hal_msp.c
* @brief This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_3);
/* System interrupt init*/
/** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
*/
HAL_PWREx_DisableUCPDDeadBattery();
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
| 2,323 | C | 25.112359 | 80 | 0.462333 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/app_x-cube-ai.c |
/**
******************************************************************************
* @file app_x-cube-ai.c
* @author X-CUBE-AI C code generator
* @brief AI program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/*
* Description
* v1.0 - Minimum template to show how to use the Embedded Client API
* model. Only one input and one output is supported. All
* memory resources are allocated statically (AI_NETWORK_XX, defines
* are used).
* Re-target of the printf function is out-of-scope.
* v2.0 - add multiple IO and/or multiple heap support
*
* For more information, see the embeded documentation:
*
* [1] %X_CUBE_AI_DIR%/Documentation/index.html
*
* X_CUBE_AI_DIR indicates the location where the X-CUBE-AI pack is installed
* typical : C:\Users\<user_name>\STM32Cube\Repository\STMicroelectronics\X-CUBE-AI\7.1.0
*/
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#elif defined ( __CC_ARM ) || ( __GNUC__ )
#endif
/* System headers */
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include "app_x-cube-ai.h"
#include "main.h"
#include "ai_datatypes_defines.h"
#include "network.h"
#include "network_data.h"
/* USER CODE BEGIN includes */
/* USER CODE END includes */
/* IO buffers ----------------------------------------------------------------*/
#if !defined(AI_NETWORK_INPUTS_IN_ACTIVATIONS)
AI_ALIGNED(4) ai_i8 data_in_1[AI_NETWORK_IN_1_SIZE_BYTES];
ai_i8* data_ins[AI_NETWORK_IN_NUM] = {
data_in_1
};
#else
ai_i8* data_ins[AI_NETWORK_IN_NUM] = {
NULL
};
#endif
#if !defined(AI_NETWORK_OUTPUTS_IN_ACTIVATIONS)
AI_ALIGNED(4) ai_i8 data_out_1[AI_NETWORK_OUT_1_SIZE_BYTES];
AI_ALIGNED(4) ai_i8 data_out_2[AI_NETWORK_OUT_2_SIZE_BYTES];
AI_ALIGNED(4) ai_i8 data_out_3[AI_NETWORK_OUT_3_SIZE_BYTES];
ai_i8* data_outs[AI_NETWORK_OUT_NUM] = {
data_out_1,
data_out_2,
data_out_3
};
#else
ai_i8* data_outs[AI_NETWORK_OUT_NUM] = {
NULL,
NULL,
NULL
};
#endif
/* Activations buffers -------------------------------------------------------*/
AI_ALIGNED(32)
static uint8_t pool0[AI_NETWORK_DATA_ACTIVATION_1_SIZE];
ai_handle data_activations0[] = {pool0};
/* AI objects ----------------------------------------------------------------*/
static ai_handle network = AI_HANDLE_NULL;
static ai_buffer* ai_input;
static ai_buffer* ai_output;
static void ai_log_err(const ai_error err, const char *fct)
{
/* USER CODE BEGIN log */
if (fct)
printf("TEMPLATE - Error (%s) - type=0x%02x code=0x%02x\r\n", fct,
err.type, err.code);
else
printf("TEMPLATE - Error - type=0x%02x code=0x%02x\r\n", err.type, err.code);
do {} while (1);
/* USER CODE END log */
}
static int ai_boostrap(ai_handle *act_addr)
{
ai_error err;
/* Create and initialize an instance of the model */
err = ai_network_create_and_init(&network, act_addr, NULL);
if (err.type != AI_ERROR_NONE) {
ai_log_err(err, "ai_network_create_and_init");
return -1;
}
ai_input = ai_network_inputs_get(network, NULL);
ai_output = ai_network_outputs_get(network, NULL);
#if defined(AI_NETWORK_INPUTS_IN_ACTIVATIONS)
/* In the case where "--allocate-inputs" option is used, memory buffer can be
* used from the activations buffer. This is not mandatory.
*/
for (int idx=0; idx < AI_NETWORK_IN_NUM; idx++) {
data_ins[idx] = ai_input[idx].data;
}
#else
for (int idx=0; idx < AI_NETWORK_IN_NUM; idx++) {
ai_input[idx].data = data_ins[idx];
}
#endif
#if defined(AI_NETWORK_OUTPUTS_IN_ACTIVATIONS)
/* In the case where "--allocate-outputs" option is used, memory buffer can be
* used from the activations buffer. This is no mandatory.
*/
for (int idx=0; idx < AI_NETWORK_OUT_NUM; idx++) {
data_outs[idx] = ai_output[idx].data;
}
#else
for (int idx=0; idx < AI_NETWORK_OUT_NUM; idx++) {
ai_output[idx].data = data_outs[idx];
}
#endif
return 0;
}
static int ai_run(void)
{
ai_i32 batch;
batch = ai_network_run(network, ai_input, ai_output);
if (batch != 1) {
ai_log_err(ai_network_get_error(network),
"ai_network_run");
return -1;
}
return 0;
}
/* USER CODE BEGIN 2 */
extern ai_float in_data1[AI_NETWORK_IN_1_SIZE];
extern ai_float out_data1[AI_NETWORK_OUT_1_SIZE];
extern ai_float out_data2[AI_NETWORK_OUT_2_SIZE];
extern ai_float out_data3[AI_NETWORK_OUT_3_SIZE];
int acquire_and_process_data(ai_i8* data[])
{
/* process the predictions
for (int idx=0; idx < AI_NETWORK_OUT_NUM; idx++ )
{
data[idx] = ....
}
*/
// Cast data_ins[0] to a pointer of type ai_float*
memcpy(data[0], in_data1, AI_NETWORK_IN_1_SIZE * sizeof(ai_float));
return 0;
}
int post_process(ai_i8* data[])
{
/* process the predictions
for (int idx=0; idx < AI_NETWORK_OUT_NUM; idx++ )
{
data[idx] = ....
}
*/
memcpy(out_data1, data[0], AI_NETWORK_OUT_1_SIZE * sizeof(ai_float));
memcpy(out_data2, data[1], AI_NETWORK_OUT_2_SIZE * sizeof(ai_float));
memcpy(out_data3, data[2], AI_NETWORK_OUT_3_SIZE * sizeof(ai_float));
return 0;
}
/* USER CODE END 2 */
/* Entry points --------------------------------------------------------------*/
void MX_X_CUBE_AI_Init(void)
{
/* USER CODE BEGIN 5 */
printf("\r\nTEMPLATE - initialization\r\n");
ai_boostrap(data_activations0);
/* USER CODE END 5 */
}
void MX_X_CUBE_AI_Process(void)
{
/* USER CODE BEGIN 6 */
int res = -1;
printf("TEMPLATE - run - main loop\r\n");
if (network) {
/* 1 - acquire and pre-process input data */
res = acquire_and_process_data(data_ins);
/* 2 - process the data - call inference engine */
if (res == 0)
res = ai_run();
/* 3- post-process the predictions */
if (res == 0)
res = post_process(data_outs);
}
if (res) {
ai_error err = {AI_ERROR_INVALID_STATE, AI_ERROR_CODE_NETWORK};
ai_log_err(err, "Process has FAILED");
}
/* USER CODE END 6 */
}
#ifdef __cplusplus
}
#endif
| 6,498 | C | 24.486274 | 92 | 0.586642 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mc_configuration_registers.c |
/**
******************************************************************************
* @file mc_configuration_registers.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides project configuration information registers.
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#include "mc_type.h"
#include "mc_configuration_registers.h"
#include "register_interface.h"
#include "parameters_conversion.h"
#define FIRMWARE_NAME_STR "ST MC SDK\tVer.6.2.0"
const char_t CTL_BOARD[] = "NUCLEO-G474RE";
static const char_t M1_PWR_BOARD[] = "~BOOSTXL-DRV8323Rx";
const char_t FIRMWARE_NAME [] = FIRMWARE_NAME_STR;
const GlobalConfig_reg_t globalConfig_reg =
{
.SDKVersion = SDK_VERSION,
.MotorNumber = 1 ,
.MCP_Flag = FLAG_MCP_OVER_STLINK + FLAG_MCP_OVER_UARTA + FLAG_MCP_OVER_UARTB,
.MCPA_UARTA_LOG = 10,
.MCPA_UARTB_LOG = 0,
.MCPA_STLNK_LOG = 0,
};
static const ApplicationConfig_reg_t M1_ApplicationConfig_reg =
{
.maxMechanicalSpeed = 2478,
.maxReadableCurrent = M1_MAX_READABLE_CURRENT,
.nominalCurrent = 10,
.nominalVoltage = 30,
.driveType = DRIVE_TYPE_M1,
};
//cstat !MISRAC2012-Rule-9.2
static const MotorConfig_reg_t M1_MotorConfig_reg =
{
.polePairs = 14,
.ratedFlux = 5.2,
.rs = 0.15,
.ls = 0.00006*1.000,
.ld = 0.00006,
.maxCurrent = 10,
.name = "MN5008"
};
static const FOCFwConfig_reg_t M1_FOCConfig_reg =
{
.primarySensor = (uint8_t)PRIM_SENSOR_M1,
.auxiliarySensor = (uint8_t)AUX_SENSOR_M1,
.topology = (uint8_t)TOPOLOGY_M1,
.FOCRate = (uint8_t)FOC_RATE_M1,
.PWMFrequency = (uint32_t)PWM_FREQ_M1,
.MediumFrequency = (uint16_t)MEDIUM_FREQUENCY_TASK_RATE,
.configurationFlag1 = (uint16_t)configurationFlag1_M1, //cstat !MISRAC2012-Rule-10.1_R6
.configurationFlag2 = (uint16_t)configurationFlag2_M1, //cstat !MISRAC2012-Rule-10.1_R6
};
const char_t * PWR_BOARD_NAME[NBR_OF_MOTORS] = {M1_PWR_BOARD};
const FOCFwConfig_reg_t* FOCConfig_reg[NBR_OF_MOTORS] = {&M1_FOCConfig_reg};
const MotorConfig_reg_t* MotorConfig_reg[NBR_OF_MOTORS] = {&M1_MotorConfig_reg};
const ApplicationConfig_reg_t* ApplicationConfig_reg[NBR_OF_MOTORS] = {&M1_ApplicationConfig_reg};
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 2,860 | C | 33.469879 | 98 | 0.606294 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/stm32g4xx_mc_it.c |
/**
******************************************************************************
* @file stm32g4xx_mc_it.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief Main Interrupt Service Routines.
* This file provides exceptions handler and peripherals interrupt
* service routine related to Motor Control for the STM32G4 Family.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup STM32G4xx_IRQ_Handlers
*/
/* Includes ------------------------------------------------------------------*/
#include "mc_config.h"
#include "mc_type.h"
//cstat -MISRAC2012-Rule-3.1
#include "mc_tasks.h"
//cstat +MISRAC2012-Rule-3.1
#include "motorcontrol.h"
#include "stm32g4xx_ll_exti.h"
#include "stm32g4xx_hal.h"
#include "stm32g4xx.h"
#include "mcp_config.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup STM32G4xx_IRQ_Handlers STM32G4xx IRQ Handlers
* @{
*/
/* USER CODE BEGIN PRIVATE */
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define SYSTICK_DIVIDER (SYS_TICK_FREQUENCY/1000U)
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* USER CODE END PRIVATE */
/* Public prototypes of IRQ handlers called from assembly code ---------------*/
void ADC1_2_IRQHandler(void);
void TIMx_UP_M1_IRQHandler(void);
void TIMx_BRK_M1_IRQHandler(void);
void SPD_TIM_M1_IRQHandler(void);
void HardFault_Handler(void);
void SysTick_Handler(void);
void EXTI15_10_IRQHandler(void);
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section (".ccmram")))
#endif
#endif
/**
* @brief This function handles ADC1/ADC2 interrupt request.
* @param None
*/
void ADC1_2_IRQHandler(void)
{
/* USER CODE BEGIN ADC1_2_IRQn 0 */
/* USER CODE END ADC1_2_IRQn 0 */
/* Clear Flags M1 */
LL_ADC_ClearFlag_JEOS(ADC1);
(void)TSK_HighFrequencyTask();
/* USER CODE BEGIN HighFreq */
/* USER CODE END HighFreq */
/* USER CODE BEGIN ADC1_2_IRQn 1 */
/* USER CODE END ADC1_2_IRQn 1 */
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section (".ccmram")))
#endif
#endif
/**
* @brief This function handles first motor TIMx Update interrupt request.
* @param None
*/
void TIMx_UP_M1_IRQHandler(void)
{
/* USER CODE BEGIN TIMx_UP_M1_IRQn 0 */
/* USER CODE END TIMx_UP_M1_IRQn 0 */
LL_TIM_ClearFlag_UPDATE(TIM1);
(void)R3_1_TIMx_UP_IRQHandler(&PWM_Handle_M1);
/* USER CODE BEGIN TIMx_UP_M1_IRQn 1 */
/* USER CODE END TIMx_UP_M1_IRQn 1 */
}
void TIMx_BRK_M1_IRQHandler(void)
{
/* USER CODE BEGIN TIMx_BRK_M1_IRQn 0 */
/* USER CODE END TIMx_BRK_M1_IRQn 0 */
if (0U == LL_TIM_IsActiveFlag_BRK(TIM1))
{
/* Nothing to do */
}
else
{
LL_TIM_ClearFlag_BRK(TIM1);
PWMC_OVP_Handler(&PWM_Handle_M1._Super, TIM1);
}
if (0U == LL_TIM_IsActiveFlag_BRK2(TIM1))
{
/* Nothing to do */
}
else
{
LL_TIM_ClearFlag_BRK2(TIM1);
PWMC_OVP_Handler(&PWM_Handle_M1._Super, TIM1);
}
/* Systick is not executed due low priority so is necessary to call MC_Scheduler here */
MC_Scheduler();
/* USER CODE BEGIN TIMx_BRK_M1_IRQn 1 */
/* USER CODE END TIMx_BRK_M1_IRQn 1 */
}
/**
* @brief This function handles TIMx global interrupt request for M1 Speed Sensor.
* @param None
*/
void SPD_TIM_M1_IRQHandler(void)
{
/* USER CODE BEGIN SPD_TIM_M1_IRQn 0 */
/* USER CODE END SPD_TIM_M1_IRQn 0 */
/* Encoder Timer UPDATE IT is dynamicaly enabled/disabled, checking enable state is required */
if (LL_TIM_IsEnabledIT_UPDATE (ENCODER_M1.TIMx) != 0U)
{
if (LL_TIM_IsActiveFlag_UPDATE (ENCODER_M1.TIMx) != 0U)
{
LL_TIM_ClearFlag_UPDATE(ENCODER_M1.TIMx);
(void)ENC_IRQHandler(&ENCODER_M1);
/* USER CODE BEGIN M1 ENCODER_Update */
/* USER CODE END M1 ENCODER_Update */
}
else
{
/* No other IT to manage for encoder config */
}
}
else
{
/* No other IT to manage for encoder config */
}
/* USER CODE BEGIN SPD_TIM_M1_IRQn 1 */
/* USER CODE END SPD_TIM_M1_IRQn 1 */
}
/**
* @brief This function handles DMA_RX_A channel DMACH_RX_A global interrupt.
*/
//cstat !MISRAC2012-Rule-8.4
void DMA1_Channel1_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel1_IRQHandler 0 */
/* USER CODE BEGIN DMA1_Channel1_IRQHandler 0 */
/* Buffer is ready by the HW layer to be processed */
if (0U == LL_DMA_IsActiveFlag_TC(DMA_RX_A, DMACH_RX_A))
{
/* Nothing to do */
}
else
{
LL_DMA_ClearFlag_TC (DMA_RX_A, DMACH_RX_A);
ASPEP_HWDataReceivedIT (&aspepOverUartA);
}
/* USER CODE BEGIN DMA1_Channel1_IRQHandler 1 */
/* USER CODE BEGIN DMA1_Channel1_IRQHandler 1 */
}
/* This section is present only when MCP over UART_A is used */
/**
* @brief This function handles USART interrupt request.
* @param None
*/
//cstat !MISRAC2012-Rule-8.4
void USART2_IRQHandler(void)
{
/* USER CODE BEGIN USART2_IRQHandler 0 */
/* USER CODE END USART2_IRQHandler 0 */
if (0U == LL_USART_IsActiveFlag_TC(USARTA))
{
/* Nothing to do */
}
else
{
/* LL_GPIO_SetOutputPin(GPIOC , LL_GPIO_PIN_6) */
/* Disable the DMA channel to prepare the next chunck of data */
LL_DMA_DisableChannel(DMA_TX_A, DMACH_TX_A);
LL_USART_ClearFlag_TC (USARTA);
/* Data Sent by UART */
/* Need to free the buffer, and to check pending transfer */
ASPEP_HWDataTransmittedIT (&aspepOverUartA);
/* LL_GPIO_ResetOutputPin(GPIOC , LL_GPIO_PIN_6) */
}
uint32_t flags;
uint32_t oreFlag;
uint32_t feFlag;
uint32_t neFlag;
uint32_t errorMask;
uint32_t activeIdleFlag;
uint32_t isEnabledIdelFlag;
oreFlag = LL_USART_IsActiveFlag_ORE(USARTA);
feFlag = LL_USART_IsActiveFlag_FE(USARTA);
neFlag = LL_USART_IsActiveFlag_NE(USARTA);
errorMask = LL_USART_IsEnabledIT_ERROR(USARTA);
flags = ((oreFlag | feFlag | neFlag) & errorMask);
if (0U == flags)
{
/* Nothing to do */
}
else
{ /* Stopping the debugger will generate an OverRun error */
WRITE_REG(USARTA->ICR, USART_ICR_FECF|USART_ICR_ORECF|USART_ICR_NECF);
/* We disable ERROR interrupt to avoid to trig one Overrun IT per additional byte recevied */
LL_USART_DisableIT_ERROR (USARTA);
LL_USART_EnableIT_IDLE (USARTA);
}
activeIdleFlag = LL_USART_IsActiveFlag_IDLE (USARTA);
isEnabledIdelFlag = LL_USART_IsEnabledIT_IDLE (USARTA);
flags = activeIdleFlag & isEnabledIdelFlag;
if (0U == flags)
{
/* Nothing to do */
}
else
{ /* Stopping the debugger will generate an OverRun error */
LL_USART_DisableIT_IDLE (USARTA);
/* Once the complete unexpected data are received, we enable back the error IT */
LL_USART_EnableIT_ERROR (USARTA);
/* To be sure we fetch the potential pendig data */
/* We disable the DMA request, Read the dummy data, endable back the DMA request */
LL_USART_DisableDMAReq_RX (USARTA);
(void)LL_USART_ReceiveData8(USARTA);
LL_USART_EnableDMAReq_RX (USARTA);
ASPEP_HWDMAReset (&aspepOverUartA);
}
/* USER CODE BEGIN USART2_IRQHandler 1 */
/* USER CODE END USART2_IRQHandler 1 */
}
/**
* @brief This function handles Hard Fault exception.
* @param None
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
TSK_HardwareFaultTask();
/* Go to infinite loop when Hard Fault exception occurs */
while (true)
{
}
/* USER CODE BEGIN HardFault_IRQn 1 */
/* USER CODE END HardFault_IRQn 1 */
}
void SysTick_Handler(void)
{
#ifdef MC_HAL_IS_USED
static uint8_t SystickDividerCounter = SYSTICK_DIVIDER;
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
if (SystickDividerCounter == SYSTICK_DIVIDER)
{
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
SystickDividerCounter = 0;
}
SystickDividerCounter ++;
#endif /* MC_HAL_IS_USED */
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
MC_RunMotorControlTasks();
/* USER CODE BEGIN SysTick_IRQn 2 */
/* USER CODE END SysTick_IRQn 2 */
}
/**
* @brief This function handles Button IRQ on PIN PC13.
*/
void EXTI15_10_IRQHandler (void)
{
/* USER CODE BEGIN START_STOP_BTN */
if (0U == LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_13))
{
/* Nothing to do */
}
else
{
LL_EXTI_ClearFlag_0_31 (LL_EXTI_LINE_13);
(void)UI_HandleStartStopButton_cb ();
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 9,572 | C | 24.325397 | 97 | 0.606456 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/tim.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file tim.c
* @brief This file provides code for the configuration
* of the TIM instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "tim.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
TIM_HandleTypeDef htim1;
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim3;
TIM_HandleTypeDef htim5;
/* TIM1 init function */
void MX_TIM1_Init(void)
{
/* USER CODE BEGIN TIM1_Init 0 */
/* USER CODE END TIM1_Init 0 */
TIM_SlaveConfigTypeDef sSlaveConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
/* USER CODE BEGIN TIM1_Init 1 */
/* USER CODE END TIM1_Init 1 */
htim1.Instance = TIM1;
htim1.Init.Prescaler = ((TIM_CLOCK_DIVIDER) - 1);
htim1.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED1;
htim1.Init.Period = ((PWM_PERIOD_CYCLES) / 2);
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV2;
htim1.Init.RepetitionCounter = (REP_COUNTER);
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
{
Error_Handler();
}
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
sSlaveConfig.InputTrigger = TIM_TS_ITR1;
if (HAL_TIM_SlaveConfigSynchro(&htim1, &sSlaveConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC4REF;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = ((PWM_PERIOD_CYCLES) / 4);
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM2;
sConfigOC.Pulse = (((PWM_PERIOD_CYCLES) / 2) - (HTMIN));
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
{
Error_Handler();
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_ENABLE;
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_ENABLE;
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
sBreakDeadTimeConfig.DeadTime = ((DEAD_TIME_COUNTS) / 2);
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.BreakFilter = 0;
sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT;
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
sBreakDeadTimeConfig.Break2Filter = 3;
sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM1_Init 2 */
/* USER CODE END TIM1_Init 2 */
HAL_TIM_MspPostInit(&htim1);
}
/* TIM2 init function */
void MX_TIM2_Init(void)
{
/* USER CODE BEGIN TIM2_Init 0 */
/* USER CODE END TIM2_Init 0 */
TIM_Encoder_InitTypeDef sConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM2_Init 1 */
/* USER CODE END TIM2_Init 1 */
htim2.Instance = TIM2;
htim2.Init.Prescaler = 0;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = M1_PULSE_NBR;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
sConfig.IC1Filter = M1_ENC_IC_FILTER;
sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
sConfig.IC2Filter = M1_ENC_IC_FILTER;
if (HAL_TIM_Encoder_Init(&htim2, &sConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM2_Init 2 */
/* USER CODE END TIM2_Init 2 */
}
/* TIM3 init function */
void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
/* USER CODE END TIM3_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 17000;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 65535;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM3_Init 2 */
/* USER CODE END TIM3_Init 2 */
}
/* TIM5 init function */
void MX_TIM5_Init(void)
{
/* USER CODE BEGIN TIM5_Init 0 */
/* USER CODE END TIM5_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM5_Init 1 */
/* USER CODE END TIM5_Init 1 */
htim5.Instance = TIM5;
htim5.Init.Prescaler = 170;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 10000;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM5_Init 2 */
/* USER CODE END TIM5_Init 2 */
}
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM1)
{
/* USER CODE BEGIN TIM1_MspInit 0 */
/* USER CODE END TIM1_MspInit 0 */
/* TIM1 clock enable */
__HAL_RCC_TIM1_CLK_ENABLE();
/* USER CODE BEGIN TIM1_MspInit 1 */
/* USER CODE END TIM1_MspInit 1 */
}
else if(tim_baseHandle->Instance==TIM3)
{
/* USER CODE BEGIN TIM3_MspInit 0 */
/* USER CODE END TIM3_MspInit 0 */
/* TIM3 clock enable */
__HAL_RCC_TIM3_CLK_ENABLE();
/* USER CODE BEGIN TIM3_MspInit 1 */
/* USER CODE END TIM3_MspInit 1 */
}
else if(tim_baseHandle->Instance==TIM5)
{
/* USER CODE BEGIN TIM5_MspInit 0 */
/* USER CODE END TIM5_MspInit 0 */
/* TIM5 clock enable */
__HAL_RCC_TIM5_CLK_ENABLE();
/* TIM5 interrupt Init */
HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM5_IRQn);
/* USER CODE BEGIN TIM5_MspInit 1 */
/* USER CODE END TIM5_MspInit 1 */
}
}
void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* tim_encoderHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(tim_encoderHandle->Instance==TIM2)
{
/* USER CODE BEGIN TIM2_MspInit 0 */
/* USER CODE END TIM2_MspInit 0 */
/* TIM2 clock enable */
__HAL_RCC_TIM2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**TIM2 GPIO Configuration
PA15 ------> TIM2_CH1
PB3 ------> TIM2_CH2
*/
GPIO_InitStruct.Pin = M1_ENCODER_A_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
HAL_GPIO_Init(M1_ENCODER_A_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = M1_ENCODER_B_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
HAL_GPIO_Init(M1_ENCODER_B_GPIO_Port, &GPIO_InitStruct);
/* USER CODE BEGIN TIM2_MspInit 1 */
/* USER CODE END TIM2_MspInit 1 */
}
}
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(timHandle->Instance==TIM1)
{
/* USER CODE BEGIN TIM1_MspPostInit 0 */
/* USER CODE END TIM1_MspPostInit 0 */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**TIM1 GPIO Configuration
PA7 ------> TIM1_CH1N
PB0 ------> TIM1_CH2N
PB1 ------> TIM1_CH3N
PA8 ------> TIM1_CH1
PA9 ------> TIM1_CH2
PA10 ------> TIM1_CH3
*/
GPIO_InitStruct.Pin = M1_PWM_UL_Pin|M1_PWM_UH_Pin|M1_PWM_VH_Pin|M1_PWM_WH_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF6_TIM1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = M1_PWM_VL_Pin|M1_PWM_WL_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF6_TIM1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN TIM1_MspPostInit 1 */
/* USER CODE END TIM1_MspPostInit 1 */
}
}
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM1)
{
/* USER CODE BEGIN TIM1_MspDeInit 0 */
/* USER CODE END TIM1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM1_CLK_DISABLE();
/* TIM1 interrupt Deinit */
HAL_NVIC_DisableIRQ(TIM1_BRK_TIM15_IRQn);
HAL_NVIC_DisableIRQ(TIM1_UP_TIM16_IRQn);
/* USER CODE BEGIN TIM1_MspDeInit 1 */
/* USER CODE END TIM1_MspDeInit 1 */
}
else if(tim_baseHandle->Instance==TIM3)
{
/* USER CODE BEGIN TIM3_MspDeInit 0 */
/* USER CODE END TIM3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM3_CLK_DISABLE();
/* USER CODE BEGIN TIM3_MspDeInit 1 */
/* USER CODE END TIM3_MspDeInit 1 */
}
else if(tim_baseHandle->Instance==TIM5)
{
/* USER CODE BEGIN TIM5_MspDeInit 0 */
/* USER CODE END TIM5_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM5_CLK_DISABLE();
/* TIM5 interrupt Deinit */
HAL_NVIC_DisableIRQ(TIM5_IRQn);
/* USER CODE BEGIN TIM5_MspDeInit 1 */
/* USER CODE END TIM5_MspDeInit 1 */
}
}
void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* tim_encoderHandle)
{
if(tim_encoderHandle->Instance==TIM2)
{
/* USER CODE BEGIN TIM2_MspDeInit 0 */
/* USER CODE END TIM2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM2_CLK_DISABLE();
/**TIM2 GPIO Configuration
PA15 ------> TIM2_CH1
PB3 ------> TIM2_CH2
*/
HAL_GPIO_DeInit(M1_ENCODER_A_GPIO_Port, M1_ENCODER_A_Pin);
HAL_GPIO_DeInit(M1_ENCODER_B_GPIO_Port, M1_ENCODER_B_Pin);
/* TIM2 interrupt Deinit */
HAL_NVIC_DisableIRQ(TIM2_IRQn);
/* USER CODE BEGIN TIM2_MspDeInit 1 */
/* USER CODE END TIM2_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
| 12,677 | C | 27.554054 | 82 | 0.660724 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/usart_aspep_driver.c |
/**
******************************************************************************
* @file usart_aspep_driver.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the uart driver for the aspep protocol
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#include <stdint.h>
#include "mc_stm_types.h"
#include "usart_aspep_driver.h"
void UASPEP_DAMCONFIG_TX(UASPEP_Handle_t *pHandle);
void UASPEP_DAMCONFIG_RX(UASPEP_Handle_t *pHandle);
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MCP
* @{
*/
/**
* @brief Initialization of the DMAs used for data transmission and reception.
*
* @param pHandle Handler of the current instance of the UASPEP component
*/
void UASPEP_INIT(void *pHWHandle)
{
UASPEP_Handle_t *pHandle = (UASPEP_Handle_t *)pHWHandle; //cstat !MISRAC2012-Rule-11.5
UASPEP_DAMCONFIG_TX(pHandle);
UASPEP_DAMCONFIG_RX(pHandle);
}
/**
* @brief Configures the DMA used for data transmission to controller.
*
* @param pHandle Handler of the current instance of the UASPEP component
*/
void UASPEP_DAMCONFIG_TX(UASPEP_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_USA_ASP_DRV
if (NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
/* Enable DMA UART */
LL_USART_ClearFlag_TC(pHandle->USARTx);
LL_USART_EnableIT_TC(pHandle->USARTx);
/* Enable DMA UART to start the TX request */
LL_USART_EnableDMAReq_TX(pHandle->USARTx);
/* Write the USART_TDR register address in the DMA control register to configure it as
* the destination of the transfer */
//cstat !MISRAC2012-Rule-11.4
LL_DMA_SetPeriphAddress(pHandle->txDMA, pHandle->txChannel, (uint32_t)&pHandle->USARTx->TDR);
/* Clear UART ISR */
LL_USART_ClearFlag_TC(pHandle->USARTx);
/* DMA end of transfer on UART TX channel completion is not activated */
/* We prefer to activate UART TC itself to avoid to trig IT while queued data are still to be transmitted */
#ifdef NULL_PTR_CHECK_USA_ASP_DRV
}
#endif
}
/**
* @brief Configures the DMA used for data reception from controller.
*
* @param pHandle Handler of the current instance of the UASPEP component
*/
void UASPEP_DAMCONFIG_RX(UASPEP_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_USA_ASP_DRV
if (NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
/* Enable DMA end of transfer on UART RX channel completion */
LL_DMA_EnableIT_TC(pHandle->rxDMA, pHandle->rxChannel);
/* Enable Error interrupt (EIE) to unmask Overrun interrupt */
LL_USART_EnableIT_ERROR(pHandle->USARTx);
/* Write the USART_RDR register address in the DMA control register to configure it as
* the source of the transfer */
//cstat !MISRAC2012-Rule-11.4
LL_DMA_SetPeriphAddress(pHandle->rxDMA, pHandle->rxChannel, (uint32_t)&pHandle->USARTx->RDR);
/* Clear UART ISR */
LL_USART_ClearFlag_TC(pHandle->USARTx);
LL_USART_EnableDMAReq_RX(pHandle->USARTx);
#ifdef NULL_PTR_CHECK_USA_ASP_DRV
}
#endif
}
/**
* @brief Enables the configured DMA to send packet.
*
* @param pHWHandle Hardware components chosen for communication
* @param data Data to be transmitted to controller
* @param length Length of the data to be transmitted
*/
bool UASPEP_SEND_PACKET(void *pHWHandle, void *data, uint16_t length)
{
UASPEP_Handle_t *pHandle = (UASPEP_Handle_t *)pHWHandle; //cstat !MISRAC2012-Rule-11.5
bool result;
if (0U == LL_DMA_IsEnabledChannel(pHandle->txDMA, pHandle->txChannel))
{
//cstat !MISRAC2012-Rule-11.4 !MISRAC2012-Rule-11.6
LL_DMA_SetMemoryAddress(pHandle->txDMA, pHandle->txChannel, (uint32_t)data);
LL_DMA_SetDataLength(pHandle->txDMA, pHandle->txChannel, length);
LL_DMA_EnableChannel(pHandle->txDMA, pHandle->txChannel);
result = true;
}
else
{
result = false;
}
return (result);
}
/**
* @brief Enables the configured DMA to receive packet.
*
* @param pHWHandle Hardware components chosen for communication
* @param buffer Buffer which will receive the communicated data
* @param length Length of the received data
*/
void UASPEP_RECEIVE_BUFFER(void *pHWHandle, void* buffer, uint16_t length)
{
UASPEP_Handle_t *pHandle = (UASPEP_Handle_t *)pHWHandle; //cstat !MISRAC2012-Rule-11.5
LL_DMA_DisableChannel(pHandle->rxDMA, pHandle->rxChannel);
//cstat !MISRAC2012-Rule-11.4 !MISRAC2012-Rule-11.6
LL_DMA_SetMemoryAddress(pHandle->rxDMA, pHandle->rxChannel, (uint32_t)buffer);
LL_DMA_SetDataLength(pHandle->rxDMA, pHandle->rxChannel, length);
LL_DMA_EnableChannel(pHandle->rxDMA, pHandle->rxChannel);
}
/**
* @brief Sets IDLE state : no transmission on going.
*
* @param pHandle Handler of the current instance of the UASPEP component
*/
void UASPEP_IDLE_ENABLE(void *pHWHandle)
{
UASPEP_Handle_t *pHandle = (UASPEP_Handle_t *)pHWHandle; //cstat !MISRAC2012-Rule-11.5
LL_USART_ClearFlag_IDLE(pHandle->USARTx);
LL_USART_EnableIT_IDLE(pHandle->USARTx);
}
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 5,641 | C | 29.497297 | 112 | 0.656976 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/stm32g4xx_it.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g4xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32g4xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
extern uint8_t data_flag;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern TIM_HandleTypeDef htim5;
extern DMA_HandleTypeDef hdma_usart2_rx;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M4 Processor Interruption and Exception Handlers */
/******************************************************************************/
/******************************************************************************/
/* STM32G4xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32g4xx.s). */
/******************************************************************************/
/**
* @brief This function handles TIM5 global interrupt.
*/
void TIM5_IRQHandler(void)
{
/* USER CODE BEGIN TIM5_IRQn 0 */
data_flag=1;
/* USER CODE END TIM5_IRQn 0 */
HAL_TIM_IRQHandler(&htim5);
/* USER CODE BEGIN TIM5_IRQn 1 */
/* USER CODE END TIM5_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
| 3,021 | C | 31.847826 | 80 | 0.398875 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/adc.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file adc.c
* @brief This file provides code for the configuration
* of the ADC instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "adc.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
ADC_HandleTypeDef hadc1;
/* ADC1 init function */
void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_MultiModeTypeDef multimode = {0};
ADC_InjectionConfTypeDef sConfigInjected = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_LEFT;
hadc1.Init.GainCompensation = 0;
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure Injected Channel
*/
sConfigInjected.InjectedChannel = ADC_CHANNEL_1;
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_6CYCLES_5;
sConfigInjected.InjectedSingleDiff = ADC_SINGLE_ENDED;
sConfigInjected.InjectedOffsetNumber = ADC_OFFSET_NONE;
sConfigInjected.InjectedOffset = 0;
sConfigInjected.InjectedNbrOfConversion = 3;
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
sConfigInjected.AutoInjectedConv = DISABLE;
sConfigInjected.QueueInjectedContext = DISABLE;
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJEC_T1_TRGO;
sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONV_EDGE_RISING;
sConfigInjected.InjecOversamplingMode = DISABLE;
if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
{
Error_Handler();
}
/** Configure Injected Channel
*/
sConfigInjected.InjectedChannel = ADC_CHANNEL_7;
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2;
if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
{
Error_Handler();
}
/** Configure Injected Channel
*/
sConfigInjected.InjectedChannel = ADC_CHANNEL_6;
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3;
if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_2;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_47CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(adcHandle->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
/** Initializes the peripherals clocks
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC12;
PeriphClkInit.Adc12ClockSelection = RCC_ADC12CLKSOURCE_PLL;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* ADC1 clock enable */
__HAL_RCC_ADC12_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**ADC1 GPIO Configuration
PC0 ------> ADC1_IN6
PC1 ------> ADC1_IN7
PA0 ------> ADC1_IN1
PA1 ------> ADC1_IN2
*/
GPIO_InitStruct.Pin = M1_CURR_AMPL_W_Pin|M1_CURR_AMPL_V_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = M1_CURR_AMPL_U_Pin|M1_BUS_VOLTAGE_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN ADC1_MspInit 1 */
/* USER CODE END ADC1_MspInit 1 */
}
}
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
{
if(adcHandle->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspDeInit 0 */
/* USER CODE END ADC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_ADC12_CLK_DISABLE();
/**ADC1 GPIO Configuration
PC0 ------> ADC1_IN6
PC1 ------> ADC1_IN7
PA0 ------> ADC1_IN1
PA1 ------> ADC1_IN2
*/
HAL_GPIO_DeInit(GPIOC, M1_CURR_AMPL_W_Pin|M1_CURR_AMPL_V_Pin);
HAL_GPIO_DeInit(GPIOA, M1_CURR_AMPL_U_Pin|M1_BUS_VOLTAGE_Pin);
/* ADC1 interrupt Deinit */
HAL_NVIC_DisableIRQ(ADC1_2_IRQn);
/* USER CODE BEGIN ADC1_MspDeInit 1 */
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
| 6,036 | C | 27.611374 | 84 | 0.649271 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/usart.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart.c
* @brief This file provides code for the configuration
* of the USART instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "usart.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
UART_HandleTypeDef huart2;
DMA_HandleTypeDef hdma_usart2_rx;
DMA_HandleTypeDef hdma_usart2_tx;
/* USART2 init function */
void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 1843200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(uartHandle->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspInit 0 */
/* USER CODE END USART2_MspInit 0 */
/** Initializes the peripherals clocks
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* USART2 clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
GPIO_InitStruct.Pin = UART_TX_Pin|UART_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART2 DMA Init */
/* USART2_RX Init */
hdma_usart2_rx.Instance = DMA1_Channel1;
hdma_usart2_rx.Init.Request = DMA_REQUEST_USART2_RX;
hdma_usart2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_usart2_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart2_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart2_rx.Init.Mode = DMA_NORMAL;
hdma_usart2_rx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_usart2_rx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx);
/* USART2_TX Init */
hdma_usart2_tx.Instance = DMA1_Channel2;
hdma_usart2_tx.Init.Request = DMA_REQUEST_USART2_TX;
hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart2_tx.Init.Mode = DMA_NORMAL;
hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_usart2_tx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx);
/* USER CODE BEGIN USART2_MspInit 1 */
/* USER CODE END USART2_MspInit 1 */
}
}
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
{
if(uartHandle->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspDeInit 0 */
/* USER CODE END USART2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART2_CLK_DISABLE();
/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
HAL_GPIO_DeInit(GPIOA, UART_TX_Pin|UART_RX_Pin);
/* USART2 DMA DeInit */
HAL_DMA_DeInit(uartHandle->hdmarx);
HAL_DMA_DeInit(uartHandle->hdmatx);
/* USART2 interrupt Deinit */
HAL_NVIC_DisableIRQ(USART2_IRQn);
/* USER CODE BEGIN USART2_MspDeInit 1 */
/* USER CODE END USART2_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
| 5,314 | C | 27.885869 | 82 | 0.62834 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/dma.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file dma.c
* @brief This file provides code for the configuration
* of all the requested memory to memory DMA transfers.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "dma.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure DMA */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/**
* Enable DMA controller clock
*/
void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMAMUX1_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
}
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
| 1,412 | C | 26.173076 | 80 | 0.395892 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mc_app_hooks.c | /**
******************************************************************************
* @file mc_app_hooks.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file implements default motor control app hooks.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCAppHooks
*/
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
#include "mc_app_hooks.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MCTasks
* @{
*/
/**
* @defgroup MCAppHooks Motor Control Applicative hooks
* @brief User defined functions that are called in the Motor Control tasks.
*
*
* @{
*/
/**
* @brief Hook function called right before the end of the MCboot function.
*
*
*
*/
__weak void MC_APP_BootHook(void)
{
/*
* This function can be overloaded or the application can inject
* code into it that will be executed at the end of MCboot().
*/
/* USER CODE BEGIN BootHook */
/* USER CODE END BootHook */
}
/**
* @brief Hook function called right after the Medium Frequency Task for Motor 1.
*
*
*
*/
__weak void MC_APP_PostMediumFrequencyHook_M1(void)
{
/*
* This function can be overloaded or the application can inject
* code into it that will be executed right after the Medium
* Frequency Task of Motor 1
*/
/* USER SECTION BEGIN PostMediumFrequencyHookM1 */
/* USER SECTION END PostMediumFrequencyHookM1 */
}
/** @} */
/** @} */
/** @} */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 2,067 | C | 23.046511 | 85 | 0.544267 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mcp.c |
/**
******************************************************************************
* @file mcp.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the MCP protocol
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#include "mc_type.h"
#include "mcp.h"
#include "register_interface.h"
#include "mc_config.h"
#include "mcp_config.h"
#include "mc_api.h"
/** @addtogroup MCSDK
* @{
*/
/** @defgroup MCP Motor Control Protocol
*
* @brief Motor Control Protocol components of the Motor Control SDK.
*
* These components implement the features needed to drive and monitor motor control applications embedded in STM32 MCUs.
* They mainly focus on the communication with the controller, both on the receiving and the transmitting end.
*
* @{
*/
/**
* @brief Parses the payload in the received packet and call the required function in order to modify a value.
*
* The function called depends on the targeted motor and/or targeted register : RI_SetRegisterGlobal or RI_SetRegisterMotorX.
*
* @param pHandle Handler of the current instance of the MCP component
* @param txSyncFreeSpace Space available for synchronous transmission
*
* @retval Returns #MCP_CMD_OK if the command is acknowledged and #MCP_CMD_NOK if not.
*/
uint8_t RI_SetRegCommandParser (MCP_Handle_t * pHandle, uint16_t txSyncFreeSpace)
{
uint8_t retVal = MCP_CMD_OK;
#ifdef NULL_PTR_CHECK_REG_INT
if (MC_NULL == pHandle)
{
retVal = MCP_CMD_NOK;
}
else
{
#endif
uint16_t * dataElementID;
uint8_t * rxData = pHandle->rxBuffer;
uint8_t * txData = pHandle->txBuffer;
int16_t rxLength = pHandle->rxLength;
uint16_t size = 0U;
uint8_t accessResult;
uint16_t regID;
uint8_t typeID;
uint8_t motorID;
uint8_t (*SetRegFcts[NBR_OF_MOTORS+1])(uint16_t, uint8_t, uint8_t*, uint16_t*, int16_t) = {&RI_SetRegisterGlobal, &RI_SetRegisterMotor1};
uint8_t number_of_item =0;
pHandle->txLength = 0;
while (rxLength > 0)
{
number_of_item ++;
dataElementID = (uint16_t *) rxData;
rxLength = rxLength-MCP_ID_SIZE; // We consume 2 byte in the DataID
rxData = rxData+MCP_ID_SIZE; // Shift buffer to the next data
regID = *dataElementID & REG_MASK;
typeID = (uint8_t)*dataElementID & TYPE_MASK;
motorID = (uint8_t)((*dataElementID & MOTOR_MASK));
if (motorID > NBR_OF_MOTORS)
{
retVal = MCP_CMD_NOK;
rxLength = 0;
}
else
{
accessResult = SetRegFcts[motorID](regID, typeID, rxData, &size, rxLength);
/* Prepare next data*/
rxLength = (int16_t) (rxLength - size);
rxData = rxData+size;
/* If there is only one CMD in the buffer, we do not store the result */
if ((1U == number_of_item) && (0 == rxLength))
{
retVal = accessResult;
}
else
{/* Store the result for each access to be able to report failing access */
if (txSyncFreeSpace !=0 )
{
*txData = accessResult;
txData = txData+1;
pHandle->txLength++;
txSyncFreeSpace--; /* decrement one by one no wraparound possible */
retVal = (accessResult != MCP_CMD_OK) ? MCP_CMD_NOK : retVal;
if ((accessResult == MCP_ERROR_BAD_DATA_TYPE) || (accessResult == MCP_ERROR_BAD_RAW_FORMAT))
{ /* From this point we are not able to continue to decode CMD buffer*/
/* We stop the parsing */
rxLength = 0;
}
}
else
{
/* Stop parsing the cmd buffer as no space to answer */
/* If we reach this state, chances are high the command was badly formated or received */
rxLength = 0;
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
}
}
}
/* If all accesses are fine, just one global MCP_CMD_OK is required*/
if (MCP_CMD_OK == retVal)
{
pHandle->txLength = 0;
}
else
{
/* Nothing to do */
}
#ifdef NULL_PTR_CHECK_REG_INT
}
#endif
return (retVal);
}
/**
* @brief Parses the payload in the received packet and call the required function in order to return a value.
*
* The function called depends on the targeted motor and/or targeted register : RI_GetRegisterGlobal or RI_GetRegisterMotorX.
*
* @param pHandle Handler of the current instance of the MCP component
* @param txSyncFreeSpace Space available for synchronous transmission
*
* @retval Returns #MCP_CMD_OK if the command is acknowledged and #MCP_CMD_NOK if not.
*/
uint8_t RI_GetRegCommandParser (MCP_Handle_t * pHandle, uint16_t txSyncFreeSpace)
{
uint8_t retVal = MCP_CMD_NOK;
#ifdef NULL_PTR_CHECK_REG_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
uint16_t * dataElementID;
uint8_t * rxData = pHandle->rxBuffer;
uint8_t * txData = pHandle->txBuffer;
uint16_t size = 0U;
uint16_t rxLength = pHandle->rxLength;
int16_t freeSpaceS16 = (int16_t) txSyncFreeSpace;
uint16_t regID;
uint8_t typeID;
uint8_t motorID;
uint8_t (*GetRegFcts[NBR_OF_MOTORS+1])(uint16_t, uint8_t, uint8_t*, uint16_t*, int16_t) = {&RI_GetRegisterGlobal, &RI_GetRegisterMotor1};
pHandle->txLength = 0;
while (rxLength > 0U)
{
dataElementID = (uint16_t *) rxData;
rxLength = rxLength - MCP_ID_SIZE;
rxData = rxData + MCP_ID_SIZE; // Shift buffer to the next MCP_ID
regID = *dataElementID & REG_MASK;
typeID = (uint8_t)*dataElementID & TYPE_MASK;
motorID = (uint8_t)((*dataElementID & MOTOR_MASK));
if (motorID > NBR_OF_MOTORS)
{
retVal = MCP_CMD_NOK;
rxLength = 0;
}
else
{
retVal = GetRegFcts[motorID](regID, typeID, txData, &size, freeSpaceS16);
if (retVal == MCP_CMD_OK )
{
/* Prepare next data */
txData = txData+size;
pHandle->txLength += size;
freeSpaceS16 = freeSpaceS16-size;
}
else
{
rxLength = 0;
}
}
}
#ifdef NULL_PTR_CHECK_REG_INT
}
#endif
return (retVal);
}
/**
* @brief Parses the header from the received packet and call the required function depending on the command sent by the controller device.
*
* @param pHandle Handler of the current instance of the MCP component
*/
void MCP_ReceivedPacket(MCP_Handle_t *pHandle)
{
const uint16_t *packetHeader;
uint16_t command;
int16_t txSyncFreeSpace;
uint8_t motorID;
uint8_t MCPResponse;
uint8_t userCommand=0;
#ifdef NULL_PTR_CHECK_MCP
if ((MC_NULL == pHandle) || (0U == pHandle->rxLength))
{
/* Nothing to do, txBuffer and txLength have not been modified */
}
else /* Length is 0, this is a request to send back the last packet */
{
#endif
packetHeader = (uint16_t *)pHandle->rxBuffer; //cstat !MISRAC2012-Rule-11.3
command = (uint16_t)(*packetHeader & CMD_MASK);
if ((command & MCP_USER_CMD_MASK) == MCP_USER_CMD)
{
userCommand = ((uint8_t)(command & 0xF8U) >> 3U);
command = MCP_USER_CMD;
}
else
{
/* Nothing to do */
}
motorID = (uint8_t)((*packetHeader - 1U) & MOTOR_MASK);
MCI_Handle_t *pMCI = &Mci[motorID];
/* Removing MCP Header from RxBuffer */
pHandle->rxLength = pHandle->rxLength - MCP_HEADER_SIZE;
pHandle->rxBuffer = pHandle->rxBuffer + MCP_HEADER_SIZE;
/* Commands requiering payload response must be aware of space available for the payload */
/* Last byte is reserved for MCP response*/
txSyncFreeSpace = (int16_t)pHandle->pTransportLayer->txSyncMaxPayload - 1;
/* Initialization of the tx length, command which send back data has to increment the txLength
* (case of Read register) */
pHandle->txLength = 0U;
switch (command)
{
case GET_MCP_VERSION:
{
pHandle->txLength = 4U;
*pHandle->txBuffer = MCP_VERSION;
MCPResponse = MCP_CMD_OK;
break;
}
case SET_DATA_ELEMENT:
{
MCPResponse = RI_SetRegCommandParser(pHandle, (uint16_t)txSyncFreeSpace);
break;
}
case GET_DATA_ELEMENT:
{
MCPResponse = RI_GetRegCommandParser(pHandle, (uint16_t)txSyncFreeSpace);
break;
}
case START_MOTOR:
{
MCPResponse = (MCI_StartWithPolarizationMotor(pMCI) == false) ? MCP_CMD_OK : MCP_CMD_NOK;
break;
}
case STOP_MOTOR: /* Todo: Check the pertinance of return value */
{
(void)MCI_StopMotor(pMCI);
MCPResponse = MCP_CMD_OK;
break;
}
case STOP_RAMP:
{
if (RUN == MCI_GetSTMState(pMCI))
{
MCI_StopRamp(pMCI);
}
else
{
/* Nothing to do */
}
MCPResponse = MCP_CMD_OK;
break;
}
case START_STOP:
{
/* Queries the STM and a command start or stop depending on the state */
if (IDLE == MCI_GetSTMState(pMCI))
{
MCPResponse = (MCI_StartWithPolarizationMotor(pMCI) == true) ? MCP_CMD_OK : MCP_CMD_NOK;
}
else
{
(void)MCI_StopMotor(pMCI);
MCPResponse = MCP_CMD_OK;
}
break;
}
case FAULT_ACK:
{
(void)MCI_FaultAcknowledged(pMCI);
MCPResponse = MCP_CMD_OK;
break;
}
case IQDREF_CLEAR:
{
MCI_Clear_Iqdref(pMCI);
MCPResponse = MCP_CMD_OK;
break;
}
case PFC_ENABLE:
case PFC_DISABLE:
case PFC_FAULT_ACK:
{
MCPResponse = MCP_CMD_UNKNOWN;
break;
}
case PROFILER_CMD:
{
MCPResponse = MC_ProfilerCommand(pHandle->rxLength, pHandle->rxBuffer, txSyncFreeSpace, &pHandle->txLength,
pHandle->txBuffer);
break;
}
case MCP_USER_CMD:
{
if ((userCommand < MCP_USER_CALLBACK_MAX) && (MCP_UserCallBack[userCommand] != NULL))
{
MCPResponse = MCP_UserCallBack[userCommand](pHandle->rxLength, pHandle->rxBuffer, txSyncFreeSpace,
&pHandle->txLength, pHandle->txBuffer);
}
else
{
MCPResponse = MCP_ERROR_CALLBACK_NOT_REGISTRED;
}
break;
}
default :
{
MCPResponse = MCP_CMD_UNKNOWN;
break;
}
}
pHandle->txBuffer[pHandle->txLength] = MCPResponse;
pHandle->txLength++;
#ifdef NULL_PTR_CHECK_MCP
}
#endif
}
/**
* @brief Stores user's MCP function to be later called as MCP function.
*
* @param callBackID: ID used to get to the stored @p fctCB function
* @param fctCB: User call back function structure
*
* @retval Returns #MCP_CMD_OK if the command is acknowledged and #MCP_CMD_NOK if not
*/
uint8_t MCP_RegisterCallBack (uint8_t callBackID, MCP_user_cb_t fctCB)
{
uint8_t result;
if (callBackID < MCP_USER_CALLBACK_MAX)
{
MCP_UserCallBack[callBackID] = fctCB;
result = MCP_CMD_OK;
}
else
{
result = MCP_CMD_NOK;
}
return (result);
}
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 11,873 | C | 27.004717 | 141 | 0.583677 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/regular_conversion_manager.c |
/**
******************************************************************************
* @file regular_conversion_manager.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the following features
* of the regular_conversion_manager component of the Motor Control SDK:
* Register conversion with or without callback
* Execute regular conv directly from Temperature and VBus sensors
* Execute user regular conversion scheduled by medium frequency task
* Manage user conversion state machine
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
#include "regular_conversion_manager.h"
#include "mc_config.h"
/** @addtogroup MCSDK
* @{
*/
/** @defgroup RCM Regular Conversion Manager
* @brief Regular Conversion Manager component of the Motor Control SDK
*
* MotorControl SDK makes an extensive usage of ADCs. Some conversions are timing critical
* like current reading, and some have less constraints. If an ADC offers both Injected and Regular,
* channels, critical conversions will be systematically done on Injected channels, because they
* interrupt any ongoing regular conversion so as to be executed without delay.
* Others conversions, mainly Bus voltage, and Temperature sensing are performed with regular channels.
* If users wants to perform ADC conversions with an ADC already used by MC SDK, they must use regular
* conversions. It is forbidden to use Injected channel on an ADC that is already in use for current reading.
* As usera and MC-SDK may share ADC regular scheduler, this component intents to manage all the
* regular conversions.
*
* If users wants to execute their own conversion, they first have to register it through the
* RCM_RegisterRegConv_WithCB() or RCM_RegisterRegConv() APIs. Multiple conversions can be registered,
* but only one can be scheduled at a time .
*
* A requested user regular conversion will be executed by the medium frequency task after the
* MC-SDK regular safety conversions: Bus voltage and Temperature.
*
* If a callback is registered, particular care must be taken with the code executed inside the CB.
* The callback code is executed under Medium frequency task IRQ context (Systick).
*
* If the Users do not register a callback, they must poll the RCM state machine to know if
* a conversion is ready to be read, scheduled, or free to be scheduled. This is performed through
* the RCM_GetUserConvState() API.
*
* If the state is #RCM_USERCONV_IDLE, a conversion is ready to be scheduled.
* if a conversion is already scheduled, the returned value is #RCM_USERCONV_REQUESTED.
* if a conversion is ready to be read, the returned value is #RCM_USERCONV_EOC.
* In #RCM_USERCONV_EOC state, a call to RCM_GetUserConv will consume the value, and set the state machine back
* to #RCM_USERCONV_IDLE state. It implies that a second call without new conversion performed,
* will send back 0xffff which is an error value meaning that the data is not available.
* If a conversion request is executed, but the previous conversion has not been completed, nor consumed,
* the request is discarded and the RCM_RequestUserConv() return false.
*
* If a callback is registered, the data read is sent back to the callback parameters, and therefor consumed.
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/**
* @brief Document as stated in template.h
*
* ...
*/
typedef enum
{
notvalid,
ongoing,
valid
} RCM_status_t;
typedef struct
{
bool enable;
RCM_status_t status;
uint16_t value;
uint8_t prev;
uint8_t next;
} RCM_NoInj_t;
typedef struct
{
RCM_exec_cb_t cb;
void *data;
} RCM_callback_t;
/* Private defines -----------------------------------------------------------*/
/**
* @brief Number of regular conversion allowed By default.
*
* In single drive configuration, it is defined to 4. 2 of them are consumed by
* Bus voltage and temperature reading. This leaves 2 handles available for
* user conversions
*
* In dual drives configuration, it is defined to 6. 2 of them are consumed by
* Bus voltage and temperature reading for each motor. This leaves 2 handles
* available for user conversion.
*
* Defined to 4 here.
*/
#define RCM_MAX_CONV 4U
/* Global variables ----------------------------------------------------------*/
static RegConv_t *RCM_handle_array[RCM_MAX_CONV];
static RCM_callback_t RCM_CB_array[RCM_MAX_CONV];
static RCM_NoInj_t RCM_NoInj_array[RCM_MAX_CONV];
static uint8_t RCM_currentHandle;
static uint16_t RCM_UserConvValue;
static RCM_UserConvState_t RCM_UserConvState;
static RegConv_t* RCM_UserConvHandle;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Registers a regular conversion, and attaches a callback.
*
* This function registers a regular ADC conversion that can be later scheduled for execution. It
* returns a handle that uniquely identifies the conversion. This handle is used in the other API
* of the Regular Converion Manager to reference the registered conversion.
*
* A regular conversion is defined by an ADC + ADC channel pair. If a registration already exists
* for the requested ADC + ADC channel pair, the same handle will be reused.
*
* The regular conversion is registered along with a callback that is executed each time the
* conversion has completed. The callback is invoked with two parameters:
*
* - the handle of the regular conversion
* - a data pointer, supplied by uthe users at registration time.
*
* The registration may fail if there is no space left for additional conversions. The
* maximum number of regular conversion that can be registered is defined by #RCM_MAX_CONV.
*
* @note Users who do not want a callback to be executed at the end of the conversion,
* should use RCM_RegisterRegConv() instead.
*
* @param regConv Pointer to the regular conversion parameters.
* Contains ADC, Channel and sampling time to be used.
*
* @param fctCB Function called once the regular conversion is executed.
*
* @param Data Used to save a user context. this parameter will be send back by
* the fctCB function. @b Note: This parameter can be NULL if not used.
*
*/
void RCM_RegisterRegConv_WithCB (RegConv_t *regConv, RCM_exec_cb_t fctCB, void *data)
{
RCM_RegisterRegConv(regConv);
if (regConv->convHandle < RCM_MAX_CONV)
{
RCM_CB_array [regConv->convHandle].cb = fctCB;
RCM_CB_array [regConv->convHandle].data = data;
}
else
{
/* Nothing to do */
}
}
/**
* @brief Registers a regular conversion.
*
* This function registers a regular ADC conversion that can be later scheduled for execution. It
* returns a handle that uniquely identifies the conversion. This handle is used in the other API
* of the Regular Converion Manager to reference the registered conversion.
*
* A regular conversion is defined by an ADC + ADC channel pair. If a registration already exists
* for the requested ADC + ADC channel pair, the same handle will be reused.
*
* The registration may fail if there is no space left for additional conversions. The
* maximum number of regular conversion that can be registered is defined by #RCM_MAX_CONV.
*
* @note Users who do not want a callback to be executed at the end of the conversion,
* should use RCM_RegisterRegConv() instead.
*
* @param regConv Pointer to the regular conversion parameters.
* Contains ADC, Channel and sampling time to be used.
*
*/
void RCM_RegisterRegConv(RegConv_t *regConv)
{
uint8_t handle = 255U;
#ifdef NULL_PTR_CHECK_REG_CON_MNG
if (MC_NULL == regConv)
{
handle = 0U;
}
else
{
#endif
uint8_t i = 0;
/* Parse the array to be sure that same
* conversion does not already exist*/
while (i < RCM_MAX_CONV)
{
if ((0 == RCM_handle_array [i]) && (handle > RCM_MAX_CONV))
{
handle = i; /* First location available, but still looping to check that this config does not already exist */
}
else
{
/* Nothing to do */
}
/* Ticket 64042 : If RCM_handle_array [i] is null access to data member will cause Memory Fault */
if (RCM_handle_array [i] != 0)
{
if ((RCM_handle_array [i]->channel == regConv->channel)
&& (RCM_handle_array [i]->regADC == regConv->regADC))
{
handle = i; /* Reuse the same handle */
i = RCM_MAX_CONV; /* We can skip the rest of the loop */
}
else
{
/* Nothing to do */
}
}
else
{
/* Nothing to do */
}
i++;
}
if (handle < RCM_MAX_CONV)
{
RCM_handle_array [handle] = regConv;
RCM_CB_array [handle].cb = NULL; /* If a previous callback was attached, it is cleared */
if (0U == LL_ADC_IsEnabled(regConv->regADC))
{
LL_ADC_DisableIT_EOC(regConv->regADC);
LL_ADC_ClearFlag_EOC(regConv->regADC);
LL_ADC_DisableIT_JEOC(regConv->regADC);
LL_ADC_ClearFlag_JEOC(regConv->regADC);
LL_ADC_StartCalibration(regConv->regADC, LL_ADC_SINGLE_ENDED);
while (1U == LL_ADC_IsCalibrationOnGoing(regConv->regADC))
{
/* Nothing to do */
}
/* ADC Enable (must be done after calibration) */
/* ADC5-140924: Enabling the ADC by setting ADEN bit soon after polling ADCAL=0
* following a calibration phase, could have no effect on ADC
* within certain AHB/ADC clock ratio
*/
while (0U == LL_ADC_IsActiveFlag_ADRDY(regConv->regADC))
{
LL_ADC_Enable(regConv->regADC);
}
}
else
{
/* Nothing to do */
}
/* Conversion handler is created, will be enabled by the first call to RCM_ExecRegularConv */
RCM_NoInj_array[handle].enable = false;
RCM_NoInj_array[handle].next = handle;
RCM_NoInj_array[handle].prev = handle;
/* Reset regular conversion sequencer length set by cubeMX */
LL_ADC_REG_SetSequencerLength(regConv->regADC, LL_ADC_REG_SEQ_SCAN_DISABLE);
/* Configure the sampling time (should already be configured by for non user conversions) */
LL_ADC_SetChannelSamplingTime(regConv->regADC, __LL_ADC_DECIMAL_NB_TO_CHANNEL(regConv->channel),
regConv->samplingTime);
}
else
{
/* Nothing to do handle is already set to error value : 255 */
}
#ifdef NULL_PTR_CHECK_REG_CON_MNG
}
#endif
regConv->convHandle = handle;
}
/*
* This function is used to read the result of a regular conversion.
* Depending of the MC state machine, this function can poll on the ADC end of conversion or not.
* If the ADC is already in use for currents sensing, the regular conversion can not
* be executed instantaneously but have to be scheduled in order to be executed after currents sensing
* inside HF task.
* This function takes care of inserting the handle into the scheduler.
* If it is possible to execute the conversion instantaneously, it will be executed, and result returned.
* Otherwise, the latest stored conversion result will be returned.
*
* NOTE: This function is not part of the public API and users should not call it.
*/
uint16_t RCM_ExecRegularConv (RegConv_t *regConv)
{
uint16_t retVal;
uint8_t handle = regConv->convHandle;
uint8_t formerNext;
uint8_t i=0;
uint8_t LastEnable = RCM_MAX_CONV;
if (false == RCM_NoInj_array [handle].enable)
{
/* Find position in the list */
while (i < RCM_MAX_CONV)
{
if (true == RCM_NoInj_array [i].enable)
{
if (RCM_NoInj_array[i].next > handle)
/* We found a previous reg conv to link with */
{
formerNext = RCM_NoInj_array [i].next;
RCM_NoInj_array[handle].next = formerNext;
RCM_NoInj_array[handle].prev = i;
RCM_NoInj_array[i].next = handle;
RCM_NoInj_array[formerNext].prev = handle;
i = RCM_MAX_CONV; /* Stop the loop, handler inserted */
}
else
{ /* We found an enabled regular conv,
* but do not know yet if it is the one we have to be linked to */
LastEnable = i;
}
}
else
{
/* Nothing to do */
}
i++;
if (RCM_MAX_CONV == i)
/* We reach end of the array without handler inserted */
{
if (LastEnable != RCM_MAX_CONV )
/* We find a regular conversion with smaller position to be linked with */
{
formerNext = RCM_NoInj_array[LastEnable].next;
RCM_NoInj_array[handle].next = formerNext;
RCM_NoInj_array[handle].prev = LastEnable;
RCM_NoInj_array[LastEnable].next = handle;
RCM_NoInj_array[formerNext].prev = handle;
}
else
{ /* The current handle is the only one in the list */
/* Previous and next are already pointing to itself (done at registerRegConv) */
RCM_currentHandle = handle;
}
}
else
{
/* Nothing to do we are parsing the array, nothing inserted yet */
}
}
/* The handle is now linked with others, we can set the enable flag */
RCM_NoInj_array[handle].enable = true;
RCM_NoInj_array[handle].status = notvalid;
if (RCM_NoInj_array[RCM_currentHandle].status != ongoing)
{/* Select the new conversion to be the next scheduled only if a conversion is not ongoing */
RCM_currentHandle = handle;
}
else
{
/* Nothing to do */
}
}
else
{
/* Nothing to do the current handle is already scheduled */
}
if (false == PWM_Handle_M1.ADCRegularLocked)
/* The ADC is free to be used asynchronously */
{
LL_ADC_REG_SetSequencerRanks(RCM_handle_array[handle]->regADC,
LL_ADC_REG_RANK_1,
__LL_ADC_DECIMAL_NB_TO_CHANNEL(RCM_handle_array[handle]->channel));
(void)LL_ADC_REG_ReadConversionData12(RCM_handle_array[handle]->regADC);
/* Start ADC conversion */
LL_ADC_REG_StartConversion(RCM_handle_array[handle]->regADC);
/* Wait EOC */
while ( 0U == LL_ADC_IsActiveFlag_EOC(RCM_handle_array[handle]->regADC))
{
/* Nothing to do */
}
/* Read the "Regular" conversion (Not related to current sampling) */
RCM_NoInj_array[handle].value = LL_ADC_REG_ReadConversionData12(RCM_handle_array[handle]->regADC);
RCM_currentHandle = RCM_NoInj_array[handle].next;
RCM_NoInj_array[handle].status = valid;
}
else
{
/* Nothing to do */
}
retVal = RCM_NoInj_array[handle].value;
return (retVal);
}
/**
* @brief Schedules a regular conversion for execution.
*
* This function requests the execution of the user-defined regular conversion identified
* by @p handle. All user defined conversion requests must be performed inside routines with the
* same priority level. If a previous regular conversion request is pending this function has no
* effect, for this reason is better to call RCM_GetUserConvState() and check if the state is
* #RCM_USERCONV_IDLE before calling RCM_RequestUserConv().
*
* @param handle used for the user conversion.
*
* @return True if the regular conversion could be scheduled and false otherwise.
*/
bool RCM_RequestUserConv(RegConv_t *regConv)
{
bool retVal = false;
if (RCM_USERCONV_IDLE == RCM_UserConvState)
{
RCM_UserConvHandle = regConv;
/* must be done last so that RCM_UserConvHandle already has the right value */
RCM_UserConvState = RCM_USERCONV_REQUESTED;
retVal = true;
}
else
{
/* Nothing to do */
}
return (retVal);
}
/**
* @brief Returns the last user-defined regular conversion that was executed.
*
* This function returns a valid result if the state returned by
* RCM_GetUserConvState is #RCM_USERCONV_EOC.
*
* @retval uint16_t The converted value or 0xFFFF in case of conversion error.
*/
uint16_t RCM_GetUserConv(void)
{
uint16_t hRetVal = 0xFFFFu;
if (RCM_USERCONV_EOC == RCM_UserConvState)
{
hRetVal = RCM_UserConvValue;
RCM_UserConvState = RCM_USERCONV_IDLE;
}
else
{
/* Nothing to do */
}
return (hRetVal);
}
/*
* This function must be scheduled by mc_task.
* It executes the current user conversion that has been selected by the
* latest call to RCM_RequestUserConv.
*
* NOTE: This function is not part of the public API and users should not call it.
*/
void RCM_ExecUserConv()
{
uint8_t handle;
if (RCM_UserConvHandle != NULL)
{
handle = RCM_UserConvHandle->convHandle;
if (RCM_USERCONV_REQUESTED == RCM_UserConvState)
{
RCM_UserConvValue = RCM_ExecRegularConv(RCM_UserConvHandle);
/* Regular conversion is read from RCM_NoInj_array but we must take care that first conversion is done */
/* Status could also be ongoing, but decision is taken to provide previous conversion
* instead of waiting for RCM_NoInj_array [handle].status == valid */
if (RCM_NoInj_array [handle].status != notvalid)
{
RCM_UserConvState = RCM_USERCONV_EOC;
}
else
{
/* Nothing to do */
}
if (RCM_CB_array[handle].cb != NULL)
{
RCM_UserConvState = RCM_USERCONV_IDLE;
RCM_CB_array[handle].cb(RCM_UserConvHandle, RCM_UserConvValue,
RCM_CB_array[handle].data);
}
else
{
/* Nothing to do */
}
}
}
else
{
/* Nothing to do */
}
}
/**
* @brief Returns the status of the last requested regular conversion.
*
* It can be one of the following values:
* - UDRC_STATE_IDLE no regular conversion request pending.
* - UDRC_STATE_REQUESTED regular conversion has been requested and not completed.
* - UDRC_STATE_EOC regular conversion has been completed but not readed from the user.
*
* @retval The state of the last user-defined regular conversion.
*/
RCM_UserConvState_t RCM_GetUserConvState(void)
{
return (RCM_UserConvState);
}
/**
* @brief Un-schedules a regular conversion
*
* This function does not poll ADC read and is meant to be used when
* ADCs do not support injected channels.
*
* In such configurations, once a regular conversion has been executed once,
* It is continuously scheduled in HF task after current reading.
*
* This function remove the handle from the scheduling.
*
* @note Note that even though, in such configurations, regular conversions are
* continuously scheduled after having been requested once, the results of
* subsequent conversions are not made available unless the users invoke
* RCM_RequestUserConv() again.
*
*/
bool RCM_PauseRegularConv(RegConv_t *regConv)
{
bool retVal;
uint8_t Prev;
uint8_t Next;
uint8_t handle = regConv->convHandle;
if (handle < RCM_MAX_CONV)
{
retVal = true;
if (true == RCM_NoInj_array [handle].enable)
{
RCM_NoInj_array [handle].enable = false;
RCM_NoInj_array [handle].status = notvalid;
Prev = RCM_NoInj_array [handle].prev;
Next = RCM_NoInj_array [handle].next;
RCM_NoInj_array [Prev].next = RCM_NoInj_array [handle].next;
RCM_NoInj_array [Next].prev = RCM_NoInj_array [handle].prev;
}
else
{
/* Nothing to do */
}
}
else
{
retVal = false;
}
return (retVal);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section (".ccmram")))
#endif
#endif
/*
* Starts the next scheduled regular conversion
*
* This function does not poll on ADC read and is foreseen to be used inside
* high frequency task where ADC are shared between currents reading
* and user conversion.
*
* NOTE: This function is not part of the public API and users should not call it.
*/
void RCM_ExecNextConv(void)
{
if (true == RCM_NoInj_array [RCM_currentHandle].enable)
{
/* When this function is called, the ADC conversions triggered by External
event for current reading has been completed.
ADC is therefore ready to be started because already stopped */
/* Clear EOC */
LL_ADC_ClearFlag_EOC(RCM_handle_array[RCM_currentHandle]->regADC);
LL_ADC_REG_SetSequencerRanks(RCM_handle_array[RCM_currentHandle]->regADC,
LL_ADC_REG_RANK_1,
__LL_ADC_DECIMAL_NB_TO_CHANNEL(RCM_handle_array[RCM_currentHandle]->channel));
(void)LL_ADC_REG_ReadConversionData12(RCM_handle_array[RCM_currentHandle]->regADC);
/* Start ADC for regular conversion */
LL_ADC_REG_StartConversion(RCM_handle_array[RCM_currentHandle]->regADC);
RCM_NoInj_array[RCM_currentHandle].status = ongoing;
}
else
{
/* Nothing to do, conversion not enabled have already notvalid status */
}
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__((section (".ccmram")))
#endif
#endif
/*
* Reads the result of the ongoing regular conversion
*
* This function is foreseen to be used inside
* high frequency task where ADC are shared between current reading
* and user conversion.
*
* NOTE: This function is not part of the public API and users should not call it.
*/
void RCM_ReadOngoingConv(void)
{
uint32_t result;
RCM_status_t status;
status = RCM_NoInj_array[RCM_currentHandle].status;
result = LL_ADC_IsActiveFlag_EOC(RCM_handle_array[RCM_currentHandle]->regADC);
if (( valid == status ) || ( notvalid == status ) || ( 0U == result ))
{
/* Nothing to do */
}
else
{
/* Reading of ADC Converted Value */
RCM_NoInj_array[RCM_currentHandle].value
= LL_ADC_REG_ReadConversionData12(RCM_handle_array[RCM_currentHandle]->regADC);
RCM_NoInj_array[RCM_currentHandle].status = valid;
/* Restore back DMA configuration */
}
/* Prepare next conversion */
RCM_currentHandle = RCM_NoInj_array [RCM_currentHandle].next;
}
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 23,017 | C | 33.458084 | 118 | 0.649346 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mc_math.c |
/**
******************************************************************************
* @file mc_math.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides mathematics functions useful for and specific to
* Motor Control.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "mc_math.h"
#include "mc_type.h"
/** @addtogroup MCSDK
* @{
*/
/** @defgroup MC_Math Motor Control Math functions
* @brief Motor Control Mathematic functions of the Motor Control SDK
*
* @todo Document the Motor Control Math "module".
*
* @{
*/
/* Private macro -------------------------------------------------------------*/
#define divSQRT_3 (int32_t)0x49E6 /* 1/sqrt(3) in q1.15 format=0.5773315 */
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief This function transforms stator values a and b (which are
* directed along axes each displaced by 120 degrees) into values
* alpha and beta in a stationary qd reference frame.
* alpha = a
* beta = -(2*b+a)/sqrt(3)
* @param Input: stator values a and b in ab_t format.
* @retval Stator values alpha and beta in alphabeta_t format.
*/
__weak alphabeta_t MCM_Clarke(ab_t Input)
{
alphabeta_t Output;
int32_t a_divSQRT3_tmp;
int32_t b_divSQRT3_tmp;
int32_t wbeta_tmp;
int16_t hbeta_tmp;
/* qIalpha = qIas*/
Output.alpha = Input.a;
a_divSQRT3_tmp = divSQRT_3 * ((int32_t)Input.a);
b_divSQRT3_tmp = divSQRT_3 * ((int32_t)Input.b);
/* qIbeta = -(2*qIbs+qIas)/sqrt(3) */
#ifndef FULL_MISRA_C_COMPLIANCY_MC_MATH
/* WARNING: the below instruction is not MISRA compliant, user should verify
that Cortex-M3 assembly instruction ASR (arithmetic shift right) is used by
the compiler to perform the shift (instead of LSR logical shift right) */
//cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6
wbeta_tmp = (-(a_divSQRT3_tmp) - (b_divSQRT3_tmp) - (b_divSQRT3_tmp)) >> 15;
#else
wbeta_tmp = (-(a_divSQRT3_tmp) - (b_divSQRT3_tmp) - (b_divSQRT3_tmp)) / 32768;
#endif
/* Check saturation of Ibeta */
if (wbeta_tmp > INT16_MAX)
{
hbeta_tmp = INT16_MAX;
}
else if (wbeta_tmp < (-32768))
{
hbeta_tmp = ((int16_t)-32768);
}
else
{
hbeta_tmp = ((int16_t)wbeta_tmp);
}
Output.beta = hbeta_tmp;
if (((int16_t )-32768) == Output.beta)
{
Output.beta = -32767;
}
else
{
/* Nothing to do */
}
return (Output);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief This function transforms stator values alpha and beta, which
* belong to a stationary qd reference frame, to a rotor flux
* synchronous reference frame (properly oriented), so as q and d.
* d= alpha *sin(theta)+ beta *cos(Theta)
* q= alpha *cos(Theta)- beta *sin(Theta)
* @param Input: stator values alpha and beta in alphabeta_t format.
* @param Theta: rotating frame angular position in q1.15 format.
* @retval Stator values q and d in qd_t format
*/
__weak qd_t MCM_Park(alphabeta_t Input, int16_t Theta)
{
qd_t Output;
int32_t d_tmp_1;
int32_t d_tmp_2;
int32_t q_tmp_1;
int32_t q_tmp_2;
int32_t wqd_tmp;
int16_t hqd_tmp;
Trig_Components Local_Vector_Components;
Local_Vector_Components = MCM_Trig_Functions(Theta);
/* No overflow guaranteed */
q_tmp_1 = Input.alpha * ((int32_t )Local_Vector_Components.hCos);
/* No overflow guaranteed */
q_tmp_2 = Input.beta * ((int32_t)Local_Vector_Components.hSin);
/* Iq component in Q1.15 Format */
#ifndef FULL_MISRA_C_COMPLIANCY_MC_MATH
/* WARNING: the below instruction is not MISRA compliant, user should verify
that Cortex-M3 assembly instruction ASR (arithmetic shift right) is used by
the compiler to perform the shift (instead of LSR logical shift right) */
wqd_tmp = (q_tmp_1 - q_tmp_2) >> 15; //cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6
#else
wqd_tmp = (q_tmp_1 - q_tmp_2) / 32768;
#endif
/* Check saturation of Iq */
if (wqd_tmp > INT16_MAX)
{
hqd_tmp = INT16_MAX;
}
else if (wqd_tmp < (-32768))
{
hqd_tmp = ((int16_t)-32768);
}
else
{
hqd_tmp = ((int16_t)wqd_tmp);
}
Output.q = hqd_tmp;
if (((int16_t)-32768) == Output.q)
{
Output.q = -32767;
}
else
{
/* Nothing to do */
}
/* No overflow guaranteed */
d_tmp_1 = Input.alpha * ((int32_t )Local_Vector_Components.hSin);
/* No overflow guaranteed */
d_tmp_2 = Input.beta * ((int32_t )Local_Vector_Components.hCos);
/* Id component in Q1.15 Format */
#ifndef FULL_MISRA_C_COMPLIANCY_MC_MATH
/* WARNING: the below instruction is not MISRA compliant, user should verify
that Cortex-M3 assembly instruction ASR (arithmetic shift right) is used by
the compiler to perform the shift (instead of LSR logical shift right) */
wqd_tmp = (d_tmp_1 + d_tmp_2) >> 15; //cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6
#else
wqd_tmp = (d_tmp_1 + d_tmp_2) / 32768;
#endif
/* Check saturation of Id */
if (wqd_tmp > INT16_MAX)
{
hqd_tmp = INT16_MAX;
}
else if (wqd_tmp < (-32768))
{
hqd_tmp = ((int16_t)-32768);
}
else
{
hqd_tmp = ((int16_t)wqd_tmp);
}
Output.d = hqd_tmp;
if (((int16_t)-32768) == Output.d)
{
Output.d = -32767;
}
else
{
/* Nothing to do */
}
return (Output);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief This function transforms stator voltage qVq and qVd, that belong to
* a rotor flux synchronous rotating frame, to a stationary reference
* frame, so as to obtain qValpha and qVbeta:
* Valfa= Vq*Cos(theta)+ Vd*Sin(theta)
* Vbeta=-Vq*Sin(theta)+ Vd*Cos(theta)
* @param Input: stator voltage Vq and Vd in qd_t format.
* @param Theta: rotating frame angular position in q1.15 format.
* @retval Stator voltage Valpha and Vbeta in qd_t format.
*/
__weak alphabeta_t MCM_Rev_Park(qd_t Input, int16_t Theta)
{
int32_t alpha_tmp1;
int32_t alpha_tmp2;
int32_t beta_tmp1;
int32_t beta_tmp2;
Trig_Components Local_Vector_Components;
alphabeta_t Output;
Local_Vector_Components = MCM_Trig_Functions(Theta);
/* No overflow guaranteed */
alpha_tmp1 = Input.q * ((int32_t)Local_Vector_Components.hCos);
alpha_tmp2 = Input.d * ((int32_t)Local_Vector_Components.hSin);
#ifndef FULL_MISRA_C_COMPLIANCY_MC_MATH
/* WARNING: the below instruction is not MISRA compliant, user should verify
that Cortex-M3 assembly instruction ASR (arithmetic shift right) is used by
the compiler to perform the shift (instead of LSR logical shift right) */
//cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6
Output.alpha = (int16_t)(((alpha_tmp1) + (alpha_tmp2)) >> 15);
#else
Output.alpha = (int16_t)(((alpha_tmp1) + (alpha_tmp2)) / 32768);
#endif
beta_tmp1 = Input.q * ((int32_t)Local_Vector_Components.hSin);
beta_tmp2 = Input.d * ((int32_t)Local_Vector_Components.hCos);
#ifndef FULL_MISRA_C_COMPLIANCY_MC_MATH
/* WARNING: the below instruction is not MISRA compliant, user should verify
that Cortex-M3 assembly instruction ASR (arithmetic shift right) is used by
the compiler to perform the shift (instead of LSR logical shift right) */
//cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6
Output.beta = (int16_t)((beta_tmp2 - beta_tmp1) >> 15);
#else
Output.beta = (int16_t)((beta_tmp2 - beta_tmp1) / 32768);
#endif
return (Output);
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief This function returns cosine and sine functions of the angle fed in input.
* @param hAngle: angle in q1.15 format.
* @retval Sin(angle) and Cos(angle) in Trig_Components format.
*/
__weak Trig_Components MCM_Trig_Functions(int16_t hAngle)
{
/* MISRAC2012-violation Rule 19.2. The union keyword should not be used.
* If this rule is not followed, the kinds of behavior that need to be determined
* are:
* Padding — how much padding is inserted at the end of the union;
* Alignment — how are members of any structures within the union aligned;
* Endianness — is the most significant byte of a word stored at the lowest or
* highest memory address;
* Bit-order — how are bits numbered within bytes and how are bits allocated to
* bit fields.
* Low. Use of union (u32toi16x2). */
//cstat -MISRAC2012-Rule-19.2
union u32toi16x2 {
uint32_t CordicRdata;
Trig_Components Components;
} CosSin;
//cstat +MISRAC2012-Rule-19.2
/* Configure CORDIC */
/* Misra violation Rule 11.4 A�Conversion�should�not�be�performed�between�a�
* pointer�to�object and an integer type */
WRITE_REG(CORDIC->CSR, CORDIC_CONFIG_COSINE);
/* Misra violation Rule�11.4 A�Conversion�should�not�be�performed�between�a
* pointer�to�object and an integer type */
LL_CORDIC_WriteData(CORDIC, ((uint32_t)0x7FFF0000) + ((uint32_t)hAngle));
/* Read angle */
/* Misra violation Rule�11.4 A�Conversion�should�not�be�performed between�a
* pointer�to object and an integer type */
CosSin.CordicRdata = LL_CORDIC_ReadData(CORDIC);
return (CosSin.Components); //cstat !UNION-type-punning
}
#if defined (CCMRAM)
#if defined (__ICCARM__)
#pragma location = ".ccmram"
#elif defined (__CC_ARM) || defined(__GNUC__)
__attribute__( ( section ( ".ccmram" ) ) )
#endif
#endif
/**
* @brief It calculates the square root of a non-negative int32_t. It returns 0 for negative int32_t.
* @param Input int32_t number.
* @retval int32_t Square root of Input (0 if Input<0).
*/
__weak int32_t MCM_Sqrt(int32_t wInput)
{
int32_t wtemprootnew;
if (wInput > 0)
{
uint32_t retVal;
/* Disable Irq as sqrt is used in MF and HF task */
__disable_irq();
/* Configure CORDIC */
WRITE_REG(CORDIC->CSR, CORDIC_CONFIG_SQRT);
LL_CORDIC_WriteData(CORDIC, ((uint32_t)wInput));
/* Read sqrt and return */
#ifndef FULL_MISRA_C_COMPLIANCY_MC_MATH
retVal = (LL_CORDIC_ReadData(CORDIC)) >> 15; //cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6
#else
retVal = (LL_CORDIC_ReadData(CORDIC)) / 32768U;
#endif
wtemprootnew = (int32_t)retVal;
__enable_irq();
}
else
{
wtemprootnew = (int32_t)0;
}
return (wtemprootnew);
}
/**
* @brief This function codify a floating point number into the relative 32bit integer.
* @param float Floating point number to be coded.
* @retval uint32_t Coded 32bit integer.
*/
__weak uint32_t MCM_floatToIntBit( float_t x ) //cstat !MISRAC2012-Dir-4.6_a
{
const uint32_t *pInt;
pInt = (uint32_t *)(&x); //cstat !MISRAC2012-Rule-11.3
return (*pInt);
}
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 11,992 | C | 29.439086 | 119 | 0.625834 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/gpio.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file gpio.c
* @brief This file provides code for the configuration
* of all used GPIO pins.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "gpio.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure GPIO */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = Start_Stop_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(Start_Stop_GPIO_Port, &GPIO_InitStruct);
}
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
| 1,771 | C | 26.6875 | 80 | 0.438735 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mc_parameters.c |
/**
******************************************************************************
* @file mc_parameters.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides definitions of HW parameters specific to the
* configuration of the subsystem.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
//cstat -MISRAC2012-Rule-21.1
#include "main.h" //cstat !MISRAC2012-Rule-21.1
//cstat +MISRAC2012-Rule-21.1
#include "parameters_conversion.h"
#include "r3_1_g4xx_pwm_curr_fdbk.h"
/* USER CODE BEGIN Additional include */
/* USER CODE END Additional include */
#define FREQ_RATIO 1 /* Dummy value for single drive */
#define FREQ_RELATION HIGHEST_FREQ /* Dummy value for single drive */
/**
* @brief Current sensor parameters Motor 1 - three shunt - G4
*/
const R3_1_Params_t R3_1_ParamsM1 =
{
/* Dual MC parameters --------------------------------------------------------*/
.FreqRatio = FREQ_RATIO,
.IsHigherFreqTim = FREQ_RELATION,
/* Current reading A/D Conversions initialization -----------------------------*/
.ADCx = ADC1,
.ADCConfig = {
(7U << ADC_JSQR_JSQ1_Pos)
| (6U << ADC_JSQR_JSQ2_Pos) | 1<< ADC_JSQR_JL_Pos
| (LL_ADC_INJ_TRIG_EXT_TIM1_TRGO & ~ADC_INJ_TRIG_EXT_EDGE_DEFAULT)
,(1U << ADC_JSQR_JSQ1_Pos)
| (6U << ADC_JSQR_JSQ2_Pos) | 1<< ADC_JSQR_JL_Pos
| (LL_ADC_INJ_TRIG_EXT_TIM1_TRGO & ~ADC_INJ_TRIG_EXT_EDGE_DEFAULT)
,(1U << ADC_JSQR_JSQ1_Pos)
| (6U << ADC_JSQR_JSQ2_Pos) | 1<< ADC_JSQR_JL_Pos
| (LL_ADC_INJ_TRIG_EXT_TIM1_TRGO & ~ADC_INJ_TRIG_EXT_EDGE_DEFAULT)
,(1U << ADC_JSQR_JSQ1_Pos)
| (7U << ADC_JSQR_JSQ2_Pos) | 1<< ADC_JSQR_JL_Pos
| (LL_ADC_INJ_TRIG_EXT_TIM1_TRGO & ~ADC_INJ_TRIG_EXT_EDGE_DEFAULT)
,(1U << ADC_JSQR_JSQ1_Pos)
| (7U << ADC_JSQR_JSQ2_Pos) | 1<< ADC_JSQR_JL_Pos
| (LL_ADC_INJ_TRIG_EXT_TIM1_TRGO & ~ADC_INJ_TRIG_EXT_EDGE_DEFAULT)
,(7U << ADC_JSQR_JSQ1_Pos)
| (6U << ADC_JSQR_JSQ2_Pos) | 1<< ADC_JSQR_JL_Pos
| (LL_ADC_INJ_TRIG_EXT_TIM1_TRGO & ~ADC_INJ_TRIG_EXT_EDGE_DEFAULT)
},
/* PWM generation parameters --------------------------------------------------*/
.RepetitionCounter = REP_COUNTER,
.Tafter = TW_AFTER,
.Tbefore = TW_BEFORE_R3_1,
.Tsampling = (uint16_t)SAMPLING_TIME,
.Tcase2 = (uint16_t)SAMPLING_TIME + (uint16_t)TDEAD + (uint16_t)TRISE,
.Tcase3 = ((uint16_t)TDEAD + (uint16_t)TNOISE + (uint16_t)SAMPLING_TIME)/2u,
.TIMx = TIM1,
/* Internal OPAMP common settings --------------------------------------------*/
.OPAMPParams = MC_NULL,
/* Internal COMP settings ----------------------------------------------------*/
.CompOCPASelection = MC_NULL,
.CompOCPAInvInput_MODE = NONE,
.CompOCPBSelection = MC_NULL,
.CompOCPBInvInput_MODE = NONE,
.CompOCPCSelection = MC_NULL,
.CompOCPCInvInput_MODE = NONE,
.DAC_OCP_ASelection = MC_NULL,
.DAC_OCP_BSelection = MC_NULL,
.DAC_OCP_CSelection = MC_NULL,
.DAC_Channel_OCPA = (uint32_t) 0,
.DAC_Channel_OCPB = (uint32_t) 0,
.DAC_Channel_OCPC = (uint32_t) 0,
.CompOVPSelection = MC_NULL,
.CompOVPInvInput_MODE = NONE,
.DAC_OVP_Selection = MC_NULL,
.DAC_Channel_OVP = (uint32_t) 0,
/* DAC settings --------------------------------------------------------------*/
.DAC_OCP_Threshold = 0,
.DAC_OVP_Threshold = 23830,
};
ScaleParams_t scaleParams_M1 =
{
.voltage = NOMINAL_BUS_VOLTAGE_V/(1.73205 * 32767), /* sqrt(3) = 1.73205 */
.current = CURRENT_CONV_FACTOR_INV,
.frequency = (1.15 * MAX_APPLICATION_SPEED_UNIT * U_RPM)/(32768* SPEED_UNIT)
};
/* USER CODE BEGIN Additional parameters */
/* USER CODE END Additional parameters */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 4,662 | C | 37.53719 | 89 | 0.510725 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/cordic.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file cordic.c
* @brief This file provides code for the configuration
* of the CORDIC instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "cordic.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
CORDIC_HandleTypeDef hcordic;
/* CORDIC init function */
void MX_CORDIC_Init(void)
{
/* USER CODE BEGIN CORDIC_Init 0 */
/* USER CODE END CORDIC_Init 0 */
/* USER CODE BEGIN CORDIC_Init 1 */
/* USER CODE END CORDIC_Init 1 */
hcordic.Instance = CORDIC;
if (HAL_CORDIC_Init(&hcordic) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CORDIC_Init 2 */
/* USER CODE END CORDIC_Init 2 */
}
void HAL_CORDIC_MspInit(CORDIC_HandleTypeDef* cordicHandle)
{
if(cordicHandle->Instance==CORDIC)
{
/* USER CODE BEGIN CORDIC_MspInit 0 */
/* USER CODE END CORDIC_MspInit 0 */
/* CORDIC clock enable */
__HAL_RCC_CORDIC_CLK_ENABLE();
/* USER CODE BEGIN CORDIC_MspInit 1 */
/* USER CODE END CORDIC_MspInit 1 */
}
}
void HAL_CORDIC_MspDeInit(CORDIC_HandleTypeDef* cordicHandle)
{
if(cordicHandle->Instance==CORDIC)
{
/* USER CODE BEGIN CORDIC_MspDeInit 0 */
/* USER CODE END CORDIC_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_CORDIC_CLK_DISABLE();
/* USER CODE BEGIN CORDIC_MspDeInit 1 */
/* USER CODE END CORDIC_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
| 2,034 | C | 22.66279 | 80 | 0.549656 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/main.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "cordic.h"
#include "crc.h"
#include "dma.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
#include "app_x-cube-ai.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <math.h>
#include <stdint.h>
#include "network.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define VEL_SCALE 20
#define NUM_FLOATS 8
#define MAX_EFFORT 0.175 //Nm
#define TORQUE_K 0.0562 //Nm/A
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
union floatUnion {
float floatValue[NUM_FLOATS];
uint8_t bytes[NUM_FLOATS * sizeof(float)];
};
union floatUnion data;
float sin_encode, cos_encode;
float vel_scaled;
ai_float in_data1[AI_NETWORK_IN_1_SIZE];
ai_float out_data1[AI_NETWORK_OUT_1_SIZE];
ai_float out_data2[AI_NETWORK_OUT_2_SIZE];
ai_float out_data3[AI_NETWORK_OUT_3_SIZE];
volatile uint8_t data_flag;
float action;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_NVIC_Init(void);
/* USER CODE BEGIN PFP */
void convert_angle(float angle, float *sin_component, float *cos_component);
float scale_vel(float rpm);
float clip(float value, float min, float max);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
data_flag=0;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_CORDIC_Init();
MX_TIM1_Init();
MX_TIM2_Init();
MX_USART2_UART_Init();
MX_MotorControl_Init();
MX_CRC_Init();
MX_TIM3_Init();
MX_TIM5_Init();
MX_X_CUBE_AI_Init();
/* Initialize interrupts */
MX_NVIC_Init();
/* USER CODE BEGIN 2 */
MC_StartMotor1();
// MC_ProgramSpeedRampMotor1_F(-250, 1000);
MC_ProgramTorqueRampMotor1_F(0.0, 0);
HAL_TIM_Base_Start_IT(&htim5);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
if(data_flag)
{
TIM3->CNT = 0;
HAL_TIM_Base_Start(&htim3);
float enc_mec_angle = (float)ENCODER_M1._Super.hMecAngle/65536*2*M_PI;
convert_angle(enc_mec_angle, &sin_encode, &cos_encode);
vel_scaled = scale_vel(MC_GetAverageMecSpeedMotor1_F());
in_data1[0] = sin_encode; // Sin Encoding
in_data1[1] = cos_encode; // Cosine Encoding
in_data1[2] = vel_scaled; // Velocity
MX_X_CUBE_AI_Process();
action = clip(out_data1[0], -1.0, 1.0) * MAX_EFFORT/TORQUE_K; //Result is in Amps
MC_ProgramTorqueRampMotor1_F(action, 0);
HAL_TIM_Base_Stop(&htim3);
data.floatValue[0] = out_data1[0]; // Value
data.floatValue[1] = out_data2[0]; // Mu
data.floatValue[2] = out_data3[0]; // STD
// ab_f_t m1_ab = MC_GetIabMotor1_F();
// qd_f_t m1_qd MC_GetIqdMotor1_F();
// qd_f_t m1_qdref MC_GetIqdrefMotor1_F();
// data.floatValue[0] = (float)TIM3->CNT/10000.0;
// data.floatValue[1] = MC_GetMecSpeedReferenceMotor1_F();
// data.floatValue[2] = MC_GetAverageMecSpeedMotor1_F();
// data.floatValue[3] = MC_GetTerefMotor1_F(); //electrical torque reference
// data.floatValue[4] = MC_GetAveragePowerMotor1_F();
data.floatValue[5] = sin_encode;
data.floatValue[6] = cos_encode;
data.floatValue[7] = vel_scaled;
// HAL_UART_Transmit(&huart2, data.bytes, sizeof(data.bytes), 100);
data_flag = 0;
}
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV6;
RCC_OscInitStruct.PLL.PLLN = 85;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV8;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
/** Enables the Clock Security System
*/
HAL_RCC_EnableCSS();
}
/**
* @brief NVIC Configuration.
* @retval None
*/
static void MX_NVIC_Init(void)
{
/* USART2_IRQn interrupt configuration */
HAL_NVIC_SetPriority(USART2_IRQn, 3, 1);
HAL_NVIC_EnableIRQ(USART2_IRQn);
/* DMA1_Channel1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
/* TIM1_BRK_TIM15_IRQn interrupt configuration */
HAL_NVIC_SetPriority(TIM1_BRK_TIM15_IRQn, 4, 1);
HAL_NVIC_EnableIRQ(TIM1_BRK_TIM15_IRQn);
/* TIM1_UP_TIM16_IRQn interrupt configuration */
HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);
/* ADC1_2_IRQn interrupt configuration */
HAL_NVIC_SetPriority(ADC1_2_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
/* TIM2_IRQn interrupt configuration */
HAL_NVIC_SetPriority(TIM2_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(TIM2_IRQn);
/* EXTI15_10_IRQn interrupt configuration */
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
/* USER CODE BEGIN 4 */
void convert_angle(float angle, float *sin_component, float *cos_component) {
// Apply sine and cosine functions
float offset_angle = angle + M_PI;
*sin_component = sinf(offset_angle);
*cos_component = cosf(offset_angle);
}
float scale_vel(float rpm) {
return rpm * (2 * M_PI / 60) / VEL_SCALE;
}
float clip(float value, float min, float max) {
if (value < min) {
return min;
} else if (value > max) {
return max;
} else {
return value;
}
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
| 9,294 | C | 28.321766 | 87 | 0.603292 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mc_config.c |
/**
******************************************************************************
* @file mc_config.c
* @author Motor Control SDK Team,ST Microelectronics
* @brief Motor Control Subsystem components configuration and handler structures.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044,the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
//cstat -MISRAC2012-Rule-21.1
#include "main.h" //cstat !MISRAC2012-Rule-21.1
//cstat +MISRAC2012-Rule-21.1
#include "mc_type.h"
#include "parameters_conversion.h"
#include "mc_parameters.h"
#include "mc_config.h"
/* USER CODE BEGIN Additional include */
/* USER CODE END Additional include */
#define FREQ_RATIO 1 /* Dummy value for single drive */
#define FREQ_RELATION HIGHEST_FREQ /* Dummy value for single drive */
#include "pqd_motor_power_measurement.h"
/* USER CODE BEGIN Additional define */
/* USER CODE END Additional define */
PQD_MotorPowMeas_Handle_t PQD_MotorPowMeasM1 =
{
.ConvFact = PQD_CONVERSION_FACTOR
};
/**
* @brief PI / PID Speed loop parameters Motor 1.
*/
PID_Handle_t PIDSpeedHandle_M1 =
{
.hDefKpGain = (int16_t)PID_SPEED_KP_DEFAULT,
.hDefKiGain = (int16_t)PID_SPEED_KI_DEFAULT,
.wUpperIntegralLimit = (int32_t)IQMAX * (int32_t)SP_KIDIV,
.wLowerIntegralLimit = -(int32_t)IQMAX * (int32_t)SP_KIDIV,
.hUpperOutputLimit = (int16_t)IQMAX,
.hLowerOutputLimit = -(int16_t)IQMAX,
.hKpDivisor = (uint16_t)SP_KPDIV,
.hKiDivisor = (uint16_t)SP_KIDIV,
.hKpDivisorPOW2 = (uint16_t)SP_KPDIV_LOG,
.hKiDivisorPOW2 = (uint16_t)SP_KIDIV_LOG,
.hDefKdGain = 0x0000U,
.hKdDivisor = 0x0000U,
.hKdDivisorPOW2 = 0x0000U,
};
/**
* @brief PI / PID Iq loop parameters Motor 1.
*/
PID_Handle_t PIDIqHandle_M1 =
{
.hDefKpGain = (int16_t)PID_TORQUE_KP_DEFAULT,
.hDefKiGain = (int16_t)PID_TORQUE_KI_DEFAULT,
.wUpperIntegralLimit = (int32_t)INT16_MAX * TF_KIDIV,
.wLowerIntegralLimit = (int32_t)-INT16_MAX * TF_KIDIV,
.hUpperOutputLimit = INT16_MAX,
.hLowerOutputLimit = -INT16_MAX,
.hKpDivisor = (uint16_t)TF_KPDIV,
.hKiDivisor = (uint16_t)TF_KIDIV,
.hKpDivisorPOW2 = (uint16_t)TF_KPDIV_LOG,
.hKiDivisorPOW2 = (uint16_t)TF_KIDIV_LOG,
.hDefKdGain = 0x0000U,
.hKdDivisor = 0x0000U,
.hKdDivisorPOW2 = 0x0000U,
};
/**
* @brief PI / PID Id loop parameters Motor 1.
*/
PID_Handle_t PIDIdHandle_M1 =
{
.hDefKpGain = (int16_t)PID_FLUX_KP_DEFAULT,
.hDefKiGain = (int16_t)PID_FLUX_KI_DEFAULT,
.wUpperIntegralLimit = (int32_t)INT16_MAX * TF_KIDIV,
.wLowerIntegralLimit = (int32_t)-INT16_MAX * TF_KIDIV,
.hUpperOutputLimit = INT16_MAX,
.hLowerOutputLimit = -INT16_MAX,
.hKpDivisor = (uint16_t)TF_KPDIV,
.hKiDivisor = (uint16_t)TF_KIDIV,
.hKpDivisorPOW2 = (uint16_t)TF_KPDIV_LOG,
.hKiDivisorPOW2 = (uint16_t)TF_KIDIV_LOG,
.hDefKdGain = 0x0000U,
.hKdDivisor = 0x0000U,
.hKdDivisorPOW2 = 0x0000U,
};
/**
* @brief SpeednTorque Controller parameters Motor 1.
*/
SpeednTorqCtrl_Handle_t SpeednTorqCtrlM1 =
{
.STCFrequencyHz = MEDIUM_FREQUENCY_TASK_RATE,
.MaxAppPositiveMecSpeedUnit = (uint16_t)(MAX_APPLICATION_SPEED_UNIT),
.MinAppPositiveMecSpeedUnit = (uint16_t)(MIN_APPLICATION_SPEED_UNIT),
.MaxAppNegativeMecSpeedUnit = (int16_t)(-MIN_APPLICATION_SPEED_UNIT),
.MinAppNegativeMecSpeedUnit = (int16_t)(-MAX_APPLICATION_SPEED_UNIT),
.MaxPositiveTorque = (int16_t)NOMINAL_CURRENT,
.MinNegativeTorque = -(int16_t)NOMINAL_CURRENT,
.ModeDefault = DEFAULT_CONTROL_MODE,
.MecSpeedRefUnitDefault = (int16_t)(DEFAULT_TARGET_SPEED_UNIT),
.TorqueRefDefault = (int16_t)DEFAULT_TORQUE_COMPONENT,
.IdrefDefault = (int16_t)DEFAULT_FLUX_COMPONENT,
};
/**
* @brief PWM parameters Motor 1 for one ADC.
*/
PWMC_R3_1_Handle_t PWM_Handle_M1 =
{
{
.pFctGetPhaseCurrents = &R3_1_GetPhaseCurrents,
.pFctSetADCSampPointSectX = &R3_1_SetADCSampPointSectX,
.pFctSetOffsetCalib = &R3_1_SetOffsetCalib,
.pFctGetOffsetCalib = &R3_1_GetOffsetCalib,
.pFctSwitchOffPwm = &R3_1_SwitchOffPWM,
.pFctSwitchOnPwm = &R3_1_SwitchOnPWM,
.pFctCurrReadingCalib = &R3_1_CurrentReadingPolarization,
.pFctTurnOnLowSides = &R3_1_TurnOnLowSides,
.pFctOCPSetReferenceVoltage = MC_NULL,
.pFctRLDetectionModeEnable = &R3_1_RLDetectionModeEnable,
.pFctRLDetectionModeDisable = &R3_1_RLDetectionModeDisable,
.pFctRLDetectionModeSetDuty = &R3_1_RLDetectionModeSetDuty,
.pFctRLTurnOnLowSidesAndStart = &R3_1_RLTurnOnLowSidesAndStart,
.LowSideOutputs = (LowSideOutputsFunction_t)LOW_SIDE_SIGNALS_ENABLING,
.pwm_en_u_port = MC_NULL,
.pwm_en_u_pin = (uint16_t)0,
.pwm_en_v_port = MC_NULL,
.pwm_en_v_pin = (uint16_t)0,
.pwm_en_w_port = MC_NULL,
.pwm_en_w_pin = (uint16_t)0,
.hT_Sqrt3 = (PWM_PERIOD_CYCLES*SQRT3FACTOR)/16384u,
.Sector = 0,
.CntPhA = 0,
.CntPhB = 0,
.CntPhC = 0,
.SWerror = 0,
.TurnOnLowSidesAction = false,
.OffCalibrWaitTimeCounter = 0,
.Motor = M1,
.RLDetectionMode = false,
.SingleShuntTopology = false,
.Ia = 0,
.Ib = 0,
.Ic = 0,
.LPFIqd_const = LPF_FILT_CONST,
.DTTest = 0,
.DTCompCnt = DTCOMPCNT,
.PWMperiod = PWM_PERIOD_CYCLES,
.Ton = TON,
.Toff = TOFF,
.OverCurrentFlag = false,
.OverVoltageFlag = false,
.BrakeActionLock = false,
.driverProtectionFlag = false,
},
.PhaseAOffset = 0,
.PhaseBOffset = 0,
.PhaseCOffset = 0,
.Half_PWMPeriod = PWM_PERIOD_CYCLES / 2u,
.ADC_ExternalPolarityInjected = 0,
.PolarizationCounter = 0,
.PolarizationSector = 0,
.ADCRegularLocked = false,
.pParams_str = &R3_1_ParamsM1
};
/**
* @brief SpeedNPosition sensor parameters Motor 1 - Base Class.
*/
VirtualSpeedSensor_Handle_t VirtualSpeedSensorM1 =
{
._Super =
{
.bElToMecRatio = POLE_PAIR_NUM,
.hMaxReliableMecSpeedUnit = (uint16_t)(1.15*MAX_APPLICATION_SPEED_UNIT),
.hMinReliableMecSpeedUnit = (uint16_t)(MIN_APPLICATION_SPEED_UNIT),
.bMaximumSpeedErrorsNumber = M1_SS_MEAS_ERRORS_BEFORE_FAULTS,
.hMaxReliableMecAccelUnitP = 65535,
.hMeasurementFrequency = TF_REGULATION_RATE_SCALED,
.DPPConvFactor = DPP_CONV_FACTOR,
},
.hSpeedSamplingFreqHz = MEDIUM_FREQUENCY_TASK_RATE,
.hTransitionSteps = (int16_t)((TF_REGULATION_RATE * TRANSITION_DURATION) / 1000.0),
};
/**
* @brief SpeedNPosition sensor parameters Motor 1 - State Observer + PLL.
*/
STO_PLL_Handle_t STO_PLL_M1 =
{
._Super =
{
.bElToMecRatio = POLE_PAIR_NUM,
.SpeedUnit = SPEED_UNIT,
.hMaxReliableMecSpeedUnit = (uint16_t)(1.15 * MAX_APPLICATION_SPEED_UNIT),
.hMinReliableMecSpeedUnit = (uint16_t)(MIN_APPLICATION_SPEED_UNIT),
.bMaximumSpeedErrorsNumber = M1_SS_MEAS_ERRORS_BEFORE_FAULTS,
.hMaxReliableMecAccelUnitP = 65535,
.hMeasurementFrequency = TF_REGULATION_RATE_SCALED,
.DPPConvFactor = DPP_CONV_FACTOR,
},
.hC1 = C1,
.hC2 = C2,
.hC3 = C3,
.hC4 = C4,
.hC5 = C5,
.hF1 = F1,
.hF2 = F2,
.PIRegulator =
{
.hDefKpGain = PLL_KP_GAIN,
.hDefKiGain = PLL_KI_GAIN,
.hDefKdGain = 0x0000U,
.hKpDivisor = PLL_KPDIV,
.hKiDivisor = PLL_KIDIV,
.hKdDivisor = 0x0000U,
.wUpperIntegralLimit = INT32_MAX,
.wLowerIntegralLimit = -INT32_MAX,
.hUpperOutputLimit = INT16_MAX,
.hLowerOutputLimit = -INT16_MAX,
.hKpDivisorPOW2 = PLL_KPDIV_LOG,
.hKiDivisorPOW2 = PLL_KIDIV_LOG,
.hKdDivisorPOW2 = 0x0000U,
},
.SpeedBufferSizeUnit = STO_FIFO_DEPTH_UNIT,
.SpeedBufferSizeDpp = STO_FIFO_DEPTH_DPP,
.VariancePercentage = PERCENTAGE_FACTOR,
.SpeedValidationBand_H = SPEED_BAND_UPPER_LIMIT,
.SpeedValidationBand_L = SPEED_BAND_LOWER_LIMIT,
.MinStartUpValidSpeed = OBS_MINIMUM_SPEED_UNIT,
.StartUpConsistThreshold = NB_CONSECUTIVE_TESTS,
.Reliability_hysteresys = M1_SS_MEAS_ERRORS_BEFORE_FAULTS,
.BemfConsistencyCheck = M1_BEMF_CONSISTENCY_TOL,
.BemfConsistencyGain = M1_BEMF_CONSISTENCY_GAIN,
.MaxAppPositiveMecSpeedUnit = (uint16_t)(MAX_APPLICATION_SPEED_UNIT * 1.15),
.F1LOG = F1_LOG,
.F2LOG = F2_LOG,
.SpeedBufferSizeDppLOG = STO_FIFO_DEPTH_DPP_LOG,
.hForcedDirection = 0x0000U
};
/**
* @brief SpeedNPosition sensor parameters Motor 1 - Encoder.
*/
ENCODER_Handle_t ENCODER_M1 =
{
._Super =
{
.bElToMecRatio = POLE_PAIR_NUM,
.hMaxReliableMecSpeedUnit = (uint16_t)(1.15 * MAX_APPLICATION_SPEED_UNIT),
.hMinReliableMecSpeedUnit = (uint16_t)(MIN_APPLICATION_SPEED_UNIT),
.bMaximumSpeedErrorsNumber = M1_SS_MEAS_ERRORS_BEFORE_FAULTS,
.hMaxReliableMecAccelUnitP = 65535,
.hMeasurementFrequency = TF_REGULATION_RATE_SCALED,
.DPPConvFactor = DPP_CONV_FACTOR,
},
.PulseNumber = M1_ENCODER_PPR * 4,
.SpeedSamplingFreqHz = MEDIUM_FREQUENCY_TASK_RATE,
.SpeedBufferSize = ENC_AVERAGING_FIFO_DEPTH,
.TIMx = TIM2,
.ICx_Filter = M1_ENC_IC_FILTER_LL,
};
/**
* @brief Encoder Alignment Controller parameters Motor 1.
*/
EncAlign_Handle_t EncAlignCtrlM1 =
{
.hEACFrequencyHz = MEDIUM_FREQUENCY_TASK_RATE,
.hFinalTorque = FINAL_I_ALIGNMENT,
.hElAngle = ALIGNMENT_ANGLE_S16,
.hDurationms = M1_ALIGNMENT_DURATION,
.bElToMecRatio = POLE_PAIR_NUM,
};
/**
* Virtual temperature sensor parameters Motor 1.
*/
NTC_Handle_t TempSensor_M1 =
{
.bSensorType = VIRTUAL_SENSOR,
.hExpectedTemp_d = 555,
.hExpectedTemp_C = M1_VIRTUAL_HEAT_SINK_TEMPERATURE_VALUE,
};
/* Bus voltage sensor value filter buffer */
static uint16_t RealBusVoltageSensorFilterBufferM1[M1_VBUS_SW_FILTER_BW_FACTOR];
/**
* Bus voltage sensor parameters Motor 1.
*/
RegConv_t VbusRegConv_M1 =
{
.regADC = ADC1,
.channel = MC_ADC_CHANNEL_2,
.samplingTime = M1_VBUS_SAMPLING_TIME,
};
RDivider_Handle_t BusVoltageSensor_M1 =
{
._Super =
{
.SensorType = REAL_SENSOR,
.ConversionFactor = (uint16_t)(ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR),
},
.LowPassFilterBW = M1_VBUS_SW_FILTER_BW_FACTOR,
.OverVoltageThreshold = OVERVOLTAGE_THRESHOLD_d,
.OverVoltageThresholdLow = OVERVOLTAGE_THRESHOLD_d,
.OverVoltageHysteresisUpDir = true,
.UnderVoltageThreshold = UNDERVOLTAGE_THRESHOLD_d,
.aBuffer = RealBusVoltageSensorFilterBufferM1,
};
/** RAMP for Motor1
*
*/
RampExtMngr_Handle_t RampExtMngrHFParamsM1 =
{
.FrequencyHz = TF_REGULATION_RATE
};
/**
* @brief CircleLimitation Component parameters Motor 1 - Base Component.
*/
CircleLimitation_Handle_t CircleLimitationM1 =
{
.MaxModule = MAX_MODULE,
.MaxVd = (uint16_t)((MAX_MODULE * 950) / 1000),
};
MCI_Handle_t Mci[NBR_OF_MOTORS];
SpeednTorqCtrl_Handle_t *pSTC[NBR_OF_MOTORS] = {&SpeednTorqCtrlM1};
NTC_Handle_t *pTemperatureSensor[NBR_OF_MOTORS] = {&TempSensor_M1};
PID_Handle_t *pPIDIq[NBR_OF_MOTORS] = {&PIDIqHandle_M1};
PID_Handle_t *pPIDId[NBR_OF_MOTORS] = {&PIDIdHandle_M1};
PQD_MotorPowMeas_Handle_t *pMPM[NBR_OF_MOTORS] = {&PQD_MotorPowMeasM1};
/* USER CODE BEGIN Additional configuration */
/* USER CODE END Additional configuration */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 13,057 | C | 34.387534 | 96 | 0.592479 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/network_data_params.c | /**
******************************************************************************
* @file network_data_params.c
* @author AST Embedded Analytics Research Platform
* @date Tue Jan 16 16:02:48 2024
* @brief AI Tool Automatic Code Generator for Embedded NN computing
******************************************************************************
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
******************************************************************************
*/
#include "network_data_params.h"
/** Activations Section ****************************************************/
ai_handle g_network_activations_table[1 + 2] = {
AI_HANDLE_PTR(AI_MAGIC_MARKER),
AI_HANDLE_PTR(NULL),
AI_HANDLE_PTR(AI_MAGIC_MARKER),
};
/** Weights Section ********************************************************/
AI_ALIGNED(32)
const ai_u64 s_network_weights_array_u64[5605] = {
0xc0202e8bU, 0x3f117e3b3ec19bebU, 0x3c9a901b3ec14b1fU, 0xbc8856913f3b0461U,
0xbe94180b3e8414b0U, 0xbeeb643c3d6095bdU, 0x3f2e4bf23e7871c5U, 0x3ea6017abedadf73U,
0x3e4f562d3e90781dU, 0x3ebf8245bcb225d8U, 0x3e3a7ebabdd261adU, 0xbe7c42593de9e913U,
0xbf139e6e3e09e884U, 0xbcf60b073e4509ecU, 0xbeb25e2e3f2f2d00U, 0xbe9d74d33cfd8a5bU,
0x3e09fa80be92c91fU, 0x3f2db3cebf444a02U, 0x3f96bed5be1f9e18U, 0xbd222a3b3eb01365U,
0xbceec9553f58a236U, 0x3e469b7b3e8a318cU, 0x3d4c20dabe254a44U, 0x3b3f71c0beb3a3eaU,
0x3f3fceeb3ee76468U, 0x3e3a1ad5be0a1f83U, 0x3d4ba7663dac2926U, 0xbf151402bea21908U,
0xbe4142183e4940f8U, 0x3db0c2553f38d3f9U, 0x3eb9d7173e34b9dbU, 0x3e997d293e09292aU,
0x3e3de249bf419491U, 0x3e97d4c4be167802U, 0x3cfd85f5be301d35U, 0x3eba1185be89c79eU,
0xbf22841abeb11d43U, 0x3ec463adbeeb8eb5U, 0x3e848f063e98dcd3U, 0xbf3c4fa5bf2611e0U,
0xbdd5a7393bf4a892U, 0x3e8aed223e3f3f11U, 0xbf1f9ced3e8ddae8U, 0x3e52aed7be9fec0dU,
0x3ecdcbddbefe944aU, 0x3f54b9e6bd81fe39U, 0xbd6b9d4abe67a39aU, 0x3e8e031c3da1e8d8U,
0x3f2bc172392b7b62U, 0xbead2e0a3d893fb1U, 0x3eb8f14cbe6f5f70U, 0xbeffdf15be91451cU,
0xbcef2d12bedf71edU, 0x3db0fda23d54c95aU, 0x3e0f6d1dbe292f78U, 0xbde2a464beb5173aU,
0xbe2fc800beee10d1U, 0x3ee48a71bdd2f978U, 0x3de4eb063e633bfaU, 0xbdf8c6bebf592819U,
0xbd516ebcbcf92494U, 0x3d8bbcf3beb86d31U, 0x3d592b69bedb7765U, 0x3e0521ae3c82fc62U,
0x3c960532beca6cf3U, 0x3e1ad55cbee5b333U, 0x3f0f9941be8a207bU, 0x3ee81010be248055U,
0xbee97ff23ed6d59aU, 0xbead9cef3e5aeedbU, 0xbe0393c7be88929bU, 0x3e40cbcdbefadd14U,
0x3ebf7550bcd63e1eU, 0x3ea0d7ebbec29538U, 0x3d16b57abf22b9f1U, 0x3e8298d13d4b8409U,
0x3ea3d1a83f136b20U, 0x3e61458fbf7e676aU, 0x3ed0e962bad2076cU, 0x3ed95ce7be5e7cb9U,
0x3cd0a252bf2e24b7U, 0x3dfcad1f3da380e7U, 0x3eb07f57beb05e39U, 0x3ea7bc813eae8372U,
0x3f2264a5bdd022e7U, 0xbbf48eba3ea6b81fU, 0xbd6501803f68318aU, 0xbea370dcbe2522a2U,
0x3d891fd4be2dd8d1U, 0xbea3e69cbeab23fcU, 0xbf2a4ecc3d16d41eU, 0x3e6bc8523e9a8e58U,
0xbc2cb944bf68453dU, 0x3c57ec7c3e090752U, 0x3e83c80ebe3e906dU, 0x3bd097113f031c01U,
0xbe303f9bbe05ed82U, 0x3e1f90f53cf63710U, 0x3e9f9fae3d920f2bU, 0xbea0a81b3e721477U,
0xbc334190bc8f3f38U, 0x3e578af9bd66124aU, 0xbf579f4c3dc42ca3U, 0x3ee2b172be4eea6aU,
0xbe07711d3ef3b462U, 0xbebbe57abd67ac91U, 0xbd1a0a41be2456abU, 0x3ecd38f1bbe618efU,
0xbf69e7b33dd4d870U, 0x3da946153e0df325U, 0x3eb865e33f896d98U, 0x3f35fc08bd4c32a6U,
0xbde67ef43e0c3fb6U, 0xbe5ceaff3f08e4ebU, 0xbf4286d63e81dccbU, 0x3ea463b03d21ec32U,
0xbebad84a3f008e31U, 0xbf026145bdf37da4U, 0x3e82a4c13e6febf1U, 0xbca71db03f8cb702U,
0xbe50910ebdfc7ea4U, 0xbe273a74bee84693U, 0x3d8de276bf0ca8d8U, 0x3dbc0ee73ca7981bU,
0x3e3a3376be2860b5U, 0xbe93bc03bf40b618U, 0xbec242f83dede36dU, 0xbe81b3e03cfab7d1U,
0xbd91a070bec9ce11U, 0xbde8174c3ccf5ae9U, 0x3e697fd1bef724bcU, 0x3e5115a1bf0d5d00U,
0x3f5e98f43e8a3f2dU, 0x3e812927bea2e6bfU, 0x3e78aadfbeb99c0dU, 0xbeab8e343ed2e898U,
0x3df4037abd73ade4U, 0x3f0fb3fabf067e8cU, 0x3f7562a7be1d71feU, 0x3eb609273eee16c9U,
0xbe2b98acbf205b15U, 0x3e4923c23da2b094U, 0x3e591ffabf05cb4dU, 0xbd22f661bf1d60c3U,
0xbd97ba3c3d7c1925U, 0xbeb58c0f3db5ca4bU, 0x3d3efcb83f0ab289U, 0xbe4ebfecbe727a32U,
0xbe522196be88f65dU, 0xbd27a690bef40a94U, 0xbe977bebbe39a379U, 0x3cf1ba88bc2bafc5U,
0x3b8f3060bb353a7aU, 0x3c02efe53c3f63c8U, 0xbdf6cc7b3e211541U, 0xbe2bbe983f459b89U,
0xbe88da433c4cc020U, 0x3f0ca450bd92526fU, 0xbf4cf5623f378695U, 0x3f61f3413e31ec91U,
0x3ef679a6bd034dd3U, 0xbe2e08803f811552U, 0xbef67ada3d712bccU, 0x3ea773e5be826770U,
0xbe9680b53f00a878U, 0xbec85284bca5259dU, 0xbca09b82bed0de28U, 0x3ef18fdebe9d81ecU,
0xbf4c4482bcbb8c07U, 0x3e2bad7bbeb6bc5eU, 0xbd53349dbf1b3b6bU, 0xbf00f1b93e13f791U,
0x3d1631a6bd056440U, 0xbe937dc0be862349U, 0xbf13182bbe1ded86U, 0x3ecbf053be749f58U,
0xbcd2381ebeca1f80U, 0xbd415131bd3b7fe3U, 0x3eeb27cf3dc2a622U, 0xbe70c45a3f2429e8U,
0x3eebd5763e5b78e1U, 0xbe1c5d833e836409U, 0xbe8eab2b3f68dcd8U, 0xbedb0d81bc5e0628U,
0x3d918bc73ca7faa8U, 0xbdac08063defd257U, 0xbeab44bfbe83cb8dU, 0x3ee2d915be2f7979U,
0xbe2f56663f3730e3U, 0xbf4162733e827825U, 0x3df89f84bc93bac6U, 0x3f139eeb3e91d0faU,
0x3f5afd7ebe387f27U, 0x3e61237cbefe59d7U, 0x3e48c5a43f37244fU, 0xbf4745153ec65ba8U,
0xbe85ffd63ea40330U, 0x3d94ff93be4a651bU, 0x3d3d95ffbdcee45bU, 0xbea1527abe6629d3U,
0x3bc43f663e458af2U, 0x3d925db7bdd7a8f2U, 0x3d7bb8853e860c1eU, 0xbe79eea23c695237U,
0x3e232bc5be3e4249U, 0xbe75e4fe3da8c2bcU, 0xbcafa9d53e91e065U, 0xbe604a17bea04fdbU,
0x3e0d2c9bbeabf1ddU, 0x3d5e32a63e0567a3U, 0xbe2aea90be869519U, 0x3d7253c0bdf805bdU,
0xbea413babe33e5b6U, 0xbe865964be89ca08U, 0xbe8474703d9a0c94U, 0xbe598a4ebeac9f45U,
0xbe6e0d21be888984U, 0x3df38c863dae3813U, 0x3d325c9ebe96b08bU, 0xbcffa6e43e302653U,
0xbc2145e23d6b4763U, 0xbdc1dbf93e679eb8U, 0xbd3bbe69be4285daU, 0xbc9e3185be4065bcU,
0x3df704323db8ed14U, 0x3e3f4f75bab67518U, 0x3e28417ebda35e82U, 0x3e258ee9be5378c7U,
0x3deca43a3e0b3ba8U, 0x3da6a894bb294e61U, 0xbd0995e6bea646deU, 0x3a019da8be1b062fU,
0xbcf44055be81ce21U, 0xbea236b8bd4f4398U, 0x3e2c9adabdcd6eceU, 0xbe0b151bbe92c2d3U,
0x3e9023c73e05f3d9U, 0xbe6ebf9ebe4cf0afU, 0x3da4a1b13e9d5d10U, 0x3df1f92c3e705e3cU,
0xbd484878bd83ec07U, 0xbc9ebc943d9d69feU, 0xbe67639dbe5db0d0U, 0xbd762eedbe4615ddU,
0xbe43cbf8be4a9baaU, 0xbcd5760bbdb0ea7fU, 0x3d1b8436be8c1501U, 0xbe97a7e83d835889U,
0x3d806fd6be032846U, 0xbe8be4ecbe59f9a2U, 0xba12dbb6bec242c8U, 0x3dbcdb8e3deee458U,
0xbe0b702c3ddf2e5cU, 0x3d79c3cf3e582017U, 0xbe311ca33df79659U, 0xbe78a4a1be3cdb4eU,
0xbe71484fbdaf4361U, 0x3b3ca4c2be7d8409U, 0xbe014f3fbe83ad05U, 0x3dd532e0be3c0bbbU,
0xbccd5a28be6588b9U, 0xbb1b47f4be1ad0caU, 0x3c01112e3d1cf594U, 0xbc39678e3d4c5ab8U,
0x3c47ba003d1bdb66U, 0x3db9c5edbdd0158bU, 0xbb653f99bd13c3f0U, 0xbd8edb213d188658U,
0xbcd32466bd9f2daeU, 0x3d0df3b83dcb830dU, 0xbe71f6a8bd9d0e1aU, 0xbe838e83bd9000f6U,
0xbcea074e3d19496fU, 0xbdd0877cbd1e41e7U, 0x3d968162bc8ac58bU, 0xbde29adabdedd093U,
0x3cc078703ca884fdU, 0xbda14006bd8d678eU, 0xbc87c9c7bd189c39U, 0xbc805b133d455a72U,
0xbb9d9482bdaf52deU, 0xbd2bfba73c15bdb2U, 0xbb92d5e13d4fcf6aU, 0xbcfe86863d35613eU,
0xbd8728d3bdf7c459U, 0xbb6d28bbbd3b42e8U, 0xbdbeaf9dbdaa78afU, 0xbdf84466bdc86816U,
0xbd752a46bdc243cfU, 0x3e07cc343ba3f93aU, 0xbe35ad81bd1ae1caU, 0xbccfb0923e4411c4U,
0xbd016c71bc312231U, 0x3bb6e830bdbec035U, 0xbda625c33d8c47cdU, 0xbdbf8b92bd0031c2U,
0x3d953639bcfd507cU, 0xbb172dd33d515492U, 0xbe342dbd3c0ef31bU, 0xbd4a6577bd88dc6aU,
0xbda28b48bc5ec36cU, 0x3dc0f77cbe3d1311U, 0xbde0ac16bda2931eU, 0xbc77c47a3b99536eU,
0xbd2cab413cf9e7a4U, 0xbdba952abd847ac9U, 0x3df8fd68bc5b0bfaU, 0xbdd064303d0b8906U,
0xbdc91b39bdd31fddU, 0x3db5aca43dc8a83eU, 0x3bbbef22bcf18eb4U, 0xbe6304b0bda4c69eU,
0xbd2ff8603d5c8061U, 0xbdbc92dabccd35e3U, 0xbe1de2dbbda0d5e3U, 0xbad6e98abdd28ab0U,
0xbe075f2b3db4a129U, 0xbe2cadb73d17bf95U, 0x3cd390d7bd647142U, 0xbcecbbdd3d0e1f58U,
0xbe0374a53d6a2f39U, 0x3bada013bd4f40aeU, 0xbb011e6c3d9074e1U, 0x3dd414dcbe4f0894U,
0xbd304b733d8b5e14U, 0xbe87f666bd449bf0U, 0x3e576b5b3e033c05U, 0x3e2a6299be49b852U,
0xbcafbf6ebe05fb7eU, 0xbe5a185c3dd80cedU, 0xbe469fc7be847085U, 0xbe0c595ebd1efa3eU,
0xbcb8ba3d3deb3ef4U, 0xbe5c473abd928644U, 0xbd162b12bc9df399U, 0xbd977b9abd9e0e95U,
0x3ec5925fbdece6fdU, 0x3d3b7a04be427ff9U, 0x3cda5b7c3c5a3cccU, 0x3aa26495be5bf4cfU,
0xbdb2ed55bd91433dU, 0xbd3d39b1be366fa3U, 0x3d9002dbbc095e3cU, 0xbe2cf6b33a12889cU,
0x3c3694343e456b3bU, 0xbd1b02d33e48a8b7U, 0x3d72bb9bbe1c74e5U, 0x3b53a5b33ccf120fU,
0xbdbf2314bd4bfbe4U, 0x3c3cce9a3cabc5b9U, 0xbd66670dbdd14becU, 0x3e373da2bd4c3407U,
0xbdd63cf2bde361e1U, 0xbd8f1ec1bdb1e026U, 0xbcbc5a81be53c833U, 0x3e29a311be22c050U,
0x3dc153b6be2e2f72U, 0xbd53f37a3c804de4U, 0x3e67f061bdc0caffU, 0x3e681606be33814bU,
0xbd58216b3d169c56U, 0xbdc41a32be914298U, 0x3c84400abe323a1eU, 0xbd86ede53d72c08aU,
0xbd6db2b6be1122d4U, 0xbe002d053d883d0fU, 0xbe305af6be06fdd6U, 0xbc8d2b2c3baaa2f7U,
0xbdd2470ebe33404bU, 0xbd6d3a8d3d64ea13U, 0xbd65a7efbe6aa2aeU, 0x3d3d0236bd3de737U,
0xbdc401253e00bcb0U, 0xbd0aa785bd89d6e3U, 0x3d2cd52e3d2d9bdeU, 0xbd59dfbd3de4a347U,
0x3d981126bd2a805bU, 0x3e02c2db3e1f2ca8U, 0x3e4d2a1cbde7e0beU, 0x3e248f5a3c9f9de4U,
0xbdd77416bdc57320U, 0xbde2e8b6bd181c30U, 0xbdc7234b3cc7f60fU, 0xbcb281fdbcb0977dU,
0xbe8521aa3d672acbU, 0xbd8d92853d3d56beU, 0x3e79b5c2bdbe0fb3U, 0x3e4b0a81bd3a2dcaU,
0x3d1b4aa8be897b8dU, 0xbdc00090bdd2efc8U, 0x3d4ee2763e35009bU, 0x3a62dde2be2a3b1dU,
0xbd55e790bda503d0U, 0x3dc584e1bcf69df7U, 0xbd1877103d8ad653U, 0xbd181568bd9f8396U,
0x3b666d1a3bf78811U, 0x3c1dc810bb6266c1U, 0xbda6eeca3d24b80aU, 0x3d20e543bdd456b9U,
0xbd31432a3e080f49U, 0xbe676d38be3863dfU, 0xbe7fcd4b3d1f1778U, 0x3dd1d77a3d90061fU,
0xbddb593e3d7d09c0U, 0x3d83393cbd2ccf14U, 0xbd414865be05ded4U, 0xbd18716bbdd2498fU,
0x3cc3f95dbd83bb47U, 0x3db4cc023e1503bfU, 0x3e333b153bd2baedU, 0xbd8ab3093caf37f5U,
0xbd192a523dcb5d65U, 0xbda0d084bc9be70bU, 0x3c385386bc5d928fU, 0x3bcc66bd3e58de51U,
0xbc69a54d3ccecb44U, 0xba817510bda0fe1dU, 0xbe6968ddbb65005dU, 0xbe00cdc6bc514f25U,
0xbda7eab73e8c17efU, 0xbe3a57613c6dcd57U, 0x3d9d973c3e19e603U, 0x3d038fdabe1771bfU,
0xbe060196bd5d70a8U, 0x3e0f8cd33af9d038U, 0xbc056680bd1eab4eU, 0x3e041b3d3da112dcU,
0xbe3549e03daa7b4dU, 0xbe4295a43d45effcU, 0x3d990100bd90e3acU, 0xbc638a033df82a25U,
0x3d8926babcd42aa5U, 0x3da2718dbe029a6eU, 0x3dda29e0bd6ba033U, 0xbabb98e53e0aeeebU,
0xbd709c453e3c3fbdU, 0x3d739adfbd3f0577U, 0xbdb9678d3bfdf414U, 0xbddb07a0bdf2753bU,
0xbd8d1c6e3c4171a6U, 0x3caf13a0bc127917U, 0xbc2bd6193d712102U, 0x3d1f55413e007f45U,
0xbbb88be83da4bee7U, 0x3dab95bc3d2e673bU, 0x3d2aaf34bc634ee2U, 0xbe047a6c3bf4a2e6U,
0x3dc4b7db3cac5ff8U, 0x3cca222e3d60f21aU, 0xbd8402ae3c1b702dU, 0xbe01a1e5bdcca9a6U,
0x3e4f630d3d00757dU, 0x3d263aae3e4f1cc8U, 0x3e7c9faebd0d46daU, 0x3d9c8b1f3d876d10U,
0xbe6c8e453d0f0c05U, 0x3cdf9b353ae91066U, 0x3e8985533c6ed144U, 0x3d2d467f3c752c45U,
0xbd939366bc8c51c1U, 0xbe45ec30be4fc0eaU, 0xbe645ae2bb9ff8b6U, 0xbd2b16fd39fa1de7U,
0xba8b4829bd403b6cU, 0xbbe9cfdabd3be82eU, 0xbe4e9d3a3e02f4feU, 0x3e6daf90bdb94474U,
0x3c95fab3bdc85a50U, 0xbd9f1a8abd482626U, 0xbd5dc888be2d82f2U, 0xbd29aae7bc9c94e5U,
0xbe28d3cebe147ab7U, 0xbd80ac6b3d930b39U, 0xbdbdf493bd6b7602U, 0xbd151dce3d93b885U,
0xbda9d3083dee111fU, 0xbc769befbb21a964U, 0x3d6ba791bdd1c185U, 0x3c872440bcb7b5dfU,
0xbda1e971bd07321cU, 0x3d79d3b8bd277003U, 0x3d8adfec3e535584U, 0xbe5474e6bdaa2990U,
0xbde6e5b8be04673fU, 0x3d7e5378bd27ea5fU, 0x3d73afb5bd98e247U, 0x3e98be7abe885506U,
0xbdf94c8a3d0a8498U, 0x3dfff28ebd8aee36U, 0x3c745f74be0f2ac7U, 0xbe2e100b3d84d5fbU,
0x3d0e81a8bdcc5f47U, 0x3dc524563afd99e1U, 0xbe63815b3d53f559U, 0xbdca39e6be8148b1U,
0xbd12f7453e44197bU, 0xbce3c312be14b5fbU, 0xbdce6f483e098892U, 0x3b98a39ebe2024f9U,
0x3c9558e9bc5ab3f0U, 0x3beabb7bbe1724d5U, 0x3d044408bdf0b313U, 0xbdeb26b73dac1f4bU,
0xbdba1f92bd0e68cfU, 0x3dcba1e8bd8bcb6cU, 0xbdba0493bdb0b099U, 0x3cea8b8ebdfa7a0fU,
0xbe05efc1bdc3a14cU, 0x3e41f20fbc4f74f3U, 0xbd886afa3d5fedaeU, 0xbb758dc23b8836ecU,
0xbe87e2403cc57f2bU, 0xbdbd908fbddec34aU, 0x3d10bf9dbe490b5dU, 0xbddc87bd3d83da65U,
0x3e2fe270bd3801abU, 0x3e39627abd85d8afU, 0x3e2d5120bcf01446U, 0x3ab69e43be248700U,
0x3de250463ddb3a56U, 0xbdc027f93df0ce0cU, 0xbcc53341be59b17eU, 0xbe1f3f683da8e161U,
0x3d877eb33c1e4036U, 0x3da32e073db6499dU, 0xbd68fc473d9647bbU, 0x3d40fb48bc3bf74dU,
0xbdd9309dbde00379U, 0xbd28ce10bd29fcf7U, 0xbe05b2903d5c73bbU, 0x3e11deb33d6b3773U,
0xbe8d0349be83fafdU, 0xbdfbd9dc3d9ca991U, 0xbd0a822d3e3f51a7U, 0xbe3cad333dbfd753U,
0x3e213fc73d880d2aU, 0xbe1b4cb8bd313861U, 0x3e211a773be1d20eU, 0xbcc2707c3c196855U,
0x3d739d0c3cf81d8aU, 0x3e5047383df2b02bU, 0x3c870f193c96e1b8U, 0xbd3cae95bd620728U,
0xbc958d98be2592cdU, 0x3d67a9c03e27f5eeU, 0xbd3129c23d842062U, 0x3d48169e3d5e0b93U,
0xbce63ac33d7d0e50U, 0xbdddc65c3df26892U, 0xbd43974ebcac9686U, 0xbd8d98743e073933U,
0xbe7f12963d95592aU, 0xbda669cd3eaee7bdU, 0xbd452befbce3c7d0U, 0xbcdaca673d34dbe5U,
0xbcbc65383dba33c2U, 0xbd91811e3ddac1b5U, 0x3e130fb13c9d0f2dU, 0xbda09d323daf56c2U,
0xbe90b9ecbdad8bf5U, 0x3e67db3abd12b4e9U, 0xbdb387443e29f710U, 0x3e2b99a5be3a562fU,
0xbc8c82bebd0384aeU, 0x3d6ea717bd2dc261U, 0x3d07e6323e4cf7b7U, 0xbd1e74173cb4f923U,
0x3e1e82683e6f4ba4U, 0xbd910e43bd5f8a02U, 0xbdc054abbe255858U, 0x3cc4bada3e6ba72dU,
0x3d1dbfd13caec0cdU, 0x3db3c722bd8de086U, 0x3d0a4ec0bdbf606fU, 0xbd2bdaefbc8cffc1U,
0xbd8b1d86bd986c23U, 0xbcfe2bcc3d994186U, 0xbdd593cd3dc1a941U, 0xbd9557b23ddaf65fU,
0x3e2994fbbd888246U, 0xbd6bce913def709aU, 0xbdd016f03d8e46e4U, 0x3e89f8eb3d3555cfU,
0xbcecdd393e7cd54bU, 0x3d4c95723e0796dcU, 0x3c1a22fc3cdfab3bU, 0xbd62b873bda728e5U,
0xbe01c7eabe904a7eU, 0x3ca60a41bdad13f7U, 0xbcea49a73d3face4U, 0x3da1dcfe3d66040eU,
0xbdaa1e59bdc01d03U, 0xbdd0d8c3bcf30e73U, 0xbd171390be3c89baU, 0xbd95c4253d3a2195U,
0xbd7916a4bde75aa0U, 0xbd96e0ba3d543fb2U, 0xbcc49c653de0f5e1U, 0xbd8da69ebc42c1abU,
0xbdaa979dbe3db296U, 0xbd01612dbe39554bU, 0x3d0a95afbdd047bdU, 0xbdd664d4bcb61adeU,
0x3c09f77f3dbf3b9aU, 0xbdc728ebbe11353cU, 0x3defab1d3c9f1c4aU, 0x3df185763db15be9U,
0xba26737abdfff909U, 0x3cba2b87b9006ddeU, 0x3d0021e63ce0edacU, 0xbe27ed5ebdf38822U,
0xbdc215ccbd175ee7U, 0xbda10265bdb8b57fU, 0xbd23b639bd9cc2a5U, 0x3d8babc1bb073d7fU,
0xbe17ba7c3e1b6deeU, 0xbdfa3c39bdbdc958U, 0x3d8bd76c3d70a7d5U, 0x3e0c1938bdb7f7b1U,
0xbdc82a00be1f9534U, 0xbb20c5333dd9f0c7U, 0xbe4e78adbdff2b8bU, 0xbd4e68e2bd8ca7e5U,
0xbc27e6723d7403d2U, 0xbe80e18d3d6abd36U, 0xb9613b07bd0bf8d6U, 0x3d76b6193cab6950U,
0x3d574a7dbe1003eeU, 0xbdd0b19a3d553132U, 0xbd8274b3bd997b06U, 0x3d9ec9dcbd16e085U,
0xbe138021bdf06762U, 0xbb898393bde8d544U, 0x3cc568debbf2b7f5U, 0x3c9aa6593dab323cU,
0x3d3e62f73e04772aU, 0xbdb05010bd612ca7U, 0xbde026133c6ea290U, 0xbe82a624becf2093U,
0xbd83965a3d81fb1cU, 0x3c985d8a3dc6cf89U, 0xbdcf7cedbdb62ac6U, 0x3d6b4f32bd3116c9U,
0xbd9236003c7e6683U, 0xbcf352613d115eabU, 0xbd952694be836b17U, 0xbc95f82a3dcc4880U,
0xbd4a99563e07ec92U, 0xbb19e78f3d554c36U, 0xbee0c77c3d09dc8eU, 0x3c11cee3be1c013cU,
0xbe357fb3b98e5608U, 0x3d1ee5e1bc9e241eU, 0xbeab33fd3d793ed4U, 0x3e616ec5bc4f0e27U,
0x3e5ef538bea1fafaU, 0xbf3390ef3e732af7U, 0xbdcf76e6bef5f5fcU, 0xbdc4c9693e210567U,
0x3c5f82ddbd1dc672U, 0xbe6abb2ebd82e014U, 0xbdb7c37b3e04154bU, 0x3d226e4a3e0bedb1U,
0xbd17bc533cd3c032U, 0x3dbd51d33d34f0a3U, 0xbf1d02363e3f32ddU, 0xbf074b1f3e4cdb41U,
0x3db00c443cc1e9e6U, 0xbc083faa3e72495eU, 0x3e3353fd3e8d5c18U, 0x3e6d830c3e308b30U,
0xbd5c6ae33e23553dU, 0x3d5469133e3b4d38U, 0x3da36d24bd62d1cbU, 0xbebafdb93d877cebU,
0xbdb82b763e1b60deU, 0xbebfd4563de21f70U, 0xbdd466bb3d69f8b0U, 0xbe9a9ff03c88cf96U,
0x3d029610befe6997U, 0x3e92de913e1cb7bcU, 0xbe212ec33e007558U, 0xbcdc7ee0bcd2a8beU,
0xbc882ea9bd1dd357U, 0x3df8b4dfbda2b387U, 0x3e31f033be015bdaU, 0x3e2faa403e7c896bU,
0xbf20c2f0be377c68U, 0x3e136d97bdf903a3U, 0x3e78cd44be5c40a5U, 0x3da8130fbeca5573U,
0x3bc4a4023e87b71dU, 0x3e3fb0293dd23825U, 0x3e30cdbdbcfab636U, 0xbead0c8c3e15cc2cU,
0xbd94aaad3dd452d5U, 0xbf0b57903c1c60edU, 0x3e0de8413caa26d4U, 0x3de0aa1d3e57ce1aU,
0x3cb5b29d3de6e81dU, 0xbc61bcd53e3054acU, 0xbcea51ba3c7b655bU, 0x3e1cdc80be0e826aU,
0x3d892356be0fad37U, 0x3e34c986be7771e6U, 0x3e0e10d6bcf8a162U, 0x3decf5383e6921f6U,
0x3df5c4f93e523047U, 0x3e16fa2e3cb8334dU, 0x3d5689403cfb761dU, 0x3d2d1d09be5e9513U,
0x3e1e67dbbe52f26cU, 0x3d6fcd01bd4508f2U, 0x3e2e9e1fbe344f00U, 0xbeb970aabd480d01U,
0x3dba30cb3d2fe430U, 0xbd39cff7be5fb7f4U, 0xbcc1358bbe6676b3U, 0xbe17f655bd5f2f21U,
0x3d9d7801be8451a7U, 0xbecfa0983e6a0ea4U, 0x3e42b9373dc35b11U, 0xbf0a0336bf12f14cU,
0x3d06caabbd980413U, 0xbcd214c5bda35751U, 0xbecef5f23ec24698U, 0x3ea8fd46be301968U,
0x3d9bee64be168441U, 0xbcce6abe3ea4cbb0U, 0x3e1e35073e773230U, 0x3e147c8b3e6e90fdU,
0xbdde0fe9befb54f1U, 0x3e2c3d0ebecb750aU, 0xbe3678b93e3ba252U, 0x3e2664413de629ccU,
0x3f07a96ebe21c23bU, 0x3da6b36f3e3bcf56U, 0x3da911f73dbf7e26U, 0xbdde32f8be6e7f42U,
0x3e5db23e3c0a5788U, 0x3d97a8b1be85d84dU, 0x3e5fa5cdbdc5154fU, 0x3cbef5b2be37c35cU,
0xbd8cc7b23d0c7d97U, 0xbed8577dbec784fdU, 0x3da1c4f83e7e8f1fU, 0x3ebc21443e65e721U,
0xbe2ee7debe648a93U, 0x3c45ad35bd252061U, 0xbe98289ebd5621a3U, 0x3818be663ef0814cU,
0x3df049de3e47ee61U, 0xbec17ab93eceeac3U, 0xbe088b8dbf0d6acfU, 0x3d7c2a713e0a696fU,
0xbe1a9eb73e07d78dU, 0x3d8ec9e83d128ca5U, 0x3e8d021a3dc2889bU, 0x3eba505a3da86305U,
0x3dd2c3333eb37545U, 0x3d8edcd8be10b23aU, 0x3f01d2a43da3f9f7U, 0x3e0ee33ebef31f38U,
0xbbd3582cbddaac5eU, 0xbe8b8ee13e745feeU, 0x3e5589c83e85eba1U, 0x3e9b59db3e8687bfU,
0xbe736482bcebe384U, 0xbba2df0e3d8ac2f3U, 0xbd36986abe953f0bU, 0xbda3ab273e97a4acU,
0xbc0757363dfb4c8fU, 0x3e28ea9e3edbebc2U, 0x3daae75a3eb09be0U, 0x3d6be31f3e43af49U,
0xbda73b51bdd84770U, 0xbf06bf79be3fdcd5U, 0x3d8691783e5253f8U, 0x3db96a2a3e9954edU,
0xbd0cdd553e642c66U, 0xbe8efce9bf06797bU, 0x3dd6508d3e71b763U, 0xbef235563dab6f60U,
0xbe977076be8c889cU, 0xbe7e3a6bbe14c6a5U, 0x3ea3d615bcb7938eU, 0x3e90d283be48c274U,
0xbe8dc2643e92706dU, 0xbde6bd37bec84f6cU, 0xbeded88c3e4304d5U, 0x3cb95456bc2bb0bdU,
0xbeb1f4b4bdb1d967U, 0xbd9fc0b53e235d57U, 0xbdc2e47f3e2bb83aU, 0xbd9e4243bdcdcd46U,
0x3d8307c23e021537U, 0xbebe87d23e95715eU, 0xbe818b883e3448a9U, 0xbdc8f337bd3b69dfU,
0x3d909c153d9867ceU, 0xbd8d75c73e71dc62U, 0x3e2dbda03e0e7084U, 0xbd8693b03ec3c169U,
0xbbb2503d3e90f43aU, 0x3e218028be3cb375U, 0xbe934bfc3e9a1aefU, 0xbe4404d23e9762b8U,
0xbeabb69cbca3b63fU, 0xbd72fcd23e29a19aU, 0xbe1cdb8dbe598553U, 0x3e2e5187bea5ad1aU,
0x3e280c7c3e4ab77aU, 0xbdc0474a3d53c546U, 0xbc981f68be6192baU, 0xbcdceca1bcacb1f8U,
0x3dd290f6be5ac01fU, 0x3e4eaec0be54c5e3U, 0xbd9380663e38c94bU, 0xbede3d90bedfd193U,
0x3e5511cdbded370dU, 0x3ea949d7be802307U, 0xbdafac4bbee5fb3dU, 0xbdf67e4f3ea795c5U,
0x3e46a6723e7751f8U, 0x3e91f847bc5632ebU, 0xbee3319c3e23a93fU, 0x3ce44afd3def4a91U,
0xbe166ff63e3f0220U, 0x3a3bc066bd87b649U, 0x3e72d24d3e755698U, 0x3bcaa54ebd4a347bU,
0x3daaf2353e5336f2U, 0x3c56416f3e4a96c6U, 0x3e1b7d09bdb6501dU, 0xbeb8fc75beb9456aU,
0x3e8c811cbeeac1a9U, 0x3e828cb4be8df5cdU, 0xbe273c8c3e90bf10U, 0x3e87516a3e92e62cU,
0x3e84d0333dee11bfU, 0x3d6f898e3db4ed87U, 0xbe2c14e4bec7c131U, 0x3eba3443be5fab91U,
0x3e29cd64bc06abedU, 0x3e69a7d5bea62dd2U, 0xbe6a2c95bd873b33U, 0x3dbf5aa6be7d23cbU,
0x3b43c5fbbe3a0ac5U, 0xbe4de4ffbe84e6ccU, 0x3da8ffcf3d2aabceU, 0x3dee8c22bdb5e6d7U,
0xbe8f04ea3c65a983U, 0x3e05d5b63c6db422U, 0xbe7a0862bed07cc7U, 0x3e0077eb3dfc856cU,
0x3d4e39183d79f7cdU, 0xbe88d33d3dfa172aU, 0x3e5e8d253dc6f780U, 0x3dc770e4be0bae25U,
0x3e02885bbca115b6U, 0x3c901a603d461bfeU, 0x3cee59143dfddcccU, 0xbde3b0b8be2e6db5U,
0xbd82dd31be958f5cU, 0xbc9c48b93d9d086dU, 0x3b921a6cbe039130U, 0x3e102de6bddf87a6U,
0x3cab93683d990115U, 0xbb449d62bcbda48aU, 0x3da74bbbbe8d1604U, 0xbce03793bd549cecU,
0x3d0755e9bdfb1e62U, 0x3e14788d3d41b8c5U, 0x3e38d850bdd4ed50U, 0x3de5d6b83dffc8f4U,
0xbe852b68be3394c4U, 0x3e1bf489bb98f529U, 0x3e4f02263d67b791U, 0x3d9bc4d73dd9ffb3U,
0x3e3798babdbecf48U, 0xbd8ef6db3cf4b68cU, 0x3b47cdd23e7e83a8U, 0xbdd9482ebd4cf4acU,
0xbe7c52363e4462c2U, 0xbe32a27abea62b97U, 0x3e0956803db31b53U, 0x3beadd2d3d2e2425U,
0xbd9c8224bdfa8379U, 0x3e1635d5bc996078U, 0x3db0b9563d308c91U, 0xbd10eb31bb8557ceU,
0x3de98439bdb5b446U, 0x3d62b3cc3e0e9eb5U, 0x3e01c279bea91d2aU, 0xbd45efe4bd20f209U,
0xbeb91a563e0384a1U, 0x3c24ed1abd1d2ddaU, 0xbc1121eebd481882U, 0xbe6ca7503e30c1ecU,
0x3d43d4923a92f175U, 0x3dfbf449bc4db71fU, 0x3d8a36513dba0768U, 0x3c8c7c09bd6c0e7fU,
0xba932a323e091875U, 0xbd88b78b3e125ea5U, 0x3e24cae73ba0e9a9U, 0x3d895d38bdc7d299U,
0xbec85aa1bd6ce1efU, 0x3d9869ba3dc9fab3U, 0x3e0270c73de93200U, 0xbc6be746bad0122bU,
0xbd59632abe6e4110U, 0x3d3493a03e9403b1U, 0xbe0dc7bc3e47a986U, 0x3b345e6bbe152026U,
0xbe8f1c83bdb7f02cU, 0x3e3251e03c9b9e5eU, 0x3dd4c4b0be5acb12U, 0xbf0daf3f3dbab743U,
0xbe090b79bf112cf1U, 0xbdceb9e53d8503d4U, 0x3c6d5440bda2df2bU, 0xbe00d55bbdb60358U,
0xbd8eb7e83cbf2bd5U, 0x3d26fcc83d38e346U, 0x3dfb3108bd04c49cU, 0x3d3d2d8a3ca25cb1U,
0xbefaae0bbc95962eU, 0xbe961de93de4e5a6U, 0xbd8637f33e153c53U, 0x3c2ea942bd8110ccU,
0x39af8c113e4e11daU, 0x3e0834783c96f83eU, 0xbd969cfd3e45c5dfU, 0xbcae96453e474a83U,
0x3d8bf908bdbbbd1eU, 0xbec35cfb3e6b6991U, 0xbc094a6e3dd1ae26U, 0xbedc73753c27c45cU,
0xbd66e4533d04184cU, 0xbe8bd3fabc8e16a2U, 0x3c9e259dbed32ab3U, 0x3e065fe1bc847dd9U,
0xbdb17fe63dc66533U, 0xbd8a01b6bdf8eccaU, 0xbc6454f23bc4efc4U, 0x3e0f3a54bebb1104U,
0xbd025c4abd08d437U, 0x3a65f4393db12837U, 0xbf1877aabf0c158dU, 0x3e53543ebd9ba8d9U,
0x3e29d650be6243d1U, 0xbde8ecc4bee11152U, 0x3caf8df23e1d2899U, 0xbd3c89b63dd16590U,
0x3da832f73e000e4bU, 0xbeacf18f3d23e667U, 0x3c3c67bdbd4510cfU, 0xbee97ac7bbb4f4f7U,
0x3c4e796dbcaf67bdU, 0x3e3d3fa33d14bd82U, 0x3d80f1c0bd5a30f0U, 0x3d910ae33dca4b15U,
0xbd21c3bf3dc24225U, 0x3e1c87f7be022ea4U, 0x3dc9ba34be4784fdU, 0x3e03eac7be2f8de5U,
0x3d9e2385bdbb5178U, 0xbdb3bc233e1a6bacU, 0x3e1df3283d4763fcU, 0x3e4b32ccbe42c4bcU,
0x3da4c197bd146211U, 0xbd184225be7593ffU, 0x3e15002cbe87eea3U, 0x3d3160d23cfa919aU,
0x3e2cfed1be5a6784U, 0xbeac144ebc60b2d9U, 0x3ce512f5bd09a3f6U, 0xbe08e794bdd8a1caU,
0xbe6b91a5be868c21U, 0xbda34048bdeee368U, 0xbca40483bd91d27fU, 0x3dde62cfb9523490U,
0xbe208f643e0b7d8cU, 0x3d069ebabce235d1U, 0xbeadfa4abe3e7180U, 0xbdb6a13cbe6fa1b7U,
0x3cfb164c3d8eb5f2U, 0xbe10981bbe7b7d3cU, 0xbee78a583e894b77U, 0xbd834908bdfaeff4U,
0x3eb378d23c9fd933U, 0xbcc2ee71be40c18aU, 0x3e1ae6c03c80d3a2U, 0x3df8a8943df0c44eU,
0x3c992cddbe2f8eb1U, 0x3de7ada63ef05e50U, 0xbe26c3de3dddb3cdU, 0x3dba599a3e178da9U,
0x3dc31e7a3e9ec4b7U, 0xbeaa74563e2aaee0U, 0x3df9ffa5be178df2U, 0xbcd5de47bd7c55dbU,
0xbe71aac8bddc4e56U, 0xbd8d5d8fbcda8aa6U, 0xbe073e16bc26a13cU, 0x3deea2fc3c966bfbU,
0xbddd78f83d6daea0U, 0xbe25bd83bd98e4daU, 0xbdac6c03becd2101U, 0x3e4af236be47713fU,
0xbe5ed67dbe435e20U, 0xbe358602be7f132eU, 0x3e41c8aabd139caeU, 0xbd69524bbe4240dcU,
0x3e250562bba22961U, 0xbdb0b2603de0d87bU, 0xbe0b3ba93e412e0dU, 0x3d9aae7bbe68dfcbU,
0xbcd1b7cd3e09d3a3U, 0x3e03e157beb9a568U, 0xbe48c1c63e8e29d9U, 0xbe67cef2be4c82b1U,
0x3df7b232be69dcffU, 0xbe3962033d66c6b4U, 0x3e2b257ebd0ca456U, 0x3da20fe73e74b253U,
0x3e19a46d3de366d3U, 0x3e0eb7a93dccf187U, 0x3e118bb03da157a7U, 0xbebffb10bbcf1df6U,
0xbe709ddbbe983a8eU, 0xbd99c5d1bd87a00bU, 0x3e459aa63df56becU, 0xbba6fcd5be6d3353U,
0xbd6cce27be0aae6bU, 0xbe0ee1803dc25a45U, 0xbe9857afbd840923U, 0x3dab3861baa341aaU,
0x3d441df63e26be37U, 0xbdd5d0be3e316bb5U, 0x3e36100e3e0ad0ecU, 0xbe41defe3e28fc71U,
0x3da482bdbe2209e2U, 0x3bce1c3cbd1b4bd7U, 0x3e8622abbec6b56cU, 0xbdded5b43dece3f7U,
0x3dd4b8bd3dbce506U, 0x3d23c7943e1f06dcU, 0xbe46d8b2bd768bb3U, 0xbb819793bd32ff57U,
0x3e073708be94a5b5U, 0xbe03ea9dba52f91cU, 0xbda5f6c0bcf37bafU, 0x3da0c9103e5a15d0U,
0xbe78bd3dbe8a1570U, 0xbe5964a73e78b6e9U, 0x3de9dba93e0a017dU, 0xbe08e73c3d2f22a3U,
0x3dbde5f63e09891cU, 0xbe6e8413bde94f50U, 0x3e1033b33d4ed4abU, 0x3e05d756bd3d76ebU,
0x3e3156913e30231fU, 0x3ea6906e3dbfc7a4U, 0x3d92ac15bd21639aU, 0x3da082343e10c51fU,
0xbe1faa44bdc6ce44U, 0xbd45217f3dc26cf2U, 0xbdb0fd1c3e7823c8U, 0xbe0a9092bd3e2f3bU,
0xbd8c032b3e0fd33fU, 0xbe12175ebd886ca8U, 0x3c8763df3db2371bU, 0xbdbef5e83e9dd1d8U,
0xbe4ad0073d69ae8eU, 0x3d0b66b93e978b4cU, 0x3d543647be2c0e6eU, 0x3c604cf93db3e3e7U,
0x3e690fba3e490f39U, 0xbe48ea573d98b2dcU, 0x3dde8d733cc16c19U, 0x3c4ec58f3d5e8e7fU,
0xbe370388bcb8cf97U, 0x3d14d618bdba6c59U, 0xbdbb024c3d195e8fU, 0x3e20fe36bd903d53U,
0xbdf29f3cbda13869U, 0x3e11d1cfbd83c3bbU, 0xbe2cbe283dbcc432U, 0xbd5227dd3e28dc35U,
0x3e07947c3e42c89aU, 0xbe2ec9dfbd373679U, 0xbd8e01eebe693b23U, 0xbd640a783e125fb0U,
0xbcec782a3dbdcc9bU, 0x3dbbd0fe3cba5c81U, 0x3b2c7dfc3dfae6f0U, 0x3c7aae2f3e7bafaaU,
0x3d488fd6bd135252U, 0x3d8486da3cefd78dU, 0xbdbe410d3cb800e6U, 0x3cfcda89bd135799U,
0x3d8abaa33c128816U, 0x3c1d59a03d3bd337U, 0xbdb232f5bd567299U, 0x3e18bf673e8e80bbU,
0xbe31edba3ebcd779U, 0x3dfde6ac3e4bd039U, 0x3e7595a93d1b0483U, 0xbe4806a43c9f0c45U,
0xbd330e73bd8ed3e6U, 0xbc71352dbd7b0847U, 0x3d2a3244bc6342f7U, 0xbda000293d91efd3U,
0x3d9d6fa93d72b0ddU, 0xbe4ed0a8be39ba39U, 0xbdac0b8bbe6b6b3bU, 0x3d6eb835bd5766cfU,
0x3cef9463be332489U, 0xbe93b8223e31b9e6U, 0xbdba4eabbe46e71fU, 0x3e3b1ec2bde6635aU,
0xbd2015c8be270696U, 0x3cbf990cbe163fb5U, 0x3dbc6b8c3cc06b5eU, 0xbd6ab5cabe1b708dU,
0xbbd300513e123a47U, 0xbe0253a9bd413050U, 0x3d9def233e0efbbdU, 0x3d45fade3e01abf3U,
0xbe609469bc29b012U, 0x3df9ef57bdfb2e83U, 0xbcb94df7bd8e9618U, 0xbe27680fbda80ca5U,
0x3d049963bd61f0baU, 0xbdc6fe0c3dd527acU, 0x3de5ca1b3db5eb7aU, 0xbc96e6233d3daa7cU,
0xbe29f25fbddf6860U, 0xbd9962a7be34e8abU, 0x3deb8c61be72ccc6U, 0xbe634f57be1c4976U,
0xbe11ad2dbe1d86dfU, 0x3e1ce511bd8096ecU, 0xbd8c0d37be26aa78U, 0x3e18254a3d6cd92fU,
0xbe0b93ae3dab9e1aU, 0xbda4b204bc05a81eU, 0x3d2b3142bdee4228U, 0xbd6135773d8b592cU,
0xbc17cdf8be896379U, 0xbe5083963dfd0d4dU, 0xbdd03b29be404fb1U, 0x3cbfde8ebe19e3e1U,
0xbe058aa3bd492301U, 0x3dd0bd27baa60eefU, 0x3d7b62193df91a3dU, 0x3caaef133c0af478U,
0x3d5173453bf27adbU, 0x3d582945bd30d467U, 0xbe65bf65be03c24cU, 0xbdab5ce1be6a4e7eU,
0xbcd248013c856c61U, 0x3cc5472c3d805295U, 0xbe12461dbe28cecbU, 0xbd4349c9bdb2eba6U,
0xbe0b41a0bc9128acU, 0xbd8a5673bd9ef965U, 0x3d4cd52abdd4deb3U, 0x3d83f8a03d7d9d0fU,
0xbca9417e3d81fccfU, 0x3dd42dae3de10a7fU, 0xbde7f2cf3c878031U, 0x3ce64020bd1d2e7fU,
0xbd83f876bd7170ccU, 0x3df65a27be223c23U, 0xbc5932dc3da75a9aU, 0xbdc23a103dd01f81U,
0x3e5d8faa3e836395U, 0x3daf62c2be05a643U, 0xbe139b9e3e4acebfU, 0xbd72bb3ebeb72d65U,
0x3d0ebbe5bd10a399U, 0xbd8c004e3e85250aU, 0x3e09ffa0bdc4fba2U, 0xbdf59f82be40d7baU,
0xbe4ccc643dc0bd31U, 0xbe8639a23e87b9e5U, 0xbd061628bdc76ba6U, 0x3e3b36813e826aa1U,
0xbe927002bc875eaaU, 0x3e2505043e36cd5bU, 0x3e80623d3d837f94U, 0x3e8b8773be5391caU,
0x3e83a4dc3deaac08U, 0x3e0146f83dda770fU, 0xbdcff223bdc0cd88U, 0xbc86815c3c02f81aU,
0x3e1e8453be0bf4a1U, 0x3c960bfabe1e21b6U, 0x3cba0dcabe3bb076U, 0x3d3874c1ba87aa4cU,
0xbd9042223e77ab8cU, 0x3c987b07be19e56fU, 0xbe8746bbbe543fffU, 0xbe8ac3203d884620U,
0xbe23c4e13e1bb203U, 0xbeb23832bdeaba4eU, 0xbe141a64bb6454e6U, 0xbe5b32733e9266aeU,
0x3cc6c45d3e7f739dU, 0x3d1de0bb3e26ceedU, 0x3e302c54bc332c6bU, 0xbea5f0093dc64ec5U,
0x3dd6f09d3d94037fU, 0xbe48cdf9bde62bacU, 0x3dadb88fbe03d5b9U, 0xbd929ad4bd9540b2U,
0xbe6262cdbd67a8a5U, 0x3e1e48fb3d1f3f17U, 0x3dbc7136be85d4e5U, 0x3e3a27413e40cc10U,
0xbd3ff2c83da16756U, 0x3cf040ae3c098c85U, 0x3bdec97b3e4059bfU, 0xbd2e15573e625ed0U,
0x3e5c1d39bcd8a6f4U, 0xbe433ebb3d1daf5dU, 0x3e3cb9703d6c58d6U, 0xbe4d1c513e6f803aU,
0xbdf1223cbe0f858fU, 0x3db7995ebe88ee3eU, 0xbd4c152cbd6eb068U, 0x3e814b03bdf7ce08U,
0x3e2e7fa63e1c3483U, 0xbc4048273d166ffbU, 0xbd2ad17bbc3a185bU, 0x3d40309c3eb0a9ceU,
0xbdfce3c23d6a7be4U, 0xbd880f93bd8f2d2cU, 0xbe5204053e30b565U, 0x3e7330de3e0d6de2U,
0x3dd59c17bcabf828U, 0xbd41ab8dbe13d3b0U, 0xbdf0e87b3d9a8da8U, 0xbdd3a895be053d9cU,
0xbe6e0f4e3e4045d4U, 0xbc5fd7053e423424U, 0xbd0e805ebd8f9f0fU, 0x3d90d65f3dc75573U,
0xbe3c027a3c011c5aU, 0x3e6340babdcce873U, 0x3bd6cdb1be048520U, 0xbe1bdfb9ba542236U,
0x3cf2670fbd4ca089U, 0xbe55a29ebcfe272fU, 0xbd211a163c83812fU, 0x3cea6c143dbd6b39U,
0x3c79201fbd8b706aU, 0x3dd626fc3dee82d0U, 0x3d6f56103e7d72d1U, 0x3e624683be20b6ebU,
0xbd50269a3d8882c0U, 0xbdac266f3d57fe78U, 0x3e4958683c6149a3U, 0xbdb6f9253da1c6ccU,
0x3e4222103d9e1e42U, 0x3c6d87e6bdda20b3U, 0xbd61dcb6be16dd95U, 0x3dbff5a0be0bdd8aU,
0x3e65e6ecbde60cf9U, 0x3e3c8350be879941U, 0xbe69de773e16d90eU, 0x3e43a997bba507baU,
0xbc0f58e4be2ac5e4U, 0x3cddfeb83e139e62U, 0x3d95c759bdcecf8cU, 0x3e86b549be161036U,
0x3de2e4d6bdb174dcU, 0xbad12085be99af7cU, 0xbe5d0a4c3e37e4f5U, 0x3ce41c24bdc76da0U,
0xbe1d7d963da8de3aU, 0xbd95b3973dfb8f24U, 0xbd2199f03e27c539U, 0x3deeda84bdeb8431U,
0xbd162d6f3d93b228U, 0xbda665663e38051eU, 0xbdb344dcbdebee4aU, 0x3d905dbfbe0f8140U,
0xbcec4a023dad150cU, 0x3ec99e37bda12c51U, 0x3e7fd6e73dfe88ecU, 0x3e6f30d4bdcb45caU,
0x3dd2f7d5bc95c322U, 0xbe0b0ed33d519ddbU, 0xbdf01dbebd1ab74bU, 0xbc274ce3bda94a0fU,
0x3e85936bbda4bcedU, 0xbcf887313e1472c1U, 0x3d885789bd040924U, 0x3ede683ebddca756U,
0x3e9c6985bd827c29U, 0x3e1fa566bd10ecb1U, 0x3cde6afc3c92f8faU, 0x3d8862353e803ccbU,
0x3da4aa5ebe3750a4U, 0xbddf6c7fbd8137b1U, 0x3ddbdc3b3d8f4011U, 0x3cea72943e209f5dU,
0x3d42ccd1bd80aa60U, 0xbd37b5053d39865fU, 0x3c47e292bd1fdbceU, 0x3cc8e9bb3d95c1b7U,
0x3ca7607e3d593cd5U, 0x3d85e367baf2cc25U, 0xbcc11524bddbf6adU, 0xbd602efd3de06106U,
0x3df3dc92bcdef247U, 0xbd011ee33c1ea5ffU, 0x3d89ee293da4cee6U, 0xbdb5bf49baff11e0U,
0xbd70a57a3c9bb0d0U, 0xbce4f6d53cf393b6U, 0x3dce4f98bcd37d72U, 0x3d9430f83cf851e6U,
0x3c77108e3d25714aU, 0xbd42844bbcbd0e0dU, 0x3c0e1e84bd4606a3U, 0xbd63744abd1ca21fU,
0xbae2072b3d53d687U, 0x3b973916bbaffa88U, 0x3c8a348abc310ff8U, 0xbdafb71a3d10942aU,
0x3d726c183db8b39fU, 0xbcbddb743d4b2a80U, 0xbe3a611d3dfeba6dU, 0xbd8487263db3d003U,
0xbad6d699bc7b9a35U, 0x3da25014bc58bdeaU, 0x3df39233bd406231U, 0x3cf889d93daf9cb4U,
0x3dd290da3d8250b0U, 0xbd214c293e0e01e9U, 0xbe2a95603d6ed847U, 0x3e06e4033d0b00d1U,
0xbca05b593e38be11U, 0x3e0d5dff3d26d8beU, 0x3d8a680bbc2ed3bfU, 0x3c36492ebcffb5e1U,
0x3dd3dfa93da437e6U, 0xbd8f5c323d5009d7U, 0x3c833f003dc7e41bU, 0xbcba12c2bd1ffb9bU,
0x3d9e6815bc802821U, 0x3c441a7e3cecf6c9U, 0x3d1cd49ebcbbeaa0U, 0x3d1579543e2e5674U,
0x3ddf55d63e3813f9U, 0x3d4c5cd23e2b7da0U, 0xbc3f83bf3cbcba9cU, 0x3dc5b2563d9f2b26U,
0x3c53dd3dbc1ee05aU, 0xbe08b2abb92404e1U, 0x3ddfc44fbd6bbd98U, 0x3dbb97ce3d1dc8abU,
0xbbfcfe833cb86a5bU, 0x3e3df7113e54d418U, 0x3e039dbf3d1e52fbU, 0x3e09d1393d8bec2fU,
0x3e257314bc2528d2U, 0xbe87deabbdf2a564U, 0x3e0eb4473d970b4dU, 0x3e1dd288bde992a1U,
0xbdcbaa833db8e989U, 0xbc881c453db418a4U, 0xbe438271be9ad4f4U, 0xbe0566f53d905543U,
0x3d8650b9bdfa2707U, 0xbd9bfa72bdf1f65fU, 0x3de3ec1bbd9f4afbU, 0xbe8723a33e32b949U,
0x3dd2aa5ebdb111a3U, 0x3bc1a904be634336U, 0xbdd043e23d27237eU, 0xbd90a115be95d09bU,
0xbe26b338bd7b5cafU, 0xbde1c7e0be6515d8U, 0xbdd2ca5e3df0aa8eU, 0xbe33502cbcba5e58U,
0x3ca57b7fbd171a41U, 0x3d2613013e251fb8U, 0x3c5aba55be01c23fU, 0xbe04f3f8bcdab430U,
0xbd1fd81cbdfde844U, 0xbdc9c084bd6d29e0U, 0x3c24749fbe0a8af8U, 0x3e2592763e177d97U,
0xbe023fbdbe21bc59U, 0xbc2117f8bdc9b17aU, 0x3d20da3dbdf8b9d9U, 0x3d913bd63cf337f9U,
0x3e9f90fdbeb219b1U, 0xbe3e6fdcbd7f504dU, 0x3dd23551be320748U, 0x3ce57cdcbe23c5aeU,
0xbedbe1a2be0ec2dfU, 0xbd4419f9be9cb163U, 0x3d8f792a3dc1e6b9U, 0xbea3ba68bde7cf2bU,
0xbd6deb1fbe49b955U, 0xbca459cb3e2dce2bU, 0xbe0f5cf3bdd8a6feU, 0xbd9155253dfa0869U,
0x3cf47d87be4923c1U, 0x3e1e9c663bb2be09U, 0xbd62bf52be87def7U, 0x3ce587aebc132f80U,
0xbd9878ff3e1abe9aU, 0xbe2f13d2be0af796U, 0x3e6bd7bfbcc414a6U, 0xbc8545e5bac0fdbdU,
0xbcb8bb77bd3385d1U, 0xbdcf90c9bdb355bfU, 0x3e20ec753c2388caU, 0xbdc8f9583d4bd390U,
0xbdac1195bde4f2d1U, 0xbe1e1019bc0f9a60U, 0x3d69aa8abd9b6d47U, 0xbe02756ebead31d1U,
0xbe55977d3d519c53U, 0x3e6ce626bd98815eU, 0xba7e073cbd47b136U, 0x3e6f385a3e121586U,
0x3c857749be18c9c6U, 0x3dd2f000ba8b757fU, 0xbd88e1383e901e7eU, 0x3c8f5cf33cb05822U,
0xbbb4a2193d79ca12U, 0xbdd1341a3d221bf3U, 0xbd5fff66bdaa4093U, 0xbea4660dbddff417U,
0xbd3f5293be712651U, 0x3da8d9343baeaf0cU, 0xba96d1ffbdb91780U, 0xbce95932bdd5b661U,
0xbd8dfde7bdab7442U, 0x3ce8dba4bde8a84cU, 0x3ddf40333d8ca1e5U, 0x3d26a93a3d7c3768U,
0xbe1f133cbdd69094U, 0xbe2b5e7dbbff9850U, 0x3ba1fb173d922c02U, 0xbd2b2529bdba0dfeU,
0x3b8c4e103d9068b6U, 0xbcc4cc5a3dc95097U, 0x3db73f9cbbc7d9ceU, 0xbe26aeb8bd7272e9U,
0xbe0e0da43dcb74c6U, 0xbd1d7cfa3e00719aU, 0x3d78e2cabdafcc75U, 0x3a975c713d8f528dU,
0x3c610330bd96d58aU, 0xbe137a5a3c1bdbc8U, 0x3d9dc659bddad810U, 0xbdaffcfd3c9a1b34U,
0xbde061233b02f4e2U, 0xbdba9bee3da9d667U, 0x3d4e287f3d9b730fU, 0xbcb73a56bdca1d67U,
0xbd8f92f3ba1c0657U, 0xbc8ae6583d597062U, 0xbdc17445bd0dd457U, 0xbde5b941bd87ab97U,
0x3dad9bcc3e077369U, 0x3cbd79dc3d8d028eU, 0x3dd37b2ebc0db257U, 0xbe18a11ebd916fc9U,
0xb9a6ce3e3ddcf723U, 0xbc62543bbe136a07U, 0xbd606648bdd66ea8U, 0xbe27fef5bda638b1U,
0xbda46e733d99f55dU, 0x3d2d65bdbe40a5eeU, 0xbca4de42be24f50fU, 0x3dd024863cfe2d60U,
0xbd9024e3bb16fef4U, 0xbdf3015bbe138c97U, 0xbca80b763d7db297U, 0x3d604d6c3d5c690cU,
0x3da8569e3dd30b25U, 0x3d9047ff3cd0bb5bU, 0xbe01e076bd190264U, 0x3d84836cbdf71becU,
0xbc3f3001be0ed15cU, 0xbdfe5ca1bc8d1ee6U, 0x3d31ea2fbe2b3df7U, 0x3dd558193b8affecU,
0xbe2d1fa23d077f3fU, 0xbe8857a23dbadde8U, 0x3c0b6ca9bbe6652cU, 0x3d949d3e3dbebedaU,
0xbe4972a3be0ad38fU, 0xbdc6f689be76d1f1U, 0xbd065d17be199ad7U, 0xbe85d2433e2a5df9U,
0x3e3849253e9784c4U, 0xbe94fc09be61a0e2U, 0x3dd66166be5ad380U, 0x3d35826cbe865752U,
0xbe348be23c9a63fbU, 0x3d302960be9da981U, 0x3d40060abd4208b2U, 0xbd80de77bdf928c1U,
0x3d2e5590bd57ca48U, 0x3e7fa00ebe35f487U, 0x3e25cf2fbe9987ddU, 0x3dd3795ebe887aa4U,
0x3dc5f1b6be1dd3d9U, 0x3e350d123e011d7dU, 0xbe014740bd361e8fU, 0x3e669e5e3e4174beU,
0x3e2857593e040877U, 0xbde4387ebc8cdf36U, 0x3e3412c23e24a7cfU, 0x3e6e2937bea70dfdU,
0xbe4d59cfbccb9728U, 0x3e4f2115be7ac284U, 0xbdac680d3cab314dU, 0xbebba816be62e40cU,
0x3e2b5dee3dc66788U, 0xbe4301c33e7102b2U, 0xbe55baa9bdc3b523U, 0x3e29f51dbdb8d670U,
0xbe14b1e0be8a02fcU, 0xbe768cb7bd865df8U, 0x3e1fd16c3e235ae7U, 0xbed0dd17be684a00U,
0xbdb5a14bbeda519cU, 0xbe67b3d33e74dba6U, 0xbecadcb13e28efe9U, 0x3e4b4969bdbacc0dU,
0x3db2a1d9bd87a9e4U, 0x3d278d503df876ecU, 0x3e2639493e8e96f0U, 0x3e3d1fb4beacabe2U,
0x3d55f50cbe11cae0U, 0xbe187d3cbe33fd0eU, 0x3e58c4423c415ed7U, 0xbde16bc13e6043baU,
0x3e38ebfe3c8d3386U, 0x3dcd85523db4fbc0U, 0xbde46efbbd5100f6U, 0xbeb2e26d3e58f871U,
0xbeef663fbe125c70U, 0xbe58e17d3de7a012U, 0x3e51decf3e69cd3fU, 0x3e1040cabe4fc5a9U,
0xbdd4c4103d682e2cU, 0x3ddd3bd93e6ff424U, 0xbe9631dbbdc7c248U, 0xbe4e04d7bdb9913aU,
0xbc1dc1f13e532e42U, 0xbea938223dc7f4b7U, 0xbb746e803e317a64U, 0xbe5166bbbdd5c5abU,
0xbdf642873d1d0d97U, 0xbe4452d3be013aa6U, 0xbceb1b03bdb35460U, 0x3cd1984bbdb1ff9dU,
0xbde64a593d109820U, 0x3c19acecba75ade2U, 0x3d367d5ebe2e533bU, 0xbda5dd5b3d0c0ba2U,
0xbe186b88be992810U, 0x3c555e80be046e75U, 0xbe1d84083d35e2e3U, 0x3dc058ebbd9a1f3bU,
0xbdd565b7be1e58f6U, 0x3d17770b3c6d95afU, 0xbe4a844e3db217eaU, 0xbd8f3b77bd2af80eU,
0xba3e03003dbd9bf8U, 0xbe0a5cf33e222bf3U, 0x3e90171fbc528024U, 0x3d4afafe3cbd7a54U,
0x3e1d9626be225f9cU, 0x3dd00fe93c8a31f2U, 0x3d78c9e33d4e7b11U, 0xbd903b5dbe5b0781U,
0xbda3e2b73d62a20cU, 0x3d4d02e3be2e5964U, 0x3d3d11efbe7a8522U, 0x3d98005cbdb0d4a6U,
0xbc6c5fb9bd89d266U, 0xbd96f219bbd4cc54U, 0xbdfb9b47bc6c26dbU, 0xbe161750bdf409f2U,
0xbc9290c3bca42147U, 0xbd6872693ca62ec1U, 0xbe959930be531830U, 0xbbc67c39bdbd7daeU,
0xbe8cd8823e0b6b5cU, 0x3dc1bba23d1d4b4fU, 0x3ca980a63e0dc1faU, 0x3dfb5afebde77a51U,
0xbe182a7b3d7da2dcU, 0x3ddfd1013cb792b2U, 0xbe214e37bc9ba980U, 0x3d947f603db3de72U,
0xbd9b0c21be42da01U, 0xbe004cc6bdc8e531U, 0x3b3c9cb5bdb6c876U, 0xbe12b00ebe5eb81eU,
0x3d9f7f0b3e0f2dffU, 0x3d364ee63d7ae4b2U, 0x3d2d38ae3c642bdfU, 0xbcd7f45a3e02da60U,
0x3b4dbaad3dcc3495U, 0xbe5effeebe0e0052U, 0xbe326f5bbe2f39fbU, 0x3d6be089bd402d66U,
0xbe01d31c3dbe4056U, 0xbe2ab6f6bd565888U, 0x3d9ccb1ebe3eeef0U, 0xbc0f0476bdbf24f5U,
0xbdaa35dcbe12d7f1U, 0x3c3047fe3d26f723U, 0x3da11b283e1a2298U, 0xbd862b13bdf02c6dU,
0x3d540bb53df43a0cU, 0xbdc5d35dbe04464fU, 0xbdd77b52bd4f7e6fU, 0xbe11e70e3d18ec3fU,
0x3e3f7ca43e5c5312U, 0x3d8882753dbc5d1bU, 0xbd2fc94abd54d3b0U, 0xbe748935bcf3b10fU,
0xbe0b4ceebe5d5aa9U, 0xbe5872213e2a8a84U, 0xbb8402373e9cb833U, 0xbd7269acbd01d02eU,
0x3c1ed9ab3e26c364U, 0xbe1e0c993d341766U, 0x3eba64883d92d414U, 0x3b98e9123cb88946U,
0xbc9168783d5b57a7U, 0xbcb416663b6ddbe0U, 0xbe3647a13d643561U, 0xbd79b6883d7fb0f3U,
0xbde97affbd85da65U, 0x3db11588bdc2bbecU, 0xbd1ca3cebcfcb24aU, 0xbdb5c52b3e2ec8daU,
0x3e991511bdc9e104U, 0xbb3840f83d47f4a9U, 0xbbdbaa00bd84ba73U, 0x3dc6d3a33d908203U,
0xbcfc3e8abcd6bfddU, 0x3e63eefd3e140a6dU, 0x3beb0cfcbdd46efeU, 0xbe1857efbe0bc5f3U,
0x3d932a43be50b8b7U, 0x3e091bbbbd4bf665U, 0x3e941eeebea06f2fU, 0xbdeb7faf3cac6d8cU,
0x3e90bc81bc357d86U, 0xbcca8d82be452016U, 0x3cf655fd3e360a38U, 0xbd67dd4abdf9a58cU,
0x3e85a7e8bd864556U, 0x3e436e15bd2188e0U, 0xbe046836bea6afc7U, 0xbe39a9743e2984cdU,
0xbcee8cbabe29b1eaU, 0x3ca3018e3c1ad704U, 0x3c0cf9853e1e55f4U, 0xbdcd8a1c3de31e7eU,
0x3de816a6bd73b7ceU, 0x3cb35400bc79f263U, 0xbdfdc9e93d3178dcU, 0xbd8e64debddbaf8fU,
0x3d22acc9bc8c5c24U, 0xbd0639813dc1771eU, 0x3ed01c99be10e0b7U, 0x3ebd0fdb3e783ad1U,
0x3e68de21bddec619U, 0x3c22bc68bdb2b179U, 0xbe0182fe3e3b177dU, 0xbdccfef53d748f47U,
0x3d0ad5c6be1ff820U, 0x3e78254abe12325bU, 0xbe2450043e2da6f3U, 0x3e04cbf9bdad38c3U,
0x3ed30fe9bd5dec11U, 0x3e925feebe313936U, 0x3e403453bdf16ed3U, 0x3d80c2473d55fbf5U,
0xbc87ca053e957eceU, 0x3d9ae0903d60eab0U, 0xbdc50d703d8fd246U, 0x3d454cf9bd8f387aU,
0x3c2bf68dbe6f36edU, 0xbe827b413db74c4aU, 0xbcc71267be90f341U, 0xbd41cf76bc808f81U,
0x3db54ea33d0ae747U, 0xbd925119be5bb2f8U, 0xbd06c0053ad00915U, 0x3e1ad739bce486faU,
0x3e93fcb23b31ab13U, 0x3cdcc4a53d1a1a06U, 0xbdc5d1a33b5504dcU, 0xbe298b92bdcbedfeU,
0x3e7158d93decd75eU, 0x3cd3ed69be167589U, 0x3be9fe4cbd7b5729U, 0x3d5eaa3c3dcea051U,
0x3d7f0259bdf8e927U, 0xbe16ab0bbd9c8d4fU, 0xbcc4b3663d2a52c8U, 0xbe3d4936ba87e838U,
0xbc366714bca234bbU, 0xbd6c0c403dfd3947U, 0xbd4e4a0bbc8ab4e2U, 0xbdbba112bd7277d7U,
0x3dd1e968be94eaa8U, 0xbd1362983acd9f93U, 0xbd8b18803d59b3a1U, 0x3d8ed8893c4b24a8U,
0xbd4169cf3d5a98a3U, 0x3e0ab0dcbdfc18ffU, 0x3e0fbabc3da3a23bU, 0x3d1d4d14be01e03aU,
0xbe693dffbe547d40U, 0x3d1d6b2fbd93d0a5U, 0xbd1502923d0e6c95U, 0x3e03dab5bda178d5U,
0xbd71d0aa3d70409eU, 0xbda00ea1bbd734cfU, 0x3dc0738e3e396b4fU, 0xbab6cedfbcc52bd1U,
0x3d0ee890bd995b57U, 0xbe3721723d6f4aa8U, 0xbd9241653bf132b5U, 0xbc800be2be0f585cU,
0x3e9532a8bdf6183fU, 0x3e1a42da3d5fbb36U, 0x3cbfff48bcd7865eU, 0xbcac236bbe28f7dbU,
0xbd52b0663d520a9aU, 0x3d30d8d63ce2a2eaU, 0xbd6ce14f3db4f283U, 0x3e411f32bd0c435fU,
0x3dc6f520bd261e0dU, 0x3bb556443d0616eeU, 0x3c417a39bc956d98U, 0xbc94d9903d9514cdU,
0xbd1def82be919681U, 0x3ddd5a76bdc9c91cU, 0xbdb5fd3a3ceddc6bU, 0xbe8681de3cebf3d6U,
0xbd9f8674bd8935deU, 0x3d3b3b1e3c3598feU, 0xbe449d50be1d5c66U, 0xbdc23835be24b976U,
0x3e0f87cfbda20f93U, 0x3c346e893e0294adU, 0xbd7c3b643bcf21ddU, 0x3c323112be11cb78U,
0xbdc83f8fbc9c9d5cU, 0x3de4d5d3bcead34eU, 0xbe2423c4bd818f54U, 0x3d7a7136bd905c79U,
0xbe24e5b9bd996b01U, 0x3c941a97be3b3228U, 0xbd41b0a9be702531U, 0xbd82d3a8bd5564c9U,
0xbe073f9dbdb2c315U, 0xbe0e623cbcb07abfU, 0xbd817233be87fa74U, 0xbbf7984b3d93e84eU,
0xbe3768fdbd80787fU, 0xbd212cdcbd37943eU, 0x3c9c70e13e3fff87U, 0xbd71323abd86cec5U,
0x3caf01adbd9ca063U, 0xbd224821be0e78c3U, 0xbe3459e83c3a3fecU, 0x3db995d8bce1b7ecU,
0x3b90726f3dda08e3U, 0xbcb9778dbe16b01aU, 0xbd31865dbcb03d39U, 0xbddd51cfbcd5d05dU,
0x3cb67658bcc389ddU, 0x3e706e51bdd4216aU, 0xbdf4dfa9bd67ab92U, 0xbc752ad3bdbddc61U,
0xbd8431d7bd921d01U, 0xbe5ee1bbbdb4f916U, 0xbc496485be15d86fU, 0x3e19171c3da94fd4U,
0xbd4109ddbddd384fU, 0xbce32a48be31a18cU, 0x3d9098733e120d9dU, 0xbe01c438bdc851f0U,
0xbddbc1d13c65e804U, 0xbcd4ac7fbb9c940aU, 0x3da56ee53e1c99baU, 0xbd416df4bda48b30U,
0xbd084053bd38ea21U, 0xbe111fdc3defdb53U, 0xbd0bf225bdb0be8aU, 0x3d4a82d2bcbc00dcU,
0xbe3ff108bb46de8bU, 0x3d15ad483d041d2aU, 0xbc335f12beaeb637U, 0x3dca7a90bce4900aU,
0x3cd69faebd851d3aU, 0x3d24135dbe242464U, 0x3d6343e13df2979eU, 0xbc22e890bd851a06U,
0x3c9cbb32be003028U, 0xbe2ad9d2bc12c33cU, 0x3dce84983ce470ccU, 0x3dac6911bcfcc848U,
0x3e1f0e7f3e08df33U, 0xbdb798f8bdb1ad70U, 0x3d5957393d29de1bU, 0x3cd027523da9d301U,
0x3e9d13d7bd346917U, 0x3cda632e3e08df1fU, 0xbe350ac93daf724aU, 0xbd8c728c3dec5bacU,
0x3d526842be425657U, 0x3d5ccc843dd938dfU, 0x3e96d126be205c3eU, 0xbc70d7913d2d601fU,
0x3e1575563d2f9497U, 0x3c25bb97bd67cd05U, 0x3bb076b5bdd86173U, 0x3d3e78c23e43d72eU,
0x3d16fdda3d23b579U, 0x3e1ac9fcbd55af41U, 0x3db259af3d86e11eU, 0x3da58109be37e323U,
0xbdc973b93c48042cU, 0x3d924b7ebe54031fU, 0xbdec94233df78bb2U, 0xbcaa9360be00bba1U,
0xbcce36d4be30837eU, 0x3dc6af593e894c1cU, 0x3d98ee43be4b91daU, 0x3e4fadcbbde570b7U,
0xbc1d55e73d90a4d6U, 0x3e512650bdb3a319U, 0xbbb2705c3e7fb672U, 0xbde6ce203daba720U,
0xbe3d43bbbd734919U, 0x3d70ec833d868b8dU, 0xbdfff34b3e89cdc4U, 0x3e153d2bbc958d1aU,
0x3c985ff1bdccf35eU, 0xbe45a77f3e99d2b5U, 0x3d2688813d0b4a70U, 0x3dd9b1a63e55a53dU,
0xbe8284d536650b1eU, 0xbe3c22613e4d0579U, 0xbd39eac23e6b8f3fU, 0x3d80352cbe176ab3U,
0xbd907c5ebe3f642bU, 0xbcc2d502bd9c8d5eU, 0x3e449df6bdcc76c5U, 0xbb94912d3ca2b54cU,
0x3c8e7b12bdb4611cU, 0x3e1d729b3e123a0dU, 0xbdc34b44be29263aU, 0xbda35044bcbc57ebU,
0xbe18fa3ebe0e2943U, 0xbd739fdebdaef85aU, 0xbde8609a3e00be32U, 0x3e9d13793e251da2U,
0xbced19c93ebd784bU, 0xbd5b9c3f3e80ae73U, 0x3e70d54bbe155c6bU, 0xbe03efcabe085924U,
0xbe4e5ff7be192b34U, 0xbdf5da473d5c2910U, 0x3e6f23463e85deb2U, 0xbd3b70b13dcce683U,
0xbe0e554b3dc20612U, 0xbe09db2b3eb34357U, 0x3d83cc9e3e11b041U, 0xbd0f04163e61b79fU,
0x3d6618453d526ad7U, 0xbda774273da0ffc0U, 0x3d939be53dff3766U, 0xbc58beefba1bd570U,
0x3e2c1cbebd0459b3U, 0x3c80238dbd634377U, 0x3da822623cf278e1U, 0xbe16290dbc3eab4fU,
0x3d7f69c03ccc58aaU, 0xbd81b6ea3a5ab29fU, 0x3e5c2a98bd6aebbaU, 0xbe00a5c93ddeeef4U,
0x3d2f7b893da6576eU, 0xbb1ea89a3bc21971U, 0x3d3defa03e069488U, 0xbd5455abba197908U,
0xbd4c29cc3dd577b1U, 0xbd9af5d43c0d33cbU, 0xbdeee8d63d8a9186U, 0x3d88e8d03dad8f40U,
0x3ddbea483d87b9f3U, 0x3d792a5e3e0fd06bU, 0x3dfa7c4f3d41689aU, 0x3d41e62abc177fdeU,
0x3ab2dbc5bd550ab8U, 0x3e1ad1613e23a682U, 0x3be8157abcb03882U, 0x3ddcc6df3dd82c39U,
0x3d8011a2bc626ecbU, 0xbd3fc55bbd39b18bU, 0x3df198b3bda5618cU, 0x3e086405bd810f0bU,
0x3e4ada1abda3b6c4U, 0xbeba03e23da2cd7aU, 0x3d625a743de8d3e6U, 0x3d480956be3007dcU,
0x3d68e4583e178615U, 0x3da5f0bebb64cc31U, 0x3e09bfe13e047e04U, 0x3df341b9bcb220a3U,
0xbdf0a8c5bdb091dcU, 0xbd7c373c3d518822U, 0x3d7a6c19be3447b1U, 0xbdd8fff63e0dbd1dU,
0x3afc85fd3d53ea66U, 0x3de504d93e202d78U, 0x3e2bc045bdb8461fU, 0x3d6348abbdd2ac5dU,
0x3d3cdd783e31346bU, 0xbde814853d3fdfdaU, 0x3e107e913dba56a6U, 0x3cd1cbc8be6b22caU,
0x3df79b1cbd9c0c10U, 0x3e4a4e723deb944fU, 0x3ce27d783b1f2ecbU, 0xbdade705bd3c7090U,
0x3d2c48343d5527d4U, 0xbe28d9c9bc1fdee0U, 0xbc017497be27b8e6U, 0x3d1b7d4d37fa514dU,
0x3d39f597bcaa190bU, 0x3dfb0b8a3dacffb8U, 0x3e1c28d73d4f7dc7U, 0x3e9079d73d1f24c3U,
0x3e1874b5bcdb7e64U, 0x3c2d5bed3d96bb22U, 0xbcb23a673e0e51c7U, 0x3d2ac58bbdea86baU,
0x3d2a7d20bd5b4785U, 0x3c76c80ebd958433U, 0x3d77827e3e5eaa16U, 0x3e15d9f03d596d66U,
0xbdce53a13e9303a3U, 0x3c0ade7fbd71d453U, 0x3e46ba17bd270e97U, 0xbd0beb613deb4a4bU,
0x3df9ced03da527b7U, 0x3e281167bde9570cU, 0x3e416c08bdd6b9a3U, 0x3d87364d3e1c5ffeU,
0xbc91067c3da4f5aaU, 0x3e9062fd3cd250deU, 0xbd1d9b8b3d92e114U, 0x3e6b357fbd4bee97U,
0x3d89ec6b3dbc8aa3U, 0x3dd12ae83dd40f17U, 0x3e89517a3d9b122dU, 0x3dff040d3cbd3838U,
0xbdaff0aabde169e4U, 0x3dc2ffc23e2a7c7bU, 0xbda79da13db57be7U, 0x3e1a9a063da4dd37U,
0xbbfc0b6f3df2da0bU, 0x3d863bb4bdc78f15U, 0x3daf77c03e96e66aU, 0x3de36e1f3c01a9b8U,
0xbc04f6813e4cd05eU, 0xbd5827f3bd329536U, 0xbdae86c93e77b1dfU, 0x3e01da493bf74b5cU,
0xbbda0408be0acc0fU, 0x3d8489dd3cd94097U, 0x3e4740283e7f4518U, 0x3e68f7623e183194U,
0x3d9adcd4bc945d47U, 0xbe30f4ef3cc3feeeU, 0x3e883b6cbac6bba6U, 0xbe0f33163e2bc47bU,
0x3d365fad3e33b59dU, 0x3d732739bd248054U, 0x3cef7c5ebc421713U, 0x3e1023583deb158eU,
0xbde59fcf3d56d345U, 0x3e438f423e0370e7U, 0x3d818a803dda6c90U, 0x3e32ee64bc9f5f0dU,
0x3dd9ceff3dcdd2bdU, 0xbdd00f033e73ca96U, 0xbe0665ecbcbbf65fU, 0x3d9c6e723d957866U,
0x3d44f762bc584804U, 0x3d06c58f3da7962fU, 0x3df619253d0d47f2U, 0x3cd17e1b3c555786U,
0xbd18efe23d73029dU, 0x3e09e9dfbd021803U, 0x3e08f39e3e2f0293U, 0x3d8b455d3d8910abU,
0x3e8407013d9d2bc7U, 0x3e2abe393e514390U, 0x3d9e28c13c3b6669U, 0x3d2181a53dacbe3aU,
0xbe3db86cbd9f68acU, 0x3dc139043e2d9cf6U, 0x3d8771b03ad017fcU, 0xbd8d37d6bdf2215dU,
0xbd0de13f3d191ad8U, 0xbe1d5ad8be534817U, 0xbd33f1c23c02c6b1U, 0x3d338dbabd5c117dU,
0xbc91e5b83c313332U, 0xbc3a94e13a836d78U, 0xbe186f0a3d914e8fU, 0x3e83d69e3d013106U,
0x3dbf76243c8fa06aU, 0xbdc57880bdb28de9U, 0x3da35a77be05d0ffU, 0x3d4eab4abe3f6973U,
0x3d8659dd3c175dd2U, 0xbcc99566bce8ce46U, 0xbcf098a7bd0e57f7U, 0xbd9eebcb3d349a2aU,
0xbd113b083e1527afU, 0x3c0ec8f0bbee0abeU, 0xbd4b8e60bc58100bU, 0x3cb6b4f9bce1cbc5U,
0x3a3b62d83ded0bd1U, 0xbe047c6cbd36efbaU, 0x3e0910e73de31b9dU, 0xbe682a10be4d76cbU,
0xbcba7ae2bdce8886U, 0xbc20b879be0a390aU, 0x3d857e563c88d31cU, 0x3db25681bd9232a9U,
0xbe5e5cc43d630647U, 0x3ddfbab03d98f6d0U, 0x3e0a971abdcc79f0U, 0xbe4b085d3d54a9d7U,
0xbcf306e6be2f5dceU, 0x3d55507ebe2d71f0U, 0xbdd8bf4abc96b70dU, 0xbd231394be0e5fa0U,
0xbe01fcbc3cd85e4cU, 0x3c9d6adc3ba3addcU, 0xbdda67bd3cf58998U, 0xbd321907bd771661U,
0xbc569b09bd677ed3U, 0x3dc5f639be974257U, 0xbd6f99223c4da6a9U, 0xbbdfddc93d54df0cU,
0xbd7131123e1cc995U, 0x3e1ff350bb1b761dU, 0xbdedfb56bda9ad9eU, 0x3d67b8b5bd50d29aU,
0xbc6f3af43e0c993cU, 0x3e4c87adbd99229eU, 0x3db101793d9265f4U, 0xbbd003b23d53437eU,
0xbe22445fbddba329U, 0xbb1281c83d78eb5bU, 0x3d98a813bdb4a3faU, 0xbe02f95cbcfcef59U,
0xbc51683fbc84f9a5U, 0x3df9fd25bc5d1531U, 0x3e161861bdd32a8cU, 0x3dd9f87bbe16c226U,
0x3c3b60d13d8eb872U, 0xbb5e49aa3e2ba353U, 0x3d60b38abdfa04c2U, 0x3d9eb3bb3dc19525U,
0x3c0c48b8be114348U, 0x3d68b4d7bc75e8d4U, 0xbcf8d9393d5cf83cU, 0xbd3b01273c1a6cdeU,
0x3c9f10eb3bcb0680U, 0x3de65fd3bd87bdfdU, 0xbd5c1397bd61e88bU, 0x3d2c58b13dac834aU,
0x3dd96326be21840cU, 0x3dd3c9d53dd22644U, 0x3c4dc0983d83a54aU, 0xbde9ee65bd2f098cU,
0x3bdf744dbd9e01c7U, 0x3e3448703e1ac6a2U, 0x3e01a34fbc1ffcbaU, 0x3d47d723bda8757cU,
0xbd99b1dd3e43f848U, 0x3dc39311bdc059edU, 0xbd37e24fbcd8cb05U, 0x3ccd75f3bd30afd5U,
0xbcde399cbb769fc4U, 0x3d469422be05bea8U, 0xbacaca2f3de9c9d0U, 0xbdce181cbd456b6fU,
0xbd57d5573d9e0ad2U, 0x3dab0948bd2b3049U, 0xbc456688bd33bee8U, 0xbda3a0213df7fd52U,
0xbbd761a93db2d3d7U, 0x3dfc50943bcc3941U, 0x3e5af7c6be2c6076U, 0x3dc7d12b3c1d804aU,
0x3e456aa23ca5983aU, 0xbdadd41b3cae2df7U, 0x3cc333d4bce20511U, 0xbd02e2f93d966eb6U,
0x3d0b5e293dddf7beU, 0xbd2178afbd9fdb37U, 0xbdbeda8f3cbf094dU, 0xbd815f633e44b83cU,
0xbcf32ac3bd4b4483U, 0x3db664e8bca8d97aU, 0xbdd2448d3dbbc2dbU, 0xbd911ccd3bc469efU,
0x3dd6c1e6bdd554d2U, 0x3e259874bd0d5af4U, 0x3dca6d3a3d2ebcf6U, 0xbc7be6f5bd312779U,
0x3dae901cbc9cd957U, 0x3e23b8bf3d61a066U, 0x3d80afd13e1ccfe8U, 0xbd86a9193df3c2c0U,
0x3e4f72063ca0d62aU, 0x3cb719f0bd573eb7U, 0xbd1d804bbe353917U, 0x3e1221c8bc897bceU,
0x3d5bbf84ba5833b1U, 0xbbf2bb55bb729025U, 0x3c324f04be00d4e8U, 0xbcefcd533e2d9298U,
0x3b6e3b043d34683eU, 0x3d4f83fa3d0094e8U, 0x3c4673bd3d8ed600U, 0xbe13a79e3bec204cU,
0xbdb08e13be874286U, 0x3db1b11f3cf77b57U, 0xbe00d3c6bd6a6d55U, 0x3d20fae3bd464557U,
0xbe56ee68bcfae91eU, 0xbcc0f2973da46565U, 0x3d508d75be20b771U, 0xbdd74a42bd89376eU,
0xbd6169edbdf14a93U, 0xbcac72083d71888fU, 0xbe04b4bdbe636e3aU, 0xbd2ea17ebe6591d0U,
0x3d420093bd02e5caU, 0xbc9267913b2f0073U, 0xbbedf4f2be16a8a0U, 0xbe2b79d4bdcbed77U,
0xbe036a783d8ee145U, 0xbe7a6eb0bd824a1cU, 0xbd622313bbf97633U, 0xbd8512b93d3c0e54U,
0x3b824faebe25141bU, 0xbde225443c9e6e94U, 0xbd44bcb4be08d2dcU, 0xbe784e85bda8907aU,
0x3d3fea44bcf1c973U, 0x3cf9de30bd197ff4U, 0xbe5d0262bd5cb82bU, 0xbd7094eebd962be0U,
0xbe8bb142bdab31b4U, 0xbe19f20b3c2706b5U, 0x3db4662abd055df1U, 0xbd5a76acbdce0418U,
0xbcdba584be8bc1ebU, 0xbd983787bd29e13cU, 0xbe42ce7ebe81f85eU, 0xbdd07f0abe307c37U,
0xbd5f36b0bcfeb295U, 0xbe500b76bcb33111U, 0xbc9c399dbe093493U, 0xbd605b78bd40eeedU,
0xbd72ee543c0345e2U, 0xbd7199593d960731U, 0xbda90d00bdf1c1ffU, 0xbdf5b5d9bbda41caU,
0xbe10f697bcfa378bU, 0xbba9664fbd006da7U, 0xbdf022ed3d94ee2bU, 0xbe1c2d92bb778b5fU,
0x3d59d117bdc4b338U, 0xbdd1c5c13dcacdfbU, 0xbd4d1da7bda6794aU, 0xbe94979bbec491d2U,
0xbe32ff8dbd3a2211U, 0xbe0efba1be0ccb72U, 0x3b4dd8e9be62f468U, 0x3cd79ce1bba4379dU,
0xbcd80c47be0da647U, 0xbe25cc2bbdfc9433U, 0xbe4a9ca8bcfb058bU, 0xbd7329fabdad1dd2U,
0xbe1a7b37bd135fb7U, 0x3d52d8acbd5786a7U, 0xbe8bbad03c719c2fU, 0xbccd15b03cb35213U,
0x3cae5f573c95bac4U, 0xbef3a926bccacb39U, 0xbe2b4006be21e312U, 0xbdb56c04bdf971acU,
0xbd5abb14be82213cU, 0xbe3ec08ebe026946U, 0xbe313274beb01844U, 0xbeaa01bc3d98b5cdU,
0x3dbb4cc7bd7b402eU, 0xbe8a047dbe6d9d1bU, 0xbd93ad88be18ba79U, 0x3d14867dbcb19260U,
0x3e38d87ebe2677c0U, 0xbdcb77e6bd96d19aU, 0xbe181e71bdee0777U, 0xbe80c539be58b479U,
0x3d0400313dc7e052U, 0xbc06fcedbe8397cbU, 0xbe93f66c3d10a5a1U, 0x3cbf5b28be72e1a7U,
0xbd2b2a203dc56980U, 0xbdb218093ccf854cU, 0xbe244dc5be8b434bU, 0xbe27d9373dda8463U,
0xbebb3d2cbd976461U, 0xbd929c0dbe96017bU, 0xbe248649be0e33bfU, 0xbddfaea2be93b114U,
0x3daa9831be7208a3U, 0x3d8c598d3c940d81U, 0xbd9e7445be89d6a3U, 0xbc0c8bcbbed1a833U,
0xbe2b34f53b45d235U, 0xbe29fce9bb39f8f1U, 0x3db0a0aebe85bf6cU, 0xbe930b31bd24ba9dU,
0xbe68ce72bf115fbbU, 0xbe0654e9be821ea1U, 0xbd026fc9bdeaa4f5U, 0x3beb4ee3beee8765U,
0x3ca0265bbc778dc5U, 0xbd71866dbdc7ecdeU, 0x3d10b4f03e2eb6dcU, 0xbeb9df2abd8d8a06U,
0xbdfae8acbc496afdU, 0xbd1dfa153d60af92U, 0xbe673a87be1e3d9fU, 0xb98b5ca3bd87258aU,
0x3e1c5340bd9c1ac0U, 0x3e1c16b43de175f4U, 0x3d7ef39a3cb9049aU, 0x3dd69e93be89fce9U,
0xbf4355a6bea94302U, 0x3d5d08ebbf05d5eaU, 0x3c385186bec6b683U, 0xbda33fa23d14ec45U,
0xbd2ddc5abc5f2ebeU, 0x39bc83e4baeac804U, 0xbd994fc2be1090d0U, 0xbeb592acbe586e42U,
0x3e01d796bea43805U, 0x3e2ba668be0862adU, 0xbc79c603beb76d31U, 0xbc83e22dbe79ff9bU,
0xbe1bc5e5bf21f530U, 0xbd1aba273d0a5084U, 0xbebd493cbe6e1d57U, 0x3e5f5ae43e713f4bU,
0x3dbcb7cdbe1fd133U, 0x3e0a206dbbbccdc0U, 0xbc8a9bf23d897ed0U, 0xbdd67cb5bea8a111U,
0xbe6e86913d3351a8U, 0x3e0d104f3e296ef5U, 0xbd2bc6af3c8203d0U, 0x3d8908b2bd382a17U,
0xbe8a07e3bc2c8270U, 0x3ee941e3b9b3d502U, 0x3e0aa87dbda6ac84U, 0xbd63db3b3d35461bU,
0x3ddef426bdba5aabU, 0xbe1fca693d51e7aeU, 0x3d7236f3be1488b5U, 0xbb8cd50d3ce6722bU,
0x3d4d4b553d30c392U, 0x3e2448bd3e47c908U, 0xbc6a032a3e82578bU, 0x3e278db4bd44e103U,
0x3d0cfdd73a7df608U, 0x3cd76401be00dd11U, 0x3e26e21a3b1a5cb2U, 0x3c89a110bd38833aU,
0x3e54575fbc8482eeU, 0x3b8965abbe1ad8dbU, 0xbd1928a3bd1705c1U, 0x3da63d0abe025e14U,
0x3e7c0439bb86bf39U, 0x3e82dd9ebe371334U, 0xbe1fd6233dc404d3U, 0x3e87ae623df7627fU,
0x3e26474cbe0a3f0eU, 0xbcf893a53e5b1930U, 0x3e14454bbd8a1426U, 0x3dd8fff43db5bfdeU,
0xbd862ed6bd7947f5U, 0xbd84c791be8e4f2fU, 0x3c5935923e4a72b2U, 0xbd9e66a7be044f80U,
0x3c2b265f3e28d0d1U, 0xbd763344bcb2fb94U, 0x3d85ea6e3d56596cU, 0x3e20d42fbe9f4eb2U,
0x3d5050053da7f8ebU, 0xbd6ad6b03e02a041U, 0xbd0f56643a9430cfU, 0x3e11ff62bbf2c2b1U,
0x3e0c56873e28b0d3U, 0x3e1ab19d3cd6b3a8U, 0x3e1337a53e962f9aU, 0x3e80abccbc6e0e36U,
0x3d851bf8ba3f56f5U, 0x3c2508623d9191c3U, 0xbe473fb73d6ac1dfU, 0xbd806d8abd8e5cb6U,
0x3e051c70bc91724bU, 0x3ce2f9503e23a974U, 0x3d9930e83ba5627cU, 0x3eb96045bdb4b184U,
0x3eabd7053c9713b1U, 0x3e81a260be3ce689U, 0x3ceec60f3e078cbeU, 0x3d8a5a233e901e19U,
0x3e2d5838bcf8f980U, 0x3dd09c073e1b9847U, 0xbdfa32623e2de51bU, 0xbda2c8d33d28739eU,
0xbd200c7abe22753eU, 0x3dff4ebc3c9c03acU, 0x3eaaef44bd9218deU, 0xbdfe06d93e05e594U,
0x3dc4b67dbda59e33U, 0xbd82ec1d3df8f8deU, 0xbbf6675bbdf6ec30U, 0xbe1b89d23e4a9dacU,
0x3dbc20a93ddfaeedU, 0xbda532963d2c2662U, 0x3d8d3bbfbc164f95U, 0xbc5167c8be3129b0U,
0x3d7b3c1bbd8d247eU, 0x3b71c57dbda11510U, 0xbc241b053cd7e9b7U, 0x3d973f4abd99c4b6U,
0xbdf67ff7bd004389U, 0x3d3f7fa03ea615a5U, 0xbca3553c3cd0a71eU, 0x3e20c1a8bc93cb04U,
0xbd43a6f53db9c4a4U, 0x3dfa74933cf12154U, 0xbd3034ea3e3224d5U, 0xbe03a7cbbd7bc955U,
0xbde75503bd7e8f26U, 0xbcd7a70a3db9c58eU, 0xbe7a9a093e1633d9U, 0x3cdf8abf3e28308eU,
0xbc26bcdcbe81feefU, 0xbd75b4e93e953f77U, 0x3e26905fbd1f7c39U, 0xbda290de3ce0f0fdU,
0xbcf64fb33beb8df6U, 0x3c108d923eabd884U, 0xbe9c67cf3e094693U, 0x3db6dddcbd8622f9U,
0x3b12db12be0689e9U, 0x3ce0fadebdbaff3bU, 0x3e1416cdbd7ace0cU, 0x3def63ae3da10163U,
0xbde24791bd611e26U, 0xbc8783733d509823U, 0xbb518db93bb5cbe0U, 0xbd8ca1c7bd8a0740U,
0xbbd7f65fbd2f80afU, 0x3cdeadae3da84b6bU, 0xbd4c3e9f3d3bc7d9U, 0x3e0b3c583ec6ac30U,
0xbd8a10ec3eced4b8U, 0x3cd4d9363e6c4552U, 0x3e553b983c89f100U, 0xbd479f8bbd987dc9U,
0xbe0c18b0bd9430adU, 0x3c45c6f93d5b5a4bU, 0x3d9cc96d3e84f441U, 0xbddca51cbd3aa1deU,
0xbdb97c4a3dc37330U, 0xbd38267b3ea3de9cU, 0xbdd6b0d03e983909U, 0x3e16a2683e29def3U,
0x3eafea71bc63ed0fU, 0xbe53c7173d83b624U, 0x3e278ed43d93b20aU, 0x3e025883bdf0b73fU,
0x3dd4d4553d07cf20U, 0x3d8b93533dcc4ff4U, 0xbe06a3fcbda244f7U, 0xbca43469bd9d34d6U,
0x3cdcf8863d719309U, 0x3dcfb3233dcbaffeU, 0x3e296f873c4b25ceU, 0xbd9991cd3cc256d4U,
0x3dc356a13bff4c30U, 0x3dfa48623ca7233aU, 0x3e07ffd13e1f93fcU, 0x3e13e786be11f2beU,
0xbda7e308ba5f9318U, 0x3d4bc910b9411effU, 0x3da658353df16ab3U, 0x3da76bbb3dfe0d16U,
0x3df10c123c59845dU, 0x3d8af59b3e4c2ef8U, 0x3d096c9c3d1f4460U, 0x3da357ef3caaec26U,
0x3d1a0590be0cc2f7U, 0x3e49f465bba3c084U, 0x3e2fe4dc3d29f36bU, 0x3d8e0df63d8f4c8aU,
0x3b0ebea5bc1f7d14U, 0x3d9749c0bd53b3ecU, 0x3e8e561c3b7d333cU, 0x3dca153fbbc81d2dU,
0x3e1bcb60bd9210d5U, 0xbd8399b8bc4ff25aU, 0x3dbce1063e271093U, 0x3e32c4e1bd6de1a8U,
0xbc0805ab3e2fc45aU, 0x3df399f2be3c2179U, 0x3c24641c3e8edc84U, 0xbdc87ddf3d417a92U,
0xbc701505be5b061aU, 0x3e2615eb3cbf8402U, 0x3d7f6ed4bcd6d0e4U, 0x3d4219cd3c266ee7U,
0x3dbc4c293c247d34U, 0x3e4b5d293d7c7787U, 0x3e453447bb7577f5U, 0x3e1de3afbd51d85aU,
0xbcfd2ed83cc300d9U, 0xbceae1b53d87c567U, 0x3e226acfbc3b3db8U, 0x3bd0b3043e32cb34U,
0xbd5021b9bd811048U, 0x3d97fe123e95fd6cU, 0x3e4a437e3e27febcU, 0x3e0924353d435652U,
0x3dc65afb3e0a434aU, 0x3c096d0c3d945f9dU, 0x3dad43c93d5ed2d2U, 0xbdde6e56bd9b95daU,
0x3df832583e192542U, 0x3d6d5e0f3df7770aU, 0x3e0273cdbc8c703bU, 0x3e28589a3e2a467fU,
0x3e331d3a3c75a94fU, 0xbdb268e73e2398b0U, 0xbe57351a3e5cb05dU, 0xbe0f1954bdd96cd3U,
0xbb686b143b53fc5eU, 0xbdea4b82bd8b2c37U, 0x3e0c125a3e1c694dU, 0xbd282206bdcd79d7U,
0xbe6aafd93de6f8e6U, 0xbe8cc4c7be0ae08cU, 0xbd91829cbe1fa067U, 0xbd1662673df56a91U,
0x3e3c530ebe44877eU, 0xbe3b0d54be651ff6U, 0xbc8c9241bce342f2U, 0xbe001cd43e45dab3U,
0xbd64d72dba27a665U, 0x3d82c9293de2ac59U, 0xbd819fef3db36d8cU, 0x3e804b28bce35939U,
0x3d8a58eb3d6a4aafU, 0x3e18bffdbe38a1d5U, 0x3d92f3913e36bb0bU, 0x3e19e1ecbc049432U,
0xbdae5a93be694cd6U, 0xbc86af7b3dfe72c9U, 0xbb6ca5ccbc5c2b33U, 0x3d007aa6be2da309U,
0x3d2703fbbdad919fU, 0xbcdeb185bca96533U, 0x3daddb883d78b13fU, 0x3b43b1ea3c412941U,
0xbe2e6890bd9cedf2U, 0xbdff9ca7bdd5711dU, 0xbd6721fb3e0d8058U, 0xbe8836f6be2c8a58U,
0xbd9fdaffbdc10325U, 0xbe69e4fe3e16c426U, 0x3b833343bd75e76bU, 0xbc1442d33e173e1cU,
0x3dc27d39bd35710cU, 0xbd129af13c88b90fU, 0x3e0083e13de1a586U, 0xbe4d524abd8fffb4U,
0x3e4757f63d27c0a9U, 0xbe1fb802be327f87U, 0xbe37a9e1be46512aU, 0x3cfe79613ca3dfdbU,
0xbde99c5ebe12a309U, 0x3d2205163d90b99eU, 0x3c3cbb943e19ca83U, 0x3dd0fce83d907dccU,
0x3dd9492b3d3d8639U, 0xbcbc10a73d5583eaU, 0xbdf45ea8be9eba51U, 0xbd810db9be144bb3U,
0x3e17869cbd9bf448U, 0xbe18990a3e1ba241U, 0xbd9724aebdb33a15U, 0xbcf488a9be00da26U,
0xbc6703e6bdea5d87U, 0xbe14f417be5925d7U, 0x3ddf14f93dbdcf6dU, 0x3dffc14bbd87454cU,
0x3d6c8fc2be332ceeU, 0x3d26f6db3e03e0e7U, 0xbe3c2ea3bcb74721U, 0xbcba736ebc01632aU,
0xbe841f093ce0add8U, 0x3e0806633e662e17U, 0x3e81b5e73d3cb10cU, 0x3e4748c53d1e0ef1U,
0xbcc306293d888007U, 0x3dc360153bb1bb6dU, 0xbdb3b2293e2d51c2U, 0x3dbd85c83e7e9181U,
0x3e044def38a65329U, 0x3d3110963e04fa18U, 0xbe5733ea3de9cf6eU, 0x3e0bf0e6be2eabf4U,
0x3e0c85a0bde1ef73U, 0x3c8dfc8b3d6a7100U, 0x3b0043653daa7b21U, 0xbddb88283e42415fU,
0x3b92c355be3bc8e3U, 0x3d6aa2dbbc8be4d5U, 0x3e08fb1b3e12314dU, 0x3e0cb2533e058165U,
0x3d9e86373e9c669aU, 0x3e71a20fbcaa1f15U, 0xbcf013d53cad0bcfU, 0x3dc28b16bc125ff0U,
0x3e954d523df4178eU, 0x3dcf20563da8cbe2U, 0x3e3ebfee3e7de24cU, 0x3e0e25db3d9f057cU,
0xbc7be0d5bd7a2d98U, 0x3e76caa5bd97148dU, 0x3e439d00bcc69599U, 0x3e9c0fdcbec8b23cU,
0xbd8f6ee73af22519U, 0x3dd683a73e217a55U, 0x3e111c2abe14abd8U, 0x3e84ee6e3e154807U,
0x3dccefdf3de5c385U, 0x3eb18dd7bcf26063U, 0x3e92e01c3d15cf9fU, 0x3cdc8006bea29359U,
0xbc4c793d3da728d5U, 0x3d6dcb08bd86a0e7U, 0xbd40786d3d866ec2U, 0xbd72f8873def002eU,
0x3dcd6bed3e1bfeb6U, 0x3e15d4dd3d7b65cbU, 0x3d9e9efe3d8947c2U, 0xbd89e0823e3d9cbeU,
0x3b8782c0bd953e90U, 0x3dced4413d37f705U, 0x3da5168ebc853958U, 0x3ea814d8bb044696U,
0x3ed344223e3e2cf7U, 0x3e763a10bd92fd42U, 0xbd5fc6e1bc29f956U, 0x3d4f49bc3dbce229U,
0xbc699e76bb9acb8dU, 0x3d976fbcbe13991cU, 0x3e91e72ebe1413e2U, 0x3d07a88f3e2b6307U,
0x3ea9a5643c6b11a3U, 0x3efaacf7bc955dc7U, 0x3e85985dbcf20a50U, 0x3e396c953dc79227U,
0x3dcd91253d9d0223U, 0xbdbd12973e50dbe7U, 0xbeabd45bbd83cf31U, 0xbda55e3bbe11619fU,
0x3e1e4dd53d145ed4U, 0xbd10ba06bda178b9U, 0x3c6fdd5d3dadfe6dU, 0xbcf8b3e0be84bfe3U,
0xbe9625943d48378eU, 0xbd5fff5bbd8c162cU, 0xbd51831ebcd14490U, 0x3d94f6f63c6c9df5U,
0xbdb9aa253d8ec7e1U, 0xbdeea84abdbfcc82U, 0xbd8ceb0b3d89d5d1U, 0xbe2afdc83db86b6bU,
0xbdd84e53be04ac4cU, 0xbe3eaa23be1cb1b6U, 0xbcead079bdd95047U, 0xbd48b5333c0189f1U,
0xbceaac7ebe649486U, 0x3d6dba61bc95d12fU, 0xbd8903423d952908U, 0x3de0d3d2be123e20U,
0xbdcda7adbd4f772dU, 0x3ca27a6f3c9914eeU, 0xbd9501c2be285810U, 0x3db0cebd3e179123U,
0xbd89d7d4bd8648a4U, 0x3c986939be523723U, 0x3cec87143d988418U, 0xbd6f2e1fbdc3cdd8U,
0xbc85c42dbe033281U, 0xbdbe49af3d450284U, 0xbdd2f60bbd123b2fU, 0xbdbaae53bd93d77fU,
0xbe8281e7bd3957eaU, 0xbe2c2035bea86bb5U, 0x3ddc84b0bd88e606U, 0xbcb8ec38bd0f361cU,
0xbd919678be5d9bd5U, 0x3d21bd293d1ab234U, 0x3d69113f3c86edcdU, 0x3cf6a418be0bd3daU,
0xbe895f283d16276fU, 0xbc7f7c89bca6fdabU, 0x3d3e6032baf4e9f5U, 0xbdd40748be1e726eU,
0xbbc393da3e0ca4f2U, 0xbdefc1033d04e594U, 0xbd5f62debdddb2a5U, 0x3c13c098bc7a1cf2U,
0x3d506effbe22cbdaU, 0xbea607cabe6e1d07U, 0xbc367e77bedc5c8dU, 0x3d832389be0bd77dU,
0xbe9bee3ebbbf4a58U, 0xbcb5224d3d723f6dU, 0x3c2e7efd3c674dfbU, 0xbd1ef07b3e0a4b05U,
0xbdc3484abe3af3e7U, 0x3d02c322bd816831U, 0xbdcd6ec0bcfabf43U, 0x3e16cc62be4e8cdfU,
0xbc6ce87fbc6d1db0U, 0xbdbce136bea54b0dU, 0xba0d8063bdb5c8e1U, 0x3d6f68a5be0a0300U,
0x3c010551be268e27U, 0xbda81e5c3d13f1afU, 0xbe784145be7c5651U, 0xbd9c6f9bbe133b8dU,
0xbe370033be92148dU, 0xbc03a4523db1efb8U, 0xbddf9e41bd48ff5aU, 0xbe5e76363dd9b08bU,
0xbc1a6a28bccf272cU, 0xbe123aa43d1a88deU, 0x3caaaf2c3d841b4dU, 0xbccfd1d73e2ca692U,
0xbe59a09bbc85dc0cU, 0xbd74c67bbdc8c764U, 0x3df76908be0dda0cU, 0xbe3d51473d492c1cU,
0xbe1001ebbcbdcad2U, 0x3d07ecc3be4c2fd4U, 0xbe4989b5bdc60cafU, 0xbdc2933c3dad90b3U,
0xbc294b8abe4a08d5U, 0xbd514e11bea1e4eaU, 0xbea79df9bd9512caU, 0xbd4188f8bd019015U,
0xbe28cfc1be12d733U, 0x3d9b5990bbd1d5e8U, 0xbe83de3bbe1cc199U, 0xbe07a6a7bcd753b0U,
0xbbff689cbdf0afb9U, 0xbd1c32bebd4b7f43U, 0x3d723b04bd261625U, 0xbe4c7ff5bd8dbd94U,
0x3b96504cbdae1458U, 0xbd8b2ad63c3bd624U, 0xbe820e6c3c62d3dcU, 0xbe5b4274be5ca3f3U,
0x3db5df99be9b32d6U, 0xbe566ab33c844a75U, 0xbe2688b5bd8173f8U, 0xbe242f6a3cb0a328U,
0x3e537f69be7b6e6dU, 0xbe9d4ad33cb2c8a5U, 0xbe242d2bbe252953U, 0xbdb6f8b53d2af868U,
0xbc8a7ee6be94a998U, 0xbeaaccafbde0c899U, 0xbe79e3e43df0104aU, 0x3d8d88923e26cb5bU,
0x3d1c988e3d3947feU, 0xbe96f3f6bc6f81efU, 0x3e05989d3aa7cfd1U, 0xbd81e1bbbe992cf0U,
0xbce89ab9bd0858f9U, 0xbe821c51be0ed9d5U, 0xbe397e993ddbd1ebU, 0xbd7c8f51bd763d8bU,
0xbe259e84be00aa24U, 0x3b432c21bcea866aU, 0xbe80e126bdaec1aeU, 0xbbc927e0bdb2de82U,
0xbcf8b9d13e0ed326U, 0xbddbeb73be5ad997U, 0xbe4b0ab4be64dcf7U, 0x3d2ccdd4bc04ff35U,
0xbddc0c873cd0a7cfU, 0xbe1ea61abdd460c0U, 0xbd56985abe0e66b7U, 0x3d8e8cdf3d87520cU,
0x3d7e17033d3149efU, 0xbd0e39113daad4bbU, 0xbd494faf3d30d7d8U, 0xbdb303abbe3e5d5cU,
0x3e28f4dcbdaabcb5U, 0xbe092a1f3d0a7ecfU, 0x3dcd6771bcdf43faU, 0x3dc60fb3be0e7db7U,
0x3a1e71a4bd48700bU, 0xbce2801e3e2b4dd4U, 0xbd9c3fe7bc9c040bU, 0x37a11ba2bcdcbc6bU,
0xbc6e0a8d3d25924dU, 0x3e3695d2bc67779eU, 0xbbb68c393d204e70U, 0x3d84ba49bdd2e7f2U,
0x3e80071a3dcc269bU, 0x3dfe5b493e138d83U, 0xbe28c307bcfd33baU, 0x3d3378c03e39fcabU,
0x3b8deb6fbd6a34efU, 0x3bc50aaabd706972U, 0x3cc815e43ce834ecU, 0x3d83cb8fbd0032dcU,
0x3dc26fac3e30993aU, 0x3d8446bebe0b9a6dU, 0xbe3776bfbdc5d78dU, 0xbdda7681bdbfea75U,
0xbe581fb83e1c9bf5U, 0xbdabaeacbe31a84aU, 0x3cbff53bbc883256U, 0xbb9fa7243dc1ae46U,
0xbd88b370bccf0b0fU, 0x3d32f6a73e154825U, 0x3da24cd53db67e70U, 0xbd88bc9fbd6e8070U,
0x3e6ea65e3db2c568U, 0xbe171e783df4f692U, 0x3e385a2f3e278263U, 0xbd60e8e4bdd37accU,
0xbe08dcaebe16ccc8U, 0xbd567ea33e3a5e98U, 0xbdf2ec74bdc30242U, 0x3e2aacbe3d4e0f8eU,
0x3db0c2743c6c14ebU, 0x3e37d2e73d21200aU, 0xbd39cec83dcbcd43U, 0xbdd9877f3e0da4e2U,
0xbec944d4bda01abeU, 0x3b151e12bd0afb7bU, 0x3e2984edbdb2d039U, 0xbd9787733cc235f0U,
0xbcfc6a7b3cfa7613U, 0x3dc034b2baf8d964U, 0xbd9cafcebd9826a0U, 0xbdf3506e3c6726d1U,
0x3e3d47563d7f9e52U, 0x3da9959e3cc91fc6U, 0x3d5a0dcd3c8422c5U, 0x3dc821613e62421bU,
0xbda53fdabe8f45f7U, 0x3de227913cb7edcdU, 0xbdff1044be1e70ceU, 0xbd73290ebe1ff0e1U,
0xbb7438a4bd148e5bU, 0x3db6673b3ceb4d4dU, 0x3ded30973ddecb76U, 0xbb4ea528bd368545U,
0xbd8b02a63dd4b21eU, 0xbd8abdf63de454cdU, 0xbd563bc83df01880U, 0x3dc00273bd74f5a1U,
0xbdcf94e0bd6f9deeU, 0x3c20a8543dded8f8U, 0x3c7b304c3dffa0abU, 0xbdb297ce3d922ee0U,
0x3ca2455dbda0d94cU, 0x3c6e7de93e1afd91U, 0xbcaa87143d7892ffU, 0x3ca7a1893d98bb27U,
0xbc1a74babd25442fU, 0x3db6b80ebcdfbb8fU, 0x3caa40c43d81ea4dU, 0x3dcde09d3ce25b37U,
0x3dfd2961bdad11ceU, 0xbccaacb3bc900a12U, 0x3ca503d3bd70782cU, 0x3cb9c9ff3db1f735U,
0xba49cbe4bd389794U, 0x3d0e7aa2bc717c39U, 0xbce7798e3d7d055dU, 0x3b06b9103d0c36bcU,
0xbdbbc6c8bd20ef87U, 0x3e458c333c53ec2fU, 0x3e022f103d254b92U, 0xb9f8f95b3d765ff8U,
0x3d3ed2d73c06e7b6U, 0x3da06a94bc97ac09U, 0x3c499c513db05629U, 0x3defbaa53e76607aU,
0xbd9ad6893c9d667aU, 0x3d0d3590bc267cc2U, 0x3d903fdd3e2b16d2U, 0x3cb87243bc8f420aU,
0xbdf849623d9c543aU, 0xbc884e4cbddb11bfU, 0x3e3ee8923e20b4a6U, 0x3de20263ba191dc3U,
0x3d6bfcf2bda2371fU, 0x3c2e89b23e1615cfU, 0x3dfb2aeb3d129a19U, 0x3d8b650a3e2a290bU,
0x3c4d53583d89ca87U, 0x3e155202bd110d4dU, 0x3e0f8ee2be4f58e9U, 0xbc6e5cd3bc8e6188U,
0xbd1d71ab3d13ad06U, 0xbd434b6d3d7bdcf5U, 0x3db353123ddb166aU, 0xbb0333843dd3b028U,
0x3dd3897fbdc2e762U, 0x3b4dd46e3cd0dc16U, 0xbcce13e73db3c178U, 0x3ce97f703daa87eeU,
0x3e214bff3e21fd93U, 0xbd16123b3d6bf15dU, 0x3cd6d6fb3defa5f1U, 0xbe3916423d815fbeU,
0xbd5ecd4e3b521aeeU, 0xbaaa811abccb0e64U, 0xbd89a9d83ce72f8cU, 0xbd3d3e02be81c5f6U,
0xbe9af979bdc7ed1dU, 0xbd2e390ebe0bc1c1U, 0x3d75df8ebd74f7ceU, 0x3e2604483a9e565cU,
0x3ca12174be51bf5bU, 0xbb4a36e0ba828741U, 0x3e03cd89bd557d57U, 0x3e6a8d363d3b6107U,
0xbdc8998fbddba9bfU, 0xbdbf77c0be6b51ebU, 0xbe3f182fbe132966U, 0x3e0066383d78017fU,
0x3d3d394dbe63d2acU, 0xbdf76dc2be070069U, 0xbdeead5b3caf181eU, 0xbcd78980bde36baeU,
0xbd85af87be17b3beU, 0xbe0a4e273c8a6b5dU, 0xbcf1fa11bcfdd658U, 0x3d3b18d7bdc3c32dU,
0xbe1199bcbd4c4dd4U, 0x3d209417be54fc6aU, 0xbd9161d63d3da564U, 0x3e09a86fbe2c7f13U,
0xbe1135acbdd63dcdU, 0x3d0e5414bd4dcc8dU, 0x3dd67b7cbda01e65U, 0x3cad7f0e3d1a8dc0U,
0x3dd1be223bac86bbU, 0xbb0657c63e00f6f6U, 0x3d8c759abdf89961U, 0xbe22cbcdbdb99cf9U,
0xbe3c891dbe21fb52U, 0x3bec8284bcd785a3U, 0x3df1ef0dbe3a5026U, 0xbd514426bd2c9205U,
0xbe096800be22b34dU, 0x3d0853593d4c99c5U, 0xbdc38b28be2d3b5fU, 0xbd4d575dbe19424eU,
0xbe811322bd498fa5U, 0xbd9c5709bd1cbea7U, 0x3dd55615be968555U, 0x3e40bc3ebe19405aU,
0x3daaedc03dbd4536U, 0xbd2f6e2d3e041d1bU, 0xbdc7386cbe390971U, 0xbd09815b3bdf26beU,
0xbd8a599c3d9c4d8aU, 0xbdca337abcb1fc9cU, 0x3c93d9dcbdf7ffcbU, 0xbdb94083be5739b0U,
0x3b73207e3cc1fb01U, 0x3d0b2dd4be0e269aU, 0xbca101623d717c66U, 0xbd6e729fbe45004dU,
0x3e07e1723d5d25e9U, 0xbde470683dd00a42U, 0xbdb21aa4bd82b062U, 0x3d652dd6bd2bbc12U,
0x3d499f1f3e1c08a2U, 0x3dfa77133af44f10U, 0xbd63245ebd0e4e51U, 0xbd5560033cd6168eU,
0xbdbb18c73d4d6e52U, 0xbd6e5562bdda706fU, 0xbe0f2563bdda2711U, 0x3dadbe843c959eddU,
0x3d3d9768bdb262a8U, 0xbc2f0d8fbdc9cff3U, 0x3cca8679bddb55f3U, 0xbc2ea06abd309c4aU,
0xbc2320a5bde942b8U, 0x3d39de42be2c27b6U, 0xbbe50380be015feaU, 0x3c29417ebc451eb0U,
0xbd8dbc1cbe28a879U, 0x3bdf1796bd4bbe9bU, 0x3b82e08ebcbc6a1cU, 0xbde8a109bc7d1722U,
0xbd2b08e9bc9a1505U, 0xbde71e51bda7efe4U, 0xbe05360c3ca04fd3U, 0xbdcf1b61bd0c345bU,
0xbd91ab86bd3c45f8U, 0xbbafa5f33cef13d4U, 0x3cbb9b12bdff5860U, 0xbde31e683db46d28U,
0xbe41f63c3d3a96ebU, 0x3d45f651bd22d38cU, 0xbdf5ed0abd743210U, 0xbe0810aabd8ac395U,
0xbd18b444bdd5aa1cU, 0xbe0cdf9fbd9ec038U, 0xbd3049b7be0e3927U, 0x3d46a37d3c275f23U,
0xbe984960be238194U, 0xbd18a5ccbdcd5f14U, 0xbe4becc5bced744eU, 0xbe7553d1bc8936daU,
0xbdc56397bb89f3ebU, 0xbe25a966bd471db7U, 0xbc646b053d10351bU, 0x3bf6e0f2bc8323cfU,
0xbd8057dcbe21162eU, 0xbe287c4a3d6e5284U, 0x3d1d182abd9a07efU, 0xbd959b323d0cb229U,
0x3e0df3c7bdab8e46U, 0xbc2b4a5cbabc5073U, 0xbc5415f33c1f8e14U, 0xbd334f9e3e0f99efU,
0xbe0428e1bccd9fd2U, 0xbe54bc453b827034U, 0xbdc9fe99bd69d13fU, 0xbddef1edbdf7ab9eU,
0xbd86113ebe53901bU, 0xbe483349bdcc1fabU, 0xbd29b91abe246893U, 0xbda823ccbd9d88e9U,
0xbdde745cbdef0885U, 0x3de76a8ebe370d34U, 0xbe2de8bebd7b54dbU, 0xbd93fbf2bd77117bU,
0x3de21d0fbc960de4U, 0xbd76fce33c8f056fU, 0xbbdacd96bddad92fU, 0xbe417f7cbc531af4U,
0xbc0e3015bd2f84cdU, 0x3da7b863bd3bd2e2U, 0x3d0bd8c6be0fce91U, 0xbc9fa2ecbd7f16b3U,
0xbd775c5abdcff192U, 0xbdad92f13cdcce22U, 0xbe222d73bbf51030U, 0x39c784b13c507fbaU,
0xbd4e92febe090db5U, 0xbe8571513cb640baU, 0xbea7690fbe6814a6U, 0xbc0e75aebd95e377U,
0xbac534413c171e7aU, 0xbdf5e905bd5770f0U, 0xbe59d720bddaef1fU, 0xbc211bc8bbb4c972U,
0xbd92197d3d0e969bU, 0xbd92570ebe1bcbb5U, 0xbc874fbb3db6cfa3U, 0x3cb93e683d63a835U,
0x3da2e231bd05b7f9U, 0xbe08c4203d854a25U, 0xbbf74c3abd238179U, 0xbd23f2a6bdc1683bU,
0xba8582fa3d62c0ffU, 0x3c9b24fbbe0e1ee3U, 0xbd4eccbbbbc4d802U, 0x3d86b710bbe9fbf9U,
0x3d361e17bd8794bbU, 0xbcb292aabe03b48bU, 0x3da2de39bd826f34U, 0xbe055f2fbe24c97fU,
0xbded0e76be1d28a1U, 0xbe7bd3b0bc684ac6U, 0xbc0aed21be42c348U, 0xbcb27b1ebd4b0b19U,
0xbd6a9e06bdaee0cdU, 0x3cbe924bbdb2cf9eU, 0x3a631794bd8c0263U, 0x3d0dd1433d56b3d5U,
0x3c880e15be688b68U, 0xbc36c728bc777012U, 0x3d704c5e3c921006U, 0x3d07b16abd46179bU,
0xbdd37d4ebc2e256aU, 0x3dc82a9a3cb062cbU, 0xbd2f751e3cfcace8U, 0xbd1e98cbbc5fd45dU,
0x3d31dfd0bdb7c113U, 0x3dcbe98f3c906a45U, 0xbe6f812ebe09341dU, 0x3d98d54abe527412U,
0xbc9e5f68be3e2276U, 0xbe5d9245bcd8f51bU, 0xbd8f65c33d4ffc7fU, 0xbc633656bd2a5bc4U,
0xbd524dffbbfd3e3cU, 0xbe6d8905bdc16074U, 0xbd691beebc5392cdU, 0xbdff6dc13d03057fU,
0x3d6779a4be40c50bU, 0xbd4c401fbd9d6983U, 0xbdede76bbe12f06cU, 0xbd189b0ebc8749b5U,
0xbeb7bbe23d391845U, 0xbdc48051bdaadee2U, 0xbd030e5bbdeb9337U, 0x3cde30aa3dbc6788U,
0x3c91387f3e049fdaU, 0x3e084bfd3ce7d768U, 0xbdc53d3f3ded8618U, 0xbe1b34f03d9a384dU,
0x3d0fdc783de2b858U, 0x3e6a9ea63c017c4fU, 0xbe34982fbd7b2e75U, 0xbe1303b33d6373a3U,
0x3d5ab11a3d41e9ebU, 0x3b1a77b43e84d0a6U, 0xbcef7966bd88c07eU, 0xbcb2e3333e0d795fU,
0xbde900153b8ef37bU, 0xbd5976d3bca37aa4U, 0x3df153e83a69c02cU, 0x3e42ec2c3e0eab6cU,
0x3ba317053e1a6f26U, 0xbce3a1a3be02a0a7U, 0xbc777e70bd6eef56U, 0xbe139c91bd84d765U,
0x3e5a0b3dbdb1e17dU, 0x3db5b3f53c9eaffaU, 0xbd6daec03df9906bU, 0x3df03a003daeca82U,
0xbdfb3c88bc2865e6U, 0x3e6628d53d204837U, 0xbdb2bd8f3c21a622U, 0x3ebce2f1be4c8e7bU,
0xbc1bb3773dc7ce0cU, 0xbcbdca873dc89410U, 0x3e0c68eebd5438e7U, 0x3c4d60f73e7d6a86U,
0xbcd54e08bd997050U, 0x3e6598d93e67c316U, 0x3d7fe5ac3c8518e6U, 0xbc8fee84be6b4c05U,
0x3d9c29be3e2410b6U, 0x3d940159bddbb0faU, 0xbe4aa4283e46da0dU, 0xbd84cdbabd4b4fa0U,
0x3e9471783e91524cU, 0x3ea6d6d0bd6844a9U, 0x3d76da57be50edc1U, 0xbe4f72d83e6650a8U,
0xbd835fcbbe306ebfU, 0x3e28a2993de57b25U, 0x3cfb8d323e7b222cU, 0x3dbd31f9be0cbae6U,
0x3dcf3d7bbdc09b1fU, 0x3ceba150bcdff79cU, 0x3cba5d8c3c10850aU, 0xbd5f28f33db9b8d0U,
0x3d978b343db3556bU, 0x3cffbfc8bd57cbdeU, 0x3e12956bbe1dbe62U, 0xbcb305393d5a1e28U,
0x3d57a1d33d9b3b55U, 0x3e1fd87f3d907ff1U, 0x3e03f8473e6480abU, 0xbd7ebf073ddc2b40U,
0x3e0cb6bf3eaa927dU, 0xbe452db13ea2d32dU, 0x3d830cd9be38fbbeU, 0x3c0919243d285a6cU,
0x3d1a24ff3df44d94U, 0x3e09f7653e021cf6U, 0x3bca9f29bdd86609U, 0x3c82b2153c2b3f03U,
0x3d5615c6be0d1d23U, 0xbd0368b9bdd276d3U, 0xb776597c3df50d06U, 0xbbf383283dcbdef3U,
0xbdc113afbe2f2753U, 0xbdd71f683e1a6d49U, 0x3e00f5b43d8cd5c9U, 0xbc71778abd1d61edU,
0x3d3c0cf43e2d120eU, 0xbd9f0bfdbb6983e5U, 0x3d82b16f3e052090U, 0x3db955a33d3c2afaU,
0x3d599dc93d6c5f82U, 0x3e3f9405bc1a4d98U, 0x3d63c6613df208b8U, 0xbb03c1193d002e85U,
0xbdbec42bbcd3a440U, 0x3d3960e0bdb6107eU, 0xbdb2818d3e44cc12U, 0x3e121fb6bd9a302dU,
0xbd897b953c362456U, 0xbc4a39b83dac7792U, 0xbda1a99a3d8442a9U, 0x3d0a046a3e3169cdU,
0xbe2d82f13e1e1650U, 0x3d9483db3e59212fU, 0x3deeecf1be55853eU, 0xbe4046143da79e96U,
0x3dd052d23dade954U, 0xbd3ee95e3d2bbd6cU, 0xbdedf3a53d196915U, 0x3d1993a63da1190aU,
0xbe383b923dacb742U, 0x3d853db03b1d9091U, 0xbe05676bbe0c3db7U, 0x3cb227f9bd627fc8U,
0x3c93ea2bbdf0dc17U, 0x3e38e03b3c4f8237U, 0xbb9390b43cf49d5fU, 0xbd6f545b3e3eb3a5U,
0x3dc8b524bc05fbdeU, 0x3ccb6480bd6e2edaU, 0xbdb68573bd0f212dU, 0xbd125e633dc735c1U,
0x3d3909933e21f8cfU, 0x3e7a74e93da701adU, 0x3d73cb973e0f1ea7U, 0x3d449a3a3dda54b0U,
0x3e2babd23dff412aU, 0xbc62e3c03bbbac49U, 0x3c73565dbdfa1054U, 0xbd4d3feebd2ae7f3U,
0x3d0e485b3dae8710U, 0x3cd4281f3c7dc31bU, 0xbccc23003e194627U, 0x3b9926453e26e9feU,
0x3aff5f233e3a1d18U, 0x3e34a5313e063719U, 0x3df5b3493c0aa0c4U, 0x3e0c03763cb55900U,
0xbd34cc1abe57213aU, 0xbd0e5335bc416ab2U, 0xbe502b04bd1ade03U, 0x3d45a7e4be44a9c4U,
0xbe58d207bd7d1771U, 0x3e002b683dbcd6b9U, 0x3a7dbf863d789726U, 0xbe349ffa3e80ee55U,
0x3e9059863d77327eU, 0x3c78d6e4bdd73db3U, 0xbdf3cf613eba6c80U, 0xbe3835ce3e8e50c2U,
0x3e02ebbe3ec98296U, 0xbe80b8d3bdc15bccU, 0x3e027fcdbe5aa45cU, 0xbe9e18983ec2361fU,
0xbe103fedbd9a62c0U, 0x3ef040bbbeae946eU, 0xbe2dbe9abe870305U, 0xbe5314a7bd048944U,
0x3d965f3cbe2bc871U, 0xbc0845ffbdb136c4U, 0x3e063dd0bce86f94U, 0x3ee2effebe1de953U,
0x3e208511bd1b5292U, 0xbd88d1653c72246bU, 0xbdccddb1bd7fe1aaU, 0x3debe0533dec337dU,
0x3e9f9776bcbcbab7U, 0xbcf79bff3d863bf6U, 0xbd4115dc3e41193bU, 0x3d3bc2083e95a694U,
0x3cffde543ec00558U, 0xbe59f5013cfcde0dU, 0xbe22bf933ec3a887U, 0xbe005169bc48454cU,
0x3de0a6bbbd4fdda9U, 0x3bb01d77bd497750U, 0xbd722c093e105d95U, 0x3e26fb7d3e05d1f6U,
0x3e198d9fbbd9947cU, 0x3d1d1d74bca8e945U, 0x3dd383e83e0663efU, 0x3e193dfd3e441101U,
0x3e7d6851bdac54fdU, 0xbe174d9abe11c6ebU, 0xbe8fe428bdaf335bU, 0xbdf281e93e8407fbU,
0xbda471703e347ee4U, 0xbe340f053d6bf60bU, 0x3d3b3e103d907297U, 0x3e160127be92693aU,
0xbdfaf40e3dadbc14U, 0xbe648962bd5be4b5U, 0x3b7e24423ef3b4fdU, 0x3e91b9103e807800U,
0x3d0e1a21bce431d7U, 0x3e101a30bd0b843dU, 0xbe1e8ab7be63a4a7U, 0x3ce6ea72bd95d832U,
0xbc8ae1583d00f248U, 0xbe28ebab3d01d5fbU, 0xbe29b224bd78e002U, 0x3e567d323e912a58U,
0xbe3645253e3e08b8U, 0x3e7775d8be21ec9eU, 0xbde24c3e3e3a27dfU, 0xbd5411733d9a1245U,
0x3d21910d38b3b4e4U, 0xbe83e163bdd82435U, 0x3dc20a51bd61834dU, 0x3d8da3a2bdc39b8aU,
0x39369f1a3da12910U, 0x3c9376ecbdea09a2U, 0xbd9331b2bd40202aU, 0x3da428ed3c8bf881U,
0x3d7a346e3e82bde8U, 0x3de8937a3d7e35c0U, 0xbe0afbc73deb292dU, 0xbdb8ff713dc43d04U,
0xbd6b2e1e3d02f34aU, 0x3c9f01c53e05c8cfU, 0x3e024b563e242d6dU, 0x3d9cce303e0e3244U,
0xbc4abc4f3d225db6U, 0xbce5182d3e11dbabU, 0x3e32df123e4fc76aU, 0xbd3f338d3d7a569cU,
0x3d69c8d4bd155256U, 0xbe2758593d202adfU, 0x3d0bf6e2bad7f7d0U, 0xbd3791a33e45e967U,
0xbda339f4bde53f4fU, 0x3cd7e5003ce18715U, 0x3cf0fc903d204eb3U, 0xbdde7be23de7e3d0U,
0xbd28be133d353282U, 0x3c81b5e9bc88089aU, 0xbce86e7b3e239258U, 0x3e2a8bd63e5f8ebcU,
0xbe1f01a83c855ec8U, 0xbd01466d3cd25e7cU, 0x3dd224553e14f8d7U, 0xbd096d8f3da3aefeU,
0xbd824e753dc0cf79U, 0xbce975aebd4a6bf6U, 0x3d96d51a3d6454c4U, 0xbd3630cb3e08814aU,
0x3d781ddcbc7eea20U, 0xbe5c1c373d447eb3U, 0x3e0b8c173dbc13b2U, 0x3d4d40e93d96194bU,
0x3dc57724bbf68249U, 0x3d7ef7fa3ce18412U, 0x3cbe0c0d3dec8030U, 0xbbd87cdebd263f40U,
0x3e5d56b73e5c706cU, 0x3c2b22573dca57ecU, 0x3cd855193e4d4397U, 0x3df8164a3dce3c66U,
0x3c99467f3d7afccbU, 0x3d630917bdb29ab0U, 0x3df832d8bd705517U, 0x3e34980a3dcbd9daU,
0x3dfe0c22be0c58ecU, 0xbd4600b4bc8e692eU, 0xbd660c2e3eb8718cU, 0xbe0f2f663e2e97abU,
0x3dda08b63e86eff4U, 0x3e7b273bbe133f30U, 0xbdc1b08bbcc5e995U, 0xbe53d0b4bea13908U,
0x3d16070dbdecaf1eU, 0xbe253bad3e0a6d67U, 0x3d7b6769bd46c523U, 0xbea41356bef2b8e4U,
0x3cf2a6a73b02b2e4U, 0xbe65b1b2bddb8cbfU, 0xbeaa4bb53e9d7d3eU, 0x3e73628bbe32c1deU,
0xbe12d4dc3c347a1bU, 0xbd0f598c3e8f587cU, 0xbb5d68053e986f3eU, 0x3d47bce83e2f3a67U,
0xbe5f9af8be8f3d8eU, 0x3e7749a3be0f1e2aU, 0xbe968a4b3e3162c2U, 0x3d94f3203df118b5U,
0x3ea4c08dbe4704d9U, 0x3d955c723d832b78U, 0xbcb5a75b3e4c9902U, 0x3ce0611bbe9e6570U,
0x3df1a6e0bdcdf062U, 0x3d983d8dbe48178eU, 0x3e9d9f8fbe26be83U, 0x3dc37d26bda810edU,
0xbe2949a53d9b2250U, 0xbe4a6344be782e07U, 0x3c5d8c843d926b8cU, 0x3f013108bcd8f737U,
0xbe87888cbdc53ba0U, 0x3e9ec765bd1b2799U, 0x3c1d20263d45f6c9U, 0xbd09016d3eb97632U,
0x3cc96038bce883f5U, 0xbe6f70fe3ee1b979U, 0xbdd65aabbe75b02cU, 0x3d238dd63e0559c0U,
0xbda57cca3ddbe9dbU, 0xbd0b4154bd8deb79U, 0x3e31e6143de2282aU, 0x3e7bfdb5bd72c7d4U,
0xbd5882d73e36ef5aU, 0x3cfc486ebe599ec8U, 0x3ed61e1f3d6ef5f6U, 0x3e0bda17bec0b415U,
0x3d1dbae5be93fc37U, 0xbe83a03c3e886e95U, 0x3e022b393e832a20U, 0x3dd010363e76dbfbU,
0xbe6773393c4efcacU, 0x3cb6dd07be15a4a8U, 0x3d0eacaabee79a53U, 0xbd6084713e2d44f5U,
0xbc457caa3dd5a2cfU, 0x3d849a6d3ec384e7U, 0x3d84d0aa3e47b40cU, 0xbc1841073dc037ecU,
0x3ca3a093be42d714U, 0xbee73f05be12f3c7U, 0xbd92d95a3e2363b6U, 0xbcd1480b3e2f9a9dU,
0x3d9b18f83e3ade6eU, 0xbeabff09bebeac5eU, 0x3e219e413e9551d7U, 0xbee72e1d3d96f83eU,
0x3d52af7cbe943181U, 0xbe985ea1bd105cddU, 0x3dcee27e3d39fc0fU, 0x3eb918b3bd67d04aU,
0xbe72a7e5bb84ba89U, 0xbe72deadbe18e19aU, 0xbe4587cdbddb9a94U, 0xbe89c26abd58cb70U,
0xbebf56b33d7743b2U, 0x3d21912dbd2c66b0U, 0xbe9a3552be1266f1U, 0xbed39161bd1e15b2U,
0xbd8798d53e411e0cU, 0xbe2db63b3db3f830U, 0xbe19724e3e2e3486U, 0xbeb064f8be15f2dcU,
0x3e23faec3e31d3f0U, 0x3dc4d0fe3e5ae35fU, 0x3ebcf627be1794d0U, 0x3e6b94b03eab140fU,
0xbc67272e3eb25f9cU, 0x3e00b463be402dceU, 0xbe5bc1843e5c0758U, 0xbce8968d3d969b8eU,
0xbea5d94ebe059e99U, 0xbd743ed7bd808f45U, 0xbe1701b2bd722853U, 0xbdf23f00bb46e5e5U,
0x3da344c13d98f23dU, 0xbe9578c0bcc50eb9U, 0xbe4209bebd19af8dU, 0xbe3798b33e3588f8U,
0xbe5a0b72bec77890U, 0x3d437880bdcc4975U, 0xbdfbcfa13e55e4d9U, 0xbe1b296ebce8bde3U,
0x3d8d63f73d056937U, 0x3ea09cdbbea3bf20U, 0xbe60c02ebec35cb9U, 0x3c593e1d3e5235c8U,
0xbd596660bce15b06U, 0x3ed26f92be9333d7U, 0xbea7eb263acaa0c7U, 0xbe0009b9bbfeda30U,
0xbdee5e3abc186bacU, 0xbca3aaefbe32f32bU, 0x3e9f5a873e534523U, 0xbe3c3b9dbd4310cdU,
0xbdf86d463e382429U, 0x3ce9d5363e9f5a7aU, 0x3e0bd7813da13983U, 0x3d077963bea2330eU,
0xbd776801be800f87U, 0x3eba7c443c9ce8e6U, 0xbe9bf8e93ea55079U, 0x3d4fc3ab3dca8bbcU,
0x3dd11ba43cc43cf3U, 0xbde60997bda82688U, 0x3d14703bbeab3cbfU, 0x3e8711f7bdd84210U,
0x3cac843cbdb5b7d8U, 0x3d88e46dbe273f34U, 0xbdfa2cb83e204aa9U, 0xbcd7b679bca482cbU,
0xbd1b020cbdcf35e4U, 0xbe51a00cbca297b4U, 0x3e4b84ad3ea2876aU, 0x3db70e80bcb3eeecU,
0x3df2beb9bcf2cc64U, 0xbdb7423d3d990652U, 0xbe02083bbe6745caU, 0xbe33853f3df381e2U,
0x3d714fa13dc74661U, 0x3cdb117d3d4ea9dbU, 0x3e3ab4f4baae1b3eU, 0xbe3601bbbd8706fcU,
0x3e8944833d724c72U, 0x3e3f5f13bd2a415bU, 0xbd4518993e0c1060U, 0x3e0eca10bda4d3d5U,
0x3a79a677bb7447d0U, 0x3df5c8c5bad84064U, 0xbd1034baba994516U, 0x3e38fefb3e075017U,
0x3e0838a63de324c3U, 0x3c2d00503dc52df9U, 0x3deb49e43db56ae4U, 0xbccd525bbca253e6U,
0x3a230401be0af4dfU, 0x3e3bee06bc188cfbU, 0xbcbcc070bc2cb419U, 0x3e107c61bd719256U,
0x3c9b1036bd33e31eU, 0xbdbac2f3bcdbb8daU, 0x3e82f0a5bdcc7f30U, 0x3e5265543bba181aU,
0x3e163cddbdaf8e87U, 0xbdc5892cbc6b9d99U, 0x3e3a0b633e390c3bU, 0x3e1657bdbd7c14d7U,
0xba9d7ddc3e105dcdU, 0x3dcb102dbe01e436U, 0x3e2955febd1424cdU, 0x3c0478a73dae0df1U,
0xbd9066c7be8541e9U, 0xbe0d756a3d89e73bU, 0x3e05fb163c540defU, 0x3d6a24803e1eac22U,
0x3d8a6c333da3055eU, 0xbc29cd0f3e240914U, 0x3e234139be39d0f6U, 0xbcd3fb9a3cc803e6U,
0xbd4dd02a3dfffdd0U, 0xbde2d726bd5fb7d7U, 0x3e4d69efbcb769afU, 0x3daf44b1ba08dc2dU,
0x3e2340efbdb9d7fcU, 0x3e94789e3e888dd9U, 0x3e9dad6bbdcfb975U, 0xbb81ae3d3d36dbcfU,
0x3ba6e6243e0c07a6U, 0xbc86ef8cbd17e7efU, 0x3d8f434abdefc3a9U, 0x3e10c460bd969abdU,
0xbd99c72d3e28e381U, 0x3ca178aabc04f8faU, 0x3ece652abc57fffcU, 0x3e7e02eebd49fdffU,
0x3e228881be5a4649U, 0xbd4a0ed93e30fa48U, 0xbd0113793e241762U, 0x3e90526abe8aca8dU,
0xbdb3cbee3e859b49U, 0xbcc9e2693e46c7c5U, 0x3e2d8ba4bdb38e2eU, 0xbe751ae93ccd8e28U,
0x3d7df72bbe455677U, 0x3d2d81b0bce24d5bU, 0xbc0157de3e26817cU, 0xbd6d3936bdb716fcU,
0xbde35b603d9e3141U, 0xbde0dab73d76786bU, 0xbe13ebbf3ed7e7a0U, 0x3c430ad23dbb07fdU,
0xbe62289e3d41a60fU, 0xbe7a59073d9b5233U, 0xbe52f5d6be15b632U, 0xbd491dc73e389455U,
0x3df331873c536386U, 0x3dad57d33d9c635eU, 0x3d75b8013de926ccU, 0xbdb8156d3e387ff5U,
0x3e6a45833e6c9707U, 0xbda79aee3df9907bU, 0xbd2b49c13db8e33eU, 0xbd25588d3cb0cd17U,
0xbcd019c9bd8ae2ddU, 0xbe329f1a3e6e8a22U, 0xbdaee78bbdb7c268U, 0x3c299d71bc7d9034U,
0xbcb7c98cbd7c1136U, 0xbe385cea3e17b413U, 0xbd78ecd13c0f5645U, 0x3c7ad2f1bd62b521U,
0xbdd5c8013e95ed2aU, 0x3d6067ee3db48ef9U, 0xbe0d6acdbc205e69U, 0x3d03ca10be118e0eU,
0x3d96f5433ba8a72bU, 0xbe23d3d7bb80228bU, 0xbda0aef93d93632cU, 0x3c687516be0e7bdbU,
0x3e0605523b79470aU, 0xbd7c3f813dfbb976U, 0x3d918849bbd36c9dU, 0xbeab0cb43d1881e7U,
0x3e44683cbbc7a778U, 0x3c9fdef63e393548U, 0xbdaaf9b7bde004cbU, 0xbd2789e83de94494U,
0xbcaab0113de91ee7U, 0x3c4a363fbbbcbd47U, 0x3e52fecd3e5136e3U, 0xbd8127783e3a25c3U,
0x3d86c41e3ebb4d10U, 0xbdafa0973e12e90cU, 0xbd570ade3d885a2fU, 0xbaaf4277be17510fU,
0xbb852a533db3395bU, 0x3e850bc73cff8671U, 0x3d71d2bdbdf4b7a7U, 0xbd0f6d0d3da6bcffU,
0xbd83f8763e9b199aU, 0xbed45ac83e36a3d0U, 0x3d83745c3e2d6404U, 0x3e0d3d40be4472bfU,
0xbe6ad639bd0c3f50U, 0xbdae2ef4be0629caU, 0xbd12d35bbe4f8fbbU, 0xbececeec3ef055efU,
0x3ec41b2c3e0358c3U, 0xbefa0f83bf0c6265U, 0x3ebc6d4c3d306ad0U, 0x3d04afb8be420ee4U,
0xbea9e4b5bd86719bU, 0x3eb05f89be1c4c31U, 0x3e18e07dbe36f3f6U, 0xbde1d3e6bc09c70eU,
0xbe41fc78be37b5edU, 0x3e90707b3e6d9f31U, 0xbc813e17bf16c4e7U, 0xbe04fd29bec9a4c8U,
0xbd9dd5c6bdaab8f5U, 0x3d62ef62bdb49ef5U, 0x3ec0a97cbe3d77c2U, 0x3e2e08d4badaf728U,
0x3e651140bc911dc0U, 0xbd61bb41be93c9b0U, 0xbc85c6993db272c4U, 0x3e96a4c0be93cc69U,
0x3ece0726bd693e19U, 0x3ea8fc7cbe4720d3U, 0xbc4ad7893d5228f3U, 0xbef76d4dbeb91ea4U,
0x3e765715bd2ae60aU, 0x3f062e353ec043a9U, 0xbdda8f9a3d7f4899U, 0xbc301b3f3ce27dc2U,
0xbda7c2df3e2d07e6U, 0xbd60b8153ead6465U, 0xbd89ba293c24cf5eU, 0xbe921c073ecab756U,
0xbeab9259bf0c8bc6U, 0xbda47c683ee297aeU, 0xbeaec5be3db967fcU, 0x3d9036973d4a68caU,
0x3ee4def53ce62fc9U, 0xbd59225c3e1a6c25U, 0x3eb1fa22bbfcc5bbU, 0x3e6932ccbeb8d2deU,
0x3ed21e7d3e0f7e3aU, 0x3e820812bef73776U, 0x3eda600ebd214112U, 0xbe8838a53d15795fU,
0x3d732ebfbd7bbf62U, 0xbd7778273c95a111U, 0xbe72d2633d39843dU, 0xbdeb8bf93d916900U,
0xbe814c54be4826baU, 0xbd809c6a3ebe92a0U, 0x3e0c0e9e3d3cc3cdU, 0x3ebf66883e6a3857U,
0x3e68a9153ed6bdbaU, 0x3e3a6f113d45bc38U, 0xbe6270aabdd96e33U, 0xbec4169abdb8956dU,
0x3de1619c3d4c5f2aU, 0xbe871efbbd350e22U, 0xbe1a5be73f0908faU, 0xbe57c9c1bef1519eU,
0x3c63a0dc3ece97a6U, 0xbec62e363dee79c5U, 0xbe3410f63ba48c34U, 0xbd9ddc8bbe4aae7fU,
0xbd3e24b7bdd7307eU, 0xbd570a333c2e6bfdU, 0x3c7981f9bc454043U, 0xbe67a8d73e12b120U,
0xbe7806e1be647b6bU, 0x3e8ccb4ebe8db5c9U, 0xbe0990c53d2ce2f1U, 0x3e34ccbcbca893e3U,
0x3e60f13bbe76ddd1U, 0x3ea92fcebe2e2945U, 0xbe213a183d9c43b7U, 0xbd59233cbe772fbbU,
0x3c8df8be3d559c38U, 0x3db6af5c3e86c7faU, 0x3e5266c6bc23de8fU, 0x3d46a7ae3d38a9e6U,
0x3dea4ce83c46cffbU, 0x3d7edaf23dcc12f7U, 0x3de929f93c4cf1e1U, 0xbe191a1abec8f987U,
0x3dc62ccc3e02280dU, 0xbdc56618be37813aU, 0x3e04cbd9bd9effbbU, 0xbcdec9f8be35f9f8U,
0x3dc4082dbdf21827U, 0x3e1170f33d2c9ef3U, 0xbc1bed7ebdf4484cU, 0xbe887355bda8c2dcU,
0x3d62e875be7e92baU, 0xbdf6ef553d8cf51cU, 0xbdbdf0ecbd3a9842U, 0x3de5079ebeb15a0eU,
0x3d3d56f43d911876U, 0x3e01145abd290179U, 0x3ca6abf33e270c8bU, 0x3dab1c71be95382eU,
0x3cced5a1be21312eU, 0xbcfe8a4c3d8f788cU, 0xbe57565f3c554379U, 0x3d9412e53e89b674U,
0xbe3a64c6be3c0ad4U, 0xbe919672be41242dU, 0xbc27471c3d8ae947U, 0xbce5882fbd86a07fU,
0x3d892f2d3c60c3fdU, 0x3e66bc7e3e22f72eU, 0x3e7e8bb03c3fc51bU, 0x3cc244a13dc5a7b6U,
0xbda78bf13db58db6U, 0xbd024996becd2f09U, 0xbe1107e3bec1187bU, 0xbbaa0deebe2ef524U,
0xbbde86cbbd1ad83fU, 0xbd692d68be072a94U, 0x3e08ac633ccc39deU, 0x3d664069be11a19cU,
0xbd246ef9be716835U, 0x3d7785b23c108478U, 0x3e1d38e5bd8b26a1U, 0x3d2fe29abe235be4U,
0x3e12dfab3da7c945U, 0xbdc31c3cbe31fd65U, 0xbe740a213c9cad62U, 0xbea91c143d1eb6b1U,
0x3bd2ab1ebd120833U, 0x3d56d553beafb553U, 0xbe2eead03f0aa13bU, 0x3ef632a63e40d02bU,
0xbea616aebec5cfd3U, 0x3e97b0f93ccc8429U, 0x3c7e66c0be848378U, 0xbe34188c3e35aeddU,
0x3ef5b2a9bdd28738U, 0x3e9fecfcbd9676fcU, 0xbb4c7cd43ca810faU, 0xbde3efbbbd0c712dU,
0x3ecc2b553eaee6a6U, 0xbdc8e9c6bf15803eU, 0xbc49be57be4d59cdU, 0x3c904d49bd80c459U,
0x3e661a33be24cb78U, 0x3e8e58a83b2bb766U, 0x3e51ed70bcab4bb7U, 0x3e80a622bd996fc6U,
0xbe0fe863be254547U, 0x3e4c02ce3ebe3040U, 0x3eae39cabe5bf185U, 0x3eecba97bdfd6cb9U,
0x3eb51764be2e8444U, 0x3b9ccadbbd3066a6U, 0xbe8caf06be6a8551U, 0x3e89b1873e015335U,
0x3ea8bcd03ef07ca0U, 0xbe051ded3e353291U, 0xbbc34f423d14d8f9U, 0x3eb055be3e76f01aU,
0xbe3e314c3e952ff4U, 0x3cc439833e1a8ed5U, 0xbe6d47c23ebc40fcU, 0xbd657207bec69574U,
0xbd92d3973f01ee3cU, 0xbee388b53e5d1114U, 0x3e0f80c83d67ad4cU, 0x3f11cf70bda12a77U,
0x3e1e21dc3ed40b00U, 0x3e9088f13d07ee9eU, 0x3e750f48beb43505U, 0x3ef1dbbc3eb94704U,
0x3ebdbc26be989d8eU, 0x3f08364e3d0b7ecdU, 0xbe5c3188bd99d148U, 0x3da3a02dbdf968b2U,
0xbd622cdd3e1ba631U, 0xbcbea9edbc844359U, 0xbe56b4d23e4b7a42U, 0xbea2531abd71179fU,
0xbd3ad19e3eb39eedU, 0x3df482863de8b6e0U, 0x3ea7e05e3e0a9a8bU, 0x3ebf5ea73eba6309U,
0x3ea59cbe3e498f9cU, 0xbdfac2bdbcfdca80U, 0xbe5035163d4eeb64U, 0xbd9236543e8761a2U,
0xbdd2c2123d90492fU, 0xbe00f1743f20240fU, 0xbde3c056bead257eU, 0xbe845e7d3eda490aU,
0xbef8209d3e051d07U, 0xbe4c3a8e3e20bf8dU, 0xbd8bfa14be675f76U, 0xbd2635eebe0ff08cU,
0xbdee3bf6be3ad51cU, 0xbd9c3cfcbd84c33dU, 0xbcaafde5be1226a5U, 0xbe855b163e0e5533U,
0xbcbf35bdbdabaeaaU, 0xbc252338bde621acU, 0xbdc7cfd0be38002aU, 0xbd9f5cdb3dd05558U,
0xbd3a30e2be85a1b8U, 0xbc882202bdd0cf13U, 0x3b8062ba3d2b5933U, 0xbe476418bd416687U,
0xbd9734763e04e1a4U, 0xbdc81473bdc96108U, 0xbd1000a33d5cb917U, 0xbe078a9abe46fa9aU,
0xbe069b3bbe1c3949U, 0xbb9d70bcbdba39c0U, 0x3c8d8609be33e7c7U, 0xbcceef763d484296U,
0xbe06b439bc96fd77U, 0xbe09fb64be2e15c8U, 0xbd85a499bdb4e2fcU, 0xbbf58237be49cb0bU,
0x3cc25901be2efd29U, 0xbd7c7d9bbd133d39U, 0x3c82f652be207857U, 0x3e36a7adbd9db0c3U,
0xbd7d8b89be2a6e43U, 0xbe1f86f53df93debU, 0x3c697379be02a5b1U, 0xbe3f1bd0bced66e9U,
0xbd9b8e67be1a4e76U, 0x3c7f9880bdc4ceabU, 0x3d1e1a02be221176U, 0x3df8d975be8ee56cU,
0xbe13d470bdad2f95U, 0x3d71596cbb317bacU, 0xbcd638c4bd973d6dU, 0xbe3049a4bda615d7U,
0xbe25173f3c50de2dU, 0xbdfe9876bd86c436U, 0xbdc9adf1bd87f3e3U, 0xbdd38106be3416b6U,
0x3d7e49263d12d6beU, 0xbc9d42b63dbb51d2U, 0xbc4a72cdbcb71eafU, 0xbce2c54dbe145164U,
0xbe49d274be69bff3U, 0x3d582bd1bed03e5fU, 0x3d50b86ebe4786a0U, 0xbe2e0c58bdb162bdU,
0x3d0d43f4bd8f8771U, 0x3d9bfbf23ce4866dU, 0x3daa583dbde9ea40U, 0xbe458bb8be7f6a86U,
0xbd66a8fdbe2d5fd1U, 0x3d5c5d6cbd849ab5U, 0xbbb3691abe618b8eU, 0x3b34bd4cbe895e0fU,
0xbe38673ebe46ca91U, 0xbe274e39bcce9c6cU, 0xbe72b0263d4a9637U, 0x3e39f6a33e9c3f9eU,
0x3dfe32d5bdb830fdU, 0x3da5c5cfbd0922a8U, 0xbe45ae933d2ea2e5U, 0x3d64409cbda3b036U,
0xbe17a8a5bcdc3972U, 0xbd9050113d8c70acU, 0x3d312cf03cb0f01dU, 0x3e2ba700bd2e2672U,
0xbe94f5cc3d977ccbU, 0x3e77a940bc1e8fe3U, 0x3c4140d6bdc653b7U, 0x3beae71d3de607edU,
0x3e1d7174bdecd057U, 0xbe1134483c8fe331U, 0xbbd20d81bd977738U, 0xbdbdfabd3da5c573U,
0x3df1f70e3e1be03bU, 0x3cc182533dbc82deU, 0x3d4b2af43dd71a71U, 0x3d667e863de10e80U,
0xbd9a5cbebd83a416U, 0xbd4f83debdee0460U, 0x3ea1a0dcbc49785dU, 0xbdd1e337bafc081fU,
0x3e2b82ce3e01e876U, 0x3d8a8d10bdbc0474U, 0xbd3355a2be5b1b73U, 0x3e0c1bd6be4cd336U,
0x3e2546dcbd321d5cU, 0x3e345fb5be627689U, 0xbea1989abc9c769bU, 0x3e14db943e204b1cU,
0x3d814a27bcc2ac75U, 0xbc7ef9123e70c682U, 0x3d9cbc96bd34644cU, 0x3dc4192dbcd12feaU,
0x3d7d41dabdb4ff98U, 0xbdb2bd84be11cb70U, 0xbe0013433e0fd39fU, 0xbd3655b3be1952f7U,
0xbe06af333de924a9U, 0xbda208023c04a86fU, 0xbc1dc5873c3f831cU, 0x3e7474ccbc1d24dfU,
0x3da5eda8bba3cb09U, 0x3d99132f3d964714U, 0xbd60ac8d3d2e0a22U, 0x3d910f81bdadc60eU,
0xbbfa02693ca368f0U, 0x3e2bb5afbd0fa9b8U, 0x3e66061c3e7ee76bU, 0x3e533a2dbbff2a68U,
0x3beb9396bcdc5ac3U, 0xbdca8e263da1cd2cU, 0xbe6261e03d6cc197U, 0xbcda6895bc8391f0U,
0x3e21e2923d075c45U, 0xbbc3135b3d661305U, 0x3cbbaceb3d974cffU, 0x3e7341363cc4b34aU,
0x3ea7070e3ce7b668U, 0x3e2bfd96bc9a74f9U, 0x3ca4fed93dabc07aU, 0x3d5952aa3e721c50U,
0xbec8922cbcf9b613U, 0xbd354a0bbddd15b3U, 0x3d41aaa6bdc73bcbU, 0x3e2fd269be8d88a7U,
0xbe0b86f53e5a8914U, 0xbe414e92be52a257U, 0xbeea1f753e5ae12fU, 0xbc33c624be05e875U,
0xbe3d23ecbdd39695U, 0x3cef34b4be5eccdfU, 0x3e34a9543e2949c0U, 0x3d56df94be2a09daU,
0xbe4f4248be516460U, 0xbe5448d63e0ea9cfU, 0xbe35c77bbddd2b3aU, 0x3e270bca3d575185U,
0xbd96117e3ceeae95U, 0xbdcf80dc3e5327ffU, 0xbdba636bbe828045U, 0xbdce5fdc3d9511baU,
0xbdbbde013e2e39cfU, 0x3da4a1cfbe591132U, 0xbd89e8423e4ce020U, 0xbdfd9f213df8eb62U,
0xbe5c0e7ebee49a86U, 0xbdf981913d190e8cU, 0xbd3088bcbe2c1109U, 0x3e1bc54fbe427e5fU,
0x3e0ec0a33de7cfe4U, 0x3c7635a0be85c435U, 0x3da591dcbecc93dfU, 0xbe75c40bbde0ab47U,
0xbdbd7a4d3aa0ab31U, 0x3dd284e2be86424fU, 0xbe661cc5bde77505U, 0xbe1aa451bec094a7U,
0x3cd39916be0bf6e1U, 0x3e03f02fbebb517cU, 0x3e010390bef56992U, 0xbd8ec7b33e060dfaU,
0x3e2a454c3d7acdd0U, 0xbddec21d3da5f402U, 0xbebd60c63e38860aU, 0xbe33b6893d58156cU,
0xbdabd64f3d632796U, 0xbe0c1174be9f47baU, 0xbd1fb4073e8a208aU, 0x3dbcce38bdc4f47eU,
0x3d7f72c53e5a5a72U, 0x3d1f8cb4bd8d7d40U, 0x3e3b8bddbe204223U, 0xbec15441bedff782U,
0x3e1ed038bf0e43bbU, 0x3d8cb6eebe8e34aaU, 0xbe6d7dcb3d8b0f1aU, 0xbd837f403e2afebaU,
0x3e1278f03df97924U, 0x3dacb8afbcab8559U, 0xbe9652ccbec47e94U, 0x3d656880be4ef3ceU,
0x3daf18e3be706191U, 0x3c6f6c02bee6458cU, 0xbd662fe3be33adb6U, 0xbdf43ee7bec8d830U,
0xbe6e684abe2995bfU, 0xbb8fb977bdca74caU, 0xbd902473bdb1bf1fU, 0xbdcf29d1bb09c174U,
0xbeaec0d53d4e43bbU, 0xbd585221bdd0d6e4U, 0xbe4b67f7bdedfc72U, 0x3dc74f31be03d49aU,
0x3d83f7a5be220092U, 0xbe27df97bdff0b68U, 0xbe0a6860bd878a9bU, 0x3e2a8a01be24273bU,
0xbe1a6eb6bd3dff97U, 0xbe196c84be3da887U, 0xbd4e3724be28e758U, 0xbbd1ae0fbd0dbeecU,
0xbc9cd231be85020aU, 0x3d5fe188bdcbf49bU, 0xbda8dbefbe351b45U, 0xbe4afe50bceff30bU,
0xbd05da38bd2f3d19U, 0xbdabab09be1ba790U, 0xbdd42613bdc4d0ecU, 0xbc6b8d7d3c2acc6bU,
0xbda2806bbe4b193dU, 0xbe48f996bd468e90U, 0x3d21a1cabe37bd7bU, 0xbe08d520bdd9f238U,
0xbead19f7bd4c98f6U, 0x3dfe5b973b856defU, 0xbe81a1b83d5ba534U, 0xbdd528203e086fa3U,
0xbe6906133d65938bU, 0x3db19104bdaf0051U, 0xbe17fe64be79cea6U, 0xbe2aa32d3dfa6f9fU,
0xbe8ac7cdbeb354ecU, 0xbe893884bde4c419U, 0xbdbb8d42be19eff9U, 0xbea3ed9b3d974315U,
0x3da47b403e49d4f1U, 0xbd45f292bda8c630U, 0xbd60aa823db30830U, 0xbd7350dabdb98a87U,
0x3db73159be12b73aU, 0xbe43af86bdfe0097U, 0xbe28946ebe226de1U, 0xbdfd702bbce452bbU,
0x3cbe2fadbe4e2958U, 0x3ded9ab13d19ac34U, 0xbd6eea63bb349c0bU, 0xbe88622e3d4327ccU,
0xbe1536523d5c9bc0U, 0xbe8d1323be0ff076U, 0xbe5d933bbd62a131U, 0xbd42e10bbda003dcU,
0xbc6f0533be897845U, 0x3de50823bd31d587U, 0x3d38dc6cbc1123c3U, 0xbe175ab6bdaddde6U,
0xbe6c7338be5e9c59U, 0xbdbe5b293ca764a7U, 0xbe637003bce67a40U, 0xbe8e236ebe0a6757U,
0xbdffa6b9bde75da0U, 0xbe3b4890be11c2c0U, 0xbcb8c9a9be598cc7U, 0xbd05d1523d83aee1U,
0xbcadd0693cc62166U, 0x3dab52b2bdcc24d0U, 0xbc88cc29be055486U, 0xbebab8193de9b8d0U,
0x3ca39e9abe9da720U, 0xbd5ace233da225b4U, 0x3cab441bbd85e7ecU, 0xbdc62173bcf47847U,
0xbd601b3b3dab2cbdU, 0x3d70e1793d7c79a2U, 0x3d0485113dc3c8c4U, 0x3dac4fde3d669343U,
0xbeb838503d028767U, 0xbead3eda3d934aa9U, 0xbd02e4893d5c898fU, 0x3bd730693c3d5e43U,
0x3c823a81bd835eb7U, 0xbcd43180bba8ff6eU, 0x3d9a6cbdbc94c66fU, 0xbcb6774d3d8dae89U,
0x3d124d65bb7b9ac0U, 0xbdbc16043cc9fdf3U, 0xbcb572693dc960bfU, 0xbd97aff33ce50bd5U,
0x3d6846453df9ddd7U, 0xbe4e33b4bd127293U, 0x3da13da8be957bc5U, 0xbd430ecabd3a56b2U,
0xbd296b283ceb9891U, 0xbdb19e0abda41386U, 0xbcba20cfbc2e3e3bU, 0x3cdeba1abd8a69c4U,
0xbd2c064bbdec41b3U, 0x3d6fe6b5bd212ef8U, 0xbeb227bcbe67a946U, 0x3ca5e0eabe1446a1U,
0x3d92ee2bbe04e021U, 0xbdc80b2cbe87342dU, 0x3c90abb4bd833763U, 0x3da363a0bc6cd495U,
0xbcca66c03d5ec309U, 0xbe67a7d93d4f5031U, 0x3c119fc43d090cf6U, 0xbeaf6d1abddcae43U,
0xbda656edbd0735c9U, 0x3d7fe1933c418368U, 0x3de44c93bdba336bU, 0x3db4d4c0bd63a156U,
0xbcf27a8a3c3a0bcbU, 0x3d10a9b4bd5c3ebdU, 0x3df034afbde146b3U, 0x3d4cb587be1bc1fdU,
0xbc618fde3a5b6455U, 0x3a57c1b2bc246226U, 0x3dc506793dd2b16bU, 0xbdbf5eef3c9f90afU,
0xbd589d073dd9718bU, 0xbda07a14bdb23b37U, 0x3d606a57be312d9aU, 0xbd71c9853e4cd869U,
0x3c032290bd33e53fU, 0xbdf0f71cbda33d53U, 0x3a530fdb3d1be1f8U, 0xbc9d8a59bdcc9b36U,
0x3c7bba56bda16a54U, 0xbcad1980be056f68U, 0xbb90476abe11c2f5U, 0xbe38686b3e0f447eU,
0x3e4aee443d95029cU, 0xbe6d1db0be275817U, 0x3d8507bcbc52a616U, 0xbd551a35bd7f3499U,
0xbd7348d53d9d50bbU, 0x3cd3a776bca678b1U, 0xbd0f8e723d4a5694U, 0xbd90dd463bc16851U,
0x3dc989c33db79a06U, 0xbb68cba8be056f62U, 0x3cdd80cabd576c79U, 0x3dde816cbe2ba3a1U,
0xbce370fabd7f5f3fU, 0x3dc2f8963d008d0dU, 0x3ce6da67bcf6d72aU, 0x3de82cb23cda9553U,
0x3d804e613d10cef8U, 0x3b45f55fbd27da91U, 0x3d4d29053e06387dU, 0x3d5eb17bbc8a0bc2U,
0xbe037a32bd8b197fU, 0x3dfb9b353d8d3c3aU, 0xbc1f2e04be0af505U, 0xbe130f233bf2367bU,
0xbcd3b7953d35904eU, 0xbe1ab2703d4de570U, 0xbe0776b6bd9533acU, 0x3d210f263d87ccaeU,
0xbdc3eb90bd0f3c51U, 0xbdb809fb3d99d6a0U, 0xbabd51043dbfeb22U, 0xbe44c2d7bd219855U,
0xbdf12619bda15211U, 0xbd1a1bcb3e224cf4U, 0xbe3621cf3d1b4a1aU, 0x3e2e70aabc23a806U,
0x3d949fdc3e0ddd92U, 0x3ccc69043c2a9d7dU, 0x3d831f5b3dcf778bU, 0x3d42dba2be7319fdU,
0x3d392a86bd285c22U, 0xbe28b4b6bd13b073U, 0x3e1ba6063d1412a4U, 0xb8d65c523d4993b2U,
0x3d8f48cb3d6c62abU, 0x3e194b1d3d2102a6U, 0xbd98fa70bcbd0314U, 0xbe2d20123d4a566cU,
0xbe44b21abe2871c2U, 0xbd07d66e3e30fdf5U, 0x3cee858e3d6f0834U, 0x3e3468aa3a7d5777U,
0x3b1995483dbbd690U, 0xbc4d977c3e331b41U, 0xbe43df79bc73bb91U, 0xbe5b9042bde8249eU,
0xbd91a36e3d1b7d86U, 0xbddf69ae3ded942eU, 0xbdf94e273e0dac52U, 0xbd9f86f9bdacd067U,
0xbbe38f4fbdd909e7U, 0xbe8c6dfbbcd9b8f8U, 0xbeaa288cbe0d749eU, 0xbe999173bdaaac16U,
0x3e861aa03d66b839U, 0x3e6b2e48bdfbafb3U, 0xbdf013f83db30995U, 0x3d34c253be4f962eU,
0xbe47c63f3dba77c5U, 0x3e2801ef3ccec46eU, 0xbe40cf2cbe8937a0U, 0xbd7310253d16e5e1U,
0x3d13ee223cd9137aU, 0x3e25a7023c73e66aU, 0xbd2f9db23d3b463cU, 0xbe9492ca3e0e13feU,
0xbe6feb813dcd1f60U, 0x3d8640c13c0f34d7U, 0xbd057f11bd318157U, 0xbde88b513e2a3e86U,
0x3e51a96ebdb672d0U, 0x3df6c8cf3e6170f7U, 0xbea989663e870375U, 0x3ddb377fbd231796U,
0xbea346bd3e19cef9U, 0xbe14d3ef3e269219U, 0xbe2bf4b1be5b1895U, 0x3c5b578a3cf94d88U,
0xbe560160be0747d6U, 0x3e325c88be2a6654U, 0x3e6c2a093e31171aU, 0xbbd70643bae5bb2aU,
0x3c7d9c68be636c85U, 0xbdafd7033dd7c235U, 0xbb2e857ebdbf8133U, 0x3dcdeb24be4c913aU,
0xbdbe5d9a3da2d47eU, 0xbe82af89be97b5beU, 0x3e6a8e22be509c9cU, 0x3e967cb2bd05ffeeU,
0xbdd1a8d1be3c7455U, 0xbcd3fbc03e1abb68U, 0x3d721e9e3e76ed60U, 0x3e8018b83da3286bU,
0xbe654b673d77500eU, 0xbd06dd963d49353eU, 0xbdfdb1613e8118a5U, 0xbe2bd4d6be53e6e5U,
0x3e410a403e9e2d85U, 0x3ddcfe6cbe615ac7U, 0x3e1d241a3e38f6e1U, 0xbd2e56583e59a2bfU,
0x3e30a4e5be8c8dceU, 0xbed01d09be133abfU, 0x3e860b41be8f1447U, 0x3e646c5dbdfaee5bU,
0xbdc151513e292ceeU, 0x3df005553d82076fU, 0x3e3b3a573e4fa92cU, 0xbe2313e03df91819U,
0xbe493275bd83036aU, 0x3ea396aebea796d2U, 0x3e26220ebde7936bU, 0x3e50e59cbe3e30c5U,
0xbdf94436bd99f315U, 0x3da36dc2bea6c24cU, 0x3d9b1f8ebdf70c77U, 0xbdbd1f3abe3836d7U,
0x3db06add3d2a7cb9U, 0x3d8b49babe750ed9U, 0xbef703a23f02a78eU, 0x3efb74f6bd55f6c7U,
0xbf27474cbf52b81bU, 0x3ebe780b3de48fdfU, 0x3d8bd035bddeed70U, 0xbeed54a23e8c7d98U,
0x3ea45240bdcb1c2dU, 0x3e660733bea74b6aU, 0x3e1f94ec3e2da915U, 0xbe4b59073e9a65f0U,
0x3ed9355e3e4ee394U, 0xbd54ba2bbf10b0ddU, 0x3caabf46bf149847U, 0x3c7e14f73df56c0bU,
0xbd671254be7addc2U, 0x3ecd25f0bdef37afU, 0x3da79a16bd9b8094U, 0x3cc09095be2bc2feU,
0xbd8a7772beb9e9b0U, 0x3dc00fca3e898034U, 0x3ed322cabec2aa41U, 0x3ea8fe36be1108f4U,
0x3ead5b07beb6d0b8U, 0x3d0503eb3ca2980fU, 0xbf1e5d7cbeeaa424U, 0x3ec444a73e24565aU,
0x3ed0027e3eca0fa4U, 0x3c1f9a273dd4d3f5U, 0xbcde71a4bc96562eU, 0x3dc05ccf3e1b08d8U,
0xbd4ed6f53eb7cac0U, 0xbd81483d3d8e4aa1U, 0xbecdf9373efc42c8U, 0xbe9be6ebbf473b2aU,
0xbdd938663ef7aacdU, 0xbeb1a0153cd03f98U, 0x3dbaa4463dd5d9b9U, 0x3edfa86abda95e6eU,
0x3e65e2423ed1c5f2U, 0x3edd65cdbde5a7f3U, 0x3eaf12aebe1bf5aeU, 0x3ee5427e3e738aa7U,
0x3e6c986dbf2a3d39U, 0x3e8a398ebce0e6a2U, 0xbe7f0a82bd889131U, 0x3d55ae143d7bec3cU,
0xbd4378213e2360f0U, 0xbed2dfdebcdc4cf9U, 0xbdee31fc3e77b1c7U, 0xbe2b10433dcbd2f4U,
0xbcfb5aa53eff3086U, 0xbd3de5463d0565f1U, 0x3eb333363eb715ecU, 0x3e81a9303e9fec0bU,
0x3eb0adb63dd99939U, 0xbc86da3d3da0aa96U, 0xbf085e0e3d2581a6U, 0xbcfcbeb83dde9c82U,
0xbb7964543df977a9U, 0xbe06c40b3edda7e6U, 0x3dbd7703bf0a91a1U, 0xbe288ba23eb5ba55U,
0xbeec75c83d5c9d81U, 0xbd3e7c7fbde4d5cdU, 0xbd2bd4f6bd7808e4U, 0xbc0e058c3d9f1feaU,
0xbda1b3f7bca4fdbcU, 0xbe7b0f89bd9fafe2U, 0xbd6542a0be26b3d6U, 0x3bcaec49bde2b80fU,
0x3e13f198bdfa9de1U, 0xbd897489bdc62f87U, 0xbd64197e3d80ef04U, 0x3da8f33bbe0ee1e6U,
0x3e2bd276bcf0ddadU, 0x3dc9bfa1bd7a6fc2U, 0xbdb256b33b9fdc9eU, 0x3aab4a89bdda3e22U,
0x3d91d3d93ce4df72U, 0x3e20712abdeae49dU, 0xbdb386a23cea8b18U, 0xbd36513a3d8691f1U,
0x3d92225f3c8d2cdaU, 0xbddd8d2b3c27c73eU, 0xbe22b7333daa5eceU, 0xbdcc6f963e048bf1U,
0xbe0575abbdc78879U, 0xbca13a483e35aadeU, 0x3d28f736be0da760U, 0xbdeaf44a3d61718fU,
0x3d9a096bbcb5a67bU, 0x3d6e7231bcd757c4U, 0xbde9ede43e1f2b92U, 0xbcab4b94bbbea1e5U,
0x3d66b57f3e0056f2U, 0x3ca3654dbe498011U, 0xbd842f193daa0befU, 0x3dbe82f7bd6ac201U,
0xbe064b0ebc8ff7b4U, 0x3d809e55bdead3e3U, 0x3cca75cd3ac83e72U, 0xbda38a963a91aa4eU,
0x3d9689163c67e8a7U, 0xbe029e9bbd2ca83dU, 0x3d8bd0ef3e4d0192U, 0xbc394903be22891fU,
0xbc61617abd888ae4U, 0xbdad09943d9e9143U, 0xbe66a0693b72ae1cU, 0x3e0fc3a7be1f5de3U,
0x3ddae866bd8296a2U, 0x3d2e1b13bc6cb74eU, 0x3d8535673d8f9943U, 0xbd88bfc6bd79c790U,
0xbacda944bcbc6745U, 0x3e0a74413da4943bU, 0xbd092137bc8ada33U, 0x3e4903febcb0e119U,
0x3db935f2bbebd354U, 0x3d833c2a3b7e1ef4U, 0x3c9fc637bde012aeU, 0x3b1c6971bd42b852U,
0x3b4fe978bda7fb6eU, 0x3dcfd06abc80478bU, 0x3d7714743e3db8aaU, 0xbe2dbb393d3913c2U,
0x3dbf3461bcf3d9c9U, 0x3e10e8a53dd0c896U, 0xbebdc363bd924b27U, 0xbe036660beb65b32U,
0x3d695c76be8940e8U, 0x3d23c4423ca98d5eU, 0xbd1921823e8d052fU, 0xbd9b06e3be551b7bU,
0xbe188d75bce43169U, 0xbda0ac1dbe4d461dU, 0xbdd1b1c13c578ff5U, 0x3da1e29bbe0edc60U,
0xbe8c4e7a3dc77270U, 0xbdebc7f1bd4a82dbU, 0x3e54596dbdf70379U, 0x3d82ea99bc128390U,
0x3c4563edbe1d8bfeU, 0xbc87a14b3df26ed5U, 0xbd0ffcfbbde0ba44U, 0x3e2940313e27ac33U,
0x3cb7adf1be21f7b2U, 0x3e9ee7aa3e3bf1cbU, 0x3e26bff53e602b75U, 0xbe3a6320bd19d9e8U,
0x3e6375f8bc1cb5afU, 0x3cb83113be3b730fU, 0xbdc21ce8bddc99acU, 0xbd5079403a706a59U,
0xbe22b25ebd565b12U, 0xbd3c464dbdb866b7U, 0x3ab976b13bd3d8c4U, 0xbd9d42c33caabc4aU,
0xbe9fb7cebd825eb8U, 0x3eb36517be7c395eU, 0xbe1829933d150361U, 0xbe764ac7be051ea8U,
0x3e54989f3cb563a5U, 0xbd8aabf9bdd5a4f9U, 0xbcc88767be23ed05U, 0x3de4b3df3e868686U,
0xbda9690d3e3d44f7U, 0x3dffc861be4b95dcU, 0x3e38008e3e60568dU, 0x3d376fd2bded0bb1U,
0xbcdf2e053ea5be02U, 0x3ce5fc9ebe10e713U, 0x3e9e2dc6bd0166a4U, 0xbde67299be123f9bU,
0x3e7f5641be673aa3U, 0xbe829a9f3ea67228U, 0x3dc9a0bcbd4cd7f3U, 0x3e5f8ca53e2d09d2U,
0x3bdfb9583cf2f49fU, 0xbd811c9c3cf14debU, 0xbe2b9017beec33fcU, 0xbe6698463d9672eeU,
0x3da07cf13db8dda4U, 0x3d284609be703475U, 0x3dcbcda83de7c712U, 0x3d239a543cc8b579U,
0xbc5338dcbda75ff5U, 0xbdf6440bbe26abd4U, 0x3d5b538f3e4d3cc1U, 0xbe1233bb3d67f27bU,
0x3e00a5743e93036bU, 0xbed89c57bd9e7be4U, 0x3b6e5ae23dbba8b0U, 0xbe64e8d63e153f25U,
0xbe86d497be69531fU, 0xbd69536ebe99d5eeU, 0xbe373eedbdc0c705U, 0xbd14b62c3e305d3fU,
0x3cbff972bd9136d9U, 0xbee9e9d63d85286bU, 0xbea9ff5cbefb3820U, 0xbd0a4e50bec1001bU,
0xbe07d1e5be8160bfU, 0xbd81e2893cfe0d53U, 0xbc1ce707beaf3683U, 0xbea35abb3dabdaaaU,
0xbdc0ac713dc61ac2U, 0x3c4c2ef3be920e84U, 0xbe14fd973b9400c8U, 0xbe8319d6be52f73fU,
0xbd73b2963d2c6967U, 0xbdf75a64bea144bfU, 0xbd33afd1be15591aU, 0xbe70739bbebed830U,
0x3db27e173d3efccbU, 0xbea83854bdb1c2c8U, 0x3e6bb880bdae6cafU, 0xbd8f18e23abfcbfbU,
0xbddeee3bbe6af1f7U, 0xbe0228d33d5d15ddU, 0xbdd35d56be3f525bU, 0xbe0108cfbc8f8257U,
0x3d3f47953d479b31U, 0x3d047e1c3d8022a0U, 0x3e3fb31abe5b95d7U, 0xbec7e38cbdce4f43U,
0xbdbe19c43c146ed3U, 0x3bf82de9bd9eda43U, 0x3e1fc8afbe880e9eU, 0xbf0171d839f94501U,
0xbe2956463e6602e8U, 0xbdb6ce8dbdea19baU, 0x3d2823d1bf0748d8U, 0xbe16b30abf1f2544U,
0x3ced8546bda2adf8U, 0x3e5afdc5bdd57405U, 0xbdb7a349be41bfdeU, 0x3c169127bc0a9c81U,
0xbdfb7ccbbe8b6c3bU, 0xbbcff421bdeca6b0U, 0x3e7574e6bdf11675U, 0xbec3e8893eaaeac8U,
0x3b1dabccbdeb6ba7U, 0xbe6dbc0dbe5a0c1cU, 0x3e090a5f3e507c56U, 0xbced0e06bc97243eU,
0x3e3896463dd8120bU, 0xbb10052b3de297deU, 0xbea14ceebe2c28d3U, 0xbedbe1a1bc4b244aU,
0xbe5380b6be220f91U, 0xbe33c3df3d25c7abU, 0xbe2a1e883e18b61cU, 0xbe7df18a3e7f133eU,
0x3e68e1863e91e7f9U, 0x3e06b5ec3dc1ff6bU, 0xbeadb7993daeb149U, 0xbdb958f6bbd686b3U,
0x3d1734143e0025cdU, 0xbc0a3472be5e8690U, 0x3d23eff2be043e70U, 0x3dfaf7313dbc794fU,
0xbdd946a6bc21f90bU, 0xbd91fe77be060f68U, 0xbd3356453ca668d8U, 0x3e13cc42bd042318U,
0xbd98f14d3d11be52U, 0x3de9cd613d126838U, 0x3be6e0003e052d8bU, 0x3e2a9e9b3d5f5475U,
0xbc0cfda4bcd687aeU, 0xbcb948cd3d744958U, 0x3dcc9f2c3dfcae42U, 0xbaa5d2313e072a63U,
0xbcaad0eabdb798cbU, 0x3d5736d0bd4a3688U, 0xbd354d04bcb666f6U, 0xbcc2f261bca2bf77U,
0xbc099733bdae854eU, 0xbe077c91bd15b16bU, 0xbe0e0eff3d273898U, 0x3be23f653d623930U,
0x3dcf471cbda4380bU, 0xbd18fdf6be58964bU, 0x3da7f96abd9cf725U, 0x3d3086eebda1b9f1U,
0xbd38022cbe8ba07eU, 0xbd20c06abdc0100dU, 0xbc4421cbbc8af2c7U, 0x3db7483cbdb5c43fU,
0x3ca77702bbe3069cU, 0xbd0fcdffbc3b371eU, 0xbe1b141fbb951ab8U, 0xbcab45283caee611U,
0x3da5d7193cc435c7U, 0xbcdc870d3c2e2779U, 0xbdd80a13bd7383d0U, 0x3c6008013e66d70fU,
0xbd88a2893deba67eU, 0x3dc90a9e3d9c1267U, 0xbde6d49dbe095855U, 0x3d1bf8f63d2ee896U,
0x3e3cf0e83d3fffd0U, 0xbe75d569bd863bb9U, 0x3ddb390abe43194dU, 0x3cdb51cbbe37f631U,
0xbda9ba25bd08b31aU, 0x3d178015ba930c9cU, 0xbdd7fe213d305e70U, 0x3dbdbab6be4b4086U,
0x3ddc40b4be5e2fd4U, 0xbe2cb9453dbf03e7U, 0xbca68e4c3d190e63U, 0xbc8c0986be52c3b4U,
0x3d19a598bcd0c08eU, 0xbe17393cbcc5cbc1U, 0xbe100181be03cf5eU, 0xbdf232df3ddfc9dbU,
0x3c9aaf11bdd4ad39U, 0xbadeddb6be50be72U, 0xbd5381edbd86bf8eU, 0x3cb3c9043e29f6e7U,
0x3e183bb83cdb2311U, 0xbde0fbe33dd1ff1cU, 0x3df2c265be0984f5U, 0x3ea9d610bd0a3aa5U,
0xbd9f9d48bd4b05b9U, 0x3d877deb3db275d3U, 0xbe3b57483d99286cU, 0xbcd136f03da1a453U,
0x3d124e35bd4f9ecfU, 0x3ce20a2a3e1d1c2eU, 0x3e096b7cbcf1f9c4U, 0xbc94dd91be46a2e0U,
0xbd9689c03c8b5487U, 0x3d16c9fb3d0d1cf7U, 0xbe8ce4163dc31301U, 0x3bcd0edf3dc722fdU,
0xbd18103abc9a1d9dU, 0xbda7ee403e3ed703U, 0x3d591527bdc504bfU, 0x3c5fd38a3df7bd77U,
0x3de4d9043e1d2d59U, 0xbdad03e43c554551U, 0x3c435703bcf07ef6U, 0x3c9817ce3d7c457fU,
0x3c0a8f863e014508U, 0x3daa8bdebd1df7bbU, 0xbe07f02a3d9e2c2dU, 0x3d17978a3dc563d5U,
0xbd7e4d253c626ca7U, 0x3d7849713d33e1daU, 0x3db9f83dbdfc03a4U, 0xbd7d0b78be2c9a97U,
0x3da1177fbc0e8c80U, 0x3d624a813ce48096U, 0x3cec3c45bde50890U, 0x3d676592bbe067baU,
0x3d164dbc3e083586U, 0xbe41f64d3bbcd3b1U, 0x3e12bebebce1ba47U, 0x3d6635813d503e81U,
0xbc48207c3bc31f6aU, 0xbc646f1abe864c31U, 0xbd3b5bcdbe23e9a3U, 0xbcf6b8173cd2d315U,
0xbde5b3ce3d452051U, 0x3c413cca3e0d2d4cU, 0x3e2d742f3d83bebaU, 0x3c91f7ae3e115f57U,
0x3d9927b93cd19459U, 0xbded7f1ebd31696eU, 0xbd64fe79bd850d1eU, 0x3d37a191bdf53524U,
0x3dc4073e3d367477U, 0x3e23d7803e352cafU, 0xbdba97f2bcf1af90U, 0xbd4034243bb731dbU,
0xbd2df10c3cfdc457U, 0xbb9e710dbcf7fbbeU, 0xbd393bebbd5872f7U, 0x3d6463b7bd98a380U,
0xbdf78fce3de2b250U, 0xbd376410bd6a6886U, 0x3d3434e9be5e5d25U, 0xbcc3594abdfc91c3U,
0x3db0a635bcfd209fU, 0x3dd0f2f7bcb2775aU, 0x3b273cf2bb54058dU, 0x3db5089fbe22a462U,
0xbc3275c13e049f41U, 0x3dbc86b73dd67932U, 0xbe88af3f3e26f04eU, 0x3dbd225abda8a56cU,
0x3e7121bf3ded5790U, 0xb7cf59093d6341e7U, 0x3e539094be13abedU, 0xbecc5c103dd2a201U,
0x3dbf909cbd89b00fU, 0xbd556c1b3d121e13U, 0xbea38fbdbe0bccf3U, 0xbd28bb11be16626aU,
0xbdf125923e5fe47fU, 0xbdc867acbe315204U, 0xbe18e4a7bd0c4570U, 0xbd64b5e83e60a9b0U,
0x3d660bb13da8963eU, 0x3e025c83bd78dd5dU, 0x3a461a26bbb0f216U, 0xbd508b623d9ff77dU,
0x3d9d2261bc21beb5U, 0xbd724340bb2641dfU, 0xbd9cf547be4e3b26U, 0xbd3c59f03b868ebeU,
0x3dff5d51bd8516ebU, 0xbd9d61233ba5d74bU, 0x3d75f325bd5133e3U, 0x3e73f875bd708a2dU,
0xbbc984cf3d2c8024U, 0x3cd075a7be8cc4c8U, 0xbd89a4ffbd43e6c4U, 0xbeef9314bd02b90cU,
0x3df5b2af3d6c2f3bU, 0xbe9935b1bdec1ad4U, 0xbe0b5f5d3db6ebf5U, 0xbe02c30fbde4b1f6U,
0xbe355008bdeb5b68U, 0xbc83d552be294b37U, 0x3df18bc2bdd1f965U, 0xbc94b4f0bd911ff2U,
0xbcb7e7ebbc968f0eU, 0x3e12424c3dc6f8f5U, 0xbe0cfac1bd4edfccU, 0xbd6ccf263a3102a3U,
0xbb951384bdbbf183U, 0xbced09f2bd9b43c9U, 0xbd9bcb70b8d87bdeU, 0xbd85c2e73c052257U,
0x3c64a659bbd13f13U, 0xbd8775d8bdca0384U, 0x3d7764bcbe141c17U, 0x3e088846bd8378dbU,
0x3e1a43b13da75647U, 0xbc81b710bdba8a31U, 0xbceee9dbbd0e1b80U, 0x3e164dc23e05be8dU,
0xbcb2931abdc5b616U, 0xbe014f20bc7f9a06U, 0xbd8aedc53d4d1df7U, 0xbdd14a9f3daddd49U,
0x3d708eebbd8b8ed6U, 0x3de39fd8be96546eU, 0x3df05d533d01069cU, 0xbe7a63aebdb728bbU,
0xbd132be2bd31768bU, 0xbd6cce0abd80bdb8U, 0x3cff98633d3fbe8cU, 0xbd605468bd03ed7cU,
0xbdf6723f3c1cf502U, 0xbe17d4c6be1dfa8fU, 0x3e35ad98be893ec4U, 0xbd4346a23c2ad940U,
0x3d3031f03dd15227U, 0x3e89bee4bdfc29afU, 0xbe0cc6063de11660U, 0x3d59cfd5be0c304bU,
0xbdf0783a3d7dc47aU, 0xbe34d9903e16374eU, 0x3c25bda2be022e5eU, 0xbd4cfaad3e62f089U,
0xbddd9cb6be0991b6U, 0xbe26ec4fbe8cd3e0U, 0xbf01d1863dc7f3ffU, 0x3e045dd6bdc51f98U,
0x3e06e49b3c8ce0bbU, 0xbe00e0f83e438958U, 0xbe5fd753bdaf56cbU, 0x3e2de0723da41f03U,
0xbd0db605be49f04aU, 0xbd875b813d853d8eU, 0xbc4b0fc33d3d1d0dU, 0x3d42d6f2bc98dad3U,
0x3d43cd613ca6b397U, 0xbdb6ff56be75f13cU, 0x3dbf7e63bde2a172U, 0xbd7a9d0fbdabf639U,
0xbd1959653d056e0cU, 0x3d99ac833e50dbb3U, 0xbe8aeb533c85392dU, 0x3e45856ebd7bd11fU,
0xbec4f070be6fd4baU, 0x3e19bef03c4442beU, 0xbe2014b6be055bfeU, 0xbcf799e9bd803c43U,
0xbc8ac1913d8b25d6U, 0x3d59932a3c994459U, 0x3d6b0197bc894236U, 0xbebfcf05bdf0f7d7U,
0xbd93295f3c531d91U, 0xbd1537a3be092b9cU, 0xbdc6c7fc3e1eb3d8U, 0xbe04157cbe7ea099U,
0x3d1dfcce3d1ed04aU, 0xbdebccbbbd30ecb6U, 0x3c858439bd96205bU, 0x3d0db0f4be242c86U,
0x3bb620043dbff1a5U, 0xbc96881fbdd5e785U, 0x3d937e623d844675U, 0x3db78f443e44982eU,
0xbda4364abe007e19U, 0x3d64f992bc1c45dcU, 0x3ddfa9d1ba9f0b9bU, 0xbd897e6ebcb2fcb6U,
0x3c2e15783d1c1e35U, 0x3b741477bcae6acbU, 0xbe81c25f3dca313eU, 0xbe4aa922bde91874U,
0xbd8a2977be5d8a41U, 0x3d59b6fdbe064dfaU, 0xbe40884dbbcfa76cU, 0x3dd5ee8b3cde9c76U,
0xbd8862aebca629d8U, 0x3ce03f53be8422f0U, 0xbe60a14fbd19bf82U, 0x3d938ad8bceb65dcU,
0xbe641aea3da8c090U, 0x3e3ecca83d10c700U, 0x3e0d126a3d8c5cb3U, 0x3eb1c96a3ea72089U,
0x3de815eebe6b1596U, 0x3dfafa6c3db0f6c1U, 0x3de3d7393dcb8230U, 0x3e5946303e8c6d49U,
0x3e88c9c13e28c90bU, 0xbd312f90be9953deU, 0x3e8c1b6c3ea19f8fU, 0x3e6a80113cd6c19aU,
0x3e063c0bbe33e60cU, 0xbee8eaf13e41f021U, 0x3e66886b3d4c291bU, 0x3e0d92b93e4166acU,
0xbf060d50bb638770U, 0xbdd44bbe3e599741U, 0x3e9bf2fa3dbb970dU, 0xbd1d5889bec69f7fU,
0x3d2676b7bbec2b65U, 0x3d8b24ad3e00082dU, 0xbe379242bd91dfc4U, 0xbdc47a5f3deee52fU,
0x3da1ff7d3d5ed353U, 0x3e085747bd8fe168U, 0x3cc36bbc3db41961U, 0xbd82fd113e331416U,
0xbe871be33e353c6eU, 0x3d4dc98abdd756adU, 0x3dbdf1aabe77d176U, 0xbe06f9263cd8bcfbU,
0x3e8f80e83e1c37d8U, 0x3df633b8beb43eb3U, 0xbcc1b2c23e3b1260U, 0x3d2642c43d539efcU,
0x3dac7e4abb2cf1e1U, 0x3b32edb43db53449U, 0xbe019607be138d77U, 0x3d279ef33e34f1d8U,
0x3d09b67d3d660600U, 0x3e11f3873e4cda3dU, 0xbe445800bd6e7bb0U, 0x3de329d4bd0c31d3U,
0x3e512cdd3e449b0eU, 0xbd80254ebdf85ae3U, 0x3db45b0e3d826618U, 0x3ce88486be4cb26eU,
0x3da3c5933ddecaa1U, 0xbe00becc3e66d833U, 0xbce8af483c7a448fU, 0x3e3d2247bdc7bb8eU,
0xbe4041ecbda27d6dU, 0xbdd9d8bb3e3faf5aU, 0x3e3867cd3d964b27U, 0xbcf00c34bdc8c936U,
0x3d41d520bdbdf4a4U, 0xbe569cb0bd0fa134U, 0x3c8f5a9c3c392464U, 0xbd17e76d3dd1fff4U,
0xbe70b385be365033U, 0xbe97914abe295d42U, 0x3db9ddc4be17f096U, 0xbdfc4b293daa36ceU,
0x3dc5d8c8bceed5f5U, 0xbe9f61ed3e1aa82bU, 0x3e65ea413e630001U, 0x3e89baf4bde4afb4U,
0xbd0be6ecbeb126fbU, 0x3d0bd6d83dbeced4U, 0x3de761933d9a3ed1U, 0x3e294e3bbad97c50U,
0xbe05c319bd20de1fU, 0xbdd1da703df5f789U, 0x3d993e67bd4e56feU, 0x3ced56cbbd3733a1U,
0x3d9feb813d0e46c0U, 0xbca8ce853dfdc239U, 0xbe4d5215bdb00386U, 0x3dcd19dbbddf0b88U,
0xbdf5f82d3d1fc991U, 0x3dcae2ffbd9d668aU, 0xbc9046103e65de11U, 0xbcf125d63d8b7b55U,
0xbe0cbda13dc4d770U, 0xbdfee20f3dc428f2U, 0xbd115617be633943U, 0x3ce348d3bd8187dbU,
0x3cdfb1093d2cf439U, 0x3bb666bd3db0f6a1U, 0xbd5325bdbd18189cU, 0x3e4ac0aebcd2d473U,
0x3d89d409bdf92232U, 0x3e373a0c3e06fb6cU, 0x3de4e39bbc15ca93U, 0xbe25d990be05df88U,
0xbd55c788bc82d5f2U, 0x3e40e5e2bc4907a0U, 0xbe077438bd547c22U, 0xbda2b50cbd8c067aU,
0xbe81a6933d77efd4U, 0xbe81c22d3e53808bU, 0xbe8499853e09d5ffU, 0xbd6ac7f13b797dd1U,
0x3ce6b25d3d888c22U, 0xbedfee69be8aa250U, 0xbe05df91bcd0c431U, 0x3d2e7d11be4dca2aU,
0x3e13cdf1bd505c28U, 0xbec965c6bbb87b07U, 0xbdd637173c4f4c87U, 0x3d1f2d45bdab063fU,
0xbedcb5a7bcd77371U, 0x3d92ecdabd58207cU, 0x3c901c48ba6eef08U, 0xbe461dbbbe3b7f52U,
0x3e0e2b8bbdd058b4U, 0xbe64c9463d10f9e8U, 0xbd497c19bebcd50fU, 0x3c84e49c3df71cc5U,
0x3bf322b33d999f8cU, 0xbd4aaf353d193261U, 0xbd95b0dfbc0c2251U, 0xbd5c327a3d928520U,
0xbea0e023bc1a3500U, 0xbe89adf5be42f41eU, 0xbdb3362b3d74ef11U, 0x3d2cfe9cbea0d92bU,
0xbdf2db3e3dab8605U, 0x3ba6811bbcc5086eU, 0x3e092a283d05c64cU, 0xbdf55d56bdf6763fU,
0xbe66eb643b067814U, 0x3d31e50ebdad7182U, 0xbe7efdef3aef02b8U, 0x3d716a833d45c93cU,
0x3cc20a513da893f5U, 0xbdde5b8d3da4e439U, 0x3aeff2b33e15e18eU, 0xbeb083c53e3cd8cdU,
0x3e574378bdd9f79eU, 0xbd8361b5bda7a844U, 0xbdd7bd893e25fc28U, 0x3ca85773bd7f3944U,
0x3af9b0cc3d643a22U, 0xbd1cecebbe81ff94U, 0x3d672a58bdcd910bU, 0xbe0b7d373d93451aU,
0xbd22ec3c3dfbaecfU, 0x3d41c039be08f1b7U, 0x3e3f7e793ca8e420U, 0x3d26dfcbbdaa7b27U,
0xbd4a245dbd80d78fU, 0xbdfdff32baeb63f9U, 0x3e240a9c3e0d5cc5U, 0x3de763983d7482daU,
0x3cd5fd9d3cf6a9b8U, 0x3d04e495bdac0fd6U, 0xbd70591b3e1b2078U, 0xbb122e743df82ce0U,
0xbd5b0aef3c0beac6U, 0x3da753e8bf1e4783U, 0x3e3dfbb6bec93732U, 0xbd730862bc92cae7U,
0x3d4950543ea7040aU, 0x3d966c163db5844cU, 0xbcc53fb6bd8b7882U, 0xbd33b851bd97ca2eU,
0xbe7561a63da2d630U, 0xbe2f7bd33dfb59f0U, 0x3e0ee236bcf7fc25U, 0xbd0a48ef3c4388a4U,
0xbe7da349bd1b5bf8U, 0xbd9558cbbe3cc289U, 0x3cc7959a3d38cd8aU, 0x3e0c6347bceb3e2aU,
0xbec26efd3dbe7683U, 0x3e1f9da1bd8421b5U, 0xbdbe1288be1d3409U, 0xbf09b7a33e22c334U,
0x3e3d713ebe19c488U, 0x3cdf307bbe8260a0U, 0xbe09cf91bbb7e57fU, 0x3d6125f2bc9f9384U,
0xbe2fcd7dbdf99946U, 0xbd961ce5bf1cf918U, 0xbe1d091a3d9d2122U, 0xbd0ebafd3dc20322U,
0xbc7888febd8c5d90U, 0x3e082df9bd0ace71U, 0x3c9a8fbe3d4e2660U, 0xbeda997ebceb035bU,
0xbe39e72bbeb2e60fU, 0xbe7dfdc2bb168cabU, 0xbdedec42be85b75dU, 0x3dfae62f3db613b1U,
0xbe140d293e1dc361U, 0x3daf94a2be106145U, 0xbe1874083d121077U, 0xbe364a7ebdea154aU,
0x3ca227f6bd515c88U, 0xbea762f5bdff7933U, 0x3d8775cf3d7e825dU, 0xbdd449a43dcd30b8U,
0x3d983498bc3f4fd1U, 0x3c235c023ddddc05U, 0xbe3f9ee8be8e00cdU, 0xbe2b81e7bd98fd0bU,
0x3cbafc6fbe0127cdU, 0x3e32f3cabe21b90eU, 0x3e2235b9be01f4f1U, 0xbd2de61f3d7f2509U,
0x3c995b24be1ccc74U, 0x3d5c4be1bd729f8dU, 0xbd909bf3bcb855f1U, 0xbce71dfc3d896aa7U,
0xbd89cb143daa63a6U, 0x3e150f2abc3e879aU, 0x3d8d050d3dfd3837U, 0xbdace2003d4fa0aeU,
0x3b90968dbdcc8e93U, 0x3cb34baa3cfdb281U, 0xbc2ca5773dbf1411U, 0xbdc60afabcea4455U,
0x3d8140293ca7c25eU, 0x3e21a6e0be2824e8U, 0xbe24b83abe2289aaU, 0xbd27de0ebc33671dU,
0xbc87636c3e424aeaU, 0x3ccc4ad1bc217291U, 0xbdf6aff1bd8d9360U, 0x3c201c1f3c8037d6U,
0x3cfc06b03e0d1588U, 0x3ce99ed8bd1c6221U, 0x3c05cbed3dbba8e7U, 0xbdf6f99bbd683100U,
0x3cd96b9ebd81e124U, 0x3d5bddc93d1d87cbU, 0x3df5b4e43dc471b6U, 0x3d81009dbd753964U,
0x3e06cf39bdfbc5e9U, 0xbd6352a03d76ba0dU, 0xbda3723d3c57f7b2U, 0xbdb237bd3db0199bU,
0xbdba486fbdadf9ceU, 0xbd18a5cebcb7a182U, 0x3daa3618bcfefa3dU, 0xbe11cd4dbb485312U,
0x3d8331683d34959dU, 0xbd4f76d73dc29f76U, 0xbd7056e03c1428a4U, 0x3d794ab93e07fde5U,
0x3c83ad343d55b443U, 0x3ca8cefbbca9d29cU, 0xbdef6f55be3beaefU, 0xbd0ce11b3e32bc06U,
0xbd047c03bde191ceU, 0xbd751804bd22b9abU, 0xbd1d3cd13da0ed78U, 0x3d336c80bccf4e6eU,
0xbd4759693c26a8f8U, 0xbb8eb437bd927977U, 0xbcd6cf1a3caa3bb6U, 0x3da36f83bda51799U,
0xbb89f19b3d4cac22U, 0xbcad7417bcc03634U, 0x3a15a0273d9b589aU, 0x3e19fdc33a3cd592U,
0xbd47dea8be0964cbU, 0xbe20d956bda235dfU, 0xbd1be3cdbce8cbf6U, 0x3cb347d23d9f6034U,
0x3c85356d3d739952U, 0xbe413ee63e910473U, 0xbd9070a5bcef53beU, 0xbda4f7bbbc2aa8a6U,
0xbe1dfa5cbe671e1eU, 0x3d052d22bd84c49eU, 0x3e41d33b3dffe1e8U, 0xbe89eb283dac98baU,
0x3d85f01abd9caaa9U, 0xbbc586323d88d63eU, 0xbd5405eabd71bd11U, 0xbe0932b1bcc54aedU,
0x3d675dee3e1ac20bU, 0xbe173fc73d52be8eU, 0xbdf472e43c20de97U, 0xbc46b8b73da808a3U,
0x3caff6ea3c946ac6U, 0x3d7f5b9bbdd9ec31U, 0xbd11c39abdb216d2U, 0xbd28b4dfbe9e51e4U,
0x3dea7519bd04deb0U, 0xbdcaca083d824147U, 0x3d1eda213dee31a2U, 0xbd9b0d8cbeb696b4U,
0x3de71c9bbed2d803U, 0x3e00f1db3b4eff91U, 0x3caf95f53de69d08U, 0xbb0d1e0b3d38c496U,
0xbc95973c3b104179U, 0xbdfbc2b43c287ab7U, 0xbcc5b9923d632fb4U, 0xbdc691503d0159a2U,
0x3db72996bd3e2f50U, 0x3da5adb13ddaf449U, 0xbd8d2d4a3d67eaffU, 0xbc687798bea5de14U,
0x3bd7675b3df2cc70U, 0x3d9ff60f3daebc3eU, 0xbdc27727bcf9bf68U, 0xbc4140ed3c3db1b6U,
0xbe29cb3fbe385516U, 0xbe781b4fbe437b8fU, 0xbc8a0b6dbdaba1d9U, 0xbd26659bbe7c4941U,
0x3e11aee13d998d2cU, 0xbd25b799bd2cad7fU, 0x3e1b3ee63d5a4910U, 0x3ea03bc5be259c18U,
0xbda6427e3c684b97U, 0xbda5e5643c256ab0U, 0x3dbcf2e73db59ce6U, 0xbd65639ebd9604b6U,
0x3d5aa79c3d60b6b4U, 0xbe0f09003a75a9cfU, 0xbdf54ad73d0808edU, 0x3d0d33e2bd440ef4U,
0xbe333de63d2159deU, 0xbdace8e6bc24c19dU, 0x3dccb403bc9732baU, 0x3d0b0279be959bcaU,
0xbe1b4e003de3ab0fU, 0xbc5b5c8cbea65ed9U, 0xbcf127adbd28ad36U, 0xbd3b9a05be8d4004U,
0x3ddd5a6dba296ed9U, 0xbe4f20de3df7f3c1U, 0x3bd7db943d539b0eU, 0x3e2d468fbca5ce6fU,
0xbe16beb7bc665668U, 0x3d909225bdf7c361U, 0x3d52ebb8bdd48dc9U, 0xbdbdc412bd968dbbU,
0x3e0631c1be08f4d9U, 0x3e21f50c3dc3d8e7U, 0x3dfc26aabdd5b0d6U, 0xbe58d0e8bdec783cU,
0xbe6a276c3dc5f7fbU, 0xbc2c1b533d55337cU, 0xbd56f7923d83cb0cU, 0xbdd2722b3d9c84b9U,
0xbd7dc88d3de68ab7U, 0x3b2efec53e080dc3U, 0x3d73abdf3dcbc1f6U, 0xbc57fae33c236291U,
0x3b427d2dbd92a4d8U, 0x3d0af67b3b425d15U, 0x3c38d9d5bd2c2988U, 0xbd42b57cbe052fa4U,
0x3d9a3796bdfbc628U, 0x3d09dd3d3d26cb8fU, 0xbe51ac75be62826cU, 0xbdd2d27bbe1d2775U,
0xbe97c4b13e0566beU, 0x3d1f29973d22767eU, 0xbda137f8bcf6a5ddU, 0x3cf324a63c029be4U,
0xbe4169653da4aa0cU, 0xbd1e6c05bdb5efd7U, 0x3dd5cf5d3d622137U, 0xbe01238b3e63ab4cU,
0x3e144eb53d59cdb6U, 0xbec05968beaba06eU, 0xbf81793f3e88794eU, 0x3d6f8122be659695U,
0xbc4d97b53e9e7124U, 0xbd02ddd83c2a80dbU, 0xbe08ea6f3d4eb954U, 0x3e2085bdbdb528f8U,
0xbdc74a7fbb680ec4U, 0x3dfd5a47bddc1835U, 0x3e6c3eb03e59b081U, 0xbe2e30a83e793e13U,
0xbdb146a03e05b5dcU, 0x3e0aa8223ef5b2faU, 0xbda9f7e9bc7c3a3dU, 0x3ea96724bd82b802U,
0x3e12d1b0bc4ee3d2U, 0x3e3c754a3e5b4d74U, 0xbe93a3c43def2e3aU, 0x3ea12808be03a904U,
0xbe8e72fd3e820cddU, 0xbebe34eb3d8c8accU, 0x3b64741cbe78cafaU, 0xbe0a7624be2d7044U,
0xbd9eaaba3d8bf8d0U, 0x3e9a6b86be8a9c3fU, 0xbf04e4cb3ec92230U, 0x3ccd44cabee2cfbbU,
0xbf61cec03ec706e6U, 0x3e99080f3d0ecd38U, 0xbd00663e3ee985d1U, 0xbddfe03b3e8b81cbU,
0xbd95ab423e0d30e3U, 0xbdd57ce8bc7d1ed1U, 0xbf03a7c6bd556a31U, 0xbe6bf0823d4cb87cU,
0xbeaf1c783d6c1a3eU, 0xbd4c524bbedc5ed6U, 0xbcda4234be6051b3U, 0x3c1d8b533d8b1a22U,
0x3cdb10c7bcfa2496U, 0xbe59eee2be1ce643U, 0x3c7b65433d3ec1e1U, 0x3d8af05ebe139d4cU,
0xbe278e37bd5e9f53U, 0x3c79c4b53c8ff840U, 0x3e0cc1ddbdb4fe39U, 0x3d03b41a3dadf3e1U,
0xbe166702bde67597U, 0xbc68cf18bd01be49U, 0xbe12c49f3d954a18U, 0x3d9a3ae13ce0d45eU,
0xbdbf711bbc066ceeU, 0x3c3c2b01bca0e1acU, 0x3d5d6c4d3e18fa59U, 0xbe2a7522bb4af95cU,
0x3d86d60d3ded8448U, 0xbe8d093cbe936088U, 0xbdc97001bef316c8U, 0x3be0536f3cf31acaU,
0xbd6611b4bcabe4d8U, 0x3d8a3ac3bdd4e8efU, 0x3d916a98bf39c3b3U, 0xbe4ed724bdd568e8U,
0x3d976ff03e249e83U, 0x3e4642af3e0b4d83U, 0x3b9af70f3e3eea7bU, 0xbdaddfddbe7fc802U,
0x3d6d613b3e35f707U, 0x3db15af2bdce62fbU, 0xbb0f0e8b3de1c46bU, 0x3dc26546bdab9bf4U,
0xbe1db417be3b7700U, 0x3d1328a4bd60fd2cU, 0xbe05caf4bd7d3c0dU, 0xbe6194e03d3d2751U,
0x3d32692d3d16f607U, 0x3ce4c8dabe2d3621U, 0xbd816bbabd9da3abU, 0x3d4d9e0dbda88533U,
0xbded6e063e8dfe97U, 0x3d943dc9bd35896cU, 0xbe22c715bcfa1a12U, 0x3c97efed3e130f16U,
0xbd2e6682be0281dbU, 0x3d98398fbe0b28e4U, 0xbdf7fd3a3d6eafd3U, 0xbba6489d3d0b855dU,
0x3d7e67cebc934d7aU, 0x3c0b62573da6691eU, 0x3bef53ccbd63f2fbU, 0xbd9ccfc7bdf5e23aU,
0xbe13f9e53d58fa53U, 0x3e3a6c23be41865bU, 0xbb7322693e4220b7U, 0x3e4f5a75be7c73b5U,
0xbda00eacbd954907U, 0xbda5c866bde90f38U, 0xbcf62bd5be21fc17U, 0xbe41b4463db9e9aaU,
0xbda2cf81be0cbc9eU, 0xbdd0dae43e0af59eU, 0x3d48d90d3e30c983U, 0x3e2881a7bebac127U,
0xbd98f0953d32e2f0U, 0xbc8936b4bd88f86fU, 0xbe0c65023d07b7b1U, 0x3d090844bd327236U,
0x3da251623dfff560U, 0x3d93f0453d616e35U, 0x3daaac9fbbad3fe7U, 0xbe06453abd2b560cU,
0x3bef1e873d6b6689U, 0x3e24573b3e06f77cU, 0x3b2a70233df80d23U, 0xbd8e57c1bdb2c9aeU,
0x3d55913fbcff86d1U, 0xbd1d05403e1ad427U, 0x3c50f2b0bdb833d5U, 0x3e3e3afa3d417ec9U,
0xbd49f606bda2d407U, 0xbc8ac6b0bc7636d5U, 0x3db2233d3d7f24abU, 0xbd0d3d24bda33188U,
0x3daa18f4beaa356dU, 0x3e8b6306bea5c096U, 0x3ec3bebf3dc56781U, 0xbd92fb183eb0fa42U,
0x3ea68dc13ddf3250U, 0xbdae1709bb47547eU, 0x3e425acc3dc5fe83U, 0x3ca8c970be113386U,
0xbcc0f11bbd4d253bU, 0x3e0937653d89112dU, 0x3ded35133bf3af76U, 0x3c2729ac3df72f44U,
0xbd0e8d2abda30913U, 0xbdf503103dc10141U, 0xbe0c15e6bde4a1ebU, 0x3c1dfd81be1cad26U,
0xbd7575fabd9f4d9bU, 0x3d115d0a3e0433c1U, 0x3d13ed63be880b3fU, 0xbde8a7fdbdaf751bU,
0x3da31150bd8fd56bU, 0x3d423a92be3e7578U, 0x3d78023f3d0d8a5dU, 0x3d8e83d03e2bb3f0U,
0xbdead9243d8a0966U, 0xbd9ba0c0be8bed9cU, 0x3d9ff5c53c32265fU, 0xbd570bd73dcd515aU,
0x3c8eebdebd1db39fU, 0x3e580e2fbd32bdbaU, 0xbdb89b46bd596661U, 0x3e02abb33a2444aaU,
0x3dfeb228be6b03afU, 0xbd6f3b4c3c8b9b14U, 0xbe345464be1a3a47U, 0xbd18f9f0bc25dfc4U,
0xbd60580a3c597dd4U, 0x3da318423d29a02bU, 0xbdb3ff11bd3a5117U, 0x3da2633c3e107ff7U,
0x3e28f832bdc8c2eeU, 0x3d94728bbd85af2aU, 0x3e03fe93bddf3fcfU, 0xbb9af3d93d20374cU,
0xbd14e1733d64b039U, 0x3dd61fa5be2f1b05U, 0xbe30a6a7be3fa123U, 0xbd1e60fcbe5435b8U,
0xbe5646b83d244d73U, 0x3ce455bfbd5e1061U, 0xbd81b122bc97a366U, 0xbd87d0743d91994bU,
0xbe6ea92bbe0477e0U, 0xbe0cef8639a85412U, 0x3c1f4a933db21800U, 0x3c196978bdbe5f56U,
0x3c943fa53d90a0b9U, 0xbd476eb6bdb83503U, 0xbe09ac12bd24e40cU, 0x3cc941433dba9696U,
0x3db51bc2bcfc90bdU, 0xbd9cf596bd7f0fb0U, 0x3cd70d13be3a65a9U, 0x3de37030bcb3ad72U,
0xbe378016be92ee37U, 0xbc468b5cbd3efd99U, 0xbdb18177bde98defU, 0xbd98f120bd26ea40U,
0x3cbd8a3c3b7a7b28U, 0x3e34396e3d9635eaU, 0xbe2bdbcb3c9bb776U, 0xbd99b815bdfec8feU,
0xbd832d44bda71ac0U, 0x3dd2a1523e0a967dU, 0xbcc448b53ef7fca3U, 0x3bbed5863e70c659U,
0x3d2dea333d6a95e5U, 0xbd0497cc3e243260U, 0x3d6c2444bd9b62d0U, 0xbe0872f5bf2db1d3U,
0x3d07dc89be2af55dU, 0x3e22ee683e213ebaU, 0xbda0a10bbd57a9d7U, 0xbc0ad79bbd0c9d0cU,
0xbef4e714bd063ab9U, 0x3c29092c3d845a02U, 0x3e883964bd510b82U, 0x3dac4f80bdec6184U,
0x3c473ea2bdd15a30U, 0x3e2bbf14bd2f62b6U, 0xba86a03cbe7e2f26U, 0x3e4a3e60be0b2562U,
0xbc64744f3e1326afU, 0xbd0fa498be8f3eddU, 0xbd191495bd246b72U, 0x3cee955cbdb5a1a6U,
0x3d9fb8c33dda05abU, 0xbe0e12ae3ce7a86aU, 0xbccf23c3bd0a3fc8U, 0xbd88fb9a3eabf950U,
0xbf18d1e4bd8eaad1U, 0xbedf6474be12ce26U, 0x3c393def3bb75431U, 0x3c3b6fa5bf10f658U,
0xbe1803fbbd38f5c9U, 0xbe51fae4be6f32dcU, 0xbdeb524dbd935a27U, 0x3ebe5e95be058e7cU,
0xbe2bcb20bd4f8ee9U, 0x3cb5fbdd3e029f46U, 0x3cf62bc73dc164d6U, 0xbdd981d63e8bdfb2U,
0xbe8f20f3be219c9cU, 0xbc733f7c3cee8999U, 0x3d42bc33bd40fb36U, 0xbbe73da2be03b2beU,
0x3bf6f54bbd381945U, 0x3d4e75293e2bc83cU, 0xbcbb67cbbe0e285eU, 0x3d06b19b3dbde788U,
0xbc8bae9dbde901e2U, 0x3d42f6973c1076cdU, 0x3d55fe713e21d2fcU, 0x3dd872f73dcc0045U,
0x3c03bf033d96e1b6U, 0xbd5d5fda3e09cd33U, 0xbd9c0f18be0e4c38U, 0x3d7273583e45c388U,
0x3d35bc6d3c4003c0U, 0xbd44bcbb3d82383eU, 0x3c9c505c3c345291U, 0x3d8e49c0bd471a8bU,
0xbc75cc113cf58c59U, 0x3b9be7123bb3f862U, 0xbd71704fbdedf0fbU, 0xbdd836363d4ca44bU,
0xbe0749e2bdd555c7U, 0x3e69f8033d3cb6a3U, 0x3bb001de3d7bbbdbU, 0x3e1c5dbcbd2e6509U,
0xbd0b775e39814c63U, 0xbe94388b3e229308U, 0xbbce36d2be27b426U, 0x3d1b6ef63d9b494cU,
0x3e2b93703cd79f18U, 0x3bb4adf93e637532U, 0x3e112106bdad2fa5U, 0x3d227f613dddc27eU,
0x3d4d9f40bc282526U, 0x3d8be4a33bab8019U, 0xbce5cf173dc6e7ceU, 0xbbae3ca93e53d492U,
0xbd107b6dbd8c08a7U, 0x3b0433843c9b4fd6U, 0x3c40be293c091e4cU, 0x3dbfb5ea3e07d5b7U,
0x3ca406fa3bc9faf1U, 0x3d6f70f63db7b03cU, 0xbd40874ebdc33b6fU, 0x3d8ccbe2bdaeda93U,
0x3d5240dd3e4282d6U, 0xbd46ed483e23aa63U, 0xbc04258b3d1f3a28U, 0x3e0eb01dbe371d2cU,
0xbd0ca1b7bdea15c3U, 0xbdf3a7eabb7703e7U, 0x3dbd8a4fbb125565U, 0xbdf531ae3e3c097cU,
0xbe58eff63d8386eeU, 0x3c3e71a1bda0e915U, 0x3d3432f9bdae530cU, 0x3d044c963e4cc2b3U,
0xbe045ec63e6ef0deU, 0x3d03aaecbca30d35U, 0x3daf52e2be14ddefU, 0xbe16319fbe26b2f2U,
0xbe0bc2f23e88834bU, 0xbe0e67133d8c47a6U, 0x3e654a433df8b881U, 0xbe322b173e37d997U,
0x3e237ee53d9d77d6U, 0xbd023ff0be74dd2fU, 0xbd950271be4b716cU, 0x3cc974df3e12ed5aU,
0x3dbc096e3c92ea65U, 0xbebfe993bba58c69U, 0xbb4fc20a3df46f41U, 0xbdbd551fbdf15dd7U,
0xbe5f7b8abd36fdebU, 0x3d34664d3d4ee5b7U, 0x3df6f1eabcfe5470U, 0xbca3d1163de5595cU,
0xbe1805c0bc2c2d4fU, 0xbd8d7d95bdfb1fa9U, 0x3e2b64633e236958U, 0x3df45ebf3d8d6b65U,
0xbe146f923c488e1fU, 0x3d0ddccbbced0acaU, 0x3d7175353e008537U, 0xbe24795b3c436252U,
0x3e12dce23e2d8aacU, 0x3e04deefbe53f665U, 0x3cbf997bbe524693U, 0x3bfc2ec73c9d34faU,
0xbcbe159d3d88a890U, 0x3dda393d3e2ac2eeU, 0x3e03955f3d9c541bU, 0x3ddc27e3bc6fc2e5U,
0xbe3985203ca79c52U, 0x3d7234893d33adf0U, 0x39e02b0abe0b84e2U, 0xbdb390ebbcacb303U,
0xbe76a4f0bc9f9810U, 0x3de1529c3e0aa114U, 0xbdaf826abe55d78fU, 0xbdcf29403d143470U,
0xbd05a0d6bd3efc9eU, 0xbd3b67a93d200a70U, 0xbd2a2c623d9d9ed1U, 0x3ce56d873c0bdc9aU,
0x3d56c1713cf933f6U, 0xb9f0affebe7d10c7U, 0x3e62de903bcd56dfU, 0xbe3ed8723d72d08dU,
0x3d8feaf33e27a12dU, 0x3d93cb2abde2a792U, 0xbe5e31303d8827e2U, 0x3d2cb9cb3e8914c7U,
0xbe2bbdc53dae6228U, 0x3dda0090be1e62c8U, 0xbdf886f3be30083fU, 0x3c36471e3e0344abU,
0xbe84be323e27a4c8U, 0x3e0d2237be975008U, 0x3dc7b8043e121416U, 0x3d2a6103ba7495afU,
0xbd5cc4d8bdfc67d7U, 0xbd96a4e4bdd4d7d6U, 0x3e0097e23d8c190dU, 0xbdffa08fbd04ad52U,
0xbdc625d03dd63f24U, 0x3d1ae68dbe37c894U, 0x3c9670ff3daaa2c0U, 0x3d698e213dea96e9U,
0xbdced93d3dddf689U, 0xbe1bd1853dcb4977U, 0xbc8659e0bed64971U, 0xbe26e0e63cffc29bU,
0xbd424fd5bcb48decU, 0xbde0fdefbccd25b9U, 0xbddc25ee3c43516cU, 0x3d9359333d960541U,
0xbe3a0c033d8c4ae8U, 0xbd59fc433d81ee4fU, 0xbe48ac5d3d7571faU, 0xbdf949333cdabca6U,
0x3d988b8fbcc150d5U, 0x3e2eb91fbd0e9dd0U, 0xbda19f2dbc23b3b7U, 0xbdc80300be0e873aU,
0xbcb6002dbe08870cU, 0xbd7625f23e01dce2U, 0xbd0ae9c5bd201a88U, 0xbdbb6ac5bdb77c4cU,
0x3d80e5d2bd1116f6U, 0xbe1581e6be8d0541U, 0xbe834baabed5305dU, 0xbe0807bcbce5055cU,
0x3d9004613db08af2U, 0xbdcf015fbe2b8f47U, 0x3dbb4779bd67490bU, 0xbc5a6dc0bc8787b9U,
0xbcb091b9bd8e2141U, 0x3daec329beaa0261U, 0x3be94f083e0d3311U, 0xbdb9ded3be6dc307U,
0xbc7c357ebd3b3da0U, 0x3d98381abdeb3b5dU, 0xbe03225ebd8a6223U, 0xbe946a6ebe0c592dU,
0xbe2f7baabe46f3caU, 0x3ca3f12bbdb19822U, 0xbdfdfaccbe3ccb29U, 0xbe35ac94be63371eU,
0xbe1a50ef3dd6778bU, 0xbe78bbc9bea2af66U, 0xbe11f5bcbe1c2a4aU, 0x3e40b83cbe469526U,
0xbd696e893d91b71eU, 0x3c11ded5be685296U, 0x3dc21d483cdb44eaU, 0xbe8005c7be7738d0U,
0xbc877eb7be25336bU, 0xbace08e2bca32ec7U, 0x3c4cb4233ca51164U, 0xbcb205433c846011U,
0xbd76175dbc2ca8c5U, 0x3a5717d03e32793bU, 0x3c92d295bd0b2234U, 0x3ca304b43d2dcaccU,
0x38bfe4983b5f5c40U, 0xbca98156bcec5562U, 0xbd876db6be173fe4U, 0xbd13121cbcc72b32U,
0x3d0643e53ce69a45U, 0x3cef857ebcd022c2U, 0xbc6996763caf5e21U, 0x3d12b5b33cde9149U,
0xbde6b3d8bd4c1fbcU, 0xbdfe81bcbc230703U, 0xbb202dd7bad3de1cU, 0xba0fe092bb332caeU,
0x3c49d3a93bc61ecfU, 0xbdab5354baf6bda6U, 0x3e1521e83b94a8efU, 0x3e2f2015bd988f73U,
0x3a922ae9bbb0b932U, 0xbaf07b90bc0d722cU, 0xbaa56a1fbb4722e4U, 0x3c411d9bbe75316eU,
0xbb7d1d0ebc0b0e33U, 0xbe178cabbda2f392U, 0xbacec7bebb95b595U, 0xbadf6dd93db6b8d4U,
0x3bcac7fc3c84e54cU,
};
ai_handle g_network_weights_table[1 + 2] = {
AI_HANDLE_PTR(AI_MAGIC_MARKER),
AI_HANDLE_PTR(s_network_weights_array_u64),
AI_HANDLE_PTR(AI_MAGIC_MARKER),
};
| 121,806 | C | 83.353878 | 85 | 0.879645 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/register_interface.c |
/**
******************************************************************************
* @file register_interface.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the register access for the MCP protocol
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#include "mc_type.h"
#include "string.h"
#include "register_interface.h"
#include "mc_config.h"
#include "mcp.h"
#include "mcp_config.h"
#include "mcpa.h"
#include "mc_configuration_registers.h"
uint8_t RI_SetRegisterGlobal(uint16_t regID, uint8_t typeID, uint8_t *data, uint16_t *size, int16_t dataAvailable)
{
uint8_t retVal = MCP_CMD_OK;
switch(typeID)
{
case TYPE_DATA_8BIT:
{
switch (regID)
{
case MC_REG_STATUS:
{
retVal = MCP_ERROR_RO_REG;
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 1;
break;
}
case TYPE_DATA_16BIT:
{
switch (regID)
{
case MC_REG_BUS_VOLTAGE:
case MC_REG_HEATS_TEMP:
case MC_REG_MOTOR_POWER:
{
retVal = MCP_ERROR_RO_REG;
break;
}
case MC_REG_DAC_USER1:
case MC_REG_DAC_USER2:
break;
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 2;
break;
}
case TYPE_DATA_32BIT:
{
switch (regID)
{
case MC_REG_FAULTS_FLAGS:
{
retVal = MCP_ERROR_RO_REG;
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 4;
break;
}
case TYPE_DATA_STRING:
{
const char_t *charData = (const char_t *)data;
char_t *dummy = (char_t *)data;
retVal = MCP_ERROR_RO_REG;
/* Used to compute String length stored in RXBUFF even if Reg does not exist */
/* It allows to jump to the next command in the buffer */
(void)RI_MovString(charData, dummy, size, dataAvailable);
break;
}
case TYPE_DATA_RAW:
{
uint16_t rawSize = *(uint16_t *)data; //cstat !MISRAC2012-Rule-11.3
/* The size consumed by the structure is the structure size + 2 bytes used to store the size */
*size = rawSize + 2U;
uint8_t *rawData = data; /* rawData points to the first data (after size extraction) */
rawData++;
rawData++;
if (*size > (uint16_t)dataAvailable)
{
/* The decoded size of the raw structure can not match with transmitted buffer, error in buffer
construction */
*size = 0;
retVal = MCP_ERROR_BAD_RAW_FORMAT; /* This error stop the parsing of the CMD buffer */
}
else
{
switch (regID)
{
case MC_REG_APPLICATION_CONFIG:
case MC_REG_MOTOR_CONFIG:
case MC_REG_GLOBAL_CONFIG:
case MC_REG_FOCFW_CONFIG:
{
retVal = MCP_ERROR_RO_REG;
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
}
break;
}
default:
{
retVal = MCP_ERROR_BAD_DATA_TYPE;
*size =0; /* From this point we are not able anymore to decode the RX buffer */
break;
}
}
return (retVal);
}
uint8_t RI_SetRegisterMotor1(uint16_t regID, uint8_t typeID, uint8_t *data, uint16_t *size, int16_t dataAvailable)
{
uint8_t retVal = MCP_CMD_OK;
uint8_t motorID=0;
MCI_Handle_t *pMCIN = &Mci[motorID];
switch(typeID)
{
case TYPE_DATA_8BIT:
{
switch (regID)
{
case MC_REG_STATUS:
{
retVal = MCP_ERROR_RO_REG;
break;
}
case MC_REG_CONTROL_MODE:
{
uint8_t regdata8 = *data;
if ((uint8_t)MCM_TORQUE_MODE == regdata8)
{
MCI_ExecTorqueRamp(pMCIN, MCI_GetTeref(pMCIN), 0);
}
else
{
/* Nothing to do */
}
if ((uint8_t)MCM_SPEED_MODE == regdata8)
{
MCI_ExecSpeedRamp(pMCIN, MCI_GetMecSpeedRefUnit(pMCIN), 0);
}
else
{
/* Nothing to do */
}
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 1;
break;
}
case TYPE_DATA_16BIT:
{
uint16_t regdata16 = *(uint16_t *)data; //cstat !MISRAC2012-Rule-11.3
switch (regID)
{
case MC_REG_SPEED_KP:
{
PID_SetKP(&PIDSpeedHandle_M1, (int16_t)regdata16);
break;
}
case MC_REG_SPEED_KI:
{
PID_SetKI(&PIDSpeedHandle_M1, (int16_t)regdata16);
break;
}
case MC_REG_SPEED_KD:
{
PID_SetKD(&PIDSpeedHandle_M1, (int16_t)regdata16);
break;
}
case MC_REG_I_Q_KP:
{
PID_SetKP(&PIDIqHandle_M1, (int16_t)regdata16);
break;
}
case MC_REG_I_Q_KI:
{
PID_SetKI(&PIDIqHandle_M1, (int16_t)regdata16);
break;
}
case MC_REG_I_Q_KD:
{
PID_SetKD(&PIDIqHandle_M1, (int16_t)regdata16);
break;
}
case MC_REG_I_D_KP:
{
PID_SetKP(&PIDIdHandle_M1, (int16_t)regdata16);
break;
}
case MC_REG_I_D_KI:
{
PID_SetKI(&PIDIdHandle_M1, (int16_t)regdata16);
break;
}
case MC_REG_I_D_KD:
{
PID_SetKD(&PIDIdHandle_M1, (int16_t)regdata16);
break;
}
case MC_REG_BUS_VOLTAGE:
case MC_REG_HEATS_TEMP:
case MC_REG_MOTOR_POWER:
{
retVal = MCP_ERROR_RO_REG;
break;
}
case MC_REG_I_A:
case MC_REG_I_B:
case MC_REG_I_ALPHA_MEAS:
case MC_REG_I_BETA_MEAS:
case MC_REG_I_Q_MEAS:
case MC_REG_I_D_MEAS:
case MC_REG_FLUXWK_BUS_MEAS:
{
retVal = MCP_ERROR_RO_REG;
break;
}
case MC_REG_I_Q_REF:
{
qd_t currComp;
currComp = MCI_GetIqdref(pMCIN);
currComp.q = (int16_t)regdata16;
MCI_SetCurrentReferences(pMCIN,currComp);
break;
}
case MC_REG_I_D_REF:
{
qd_t currComp;
currComp = MCI_GetIqdref(pMCIN);
currComp.d = (int16_t)regdata16;
MCI_SetCurrentReferences(pMCIN,currComp);
break;
}
case MC_REG_V_Q:
case MC_REG_V_D:
case MC_REG_V_ALPHA:
case MC_REG_V_BETA:
case MC_REG_ENCODER_EL_ANGLE:
case MC_REG_ENCODER_SPEED:
{
retVal = MCP_ERROR_RO_REG;
break;
}
case MC_REG_STOPLL_C1:
{
int16_t hC1;
int16_t hC2;
STO_PLL_GetObserverGains(&STO_PLL_M1, &hC1, &hC2);
STO_PLL_SetObserverGains(&STO_PLL_M1, (int16_t)regdata16, hC2);
break;
}
case MC_REG_STOPLL_C2:
{
int16_t hC1;
int16_t hC2;
STO_PLL_GetObserverGains(&STO_PLL_M1, &hC1, &hC2);
STO_PLL_SetObserverGains(&STO_PLL_M1, hC1, (int16_t)regdata16);
break;
}
case MC_REG_STOPLL_KI:
{
PID_SetKI (&(&STO_PLL_M1)->PIRegulator, (int16_t)regdata16);
break;
}
case MC_REG_STOPLL_KP:
{
PID_SetKP (&(&STO_PLL_M1)->PIRegulator, (int16_t)regdata16);
break;
}
case MC_REG_STOPLL_EL_ANGLE:
case MC_REG_STOPLL_ROT_SPEED:
case MC_REG_STOPLL_I_ALPHA:
case MC_REG_STOPLL_I_BETA:
case MC_REG_STOPLL_BEMF_ALPHA:
case MC_REG_STOPLL_BEMF_BETA:
{
retVal = MCP_ERROR_RO_REG;
break;
}
case MC_REG_DAC_USER1:
case MC_REG_DAC_USER2:
break;
case MC_REG_SPEED_KP_DIV:
{
PID_SetKPDivisorPOW2(&PIDSpeedHandle_M1, regdata16);
break;
}
case MC_REG_SPEED_KI_DIV:
{
PID_SetKIDivisorPOW2(&PIDSpeedHandle_M1, regdata16);
break;
}
case MC_REG_SPEED_KD_DIV:
{
PID_SetKDDivisorPOW2(&PIDSpeedHandle_M1, regdata16);
break;
}
case MC_REG_I_D_KP_DIV:
{
PID_SetKPDivisorPOW2(&PIDIdHandle_M1, regdata16);
break;
}
case MC_REG_I_D_KI_DIV:
{
PID_SetKIDivisorPOW2(&PIDIdHandle_M1, regdata16);
break;
}
case MC_REG_I_D_KD_DIV:
{
PID_SetKDDivisorPOW2(&PIDIdHandle_M1, regdata16);
break;
}
case MC_REG_I_Q_KP_DIV:
{
PID_SetKPDivisorPOW2(&PIDIqHandle_M1, regdata16);
break;
}
case MC_REG_I_Q_KI_DIV:
{
PID_SetKIDivisorPOW2(&PIDIqHandle_M1, regdata16);
break;
}
case MC_REG_I_Q_KD_DIV:
{
PID_SetKDDivisorPOW2(&PIDIqHandle_M1, regdata16);
break;
}
case MC_REG_STOPLL_KI_DIV:
{
PID_SetKIDivisorPOW2 (&(&STO_PLL_M1)->PIRegulator,regdata16);
break;
}
case MC_REG_STOPLL_KP_DIV:
{
PID_SetKPDivisorPOW2 (&(&STO_PLL_M1)->PIRegulator,regdata16);
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 2;
break;
}
case TYPE_DATA_32BIT:
{
uint32_t regdata32 = *(uint32_t *)data; //cstat !MISRAC2012-Rule-11.3
switch (regID)
{
case MC_REG_FAULTS_FLAGS:
case MC_REG_SPEED_MEAS:
{
retVal = MCP_ERROR_RO_REG;
break;
}
case MC_REG_SPEED_REF:
{
MCI_ExecSpeedRamp(pMCIN,((((int16_t)regdata32) * ((int16_t)SPEED_UNIT)) / (int16_t)U_RPM), 0);
break;
}
case MC_REG_STOPLL_EST_BEMF:
case MC_REG_STOPLL_OBS_BEMF:
{
retVal = MCP_ERROR_RO_REG;
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 4;
break;
}
case TYPE_DATA_STRING:
{
const char_t *charData = (const char_t *)data;
char_t *dummy = (char_t *)data;
retVal = MCP_ERROR_RO_REG;
/* Used to compute String length stored in RXBUFF even if Reg does not exist */
/* It allows to jump to the next command in the buffer */
(void)RI_MovString(charData, dummy, size, dataAvailable);
break;
}
case TYPE_DATA_RAW:
{
uint16_t rawSize = *(uint16_t *)data; //cstat !MISRAC2012-Rule-11.3
/* The size consumed by the structure is the structure size + 2 bytes used to store the size */
*size = rawSize + 2U;
uint8_t *rawData = data; /* rawData points to the first data (after size extraction) */
rawData++;
rawData++;
if (*size > (uint16_t)dataAvailable)
{
/* The decoded size of the raw structure can not match with transmitted buffer, error in buffer
construction */
*size = 0;
retVal = MCP_ERROR_BAD_RAW_FORMAT; /* This error stop the parsing of the CMD buffer */
}
else
{
switch (regID)
{
case MC_REG_APPLICATION_CONFIG:
case MC_REG_MOTOR_CONFIG:
case MC_REG_GLOBAL_CONFIG:
case MC_REG_FOCFW_CONFIG:
{
retVal = MCP_ERROR_RO_REG;
break;
}
case MC_REG_SPEED_RAMP:
{
int32_t rpm;
uint16_t duration;
rpm = *(int32_t *)rawData; //cstat !MISRAC2012-Rule-11.3
duration = *(uint16_t *)&rawData[4]; //cstat !MISRAC2012-Rule-11.3
MCI_ExecSpeedRamp(pMCIN, (int16_t)((rpm * SPEED_UNIT) / U_RPM), duration);
break;
}
case MC_REG_TORQUE_RAMP:
{
uint32_t torque;
uint16_t duration;
torque = *(uint32_t *)rawData; //cstat !MISRAC2012-Rule-11.3
duration = *(uint16_t *)&rawData[4]; //cstat !MISRAC2012-Rule-11.3
MCI_ExecTorqueRamp(pMCIN, (int16_t)torque, duration);
break;
}
case MC_REG_CURRENT_REF:
{
qd_t currComp;
currComp.q = *((int16_t *) rawData); //cstat !MISRAC2012-Rule-11.3
currComp.d = *((int16_t *) &rawData[2]); //cstat !MISRAC2012-Rule-11.3
MCI_SetCurrentReferences(pMCIN, currComp);
break;
}
case MC_REG_ASYNC_UARTA:
{
retVal = MCPA_cfgLog (&MCPA_UART_A, rawData);
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
}
break;
}
default:
{
retVal = MCP_ERROR_BAD_DATA_TYPE;
*size =0; /* From this point we are not able anymore to decode the RX buffer */
break;
}
}
return (retVal);
}
uint8_t RI_GetRegisterGlobal(uint16_t regID,uint8_t typeID,uint8_t * data,uint16_t *size,int16_t freeSpace){
uint8_t retVal = MCP_CMD_OK;
switch (typeID)
{
case TYPE_DATA_8BIT:
{
if (freeSpace > 0)
{
switch (regID)
{
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 1;
}
else
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
break;
}
case TYPE_DATA_16BIT:
{
if (freeSpace >= 2)
{
switch (regID)
{
case MC_REG_DAC_USER1:
case MC_REG_DAC_USER2:
break;
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 2;
}
else
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
break;
}
case TYPE_DATA_32BIT:
{
if (freeSpace >= 4)
{
switch (regID)
{
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 4;
}
else
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
break;
}
case TYPE_DATA_STRING:
{
char_t *charData = (char_t *)data;
switch (regID)
{
case MC_REG_FW_NAME:
retVal = RI_MovString (FIRMWARE_NAME ,charData, size, freeSpace);
break;
case MC_REG_CTRL_STAGE_NAME:
{
retVal = RI_MovString (CTL_BOARD ,charData, size, freeSpace);
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
*size= 0 ; /* */
break;
}
}
break;
}
case TYPE_DATA_RAW:
{
/* First 2 bytes of the answer is reserved to the size */
uint16_t *rawSize = (uint16_t *)data; //cstat !MISRAC2012-Rule-11.3
uint8_t * rawData = data;
rawData++;
rawData++;
switch (regID)
{
case MC_REG_GLOBAL_CONFIG:
{
*rawSize = (uint16_t)sizeof(GlobalConfig_reg_t);
if (((*rawSize) + 2U) > (uint16_t)freeSpace)
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
else
{
(void)memcpy(rawData, &globalConfig_reg, sizeof(GlobalConfig_reg_t));
}
break;
}
case MC_REG_ASYNC_UARTA:
case MC_REG_ASYNC_UARTB:
case MC_REG_ASYNC_STLNK:
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
/* Size of the answer is size of the data + 2 bytes containing data size */
*size = (*rawSize) + 2U;
break;
}
default:
{
retVal = MCP_ERROR_BAD_DATA_TYPE;
break;
}
}
return (retVal);
}
uint8_t RI_GetRegisterMotor1(uint16_t regID,uint8_t typeID,uint8_t * data,uint16_t *size,int16_t freeSpace) {
uint8_t retVal = MCP_CMD_OK;
uint8_t motorID=0;
MCI_Handle_t *pMCIN = &Mci[motorID];
BusVoltageSensor_Handle_t* BusVoltageSensor= &BusVoltageSensor_M1._Super;
switch (typeID)
{
case TYPE_DATA_8BIT:
{
if (freeSpace > 0)
{
switch (regID)
{
case MC_REG_STATUS:
{
*data = (uint8_t)MCI_GetSTMState(pMCIN);
break;
}
case MC_REG_CONTROL_MODE:
{
*data = (uint8_t)MCI_GetControlMode(pMCIN);
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 1;
}
else
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
break;
}
case TYPE_DATA_16BIT:
{
uint16_t *regdataU16 = (uint16_t *)data; //cstat !MISRAC2012-Rule-11.3
int16_t *regdata16 = (int16_t *) data; //cstat !MISRAC2012-Rule-11.3
if (freeSpace >= 2)
{
switch (regID)
{
case MC_REG_SPEED_KP:
{
*regdata16 = PID_GetKP(&PIDSpeedHandle_M1);
break;
}
case MC_REG_SPEED_KI:
{
*regdata16 = PID_GetKI(&PIDSpeedHandle_M1);
break;
}
case MC_REG_SPEED_KD:
{
*regdata16 = PID_GetKD(&PIDSpeedHandle_M1);
break;
}
case MC_REG_I_Q_KP:
{
*regdata16 = PID_GetKP(&PIDIqHandle_M1);
break;
}
case MC_REG_I_Q_KI:
{
*regdata16 = PID_GetKI(&PIDIqHandle_M1);
break;
}
case MC_REG_I_Q_KD:
{
*regdata16 = PID_GetKD(&PIDIqHandle_M1);
break;
}
case MC_REG_I_D_KP:
{
*regdata16 = PID_GetKP(&PIDIdHandle_M1);
break;
}
case MC_REG_I_D_KI:
{
*regdata16 = PID_GetKI(&PIDIdHandle_M1);
break;
}
case MC_REG_I_D_KD:
{
*regdata16 = PID_GetKD(&PIDIdHandle_M1);
break;
}
case MC_REG_BUS_VOLTAGE:
{
*regdataU16 = VBS_GetAvBusVoltage_V(BusVoltageSensor);
break;
}
case MC_REG_HEATS_TEMP:
{
*regdata16 = NTC_GetAvTemp_C(&TempSensor_M1);
break;
}
case MC_REG_I_A:
{
*regdata16 = MCI_GetIab(pMCIN).a;
break;
}
case MC_REG_I_B:
{
*regdata16 = MCI_GetIab(pMCIN).b;
break;
}
case MC_REG_I_ALPHA_MEAS:
{
*regdata16 = MCI_GetIalphabeta(pMCIN).alpha;
break;
}
case MC_REG_I_BETA_MEAS:
{
*regdata16 = MCI_GetIalphabeta(pMCIN).beta;
break;
}
case MC_REG_I_Q_MEAS:
{
*regdata16 = MCI_GetIqd(pMCIN).q;
break;
}
case MC_REG_I_D_MEAS:
{
*regdata16 = MCI_GetIqd(pMCIN).d;
break;
}
case MC_REG_I_Q_REF:
{
*regdata16 = MCI_GetIqdref(pMCIN).q;
break;
}
case MC_REG_I_D_REF:
{
*regdata16 = MCI_GetIqdref(pMCIN).d;
break;
}
case MC_REG_V_Q:
{
*regdata16 = MCI_GetVqd(pMCIN).q;
break;
}
case MC_REG_V_D:
{
*regdata16 = MCI_GetVqd(pMCIN).d;
break;
}
case MC_REG_V_ALPHA:
{
*regdata16 = MCI_GetValphabeta(pMCIN).alpha;
break;
}
case MC_REG_V_BETA:
{
*regdata16 = MCI_GetValphabeta(pMCIN).beta;
break;
}
case MC_REG_ENCODER_EL_ANGLE:
{
*regdata16 = SPD_GetElAngle ((SpeednPosFdbk_Handle_t*) &ENCODER_M1); //cstat !MISRAC2012-Rule-11.3
break;
}
case MC_REG_ENCODER_SPEED:
{
*regdata16 = SPD_GetS16Speed ((SpeednPosFdbk_Handle_t*) &ENCODER_M1); //cstat !MISRAC2012-Rule-11.3
break;
}
case MC_REG_STOPLL_EL_ANGLE:
{
//cstat !MISRAC2012-Rule-11.3
*regdata16 = SPD_GetElAngle((SpeednPosFdbk_Handle_t *)&STO_PLL_M1);
break;
}
case MC_REG_STOPLL_ROT_SPEED:
{
//cstat !MISRAC2012-Rule-11.3
*regdata16 = SPD_GetS16Speed((SpeednPosFdbk_Handle_t *)&STO_PLL_M1);
break;
}
case MC_REG_STOPLL_I_ALPHA:
{
*regdata16 = STO_PLL_GetEstimatedCurrent(&STO_PLL_M1).alpha;
break;
}
case MC_REG_STOPLL_I_BETA:
{
*regdata16 = STO_PLL_GetEstimatedCurrent(&STO_PLL_M1).beta;
break;
}
case MC_REG_STOPLL_BEMF_ALPHA:
{
*regdata16 = STO_PLL_GetEstimatedBemf(&STO_PLL_M1).alpha;
break;
}
case MC_REG_STOPLL_BEMF_BETA:
{
*regdata16 = STO_PLL_GetEstimatedBemf(&STO_PLL_M1).beta;
break;
}
case MC_REG_STOPLL_C1:
{
int16_t hC1;
int16_t hC2;
STO_PLL_GetObserverGains(&STO_PLL_M1, &hC1, &hC2);
*regdata16 = hC1;
break;
}
case MC_REG_STOPLL_C2:
{
int16_t hC1;
int16_t hC2;
STO_PLL_GetObserverGains(&STO_PLL_M1, &hC1, &hC2);
*regdata16 = hC2;
break;
}
case MC_REG_STOPLL_KI:
{
*regdata16 = PID_GetKI (&(&STO_PLL_M1)->PIRegulator);
break;
}
case MC_REG_STOPLL_KP:
{
*regdata16 = PID_GetKP (&(&STO_PLL_M1)->PIRegulator);
break;
}
case MC_REG_DAC_USER1:
case MC_REG_DAC_USER2:
break;
case MC_REG_SPEED_KP_DIV:
{
*regdataU16 = (uint16_t)PID_GetKPDivisorPOW2(&PIDSpeedHandle_M1);
break;
}
case MC_REG_SPEED_KI_DIV:
{
*regdataU16 = (uint16_t)PID_GetKIDivisorPOW2(&PIDSpeedHandle_M1);
break;
}
case MC_REG_SPEED_KD_DIV:
{
*regdataU16 = PID_GetKDDivisorPOW2(&PIDSpeedHandle_M1);
break;
}
case MC_REG_I_D_KP_DIV:
{
*regdataU16 = PID_GetKPDivisorPOW2(&PIDIdHandle_M1);
break;
}
case MC_REG_I_D_KI_DIV:
{
*regdataU16 = PID_GetKIDivisorPOW2(&PIDIdHandle_M1);
break;
}
case MC_REG_I_D_KD_DIV:
{
*regdataU16 = PID_GetKDDivisorPOW2(&PIDIdHandle_M1);
break;
}
case MC_REG_I_Q_KP_DIV:
{
*regdataU16 = PID_GetKPDivisorPOW2(&PIDIqHandle_M1);
break;
}
case MC_REG_I_Q_KI_DIV:
{
*regdataU16 = PID_GetKIDivisorPOW2(&PIDIqHandle_M1);
break;
}
case MC_REG_I_Q_KD_DIV:
{
*regdataU16 = PID_GetKDDivisorPOW2(&PIDIqHandle_M1);
break;
}
case MC_REG_STOPLL_KI_DIV:
{
*regdataU16 = PID_GetKIDivisorPOW2(&(&STO_PLL_M1)->PIRegulator);
break;
}
case MC_REG_STOPLL_KP_DIV:
{
*regdataU16 = PID_GetKPDivisorPOW2(&(&STO_PLL_M1)->PIRegulator);
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 2;
}
else
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
break;
}
case TYPE_DATA_32BIT:
{
uint32_t *regdataU32 = (uint32_t *)data; //cstat !MISRAC2012-Rule-11.3
int32_t *regdata32 = (int32_t *)data; //cstat !MISRAC2012-Rule-11.3
if (freeSpace >= 4)
{
switch (regID)
{
case MC_REG_FAULTS_FLAGS:
{
*regdataU32 = MCI_GetFaultState(pMCIN);
break;
}
case MC_REG_SPEED_MEAS:
{
*regdata32 = (((int32_t)MCI_GetAvrgMecSpeedUnit(pMCIN) * U_RPM) / SPEED_UNIT);
break;
}
case MC_REG_SPEED_REF:
{
*regdata32 = (((int32_t)MCI_GetMecSpeedRefUnit(pMCIN) * U_RPM) / SPEED_UNIT);
break;
}
case MC_REG_STOPLL_EST_BEMF:
{
*regdata32 = STO_PLL_GetEstimatedBemfLevel(&STO_PLL_M1);
break;
}
case MC_REG_STOPLL_OBS_BEMF:
{
*regdata32 = STO_PLL_GetObservedBemfLevel(&STO_PLL_M1);
break;
}
case MC_REG_MOTOR_POWER:
{
FloatToU32 ReadVal; //cstat !MISRAC2012-Rule-19.2
ReadVal.Float_Val = PQD_GetAvrgElMotorPowerW(pMPM[M1]);
*regdataU32 = ReadVal.U32_Val; //cstat !UNION-type-punning
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
*size = 4;
}
else
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
break;
}
case TYPE_DATA_STRING:
{
char_t *charData = (char_t *)data;
switch (regID)
{
case MC_REG_PWR_STAGE_NAME:
{
retVal = RI_MovString (PWR_BOARD_NAME[motorID], charData, size, freeSpace);
break;
}
case MC_REG_MOTOR_NAME:
{
retVal = RI_MovString (MotorConfig_reg[motorID]->name ,charData, size, freeSpace);
break;
}
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
*size= 0 ; /* */
break;
}
}
break;
}
case TYPE_DATA_RAW:
{
/* First 2 bytes of the answer is reserved to the size */
uint16_t *rawSize = (uint16_t *)data; //cstat !MISRAC2012-Rule-11.3
uint8_t * rawData = data;
rawData++;
rawData++;
switch (regID)
{
case MC_REG_APPLICATION_CONFIG:
{
*rawSize = (uint16_t)sizeof(ApplicationConfig_reg_t);
if (((*rawSize) + 2U) > (uint16_t)freeSpace)
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
else
{
ApplicationConfig_reg_t const *pApplicationConfig_reg = ApplicationConfig_reg[motorID];
(void)memcpy(rawData, (const uint8_t *)pApplicationConfig_reg, sizeof(ApplicationConfig_reg_t));
}
break;
}
case MC_REG_MOTOR_CONFIG:
{
*rawSize = (uint16_t)sizeof(MotorConfig_reg_t);
if (((*rawSize) + 2U) > (uint16_t)freeSpace)
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
else
{
MotorConfig_reg_t const *pMotorConfig_reg = MotorConfig_reg[motorID];
(void)memcpy(rawData, (const uint8_t *)pMotorConfig_reg, sizeof(MotorConfig_reg_t));
}
break;
}
case MC_REG_FOCFW_CONFIG:
{
*rawSize = (uint16_t)sizeof(FOCFwConfig_reg_t);
if (((*rawSize) + 2U) > (uint16_t)freeSpace)
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
else
{
FOCFwConfig_reg_t const *pFOCConfig_reg = FOCConfig_reg[motorID];
(void)memcpy(rawData, (const uint8_t *)pFOCConfig_reg, sizeof(FOCFwConfig_reg_t));
}
break;
}
case MC_REG_SCALE_CONFIG:
{
*rawSize = 12;
if ((*rawSize) +2U > (uint16_t)freeSpace)
{
retVal = MCP_ERROR_NO_TXSYNC_SPACE;
}
else
{
memcpy(rawData, &scaleParams_M1, sizeof(ScaleParams_t) );
}
break;
}
case MC_REG_SPEED_RAMP:
{
int32_t *rpm = (int32_t *)rawData; //cstat !MISRAC2012-Rule-11.3
uint16_t *duration = (uint16_t *)&rawData[4]; //cstat !MISRAC2012-Rule-11.3
*rpm = (((int32_t)MCI_GetLastRampFinalSpeed(pMCIN) * U_RPM) / (int32_t)SPEED_UNIT);
*duration = MCI_GetLastRampFinalDuration(pMCIN);
*rawSize = 6;
break;
}
case MC_REG_TORQUE_RAMP:
{
int16_t *torque = (int16_t *)rawData; //cstat !MISRAC2012-Rule-11.3
uint16_t *duration = (uint16_t *)&rawData[2]; //cstat !MISRAC2012-Rule-11.3
*rawSize = 4;
*torque = MCI_GetLastRampFinalTorque(pMCIN);
*duration = MCI_GetLastRampFinalDuration(pMCIN) ;
break;
}
case MC_REG_CURRENT_REF:
{
uint16_t *iqref = (uint16_t *)rawData; //cstat !MISRAC2012-Rule-11.3
uint16_t *idref = (uint16_t *)&rawData[2]; //cstat !MISRAC2012-Rule-11.3
*rawSize = 4;
*iqref = (uint16_t)MCI_GetIqdref(pMCIN).q;
*idref = (uint16_t)MCI_GetIqdref(pMCIN).d;
break;
}
case MC_REG_ASYNC_UARTA:
case MC_REG_ASYNC_UARTB:
case MC_REG_ASYNC_STLNK:
default:
{
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
/* Size of the answer is size of the data + 2 bytes containing data size */
*size = (*rawSize) + 2U;
break;
}
default:
{
retVal = MCP_ERROR_BAD_DATA_TYPE;
break;
}
}
return (retVal);
}
uint8_t RI_MovString(const char_t *srcString, char_t *destString, uint16_t *size, int16_t maxSize)
{
uint8_t retVal = MCP_CMD_OK;
const char_t *tempsrcString = srcString;
char_t *tempdestString = destString;
*size= 1U ; /* /0 is the min String size */
while ((*tempsrcString != (char_t)0) && (*size < (uint16_t)maxSize))
{
*tempdestString = *tempsrcString;
tempdestString++;
tempsrcString++;
*size = *size + 1U;
}
if (*tempsrcString != (char_t)0)
{ /* Last string char must be 0 */
retVal = MCP_ERROR_STRING_FORMAT;
}
else
{
*tempdestString = (int8_t)0;
}
return (retVal);
}
uint8_t RI_GetIDSize(uint16_t dataID)
{
uint8_t typeID = ((uint8_t)dataID) & TYPE_MASK;
uint8_t result;
switch (typeID)
{
case TYPE_DATA_8BIT:
{
result = 1;
break;
}
case TYPE_DATA_16BIT:
{
result = 2;
break;
}
case TYPE_DATA_32BIT:
{
result = 4;
break;
}
default:
{
result=0;
break;
}
}
return (result);
}
__weak uint8_t RI_GetPtrReg(uint16_t dataID, void **dataPtr)
{
uint8_t retVal = MCP_CMD_OK;
static uint16_t nullData16=0;
#ifdef NULL_PTR_CHECK_REG_INT
if (MC_NULL == dataPtr)
{
retVal = MCP_CMD_NOK;
}
else
{
#endif
MCI_Handle_t *pMCIN = &Mci[0];
uint16_t regID = dataID & REG_MASK;
uint8_t typeID = ((uint8_t)dataID) & TYPE_MASK;
switch (typeID)
{
case TYPE_DATA_16BIT:
{
switch (regID)
{
case MC_REG_I_A:
{
*dataPtr = &(pMCIN->pFOCVars->Iab.a);
break;
}
case MC_REG_I_B:
{
*dataPtr = &(pMCIN->pFOCVars->Iab.b);
break;
}
case MC_REG_I_ALPHA_MEAS:
{
*dataPtr = &(pMCIN->pFOCVars->Ialphabeta.alpha);
break;
}
case MC_REG_I_BETA_MEAS:
{
*dataPtr = &(pMCIN->pFOCVars->Ialphabeta.beta);
break;
}
case MC_REG_I_Q_MEAS:
{
*dataPtr = &(pMCIN->pFOCVars->Iqd.q);
break;
}
case MC_REG_I_D_MEAS:
{
*dataPtr = &(pMCIN->pFOCVars->Iqd.d);
break;
}
case MC_REG_I_Q_REF:
{
*dataPtr = &(pMCIN->pFOCVars->Iqdref.q);
break;
}
case MC_REG_I_D_REF:
{
*dataPtr = &(pMCIN->pFOCVars->Iqdref.d);
break;
}
case MC_REG_V_Q:
{
*dataPtr = &(pMCIN->pFOCVars->Vqd.q);
break;
}
case MC_REG_V_D:
{
*dataPtr = &(pMCIN->pFOCVars->Vqd.d);
break;
}
case MC_REG_V_ALPHA:
{
*dataPtr = &(pMCIN->pFOCVars->Valphabeta.alpha);
break;
}
case MC_REG_V_BETA:
{
*dataPtr = &(pMCIN->pFOCVars->Valphabeta.beta);
break;
}
case MC_REG_ENCODER_SPEED:
{
*dataPtr = &((&ENCODER_M1)->_Super.hAvrMecSpeedUnit);
break;
}
case MC_REG_ENCODER_EL_ANGLE:
{
*dataPtr = &((&ENCODER_M1)->_Super.hElAngle);
break;
}
case MC_REG_STOPLL_ROT_SPEED:
{
*dataPtr = &((&STO_PLL_M1)->_Super.hAvrMecSpeedUnit);
break;
}
case MC_REG_STOPLL_EL_ANGLE:
{
*dataPtr = &((&STO_PLL_M1)->_Super.hElAngle);
break;
}
#ifdef NOT_IMPLEMENTED /* Not yet implemented */
case MC_REG_STOPLL_I_ALPHA:
case MC_REG_STOPLL_I_BETA:
break;
#endif
case MC_REG_STOPLL_BEMF_ALPHA:
{
*dataPtr = &((&STO_PLL_M1)->hBemf_alfa_est);
break;
}
case MC_REG_STOPLL_BEMF_BETA:
{
*dataPtr = &((&STO_PLL_M1)->hBemf_beta_est);
break;
}
default:
{
*dataPtr = &nullData16;
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
break;
}
default:
{
*dataPtr = &nullData16;
retVal = MCP_ERROR_UNKNOWN_REG;
break;
}
}
#ifdef NULL_PTR_CHECK_REG_INT
}
#endif
return (retVal);
}
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 36,418 | C | 23.102581 | 114 | 0.454391 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mc_api.c |
/**
******************************************************************************
* @file mc_api.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file implements the high level interface of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCIAPI
*/
#include "mc_interface.h"
#include "mc_api.h"
#include "mc_config.h"
#include "mcp.h"
/** @addtogroup MCSDK
* @{
*/
/**
* @defgroup CAI Application Programming Interface
* @brief Interface for Motor Control applications using the classic SDK
*
* @{
*/
/** @defgroup MCIAPI Motor Control API
*
* @brief High level Programming Interface of the Motor Control SDK
*
* This interface allows for performing basic operations on the motor(s) driven by an
* Motor Control SDK based application. With it, motors can be started and stopped, speed or
* torque ramps can be programmed and executed and information on the state of the motors can
* be retrieved, among others.
*
* This interface consists in functions that target a specific motor, indicated in their name.
* These functions aims at being the main interface used by an Application to control motors.
*
* The current Motor Control API can cope with up to 2 motors.
* @{
*/
/**
* @brief Initiates the start-up procedure for Motor 1
*
* If the state machine of Motor 1 is in #IDLE state, the command is immediately
* executed. Otherwise the command is discarded. The Application can check the
* return value to know whether the command was executed or discarded.
*
* One of the following commands must be executed before calling MC_StartMotor1()
* in order to set a torque or a speed reference:
*
* - MC_ProgramSpeedRampMotor1()
* - MC_ProgramTorqueRampMotor1()
* - MC_SetCurrentReferenceMotor1()
*
* Failing to do so results in an unpredictable behaviour.
*
* If the offsets of the current measurement circuitry offsets are not known yet,
* an offset calibration procedure is executed to measure them prior to acutally
* starting up the motor.
*
* @note The MCI_StartMotor1 command only triggers the execution of the start-up
* procedure (or eventually the offset calibration procedure) and returns
* immediately after. It is not blocking the execution of the application until
* the motor is indeed running in steady state. If the application needs to wait
* for the motor to be running in steady state, the application has to check the
* state machine of the motor and verify that the #RUN state has been reached.
* Note also that if the startup sequence fails the #RUN state may never be reached.
*
* @retval returns true if the command is successfully executed, false otherwise.
*/
__weak bool MC_StartMotor1(void)
{
return (MCI_StartMotor(pMCI[M1]));
}
/**
* @brief Initiates the stop procedure for Motor 1.
*
* If the state machine is in any state but the #ICLWAIT, #IDLE, FAULT_NOW and
* #FAULT_OVER states, the command is immediately executed. Otherwise, it is
* discarded. The Application can check the return value to know whether the
* command was executed or discarded.
*
* @note The MC_StopMotor1() command only triggers the stop motor procedure
* and then returns. It is not blocking the application until the motor is indeed
* stopped. To know if it has stopped, the application can query the motor's state
* machine and check if the #IDLE state has been reached.
*
* @retval returns true if the command is successfully executed, false otherwise.
*/
__weak bool MC_StopMotor1(void)
{
return (MCI_StopMotor(pMCI[M1]));
}
/**
* @brief Programs a speed ramp for Motor 1 for later or immediate execution.
*
* A speed ramp is a linear change from the current speed reference to the @p hFinalSpeed
* target speed in the given @p hDurationms time.
*
* Invoking the MC_ProgramSpeedRampMotor1() function programs a new speed ramp
* with the provided parameters. The programmed ramp is executed immediately if
* Motor 1's state machine is in the #RUN states. Otherwise, the ramp is buffered
* and will be executed when the state machine reaches any of the aforementioned state.
*
* The Application can check the status of the command with the MC_GetCommandStateMotor1()
* to know whether the last command was executed immediately or not.
*
* Only one command can be buffered at any given time. If another ramp - whether a
* speed or a torque one - or if another buffered command is programmed before the
* current one has completed, the latter replaces the former.
*
* @note A ramp cannot reverse the rotation direction if the Application is using
* sensorless motor control techniques. If the sign of the hFinalSpeed parameter
* differs from that of the current speed, the ramp will not complete and a Speed
* Feedback error (#MC_SPEED_FDBK) will occur when the rotation speed is about to
* reach 0 rpm.
*
* @param hFinalSpeed Mechanical rotor speed reference at the end of the ramp.
* Expressed in the unit defined by #SPEED_UNIT.
* @param hDurationms Duration of the ramp expressed in milliseconds. It
* is possible to set 0 to perform an instantaneous change in the speed
* value.
*/
__weak void MC_ProgramSpeedRampMotor1(int16_t hFinalSpeed, uint16_t hDurationms)
{
MCI_ExecSpeedRamp(pMCI[M1], hFinalSpeed, hDurationms);
}
/**
* @brief Programs a speed ramp for Motor 1 for later or immediate execution.
*
* A speed ramp is a linear change from the current speed reference to the @p FinalSpeed
* target speed in the given @p hDurationms time.
*
* Invoking the MC_ProgramSpeedRampMotor1() function programs a new speed ramp
* with the provided parameters. The programmed ramp is executed immediately if
* Motor 1's state machine is in the #RUN states. Otherwise, the ramp is buffered
* and will be executed when the state machine reaches any of the aforementioned state.
*
* The Application can check the status of the command with the MC_GetCommandStateMotor1()
* to know whether the last command was executed immediately or not.
*
* Only one command can be buffered at any given time. If another ramp - whether a
* speed or a torque one - or if another buffered command is programmed before the
* current one has completed, the latter replaces the former.
*
* @note A ramp cannot reverse the rotation direction if the Application is using
* sensorless motor control techniques. If the sign of the hFinalSpeed parameter
* differs from that of the current speed, the ramp will not complete and a Speed
* Feedback error (#MC_SPEED_FDBK) will occur when the rotation speed is about to
* reach 0 rpm.
*
* @param FinalSpeed Mechanical rotor speed reference at the end of the ramp.
* Expressed in rpm.
* @param hDurationms Duration of the ramp expressed in milliseconds. It
* is possible to set 0 to perform an instantaneous change in the speed
* value.
*/
__weak void MC_ProgramSpeedRampMotor1_F(float_t FinalSpeed, uint16_t hDurationms)
{
MCI_ExecSpeedRamp_F(pMCI[M1], FinalSpeed, hDurationms);
}
/**
* @brief Programs a torque ramp for Motor 1 for later or immediate execution.
*
* A torque ramp is a linear change from the current torque reference to the @p hFinalTorque
* target torque reference in the given @p hDurationms time.
*
* Invoking the MC_ProgramTorqueRampMotor1() function programs a new torque ramp
* with the provided parameters. The programmed ramp is executed immediately if
* Motor 1's state machine is in the #RUN states. Otherwise, the ramp is buffered
* and will be executed when the state machine reaches any of the aforementioned state.
*
* The Application can check the status of the command with the MC_GetCommandStateMotor1()
* to know whether the last command was executed immediately or not.
*
* Only one command can be buffered at any given time. If another ramp - whether a
* torque or a speed one - or if another buffered command is programmed before the
* current one has completed, the latter replaces the former.
*
* @note A ramp cannot reverse the rotation direction if the Application is using
* sensorless motor control techniques. If the sign of the hFinalTorque parameter
* differs from that of the current torque, the ramp will not complete and a Speed
* Feedback error (#MC_SPEED_FDBK) will occur when the rotation speed is about to
* reach 0 rpm.
*
* @param hFinalTorque Mechanical motor torque reference at the end of the ramp.
* This value represents actually the Iq current expressed in digit.
* @param hDurationms Duration of the ramp expressed in milliseconds. It
* is possible to set 0 to perform an instantaneous change in the torque
* value.
*/
__weak void MC_ProgramTorqueRampMotor1(int16_t hFinalTorque, uint16_t hDurationms)
{
MCI_ExecTorqueRamp(pMCI[M1], hFinalTorque, hDurationms);
}
/**
* @brief Programs a torque ramp for Motor 1 for later or immediate execution.
*
* A torque ramp is a linear change from the current torque reference to the @p FinalTorque
* target torque reference in the given @p hDurationms time.
*
* Invoking the MC_ProgramTorqueRampMotor1() function programs a new torque ramp
* with the provided parameters. The programmed ramp is executed immediately if
* Motor 1's state machine is in the #RUN states. Otherwise, the ramp is buffered
* and will be executed when the state machine reaches any of the aforementioned state.
*
* The Application can check the status of the command with the MC_GetCommandStateMotor1()
* to know whether the last command was executed immediately or not.
*
* Only one command can be buffered at any given time. If another ramp - whether a
* torque or a speed one - or if another buffered command is programmed before the
* current one has completed, the latter replaces the former.
*
* @note A ramp cannot reverse the rotation direction if the Application is using
* sensorless motor control techniques. If the sign of the FinalTorque parameter
* differs from that of the current torque, the ramp will not complete and a Speed
* Feedback error (#MC_SPEED_FDBK) will occur when the rotation speed is about to
* reach 0 rpm.
*
* @param FinalTorque Mechanical motor torque reference at the end of the ramp.
* This value represents actually the Iq current expressed in Ampere.
* @param hDurationms Duration of the ramp expressed in milliseconds. It
* is possible to set 0 to perform an instantaneous change in the torque
* value.
*/
__weak void MC_ProgramTorqueRampMotor1_F(float_t FinalTorque, uint16_t hDurationms)
{
MCI_ExecTorqueRamp_F(pMCI[M1], FinalTorque, hDurationms);
}
/**
* @brief Programs the current reference to Motor 1 for later or immediate execution.
*
* The current reference to consider is made of the $I_d$ and $I_q$ current components.
*
* Invoking the MC_SetCurrentReferenceMotor1() function programs a current reference
* with the provided parameters. The programmed reference is executed immediately if
* Motor 1's state machine is in the #RUN states. Otherwise, the command is buffered
* and will be executed when the state machine reaches any of the aforementioned state.
*
* The Application can check the status of the command with the MC_GetCommandStateMotor1()
* to know whether the last command was executed immediately or not.
*
* Only one command can be buffered at any given time. If another buffered command is
* programmed before the current one has completed, the latter replaces the former.
*
* @param Iqdref current reference in the Direct-Quadratic reference frame. Expressed
* in the qd_t format.
*/
__weak void MC_SetCurrentReferenceMotor1(qd_t Iqdref)
{
MCI_SetCurrentReferences(pMCI[M1], Iqdref);
}
/**
* @brief Programs the current reference to Motor 1 for later or immediate execution.
*
* The current reference to consider is made of the $I_d$ and $I_q$ current components.
*
* Invoking the MC_SetCurrentReferenceMotor1_F() function programs a current reference
* with the provided parameters. The programmed reference is executed immediately if
* Motor 1's state machine is in the #RUN states. Otherwise, the command is buffered
* and will be executed when the state machine reaches any of the aforementioned state.
*
* The Application can check the status of the command with the MC_GetCommandStateMotor1()
* to know whether the last command was executed immediately or not.
*
* Only one command can be buffered at any given time. If another buffered command is
* programmed before the current one has completed, the latter replaces the former.
*
* @param IqdRef current reference in the Direct-Quadratic reference frame. Expressed
* in the qd_f_t format.
*/
__weak void MC_SetCurrentReferenceMotor1_F(qd_f_t IqdRef)
{
MCI_SetCurrentReferences_F(pMCI[M1], IqdRef);
}
/**
* @brief Returns the status of the last buffered command for Motor 1.
*
* The status can be one of the following values:
* - #MCI_BUFFER_EMPTY: no buffered command is currently programmed.
* - #MCI_COMMAND_NOT_ALREADY_EXECUTED: A command has been buffered but the conditions for its
* execution have not occurred yet. The command is still in the buffer, pending execution.
* - #MCI_COMMAND_EXECUTED_SUCCESSFULLY: the last buffered command has been executed successfully.
* In this case calling this function resets the command state to #MCI_BUFFER_EMPTY.
* - #MCI_COMMAND_EXECUTED_UNSUCCESSFULLY: the buffered command has been executed unsuccessfully.
* In this case calling this function resets the command state to #MCI_BUFFER_EMPTY.
*/
__weak MCI_CommandState_t MC_GetCommandStateMotor1(void)
{
return (MCI_IsCommandAcknowledged(pMCI[M1]));
}
/**
* @brief Stops the execution of the on-going speed ramp for Motor 1, if any.
*
* If a speed ramp is currently being executed, it is immediately stopped, the rotation
* speed of Motor 1 is maintained to its current value and true is returned. If no speed
* ramp is on-going, nothing is done and false is returned.
*
* @deprecated This function is deprecated and should not be used anymore. It will be
* removed in a future version of the MCSDK. Use MC_StopRampMotor1() instead.
*/
__weak bool MC_StopSpeedRampMotor1(void)
{
return (MCI_StopSpeedRamp(pMCI[M1]));
}
/**
* @brief Stops the execution of the on-going ramp for Motor 1, if any.
*
* If a ramp is currently being executed, it is immediately stopped, the torque or the speed
* of Motor 1 is maintained to its current value.
*/
__weak void MC_StopRampMotor1(void)
{
MCI_StopRamp(pMCI[M1]);
}
/**
* @brief Returns true if the last ramp submited for Motor 1 has completed, false otherwise
*/
__weak bool MC_HasRampCompletedMotor1(void)
{
return (MCI_RampCompleted(pMCI[M1]));
}
/**
* @brief Returns the current mechanical rotor speed reference set for Motor 1, expressed in the unit defined by #SPEED_UNIT
*/
__weak int16_t MC_GetMecSpeedReferenceMotor1(void)
{
return (MCI_GetMecSpeedRefUnit(pMCI[M1]));
}
/**
* @brief Returns the current mechanical rotor speed reference set for Motor 1, expressed in rpm.
*/
__weak float_t MC_GetMecSpeedReferenceMotor1_F(void)
{
return (MCI_GetMecSpeedRef_F(pMCI[M1]));
}
/**
* @brief Returns the last computed average mechanical rotor speed for Motor 1, expressed in the unit defined by #SPEED_UNIT
*/
__weak int16_t MC_GetMecSpeedAverageMotor1(void)
{
return (MCI_GetAvrgMecSpeedUnit(pMCI[M1]));
}
#define S16ToRAD 10430.37835f /* 2^16/2Pi */
/**
* @brief Returns the last computed average mechanical rotor speed from auxiliary sensor for Motor 1, expressed in the unit defined by #SPEED_UNIT
*/
__weak int16_t MC_GetMecAuxiliarySpeedAverageM1(void)
{
return (SPD_GetAvrgMecSpeedUnit(&STO_PLL_M1._Super));
}
/**
* @brief Returns the last computed average mechanical rotor speed from auxiliary sensor for Motor 1, expressed in RPM
*/
__weak float_t MC_GetMecAuxiliarySpeedAvgM1_F(void)
{
int16_t returnValue;
returnValue = (SPD_GetAvrgMecSpeedUnit(&STO_PLL_M1._Super) * U_RPM) / SPEED_UNIT;
return ((float_t)returnValue);
}
/**
* @brief Returns the electrical angle of the rotor from auxiliary sensor of Motor 1, in DDP format
*/
__weak int16_t MC_GetAuxiliaryElAngledppMotor1(void)
{
return (SPD_GetElAngle(&STO_PLL_M1._Super));
}
/**
* @brief Returns the electrical angle of the rotor from auxiliary sensor of Motor 1, expressed in radians
*/
__weak float_t MC_GetAuxiliaryElAngleMotor1_F(void)
{
return (((float_t)SPD_GetElAngle(&STO_PLL_M1._Super)) / S16ToRAD);
}
/**
* @brief Returns the last computed average mechanical rotor speed for Motor 1, expressed in rpm.
*/
__weak float_t MC_GetAverageMecSpeedMotor1_F(void)
{
return (MCI_GetAvrgMecSpeed_F(pMCI[M1]));
}
/**
* @brief Returns the final speed of the last ramp programmed for Motor 1 if this ramp was a speed ramp, 0 otherwise.
*/
__weak int16_t MC_GetLastRampFinalSpeedMotor1(void)
{
return (MCI_GetLastRampFinalSpeed(pMCI[M1]));
}
/**
* @brief Returns the final speed of the last ramp programmed for Motor 1 if this ramp was a speed ramp, 0 otherwise.
*/
__weak float_t MC_GetLastRampFinalSpeedM1_F(void)
{
return (MCI_GetLastRampFinalSpeed_F(pMCI[M1]));
}
/**
* @brief Returns the Control Mode used for Motor 1 (either Speed or Torque)
*/
__weak MC_ControlMode_t MC_GetControlModeMotor1(void)
{
return (MCI_GetControlMode(pMCI[M1]));
}
/**
* @brief Returns the rotation direction imposed by the last command on Motor 1
*
* The last command is either MC_ProgramSpeedRampMotor1(), MC_ProgramTorqueRampMotor1() or
* MC_SetCurrentReferenceMotor1().
*
* The function returns -1 if the sign of the final speed, the final torque or the Iq current
* reference component of the last command is negative. Otherwise, 1 is returned.
*
* @note if no such command has ever been submitted, 1 is returned as well.
*/
__weak int16_t MC_GetImposedDirectionMotor1(void)
{
return (MCI_GetImposedMotorDirection(pMCI[M1]));
}
/**
* @brief Returns true if the speed sensor used for Motor 1 is reliable, false otherwise
*/
__weak bool MC_GetSpeedSensorReliabilityMotor1(void)
{
return (MCI_GetSpdSensorReliability(pMCI[M1]));
}
/**
* @brief returns the amplitude of the phase current injected in Motor 1
*
* The returned amplitude (0-to-peak) is expressed in s16A unit. To convert it to amperes, use the following formula:
*
* @f[
* I_{Amps} = \frac{ I_{s16A} \times V_{dd}}{ 65536 \times R_{shunt} \times A_{op} }
* @f]
*
*/
__weak int16_t MC_GetPhaseCurrentAmplitudeMotor1(void)
{
return (MCI_GetPhaseCurrentAmplitude(pMCI[M1]));
}
/**
* @brief returns the amplitude of the phase voltage applied to Motor 1
*
* The returned amplitude (0-to-peak) is expressed in s16V unit. To convert it to volts, use the following formula:
*
* @f[
* U_{Volts} = \frac{ U_{s16V} \times V_{bus}}{ \sqrt{3} \times 32768 }
* @f]
*
*/
__weak int16_t MC_GetPhaseVoltageAmplitudeMotor1(void)
{
return (MCI_GetPhaseVoltageAmplitude(pMCI[M1]));
}
/**
* @brief returns Ia and Ib current values for Motor 1 in ab_t format
*/
__weak ab_t MC_GetIabMotor1(void)
{
return (MCI_GetIab(pMCI[M1]));
}
/**
* @brief returns Ia and Ib current values for Motor 1 in ab_f_t format
*/
__weak ab_f_t MC_GetIabMotor1_F(void)
{
return (MCI_GetIab_F(pMCI[M1]));
}
/**
* @brief returns Ialpha and Ibeta current values for Motor 1 in alphabeta_t format
*/
__weak alphabeta_t MC_GetIalphabetaMotor1(void)
{
return (MCI_GetIalphabeta(pMCI[M1]));
}
/**
* @brief returns Iq and Id current values for Motor 1 in qd_t format
*/
__weak qd_t MC_GetIqdMotor1(void)
{
return (MCI_GetIqd(pMCI[M1]));
}
/**
* @brief returns Iq and Id current values for Motor 1 in float_t type
*/
__weak qd_f_t MC_GetIqdMotor1_F(void)
{
return (MCI_GetIqd_F(pMCI[M1]));
}
/**
* @brief returns Iq and Id reference current values for Motor 1 in qd_t format
*/
__weak qd_t MC_GetIqdrefMotor1(void)
{
return (MCI_GetIqdref(pMCI[M1]));
}
/**
* @brief returns Iq and Id reference current values for Motor 1 in float_t type
*/
__weak qd_f_t MC_GetIqdrefMotor1_F(void)
{
return (MCI_GetIqdref_F(pMCI[M1]));
}
/**
* @brief returns Vq and Vd voltage values for Motor 1 in qd_t format
*/
__weak qd_t MC_GetVqdMotor1(void)
{
return (MCI_GetVqd(pMCI[M1]));
}
/**
* @brief returns Valpha and Vbeta voltage values for Motor 1 in alphabeta_t format
*/
__weak alphabeta_t MC_GetValphabetaMotor1(void)
{
return (MCI_GetValphabeta(pMCI[M1]));
}
/**
* @brief returns the electrical angle of the rotor of Motor 1, in DDP format
*/
__weak int16_t MC_GetElAngledppMotor1(void)
{
return (MCI_GetElAngledpp(pMCI[M1]));
}
/**
* @brief returns the electrical torque reference for Motor 1
*/
__weak int16_t MC_GetTerefMotor1(void)
{
return (MCI_GetTeref(pMCI[M1]));
}
/**
* @brief returns the electrical torque reference for Motor 1
*/
__weak float_t MC_GetTerefMotor1_F(void)
{
return (MCI_GetTeref_F(pMCI[M1]));
}
/**
* @brief re-initializes Iq and Id references to their default values for Motor 1
*
* The default values for the Iq and Id references are coming from the Speed
* or the Torque controller depending on the control mode.
*
* @see SpeednTorqCtrl for more details.
*/
__weak void MC_Clear_IqdrefMotor1(void)
{
MCI_Clear_Iqdref(pMCI[M1]);
}
/**
* @brief Acknowledge a Motor Control fault that occured on Motor 1
*
* This function informs Motor 1's state machine that the Application has taken
* the error condition that occured into account. If no error condition exists when
* the function is called, nothing is done and false is returned. Otherwise, true is
* returned.
*/
__weak bool MC_AcknowledgeFaultMotor1(void)
{
return (MCI_FaultAcknowledged(pMCI[M1]));
}
/**
* @brief Returns a bit-field showing non acknowledged faults that occurred on Motor 1.
*
* This function returns a 16 bit fields containing the Motor Control faults
* that have occurred on Motor 1 since its state machine moved to the #FAULT_NOW state.
*
* See @ref fault_codes "Motor Control Faults" for a list of
* of all possible faults codes.
*/
__weak uint16_t MC_GetOccurredFaultsMotor1(void)
{
return (MCI_GetOccurredFaults(pMCI[M1]));
}
/**
* @brief returns a bitfield showing all current faults on Motor 1
*
* This function returns a 16 bit fields containing the Motor Control faults
* that are currently active.
*
* See @ref fault_codes "Motor Control Faults" for a list of
* of all possible faults codes.
*/
__weak uint16_t MC_GetCurrentFaultsMotor1(void)
{
return (MCI_GetCurrentFaults(pMCI[M1]));
}
/**
* @brief returns the current state of Motor 1 state machine
*/
__weak MCI_State_t MC_GetSTMStateMotor1(void)
{
return (MCI_GetSTMState(pMCI[M1]));
}
/**
* @brief Sets the polarization offset values to use for Motor 1
*
* The Motor Control algorithm relies on a number of current and voltage measures. The hardware
* parts that make these measurements need to be characterized at least once in the course of
* product life, prior to its first activation. This characterization consists in measuring the
* voltage presented to the ADC channels when either no current flows into the phases of the motor
* or no voltage is applied to them. This characterization is named polarization offsets measurement
* and its results are the polarization offsets.
*
* The Motor Control Firmware can performs this polarization offsets measurement procedure which
* results in a number of offset values that the application can store in a non volatile memory and
* then set into the Motor Control subsystem at power-on or after a reset.
*
* The application uses this function to set the polarization offset values that the Motor Control
* subsystem is to use in the current session. This function can only be used when the state machine
* of the motor is in the #IDLE state in which case it returns #MC_SUCCESS. Otherwise, it does nothing
* and returns the #MC_WRONG_STATE_ERROR error code.
*
* The Motor Control subsystem needs to know the polarization offsets before the motor can be controlled.
* The MC_SetPolarizationOffsetsMotor1() function provides a way to set these offsets. Alternatively, the
* application can either:
*
* * Execute the polarization offsets measurement procedure with a call to
* MC_StartPolarizationOffsetsMeasurementMotor1() after a reset or a power on;
* * Start the motor control with the MC_StartWithPolarizationMotor1() that will execute the procedure
* before actually starting the motor, on the first time it is called after a reset or a power on.
*
* When this function completes successfully, the state of the polarization offsets measurement procedure
* is set to #COMPLETED. See MC_GetPolarizationState().
*
* @param PolarizationOffsets an pointer on a structure containing the offset values
*/
bool MC_SetPolarizationOffsetsMotor1(PolarizationOffsets_t * PolarizationOffsets)
{
return (MCI_SetCalibratedOffsetsMotor(pMCI[M1], PolarizationOffsets));
}
/**
* @brief Returns the polarization offset values measured or set for Motor 1
*
* See MC_SetPolarizationOffsetsMotor1() for more details.
*
* If the Motor Control Firmware knows the polarization offset values, they are copied into the
* @p PolarizationOffsets structure and #MC_SUCCESS is returned. Otherwise, nothing is done and
* #MC_NO_POLARIZATION_OFFSETS_ERROR is returned.
*
* @param PolarizationOffsets an pointer on the structure into which the polarization offsets will be
* copied
* @return #MC_SUCCESS if calibration data were present and could be copied into @p PolarizationOffsets,
* #MC_NO_POLARIZATION_OFFSETS_ERROR otherwise.
*/
bool MC_GetPolarizationOffsetsMotor1(PolarizationOffsets_t * PolarizationOffsets)
{
return (MCI_GetCalibratedOffsetsMotor(pMCI[M1], PolarizationOffsets));
}
/**
* @brief Starts the polarization offsets measurement procedure.
*
* See MC_SetPolarizationOffsetsMotor1() for more details.
*
* If the Motor Control Firmware is in the #IDLE state, the procedure is started, the state machine
* of the motor switches to #OFFSET_CALIB and #MC_SUCCESS is returned. Otherwise, nothing is done
* and the #MC_WRONG_STATE_ERROR error code is returned.
*
* The polarization offsets measurement procedure is only triggered by this function and it is has not
* completed when this function returns. The application can use the MC_GetPolarizationState()
* function to query the state of the procedure.
*
* @see MC_GetPolarizationState()
*/
bool MC_StartPolarizationOffsetsMeasurementMotor1(void)
{
return (MCI_StartOffsetMeasurments(pMCI[M1]));
}
/**
* @brief This method is used to get the average measured motor power
* expressed in watt for Motor 1.
* @retval float_t The average measured motor power expressed in watt.
*/
__weak float_t MC_GetAveragePowerMotor1_F(void)
{
return (PQD_GetAvrgElMotorPowerW(pMPM[M1]));
}
/**
* @brief Not implemented MC_Profiler function.
* */ //cstat !MISRAC2012-Rule-2.7 !RED-unused-param !MISRAC2012-Rule-2.7 !MISRAC2012-Rule-8.13
__weak uint8_t MC_ProfilerCommand(uint16_t rxLength, uint8_t *rxBuffer, int16_t txSyncFreeSpace, uint16_t *txLength, uint8_t *txBuffer)
{
return (MCP_CMD_UNKNOWN);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 28,263 | C | 36.091863 | 146 | 0.722606 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mcp_config.c | /**
******************************************************************************
* @file mcp_config.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides configuration information of the MCP protocol
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#include "parameters_conversion.h"
#include "usart_aspep_driver.h"
#include "aspep.h"
#include "mcp.h"
#include "mcpa.h"
#include "mcp_config.h"
static uint8_t MCPSyncTxBuff[MCP_TX_SYNCBUFFER_SIZE] __attribute__((aligned(4))); //cstat !MISRAC2012-Rule-1.4_a
static uint8_t MCPSyncRXBuff[MCP_RX_SYNCBUFFER_SIZE] __attribute__((aligned(4))); //cstat !MISRAC2012-Rule-1.4_a
/* Asynchronous buffer dedicated to UART_A */
static uint8_t MCPAsyncBuffUARTA_A[MCP_TX_ASYNCBUFFER_SIZE_A] __attribute__((aligned(4))); //cstat !MISRAC2012-Rule-1.4_a
static uint8_t MCPAsyncBuffUARTA_B[MCP_TX_ASYNCBUFFER_SIZE_A] __attribute__((aligned(4))); //cstat !MISRAC2012-Rule-1.4_a
/* Buffer dedicated to store pointer of data to be streamed over UART_A */
static void *dataPtrTableA[MCPA_OVER_UARTA_STREAM];
static void *dataPtrTableBuffA[MCPA_OVER_UARTA_STREAM];
static uint8_t dataSizeTableA[MCPA_OVER_UARTA_STREAM];
static uint8_t dataSizeTableBuffA[MCPA_OVER_UARTA_STREAM]; /* buffered version of dataSizeTableA */
MCP_user_cb_t MCP_UserCallBack[MCP_USER_CALLBACK_MAX];
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MCP
* @{
*/
static UASPEP_Handle_t UASPEP_A =
{
.USARTx = USARTA,
.rxDMA = DMA_RX_A,
.txDMA = DMA_TX_A,
.rxChannel = DMACH_RX_A,
.txChannel = DMACH_TX_A,
};
ASPEP_Handle_t aspepOverUartA =
{
._Super =
{
.fGetBuffer = &ASPEP_getBuffer,
.fSendPacket = &ASPEP_sendPacket,
.fRXPacketProcess = &ASPEP_RXframeProcess,
},
.HWIp = &UASPEP_A,
.Capabilities =
{
.DATA_CRC = 0U,
.RX_maxSize = (MCP_RX_SYNC_PAYLOAD_MAX >> 5U) - 1U,
.TXS_maxSize = (MCP_TX_SYNC_PAYLOAD_MAX >> 5U) - 1U,
.TXA_maxSize = (MCP_TX_ASYNC_PAYLOAD_MAX_A >> 6U),
.version = 0x0U,
},
.syncBuffer =
{
.buffer = MCPSyncTxBuff,
},
.asyncBufferA =
{
.buffer = MCPAsyncBuffUARTA_A,
},
.asyncBufferB =
{
.buffer = MCPAsyncBuffUARTA_B,
},
.rxBuffer = MCPSyncRXBuff,
.fASPEP_HWInit = &UASPEP_INIT,
.fASPEP_HWSync = &UASPEP_IDLE_ENABLE,
.fASPEP_receive = &UASPEP_RECEIVE_BUFFER,
.fASPEP_send = &UASPEP_SEND_PACKET,
.liid = 0,
};
MCP_Handle_t MCP_Over_UartA =
{
.pTransportLayer = (MCTL_Handle_t *)&aspepOverUartA, //cstat !MISRAC2012-Rule-11.3
};
MCPA_Handle_t MCPA_UART_A =
{
.pTransportLayer = (MCTL_Handle_t *) &aspepOverUartA, //cstat !MISRAC2012-Rule-11.3
.dataPtrTable = dataPtrTableA,
.dataPtrTableBuff = dataPtrTableBuffA,
.dataSizeTable = dataSizeTableA,
.dataSizeTableBuff = dataSizeTableBuffA,
.nbrOfDataLog = MCPA_OVER_UARTA_STREAM,
};
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 3,465 | C | 27.409836 | 121 | 0.618182 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/network.c | /**
******************************************************************************
* @file network.c
* @author AST Embedded Analytics Research Platform
* @date Tue Jan 16 16:02:48 2024
* @brief AI Tool Automatic Code Generator for Embedded NN computing
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
******************************************************************************
*/
#include "network.h"
#include "network_data.h"
#include "ai_platform.h"
#include "ai_platform_interface.h"
#include "ai_math_helpers.h"
#include "core_common.h"
#include "core_convert.h"
#include "layers.h"
#undef AI_NET_OBJ_INSTANCE
#define AI_NET_OBJ_INSTANCE g_network
#undef AI_NETWORK_MODEL_SIGNATURE
#define AI_NETWORK_MODEL_SIGNATURE "be6727b6cb0b80bc5853d0f719fdd0a1"
#ifndef AI_TOOLS_REVISION_ID
#define AI_TOOLS_REVISION_ID ""
#endif
#undef AI_TOOLS_DATE_TIME
#define AI_TOOLS_DATE_TIME "Tue Jan 16 16:02:48 2024"
#undef AI_TOOLS_COMPILE_TIME
#define AI_TOOLS_COMPILE_TIME __DATE__ " " __TIME__
#undef AI_NETWORK_N_BATCHES
#define AI_NETWORK_N_BATCHES (1)
static ai_ptr g_network_activations_map[1] = AI_C_ARRAY_INIT;
static ai_ptr g_network_weights_map[1] = AI_C_ARRAY_INIT;
/** Array declarations section **********************************************/
/* Array#0 */
AI_ARRAY_OBJ_DECLARE(
obs_output_array, AI_ARRAY_FORMAT_FLOAT|AI_FMT_FLAG_IS_IO,
NULL, NULL, 3, AI_STATIC)
/* Array#1 */
AI_ARRAY_OBJ_DECLARE(
_model_running_mean_std_Sub_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 3, AI_STATIC)
/* Array#2 */
AI_ARRAY_OBJ_DECLARE(
_model_running_mean_std_Div_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 3, AI_STATIC)
/* Array#3 */
AI_ARRAY_OBJ_DECLARE(
_model_running_mean_std_Clip_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 3, AI_STATIC)
/* Array#4 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_0_Gemm_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 128, AI_STATIC)
/* Array#5 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_0_Elu_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 128, AI_STATIC)
/* Array#6 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_Concat_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 131, AI_STATIC)
/* Array#7 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_1_Gemm_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 64, AI_STATIC)
/* Array#8 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_1_Elu_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 64, AI_STATIC)
/* Array#9 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_Concat_1_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 67, AI_STATIC)
/* Array#10 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_2_Gemm_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 32, AI_STATIC)
/* Array#11 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_2_Elu_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 32, AI_STATIC)
/* Array#12 */
AI_ARRAY_OBJ_DECLARE(
value_output_array, AI_ARRAY_FORMAT_FLOAT|AI_FMT_FLAG_IS_IO,
NULL, NULL, 1, AI_STATIC)
/* Array#13 */
AI_ARRAY_OBJ_DECLARE(
mu_output_array, AI_ARRAY_FORMAT_FLOAT|AI_FMT_FLAG_IS_IO,
NULL, NULL, 1, AI_STATIC)
/* Array#14 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_Mul_output_0_output_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 1, AI_STATIC)
/* Array#15 */
AI_ARRAY_OBJ_DECLARE(
log_std_output_array, AI_ARRAY_FORMAT_FLOAT|AI_FMT_FLAG_IS_IO,
NULL, NULL, 1, AI_STATIC)
/* Array#16 */
AI_ARRAY_OBJ_DECLARE(
model__model_a2c_network_sigma_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 1, AI_STATIC)
/* Array#17 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_Constant_output_0_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 1, AI_STATIC)
/* Array#18 */
AI_ARRAY_OBJ_DECLARE(
onnxDiv_43_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 3, AI_STATIC)
/* Array#19 */
AI_ARRAY_OBJ_DECLARE(
onnxSub_40_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 3, AI_STATIC)
/* Array#20 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_0_Gemm_output_0_weights_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 384, AI_STATIC)
/* Array#21 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_0_Gemm_output_0_bias_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 128, AI_STATIC)
/* Array#22 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_1_Gemm_output_0_weights_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 8384, AI_STATIC)
/* Array#23 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_1_Gemm_output_0_bias_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 64, AI_STATIC)
/* Array#24 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_2_Gemm_output_0_weights_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 2144, AI_STATIC)
/* Array#25 */
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_2_Gemm_output_0_bias_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 32, AI_STATIC)
/* Array#26 */
AI_ARRAY_OBJ_DECLARE(
value_weights_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 32, AI_STATIC)
/* Array#27 */
AI_ARRAY_OBJ_DECLARE(
value_bias_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 1, AI_STATIC)
/* Array#28 */
AI_ARRAY_OBJ_DECLARE(
mu_weights_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 32, AI_STATIC)
/* Array#29 */
AI_ARRAY_OBJ_DECLARE(
mu_bias_array, AI_ARRAY_FORMAT_FLOAT,
NULL, NULL, 1, AI_STATIC)
/** Tensor declarations section *********************************************/
/* Tensor #0 */
AI_TENSOR_OBJ_DECLARE(
obs_output, AI_STATIC,
0, 0x0,
AI_SHAPE_INIT(4, 1, 3, 1, 1), AI_STRIDE_INIT(4, 4, 4, 12, 12),
1, &obs_output_array, NULL)
/* Tensor #1 */
AI_TENSOR_OBJ_DECLARE(
_model_running_mean_std_Sub_output_0_output, AI_STATIC,
1, 0x0,
AI_SHAPE_INIT(4, 1, 3, 1, 1), AI_STRIDE_INIT(4, 4, 4, 12, 12),
1, &_model_running_mean_std_Sub_output_0_output_array, NULL)
/* Tensor #2 */
AI_TENSOR_OBJ_DECLARE(
_model_running_mean_std_Div_output_0_output, AI_STATIC,
2, 0x0,
AI_SHAPE_INIT(4, 1, 3, 1, 1), AI_STRIDE_INIT(4, 4, 4, 12, 12),
1, &_model_running_mean_std_Div_output_0_output_array, NULL)
/* Tensor #3 */
AI_TENSOR_OBJ_DECLARE(
_model_running_mean_std_Clip_output_0_output, AI_STATIC,
3, 0x0,
AI_SHAPE_INIT(4, 1, 3, 1, 1), AI_STRIDE_INIT(4, 4, 4, 12, 12),
1, &_model_running_mean_std_Clip_output_0_output_array, NULL)
/* Tensor #4 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_0_Gemm_output_0_output, AI_STATIC,
4, 0x0,
AI_SHAPE_INIT(4, 1, 128, 1, 1), AI_STRIDE_INIT(4, 4, 4, 512, 512),
1, &_model_a2c_network_actor_mlp_0_Gemm_output_0_output_array, NULL)
/* Tensor #5 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_0_Elu_output_0_output, AI_STATIC,
5, 0x0,
AI_SHAPE_INIT(4, 1, 128, 1, 1), AI_STRIDE_INIT(4, 4, 4, 512, 512),
1, &_model_a2c_network_actor_mlp_activations_0_Elu_output_0_output_array, NULL)
/* Tensor #6 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_Concat_output_0_output, AI_STATIC,
6, 0x0,
AI_SHAPE_INIT(4, 1, 131, 1, 1), AI_STRIDE_INIT(4, 4, 4, 524, 524),
1, &_model_a2c_network_actor_mlp_Concat_output_0_output_array, NULL)
/* Tensor #7 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_1_Gemm_output_0_output, AI_STATIC,
7, 0x0,
AI_SHAPE_INIT(4, 1, 64, 1, 1), AI_STRIDE_INIT(4, 4, 4, 256, 256),
1, &_model_a2c_network_actor_mlp_1_Gemm_output_0_output_array, NULL)
/* Tensor #8 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_1_Elu_output_0_output, AI_STATIC,
8, 0x0,
AI_SHAPE_INIT(4, 1, 64, 1, 1), AI_STRIDE_INIT(4, 4, 4, 256, 256),
1, &_model_a2c_network_actor_mlp_activations_1_Elu_output_0_output_array, NULL)
/* Tensor #9 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_Concat_1_output_0_output, AI_STATIC,
9, 0x0,
AI_SHAPE_INIT(4, 1, 67, 1, 1), AI_STRIDE_INIT(4, 4, 4, 268, 268),
1, &_model_a2c_network_actor_mlp_Concat_1_output_0_output_array, NULL)
/* Tensor #10 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_2_Gemm_output_0_output, AI_STATIC,
10, 0x0,
AI_SHAPE_INIT(4, 1, 32, 1, 1), AI_STRIDE_INIT(4, 4, 4, 128, 128),
1, &_model_a2c_network_actor_mlp_2_Gemm_output_0_output_array, NULL)
/* Tensor #11 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_2_Elu_output_0_output, AI_STATIC,
11, 0x0,
AI_SHAPE_INIT(4, 1, 32, 1, 1), AI_STRIDE_INIT(4, 4, 4, 128, 128),
1, &_model_a2c_network_actor_mlp_activations_2_Elu_output_0_output_array, NULL)
/* Tensor #12 */
AI_TENSOR_OBJ_DECLARE(
value_output, AI_STATIC,
12, 0x0,
AI_SHAPE_INIT(4, 1, 1, 1, 1), AI_STRIDE_INIT(4, 4, 4, 4, 4),
1, &value_output_array, NULL)
/* Tensor #13 */
AI_TENSOR_OBJ_DECLARE(
mu_output, AI_STATIC,
13, 0x0,
AI_SHAPE_INIT(4, 1, 1, 1, 1), AI_STRIDE_INIT(4, 4, 4, 4, 4),
1, &mu_output_array, NULL)
/* Tensor #14 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_Mul_output_0_output, AI_STATIC,
14, 0x0,
AI_SHAPE_INIT(4, 1, 1, 1, 1), AI_STRIDE_INIT(4, 4, 4, 4, 4),
1, &_model_a2c_network_Mul_output_0_output_array, NULL)
/* Tensor #15 */
AI_TENSOR_OBJ_DECLARE(
log_std_output, AI_STATIC,
15, 0x0,
AI_SHAPE_INIT(4, 1, 1, 1, 1), AI_STRIDE_INIT(4, 4, 4, 4, 4),
1, &log_std_output_array, NULL)
/* Tensor #16 */
AI_TENSOR_OBJ_DECLARE(
model__model_a2c_network_sigma, AI_STATIC,
16, 0x0,
AI_SHAPE_INIT(4, 1, 1, 1, 1), AI_STRIDE_INIT(4, 4, 4, 4, 4),
1, &model__model_a2c_network_sigma_array, NULL)
/* Tensor #17 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_Constant_output_0, AI_STATIC,
17, 0x0,
AI_SHAPE_INIT(4, 1, 1, 1, 1), AI_STRIDE_INIT(4, 4, 4, 4, 4),
1, &_model_a2c_network_Constant_output_0_array, NULL)
/* Tensor #18 */
AI_TENSOR_OBJ_DECLARE(
onnxDiv_43, AI_STATIC,
18, 0x0,
AI_SHAPE_INIT(4, 1, 3, 1, 1), AI_STRIDE_INIT(4, 4, 4, 12, 12),
1, &onnxDiv_43_array, NULL)
/* Tensor #19 */
AI_TENSOR_OBJ_DECLARE(
onnxSub_40, AI_STATIC,
19, 0x0,
AI_SHAPE_INIT(4, 1, 3, 1, 1), AI_STRIDE_INIT(4, 4, 4, 12, 12),
1, &onnxSub_40_array, NULL)
/* Tensor #20 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_0_Gemm_output_0_weights, AI_STATIC,
20, 0x0,
AI_SHAPE_INIT(4, 3, 128, 1, 1), AI_STRIDE_INIT(4, 4, 12, 1536, 1536),
1, &_model_a2c_network_actor_mlp_0_Gemm_output_0_weights_array, NULL)
/* Tensor #21 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_0_Gemm_output_0_bias, AI_STATIC,
21, 0x0,
AI_SHAPE_INIT(4, 1, 128, 1, 1), AI_STRIDE_INIT(4, 4, 4, 512, 512),
1, &_model_a2c_network_actor_mlp_0_Gemm_output_0_bias_array, NULL)
/* Tensor #22 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_1_Gemm_output_0_weights, AI_STATIC,
22, 0x0,
AI_SHAPE_INIT(4, 131, 64, 1, 1), AI_STRIDE_INIT(4, 4, 524, 33536, 33536),
1, &_model_a2c_network_actor_mlp_1_Gemm_output_0_weights_array, NULL)
/* Tensor #23 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_1_Gemm_output_0_bias, AI_STATIC,
23, 0x0,
AI_SHAPE_INIT(4, 1, 64, 1, 1), AI_STRIDE_INIT(4, 4, 4, 256, 256),
1, &_model_a2c_network_actor_mlp_1_Gemm_output_0_bias_array, NULL)
/* Tensor #24 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_2_Gemm_output_0_weights, AI_STATIC,
24, 0x0,
AI_SHAPE_INIT(4, 67, 32, 1, 1), AI_STRIDE_INIT(4, 4, 268, 8576, 8576),
1, &_model_a2c_network_actor_mlp_2_Gemm_output_0_weights_array, NULL)
/* Tensor #25 */
AI_TENSOR_OBJ_DECLARE(
_model_a2c_network_actor_mlp_2_Gemm_output_0_bias, AI_STATIC,
25, 0x0,
AI_SHAPE_INIT(4, 1, 32, 1, 1), AI_STRIDE_INIT(4, 4, 4, 128, 128),
1, &_model_a2c_network_actor_mlp_2_Gemm_output_0_bias_array, NULL)
/* Tensor #26 */
AI_TENSOR_OBJ_DECLARE(
value_weights, AI_STATIC,
26, 0x0,
AI_SHAPE_INIT(4, 32, 1, 1, 1), AI_STRIDE_INIT(4, 4, 128, 128, 128),
1, &value_weights_array, NULL)
/* Tensor #27 */
AI_TENSOR_OBJ_DECLARE(
value_bias, AI_STATIC,
27, 0x0,
AI_SHAPE_INIT(4, 1, 1, 1, 1), AI_STRIDE_INIT(4, 4, 4, 4, 4),
1, &value_bias_array, NULL)
/* Tensor #28 */
AI_TENSOR_OBJ_DECLARE(
mu_weights, AI_STATIC,
28, 0x0,
AI_SHAPE_INIT(4, 32, 1, 1, 1), AI_STRIDE_INIT(4, 4, 128, 128, 128),
1, &mu_weights_array, NULL)
/* Tensor #29 */
AI_TENSOR_OBJ_DECLARE(
mu_bias, AI_STATIC,
29, 0x0,
AI_SHAPE_INIT(4, 1, 1, 1, 1), AI_STRIDE_INIT(4, 4, 4, 4, 4),
1, &mu_bias_array, NULL)
/** Layer declarations section **********************************************/
AI_TENSOR_CHAIN_OBJ_DECLARE(
log_std_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &_model_a2c_network_Mul_output_0_output, &model__model_a2c_network_sigma),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &log_std_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
log_std_layer, 19,
ELTWISE_TYPE, 0x0, NULL,
eltwise, forward_eltwise,
&log_std_chain,
NULL, &log_std_layer, AI_STATIC,
.operation = ai_sum_f32,
.buffer_operation = ai_sum_buffer_f32,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_a2c_network_Mul_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &mu_output, &_model_a2c_network_Constant_output_0),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_Mul_output_0_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_a2c_network_Mul_output_0_layer, 18,
ELTWISE_TYPE, 0x0, NULL,
eltwise, forward_eltwise,
&_model_a2c_network_Mul_output_0_chain,
NULL, &log_std_layer, AI_STATIC,
.operation = ai_mul_f32,
.buffer_operation = ai_mul_buffer_f32,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
mu_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_activations_2_Elu_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &mu_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &mu_weights, &mu_bias),
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
mu_layer, 16,
DENSE_TYPE, 0x0, NULL,
dense, forward_dense,
&mu_chain,
NULL, &_model_a2c_network_Mul_output_0_layer, AI_STATIC,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
value_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_activations_2_Elu_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &value_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &value_weights, &value_bias),
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
value_layer, 15,
DENSE_TYPE, 0x0, NULL,
dense, forward_dense,
&value_chain,
NULL, &mu_layer, AI_STATIC,
)
AI_STATIC_CONST ai_float _model_a2c_network_actor_mlp_activations_2_Elu_output_0_nl_params_data[] = { 1.0 };
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_2_Elu_output_0_nl_params, AI_ARRAY_FORMAT_FLOAT,
_model_a2c_network_actor_mlp_activations_2_Elu_output_0_nl_params_data, _model_a2c_network_actor_mlp_activations_2_Elu_output_0_nl_params_data, 1, AI_STATIC_CONST)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_2_Elu_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_2_Gemm_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_activations_2_Elu_output_0_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_2_Elu_output_0_layer, 14,
NL_TYPE, 0x0, NULL,
nl, forward_elu,
&_model_a2c_network_actor_mlp_activations_2_Elu_output_0_chain,
NULL, &value_layer, AI_STATIC,
.nl_params = &_model_a2c_network_actor_mlp_activations_2_Elu_output_0_nl_params,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_a2c_network_actor_mlp_2_Gemm_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_Concat_1_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_2_Gemm_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &_model_a2c_network_actor_mlp_2_Gemm_output_0_weights, &_model_a2c_network_actor_mlp_2_Gemm_output_0_bias),
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_a2c_network_actor_mlp_2_Gemm_output_0_layer, 13,
DENSE_TYPE, 0x0, NULL,
dense, forward_dense,
&_model_a2c_network_actor_mlp_2_Gemm_output_0_chain,
NULL, &_model_a2c_network_actor_mlp_activations_2_Elu_output_0_layer, AI_STATIC,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_a2c_network_actor_mlp_Concat_1_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &_model_a2c_network_actor_mlp_activations_1_Elu_output_0_output, &_model_running_mean_std_Clip_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_Concat_1_output_0_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_a2c_network_actor_mlp_Concat_1_output_0_layer, 12,
CONCAT_TYPE, 0x0, NULL,
concat, forward_concat,
&_model_a2c_network_actor_mlp_Concat_1_output_0_chain,
NULL, &_model_a2c_network_actor_mlp_2_Gemm_output_0_layer, AI_STATIC,
.axis = AI_SHAPE_CHANNEL,
)
AI_STATIC_CONST ai_float _model_a2c_network_actor_mlp_activations_1_Elu_output_0_nl_params_data[] = { 1.0 };
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_1_Elu_output_0_nl_params, AI_ARRAY_FORMAT_FLOAT,
_model_a2c_network_actor_mlp_activations_1_Elu_output_0_nl_params_data, _model_a2c_network_actor_mlp_activations_1_Elu_output_0_nl_params_data, 1, AI_STATIC_CONST)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_1_Elu_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_1_Gemm_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_activations_1_Elu_output_0_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_1_Elu_output_0_layer, 11,
NL_TYPE, 0x0, NULL,
nl, forward_elu,
&_model_a2c_network_actor_mlp_activations_1_Elu_output_0_chain,
NULL, &_model_a2c_network_actor_mlp_Concat_1_output_0_layer, AI_STATIC,
.nl_params = &_model_a2c_network_actor_mlp_activations_1_Elu_output_0_nl_params,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_a2c_network_actor_mlp_1_Gemm_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_Concat_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_1_Gemm_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &_model_a2c_network_actor_mlp_1_Gemm_output_0_weights, &_model_a2c_network_actor_mlp_1_Gemm_output_0_bias),
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_a2c_network_actor_mlp_1_Gemm_output_0_layer, 10,
DENSE_TYPE, 0x0, NULL,
dense, forward_dense,
&_model_a2c_network_actor_mlp_1_Gemm_output_0_chain,
NULL, &_model_a2c_network_actor_mlp_activations_1_Elu_output_0_layer, AI_STATIC,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_a2c_network_actor_mlp_Concat_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &_model_a2c_network_actor_mlp_activations_0_Elu_output_0_output, &_model_running_mean_std_Clip_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_Concat_output_0_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_a2c_network_actor_mlp_Concat_output_0_layer, 9,
CONCAT_TYPE, 0x0, NULL,
concat, forward_concat,
&_model_a2c_network_actor_mlp_Concat_output_0_chain,
NULL, &_model_a2c_network_actor_mlp_1_Gemm_output_0_layer, AI_STATIC,
.axis = AI_SHAPE_CHANNEL,
)
AI_STATIC_CONST ai_float _model_a2c_network_actor_mlp_activations_0_Elu_output_0_nl_params_data[] = { 1.0 };
AI_ARRAY_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_0_Elu_output_0_nl_params, AI_ARRAY_FORMAT_FLOAT,
_model_a2c_network_actor_mlp_activations_0_Elu_output_0_nl_params_data, _model_a2c_network_actor_mlp_activations_0_Elu_output_0_nl_params_data, 1, AI_STATIC_CONST)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_0_Elu_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_0_Gemm_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_activations_0_Elu_output_0_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_a2c_network_actor_mlp_activations_0_Elu_output_0_layer, 8,
NL_TYPE, 0x0, NULL,
nl, forward_elu,
&_model_a2c_network_actor_mlp_activations_0_Elu_output_0_chain,
NULL, &_model_a2c_network_actor_mlp_Concat_output_0_layer, AI_STATIC,
.nl_params = &_model_a2c_network_actor_mlp_activations_0_Elu_output_0_nl_params,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_a2c_network_actor_mlp_0_Gemm_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_running_mean_std_Clip_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_a2c_network_actor_mlp_0_Gemm_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &_model_a2c_network_actor_mlp_0_Gemm_output_0_weights, &_model_a2c_network_actor_mlp_0_Gemm_output_0_bias),
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_a2c_network_actor_mlp_0_Gemm_output_0_layer, 7,
DENSE_TYPE, 0x0, NULL,
dense, forward_dense,
&_model_a2c_network_actor_mlp_0_Gemm_output_0_chain,
NULL, &_model_a2c_network_actor_mlp_activations_0_Elu_output_0_layer, AI_STATIC,
)
AI_STATIC_CONST ai_float _model_running_mean_std_Clip_output_0_nl_params_data[] = { -5.0, 5.0 };
AI_ARRAY_OBJ_DECLARE(
_model_running_mean_std_Clip_output_0_nl_params, AI_ARRAY_FORMAT_FLOAT,
_model_running_mean_std_Clip_output_0_nl_params_data, _model_running_mean_std_Clip_output_0_nl_params_data, 2, AI_STATIC_CONST)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_running_mean_std_Clip_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_running_mean_std_Div_output_0_output),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_running_mean_std_Clip_output_0_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_running_mean_std_Clip_output_0_layer, 5,
NL_TYPE, 0x0, NULL,
nl, forward_clip,
&_model_running_mean_std_Clip_output_0_chain,
NULL, &_model_a2c_network_actor_mlp_0_Gemm_output_0_layer, AI_STATIC,
.nl_params = &_model_running_mean_std_Clip_output_0_nl_params,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_running_mean_std_Div_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &_model_running_mean_std_Sub_output_0_output, &onnxDiv_43),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_running_mean_std_Div_output_0_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_running_mean_std_Div_output_0_layer, 2,
ELTWISE_TYPE, 0x0, NULL,
eltwise, forward_eltwise,
&_model_running_mean_std_Div_output_0_chain,
NULL, &_model_running_mean_std_Clip_output_0_layer, AI_STATIC,
.operation = ai_div_f32,
.buffer_operation = ai_div_buffer_f32,
)
AI_TENSOR_CHAIN_OBJ_DECLARE(
_model_running_mean_std_Sub_output_0_chain, AI_STATIC_CONST, 4,
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 2, &obs_output, &onnxSub_40),
AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, 1, &_model_running_mean_std_Sub_output_0_output),
AI_TENSOR_LIST_OBJ_EMPTY,
AI_TENSOR_LIST_OBJ_EMPTY
)
AI_LAYER_OBJ_DECLARE(
_model_running_mean_std_Sub_output_0_layer, 1,
ELTWISE_TYPE, 0x0, NULL,
eltwise, forward_eltwise,
&_model_running_mean_std_Sub_output_0_chain,
NULL, &_model_running_mean_std_Div_output_0_layer, AI_STATIC,
.operation = ai_sub_f32,
.buffer_operation = ai_sub_buffer_f32,
)
#if (AI_TOOLS_API_VERSION < AI_TOOLS_API_VERSION_1_5)
AI_NETWORK_OBJ_DECLARE(
AI_NET_OBJ_INSTANCE, AI_STATIC,
AI_BUFFER_INIT(AI_FLAG_NONE, AI_BUFFER_FORMAT_U8,
AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, 44840, 1, 1),
44840, NULL, NULL),
AI_BUFFER_INIT(AI_FLAG_NONE, AI_BUFFER_FORMAT_U8,
AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, 1048, 1, 1),
1048, NULL, NULL),
AI_TENSOR_LIST_IO_OBJ_INIT(AI_FLAG_NONE, AI_NETWORK_IN_NUM, &obs_output),
AI_TENSOR_LIST_IO_OBJ_INIT(AI_FLAG_NONE, AI_NETWORK_OUT_NUM, &mu_output, &log_std_output, &value_output),
&_model_running_mean_std_Sub_output_0_layer, 0, NULL)
#else
AI_NETWORK_OBJ_DECLARE(
AI_NET_OBJ_INSTANCE, AI_STATIC,
AI_BUFFER_ARRAY_OBJ_INIT_STATIC(
AI_FLAG_NONE, 1,
AI_BUFFER_INIT(AI_FLAG_NONE, AI_BUFFER_FORMAT_U8,
AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, 44840, 1, 1),
44840, NULL, NULL)
),
AI_BUFFER_ARRAY_OBJ_INIT_STATIC(
AI_FLAG_NONE, 1,
AI_BUFFER_INIT(AI_FLAG_NONE, AI_BUFFER_FORMAT_U8,
AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, 1048, 1, 1),
1048, NULL, NULL)
),
AI_TENSOR_LIST_IO_OBJ_INIT(AI_FLAG_NONE, AI_NETWORK_IN_NUM, &obs_output),
AI_TENSOR_LIST_IO_OBJ_INIT(AI_FLAG_NONE, AI_NETWORK_OUT_NUM, &mu_output, &log_std_output, &value_output),
&_model_running_mean_std_Sub_output_0_layer, 0, NULL)
#endif /*(AI_TOOLS_API_VERSION < AI_TOOLS_API_VERSION_1_5)*/
/******************************************************************************/
AI_DECLARE_STATIC
ai_bool network_configure_activations(
ai_network* net_ctx, const ai_network_params* params)
{
AI_ASSERT(net_ctx)
if (ai_platform_get_activations_map(g_network_activations_map, 1, params)) {
/* Updating activations (byte) offsets */
obs_output_array.data = AI_PTR(g_network_activations_map[0] + 0);
obs_output_array.data_start = AI_PTR(g_network_activations_map[0] + 0);
_model_running_mean_std_Sub_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 0);
_model_running_mean_std_Sub_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 0);
_model_running_mean_std_Div_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 0);
_model_running_mean_std_Div_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 0);
_model_running_mean_std_Clip_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 0);
_model_running_mean_std_Clip_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 0);
_model_a2c_network_actor_mlp_0_Gemm_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 12);
_model_a2c_network_actor_mlp_0_Gemm_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 12);
_model_a2c_network_actor_mlp_activations_0_Elu_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 12);
_model_a2c_network_actor_mlp_activations_0_Elu_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 12);
_model_a2c_network_actor_mlp_Concat_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 524);
_model_a2c_network_actor_mlp_Concat_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 524);
_model_a2c_network_actor_mlp_1_Gemm_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 12);
_model_a2c_network_actor_mlp_1_Gemm_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 12);
_model_a2c_network_actor_mlp_activations_1_Elu_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 268);
_model_a2c_network_actor_mlp_activations_1_Elu_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 268);
_model_a2c_network_actor_mlp_Concat_1_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 524);
_model_a2c_network_actor_mlp_Concat_1_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 524);
_model_a2c_network_actor_mlp_2_Gemm_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 0);
_model_a2c_network_actor_mlp_2_Gemm_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 0);
_model_a2c_network_actor_mlp_activations_2_Elu_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 128);
_model_a2c_network_actor_mlp_activations_2_Elu_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 128);
value_output_array.data = AI_PTR(g_network_activations_map[0] + 0);
value_output_array.data_start = AI_PTR(g_network_activations_map[0] + 0);
mu_output_array.data = AI_PTR(g_network_activations_map[0] + 4);
mu_output_array.data_start = AI_PTR(g_network_activations_map[0] + 4);
_model_a2c_network_Mul_output_0_output_array.data = AI_PTR(g_network_activations_map[0] + 8);
_model_a2c_network_Mul_output_0_output_array.data_start = AI_PTR(g_network_activations_map[0] + 8);
log_std_output_array.data = AI_PTR(g_network_activations_map[0] + 12);
log_std_output_array.data_start = AI_PTR(g_network_activations_map[0] + 12);
return true;
}
AI_ERROR_TRAP(net_ctx, INIT_FAILED, NETWORK_ACTIVATIONS);
return false;
}
/******************************************************************************/
AI_DECLARE_STATIC
ai_bool network_configure_weights(
ai_network* net_ctx, const ai_network_params* params)
{
AI_ASSERT(net_ctx)
if (ai_platform_get_weights_map(g_network_weights_map, 1, params)) {
/* Updating weights (byte) offsets */
model__model_a2c_network_sigma_array.format |= AI_FMT_FLAG_CONST;
model__model_a2c_network_sigma_array.data = AI_PTR(g_network_weights_map[0] + 0);
model__model_a2c_network_sigma_array.data_start = AI_PTR(g_network_weights_map[0] + 0);
_model_a2c_network_Constant_output_0_array.format |= AI_FMT_FLAG_CONST;
_model_a2c_network_Constant_output_0_array.data = AI_PTR(g_network_weights_map[0] + 4);
_model_a2c_network_Constant_output_0_array.data_start = AI_PTR(g_network_weights_map[0] + 4);
onnxDiv_43_array.format |= AI_FMT_FLAG_CONST;
onnxDiv_43_array.data = AI_PTR(g_network_weights_map[0] + 8);
onnxDiv_43_array.data_start = AI_PTR(g_network_weights_map[0] + 8);
onnxSub_40_array.format |= AI_FMT_FLAG_CONST;
onnxSub_40_array.data = AI_PTR(g_network_weights_map[0] + 20);
onnxSub_40_array.data_start = AI_PTR(g_network_weights_map[0] + 20);
_model_a2c_network_actor_mlp_0_Gemm_output_0_weights_array.format |= AI_FMT_FLAG_CONST;
_model_a2c_network_actor_mlp_0_Gemm_output_0_weights_array.data = AI_PTR(g_network_weights_map[0] + 32);
_model_a2c_network_actor_mlp_0_Gemm_output_0_weights_array.data_start = AI_PTR(g_network_weights_map[0] + 32);
_model_a2c_network_actor_mlp_0_Gemm_output_0_bias_array.format |= AI_FMT_FLAG_CONST;
_model_a2c_network_actor_mlp_0_Gemm_output_0_bias_array.data = AI_PTR(g_network_weights_map[0] + 1568);
_model_a2c_network_actor_mlp_0_Gemm_output_0_bias_array.data_start = AI_PTR(g_network_weights_map[0] + 1568);
_model_a2c_network_actor_mlp_1_Gemm_output_0_weights_array.format |= AI_FMT_FLAG_CONST;
_model_a2c_network_actor_mlp_1_Gemm_output_0_weights_array.data = AI_PTR(g_network_weights_map[0] + 2080);
_model_a2c_network_actor_mlp_1_Gemm_output_0_weights_array.data_start = AI_PTR(g_network_weights_map[0] + 2080);
_model_a2c_network_actor_mlp_1_Gemm_output_0_bias_array.format |= AI_FMT_FLAG_CONST;
_model_a2c_network_actor_mlp_1_Gemm_output_0_bias_array.data = AI_PTR(g_network_weights_map[0] + 35616);
_model_a2c_network_actor_mlp_1_Gemm_output_0_bias_array.data_start = AI_PTR(g_network_weights_map[0] + 35616);
_model_a2c_network_actor_mlp_2_Gemm_output_0_weights_array.format |= AI_FMT_FLAG_CONST;
_model_a2c_network_actor_mlp_2_Gemm_output_0_weights_array.data = AI_PTR(g_network_weights_map[0] + 35872);
_model_a2c_network_actor_mlp_2_Gemm_output_0_weights_array.data_start = AI_PTR(g_network_weights_map[0] + 35872);
_model_a2c_network_actor_mlp_2_Gemm_output_0_bias_array.format |= AI_FMT_FLAG_CONST;
_model_a2c_network_actor_mlp_2_Gemm_output_0_bias_array.data = AI_PTR(g_network_weights_map[0] + 44448);
_model_a2c_network_actor_mlp_2_Gemm_output_0_bias_array.data_start = AI_PTR(g_network_weights_map[0] + 44448);
value_weights_array.format |= AI_FMT_FLAG_CONST;
value_weights_array.data = AI_PTR(g_network_weights_map[0] + 44576);
value_weights_array.data_start = AI_PTR(g_network_weights_map[0] + 44576);
value_bias_array.format |= AI_FMT_FLAG_CONST;
value_bias_array.data = AI_PTR(g_network_weights_map[0] + 44704);
value_bias_array.data_start = AI_PTR(g_network_weights_map[0] + 44704);
mu_weights_array.format |= AI_FMT_FLAG_CONST;
mu_weights_array.data = AI_PTR(g_network_weights_map[0] + 44708);
mu_weights_array.data_start = AI_PTR(g_network_weights_map[0] + 44708);
mu_bias_array.format |= AI_FMT_FLAG_CONST;
mu_bias_array.data = AI_PTR(g_network_weights_map[0] + 44836);
mu_bias_array.data_start = AI_PTR(g_network_weights_map[0] + 44836);
return true;
}
AI_ERROR_TRAP(net_ctx, INIT_FAILED, NETWORK_WEIGHTS);
return false;
}
/** PUBLIC APIs SECTION *****************************************************/
AI_DEPRECATED
AI_API_ENTRY
ai_bool ai_network_get_info(
ai_handle network, ai_network_report* report)
{
ai_network* net_ctx = AI_NETWORK_ACQUIRE_CTX(network);
if (report && net_ctx)
{
ai_network_report r = {
.model_name = AI_NETWORK_MODEL_NAME,
.model_signature = AI_NETWORK_MODEL_SIGNATURE,
.model_datetime = AI_TOOLS_DATE_TIME,
.compile_datetime = AI_TOOLS_COMPILE_TIME,
.runtime_revision = ai_platform_runtime_get_revision(),
.runtime_version = ai_platform_runtime_get_version(),
.tool_revision = AI_TOOLS_REVISION_ID,
.tool_version = {AI_TOOLS_VERSION_MAJOR, AI_TOOLS_VERSION_MINOR,
AI_TOOLS_VERSION_MICRO, 0x0},
.tool_api_version = AI_STRUCT_INIT,
.api_version = ai_platform_api_get_version(),
.interface_api_version = ai_platform_interface_api_get_version(),
.n_macc = 13692,
.n_inputs = 0,
.inputs = NULL,
.n_outputs = 0,
.outputs = NULL,
.params = AI_STRUCT_INIT,
.activations = AI_STRUCT_INIT,
.n_nodes = 0,
.signature = 0x0,
};
if (!ai_platform_api_get_network_report(network, &r)) return false;
*report = r;
return true;
}
return false;
}
AI_API_ENTRY
ai_bool ai_network_get_report(
ai_handle network, ai_network_report* report)
{
ai_network* net_ctx = AI_NETWORK_ACQUIRE_CTX(network);
if (report && net_ctx)
{
ai_network_report r = {
.model_name = AI_NETWORK_MODEL_NAME,
.model_signature = AI_NETWORK_MODEL_SIGNATURE,
.model_datetime = AI_TOOLS_DATE_TIME,
.compile_datetime = AI_TOOLS_COMPILE_TIME,
.runtime_revision = ai_platform_runtime_get_revision(),
.runtime_version = ai_platform_runtime_get_version(),
.tool_revision = AI_TOOLS_REVISION_ID,
.tool_version = {AI_TOOLS_VERSION_MAJOR, AI_TOOLS_VERSION_MINOR,
AI_TOOLS_VERSION_MICRO, 0x0},
.tool_api_version = AI_STRUCT_INIT,
.api_version = ai_platform_api_get_version(),
.interface_api_version = ai_platform_interface_api_get_version(),
.n_macc = 13692,
.n_inputs = 0,
.inputs = NULL,
.n_outputs = 0,
.outputs = NULL,
.map_signature = AI_MAGIC_SIGNATURE,
.map_weights = AI_STRUCT_INIT,
.map_activations = AI_STRUCT_INIT,
.n_nodes = 0,
.signature = 0x0,
};
if (!ai_platform_api_get_network_report(network, &r)) return false;
*report = r;
return true;
}
return false;
}
AI_API_ENTRY
ai_error ai_network_get_error(ai_handle network)
{
return ai_platform_network_get_error(network);
}
AI_API_ENTRY
ai_error ai_network_create(
ai_handle* network, const ai_buffer* network_config)
{
return ai_platform_network_create(
network, network_config,
&AI_NET_OBJ_INSTANCE,
AI_TOOLS_API_VERSION_MAJOR, AI_TOOLS_API_VERSION_MINOR, AI_TOOLS_API_VERSION_MICRO);
}
AI_API_ENTRY
ai_error ai_network_create_and_init(
ai_handle* network, const ai_handle activations[], const ai_handle weights[])
{
ai_error err;
ai_network_params params;
err = ai_network_create(network, AI_NETWORK_DATA_CONFIG);
if (err.type != AI_ERROR_NONE)
return err;
if (ai_network_data_params_get(¶ms) != true) {
err = ai_network_get_error(*network);
return err;
}
#if defined(AI_NETWORK_DATA_ACTIVATIONS_COUNT)
if (activations) {
/* set the addresses of the activations buffers */
for (int idx=0;idx<params.map_activations.size;idx++)
AI_BUFFER_ARRAY_ITEM_SET_ADDRESS(¶ms.map_activations, idx, activations[idx]);
}
#endif
#if defined(AI_NETWORK_DATA_WEIGHTS_COUNT)
if (weights) {
/* set the addresses of the weight buffers */
for (int idx=0;idx<params.map_weights.size;idx++)
AI_BUFFER_ARRAY_ITEM_SET_ADDRESS(¶ms.map_weights, idx, weights[idx]);
}
#endif
if (ai_network_init(*network, ¶ms) != true) {
err = ai_network_get_error(*network);
}
return err;
}
AI_API_ENTRY
ai_buffer* ai_network_inputs_get(ai_handle network, ai_u16 *n_buffer)
{
if (network == AI_HANDLE_NULL) {
network = (ai_handle)&AI_NET_OBJ_INSTANCE;
((ai_network *)network)->magic = AI_MAGIC_CONTEXT_TOKEN;
}
return ai_platform_inputs_get(network, n_buffer);
}
AI_API_ENTRY
ai_buffer* ai_network_outputs_get(ai_handle network, ai_u16 *n_buffer)
{
if (network == AI_HANDLE_NULL) {
network = (ai_handle)&AI_NET_OBJ_INSTANCE;
((ai_network *)network)->magic = AI_MAGIC_CONTEXT_TOKEN;
}
return ai_platform_outputs_get(network, n_buffer);
}
AI_API_ENTRY
ai_handle ai_network_destroy(ai_handle network)
{
return ai_platform_network_destroy(network);
}
AI_API_ENTRY
ai_bool ai_network_init(
ai_handle network, const ai_network_params* params)
{
ai_network* net_ctx = ai_platform_network_init(network, params);
if (!net_ctx) return false;
ai_bool ok = true;
ok &= network_configure_weights(net_ctx, params);
ok &= network_configure_activations(net_ctx, params);
ok &= ai_platform_network_post_init(network);
return ok;
}
AI_API_ENTRY
ai_i32 ai_network_run(
ai_handle network, const ai_buffer* input, ai_buffer* output)
{
return ai_platform_network_process(network, input, output);
}
AI_API_ENTRY
ai_i32 ai_network_forward(ai_handle network, const ai_buffer* input)
{
return ai_platform_network_process(network, input, NULL);
}
#undef AI_NETWORK_MODEL_SIGNATURE
#undef AI_NET_OBJ_INSTANCE
#undef AI_TOOLS_DATE_TIME
#undef AI_TOOLS_COMPILE_TIME
| 39,305 | C | 36.256872 | 167 | 0.670373 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/mc_interface.c |
/**
******************************************************************************
* @file mc_interface.c
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware functions that implement the features
* of the MC Interface component of the Motor Control SDK:
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCInterface
*/
/* Includes ------------------------------------------------------------------*/
#include "mc_math.h"
#include "speed_torq_ctrl.h"
#include "mc_interface.h"
#include "motorcontrol.h"
#define ROUNDING_OFF
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup CAI
* @{
*/
/** @defgroup MCInterface Motor Control Interface
* @brief MC Interface component of the Motor Control SDK
*
* This interface allows for performing basic operations on the motor driven by a
* Motor Control SDK based application. With it, motors can be started and stopped, speed or
* torque ramps can be programmed and executed and information on the state of the motor can
* be retrieved, among others.
*
* These functions aims at being the main interface used by an application to control the motor.
*
* @{
*/
/* Private macros ------------------------------------------------------------*/
#define round(x) ((x)>=0?(int32_t)((x)+0.5):(int32_t)((x)-0.5))
/* Functions -----------------------------------------------*/
/**
* @brief Initializes all the object variables, usually it has to be called
* once right after object creation. It is also used to assign the
* state machine object, the speed and torque controller, and the FOC
* drive object to be used by MC Interface.
* @param pHandle pointer on the component instance to initialize.
* @param pSTC the speed and torque controller used by the MCI.
* @param pFOCVars pointer to FOC vars to be used by MCI.
* @param pPosCtrl pointer to the position controller to be used by the MCI
* (only present if position control is enabled)
* @param pPWMHandle pointer to the PWM & current feedback component to be used by the MCI.
*/
__weak void MCI_Init(MCI_Handle_t *pHandle, SpeednTorqCtrl_Handle_t *pSTC, pFOCVars_t pFOCVars,
PWMC_Handle_t *pPWMHandle )
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pSTC = pSTC;
pHandle->pFOCVars = pFOCVars;
pHandle->pPWM = pPWMHandle;
/* Buffer related initialization */
pHandle->lastCommand = MCI_NOCOMMANDSYET;
pHandle->hFinalSpeed = 0;
pHandle->hFinalTorque = 0;
pHandle->hDurationms = 0;
pHandle->CommandState = MCI_BUFFER_EMPTY;
pHandle->DirectCommand = MCI_NO_COMMAND;
pHandle->State = IDLE;
pHandle->CurrentFaults = MC_NO_FAULTS;
pHandle->PastFaults = MC_NO_FAULTS;
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief Programs a motor speed ramp
*
* @param pHandle Pointer on the component instance to operate on.
* @param hFinalSpeed The value of mechanical rotor speed reference at the
* end of the ramp expressed in the unit defined by #SPEED_UNIT.
* @param hDurationms The duration of the ramp expressed in milliseconds. It
* is possible to set 0 to perform an instantaneous change in the
* value.
*
* This command is executed immediately if the target motor's state machine is in
* the #RUN state. Otherwise, it is buffered and its execution is delayed until This
* state is reached.
*
* Users can check the status of the command by calling the MCI_IsCommandAcknowledged()
* function.
*
* @sa MCI_ExecSpeedRamp_F
*/
__weak void MCI_ExecSpeedRamp(MCI_Handle_t *pHandle, int16_t hFinalSpeed, uint16_t hDurationms)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->lastCommand = MCI_CMD_EXECSPEEDRAMP;
pHandle->hFinalSpeed = hFinalSpeed;
pHandle->hDurationms = hDurationms;
pHandle->CommandState = MCI_COMMAND_NOT_ALREADY_EXECUTED;
pHandle->LastModalitySetByUser = MCM_SPEED_MODE;
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief Programs a motor speed ramp
*
* @param pHandle Pointer on the component instance to operate on.
* @param FinalSpeed is the value of mechanical rotor speed reference at the
* end of the ramp expressed in RPM.
* @param hDurationms the duration of the ramp expressed in milliseconds. It
* is possible to set 0 to perform an instantaneous change in the
* value.
*
* This command is executed immediately if the target motor's state machine is in
* the #RUN state. Otherwise, it is buffered and its execution is delayed until This
* state is reached.
*
* Users can check the status of the command by calling the MCI_IsCommandAcknowledged()
* function.
*
* @sa MCI_ExecSpeedRamp
*/
__weak void MCI_ExecSpeedRamp_F(MCI_Handle_t *pHandle, const float_t FinalSpeed, uint16_t hDurationms)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
int16_t hFinalSpeed = (((int16_t)FinalSpeed * (int16_t)SPEED_UNIT) / (int16_t)U_RPM);
MCI_ExecSpeedRamp(pHandle, hFinalSpeed, hDurationms);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief Programs a motor torque ramp
*
* @param pHandle Pointer on the component instance to work on.
* @param hFinalTorque is the value of motor torque reference at the end of
* the ramp. This value represents actually the $I_q$ current expressed in
* digit.
* To convert current expressed in Amps to current expressed in digit
* is possible to use the formula:
* Current (digit) = [Current(Amp) * 65536 * Rshunt * Aop] / Vdd micro.
* @param hDurationms the duration of the ramp expressed in milliseconds. It
* is possible to set 0 to perform an instantaneous change in the
* value.
*
* This command is executed immediately if the target motor's state machine is in
* the #RUN state. Otherwise, it is buffered and its execution is delayed until This
* state is reached.
*
* Users can check the status of the command by calling the MCI_IsCommandAcknowledged()
* function.
*
* @sa MCI_ExecTorqueRamp_F
*/
__weak void MCI_ExecTorqueRamp(MCI_Handle_t *pHandle, int16_t hFinalTorque, uint16_t hDurationms)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->lastCommand = MCI_CMD_EXECTORQUERAMP;
pHandle->hFinalTorque = hFinalTorque;
pHandle->hDurationms = hDurationms;
pHandle->CommandState = MCI_COMMAND_NOT_ALREADY_EXECUTED;
pHandle->LastModalitySetByUser = MCM_TORQUE_MODE;
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief Programs a motor torque ramp
*
* @param pHandle Pointer on the component instance to work on.
* @param FinalTorque is the value of motor torque reference at the end of
* the ramp. This value represents actually the $I_q$ current expressed in
* Ampere.
* Here the formula for conversion from current in Ampere to digit:
* I(s16) = [i(Amp) * 65536 * Rshunt * Aop] / Vdd_micro.
* @param hDurationms the duration of the ramp expressed in milliseconds. It
* is possible to set 0 to perform an instantaneous change in the
* value.
*
* This command is executed immediately if the target motor's state machine is in
* the #RUN state. Otherwise, it is buffered and its execution is delayed until This
* state is reached.
*
* Users can check the status of the command by calling the MCI_IsCommandAcknowledged()
* function.
*
* @sa MCI_ExecTorqueRamp
*/
__weak void MCI_ExecTorqueRamp_F(MCI_Handle_t *pHandle, const float_t FinalTorque, uint16_t hDurationms)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
int16_t hFinalTorque = (int16_t)(FinalTorque * (int16_t)CURRENT_CONV_FACTOR);
MCI_ExecTorqueRamp(pHandle, hFinalTorque, hDurationms);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief Sets the motor current references $I_q$ and $I_d$ directly.
*
* @param pHandle Pointer on the component instance to work on.
* @param Iqdref current references on qd reference frame in qd_t format.
*
* This command is executed immediately if the target motor's state machine is in
* the #RUN state. Otherwise, it is buffered and its execution is delayed until This
* state is reached.
*
* Users can check the status of the command by calling the MCI_IsCommandAcknowledged()
* function.
@sa MCI_SetCurrentReferences_F
*/
__weak void MCI_SetCurrentReferences(MCI_Handle_t *pHandle, qd_t Iqdref)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->lastCommand = MCI_CMD_SETCURRENTREFERENCES;
pHandle->Iqdref.q = Iqdref.q;
pHandle->Iqdref.d = Iqdref.d;
pHandle->CommandState = MCI_COMMAND_NOT_ALREADY_EXECUTED;
pHandle->LastModalitySetByUser = MCM_TORQUE_MODE;
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief Sets the motor current references $I_q$ and $I_d$ directly.
*
* @param pHandle Pointer on the component instance to work on.
* @param IqdRef current (A) references on qd reference frame in qd_f_t format.
*
* This command is executed immediately if the target motor's state machine is in
* the #RUN state. Otherwise, it is buffered and its execution is delayed until This
* state is reached.
*
* Users can check the status of the command by calling the MCI_IsCommandAcknowledged()
* function.
@sa MCI_SetCurrentReferences
*/
__weak void MCI_SetCurrentReferences_F(MCI_Handle_t *pHandle, qd_f_t IqdRef)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
qd_t iqDrefTemp;
iqDrefTemp.d = (int16_t)((int16_t)IqdRef.d * (int16_t)CURRENT_CONV_FACTOR);
iqDrefTemp.q = (int16_t)((int16_t)IqdRef.q * (int16_t)CURRENT_CONV_FACTOR);
MCI_SetCurrentReferences(pHandle, iqDrefTemp);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief Initiates a motor startup procedure
*
* @param pHandle Handle on the target motor interface structure
* @retval Returns true if the command is successfully executed;
* returns false otherwise
*
* If the state machine of target the motor is in #IDLE state the command is
* executed instantaneously otherwise it is discarded. Users can check
* the return value of the function to get its status. The state of the motor
* can be queried with the MCI_GetSTMState() function.
*
* Before calling MCI_StartMotor() it is mandatory to execute one of the
* following commands, in order to set a torque or a speed reference
* otherwise the behavior of the motor when it reaches the #RUN state will
* be unpredictable:
* - MCI_ExecSpeedRamp
* - MCI_ExecTorqueRamp
* - MCI_SetCurrentReferences
*
* If the offsets of the current measurement circuitry offsets are not known yet,
* an offset calibration procedure is executed to measure them prior to acutally
* starting up the motor.
*
* @note The MCI_StartMotor command only triggers the execution of the start-up
* procedure (or eventually the offset calibration procedure) and returns
* immediately after. It is not blocking the execution of the application until
* the motor is indeed running in steady state. If the application needs to wait
* for the motor to be running in steady state, the application has to check the
* state machine of the motor and verify that the #RUN state has been reached.
* Note also that if the startup sequence fails the #RUN state may never be reached.
*/
__weak bool MCI_StartMotor(MCI_Handle_t *pHandle)
{
bool retVal = false;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if ((IDLE == MCI_GetSTMState(pHandle)) &&
(MC_NO_FAULTS == MCI_GetOccurredFaults(pHandle)) &&
(MC_NO_FAULTS == MCI_GetCurrentFaults(pHandle)))
{
pHandle->DirectCommand = MCI_START;
pHandle->CommandState = MCI_COMMAND_NOT_ALREADY_EXECUTED;
retVal = true;
}
else
{
/* Reject the command as the condition are not met */
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (retVal);
}
/**
* @brief Initiates a motor startup procedure preceded by an offset
* calibration procedure
*
* @param pHandle Handle on the target motor interface structure
* @retval Returns true if the command is successfully executed;
* returns false otherwise
*
* If the state machine of target the motor is in #IDLE state the command is
* executed instantaneously otherwise it is discarded. Users can check
* the return value of the function to get its status. The state of the motor
* can be queried with the MCI_GetSTMState() function.
*
* Before calling MCI_StartMotor() it is mandatory to execute one of the
* following commands, in order to set a torque or a speed reference
* otherwise the behavior of the motor when it reaches the #RUN state will
* be unpredictable:
* - MCI_ExecSpeedRamp
* - MCI_ExecTorqueRamp
* - MCI_SetCurrentReferences
*
* Whether the current measurement circuitry offsets are known or not, an
* offset calibration procedure is executed to (re)measure them. Once it has
* completed, the start up procedure of the motor is executed.
*
* @note The MCI_StartMotor command only triggers the execution of the start-up
* procedure (or eventually the offset calibration procedure) and returns
* immediately after. It is not blocking the execution of the application until
* the motor is indeed running in steady state. If the application needs to wait
* for the motor to be running in steady state, the application has to check the
* state machine of the motor and verify that the #RUN state has been reached.
* Note also that if the startup sequence fails the #RUN state may never be reached.
*/
__weak bool MCI_StartWithPolarizationMotor(MCI_Handle_t* pHandle)
{
bool retVal = true;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if ((IDLE == MCI_GetSTMState(pHandle)) &&
(MC_NO_FAULTS == MCI_GetOccurredFaults(pHandle)) &&
(MC_NO_FAULTS == MCI_GetCurrentFaults(pHandle)))
{
pHandle->DirectCommand = MCI_START;
pHandle->CommandState = MCI_COMMAND_NOT_ALREADY_EXECUTED;
pHandle->pPWM->offsetCalibStatus = false;
retVal = false;
}
else
{
/* Reject the command as the condition are not met */
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (retVal);
}
/**
* @brief This is a user command used to begin the phase offset calibration
* procedure. If the state machine is in IDLE state the command is executed
* instantaneously otherwise the command is discarded. User must take
* care of this possibility by checking the return value.\n
* <B>Note:</B> The MCI_StartOffsetMeasurments command is used to begin phase
* offset calibration procedure moving the state machine from IDLE state to
* OFFSET_CALIB. The command MCI_StartOffsetMeasurments is not blocking
* the execution of project until the measurments are done; to do this, the user
* have to check the state machine and verify that the IDLE state (or
* any other state) has been reached.
* @param pHandle Pointer on the component instance to work on.
* @retval bool It returns true if the command is successfully executed
* otherwise it return false.
*/
__weak bool MCI_StartOffsetMeasurments(MCI_Handle_t *pHandle)
{
bool retVal = false;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if ((IDLE == MCI_GetSTMState(pHandle)) &&
(MC_NO_FAULTS == MCI_GetOccurredFaults(pHandle)) &&
(MC_NO_FAULTS == MCI_GetCurrentFaults(pHandle)))
{
pHandle->DirectCommand = MCI_MEASURE_OFFSETS;
pHandle->pPWM->offsetCalibStatus = false;
retVal = true;
}
else
{
/* Reject the command as the condition are not met */
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (retVal);
}
/**
* @brief Gets the phase current measurement offset values
*
* The offset values are written in the PolarizationOffsets structure provided that they
* have been previously provided for the Motor Control subsystem or measured by it.
*
* If the offset have not previously been provided to the Motor Control subsystem or
* if it has not measured them the function returns false and nothing is written in the
* PolarizationOffsets structure.
*
* @param pHandle Pointer on the component instance to work on.
* @param PolarizationOffsets Pointer on ploarization offset structure in which offsets will be written
* @retval returns true if the command is successfully executed; returns false otherwise.
*/
__weak bool MCI_GetCalibratedOffsetsMotor(MCI_Handle_t *pHandle, PolarizationOffsets_t *PolarizationOffsets)
{
bool retVal = false;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if (pHandle->pPWM->offsetCalibStatus == true)
{
PWMC_GetOffsetCalib(pHandle->pPWM, PolarizationOffsets);
retVal = true;
}
else
{
/* Reject the command as the condition are not met */
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return(retVal);
}
/**
* @brief Sets the phase current measurement offset values
*
* If the state machine is in IDLE state the command is executed
* instantaneously otherwise the command is discarded. User must take
* care of this possibility by checking the return value.
*
* @note The MCI_SetCalibratedOffsetsMotor command is used to set the phase
* offset values . The command MCI_SetCalibratedOffsetsMotor is not blocking
* the execution of project until the measurments are done; to do this, the user
* have to check the state machine and verify that the IDLE state (or
* any other state) has been reached.
*
* @param pHandle Pointer on the component instance to work on.
* @param PolarizationOffsets Pointer on ploarization offset structure that contains phase A,
* and C values.
* @retval Returns true if the command is successfully executed
* otherwise it return false.
*/
__weak bool MCI_SetCalibratedOffsetsMotor(MCI_Handle_t *pHandle, PolarizationOffsets_t *PolarizationOffsets)
{
bool retVal = false;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if ((IDLE == MCI_GetSTMState(pHandle)) &&
(MC_NO_FAULTS == MCI_GetOccurredFaults(pHandle)) &&
(MC_NO_FAULTS == MCI_GetCurrentFaults(pHandle)))
{
PWMC_SetOffsetCalib(pHandle->pPWM, PolarizationOffsets);
pHandle->pPWM->offsetCalibStatus = true;
retVal = true;
}
else
{
/* Reject the command as the condition are not met */
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return(retVal);
}
/**
* @brief Initiates the stop procedure for a motor
*
* If the state machine is in any state but the #ICLWAIT, #IDLE, #FAULT_NOW and
* #FAULT_OVER states, the command is immediately executed. Otherwise, it is
* discarded. The Application can check the return value to know whether the
* command was executed or discarded.
*
* @note The MCI_StopMotor() command only triggers the stop motor procedure
* and then returns. It is not blocking the application until the motor is indeed
* stopped. To know if it has stopped, the application can query the motor's state
* machine and check if the #IDLE state has been reached.
*
* @param pHandle Pointer on the component instance to work on.
* @retval returns true if the command is successfully executed, false otherwise.
*/
__weak bool MCI_StopMotor(MCI_Handle_t *pHandle)
{
bool retVal = false;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
bool status;
MCI_State_t State;
State = MCI_GetSTMState(pHandle);
if ((IDLE == State) || (ICLWAIT == State))
{
status = false;
}
else
{
status = true;
}
if ((MC_NO_FAULTS == MCI_GetOccurredFaults(pHandle)) &&
(MC_NO_FAULTS == MCI_GetCurrentFaults(pHandle)) &&
(status == true))
{
pHandle->DirectCommand = MCI_STOP;
retVal = true;
}
else
{
/* Reject the command as the condition are not met */
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (retVal);
}
/**
* @brief Acknowledges Motor Control faults that occurred on the target motor 1.
*
* This function must be called before the motor can be started again when a fault
* condition has occured. It clears the faults status and resets the state machine
* of the target motor to the #IDLE state provided that there is no active fault
* condition anymore.
*
* If the state machine of the target motor is in the #FAULT_OVER state, the function
* clears the list of past faults, transitions to the #IDLE state and returns true.
* Otherwise, it oes nothing and returns false.
*
* @param pHandle Pointer on the target motor drive structure.
*/
__weak bool MCI_FaultAcknowledged(MCI_Handle_t *pHandle)
{
bool reVal = false;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if ((FAULT_OVER == MCI_GetSTMState(pHandle)) && (MC_NO_FAULTS == MCI_GetCurrentFaults(pHandle)))
{
pHandle->PastFaults = MC_NO_FAULTS;
pHandle->DirectCommand = MCI_ACK_FAULTS;
reVal = true;
}
else
{
/* Reject the command as the conditions are not met */
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (reVal);
}
/**
* @brief It clocks both HW and SW faults processing and update the state
* machine accordingly with hSetErrors, hResetErrors and present state.
* Refer to State_t description for more information about fault states.
* @param pHandle pointer of type STM_Handle_t
* @param hSetErrors Bit field reporting faults currently present
* @param hResetErrors Bit field reporting faults to be cleared
*/
__weak void MCI_FaultProcessing(MCI_Handle_t *pHandle, uint16_t hSetErrors, uint16_t hResetErrors)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
/* Set current errors */
pHandle->CurrentFaults = (pHandle->CurrentFaults | hSetErrors ) & (~hResetErrors);
pHandle->PastFaults |= hSetErrors;
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief This is usually a method managed by task. It must be called
* periodically in order to check the status of the related pSTM object
* and eventually to execute the buffered command if the condition
* occurs.
* @param pHandle Pointer on the component instance to work on.
*/
__weak void MCI_ExecBufferedCommands(MCI_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if ( pHandle->CommandState == MCI_COMMAND_NOT_ALREADY_EXECUTED )
{
bool commandHasBeenExecuted = false;
switch (pHandle->lastCommand)
{
case MCI_CMD_EXECSPEEDRAMP:
{
pHandle->pFOCVars->bDriveInput = INTERNAL;
STC_SetControlMode(pHandle->pSTC, MCM_SPEED_MODE);
commandHasBeenExecuted = STC_ExecRamp(pHandle->pSTC, pHandle->hFinalSpeed, pHandle->hDurationms);
break;
}
case MCI_CMD_EXECTORQUERAMP:
{
pHandle->pFOCVars->bDriveInput = INTERNAL;
STC_SetControlMode(pHandle->pSTC, MCM_TORQUE_MODE);
commandHasBeenExecuted = STC_ExecRamp(pHandle->pSTC, pHandle->hFinalTorque, pHandle->hDurationms);
break;
}
case MCI_CMD_SETCURRENTREFERENCES:
{
pHandle->pFOCVars->bDriveInput = EXTERNAL;
pHandle->pFOCVars->Iqdref = pHandle->Iqdref;
commandHasBeenExecuted = true;
break;
}
default:
break;
}
if (commandHasBeenExecuted)
{
pHandle->CommandState = MCI_COMMAND_EXECUTED_SUCCESSFULLY;
}
else
{
pHandle->CommandState = MCI_COMMAND_EXECUTED_UNSUCCESSFULLY;
}
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief Returns information about the state of the last buffered command.
* @param pHandle Pointer on the component instance to work on.
* @retval The state of the last buffered command
*
* The state returned by this function can be one of the following codes:
* - #MCI_BUFFER_EMPTY if no buffered command has been called.
* - #MCI_COMMAND_NOT_ALREADY_EXECUTED if the buffered command
* condition has not already occurred.
* - #MCI_COMMAND_EXECUTED_SUCCESSFULLY if the buffered command has
* been executed successfully. In this case calling this function resets
* the command state to #MCI_BUFFER_EMPTY.
* - #MCI_COMMAND_EXECUTED_UNSUCCESSFULLY if the buffered command has
* been executed unsuccessfully. In this case calling this function
* resets the command state to #MCI_BUFFER_EMPTY.
*/
__weak MCI_CommandState_t MCI_IsCommandAcknowledged(MCI_Handle_t *pHandle)
{
MCI_CommandState_t retVal;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
retVal = MCI_COMMAND_EXECUTED_UNSUCCESSFULLY;
}
else
{
#endif
retVal = pHandle->CommandState;
if ((MCI_COMMAND_EXECUTED_SUCCESSFULLY == retVal) || (MCI_COMMAND_EXECUTED_UNSUCCESSFULLY == retVal) )
{
pHandle->CommandState = MCI_BUFFER_EMPTY;
}
else
{
/* Nothing to do */
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (retVal);
}
/**
* @brief It returns information about the state of the related pSTM object.
* @param pHandle Pointer on the component instance to work on.
* @retval State_t It returns the current state of the related pSTM object.
*/
__weak MCI_State_t MCI_GetSTMState(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? FAULT_NOW : pHandle->State);
#else
return (pHandle->State);
#endif
}
/**
* @brief Returns the list of non-acknowledged faults that occured on the target motor
*
* This function returns a bitfield indicating the faults that occured since the state machine
* of the target motor has been moved into the #FAULT_NOW state.
*
* Possible error codes are listed in the @ref fault_codes "Fault codes" section.
*
* @param pHandle Pointer on the target motor drive structure.
* @retval uint16_t 16 bit fields with information about the faults
* historically occurred since the state machine has been moved into
*/
__weak uint16_t MCI_GetOccurredFaults(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? MC_SW_ERROR : (uint16_t)pHandle->PastFaults);
#else
return ((uint16_t)pHandle->PastFaults);
#endif
}
/**
* @brief Returns the list of faults that are currently active on the target motor
*
* This function returns a bitfield that indicates faults that occured on the Motor
* Control subsystem for the target motor and that are still active (the conditions
* that triggered the faults returned are still true).
*
* Possible error codes are listed in the @ref fault_codes "Fault codes" section.
*
* @param pHandle Pointer on the target motor drive structure.
*/
__weak uint16_t MCI_GetCurrentFaults(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? MC_SW_ERROR : (uint16_t)pHandle->CurrentFaults);
#else
return ((uint16_t)pHandle->CurrentFaults);
#endif
}
/**
* @brief Returns the lists of current and past faults that occurred on the target motor
*
* This function returns two bitfields containing information about the faults currently
* present and the faults occurred since the state machine has been moved into the #FAULT_NOW
* state.
*
* These two bitfields are 16 bits wide each and are concatenated into the 32-bit data. The
* 16 most significant bits contains the status of the current faults while that of the
* past faults is in the 16 least significant bits.
*
* @sa MCI_GetOccurredFaults, MCI_GetCurrentFaults
*
* @param pHandle Pointer on the target motor drive structure.
*/
__weak uint32_t MCI_GetFaultState(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
uint32_t LocalFaultState;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
LocalFaultState = MC_SW_ERROR | (MC_SW_ERROR << 16);
}
else
{
#endif
LocalFaultState = (uint32_t)(pHandle->PastFaults);
LocalFaultState |= (uint32_t)(pHandle->CurrentFaults) << 16;
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (LocalFaultState);
}
/**
* @brief It returns the modality of the speed and torque controller.
* @param pHandle Pointer on the component instance to work on.
* @retval MC_ControlMode_t It returns the modality of STC. It can be one of
* these two values: MCM_TORQUE_MODE or MCM_SPEED_MODE.
*/
__weak MC_ControlMode_t MCI_GetControlMode(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? MCM_TORQUE_MODE : pHandle->LastModalitySetByUser);
#else
return (pHandle->LastModalitySetByUser);
#endif
}
/**
* @brief It returns the motor direction imposed by the last command
* (MCI_ExecSpeedRamp, MCI_ExecTorqueRamp or MCI_SetCurrentReferences).
* @param pHandle Pointer on the component instance to work on.
* @retval int16_t It returns 1 or -1 according the sign of hFinalSpeed,
* hFinalTorque or Iqdref.q of the last command.
*/
__weak int16_t MCI_GetImposedMotorDirection(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
int16_t retVal = 1;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
switch (pHandle->lastCommand)
{
case MCI_CMD_EXECSPEEDRAMP:
{
if (pHandle->hFinalSpeed < 0)
{
retVal = -1;
}
else
{
/* Nothing to do */
}
break;
}
case MCI_CMD_EXECTORQUERAMP:
{
if (pHandle->hFinalTorque < 0)
{
retVal = -1;
}
else
{
/* Nothing to do */
}
break;
}
case MCI_CMD_SETCURRENTREFERENCES:
{
if (pHandle->Iqdref.q < 0)
{
retVal = -1;
}
else
{
/* Nothing to do */
}
break;
}
default:
break;
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (retVal);
}
/**
* @brief It returns information about the last ramp final speed sent by the
* user expressed in the unit defined by #SPEED_UNIT.
* @param pHandle Pointer on the component instance to work on.
* @retval int16_t last ramp final speed sent by the user expressed in
* the unit defined by #SPEED_UNIT.
*/
__weak int16_t MCI_GetLastRampFinalSpeed(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
int16_t retVal = 0;
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
retVal = pHandle->hFinalSpeed;
}
return (retVal);
#else
return (pHandle->hFinalSpeed);
#endif
}
/**
* @brief It returns information about the last ramp final torque sent by the
* user .This value represents actually the Iq current expressed in
* digit.
* @param pHandle Pointer on the component instance to work on.
* @retval int16_t last ramp final torque sent by the user expressed in digit
*/
__weak int16_t MCI_GetLastRampFinalTorque(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
int16_t retVal = 0;
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
retVal = pHandle->hFinalTorque;
}
return (retVal);
#else
return (pHandle->hFinalTorque);
#endif
}
/**
* @brief It returns information about the last ramp Duration sent by the
* user .
* @param pHandle Pointer on the component instance to work on.
* @retval uint16_t last ramp final torque sent by the user expressed in digit
*/
__weak uint16_t MCI_GetLastRampFinalDuration(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
uint16_t retVal = 0;
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
retVal = pHandle->hDurationms;
}
return (retVal);
#else
return (pHandle->hDurationms);
#endif
}
/**
* @brief It returns last ramp final speed expressed in rpm.
* @param pHandle Pointer on the component instance to work on.
* @retval float_t last ramp final speed sent by the user expressed in rpm.
*/
__weak float_t MCI_GetLastRampFinalSpeed_F(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
float_t reVal = 0.0f;
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
reVal = (((float_t)pHandle->hFinalSpeed * (float_t)U_RPM) / (float_t)SPEED_UNIT);
}
return (reVal);
}
/**
* @brief Check if the settled speed or torque ramp has been completed.
* @param pHandle Pointer on the component instance to work on.
* @retval bool It returns true if the ramp is completed, false otherwise.
*/
__weak bool MCI_RampCompleted(MCI_Handle_t *pHandle)
{
bool retVal = false;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if (RUN == MCI_GetSTMState(pHandle))
{
retVal = STC_RampCompleted(pHandle->pSTC);
}
else
{
/* Nothing to do */
}
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (retVal);
}
/**
* @brief Stop the execution of speed ramp.
* @param pHandle Pointer on the component instance to work on.
* @retval bool It returns true if the command is executed, false otherwise.
*
* @deprecated This function is deprecated and should not be used anymore. It will be
* removed in a future version of the MCSDK. Use MCI_StopRamp() instead.
*/
__weak bool MCI_StopSpeedRamp(MCI_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? false : STC_StopSpeedRamp(pHandle->pSTC));
#else
return (STC_StopSpeedRamp(pHandle->pSTC));
#endif
}
/**
* @brief Stop the execution of ongoing ramp.
* @param pHandle Pointer on the component instance to work on.
*/
__weak void MCI_StopRamp(MCI_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
STC_StopRamp(pHandle->pSTC);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @brief It returns speed sensor reliability with reference to the sensor
* actually used for reference frame transformation
* @param pHandle Pointer on the component instance to work on.
* @retval bool It returns true if the speed sensor utilized for reference
* frame transformation and (in speed control mode) for speed
* regulation is reliable, false otherwise
*/
__weak bool MCI_GetSpdSensorReliability(MCI_Handle_t *pHandle)
{
bool status;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
status = false;
}
else
{
#endif
SpeednPosFdbk_Handle_t *SpeedSensor = STC_GetSpeedSensor(pHandle->pSTC);
status = SPD_Check(SpeedSensor);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (status);
}
/**
* @brief Returns the last computed average mechanical speed, expressed in
* the unit defined by #SPEED_UNIT and related to the sensor actually
* used by FOC algorithm
* @param pHandle Pointer on the component instance to work on.
*/
__weak int16_t MCI_GetAvrgMecSpeedUnit(MCI_Handle_t *pHandle)
{
int16_t temp_speed;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
temp_speed = 0;
}
else
{
#endif
SpeednPosFdbk_Handle_t * SpeedSensor = STC_GetSpeedSensor(pHandle->pSTC);
temp_speed = SPD_GetAvrgMecSpeedUnit(SpeedSensor);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (temp_speed);
}
/**
* @brief Returns the last computed average mechanical speed, expressed in rpm
* and related to the sensor actually used by FOC algorithm.
* @param pHandle Pointer on the component instance to work on.
*/
__weak float_t MCI_GetAvrgMecSpeed_F(MCI_Handle_t *pHandle)
{
float_t returnAvrgSpeed;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
returnAvrgSpeed = 0.0f;
}
else
{
#endif
SpeednPosFdbk_Handle_t *SpeedSensor = STC_GetSpeedSensor(pHandle->pSTC);
returnAvrgSpeed = (((float_t)SPD_GetAvrgMecSpeedUnit(SpeedSensor) * (float_t)U_RPM) / (float_t)SPEED_UNIT);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (returnAvrgSpeed);
}
/**
* @brief Returns the current mechanical rotor speed reference expressed in the unit defined by #SPEED_UNIT
*
* @param pHandle Pointer on the component instance to work on.
*
*/
__weak int16_t MCI_GetMecSpeedRefUnit(MCI_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? 0 : STC_GetMecSpeedRefUnit(pHandle->pSTC));
#else
return (STC_GetMecSpeedRefUnit(pHandle->pSTC));
#endif
}
/**
* @brief Returns the current mechanical rotor speed reference expressed in rpm.
*
* @param pHandle Pointer on the component instance to work on.
*
*/
__weak float_t MCI_GetMecSpeedRef_F(MCI_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? 0.0f :
(((float_t)STC_GetMecSpeedRefUnit(pHandle->pSTC) * (float_t)U_RPM) / (float_t)SPEED_UNIT));
#else
return ((((float_t)STC_GetMecSpeedRefUnit(pHandle->pSTC) * (float_t)U_RPM) / (float_t)SPEED_UNIT));
#endif
}
/**
* @brief It returns stator current Iab in ab_t format
* @param pHandle Pointer on the component instance to work on.
* @retval ab_t Stator current Iab
*/
__weak ab_t MCI_GetIab(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
ab_t tempVal;
if (MC_NULL == pHandle)
{
tempVal.a = 0;
tempVal.b = 0;
}
else
{
tempVal = pHandle->pFOCVars->Iab;
}
return (tempVal);
#else
return (pHandle->pFOCVars->Iab);
#endif
}
__weak ab_f_t MCI_GetIab_F(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
ab_f_t iab;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
iab.a = 0.0f;
iab.b = 0.0f;
}
else
{
#endif
iab.a = (float_t)((float_t)pHandle->pFOCVars->Iab.a * pHandle->pScale->current);
iab.b = (float_t)((float_t)pHandle->pFOCVars->Iab.b * pHandle->pScale->current);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (iab);
}
/**
* @brief It returns stator current Ialphabeta in alphabeta_t format
* @param pHandle Pointer on the component instance to work on.
* @retval alphabeta_t Stator current Ialphabeta
*/
__weak alphabeta_t MCI_GetIalphabeta(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
alphabeta_t tempVal;
if (MC_NULL == pHandle)
{
tempVal.alpha = 0;
tempVal.beta = 0;
}
else
{
tempVal = pHandle->pFOCVars->Ialphabeta;
}
return (tempVal);
#else
return (pHandle->pFOCVars->Ialphabeta);
#endif
}
/**
* @brief It returns stator current Iqd in qd_t format
* @param pHandle Pointer on the component instance to work on.
* @retval qd_t Stator current Iqd
*/
__weak qd_t MCI_GetIqd(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
qd_t tempVal;
if (MC_NULL == pHandle)
{
tempVal.q = 0;
tempVal.d = 0;
}
else
{
tempVal = pHandle->pFOCVars->Iqd;
}
return (tempVal);
#else
return (pHandle->pFOCVars->Iqd);
#endif
}
/**
* @brief It returns stator current Iqd in float_t format
* @param pHandle Pointer on the component instance to work on.
* @retval qd_f_t Stator current Iqd (in Ampere)
*/
__weak qd_f_t MCI_GetIqd_F(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
qd_f_t iqd;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
iqd.d = 0.0f;
iqd.q = 0.0f;
}
else
{
#endif
iqd.d = (float_t)((float_t)pHandle->pFOCVars->Iqd.d * pHandle->pScale->current);
iqd.q = (float_t)((float_t)pHandle->pFOCVars->Iqd.q * pHandle->pScale->current);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (iqd);
}
/**
* @brief It returns stator current IqdHF in qd_t format
* @param pHandle Pointer on the component instance to work on.
* @retval qd_t Stator current IqdHF if HFI is selected as main
* sensor. Otherwise it returns { 0, 0}.
*/
__weak qd_t MCI_GetIqdHF(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
qd_t tempVal;
if (MC_NULL == pHandle)
{
tempVal.q = 0;
tempVal.d = 0;
}
else
{
tempVal = pHandle->pFOCVars->IqdHF;
}
return (tempVal);
#else
return (pHandle->pFOCVars->IqdHF);
#endif
}
/**
* @brief It returns stator current Iqdref in qd_t format
* @param pHandle Pointer on the component instance to work on.
* @retval qd_t Stator current Iqdref
*/
__weak qd_t MCI_GetIqdref(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
qd_t tempVal;
if (MC_NULL == pHandle)
{
tempVal.q = 0;
tempVal.d = 0;
}
else
{
tempVal = pHandle->pFOCVars->Iqdref;
}
return (tempVal);
#else
return (pHandle->pFOCVars->Iqdref);
#endif
}
/**
* @brief It returns stator current Iqdref in float_t format
* @param pHandle Pointer on the component instance to work on.
* @retval qd_f_t Stator current Iqdref (in Ampere)
*/
__weak qd_f_t MCI_GetIqdref_F(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
qd_f_t iqdref;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
iqdref.d = 0.0f;
iqdref.q = 0.0f;
}
else
{
#endif
iqdref.d = (float_t)((float_t)pHandle->pFOCVars->Iqdref.d * pHandle->pScale->current);
iqdref.q = (float_t)((float_t)pHandle->pFOCVars->Iqdref.q * pHandle->pScale->current);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (iqdref);
}
/**
* @brief It returns stator current Vqd in qd_t format
* @param pHandle Pointer on the component instance to work on.
* @retval qd_t Stator current Vqd
*/
__weak qd_t MCI_GetVqd(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
qd_t tempVal;
if (MC_NULL == pHandle)
{
tempVal.q = 0;
tempVal.d = 0;
}
else
{
tempVal = pHandle->pFOCVars->Vqd;
}
return (tempVal);
#else
return (pHandle->pFOCVars->Vqd);
#endif
}
/**
* @brief It returns stator current Valphabeta in alphabeta_t format
* @param pHandle Pointer on the component instance to work on.
* @retval alphabeta_t Stator current Valphabeta
*/
__weak alphabeta_t MCI_GetValphabeta(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
alphabeta_t tempVal;
if (MC_NULL == pHandle)
{
tempVal.alpha = 0;
tempVal.beta = 0;
}
else
{
tempVal = pHandle->pFOCVars->Valphabeta;
}
return (tempVal);
#else
return (pHandle->pFOCVars->Valphabeta);
#endif
}
/**
* @brief It returns the rotor electrical angle actually used for reference
* frame transformation
* @param pHandle Pointer on the component instance to work on.
* @retval int16_t Rotor electrical angle in dpp format
*/
__weak int16_t MCI_GetElAngledpp(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? 0 : pHandle->pFOCVars->hElAngle);
#else
return (pHandle->pFOCVars->hElAngle);
#endif
}
/**
* @brief It returns the reference electrical torque, fed to derived class for
* Iqref and Idref computation
* @param pHandle Pointer on the component instance to work on.
* @retval int16_t Teref
*/
__weak int16_t MCI_GetTeref(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? 0 : pHandle->pFOCVars->hTeref);
#else
return (pHandle->pFOCVars->hTeref);
#endif
}
/**
* @brief It returns the reference electrical torque.
* @param pHandle Pointer on the component instance to work on.
* @retval float_t Teref
*/
__weak float_t MCI_GetTeref_F(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
#ifdef NULL_PTR_CHECK_MC_INT
return ((MC_NULL == pHandle) ? 0.0f : ((float_t)pHandle->pFOCVars->hTeref * (float_t)pHandle->pScale->current));
#else
return ((float_t)(pHandle->pFOCVars->hTeref * pHandle->pScale->current));
#endif
}
/**
* @brief It returns the motor phase current amplitude (0-to-peak) in s16A
* To convert s16A into Ampere following formula must be used:
* Current(Amp) = [Current(s16A) * Vdd micro] / [65536 * Rshunt * Aop]
* @param pHandle Pointer on the component instance to work on.
* @retval int16_t Motor phase current (0-to-peak) in s16A
*/
__weak int16_t MCI_GetPhaseCurrentAmplitude(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
alphabeta_t Local_Curr;
int16_t wAux;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
wAux = 0;
}
else
{
#endif
Local_Curr = pHandle->pFOCVars->Ialphabeta;
wAux = MCM_Modulus(Local_Curr.alpha, Local_Curr.beta);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (wAux);
}
/**
* @brief It returns the applied motor phase voltage amplitude (0-to-peak) in
* s16V. To convert s16V into Volts following formula must be used:
* PhaseVoltage(V) = [PhaseVoltage(s16A) * Vbus(V)] /[sqrt(3) *32767]
* @param pHandle Pointer on the component instance to work on.
* @retval int16_t Motor phase voltage (0-to-peak) in s16V
*/
__weak int16_t MCI_GetPhaseVoltageAmplitude(MCI_Handle_t *pHandle) //cstat !MISRAC2012-Rule-8.13
{
int16_t temp_wAux;
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
temp_wAux = 0;
}
else
{
#endif
alphabeta_t Local_Voltage;
int32_t wAux1;
int32_t wAux2;
Local_Voltage = pHandle->pFOCVars->Valphabeta;
wAux1 = (int32_t)(Local_Voltage.alpha) * Local_Voltage.alpha;
wAux2 = (int32_t)(Local_Voltage.beta) * Local_Voltage.beta;
wAux1 += wAux2;
wAux1 = MCM_Sqrt(wAux1);
if (wAux1 > INT16_MAX)
{
wAux1 = (int32_t)INT16_MAX;
}
temp_wAux = (int16_t)wAux1;
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
return (temp_wAux);
}
/**
* @brief It re-initializes Iqdref variables with their default values.
* @param pHandle Pointer on the component instance to work on.
*/
__weak void MCI_Clear_Iqdref(MCI_Handle_t *pHandle)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->pFOCVars->Iqdref = STC_GetDefaultIqdref(pHandle->pSTC);
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 47,844 | C | 27.926844 | 114 | 0.666479 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Src/crc.c | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file crc.c
* @brief This file provides code for the configuration
* of the CRC instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "crc.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
CRC_HandleTypeDef hcrc;
/* CRC init function */
void MX_CRC_Init(void)
{
/* USER CODE BEGIN CRC_Init 0 */
/* USER CODE END CRC_Init 0 */
/* USER CODE BEGIN CRC_Init 1 */
/* USER CODE END CRC_Init 1 */
hcrc.Instance = CRC;
hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
if (HAL_CRC_Init(&hcrc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CRC_Init 2 */
/* USER CODE END CRC_Init 2 */
}
void HAL_CRC_MspInit(CRC_HandleTypeDef* crcHandle)
{
if(crcHandle->Instance==CRC)
{
/* USER CODE BEGIN CRC_MspInit 0 */
/* USER CODE END CRC_MspInit 0 */
/* CRC clock enable */
__HAL_RCC_CRC_CLK_ENABLE();
/* USER CODE BEGIN CRC_MspInit 1 */
/* USER CODE END CRC_MspInit 1 */
}
}
void HAL_CRC_MspDeInit(CRC_HandleTypeDef* crcHandle)
{
if(crcHandle->Instance==CRC)
{
/* USER CODE BEGIN CRC_MspDeInit 0 */
/* USER CODE END CRC_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_CRC_CLK_DISABLE();
/* USER CODE BEGIN CRC_MspDeInit 1 */
/* USER CODE END CRC_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
| 2,235 | C | 23.571428 | 80 | 0.564206 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_tasks.h | /**
******************************************************************************
* @file mc_tasks.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file implementes tasks definition.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCTasks
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MCTASKS_H
#define MCTASKS_H
/* Includes ------------------------------------------------------------------*/
#include "mc_parameters.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** @addtogroup MCSDK
* @{
*/
/** @defgroup MCTasks Motor Control Tasks
*
* @brief Motor Control subsystem configuration and operation routines.
*
* @{
*/
/* Initializes the Motor subsystem core according to user defined parameters */
void MCboot(MCI_Handle_t *pMCIList[NBR_OF_MOTORS]);
/* Runs all the Tasks of the Motor Control cockpit */
void MC_RunMotorControlTasks(void);
/* Executes the Medium Frequency Task functions for each drive instance */
void MC_Scheduler(void);
/* Executes safety checks (e.g. bus voltage and temperature) for all drive instances */
void TSK_SafetyTask(void);
/* Executes the Motor Control duties that require a high frequency rate and a precise timing */
uint8_t TSK_HighFrequencyTask(void);
void UI_HandleStartStopButton_cb(void);
/* Reserves FOC execution on ADC ISR half a PWM period in advance */
void TSK_DualDriveFIFOUpdate(uint8_t Motor);
/* Puts the Motor Control subsystem in in safety conditions on a Hard Fault */
void TSK_HardwareFaultTask(void);
/* Locks GPIO pins used for Motor Control to prevent accidental reconfiguration */
void mc_lock_pins(void);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* MCTASKS_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 2,397 | C | 28.243902 | 95 | 0.587818 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/pwm_curr_fdbk.h | /**
******************************************************************************
* @file pwm_curr_fdbk.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains all definitions and functions prototypes for the
* PWM & Current Feedback component of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup pwm_curr_fdbk
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef PWMNCURRFDBK_H
#define PWMNCURRFDBK_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
/* Exported defines ------------------------------------------------------------*/
#define SECTOR_1 0U
#define SECTOR_2 1U
#define SECTOR_3 2U
#define SECTOR_4 3U
#define SECTOR_5 4U
#define SECTOR_6 5U
/* @brief Used in calculation of Ia, Ib and Ic
*
* See function PWMC_CalcPhaseCurrentsEst
*/
#define SQRT3FACTOR ((uint16_t)0xDDB4) /* = (16384 * 1.732051 * 2)*/
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup pwm_curr_fdbk
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @brief PWM & Current Sensing component handle type */
typedef struct PWMC_Handle PWMC_Handle_t;
/**
* @brief Pointer on callback functions used by PWMC components
*
* This type is needed because the actual functions to use can change at run-time.
*
* See the following items:
* - PWMC_Handle::pFctSwitchOffPwm
* - PWMC_Handle::pFctSwitchOnPwm
* - PWMC_Handle::pFctCurrReadingCalib
* - PWMC_Handle::pFctRLDetectionModeEnable
* - PWMC_Handle::pFctRLDetectionModeDisable
*
*
*/
typedef void (*PWMC_Generic_Cb_t)(PWMC_Handle_t *pHandle);
/**
* @brief Pointer on the function provided by the PMWC component instance to get the phase current.
*
* This type is needed because the actual function to use can change at run-time
* (See PWMC_Handle::pFctGetPhaseCurrents).
*
*/
typedef void (*PWMC_GetPhaseCurr_Cb_t)(PWMC_Handle_t *pHandle, ab_t *Iab);
/**
* @brief Pointer on the function provided by the PMWC component instance to set low sides ON.
*
* This type is needed because the actual function to use can change at run-time
* (See PWMC_Handle::pFctTurnOnLowSides).
*
*/
typedef void (*PWMC_TurnOnLowSides_Cb_t)(PWMC_Handle_t *pHandle, const uint32_t ticks);
/**
* @brief Pointer on the function provided by the PMWC component instance to set the reference
* voltage for the over current protection.
*
* This type is needed because the actual function to use can change at run-time
* (See PWMC_Handle::pFctOCPSetReferenceVoltage).
*
*/
typedef void (*PWMC_SetOcpRefVolt_Cb_t)(PWMC_Handle_t *pHandle, uint16_t hDACVref);
/**
* @brief Pointer on the functions provided by the PMWC component instance to set the ADC sampling
* point for each sectors.
*
* This type is needed because the actual function to use can change at run-time. See:
* - PWMC_Handle::pFctSetADCSampPointSect1
* - PWMC_Handle::pFctSetADCSampPointSect2
* - PWMC_Handle::pFctSetADCSampPointSect3
* - PWMC_Handle::pFctSetADCSampPointSect4
* - PWMC_Handle::pFctSetADCSampPointSect5
* - PWMC_Handle::pFctSetADCSampPointSect6
*
*/
typedef uint16_t (*PWMC_SetSampPointSectX_Cb_t)(PWMC_Handle_t *pHandle);
/**
* @brief Pointer on the function provided by the PMWC component instance to set the PWM duty cycle
* in RL detection mode.
*
* This type is needed because the actual function to use can change at run-time
* (See PWMC_Handle::pFctRLDetectionModeSetDuty).
*
*/
typedef uint16_t (*PWMC_RLDetectSetDuty_Cb_t)(PWMC_Handle_t *pHandle, uint16_t hDuty);
/**
* @brief Pointer on the function provided by the PMWC component instance to set the calibrated offsets
* in RL detection mode.
*
* This type is needed because the actual function to use can change at run-time
* (See PWMC_Handle::pFctSetOffsetCalib).
*
*/
typedef void (*PWMC_SetOffsetCalib_Cb_t)(PWMC_Handle_t *pHandle, PolarizationOffsets_t *offsets);
/**
* @brief Pointer on the function provided by the PMWC component instance to get the calibrated offsets
* in RL detection mode.
*
* This type is needed because the actual function to use can change at run-time
*/
typedef void (*PWMC_GetOffsetCalib_Cb_t)(PWMC_Handle_t *pHandle, PolarizationOffsets_t *offsets);
/**
* @brief This structure is used to handle the data of an instance of the PWM & Current Feedback component
*
*/
struct PWMC_Handle
{
/** @{ */
PWMC_GetPhaseCurr_Cb_t
pFctGetPhaseCurrents; /**< Pointer on the function the component instance uses to retrieve phase currents. */
PWMC_Generic_Cb_t
pFctSwitchOffPwm; /**< Pointer on the function the component instance uses to switch PWM off. */
PWMC_Generic_Cb_t
pFctSwitchOnPwm; /**< Pointer on the function the component instance uses to switch PWM on. */
PWMC_Generic_Cb_t
pFctCurrReadingCalib; /**< Pointer on the fct the component instance uses to calibrate the current reading ADC(s). */
PWMC_TurnOnLowSides_Cb_t
pFctTurnOnLowSides; /**< Pointer on the function the component instance uses to turn low sides on. */
PWMC_SetSampPointSectX_Cb_t
pFctSetADCSampPointSectX; /**< Pointer on the function the component instance uses to set the ADC sampling point. */
PWMC_SetOcpRefVolt_Cb_t
pFctOCPSetReferenceVoltage; /**< Pointer on the fct the component instance uses to set the over current ref voltage. */
PWMC_Generic_Cb_t
pFctRLDetectionModeEnable; /**< Pointer on the function the component instance uses to enable RL detection mode. */
PWMC_Generic_Cb_t
pFctRLDetectionModeDisable; /**< Pointer on the function the component instance uses to disable RL detection mode. */
PWMC_RLDetectSetDuty_Cb_t
pFctRLDetectionModeSetDuty; /**< Pointer on the fct the component instance uses to set the PWM duty cycle in RL
detection mode. */
PWMC_Generic_Cb_t
pFctRLTurnOnLowSidesAndStart; /**< Pointer on the function the component instance uses to turn on low side and start. */
PWMC_SetOffsetCalib_Cb_t
pFctSetOffsetCalib; /**< Pointer on the fct the component instance uses to set the calibrated offsets. */
PWMC_GetOffsetCalib_Cb_t
pFctGetOffsetCalib; /**< Pointer on the fct the component instance uses to get the calibrated offsets. */
/** @} */
int32_t LPFIqBuf; /**< Low Pass Filter buffer used for averaged @f$ I_q @f$ value computation. */
int32_t LPFIdBuf; /**< Low Pass Filter Buffer used for averaged @f$ I_d @f$ value computation. */
GPIO_TypeDef * pwm_en_u_port; /*!< Channel 1N (low side) GPIO output */
GPIO_TypeDef * pwm_en_v_port; /*!< Channel 2N (low side) GPIO output*/
GPIO_TypeDef * pwm_en_w_port; /*!< Channel 3N (low side) GPIO output */
uint16_t pwm_en_u_pin; /*!< Channel 1N (low side) GPIO output pin. */
uint16_t pwm_en_v_pin; /*!< Channel 2N (low side) GPIO output pin. */
uint16_t pwm_en_w_pin; /*!< Channel 3N (low side) GPIO output pin. */
uint16_t hT_Sqrt3; /**< Constant used by PWM algorithm (@f$\sqrt{3}@f$). */
uint16_t CntPhA; /**< PWM Duty cycle for phase A. */
uint16_t CntPhB; /**< PWM Duty cycle for phase B. */
uint16_t CntPhC; /**< PWM Duty cycle for phase C. */
uint16_t SWerror; /**< Contains status about SW error. */
uint16_t lowDuty;
uint16_t midDuty;
uint16_t highDuty;
uint16_t HighDutyStored; /**< Discontinuous PWM Store current Highest Duty for recovering. */
uint16_t OffCalibrWaitTimeCounter; /**< Counter to wait fixed time before motor
current measurement offset calibration. */
int16_t Ia; /**< Last @f$I_{a}@f$ measurement. */
int16_t Ib; /**< Last @f$I_{b}@f$ measurement. */
int16_t Ic; /**< Last @f$I_{c}@f$ measurement. */
int16_t IaEst; /**< Estimated @f$I_{a}@f$ based on averaged @f$ I_q @f$,@f$ I_d @f$ values and used when @f$I_{a}@f$ current is not available. */
int16_t IbEst; /**< Estimated @f$I_{b}@f$ based on averaged @f$ I_q @f$,@f$ I_d @f$ values and used when @f$I_{b}@f$ current is not available. */
int16_t IcEst; /**< Estimated @f$I_{c}@f$ based on averaged @f$ I_q @f$,@f$ I_d @f$ values and used when @f$I_{c}@f$ current is not available. */
int16_t LPFIqd_const; /**< Low pass filter constant (averaging coeficient). */
uint16_t DTTest; /**< Reserved. */
uint16_t PWMperiod; /**< PWM period expressed in timer clock cycles unit:
* @f$hPWMPeriod = TimerFreq_{CLK} / F_{PWM}@f$ */
uint16_t DTCompCnt; /**< Half of Dead time expressed
* in timer clock cycles unit:
* @f$hDTCompCnt = (DT_s \cdot TimerFreq_{CLK})/2@f$ */
uint16_t Ton; /**< Reserved. */
uint16_t Toff; /**< Reserved. */
uint8_t Motor; /**< Motor reference number. */
uint8_t AlignFlag; /**< Phase current 0 is reliable, 1 is not. */
uint8_t Sector; /**< Space vector sector number. */
LowSideOutputsFunction_t LowSideOutputs; /*!< Low side or enabling signals generation method are defined here. */
bool TurnOnLowSidesAction; /**< True if TurnOnLowSides action is active,
false otherwise. */
bool DPWM_Mode; /**< Discontinuous PWM mode activation. */
bool RLDetectionMode; /**< True if enabled, false if disabled. */
bool offsetCalibStatus; /**< True if offset calibration completed, false otherwise. */
bool OverCurrentFlag; /* This flag is set when an overcurrent occurs.*/
bool OverVoltageFlag; /* This flag is set when an overvoltage occurs.*/
bool driverProtectionFlag; /* This flag is set when a driver protection occurs.*/
bool BrakeActionLock; /* This flag is set to avoid that brake action is interrupted.*/
volatile bool useEstCurrent; /**< Estimated current flag. */
bool SingleShuntTopology; /*!< This flag is set when Single Shunt topology is used */
};
/**
* @brief Current reading calibration definition.
*/
typedef enum
{
CRC_START, /**< Initializes the current reading calibration. */
CRC_EXEC /**< Executes the current reading calibration. */
} CRCAction_t;
/* Returns the phase current of the motor as read by the ADC (in s16A unit). */
void PWMC_GetPhaseCurrents(PWMC_Handle_t *pHandle, ab_t *Iab);
/* Converts input voltages @f$ V_{\alpha} @f$ and @f$ V_{\beta} @f$ into PWM duty cycles
* and feed them to the inverter. */
uint16_t PWMC_SetPhaseVoltage(PWMC_Handle_t *pHandle, alphabeta_t Valfa_beta);
/* Switches PWM generation off, inactivating the outputs. */
void PWMC_SwitchOffPWM(PWMC_Handle_t *pHandle);
/* Enables PWM generation on the proper Timer peripheral. */
void PWMC_SwitchOnPWM(PWMC_Handle_t *pHandle);
/* Calibrates ADC current conversions by reading the offset voltage
* present on ADC pins when no motor current is flowing in. */
bool PWMC_CurrentReadingCalibr(PWMC_Handle_t *pHandle, CRCAction_t action);
/* Switches power stage Low Sides transistors on. */
void PWMC_TurnOnLowSides(PWMC_Handle_t *pHandle, uint32_t ticks);
/* Sets the calibrated @p offsets for each of the phases in the @p pHandle handler. In case
* of single shunt only phase A is relevant. */
void PWMC_SetOffsetCalib(PWMC_Handle_t *pHandle, PolarizationOffsets_t *offsets);
/* Gets the calibrated @p offsets for each of the phases in the @p pHandle handler. In case
* of single shunt only phase A is relevant. */
void PWMC_GetOffsetCalib(PWMC_Handle_t *pHandle, PolarizationOffsets_t *offsets);
/* Manages HW overcurrent protection. */
void *PWMC_OCP_Handler(PWMC_Handle_t *pHandle);
/* Manages driver protection. */
void *PWMC_DP_Handler(PWMC_Handle_t *pHandle);
/* Manages HW overvoltage protection. */
void *PWMC_OVP_Handler(PWMC_Handle_t *pHandle, TIM_TypeDef *TIMx);
/* Checks if a fault (OCP, DP or OVP) occurred since last call. */
uint16_t PWMC_IsFaultOccurred(PWMC_Handle_t *pHandle);
/* Sets the over current threshold through the DAC reference voltage. */
void PWMC_OCPSetReferenceVoltage(PWMC_Handle_t *pHandle, uint16_t hDACVref);
/* Retrieves the satus of TurnOnLowSides action. */
bool PWMC_GetTurnOnLowSidesAction(const PWMC_Handle_t *pHandle);
/* Enables Discontinuous PWM mode using the @p pHandle PWMC component. */
void PWMC_DPWM_ModeEnable(PWMC_Handle_t *pHandle);
/* Disables Discontinuous PWM mode using the @p pHandle PWMC component. */
void PWMC_DPWM_ModeDisable(PWMC_Handle_t *pHandle);
/* Returns the status of the Discontinuous PWM Mode stored in the @p pHandle PWMC component. */
bool PWMC_GetDPWM_Mode(PWMC_Handle_t *pHandle);
/* Enables the RL detection mode by calling the function in @p pHandle PWMC component. */
void PWMC_RLDetectionModeEnable(PWMC_Handle_t *pHandle);
/* Disables the RL detection mode by calling the function in @p pHandle PWMC component. */
void PWMC_RLDetectionModeDisable(PWMC_Handle_t *pHandle);
/* Sets the PWM duty cycle to apply in the RL Detection mode. */
uint16_t PWMC_RLDetectionModeSetDuty(PWMC_Handle_t *pHandle, uint16_t hDuty);
/* Turns on low sides switches and starts ADC triggerin. */
void PWMC_RLTurnOnLowSidesAndStart(PWMC_Handle_t *pHandle);
/* Sets the aligned motor flag. */
void PWMC_SetAlignFlag(PWMC_Handle_t *pHandle, uint8_t flag);
/* Sets the Callback that the PWMC component shall invoke to get phases current. */
void PWMC_RegisterGetPhaseCurrentsCallBack(PWMC_GetPhaseCurr_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Sets the Callback that the PWMC component shall invoke to switch PWM generation off. */
void PWMC_RegisterSwitchOffPwmCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Sets the Callback that the PWMC component shall invoke to switch PWM generation on. */
void PWMC_RegisterSwitchonPwmCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Sets the Callback that the PWMC component shall invoke to execute a calibration of the current sensing system. */
void PWMC_RegisterReadingCalibrationCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Sets the Callback that the PWMC component shall invoke to turn low sides on. */
void PWMC_RegisterTurnOnLowSidesCallBack(PWMC_TurnOnLowSides_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Sets the Callback that the PWMC component shall invoke to compute ADC sampling point. */
void PWMC_RegisterSampPointSectXCallBack(PWMC_SetSampPointSectX_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Sets the Callback that the PWMC component shall invoke to set the reference voltage for the overcurrent
* protection. */
void PWMC_RegisterOCPSetRefVoltageCallBack(PWMC_SetOcpRefVolt_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Sets the Callback that the PWMC component shall invoke to enable the R/L detection mode. */
void PWMC_RegisterRLDetectionModeEnableCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Sets the Callback that the PWMC component shall invoke to disable the R/L detection mode. */
void PWMC_RegisterRLDetectionModeDisableCallBack(PWMC_Generic_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Sets the Callback that the PWMC component shall invoke to set the duty cycle for the R/L detection mode */
void PWMC_RegisterRLDetectionModeSetDutyCallBack(PWMC_RLDetectSetDuty_Cb_t pCallBack, PWMC_Handle_t *pHandle);
/* Used to clear variables in CPWMC. */
void PWMC_Clear(PWMC_Handle_t *pHandle);
/* Converts input currents components Iqd into estimated currents Ia, Ib and Ic. */
void PWMC_CalcPhaseCurrentsEst(PWMC_Handle_t *pHandle, qd_t Iqd, int16_t hElAngledpp);
/* Converts input voltage components @f$ V_{\alpha} @f$ and @f$ V_{\beta} @f$ into duty cycles
* and feed them to the inverter with overmodulation function. */
uint16_t PWMC_SetPhaseVoltage_OVM(PWMC_Handle_t *pHandle, alphabeta_t Valfa_beta);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* PWMNCURRFDBK_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 18,081 | C | 48.135869 | 175 | 0.631381 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/register_interface.h |
/**
******************************************************************************
* @file register_interface.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides firmware registers definitions used by MCP protocol
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#ifndef REGISTER_INTERFACE_H
#define REGISTER_INTERFACE_H
#include "mcp.h"
#include "mc_type.h"
#include "mc_parameters.h"
/*
MCP_ID definition :
| Element Identifier 10 bits | Type | Motor #|
| | | |
|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
Type definition :
0 Reserved
1 8-bit data
2 16-bit data
3 32-bit data
4 Character string
5 Raw Structure
6 Reserved
7 Reserved
*/
#define MCP_ID_SIZE 2U /* Number of byte */
#define MCP_ID_SIZE_16B 1U /* Number of 16bits word */
#define ELT_IDENTIFIER_POS 6U
#define TYPE_POS 3U
#define TYPE_MASK 0x38U
#define MOTOR_MASK 0x7U
#define REG_MASK 0xFFF8U
#define EXTRACT_MOTORID(dataID) ((dataID -1U) & MOTOR_MASK)
#define TYPE_DATA_SEG_END (0U << TYPE_POS)
#define TYPE_DATA_8BIT (1U << TYPE_POS)
#define TYPE_DATA_16BIT (2U << TYPE_POS)
#define TYPE_DATA_32BIT (3U << TYPE_POS)
#define TYPE_DATA_STRING (4U << TYPE_POS)
#define TYPE_DATA_RAW (5U << TYPE_POS)
#define TYPE_DATA_FLAG (6U << TYPE_POS)
#define TYPE_DATA_SEG_BEG (7U << TYPE_POS)
/* TYPE_DATA_8BIT registers definition */
#define MC_REG_STATUS ((1U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_CONTROL_MODE ((2U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_RUC_STAGE_NBR ((3U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_PFC_STATUS ((13U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_PFC_ENABLED ((14U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_SC_CHECK ((15U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_SC_STATE ((16U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_SC_STEPS ((17U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_SC_PP ((18U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_SC_FOC_REP_RATE ((19U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_SC_COMPLETED ((20U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_POSITION_CTRL_STATE ((21U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_POSITION_ALIGN_STATE ((22U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_HT_STATE ((23U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_HT_PROGRESS ((24U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_HT_PLACEMENT ((25U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_HT_MECH_WANTED_DIRECTION ((26U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_FAST_DEMAG ((27U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_QUASI_SYNCH ((28U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
#define MC_REG_PB_CHARACTERIZATION ((29U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT)
/* TYPE_DATA_16BIT registers definition */
#define MC_REG_SPEED_KP ((2U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_SPEED_KI ((3U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_SPEED_KD ((4U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_Q_KP ((6U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_Q_KI ((7U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_Q_KD ((8U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_D_KP ((10U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_D_KI ((11U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_D_KD ((12U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_C1 ((13U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_C2 ((14U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOCORDIC_C1 ((15U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOCORDIC_C2 ((16U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_KI ((17U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_KP ((18U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FLUXWK_KP ((19U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FLUXWK_KI ((20U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FLUXWK_BUS ((21U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_BUS_VOLTAGE ((22U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_HEATS_TEMP ((23U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_DAC_OUT1 ((25U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_DAC_OUT2 ((26U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_DAC_OUT3 ((27 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FLUXWK_BUS_MEAS ((30U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_A ((31U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_B ((32U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_ALPHA_MEAS ((33U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_BETA_MEAS ((34U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_Q_MEAS ((35U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_D_MEAS ((36U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_Q_REF ((37U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_D_REF ((38U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_V_Q ((39U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_V_D ((40U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_V_ALPHA ((41U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_V_BETA ((42U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_ENCODER_EL_ANGLE ((43 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_ENCODER_SPEED ((44 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_EL_ANGLE ((45U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_ROT_SPEED ((46U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_I_ALPHA ((47U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_I_BETA ((48U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_BEMF_ALPHA ((49U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_BEMF_BETA ((50U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOCORDIC_EL_ANGLE ((51 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOCORDIC_ROT_SPEED ((52 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOCORDIC_I_ALPHA ((53 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOCORDIC_I_BETA ((54 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOCORDIC_BEMF_ALPHA ((55 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOCORDIC_BEMF_BETA ((56 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_DAC_USER1 ((57U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_DAC_USER2 ((58U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_HALL_EL_ANGLE ((59 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_HALL_SPEED ((60 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FF_VQ ((62U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FF_VD ((63U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FF_VQ_PIOUT ((64U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FF_VD_PIOUT ((65U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_DCBUS_REF ((66U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_DCBUS_MEAS ((67U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_ACBUS_FREQ ((68U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_ACBUS_RMS ((69U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_I_KP ((70U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_I_KI ((71U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_I_KD ((72U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_V_KP ((73U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_V_KI ((74U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_V_KD ((75U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_STARTUP_DURATION ((76U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_SC_PWM_FREQUENCY ((77 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_POSITION_KP ((78 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_POSITION_KI ((79 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_POSITION_KD ((80 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_SPEED_KP_DIV ((81 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_SPEED_KI_DIV ((82 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_SPEED_KD_DIV ((83 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_D_KP_DIV ((84 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_D_KI_DIV ((85 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_D_KD_DIV ((86 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_Q_KP_DIV ((87 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_Q_KI_DIV ((88 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_I_Q_KD_DIV ((89 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_POSITION_KP_DIV ((90 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_POSITION_KI_DIV ((91 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_POSITION_KD_DIV ((92 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_I_KP_DIV ((93 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_I_KI_DIV ((94 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_I_KD_DIV ((95 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_V_KP_DIV ((96 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_V_KI_DIV ((97 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PFC_V_KD_DIV ((98 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_KI_DIV ((99 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STOPLL_KP_DIV ((100 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FLUXWK_KP_DIV ((101 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FLUXWK_KI_DIV ((102 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_STARTUP_CURRENT_REF ((105 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_PULSE_VALUE ((106 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_FOC_VQREF ((107 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_BEMF_ZCR ((108 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_BEMF_U ((109 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_BEMF_V ((110 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_BEMF_W ((111 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT)
#define MC_REG_OVERVOLTAGETHRESHOLD ((112U << ELT_IDENTIFIER_POS)| TYPE_DATA_16BIT )
#define MC_REG_UNDERVOLTAGETHRESHOLD ((113U << ELT_IDENTIFIER_POS)| TYPE_DATA_16BIT )
/* TYPE_DATA_32BIT registers definition */
#define MC_REG_FAULTS_FLAGS ((0 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SPEED_MEAS ((1 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SPEED_REF ((2 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_STOPLL_EST_BEMF ((3 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT) /* To check shifted by >> 16*/
#define MC_REG_STOPLL_OBS_BEMF ((4 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT) /* To check shifted by >> 16*/
#define MC_REG_STOCORDIC_EST_BEMF ((5 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT) /* To check shifted by >> 16*/
#define MC_REG_STOCORDIC_OBS_BEMF ((6 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT) /* To check shifted by >> 16*/
#define MC_REG_FF_1Q ((7 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT) /* To check shifted by >> 16*/
#define MC_REG_FF_1D ((8 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT) /* To check shifted by >> 16*/
#define MC_REG_FF_2 ((9 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT) /* To check shifted by >> 16*/
#define MC_REG_PFC_FAULTS ((40 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_CURRENT_POSITION ((41 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_RS ((91 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_LS ((92 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_KE ((93 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_VBUS ((94 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_MEAS_NOMINALSPEED ((95 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_CURRENT ((96 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_SPDBANDWIDTH ((97 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_LDLQRATIO ((98 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_NOMINAL_SPEED ((99 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_CURRBANDWIDTH ((100 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_J ((101 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_F ((102 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_MAX_CURRENT ((103 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_STARTUP_SPEED ((104 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_SC_STARTUP_ACC ((105 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_RESISTOR_OFFSET ((116 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_MOTOR_POWER ((109 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT)
#define MC_REG_FW_NAME ((0U << ELT_IDENTIFIER_POS) | TYPE_DATA_STRING)
#define MC_REG_CTRL_STAGE_NAME ((1U << ELT_IDENTIFIER_POS) | TYPE_DATA_STRING)
#define MC_REG_PWR_STAGE_NAME ((2U << ELT_IDENTIFIER_POS) | TYPE_DATA_STRING)
#define MC_REG_MOTOR_NAME ((3U << ELT_IDENTIFIER_POS) | TYPE_DATA_STRING)
#define MC_REG_GLOBAL_CONFIG ((0U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_MOTOR_CONFIG ((1U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_APPLICATION_CONFIG ((2U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_FOCFW_CONFIG ((3U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_SCALE_CONFIG ((4U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_SPEED_RAMP ((6U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_TORQUE_RAMP ((7U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_REVUP_DATA ((8U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW) /* Configure all steps*/
#define MC_REG_CURRENT_REF ((13U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_POSITION_RAMP ((14U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_ASYNC_UARTA ((20U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_ASYNC_UARTB ((21U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_ASYNC_STLNK ((22U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_HT_HEW_PINS ((28U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_HT_CONNECTED_PINS ((29U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_HT_PHASE_SHIFT ((30U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_BEMF_ADC_CONFIG ((31U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
#define MC_REG_BEMF_ONTIME_ADC_CONFIG ((32U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW)
uint8_t RI_SetRegisterGlobal(uint16_t regID, uint8_t typeID, uint8_t *data, uint16_t *size, int16_t dataAvailable);
uint8_t RI_SetRegisterMotor1(uint16_t regID, uint8_t typeID,uint8_t *data, uint16_t *size, int16_t dataAvailable);
uint8_t RI_GetRegisterGlobal(uint16_t regID, uint8_t typeID, uint8_t * data, uint16_t *size, int16_t freeSpace);
uint8_t RI_GetRegisterMotor1(uint16_t regID, uint8_t typeID, uint8_t * data, uint16_t *size, int16_t freeSpace);
uint8_t RI_MovString(const char_t * srcString, char_t * destString, uint16_t *size, int16_t maxSize);
uint8_t RI_GetPtrReg(uint16_t dataID, void **dataPtr);
uint8_t RI_GetIDSize(uint16_t dataID);
#endif /* REGISTER_INTERFACE_H */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 18,797 | C | 70.204545 | 117 | 0.584029 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/network_data.h | /**
******************************************************************************
* @file network_data.h
* @author AST Embedded Analytics Research Platform
* @date Tue Jan 16 16:02:48 2024
* @brief AI Tool Automatic Code Generator for Embedded NN computing
******************************************************************************
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
******************************************************************************
*/
#ifndef NETWORK_DATA_H
#define NETWORK_DATA_H
#pragma once
#include "network_config.h"
#include "network_data_params.h"
AI_DEPRECATED
#define AI_NETWORK_DATA_ACTIVATIONS(ptr_) \
ai_network_data_activations_buffer_get(AI_HANDLE_PTR(ptr_))
AI_DEPRECATED
#define AI_NETWORK_DATA_WEIGHTS(ptr_) \
ai_network_data_weights_buffer_get(AI_HANDLE_PTR(ptr_))
AI_API_DECLARE_BEGIN
extern const ai_u64 s_network_weights_array_u64[5605];
/*!
* @brief Get network activations buffer initialized struct.
* @ingroup network_data
* @param[in] ptr a pointer to the activations array storage area
* @return an ai_buffer initialized struct
*/
AI_DEPRECATED
AI_API_ENTRY
ai_buffer ai_network_data_activations_buffer_get(const ai_handle ptr);
/*!
* @brief Get network weights buffer initialized struct.
* @ingroup network_data
* @param[in] ptr a pointer to the weights array storage area
* @return an ai_buffer initialized struct
*/
AI_DEPRECATED
AI_API_ENTRY
ai_buffer ai_network_data_weights_buffer_get(const ai_handle ptr);
/*!
* @brief Get network weights array pointer as a handle ptr.
* @ingroup network_data
* @return a ai_handle pointer to the weights array
*/
AI_DEPRECATED
AI_API_ENTRY
ai_handle ai_network_data_weights_get(void);
/*!
* @brief Get network params configuration data structure.
* @ingroup network_data
* @return true if a valid configuration is present, false otherwise
*/
AI_API_ENTRY
ai_bool ai_network_data_params_get(ai_network_params* params);
AI_API_DECLARE_END
#endif /* NETWORK_DATA_H */
| 2,262 | C | 26.26506 | 80 | 0.655615 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/stm32g4xx_it.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g4xx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32G4xx_IT_H
#define __STM32G4xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void TIM5_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32G4xx_IT_H */
| 1,636 | C | 26.745762 | 80 | 0.433985 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/adc.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file adc.h
* @brief This file contains all the function prototypes for
* the adc.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ADC_H__
#define __ADC_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern ADC_HandleTypeDef hadc1;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_ADC1_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __ADC_H__ */
| 1,293 | C | 23.415094 | 80 | 0.482599 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_perf.h | /**
******************************************************************************
* @file mc_perf.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief Execution time measurement definitions
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#ifndef MC_PERF_H
#define MC_PERF_H
typedef enum
{
MEASURE_TSK_HighFrequencyTaskM1,
MEASURE_TSK_MediumFrequencyTaskM1,
/* Others functions to measure to be added here. */
} MC_PERF_FUNCTIONS_LIST_t;
/* Define max number of traces according to the list defined in MC_PERF_FUNCTIONS_LIST_t */
#define MC_PERF_NB_TRACES 2U
/* DWT (Data Watchpoint and Trace) registers, only exists on ARM Cortex with a DWT unit */
/* The DWT is usually implemented in Cortex-M3 or higher, but not on Cortex-M0(+) (ie not present on G0) */
typedef struct
{
uint32_t StartMeasure;
uint32_t DeltaTimeInCycle;
uint32_t min;
uint32_t max;
} Perf_Handle_t;
typedef struct
{
bool BG_Task_OnGoing;
uint32_t AccHighFreqTasksCnt;
Perf_Handle_t MC_Perf_TraceLog[MC_PERF_NB_TRACES];
} MC_Perf_Handle_t;
void MC_Perf_Measure_Init(MC_Perf_Handle_t *pHandle);
void MC_Perf_Clear(MC_Perf_Handle_t *pHandle,uint8_t bMotor);
void MC_Perf_Measure_Start(MC_Perf_Handle_t *pHandle, uint8_t i);
void MC_BG_Perf_Measure_Start(MC_Perf_Handle_t *pHandle, uint8_t i);
void MC_Perf_Measure_Stop(MC_Perf_Handle_t *pHandle, uint8_t i);
void MC_BG_Perf_Measure_Stop(MC_Perf_Handle_t *pHandle, uint8_t i);
float_t MC_Perf_GetCPU_Load(const MC_Perf_Handle_t *pHandle);
float_t MC_Perf_GetMaxCPU_Load(const MC_Perf_Handle_t *pHandle);
float_t MC_Perf_GetMinCPU_Load(const MC_Perf_Handle_t *pHandle);
#endif /* MC_PERF_H */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 2,284 | C | 35.269841 | 107 | 0.620841 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/gpio.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file gpio.h
* @brief This file contains all the function prototypes for
* the gpio.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __GPIO_H__
#define __GPIO_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_GPIO_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ GPIO_H__ */
| 1,264 | C | 24.3 | 80 | 0.476266 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mcp_config.h |
/**
******************************************************************************
* @file mcp_config.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides configuration definition of the MCP protocol
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#ifndef MCP_CONFIG_H
#define MCP_CONFIG_H
#include "mcp.h"
#include "aspep.h"
#include "mcpa.h"
#define USARTA USART2
#define DMA_RX_A DMA1
#define DMA_TX_A DMA1
#define DMACH_RX_A LL_DMA_CHANNEL_1
#define DMACH_TX_A LL_DMA_CHANNEL_2
#define MCP_USER_CALLBACK_MAX 2U
#define MCP_TX_SYNC_PAYLOAD_MAX 128U
#define MCP_RX_SYNC_PAYLOAD_MAX 128U
#define MCP_TX_SYNCBUFFER_SIZE (MCP_TX_SYNC_PAYLOAD_MAX+ASPEP_HEADER_SIZE+ASPEP_DATACRC_SIZE)
#define MCP_RX_SYNCBUFFER_SIZE (MCP_RX_SYNC_PAYLOAD_MAX+ASPEP_DATACRC_SIZE) // ASPEP_HEADER_SIZE is not stored in the RX buffer.
#define MCP_TX_ASYNC_PAYLOAD_MAX_A 2048U
#define MCP_TX_ASYNCBUFFER_SIZE_A (MCP_TX_ASYNC_PAYLOAD_MAX_A+ASPEP_HEADER_SIZE+ASPEP_DATACRC_SIZE)
#define MCPA_OVER_UARTA_STREAM 10
extern ASPEP_Handle_t aspepOverUartA;
extern MCP_Handle_t MCP_Over_UartA;
extern MCPA_Handle_t MCPA_UART_A;
extern MCP_user_cb_t MCP_UserCallBack[MCP_USER_CALLBACK_MAX];
#endif /* MCP_CONFIG_H */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 1,844 | C | 33.166666 | 128 | 0.613341 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/network_data_params.h | /**
******************************************************************************
* @file network_data_params.h
* @author AST Embedded Analytics Research Platform
* @date Tue Jan 16 16:02:48 2024
* @brief AI Tool Automatic Code Generator for Embedded NN computing
******************************************************************************
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
******************************************************************************
*/
#ifndef NETWORK_DATA_PARAMS_H
#define NETWORK_DATA_PARAMS_H
#pragma once
#include "ai_platform.h"
/*
#define AI_NETWORK_DATA_WEIGHTS_PARAMS \
(AI_HANDLE_PTR(&ai_network_data_weights_params[1]))
*/
#define AI_NETWORK_DATA_CONFIG (NULL)
#define AI_NETWORK_DATA_ACTIVATIONS_SIZES \
{ 1048, }
#define AI_NETWORK_DATA_ACTIVATIONS_SIZE (1048)
#define AI_NETWORK_DATA_ACTIVATIONS_COUNT (1)
#define AI_NETWORK_DATA_ACTIVATION_1_SIZE (1048)
#define AI_NETWORK_DATA_WEIGHTS_SIZES \
{ 44840, }
#define AI_NETWORK_DATA_WEIGHTS_SIZE (44840)
#define AI_NETWORK_DATA_WEIGHTS_COUNT (1)
#define AI_NETWORK_DATA_WEIGHT_1_SIZE (44840)
#define AI_NETWORK_DATA_ACTIVATIONS_TABLE_GET() \
(&g_network_activations_table[1])
extern ai_handle g_network_activations_table[1 + 2];
#define AI_NETWORK_DATA_WEIGHTS_TABLE_GET() \
(&g_network_weights_table[1])
extern ai_handle g_network_weights_table[1 + 2];
#endif /* NETWORK_DATA_PARAMS_H */
| 1,719 | C | 27.196721 | 80 | 0.596859 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/crc.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file crc.h
* @brief This file contains all the function prototypes for
* the crc.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CRC_H__
#define __CRC_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern CRC_HandleTypeDef hcrc;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_CRC_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __CRC_H__ */
| 1,291 | C | 23.377358 | 80 | 0.481797 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/constants_ai.h | /**
******************************************************************************
* @file constants.h
* @author X-CUBE-AI C code generator
* @brief AI constants definitions
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CONSTANTS_H
#define __CONSTANTS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Constants definitions ------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif /*__constants_ai_h_H */
| 975 | C | 30.48387 | 93 | 0.44 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/stm32g4xx_hal_conf.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g4xx_hal_conf.h
* @author MCD Application Team
* @brief HAL configuration file
******************************************************************************
* @attention
*
* Copyright (c) 2019 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32G4xx_HAL_CONF_H
#define STM32G4xx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
/*#define HAL_COMP_MODULE_ENABLED */
#define HAL_CORDIC_MODULE_ENABLED
#define HAL_CRC_MODULE_ENABLED
/*#define HAL_CRYP_MODULE_ENABLED */
/*#define HAL_DAC_MODULE_ENABLED */
/*#define HAL_FDCAN_MODULE_ENABLED */
/*#define HAL_FMAC_MODULE_ENABLED */
/*#define HAL_HRTIM_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
/*#define HAL_I2C_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_NAND_MODULE_ENABLED */
/*#define HAL_NOR_MODULE_ENABLED */
/*#define HAL_OPAMP_MODULE_ENABLED */
/*#define HAL_PCD_MODULE_ENABLED */
/*#define HAL_QSPI_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */
/*#define HAL_SAI_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
/*#define HAL_SRAM_MODULE_ENABLED */
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
/* ########################## Register Callbacks selection ############################## */
/**
* @brief This is the list of modules where register callback can be used
*/
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U
#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U
#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U
#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U
#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U
#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U
#define USE_HAL_UART_REGISTER_CALLBACKS 0U
#define USE_HAL_USART_REGISTER_CALLBACKS 0U
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE (24000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG.
* This internal oscillator is mainly dedicated to provide a high precision clock to
* the USB peripheral by means of a special Clock Recovery System (CRS) circuitry.
* When the CRS is not used, the HSI48 RC oscillator runs on it default frequency
* which is subject to manufacturing process variations.
*/
#if !defined (HSI48_VALUE)
#define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz.
The real value my vary depending on manufacturing process variations.*/
#endif /* HSI48_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
/*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations in voltage and temperature.*/
#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/
#endif /* LSI_VALUE */
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
/**
* @brief External clock source for I2S and SAI peripherals
* This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source
* frequency, this source is inserted directly through I2S_CKIN pad.
*/
#if !defined (EXTERNAL_CLOCK_VALUE)
#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/
#endif /* EXTERNAL_CLOCK_VALUE */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY (4UL) /*!< tick interrupt priority (lowest by default) */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 1U
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1U */
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 0U
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32g4xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32g4xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32g4xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32g4xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32g4xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED
#include "stm32g4xx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CORDIC_MODULE_ENABLED
#include "stm32g4xx_hal_cordic.h"
#endif /* HAL_CORDIC_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32g4xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_CRYP_MODULE_ENABLED
#include "stm32g4xx_hal_cryp.h"
#endif /* HAL_CRYP_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32g4xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32g4xx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_FDCAN_MODULE_ENABLED
#include "stm32g4xx_hal_fdcan.h"
#endif /* HAL_FDCAN_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32g4xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_FMAC_MODULE_ENABLED
#include "stm32g4xx_hal_fmac.h"
#endif /* HAL_FMAC_MODULE_ENABLED */
#ifdef HAL_HRTIM_MODULE_ENABLED
#include "stm32g4xx_hal_hrtim.h"
#endif /* HAL_HRTIM_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32g4xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32g4xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32g4xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32g4xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_LPTIM_MODULE_ENABLED
#include "stm32g4xx_hal_lptim.h"
#endif /* HAL_LPTIM_MODULE_ENABLED */
#ifdef HAL_NAND_MODULE_ENABLED
#include "stm32g4xx_hal_nand.h"
#endif /* HAL_NAND_MODULE_ENABLED */
#ifdef HAL_NOR_MODULE_ENABLED
#include "stm32g4xx_hal_nor.h"
#endif /* HAL_NOR_MODULE_ENABLED */
#ifdef HAL_OPAMP_MODULE_ENABLED
#include "stm32g4xx_hal_opamp.h"
#endif /* HAL_OPAMP_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32g4xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32g4xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_QSPI_MODULE_ENABLED
#include "stm32g4xx_hal_qspi.h"
#endif /* HAL_QSPI_MODULE_ENABLED */
#ifdef HAL_RNG_MODULE_ENABLED
#include "stm32g4xx_hal_rng.h"
#endif /* HAL_RNG_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32g4xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SAI_MODULE_ENABLED
#include "stm32g4xx_hal_sai.h"
#endif /* HAL_SAI_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32g4xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32g4xx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32g4xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_SRAM_MODULE_ENABLED
#include "stm32g4xx_hal_sram.h"
#endif /* HAL_SRAM_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32g4xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32g4xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32g4xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32g4xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t *file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* STM32G4xx_HAL_CONF_H */
| 12,922 | C | 32.918635 | 118 | 0.648042 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_type.h |
/**
******************************************************************************
* @file mc_type.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief Motor Control SDK global types definitions
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MC_Type
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MC_TYPE_H
#define MC_TYPE_H
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MC_Type Motor Control types
* @{
*/
#include <mc_stm_types.h>
/* char definition to match Misra Dir 4.6 typedefs that indicate size and
* signedness should be used in place ofthe basic numerical types */
typedef int8_t char_t;
#ifndef _MATH
typedef float float_t;
#endif
/** @name Macros to use bit banding capability */
/** @{ */
#define BB_REG_BIT_SET(regAddr,bit_number) *(uint32_t *) (0x42000000+(((uint32_t)regAddr - 0x40000000 )<<5)\
+ (bit_number <<2)) = (uint32_t)(0x1u)
#define BB_REG_BIT_CLR(regAddr,bit_number) (*(uint32_t *) (0x42000000+(((uint32_t)regAddr - 0x40000000)<<5)\
+ (bit_number <<2)) = (uint32_t)(0x0u))
#define BB_REG_BIT_READ(regAddr,bit_number) (*(uint32_t *) (0x42000000+(((uint32_t)regAddr - 0x40000000)<<5)\
+ (bit_number <<2)) )
/** @} */
/** @brief Not initialized pointer */
#define MC_NULL (void *)(0x0)
/** @name Motor identification macros */
/** @{ */
#define M1 (uint8_t)(0x0) /*!< Motor 1.*/
#define M2 (uint8_t)(0x1) /*!< Motor 2.*/
#define M_NONE (uint8_t)(0xFF) /*!< None motor.*/
/** @} */
/**
* @anchor fault_codes
* @name Fault codes
* The symbols below define the codes associated to the faults that the
* Motor Control subsystem can raise.
* @{ */
#define MC_NO_ERROR ((uint16_t)0x0000) /**< @brief No error. */
#define MC_NO_FAULTS ((uint16_t)0x0000) /**< @brief No error. */
#define MC_DURATION ((uint16_t)0x0001) /**< @brief Error: FOC rate to high. */
#define MC_OVER_VOLT ((uint16_t)0x0002) /**< @brief Error: Software over voltage. */
#define MC_UNDER_VOLT ((uint16_t)0x0004) /**< @brief Error: Software under voltage. */
#define MC_OVER_TEMP ((uint16_t)0x0008) /**< @brief Error: Software over temperature. */
#define MC_START_UP ((uint16_t)0x0010) /**< @brief Error: Startup failed. */
#define MC_SPEED_FDBK ((uint16_t)0x0020) /**< @brief Error: Speed feedback. */
#define MC_OVER_CURR ((uint16_t)0x0040) /**< @brief Error: Emergency input (Over current). */
#define MC_SW_ERROR ((uint16_t)0x0080) /**< @brief Software Error. */
#define MC_DP_FAULT ((uint16_t)0x0400) /**< @brief Error Driver protection fault. */
/** @}*/
/** @name Dual motor Frequency comparison definition */
/** @{ */
#define SAME_FREQ 0U
#define HIGHER_FREQ 1U
#define LOWER_FREQ 2U
#define HIGHEST_FREQ 1U
#define LOWEST_FREQ 2U
/** @} */
/** @name Error codes */
/** @{ */
#define MC_SUCCESS ((uint32_t)(0u)) /**< Success. The function executed successfully. */
#define MC_WRONG_STATE_ERROR ((uint32_t)(1u)) /**< The state machine of the motor is not in a suitable state. */
#define MC_NO_POLARIZATION_OFFSETS_ERROR ((uint32_t)(2u)) /**< Polarization offsets are needed but missing */
/** @} */
/** @brief Return type of API functions that return a status */
typedef uint32_t MC_RetStatus_t;
/**
* @brief union type definition for u32 to Float conversion and vice versa
*/
//cstat -MISRAC2012-Rule-19.2
typedef union _FLOAT_U32_
{
uint32_t U32_Val;
float Float_Val;
} FloatToU32;
//cstat +MISRAC2012-Rule-19.2
/**
* @brief Two components q, d type definition
*/
typedef struct
{
int16_t q;
int16_t d;
} qd_t;
/**
* @brief Two components q, d in float type
*/
typedef struct
{
float q;
float d;
} qd_f_t;
/**
* @brief Two components a,b type definition
*/
typedef struct
{
int16_t a;
int16_t b;
} ab_t;
/**
* @brief Two components a,b in float type
*/
typedef struct
{
float a;
float b;
} ab_f_t;
/**
* @brief Two components alpha, beta type definition
*/
typedef struct
{
int16_t alpha;
int16_t beta;
} alphabeta_t;
/* ACIM definitions start */
typedef struct
{
float fS_Component1;
float fS_Component2;
} Signal_Components;
/**
* @brief Two components type definition
*/
typedef struct
{
int16_t qVec_Component1;
int16_t qVec_Component2;
} Vector_s16_Components;
/* ACIM definitions end */
/**
* @brief SensorType_t type definition, it's used in BusVoltageSensor and TemperatureSensor component parameters
* structures to specify whether the sensor is real or emulated by SW.
*/
typedef enum
{
REAL_SENSOR, VIRTUAL_SENSOR
} SensorType_t;
/**
* @brief DOutputState_t type definition, it's used by DOUT_SetOutputState method of DigitalOutput class to specify
* the required output state.
*/
typedef enum
{
INACTIVE, ACTIVE
} DOutputState_t;
/**
* @brief DrivingMode_t type definition, it's used by Bemf_ADC class to specify the driving mode type.
*/
typedef enum
{
VM, /**< @brief Voltage mode. */
CM /**< @brief Current mode. */
} DrivingMode_t;
/**
* @brief Specifies the control modality of the motor.
*/
typedef enum
{
MCM_OBSERVING_MODE = 0, /**< @brief All transistors are opened in order to let the motor spin freely and
* observe Bemf thanks to phase voltage measurements.
*
* Only relevant when HSO is used.
*/
MCM_OPEN_LOOP_VOLTAGE_MODE, /**< @brief Open loop, duty cycle set as reference. */
MCM_OPEN_LOOP_CURRENT_MODE, /**< @brief Open loop, q & d currents set as reference. */
MCM_SPEED_MODE, /**< @brief Closed loop, Speed mode.*/
MCM_TORQUE_MODE, /**< @brief Closed loop, Torque mode.*/
MCM_PROFILING_MODE, /**< @brief FW is configured to execute the motor profiler feature.
*
* Only relevant when HSO is used.
*/
MCM_SHORTED_MODE, /**< @brief Low sides are turned on.
*
* Only relevant when HSO is used.
*/
MCM_POSITION_MODE, /**< @brief Closed loop, sensored position control mode. */
MCM_MODE_NUM /**< @brief Number of modes in enum. */
} MC_ControlMode_t;
/**
* @brief Structure type definition for feed-forward constants tuning.
*/
typedef struct
{
int32_t wConst_1D;
int32_t wConst_1Q;
int32_t wConst_2;
} FF_TuningStruct_t;
/**
* @brief structure type definition for phase offsets setting/getting. In case of single shunt
* only phaseAOffset is relevant.
*/
typedef struct
{
int32_t phaseAOffset;
int32_t phaseBOffset;
int32_t phaseCOffset;
} PolarizationOffsets_t;
/**
* @brief Current references source type, internal or external to FOCDriveClass.
*/
typedef enum
{
INTERNAL, EXTERNAL
} CurrRefSource_t ;
/**
* @brief FOC variables structure.
*/
typedef struct
{ //cstat !MISRAC2012-Dir-4.8
ab_t Iab; /**< @brief Stator current on stator reference frame abc.
*
* @note This field does not exists if HSO is used.
*/
alphabeta_t Ialphabeta; /**< @brief Stator current on stator reference frame alfa-beta.
*
* @note This field does not exists if HSO is used.
*/
qd_t IqdHF; /**< @brief Stator current on stator reference frame alfa-beta.
*
* @note This field does not exists if HSO is used.
*/
qd_t Iqd; /**< @brief Stator current on rotor reference frame qd.
*
* @note This field does not exists if HSO is used.
*/
qd_t Iqdref; /**< @brief Stator current on rotor reference frame qd.
*
* @note This field does not exists if HSO is used.
*/
int16_t UserIdref; /**< @brief User value for the Idref stator current.
*
* @note This field does not exists if HSO is used.
*/
qd_t Vqd; /**< @brief Phase voltage on rotor reference frame qd.
*
* @note This field does not exists if HSO is used.
*/
alphabeta_t Valphabeta; /**< @brief Phase voltage on stator reference frame alpha-beta.
*
* @note This field does not exists if HSO is used.
*/
int16_t hTeref; /**< @brief Reference torque.
*
* @note This field does not exists if HSO is used.
*/
int16_t hElAngle; /**< @brief Electrical angle used for reference frame transformation.
*
* @note This field does not exists if HSO is used.
*/
uint16_t hCodeError; /**< @brief Error Code.
*
* @note This field does not exists if HSO is used.
*/
CurrRefSource_t bDriveInput; /**< @brief Specifies whether the current reference source must be
* #INTERNAL or #EXTERNAL.
*
* @note This field does not exists if HSO is used.
*/
} FOCVars_t, *pFOCVars_t;
/**
* @brief 6step variables structure.
*/
typedef struct
{
uint16_t DutyCycleRef; /**< @brief Reference speed. */
uint16_t hCodeError; /**< @brief error message. */
CurrRefSource_t bDriveInput; /**< @brief It specifies whether the current reference source must be
* #INTERNAL or #EXTERNAL. */
int16_t qElAngle;
} SixStepVars_t, *pSixStepVars_t;
/**
* @brief Low side or enabling signal definition.
*/
typedef enum
{
LS_DISABLED = 0x0U, /**< @brief Low side signals and enabling signals always off.
It is equivalent to DISABLED. */
LS_PWM_TIMER = 0x1U, /**< @brief Low side PWM signals are generated by timer.
It is equivalent to ENABLED. */
ES_GPIO = 0x2U /**< @brief Enabling signals are managed by GPIOs (L6230 mode). */
} LowSideOutputsFunction_t;
/** @name UserInterface related exported definitions. */
/** @{ */
#define OPT_NONE 0x00 /**< @brief No UI option selected. */
#define OPT_COM 0x02 /**< @brief Bit field indicating that the UI uses serial communication. */
#define OPT_DAC 0x04 /**< @brief Bit field indicating that the UI uses real DAC. */
#define OPT_DACT 0x08 /**< @brief Bit field indicating that the UI uses RC Timer DAC. */
#define OPT_DACS 0x10 /**< @brief Bit field indicating that the UI uses SPI communication. */
#define OPT_DACF3 0x40 /**< @brief Bit field indicating that the UI uses DAC for STM32F3. */
#define OPT_DACF072 0x80 /**< @brief Bit field indicating that the UI uses DAC for STM32F072. */
/** @} */
#define MAIN_SCFG_POS (28)
#define AUX_SCFG_POS (24)
#define MAIN_SCFG_VALUE(x) (((x)>>MAIN_SCFG_POS)& ( uint8_t )0x0F)
#define AUX_SCFG_VALUE(x) (((x)>>AUX_SCFG_POS)& ( uint8_t )0x0F)
/** @name PFC related exported definitions */
/** @{ */
#define PFC_SWE 0x0001U /**< @brief PFC Software error. */
#define PFC_HW_PROT 0x0002U /**< @brief PFC hardware protection. */
#define PFC_SW_OVER_VOLT 0x0004U /**< @brief PFC software over voltage. */
#define PFC_SW_OVER_CURRENT 0x0008U /**< @brief PFC software over current. */
#define PFC_SW_MAINS_FREQ 0x0010U /**< @brief PFC mains frequency error. */
#define PFC_SW_MAIN_VOLT 0x0020U /**< @brief PFC mains voltage error. */
/** @} */
/** @name Definitions exported for the DAC channel used as reference for protection. */
/** @{ */
#define AO_DISABLED 0x00U /**< @brief Analog output disabled. */
#define AO_DEBUG 0x01U /**< @brief Analog output debug. */
#define VREF_OCPM1 0x02U /**< @brief Voltage reference for over current protection of motor 1. */
#define VREF_OCPM2 0x03U /**< @brief Voltage reference for over current protection of motor 2. */
#define VREF_OCPM12 0x04U /**< @brief Voltage reference for over current protection of both motors. */
#define VREF_OVPM12 0x05U /**< @brief Voltage reference for over voltage protection of both motors. */
/** @} */
/** @name ADC channel number definitions */
/** @{ */
#define MC_ADC_CHANNEL_0 0
#define MC_ADC_CHANNEL_1 1
#define MC_ADC_CHANNEL_2 2
#define MC_ADC_CHANNEL_3 3
#define MC_ADC_CHANNEL_4 4
#define MC_ADC_CHANNEL_5 5
#define MC_ADC_CHANNEL_6 6
#define MC_ADC_CHANNEL_7 7
#define MC_ADC_CHANNEL_8 8
#define MC_ADC_CHANNEL_9 9
#define MC_ADC_CHANNEL_10 10
#define MC_ADC_CHANNEL_11 11
#define MC_ADC_CHANNEL_12 12
#define MC_ADC_CHANNEL_13 13
#define MC_ADC_CHANNEL_14 14
#define MC_ADC_CHANNEL_15 15
#define MC_ADC_CHANNEL_16 16
#define MC_ADC_CHANNEL_17 17
#define MC_ADC_CHANNEL_18 18
#define MC_ADC_CHANNEL_19 19
#define MC_ADC_CHANNEL_20 20
#define MC_ADC_CHANNEL_21 21
#define MC_ADC_CHANNEL_22 22
/** @} */
/** @name Utility macros definitions */
/** @{ */
#define RPM2MEC01HZ(rpm) (int16_t)((int32_t)(rpm)/6)
#define MAX(a,b) (((a)>(b))?(a):(b))
/** @} */
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* MC_TYPE_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 15,166 | C | 33.707094 | 130 | 0.551826 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/app_x-cube-ai.h |
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __APP_AI_H
#define __APP_AI_H
#ifdef __cplusplus
extern "C" {
#endif
/**
******************************************************************************
* @file app_x-cube-ai.h
* @author X-CUBE-AI C code generator
* @brief AI entry function definitions
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "ai_platform.h"
void MX_X_CUBE_AI_Init(void);
void MX_X_CUBE_AI_Process(void);
/* USER CODE BEGIN includes */
/* USER CODE END includes */
#ifdef __cplusplus
}
#endif
#endif /*__STMicroelectronics_X-CUBE-AI_8_1_0_H */
| 1,132 | C | 30.472221 | 80 | 0.470848 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_app_hooks.h | /**
******************************************************************************
* @file mc_app_hooks.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file implements tasks definition.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCAppHooks
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MC_APP_HOOKS_H
#define MC_APP_HOOKS_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MCTasks
* @{
*/
/** @addtogroup MCAppHooks
* @{
*/
/* Exported functions ------------------------------------------------------- */
/* Hook function called at end of MCboot() */
void MC_APP_BootHook(void);
/* Hook function called right after the Medium Frequency Task of Motor 1 */
void MC_APP_PostMediumFrequencyHook_M1(void);
/** @} */
/** @} */
/** @} */
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* MC_APP_HOOKS_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 1,655 | C | 24.875 | 80 | 0.470695 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/aspep.h | /**
******************************************************************************
* @file aspep.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides aspep API that implement the aspep protocol
*
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#ifndef ASPEP_H
#define ASPEP_H
#include "parameters_conversion.h"
#include "mcptl.h"
#define ASPEP_CTRL ((uint8_t)0) /* Beacon, Nack, or Ping*/
#define ASPEP_OK ((uint8_t)0)
#define ASPEP_SYNC_NOT_EXPECTED 1
#define ASPEP_NOT_CONNECTED 2
#define ASPEP_BUFFER_ERROR 3
#define ASPEP_BAD_PACKET_TYPE 1
#define ASPEP_BAD_PACKET_SIZE 2
#define ASPEP_BAD_CRC_HEADER 4
#define ASPEP_BAD_CRC_DATA 5
#define ASPEP_PING_RESET 0
#define ASPEP_PING_CFG 1
#define ASPEP_HEADER_SIZE 4
#define ASPEP_CTRL_SIZE 4
#define ASPEP_DATACRC_SIZE 2U
#define ID_MASK ((uint32_t)0xF)
#define DATA_PACKET ((uint32_t)0x9)
#define PING ((uint32_t)0x6)
#define BEACON ((uint32_t)0x5)
#define NACK ((uint32_t)0xF)
#define ACK ((uint32_t)0xA)
typedef uint32_t ASPEP_packetType;
typedef bool (*ASPEP_send_cb_t) (void *pHW_Handle, void *txbuffer, uint16_t length);
typedef void (*ASPEP_receive_cb_t) (void *pHW_Handle, void *rxbuffer, uint16_t length);
typedef void (*ASPEP_hwinit_cb_t) (void *pHW_Handle);
typedef void (*ASPEP_hwsync_cb_t) (void *pHW_Handle);
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MCP
* @{
*/
/**
* @brief ASPEP State Machine Type.
*/
typedef enum
{
ASPEP_IDLE,
ASPEP_CONFIGURED,
ASPEP_CONNECTED,
} ASPEP_sm_type;
/**
* @brief ASPEP Transport Layer State Machine Type.
*/
typedef enum
{
WAITING_PACKET,
WAITING_PAYLOAD,
} ASPEP_TL_sm_type;
/**
* @brief ASPEP Control Buffer structure.
*/
typedef struct
{
uint8_t buffer[ASPEP_HEADER_SIZE];
buff_access_t state;
} ASPEP_ctrlBuff_t;
/**
* @brief ASPEP communication capabilities.
*
* Minimum between Controller and Performer capabilities.
*/
typedef struct
{
uint8_t DATA_CRC;
uint8_t RX_maxSize;
uint8_t TXS_maxSize;
uint8_t TXA_maxSize;
uint8_t version;
} ASPEP_Capabilities_def;
/**
* @brief Handle structure for ASPEP related components.
*/
typedef struct
{
MCTL_Handle_t _Super; /** Transport Layer component handle */
void *HWIp; /** Hardware components chosen for communication */
uint8_t *rxBuffer; /** Contains the ASPEP Data payload */
uint8_t rxHeader[4]; /** Contains the ASPEP 32 bits header */
ASPEP_ctrlBuff_t ctrlBuffer; /** ASPEP protocol control buffer */
MCTL_Buff_t syncBuffer; /** Buffer used for synchronous communication */
MCTL_Buff_t asyncBufferA; /** First buffer used for asynchronous communication */
MCTL_Buff_t asyncBufferB; /** Second buffer used for asynchronous communication */
MCTL_Buff_t *lastRequestedAsyncBuff; /** Last buffer requested for asynchronous communication */
MCTL_Buff_t *asyncNextBuffer; /** Next buffer that will be transmitted by asynchronous communication */
void *lockBuffer; /** Buffer locked to avoid erasing data not yet transmitted */
ASPEP_hwinit_cb_t fASPEP_HWInit; /** Pointer to the initialization function */
ASPEP_hwsync_cb_t fASPEP_HWSync; /** Pointer to the starting function */
ASPEP_receive_cb_t fASPEP_receive; /** Pointer to the receiving packet function */
ASPEP_send_cb_t fASPEP_send; /** Pointer to the sending packet function */
uint16_t rxLength; /** Length of the received data packet : payload and header */
uint16_t maxRXPayload; /** Maximum payload size the performer can process */
uint8_t syncPacketCount; /** Reset at startup only, this counter is incremented at each valid data packet received from controller */
bool NewPacketAvailable; /** Boolean stating if performer is ready to receive a new packet or not */
uint8_t badPacketFlag; /** Contains the error code in case of ASPEP decoding issue */
uint8_t liid;
ASPEP_sm_type ASPEP_State; /** ASPEP State of the communication between performer and controller */
ASPEP_TL_sm_type ASPEP_TL_State; /** Transport Layer state of the communication between performer and controller */
ASPEP_packetType rxPacketType; /** Type of the received packet */
ASPEP_Capabilities_def Capabilities; /** Minimum between Controller and Performer capabilities */
} ASPEP_Handle_t;
void ASPEP_start(ASPEP_Handle_t *pHandle);
/* MCTL (Motor Control Transport Layer) API */
bool ASPEP_getBuffer(MCTL_Handle_t *pHandle, void **buffer, uint8_t syncAsync);
uint8_t ASPEP_sendPacket(MCTL_Handle_t *pHandle, void *txBuffer, uint16_t txDataLength, uint8_t syncAsync);
uint8_t *ASPEP_RXframeProcess(MCTL_Handle_t *pHandle, uint16_t *packetLength);
/* */
void ASPEP_HWDataReceivedIT(ASPEP_Handle_t *pHandle);
void ASPEP_HWDataTransmittedIT(ASPEP_Handle_t *pHandle);
/* Debugger stuff */
void ASPEP_HWDMAReset(ASPEP_Handle_t *pHandle);
#endif /* ASPEP_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 6,017 | C | 35.695122 | 151 | 0.614924 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_configuration_registers.h |
/**
******************************************************************************
* @file mc_configuration_registers.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides the definitions needed to build the project
* configuration information registers.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#ifndef MC_CONFIGURATION_REGISTERS_H
#define MC_CONFIGURATION_REGISTERS_H
#include "mc_type.h"
typedef struct
{
uint32_t SDKVersion;
uint8_t MotorNumber;
uint8_t MCP_Flag;
uint8_t MCPA_UARTA_LOG;
uint8_t MCPA_UARTB_LOG;
uint8_t MCPA_STLNK_LOG;
uint8_t Padding;
} __attribute__ ((packed)) GlobalConfig_reg_t;
typedef struct
{
float_t polePairs;
float_t ratedFlux;
float_t rs;
float_t rsSkinFactor;
float_t ls;
float_t ld;
float_t maxCurrent;
float_t mass_copper_kg;
float_t cooling_tau_s;
char_t name[24];
} __attribute__ ((packed)) MotorConfig_reg_t;
typedef struct
{
uint32_t maxMechanicalSpeed;
float_t maxReadableCurrent;
float_t nominalCurrent;
uint16_t nominalVoltage;
uint8_t driveType;
uint8_t padding;
} __attribute__ ((packed)) ApplicationConfig_reg_t;
typedef struct
{
uint8_t primarySensor;
uint8_t auxiliarySensor;
uint8_t topology;
uint8_t FOCRate;
uint32_t PWMFrequency;
uint16_t MediumFrequency;
uint16_t configurationFlag1;
uint16_t configurationFlag2;
} __attribute__ ((packed)) FOCFwConfig_reg_t;
#define ENO_SENSOR 0
#define EPLL 1
#define ECORDIC 2
#define EENCODER 3
#define EHALL 4
#define EHSO 5
#define EZEST 6
#define SDK_VERSION_MAIN (0x6) /*!< [31:24] main version */
#define SDK_VERSION_SUB1 (0x2) /*!< [23:16] sub1 version */
#define SDK_VERSION_SUB2 (0x0) /*!< [15:8] sub2 version */
#define SDK_VERSION_RC (0x0) /*!< [7:0] release candidate */
#define SDK_VERSION ((SDK_VERSION_MAIN << 24U)\
|(SDK_VERSION_SUB1 << 16U)\
|(SDK_VERSION_SUB2 << 8U )\
|(SDK_VERSION_RC))
/* configurationFlag1 definition */
#define FLUX_WEAKENING_FLAG (1U)
#define FEED_FORWARD_FLAG (1U << 1U)
#define MTPA_FLAG (1U << 2U)
#define PFC_FLAG (1U << 3U)
#define ICL_FLAG (1U << 4U)
#define RESISTIVE_BREAK_FLAG (1U << 5U)
#define OCP_DISABLE_FLAG (1U << 6U)
#define STGAP_FLAG (1U << 7U)
#define POSITION_CTRL_FLAG (1U << 8U)
#define VBUS_SENSING_FLAG (1U << 9U)
#define TEMP_SENSING_FLAG (1U << 10U)
#define VOLTAGE_SENSING_FLAG (1U << 11U)
#define FLASH_CONFIG_FLAG (1U << 12U)
#define DAC_CH1_FLAG (1U << 13U)
#define DAC_CH2_FLAG (1U << 14U)
#define OTF_STARTUP_FLAG (1U << 15U)
/* configurationFlag2 definition */
#define OVERMODULATION_FLAG (1U)
#define DISCONTINUOUS_PWM_FLAG (1U << 1U)
#define PROFILER_FLAG (1U << 13U)
#define DBG_MCU_LOAD_MEASURE_FLAG (1U << 14U)
#define DBG_OPEN_LOOP_FLAG (1U << 15U)
/* MCP_Flag definition */
#define FLAG_MCP_OVER_STLINK 0U
#define FLAG_MCP_OVER_UARTA (1U << 1U)
#define FLAG_MCP_OVER_UARTB 0U
#define configurationFlag1_M1 (VBUS_SENSING_FLAG)
#define configurationFlag2_M1 (0U)
#define DRIVE_TYPE_M1 0
#define PRIM_SENSOR_M1 EENCODER
#define AUX_SENSOR_M1 EPLL
#define TOPOLOGY_M1 0
#define FOC_RATE_M1 1
#define PWM_FREQ_M1 16000
extern const char_t FIRMWARE_NAME[]; //cstat !MISRAC2012-Rule-18.8 !MISRAC2012-Rule-8.11
extern const char_t CTL_BOARD[]; //cstat !MISRAC2012-Rule-18.8 !MISRAC2012-Rule-8.11
extern const char_t *PWR_BOARD_NAME[NBR_OF_MOTORS];
extern const char_t *MOTOR_NAME[NBR_OF_MOTORS];
extern const GlobalConfig_reg_t globalConfig_reg;
extern const FOCFwConfig_reg_t *FOCConfig_reg[NBR_OF_MOTORS];
extern const MotorConfig_reg_t *MotorConfig_reg[NBR_OF_MOTORS];
extern const ApplicationConfig_reg_t *ApplicationConfig_reg[NBR_OF_MOTORS];
#endif /* MC_CONFIGURATION_REGISTERS_H */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 4,871 | C | 33.309859 | 88 | 0.583658 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/network.h | /**
******************************************************************************
* @file network.h
* @author AST Embedded Analytics Research Platform
* @date Tue Jan 16 16:02:48 2024
* @brief AI Tool Automatic Code Generator for Embedded NN computing
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
******************************************************************************
*/
#ifndef AI_NETWORK_H
#define AI_NETWORK_H
#pragma once
#include "network_config.h"
#include "ai_platform.h"
/******************************************************************************/
#define AI_NETWORK_MODEL_NAME "network"
#define AI_NETWORK_ORIGIN_MODEL_NAME "pendulumeff1p5"
/******************************************************************************/
#define AI_NETWORK_ACTIVATIONS_ALIGNMENT (4)
#define AI_NETWORK_INPUTS_IN_ACTIVATIONS (4)
#define AI_NETWORK_OUTPUTS_IN_ACTIVATIONS (4)
/******************************************************************************/
#define AI_NETWORK_IN_NUM (1)
AI_DEPRECATED
#define AI_NETWORK_IN \
ai_network_inputs_get(AI_HANDLE_NULL, NULL)
#define AI_NETWORK_IN_SIZE { \
AI_NETWORK_IN_1_SIZE, \
}
#define AI_NETWORK_IN_SIZE_BYTES { \
AI_NETWORK_IN_1_SIZE_BYTES, \
}
#define AI_NETWORK_IN_1_FORMAT AI_BUFFER_FORMAT_FLOAT
#define AI_NETWORK_IN_1_CHANNEL (3)
#define AI_NETWORK_IN_1_SIZE (3)
#define AI_NETWORK_IN_1_SIZE_BYTES (12)
/******************************************************************************/
#define AI_NETWORK_OUT_NUM (3)
AI_DEPRECATED
#define AI_NETWORK_OUT \
ai_network_outputs_get(AI_HANDLE_NULL, NULL)
#define AI_NETWORK_OUT_SIZE { \
AI_NETWORK_OUT_1_SIZE, \
AI_NETWORK_OUT_2_SIZE, \
AI_NETWORK_OUT_3_SIZE, \
}
#define AI_NETWORK_OUT_SIZE_BYTES { \
AI_NETWORK_OUT_1_SIZE_BYTES, \
AI_NETWORK_OUT_2_SIZE_BYTES, \
AI_NETWORK_OUT_3_SIZE_BYTES, \
}
#define AI_NETWORK_OUT_1_FORMAT AI_BUFFER_FORMAT_FLOAT
#define AI_NETWORK_OUT_1_CHANNEL (1)
#define AI_NETWORK_OUT_1_SIZE (1)
#define AI_NETWORK_OUT_1_SIZE_BYTES (4)
#define AI_NETWORK_OUT_2_FORMAT AI_BUFFER_FORMAT_FLOAT
#define AI_NETWORK_OUT_2_CHANNEL (1)
#define AI_NETWORK_OUT_2_SIZE (1)
#define AI_NETWORK_OUT_2_SIZE_BYTES (4)
#define AI_NETWORK_OUT_3_FORMAT AI_BUFFER_FORMAT_FLOAT
#define AI_NETWORK_OUT_3_CHANNEL (1)
#define AI_NETWORK_OUT_3_SIZE (1)
#define AI_NETWORK_OUT_3_SIZE_BYTES (4)
/******************************************************************************/
#define AI_NETWORK_N_NODES (15)
AI_API_DECLARE_BEGIN
/*!
* @defgroup network
* @brief Public neural network APIs
* @details This is the header for the network public APIs declarations
* for interfacing a generated network model.
* @details The public neural network APIs hide the structure of the network
* and offer a set of interfaces to create, initialize, query, configure,
* run and destroy a network instance.
* To handle this, an opaque handler to the network context is provided
* on creation.
* The APIs are meant as stadard interfaces for the calling code; depending on
* the supported platforms and the models, different implementations could be
* available.
*/
/******************************************************************************/
/*! Public API Functions Declarations */
/*!
* @brief Get network library info as a datastruct.
* @ingroup network
* @param[in] network: the handler to the network context
* @param[out] report a pointer to the report struct where to
* store network info. See @ref ai_network_report struct for details
* @return a boolean reporting the exit status of the API
*/
AI_DEPRECATED
AI_API_ENTRY
ai_bool ai_network_get_info(
ai_handle network, ai_network_report* report);
/*!
* @brief Get network library report as a datastruct.
* @ingroup network
* @param[in] network: the handler to the network context
* @param[out] report a pointer to the report struct where to
* store network info. See @ref ai_network_report struct for details
* @return a boolean reporting the exit status of the API
*/
AI_API_ENTRY
ai_bool ai_network_get_report(
ai_handle network, ai_network_report* report);
/*!
* @brief Get first network error code.
* @ingroup network
* @details Get an error code related to the 1st error generated during
* network processing. The error code is structure containing an
* error type indicating the type of error with an associated error code
* Note: after this call the error code is internally reset to AI_ERROR_NONE
* @param network an opaque handle to the network context
* @return an error type/code pair indicating both the error type and code
* see @ref ai_error for struct definition
*/
AI_API_ENTRY
ai_error ai_network_get_error(ai_handle network);
/*!
* @brief Create a neural network.
* @ingroup network
* @details Instantiate a network and returns an object to handle it;
* @param network an opaque handle to the network context
* @param network_config a pointer to the network configuration info coded as a
* buffer
* @return an error code reporting the status of the API on exit
*/
AI_API_ENTRY
ai_error ai_network_create(
ai_handle* network, const ai_buffer* network_config);
/*!
* @brief Destroy a neural network and frees the allocated memory.
* @ingroup network
* @details Destroys the network and frees its memory. The network handle is returned;
* if the handle is not NULL, the unloading has not been successful.
* @param network an opaque handle to the network context
* @return an object handle : AI_HANDLE_NULL if network was destroyed
* correctly. The same input network handle if destroy failed.
*/
AI_API_ENTRY
ai_handle ai_network_destroy(ai_handle network);
/*!
* @brief Initialize the data structures of the network.
* @ingroup network
* @details This API initialized the network after a successfull
* @ref ai_network_create. Both the activations memory buffer
* and params (i.e. weights) need to be provided by caller application
*
* @param network an opaque handle to the network context
* @param params the parameters of the network (required).
* see @ref ai_network_params struct for details
* @return true if the network was correctly initialized, false otherwise
* in case of error the error type could be queried by
* using @ref ai_network_get_error
*/
AI_API_ENTRY
ai_bool ai_network_init(
ai_handle network, const ai_network_params* params);
/*!
* @brief Create and initialize a neural network (helper function)
* @ingroup network
* @details Helper function to instantiate and to initialize a network. It returns an object to handle it;
* @param network an opaque handle to the network context
* @param activations array of addresses of the activations buffers
* @param weights array of addresses of the weights buffers
* @return an error code reporting the status of the API on exit
*/
AI_API_ENTRY
ai_error ai_network_create_and_init(
ai_handle* network, const ai_handle activations[], const ai_handle weights[]);
/*!
* @brief Get network inputs array pointer as a ai_buffer array pointer.
* @ingroup network
* @param network an opaque handle to the network context
* @param n_buffer optional parameter to return the number of outputs
* @return a ai_buffer pointer to the inputs arrays
*/
AI_API_ENTRY
ai_buffer* ai_network_inputs_get(
ai_handle network, ai_u16 *n_buffer);
/*!
* @brief Get network outputs array pointer as a ai_buffer array pointer.
* @ingroup network
* @param network an opaque handle to the network context
* @param n_buffer optional parameter to return the number of outputs
* @return a ai_buffer pointer to the outputs arrays
*/
AI_API_ENTRY
ai_buffer* ai_network_outputs_get(
ai_handle network, ai_u16 *n_buffer);
/*!
* @brief Run the network and return the output
* @ingroup network
*
* @details Runs the network on the inputs and returns the corresponding output.
* The size of the input and output buffers is stored in this
* header generated by the code generation tool. See AI_NETWORK_*
* defines into file @ref network.h for all network sizes defines
*
* @param network an opaque handle to the network context
* @param[in] input buffer with the input data
* @param[out] output buffer with the output data
* @return the number of input batches processed (default 1) or <= 0 if it fails
* in case of error the error type could be queried by
* using @ref ai_network_get_error
*/
AI_API_ENTRY
ai_i32 ai_network_run(
ai_handle network, const ai_buffer* input, ai_buffer* output);
/*!
* @brief Runs the network on the inputs.
* @ingroup network
*
* @details Differently from @ref ai_network_run, no output is returned, e.g. for
* temporal models with a fixed step size.
*
* @param network the network to be run
* @param[in] input buffer with the input data
* @return the number of input batches processed (usually 1) or <= 0 if it fails
* in case of error the error type could be queried by
* using @ref ai_network_get_error
*/
AI_API_ENTRY
ai_i32 ai_network_forward(
ai_handle network, const ai_buffer* input);
AI_API_DECLARE_END
#endif /* AI_NETWORK_H */
| 9,499 | C | 34.849056 | 106 | 0.671965 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/regular_conversion_manager.h |
/**
******************************************************************************
* @file regular_conversion_manager.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains all definitions and functions prototypes for the
* regular_conversion_manager component of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef REGULAR_CONVERSION_MANAGER_H
#define REGULAR_CONVERSION_MANAGER_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup RCM
* @{
*/
/* Exported types ------------------------------------------------------------*/
/**
* @brief RegConv_t contains all the parameters required to execute a regular conversion
*
* it is used by all regular_conversion_manager's client
*
*/
typedef struct
{
ADC_TypeDef *regADC;
uint8_t channel;
uint32_t samplingTime;
uint8_t convHandle; /*!< handler to the regular conversion */
} RegConv_t;
/**
* @brief Conversion states
*/
typedef enum
{
RCM_USERCONV_IDLE, /**< @brief No conversion currently scheduled. */
RCM_USERCONV_REQUESTED, /**< @brief A conversion is scheduled for execution. */
RCM_USERCONV_EOC /**< @brief A conversion has completed and the value is ready. */
}RCM_UserConvState_t;
typedef void (*RCM_exec_cb_t)(RegConv_t *regConv, uint16_t data, void *UserData);
/* Exported functions ------------------------------------------------------- */
/* Function used to register a regular conversion */
void RCM_RegisterRegConv(RegConv_t *regConv);
/* Function used to register a regular conversion with a callback attached*/
void RCM_RegisterRegConv_WithCB(RegConv_t *regConv, RCM_exec_cb_t fctCB, void *data);
/* Function used to execute an already registered regular conversion */
uint16_t RCM_ExecRegularConv(RegConv_t *regConv);
/* select the handle conversion to be executed during the next call to RCM_ExecUserConv */
bool RCM_RequestUserConv(RegConv_t *regConv);
/* Return the latest user conversion value */
uint16_t RCM_GetUserConv(void);
/* Must be called by MC_TASK only to grantee proper scheduling */
void RCM_ExecUserConv(void);
/* return the state of the user conversion state machine*/
RCM_UserConvState_t RCM_GetUserConvState(void);
/* Function used to un-schedule a regular conversion exectuted after current sampling in HF task */
bool RCM_PauseRegularConv(RegConv_t *regConv);
/* Non blocking function to start conversion inside HF task */
void RCM_ExecNextConv(void);
/* Non blocking function used to read back already started regular conversion */
void RCM_ReadOngoingConv(void);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* REGULAR_CONVERSION_MANAGER_H */
/************************ (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 3,579 | C | 29.862069 | 99 | 0.6038 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_stm_types.h | /**
******************************************************************************
* @file mc_stm_types.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief Includes HAL/LL headers relevant to the current configuration.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#ifndef MC_STM_TYPES_H
#define MC_STM_TYPES_H
#ifdef FULL_MISRA_C_COMPLIANCY
#define FULL_MISRA_C_COMPLIANCY_ENC_SPD_POS
#define FULL_MISRA_C_COMPLIANCY_FWD_FDB
#define FULL_MISRA_C_COMPLIANCY_FLUX_WEAK
#define FULL_MISRA_C_COMPLIANCY_MAX_TOR
#define FULL_MISRA_C_COMPLIANCY_MC_MATH
#define FULL_MISRA_C_COMPLIANCY_NTC_TEMP
#define FULL_MISRA_C_COMPLIANCY_PID_REGULATOR
#define FULL_MISRA_C_COMPLIANCY_PFC
#define FULL_MISRA_C_COMPLIANCY_PWM_CURR
#define FULL_MISRA_C_COMPLIANCY_PW_CURR_FDB_OVM
#define FULL_MISRA_C_COMPLIANCY_SPD_TORQ_CTRL
#define FULL_MISRA_C_COMPLIANCY_STO_CORDIC
#define FULL_MISRA_C_COMPLIANCY_STO_PLL
#define FULL_MISRA_C_COMPLIANCY_VIRT_SPD_SENS
#endif
#ifdef NULL_PTR_CHECK
#define NULL_PTR_CHECK_ASP
#define NULL_PTR_CHECK_BUS_VOLT
#define NULL_PTR_CHECK_CRC_LIM
#define NULL_PTR_CHECK_DAC_UI
#define NULL_PTR_CHECK_DIG_OUT
#define NULL_PTR_CHECK_ENC_ALI_CTRL
#define NULL_PTR_CHECK_ENC_SPD_POS_FDB
#define NULL_PTR_CHECK_FEED_FWD_CTRL
#define NULL_PTR_CHECK_FLUX_WEAK
#define NULL_PTR_CHECK_HALL_SPD_POS_FDB
#define NULL_PTR_CHECK_MAX_TRQ_PER_AMP
#define NULL_PTR_CHECK_MCP
#define NULL_PTR_CHECK_MCPA
#define NULL_PTR_CHECK_MC_INT
#define NULL_PTR_CHECK_MC_PERF
#define NULL_PTR_CHECK_MOT_POW_MES
#define NULL_PTR_CHECK_NTC_TEMP_SENS
#define NULL_PTR_CHECK_OPEN_LOOP
#define NULL_PTR_CHECK_PID_REG
#define NULL_PTR_CHECK_POT
#define NULL_PTR_CHECK_POW_COM
#define NULL_PTR_CHECK_PQD_MOT_POW_MEAS
#define NULL_PTR_CHECK_PWR_CUR_FDB
#define NULL_PTR_CHECK_PWM_CUR_FDB_OVM
#define NULL_PTR_CHECK_RDIV_BUS_VLT_SNS
#define NULL_PTR_CHECK_REG_CON_MNG
#define NULL_PTR_CHECK_REG_INT
#define NULL_PTR_CHECK_REV_UP_CTL
#define NULL_PTR_CHECK_RMP_EXT_MNG
#define NULL_PTR_CHECK_R1_PS_PWR_CUR_FDB
#define NULL_PTR_CHECK_R3_2_PWM_CURR_FDB
#define NULL_PTR_CHECK_SPD_POS_FBK
#define NULL_PTR_CHECK_SPD_POT
#define NULL_PTR_CHECK_SPD_REG_POT
#define NULL_PTR_CHECK_SPD_TRQ_CTL
#define NULL_PTR_CHECK_STL_MNG
#define NULL_PTR_CHECK_STO_COR_SPD_POS_FDB
#define NULL_PTR_CHECK_STO_PLL_SPD_POS_FDB
#define NULL_PTR_CHECK_USA_ASP_DRV
#define NULL_PTR_CHECK_VIR_SPD_SEN
#endif
#ifndef USE_FULL_LL_DRIVER
#define USE_FULL_LL_DRIVER
#endif
#include "stm32g4xx_ll_bus.h"
#include "stm32g4xx_ll_rcc.h"
#include "stm32g4xx_ll_system.h"
#include "stm32g4xx_ll_adc.h"
#include "stm32g4xx_ll_tim.h"
#include "stm32g4xx_ll_gpio.h"
#include "stm32g4xx_ll_usart.h"
#include "stm32g4xx_ll_dac.h"
#include "stm32g4xx_ll_dma.h"
#include "stm32g4xx_ll_comp.h"
#include "stm32g4xx_ll_opamp.h"
#include "stm32g4xx_ll_cordic.h"
/* Make this define visible for all projects */
#define NBR_OF_MOTORS 1
__STATIC_INLINE void LL_DMA_ClearFlag_TC(DMA_TypeDef *DMAx, uint32_t Channel)
{
if (NULL == DMAx)
{
/* Nothing to do */
}
else
{
/* Clear TC bits with bits position depending on parameter "Channel" */
WRITE_REG (DMAx->IFCR, DMA_IFCR_CTCIF1 << ((Channel-LL_DMA_CHANNEL_1)<<2));
}
}
//cstat !MISRAC2012-Rule-8.13
__STATIC_INLINE uint32_t LL_DMA_IsActiveFlag_TC(DMA_TypeDef *DMAx, uint32_t Channel)
{
return ((NULL == DMAx) ? 0U : ((READ_BIT(DMAx->ISR,
(DMA_ISR_TCIF1 << ((Channel-LL_DMA_CHANNEL_1)<<2))) == (DMA_ISR_TCIF1 << ((Channel-LL_DMA_CHANNEL_1)<<2))) ?
1UL : 0UL));
}
//cstat !MISRAC2012-Rule-8.13
__STATIC_INLINE void LL_DMA_ClearFlag_HT(DMA_TypeDef *DMAx, uint32_t Channel)
{
if (NULL == DMAx)
{
/* Nothing to do */
}
else
{
/* Clear HT bits with bits position depending on parameter "Channel" */
WRITE_REG (DMAx->IFCR, DMA_IFCR_CHTIF1 << ((Channel-LL_DMA_CHANNEL_1)<<2));
}
}
//cstat !MISRAC2012-Rule-8.13
__STATIC_INLINE uint32_t LL_DMA_IsActiveFlag_HT(DMA_TypeDef *DMAx, uint32_t Channel)
{
return ((NULL == DMAx) ? 0U : ((READ_BIT(DMAx->ISR,
(DMA_ISR_HTIF1 << ((Channel-LL_DMA_CHANNEL_1)<<2))) == (DMA_ISR_HTIF1 << ((Channel-LL_DMA_CHANNEL_1)<<2))) ?
1UL : 0UL));
}
#define PIN_CONNECT (uint32_t)(0)
#define DIRECT_CONNECT (uint32_t)(OPAMP_CSR_OPAMPINTEN)
#define OPAMP_UNCHANGED (uint32_t)(0xFFFFFFFFUL)
/* #define ADC_INJ_TRIG_TIMER LL_ADC_INJ_TRIG_EXT_TIM1_TRGO */
/**
* @name Predefined Speed Units
*
* Each of the following symbols defines a rotation speed unit that can be used by the
* functions of the API for their speed parameter. Each Unit is defined by expressing
* the value of 1 Hz in this unit.
*
* These symbols can be used to set the #SPEED_UNIT macro which defines the rotation speed
* unit used by the functions of the API.
*
* @anchor SpeedUnit
*/
/** @{ */
/** Revolutions Per Minute: 1 Hz is 60 RPM */
#define U_RPM 60
/** Tenth of Hertz: 1 Hz is 10 01Hz */
#define U_01HZ 10
/* Hundreth of Hertz: 1 Hz is 100 001Hz */
/* #define _001HZ 100 */
/** @} */
/* USER CODE BEGIN DEFINITIONS */
/* Definitions placed here will not be erased by code generation */
/**
* @brief Rotation speed unit used at the interface with the application
*
* This symbols defines the value of 1 Hertz in the unit used by the functions of the API for
* their speed parameters.
*
* For instance, if the chosen unit is the RPM, SPEED_UNIT is defined to 60, since 1 Hz is 60 RPM.
* The default unit is #U_01HZ, set on the initial generation of the project by the Workbench.
* As this symbol is defined in a User Section, custom values set by users persist across project
* regeneration.
*
* PID parameters computed by the Motor Control Workbench for speed regulation are
* suited for a speed in 01Hz. The motor control subsystem internally scales them to adapt to the
* actual speed unit.
*
* This symbol should not be set to a literal numeric value. Rather, it should be set to one
* of the symbols predefined for that purpose such as #U_RPM, #U_01HZ,... See @ref SpeedUnit for
* more details.
*
* Refer to the documentation of the @ref MCIAPI for the functions that use this unit.
*
* @{
*/
#define SPEED_UNIT U_01HZ
/* USER CODE END DEFINITIONS */
/*!< Convenient macro to convert user friendly RPM into SpeedUnit used by MC API */
#define RPM_2_SPEED_UNIT(rpm) ((int16_t)(((rpm)*SPEED_UNIT)/U_RPM))
/*!< Convenient macro to convert SpeedUnit used by MC API into user friendly RPM */
#define SPEED_UNIT_2_RPM(speed) ((int16_t)(((speed)*U_RPM)/SPEED_UNIT))
/**
* @}
*/
#endif /* MC_STM_TYPES_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 7,159 | C | 33.423077 | 118 | 0.680821 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_config.h |
/**
******************************************************************************
* @file mc_config.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief Motor Control Subsystem components configuration and handler
* structures declarations.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#ifndef MC_CONFIG_H
#define MC_CONFIG_H
#include "pid_regulator.h"
#include "speed_torq_ctrl.h"
#include "virtual_speed_sensor.h"
#include "ntc_temperature_sensor.h"
#include "revup_ctrl.h"
#include "pwm_curr_fdbk.h"
#include "mc_interface.h"
#include "mc_configuration_registers.h"
#include "regular_conversion_manager.h"
#include "r_divider_bus_voltage_sensor.h"
#include "virtual_bus_voltage_sensor.h"
#include "pqd_motor_power_measurement.h"
#include "r3_1_g4xx_pwm_curr_fdbk.h"
#include "encoder_speed_pos_fdbk.h"
#include "enc_align_ctrl.h"
#include "ramp_ext_mngr.h"
#include "circle_limitation.h"
#include "sto_speed_pos_fdbk.h"
#include "sto_pll_speed_pos_fdbk.h"
/* USER CODE BEGIN Additional include */
/* USER CODE END Additional include */
extern PID_Handle_t PIDSpeedHandle_M1;
extern PID_Handle_t PIDIqHandle_M1;
extern PID_Handle_t PIDIdHandle_M1;
extern NTC_Handle_t TempSensor_M1;
extern PWMC_R3_1_Handle_t PWM_Handle_M1;
extern SpeednTorqCtrl_Handle_t SpeednTorqCtrlM1;
extern PQD_MotorPowMeas_Handle_t PQD_MotorPowMeasM1;
extern PQD_MotorPowMeas_Handle_t *pPQD_MotorPowMeasM1;
extern VirtualSpeedSensor_Handle_t VirtualSpeedSensorM1;
extern STO_PLL_Handle_t STO_PLL_M1;
extern ENCODER_Handle_t ENCODER_M1;
extern EncAlign_Handle_t EncAlignCtrlM1;
extern RegConv_t VbusRegConv_M1;
extern RDivider_Handle_t BusVoltageSensor_M1;
extern CircleLimitation_Handle_t CircleLimitationM1;
extern RampExtMngr_Handle_t RampExtMngrHFParamsM1;
extern MCI_Handle_t Mci[NBR_OF_MOTORS];
extern SpeednTorqCtrl_Handle_t *pSTC[NBR_OF_MOTORS];
extern PID_Handle_t *pPIDIq[NBR_OF_MOTORS];
extern PID_Handle_t *pPIDId[NBR_OF_MOTORS];
extern NTC_Handle_t *pTemperatureSensor[NBR_OF_MOTORS];
extern PQD_MotorPowMeas_Handle_t *pMPM[NBR_OF_MOTORS];
extern MCI_Handle_t* pMCI[NBR_OF_MOTORS];
/* USER CODE BEGIN Additional extern */
/* USER CODE END Additional extern */
#endif /* MC_CONFIG_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 2,822 | C | 32.607142 | 80 | 0.675053 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/usart.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart.h
* @brief This file contains all the function prototypes for
* the usart.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USART_H__
#define __USART_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern UART_HandleTypeDef huart2;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_USART2_UART_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __USART_H__ */
| 1,312 | C | 23.773584 | 80 | 0.489329 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/parameters_conversion.h |
/**
******************************************************************************
* @file parameters_conversion.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file includes the proper Parameter conversion on the base
* of stdlib for the first drive
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef PARAMETERS_CONVERSION_H
#define PARAMETERS_CONVERSION_H
#include "mc_math.h"
#include "parameters_conversion_g4xx.h"
#include "pmsm_motor_parameters.h"
#include "drive_parameters.h"
#include "power_stage_parameters.h"
/* Current conversion from Ampere unit to 16Bit Digit */
#define CURRENT_CONV_FACTOR (uint16_t)((65536.0 * RSHUNT * AMPLIFICATION_GAIN)/ADC_REFERENCE_VOLTAGE)
#define CURRENT_CONV_FACTOR_INV (1.0 / ((65536.0 * RSHUNT * AMPLIFICATION_GAIN) / ADC_REFERENCE_VOLTAGE))
/* Current conversion from Ampere unit to 16Bit Digit */
#define NOMINAL_CURRENT (NOMINAL_CURRENT_A * CURRENT_CONV_FACTOR)
#define ADC_REFERENCE_VOLTAGE 3.3
#define M1_MAX_READABLE_CURRENT (ADC_REFERENCE_VOLTAGE / (2 * RSHUNT * AMPLIFICATION_GAIN))
/************************* CONTROL FREQUENCIES & DELAIES **********************/
#define TF_REGULATION_RATE (uint32_t)((uint32_t)(PWM_FREQUENCY) / (REGULATION_EXECUTION_RATE))
/* TF_REGULATION_RATE_SCALED is TF_REGULATION_RATE divided by PWM_FREQ_SCALING to allow more dynamic */
#define TF_REGULATION_RATE_SCALED (uint16_t)((uint32_t)(PWM_FREQUENCY) / (REGULATION_EXECUTION_RATE\
* PWM_FREQ_SCALING))
/* DPP_CONV_FACTOR is introduce to compute the right DPP with TF_REGULATOR_SCALED */
#define DPP_CONV_FACTOR (65536 / PWM_FREQ_SCALING)
/* Current conversion from Ampere unit to 16Bit Digit */
#define ID_DEMAG (ID_DEMAG_A * CURRENT_CONV_FACTOR)
#define IQMAX (IQMAX_A * CURRENT_CONV_FACTOR)
#define DEFAULT_TORQUE_COMPONENT (DEFAULT_TORQUE_COMPONENT_A * CURRENT_CONV_FACTOR)
#define DEFAULT_FLUX_COMPONENT (DEFAULT_FLUX_COMPONENT_A * CURRENT_CONV_FACTOR)
#define REP_COUNTER (uint16_t)((REGULATION_EXECUTION_RATE * 2u) - 1u)
#define SYS_TICK_FREQUENCY (uint16_t)2000
#define UI_TASK_FREQUENCY_HZ 10U
#define PHASE1_FINAL_CURRENT (PHASE1_FINAL_CURRENT_A * CURRENT_CONV_FACTOR)
#define PHASE2_FINAL_CURRENT (PHASE2_FINAL_CURRENT_A * CURRENT_CONV_FACTOR)
#define PHASE3_FINAL_CURRENT (PHASE3_FINAL_CURRENT_A * CURRENT_CONV_FACTOR)
#define PHASE4_FINAL_CURRENT (PHASE4_FINAL_CURRENT_A * CURRENT_CONV_FACTOR)
#define PHASE5_FINAL_CURRENT (PHASE5_FINAL_CURRENT_A * CURRENT_CONV_FACTOR)
#define MEDIUM_FREQUENCY_TASK_RATE (uint16_t)SPEED_LOOP_FREQUENCY_HZ
#define MF_TASK_OCCURENCE_TICKS (SYS_TICK_FREQUENCY / SPEED_LOOP_FREQUENCY_HZ) - 1u
#define UI_TASK_OCCURENCE_TICKS (SYS_TICK_FREQUENCY / UI_TASK_FREQUENCY_HZ) - 1u
#define SERIALCOM_TIMEOUT_OCCURENCE_TICKS (SYS_TICK_FREQUENCY / SERIAL_COM_TIMEOUT_INVERSE) - 1u
#define SERIALCOM_ATR_TIME_TICKS (uint16_t)(((SYS_TICK_FREQUENCY * SERIAL_COM_ATR_TIME_MS) / 1000u) - 1u)
/************************* COMMON OBSERVER PARAMETERS **************************/
#define MAX_BEMF_VOLTAGE (uint16_t)((MAX_APPLICATION_SPEED_RPM * 1.2 *\
MOTOR_VOLTAGE_CONSTANT * SQRT_2) / (1000u * SQRT_3))
/*max phase voltage, 0-peak Volts*/
#define MAX_VOLTAGE (int16_t)((ADC_REFERENCE_VOLTAGE / SQRT_3) / VBUS_PARTITIONING_FACTOR)
#define MAX_CURRENT (ADC_REFERENCE_VOLTAGE / (2 * RSHUNT * AMPLIFICATION_GAIN))
#define OBS_MINIMUM_SPEED_UNIT (uint16_t)((OBS_MINIMUM_SPEED_RPM * SPEED_UNIT) / U_RPM)
#define MAX_APPLICATION_SPEED_UNIT ((MAX_APPLICATION_SPEED_RPM * SPEED_UNIT) / U_RPM)
#define MIN_APPLICATION_SPEED_UNIT ((MIN_APPLICATION_SPEED_RPM * SPEED_UNIT) / U_RPM)
/************************* PLL PARAMETERS **************************/
#define C1 (int32_t)((((int16_t)F1) * RS) / (LS * TF_REGULATION_RATE))
#define C2 (int32_t)GAIN1
#define C3 (int32_t)((((int16_t)F1) * MAX_BEMF_VOLTAGE) / (LS * MAX_CURRENT * TF_REGULATION_RATE))
#define C4 (int32_t)GAIN2
#define C5 (int32_t)((((int16_t)F1) * MAX_VOLTAGE) / (LS * MAX_CURRENT * TF_REGULATION_RATE))
#define PERCENTAGE_FACTOR (uint16_t)(VARIANCE_THRESHOLD*128u)
#define HFI_MINIMUM_SPEED (uint16_t) (HFI_MINIMUM_SPEED_RPM/6u)
#define MAX_APPLICATION_SPEED_UNIT2 ((MAX_APPLICATION_SPEED_RPM2 * SPEED_UNIT) / U_RPM)
#define MIN_APPLICATION_SPEED_UNIT2 ((MIN_APPLICATION_SPEED_RPM2 * SPEED_UNIT) / U_RPM)
/************************** VOLTAGE CONVERSIONS Motor 1 *************************/
#define OVERVOLTAGE_THRESHOLD_d (uint16_t)(OV_VOLTAGE_THRESHOLD_V * 65535 /\
(ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR))
#define OVERVOLTAGE_THRESHOLD_LOW_d (uint16_t)(OV_VOLTAGE_THRESHOLD_V * 65535 /\
(ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR))
#define UNDERVOLTAGE_THRESHOLD_d (uint16_t)((UD_VOLTAGE_THRESHOLD_V * 65535) /\
((uint16_t)(ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR)))
#define INT_SUPPLY_VOLTAGE (uint16_t)(65536 / ADC_REFERENCE_VOLTAGE)
#define DELTA_TEMP_THRESHOLD (OV_TEMPERATURE_THRESHOLD_C - T0_C)
#define DELTA_V_THRESHOLD (dV_dT * DELTA_TEMP_THRESHOLD)
#define OV_TEMPERATURE_THRESHOLD_d ((V0_V + DELTA_V_THRESHOLD) * INT_SUPPLY_VOLTAGE)
#define DELTA_TEMP_HYSTERESIS (OV_TEMPERATURE_HYSTERESIS_C)
#define DELTA_V_HYSTERESIS (dV_dT * DELTA_TEMP_HYSTERESIS)
#define OV_TEMPERATURE_HYSTERESIS_d (DELTA_V_HYSTERESIS * INT_SUPPLY_VOLTAGE)
#define ALIGNMENT_ANGLE_S16 (int16_t)(M1_ALIGNMENT_ANGLE_DEG * 65536u / 360u)
#define FINAL_I_ALIGNMENT (uint16_t)(FINAL_I_ALIGNMENT_A * CURRENT_CONV_FACTOR)
/*************** Timer for PWM generation & currenst sensing parameters ******/
#define PWM_PERIOD_CYCLES (uint16_t)(((uint32_t)ADV_TIM_CLK_MHz * (uint32_t)1000000u\
/ ((uint32_t)(PWM_FREQUENCY))) & (uint16_t)0xFFFE)
#define DEADTIME_NS SW_DEADTIME_NS
#define DEAD_TIME_ADV_TIM_CLK_MHz (ADV_TIM_CLK_MHz * TIM_CLOCK_DIVIDER)
#define DEAD_TIME_COUNTS_1 (DEAD_TIME_ADV_TIM_CLK_MHz * DEADTIME_NS / 1000uL)
#if (DEAD_TIME_COUNTS_1 <= 255)
#define DEAD_TIME_COUNTS (uint16_t)DEAD_TIME_COUNTS_1
#elif (DEAD_TIME_COUNTS_1 <= 508)
#define DEAD_TIME_COUNTS (uint16_t)(((DEAD_TIME_ADV_TIM_CLK_MHz * DEADTIME_NS/2) /1000uL) + 128)
#elif (DEAD_TIME_COUNTS_1 <= 1008)
#define DEAD_TIME_COUNTS (uint16_t)(((DEAD_TIME_ADV_TIM_CLK_MHz * DEADTIME_NS/8) /1000uL) + 320)
#elif (DEAD_TIME_COUNTS_1 <= 2015)
#define DEAD_TIME_COUNTS (uint16_t)(((DEAD_TIME_ADV_TIM_CLK_MHz * DEADTIME_NS/16) /1000uL) + 384)
#else
#define DEAD_TIME_COUNTS 510
#endif
#define DTCOMPCNT (uint16_t)((DEADTIME_NS * ADV_TIM_CLK_MHz) / 2000)
#define TON_NS 500
#define TOFF_NS 500
#define TON (uint16_t)((TON_NS * ADV_TIM_CLK_MHz) / 2000)
#define TOFF (uint16_t)((TOFF_NS * ADV_TIM_CLK_MHz) / 2000)
/**********************/
/* MOTOR 1 ADC Timing */
/**********************/
/* In ADV_TIMER CLK cycles*/
#define SAMPLING_TIME ((ADC_SAMPLING_CYCLES * ADV_TIM_CLK_MHz) / ADC_CLK_MHz)
#define TRISE ((TRISE_NS * ADV_TIM_CLK_MHz)/1000uL)
#define TDEAD ((uint16_t)((DEADTIME_NS * ADV_TIM_CLK_MHz)/1000))
#define TNOISE ((uint16_t)((TNOISE_NS*ADV_TIM_CLK_MHz)/1000))
#define HTMIN 1 /* Required for main.c compilation only, CCR4 is overwritten at runtime */
#define TW_AFTER ((uint16_t)(((DEADTIME_NS+MAX_TNTR_NS)*ADV_TIM_CLK_MHz)/1000UL))
#define MAX_TWAIT ((uint16_t)((TW_AFTER - SAMPLING_TIME)/2))
#define TW_BEFORE ((uint16_t)((ADC_TRIG_CONV_LATENCY_CYCLES + ADC_SAMPLING_CYCLES) * ADV_TIM_CLK_MHz) / ADC_CLK_MHz + 1u)
#define TW_BEFORE_R3_1 ((uint16_t)((ADC_TRIG_CONV_LATENCY_CYCLES + ADC_SAMPLING_CYCLES*2 + ADC_SAR_CYCLES) * ADV_TIM_CLK_MHz) / ADC_CLK_MHz + 1u)
/* USER CODE BEGIN temperature */
#define M1_VIRTUAL_HEAT_SINK_TEMPERATURE_VALUE 25u
#define M1_TEMP_SW_FILTER_BW_FACTOR 250u
/* USER CODE END temperature */
#define PQD_CONVERSION_FACTOR (float_t)(((1.732 * ADC_REFERENCE_VOLTAGE) /\
(RSHUNT * AMPLIFICATION_GAIN)) / 65536.0f)
/****** Prepares the UI configurations according the MCconfxx settings ********/
#define DAC_ENABLE
#define DAC_OP_ENABLE
/* Motor 1 settings */
#define FW_ENABLE
#define DIFFTERM_ENABLE
/* Sensors setting */
#define AUX_SCFG UI_SCODE_STO_PLL
#define MAIN_SCFG UI_SCODE_ENC
#define PLLTUNING_ENABLE
#define UI_CFGOPT_PFC_ENABLE
/*******************************************************************************
* UI configurations settings. It can be manually overwritten if special
* configuartion is required.
*******************************************************************************/
/* Specific options of UI */
#define UI_CONFIG_M1 (UI_CFGOPT_NONE DAC_OP_ENABLE FW_ENABLE DIFFTERM_ENABLE\
| (MAIN_SCFG << MAIN_SCFG_POS)\
| (AUX_SCFG << AUX_SCFG_POS)\
| UI_CFGOPT_SETIDINSPDMODE PLLTUNING_ENABLE UI_CFGOPT_PFC_ENABLE\
| UI_CFGOPT_PLLTUNING)
#define UI_CONFIG_M2
#define DIN_ACTIVE_LOW Bit_RESET
#define DIN_ACTIVE_HIGH Bit_SET
#define DOUT_ACTIVE_HIGH DOutputActiveHigh
#define DOUT_ACTIVE_LOW DOutputActiveLow
/********** AUXILIARY ENCODER TIMER MOTOR 1 *************/
#define M1_PULSE_NBR ((4 * (M1_ENCODER_PPR)) - 1)
#define M1_ENC_IC_FILTER_LL LL_TIM_IC_FILTER_FDIV16_N8
#define M1_ENC_IC_FILTER 12
#define SPD_TIM_M1_IRQHandler TIM2_IRQHandler
#define LPF_FILT_CONST ((int16_t)(32767 * 0.5))
/* MMI Table Motor 1 MAX_MODULATION_100_PER_CENT */
#define MAX_MODULE (uint16_t)((100* 32767)/100)
#define SAMPLING_CYCLE_CORRECTION 0.5 /* Add half cycle required by STM32G474RETx ADC */
#define LL_ADC_SAMPLINGTIME_1CYCLES_5 LL_ADC_SAMPLINGTIME_1CYCLE_5
//cstat !MISRAC2012-Rule-20.10 !DEFINE-hash-multiple
#define LL_ADC_SAMPLING_CYCLE(CYCLE) LL_ADC_SAMPLINGTIME_ ## CYCLE ## CYCLES_5
#endif /*PARAMETERS_CONVERSION_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 12,247 | C | 52.021645 | 146 | 0.558912 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/parameters_conversion_g4xx.h |
/**
******************************************************************************
* @file parameters_conversion_g4xx.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains the definitions needed to convert MC SDK parameters
* so as to target the STM32G4 Family.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef PARAMETERS_CONVERSION_G4XX_H
#define PARAMETERS_CONVERSION_G4XX_H
#include "drive_parameters.h"
#include "power_stage_parameters.h"
#include "mc_math.h"
/************************* CPU & ADC PERIPHERAL CLOCK CONFIG ******************/
#define SYSCLK_FREQ 170000000uL
#define TIM_CLOCK_DIVIDER 1
#define ADV_TIM_CLK_MHz 170 /* Actual TIM clk including Timer clock divider*/
#define ADC_CLK_MHz 42
#define HALL_TIM_CLK 170000000uL
#define APB1TIM_FREQ 170000000uL
/************************* IRQ Handler Mapping *********************/
#define TIMx_UP_M1_IRQHandler TIM1_UP_TIM16_IRQHandler
#define TIMx_BRK_M1_IRQHandler TIM1_BRK_TIM15_IRQHandler
#define ADC_TRIG_CONV_LATENCY_CYCLES 3.5
#define ADC_SAR_CYCLES 12.5
#define M1_VBUS_SW_FILTER_BW_FACTOR 6u
#define OPAMP1_InvertingInput_PC5 LL_OPAMP_INPUT_INVERT_IO0
#define OPAMP1_InvertingInput_PA3 LL_OPAMP_INPUT_INVERT_IO1
#define OPAMP1_InvertingInput_PGA LL_OPAMP_INPUT_INVERT_CONNECT_NO
#define OPAMP1_InvertingInput_FOLLOWER LL_OPAMP_MODE_FOLLOWER
#define OPAMP2_InvertingInput_PC5 LL_OPAMP_INPUT_INVERT_IO0
#define OPAMP2_InvertingInput_PA5 LL_OPAMP_INPUT_INVERT_IO1
#define OPAMP2_InvertingInput_PGA LL_OPAMP_INPUT_INVERT_CONNECT_NO
#define OPAMP2_InvertingInput_FOLLOWER LL_OPAMP_MODE_FOLLOWER
#define OPAMP3_InvertingInput_PB10 LL_OPAMP_INPUT_INVERT_IO0
#define OPAMP3_InvertingInput_PB2 LL_OPAMP_INPUT_INVERT_IO1
#define OPAMP3_InvertingInput_PGA LL_OPAMP_INPUT_INVERT_CONNECT_NO
#define OPAMP3_InvertingInput_FOLLOWER LL_OPAMP_MODE_FOLLOWER
#define OPAMP4_InvertingInput_PB10 LL_OPAMP_INPUT_INVERT_IO0
#define OPAMP4_InvertingInput_PD8 LL_OPAMP_INPUT_INVERT_IO1
#define OPAMP4_InvertingInput_PGA LL_OPAMP_INPUT_INVERT_CONNECT_NO
#define OPAMP4_InvertingInput_FOLLOWER LL_OPAMP_MODE_FOLLOWER
#define OPAMP1_NonInvertingInput_PA1 LL_OPAMP_INPUT_NONINVERT_IO0
#define OPAMP1_NonInvertingInput_PA3 LL_OPAMP_INPUT_NONINVERT_IO1
#define OPAMP1_NonInvertingInput_PA7 LL_OPAMP_INPUT_NONINVERT_IO2
#define OPAMP2_NonInvertingInput_PA7 LL_OPAMP_INPUT_NONINVERT_IO0
#define OPAMP2_NonInvertingInput_PB14 LL_OPAMP_INPUT_NONINVERT_IO1
#define OPAMP2_NonInvertingInput_PB0 LL_OPAMP_INPUT_NONINVERT_IO2
#define OPAMP2_NonInvertingInput_PD14 LL_OPAMP_INPUT_NONINVERT_IO3
#define OPAMP3_NonInvertingInput_PB0 LL_OPAMP_INPUT_NONINVERT_IO0
#define OPAMP3_NonInvertingInput_PB13 LL_OPAMP_INPUT_NONINVERT_IO1
#define OPAMP3_NonInvertingInput_PA1 LL_OPAMP_INPUT_NONINVERT_IO2
#define OPAMP4_NonInvertingInput_PB13 LL_OPAMP_INPUT_NONINVERT_IO0
#define OPAMP4_NonInvertingInput_PD11 LL_OPAMP_INPUT_NONINVERT_IO1
#define OPAMP4_NonInvertingInput_PB11 LL_OPAMP_INPUT_NONINVERT_IO2
#define OPAMP5_NonInvertingInput_PB14 LL_OPAMP_INPUT_NONINVERT_IO0
#define OPAMP5_NonInvertingInput_PD12 LL_OPAMP_INPUT_NONINVERT_IO1
#define OPAMP5_NonInvertingInput_PC3 LL_OPAMP_INPUT_NONINVERT_IO2
#define OPAMP6_NonInvertingInput_PB12 LL_OPAMP_INPUT_NONINVERT_IO0
#define OPAMP6_NonInvertingInput_PD9 LL_OPAMP_INPUT_NONINVERT_IO1
#define OPAMP6_NonInvertingInput_PB13 LL_OPAMP_INPUT_NONINVERT_IO2
#define OPAMP1_PGAConnect_PC5 OPAMP_CSR_PGGAIN_3
#define OPAMP1_PGAConnect_PA3 (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_PGGAIN_2)
#define OPAMP2_PGAConnect_PC5 OPAMP_CSR_PGGAIN_3
#define OPAMP2_PGAConnect_PA5 (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_PGGAIN_2)
#define OPAMP3_PGAConnect_PB10 OPAMP_CSR_PGGAIN_3
#define OPAMP3_PGAConnect_PB2 (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_PGGAIN_2)
#define OPAMP4_PGAConnect_PB10 OPAMP_CSR_PGGAIN_3
#define OPAMP4_PGAConnect_PD8 (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_PGGAIN_2)
#define COMP1_InvertingInput_PA0 LL_COMP_INPUT_MINUS_IO1
#define COMP2_InvertingInput_PA2 LL_COMP_INPUT_MINUS_IO1
#define COMP3_InvertingInput_PD15 LL_COMP_INPUT_MINUS_IO1
#define COMP3_InvertingInput_PB12 LL_COMP_INPUT_MINUS_IO2
#define COMP4_InvertingInput_PE8 LL_COMP_INPUT_MINUS_IO1
#define COMP4_InvertingInput_PB2 LL_COMP_INPUT_MINUS_IO2
#define COMP5_InvertingInput_PD13 LL_COMP_INPUT_MINUS_IO1
#define COMP5_InvertingInput_PB10 LL_COMP_INPUT_MINUS_IO2
#define COMP6_InvertingInput_PD10 LL_COMP_INPUT_MINUS_IO1
#define COMP6_InvertingInput_PB15 LL_COMP_INPUT_MINUS_IO2
#define COMP7_InvertingInput_PC0 LL_COMP_INPUT_MINUS_IO1
#define COMPX_InvertingInput_DAC1 LL_COMP_INPUT_MINUS_DAC1_CH1
#define COMPX_InvertingInput_DAC2 LL_COMP_INPUT_MINUS_DAC1_CH2
#define COMPX_InvertingInput_VREF LL_COMP_INPUT_MINUS_VREFINT
#define COMPX_InvertingInput_VREF_1_4 LL_COMP_INPUT_MINUS_1_4VREFINT
#define COMPX_InvertingInput_VREF_1_2 LL_COMP_INPUT_MINUS_1_2VREFINT
#define COMPX_InvertingInput_VREF_3_4 LL_COMP_INPUT_MINUS_3_4VREFINT
#define COMP1_NonInvertingInput_PA1 LL_COMP_INPUT_PLUS_IO1
#define COMP2_NonInvertingInput_PA3 LL_COMP_INPUT_PLUS_IO2
#define COMP2_NonInvertingInput_PA7 LL_COMP_INPUT_PLUS_IO1
#define COMP3_NonInvertingInput_PB14 LL_COMP_INPUT_PLUS_IO1
#define COMP3_NonInvertingInput_PD14 LL_COMP_INPUT_PLUS_IO2
#define COMP4_NonInvertingInput_PB0 LL_COMP_INPUT_PLUS_IO1
#define COMP4_NonInvertingInput_PE7 LL_COMP_INPUT_PLUS_IO2
#define COMP5_NonInvertingInput_PB13 LL_COMP_INPUT_PLUS_IO2
#define COMP5_NonInvertingInput_PD12 LL_COMP_INPUT_PLUS_IO1
#define COMP6_NonInvertingInput_PB11 LL_COMP_INPUT_PLUS_IO2
#define COMP6_NonInvertingInput_PD11 LL_COMP_INPUT_PLUS_IO1
#define COMP7_NonInvertingInput_PC1 LL_COMP_INPUT_PLUS_IO2
#define COMP7_NonInvertingInput_PA0 LL_COMP_INPUT_PLUS_IO1
/* USER CODE BEGIN Additional parameters */
/* USER CODE END Additional parameters */
#endif /*PARAMETERS_CONVERSION_G4XX_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 6,947 | C | 51.240601 | 83 | 0.705053 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/dma.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file dma.h
* @brief This file contains all the function prototypes for
* the dma.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DMA_H__
#define __DMA_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* DMA memory to memory transfer handles -------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_DMA_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __DMA_H__ */
| 1,341 | C | 24.320754 | 80 | 0.468307 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/power_stage_parameters.h |
/**
******************************************************************************
* @file power_stage_parameters.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains the parameters needed for the Motor Control SDK
* in order to configure a power stage.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef POWER_STAGE_PARAMETERS_H
#define POWER_STAGE_PARAMETERS_H
/************************
*** Motor Parameters ***
************************/
/************* PWM Driving signals section **************/
#define HW_DEAD_TIME_NS 1000 /*!< Dead-time inserted
by HW if low side signals
are not used */
/*********** Bus voltage sensing section ****************/
#define VBUS_PARTITIONING_FACTOR 0.052164840897235255 /*!< It expresses how
much the Vbus is attenuated
before being converted into
digital value */
#define NOMINAL_BUS_VOLTAGE_V 30
/******** Current reading parameters section ******/
/*** Topology ***/
#define THREE_SHUNT
#define RSHUNT 0.007
/* ICSs gains in case of isolated current sensors,
amplification gain for shunts based sensing */
#define AMPLIFICATION_GAIN 20
/*** Noise parameters ***/
#define TNOISE_NS 1000
#define TRISE_NS 1000
#define MAX_TNTR_NS TRISE_NS
/************ Temperature sensing section ***************/
/* V[V]=V0+dV/dT[V/Celsius]*(T-T0)[Celsius]*/
#define V0_V 0.290 /*!< in Volts */
#define T0_C 25 /*!< in Celsius degrees */
#define dV_dT 0.025 /*!< V/Celsius degrees */
#define T_MAX 70 /*!< Sensor measured
temperature at maximum
power stage working
temperature, Celsius degrees */
#endif /*POWER_STAGE_PARAMETERS_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 2,960 | C | 42.544117 | 86 | 0.440541 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/tim.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file tim.h
* @brief This file contains all the function prototypes for
* the tim.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TIM_H__
#define __TIM_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern TIM_HandleTypeDef htim1;
extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim3;
extern TIM_HandleTypeDef htim5;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_TIM1_Init(void);
void MX_TIM2_Init(void);
void MX_TIM3_Init(void);
void MX_TIM5_Init(void);
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __TIM_H__ */
| 1,519 | C | 22.75 | 80 | 0.526662 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/RTE_Components.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file
* @author MCD Application Team
* @version V2.0.0
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __RTE_COMPONENTS_H__
#define __RTE_COMPONENTS_H__
/* Defines ------------------------------------------------------------------*/
/* STMicroelectronics.X-CUBE-AI.8.1.0 */
#define AI_ApplicationTemplate
#endif /* __RTE_COMPONENTS_H__ */
| 1,003 | C | 33.620688 | 82 | 0.440678 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/motorcontrol.h | /**
******************************************************************************
* @file motorcontrol.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief Motor Control Subsystem initialization functions.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCInterface
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MOTORCONTROL_H
#define MOTORCONTROL_H
#include "mc_config.h"
#include "parameters_conversion.h"
#include "mc_api.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MCInterface
* @{
*/
/* Initializes the Motor Control Subsystem */
void MX_MotorControl_Init(void);
/* Do not remove the definition of this symbol. */
#define MC_HAL_IS_USED
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* MOTORCONTROL_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 1,506 | C | 23.704918 | 80 | 0.518592 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_api.h |
/**
******************************************************************************
* @file mc_api.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file defines the high level interface of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCIAPI
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MC_API_H
#define MC_API_H
#include "mc_type.h"
#include "mc_interface.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup CAI
* @{
*/
/** @addtogroup MCIAPI
* @{
*/
/* Starts Motor 1 */
bool MC_StartMotor1(void);
/* Stops Motor 1 */
bool MC_StopMotor1(void);
/* Programs a Speed ramp for Motor 1 */
void MC_ProgramSpeedRampMotor1(int16_t hFinalSpeed, uint16_t hDurationms);
/* Programs a Speed ramp for Motor 1 */
void MC_ProgramSpeedRampMotor1_F(float_t FinalSpeed, uint16_t hDurationms);
/* Programs a Torque ramp for Motor 1 */
void MC_ProgramTorqueRampMotor1(int16_t hFinalTorque, uint16_t hDurationms);
/* Programs a Torque ramp for Motor 1 */
void MC_ProgramTorqueRampMotor1_F(float_t FinalTorque, uint16_t hDurationms);
/* Programs a current reference for Motor 1 */
void MC_SetCurrentReferenceMotor1(qd_t Iqdref);
/* Programs a current reference for Motor 1 */
void MC_SetCurrentReferenceMotor1_F(qd_f_t IqdRef);
/* Returns the state of the last submited command for Motor 1 */
MCI_CommandState_t MC_GetCommandStateMotor1(void);
/* Stops the execution of the current speed ramp for Motor 1 if any */
bool MC_StopSpeedRampMotor1(void);
/* Stops the execution of the on going ramp for Motor 1 if any.
Note: this function is deprecated and should not be used anymore. It will be removed in a future version. */
void MC_StopRampMotor1(void);
/* Returns true if the last submited ramp for Motor 1 has completed, false otherwise */
bool MC_HasRampCompletedMotor1(void);
/* Returns the current mechanical rotor speed reference set for Motor 1, expressed in the unit defined by #SPEED_UNIT */
int16_t MC_GetMecSpeedReferenceMotor1(void);
/* Returns the current mechanical rotor speed reference set for Motor 1, expressed in rpm */
float_t MC_GetMecSpeedReferenceMotor1_F(void);
/* Returns the last computed average mechanical rotor speed for Motor 1, expressed in the unit defined by #SPEED_UNIT */
int16_t MC_GetMecSpeedAverageMotor1(void);
/* Returns the last computed average mechanical rotor speed for Motor 1, expressed in rpm */
float_t MC_GetAverageMecSpeedMotor1_F(void);
/* Returns the last computed average mechanical rotor speed from auxiliary sensor for Motor 1, expressed in the unit defined by #SPEED_UNIT */
int16_t MC_GetMecAuxiliarySpeedAverageM1(void);
/* Returns the last computed average mechanical rotor speed from auxiliary sensor for Motor 1, expressed in RPM */
float_t MC_GetMecAuxiliarySpeedAvgM1_F(void);
/* Returns the electrical angle of the rotor from auxiliary sensor of Motor 1, in DDP format */
int16_t MC_GetAuxiliaryElAngledppMotor1(void);
/* Returns the electrical angle of the rotor from auxiliary sensor of Motor 1, expressed in radians */
float_t MC_GetAuxiliaryElAngleMotor1_F(void);
/* Returns the final speed of the last ramp programmed for Motor 1, if this ramp was a speed ramp */
int16_t MC_GetLastRampFinalSpeedMotor1(void);
/* Returns the final speed of the last ramp programmed for Motor 1, if this ramp was a speed ramp */
float_t MC_GetLastRampFinalSpeedM1_F(void);
/* Returns the current Control Mode for Motor 1 (either Speed or Torque) */
MC_ControlMode_t MC_GetControlModeMotor1(void);
/* Returns the direction imposed by the last command on Motor 1 */
int16_t MC_GetImposedDirectionMotor1(void);
/* Returns the current reliability of the speed sensor used for Motor 1 */
bool MC_GetSpeedSensorReliabilityMotor1(void);
/* returns the amplitude of the phase current injected in Motor 1 */
int16_t MC_GetPhaseCurrentAmplitudeMotor1(void);
/* returns the amplitude of the phase voltage applied to Motor 1 */
int16_t MC_GetPhaseVoltageAmplitudeMotor1(void);
/* returns current Ia and Ib values for Motor 1 */
ab_t MC_GetIabMotor1(void);
/* returns current Ia and Ib values in Ampere for Motor 1 */
ab_f_t MC_GetIabMotor1_F(void);
/* returns current Ialpha and Ibeta values for Motor 1 */
alphabeta_t MC_GetIalphabetaMotor1(void);
/* returns current Iq and Id values for Motor 1 */
qd_t MC_GetIqdMotor1(void);
/* returns current Iq and Id values in Ampere for Motor 1 */
qd_f_t MC_GetIqdMotor1_F(void);
/* returns Iq and Id reference values for Motor 1 */
qd_t MC_GetIqdrefMotor1(void);
/* returns Iq and Id reference values for Motor 1 */
qd_f_t MC_GetIqdrefMotor1_F(void);
/* returns current Vq and Vd values for Motor 1 */
qd_t MC_GetVqdMotor1(void);
/* returns current Valpha and Vbeta values for Motor 1 */
alphabeta_t MC_GetValphabetaMotor1(void);
/* returns the electrical angle of the rotor of Motor 1, in DDP format */
int16_t MC_GetElAngledppMotor1(void);
/* returns the current electrical torque reference for Motor 1 */
int16_t MC_GetTerefMotor1(void);
/* returns the current electrical torque reference in Ampere for Motor 1 */
float_t MC_GetTerefMotor1_F(void);
/* re-initializes Iq and Id references to their default values */
void MC_Clear_IqdrefMotor1(void);
/* Sets the polarization offset values to use for Motor 1*/
bool MC_SetPolarizationOffsetsMotor1(PolarizationOffsets_t * PolarizationOffsets);
/* @brief Returns the polarization offset values measured or set for Motor 1 */
bool MC_GetPolarizationOffsetsMotor1(PolarizationOffsets_t * PolarizationOffsets);
/* Starts the polarization offsets measurement procedure for Motor 1. */
bool MC_StartPolarizationOffsetsMeasurementMotor1(void);
/* Acknowledge a Motor Control fault on Motor 1 */
bool MC_AcknowledgeFaultMotor1(void);
/* Returns a bitfiled showing faults that occured since the State Machine of Motor 1 was moved to FAULT_NOW state */
uint16_t MC_GetOccurredFaultsMotor1(void);
/* Returns a bitfield showing all current faults on Motor 1 */
uint16_t MC_GetCurrentFaultsMotor1(void);
/* returns the current state of Motor 1 state machine */
MCI_State_t MC_GetSTMStateMotor1(void);
/* returns the current power of Motor 1 in float_t format */
float_t MC_GetAveragePowerMotor1_F(void);
/* Call the Profiler command */
uint8_t MC_ProfilerCommand (uint16_t rxLength, uint8_t *rxBuffer, int16_t txSyncFreeSpace, uint16_t *txLength, uint8_t *txBuffer);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* MC_API_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 7,222 | C | 33.232227 | 142 | 0.713237 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/network_config.h |
/**
******************************************************************************
* @file network_config.h
* @author AST Embedded Analytics Research Platform
* @date Tue Jan 16 16:02:48 2024
* @brief AI Tool Automatic Code Generator for Custom Layers Implementation
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
******************************************************************************
*/
#ifndef AI_NETWORK_CONFIG_H
#define AI_NETWORK_CONFIG_H
#pragma once
#undef AI_TOOLS_VERSION_MAJOR
#undef AI_TOOLS_VERSION_MINOR
#undef AI_TOOLS_VERSION_MICRO
#define AI_TOOLS_VERSION_MAJOR 8
#define AI_TOOLS_VERSION_MINOR 1
#define AI_TOOLS_VERSION_MICRO 0
#define AI_TOOLS_VERSION_EXTRA "19520"
#undef AI_PLATFORM_API_MAJOR
#undef AI_PLATFORM_API_MINOR
#undef AI_PLATFORM_API_MICRO
#define AI_PLATFORM_API_MAJOR (1)
#define AI_PLATFORM_API_MINOR (1)
#define AI_PLATFORM_API_MICRO (0)
#undef AI_TOOLS_API_VERSION_MAJOR
#undef AI_TOOLS_API_VERSION_MINOR
#undef AI_TOOLS_API_VERSION_MICRO
#define AI_TOOLS_API_VERSION_MAJOR (1)
#define AI_TOOLS_API_VERSION_MINOR (5)
#define AI_TOOLS_API_VERSION_MICRO (0)
#endif /*AI_NETWORK_CONFIG_H*/
| 1,510 | C | 30.479166 | 80 | 0.611921 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/drive_parameters.h |
/**
******************************************************************************
* @file drive_parameters.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains the parameters needed for the Motor Control SDK
* in order to configure a motor drive.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef DRIVE_PARAMETERS_H
#define DRIVE_PARAMETERS_H
/************************
*** Motor Parameters ***
************************/
/******** MAIN AND AUXILIARY SPEED/POSITION SENSOR(S) SETTINGS SECTION ********/
/*** Speed measurement settings ***/
#define MAX_APPLICATION_SPEED_RPM 2478 /*!< rpm, mechanical */
#define MIN_APPLICATION_SPEED_RPM 0 /*!< rpm, mechanical,
absolute value */
#define M1_SS_MEAS_ERRORS_BEFORE_FAULTS 3 /*!< Number of speed
measurement errors before
main sensor goes in fault */
/*** Encoder **********************/
#define ENC_AVERAGING_FIFO_DEPTH 16 /*!< depth of the FIFO used to
average mechanical speed in
0.1Hz resolution */
/****** State Observer + PLL ****/
#define VARIANCE_THRESHOLD 0.25 /*!<Maximum accepted
variance on speed
estimates (percentage) */
/* State observer scaling factors F1 */
#define F1 8192
#define F2 16384
#define F1_LOG LOG2((8192))
#define F2_LOG LOG2((16384))
/* State observer constants */
#define GAIN1 -11321
#define GAIN2 8442
/*Only in case PLL is used, PLL gains */
#define PLL_KP_GAIN 1154
#define PLL_KI_GAIN 51
#define PLL_KPDIV 16384
#define PLL_KPDIV_LOG LOG2((PLL_KPDIV))
#define PLL_KIDIV 65535
#define PLL_KIDIV_LOG LOG2((PLL_KIDIV))
#define STO_FIFO_DEPTH_DPP 64 /*!< Depth of the FIFO used
to average mechanical speed
in dpp format */
#define STO_FIFO_DEPTH_DPP_LOG LOG2((64))
#define STO_FIFO_DEPTH_UNIT 64 /*!< Depth of the FIFO used
to average mechanical speed
in the unit defined by #SPEED_UNIT */
#define M1_BEMF_CONSISTENCY_TOL 64 /* Parameter for B-emf
amplitude-speed consistency */
#define M1_BEMF_CONSISTENCY_GAIN 64 /* Parameter for B-emf
amplitude-speed consistency */
/* USER CODE BEGIN angle reconstruction M1 */
#define PARK_ANGLE_COMPENSATION_FACTOR 0
#define REV_PARK_ANGLE_COMPENSATION_FACTOR 0
/* USER CODE END angle reconstruction M1 */
/************************** DRIVE SETTINGS SECTION **********************/
/* PWM generation and current reading */
#define PWM_FREQUENCY 16000
#define PWM_FREQ_SCALING 1
#define LOW_SIDE_SIGNALS_ENABLING LS_PWM_TIMER
#define SW_DEADTIME_NS 850 /*!< Dead-time to be inserted
by FW, only if low side
signals are enabled */
/* Torque and flux regulation loops */
#define REGULATION_EXECUTION_RATE 1 /*!< FOC execution rate in
number of PWM cycles */
#define ISR_FREQUENCY_HZ (PWM_FREQUENCY/REGULATION_EXECUTION_RATE) /*!< @brief FOC execution rate in
Hz */
/* Gains values for torque and flux control loops */
#define PID_TORQUE_KP_DEFAULT 2317
#define PID_TORQUE_KI_DEFAULT 730
#define PID_TORQUE_KD_DEFAULT 100
#define PID_FLUX_KP_DEFAULT 2317
#define PID_FLUX_KI_DEFAULT 730
#define PID_FLUX_KD_DEFAULT 100
/* Torque/Flux control loop gains dividers*/
#define TF_KPDIV 8192
#define TF_KIDIV 16384
#define TF_KDDIV 8192
#define TF_KPDIV_LOG LOG2((8192))
#define TF_KIDIV_LOG LOG2((16384))
#define TF_KDDIV_LOG LOG2((8192))
#define TFDIFFERENTIAL_TERM_ENABLING DISABLE
/* Speed control loop */
#define SPEED_LOOP_FREQUENCY_HZ ( uint16_t )1000 /*!<Execution rate of speed
regulation loop (Hz) */
#define PID_SPEED_KP_DEFAULT 1000/(SPEED_UNIT/10) /* Workbench compute the gain for 01Hz unit*/
#define PID_SPEED_KI_DEFAULT 100/(SPEED_UNIT/10) /* Workbench compute the gain for 01Hz unit*/
#define PID_SPEED_KD_DEFAULT 0/(SPEED_UNIT/10) /* Workbench compute the gain for 01Hz unit*/
/* Speed PID parameter dividers */
#define SP_KPDIV 256
#define SP_KIDIV 32768
#define SP_KDDIV 16
#define SP_KPDIV_LOG LOG2((256))
#define SP_KIDIV_LOG LOG2((32768))
#define SP_KDDIV_LOG LOG2((16))
/* USER CODE BEGIN PID_SPEED_INTEGRAL_INIT_DIV */
#define PID_SPEED_INTEGRAL_INIT_DIV 1 /* */
/* USER CODE END PID_SPEED_INTEGRAL_INIT_DIV */
#define SPD_DIFFERENTIAL_TERM_ENABLING DISABLE
#define IQMAX_A 10
/* Default settings */
#define DEFAULT_CONTROL_MODE MCM_SPEED_MODE
#define DEFAULT_TARGET_SPEED_RPM 892
#define DEFAULT_TARGET_SPEED_UNIT (DEFAULT_TARGET_SPEED_RPM*SPEED_UNIT/U_RPM)
#define DEFAULT_TORQUE_COMPONENT_A 0
#define DEFAULT_FLUX_COMPONENT_A 0
/************************** FIRMWARE PROTECTIONS SECTION *****************/
#define OV_VOLTAGE_THRESHOLD_V 36 /*!< Over-voltage
threshold */
#define UD_VOLTAGE_THRESHOLD_V 6 /*!< Under-voltage
threshold */
#ifdef NOT_IMPLEMENTED
#define ON_OVER_VOLTAGE TURN_OFF_PWM /*!< TURN_OFF_PWM,
TURN_ON_R_BRAKE or
TURN_ON_LOW_SIDES */
#endif /* NOT_IMPLEMENTED */
#define OV_TEMPERATURE_THRESHOLD_C 70 /*!< Celsius degrees */
#define OV_TEMPERATURE_HYSTERESIS_C 10 /*!< Celsius degrees */
#define HW_OV_CURRENT_PROT_BYPASS DISABLE /*!< In case ON_OVER_VOLTAGE
is set to TURN_ON_LOW_SIDES
this feature may be used to
bypass HW over-current
protection (if supported by
power stage) */
#define OVP_INVERTINGINPUT_MODE INT_MODE
#define OVP_INVERTINGINPUT_MODE2 INT_MODE
#define OVP_SELECTION COMP_Selection_COMP1
#define OVP_SELECTION2 COMP_Selection_COMP1
/****************************** START-UP PARAMETERS **********************/
/* Encoder alignment */
#define M1_ALIGNMENT_DURATION 700 /*!< milliseconds */
#define M1_ALIGNMENT_ANGLE_DEG 90 /*!< degrees [0...359] */
#define FINAL_I_ALIGNMENT_A 10 /*!< s16A */
// With ALIGNMENT_ANGLE_DEG equal to 90 degrees final alignment
// phase current = (FINAL_I_ALIGNMENT * 1.65/ Av)/(32767 * Rshunt)
// being Av the voltage gain between Rshunt and A/D input
/* Observer start-up output conditions */
#define OBS_MINIMUM_SPEED_RPM 1000
#define NB_CONSECUTIVE_TESTS 2 /* corresponding to
former NB_CONSECUTIVE_TESTS/
(TF_REGULATION_RATE/
MEDIUM_FREQUENCY_TASK_RATE) */
#define SPEED_BAND_UPPER_LIMIT 17 /*!< It expresses how much
estimated speed can exceed
forced stator electrical
without being considered wrong.
In 1/16 of forced speed */
#define SPEED_BAND_LOWER_LIMIT 15 /*!< It expresses how much
estimated speed can be below
forced stator electrical
without being considered wrong.
In 1/16 of forced speed */
#define TRANSITION_DURATION 25 /* Switch over duration, ms */
/****************************** BUS VOLTAGE Motor 1 **********************/
#define M1_VBUS_SAMPLING_TIME LL_ADC_SAMPLING_CYCLE(47)
/****************************** Current sensing Motor 1 **********************/
#define ADC_SAMPLING_CYCLES (6 + SAMPLING_CYCLE_CORRECTION)
/****************************** ADDITIONAL FEATURES **********************/
/*** On the fly start-up ***/
/**************************
*** Control Parameters ***
**************************/
/* ##@@_USER_CODE_START_##@@ */
/* ##@@_USER_CODE_END_##@@ */
#endif /*DRIVE_PARAMETERS_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 10,689 | C | 47.590909 | 104 | 0.461222 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/main.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx_hal.h"
#include "motorcontrol.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define Start_Stop_Pin GPIO_PIN_13
#define Start_Stop_GPIO_Port GPIOC
#define Start_Stop_EXTI_IRQn EXTI15_10_IRQn
#define M1_CURR_AMPL_W_Pin GPIO_PIN_0
#define M1_CURR_AMPL_W_GPIO_Port GPIOC
#define M1_CURR_AMPL_V_Pin GPIO_PIN_1
#define M1_CURR_AMPL_V_GPIO_Port GPIOC
#define M1_CURR_AMPL_U_Pin GPIO_PIN_0
#define M1_CURR_AMPL_U_GPIO_Port GPIOA
#define M1_BUS_VOLTAGE_Pin GPIO_PIN_1
#define M1_BUS_VOLTAGE_GPIO_Port GPIOA
#define UART_TX_Pin GPIO_PIN_2
#define UART_TX_GPIO_Port GPIOA
#define UART_RX_Pin GPIO_PIN_3
#define UART_RX_GPIO_Port GPIOA
#define M1_PWM_UL_Pin GPIO_PIN_7
#define M1_PWM_UL_GPIO_Port GPIOA
#define M1_PWM_VL_Pin GPIO_PIN_0
#define M1_PWM_VL_GPIO_Port GPIOB
#define M1_PWM_WL_Pin GPIO_PIN_1
#define M1_PWM_WL_GPIO_Port GPIOB
#define M1_PWM_UH_Pin GPIO_PIN_8
#define M1_PWM_UH_GPIO_Port GPIOA
#define M1_PWM_VH_Pin GPIO_PIN_9
#define M1_PWM_VH_GPIO_Port GPIOA
#define M1_PWM_WH_Pin GPIO_PIN_10
#define M1_PWM_WH_GPIO_Port GPIOA
#define TMS_Pin GPIO_PIN_13
#define TMS_GPIO_Port GPIOA
#define TCK_Pin GPIO_PIN_14
#define TCK_GPIO_Port GPIOA
#define M1_ENCODER_A_Pin GPIO_PIN_15
#define M1_ENCODER_A_GPIO_Port GPIOA
#define M1_ENCODER_B_Pin GPIO_PIN_3
#define M1_ENCODER_B_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
| 3,171 | C | 28.64486 | 80 | 0.5462 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_math.h |
/**
******************************************************************************
* @file mc_math.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides mathematics functions useful for and specific to
* Motor Control.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MC_Math
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MC_MATH_H
#define MC_MATH_H
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup MC_Math
* @{
*/
#define SQRT_2 1.4142
#define SQRT_3 1.732
/* CORDIC coprocessor configuration register settings */
/* CORDIC FUNCTION: PHASE q1.31 (Electrical Angle computation) */
#define CORDIC_CONFIG_PHASE (LL_CORDIC_FUNCTION_PHASE | LL_CORDIC_PRECISION_6CYCLES | LL_CORDIC_SCALE_0 |\
LL_CORDIC_NBWRITE_2 | LL_CORDIC_NBREAD_1 |\
LL_CORDIC_INSIZE_32BITS | LL_CORDIC_OUTSIZE_32BITS)
/* CORDIC FUNCTION: SQUAREROOT q1.31 */
#define CORDIC_CONFIG_SQRT (LL_CORDIC_FUNCTION_SQUAREROOT | LL_CORDIC_PRECISION_6CYCLES | LL_CORDIC_SCALE_1 |\
LL_CORDIC_NBWRITE_1 | LL_CORDIC_NBREAD_1 |\
LL_CORDIC_INSIZE_32BITS | LL_CORDIC_OUTSIZE_32BITS)
/* CORDIC FUNCTION: COSINE q1.15 */
#define CORDIC_CONFIG_COSINE (LL_CORDIC_FUNCTION_COSINE | LL_CORDIC_PRECISION_6CYCLES | LL_CORDIC_SCALE_0 |\
LL_CORDIC_NBWRITE_1 | LL_CORDIC_NBREAD_1 |\
LL_CORDIC_INSIZE_16BITS | LL_CORDIC_OUTSIZE_16BITS)
/* CORDIC FUNCTION: MODULUS q1.15 */
#define CORDIC_CONFIG_MODULUS (LL_CORDIC_FUNCTION_MODULUS | LL_CORDIC_PRECISION_6CYCLES | LL_CORDIC_SCALE_0 |\
LL_CORDIC_NBWRITE_1 | LL_CORDIC_NBREAD_1 |\
LL_CORDIC_INSIZE_16BITS | LL_CORDIC_OUTSIZE_16BITS)
/**
* @brief Macro to compute logarithm of two
*/
#define LOG2(x) \
(((x) == 65535 ) ? 16 : \
(((x) == (2*2*2*2*2*2*2*2*2*2*2*2*2*2*2)) ? 15 : \
(((x) == (2*2*2*2*2*2*2*2*2*2*2*2*2*2)) ? 14 : \
(((x) == (2*2*2*2*2*2*2*2*2*2*2*2*2)) ? 13 : \
(((x) == (2*2*2*2*2*2*2*2*2*2*2*2)) ? 12 : \
(((x) == (2*2*2*2*2*2*2*2*2*2*2)) ? 11 : \
(((x) == (2*2*2*2*2*2*2*2*2*2)) ? 10 : \
(((x) == (2*2*2*2*2*2*2*2*2)) ? 9 : \
(((x) == (2*2*2*2*2*2*2*2)) ? 8 : \
(((x) == (2*2*2*2*2*2*2)) ? 7 : \
(((x) == (2*2*2*2*2*2)) ? 6 : \
(((x) == (2*2*2*2*2)) ? 5 : \
(((x) == (2*2*2*2)) ? 4 : \
(((x) == (2*2*2)) ? 3 : \
(((x) == (2*2)) ? 2 : \
(((x) == 2) ? 1 : \
(((x) == 1) ? 0 : -1)))))))))))))))))
/**
* @brief Trigonometrical functions type definition
*/
typedef struct
{
int16_t hCos;
int16_t hSin;
} Trig_Components;
/**
* @brief This function transforms stator currents Ia and qIb (which are
* directed along axes each displaced by 120 degrees) into currents
* Ialpha and Ibeta in a stationary qd reference frame.
* Ialpha = Ia
* Ibeta = -(2*Ib+Ia)/sqrt(3)
* @param Curr_Input: stator current Ia and Ib in ab_t format.
* @retval Stator current Ialpha and Ibeta in alphabeta_t format.
*/
alphabeta_t MCM_Clarke(ab_t Input);
/**
* @brief This function transforms stator values alpha and beta, which
* belong to a stationary qd reference frame, to a rotor flux
* synchronous reference frame (properly oriented), so as Iq and Id.
* Id= Ialpha *sin(theta)+qIbeta *cos(Theta)
* Iq=qIalpha *cos(Theta)-qIbeta *sin(Theta)
* @param Curr_Input: stator values alpha and beta in alphabeta_t format.
* @param Theta: rotating frame angular position in q1.15 format.
* @retval Stator current q and d in qd_t format.
*/
qd_t MCM_Park(alphabeta_t Input, int16_t Theta);
/**
* @brief This function transforms stator voltage qVq and qVd, that belong to
* a rotor flux synchronous rotating frame, to a stationary reference
* frame, so as to obtain qValpha and qVbeta:
* Valfa= Vq*Cos(theta)+ Vd*Sin(theta)
* Vbeta=-Vq*Sin(theta)+ Vd*Cos(theta)
* @param Curr_Input: stator voltage Vq and Vd in qd_t format.
* @param Theta: rotating frame angular position in q1.15 format.
* @retval Stator values alpha and beta in alphabeta_t format.
*/
alphabeta_t MCM_Rev_Park(qd_t Input, int16_t Theta);
/**
* @brief This function returns cosine and sine functions of the angle fed in input.
* @param hAngle: angle in q1.15 format.
* @retval Trig_Components Cos(angle) and Sin(angle) in Trig_Components format.
*/
Trig_Components MCM_Trig_Functions(int16_t hAngle);
/**
* @brief It calculates the square root of a non-negative s32. It returns 0 for negative s32.
* @param Input int32_t number.
* @retval int32_t Square root of Input (0 if Input<0).
*/
int32_t MCM_Sqrt(int32_t wInput);
/**
* @brief Sqrt table used by Circle Limitation function
* used for STM32F0/STM32G0 series only
*/
#define SQRT_CIRCLE_LIMITATION {\
0 , 1023 , 1448 , 1773 , 2047 , 2289 , 2508 , 2709,\
2896 , 3071 , 3238 , 3396 , 3547 , 3691 , 3831 , 3965,\
4095 , 4221 , 4344 , 4463 , 4579 , 4692 , 4802 , 4910,\
5016 , 5119 , 5221 , 5320 , 5418 , 5514 , 5608 , 5701,\
5792 , 5882 , 5970 , 6057 , 6143 , 6228 , 6312 , 6394,\
6476 , 6556 , 6636 , 6714 , 6792 , 6868 , 6944 , 7019,\
7094 , 7167 , 7240 , 7312 , 7383 , 7454 , 7524 , 7593,\
7662 , 7730 , 7798 , 7865 , 7931 , 7997 , 8062 , 8127,\
8191 , 8255 , 8318 , 8381 , 8443 , 8505 , 8567 , 8628,\
8688 , 8748 , 8808 , 8867 , 8926 , 8985 , 9043 , 9101,\
9158 , 9215 , 9272 , 9328 , 9384 , 9440 , 9495 , 9550,\
9605 , 9660 , 9714 , 9768 , 9821 , 9874 , 9927 , 9980,\
10032 , 10084 , 10136 , 10188 , 10239 , 10290 , 10341 , 10392,\
10442 , 10492 , 10542 , 10592 , 10641 , 10690 , 10739 , 10788,\
10836 , 10884 , 10932 , 10980 , 11028 , 11075 , 11123 , 11170,\
11217 , 11263 , 11310 , 11356 , 11402 , 11448 , 11494 , 11539,\
11584 , 11630 , 11675 , 11719 , 11764 , 11808 , 11853 , 11897,\
11941 , 11985 , 12028 , 12072 , 12115 , 12158 , 12201 , 12244,\
12287 , 12330 , 12372 , 12414 , 12457 , 12499 , 12541 , 12582,\
12624 , 12665 , 12707 , 12748 , 12789 , 12830 , 12871 , 12911,\
12952 , 12992 , 13032 , 13073 , 13113 , 13153 , 13192 , 13232,\
13272 , 13311 , 13350 , 13390 , 13429 , 13468 , 13507 , 13545,\
13584 , 13623 , 13661 , 13699 , 13737 , 13776 , 13814 , 13851,\
13889 , 13927 , 13965 , 14002 , 14039 , 14077 , 14114 , 14151,\
14188 , 14225 , 14262 , 14298 , 14335 , 14372 , 14408 , 14444,\
14481 , 14517 , 14553 , 14589 , 14625 , 14661 , 14696 , 14732,\
14767 , 14803 , 14838 , 14874 , 14909 , 14944 , 14979 , 15014,\
15049 , 15084 , 15118 , 15153 , 15187 , 15222 , 15256 , 15291,\
15325 , 15359 , 15393 , 15427 , 15461 , 15495 , 15529 , 15562,\
15596 , 15630 , 15663 , 15697 , 15730 , 15763 , 15797 , 15830,\
15863 , 15896 , 15929 , 15962 , 15994 , 16027 , 16060 , 16092,\
16125 , 16157 , 16190 , 16222 , 16254 , 16287 , 16319 , 16351,\
16383 , 16415 , 16447 , 16479 , 16510 , 16542 , 16574 , 16605,\
16637 , 16669 , 16700 , 16731 , 16763 , 16794 , 16825 , 16856,\
16887 , 16918 , 16949 , 16980 , 17011 , 17042 , 17072 , 17103,\
17134 , 17164 , 17195 , 17225 , 17256 , 17286 , 17316 , 17347,\
17377 , 17407 , 17437 , 17467 , 17497 , 17527 , 17557 , 17587,\
17617 , 17646 , 17676 , 17706 , 17735 , 17765 , 17794 , 17824,\
17853 , 17882 , 17912 , 17941 , 17970 , 17999 , 18028 , 18057,\
18086 , 18115 , 18144 , 18173 , 18202 , 18231 , 18259 , 18288,\
18317 , 18345 , 18374 , 18402 , 18431 , 18459 , 18488 , 18516,\
18544 , 18573 , 18601 , 18629 , 18657 , 18685 , 18713 , 18741,\
18769 , 18797 , 18825 , 18853 , 18881 , 18908 , 18936 , 18964,\
18991 , 19019 , 19046 , 19074 , 19101 , 19129 , 19156 , 19184,\
19211 , 19238 , 19265 , 19293 , 19320 , 19347 , 19374 , 19401,\
19428 , 19455 , 19482 , 19509 , 19536 , 19562 , 19589 , 19616,\
19643 , 19669 , 19696 , 19723 , 19749 , 19776 , 19802 , 19829,\
19855 , 19881 , 19908 , 19934 , 19960 , 19987 , 20013 , 20039,\
20065 , 20091 , 20117 , 20143 , 20169 , 20235 , 20231 , 20247,\
20273 , 20299 , 20325 , 20350 , 20376 , 20402 , 20428 , 20453,\
20479 , 20504 , 20530 , 20556 , 20581 , 20606 , 20632 , 20657,\
20683 , 20708 , 20733 , 20759 , 20784 , 20809 , 20834 , 20859,\
20884 , 20910 , 20935 , 20960 , 20985 , 21010 , 21035 , 21059,\
21084 , 21109 , 21134 , 21159 , 21184 , 21208 , 21233 , 21258,\
21282 , 21307 , 21331 , 21356 , 21381 , 21405 , 21430 , 21454,\
21478 , 21503 , 21527 , 21552 , 21576 , 21600 , 21624 , 21649,\
21673 , 21697 , 21721 , 21745 , 21769 , 21793 , 21817 , 21841,\
21865 , 21889 , 21913 , 21937 , 21961 , 21985 , 22009 , 22033,\
22056 , 22080 , 22104 , 22128 , 22151 , 22175 , 22199 , 22222,\
22246 , 22269 , 22293 , 22316 , 22340 , 22363 , 22387 , 22410,\
22434 , 22457 , 22480 , 22504 , 22527 , 22550 , 22573 , 22597,\
22620 , 22643 , 22666 , 22689 , 22712 , 22735 , 22758 , 22781,\
22804 , 22827 , 22850 , 22873 , 22896 , 22919 , 22942 , 22965,\
22988 , 23010 , 23033 , 23056 , 23079 , 23101 , 23124 , 23147,\
23169 , 23192 , 23214 , 23237 , 23260 , 23282 , 23305 , 23327,\
23350 , 23372 , 23394 , 23417 , 23439 , 23462 , 23484 , 23506,\
23529 , 23551 , 23573 , 23595 , 23617 , 23640 , 23662 , 23684,\
23706 , 23728 , 23750 , 23772 , 23794 , 23816 , 23838 , 23860,\
23882 , 23904 , 23926 , 23948 , 23970 , 23992 , 24014 , 24036,\
24057 , 24079 , 24101 , 24123 , 24144 , 24166 , 24188 , 24209,\
24231 , 24253 , 24274 , 24296 , 24317 , 24339 , 24360 , 24382,\
24403 , 24425 , 24446 , 24468 , 24489 , 24511 , 24532 , 24553,\
24575 , 24596 , 24617 , 24639 , 24660 , 24681 , 24702 , 24724,\
24745 , 24766 , 24787 , 24808 , 24829 , 24851 , 24872 , 24893,\
24914 , 24935 , 24956 , 24977 , 24998 , 25019 , 25040 , 25061,\
25082 , 25102 , 25123 , 25144 , 25165 , 25186 , 25207 , 25227,\
25248 , 25269 , 25290 , 25310 , 25331 , 25352 , 25372 , 25393,\
25414 , 25434 , 25455 , 25476 , 25496 , 25517 , 25537 , 25558,\
25578 , 25599 , 25619 , 25640 , 25660 , 25681 , 25701 , 25721,\
25742 , 25762 , 25782 , 25803 , 25823 , 25843 , 25864 , 25884,\
25904 , 25924 , 25945 , 25965 , 25985 , 26005 , 26025 , 26045,\
26065 , 26086 , 26106 , 26126 , 26146 , 26166 , 26186 , 26206,\
26226 , 26246 , 26266 , 26286 , 26306 , 26326 , 26346 , 26365,\
26385 , 26405 , 26425 , 26445 , 26465 , 26484 , 26504 , 26524,\
26544 , 26564 , 26583 , 26603 , 26623 , 26642 , 26662 , 26682,\
26701 , 26721 , 26741 , 26760 , 26780 , 26799 , 26819 , 26838,\
26858 , 26877 , 26897 , 26916 , 26936 , 26955 , 26975 , 26994,\
27014 , 27033 , 27052 , 27072 , 27091 , 27111 , 27130 , 27149,\
27168 , 27188 , 27207 , 27226 , 27246 , 27265 , 27284 , 27303,\
27322 , 27342 , 27361 , 27380 , 27399 , 27418 , 27437 , 27456,\
27475 , 27495 , 27514 , 27533 , 27552 , 27571 , 27590 , 27609,\
27628 , 27647 , 27666 , 27685 , 27703 , 27722 , 27741 , 27760,\
27779 , 27798 , 27817 , 27836 , 27854 , 27873 , 27892 , 27911,\
27930 , 27948 , 27967 , 27986 , 28005 , 28023 , 28042 , 28061,\
28079 , 28098 , 28117 , 28135 , 28154 , 28173 , 28191 , 28210,\
28228 , 28247 , 28265 , 28284 , 28303 , 28321 , 28340 , 28358,\
28377 , 28395 , 28413 , 28432 , 28450 , 28469 , 28487 , 28506,\
28524 , 28542 , 28561 , 28579 , 28597 , 28616 , 28634 , 28652,\
28671 , 28689 , 28707 , 28725 , 28744 , 28762 , 28780 , 28798,\
28817 , 28835 , 28853 , 28871 , 28889 , 28907 , 28925 , 28944,\
28962 , 28980 , 28998 , 29016 , 29034 , 29052 , 29070 , 29088,\
29106 , 29124 , 29142 , 29160 , 29178 , 29196 , 29214 , 29232,\
29250 , 29268 , 29286 , 29304 , 29322 , 29339 , 29357 , 29375,\
29393 , 29411 , 29429 , 29446 , 29464 , 29482 , 29500 , 29518,\
29535 , 29553 , 29571 , 29588 , 29606 , 29624 , 29642 , 29659,\
29677 , 29695 , 29712 , 29730 , 29748 , 29765 , 29783 , 29800,\
29818 , 29835 , 29853 , 29871 , 29888 , 29906 , 29923 , 29941,\
29958 , 29976 , 29993 , 30011 , 30028 , 30046 , 30063 , 30080,\
30098 , 30115 , 30133 , 30150 , 30168 , 30185 , 30202 , 30220,\
30237 , 30254 , 30272 , 30289 , 30306 , 30324 , 30341 , 30358,\
30375 , 30393 , 30410 , 30427 , 30444 , 30461 , 30479 , 30496,\
30513 , 30530 , 30547 , 30565 , 30582 , 30599 , 30616 , 30633,\
30650 , 30667 , 30684 , 30701 , 30719 , 30736 , 30753 , 30770,\
30787 , 30804 , 30821 , 30838 , 30855 , 30872 , 30889 , 30906,\
30923 , 30940 , 30957 , 30973 , 30990 , 31007 , 31024 , 31041,\
31058 , 31075 , 31092 , 31109 , 31125 , 31142 , 31159 , 31176,\
31193 , 31210 , 31226 , 31243 , 31260 , 31277 , 31293 , 31310,\
31327 , 31344 , 31360 , 31377 , 31394 , 31410 , 31427 , 31444,\
31461 , 31477 , 31494 , 31510 , 31527 , 31544 , 31560 , 31577,\
31594 , 31610 , 31627 , 31643 , 31660 , 31676 , 31693 , 31709,\
31726 , 31743 , 31759 , 31776 , 31792 , 31809 , 31825 , 31841,\
31858 , 31874 , 31891 , 31907 , 31924 , 31940 , 31957 , 31973,\
31989 , 32006 , 32023 , 32038 , 32055 , 32071 , 32087 , 32104,\
32120 , 32136 , 32153 , 32169 , 32185 , 32202 , 32218 , 32234,\
32250 , 32267 , 32283 , 32299 , 32315 , 32332 , 32348 , 32364,\
32380 , 32396 , 32413 , 32429 , 32445 , 32461 , 32477 , 32493,\
32509 , 32526 , 32542 , 32558 , 32574 , 32590 , 32606 , 32622,\
32638 , 32654 , 32670 , 32686 , 32702 , 32718 , 32734 , 32750,\
32767 }
#define ATAN1DIV1 (int16_t)8192
#define ATAN1DIV2 (int16_t)4836
#define ATAN1DIV4 (int16_t)2555
#define ATAN1DIV8 (int16_t)1297
#define ATAN1DIV16 (int16_t)651
#define ATAN1DIV32 (int16_t)326
#define ATAN1DIV64 (int16_t)163
#define ATAN1DIV128 (int16_t)81
#define ATAN1DIV256 (int16_t)41
#define ATAN1DIV512 (int16_t)20
#define ATAN1DIV1024 (int16_t)10
#define ATAN1DIV2048 (int16_t)5
#define ATAN1DIV4096 (int16_t)3
#define ATAN1DIV8192 (int16_t)1
/**
* @brief It executes Modulus algorithm.
* @param alpha component,
* beta component.
* @retval int16_t Modulus.
*/
static inline int16_t MCM_Modulus(int16_t alpha, int16_t beta)
{
uint32_t temp_val;
__disable_irq();
/* Configure and call to CORDIC- */
WRITE_REG(CORDIC->CSR,CORDIC_CONFIG_MODULUS);
LL_CORDIC_WriteData(CORDIC, (((uint32_t)beta << 16U) | (uint32_t)alpha));
/* Wait for result */
while(LL_CORDIC_IsActiveFlag_RRDY(CORDIC) == 0U)
{
/* Nothing to do */
}
/* Read computed modulus */
temp_val = ((LL_CORDIC_ReadData(CORDIC) << 16U) >> 16U); /* Avoid Over/underflow when cast to int16_t */
__enable_irq();
return ((int16_t)temp_val);
}
/**
* @brief It executes CORDIC algorithm for rotor position extraction from B-emf alpha and beta.
* @param wBemf_alfa_est estimated Bemf alpha on the stator reference frame.
* wBemf_beta_est estimated Bemf beta on the stator reference frame.
* @retval int16_t rotor electrical angle (s16degrees).
*/
static inline int16_t MCM_PhaseComputation(int32_t wBemf_alfa_est, int32_t wBemf_beta_est)
{
/* Configure and call to CORDIC */
WRITE_REG(CORDIC->CSR,CORDIC_CONFIG_PHASE);
LL_CORDIC_WriteData(CORDIC, (uint32_t)wBemf_alfa_est);
LL_CORDIC_WriteData(CORDIC, (uint32_t)wBemf_beta_est);
/* Read computed angle */
uint32_t result;
result = LL_CORDIC_ReadData(CORDIC) >> 16U;
return ((int16_t)result);
}
/**
* @brief This function codify a floting point number into the relative 32bit integer.
* @param float_t Floting point number to be coded.
* @retval uint32_t Coded 32bit integer.
*/
uint32_t MCM_floatToIntBit(float_t x);
/**
* @}
*/
/**
* @}
*/
#endif /* MC_MATH_H*/
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 16,713 | C | 46.214689 | 115 | 0.582361 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/cordic.h | /* USER CODE BEGIN Header */
/**
******************************************************************************
* @file cordic.h
* @brief This file contains all the function prototypes for
* the cordic.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CORDIC_H__
#define __CORDIC_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern CORDIC_HandleTypeDef hcordic;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_CORDIC_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __CORDIC_H__ */
| 1,315 | C | 23.830188 | 80 | 0.491255 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_interface.h |
/**
******************************************************************************
* @file mc_interface.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains all definitions and functions prototypes for the
* MC Interface component of the Motor Control SDK.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
* @ingroup MCInterface
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MC_INTERFACE_H
#define MC_INTERFACE_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Includes ------------------------------------------------------------------*/
#include "mc_type.h"
#include "pwm_curr_fdbk.h"
#include "speed_torq_ctrl.h"
/** @addtogroup MCSDK
* @{
*/
/** @addtogroup CAI
* @{
*/
/** @addtogroup MCInterface
* @{
*/
/* Exported types ------------------------------------------------------------*/
/**
* @brief Status of a user (buffered) command
*/
typedef enum
{
MCI_BUFFER_EMPTY, /*!< If no buffered command has been called.*/
MCI_COMMAND_NOT_ALREADY_EXECUTED, /*!< If the buffered command condition hasn't already occurred.*/
MCI_COMMAND_EXECUTED_SUCCESSFULLY, /*!< If the buffered command has been executed successfully.*/
MCI_COMMAND_EXECUTED_UNSUCCESSFULLY /*!< If the buffered command has been executed unsuccessfully.*/
} MCI_CommandState_t ;
/**
* @brief list of user (buffered) commands
*/
typedef enum
{
MCI_NOCOMMANDSYET, /*!< No command has been set by the user.*/
MCI_CMD_EXECSPEEDRAMP, /*!< ExecSpeedRamp command coming from the user.*/
MCI_CMD_EXECTORQUERAMP, /*!< ExecTorqueRamp command coming from the user.*/
MCI_CMD_SETCURRENTREFERENCES, /*!< SetCurrentReferences command coming from the user.*/
MCI_CMD_SETOPENLOOPCURRENT, /*!< set open loop current .*/
MCI_CMD_SETOPENLOOPVOLTAGE, /*!< set open loop voltage .*/
} MCI_UserCommands_t;
typedef struct
{
float voltage;
float current;
float frequency;
float padding [1];
} __attribute__ ((packed)) ScaleParams_t;
/**
* @brief State_t enum type definition, it lists all the possible state machine states
*/
typedef enum
{
ICLWAIT = 12, /**< The system is waiting for ICL deactivation. Is not possible
* to run the motor if ICL is active. While the ICL is active
* the state is forced to #ICLWAIT; when ICL become inactive the
* state is moved to #IDLE. */
IDLE = 0, /**< The state machine remains in this state as long as the
* application is not controlling the motor. This state is exited
* when the application sends a motor command or when a fault occurs. */
ALIGNMENT = 2, /**< The encoder alignment procedure that will properly align the
* the encoder to a set mechanical angle is being executed. */
CHARGE_BOOT_CAP = 16, /**< The gate driver boot capacitors are being charged. */
OFFSET_CALIB = 17, /**< The offset of motor currents and voltages measurement cirtcuitry
* are being calibrated. */
START = 4, /**< The motor start-up is procedure is being executed. */
SWITCH_OVER = 19, /**< Transition between the open loop startup procedure and
* closed loop operation */
RUN = 6, /**< The state machien remains in this state as long as the
* application is running (controlling) the motor. This state
* is exited when the application isues a stop command or when
* a fault occurs. */
STOP = 8, /**< The stop motor procedure is being executed. */
FAULT_NOW = 10, /**< The state machine is moved from any state directly to this
* state when a fault occurs. The next state can only be
* #FAULT_OVER. */
FAULT_OVER = 11, /*!< The state machine transitions from #FAULT_NOW to this state
* when there is no active fault condition anymore. It remains
* in this state until either a new fault condition occurs (in which
* case it goes back to the #FAULT_NOW state) or the application
* acknowledges the faults (in which case it goes to the #IDLE state).
*/
WAIT_STOP_MOTOR = 20 /**< Temporisation to make sure the motor is stopped. */
} MCI_State_t;
/**
* @brief list of direct (unbffered) commands
*/
typedef enum
{
MCI_NO_COMMAND = 0, /**< No Command --- Set when going to IDLE */
MCI_START, /**< Start controling the Motor */
MCI_ACK_FAULTS, /**< Acknowledge Motor Control subsystem faults */
MCI_MEASURE_OFFSETS, /**< Start the ADCs Offset measurements procedure */
/* Shouldn't we remove this command ? */
MCI_ALIGN_ENCODER, /**< Start the Encoder alignment procedure */
MCI_STOP /**< Stop the Motor and the control */
} MCI_DirectCommands_t;
typedef struct
{
SpeednTorqCtrl_Handle_t *pSTC; /*!< Speed and torque controller object used by MCI.*/
pFOCVars_t pFOCVars; /*!< Pointer to FOC vars used by MCI.*/
PWMC_Handle_t *pPWM; /*!< Pointer to PWM handle structure.*/
MCI_UserCommands_t lastCommand; /*!< Last command coming from the user.*/
int16_t hFinalSpeed; /*!< Final speed of last ExecSpeedRamp command.*/
int16_t hFinalTorque; /*!< Final torque of last ExecTorqueRamp command.*/
qd_t Iqdref; /*!< Current component of last SetCurrentReferences command.*/
ScaleParams_t *pScale;
uint16_t hDurationms; /*!< Duration in ms of last ExecSpeedRamp or ExecTorqueRamp command.*/
MCI_DirectCommands_t DirectCommand;
MCI_State_t State;
uint16_t CurrentFaults;
uint16_t PastFaults;
MCI_CommandState_t CommandState; /*!< The status of the buffered command.*/
MC_ControlMode_t LastModalitySetByUser; /*!< The last MC_ControlMode_t set by the user. */
} MCI_Handle_t;
/* Exported functions ------------------------------------------------------- */
void MCI_Init(MCI_Handle_t *pHandle, SpeednTorqCtrl_Handle_t *pSTC, pFOCVars_t pFOCVars, PWMC_Handle_t *pPWMHandle);
void MCI_ExecBufferedCommands(MCI_Handle_t *pHandle );
void MCI_ExecSpeedRamp(MCI_Handle_t *pHandle, int16_t hFinalSpeed, uint16_t hDurationms);
void MCI_ExecSpeedRamp_F(MCI_Handle_t *pHandle, const float_t FinalSpeed, uint16_t hDurationms);
void MCI_ExecTorqueRamp(MCI_Handle_t *pHandle, int16_t hFinalTorque, uint16_t hDurationms);
void MCI_ExecTorqueRamp_F(MCI_Handle_t *pHandle, const float_t FinalTorque, uint16_t hDurationms);
void MCI_SetCurrentReferences(MCI_Handle_t *pHandle, qd_t Iqdref);
void MCI_SetCurrentReferences_F(MCI_Handle_t *pHandle, qd_f_t IqdRef);
void MCI_SetIdref(MCI_Handle_t *pHandle, int16_t hNewIdRef);
void MCI_SetIdref_F(MCI_Handle_t *pHandle, float_t NewIdRef);
bool MCI_StartMotor(MCI_Handle_t *pHandle);
bool MCI_StartWithPolarizationMotor(MCI_Handle_t *pHandle);
bool MCI_StartOffsetMeasurments(MCI_Handle_t *pHandle);
bool MCI_GetCalibratedOffsetsMotor(MCI_Handle_t* pHandle, PolarizationOffsets_t * PolarizationOffsets);
bool MCI_SetCalibratedOffsetsMotor(MCI_Handle_t* pHandle, PolarizationOffsets_t * PolarizationOffsets);
bool MCI_StopMotor(MCI_Handle_t *pHandle);
bool MCI_FaultAcknowledged(MCI_Handle_t *pHandle);
void MCI_FaultProcessing(MCI_Handle_t *pHandle, uint16_t hSetErrors, uint16_t hResetErrors);
uint32_t MCI_GetFaultState(MCI_Handle_t *pHandle );
MCI_CommandState_t MCI_IsCommandAcknowledged(MCI_Handle_t *pHandle);
MCI_State_t MCI_GetSTMState(MCI_Handle_t *pHandle);
uint16_t MCI_GetOccurredFaults(MCI_Handle_t *pHandle);
uint16_t MCI_GetCurrentFaults(MCI_Handle_t *pHandle);
float_t MCI_GetMecSpeedRef_F(MCI_Handle_t *pHandle);
float_t MCI_GetAvrgMecSpeed_F(MCI_Handle_t *pHandle);
MC_ControlMode_t MCI_GetControlMode(MCI_Handle_t *pHandle);
int16_t MCI_GetImposedMotorDirection(MCI_Handle_t *pHandle);
int16_t MCI_GetLastRampFinalSpeed(MCI_Handle_t *pHandle);
int16_t MCI_GetLastRampFinalTorque(MCI_Handle_t *pHandle);
uint16_t MCI_GetLastRampFinalDuration(MCI_Handle_t *pHandle);
bool MCI_RampCompleted(MCI_Handle_t *pHandle);
float_t MCI_GetLastRampFinalSpeed_F(MCI_Handle_t *pHandle);
bool MCI_StopSpeedRamp(MCI_Handle_t *pHandle);
void MCI_StopRamp(MCI_Handle_t *pHandle);
bool MCI_GetSpdSensorReliability(MCI_Handle_t *pHandle);
int16_t MCI_GetAvrgMecSpeedUnit(MCI_Handle_t *pHandle);
int16_t MCI_GetMecSpeedRefUnit(MCI_Handle_t *pHandle);
ab_t MCI_GetIab(MCI_Handle_t *pHandle);
ab_f_t MCI_GetIab_F(MCI_Handle_t *pHandle);
alphabeta_t MCI_GetIalphabeta(MCI_Handle_t *pHandle);
qd_t MCI_GetIqd(MCI_Handle_t *pHandle);
qd_f_t MCI_GetIqd_F(MCI_Handle_t *pHandle);
qd_t MCI_GetIqdHF(MCI_Handle_t *pHandle);
qd_t MCI_GetIqdref(MCI_Handle_t *pHandle);
qd_f_t MCI_GetIqdref_F(MCI_Handle_t *pHandle);
qd_t MCI_GetVqd(MCI_Handle_t *pHandle);
alphabeta_t MCI_GetValphabeta(MCI_Handle_t *pHandle);
int16_t MCI_GetElAngledpp(MCI_Handle_t *pHandle);
int16_t MCI_GetTeref(MCI_Handle_t *pHandle);
float_t MCI_GetTeref_F(MCI_Handle_t *pHandle );
int16_t MCI_GetPhaseCurrentAmplitude(MCI_Handle_t *pHandle);
int16_t MCI_GetPhaseVoltageAmplitude(MCI_Handle_t *pHandle);
void MCI_Clear_Iqdref(MCI_Handle_t *pHandle);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cpluplus */
#endif /* MC_INTERFACE_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 10,234 | C | 43.694323 | 116 | 0.637874 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/mc_parameters.h |
/**
******************************************************************************
* @file mc_parameters.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file provides declarations of HW parameters specific to the
* configuration of the subsystem.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
#ifndef MC_PARAMETERS_H
#define MC_PARAMETERS_H
#include "mc_interface.h"
#include "r3_1_g4xx_pwm_curr_fdbk.h"
/* USER CODE BEGIN Additional include */
/* USER CODE END Additional include */
extern const R3_1_Params_t R3_1_ParamsM1;
extern ScaleParams_t scaleParams_M1;
/* USER CODE BEGIN Additional extern */
/* USER CODE END Additional extern */
#endif /* MC_PARAMETERS_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 1,327 | C | 29.88372 | 80 | 0.543331 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Inc/pmsm_motor_parameters.h | /**
******************************************************************************
* @file pmsm_motor_parameters.h
* @author Motor Control SDK Team, ST Microelectronics
* @brief This file contains the parameters needed for the Motor Control SDK
* in order to configure the motor to drive.
*
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef PMSM_MOTOR_PARAMETERS_H
#define PMSM_MOTOR_PARAMETERS_H
/************************
*** Motor Parameters ***
************************/
/***************** MOTOR ELECTRICAL PARAMETERS ******************************/
#define POLE_PAIR_NUM 14 /* Number of motor pole pairs */
#define RS 0.15 /* Stator resistance , ohm*/
#define LS 0.00006 /* Stator inductance, H
For I-PMSM it is equal to Lq */
/* When using Id = 0, NOMINAL_CURRENT is utilized to saturate the output of the
PID for speed regulation (i.e. reference torque).
Transformation of real currents (A) into int16_t format must be done accordingly with
formula:
Phase current (int16_t 0-to-peak) = (Phase current (A 0-to-peak)* 32767 * Rshunt *
*Amplifying network gain)/(MCU supply voltage/2)
*/
#define MOTOR_MAX_SPEED_RPM 2478 /*!< Maximum rated speed */
#define MOTOR_VOLTAGE_CONSTANT 5.2 /*!< Volts RMS ph-ph /kRPM */
#define NOMINAL_CURRENT_A 10
#define ID_DEMAG_A (int16_t)-10 /*!< Demagnetization current */
/***************** MOTOR SENSORS PARAMETERS ******************************/
/* Motor sensors parameters are always generated but really meaningful only
if the corresponding sensor is actually present in the motor */
/*** Hall sensors ***/
#define HALL_SENSORS_PLACEMENT DEGREES_120 /*!<Define here the
mechanical position of the sensors
withreference to an electrical cycle.
It can be either DEGREES_120 or
DEGREES_60 */
#define HALL_PHASE_SHIFT 300 /*!< Define here in degrees
the electrical phase shift between
the low to high transition of
signal H1 and the maximum of
the Bemf induced on phase A */
/*** Quadrature encoder ***/
#define M1_ENCODER_PPR 1024 /*!< Number of pulses per
revolution */
#endif /* PMSM_MOTOR_PARAMETERS_H */
/******************* (C) COPYRIGHT 2023 STMicroelectronics *****END OF FILE****/
| 3,407 | C | 46.333333 | 88 | 0.484884 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Middlewares/ST/AI/Inc/formats_list.h | /**
******************************************************************************
* @file format_list.h
* @author AST Embedded Analytics Research Platform
* @brief Definitions of AI platform public APIs types
******************************************************************************
* @attention
*
* Copyright (c) 2019 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
@verbatim
@endverbatim
******************************************************************************
*/
/* FMT_ENTRY( exp_(0/1 only), name_, type_id_,
* sign_bit_, float_bit_, pmask_, bits_, fbits_, ldiv_bits_)
* Specifications (in order of the bit fields, little endian):
- name_ : it is the enum used to define both the ai_array_format and
ai_buffer_format.
- exp_ (1bit) : it is a boolean flag (0 or 1) indicating whether the format
is available as a public APIs ai_buffer format. in this case the field
exp_name_ indicates the enum name of the ai_buffer format
- (7 bits): reserved for flags
- sign_bit_ (1bit) : codes whether or not the format is of a signed type
- float_bit_ (1bit) : codes if the format is float
- ldiv_bits (2 bits) : right shift value for computing the byte size of the
format
- type_id_ (4bits) : it is used to define the "family" of the format:
see @ref AI_FMT_Q as an example. Currently supported types are:
AI_FMT_Q (fixed point types), AI_FMT_FLOAT (floating point values),
AI_FMT_LUT4 or AI_FMT_LUT8 (compressed formats)
- pmask_ (3bits) : padding mask bits for the format
- bits_ (7bits) : size in bits of the format (NB: integer+fractional bits)
- fbits_ (7bits) : number of fractional bits for the format
(for AI_FMT_Q only)
*/
/* Format none entry */
FMT_ENTRY(1, NONE, AI_FMT_NONE, 0, 0, 0x0, 0, 0, 0)
/* Floating point formats */
FMT_ENTRY(1, FLOAT, AI_FMT_FLOAT, 1, 1, 0x0, 32, 0, 0)
FMT_ENTRY(0, FLOAT64, AI_FMT_FLOAT, 1, 1, 0x0, 64, 0, 0)
FMT_ENTRY(0, FLOAT16, AI_FMT_FLOAT, 1, 1, 0x0, 16, 0, 0)
/* Integer formats (i.e. fractional bits = 0!) */
FMT_ENTRY(1, U8, AI_FMT_Q, 0, 0, 0x0, 8, 0, 0)
FMT_ENTRY(1, U16, AI_FMT_Q, 0, 0, 0x0, 16, 0, 0)
FMT_ENTRY(1, U32, AI_FMT_Q, 0, 0, 0x0, 32, 0, 0)
FMT_ENTRY(0, U64, AI_FMT_Q, 0, 0, 0x0, 64, 0, 0)
FMT_ENTRY(1, U1, AI_FMT_Q, 0, 0, 0x0, 1, 0, 0)
FMT_ENTRY(0, U4, AI_FMT_Q, 0, 0, 0x0, 4, 0, 0)
FMT_ENTRY(1, S8, AI_FMT_Q, 1, 0, 0x0, 8, 0, 0)
FMT_ENTRY(1, S16, AI_FMT_Q, 1, 0, 0x0, 16, 0, 0)
FMT_ENTRY(1, S32, AI_FMT_Q, 1, 0, 0x0, 32, 0, 0)
FMT_ENTRY(0, S64, AI_FMT_Q, 1, 0, 0x0, 64, 0, 0)
FMT_ENTRY(1, S1, AI_FMT_Q, 1, 0, 0x0, 1, 0, 0)
FMT_ENTRY(0, S4, AI_FMT_Q, 1, 0, 0x0, 4, 0, 0)
/* Fixed-point formats including ARM CMSIS Q7, Q15, Q31 ones */
FMT_ENTRY(1, Q, AI_FMT_Q, 1, 0, 0x0, 0, 0, 0)
FMT_ENTRY(1, Q7, AI_FMT_Q, 1, 0, 0x0, 8, 7, 0)
FMT_ENTRY(1, Q15, AI_FMT_Q, 1, 0, 0x0, 16, 15, 0)
FMT_ENTRY(0, Q31, AI_FMT_Q, 1, 0, 0x0, 32, 31, 0)
FMT_ENTRY(1, UQ, AI_FMT_Q, 0, 0, 0x0, 0, 0, 0)
FMT_ENTRY(1, UQ7, AI_FMT_Q, 0, 0, 0x0, 8, 7, 0)
FMT_ENTRY(1, UQ15, AI_FMT_Q, 0, 0, 0x0, 16, 15, 0)
FMT_ENTRY(0, UQ31, AI_FMT_Q, 0, 0, 0x0, 32, 31, 0)
/* Compressed formats */
FMT_ENTRY(0, LUT4_FLOAT, AI_FMT_LUT4, 1, 1, 0x0, 32, 0, 3)
FMT_ENTRY(0, LUT8_FLOAT, AI_FMT_LUT8, 1, 1, 0x0, 32, 0, 2)
FMT_ENTRY(0, LUT4_Q15, AI_FMT_LUT4, 1, 0, 0x0, 16, 15, 2)
FMT_ENTRY(0, LUT8_Q15, AI_FMT_LUT8, 1, 0, 0x0, 16, 15, 1)
FMT_ENTRY(0, LUT4_UQ15, AI_FMT_LUT4, 0, 0, 0x0, 16, 15, 2)
FMT_ENTRY(0, LUT8_UQ15, AI_FMT_LUT8, 0, 0, 0x0, 16, 15, 1)
/* Boolean format */
FMT_ENTRY(1, BOOL, AI_FMT_BOOL, 0, 0, 0x0, 8, 0, 0)
#undef FMT_ENTRY
| 3,930 | C | 41.72826 | 80 | 0.564885 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Middlewares/ST/AI/Inc/core_convert.h | /**
******************************************************************************
* @file core_convert.h
* @author AST Embedded Analytics Research Platform
* @brief header file of core utils routines
******************************************************************************
* @attention
*
* Copyright (c) 2018 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
@verbatim
@endverbatim
******************************************************************************
*/
#ifndef CORE_CONVERT_H
#define CORE_CONVERT_H
#pragma once
#include "ai_platform.h"
#include "ai_platform_interface.h"
#include "core_common.h"
AI_API_DECLARE_BEGIN
/*!
* @defgroup core_convert Core Convert Routines
* @brief Implementation of core node format convertion routines
* (Q7 to float, ... etc.)
*/
/*!
* @brief Convert tensors from float to quantized or viceversa
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert(ai_node *pNode);
/*!
* @brief Convert integer tensors between QM.N formats (8/16 bits)
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_fixed(ai_node *pNode);
/*!
* @brief Convert integer tensors between signed and usigned (int8/uint8) formats
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_integer(ai_node *pNode);
/*!
* @brief Convert float tensor to binary
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_if32os1(ai_node *pNode);
/*!
* @brief Convert binary tensor to float
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_is8os1(ai_node *pNode);
/*!
* @brief Convert binary tensor to signed int 8 bit
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_is1os8(ai_node *pNode);
/*!
* @brief Convert binary tensor to signed int 16 bit
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_is1os16(ai_node *pNode);
/*!
* @brief Convert binary tensor to float
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_is1of32(ai_node *pNode);
/*!
* @brief Convert signed int 16 bit tensor to float
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_is16of32(ai_node *pNode);
/*!
* @brief Convert unsigned int 16 bit tensor to float
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_iu16of32(ai_node *pNode);
/*!
* @brief Convert float tensor to signed int 16 bit
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_if32os16(ai_node *pNode);
/*!
* @brief Convert float tensor to unsigned int 16 bit
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_if32ou16(ai_node *pNode);
/*!
* @brief Convert signed int 16 bit tensor to unsigned int 16 bit
* @ingroup core_convert
* @param[in] pNode in a handler to node (layer or operator)
*/
AI_INTERNAL_API
void node_convert_is16ou16(ai_node *pNode);
/*!
* @brief Convert a shape struct into a stride struct
* @ingroup core_convert
* @param[in] in a pointer to a shape to convert
* @return a condverted stride datastruct
*/
AI_INTERNAL_API
void core_shape_to_stride(ai_stride* out, const ai_shape* in);
#endif /*CORE_CONVERT_H*/
| 4,123 | C | 23.993939 | 81 | 0.65171 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Middlewares/ST/AI/Inc/layers_conv2d.h | /**
******************************************************************************
* @file layers_conv2d.h
* @author AST Embedded Analytics Research Platform
* @brief header file of AI platform conv2d layers datatypes
******************************************************************************
* @attention
*
* Copyright (c) 2018 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
@verbatim
@endverbatim
******************************************************************************
*/
#ifndef LAYERS_CONV2D_H
#define LAYERS_CONV2D_H
#pragma once
#include "layers_nl.h"
#include "layers_pool.h"
#define AI_LAYER_CONV2D_FIELDS_DECLARE \
AI_LAYER_COMMON_FIELDS_DECLARE \
ai_u32 groups; /*!< groups for separable convolution */ \
AI_CONST ai_array* nl_params; /*!< array pointer to non linear parameters */ \
func_nl nl_func; /*!< function pointer to non linear transform */ \
ai_shape_2d filter_stride; /*!< filter stride, how much the filter moves */ \
ai_shape_2d dilation; /*!< dilation value along axis of the filter */ \
ai_shape filter_pad; /*!< filter pad 4d */ \
ai_layer_format_type in_ch_format; /*!< Input format (Channel 1st vs Channel last */ \
ai_layer_format_type out_ch_format; /*!< Output format (Channel 1st vs Channel last */
/*!
* @defgroup layers_conv2d Convolutive Layers Definitions
* @brief definition
*
*/
AI_API_DECLARE_BEGIN
/*!
* @struct ai_layer_dense
* @ingroup layers_conv2d
* @brief Dense (fully connected) layer
*/
typedef ai_layer_base ai_layer_dense;
/*!
* @struct ai_layer_gemm
* @ingroup layers_conv2d
* @brief layer for General Matrix Multiplication
*
* Layer for General Matrix Multiplication (GEMM):
* \f{equation}{ Y = \alpha A \cdot B + \beta C \f}
* \f$\alpha\f$ and \f$\beta\f$ are paramaters, A and B are matrices,
* C is a matrix or an array. Size checks for A, B, C, and Y are performed and
* broadcast is applied on C if necessary.
* This is a sequential layer (see @ref ai_layer).
*/
typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_gemm_ {
AI_LAYER_COMMON_FIELDS_DECLARE
ai_float alpha; /*!< alpha coefficient */
ai_float beta; /*!< beta coefficient */
ai_u8 tA; /*!< transpose A flag */
ai_u8 tB; /*!< transpose B flag */
} ai_layer_gemm;
/*!
* @struct ai_layer_conv2d
* @ingroup layers_conv2d
* @brief 2D convolutional layer with strides and pads
*/
typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_conv2d_ {
AI_LAYER_CONV2D_FIELDS_DECLARE
} ai_layer_conv2d;
/*!
* @struct ai_layer_conv2d_nl_pool
* @ingroup layers_conv2d
* @brief 2D convolutional layer + nl + pooling with strides and pads
*/
typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_conv2d_nl_pool_ {
AI_LAYER_CONV2D_FIELDS_DECLARE
ai_shape_2d pool_size; /*!< pooling size */
ai_shape_2d pool_stride; /*!< pooling stride */
ai_shape pool_pad; /*!< pooling pad */
ai_handle pool_func; /*!< function pointer to pooling transform */
} ai_layer_conv2d_nl_pool;
AI_INTERNAL_API
void ai_dict8_dot_array_f32(ai_handle out, ai_ptr_const data0, ai_ptr_const lut,
const ai_float* data1, const ai_size data_size);
AI_INTERNAL_API
void ai_dict4_dot_array_f32(ai_handle out, ai_ptr_const data0, ai_ptr_const lut,
const ai_float* data1, const ai_size data_size);
/******************************************************************************/
/* Forward Functions Section */
/******************************************************************************/
/*!
* @brief Computes the activations of a floating point 32 2D convolutional layer.
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_if32of32wf32(ai_layer* layer);
/*!
* @brief Computes the activations of a floating point 32 2D dw layer.
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_if32of32wf32(ai_layer* layer);
/*!
* @brief Computes the activations of a floating point 32 2D convolutional group layer.
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_if32of32wf32_group(ai_layer* layer);
/*!
* @brief Computes the activations of a 2D floating point 32 pool fused convolutional layer.
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_if32of32wf32_pool(ai_layer* layer);
/*!
* @brief Computes the activations of a 2D floating point 32 pool fused dw layer.
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_if32of32wf32_pool(ai_layer* layer);
/*!
* @brief Computes the activations of a 2D floating point 32 pool fused convolutional group layer.
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_if32of32wf32_group_pool(ai_layer* layer);
/*!
* @brief Computes the activations of a GEMM layer.
* @ingroup layers
* @param layer the layer including output and input tensors
*/
AI_INTERNAL_API
void forward_gemm(ai_layer* layer);
/*!
* @brief Computes matmul layer, intended as numpy.matmul(A,B).
* @ingroup layers
* @param layer the layer including output and input tensors
*/
AI_INTERNAL_API
void forward_matmul(ai_layer* layer);
/*!
* @brief Computes the activations of a dense (fully connected) layer.
* @ingroup layers_conv2d
* @param layer the dense layer
*/
AI_INTERNAL_API
void forward_dense(ai_layer* layer);
/*!
* @brief Computes the activations of a fixed point 2D convolutional layer.
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_fixed(ai_layer *pLayer);
/*!
* @brief Computes the activations of a fixed point @ref ai_layer_conv2d_nl_pool
* layer.
* The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear
* layer + optional pooling / nonlinearity (average, max)
* @ingroup layers_conv2d
* @param layer see @ai_layer_conv2d_nl_pool
*/
AI_INTERNAL_API
void forward_conv2d_nl_pool_fixed(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer quantized 2D convolutional layer.
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_integer(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer quantized 2D convolutional layer
* for SSSA per layer quantized scheme
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_integer_SSSA(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer quantized 2D convolutional layer
* for SSSA per channel quantized scheme
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_is8os8ws8_sssa_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized DW layer
* for SSSA per channel quantized scheme
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized DW layer
* for SSSA per channel quantized scheme, with 3x3 kernels
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_3x3_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized DW layer
* for SSSA per channel quantized scheme, with 3x3 kernels and input are
* channel first
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_3x3_ch1st_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized DW layer
* for SSSA per channel quantized scheme with depth multiplier > 1
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_dm_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of int8 quantized DW layers.
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_all_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized PW layer
* for SSSA per channel quantized scheme
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_pw_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized dilated Conv2d layer
* for SSSA per channel quantized scheme (valid padding)
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_dilated_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 non dilated Conv2d layer
* for SSSA per channel quantized scheme (valid padding)
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_deep_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 non dilated Conv2d layer
* for SSSA per channel quantized scheme (valid padding)
* number of output channel is greater than 8
* Kernels shall be 3x3 and stride is (1,1)
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_deep_3x3_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 non dilated Conv2d layer
* for SSSA per channel quantized scheme (valid or same padding)
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized Conv2d layer
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_all_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized RGB Conv2d layer
* for SSSA per channel quantized scheme
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_rgb_sssa8_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized DW layer
* for SSSA per channel quantized scheme with pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized DW layer
* for SSSA per channel quantized scheme, with 3x3 kernels,
* with pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_3x3_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized DW layer
* for SSSA per channel quantized scheme, with 3x3 kernels,
* with pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_3x3_ch1st_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized DW layer
* for SSSA per channel quantized scheme with depth multiplier > 1
* with pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_dm_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of int8 quantized DW layers, with pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_dw_all_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized PW layer,
* with pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_pw_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized dilated Conv2d layer
* for SSSA per channel quantized scheme (valid padding) and pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_dilated_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized non dilated Conv2d layer
* for SSSA per channel quantized scheme (valid padding) and pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_deep_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 non dilated Conv2d layer
* for SSSA per channel quantized scheme (valid padding) and pooling fused
* number of output channel is greater than 8
* Kernels shall be 3x3 and stride is (1,1)
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_deep_3x3_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized non dilated Conv2d layer
* for SSSA per channel quantized scheme (valid or same padding) and pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a int8 quantized Conv2d layer and pooling fused
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_all_sssa8_ch_nl_pool(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer quantized 2D convolutional layer
* for SSUA per layer quantized scheme
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_integer_SSUA(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer quantized 2D convolutional layer
* for SSUA per channel quantized scheme
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_integer_SSUA_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer quantized 2D convolutional layer
* for UAUA per layer quantized scheme
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_integer_UAUA(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer quantized 2D convolutional layer
* for UAUA per channel quantized scheme
* @ingroup layers_conv2d
* @param layer the convolutional (conv) layer
*/
AI_INTERNAL_API
void forward_conv2d_integer_UAUA_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer.
* The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear
* layer + optional pooling / nonlinearity (average, max)
* @ingroup layers_conv2d
* @param layer see @ai_layer_conv2d_nl_pool
*/
AI_INTERNAL_API
void forward_conv2d_nl_pool_integer(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer
* for SSSA per layer quantized scheme
* The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear
* layer + optional pooling / nonlinearity (average, max)
* @ingroup layers_conv2d
* @param layer see @ai_layer_conv2d_nl_pool
*/
AI_INTERNAL_API
void forward_conv2d_nl_pool_integer_SSSA(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer
* for SSSA per channel quantized scheme
* The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear
* layer + optional pooling / nonlinearity (average, max)
* @ingroup layers_conv2d
* @param layer see @ai_layer_conv2d_nl_pool
*/
AI_INTERNAL_API
void forward_conv2d_nl_pool_integer_SSSA_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer
* for SSUA per layer quantized scheme
* The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear
* layer + optional pooling / nonlinearity (average, max)
* @ingroup layers_conv2d
* @param layer see @ai_layer_conv2d_nl_pool
*/
AI_INTERNAL_API
void forward_conv2d_nl_pool_integer_SSUA(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer
* for SSUA per channel quantized scheme
* The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear
* layer + optional pooling / nonlinearity (average, max)
* @ingroup layers_conv2d
* @param layer see @ai_layer_conv2d_nl_pool
*/
AI_INTERNAL_API
void forward_conv2d_nl_pool_integer_SSUA_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer
* for UAUA per layer quantized scheme
* The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear
* layer + optional pooling / nonlinearity (average, max)
* @ingroup layers_conv2d
* @param layer see @ai_layer_conv2d_nl_pool
*/
AI_INTERNAL_API
void forward_conv2d_nl_pool_integer_UAUA(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer
* for UAUA per channel quantized scheme
* The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear
* layer + optional pooling / nonlinearity (average, max)
* @ingroup layers_conv2d
* @param layer see @ai_layer_conv2d_nl_pool
*/
AI_INTERNAL_API
void forward_conv2d_nl_pool_integer_UAUA_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer dense (fully connected) layer.
* @ingroup layers_dense
* @param layer the dense layer
*/
AI_INTERNAL_API
void forward_dense_integer(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer dense (fully connected) layer
* for SSSA per layer quantized scheme
* @ingroup layers_dense
* @param layer the dense layer
*/
AI_INTERNAL_API
void forward_dense_integer_SSSA(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer dense (fully connected) layer
* for SSSA per channel quantized scheme
* @ingroup layers_dense
* @param layer the dense layer
*/
AI_INTERNAL_API
void forward_dense_integer_SSSA_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer dense (fully connected) layer
* for SSUA per layer quantized scheme
* @ingroup layers_dense
* @param layer the dense layer
*/
AI_INTERNAL_API
void forward_dense_integer_SSUA(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer dense (fully connected) layer
* for SSUA per channel quantized scheme
* @ingroup layers_dense
* @param layer the dense layer
*/
AI_INTERNAL_API
void forward_dense_integer_SSUA_ch(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer dense (fully connected) layer
* for UAUA per layer quantized scheme
* @ingroup layers_dense
* @param layer the dense layer
*/
AI_INTERNAL_API
void forward_dense_integer_UAUA(ai_layer *pLayer);
/*!
* @brief Computes the activations of a integer dense (fully connected) layer
* for UAUA per channel quantized scheme
* @ingroup layers_dense
* @param layer the dense layer
*/
AI_INTERNAL_API
void forward_dense_integer_UAUA_ch(ai_layer *pLayer);
AI_API_DECLARE_END
#endif /*LAYERS_CONV2D_H*/
| 19,921 | C | 30.8752 | 98 | 0.69359 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Middlewares/ST/AI/Inc/ai_lite_math_helpers.h | #ifndef AI_LITE_MATH_HELPERS_H
#define AI_LITE_MATH_HELPERS_H
#include <math.h>
#include "ai_platform.h"
#include "ai_platform_interface.h"
#include "ai_datatypes_defines.h"
#define AI_FLOAT_TOLERANCE (6.19209290e-5F) /* Used for small calculation
noise issues */
#define AI_FLOAT_EPSILON (1.19209290e-7F)
#define AI_I8_EPSILON (0.00787401F) /* 1/(2^7 - 1) */
#define AI_I16_EPSILON (3.051851e-5F) /* 1/(2^15 - 1) */
#define AI_FLT_MAX (3.40282346638528859812e+38f)
#define AI_MIN(x,y) ( ((x)<(y)) ? (x) : (y) )
#define AI_MAX(x,y) ( ((x)>(y)) ? (x) : (y) )
#define AI_SIGN(x) (((x)>0) ? 1 : -1)
#define AI_CLAMP(x, min, max) AI_MIN(AI_MAX(x,min), max)
#define AI_ABS(x) fabsf(x)
#define AI_ABS_DIFF(x, y) ( ((x)>(y)) ? ((x)-(y)) : ((y)-(x)) )
#define AI_NEG(x) ( -1 * (x) )
#define AI_NOT(x) ( ((x)==true) ? false : true)
#define AI_RECIPROCAL(x) ( 1.0f / (x) )
#define AI_CEIL(x) ceilf(x)
#define AI_FLOOR(x) floorf(x)
#define AI_FLOOR_DIV(x, y) AI_FLOOR((x)/(y)) /* floor division: x // y */
#define AI_FLOOR_MOD(x, y) fmodf(x, y)
#define AI_ROUND(x) roundf(x)
#define AI_POW(x,y) powf(x, y)
#define AI_SQUARED_DIFF(x, y) (((x)-(y)) * ((x)-(y)))
#define AI_FLOAT_NEGATIVE_HALF (-0.5f + AI_FLOAT_EPSILON)
#define AI_FLOAT_POSITIVE_HALF (0.5f)
#define AI_MATH_ACOS(x) acosf(x)
#define AI_MATH_ACOSH(x) acoshf(x)
#define AI_MATH_ASIN(x) asinf(x)
#define AI_MATH_ASINH(x) asinhf(x)
#define AI_MATH_ATAN(x) atanf(x)
#define AI_MATH_ATANH(x) atanhf(x)
#define AI_MATH_COS(x) cosf(x)
#define AI_MATH_COSH(x) coshf(x)
#define AI_MATH_ERF(x) erff(x)
#define AI_MATH_EXP(x) expf(x)
#define AI_MATH_LOG(x) logf(x)
#define AI_MATH_POW(x, e) powf((x), (e))
#define AI_MATH_RSQRT(x) (1.0f / AI_MATH_SQRT(x))
#define AI_MATH_SIN(x) sinf(x)
#define AI_MATH_SINH(x) sinhf(x)
#define AI_MATH_SQRT(x) ai_math_sqrt(x)
#define AI_MATH_TAN(x) tanf(x)
#define AI_MATH_TANH(x) tanhf(x)
#define AI_MATH_SQUARE(x) AI_MATH_POW(x, 2.0f)
#define AI_MATH_ACOS(x) acosf(x)
#define AI_MATH_ACOSH(x) acoshf(x)
#define AI_MATH_ASIN(x) asinf(x)
#define AI_MATH_ASINH(x) asinhf(x)
#define AI_MATH_ATAN(x) atanf(x)
#define AI_MATH_ATANH(x) atanhf(x)
#define AI_MATH_COS(x) cosf(x)
#define AI_MATH_COSH(x) coshf(x)
#define AI_MATH_ERF(x) erff(x)
#define AI_MATH_EXP(x) expf(x)
#define AI_MATH_LOG(x) logf(x)
#define AI_MATH_POW(x, e) powf((x), (e))
#define AI_MATH_RSQRT(x) (1.0f / AI_MATH_SQRT(x))
#define AI_MATH_SIN(x) sinf(x)
#define AI_MATH_SINH(x) sinhf(x)
#define AI_MATH_SQRT(x) ai_math_sqrt(x)
#define AI_MATH_TAN(x) tanf(x)
#define AI_MATH_TANH(x) tanhf(x)
#define AI_MATH_SQUARE(x) AI_MATH_POW(x, 2.0f)
#define AI_MATH_RELU_TEST(x, thr, min, max) \
(((x)<=(thr)) ? (min) : (max))
#define AI_MATH_CLIP_LINEAR_REMAP(x, alpha, beta) \
(AI_MAX(0, AI_MIN(1, ((x) * (alpha) + (beta)))))
#define AI_MATH_RELU_GENERIC(x, thr, alpha, max) \
AI_MATH_RELU_TEST(x, max, AI_MATH_RELU_GENERIC_NO_MAX(x, thr, alpha), max)
#define AI_MATH_RELU_GENERIC_NO_MAX(x, thr, alpha) \
AI_MATH_RELU_TEST(x, thr, ((alpha)*((x)-(thr))), x)
#define AI_MATH_RELU_THRESHOLDED(x, thr) \
AI_MATH_RELU_TEST(x, thr, 0, (x))
#define AI_MATH_LEAKY_RELU(x, neg_slope, pos_slope) \
AI_MATH_RELU_TEST(x, 0, (x)*(neg_slope), (x)*(pos_slope))
// ( ((x)>0) ? (x)*(pos_slope) : (x)*(neg_slope) )
#define AI_MATH_PRELU(x, slope) \
AI_MATH_RELU_TEST(x, 0, (x)*(slope), (x))
// AI_MATH_LEAKY_RELU(x, slope, 1)
#define AI_MATH_RELU(x) \
AI_MATH_RELU_TEST(x, 0, 0, x)
// AI_MAX(x, 0)
#define AI_MATH_ELU(x, alpha) \
(AI_MAX(0.0f, (x)) + AI_MIN(0.0f, (alpha) * (AI_MATH_EXP(x)-1.0f)))
#define AI_MATH_SELU(x, alpha, scale) \
((scale)*AI_MATH_ELU(x, alpha))
#define AI_MATH_SCALED_TANH(x, alpha, beta) \
((alpha)*AI_MATH_TANH((beta)*(x)))
#define AI_MATH_SIGMOID(x) \
(1.0f / (1.0f + AI_MATH_EXP(-(x))))
#define AI_MATH_LOGISTIC(x)\
(x < 0) ? (1.0f -(1.0f / (1.0f + AI_MATH_EXP(-AI_ABS(x))))) :\
(1.0f / (1.0f + AI_MATH_EXP(-AI_ABS(x))))
#define AI_MATH_HARD_SIGMOID(x, alpha, beta) \
AI_MATH_CLIP_LINEAR_REMAP(x, alpha, beta)
/* Formula with higher accuracy */
#define AI_MATH_SWISH(x) \
((x) * AI_MATH_SIGMOID(x))
#define AI_MATH_HARD_SWISH(x) \
((x) * AI_MATH_CLIP_LINEAR_REMAP(x, 1.0f/6, 0.5f))
#define AI_MATH_SOFT_PLUS(x) \
AI_MATH_LOG(1.0f + AI_MATH_EXP(x))
#define AI_MATH_SOFT_SIGN(x) \
((x) / (1.0f + AI_ABS(x)))
AI_API_DECLARE_BEGIN
/*!
* @brief platform optimized square root on a float value
* @ingroup math_helpers
* @param x input value
* @return square root of the value
*/
AI_INTERFACE_ENTRY ai_float ai_math_sqrt(const ai_float x);
AI_API_DECLARE_END
#endif /* AI_LITE_MATH_HELPERS_H */
| 5,197 | C | 33.197368 | 79 | 0.556667 |
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Middlewares/ST/AI/Inc/lite_pad_dqnn.h | /**
******************************************************************************
* @file lite_pad_dqnn.h
* @author AIS
* @brief header file of AI platform lite padding kernel datatypes
******************************************************************************
* @attention
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
@verbatim
@endverbatim
******************************************************************************
*/
#ifndef LITE_PADDING_DQNN_H
#define LITE_PADDING_DQNN_H
#pragma once
#include "ai_lite_interface.h"
/******************************************************************************/
/* Forward Functions Section */
/******************************************************************************/
/*!
* @brief Handles padding with binary input and binary output - Lite I/F
* @ingroup lite_padding_dqnn
*/
LITE_API_ENTRY
void forward_lite_pad_is1os1(const ai_u32 *pDataIn_init,
ai_u32 *pDataOut_init,
const ai_i32 width_in,
const ai_i32 width_out,
const ai_i32 height_in,
const ai_i32 height_out,
const ai_u32 n_channel_out,
const ai_i32 mode,
const ai_u16 pads_x,
const ai_u16 pads_y,
const ai_u16 pads_x_r,
const ai_u16 pads_y_b,
const ai_u32 pad_value);
#endif /*LITE_PADDING_DQNN_H*/
| 2,016 | C | 37.788461 | 80 | 0.381448 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.