Ejemplo n.º 1
0
def youare(devicenums):

    eio = NetEventIO("10.0.0.2")
    for d in devicenums:
        eio.addRXMask(xrange(256), int(d))

    eio.start()

    EVENTCMD_YOUARE = 0x01


    for i in devicenums:
        devicelinknum = int(i)

        for device in xrange(4):
            e = Event()
            e.cmd = EVENTCMD_YOUARE
            e.src = eaddr.NETWORK
            deviceid = 8  + devicelinknum * 4 + device
            e.data[0] = deviceid
            ea = eaddr.TXDest()
            ea[deviceid] = 1

            print "Sending youare for ", deviceid, e
            
            reallysend(eio, ea, e)
            

    eio.stop()
Ejemplo n.º 2
0
def pingset(dspboardaddrs):
    eio = NetEventIO("10.0.0.2")

    eio.addRXMask(0xF1, xrange(256))

    eio.start()

    # Create event and set mask
    N = 40
    x = n.zeros(N)
    for i in range(N):
        e = Event()
        e.src = eaddr.NETWORK
        e.cmd = 0xF0
        e.data[0] = 0x1234

        ea = eaddr.TXDest()
        for d in dspboardaddrs:
            ea[d] = 1

        eio.sendEvent(ea, e)
        erx = eio.getEvents()
        x[i] = len(erx)
    eio.stop()
    pylab.figure()
    pylab.hist(x)
Ejemplo n.º 3
0
def pingset(dspboardaddrs):
    eio = NetEventIO("10.0.0.2")

    eio.addRXMask(0xF1, xrange(256))

    eio.start()

    # Create event and set mask
    N = 40
    x = n.zeros(N)
    for i in range(N):
        e = Event()
        e.src = eaddr.NETWORK
        e.cmd =  0xF0
        e.data[0] = 0x1234

        ea = eaddr.TXDest()
        for d in dspboardaddrs:
            ea[d] = 1

        eio.sendEvent(ea, e)
        erx = eio.getEvents()
        x[i] =  len(erx)    
    eio.stop()
    pylab.figure()
    pylab.hist(x)
Ejemplo n.º 4
0
def digital_out(ip):

    
    addr = ADDR_DIGITAL_OUT
    eio = NetEventIO(ip)
    eio.addRXMask(xrange(256), [addr])
    eio.start()

    vals = True
    
    while True:
        e = Event()
        e.src = eaddr.NETWORK
        e.cmd =  DIGITALOUT_WRITE
        e.data[0] = 0xFFFF
        e.data[1] = 0xFFFF
        if vals:
            e.data[2] = 0xFFFF
            e.data[3] = 0xFFFF
        else:
            e.data[2] = 0x0
            e.data[3] = 0x0

        ea = eaddr.TXDest()
        ea[addr] = 1

        eio.sendEvent(ea, e)


        # now read

        e = Event()
        e.src = eaddr.NETWORK
        e.cmd =  DIGITALOUT_READ

        ea = eaddr.TXDest()
        ea[addr] = 1

        eio.sendEvent(ea, e)

        erx = eio.getEvents(blocking=True)
        for e in erx:
            print e
        vals = not vals
        time.sleep(0.2)
        
    eio.stop()
Ejemplo n.º 5
0
class FPGAPing(object):
    def __init__(self, somaIP, tgts):
        self.eio = NetEventIO(somaIP)
        self.pingtgts = set(tgts)

        for i in self.pingtgts:
            #self.eio.addRXMask(0x09, i)
            self.eio.addRXMask(PING_RESPONSE_CMD, i)
        self.eio.start()

    def ping(self):

        # Create event and set mask
        e = Event()
        e.src = eaddr.NETWORK
        e.cmd = 0x08
        e.data[0] = 0x1234
        e.data[1] = 0x5678

        ea = eaddr.TXDest()
        for i in self.pingtgts:
            ea[i] = 1

        self.eio.sendEvent(ea, e)

        starttime = time.time()
        PINGWAIT = 1.0
        eventsrxed = []
        while len(eventsrxed) < len(self.pingtgts):
            erx = self.eio.getEvents(blocking=False)
            if erx != None:
                for eias in erx:
                    print eias
                eventsrxed += erx
            if time.time() > starttime + PINGWAIT:
                break

        rxset = set()
        for e in eventsrxed:
            rxset.add(e.src)

        missing = self.pingtgts.difference(rxset)
        return (rxset, missing)

    def stop(self):
        self.eio.stop()
