Commit 1b2ac7f7 authored by Tristan Gingold's avatar Tristan Gingold

mfip_urv: use command index, add traces and comments

parent f34fa95c
......@@ -102,6 +102,7 @@ struct ftb_dev {
unsigned nbr_cmds;
unsigned idx_cmd;
unsigned waitrep;
unsigned char idx;
} *ftb;
static uint8_t crc8_byte(uint8_t data)
......@@ -202,6 +203,8 @@ static int read_cons_vars(void)
if (ftb->waitrep == 0)
;
else if (ftb->waitrep == 5) {
if (flag_trace)
fprintf (stderr, "Timeout\n");
fprintf (out, "# Timeout\n");
fflush(stdout);
ftb->waitrep = 0;
......@@ -210,8 +213,14 @@ static int read_cons_vars(void)
else
ftb->waitrep++;
}
else /* if (pvar->buffer[1] != 0) */
else { /* if (pvar->buffer[1] != 0) */
if (flag_trace)
fprintf (stderr,
"Unexpected sequence cmd/id recv:%u/%u, expect:%u/%u\n",
pvar->buffer[0], pvar->buffer[1],
cmd->cmd, cmd->id);
fprintf (out, "Unexpected packet\n");
}
}
return 0;
......@@ -284,7 +293,7 @@ static int update_prod_vars(void)
/* Send next command. */
struct urv_cmd *cmd = &ftb->cmds[ftb->idx_cmd];
cmd->id = ftb->idx_cmd + 0x20;
cmd->id = ftb->idx++;
pvar->bsz = PROD_VAR_LENGTH;
pvar->buffer[0] = cmd->cmd;
......@@ -380,7 +389,10 @@ static int ftb_create_per_var(struct ftb_ba *ba)
var_cfg.max_bsz = PROD_VAR_LENGTH;
var_cfg.id = (VAR1_ID << 8) | agent_idx;
var_cfg.flags = MSTRFIP_DATA_FLAGS_PROD;
var_cfg.mstrfip_data_handler = mstrfip_prod_var_handler;
if (flag_trace > 1)
var_cfg.mstrfip_data_handler = mstrfip_prod_var_handler;
else
var_cfg.mstrfip_data_handler = NULL;
pvar = mstrfip_var_create(ba->mc, &var_cfg);
if (pvar == NULL)
return -1;
......@@ -420,41 +432,6 @@ static int ftb_create_per_var(struct ftb_ba *ba)
return 0;
}
static int ftb_ba_start(struct ftb_dev *ftb)
{
int res;
int agt_addr;
if (mstrfip_ba_reset(ftb->dev) < 0) {
fprintf(stderr, "Reset BA failed: %s\n",
mstrfip_strerror(errno));
return -1;
}
if (mstrfip_ba_load(ftb->dev, ftb->ba.mc) < 0) {
fprintf(stderr, "Loading macrocycle failed: %s\n",
mstrfip_strerror(errno));
return -1;
}
/* get turn around time of each agents */
agt_addr = agent_idx;
res = mstrfip_hw_response_time_get(ftb->dev, 1, &agt_addr, &ftb->tr_nstime);
if (res) {
fprintf(stderr, "Read turn around time failed: %s\n",
mstrfip_strerror(errno));
}
if (mstrfip_ba_start(ftb->dev) < 0) {
fprintf(stderr, "Start BA failed: %s\n",
mstrfip_strerror(errno));
return -1;
}
return 0;
}
static int ftb_define_macrocycle(struct ftb_ba *ba)
{
struct mstrfip_per_var_wind_cfg pwind_cfg = {0};
......@@ -465,17 +442,18 @@ static int ftb_define_macrocycle(struct ftb_ba *ba)
if (mstrfip_per_var_wind_append(ba->mc, &pwind_cfg) < 0)
return -1;
/* append a wait window without padding (silent) */
/* append a wait window without padding (silent) (absolute time). */
if (mstrfip_wait_wind_append(ba->mc, 1, ftb->cycle_uslength / 2) < 0)
return -1;
/* append a periodic window for consumed varaiables */
/* append a periodic window for consumed variables */
pwind_cfg.varlist = ba->cons_varlist;
pwind_cfg.var_count = 1;
if (mstrfip_per_var_wind_append(ba->mc, &pwind_cfg) < 0)
return -1;
/* append a wait window without padding (silent) */
/* append a wait window without padding (silent).
As the time is absolute, this defines the cycle length. */
if (mstrfip_wait_wind_append(ba->mc, 1, ftb->cycle_uslength) < 0)
return -1;
......@@ -521,6 +499,41 @@ static int cycle_config(struct mstrfip_hw_cfg *hw_cfg, struct mstrfip_sw_cfg *sw
return 0;
}
static int ftb_ba_start(struct ftb_dev *ftb)
{
int res;
int agt_addr;
if (mstrfip_ba_reset(ftb->dev) < 0) {
fprintf(stderr, "Reset BA failed: %s\n",
mstrfip_strerror(errno));
return -1;
}
if (mstrfip_ba_load(ftb->dev, ftb->ba.mc) < 0) {
fprintf(stderr, "Loading macrocycle failed: %s\n",
mstrfip_strerror(errno));
return -1;
}
/* get turn around time of each agents */
agt_addr = agent_idx;
res = mstrfip_hw_response_time_get(ftb->dev, 1, &agt_addr, &ftb->tr_nstime);
if (res) {
fprintf(stderr, "Read turn around time failed: %s\n",
mstrfip_strerror(errno));
}
if (mstrfip_ba_start(ftb->dev) < 0) {
fprintf(stderr, "Start BA failed: %s\n",
mstrfip_strerror(errno));
return -1;
}
return 0;
}
static int append_command(struct ftb_dev *dev, const struct urv_cmd *cmd)
{
if (dev->nbr_cmds >= MAX_CMDS)
......@@ -3901,10 +3914,11 @@ int main(int argc, char *argv[])
ftb->reset = 1;
ftb->nbr_errors = 0;
ftb->cycle_uslength = 1000; /* For 124B: 5000, for 16B: 1000 */
ftb->cycle_uslength = 2000; /* For 124B: 5000, for 16B: 1000 */
ftb->nbr_cmds = 0;
ftb->idx_cmd = 0;
ftb->waitrep = 0;
ftb->idx = 0x22;
/* Skip progname. */
argc--;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment