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(); }
void rf_init(int bus) { unsigned int flags; unsigned char reg = REG_STATUS; unsigned char s; unsigned char ret; clock_delay_us(5000); // we need to wait until the chip is ready .... RAISE_IPL(flags, PRIO_COMMUNICATION); i2c_bus = bus; // Wait until the bus is idle while(i2c_master_is_busy(i2c_bus)); // Try to access the chip ret = i2c_master_transfert_block(i2c_bus, RF_ADDRESS, ®, 1, &s, 1); if(!ret) { // FIXME // Try harder ... ret = i2c_master_transfert_block(i2c_bus, RF_ADDRESS, ®, 1, &s, 1); } IRQ_ENABLE(flags); if (ret) { write(REG_CTRL, 3); // Put us in presence detect only status = RF_PRESENT | RF_LINK_UP; } else { status = 0; } }
static void read(unsigned char reg, unsigned char * b, unsigned int len) { unsigned int flags; RAISE_IPL(flags, PRIO_COMMUNICATION); while(i2c_master_is_busy(i2c_bus)); i2c_master_transfert_block(i2c_bus, RF_ADDRESS, ®, 1, b, len); IRQ_ENABLE(flags); }
static void write(unsigned char reg, unsigned char b) { unsigned char buffer[2] = {reg,b}; unsigned int flags; RAISE_IPL(flags, PRIO_COMMUNICATION); while(i2c_master_is_busy(i2c_bus)); i2c_master_transfert_block(i2c_bus, RF_ADDRESS, buffer, 2, 0, 0); IRQ_ENABLE(flags); }
void rf_poll(void) { unsigned int flags; RAISE_IPL(flags, PRIO_COMMUNICATION); if(!(status & RF_PRESENT) || !(status & RF_LINK_UP)) { // RF not present or activated if(read_acc) { read_acc = 0; mma7660_read_async(); } } else if(!i2c_master_is_busy(i2c_bus)) { // Try to read data from the device i2c_master_start_operations(i2c_bus, i2c_cb, NULL); } IRQ_ENABLE(flags); }