-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathintc-test-asyncio.py
executable file
·69 lines (54 loc) · 1.44 KB
/
intc-test-asyncio.py
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
66
67
68
69
#!/usr/bin/python3
from uio.ti.icss import Icss
from uio.device import Uio
import ctypes
import asyncio
loop = asyncio.get_event_loop()
EVENT0 = 16 # range 16..31
EVENT1 = 17 # range 16..31
IRQ = 2 # range 2..9
pruss = Icss( "/dev/uio/pruss/module" )
irq = Uio( "/dev/uio/pruss/irq%d" % IRQ )
intc = pruss.intc
(core0, core1) = pruss.cores
pruss.initialize()
# clear and enable events and route them to our irq
for event in EVENT0, EVENT1:
intc.ev_ch[ event ] = IRQ
intc.ev_clear_one( event )
intc.ev_enable_one( event )
# load program onto both cores
core0.load( 'fw/intc-test.bin' )
core1.load( 'fw/intc-test.bin' )
# map and set parameters
class Params( ctypes.Structure ):
_fields_ = [
("interval", ctypes.c_uint32), # in 10ns units
("event", ctypes.c_uint8),
]
params0 = core0.dram.map( Params )
params0.interval = round( 1.0 * 1e8 )
params0.event = EVENT0
params1 = core1.dram.map( Params )
params1.interval = round( 0.5 * 1e8 )
params1.event = EVENT1
# start cores
core0.run()
core1.run()
def handle_events():
while True:
event = intc.out_event[ IRQ ]
if event < 0:
break
intc.ev_clear_one( event )
print( "event", event )
def irq_callback():
irq.irq_recv()
handle_events()
intc.out_enable_one( IRQ )
loop.add_reader( irq.fileno(), irq_callback )
intc.out_enable_one( IRQ )
try:
loop.run_forever()
except KeyboardInterrupt:
pass