Compare commits

..

No commits in common. "2d853d7804f2a3338a3b88ce45a405798ad85615" and "dd6bf3ef4081cf79aa6a4d01bbadc63b56d6bfb0" have entirely different histories.

5 changed files with 38 additions and 44 deletions

View file

@ -27,15 +27,15 @@ static struct ads8688_control {
void ads8688_readings(struct ads8688_control *c, unsigned int cc, int i, int ii) void ads8688_readings(struct ads8688_control *c, unsigned int cc, int i, int ii)
{ {
unsigned short first = ssp_scratch[i]; unsigned short first = ssp_buffer[i];
unsigned int sum = first; unsigned int sum = first;
int square = 0; int square = 0;
int n = 1; int n = 1;
unsigned short sdo = 0; unsigned short sdo = 0;
if (!i && ii > 1) if (!i && ii > 1)
sdo = ssp_scratch[1]; sdo = ssp_buffer[1];
while ((i+=ii) < c->nbuf) { while ((i+=ii) < c->nbuf) {
int d = ssp_scratch[i]; int d = ssp_buffer[i];
sum += d; sum += d;
d -= first; d -= first;
square += d*d; square += d*d;
@ -83,7 +83,6 @@ static int read_cb(struct ads8688_control *c)
return alldone_cb(c); return alldone_cb(c);
c->frame = 0xc000 | cc << 10; c->frame = 0xc000 | cc << 10;
ssp_set_buffer(0, c->nbuf); ssp_set_buffer(0, c->nbuf);
ssp_assert_ssel();
return ssp_submit_batch(&c->frame, 1, 2, 0, 0); return ssp_submit_batch(&c->frame, 1, 2, 0, 0);
} }
@ -113,7 +112,6 @@ static int read_auto_cb(struct ads8688_control *c)
else else
return tcnh_cb(c); return tcnh_cb(c);
ssp_set_buffer(0, n); ssp_set_buffer(0, n);
ssp_assert_ssel();
return ssp_submit_batch(&c->frame, 1, 2, 0, 0); return ssp_submit_batch(&c->frame, 1, 2, 0, 0);
} }
@ -135,7 +133,7 @@ static int gains_cb(struct ads8688_control *c)
unsigned short f = c->frame; unsigned short f = c->frame;
if (f & 0xe000) if (f & 0xe000)
return tcnh_cb(c); return tcnh_cb(c);
unsigned int cc = save_gain(f, *ssp_scratch, &c->gains); unsigned int cc = save_gain(f, *ssp_buffer, &c->gains);
cc++; cc++;
if (cc == 12) if (cc == 12)
cc = 0; cc = 0;
@ -163,18 +161,19 @@ static const struct ssp_batch ads8688_batch[] = {
{ .ssel = &ssp_conf_adc }, { .ssel = &ssp_conf_adc },
}, },
[1] = { [1] = {
.flags = ssp_b_call, .flags = ssp_b_call
| ssp_b_deassert,
{ .callback = ads8688_cb }, { .callback = ads8688_cb },
{ .data = &ads8688_control }, { .data = &ads8688_control },
}, },
[2] = { [2] {
.flags = ssp_b_job .flags = ssp_b_job
| SSP_B_REPEAT(256) | ssp_b_whilebuf | SSP_B_REPEAT(256) | ssp_b_whilebuf
| ssp_b_deassert | ssp_b_assert | SSP_B_DELAY(10), | ssp_b_assert | SSP_B_DELAY(10),
{ .job = &ads8688_control.job}, { .job = &ads8688_control.job},
{ .match = &ads8688_control.match}, { .match = &ads8688_control.match},
}, },
[3] = { [3] {
.flags = ssp_b_goto .flags = ssp_b_goto
| ssp_b_stop | ssp_b_deassert, | ssp_b_stop | ssp_b_deassert,
{ .batch = 0 }, { .batch = 0 },

View file

@ -633,6 +633,7 @@ def init_irena(scope, name="xRENA", prod=None, options="", long_options=[]):
else: else:
_ifc_uart = uartterm.init_uart(scope=scope, prefix="serial_", dname=name, addr=v, isp=False) _ifc_uart = uartterm.init_uart(scope=scope, prefix="serial_", dname=name, addr=v, isp=False)
_ifc_uart._shell_scope = scope _ifc_uart._shell_scope = scope
_ifc_uart.uart.wait_for_message(b"Altera")
if o in "-N --network": if o in "-N --network":
import udpterm import udpterm
_ifc = udpterm.init_udp(scope=scope, dname=name, addr=v) _ifc = udpterm.init_udp(scope=scope, dname=name, addr=v)
@ -647,7 +648,7 @@ def init_irena(scope, name="xRENA", prod=None, options="", long_options=[]):
vvv=vv.split(".") vvv=vv.split(".")
bus = int(vvv[0]) if vvv[0] else None bus = int(vvv[0]) if vvv[0] else None
address = int(vvv[1]) if len(vvv)>1 and vvv[1] else None address = int(vvv[1]) if len(vvv)>1 and vvv[1] else None
if _ifc_uart: if bus and _ifc_uart:
address = _ifc_uart.uart.wait_for_usb() address = _ifc_uart.uart.wait_for_usb()
_ifc = usbterm.init_usb(scope=scope, dname=name, _ifc = usbterm.init_usb(scope=scope, dname=name,
prod=prod, bus=bus, address=address) prod=prod, bus=bus, address=address)

48
ssp.c
View file

@ -68,19 +68,17 @@ static void ssp_isr(void)
unsigned int dr = SSPDR; unsigned int dr = SSPDR;
sr=SSPSR; sr=SSPSR;
nread++; nread++;
fr++;
if (!rc if (!rc
&& fr >= ssp_match.frame_count && fr >= ssp_match.frame_count
&& (fr == ssp_match.frame_count || ssp_match.mask) && (fr == ssp_match.frame_count || ssp_match.mask)
&& (dr & ssp_match.mask) == ssp_match.value) { && (dr & ssp_match.mask) == ssp_match.value) {
rc = ssp_match.read_count; rc = ssp_match.read_count;
if (ssp_match.count) { if (ssp_match.count)
int c = 1 + fr + ssp_match.count - ssp_frames_sent; j->count = ssp_match.count
if (c < 0) + ssp_match.frame_count
c = 0; - ssp_frames_sent;
j->count = c;
}
} }
fr++;
if (rc) { if (rc) {
rc--; rc--;
unsigned int bc = j->buf_count; unsigned int bc = j->buf_count;
@ -343,6 +341,9 @@ int ssp_run_batch()
if (f & ssp_b_scratch) if (f & ssp_b_scratch)
ssp_set_buffer(0, -1); ssp_set_buffer(0, -1);
if (c == ssp_b_buffer)
ssp_set_buffer(batch->buffer, f & 0xffff);
if (f & ssp_b_deassert) { if (f & ssp_b_deassert) {
ssp_deassert_ssel(); ssp_deassert_ssel();
ssel_delay(f); ssel_delay(f);
@ -373,24 +374,12 @@ int ssp_run_batch()
if (buffer_empty) if (buffer_empty)
continue; continue;
if (c == ssp_b_job) {
if (batch->match)
ssp_match = *batch->match;
else
memset(&ssp_match, 0, sizeof(ssp_match));
if (batch->job && batch->job->count)
return ssp_submit_job(batch->job);
}
if (c == ssp_b_buffer)
ssp_set_buffer(batch->buffer, f & 0xffff);
if (c == ssp_b_call) { if (c == ssp_b_call) {
int r = batch->callback(batch); int c = batch->callback(batch);
if (r != -1) { if (c != -1) {
if (r) if (c)
ssp_batch = 0; ssp_batch = 0;
return r; return c;
} }
} }
@ -406,6 +395,15 @@ int ssp_run_batch()
ssp_batch += batch->offset; ssp_batch += batch->offset;
} }
if (c == ssp_b_job) {
if (batch->match)
ssp_match = *batch->match;
else
memset(&ssp_match, 0, sizeof(ssp_match));
if (batch->job && batch->job->count)
return ssp_submit_job(batch->job);
}
if (c == ssp_b_wait) { if (c == ssp_b_wait) {
const struct timer_wait *wait = batch->wait; const struct timer_wait *wait = batch->wait;
if (!wait) { if (!wait) {
@ -668,8 +666,8 @@ int ssp_resp_cmd(struct command *cmd, const struct command_par *par)
if (what & 0x01000000 || r) { if (what & 0x01000000 || r) {
if (r) if (r)
code++; code++;
parser_format_message(cmd, "%03d ssp busy: 0x%x [%u] ssel 0x%08x mode 0x%04x\n", parser_format_message(cmd, "%03d ssp busy: 0x%x ssel 0x%08x mode 0x%04x\n",
code, r, job.buf_count, ssp_config.ssel, ssp_config.mode); code, r, ssp_config.ssel, ssp_config.mode);
return code; return code;
} }
} }

2
ssp.h
View file

@ -15,7 +15,7 @@ unsigned int ssp_busy(void);
int ssp_wait(int timeout); int ssp_wait(int timeout);
extern unsigned int ssp_bits; extern unsigned int ssp_bits;
extern unsigned short *ssp_buffer; unsigned short *ssp_buffer;
extern unsigned int ssp_ssel_mask; extern unsigned int ssp_ssel_mask;
extern unsigned int ssp_ssel; extern unsigned int ssp_ssel;
extern unsigned int ssp_read_size; extern unsigned int ssp_read_size;

View file

@ -872,6 +872,7 @@ class irena_uart(irena_ifc):
irena_ifc.__init__(self, dname=dname) irena_ifc.__init__(self, dname=dname)
self._data = uart(self, dev, baudrate) self._data = uart(self, dev, baudrate)
self.uart = self._data self.uart = self._data
self.resp = self._data.resp
if isp: if isp:
self._prompt += "-ISP" self._prompt += "-ISP"
self.uart.Init_ISP() self.uart.Init_ISP()
@ -880,19 +881,14 @@ class irena_uart(irena_ifc):
_CMDN = 1 # skip the first response character _CMDN = 1 # skip the first response character
def ucmd(self, c, timeout=10000, raise_e=None): def cmd(self, c, timeout=10000):
self._data.flush_responses() self._data.flush_responses()
self._data.serial.write(utf8_encode(c).strip()+b'\n') self._data.serial.write(utf8_encode(c).strip()+b'\n')
r = self._data.resp(timeout=timeout/1000) r = self._data.resp(timeout=timeout/1000.)
if self.verbosity >= 2: if self.verbosity >= 2:
sys.stderr.write("sent: %s recv: %s\n" % (repr(c),repr(r))) sys.stderr.write("sent: %s recv: %s\n" % (repr(c),repr(r)))
return r return r
def resp(self, timeout=1000, raise_e=None):
return self._data.resp(timeout = timeout/1000,
blocking = timeout > 0,
verbose = self.verbosity )
DataThread = None DataThread = None
class md3_gse(uart): class md3_gse(uart):