Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from uio.utils import fix_ctypes_struct
- from uio.ti.icss import Icss
- from ctypes import c_uint32 as u32, c_uint16 as u16, c_int32 as int32, c_bool as boolean, Structure
- from time import sleep
- from sys import exit
- from bone_pinmux import *
- print(get_pinmux_state("stepper"))
- if (get_pinmux_state("stepper") == "default"):
- set_pinmux_state("stepper","active")
- pruss = Icss( "/dev/uio/pruss/module" )
- pruss.initialize()
- core_0 = pruss.core0
- core_0.load( 'fw-c/pulse_crap.out' )
- # used to communicate ddr layout to C program
- class DDRLayout( Structure ):
- _fields_ = [
- ( 'msgbuf', u32 ),
- ( 'num_msgs', u16 ),
- ( 'msg_size', u16 ),
- ]
- # volatile variables in pruss shared memory
- class UserControlVars( Structure ):
- _fields_ = [
- ( 'abort_file', u32 ),
- ( 'abort_line', u32 ),
- ( 'ridx', u16 ),
- ( 'buffer1', u16),
- ( 'target_pos' , u16 ),
- ( 'current_pos' , u16 ),
- ( 'speed' , u32 ),
- ( 'halt' , boolean ),
- ( 'moving' , boolean ),
- ]
- # map shared memory variables
- ddr_layout = core_0.map( DDRLayout,0x10000 )
- shmem = core_0.map(UserControlVars, 0x10100)
- # ready, set, go!
- shmem.hault_request = False
- pruss.ecap.pwm.initialize( 2**32 )
- shmem.current_pos = 0
- core_0.run()
- print('starting PRU0')
- try:
- shmem.hault_request = False
- # shmem.target_pos = 400
- shmem.speed = 999
- shmem.moving = True
- print(f'Initial position {shmem.current_pos} Target = {shmem.target_pos}')
- while (shmem.moving == True):
- print(f'\rDesired position {shmem.target_pos} current position {shmem.current_pos}', end = '', flush = True)
- sleep(0.01)
- except KeyboardInterrupt:
- pass
- finally:
- print( '', flush=True )
- shmem.hault_request = True
- sleep( 0.01 ) # make sure that response has been receivedi
- print(f'Position {shmem.current_pos} Target = {shmem.target_pos}')
- core_0.halt()
- print('done hopefully you moved')
Advertisement
Add Comment
Please, Sign In to add comment