예제 #1
0
static int __init battery_init( void )
{
    int ret;

    printk( "\n[BM] Battery Init.\n" );

    sec_bci.ready = false;

    sec_bci.battery.battery_health = POWER_SUPPLY_HEALTH_GOOD;
    sec_bci.battery.battery_technology = POWER_SUPPLY_TECHNOLOGY_LION;
    sec_bci.battery.battery_level_ptg = 0;
    sec_bci.battery.battery_level_vol = 0;
    sec_bci.battery.monitor_duration = MONITOR_DEFAULT_DURATION;
    sec_bci.battery.monitor_field_temp = false;
    sec_bci.battery.monitor_field_rechg_vol = false;
    sec_bci.battery.confirm_full_by_current = 0;
    sec_bci.battery.support_monitor_temp = 1;
    sec_bci.battery.support_monitor_timeout = 1;
    sec_bci.battery.support_monitor_full = 1;
    sec_bci.battery.confirm_recharge = 0;

    sec_bci.charger.prev_cable_status = -1;
    sec_bci.charger.cable_status = -1;
    sec_bci.charger.prev_charge_status = 0;
    sec_bci.charger.charge_status = 0;
    sec_bci.charger.full_charge_dur_sleep = 0x0;
    sec_bci.charger.is_charging = false;
    sec_bci.charger.charge_start_time = 0;
    sec_bci.charger.charged_time = 0;
    sec_bci.charger.charging_timeout = DEFAULT_CHARGING_TIMEOUT;
    sec_bci.charger.use_ta_nconnected_irq = false;
	sec_bci.charger.rechg_count = 0;
    sec_bci.sec_battery_workq = create_singlethread_workqueue("sec_battery_workq");

    init_gptimer12();
    printk( "[BM] Init Gptimer called \n" );

    /* Get the charger driver */
    if( ( ret = charger_init() < 0 ) )
    {
        printk( "[BM] Fail to get charger driver.\n" );
        return ret;
    }

    /* Get the fuelgauge driver */
    if( ( ret = fuelgauge_init() < 0 ) )
    {
        printk( "[BM] Fail to get fuelgauge driver.\n" );        
        return ret;
    }

    wake_lock_init( &sec_bc_wakelock, WAKE_LOCK_SUSPEND, "samsung-battery" );
	
    ret = platform_driver_register( &battery_platform_driver );

    return ret;
}
예제 #2
0
int main(void)
{
    // Hardware Init
    delay_init();	    	 //ÑÓʱº¯Êý³õʼ»¯
    pwr_init();
    #ifdef YANMING3
    charger_init();
    if (check_standby_flag() == SUCCESS && check_charging() != CHARGING) {
        Key_GPIO_Config();
        exti_key_init();
        #ifdef DEBUG_POWER_OFF_WAKE_UP
        Screen_Init();
        OLED_Clear();
        OLED_Display_On();
        draw_about_mesage();
        #endif
        check_standby_wakeup_button_press();
        // If we boot up from standby by pressing 5 times, the system will reboot again without
        // this code block.
    }
    #endif

    // OLED Init
    Screen_Init();
    OLED_Clear();
    
    //
    low_switch_power_init();

    TIMx_Int_DeInit();
    EXTIX_DeInit();
    
    // Key
    Key_GPIO_Config();
    
    // PID related code
    ADC1_Configuration();
    PWM_Configuration();
    VoltagePID_Init();

    TIMx_Int_Init();
    rtc_init();

    // Our Init
    system_init();
    #ifndef YANMING3
    //iwdg_init();
    #endif

    while(1) {
        #ifndef YANMING3
        //iwdg_feed();
        #endif
        task_schedule();
    }
}
예제 #3
0
void setup()   {                

  //
  //pullup the AD   
  pinMode(A_VFB, INPUT);
  digitalWrite(A_VFB, HIGH);

  pinMode(A_IFB, INPUT);
  digitalWrite(A_IFB, HIGH);

  //pulldown pwm
  pinMode(P_PWM, OUTPUT);
  analogWrite(P_PWM,0);  
  
  
  pinMode(P_VCC5, INPUT);
  digitalWrite(P_VCC5, HIGH);
  
  //
  // charger is on
  pinMode(P_SW, OUTPUT);
  digitalWrite(P_SW, LOW);

#ifdef TINY
  //
  // setup timer to the maximum speed at 52Khz  
  OSCCAL = 0xFF;  
  Timer1_SetWaveformGenerationMode(Timer1_Fast_PWM_FF);
  Timer1_ClockSelect(Timer1_Prescale_Value_1);
#else 
  // http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM
  // Set pin 6's PWM frequency to 62500 Hz (62500/1 = 62500)
  // Note that the base frequency for pins 5 and 6 is 62500 Hz  
  // *   - Changes on pins 3, 5, 6, or 11 may cause the delay() and
  // *     millis() functions to stop working. Other timing-related
  // *   - Pins 5 and 6 are paired on timer0
  // *   - Pins 9 and 10 are paired on timer1
  // *   - Pins 3 and 11 are paired on timer2
  TCCR0B = TCCR0B & 0b11111000 | 0x01;
#endif
   
  
  charger_init(charger);

#ifdef CONFIG_WITH_PRINT
  Serial.begin(115200);
	Serial.println("Booting ");
#endif

}
예제 #4
0
int pmic_rk808_init(unsigned char bus)
{
	int ret;
	if (!rk808.pmic) {
		ret = rk808_parse_dt(gd->fdt_blob);
		if (ret < 0)
			return ret;
	}
	
	rk808.pmic->interface = PMIC_I2C;
	//enable lcdc power ldo, and enable other ldo 
	i2c_set_bus_num(rk808.pmic->bus);
	charger_init(0);
	i2c_init(RK808_I2C_SPEED, rk808.pmic->hw.i2c.addr);
	i2c_set_bus_speed(RK808_I2C_SPEED);
	i2c_reg_write(0x1b,0x23,i2c_reg_read(0x1b,0x23)|0x60);
	i2c_reg_write(0x1b,0x45,0x02);
	i2c_reg_write(0x1b,0x24,i2c_reg_read(0x1b,0x24)|0x28);

    return 0;
}
예제 #5
0
void handSensing(){

	queueHandler_init();
    charger_init(&charger);
    queueHanlder_drawTextAtCenter("Calibration...");

    //calibration
    calibrate(&charger);
    setXRange(charger.range_x);
    setYRange(charger.range_y);
    setZRange(charger.range_z);

    charger.x_state = NOT_READY;
    charger.y_state = NOT_READY;
    charger.z_state = NOT_READY;

	queueHanlder_drawTextAtCenter("System Ready...");

    while(1){

    	//recalibration interrupt
    	if(charger.y_state == READY){
    		charger.x_state = NOT_READY;
			charger.y_state = NOT_READY;
			charger.z_state = NOT_READY;
    		charger.calibration_state = BASELINE;
    		calibrate(&charger);
			setXRange(charger.range_x);
			setYRange(charger.range_y);
			setZRange(charger.range_z);

			charger.x_state = NOT_READY;
			charger.y_state = NOT_READY;
			charger.z_state = NOT_READY;
			continue;
    	}

    	//gettimeofday(&time_start, NULL);

    	if(ERROR == charger_run(&charger)){
    		charger.newDataFlag = 0;
    		continue;
    	}

		diff_x = charger.xTime - charger.baseline_x;
		diff_y = charger.yTime - charger.baseline_y;
		diff_z = charger.zTime - charger.baseline_z;

		//recalibration detection
		if(diff_x < -50 || diff_y < -50 || diff_z < -50){
			negative_count++;
			if(negative_count == NEGATIVE_MAX){
				negative_count = 0;
				calibrate_baseline(&charger);
				continue;
			}
		}else{
			negative_count = 0;
		}

		//valid point
		if((diff_x > RADIUS && diff_x <= charger.range_x )
				&& (diff_y > RADIUS && diff_y <= charger.range_y)){
			point1.x_pos = diff_x;
			point1.y_pos = diff_y;
			point1.z_pos = diff_z;
			queueHandler_pushPoint(&point1);
			queueHandler_draw();
			//gettimeofday(&time_stop, NULL);
			//printf("\r\ntime diff: %d\r\n", (int)time_stop.tv_usec - (int)time_start.tv_usec);
			printf("In range");

		}else{
			printf("Out range.");
		}

		printf("Time: %f %f %f, Diff: %f %f %f, Range: %d %d %d\r\n",
			charger.xTime, charger.yTime, charger.zTime,
			diff_x, diff_y, diff_z,
			charger.range_x, charger.range_y, charger.range_z);

        charger.newDataFlag = 0;
    }
}
예제 #6
0
파일: main.c 프로젝트: srobison/venture30
/****************************************************************************
 *
 *                        Main application
 *
****************************************************************************/
void main(void)
{
//    adc_result_t vbatt; // raw ADC of battery voltage
//    adc_result_t vbus;  // raw ADC of charger input voltage
    uint8_t soc_leds;   // result of raw ADC to 5 SOC LED conversion
    uint8_t c;  // dbg0, dbg1,

    // initialize the device
    SYSTEM_Initializer();
    CE_N_SetLow();                  // enable the input charger
    USBA_EN_SetHigh();              // enable usb porta
    M1_A_SetLow();                  // don't care since using pin_ignore/I2C only mode
    M2_A_SetHigh();                  // don't care since using pin_ignore/I2C only mode
    EM_EN_A_SetHigh();               // don't care since using pin_ignore/I2C only mode
    USBB_EN_SetHigh();              // enable usb portb
    M1_B_SetLow();                  // don't care since using pin_ignore/I2C only mode
    M2_B_SetHigh();                  // don't care since using pin_ignore/I2C only mode
    EM_EN_B_SetHigh();               // don't care since using pin_ignore/I2C only mode
    otg_mode_flag = 0;


    // initialise variables
    BTN0_dbstate = 0;                 // initial pushbutton state = released
    BTN0_change = 0;                  // clear pushbutton change flag (no change)
    BTN1_dbstate = 0;                 // initial pushbutton state = released
    BTN1_change = 0;                  // clear pushbutton change flag (no change)

    ADC_read_flag = 0;                //
    //ADC_channel = 0;

    print_start_msg();

     __delay_ms(10); // DEBUG
    charger_init();
    __delay_ms(10);  //DS: Upon power-up, the UCS1002 will not respond to any SMBus communications for 5.5 ms
    usb_port_init(USBA_ADDR);   // setup the USB smart output chips
     __delay_ms(10);    // DEBUG
    usb_port_init(USBB_ADDR);   // setup the USB smart output chips

    //enable interrupts - TODO should this wait unitl after i2c init routines?
    INTCONbits.IOCIF = 0;
    IOCBF1 = 0;
    IOCBF2 = 0;
    IOCBF3 = 0;
    IOCBF4 = 0;
    INTCONbits.IOCIE = 1;
    TMR0_StartTimer();
    TMR1_StartTimer();
    TMR2_StartTimer();
    INTERRUPT_PeripheralInterruptEnable();
    INTERRUPT_GlobalInterruptEnable();               // enable global interrupts

    /**
     *                          CORE APPLICATION
     */

    while (1)
    {
        // Add your application code

        //***DEBUG***//
        if (EUSART_IsDataReady() == 1)	// check for input
        {
                c = EUSART_GetByte();   // reading RCREG clear RCIF
                select_status_report(c);
        }

        if (A_DET_A_N_GetValue() == 0)
            FLASHLIGHT_SetHigh();
        //***DEBUG***//

        // check for self-attached cable
        if (SELF_DETECT_GetValue() == 1)
        {
            USBA_EN_SetLow();
            putstring0("Self Detect, USBA disabled"); // DEBUG
        }
        else USBA_EN_SetHigh();

        //grab battery level, input voltage, update SOC byte
        if (ADC_read_flag == 1)
        {
            ADC_read_flag = 0;
            vbatt = (ADC_GetConversion(channel_AN1) << 1);  // input voltage divided by 2 - multiply it back
            __delay_ms(1);                      // provide switching time
//            vbus = (ADC_GetConversion(channel_AN2) << 1);  // TODO figure out what to do with this
        }
        soc_leds = calc_soc(vbatt);

        // check for debounced button press
//        if (BTN0_change && !BTN0_dbstate)       // if button state changed and pressed (low)
        if (DBG_SPARE_change && DBG_SPARE_dbstate)       // if button state changed and pressed (high)
        {
            FLASHLIGHT_Toggle();               //   turn flashlight off and on
//            BTN0_change = 0;                  //   clear button change flag
            DBG_SPARE_change = 0;                  //   clear button change flag
        }
        
//        if (BTN1_change && !BTN1_dbstate)       // if button state changed and pressed (low)
//        {
//            soc_cntr_start_flag = 1;
            soc_update(soc_leds);           //   display SOC animation
//            BTN1_change = 0;                  //   clear button change flag
//        }
//        if (soc_cntr_done_flag == 1)        // let the SOC display stand for 5s
//        {
//            dbg1 += 1;
//            soc_cntr_start_flag = 0;
//            soc_cntr_done_flag = 0;
//            soc_update(dbg1);
////            soc_update(CLR_SOC);
//        }


        // TODO update more charger regs, react
        slave_check_fault(CHRGR_ADDR);
        if (otg_mode_flag == 1)
            i2c_slave_command(CHRGR_ADDR, 0x01, 0x6B); //REG01 reset watchdog, enable OTG only
        else
            i2c_slave_command(CHRGR_ADDR, 0x01, 0x5B); //REG01 reset watchdog, enable charger only

        // TODO update more usba regs, react
        slave_check_fault(USBA_ADDR);
        usb_porta_regs.REG00 = i2c_slave_read(USBA_ADDR, 0x00);   //update the current reading

        // TODO update more usbb regs, react
        slave_check_fault(USBB_ADDR);
        usb_portb_regs.REG00 = i2c_slave_read(USBB_ADDR, 0x00);   //update the current reading


        //debug
//        for (dbg0 = 0; dbg0 < 255; dbg0++);
//        {
//            __delay_ms(100);
//        }
//        soc_update(dbg1);
//        dbg1 += 1;
//        if (dbg1 == 0x1F)
//            dbg1 = 0;
//        if (debug_rprt_flag == 1)
//        {
//            debug_rprt_flag = 0;
//            FLASHLIGHT_Toggle();
//
//        }
 
    }
}
예제 #7
0
static int __devinit act8600_charger_probe(struct platform_device *pdev)
{
	struct act8600 *iodev = dev_get_drvdata(pdev->dev.parent);
	struct pmu_platform_data *pdata = dev_get_platdata(iodev->dev);
	struct act8600_charger *charger;
	int ret = 0;

	if (!pdata) {
		dev_err(&pdev->dev, "No platform_data supplied\n");
		return -ENXIO;
	}

	charger = kzalloc(sizeof(struct act8600_charger), GFP_KERNEL);
	if (!charger) {
		dev_err(&pdev->dev, "Failed to allocate driver structure\n");
		return -ENOMEM;
	}

	INIT_DELAYED_WORK(&charger->work, act8600_charger_work);

	if (pdata->charger_board_info->gpio != -1 && gpio_request_one(pdata->charger_board_info->gpio,
				GPIOF_DIR_OUT, "charger-current-set")) {
		dev_err(&pdev->dev, "no detect pin available\n");
		pdata->charger_board_info->gpio = -EBUSY;
		ret = ENODEV;
		goto err_free;
	}

	set_max_charger_current(pdata->charger_board_info);

	if (gpio_request_one(pdata->gpio,
			     GPIOF_DIR_IN, "charger-detect")) {
		dev_err(&pdev->dev, "no detect pin available\n");
		pdata->gpio = -EBUSY;
		ret = ENODEV;
		goto err_free;
	}

	charger->irq = gpio_to_irq(pdata->gpio);
	if (charger->irq < 0) {
		ret = charger->irq;
		dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
		goto err_free_gpio;
	}

	ret = request_irq(charger->irq, act8600_charger_irq,
			  IRQF_TRIGGER_LOW | IRQF_DISABLED,
			  "charger-detect",
			  charger);

	if (ret) {
		dev_err(&pdev->dev, "Failed to request irq %d\n", ret);
		goto err_free_irq;
	}
	enable_irq_wake(charger->irq);
	disable_irq(charger->irq);

	charger->dev = &pdev->dev;
	charger->iodev = iodev;

	charger_init(charger);
	power_supply_init(charger);

	act8600_callback_init(charger);

	platform_set_drvdata(pdev, charger);

	return 0;

err_free_irq:
	free_irq(charger->irq, charger);
err_free_gpio:
	gpio_free(pdata->gpio);
err_free:
	kfree(charger);

	return ret;
}