//***************************************************************************** // (C) Automotive Lighting Reutlingen GmbH // Tuebinger Strasse 123, 72762 Reutlingen, Germany // // Automotive Lighting Reutlingen GmbH owns all the rights to this work. // This work shall not be copied, reproduced, used, modified, transferred // or its information shall not be disclosed without the prior written // authorization of Automotive Lighting Reutlingen GmbH. //***************************************************************************** //----------------------------------------------------------------------------- /// \file CmdIf.c /// /// \brief Command Interface /// /// \descr /// /// \author Peter Ott (otp2rt) /// mailTo:peter.ott@al-lighting.com //----------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // includes // ---------------------------------------------------------------------------- #include #include #include #include #include #include #include #include // ---------------------------------------------------------------------------- // typedefs and defines, macros // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Global defined data // ---------------------------------------------------------------------------- tCmdIf_ArgBuffer CmdIf_ArgBuffer; tCmdIf_RetBuffer CmdIf_RetBuffer; // ---------------------------------------------------------------------------- // Interface functions // ---------------------------------------------------------------------------- //----------------------------------------------------------------------------- /// \brief Get voltage of power supply /// /// \descr This function returns the power supply voltage (single value) /// /// Arguments /// - none /// /// Return /// - INT16 nVoltage: supply voltage [mV] /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_GetSupplyVoltage(void) { CmdIf_RetBuffer.GetSupplyVoltage.nVoltage = HalAdcRead_SupplyVoltage(); CmdIf_RetBuffer.GetSupplyVoltage.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Get voltage on extension port /// /// \descr This function returns the voltage on a extension port input
/// The result is the average voltage of 32 samples at 10 kHz sampling rate /// /// Arguments /// - UINT8 ucSamples: number of samples (0...128, 0=default(32)) /// /// Return /// - INT16 nVoltage: voltage [mV] /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_GetExtPortVoltage(void) { UINT32 ulSamples = CmdIf_ArgBuffer.GetExtPortVoltage.ucSamples; ulSamples = (ulSamples == 0) ? HALADC_OldBufferSize : ulSamples; // backward compatibility ulSamples = min(ulSamples, HALADC_BufferSize); CmdIf_RetBuffer.GetExtPortVoltage.nVoltage = HalAdcReadAvrg_ExtPortVoltage(ulSamples); CmdIf_RetBuffer.GetExtPortVoltage.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Get voltage on measurement channel /// /// \descr This function returns the voltage on a measurement channel
/// The result is the average voltage of 32 samples at 10 kHz sampling rate /// /// Arguments /// - UINT8 ucChannel: measurement channel [0...3] /// - UINT8 ucSamples: number of samples (0...128, 0=default(32)) /// /// Return /// - INT16 nVoltage: voltage [mV] /// - UINT8 ucResult: CMDIF_IndexOutOfRange (if index >= ALTU_MeasChannels) /// CMDIF_ResultOk (else) //----------------------------------------------------------------------------- void CmdIf_GetVoltage(void) { if(CmdIf_ArgBuffer.GetVoltage.ucChannel >= ALTU_MeasChannels) { CmdIf_RetBuffer.GetVoltage.ucResult = CMDIF_IndexOutOfRange; } else { UINT32 ulSamples = CmdIf_ArgBuffer.GetVoltage.ucSamples; ulSamples = (ulSamples == 0) ? HALADC_OldBufferSize : ulSamples; // backward compatibility ulSamples = min(ulSamples, HALADC_BufferSize); CmdIf_RetBuffer.GetVoltage.ucResult = CMDIF_ResultOk; CmdIf_RetBuffer.GetVoltage.nVoltage = HalAdcReadAvrg_Voltage(CmdIf_ArgBuffer.GetVoltage.ucChannel, ulSamples); } } //----------------------------------------------------------------------------- /// \brief Get current on measurement channel (direct measurement) /// /// \descr This function returns the current on a measurement channel /// without using amplifier (0.3125 V/A or 0.1042 V/A)
/// The result is the average current of 32 samples at 10 kHz sampling rate
/// Measurement range (positive or negative): /// - Low current range: nominal 2 A, max. 6.4 A /// - High current range: nominal 6 A, max. 19.2 A /// /// Arguments /// - UINT8 ucChannel: measurement channel [0...3] /// - UINT8 ucSamples: number of samples (0...128, 0=default(32)) /// /// Return /// - INT16 nCurrent: current in mA /// - UINT8 ucRange: measurement range: 0 = Low, 1 = High /// - UINT8 ucResult: CMDIF_IndexOutOfRange (if index >= ALTU_MeasChannels) /// CMDIF_ResultOk (else) //----------------------------------------------------------------------------- void CmdIf_GetCurrentNorm(void) { if(CmdIf_ArgBuffer.GetCurrentNorm.ucChannel >= ALTU_MeasChannels) { CmdIf_RetBuffer.GetCurrentNorm.ucResult = CMDIF_IndexOutOfRange; } else { UINT32 ulSamples = CmdIf_ArgBuffer.GetCurrentNorm.ucSamples; ulSamples = (ulSamples == 0) ? HALADC_OldBufferSize : ulSamples; // backward compatibility ulSamples = min(ulSamples, HALADC_BufferSize); CmdIf_RetBuffer.GetCurrentNorm.ucResult = CMDIF_ResultOk; CmdIf_RetBuffer.GetCurrentNorm.nCurrent = HalAdcReadAvrg_CurrentNorm(CmdIf_ArgBuffer.GetCurrentNorm.ucChannel, ulSamples); CmdIf_RetBuffer.GetCurrentNorm.ucRange = HalPort_IsHiCurrentRange() ? 1 : 0; } } //----------------------------------------------------------------------------- /// \brief Get current on measurement channel (using amplifier) /// /// \descr This function returns the current on a measurement channel /// using amplifier (2 V/A or 0.667 V/A)
/// The result is the average current of 32 samples at 10 kHz sampling rate
/// Measurement range (positive or negative): /// - Low current mode: max. 1.2 A /// - High current mode: max. 3.6 A /// /// Arguments /// - UINT8 ucChannel: measurement channel [0...3] /// - UINT8 ucSamples: number of samples (0...128, 0=default(32)) /// /// Return /// - INT16 nCurrent: current in mA /// - UINT8 ucRange: measurement range: 0 = Low, 1 = High /// - UINT8 ucResult: CMDIF_IndexOutOfRange (if index >= ALTU_MeasChannels) /// CMDIF_ResultOk (else) //----------------------------------------------------------------------------- void CmdIf_GetCurrentAmp(void) { if(CmdIf_ArgBuffer.GetCurrentAmp.ucChannel >= ALTU_MeasChannels) { CmdIf_RetBuffer.GetCurrentAmp.ucResult = CMDIF_IndexOutOfRange; } else { UINT32 ulSamples = CmdIf_ArgBuffer.GetCurrentAmp.ucSamples; ulSamples = (ulSamples == 0) ? HALADC_OldBufferSize : ulSamples; // backward compatibility ulSamples = min(ulSamples, HALADC_BufferSize); CmdIf_RetBuffer.GetCurrentAmp.ucResult = CMDIF_ResultOk; CmdIf_RetBuffer.GetCurrentAmp.nCurrent = HalAdcReadAvrg_CurrentAmp(CmdIf_ArgBuffer.GetCurrentAmp.ucChannel, ulSamples); CmdIf_RetBuffer.GetCurrentAmp.ucRange = HalPort_IsHiCurrentRange() ? 1 : 0; } } //----------------------------------------------------------------------------- /// \brief Get duty cycle on measurement channel /// /// \descr This function returns the duty cycle of the measured current /// on a measurement channel. /// The measurement time interval starts after this command. /// So the return value of the 1st occurance of this command /// must be ignored. /// /// PWM is measured by comparing the measured current with the threshold /// value given by the "CmdIf_SetPwmThreshold" command. /// This is done in a 50us cycle. /// /// Arguments /// - UINT8 ucChannel: measurement channel [0...3] /// /// Return /// - UINT16 unDutyCycle; Duty Cycle in Promille /// - UINT8 ucResult: CMDIF_IndexOutOfRange (if index >= ALTU_MeasChannels) /// CMDIF_ResultOk (else) //----------------------------------------------------------------------------- void CmdIf_GetPwmDutyCycle(void) { if(CmdIf_ArgBuffer.GetPwmDutyCycle.ucChannel >= ALTU_MeasChannels) { CmdIf_RetBuffer.GetPwmDutyCycle.ucResult = CMDIF_IndexOutOfRange; } else { CmdIf_RetBuffer.GetPwmDutyCycle.ucResult = CMDIF_ResultOk; CmdIf_RetBuffer.GetPwmDutyCycle.unDutyCycle = HalAdcReadPwmDutyCycle(CmdIf_ArgBuffer.GetPwmDutyCycle.ucChannel); } } //----------------------------------------------------------------------------- /// \brief Set PWM frequency /// /// \descr Set PWM frequency on extension port
/// Maximum range: 31 Hz ... 20 kHz --> 1.0 % resolution @20 kHz
/// Recommended range: 50 Hz ... 2 kHz --> 0.1 % resolution @ 2 kHz /// /// Arguments /// - UINT16 unFreq: frequency [Hz] /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetPwmFreq(void) { HalPwm_SetFreq(CmdIf_ArgBuffer.SetPwmFreq.unFreq); CmdIf_RetBuffer.SetPwmFreq.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Set PWM output signal /// /// \descr Set PWM output signal on extension port
/// /// Arguments /// - UINT8 ucMode: Bit 0: 0 = positive polarity, 1 = negative polarity /// - UINT16 unPwm: pulse width in promille [0...1000] /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetPwmOutput(void) { UINT32 ulPwm = min(1000, CmdIf_ArgBuffer.SetPwmOutput.unPwm); // note: signal is inverted by driver if((CmdIf_ArgBuffer.SetPwmOutput.ucMode & 0x01) == 0) { HalPwm_SetPwm(1000 - ulPwm); // positive polarity } else { HalPwm_SetPwm(ulPwm); // negative polarity } CmdIf_RetBuffer.SetPwmOutput.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Set DAC output signal /// /// \descr Set DAC output signal on extension port. /// The output signal will be set on DAC with a delay of max. 5ms. /// Another 5 ms later the voltage will be optimized using analog feedback. /// --> complete settling time <=10ms /// /// Arguments /// - UINT16 unVoltage: output voltage [mV] /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetDacOutput(void) { Altu_PrepareDacOutput(CmdIf_ArgBuffer.SetDacOutput.unVoltage); CmdIf_RetBuffer.SetDacOutput.ucResult = CMDIF_ResultOk; } void CmdIf_CbSpiSendOk(void) // called by SPI RX interrupt { HalPort_DacLdInactive(); } //----------------------------------------------------------------------------- /// \brief Set frequency for measurement output /// /// \descr Calculate clock divider based on interruptperiod of HALPWM_RtIntPeriod /// /// Arguments /// - UINT16 unFreq: frequency [Hz, 100...10000] /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetMeasOutFreq(void) { const UINT32 ulIntFreq = 1000000u / HALPWM_RtIntPeriod; // interrupt frequency in Hz UINT32 ulMeasFreq = CmdIf_ArgBuffer.SetMeasOutFreq.unFreq; ulMeasFreq = max(100, ulMeasFreq); ulMeasFreq = min(10000, ulMeasFreq); // divide interrupt frequency by measurement frequency and round result Nvm_RamCopy.AltuMeasOut.ulClockDivider = ((2u * ulIntFreq + ulMeasFreq) / (2u * ulMeasFreq)) - 1; CmdIf_RetBuffer.SetMeasOutFreq.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Set measurement output channel /// /// \descr Set the parameters of an output channel, but do not activate the automatic output /// /// Arguments /// - UINT8 ucOutChn: CAN output channel [0...9] /// - UINT8 ucType: Type of measurement value, see CMDIF_Meas... in CmdIfType.h /// - UINT8 ucMeasChn: measurement channel [0...3] /// - UINT8 ucMin: minimum change for new signal output /// (if no signal change is recognized, at least every 40ms /// a CAN message will be sent) /// /// Return /// - UINT8 ucResult: CMDIF_Error (in case of incorrect argument, /// ucOutChn, ucType, ucMeasChn) /// CMDIF_ResultOk (else) //----------------------------------------------------------------------------- void CmdIf_SetMeasOutChn(void) { UINT8 ucOutChn = CmdIf_ArgBuffer.SetMeasOutChn.ucOutChn; UINT8 ucMeasChn = CmdIf_ArgBuffer.SetMeasOutChn.ucMeasChn; // get divider for averaging INT32 lDiv = (INT32) Nvm_RamCopy.AltuMeasOut.ulClockDivider + 1; // ulClockDivider = divider - 1 // calculate factor for averaging and round result INT32 lMult = (2 * ALTU_AvrgNorm + lDiv) / (2 * lDiv); CmdIf_RetBuffer.ucResult = CMDIF_ResultOk; // initialize to default value // avoid illegel pointer if meas. channel/output channel out of range if((ucOutChn < ALTU_OutChannels) && (ucMeasChn < ALTU_MeasChannels)) { switch(CmdIf_ArgBuffer.SetMeasOutChn.ucType) { case CMDIF_MeasVoltageAvrg: // average value of voltage on measurement lines Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrAvrg()->lVoltage[ucMeasChn]; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = lMult; // use scaling factor for averaging break; case CMDIF_MeasVoltageSmpl: // 1 sample of voltage on measurement lines Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrSmpl()->lVoltage[ucMeasChn]; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; case CMDIF_MeasCurrAmpAvrg: // average value of current amplified on measurement lines Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrAvrg()->lCurrAmp[ucMeasChn]; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = lMult; // use scaling factor for averaging break; case CMDIF_MeasCurrAmpSmpl: // 1 sample of current amplified on measurement lines Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrSmpl()->lCurrAmp[ucMeasChn]; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; case CMDIF_MeasCurrNrmAvrg: // average value of current not amplified on measurement lines Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrAvrg()->lCurrNrm[ucMeasChn]; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = lMult; // use scaling factor for averaging break; case CMDIF_MeasCurrNrmSmpl: // 1 sample of current not amplified on measurement lines Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrSmpl()->lCurrNrm[ucMeasChn]; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; case CMDIF_MeasVoltExtAvrg: // average value of voltage on extension port Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrAvrg()->lVoltExt; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = lMult; // use scaling factor for averaging break; case CMDIF_MeasVoltExtSmpl: // 1 sample of voltage on extension port Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrSmpl()->lVoltExt; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; case CMDIF_MeasStpPosRel: // simulated relative stepper position Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lActPosRel; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; case CMDIF_MeasStpPosAbs: // simulated absolute stepper position Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lActPosAbs; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; case CMDIF_MeasStpPsens: // stepper position sensor (simulated or input signal) Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & Nvm_RamCopy.AltuStpPos.lPsensState; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; case CMDIF_MeasStpCurrent: // stepper coil cuurnt (vector addition) Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lCurrent; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; case CMDIF_MeasStpSpeed: // stepper speed Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lSpeed; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; case CMDIF_MeasStpAcceleration: // stepper acceleration Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lAcceleration; Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1 break; default: CmdIf_RetBuffer.SetMeasOutChn.ucResult = CMDIF_Error; break; } Nvm_RamCopy.AltuMeasOut.aunMinChange[ucOutChn] = CmdIf_ArgBuffer.SetMeasOutChn.ucMin; } else { CmdIf_RetBuffer.SetMeasOutChn.ucResult = CMDIF_Error; // illegal output channel } } //----------------------------------------------------------------------------- /// \brief Enable/disable measurement output /// /// \descr selective enable/disable of mesurement output by channel number /// /// Arguments /// - UINT16 unEnMask: Enable mask - bit0 = Chn0, bit1 = Chn1, ... /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetMeasOutEnable(void) { UINT16 unMask, unIx; unMask = 1; // begin with bit position 0 for(unIx=0; unIxSet threshold value for PWM measurement /// /// \descr Set threshold value for PWM measurement /// (see description in "CmdIf_GetPwmDutyCycle"). /// Typical value: 50% of maximum measurement current. /// /// Arguments /// - UINT8 ucChannel: measurement channel [0...3] /// - UINT16 unThreshold: threshold in mA /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetPwmThreshold(void) { HalAdcSetPwmThreshold(CmdIf_ArgBuffer.SetPwmThreshold.ucChannel, CmdIf_ArgBuffer.SetPwmThreshold.unThreshold); CmdIf_RetBuffer.SetPwmThreshold.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Reset stepper measurement /// /// \descr Reset the following measurement results and prepare new measurement /// - GetStpPrePostStepTime /// - GetStpDutyCycle /// - GetStpVmax /// - GetStpAcceleration /// - GetStpIrunIhold /// /// Arguments /// - UINT8 ucMeasVmaxStart: delay before measurement start [HS] /// - UINT8 ucMeasVmaxLength: measurement length [HS] /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_ResetStpMeasurement(void) { UINT8 ucStart = CmdIf_ArgBuffer.ResetStpMeasurement.ucMeasVmaxStart; UINT8 ucLength = CmdIf_ArgBuffer.ResetStpMeasurement.ucMeasVmaxLength; if(ucLength == 0) // backward compatibility (Length == 0 is not possible) { ucStart = 80; ucLength = 40; } StpSim_ResetMeasurement(ucStart, ucLength); CmdIf_RetBuffer.ResetStpMeasurement.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Get PreStepTime and PostStepTime /// /// \descr PreStepTime: time after switch to Irun current until stepper start /// PostStepTime: time after stopping until switch to Ihold current /// These values are calculated during stepper measurement only! /// /// Arguments /// - none /// /// Return /// - UINT8 ucPreStep: PreStepTime [ms] /// - UINT8 ucPostStep: PostStepTime [ms] /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_GetStpPrePostStepTime(void) { CmdIf_RetBuffer.GetStpPrePostStepTime.ucPreStep = StpSim_GetPreStepTime(); CmdIf_RetBuffer.GetStpPrePostStepTime.ucPostStep = StpSim_GetPostStepTime(); CmdIf_RetBuffer.GetStpPrePostStepTime.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Get Vmax /// /// \descr Get maximum stepper velocity /// This value is calculated during stepper measurement only! /// /// Arguments /// - none /// /// Return /// - UINT16 unVmax: Vmax [HS/s] /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_GetStpVmax(void) { CmdIf_RetBuffer.GetStpVmax.unVmax = StpSim_GetVmax(); CmdIf_RetBuffer.GetStpVmax.ucResult = CMDIF_ResultOk; } void CmdIf_GetStpDutyCycle(void) { } void CmdIf_GetStpAcceleration(void) { } //----------------------------------------------------------------------------- /// \brief Get stepper position /// /// \descr Read simulated stepper position. /// - relative position: regardless of mechanical limitations /// - absolute position: step counter stopped at mechanical limitations /// /// Arguments /// - none /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk /// - INT16 nPosRel: relative position [HS] /// - INT16 nPosAbs: absolute position [HS] //----------------------------------------------------------------------------- void CmdIf_GetStpPos(void) { CmdIf_RetBuffer.GetStpPos.nPosAbs = StpSim_GetPosAbs(); CmdIf_RetBuffer.GetStpPos.nPosRel = StpSim_GetPosRel(); CmdIf_RetBuffer.GetStpPos.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Get stepper current values Irun and Ihold /// /// \descr Get peak values of Irun and Ihold. /// These values are calculated during stepper measurement only! /// /// Arguments /// - none /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk /// - UINT16 unIrun: Irun [mA] /// - UINT16 unIhold: Ihold [mA] //----------------------------------------------------------------------------- void CmdIf_GetStpIrunIhold(void) { CmdIf_RetBuffer.GetStpIrunIhold.unIrun = StpSim_GetIrun(); CmdIf_RetBuffer.GetStpIrunIhold.unIhold = StpSim_GetIhold(); CmdIf_RetBuffer.GetStpIrunIhold.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Set stepper position /// /// \descr Set simulated stepper position initial values: /// - relative position: regardless of mechanical limitations /// - absolute position: step counter stopped at mechanical limitations /// /// Arguments /// - INT16 nPosRel: relative position [HS] /// - INT16 nPosAbs: absolute position [HS] /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetStpPos(void) { StpSim_SetPosAbs(CmdIf_ArgBuffer.SetStpPos.nPosAbs); StpSim_SetPosRel(CmdIf_ArgBuffer.SetStpPos.nPosRel); CmdIf_RetBuffer.SetStpPos.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Set stepper angle /// /// \descr Set initial value for simulated stepper angle. /// Note: wraparound is performed every 8 HS. /// For normal simulation purposes this value should be set to 0. /// /// Arguments /// - UINT8 ucAngle: angle [HS] /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetStpAngle(void) { StpSim_SetAngle(CmdIf_ArgBuffer.SetStpAngle.ucAngle); CmdIf_RetBuffer.SetStpAngle.ucResult = CMDIF_ResultOk; } void CmdIf_SetStpPsens(void) { } //----------------------------------------------------------------------------- /// \brief Enable/disable stepper simulation /// /// \descr Switch stepper simulation on or off /// /// Arguments /// - UINT8 ucSimOn: 0=disabled, else enabled /// - UINT8 ucDir: 0=default, 1=reverse /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetStpSim(void) { BOOL boSimOn = CmdIf_ArgBuffer.SetStpSim.ucSimOn != 0 ? TRUE : FALSE; BOOL boReverse = CmdIf_ArgBuffer.SetStpSim.ucDir != 0 ? TRUE : FALSE; StpSim_SetSimulation(boSimOn, boReverse); CmdIf_RetBuffer.SetStpSim.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Set stepper block positions /// /// \descr Set block positions (used for absolute position) /// /// Arguments /// - INT16 nPosLo: lower block position [HS] /// - INT16 nPosHi: upper block position [HS] /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_SetStpBlockPos(void) { StpSim_SetBlockPosLo(CmdIf_ArgBuffer.SetStpBlockPos.nPosLo); StpSim_SetBlockPosHi(CmdIf_ArgBuffer.SetStpBlockPos.nPosHi); CmdIf_RetBuffer.SetStpBlockPos.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Set position sensor mode /// /// \descr /// /// \param UINT8 ucUsePsens: 0 = do not use position sensor /// 1 = use position sensor /// UINT8 ucPsensSimu: 0 = reserved (read external position sensor signal) /// 1 = simulate position sensor (create signal by ALTU) /// UINT8 ucPsensDiag: 0 = no sensor diagnosis --> use low side switch /// 1 = reserved (sensor diagnosis) /// \return void //----------------------------------------------------------------------------- void CmdIf_SetStpPsensMode(void) { StpSim_SetPsensMode(CmdIf_ArgBuffer.SetStpPsensMode.ucUsePsens, CmdIf_ArgBuffer.SetStpPsensMode.ucPsensSimu, CmdIf_ArgBuffer.SetStpPsensMode.ucPsensDiag ); CmdIf_RetBuffer.SetStpPsensMode.ucResult = CMDIF_ResultOk; } //----------------------------------------------------------------------------- /// \brief Set position sensor parameters /// /// \descr /// /// \param INT16 nPos: position of sensor regulation slope [HS] /// UINT8 ucHyst: hysteresis between regulation slope and additional slope [HS] /// UINT8 ucPol: polarity of sensor signal /// 0 = low at positive stepper positions /// 1 = high at positive stepper positions /// UINT8 ucRegSlope: definition of regulation slope /// 0 = regulation slope occurs at decrementation of step position /// 1 = regulation slope occurs at incrementation of step position /// /// \return void //----------------------------------------------------------------------------- void CmdIf_SetStpPsensPara(void) { StpSim_SetPsensPara(CmdIf_ArgBuffer.SetStpPsensPara.nPos, CmdIf_ArgBuffer.SetStpPsensPara.ucHyst, CmdIf_ArgBuffer.SetStpPsensPara.ucPol, CmdIf_ArgBuffer.SetStpPsensPara.ucRegSlope); CmdIf_RetBuffer.SetStpPsensPara.ucResult = CMDIF_ResultOk; } void CmdIf_SetStpCurThresh(void) { } //----------------------------------------------------------------------------- /// \brief Calibration of current measurement paths /// /// \descr Read all 8 current values and store the results in RAM. Make sure /// to disable the measurement currents before starting this command.
/// The functions CmdIf_GetCurrentNorm() or CmdIf_GetCurrentAmp() /// will use these values as zero current levels. /// CmdIf_StoreCurrentCalib() will store these values in NVM. /// /// Arguments /// - none /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_DoCurrentCalib(void) { HalAdc_DoCurrentCalib(); CmdIf_RetBuffer.DoCurrentCalib.ucResult = CMDIF_ResultOk; } void CmdIf_StoreCurrentCalib(void) { } void CmdIf_StoreStpPos(void) { } void CmdIf_StoreStpPara(void) { } //----------------------------------------------------------------------------- /// \brief Reset NVM contents to default settings /// /// \descr Altu2 parameters and initialization values may be modified and /// stored in NVM. This command resets the values in NVM to the default /// settings. /// /// Arguments /// - none /// /// Return /// - UINT8 ucResult: CMDIF_ResultOk //----------------------------------------------------------------------------- void CmdIf_ResetNvm(void) { // TBD CmdIf_RetBuffer.ResetNvm.ucResult = CMDIF_ResultOk; } // dummy to fill up the table void CmdIf_Dummy(void) {} // ----------------------------------------------------------------------------------------------- void CmdIf_StartService(UINT8 ucId, const UINT8* pArg, UINT8* pRet) { UtilMemCopy((void *) &CmdIf_ArgBuffer, pArg, CMDIF_CntArg); CmdIf_RetBuffer.uxData = 0; // reset all 8 bytes of return buffer CmdIf_RetBuffer.ucResult = CMDIF_IllegalSubId; if(ucId < CMDIF_CntServ) { CmdIf_CmdList[ucId](); } UtilMemCopy(pRet, (void *) &CmdIf_RetBuffer, CMDIF_CntRet); } void CmdIf_Main(void) { }