Ejemplo n.º 6
0
class FPGAPing(object):
    def __init__(self, somaIP, tgts):
        self.eio = NetEventIO(somaIP)
        self.pingtgts = set(tgts)

        for i in self.pingtgts:
            # self.eio.addRXMask(0x09, i)
            self.eio.addRXMask(PING_RESPONSE_CMD, i)
        self.eio.start()

    def ping(self):

        # Create event and set mask
        e = Event()
        e.src = eaddr.NETWORK
        e.cmd = 0x08
        e.data[0] = 0x1234
        e.data[1] = 0x5678

        ea = eaddr.TXDest()
        for i in self.pingtgts:
            ea[i] = 1

        self.eio.sendEvent(ea, e)

        starttime = time.time()
        PINGWAIT = 1.0
        eventsrxed = []
        while len(eventsrxed) < len(self.pingtgts):
            erx = self.eio.getEvents(blocking=False)
            if erx != None:
                for eias in erx:
                    print eias
                eventsrxed += erx
            if time.time() > starttime + PINGWAIT:
                break

        rxset = set()
        for e in eventsrxed:
            rxset.add(e.src)

        missing = self.pingtgts.difference(rxset)
        return (rxset, missing)

    def stop(self):
        self.eio.stop()
Ejemplo n.º 7
0
def debug(dspboardaddrs):
    eio = NetEventIO("10.0.0.2")

    eio.addRXMask(0x38, dspboardaddrs)

    eio.start()
    print "Sending to ", dspboardaddrs

    # Create event and set mask
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd = 0x38

    for d in dspboardaddrs:
        ea = eaddr.TXDest()
        ea[d] = 1
        eio.sendEvent(ea, e)
        print "sending", e
        erx = eio.getEvents()
        print erx[0]
    eio.stop()
Ejemplo n.º 8
0
def debug(dspboardaddrs):
    eio = NetEventIO("10.0.0.2")

    eio.addRXMask(0x38, dspboardaddrs)
    
    eio.start()
    print "Sending to ", dspboardaddrs
    
    # Create event and set mask
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  0x38
    
    for d in dspboardaddrs:
        ea = eaddr.TXDest()
        ea[d] = 1
        eio.sendEvent(ea, e)
        print "sending", e
        erx = eio.getEvents()
        print erx[0]
    eio.stop()
Ejemplo n.º 9
0
def ping_digital_out(ip):


    addr = DIGITAL_OUT
    eio = NetEventIO(ip)
    eio.addRXMask(PING_RESPONSE_CMD, [addr])
    eio.start()

    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  0x08
    e.data[0] = 0x1234
    e.data[1] = 0x5678

    ea = eaddr.TXDest()
    ea[addr] = 1

    eio.sendEvent(ea, e)

    erx = eio.getEvents(blocking=True)
    for e in erx:
        print e

    eio.stop()
