Compare commits

..

No commits in common. "0feba685ea7f2587d0e7103c496592361b3de760" and "fe53cbe6b8ce2db2cba84fda8436da59f7eae094" have entirely different histories.

2 changed files with 44 additions and 109 deletions

145
ssp.c
View file

@ -436,33 +436,33 @@ int ssp_ssel_cmd(struct command *cmd, const struct command_par *par)
{ {
static const struct keywords kw[] = { static const struct keywords kw[] = {
FLAG_VAL("default", 0x80000000), FLAG_VAL("default", 0x80000000),
FLAG_VAL("adc", 0x10000000), FLAG_VAL("adc", 0x81000000),
FLAG_VAL("dac", 0x20000000), FLAG_VAL("dac", 0x82000000),
FLAG_VAL("pressure", 0x30000000), FLAG_VAL("pressure", 0x83000000),
FLAG_VAL("pint", 0x40000000), FLAG_VAL("pint", 0x84000000),
FLAG_VAL("pext", 0x50000000), FLAG_VAL("pext", 0x85000000),
FLAG_VAL("current", 0x60000000), FLAG_VAL("current", 0x86000000),
FLAG_VAL("mode", 0x08000000), FLAG_VAL("mode", 0x010000),
FLAG_VAL("khz", 0x08010000), FLAG_VAL("khz", 0x010100),
FLAG_VAL("bytes", 0x08000800), FLAG_VAL("bytes", 0x010008),
FLAG_VAL("cpha", 0x08000000 | (SSPCR0_CPHA<<8)), FLAG_VAL("cpha", 0x010000 | SSPCR0_CPHA),
FLAG_VAL("cpol", 0x08000000 | (SSPCR0_CPOL<<8)), FLAG_VAL("cpol", 0x010000 | SSPCR0_CPOL),
FLAG_VAL("ssel", 0x04000000), FLAG_VAL("ssel", 0x020000),
FLAG_VAL("edriver", 0x04000040), FLAG_VAL("edriver", 0x020100),
FLAG_VAL("mclk", 0x04000080), FLAG_VAL("mclk", 0x020200),
FLAG_VAL("bate", 0x04000080 + 25), FLAG_VAL("bate", 0x020200 + 25),
FLAG_VAL("bate1", 0x040000c0), FLAG_VAL("bate1", 0x020c00),
FLAG_VAL("ads8688", 0x04000000 + 20), FLAG_VAL("ads8688", 0x020000 + 20),
FLAG_VAL("ltc2556", 0x04000000 + 11), FLAG_VAL("ltc2556", 0x020000 + 11),
FLAG_VAL("extern", 0x04000040 + 16), FLAG_VAL("extern", 0x020100 + 16),
FLAG_VAL("init", 0x02000000), FLAG_VAL("init", 0x040000),
FLAG_VAL("assert", 0x00100000), FLAG_VAL("assert", 0x100000),
FLAG_VAL("deassert", 0x00200000), FLAG_VAL("deassert", 0x200000),
FLAG_VAL("busy", 0x00400000), FLAG_VAL("busy", 0x400000),
FLAG_VAL("reset", 0x00800000), FLAG_VAL("reset", 0x800000),
{} {}
}; };
unsigned int what = (unsigned int)par->par; unsigned int what = (unsigned int)par->par;
@ -470,11 +470,11 @@ int ssp_ssel_cmd(struct command *cmd, const struct command_par *par)
unsigned int idx = imax; unsigned int idx = imax;
error_msg_t e = parse_flags(cmd, kw, &what); error_msg_t e = parse_flags(cmd, kw, &what);
if (!e) e = parse_expression_square(cmd, &idx, 1); if (!e) e = parse_expression_square(cmd, &idx, 1);
if (what & 0xf0000000) { if (what & 0x80000000)
if (idx==imax) if (idx==imax)
idx = 0; idx = (what>>24) & 7;
idx += (what>>28) & 7; else
} idx += (what>>24) & 7;
if (!e && idx > imax) e = &parser_value_error; if (!e && idx > imax) e = &parser_value_error;
if (e) goto error; if (e) goto error;
@ -482,44 +482,44 @@ int ssp_ssel_cmd(struct command *cmd, const struct command_par *par)
if (idx < imax) if (idx < imax)
conf = ssp_confs + idx; conf = ssp_confs + idx;
if (what & 0x08000000) { if (what & 0x10000) {
e = parse_expression(cmd, &conf->mode); e = parse_expression(cmd, &conf->mode);
if (e) goto error; if (e) goto error;
if (what & 0x0001ff00) if (what & 0xfff)
conf->mode = 0x0f ^ (what>>8) & 0xff | SSP_kHz(conf->mode); conf->mode = 0x0f ^ what & 0xff | SSP_kHz(conf->mode);
} }
if (what & 0x04000000) { if (what & 0x20000) {
if (!(what & 0xff)) { if (!(what & 0xfff)) {
e = parse_expression(cmd, &conf->ssel); e = parse_expression(cmd, &conf->ssel);
if (e) goto error; if (e) goto error;
} }
else { else {
unsigned int ssel = 1 << (what & 0x1f); unsigned int ssel = 1 << (what & 0x1f);
if (what & 0x40) if (what & 0x100)
ssel |= SSP_EXT; ssel |= SSP_EXT;
if (what & 0x80) if (what & 0x200)
ssel |= SSP_MCLK; ssel |= SSP_MCLK;
conf->ssel = ssel; conf->ssel = ssel;
} }
} }
if (what & 0x02000000) if (what & 0x40000)
ssp_init(idx < imax ? conf : 0); ssp_init(idx < imax ? conf : 0);
if (what & 0x00200000) if (what & 0x200000)
ssp_deassert_ssel(); ssp_deassert_ssel();
if (what & 0x00100000) if (what & 0x100000)
ssp_assert_ssel(); ssp_assert_ssel();
int status = 0; int status = 0;
if (what & 0x00400000) { if (what & 0x400000) {
unsigned int timeout = 0; unsigned int timeout = 0;
parse_expression(cmd, &timeout); parse_expression(cmd, &timeout);
status = ssp_wait(timeout); status = ssp_wait(timeout);
} }
if (what & 0x00800000) if (what & 0x800000)
ssp_reset(); ssp_reset();
parser_format_message(cmd, "%03d ssp[%s] mode=0x%04x ssel=0x%08x stat=0x%x\n", parser_format_message(cmd, "%03d ssp[%s] mode=0x%04x ssel=0x%08x stat=0x%x\n",
@ -529,72 +529,7 @@ error:
return parser_error_message(cmd, e); return parser_error_message(cmd, e);
} }
int ssp_read_cmd(struct command *cmd, const struct command_par *par)
{
static const struct keywords kw[] = {
FLAG_VAL("match", 0x01000000),
FLAG_VAL("idleframe", 0x02000000),
FLAG_VAL("zeros", 0x02000080),
FLAG_VAL("ones", 0x02000040),
{}
};
unsigned int what = (unsigned int)par->par;
error_msg_t e = parse_flags(cmd, kw, &what);
unsigned int value;
if (e) goto error;
if (what & 0x01000000) {
e = parse_expression_square(cmd, &value, 0);
if (e) goto error;
ssp_match.value = value;
ssp_match.mask = value >> 16;
}
if (what & 0x02000000) {
value = what & 0x40 ? 0xffff : 0;
if (!(what & 0x80))
e = parse_expression_square(cmd, &value, 0);
if (e) goto error;
job.idle_frame = value;
}
if (parse_expression(cmd, &value)) goto done;
ssp_match.frame_count = value;
if (parse_expression(cmd, &value)) goto done;
ssp_match.read_count = value;
if (parse_expression(cmd, &value)) goto done;
ssp_match.count = value;
done:
parser_format_message(cmd, "%03d [0x%04x%04x][0x%04x] %d %d %d\n",
par->code, ssp_match.mask, ssp_match.value, job.idle_frame,
ssp_match.frame_count, ssp_match.read_count, ssp_match.count);
return par->code;
error:
return parser_error_message(cmd, e);
}
int ssp_send_cmd(struct command *cmd, const struct command_par *par)
{
unsigned int n = 0;
unsigned int reads = 0;
unsigned int frames = 0;
unsigned int value;
if (!parse_expression_square(cmd, &frames, 0))
parse_expression_square(cmd, &reads, 0);
while (n < 256 && !parse_expression(cmd, &value))
ssp_scratch[n++] = value;
if (!frames) {
frames = n;
if (frames < reads)
frames = reads;
}
ssp_set_buffer(0,0);
int c = ssp_submit(ssp_scratch, n, frames, reads);
parser_format_message(cmd, "%03d ssp %d frames %dw %dr → %d\n",
par->code, frames, n, reads, c);
return par->code;
}
const struct keywords ssp_commands[] = { const struct keywords ssp_commands[] = {
CMD_KW("config", ssp_ssel_cmd, 350, 0), CMD_KW("config", ssp_ssel_cmd, 350, 0),
CMD_KW("reads", ssp_read_cmd, 352, 0),
CMD_KW("send", ssp_send_cmd, 354, 0),
CMD_END CMD_END
}; };

2
ssp.h
View file

@ -81,8 +81,8 @@ extern struct ssp_match {
unsigned char frame_count; unsigned char frame_count;
unsigned char read_count; unsigned char read_count;
unsigned short count; unsigned short count;
unsigned short value;
unsigned short mask; unsigned short mask;
unsigned short value;
} ssp_match; } ssp_match;
struct ssp_batch; struct ssp_batch;