@@ -0,0 +1,1591 @@
+#!/usr/bin/python3%0A%0Afrom uio.ti.icss import Icss%0Afrom uio.device import Uio%0Aimport ctypes%0A%0Apruss = Icss( %22/dev/uio/pruss/module%22 )%0Apruss.initialize()%0A%0Acore = pruss.core0%0Acore.load( 'fw/pulse-train.bin' )%0A%0A# completion event and irq%0AEVENT = 16%0AIRQ = 2%0Airq = Uio( %22/dev/uio/pruss/irq%25d%22 %25 IRQ )%0A%0A# set up completion event%0Aintc = pruss.intc%0Aintc.ev_ch%5B EVENT %5D = IRQ%0Aintc.ev_clear_one( EVENT )%0Aintc.ev_enable_one( EVENT )%0A%0Adef send_pulses( count, frequency, duty_cycle=0.5 ):%0A    # convert frequency and duty-cycle to on/off time in 10ns units%0A    period = round( 100e6 / frequency )%0A    on_time = round( duty_cycle * period )%0A    off_time = period - on_time%0A%0A    # validate parameters are in range%0A    assert count in range( 1, 2**32 )%0A    assert on_time in range( 2, 2**32 )%0A    assert off_time in range( 3, 2**32 )%0A%0A    # make sure PRU core isn't already running%0A    assert core.halted%0A%0A    # clear completion event%0A    intc.ev_clear_one( EVENT )%0A%0A    # start PRU core%0A    core.r4 = count%0A    core.r5 = on_time%0A    core.r6 = off_time%0A    core.run()%0A%0Adef wait_irq():%0A    intc.out_enable_one( IRQ )%0A    irq.irq_recv()%0A    return intc.out_event%5B IRQ %5D%0A%0Adef wait_completion():%0A    if core.halted or wait_irq() == EVENT:%0A        return%0A    # tolerate one spurious irq, try again%0A    if core.halted or wait_irq() == EVENT:%0A        return%0A    raise RuntimeError(%22Bogus IRQ%22)%0A%0A# send pulses and wait until done%0Adef send_pulses_sync( count, frequency, duty_cycle=0.5 ):%0A    send_pulses( count, frequency, duty_cycle )%0A    wait_completion()%0A%0Asend_pulses_sync( 100, 10e3 )  # send 100 pulses at 10 kHz%0A

add untested pulse-train example