Ejemplo n.º 10
0
class AcqBoardInterface(object):

    CMDFIBERCMD = 0x50
    CMDFIBERDATAA = 128
    CMDFIBERDATAB = 129
    CMDFIBERRESP = 0x82

    DESTSRCID = 76
    
    
    def __init__(self, IP="10.0.0.2", set = 'A'):
        self.eio = NetEventIO(IP)
        self.set = set
        

    def sendCommandAndBlock(self, acqboardcmd):
        """
        acqboardcmd is an AcqBoardCommand object whose state represents
        the most recent state change to the board;

        we retreive the encoded string with acqboardcmd.latestString
        and the most recent commandID with .

        """

        # setup rx
        self.eio.addRXMask(self.CMDFIBERRESP, xrange(256) )

        SRC = 3

        acmdstr = acqboardcmd.latestString
        # this is a total hack, we extract out the command byte
        bytes = struct.unpack("BBBBBB", acmdstr)
        
        cmdid = bytes[0] >> 4
        cmd = bytes[0] & 0xF
        assert cmdid == acqboardcmd.cmdid
        
        self.eio.start()
        ea = eaddr.TXDest()
        ea[:] = 1
        e = Event()
        e.cmd = self.CMDFIBERCMD
        e.src = SRC
        e.data[0] = (cmdid << 8) | cmd
        e.data[1] = bytes[4] << 8 | bytes[3]
        e.data[2] = bytes[2] << 8 | bytes[1]


        ## Substantial debugging
        
        #cmdtuple = (0x50, 4, (cmdid << 8) | (cmd & 0xF), 1, 0, 0, 0)
        #self.pne.sendEvent(addrtuple, cmdtuple)
        print "sending event", e
        self.eio.sendEvent(ea, e)
        

        success = False

        while success == False:
            erx = self.eio.getEvents()
            # extract out events
            for e in erx:
                #print e
                if e.cmd == self.CMDFIBERRESP: # and e.src == self.DESTSRCID:
                    # response; extract out bits
                    cmdid = e.data[0]
                    if cmdid == acqboardcmd.cmdid:
                        success = True

        self.eio.stop()
    def getSamples(self, N):
        """ Very simple interface to getting
        samples -- at the moment we just return N samples
        from either the A channels or the B channels"""

        data = n.zeros((5, N), dtype=n.int16)
        if self.set == "A":
            self.eio.addRXMask(self.CMDFIBERDATAA, xrange(256) )
        elif self.set == "B" :
            self.eio.addRXMask(self.CMDFIBERDATAB, xrange(256) )
        else:
            # both 
            self.eio.addRXMask(self.CMDFIBERDATAA, xrange(256) )
            self.eio.addRXMask(self.CMDFIBERDATAB, xrange(256) )

        self.eio.start()
        receivedN = 0
        while (receivedN < N):
            erx = self.eio.getEvents()
            for e in erx:
                if receivedN < N:
                    for i in xrange(5):
                        data[i][receivedN]  = e.data[i]
                receivedN += 1
        self.eio.stop()

        return data
    def getNormSamplesA(self, N):
        """
        Return 5xN "normal", that is not-raw-mode, samples, from
        the A tetrode set of channels
        """
        self.set = "A"
        return self.getSamples(N)

    def getNormSamplesB(self, N):
        """
        Return 5xN "normal", that is not-raw-mode, samples, from
        the B tetrode set of channels
        """

        self.set = "B"
        return self.getSamples(N)
        
    def getRawSamples(self, N):
        """
        return N sampes as if from "Raw"

        """
        raise "Not implemented" 
Ejemplo n.º 11
0
CMD = 0xF2

# Create event and set mask
while (1):
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd = CMD
    e.data[0] = 0xFFFF

    ea = eaddr.TXDest()
    for i in dspaddrs:
        ea[i] = 1
    eio.sendEvent(ea, e)

    #rint "on"
    time.sleep(delay)

    e = Event()
    e.src = eaddr.NETWORK
    e.cmd = CMD
    e.data[0] = 0x0

    ea = eaddr.TXDest()
    for i in dspaddrs:
        ea[i] = 1
    eio.sendEvent(ea, e)
    #          print "off"
    time.sleep(delay)

eio.stop()
Ejemplo n.º 12
0
from somapynet import eaddr 
from somapynet.neteventio import NetEventIO	

eio = NetEventIO("10.0.0.2")

timerid = 0
timecmd = 0x10

eio.addRXMask(timecmd, timerid)

eio.start()

erx = eio.getEvents()
for event in erx:
  print event

eio.stop()
Ejemplo n.º 13
0
class DeviceLinkStatus(object):
    def __init__(self, SOMAIP):
        self.eio = NetEventIO(SOMAIP)
        self.src = eaddr.NETWORK

        self.eio.addRXMask(xrange(256), eaddr.SYSCONTROL)

        self.eio.start()
        
    def getLinkStatus(self, DEVN):

        # get the link status event 
        e = Event()
        e.src = self.src
        e.cmd = 0x20
        ea = eaddr.TXDest()
        ea[eaddr.SYSCONTROL] = 1

        self.eio.sendEvent(ea, e)

        erx = self.eio.getEvents()
        linkstatus_event = erx[0]

        # now parse the link status event
        status = []
            
        for i in range(DEVN):
            if (linkstatus_event.data[1] >> i) & 0x1 > 0:
                status.append(True)
            else:
                status.append(False)
        return status
    
    def getLinkCycleCount(self, DEVN):
        # now get all of the counter events        
        rx_set = {}
        for i in range(DEVN):
            e = Event()
            e.src = self.src
            e.cmd = 0x21
            e.data[0] = i

            ea = eaddr.TXDest()
            ea[eaddr.SYSCONTROL] = 1
            self.eio.sendEvent(ea, e)

            erx = self.eio.getEvents()

            rx_set[i] = erx
        cyclecnt = []
        for i in range(DEVN):
            cyclecnt.append(rx_set[i][0].data[2])
        return cyclecnt

