CVS: python/msp430 HIL.py,NONE,1.1 hilspi.py,NONE,1.1 jtag.py,1.4,1.5

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/python/msp430
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12015/python/msp430

Modified Files:
	jtag.py 
Added Files:
	HIL.py hilspi.py 
Log Message:
- HIL python bindings
- add a library (hilspi) to do SPI over the JTAG lines
- add homepage in comments

--- NEW FILE: HIL.py ---
# Python bindings to the functions in the MSP430 JTAG HIL
# (Hardware Interface Library)
# 
# (C) 2004 Chris Liechti <[email protected]>
# this is distributed under a free software license, see license.txt
# 
# http://mspgcc.sf.net
# 
# Requires Python 2+, ctypes and HIL.dll/libHIL.so
# 
# $Id: HIL.py,v 1.1 2004/07/14 01:59:29 cliechti Exp $

import ctypes

HIL = ctypes.windll.HIL

Initialize          = HIL.HIL_Initialize
Initialize.argtypes = [ctypes.c_char_p]
Initialize.restype  = ctypes.c_int
Open                = HIL.HIL_Open
Open.argtypes       = []
Open.restype        = ctypes.c_int
Connect             = HIL.HIL_Connect
Connect.argtypes    = []
Connect.restype     = ctypes.c_int
Release             = HIL.HIL_Release
Release.argtypes    = []
Release.restype     = ctypes.c_int
Close               = HIL.HIL_Close
Close.argtypes      = [ctypes.c_long]
Close.restype       = ctypes.c_int
JTAG_IR             = HIL.HIL_JTAG_IR
JTAG_IR.argtypes    = [ctypes.c_long]
JTAG_IR.restype     = ctypes.c_long
TEST_VPP            = HIL.HIL_TEST_VPP
TEST_VPP.argtypes   = [ctypes.c_long]
TEST_VPP.restype    = ctypes.c_long
JTAG_DR             = HIL.HIL_JTAG_DR
JTAG_DR.argtypes    = [ctypes.c_long, ctypes.c_long]
JTAG_DR.restype     = ctypes.c_long
VCC                 = HIL.HIL_VCC
VCC.argtypes        = [ctypes.c_long]
VCC.restype         = ctypes.c_int
TST                 = HIL.HIL_TST
TST.argtypes        = [ctypes.c_long]
TST.restype         = ctypes.c_int
TCK                 = HIL.HIL_TCK
TCK.argtypes        = [ctypes.c_long]
TCK.restype         = ctypes.c_int
TMS                 = HIL.HIL_TMS
TMS.argtypes        = [ctypes.c_long]
TMS.restype         = ctypes.c_int
TDI                 = HIL.HIL_TDI
TDI.argtypes        = [ctypes.c_long]
TDI.restype         = ctypes.c_int
TCLK                = HIL.HIL_TCLK
TCLK.argtypes       = [ctypes.c_long]
TCLK.restype        = ctypes.c_int
RST                 = HIL.HIL_RST
RST.argtypes        = [ctypes.c_long]
RST.restype         = ctypes.c_int
VPP                 = HIL.HIL_VPP
VPP.argtypes        = [ctypes.c_long]
VPP.restype         = ctypes.c_int
DelayMSec           = HIL.HIL_DelayMSec
DelayMSec.argtypes  = [ctypes.c_ulong]
DelayMSec.restype   = ctypes.c_int
StartTimer          = HIL.HIL_StartTimer
StartTimer.argtypes = []
StartTimer.restype  = ctypes.c_int
ReadTimer           = HIL.HIL_ReadTimer
ReadTimer.argtypes  = []
ReadTimer.restype   = ctypes.c_ulong
StopTimer           = HIL.HIL_StopTimer
StopTimer.argtypes  = []
StopTimer.restype   = ctypes.c_int
ReadTDO             = HIL.HIL_ReadTDO
ReadTDO.argtypes    = []
ReadTDO.restype     = ctypes.c_long

if __name__ == '__main__':
    Initialize('1')
    Connect()
    VCC(3000)
    
    #~ HIL_TST(1)
    #~ HIL_DelayMSec(1000)
    #~ HIL_TST(0)
    
    #~ HIL_TCK(1)
    #~ HIL_TDI(1)
    
    #~ for i in range(3):
        #~ HIL_DelayMSec(100)
        #~ HIL_TMS(1)
        #~ HIL_DelayMSec(100)
        #~ HIL_TMS(0)

    JTAG_DR(0x1234, 16)
    
    Release()
    Close(1)

--- NEW FILE: hilspi.py ---
# Using the MSP430 JTAG parallel port board as SPI interface.
#
# (C) 2004 Chris Liechti <[email protected]>
# this is distributed under a free software license, see license.txt
# 
# http://mspgcc.sf.net
# 
# Requires Python 2+, ctypes and HIL.dll/libHIL.so
# 
# $Id: hilspi.py,v 1.1 2004/07/14 01:59:29 cliechti Exp $

import HIL
#~ import psyco
#~ psyco.full()

def init(port='1'):
    """open the parallel port and prepare for SPI mode"""
    HIL.Initialize(port)
    HIL.Connect()
    HIL.VCC(3000)
    HIL.TST(0)
    HIL.TCK(1)
    HIL.TDI(1)
    HIL.TMS(1)

def close():
    """close the parallel port"""
    HIL.Release()
    HIL.Close(1)

def _delay():
    """can be implemented if the SPI data rate has to be lowered"""
    #~ HIL.DelayMSec(1)
    #~ for i in range(10): HIL.DelayMSec(0)
    #~ HIL.DelayMSec(0)
    pass

def shift(data):
    """shift an binary string from/to the slave, returning the
       answer string of the same length
    """
    answer = []
    for character in data:
        shiftout = ord(character)
        indata = 0
        for i in range(8):
            HIL.TCK(0)
            HIL.TDI(shiftout & 0x80)
            shiftout <<= 1
            _delay()
            HIL.TCK(1)
            _delay()
            indata = (indata << 1) | HIL.ReadTDO()
        answer.append(chr(indata))
    return ''.join(answer)

def sync():
    """read untlil something else as a 0xff arrives.
    """
    while shift('\xff') != '\xff':
        pass

def getNullTeminated(maxlen=80):
    """read a null terminated string over SPI."""
    answer = []
    while maxlen:
        c = shift('\xff')
        if c == '\0': break
        answer.append(c)
        maxlen -= 1
    return ''.join(answer)


#test application
if __name__ == '__main__':
    import time
    init()
    #reset target
    HIL.RST(0)
    HIL.DelayMSec(10)
    HIL.RST(1)
    HIL.DelayMSec(10)
    
    #simple speed test
    bytes = 0
    t1 = time.time()
    for i in range(200):
        #~ print '%r' % getNullTeminated()
        bytes += len(getNullTeminated()) + 1
    dt = time.time() - t1
    print "%d bytes in %.2f seconds -> %.2f bytes/second" % (bytes, dt, bytes/dt)

Index: jtag.py
===================================================================
RCS file: /cvsroot/mspgcc/python/msp430/jtag.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- jtag.py	9 Jul 2004 23:18:07 -0000	1.4
+++ jtag.py	14 Jul 2004 01:59:29 -0000	1.5
@@ -3,6 +3,8 @@
 # (C) 2002-2004 Chris Liechti <[email protected]>
 # this is distributed under a free software license, see license.txt
 #
+# http://mspgcc.sf.net
+#
 # Requires Python 2+ and the binary extension _parjtag or ctypes
 # and MSP430mspgcc.dll/libMSP430mspgcc.so and HIL.dll/libHIL.so
 #



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.