# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + deletable=true editable=true
import numpy as np
from cffi import FFI

ffi = FFI()

a = 42*np.ones(16, dtype=np.uint32)
b = np.zeros_like(a)
pa = ffi.cast("float *", a.ctypes.data)
pb = ffi.cast("float *", b.ctypes.data)

print(a)
print(b)

# + deletable=true editable=true
long_out = ffi.new("long long[16]")
arr_in = 42*np.ones(16, dtype=np.uint64)

long_out[0:16] = arr_in[0:16]
arr_out = np.frombuffer(ffi.buffer(pa, 16*4), dtype=np.float32)
print(arr_out)
type(ffi)

# + deletable=true editable=true
import numpy
numpy.bitwise_and(255, numpy.array([0,1,3]))

# + deletable=true editable=true
a = numpy.array([1, 3, 5])
a_str = ','.join(str(x) for x in a)
print(a_str)

# + deletable=true editable=true
a = ['a','b','c']
y = numpy.zeros_like(a)
print(y)

# + deletable=true editable=true
from time import time
from math import log2
t1 = time()
log = int(log2(a[2]))
t2 = time()
print("Time: {}".format(t2-t1))

# + deletable=true editable=true
npdata = [6]
npdata0 = [1,3,5]
npdata1 = [2,4,6]
tri_sel = numpy.array([1,2,4])
tri_0 = numpy.array([1,3,5])
tri_1 = numpy.array([2,4,6])
array1 = numpy.bitwise_and(npdata,tri_sel)
array2 = numpy.bitwise_and(npdata0,tri_0)
array3 = numpy.bitwise_and(npdata1,tri_1)


# + deletable=true editable=true
a = temp_val2 = numpy.zeros_like(self.probes)
b = [2,4,6]
a.append(bs for bs in b)
a

# + deletable=true editable=true
b = [1,3,5]
a = [{} for _ in range(len(b))]
for index, signal_name in enumerate(b):
    a[index] = {'name': signal_name, 'wave': ''}
    a[index]['wave'] += str(signal_name)
print(a)

# + deletable=true editable=true
x='\n'
y = x.rstrip()
if not y:
    print(1)

# + deletable=true editable=true
f = open('./i2c_trace.csv')
for i in range(2):
    x = list(f.readline().rstrip().split(','))
    print(x)

# + deletable=true editable=true
a=' '
print("gap{}gap".format(a*10))

# + deletable=true editable=true
import IPython.core.display
import json
import time

t1 = time.time()
data = {'signal': [
        {'name': 'clk', 'wave': 'p.....|...'*5},
        {'name': 'dat', 'wave': 'x.345x|=.x'*5, 'data': ['D','A','T','A']},
        ]}
        
htmldata = '<script type="WaveDrom">' + json.dumps(data) + '</script>'
IPython.core.display.display_html(IPython.core.display.HTML(htmldata))
jsdata = 'WaveDrom.ProcessAll();'
IPython.core.display.display_javascript(
            IPython.core.display.Javascript(
                data=jsdata,
                lib=['files/js/WaveDrom.js', 'files/js/WaveDromSkin.js']))
t2 = time.time()
print("Time elapsed: {}s".format(t2-t1))

# + deletable=true editable=true
x = input("Type in the IOP ID of the Pmod TMP2 (A or B): ").strip().upper()
if x=='A':
    y = 1
elif x=='B':
    y = 2
else:
    raise ValueError('No IOP')
print(y)


# + deletable=true editable=true
def get_pmod_id(text):
    return input("Type in the interface ID of the {} (A or B): "
                 .format(text)).strip().upper()


# + deletable=true editable=true
get_pmod_id('test')

# + deletable=true editable=true
a = dict()
a['fclk0'] = [1]
a['fclk0'].append(2)

# + deletable=true editable=true
print(a)

# + deletable=true editable=true
from pynq.pl import _get_clk
a = _get_clk('/home/xilinx/pynq/bitstream/base.tcl')
print(a)

# + deletable=true editable=true
for i in a:
    if a[i][2]:
        div0,div1,state=a[i]
        print(div0,div1,state)

# + deletable=true editable=true
if 1:
    print(div0)
else:
    print(div1)

# + deletable=true editable=true
import cffi

ffi = cffi.FFI()

ffi.cdef("""
static uint32_t xlnkBufCnt = 0;
uint32_t cma_mmap(uint32_t phyAddr, uint32_t len);
uint32_t cma_munmap(void *buf, uint32_t len);
void *cma_alloc(uint32_t len, uint32_t cacheable);
uint32_t cma_get_phy_addr(void *buf);
void cma_free(void *buf);
uint32_t cma_pages_available();
void _xlnk_reset();
""")

libxlnk = ffi.dlopen("/usr/lib/libsds_lib.so")

# +
length = 12
data_type = "int"

try:
    buf = libxlnk.cma_alloc(length, 0)
    x = ffi.cast(data_type + "*", buf)
    x[0],x[1],x[2] = 1212,1124,1255
    print(x[0],x[1],x[2])
finally:
    libxlnk.cma_free(x)
# -

'{0:032b}'.format(12)



StarcoderdataJupyterScriptsDedupFiltered