summaryrefslogtreecommitdiff
path: root/test/inductive_charging.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2014-08-15 15:52:31 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-25 20:52:32 +0000
commit050c7df0118855ea4c33003c176132821c18c794 (patch)
tree877eaf25e1f3ffc9f78896b9ed1087e9062f0ec7 /test/inductive_charging.c
parentb0f622543c098d3335bcf12a859c33ff215d7530 (diff)
downloadchrome-ec-050c7df0118855ea4c33003c176132821c18c794.tar.gz
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
Diffstat (limited to 'test/inductive_charging.c')
-rw-r--r--test/inductive_charging.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/test/inductive_charging.c b/test/inductive_charging.c
new file mode 100644
index 0000000000..8a4a94df5f
--- /dev/null
+++ b/test/inductive_charging.c
@@ -0,0 +1,103 @@
+/* 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();
+}