示例#1
1
文件: rockchip.c 项目: thehobn/ec
/**
 * Check for some event triggering the shutdown.
 *
 * It can be either a long power button press or a shutdown triggered from the
 * AP and detected by reading POWER_GOOD.
 *
 * @return non-zero if a shutdown should happen, 0 if not
 */
static int check_for_power_off_event(void)
{
	timestamp_t now;
	int pressed = 0;
	int ret = 0;

	/*
	 * Check for power button press.
	 */
	if (power_button_is_pressed()) {
		pressed = 1;
	} else if (power_request == POWER_REQ_OFF) {
		power_request = POWER_REQ_NONE;
		return 4;  /* return non-zero for shudown down */
	}

#ifdef HAS_TASK_KEYSCAN
	/* Dis/Enable keyboard scanning when the power button state changes */
	if (!pressed || pressed != power_button_was_pressed)
		keyboard_scan_enable(!pressed, KB_SCAN_DISABLE_POWER_BUTTON);
#endif

	now = get_time();
	if (pressed) {
		if (!power_button_was_pressed) {
			power_off_deadline.val = now.val + DELAY_FORCE_SHUTDOWN;
			CPRINTS("power waiting for long press %u",
				power_off_deadline.le.lo);
			/* Ensure we will wake up to check the power key */
			timer_arm(power_off_deadline, TASK_ID_CHIPSET);
		} else if (timestamp_expired(power_off_deadline, &now)) {
			power_off_deadline.val = 0;
			CPRINTS("power off after long press now=%u, %u",
				now.le.lo, power_off_deadline.le.lo);
			return 2;
		}
	} else if (power_button_was_pressed) {
		CPRINTS("power off cancel");
		timer_cancel(TASK_ID_CHIPSET);
	}

	/* POWER_GOOD released by AP : shutdown immediately */
	if (!power_has_signals(IN_POWER_GOOD)) {
		if (power_button_was_pressed)
			timer_cancel(TASK_ID_CHIPSET);
		ret = 3;
	}

	power_button_was_pressed = pressed;

	return ret;
}
示例#2
0
/**
 * kvm_timer_sync_hwstate - sync timer state from cpu
 * @vcpu: The vcpu pointer
 *
 * Check if the virtual timer was armed and either schedule a corresponding
 * soft timer or inject directly if already expired.
 */
void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu)
{
	struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
	cycle_t cval, now;
	u64 ns;

	if ((timer->cntv_ctl & ARCH_TIMER_CTRL_IT_MASK) ||
		!(timer->cntv_ctl & ARCH_TIMER_CTRL_ENABLE))
		return;

	cval = timer->cntv_cval;
	now = kvm_phys_timer_read() - vcpu->kvm->arch.timer.cntvoff;

	BUG_ON(timer_is_armed(timer));

	if (cval <= now) {
		/*
		 * Timer has already expired while we were not
		 * looking. Inject the interrupt and carry on.
		 */
		kvm_timer_inject_irq(vcpu);
		return;
	}

	ns = cyclecounter_cyc2ns(timecounter->cc, cval - now);
	timer_arm(timer, ns);
}
示例#3
0
/*
 * Schedule the background timer before calling kvm_vcpu_block, so that this
 * thread is removed from its waitqueue and made runnable when there's a timer
 * interrupt to handle.
 */
void kvm_timer_schedule(struct kvm_vcpu *vcpu)
{
	struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
	u64 ns;
	cycle_t cval, now;

	BUG_ON(timer_is_armed(timer));

	/*
	 * No need to schedule a background timer if the guest timer has
	 * already expired, because kvm_vcpu_block will return before putting
	 * the thread to sleep.
	 */
	if (kvm_timer_should_fire(vcpu))
		return;

	/*
	 * If the timer is not capable of raising interrupts (disabled or
	 * masked), then there's no more work for us to do.
	 */
	if (!kvm_timer_irq_can_fire(vcpu))
		return;

	/*  The timer has not yet expired, schedule a background timer */
	cval = timer->cntv_cval;
	now = kvm_phys_timer_read() - vcpu->kvm->arch.timer.cntvoff;

	ns = cyclecounter_cyc2ns(timecounter->cc,
				 cval - now,
				 timecounter->mask,
				 &timecounter->frac);
	timer_arm(timer, ns);
}
示例#4
0
/******************************************************
 * FunctionName : user_application
 * Description  : 用户APP程序段
 * Parameters   : none
 * Returns      : none
******************************************************/
void user_application()
{
	timer0_t timer_led;
	timer_disarm(&timer_led);
	timer_setfn(&timer_led,(sysTimer0Func)uart_fn,1);
	timer_arm(&timer_led,1000,Timer_Status_repeat);
	while(true)
	{
	}
}
示例#5
0
/*-------------------------------------------------------------------------

	Reset all internal register and variables to a known state.

---------------------------------------------------------------------------*/
void neogeo_cold_reset ( void )
{
	neogeo_show_debugger = 0;

	if ( neogeo_debugger_enabled )
		neogeo_set_runmode ( NEOGEO_RUN_TRACE );
	else
		neogeo_set_runmode ( NEOGEO_RUN_NORMAL );

	if ( neogeo_audio_track )
	{
		Mix_FreeMusic ( neogeo_audio_track );
		neogeo_audio_track = NULL;
	}

	/* Reset the elapsed time */
	neogeo_elapsed_time = ( double ) 0;

	/* Wipe clean all RAM */
	SDL_memset ( neogeo_RAM, 0, sizeof ( neogeo_RAM ) );
	SDL_memset ( neogeo_palette_RAM, 0, sizeof ( neogeo_palette_RAM ) );
	SDL_memset ( neogeo_video_RAM, 0, sizeof ( neogeo_video_RAM ) );
	SDL_memset ( neogeo_SPR_RAM, 0, sizeof ( neogeo_SPR_RAM ) );
	SDL_memset ( neogeo_FIX_RAM, 0, sizeof ( neogeo_FIX_RAM ) );
	SDL_memset ( neogeo_z80_RAM, 0, sizeof ( neogeo_z80_RAM ) );
	SDL_memset ( neogeo_PCM_RAM, 0, sizeof ( neogeo_PCM_RAM ) );

	/* Set fix usage map to all transparent */
	SDL_memset ( neogeo_FIX_usage, 0, sizeof( neogeo_FIX_usage ) );

	/* CD Unit stuff init */
	SDL_memset ( &neogeo_memory_latch[0], 0, sizeof ( neogeo_memory_latch ) );
	neogeo_memory_latch_counter = 0;
	neogeo_spr_bank_select = 0;
	neogeo_pcm_bank_select = 0;
	neogeo_video_enable = 1;
	neogeo_spr_disable = 0;
	neogeo_fix_disable = 0;

	/* Video Hardware init */
	neogeo_palette_bank = 0;
	neogeo_videoram_offset = 0;
	neogeo_videoram_modulo = 0;
	neogeo_videoram_data = 0;
	neogeo_auto_animation_speed = 0;
	neogeo_auto_animation_disabled = 0;
	neogeo_auto_animation_counter = 0;
	neogeo_auto_animation_frame_counter = 0;
	neogeo_HIRQ_control = 0;
	neogeo_HIRQ_register = 0;
	neogeo_screen_position = 0;

	/* Clear all pending interrupts */
	neogeo_HIRQ_pending = 0;
	neogeo_VBL_irq_pending = 0;
	neogeo_cdrom_irq1_pending = 0;
	neogeo_cdrom_irq2_pending = 0;
	neogeo_cdrom_irq_mask = 0;

	/* Controllers */
	neogeo_joystick_select = 0;
	neogeo_controller1 = 0xFF;
	neogeo_controller2 = 0xFF;
	neogeo_controller3 = 0x0F;

	/* DMA */
	SDL_memset ( &neogeo_dma_config[0], 0, sizeof ( Uint16 ) * 9 );
	neogeo_dma_source = 0;
	neogeo_dma_destination = 0;
	neogeo_dma_pattern = 0;
	neogeo_dma_length = 0;

	/* CDROM */
	neogeo_cdrom_response_pointer = 9;
	neogeo_cdrom_command_pointer = 0;
	neogeo_cdrom_data_strobe = 0;
	SDL_memset ( &neogeo_cdrom_response[0], 0, sizeof ( Uint8 ) * 5 );
	SDL_memset ( &neogeo_cdrom_command[0], 0, sizeof ( Uint8 ) * 5 );
	neogeo_cdrom_register_select = 0;
	neogeo_cdrom_register_pointer = 0;
	neogeo_cdrom_stop();

	/* ROM Vectors enabled at boot time*/
	memory_regions[MEMORY_VECTORS_INDEX].Handlers = &neogeo_ROM_handlers;

	/* Double Dragon Fix */
	if ( Fix_DoubleDragon )
		m68k_memcpy ( 0xC00000, 0x110004, 0x800 );

	/* Initialize all timers */
	timer_arm ( &neogeo_watchdog_timer, M68K_TO_REF ( WATCHDOG_TIMER_DELAY ) );
	timer_arm ( &neogeo_drawline_timer, PIXEL_TO_REF ( NEOGEO_HS_START ) );
	timer_arm ( &neogeo_screen_timer, PIXEL_TO_REF ( NEOGEO_SCREEN_WIDTH * NEOGEO_SCREEN_HEIGHT ) );
	timer_arm ( &neogeo_VBL_timer, PIXEL_TO_REF ( NEOGEO_SCREEN_WIDTH * NEOGEO_VBLANK_LINE ) );
	timer_arm ( &neogeo_cdrom_irq1_timer, NEOGEO_CDROM_DELAY );
	timer_arm ( &neogeo_cdrom_irq2_timer, PIXEL_TO_REF ( NEOGEO_SCREEN_WIDTH * NEOGEO_CDROM_IRQ2_LINE ) );
	timer_set_state ( &neogeo_HIRQ_timer, TIMER_STOPPED );
	timer_set_state ( &neogeo_audio_command_timer, TIMER_STOPPED );
	timer_set_state ( &neogeo_ym2610_timer_a, TIMER_STOPPED );
	timer_set_state ( &neogeo_ym2610_timer_b, TIMER_STOPPED );

	/* Reset the 68000 */
	m68k_pulse_reset();

	/* Disable the z80 */
	neogeo_z80_disable = 1;
	neogeo_z80_time_to_execute = 0;
	neogeo_audio_command = 0;
	neogeo_audio_result = 0;
	neogeo_z80_time_this_vbl = 0;

	/* Reset the YM2610 */
	YM2610Reset();

	/* Speed limiter init */
	neogeo_speed_limiter_setup();

	/* Audio init */
	neogeo_audio_setup();
}