hwvertest.py 3.78 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
##_______________________________________________________________________________________________
##
##                                        CONV-TTL-RS485 PTS
##
##                                         CERN,BE/CO-HT
##_______________________________________________________________________________________________
##
##-----------------------------------------------------------------------------------------------
##
##                                    CONV-TTL-RS485 pcb version
##
##-----------------------------------------------------------------------------------------------
##
## Description  Test whether the version of PCB is the expected one
##
##
## Authors      Maciej Lipinski (maciej.lipinski@cern.ch)
## Website      http://www.ohwr.org/projects/pts
## Date         17/08/2017
##-----------------------------------------------------------------------------------------------
##
##------------------------------------------------------------------------------------------------
##                               GNU LESSER GENERAL PUBLIC LICENSE
##                              ------------------------------------
## This source file is free software; you can redistribute it and/or modify it under the terms of
## the GNU Lesser General Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
## without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU Lesser General Public License for more details.
## You should have received a copy of the GNU Lesser General Public License along with this
## source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
##-------------------------------------------------------------------------------------------------

##-------------------------------------------------------------------------------------------------
##                                            Import
##-------------------------------------------------------------------------------------------------

# Import system modules
import sys
sys.path.append("log/")
import time
import os, errno, re, sys, struct
import os.path
import traceback
import glob
import binascii

# Import common modules
from ctypes import *
from ptsexcept import *
from vv_pts import *
from ptsdefine import *

##-------------------------------------------------------------------------------------------------
##                                             main                                              --
##-------------------------------------------------------------------------------------------------

def main(bus,tname,inf,log):

    """
    tests : Hardware version
    uses  : pts.bit and hwvertest.py
    """

66
    HWVERS_target = 0.0
67 68 69 70 71 72 73 74 75

    pel = PTS_ERROR_LOGGER(inf,log)
    
    try:

        # Read PCB version: a 6 bits representing HW/PCB version number 
        # 4 MSB represent HW version number   (major)
        # 2 LSB represent number of execution (minor)
        # Eg: value 010010 represents PCB version 4.2
76
        hwvers = bus.vv_read(HWVERS_reg)
77 78 79 80 81 82
        maj = int(hwvers  >> HWVERS_VERS_OFS)
        min = float(hwvers & 0x03)
        min /= 10
        hwvers = maj + min

        # and now check if appropriate
83
        if (hwvers == HWVERS_target):
84 85 86
            msg = "HW/PCB version correct: %2.1f\n" % (hwvers)
            inf.write(msg)
        else:
87
            msg = "ERROR: HW/PCBe version (%2.1f) incorrect - expected %2.1f" % (hwvers, HWVERS_target)
88 89 90 91 92 93 94 95 96 97 98
            pel.set(msg)

        print "-->%s" % msg

        return pel.get()

    except BusException, e:
        raise PtsError("SKT Exception: %s" % (e))
    
    except BusWarning, e:
        raise PtsError("SKT Warning: %s" % (e))