OpenCores
URL https://opencores.org/ocsvn/wbscope/wbscope/trunk

Subversion Repositories wbscope

[/] [wbscope/] [trunk/] [sw/] [scopecls.cpp] - Diff between revs 12 and 13

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 12 Rev 13
Line 54... Line 54...
bool    SCOPE::ready() {
bool    SCOPE::ready() {
        unsigned v;
        unsigned v;
        v = m_fpga->readio(m_addr);
        v = m_fpga->readio(m_addr);
        if (m_scoplen == 0) {
        if (m_scoplen == 0) {
                m_scoplen = (1<<((v>>20)&0x01f));
                m_scoplen = (1<<((v>>20)&0x01f));
 
                m_holdoff = (v & ((1<<20)-1));
        } v = (v>>28)&6;
        } v = (v>>28)&6;
        return (v==6);
        return (v==6);
}
}
 
 
void    SCOPE::decode_control(void) {
void    SCOPE::decode_control(void) {
        unsigned        v;
        unsigned        v;
 
 
        v = m_fpga->readio(m_addr);
        v = m_fpga->readio(m_addr);
 
        printf("\tCNTRL-REG:\t0x%08x\n", v);
        printf("\t31. RESET:\t%s\n", (v&0x80000000)?"Ongoing":"Complete");
        printf("\t31. RESET:\t%s\n", (v&0x80000000)?"Ongoing":"Complete");
        printf("\t30. STOPPED:\t%s\n", (v&0x40000000)?"Yes":"No");
        printf("\t30. STOPPED:\t%s\n", (v&0x40000000)?"Yes":"No");
        printf("\t29. TRIGGERED:\t%s\n", (v&0x20000000)?"Yes":"No");
        printf("\t29. TRIGGERED:\t%s\n", (v&0x20000000)?"Yes":"No");
        printf("\t28. PRIMED:\t%s\n", (v&0x10000000)?"Yes":"No");
        printf("\t28. PRIMED:\t%s\n", (v&0x10000000)?"Yes":"No");
        printf("\t27. MANUAL:\t%s\n", (v&0x08000000)?"Yes":"No");
        printf("\t27. MANUAL:\t%s\n", (v&0x08000000)?"Yes":"No");
Line 82... Line 84...
        // If the scope length is zero, then the scope isn't present.
        // If the scope length is zero, then the scope isn't present.
        // We use a length of zero here to also represent whether or not we've
        // We use a length of zero here to also represent whether or not we've
        // looked up the length by reading from the scope.
        // looked up the length by reading from the scope.
        if (m_scoplen == 0) {
        if (m_scoplen == 0) {
                v = m_fpga->readio(m_addr);
                v = m_fpga->readio(m_addr);
 
                m_holdoff = (v & ((1<<20)-1));
 
 
                // Since the length of the scope memory is a configuration
                // Since the length of the scope memory is a configuration
                // parameter internal to the scope, we read it here to find
                // parameter internal to the scope, we read it here to find
                // out how the scope was configured.
                // out how the scope was configured.
                lgln = (v>>20) & 0x1f;
                lgln = (v>>20) & 0x1f;
Line 139... Line 142...
                        m_data[i] = m_fpga->readio(m_addr+4);
                        m_data[i] = m_fpga->readio(m_addr+4);
        }
        }
}
}
 
 
void    SCOPE::print(void) {
void    SCOPE::print(void) {
        DEVBUS::BUSW    addrv = 0;
        unsigned long addrv = 0, alen;
 
        int     offset;
 
 
        rawread();
        rawread();
 
 
 
        // Count how many values are in our (possibly compressed) buffer.
 
        // If it weren't for the compression, this'd be m_scoplen
 
        alen = getaddresslen();
 
 
 
        // If the holdoff is zero, the triggered item is the very
 
        // last one.
 
        offset = alen - m_holdoff -1;
 
 
        if(m_compressed) {
        if(m_compressed) {
                for(int i=0; i<(int)m_scoplen; i++) {
                for(int i=0; i<(int)m_scoplen; i++) {
                        if ((m_data[i]>>31)&1) {
                        if ((m_data[i]>>31)&1) {
                                addrv += (m_data[i]&0x7fffffff);
                                addrv += (m_data[i]&0x7fffffff) + 1;
                                printf(" ** (+0x%08x = %8d)\n",
                                printf(" ** (+0x%08x = %8d)\n",
                                        (m_data[i]&0x07fffffff),
                                        (m_data[i]&0x07fffffff),
                                        (m_data[i]&0x07fffffff));
                                        (m_data[i]&0x07fffffff));
                                continue;
                                continue;
                        }
                        }
                        printf("%10d %08x: ", addrv++, m_data[i]);
                        printf("%10ld %08x: ", addrv++, m_data[i]);
                        decode(m_data[i]);
                        decode(m_data[i]);
 
                        if ((int)addrv == offset)
 
                                printf(" <--- TRIGGER");
                        printf("\n");
                        printf("\n");
                }
                }
        } else {
        } else {
                for(int i=0; i<(int)m_scoplen; i++) {
                for(int i=0; i<(int)m_scoplen; i++) {
                        if ((i>0)&&(m_data[i] == m_data[i-1])&&(i<(int)(m_scoplen-1))) {
                        if ((i>0)&&(m_data[i] == m_data[i-1])&&(i<(int)(m_scoplen-1))) {
                                if ((i>2)&&(m_data[i] != m_data[i-2]))
                                if ((i>2)&&(m_data[i] != m_data[i-2]))
                                        printf(" **** ****\n");
                                        printf(" **** ****\n");
                                continue;
                                continue;
                        } printf("%9d %08x: ", i, m_data[i]);
                        } printf("%9d %08x: ", i, m_data[i]);
                        decode(m_data[i]);
                        decode(m_data[i]);
 
 
 
                        if (i == offset)
 
                                printf(" <--- TRIGGER");
                        printf("\n");
                        printf("\n");
                }
                }
        }
        }
}
}
 
 
void    SCOPE::write_trace_timescale(FILE *fp) {
void    SCOPE::write_trace_timescale(FILE *fp) {
        fprintf(fp, "$timescle 1ns $end\n\n");
        fprintf(fp, "$timescale 1ns $end\n\n");
 
}
 
 
 
void    SCOPE::write_trace_timezero(FILE *fp, int offset) {
 
        double          dwhen;
 
        long            when_ns;
 
 
 
        dwhen = 1.0/((double)m_clkfreq_hz) * (offset);
 
        when_ns = (unsigned long)(dwhen * 1e9);
 
        fprintf(fp, "$timezero %ld $end\n\n", -when_ns);
}
}
 
 
// $dumpoff and $dumpon
// $dumpoff and $dumpon
void    SCOPE::write_trace_header(FILE *fp) {
void    SCOPE::write_trace_header(FILE *fp, int offset) {
        time_t  now;
        time_t  now;
 
 
        time(&now);
        time(&now);
        fprintf(fp, "$version Generated by WBScope $end\n");
        fprintf(fp, "$version Generated by WBScope $end\n");
        fprintf(fp, "$date %s\n $end\n", ctime(&now));
        fprintf(fp, "$date %s\n $end\n", ctime(&now));
        write_trace_timescale(fp);
        write_trace_timescale(fp);
 
        if (offset != 0)
 
                write_trace_timezero(fp, offset);
 
 
        fprintf(fp, " $scope module WBSCOPE $end\n");
        fprintf(fp, " $scope module WBSCOPE $end\n");
        // Print out all of the various values
        // Print out all of the various values
 
        if (m_compressed) {
 
                fprintf(fp, "  $var wire %2d \'R _raw_data [%d:0] $end\n", 31,
 
                        30);
 
        } else {
        fprintf(fp, "  $var wire %2d \'C clk $end\n", 1);
        fprintf(fp, "  $var wire %2d \'C clk $end\n", 1);
        fprintf(fp, "  $var wire %2d \'R _raw_data [%d:0] $end\n",
                fprintf(fp, "  $var wire %2d \'R _raw_data [%d:0] $end\n", 32,
                        (m_compressed)?31:32,
                        31);
                        (m_compressed)?30:31);
        }
 
 
 
        // Add in a fake _trigger variable to the VCD file we are producing,
 
        // so we can see when our trigger took place (assuming the holdoff is
 
        // such that it is within the collect)
 
        fprintf(fp, "  $var wire %2d \'T _trigger $end\n", 1);
 
 
        for(unsigned i=0; i<m_traces.size(); i++) {
        for(unsigned i=0; i<m_traces.size(); i++) {
                TRACEINFO *info = m_traces[i];
                TRACEINFO *info = m_traces[i];
                fprintf(fp, "  $var wire %2d %s %s",
                fprintf(fp, "  $var wire %2d %s %s",
                        info->m_nbits, info->m_key, info->m_name);
                        info->m_nbits, info->m_key, info->m_name);
Line 244... Line 281...
        info->m_key[3] = '\0';
        info->m_key[3] = '\0';
 
 
        m_traces.push_back(info);
        m_traces.push_back(info);
}
}
 
 
void    SCOPE::define_traces(void) {}
/*
 
 * getaddresslen(void)
void    SCOPE::writevcd(const char *trace_file_name) {
 *
        FILE    *fp = fopen(trace_file_name, "w");
 * Returns the number of items in the scope's buffer.  For the uncompressed
 
 * scope, this is just the size of hte scope.  For the compressed scope ... this
 
 * is a touch longer.
 
 */
 
unsigned        SCOPE::getaddresslen(void) {
 
        // Find the offset to the trigger
 
        if (m_compressed) {
 
                // First, find the overall length
 
                //
 
                // If we are compressed, then *every* item increments
 
                // the address length
 
                unsigned alen = m_scoplen;
 
                //
 
                // Some items increment it more.
 
                for(int i=0; i<(int)m_scoplen; i++) {
 
                        if ((m_data[i]&0x80000000)&&(i!=0))
 
                                alen += m_data[i] & 0x7fffffff;
 
                }
 
 
        if (fp == NULL) {
                return alen;
                fprintf(stderr, "ERR: Cannot open %s for writing!\n", trace_file_name);
        } return m_scoplen;
                fprintf(stderr, "ERR: Trace file not written\n");
 
                return;
 
        }
        }
 
 
 
/*
 
 * define_traces
 
 *
 
 * This is a user stub.  User programs should define this function.
 
 */
 
void    SCOPE::define_traces(void) {}
 
 
 
void    SCOPE::writevcd(FILE *fp) {
 
        unsigned        alen;
 
        int     offset = 0;
 
 
        if (!m_data)
        if (!m_data)
                rawread();
                rawread();
 
 
        write_trace_header(fp);
        // If the traces haven't yet been defined, then define them now.
 
        if (m_traces.size()==0)
 
                define_traces();
 
 
 
        // Count how many values are in our (possibly compressed) buffer.
 
        // If it weren't for the compression, this'd be m_scoplen
 
        alen = getaddresslen();
 
 
 
        // If the holdoff is zero, the triggered item is the very
 
        // last one.
 
        offset = alen - m_holdoff -1;
 
 
 
        // Write the file header.
 
        write_trace_header(fp, offset);
 
 
 
        // And split into two paths--one for compressed scopes (wbscopc), and
 
        // the other for the more normal scopes (wbscope).
 
        if(m_compressed) {
 
                // With compressed scopes, you need to track the address
 
                // relative to the beginning.
 
                unsigned long   addrv = 0;
 
                unsigned long   now_ns;
 
                double          dnow;
 
                bool            last_trigger = true;
 
 
 
                // Loop over each data word read from the scope
 
                for(int i=0; i<(int)m_scoplen; i++) {
 
                        // If the high bit is set, the address jumps by more
 
                        // than an increment
 
                        if ((m_data[i]>>31)&1) {
 
                                if (i!=0) {
 
                                        if (last_trigger) {
 
                                                // If the trigger was valid
 
                                                // on the last clock, then we
 
                                                // need to include the change
 
                                                // to drop it.
 
                                                //
 
                                                dnow   = 1.0/((double)m_clkfreq_hz) * (addrv+1);
 
                                                now_ns = (unsigned long)(dnow * 1e9);
 
                                                fprintf(fp, "#%ld\n", now_ns);
 
                                                fprintf(fp, "0\'T\n");
 
                                        }
 
                                        // But ... with nothing to write out.
 
                                        addrv += (m_data[i]&0x7fffffff) + 1;
 
                                } continue;
 
                        }
 
 
 
                        // Produce a line identifying the time associated with
 
                        // this piece of data.
 
                        //
 
                        // dnow is the current time represented as a double
 
                        dnow = 1.0/((double)m_clkfreq_hz) * addrv;
 
                        // Convert to nanoseconds, and to integers.
 
                        now_ns = (unsigned long)(dnow * 1e9);
 
 
 
                        fprintf(fp, "#%ld\n", now_ns);
 
 
 
                        if ((int)(addrv-alen) == offset) {
 
                                fprintf(fp, "1\'T\n");
 
                                last_trigger = true;
 
                        } else if (last_trigger)
 
                                fprintf(fp, "0\'T\n");
 
 
 
                        // For compressed data, only the lower 31 bits are
 
                        // valid.  Write those bits to the VCD file as a raw
 
                        // value.
 
                        write_binary_trace(fp, 31, m_data[i], "\'R\n");
 
 
 
                        // Finally, walk through all of the user defined traces,
 
                        // writing each to the VCD file.
 
                        for(unsigned k=0; k<m_traces.size(); k++) {
 
                                TRACEINFO *info = m_traces[k];
 
                                write_binary_trace(fp, info, m_data[i]);
 
                        }
 
 
 
                        addrv++;
 
                }
 
        } else {
 
                //
 
                // Uncompressed scope.
 
                //
 
                unsigned now_ns;
 
                double  dnow;
 
 
 
                // We assume a clock signal, and set it to one and zero.
 
                // We also assume everything changes on the positive edge of
 
                // that clock within here.
 
 
 
                // Loop over all data words
        for(int i=0; i<(int)m_scoplen; i++) {
        for(int i=0; i<(int)m_scoplen; i++) {
                // Positive edge of the clock (everything is assumed to
                // Positive edge of the clock (everything is assumed to
                // be on the positive edge)
                // be on the positive edge)
                fprintf(fp, "#%d\n", m_scoplen * 10);
 
 
 
 
                        //
 
                        // Clock goes high
 
                        //
 
 
 
                        // Write the current (relative) time of this data word
 
                        dnow = 1.0/((double)m_clkfreq_hz) * i;
 
                        now_ns = (unsigned)(dnow * 1e9 + 0.5);
 
                        fprintf(fp, "#%d\n", now_ns);
 
 
                fprintf(fp, "1\'C\n");
                fprintf(fp, "1\'C\n");
                write_binary_trace(fp, (m_compressed)?31:32,
                write_binary_trace(fp, (m_compressed)?31:32,
                        m_data[i], "\'R\n");
                        m_data[i], "\'R\n");
 
 
 
                        if (i == offset)
 
                                fprintf(fp, "1\'T\n");
 
                        else // if (addrv == offset+1)
 
                                fprintf(fp, "0\'T\n");
 
 
                for(unsigned k=0; k<m_traces.size(); k++) {
                for(unsigned k=0; k<m_traces.size(); k++) {
                        TRACEINFO *info = m_traces[k];
                        TRACEINFO *info = m_traces[k];
                        write_binary_trace(fp, info, m_data[i]);
                        write_binary_trace(fp, info, m_data[i]);
                }
                }
 
 
 
                        //
                // Clock goes to zero
                // Clock goes to zero
                fprintf(fp, "#%d\n", m_scoplen * 10 + 5);
                        //
 
 
 
                        // Add half a clock period to our time
 
                        dnow += 1.0/((double)m_clkfreq_hz)/2.;
 
                        now_ns = (unsigned)(dnow * 1e9 + 0.5);
 
                        fprintf(fp, "#%d\n", now_ns);
 
 
 
                        // Now finally write the clock as zero.
                fprintf(fp, "0\'C\n");
                fprintf(fp, "0\'C\n");
        }
        }
}
}
 
}
 
 
 
/*
 
 * writevcd
 
 *
 
 * Main user entry point for VCD file creation.  This just opens a file of the
 
 * given name, and writes the VCD info to it.  If the file cannot be opened,
 
 * an error is written to the standard error stream, and the routine returns.
 
 */
 
void    SCOPE::writevcd(const char *trace_file_name) {
 
        FILE    *fp = fopen(trace_file_name, "w");
 
 
 
        if (fp == NULL) {
 
                fprintf(stderr, "ERR: Cannot open %s for writing!\n", trace_file_name);
 
                fprintf(stderr, "ERR: Trace file not written\n");
 
                return;
 
        }
 
 
 
        writevcd(fp);
 
 
 
        fclose(fp);
 
}
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.