⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 it_st7mc.c

📁 该程序是ST7MC驱动BLDC120
💻 C
字号:
/**************** (c) 2004  STMicroelectronics **********************

PROJECT  : ST7MC demokit
COMPILER : ST7 METROWERKS C (HIWARE) / COSMIC

MODULE  :  it_ST7MC.c
LIBRARY VERSION  :  1.0.2

CREATION DATE :    04.2005
AUTHOR :      Jiang Jian-guo	/  Microcontroller Competence center  / ST Shang Hai

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

DESCRIPTION :   Main interrupt service routines

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

 ******************************************************************************
 THE SOFTWARE INCLUDED IN THIS FILE IS FOR GUIDANCE ONLY. ST MICROELECTRONICS
 SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES
 WITH RESPECT TO ANY CLAIMS ARISING FROM USE OF THIS SOFTWARE.
 ******************************************************************************
                
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

******************************************************************************/


#include "lib.h"
#include "it_ST7MC.h"
#include "ST7MC_hr.h" 
#include "version.h" 
#include "ports.h"
#include "timer.h"
#include "mtc.h"
#include "regul.h" 
#include "wwdg.h"   
#include "LinSCI.h"   
#include "MTC_Settings_Sensorless.h"

volatile u8 SpdVarPeriodCounter = 0;   
volatile u16 timer_after_start = 1000;	// 10 seconds delay for stalling check in just start stage
volatile u16 Restart_Timer =0;			// Restarting 3 Min delay timer
volatile u16 SCIRX_Watchdog;
   
volatile u8 SCI_TxDelay_Timer;			// 100ms delay counter before SCI Transmission

/* TimeBaseStatus flags description */
#define SCI_TXDelay_ELAPSED		((u8)0x01)	// 100ms delay before SCI Transmission elapsed
#define Restart_3Min_Begin		((u8)0x02)
volatile u8 TimeBaseStatus = 0; 			 
   
/*-----------------------------------------------------------------------------*/
void Resert_SCIRX_Watchdog(void)
{
	SCIRX_Watchdog = 600;		// 6 second SCI RX waterdog interval
	MotorStatus &= 0xdf;
}
 
void Timer_SetSCITXDelayPeriod(u8 Period)
{
	SCI_TxDelay_Timer = Period;  			// Reset counter to new value
	TimeBaseStatus &= (u8)(~SCI_TXDelay_ELAPSED);	//	Clear Flag
}                                           
                           
BOOL Timer_IsSCITXDelayElapsed(void)
{       
	if ( TimeBaseStatus & SCI_TXDelay_ELAPSED )
	{
		TimeBaseStatus &= (u8)(~SCI_TXDelay_ELAPSED); //	Clear Flag
		return ( TRUE );
	}
	else
 	{
		return ( FALSE );
	}
}                                                                      
                                           
void Timer_SetSpdVarPeriod(u8 Period)
{
	SpdVarPeriodCounter = Period;	
}                                       

u8 Timer_GetSpdVarPeriod(void)
{
 	return(SpdVarPeriodCounter);
}

BOOL Timer_SpdVarPeriodElapsed(void)  
{
	if (SpdVarPeriodCounter == 0)
	{
		return ( TRUE );
	}
	else
 	{
		return ( FALSE );
	} 
}                                   

void Set_RestartTimer(u16 Period)
{
	Restart_Timer = 0;
	TimeBaseStatus |= (u8)(Restart_3Min_Begin);	
}
                          
BOOL Timer_RestartTimerBegin(void)
{
	if (TimeBaseStatus & Restart_3Min_Begin)
	{
		return (TRUE);
	}
	else
 	{
		return (FALSE);
	}	
}   

/*-----------------------------------------------------------------------------*/ 
  
#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif   

/*-----------------------------------------------------------------------------
ROUTINE NAME : dummy_rt
INPUT/OUTPUT : None

DESCRIPTION  : Empty Interrupt Service Routine

COMMENTS     : all the non-connected interrupt vectors are connected to this empty function
-----------------------------------------------------------------------------*/ 
void dummy_rt(void)
{
}

#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : TRAP_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : Software Interrupt Service Routine

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void TRAP_Interrupt(void)
{
}


#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : MCC_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : Software Interrupt Service Routine

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void MCC_Interrupt(void)
{
}


#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : PORTS_0_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : 

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void PORTS_0_Interrupt(void)
{
}


#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : PORTS_1_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : 

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void PORTS_1_Interrupt(void)
{
}


#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : PORTS_2_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : 

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void PORTS_2_Interrupt(void)
{
}


#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : SPI_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : 

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void SPI_Interrupt(void)
{
}

#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : TIMA_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : timer A Interrupt Service Routine

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void TIMB_Interrupt(void)
{
}

#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : TIMB_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : timer B Interrupt Service Routine

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void TIMA_Interrupt(void)
{
unsigned int timer;

if (ValBit(TASR,6))
{
	timer=TAOC1HR<<8;
	timer+=TAOC1LR;
	timer+= 10000;   		// int every 10 ms
	TAOC1HR=(u8)(timer>>8);
	TAOC1LR=(u8)timer;
    
    SCIRX_Watchdog--; 
    if (SCIRX_Watchdog == 0) MotorStatus |= SCI_FAILURE; //SetMotorStatus(SCI_FAILURE);
    
    if (SCI_TxDelay_Timer != 0) 
    {
    	SCI_TxDelay_Timer--;
		if (SCI_TxDelay_Timer == 0) TimeBaseStatus |= SCI_TXDelay_ELAPSED;		   	
    }

    if (Restart_Timer++ >= 3000)     				//by lf  05.7.31 18000-->3000
    {
 		Restart_Timer = 0;
 		TimeBaseStatus &= (u8)(~Restart_3Min_Begin);   	
    }
    
/*	
	if (Restart_Timer != 0) 
	{
		Restart_Timer--;
		if (Restart_Timer == 0) TimeBaseStatus |= Restart_3Min_Begin;		   	
	}		
*/		
	if (timer_after_start != 0) timer_after_start--;
	if (SpdVarPeriodCounter != 0) SpdVarPeriodCounter--;
	if (DebounceButton != 0) DebounceButton--;
	if (timer_10ms != 0) timer_10ms--;
	if (timer_CL_10ms != 0) timer_CL_10ms--;	           
}                                 
else 
{
	timer=TAOC2HR<<8;
	timer+=TAOC2LR;
	timer+= 1000;   // int every 1 ms
	TAOC2HR=(u8)(timer>>8);
	TAOC2LR=(u8)timer;

	if (Timer_1ms !=0) Timer_1ms--;
	if (Timer_WDG !=0) Timer_WDG--;
	if (PI_Sampling != 0) PI_Sampling--;
	else      
		{
		SetBit(Flag_MTC,SAMP_EVT);
		if (Get_CurrentTargetSpeed() <= (35*Pole_Pair_Num*10) ) PI_Sampling = SAMPLING_TIME_LowSpeed;		
		else PI_Sampling = SAMPLING_TIME_HighSpeed;
		//PI_Sampling = SAMPLING_TIME;
		}
    }
}

#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : AVD_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : Auxiliary Voltage Detector Interrupt Service Routine

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void AVD_Interrupt(void)
{
}

#ifdef __HIWARE__				/* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS		/* additional registers will be saved */
#else
#ifdef __CSMC__					/* test for Cosmic Compiler */
@interrupt						/* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!"	/* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : ART_Interrupt
INPUT/OUTPUT : None

DESCRIPTION  : ART Interrupt Service Routine

COMMENTS     : 
-----------------------------------------------------------------------------*/ 
void ART_Interrupt(void)
{
}



/*** (c) 2004  STMicroelectronics ****************** END OF FILE ***/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -