示例#1
0
/****************************************************************************
NAME    
    powerManagerHandleVbat
    
DESCRIPTION
    Called when the battery voltage is detected to be in a Normal state
*/
static void powerManagerHandleVbat(voltage_reading vbat, battery_level_source source)
{
    /* Get the event associated with this battery level */
    sink_battery_setting setting = theSink.conf1->power.bat_events[vbat.level];
    sinkEvents_t event = setting.event;

    PM_DEBUG(("PM: Battery Voltage 0x%02X (%dmV)\n", vbat.level, vbat.voltage));

    displayUpdateBatteryLevel(powerManagerIsChargerConnected());
    
    /* Send indication if not charging, not in limbo state and indication enabled for this source */
    if(!powerManagerIsChargerConnected() && (stateManagerGetState() != deviceLimbo) && (setting.sources & source))
    {
        PM_DEBUG(("PM: Sending Event 0x%X\n", event));
        MessageSend(&theSink.task, event, NULL);
    }
    
    switch(event)
    {
        case EventSysBatteryCritical:
            /* Always indicate critical battery */
            powerManagerHandleVbatCritical();
            usbSetVbatDead(TRUE);
            break;

        case EventSysBatteryLow:
            powerManagerHandleVbatLow();
            usbSetVbatDead(FALSE);
            break;

        case EventSysGasGauge0 :
        case EventSysGasGauge1 :
        case EventSysGasGauge2 :
        case EventSysGasGauge3 :
            powerManagerHandleVbatNormal(event - EventSysGasGauge0);
            usbSetVbatDead(FALSE);
            break;

        default:
            break;
    }
}
示例#2
0
文件: sink_usb.c 项目: NemProjects/BC
/****************************************************************************
NAME 
    usbTimeCriticalInit
    
DESCRIPTION
    Initialise USB. This function is time critical and must be called from
    _init. This will fail if either Host Interface is not set to USB or
    VM control of USB is FALSE in PS. It may also fail if Transport in the
    project properties is not set to USB VM.
    
RETURNS
    void
*/ 
void usbTimeCriticalInit(void)
{
#ifdef ENABLE_USB_AUDIO
    const usb_plugin_info* plugin;
#endif
    usb_device_class_status status;
    usb_file_info root;
    usb_file_info file;
    usb_file_name_info file_name;

    USB_DEBUG(("USB: Time Critical\n"));

    /* Default to not configured or suspended */
    theSink.usb.ready = FALSE;
    theSink.usb.enumerated = FALSE;
    theSink.usb.suspended  = FALSE;
    theSink.usb.vbus_okay  = TRUE;
    theSink.usb.deconfigured = FALSE;

    /* Check if we booted with dead battery */
    usbSetVbatDead(usbDeadBatteryAtBoot());

    /* Get USB configuration */
    configManagerUsb();

    /* Abort if no device classes supported */
    if(!theSink.usb.config.device_class)
        return;

    usbFileInfo(root_name, sizeof(root_name)-1, &root);
    usbFileName(&root, &file_name);
    usbFileInfo(file_name.name, file_name.size, &file);

    /* If we can't find the help file don't enumerate mass storage */
    if(file.index == FILE_NONE || root.index == FILE_NONE) 
        USB_CLASS_DISABLE(USB_DEVICE_CLASS_TYPE_MASS_STORAGE);

#ifdef ENABLE_USB_AUDIO
    plugin = &usb_plugins[theSink.usb.config.plugin_type];
    USB_DEBUG(("USB: Audio Plugin %d\n", theSink.usb.config.plugin_index));
    UsbDeviceClassConfigure(USB_DEVICE_CLASS_CONFIG_AUDIO_INTERFACE_DESCRIPTORS, 0, 0, (const uint8*)(plugin->usb_descriptors));
#else
    /* If audio not supported don't enumerate as mic or speaker */
    USB_CLASS_DISABLE(USB_DEVICE_CLASS_AUDIO);
#endif

    USB_DEBUG(("USB: Endpoint Setup [0x%04X] - ", theSink.usb.config.device_class));
    /* Attempt to enumerate - abort if failed */
    status = UsbDeviceClassEnumerate(&theSink.task, theSink.usb.config.device_class);

    if(status != usb_device_class_status_success)
    {
        USB_DEBUG(("Error %X\n", status));
        return;
    }

    USB_DEBUG(("Success\n"));
    /* Configure mass storage device */
    if(USB_CLASS_ENABLED(USB_DEVICE_CLASS_TYPE_MASS_STORAGE))
    {
        UsbDeviceClassConfigure(USB_DEVICE_CLASS_CONFIG_MASS_STORAGE_FAT_DATA_AREA, file.index, file.size, 0);
        usbFileInfo(fat_name, sizeof(fat_name)-1, &file);
        UsbDeviceClassConfigure(USB_DEVICE_CLASS_CONFIG_MASS_STORAGE_FAT_TABLE, file.index, file.size, 0);
        UsbDeviceClassConfigure(USB_DEVICE_CLASS_CONFIG_MASS_STORAGE_FAT_ROOT_DIR, root.index, root.size, 0);
    }
}