diff options
author | Bill Richardson <wfrichar@chromium.org> | 2013-03-12 15:04:16 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-13 11:14:54 -0700 |
commit | cb03fa5c63546f7a77ffe737ce053bb50c6a3906 (patch) | |
tree | 8b69e4806093e577e53ca9525691a1659b00f0b2 | |
parent | f5f30a22c676f1450052cd7d9451ff650818ba3f (diff) | |
download | chrome-ec-cb03fa5c63546f7a77ffe737ce053bb50c6a3906.tar.gz |
Update lbplay.c with correct cooperative locking.
BUG=none
BRANCH=none
TEST=manual
Build it manually, copy lbplay to DUT, run lbplay & ectool simultaneously.
cd /mnt/stateful_partition
mount -o remount,exec .
scp USER@SOMEWHERE:/SOME/PATH/TO/lbplay .
./lbplay &
ectool lightbar params
ectool lightbar params
ectool lightbar params
The lbplay program should cause the lightbar to slowly ramp up to green and
down to red. Meanwhile, the ectool command should work and not hang.
Change-Id: I4f26b0530ceaacbc18f8b9f38d7cbdfdabf78015
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/45257
Reviewed-by: Mike Frysinger <vapier@chromium.org>
-rw-r--r-- | util/lbplay.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/util/lbplay.c b/util/lbplay.c index 907374e9cc..bcf90148e7 100644 --- a/util/lbplay.c +++ b/util/lbplay.c @@ -12,12 +12,12 @@ #include "comm-host.h" #include "lightbar.h" +#include "lock/gec_lock.h" /* Handy tricks */ #define BUILD_ASSERT(cond) ((void)sizeof(char[1 - 2*!(cond)])) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) - #define LB_SIZES(SUBCMD) { \ sizeof(((struct ec_params_lightbar *)0)->SUBCMD) \ + sizeof(((struct ec_params_lightbar *)0)->cmd), \ @@ -42,6 +42,16 @@ static const struct { #undef LB_SIZES +#define GEC_LOCK_TIMEOUT_SECS 30 /* 30 secs */ +#define LOCK do { \ + if (acquire_gec_lock(GEC_LOCK_TIMEOUT_SECS) < 0) { \ + fprintf(stderr, "Could not acquire GEC lock.\n"); \ + exit(1); \ + } } while (0) + +#define UNLOCK do { release_gec_lock(); } while (0) + + static void lb_cmd_noargs(enum lightbar_command cmd) { struct ec_params_lightbar param; @@ -133,6 +143,7 @@ void wait_for_ec_to_stop(void) lb_command_paramcount[param.cmd].outsize); if (count++ > 10) { fprintf(stderr, "EC isn't responding\n"); + UNLOCK; exit(1); } } while (r < 0 && resp.get_seq.num != LIGHTBAR_STOP); @@ -144,13 +155,18 @@ int main(int argc, char **argv) BUILD_ASSERT(ARRAY_SIZE(lb_command_paramcount) == LIGHTBAR_NUM_CMDS); - if (comm_init() < 0) - return -3; + LOCK; + + if (comm_init() < 0) { + fprintf(stderr, "comm_init() failed\n"); + UNLOCK; + return 2; + } /* Tell the EC to let us drive. */ lightbar_sequence(LIGHTBAR_STOP); - /* Wait until it's listening */ + /* Wait until it's listening (or die trying) */ wait_for_ec_to_stop(); /* Initialize it */ @@ -159,20 +175,26 @@ int main(int argc, char **argv) lightbar_brightness(0xff); lightbar_on(); - /* Play a bit */ + UNLOCK; + /* Play a bit */ for (i = 0; i <= 255; i += 4) { + LOCK; lightbar_rgb(4, 0, i, 0); + UNLOCK; usleep(100000); } for (; i >= 0; i -= 4) { + LOCK; lightbar_rgb(4, i, 0, 0); + UNLOCK; usleep(100000); } /* Let the EC drive again */ + LOCK; lightbar_sequence(LIGHTBAR_RUN); - + UNLOCK; return 0; } |