asix-sigma: Pull out cluster decoding

Pull out the code for decoding the DRAM clusters into separate function.
This shall improve readability some more.

Signed-off-by: Marek Vasut <marex@denx.de>
This commit is contained in:
Marek Vasut 2014-04-21 01:29:52 +02:00 committed by Bert Vermeulen
parent a16a6391b5
commit 23239b5c84
1 changed files with 104 additions and 91 deletions

View File

@ -940,57 +940,27 @@ static uint16_t sigma_dram_cluster_ts(struct sigma_dram_cluster *cluster)
return (cluster->timestamp_hi << 8) | cluster->timestamp_lo;
}
/*
* Decode chunk of 1024 bytes, 64 clusters, 7 events per cluster.
* Each event is 20ns apart, and can contain multiple samples.
*
* For 200 MHz, events contain 4 samples for each channel, spread 5 ns apart.
* For 100 MHz, events contain 2 samples for each channel, spread 10 ns apart.
* For 50 MHz and below, events contain one sample for each channel,
* spread 20 ns apart.
*/
static int decode_chunk_ts(struct sigma_dram_line *dram_line, int triggerpos,
uint16_t events_in_line, void *cb_data)
static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster,
unsigned int events_in_cluster,
struct sr_dev_inst *sdi)
{
struct sigma_dram_cluster *dram_cluster;
struct sr_dev_inst *sdi = cb_data;
struct dev_context *devc = sdi->priv;
uint16_t tsdiff, ts;
uint8_t samples[2048];
struct sigma_state *ss = &devc->state;
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
unsigned int i, j;
uint16_t tsdiff, ts;
uint8_t samples[2048];
unsigned int i;
int triggerts = -1;
unsigned int clusters_in_line =
(events_in_line + (EVENTS_PER_CLUSTER - 1)) / EVENTS_PER_CLUSTER;
unsigned int events_in_cluster;
struct sigma_state *ss = &devc->state;
/* Check if trigger is in this chunk. */
if (triggerpos != -1) {
if (devc->cur_samplerate <= SR_MHZ(50))
triggerpos -= EVENTS_PER_CLUSTER - 1;
if (triggerpos < 0)
triggerpos = 0;
/* Find in which cluster the trigger occured. */
triggerts = triggerpos / EVENTS_PER_CLUSTER;
}
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
logic.unitsize = 2;
logic.data = samples;
/* For each full DRAM cluster. */
for (i = 0; i < clusters_in_line; i++) {
dram_cluster = &dram_line->cluster[i];
ts = sigma_dram_cluster_ts(dram_cluster);
tsdiff = ts - ss->lastts;
ss->lastts = ts;
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
logic.unitsize = 2;
logic.data = samples;
/*
@ -1005,34 +975,28 @@ static int decode_chunk_ts(struct sigma_dram_line *dram_line, int triggerpos,
* and the remaining samples happen at timestamp +1...+6 .
*/
for (ts = 0; ts < tsdiff - (EVENTS_PER_CLUSTER - 1); ts++) {
j = ts % 1024;
samples[2 * j + 0] = ss->lastsample & 0xff;
samples[2 * j + 1] = ss->lastsample >> 8;
i = ts % 1024;
samples[2 * i + 0] = ss->lastsample & 0xff;
samples[2 * i + 1] = ss->lastsample >> 8;
/*
* If we have 1024 samples ready or we're at the
* end of submitting the padding samples, submit
* the packet to Sigrok.
*/
if ((j == 1023) || (ts == (tsdiff - EVENTS_PER_CLUSTER))) {
logic.length = (j + 1) * logic.unitsize;
if ((i == 1023) || (ts == (tsdiff - EVENTS_PER_CLUSTER))) {
logic.length = (i + 1) * logic.unitsize;
sr_session_send(devc->cb_data, &packet);
}
}
/* The last cluster might not be full. */
if ((i == clusters_in_line - 1) && (events_in_line % EVENTS_PER_CLUSTER))
events_in_cluster = events_in_line % EVENTS_PER_CLUSTER;
else
events_in_cluster = EVENTS_PER_CLUSTER;
/*
* Parse the samples in current cluster and prepare them
* to be submitted to Sigrok.
*/
for (j = 0; j < events_in_cluster; j++) {
samples[2 * j + 1] = dram_cluster->samples[j].sample_lo;
samples[2 * j + 0] = dram_cluster->samples[j].sample_hi;
for (i = 0; i < events_in_cluster; i++) {
samples[2 * i + 1] = dram_cluster->samples[i].sample_lo;
samples[2 * i + 0] = dram_cluster->samples[i].sample_hi;
}
/* Send data up to trigger point (if triggered). */
@ -1064,13 +1028,62 @@ static int decode_chunk_ts(struct sigma_dram_line *dram_line, int triggerpos,
if (events_in_cluster > 0) {
packet.type = SR_DF_LOGIC;
logic.length = events_in_cluster * logic.unitsize;
logic.data = samples +
(trigger_offset * logic.unitsize);
logic.data = samples + (trigger_offset * logic.unitsize);
sr_session_send(devc->cb_data, &packet);
}
ss->lastsample = samples[2 * (events_in_cluster - 1)] |
ss->lastsample =
samples[2 * (events_in_cluster - 1) + 0] |
(samples[2 * (events_in_cluster - 1) + 1] << 8);
}
/*
* Decode chunk of 1024 bytes, 64 clusters, 7 events per cluster.
* Each event is 20ns apart, and can contain multiple samples.
*
* For 200 MHz, events contain 4 samples for each channel, spread 5 ns apart.
* For 100 MHz, events contain 2 samples for each channel, spread 10 ns apart.
* For 50 MHz and below, events contain one sample for each channel,
* spread 20 ns apart.
*/
static int decode_chunk_ts(struct sigma_dram_line *dram_line, int triggerpos,
uint16_t events_in_line, void *cb_data)
{
struct sigma_dram_cluster *dram_cluster;
struct sr_dev_inst *sdi = cb_data;
struct dev_context *devc = sdi->priv;
unsigned int clusters_in_line =
(events_in_line + (EVENTS_PER_CLUSTER - 1)) / EVENTS_PER_CLUSTER;
unsigned int events_in_cluster;
unsigned int i;
int triggerts = -1;
/* Check if trigger is in this chunk. */
if (triggerpos != -1) {
if (devc->cur_samplerate <= SR_MHZ(50))
triggerpos -= EVENTS_PER_CLUSTER - 1;
if (triggerpos < 0)
triggerpos = 0;
/* Find in which cluster the trigger occured. */
triggerts = triggerpos / EVENTS_PER_CLUSTER;
}
/* For each full DRAM cluster. */
for (i = 0; i < clusters_in_line; i++) {
dram_cluster = &dram_line->cluster[i];
/* The last cluster might not be full. */
if ((i == clusters_in_line - 1) &&
(events_in_line % EVENTS_PER_CLUSTER)) {
events_in_cluster = events_in_line % EVENTS_PER_CLUSTER;
} else {
events_in_cluster = EVENTS_PER_CLUSTER;
}
sigma_decode_dram_cluster(dram_cluster, events_in_cluster, sdi);
}
return SR_OK;