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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [usbi.cpp] - Diff between revs 46 and 91

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

Rev 46 Rev 91
Line 11... Line 11...
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015, Gisselquist Technology, LLC
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
Line 42... Line 42...
#include <libusb.h>
#include <libusb.h>
 
 
#include "llcomms.h"
#include "llcomms.h"
#include "usbi.h"
#include "usbi.h"
 
 
 
const   bool    DEBUG = false;
 
 
// Walk us through the JTAG Chain:
// Walk us through the JTAG Chain:
//      5-1's to go to test/reset
//      5-1's to go to test/reset
//      0        to go to Run-Test/Idle
//      0        to go to Run-Test/Idle
//      1       to go to select-dr-scan
//      1       to go to select-dr-scan
//      1       to go to select-ir-scan
//      1       to go to select-ir-scan
Line 289... Line 291...
        if (len > RCV_BUFMASK-avail)
        if (len > RCV_BUFMASK-avail)
                len = RCV_BUFMASK-avail;
                len = RCV_BUFMASK-avail;
        if (len > 26)
        if (len > 26)
                len = 26;
                len = 26;
 
 
        // printf("USBI::RAW-READ(%d, was %d)\n", len, clen);
        if (DEBUG) printf("USBI::RAW-READ(%d, was %d)\n", len, clen);
        memcpy(m_txbuf, REQ_RX_BITS, REQ_RX_LEN);
        memcpy(m_txbuf, REQ_RX_BITS, REQ_RX_LEN);
 
 
        // I have chased process hangs to this line, but have no more
        // I have chased process hangs to this line, but have no more
        // information than that somewhere within libusb_bulk_transfer,
        // information than that somewhere within libusb_bulk_transfer,
        // libusb_handle_events_completed,
        // libusb_handle_events_completed,
Line 304... Line 306...
        // Xess tools.  I will note that, when a followup attempt is made
        // Xess tools.  I will note that, when a followup attempt is made
        // to read from the device, previously unread data may still get dumped
        // to read from the device, previously unread data may still get dumped
        // to it.  Therefore, be careful to clear the device upon starting
        // to it.  Therefore, be careful to clear the device upon starting
        // any process.
        // any process.
        //
        //
        // fprintf(stderr, "[");
        if(DEBUG) { printf("["); fflush(stdout); }
        int r = libusb_bulk_transfer(m_xula_usb_device, XESS_ENDPOINT_OUT,
        int r = libusb_bulk_transfer(m_xula_usb_device, XESS_ENDPOINT_OUT,
                (unsigned char *)m_txbuf, REQ_RX_LEN, &actual_length,
                (unsigned char *)m_txbuf, REQ_RX_LEN, &actual_length,
                timeout_ms);
                timeout_ms);
        // fprintf(stderr, "]");
        if(DEBUG) { printf("]"); fflush(stdout); }
 
 
        if ((r==0)&&(actual_length == REQ_RX_LEN)) {
        if ((r==0)&&(actual_length == REQ_RX_LEN)) {
        } else if (r == -7) {
        } else if (r == -7) {
                // Nothing to read in the timeout provided
                // Nothing to read in the timeout provided
                // We'll have to request this data again ... later
                // We'll have to request this data again ... later
Line 327... Line 329...
 
 
        // Try to read back however many bytes we can
        // Try to read back however many bytes we can
        r = libusb_bulk_transfer(m_xula_usb_device, XESS_ENDPOINT_IN,
        r = libusb_bulk_transfer(m_xula_usb_device, XESS_ENDPOINT_IN,
                (unsigned char *)m_rxbuf, USB_PKTLEN, &actual_length, 0);
                (unsigned char *)m_rxbuf, USB_PKTLEN, &actual_length, 0);
        if ((r==0)&&(actual_length > 0)) {
        if ((r==0)&&(actual_length > 0)) {
                /*
                if (DEBUG) {
                printf("RAW-READ() -> %d Read\n", actual_length);
                        printf("RAW-READ() -> %d Read\n", actual_length);
                for(int i=0; i<actual_length; i++)
                        for(int i=0; i<actual_length; i++)
                        printf("%02x ", m_rxbuf[i] & 0x0ff);
                                printf("%02x ", m_rxbuf[i] & 0x0ff);
                printf("\n");
                        printf("\n");
                */
                }
                push_fifo(m_rxbuf, actual_length);
                push_fifo(m_rxbuf, actual_length);
        } else if (r == -7) {
        } else if (r == -7) {
                // Nothing to read in the timeout provided
                // Nothing to read in the timeout provided
                // Return, adding nothing to our FIFO
                // Return, adding nothing to our FIFO
        } else {
        } else {
Line 359... Line 361...
        char    *sptr = buf;
        char    *sptr = buf;
 
 
        // printf("Pushing %d items onto FIFO (%d - %d)\n", len, m_rend, m_rbeg);
        // printf("Pushing %d items onto FIFO (%d - %d)\n", len, m_rend, m_rbeg);
        if (m_rbeg != m_rend)
        if (m_rbeg != m_rend)
                last = m_rbuf[m_rend];
                last = m_rbuf[m_rend];
 
        if (DEBUG)
 
                printf("\tPushing:");
        for(int i=0; i<len; i++) {
        for(int i=0; i<len; i++) {
                char v = *sptr++;
                char v = *sptr++;
                if (((v & 0x80)||((unsigned char)v < 0x10))&&(v == last)) {
                if (((v & 0x80)||((unsigned char)v < 0x10))&&(v == last)) {
                        // printf("\tSkipping: %02x\n", v & 0x0ff);
                        // printf("\tSkipping: %02x\n", v & 0x0ff);
                } else if ((unsigned char)v == 0x0ff) {
                } else if ((unsigned char)v == 0x0ff) {
                } else {
                } else {
                        m_rbuf[m_rbeg] = v;
                        m_rbuf[m_rbeg] = v;
                        m_rbeg = (m_rbeg+1)&(RCV_BUFMASK);
                        m_rbeg = (m_rbeg+1)&(RCV_BUFMASK);
                        // printf("\tPushing: %02x\n", v & 0x0ff);
                        if (DEBUG)
 
                                printf(" %02x", v & 0x0ff);
                } last = v;
                } last = v;
        }
        } if (DEBUG) printf("\n");
}
}
 
 
int     USBI::pop_fifo(char *buf, int len) {
int     USBI::pop_fifo(char *buf, int len) {
        int     avail = (m_rbeg - m_rend)&(RCV_BUFMASK);
        int     avail = (m_rbeg - m_rend)&(RCV_BUFMASK);
        int     left = len;
        int     left = len;
Line 391... Line 396...
                left   -= ln;
                left   -= ln;
                avail  -= ln;
                avail  -= ln;
                m_rend  = (m_rend + ln)&(RCV_BUFMASK);
                m_rend  = (m_rend + ln)&(RCV_BUFMASK);
                nr     += ln;
                nr     += ln;
 
 
        //      printf("P:");
                if (DEBUG) {
        //      for(int i=0; i<ln; i++)
                        printf("P:");
        //              printf("%02x ", buf[len-left-ln+i]);
                        for(int i=0; i<ln; i++)
        } // printf("\n");
                                printf("%02x ", buf[len-left-ln+i]);
 
                }
 
        } if (DEBUG) printf("\n");
 
 
        /*
        /*
        if (nr > 0)
        if (nr > 0)
                printf("\tPopped %d items, buf[0] = %02x (%d - %d)\n",
                printf("\tPopped %d items, buf[0] = %02x (%d - %d)\n",
                        nr, buf[0], m_rend, m_rbeg);
                        nr, buf[0], m_rend, m_rbeg);
Line 433... Line 440...
 
 
        // printf("USBI::poll() -> %s (%d avail)\n", (r)?"true":"false", avail);
        // printf("USBI::poll() -> %s (%d avail)\n", (r)?"true":"false", avail);
        return r;
        return r;
}
}
 
 
 No newline at end of file
 No newline at end of file
 
int     USBI::available(void) {
 
        int     avail = (m_rbeg-m_rend)&(RCV_BUFMASK);
 
 
 
        if (avail > 1)
 
                return avail;
 
        else if ((avail == 1)&&((m_rbuf[m_rend]&0x80)||(m_rbuf[m_rend]<0x10)))
 
                return 1;
 
        else
 
                return 0;
 
}
 
 
 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.