Exemplo n.º 1
0
// This function is used to shutdown everything exept USB
// When this function return all the peripheral should be :
// 	- Disabled
// 	- In minimal power consuption mode
void switch_off(void) { 
	behavior_stop(B_ALL);
	
	timer_disable(TIMER_1KHZ);
	timer_disable_interrupt(TIMER_1KHZ);
	
	_LVDIE = 0;

    // Why waiting on valid vbat ?
    //   => We use an aseba variable, the user may corrupt it
    wait_valid_vbat(); // ir autocalibration is using it.

	analog_disable();
	pwm_motor_poweroff();
	prox_poweroff();
	save_settings();
	sound_poweroff();
	sd_shutdown();
	leds_poweroff();
	mma7660_suspend();
	rf_poweroff();
	
	I2C3CONbits.I2CEN = 0; // Disable i2c.
	_MI2C3IE = 0;
	
	
	ntc_shutdown();
	rc5_shutdown();

	CHARGE_500MA = 0; 
	// TODO: Force VA ?! Check me that refcount is correct
}
Exemplo n.º 2
0
void power_off(AsebaVMState *vm) {
        unsigned int flags;

    // Protect against two racing poweroff:
    //  One from the softirq (button)
    //  One from the VM
    RAISE_IPL(flags,1);

	behavior_stop(B_ALL);
	
 	play_sound_block(SOUND_POWEROFF);
	
	// Shutdown all peripherals ...
	switch_off();
	
	// Switch off USB
	// If we are connected to a PC, disconnect.
	// If we are NOT connected to a PC but 5V is present
	// ( == charger ) we need to keep the transciever on
	if(usb_uart_configured())
		USBDeviceDetach();
		
	// In any case, disable the usb interrupt. It's safer
	_USB1IE = 0;
	
	
	CHARGE_ENABLE_DIR = 1;
	
	analog_enter_poweroff_mode();
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: texane/dibal
static int behavior_switch(unsigned char id)
{
  /* if the current behavior is done, dont
     take into the account the priority and
     dont stop it.
   */

  if (!behavior_is_done())
    {
      if (prio_by_id(id) < prio_by_id(current_behavior.id))
	return -1;

      behavior_stop();
    }

  /* start the new one */

  behavior_start(id);

  return 0;
}