Avoid allocating 32KiB of data on stack in download_capture(). Instead,
do a glib-variant of calloc(1, ) to allocate the data for the samples
which will be downloaded. This avoids explosions of stack on systems
with tight stack limits.

Furthermore, define structures describing the organisation of Sigma's
DRAM memory and start using those instead of ad-hoc preprocessor macros
defining the sizes of various structures in memory.

Signed-off-by: Marek Vasut <[email protected]>
---
 hardware/asix-sigma/asix-sigma.c | 11 ++++++++++-
 hardware/asix-sigma/asix-sigma.h | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c
index c44bae7..7e4b3ca 100644
--- a/hardware/asix-sigma/asix-sigma.c
+++ b/hardware/asix-sigma/asix-sigma.c
@@ -1073,13 +1073,20 @@ static int download_capture(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc = sdi->priv;
        const int chunks_per_read = 32;
-       unsigned char buf[chunks_per_read * CHUNK_SIZE];
+       struct sigma_dram_line *dram_line;
+       unsigned char *buf;
        int bufsz, i, numchunks, newchunks;
        uint32_t stoppos, triggerpos;
        int triggerchunk, chunks_downloaded;
        struct sr_datafeed_packet packet;
        uint8_t modestatus;
 
+       dram_line = g_try_malloc0(chunks_per_read * sizeof(*dram_line));
+       if (!dram_line)
+               return FALSE;
+
+       buf = (unsigned char *)dram_line;
+
        sr_info("Downloading sample data.");
 
        /* Stop acquisition. */
@@ -1143,6 +1150,8 @@ static int download_capture(struct sr_dev_inst *sdi)
 
        dev_acquisition_stop(sdi, sdi);
 
+       g_free(dram_line);
+
        return TRUE;
 }
 
diff --git a/hardware/asix-sigma/asix-sigma.h b/hardware/asix-sigma/asix-sigma.h
index 1933064..87c92fb 100644
--- a/hardware/asix-sigma/asix-sigma.h
+++ b/hardware/asix-sigma/asix-sigma.h
@@ -76,6 +76,25 @@ enum sigma_read_register {
 
 #define CHUNK_SIZE             1024
 
+/*
+ * The entire ASIX Sigma DRAM is an array of struct sigma_dram_line[1024];
+ */
+
+/* One "DRAM cluster" contains a timestamp and 7 samples, 16b total. */
+struct sigma_dram_cluster {
+       uint8_t         timestamp_lo;
+       uint8_t         timestamp_hi;
+       struct {
+               uint8_t sample_hi;
+               uint8_t sample_lo;
+       }               samples[7];
+};
+
+/* One "DRAM line" contains 64 "DRAM clusters", 1024b total. */
+struct sigma_dram_line {
+       struct sigma_dram_cluster       cluster[64];
+};
+
 struct clockselect_50 {
        uint8_t async;
        uint8_t fraction;
-- 
1.8.5.3


------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to