summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Caruso <ejcaruso@chromium.org>2014-10-08 16:39:51 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-09 23:29:42 +0000
commit6713fa2d38a3b455be18ca1d8e1b530809f43352 (patch)
treebc69469f0f0188d23015c8b842013371deb40525
parente3e799916460fc2faf3c661534de014d692e7f19 (diff)
downloadchrome-ec-6713fa2d38a3b455be18ca1d8e1b530809f43352.tar.gz
lightbar: Rename structs and macros for kernel cros_ec_commands
This prepends EC_ a macro exposed in ec_commands.h, moves a macro into lbcc that is not used elsewhere, and changes lb_program structs to lightbar_program. BUG=None BRANCH=ToT TEST=make buildall -j Change-Id: I481562da72d91f846c64cf9af40338027641462c Signed-off-by: Eric Caruso <ejcaruso@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/222406 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--common/lightbar.c10
-rw-r--r--extra/lightbar/main.c8
-rw-r--r--extra/lightbar/simulation.h2
-rw-r--r--include/ec_commands.h9
-rw-r--r--util/ectool.c8
-rw-r--r--util/lbcc.c43
6 files changed, 41 insertions, 39 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index 5f05d6799e..cd6595bb21 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -908,8 +908,8 @@ static uint32_t sequence_TAP(void)
/* Lightbar bytecode interpreter: Lightbyte. */
/****************************************************************************/
-static struct lb_program cur_prog;
-static struct lb_program next_prog;
+static struct lightbar_program cur_prog;
+static struct lightbar_program next_prog;
static uint8_t pc;
static uint8_t led_desc[NUM_LEDS][LB_CONT_MAX][3];
@@ -1189,7 +1189,7 @@ static uint32_t sequence_PROGRAM(void)
uint8_t old_pc;
/* load next program */
- memcpy(&cur_prog, &next_prog, sizeof(struct lb_program));
+ memcpy(&cur_prog, &next_prog, sizeof(struct lightbar_program));
/* reset program state */
saved_brightness = lb_get_brightness();
@@ -1419,7 +1419,9 @@ static int lpc_cmd_lightbar(struct host_cmd_handler_args *args)
break;
case LIGHTBAR_CMD_SET_PROGRAM:
CPRINTS("LB_set_program");
- memcpy(&next_prog, &in->set_program, sizeof(struct lb_program));
+ memcpy(&next_prog,
+ &in->set_program,
+ sizeof(struct lightbar_program));
break;
case LIGHTBAR_CMD_VERSION:
CPRINTS("LB_version");
diff --git a/extra/lightbar/main.c b/extra/lightbar/main.c
index 6014719f0b..a0da1a28ba 100644
--- a/extra/lightbar/main.c
+++ b/extra/lightbar/main.c
@@ -291,7 +291,7 @@ done:
return r;
}
-int lb_load_program(const char *filename, struct lb_program *prog)
+int lb_load_program(const char *filename, struct lightbar_program *prog)
{
FILE *fp;
size_t got;
@@ -312,15 +312,15 @@ int lb_load_program(const char *filename, struct lb_program *prog)
return 1;
}
rc = (int) ftell(fp);
- if (rc > LB_PROG_LEN) {
+ if (rc > EC_LB_PROG_LEN) {
fprintf(stderr, "File %s is too long, aborting\n", filename);
fclose(fp);
return 1;
}
rewind(fp);
- memset(prog->data, 0, LB_PROG_LEN);
- got = fread(prog->data, 1, LB_PROG_LEN, fp);
+ memset(prog->data, 0, EC_LB_PROG_LEN);
+ got = fread(prog->data, 1, EC_LB_PROG_LEN, fp);
if (rc != got)
fprintf(stderr, "Warning: did not read entire file\n");
prog->size = got;
diff --git a/extra/lightbar/simulation.h b/extra/lightbar/simulation.h
index 2abfae230b..f7a30ea6a7 100644
--- a/extra/lightbar/simulation.h
+++ b/extra/lightbar/simulation.h
@@ -23,7 +23,7 @@ void *entry_lightbar(void *);
void init_windows(void);
int lb_read_params_from_file(const char *filename,
struct lightbar_params_v1 *p);
-int lb_load_program(const char *filename, struct lb_program *prog);
+int lb_load_program(const char *filename, struct lightbar_program *prog);
/* Interfaces to the EC code that we're encapsulating */
void lightbar_task(void);
int fake_consolecmd_lightbar(int argc, char *argv[]);
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 46b8a1da76..5987c46568 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1050,11 +1050,10 @@ struct lightbar_params_v1 {
} __packed;
/* Lightbyte program. */
-#define LB_PROG_LEN 192
-#define LB_PROG_MAX_OPERANDS 4
-struct lb_program {
+#define EC_LB_PROG_LEN 192
+struct lightbar_program {
uint8_t size;
- uint8_t data[LB_PROG_LEN];
+ uint8_t data[EC_LB_PROG_LEN];
};
struct ec_params_lightbar {
@@ -1083,7 +1082,7 @@ struct ec_params_lightbar {
struct lightbar_params_v0 set_params_v0;
struct lightbar_params_v1 set_params_v1;
- struct lb_program set_program;
+ struct lightbar_program set_program;
};
} __packed;
diff --git a/util/ectool.c b/util/ectool.c
index a26aecd5fc..542fc76980 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -2082,7 +2082,7 @@ static void lb_show_params_v1(const struct lightbar_params_v1 *p)
p->color[i].b, i);
}
-static int lb_load_program(const char *filename, struct lb_program *prog)
+static int lb_load_program(const char *filename, struct lightbar_program *prog)
{
FILE *fp;
size_t got;
@@ -2103,15 +2103,15 @@ static int lb_load_program(const char *filename, struct lb_program *prog)
return 1;
}
rc = (int) ftell(fp);
- if (rc > LB_PROG_LEN) {
+ if (rc > EC_LB_PROG_LEN) {
fprintf(stderr, "File %s is too long, aborting\n", filename);
fclose(fp);
return 1;
}
rewind(fp);
- memset(prog->data, 0, LB_PROG_LEN);
- got = fread(prog->data, 1, LB_PROG_LEN, fp);
+ memset(prog->data, 0, EC_LB_PROG_LEN);
+ got = fread(prog->data, 1, EC_LB_PROG_LEN, fp);
if (rc != got)
fprintf(stderr, "Warning: did not read entire file\n");
prog->size = got;
diff --git a/util/lbcc.c b/util/lbcc.c
index 0b69e7d777..a5247dcccc 100644
--- a/util/lbcc.c
+++ b/util/lbcc.c
@@ -31,10 +31,10 @@ static const char usage[] =
/* globals */
static int hit_errors;
static int opt_verbose;
-static int is_jump_target[LB_PROG_LEN]; /* does program jump here? */
-static int is_instruction[LB_PROG_LEN]; /* instruction or operand? */
-static char *label[LB_PROG_LEN]; /* labels we've seen */
-static char *reloc_label[LB_PROG_LEN]; /* put label target here */
+static int is_jump_target[EC_LB_PROG_LEN]; /* does program jump here? */
+static int is_instruction[EC_LB_PROG_LEN]; /* instruction or operand? */
+static char *label[EC_LB_PROG_LEN]; /* labels we've seen */
+static char *reloc_label[EC_LB_PROG_LEN]; /* put label target here */
static void Error(const char *format, ...)
{
@@ -56,10 +56,11 @@ static void Warning(const char *format, ...)
}
/* The longest line should have a label, an opcode, and the max operands */
+#define LB_PROG_MAX_OPERANDS 4
#define MAX_WORDS (2 + LB_PROG_MAX_OPERANDS)
-struct safe_lb_program {
- struct lb_program p;
+struct safe_lightbar_program {
+ struct lightbar_program p;
uint8_t zeros[LB_PROG_MAX_OPERANDS];
} __packed;
@@ -85,14 +86,14 @@ static const char const *color_sym[] = {
"r", "g", "b", "rgb"
};
-static void read_binary(FILE *fp, struct safe_lb_program *prog)
+static void read_binary(FILE *fp, struct safe_lightbar_program *prog)
{
int got;
memset(prog, 0, sizeof(*prog));
/* Read up to one more byte than we need, so we know if it's too big */
- got = fread(prog->p.data, 1, LB_PROG_LEN + 1, fp);
+ got = fread(prog->p.data, 1, EC_LB_PROG_LEN + 1, fp);
if (got < 1) {
Error("Unable to read any input: ");
if (feof(fp))
@@ -101,10 +102,10 @@ static void read_binary(FILE *fp, struct safe_lb_program *prog)
fprintf(stderr, "%s\n", strerror(errno));
else
fprintf(stderr, "no idea why.\n");
- } else if (got > LB_PROG_LEN) {
- Warning("Truncating input at %d bytes\n", LB_PROG_LEN);
+ } else if (got > EC_LB_PROG_LEN) {
+ Warning("Truncating input at %d bytes\n", EC_LB_PROG_LEN);
prog->zeros[0] = 0;
- got = LB_PROG_LEN;
+ got = EC_LB_PROG_LEN;
} else {
prog->p.size = got;
}
@@ -216,7 +217,7 @@ static int print_op(FILE *fp, uint8_t addr, uint8_t cmd, uint8_t *arg)
return operands;
}
-static void disassemble_prog(FILE *fp, struct safe_lb_program *prog)
+static void disassemble_prog(FILE *fp, struct safe_lightbar_program *prog)
{
int i;
uint8_t *ptr, targ;
@@ -240,7 +241,7 @@ static void disassemble_prog(FILE *fp, struct safe_lb_program *prog)
/* Finally, make sure the program doesn't jump to any location other
* than a valid instruction */
- for (i = 0; i < LB_PROG_LEN; i++)
+ for (i = 0; i < EC_LB_PROG_LEN; i++)
if (is_jump_target[i] && !is_instruction[i]) {
Warning("program jumps to 0x%02x, "
"which is not a valid instruction\n", i);
@@ -328,28 +329,28 @@ static int is_color_arg(char *buf, uint32_t *valp)
return rv;
}
-static void fixup_symbols(struct safe_lb_program *prog)
+static void fixup_symbols(struct safe_lightbar_program *prog)
{
int i, j;
- for (i = 0; i < LB_PROG_LEN; i++) {
+ for (i = 0; i < EC_LB_PROG_LEN; i++) {
if (reloc_label[i]) {
/* Looking for reloc label */
- for (j = 0; j < LB_PROG_LEN; j++) {
+ for (j = 0; j < EC_LB_PROG_LEN; j++) {
if (label[j] && !strcmp(label[j],
reloc_label[i])) {
prog->p.data[i] = j;
break;
}
}
- if (j >= LB_PROG_LEN)
+ if (j >= EC_LB_PROG_LEN)
Error("Can't find label %s from line %d\n", j);
}
}
}
-static void compile(FILE *fp, struct safe_lb_program *prog)
+static void compile(FILE *fp, struct safe_lightbar_program *prog)
{
char buf[128];
struct parse_s token[MAX_WORDS];
@@ -409,7 +410,7 @@ static void compile(FILE *fp, struct safe_lb_program *prog)
}
/* Do we even have a place to write this opcode? */
- if (addr >= LB_PROG_LEN) {
+ if (addr >= EC_LB_PROG_LEN) {
Error("out of program space at line %d\n", line);
break;
}
@@ -481,7 +482,7 @@ static void compile(FILE *fp, struct safe_lb_program *prog)
}
/* Did we run past the end? */
- if (addr > LB_PROG_LEN) {
+ if (addr > EC_LB_PROG_LEN) {
Error("out of program space at line %d\n", line);
break;
}
@@ -501,7 +502,7 @@ static void compile(FILE *fp, struct safe_lb_program *prog)
int main(int argc, char *argv[])
{
- struct safe_lb_program safe_prog;
+ struct safe_lightbar_program safe_prog;
int opt_decode = 0;
int c;
int errorcnt = 0;