##         print debug_event

##         for i in range(DEVN):
##             dly = (-1, -1)
##             if i in delays:
##                 dly = (delays[i] >> 8, delays[1] & 0xFF)

##             if (linkstatus_event.data[1] >> i) & 0x1 > 0:
##                 print "Device %2d : UP" % i, 
##             else:
##                 print "Device %2d :   " % i,
##             print "%d link cycles"  % (rx_set[i][0].data[2] )
    
    def getDLTiming(self):
        # now get the debug counters
        e = Event()
        e.src = self.src
        e.cmd = 0x22
        ea = eaddr.TXDest()
        ea[eaddr.SYSCONTROL] = 1
        self.eio.sendEvent(ea, e)
        
        erx = self.eio.getEvents()
        for e in erx:
            debug_event = erx[0]

        timings = []
        for ei in range(4):
            tpos = (debug_event.data[ei] >> 8 ) & 0xFF
            tlen = debug_event.data[ei] & 0xFF
            timings.append((tpos, tlen))
        
        return timings

    def stop(self):
        self.eio.stop()
Ejemplo n.º 14
0
def manual_boot_device(filename, devicenums, youares):
    """
    Devicenums are the device link nums. Note that they do not
    map directly onto the configuration bit lines
    """

    eio = NetEventIO("10.0.0.2")

    eio.addRXMask(xrange(256), eaddr.SYSCONTROL)

    eio.start()

    MANBOOTSER_SETMASK = 0xA0
    MANBOOTSER_TOGPROG = 0xA1
    MANBOOTSER_WRITEBYTES = 0xA2
    MANBOOTSER_SENDBYTES = 0xA3

    EVENTCMD_YOUARE = 0x01
    EVENTCMD_LINKSTATUS = 0x20
    

    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  MANBOOTSER_SETMASK

    wrd = 0
    #int_devicenums = [int(x) for x in devicenums]
    for d in devicenums: # [device_to_config_mapping[x] for x in int_devicenums]:
        cfg_line = device_to_config_bits[d]
        wrd |= (1 << cfg_line)
    #print "word = %8.8X" % wrd

    # FIXME: 
    e.data[0] = wrd >> 16 
    e.data[1] = wrd & 0xFFFF

    ea = eaddr.TXDest()
    ea[eaddr.SYSCONTROL] = 1
    eio.sendEvent(ea, e)

    # toggle FPROG
    e.cmd =  MANBOOTSER_TOGPROG
    eio.sendEvent(ea, e)

    # send the actual data
    fid = file(filename)
    fid.seek(72)

    data = fid.read(8)
    pos = 0
    ecnt = 0

    while data:

        e.cmd = MANBOOTSER_WRITEBYTES
        e.src = eaddr.NETWORK
        ea = eaddr.TXDest()
        ea[eaddr.SYSCONTROL] = 1


        if len(data) < 8:
            #print "The end" 
            data = data + "       "
        for i in xrange(4):
            e.data[i] = struct.unpack(">H", data[(i*2):(i*2+2)])[0]

        reallysend(eio, ea, e)

        # now push the bytes to the client device
        e.cmd = MANBOOTSER_SENDBYTES
        e.src = eaddr.NETWORK
        ea = eaddr.TXDest()
        ea[eaddr.SYSCONTROL] = 1

        reallysend(eio, ea, e)

        erx = eio.getEvents()


        data =fid.read(8)
        pos += 8

        ecnt  += 1

    # loop and query the linkstatus register to see if our links
    # are up yet, and once they are, go.

    up_delay = False
    allup = False
    for i in range(20):
        e = Event()
        e.cmd = EVENTCMD_LINKSTATUS
        e.src = eaddr.NETWORK
        ea = eaddr.TXDest()
        ea[eaddr.SYSCONTROL] = 1

        reallysend(eio, ea, e)

        erx =  eio.getEvents(False)
        device_status_event = None
        
        if erx != None:
            for e in erx:
                if e.cmd == EVENTCMD_LINKSTATUS:
                    device_status_event = e

        if device_status_event:
            stat = parse_linkstatus(device_status_event)
            allup = True
            for i in devicenums:
                if not stat[i]:
                    allup = False
        if allup:
            break
        up_delay += 1
        time.sleep(1)
        
    if not allup:
        print "Was unable to bring up the requested links"
        sys.exit(1)
    else:
        print "links up after", up_delay, "secs"
    
    #now send the YOUARE so the device knows who it is
    for deviceid in youares:
             e = Event()
             e.cmd = EVENTCMD_YOUARE
             e.src = eaddr.NETWORK
             
             e.data[0] = deviceid
             ea = eaddr.TXDest()
             ea[deviceid] = 1
             print "Sending youare for ", deviceid, e
             
             reallysend(eio, ea, e)                        


    eio.stop()
