?? bldczc.c
字號:
/****************************************************************************************************
*
* Motorola Inc.
* (c) Copyright 2000 Motorola Inc.
* ALL RIGHTS RESERVED.
*
*****************************************************************************************************
*
*
* FILE NAME: BldcZC.c
*
* DESCRIPTION: Motorola Bldc Zero Crossing Algorithm source file
*
* MODULES INCLUDED: stdlib.h
* dspfunc.h
* bldc.h
*
*****************************************************************************************************/
/****************************************************************************************************
*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* READ ME CAREFULLY:
*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* The general of BldcZC algorithms interconnectivity is, they are
* devided into groups according to their functionalities:
* - COMPUTATION:
* - bldczcComput(),bldczcComputInit()
* - ZERO CROSSING
* - bldczcCmtServ(),bldczcZCrosIntAlg(),bldczcZCrosInit()
* - COMMUTATION:
* - bldczcCmtServ(),bldczcCmtServInit()
* - DATA EXCHANGE:
* - bldczcHndlr(),bldczcTimeoutIntAlg(),bldczcHndlrInit()
* bldczcHndlrStop()
* !Each of the above group has its dedicated BldcZC_sState_xxx API
* typedef data structure
* !Each of BldcZC_sState_xxx structure has BldcZC_u_xxx
* Commands and Requests status flags register where the flags has
* following meaning:
* yy_zz_CmdFlag - is an output Command Flag from algorithm meaning:
* action yy happened in algorithm zz!!!
* yy_zz_RqFlag - is an input Request Flag to the algorithm meaning:
* action yy happened(somewhere),
* service in algorithm zz requested!!!
* !The data interchange between these groups is via:
* - bldczcHndlr() algorithm !!! and
* - bldczcTimeoutIntAlg () algorithm !!!
* which input is bldczc_sStates data structure containing all
* BldcZC_sState_xxx substructures
*
* The algorithms can also be splitted according to their
* suggested calls:
* - from Main SW (or Arbiter called)
* - from Interrupt subroutines called: xxxIntAlg
*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
****************************************************************************************************/
/* Include Header Files */
/* include intristic functions */
#include "types.h"
#include "arch.h"
#include "mc.h"
#include "pwm.h"
/* include file contains global tables constants and definitions bldcdrv.h */
/* include BLDC Zero Crossing functions declarations BldcZC.h */
#include "bldc.h"
#ifdef __cplusplus
extern "C" {
#endif
/* variables definitions */
typedef union
{
struct
{
UWord16 LSBpart;
Word16 MSBpart;
}RegParts;
Word32 Reg32bit;
} uReg32;
/* BldcZCAlgo.c Internal Avialibility Functions Declarations */
static inline Result PresetCalculation (bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes);
static inline Result SetCalculation (bldczc_sStateComput *pState_Comput, bldczc_sTimes *pTimes);
static inline Result PrepareToffTiming (bldczc_uCmdGeneral *pCmd_General,
UWord16 *T_Next,
UWord16 T_Cmt0,
UWord16 Per_Toff);
inline static Result PrepareProcTiming (bldczc_uCmdGeneral *pCmd_General,
UWord16 *T_Next,
UWord16 T_Cmt0,
UWord16 Const_PerProcCmt);
inline static Result CmtTimeout ( bldczc_sStates *pStates, bldczc_sTimes *pTimes , UWord16 T_Actual );
inline static Result CmtProcTimeout ( bldczc_sStates *pStates, bldczc_sTimes *pTimes );
inline static Result ZCToffTimeout ( bldczc_sStates *pStates );
/****************************************************************************************************
*
* MODULE: bldczcHndlr ( bldczc_sStates *pStates, bldczc_sTimes *pTimes, UWord16 T_Actual )
*
* DESCRIPTION: function bldczcHndlr is a command interface between bldczc software modules and their
* State_Comput, State_Cmt, State_ZCros, State_General data structures.
* Refer to SDK documentation for detailes.
*
* RETURNS: The function returns the PASS (0)
*
* SUBMODULES USED: CmtTimeout( pStates, pTimes, T_Actual )
* PrepareProcTiming ( bldczc_uCmdGeneral *pCmd_General,
* UWord16 *T_Next,
* UWord16 T_Cmt0,
* UWord16 Const_PerProcCmt )
* PrepareToffTiming ( bldczc_uCmdGeneral *pCmd_General,
* UWord16 *T_Next,
* UWord16 T_Cmt0,
* UWord16 Per_Toff)
* ZCToffTimeout ( bldczc_sStates *pStates )
*
* ARGUMENTS: The function has three arguments: in/out - pointer to bldczc_sStates structure that
* contains the status variables for all
* BLDC motor BEMF Zero Crossing algorithms
* in/out - pointer to bldczc_sTimes structure that
* contains the time variables for all
* BLDC motor BEMF Zero Crossing algorithms
* in - T_Actual - 16bit range Actual Time
*
* RANGE ISSUES: All the time variables and components T_x in bldczc_sTimes structure are
* computed as 16 bit rollower registers. It means that if their results overflows
* 16 bits, they are not saturated, just the overflow bit is ignored and low 16 bits
* word is taken as a result. Then the T_x variables can be used as outputs and inputs
* from a 16 bit past compare timer used as a system clock base!
*
* SPECIAL ISSUES: The function calculates correct results if the saturaion mode is set or not .
*
****************************************************************************************************/
/* -------------------[ bldczcHndlr - Begin ]------------------------------*/
Result bldczcHndlr ( bldczc_sStates *pStates, bldczc_sTimes *pTimes, UWord16 T_Actual )
{
/* temporary registers - unions for 16bit MSB,LSB or 32 bit acces */
uReg32 Temp1F32;
uReg32 Temp2F32;
UWord16 Temp1UW16;
UWord16 TempOMR;
if (pStates->State_Cmt.Cmd_Cmt.B.CmtDone_CmdFlag)
{
/* -------------------[ CmtDoneHndlr - Begin ]-----------------------*/
pStates->State_ZCros.Cmd_ZCros.B.ZCOKGet_CmdFlag = 0; /* clear possible hazard states */
pStates->State_ZCros.Cmd_ZCros.B.ZCMiss_CmdFlag = 0; /* clear possible hazard states */
pStates->State_Comput.Cmd_Comput.B.CmtComp_CmdFlag = 0; /* clear possible hazard states */
pStates->State_ZCros.Cmd_ZCros.B.CmtDone_ZCrosServ_CmdFlag = 0; /* clear possible hazard states */
pStates->State_Comput.Cmd_Comput.B.CmtPreComp_CmdFlag = 0; /* clear possible hazard states */
pStates->State_Cmt.Cmd_Cmt.B.CmtServ_CmdFlag = 0; /* clear possible hazard states */
pStates->State_ZCros.Cmd_ZCros.B.CmtDone_ZCrosServ_RqFlag = 1;
pStates->State_Comput.Cmd_Comput.B.CmtDone_Comput_RqFlag = 1;
pStates->State_Cmt.Cmd_Cmt.B.CmtDone_CmtServ_RqFlag = 1;
pStates->State_Cmt.Cmd_Cmt.B.CmtDone_CmdFlag = 0; /* clear command Flag */
/* -------------------[ CmtDoneHndlr - End ]-------------------------*/
};
if (pStates->State_ZCros.Cmd_ZCros.B.CmtDone_ZCrosServ_CmdFlag)
{
/* -------------------[ CmtDoneZCrosHndlr - Begin ]------------------*/
pStates->State_ZCros.Cmd_ZCros.B.CmtDone_ZCrosServ_CmdFlag = 0;
if ( pStates->State_ZCros.Cmd_ZCros.B.EndStart_ZCrosServ_CmdFlag \
&& pStates->State_General.Cmd_General.B.StartMode_HndlrFlag )
{
pStates->State_General.Cmd_General.B.EndStartMode_HndlrCmdFlag = 1;
};
if ( pStates->State_ZCros.Cmd_ZCros.B.MaxZCrosErr_ZCrosServ_CmdFlag )
{
pStates->State_General.Cmd_General.B.MaxZCrosErr_HndlrCmdFlag = 1;
};
/* -------------------[ CmtDoneZCrosHndlr - End ]--------------------*/
}
if (pStates->State_General.Cmd_General.B.CmtProcEnd_CmdFlag)
{
/* -------------------[ CmtProcEndHndlr - Begin ]--------------------*/
pStates->State_ZCros.Cmd_ZCros.B.CmtProcEnd_ZCrosServ_RqFlag = 1;
pStates->State_General.Cmd_General.B.CmtProcEnd_CmdFlag = 0;
/* -------------------[ CmtProcEndHndlr - End ]----------------------*/
}
if (pStates->State_Comput.Cmd_Comput.B.ToffComp_CmdFlag)
{
/* -------------------[ ToffCompHndlr - Begin ]----------------------*/
pStates->State_General.Cmd_General.B.ToffComp_Timeout_InfoFlag = 1;
pStates->State_Comput.Cmd_Comput.B.ToffComp_CmdFlag = 0;
/* -------------------[ ToffCompHndlr - End ]------------------------*/
}
if ( pStates->State_General.Cmd_General.B.ZCToff_TimedFlag )
{
if ( pStates->State_General.Cmd_General.B.ZCToffTest_Hndlr_RqFlag )
{
/* -------------------[ ZCToffTestHndlr - Begin ]--------------------*/
/* solving of hazard states when Toff Passed before Timer was set */
pStates->State_General.Cmd_General.B.ZCToffTest_Hndlr_RqFlag = 0;
/* if ( pTimes->Per_Toff < T_Actual - pTimes->T_Cmt0 ) */
Temp1F32.RegParts.MSBpart = 0;
Temp1F32.RegParts.LSBpart = T_Actual;
Temp2F32.RegParts.MSBpart = 0;
Temp2F32.RegParts.LSBpart = pTimes->T_Cmt0;
Temp2F32.Reg32bit = L_sub( Temp1F32.Reg32bit, Temp2F32.Reg32bit );
Temp1UW16 = Temp2F32.RegParts.LSBpart;
/* Removed asm(move OMR,TempOMR); */ /* store OMR status */
/* Removed archSetNoSat(); */ /* switch saturation off */
/* Removed Temp1UW16 = T_Actual - pTimes->T_Cmt0; */
/* Removed asm(move TempOMR,OMR); */ /* restore OMR status */
if ( pTimes->Per_Toff < Temp1UW16)
{
ZCToffTimeout ( pStates );
}
/* -------------------[ ZCToffTestHndlr - End ]----------------------*/
}
if ( pStates->State_General.Cmd_General.B.ToffComp_Timeout_InfoFlag )
{
/* -------------------[ ToffTimedHndlr - Begin ]---------------------*/
/* solving of hazard states when Toff Timer is set with last value
before ZCToff computed */
pStates->State_General.Cmd_General.B.ToffComp_Timeout_InfoFlag = 0;
PrepareToffTiming (&pStates->State_General.Cmd_General,\
&pTimes->T_Next, pTimes->T_Cmt0, pTimes->Per_Toff);
/* -------------------[ ToffTimedHndlr - End ]-----------------------*/
}
}
if (pStates->State_Cmt.Cmd_Cmt.B.CmtServ_CmdFlag)
{
/* -------------------[ CmtServHndlr - Begin ]-----------------------*/
pStates->State_ZCros.Cmd_ZCros.B.CmtServ_ZCrosServ_RqFlag = 1;
pStates->State_General.Cmd_General.B.StepPrepared_Timeout_InfoFlag = 1;
pStates->State_Cmt.Cmd_Cmt.B.CmtServ_CmdFlag = 0;
/* -------------------[ CmtServHndlr - End ]-------------------------*/
}
if (pStates->State_ZCros.Cmd_ZCros.B.CmtServ_ZCrosServ_CmdFlag)
{
/* -------------------[ CmtServZCServHndlr - Begin ]-----------------*/
pStates->State_General.Cmd_General.B.ZCPrepared_Timeout_InfoFlag = 1;
pStates->State_ZCros.Cmd_ZCros.B.CmtServ_ZCrosServ_CmdFlag = 0;
/* -------------------[ CmtServZCServHndlr - End ]-------------------*/
}
if ( pStates->State_General.Cmd_General.B.ZCToffEnd_CmdFlag && \
pStates->State_Comput.Cmd_Comput.B.CmtPreComp_CmdFlag )
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -