Example #1
1
void Mclib_API_init(void)
{
	ENC_Init();
	
  SVPWM_3ShuntInit();

  TB_Init();

//#ifdef BRAKE_RESISTOR
//    MCL_Brake_Init();
//#endif

	/* TIM1 Counter Clock stopped when the core is halted */
  DBGMCU_Config(DBGMCU_TIM1_STOP, ENABLE);
  
  // Init Bus voltage and Temperature average  
  MCL_Init_Arrays();
	
  Res_f=1;

}
static void prvSetupTimerInterrupt( void )
{
EIC_IRQInitTypeDef  EIC_IRQInitStructure;	
TB_InitTypeDef      TB_InitStructure;

	/* Setup the EIC for the TB. */
	EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE;
	EIC_IRQInitStructure.EIC_IRQChannel = TB_IRQChannel;
	EIC_IRQInitStructure.EIC_IRQChannelPriority = 1;
	EIC_IRQInit(&EIC_IRQInitStructure);
	
	/* Setup the TB for the generation of the tick interrupt. */
	TB_InitStructure.TB_Mode = TB_Mode_Timing;
	TB_InitStructure.TB_CounterMode = TB_CounterMode_Down;
	TB_InitStructure.TB_Prescaler = portPRESCALE - 1;
	TB_InitStructure.TB_AutoReload = ( ( configCPU_CLOCK_HZ / portPRESCALE ) / configTICK_RATE_HZ );
	TB_Init(&TB_InitStructure);
	
	/* Enable TB Update interrupt */
	TB_ITConfig(TB_IT_Update, ENABLE);

	/* Clear TB Update interrupt pending bit */
	TB_ClearITPendingBit(TB_IT_Update);

	/* Enable TB */
	TB_Cmd(ENABLE);
}
Example #3
0
//----------------------------------------------------------
void init(void)
{

  DDRB = BV(PB0);
  DDRD = BV(PD1) | BV(PD3) | BV(PD4);

  uart0_init(); // PC
  uart1_init(); // internal
  uart2_init(); // external (via extBus)
  adc_init();
  timer_init();
  TB_Callback_setBaud = uart1_set_baud;
  TB_Init((void*) 0x10); // addr in eeprom with settings
  pp_init();
  sei();
}
Example #4
0
int main(void)
{
	// Interrupty pøesunuty na jinou adresu pro Bootloader.
	Move_interrupts();
    /* Replace with your application code */
	cli();

	//Nastavení Systemového enable pro RS485 pro UART0
	DDRD |= (1 << DDD1) | (1 << DDD2);

	timer_init();
	
	uart0_init();
	TB_Callback_setBaud = &uart0_set_baud;
	TB_Callback_TX = &send_data;
	TB_Init((void*) 0x10); // addr in eeprom with settings
	Bootloader_Init();
	sei();
	
    while (1) 
    {
		process_timer_100Hz();
		uart0_process();
		try_receive_data();
	
		// 250 ms - V Bootloader režimu.
		if(cnt < 250)
		{
			cnt++;
		}
		else
		{
			if (!BootStatus)
			{
				cnt = 0;
				jumpaddress();
			}
		}
    }
}
Example #5
0
int Tcl_AppInit(Tcl_Interp *interp)
{
    if(Tcl_Init(interp) == TCL_ERROR)
        return TCL_ERROR;

    if(Tk_Init(interp) == TCL_ERROR)
        return TCL_ERROR;

    if(TB_Init(interp) == TCL_ERROR)
        return TCL_ERROR;

#ifdef USE_TIDE
    if(Tide_Init(interp) == TCL_ERROR)
        return TCL_ERROR;
#endif

    if(script) {
        if(Tcl_EvalFile(interp, script) != TCL_OK) {
            handle_error(interp, interp->result);
        }
    }

    return TCL_OK;
}
Example #6
0
void SV_Init(void)
{
	int index;

	SV_AddOperatorCommands();

	// serverinfo vars
	Cvar_Get("timelimit", "0", CVAR_SERVERINFO);

	Cvar_Get("sv_keywords", "", CVAR_SERVERINFO); // unused. Kept for GameTracker.com compatibility
	Cvar_Get("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO | CVAR_ROM);
	sv_mapname        = Cvar_Get("mapname", "nomap", CVAR_SERVERINFO | CVAR_ROM);
	sv_privateClients = Cvar_Get("sv_privateClients", "0", CVAR_SERVERINFO);
	sv_hostname       = Cvar_Get("sv_hostname", "ETLHost", CVAR_SERVERINFO | CVAR_ARCHIVE);
	sv_maxclients     = Cvar_Get("sv_maxclients", "20", CVAR_SERVERINFO | CVAR_LATCH);
	sv_maxRate        = Cvar_Get("sv_maxRate", "0", CVAR_ARCHIVE | CVAR_SERVERINFO);
	sv_minPing        = Cvar_Get("sv_minPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO);
	sv_maxPing        = Cvar_Get("sv_maxPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO);
	sv_floodProtect   = Cvar_Get("sv_floodProtect", "1", CVAR_ARCHIVE | CVAR_SERVERINFO);
	sv_allowAnonymous = Cvar_Get("sv_allowAnonymous", "0", CVAR_SERVERINFO);
	sv_friendlyFire   = Cvar_Get("g_friendlyFire", "1", CVAR_SERVERINFO | CVAR_ARCHIVE);
	sv_maxlives       = Cvar_Get("g_maxlives", "0", CVAR_ARCHIVE | CVAR_LATCH | CVAR_SERVERINFO);
	sv_needpass       = Cvar_Get("g_needpass", "0", CVAR_SERVERINFO | CVAR_ROM);

	// systeminfo
	// added cvar_t for sv_cheats so server engine can reference it
	sv_cheats   = Cvar_Get("sv_cheats", "1", CVAR_SYSTEMINFO | CVAR_ROM);
	sv_serverid = Cvar_Get("sv_serverid", "0", CVAR_SYSTEMINFO | CVAR_ROM);
	sv_pure     = Cvar_Get("sv_pure", "1", CVAR_SYSTEMINFO);
	Cvar_Get("sv_paks", "", CVAR_SYSTEMINFO | CVAR_ROM);
	Cvar_Get("sv_pakNames", "", CVAR_SYSTEMINFO | CVAR_ROM);
	Cvar_Get("sv_referencedPaks", "", CVAR_SYSTEMINFO | CVAR_ROM);
	Cvar_Get("sv_referencedPakNames", "", CVAR_SYSTEMINFO | CVAR_ROM);

#ifdef FEATURE_ANTICHEAT
	// note:
	// we might add CVAR_LATCH flag to wh_active saving SV_InitWallhack() call when not needed
	// but it may be helpfully (see sound issue) when wh_active isn't active all the time - we should give that a try
	// just enable sv_wh_active by random intervals ... (would also save CPU usage too)

	sv_wh_active = Cvar_Get("sv_wh_active", "0", CVAR_ARCHIVE);
	// FIXME: adjust bounding box ?
	sv_wh_bbox_horz = Cvar_Get("sv_wh_bbox_horz", "50", CVAR_ARCHIVE);

	if (sv_wh_bbox_horz->integer < 10)
	{
		Cvar_Set("sv_wh_bbox_horz", "10");
	}
	if (sv_wh_bbox_horz->integer > 50)
	{
		Cvar_Set("sv_wh_bbox_horz", "50");
	}

	sv_wh_bbox_vert = Cvar_Get("sv_wh_bbox_vert", "60", CVAR_ARCHIVE);

	if (sv_wh_bbox_vert->integer < 10)
	{
		Cvar_Set("sv_wh_bbox_vert", "30");
	}
	if (sv_wh_bbox_vert->integer > 50)
	{
		Cvar_Set("sv_wh_bbox_vert", "80");
	}


	sv_wh_check_fov = Cvar_Get("wh_check_fov", "0", CVAR_ARCHIVE);
	SV_InitWallhack();
#endif

	// server vars
	sv_rconPassword    = Cvar_Get("rconPassword", "", CVAR_TEMP);
	sv_privatePassword = Cvar_Get("sv_privatePassword", "", CVAR_TEMP);
	sv_fps             = Cvar_Get("sv_fps", "20", CVAR_TEMP);
	sv_timeout         = Cvar_Get("sv_timeout", "40", CVAR_TEMP); // used in game (also vid_restart)
	sv_dl_timeout      = Cvar_Get("sv_dl_timeout", "240", CVAR_TEMP);
	sv_zombietime      = Cvar_Get("sv_zombietime", "2", CVAR_TEMP);
	Cvar_Get("nextmap", "", CVAR_TEMP);

	sv_allowDownload = Cvar_Get("sv_allowDownload", "1", CVAR_ARCHIVE);

	// master servers
	sv_master[0] = Cvar_Get("sv_master1", MASTER_SERVER_NAME, 0);
	for (index = 1; index < MAX_MASTER_SERVERS; index++)
	{
		sv_master[index] = Cvar_Get(va("sv_master%d", index + 1), "", CVAR_ARCHIVE);
	}

	sv_reconnectlimit = Cvar_Get("sv_reconnectlimit", "3", 0);
	sv_tempbanmessage = Cvar_Get("sv_tempbanmessage", "You have been kicked and are temporarily banned from joining this server.", 0);

	sv_padPackets  = Cvar_Get("sv_padPackets", "0", 0);
	sv_killserver  = Cvar_Get("sv_killserver", "0", 0);
	sv_mapChecksum = Cvar_Get("sv_mapChecksum", "", CVAR_ROM);

	sv_lanForceRate = Cvar_Get("sv_lanForceRate", "1", CVAR_ARCHIVE);

	sv_onlyVisibleClients = Cvar_Get("sv_onlyVisibleClients", "0", 0);

	sv_showAverageBPS = Cvar_Get("sv_showAverageBPS", "0", 0); // net debugging

	// create user set cvars
	Cvar_Get("g_userTimeLimit", "0", 0);
	Cvar_Get("g_userAlliedRespawnTime", "0", 0);
	Cvar_Get("g_userAxisRespawnTime", "0", 0);
	Cvar_Get("g_maxlives", "0", 0);
	Cvar_Get("g_altStopwatchMode", "0", CVAR_ARCHIVE);
	Cvar_Get("g_minGameClients", "8", CVAR_SERVERINFO);
	Cvar_Get("g_complaintlimit", "6", CVAR_ARCHIVE);
	Cvar_Get("gamestate", "-1", CVAR_WOLFINFO | CVAR_ROM);
	Cvar_Get("g_currentRound", "0", CVAR_WOLFINFO);
	Cvar_Get("g_nextTimeLimit", "0", CVAR_WOLFINFO);

	Cvar_Get("g_fastres", "0", CVAR_ARCHIVE);
	Cvar_Get("g_fastResMsec", "1000", CVAR_ARCHIVE);

	Cvar_Get("g_voteFlags", "0", CVAR_ROM | CVAR_SERVERINFO);

	Cvar_Get("g_antilag", "1", CVAR_ARCHIVE | CVAR_SERVERINFO);

	Cvar_Get("g_needpass", "0", CVAR_SERVERINFO);

	g_gameType = Cvar_Get("g_gametype", "4", CVAR_SERVERINFO | CVAR_LATCH);

	// the download netcode tops at 18/20 kb/s, no need to make you think you can go above
	sv_dl_maxRate = Cvar_Get("sv_dl_maxRate", "42000", CVAR_ARCHIVE);

	sv_wwwDownload       = Cvar_Get("sv_wwwDownload", "0", CVAR_ARCHIVE);
	sv_wwwBaseURL        = Cvar_Get("sv_wwwBaseURL", "", CVAR_ARCHIVE);
	sv_wwwDlDisconnected = Cvar_Get("sv_wwwDlDisconnected", "0", CVAR_ARCHIVE);
	sv_wwwFallbackURL    = Cvar_Get("sv_wwwFallbackURL", "", CVAR_ARCHIVE);

	sv_packetdelay = Cvar_Get("sv_packetdelay", "0", CVAR_CHEAT);

	// note: redirecting of clients to other servers relies on this,
	// ET://someserver.com
	sv_fullmsg = Cvar_Get("sv_fullmsg", "Server is full.", CVAR_ARCHIVE);

	sv_advert = Cvar_Get("sv_advert", "1", CVAR_ARCHIVE);

	sv_protect    = Cvar_Get("sv_protect", "1", CVAR_ARCHIVE);
	sv_protectLog = Cvar_Get("sv_protectLog", "", CVAR_ARCHIVE);
	SV_InitAttackLog();

	// init the botlib here because we need the pre-compiler in the UI
	SV_BotInitBotLib();

	svs.serverLoad = -1;

#ifdef FEATURE_TRACKBASE
	TB_Init();
#endif
}
Example #7
0
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{			
	SystemInit();
	
	/*速度反馈初始化*/	
	ENC_Init( );
	
	/*电流反馈初始化*/
	SVPWM_3ShuntInit();
	
	/*时基初始化,并启动TIM6计算速度,初始化PID*/
	TB_Init( );
	Tim6_Init( );
	PID_Init(&PID_Torque_InitStructure, &PID_Flux_InitStructure, &PID_Speed_InitStructure);	
	
	/*温度,电压数组初始化*/
	MCL_Init_Arrays();  

	/*交互界面初始化*/		
	KEYS_Init( );
	LCD_Display_init();
	/*-------------------*/
	Res_f=1; //上电完成

	//串口示波器初始化
	usart_init(115200);
	while(1)
	{ 
		
		/*UI显示,以及电源报警,用户管理*/
		Display_LCD( );
		MCL_ChkPowerStage( );    
		KEYS_process( );

		/*状态机开启运行*/
		switch (State)
		{
			case IDLE:    //通过sel按键进入INIT ,在WAIT和FAULT中进入IDEL
			break;

			case INIT:
				MCL_Init( );//初始化电机控制层
				TB_Set_StartUp_Timeout(3000);
				State = START; 
			break;

			case START:  
				//passage to state RUN is performed by startup functions; 
			break;

			case RUN:  //电机运行过程中,检测速度反馈是否存在问题      
				if(ENC_ErrorOnFeedback() == TRUE)
				{
					MCL_SetFault(SPEED_FEEDBACK);
				}

			break;  

			case STOP:  //关闭TIM1的输出,状态转为等待,停止电流检测,设置Valpha和Vbeta为0,计算三相占空比 
				TIM_CtrlPWMOutputs(TIM1, DISABLE);
				State = WAIT;								        
				SVPWM_3ShuntAdvCurrentReading(DISABLE);											
				Stat_Volt_alfa_beta.qV_Component1 = Stat_Volt_alfa_beta.qV_Component2 = 0;
				SVPWM_3ShuntCalcDutyCycles(Stat_Volt_alfa_beta);
				TB_Set_Delay_500us(2000); // 1 sec delay		
			break;

			case WAIT:    // 等待速度为零时,将状态转为IDEL
				if (TB_Delay_IsElapsed( ) == TRUE) 
				{
					if(ENC_Get_Mechanical_Speed( ) ==0)             
					{              
						State = IDLE;              
					}
				}
			break;

			case FAULT: //状态变为IDEL,全局变量设为第一次启动                  
				if (MCL_ClearFault( ) == TRUE)
				{
					if(wGlobal_Flags & SPEED_CONTROL == SPEED_CONTROL)
					{
						//速度控制模式
						bMenu_index = CONTROL_MODE_MENU_1;
					}
					else
					{
						//力矩控制模式
						bMenu_index = CONTROL_MODE_MENU_6;
					} 					
					State = IDLE;
					wGlobal_Flags |= FIRST_START;
					Hall_Start_flag=0;
				}
			break;

			default:        
			break;
		}	
		usart_watcher(Speed_Iq_Id_watch);
		/********End of Usart_watch**************/
	}
}