Files
OpenCellular/test/inductive_charging.c
Vic Yang 050c7df011 Add inductive charging control module
This module controls the inductive charging transmitter. For now, the
policy is to charge whenever possible.

BUG=chrome-os-partner:31392
TEST=Unit test passed
BRANCH=None

Change-Id: Ie48a38ad92fe2bc3329c4962e96572f2bc40b4e6
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/212715
2014-08-25 20:52:32 +00:00

104 lines
2.7 KiB
C

/* 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();
}