summaryrefslogtreecommitdiff
path: root/util/lbplay.c
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2012-05-08 10:04:39 -0700
committerBill Richardson <wfrichar@chromium.org>2012-05-08 12:03:49 -0700
commit468bc6171c6c7b2b60d6b41ce443e3a6f0013161 (patch)
treedd328d98f994574599e3ff8e9fb52165673b768b /util/lbplay.c
parent4679f8f194153bc4bf9a9a16f4f4ce1b924d9e7d (diff)
downloadchrome-ec-468bc6171c6c7b2b60d6b41ce443e3a6f0013161.tar.gz
Add LPC lightbar command to get the current sequence.
Instead of making the STOP command synchronous, we can just have the host-side app tell the EC to stop, then poll until it has. BUG=chrome-os-partner:9349 TEST=manual "make BOARD=link", then copy build/link/util/lbplay to the host and run it. Change-Id: I846924ae7994a498e0089197785cf239898fe2a3 Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'util/lbplay.c')
-rw-r--r--util/lbplay.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/util/lbplay.c b/util/lbplay.c
index 33d8bb731e..56934ebea2 100644
--- a/util/lbplay.c
+++ b/util/lbplay.c
@@ -13,6 +13,9 @@
#include "lightbar.h"
#include "lpc_commands.h"
+/* Handy tricks */
+#define BUILD_ASSERT(cond) ((void)sizeof(char[1 - 2*!(cond)]))
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
/* Waits for the EC to be unbusy. Returns 0 if unbusy, non-zero if
* timeout. */
@@ -80,7 +83,7 @@ static int ec_command(int command, const void *indata, int insize,
static const struct {
uint8_t insize;
uint8_t outsize;
-} lb_command_paramcount[LIGHTBAR_NUM_CMDS] = {
+} lb_command_paramcount[] = {
{ sizeof(((struct lpc_params_lightbar_cmd *)0)->in.dump),
sizeof(((struct lpc_params_lightbar_cmd *)0)->out.dump) },
{ sizeof(((struct lpc_params_lightbar_cmd *)0)->in.off),
@@ -97,6 +100,8 @@ static const struct {
sizeof(((struct lpc_params_lightbar_cmd *)0)->out.reg) },
{ sizeof(((struct lpc_params_lightbar_cmd *)0)->in.rgb),
sizeof(((struct lpc_params_lightbar_cmd *)0)->out.rgb) },
+ { sizeof(((struct lpc_params_lightbar_cmd *)0)->in.get_seq),
+ sizeof(((struct lpc_params_lightbar_cmd *)0)->out.get_seq) },
};
@@ -169,11 +174,33 @@ void lightbar_rgb(int led, int red, int green, int blue)
&param, lb_command_paramcount[param.in.cmd].outsize);
}
+void wait_for_ec_to_stop(void)
+{
+ int r;
+ struct lpc_params_lightbar_cmd param;
+ int count = 0;
+
+ do {
+ usleep(100000);
+ param.in.cmd = LIGHTBAR_CMD_GET_SEQ;
+ r = ec_command(EC_LPC_COMMAND_LIGHTBAR_CMD,
+ &param,
+ lb_command_paramcount[param.in.cmd].insize,
+ &param,
+ lb_command_paramcount[param.in.cmd].outsize);
+ if (count++ > 10) {
+ fprintf(stderr, "EC isn't responding\n");
+ exit(1);
+ }
+ } while (r != 0 && param.out.get_seq.num != LIGHTBAR_STOP);
+}
int main(int argc, char **argv)
{
int i;
+ BUILD_ASSERT(ARRAY_SIZE(lb_command_paramcount) == LIGHTBAR_NUM_CMDS);
+
/* Request I/O privilege */
if (iopl(3) < 0) {
perror("Error getting I/O privilege");
@@ -184,6 +211,9 @@ int main(int argc, char **argv)
/* Tell the EC to let us drive. */
lightbar_sequence(LIGHTBAR_STOP);
+ /* Wait until it's listening */
+ wait_for_ec_to_stop();
+
/* Initialize it */
lightbar_off();
lightbar_init_vals();