blob: 8a4a94df5f11e03ba8cd4216bcda04441bb3677b [file] [log] [blame]
/* Copyright 2014 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Test inductive charging module.
*/
#include "common.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
#include "inductive_charging.h"
#include "lid_switch.h"
#include "test_util.h"
#include "timer.h"
#include "util.h"
static void wait_for_lid_debounce(void)
{
while (lid_is_open() != gpio_get_level(GPIO_LID_OPEN))
msleep(20);
}
static void set_lid_open(int lid_open)
{
gpio_set_level(GPIO_LID_OPEN, lid_open);
wait_for_lid_debounce();
}
static int test_lid(void)
{
/* Lid is open initially */
set_lid_open(1);
gpio_set_level(GPIO_CHARGE_DONE, 0);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
/* Close the lid. Transmitter should be enabled. */
set_lid_open(0);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 1);
/* Open the lid. Charging should stop. */
set_lid_open(1);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 0);
return EC_SUCCESS;
}
static int test_charge_done(void)
{
/* Close the lid to start charging */
set_lid_open(0);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 1);
/* Charging is done. Stop charging, but don't turn off transmitter. */
gpio_set_level(GPIO_CHARGE_DONE, 1);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 0);
/* Oops, need charging again. */
gpio_set_level(GPIO_CHARGE_DONE, 0);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 1);
return EC_SUCCESS;
}
static int test_lid_open_during_charging(void)
{
/* Close the lid. Start charging. */
set_lid_open(0);
gpio_set_level(GPIO_CHARGE_DONE, 0);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 1);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 1);
/* Open the lid. Transmitter should be turned off. */
set_lid_open(1);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 0);
/* Toggle charge done signal. Charging should not start. */
gpio_set_level(GPIO_CHARGE_DONE, 1);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 0);
gpio_set_level(GPIO_CHARGE_DONE, 0);
TEST_ASSERT(gpio_get_level(GPIO_BASE_CHG_VDD_EN) == 0);
TEST_ASSERT(gpio_get_level(GPIO_CHARGE_EN) == 0);
return EC_SUCCESS;
}
void run_test(void)
{
test_reset();
RUN_TEST(test_lid);
RUN_TEST(test_charge_done);
RUN_TEST(test_lid_open_during_charging);
test_print_result();
}