Source code for cmd_skiroc2cms

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Copyright 2012-2017 Frédéric Magniette, Miguel Rubio-Roy
# This file is part of Pyrame.
#
# Pyrame 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 3 of the License, or
# (at your option) any later version.
#
# Pyrame 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 Pyrame.  If not, see <http://www.gnu.org/licenses/>

import pools,common_roc

def init():
    common_roc.nb_chans=64

skiroc2cms_pool=pools.pool("skiroc2cms")

skiroc2cms_bs_length=384

#************************* BITSTREAM MANIPULATION FUNCTIONS ***************

# **************************************************************************
# chipid
# **************************************************************************

def extract_chipid(skiroc2cms):
    return str(int(skiroc2cms["bitstream_bin"][23:31],2))

def set_chipid(skiroc2cms_id,skiroc2cms):
    idbin=common_roc.split_bin(common_roc.bin2gray(int(skiroc2cms["chipid"])),8)
    return common_roc.apply_to_roc(skiroc2cms_pool,skiroc2cms_id,extract_chipid,common_roc.apply_mask,"undef",23,idbin)

[docs]def set_chipid_param_skiroc2cms(skiroc2cms_id,chipid): "set the chipid of a skiroc2cms chip on the pool" try: skiroc2cms=skiroc2cms_pool.get(skiroc2cms_id) except Exception as e: return 0,str(e) if chipid!="undef": skiroc2cms["chipid"]=chipid return 1,"ok"
[docs]def get_chipid_skiroc2cms(skiroc2cms_id): "get the chipid of a skiroc2cms" try: skiroc2cms=skiroc2cms_pool.get(skiroc2cms_id) except Exception as e: return 0,str(e) return 1,"chipid=%s"%(skiroc2cms["chipid"])
#********************************** GENERAL PUBLIC FUNCTIONS ***************
[docs]def dump_sc_skiroc2cms(skiroc2cms_id): "Returns bitstream of *skiroc2cms_id* in binary format" try: skiroc2cms=skiroc2cms_pool.get(skiroc2cms_id) except Exception as e: return 0,str(e) #return the bitstream bitstream=skiroc2cms["bitstream_bin"] if not skiroc2cms["missing"] else "" return 1,bitstream
[docs]def set_missing_skiroc2cms(skiroc2cms_id,missing): "Set skiroc2cms missing state" try: skiroc2cms=skiroc2cms_pool.get(skiroc2cms_id) except Exception as e: return 0,str(e) skiroc2cms["missing"]=1 if missing=="1" else 0 return 1,"ok"
[docs]def explain_sc_skiroc2cms(skiroc2cms_id): "Explains the content of a bitsteam in human readable form" try: skiroc2cms=skiroc2cms_pool.get(skiroc2cms_id) except Exception as e: return 0,str(e) if skiroc2cms["bitstream"]!="0x%s"%(common_roc.bin2hexa(skiroc2cms["bitstream_bin"],msb_padding=False)): return 0,"invalid hex bitstream" print("hexa bitstream: ") print("0x"+skiroc2cms["bitstream"].upper()) print("binary bitstream: ") print("0b"+skiroc2cms["bitstream_bin"]) chipid=extract_chipid(skiroc2cms) print("Chipid in gray: %s"%(chipid)) return 1,"ok"
#****************************** PHASES *************************************
[docs]def init_skiroc2cms(skiroc2cms_id): "Initialize a skiroc2cms" skiroc2cms_pool.new(skiroc2cms_id,{"missing":0}) return 1,"ok"
[docs]def deinit_skiroc2cms(skiroc2cms_id): "Deinitialize skiroc2cms *skiroc2cms_id*" try: skiroc2cms=skiroc2cms_pool.get(skiroc2cms_id) except Exception as e: return 1,str(e) skiroc2cms_pool.remove(skiroc2cms_id) return 1,"ok"
[docs]def config_skiroc2cms(skiroc2cms_id,file,bitstream): "Prepare the bitstream for configuring a chip" try: skiroc2cms=skiroc2cms_pool.get(skiroc2cms_id) except Exception as e: return 0,str(e) #empty the bitstream skiroc2cms["bitstream_bin"]="" #load bitstream if bitstream!="undef": retcode,res=common_roc.load_str(bitstream,skiroc2cms_bs_length) if retcode==0: return 0,"cant parse bitstream: %s"%(res) skiroc2cms["bitstream_bin"]=res #load bitstream from file if file!="undef": retcode,res=common_roc.load_file(file,skiroc2cms_bs_length) if retcode==0: return 0,"cant open config file: %s"%(res) skiroc2cms["bitstream_bin"]=res if skiroc2cms["bitstream_bin"]=="": return 0,"no bitstream defined for skiroc2cms %s"%(skiroc2cms_id) #set chip id retcode,res=set_chipid(skiroc2cms_id,skiroc2cms) if retcode==0: return 0,"cant set chipid: %s"%(res) #update the bitstream in cmod common_roc.update_bitstream(skiroc2cms) return 1,"ok"
[docs]def get_param_skiroc2cms(skiroc2cms_id,param_name): "parameter extraction" return common_roc.get_param_roc(skiroc2cms_pool,skiroc2cms_id,param_name)