예제 #1
0
파일: main.c 프로젝트: ClockSelect/myevic
//=========================================================================
// Additional initialisations
//-------------------------------------------------------------------------
__myevic__ void CustomStartup()
{

//-------------------------------------------------------------------------
// EADC test

	if ( 0 )
	{
		uint32_t s1, s2, s3;

		SetADCState( 0, 1 );
		SetADCState( 4, 1 );

		do
		{
			ClearScreenBuffer();

			CLK_SysTickDelay( 10 );
			s3 = ADC_Read( 4 );

			CLK_SysTickDelay( 10 );
			s1 = ADC_Read( 18 );

			CLK_SysTickDelay( 10 );
			s2 = ADC_Read( 0 );

			DrawValue( 8,  0, s1, 0, 0x29, 4 );
			DrawValue( 8, 20, s2, 0, 0x29, 4 );
			DrawValue( 8, 40, s3, 0, 0x29, 4 );

			DisplayRefresh();

			WaitOnTMR2( 1000 );
		}
		while ( PD3 );
	}


//-------------------------------------------------------------------------
// Timer test 1

	if ( 0 )
	{
		TIMER_Stop( TIMER3 );
		TIMER_Close( TIMER3 );

		MemClear( gPlayfield.uc, 256 );

		CLK_SetModuleClock( TMR3_MODULE, CLK_CLKSEL1_TMR3SEL_LIRC, 0 );

		gPlayfield.ul[1] =
		TIMER_Open( TIMER3, TIMER_PERIODIC_MODE, 10 );
		TIMER_EnableInt( TIMER3 );
		TIMER_Start( TIMER3 );
	}


//-------------------------------------------------------------------------
// Timer test 2

	if ( 0 )
	{
		TIMER_Close( TIMER2 );
		TIMER_Close( TIMER3 );

		MemClear( gPlayfield.uc, 256 );

		CLK_SetModuleClock( TMR2_MODULE, CLK_CLKSEL1_TMR2SEL_HXT, 0 );
		CLK_SetModuleClock( TMR3_MODULE, CLK_CLKSEL1_TMR3SEL_LIRC, 0 );

		CLK_EnableModuleClock( TMR2_MODULE );
		CLK_EnableModuleClock( TMR3_MODULE );

		__set_PRIMASK(1);

		TIMER3->CTL |= TIMER_CTL_RSTCNT_Msk;
		TIMER2->CTL |= TIMER_CTL_RSTCNT_Msk;

		TIMER3->CMP  = 1000;

		TIMER3->CTL  = TIMER_CTL_CNTEN_Msk | TIMER_ONESHOT_MODE;
		TIMER2->CTL  = TIMER_CTL_CNTEN_Msk | TIMER_CONTINUOUS_MODE;
		while(!(TIMER3->INTSTS & TIMER_INTSTS_TIF_Msk));
		TIMER2->CTL = 0;

		gPlayfield.ul[0] = TIMER2->CNT;

		__set_PRIMASK(0);

		TIMER_Close( TIMER2 );
		TIMER_Close( TIMER3 );

		CLK_SetModuleClock( TMR2_MODULE, CLK_CLKSEL1_TMR2SEL_HIRC, 0 );
		CLK_EnableModuleClock( TMR2_MODULE );
		TIMER_Open( TIMER2, TIMER_PERIODIC_MODE, 1000 );
		TIMER_EnableInt( TIMER2 );
		TIMER_Start( TIMER2 );

		CLK_SetModuleClock( TMR3_MODULE, CLK_CLKSEL1_TMR3SEL_HXT, 0 );
		CLK_EnableModuleClock( TMR3_MODULE );
		TIMER_Open( TIMER3, TIMER_PERIODIC_MODE, 10 );
		TIMER_EnableInt( TIMER3 );
		TIMER_Start( TIMER3 );
	}

	return;
}
예제 #2
0
파일: main.c 프로젝트: ClockSelect/myevic
//=========================================================================
//----- (00005D24) --------------------------------------------------------
__myevic__ void DevicesOnOff( int off )
{
	if ( off )
	{
		TIMER_DisableInt( TIMER0 );
		TIMER_DisableInt( TIMER1 );
		TIMER_DisableInt( TIMER2 );

		if ( !gFlags.light_sleep )
		{
			TIMER_DisableInt( TIMER3 );
		}

		EADC_Close( EADC );
		SetADCState( 1, 0 );
		SetADCState( 2, 0 );
		SetADCState( 14, 0 );

		if ( ISVTCDUAL || ISCUBOID || ISCUBO200 || ISRX200S || ISRX23 || ISRX300 )
		{
			SetADCState( 3, 0 );
			SetADCState( 13, 0 );

			if ( ISCUBO200 || ISRX200S || ISRX23 || ISRX300 )
			{
				SetADCState( 15, 0 );
			}

			PD7 = 0;
			BBC_Configure( BBC_PWMCH_CHARGER, 0 );
			PD7 = 0;

			if ( ISCUBOID || ISCUBO200 || ISRX200S || ISRX23 )
			{
				PF2 = 0;
			}
		}

		PC1 = 0;
		PC0 = 0;
		BBC_Configure( BBC_PWMCH_BUCK, 0 );
		if ( !ISVTCDUAL ) PC3 = 0;
		PC2 = 0;
		BBC_Configure( BBC_PWMCH_BOOST, 0 );

		if ( ISCUBO200 || ISRX200S || ISRX23 )
		{
			PF1 = 0;
		}
		else if ( ISRX300 )
		{
			PD1 = 0;
		}
		else
		{
			PB7 = 0;
		}

		GPIO_DisableInt( PD, 0 );
		PD0 = 0;
		GPIO_SetMode( PD, GPIO_PIN_PIN0_Msk, GPIO_MODE_OUTPUT );

		if ( ISRX300 )
		{
			PF5 = 0;
			PF6 = 0;
			PA3 = 0;
			PA2 = 0;
		}

		if ( ISVTCDUAL )
		{
			GPIO_DisableInt( PD, 1 );
			PD1 = 0;
			GPIO_SetMode( PD, GPIO_PIN_PIN1_Msk, GPIO_MODE_OUTPUT );
		}
		else if ( !ISCUBOID && !ISCUBO200 && !ISRX200S && !ISRX23 && !ISRX300 )
		{
			GPIO_DisableInt( PD, 7 );
			PD7 = 0;
			GPIO_SetMode( PD, GPIO_PIN_PIN7_Msk, GPIO_MODE_OUTPUT );
		}

		SYS->GPE_MFPH &= ~(SYS_GPE_MFPH_PE11MFP_Msk|SYS_GPE_MFPH_PE12MFP_Msk|SYS_GPE_MFPH_PE13MFP_Msk);
		SYS->GPE_MFPH |= (SYS_GPE_MFPH_PE11MFP_GPIO|SYS_GPE_MFPH_PE12MFP_GPIO|SYS_GPE_MFPH_PE13MFP_GPIO);
		PE11 = 0;
		GPIO_SetMode( PE, GPIO_PIN_PIN11_Msk, GPIO_MODE_OUTPUT );
		PE12 = 0;
		GPIO_SetMode( PE, GPIO_PIN_PIN12_Msk, GPIO_MODE_OUTPUT );
		PE13 = 0;
		GPIO_SetMode( PE, GPIO_PIN_PIN13_Msk, GPIO_MODE_OUTPUT );
		PE10 = 0;

		GPIO_EnableInt( PE, 0, GPIO_INT_BOTH_EDGE );
		GPIO_EnableInt( PD, 2, GPIO_INT_BOTH_EDGE );
		GPIO_EnableInt( PD, 3, GPIO_INT_BOTH_EDGE );

		if ( ISVTCDUAL )
		{
			PA3 = 0;
			PC3 = 0;
			PF2 = 0;
			PA2 = 0;
		}
		else if ( ISCUBOID || ISCUBO200 || ISRX200S || ISRX23 || ISRX300 )
		{
			PF0 = 0;
		}

		SYS_UnlockReg();
		SYS->USBPHY &= ~SYS_USBPHY_LDO33EN_Msk;
		SYS->IVSCTL &= ~(SYS_IVSCTL_VBATUGEN_Msk|SYS_IVSCTL_VTEMPEN_Msk);
		SYS_DisableBOD();
		SYS->VREFCTL = 0;
		SYS_LockReg();

		USBD_CLR_INT_FLAG( USBD_INTSTS_WAKEUP|USBD_INTSTS_FLDET|USBD_INTSTS_BUS|USBD_INTSTS_USB );
		USBD_ENABLE_INT( USBD_INT_WAKEUP );
	}
	else
	{
		USBD_CLR_INT_FLAG( USBD_INTSTS_WAKEUP );

		SYS_UnlockReg();
		SYS->USBPHY |= SYS_USBPHY_LDO33EN_Msk;
		SYS->IVSCTL |= SYS_IVSCTL_VBATUGEN_Msk;
		if ( ISRX300 )
		{
			SYS->IVSCTL |= SYS_IVSCTL_VTEMPEN_Msk;
		}
		SYS->VREFCTL = SYS_VREFCTL_VREF_2_56V;
		SYS_EnableBOD( SYS_BODCTL_BOD_RST_EN, SYS_BODCTL_BODVL_2_2V );
		SYS_LockReg();

		GPIO_DisableInt( PE, 0 );
		GPIO_DisableInt( PD, 2 );
		GPIO_DisableInt( PD, 3 );

		if ( ISCUBOID || ISCUBO200 || ISRX200S || ISRX23 )
		{
			PF2 = 1;
		}

		SYS->GPE_MFPH &= ~(SYS_GPE_MFPH_PE11MFP_Msk|SYS_GPE_MFPH_PE12MFP_Msk|SYS_GPE_MFPH_PE13MFP_Msk);
		SYS->GPE_MFPH |= (SYS_GPE_MFPH_PE11MFP_SPI0_MOSI0|SYS_GPE_MFPH_PE12MFP_SPI0_SS|SYS_GPE_MFPH_PE13MFP_SPI0_CLK);

		GPIO_SetMode( PD, GPIO_PIN_PIN0_Msk, GPIO_MODE_INPUT );
		GPIO_EnableInt( PD, 0, GPIO_INT_FALLING );

		if ( ISVTCDUAL )
		{
			GPIO_SetMode( PD, GPIO_PIN_PIN1_Msk, GPIO_MODE_INPUT );
			GPIO_EnableInt( PD, 1, GPIO_INT_RISING );
			GPIO_ENABLE_DEBOUNCE( PD, GPIO_PIN_PIN1_Msk );
		}
		else if ( !ISCUBOID && !ISCUBO200 && !ISRX200S && !ISRX23 && !ISRX300 )
		{
			GPIO_SetMode( PD, GPIO_PIN_PIN7_Msk, GPIO_MODE_INPUT );
			GPIO_EnableInt( PD, 7, GPIO_INT_RISING );
			GPIO_ENABLE_DEBOUNCE( PD, GPIO_PIN_PIN7_Msk );
		}

		if ( ISCUBO200 || ISRX200S || ISRX23 )
		{
			PF1 = 1;
		}
		else if ( ISRX300 )
		{
			PD1 = 1;
		}
		else
		{
			PB7 = 1;
		}

		SetADCState( 1, 1 );
		SetADCState( 2, 1 );
		SetADCState( 14, 1 );

		if ( ISVTCDUAL || ISCUBOID || ISCUBO200 || ISRX200S || ISRX23 || ISRX300 )
		{
			SetADCState( 3, 1 );
			SetADCState( 13, 1 );

			if ( ISCUBO200 || ISRX200S || ISRX23 || ISRX300 )
			{
				SetADCState( 15, 1 );
			}
		}

		TIMER_EnableInt( TIMER0 );
		TIMER_EnableInt( TIMER1 );
		TIMER_EnableInt( TIMER2 );
		TIMER_EnableInt( TIMER3 );
	}
}
예제 #3
0
//=========================================================================
//----- (0000344C) --------------------------------------------------------
__myevic__ void StopFire()
{

//	register const uint32_t lr __asm__("lr");
//	uint32_t caller;

//	caller = lr;

	if ( ISVTCDUAL )
	{
		GPIO_SetMode( PD, GPIO_PIN_PIN1_Msk, GPIO_MODE_INPUT );
	}
	else if ( !ISCUBOID && !ISCUBO200 && !ISRX200S && !ISRX23 && !ISRX300 )
	{
		GPIO_SetMode( PD, GPIO_PIN_PIN7_Msk, GPIO_MODE_INPUT );
	}

	PC1 = 0;
	if ( !ISVTCDUAL ) PC3 = 0;

	BuckDuty = 0;
	PC0 = 0;
	BBC_Configure( BBC_PWMCH_BUCK, 0 );

	BoostDuty = 0;
	PC2 = 0;
	BBC_Configure( BBC_PWMCH_BOOST, 0 );

	SetADCState( 1, 0 );
	SetADCState( 2, 0 );
	if ( ISCUBO200 || ISRX200S || ISRX23 || ISRX300 )
	{
		SetADCState( 15, 0 );
	}

	if ( ISEGRIPII || ISEVICAIO )
	{
		LEDTimer = 30;
	}

	if ( gFlags.firing )
	{
		gFlags.firing = 0;

		if ( FireDuration > 5 )
		{
			dfTimeCount += FireDuration;
			if ( dfTimeCount > 999999 ) dfTimeCount = 0;
			if ( ++dfPuffCount > 99999 ) dfPuffCount = 0;
			UpdatePTTimer = 80;
		}

		RTCWriteRegister( RTCSPARE_VV_MJOULES, MilliJoules );

		if (( FireDuration * 10 >= dfPreheatTime )
		||  ( dfStatus.pcurve && FireDuration > 10 ))
		{
			PreheatDelay = dfPHDelay * 100;
		}
	}

//	myprintf( "StopFire from 0x%08x\n", caller );

	AutoPuffTimer = 0;
	PreheatTimer = 0;

	LowBatVolts = 0;
	BatReadTimer = 200;
}