Ejemplo n.º 15
0
def main():

    dspaddrs = set()
    for who in sys.argv[2:]:
        if '-' in who:
            # this is a range
            (startstr, endstr) = who.split("-")
            for r in range(int(startstr), int(endstr)+1):
                dspaddrs.add(r)
        else:
            dspaddrs.add(int(who))
    if len(dspaddrs) == 0:
        raise Exception("Must specify at least one dsp board target")
    eio = NetEventIO("10.0.0.2")

    #DSPBOARDADDR = tgt
    for d in dspaddrs:
        eio.addRXMask(xrange(256), d)

    eio.start()

    ea = eaddr.TXDest()

    for d in dspaddrs:
        ea[d] = 1

    print "Asserting DSP reset" 
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  EVENTRXCMD_DSPRESET
    e.data[0] = 0x0000
    reallysend(eio, ea, e)

    print "Deasserting DSP reset" 
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  EVENTRXCMD_DSPRESET
    e.data[0] = 0xFFFF
    reallysend(eio, ea, e)

    print "Acquiring DSP SPI interface for FPGA" 
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  EVENTRXCMD_DSPSPIEN
    e.data[0] = 0xFFFF
    reallysend(eio, ea, e)

    print "Deasserting SPISS"
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  EVENTRXCMD_DSPSPISS
    e.data[0] = 0xFFFF
    reallysend(eio, ea, e)


    print "Reasserting SPISS"
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  EVENTRXCMD_DSPSPISS
    e.data[0] = 0x0000
    reallysend(eio, ea, e)

    time.sleep(1)

    # load up the blocks and send

    blocks = loadfiles()
    blockpos = 0

    for byteblock in blocks:
        MAXLEN = 1024
        chunks = chunk(byteblock, MAXLEN)
        print "byteblock, len = ", len(byteblock), len(chunks), "chunks"
        cpos = 0
        for b in chunks:
            pos = 0
            while pos < len(b):
                bytes = b[pos:pos+2]

                words = struct.unpack(">H", bytes)

                e = Event()
                e.src = eaddr.NETWORK
                e.cmd =  EVENTRXCMD_DATABUF
                e.data[0] = words[0]
                e.data[1] = pos / 2

                ea = eaddr.TXDest()
                for d in dspaddrs:
                    ea[d] = 1

                reallysend(eio, ea, e) # idempotent 
                pos += 2
            e = Event()
            e.src = eaddr.NETWORK
            e.cmd =  EVENTRXCMD_DATABUFTX
            # this is the length 
            e.data[0] = pos/2
            # now the nonce
            e.data[1] = cpos * 256 + pos 
            ea = eaddr.TXDest()
            for d in dspaddrs:
                ea[d] = 1

            reallysend(eio, ea, e)
            print "sent databuftx event, blockpos =%d,  block len = %d, chunk number %d" % (blockpos, len(b), cpos)

            # we need to get events from everyone
            ecnt = 0
            while ecnt < len(dspaddrs):
                erx = eio.getEvents()
                for q in erx:
                    ecnt += 1
		    print "Heard back from ", q.src, q
            

            cpos += 1
        blockpos += 1
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  EVENTRXCMD_DSPSPISS
    e.data[0] = 0xFFFF

    ea = eaddr.TXDest()
    for d in dspaddrs:
        ea[d] = 1
    reallysend(eio, ea, e)


    # Give DSP control of SPI interface
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  EVENTRXCMD_DSPSPIEN
    e.data[0] = 0x0000

    ea = eaddr.TXDest()

    for d in dspaddrs:
        ea[d] = 1

    reallysend(eio, ea, e)

    time.sleep(1)
    # now send all of the UART settings
    e = Event()
    e.src = eaddr.NETWORK
    e.cmd =  0x37
    for d in dspaddrs:
        e.data[0] = d
        e.data[1] = d
        e.data[2] = d
        e.data[3] = d
        e.data[4] = d
        ea = eaddr.TXDest()
        ea[d] = 1

        reallysend(eio, ea, e)
        
    
    eio.stop()