View difference between Paste ID: MtFq6Xdv and 6R7iN14Z
SHOW: | | - or go back to the newest paste.
1-
#!/usr/bin/python3
1+
2
    global ridx, widx, lastid, timestamp_cycles
3-
from uio.utils import fix_ctypes_struct
3+
4-
from uio.ti.icss import Icss
4+
5-
import ctypes
5+
6-
from ctypes import c_uint32 as u32, c_uint16 as u16, c_int32 as int32
6+
7-
from time import sleep
7+
8-
from sys import exit
8+
    if ridx == widx:
9
        return  # no messages received
10-
pruss = Icss( "/dev/uio/pruss/module" )
10+
11-
pruss.initialize()
11+
12-
ddr = pruss.ddr
12+
13-
pruss.uart.initialize(baudrate = 460800)
13+
14
        # instead of directly accessing individual messages and their fields.
15
        msg = msgbuf[ ridx ]
16-
core_1 = pruss.core1
16+
17-
core_1.load( 'fw-c/stream.out' )
17+
18
        lastid = ( lastid + 1 ) & 0xffffffff
19
        assert msg.id == lastid
20-
core_0 = pruss.core0
20+
21-
core_0.load( 'fw/decoder.bin' )
21+
22
        timestamp_cycles += ( msg.timestamp - timestamp_cycles ) & 0xffffffff
23-
class Message( ctypes.Structure ):
23+
24-
    _fields_ = [
24+
        # process rest of message
25-
            ( 'id',     u32 ),
25+
26-
            ('timestamp',u32),
26+
27-
            ('position',   u32),
27+
28-
            ('force', int32),
28+
29-
        ]
29+
30
        ridx += 1
31-
# used to communicate ddr layout to C program
31+
32-
class DDRLayout( ctypes.Structure ):
32+
33-
    _fields_ = [
33+
34-
            ( 'msgbuf',      u32 ),
34+
35-
            ( 'num_msgs',    u16 ),
35+
36-
            ( 'msg_size',    u16 ),
36+
    ts_ms = timestamp_cycles // 200000
37-
        ]
37+
    ts_s = ( ts_ms % 60000 ) / 1000
38
    ts_m = ts_ms // 60000
39-
# volatile variables in pruss shared memory
39+
    ts_h = ts_m // 60
40-
class SharedVars( ctypes.Structure ):
40+
    ts_m = ts_m % 60
41-
    _fields_ = [
41+
    print(f'\ridx=0x{ridx:04x} id=0x{lastid:08x} time={ts_h:02d}:{ts_m:02d}:{ts_s:06.3f} position={position:08d} force={force:08d}', end='', flush=True )