Guest User

Untitled

a guest
May 19th, 2023
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. #!/usr/bin/python3
  2. from uio.utils import fix_ctypes_struct
  3. from uio.ti.icss import Icss
  4. import ctypes
  5. from ctypes import c_uint32 as u32, c_uint16 as u16, c_int32 as int32, c_bool as boolean
  6. from time import sleep
  7. from sys import exit
  8.  
  9.  
  10. pruss = Icss( "/dev/uio/pruss/module" )
  11. pruss.initialize()
  12.  
  13. core_0 = pruss.core0
  14. core_1 = pruss.core1
  15.  
  16. core_0.load( 'pulse_train.out' )
  17.  
  18. # volatile variables in pruss shared memory
  19. class SharedVars( ctypes.Structure ):
  20.     _fields_ = [
  21.             ( 'target_pos',  u32 ),
  22.             ( 'current_pos', u32 ),
  23.             ( 'hault_request', boolean ),
  24.         ]
  25.  
  26.  
  27. # map shared memory variables
  28. shmem = core_0.map( SharedVars, 0x10100 )
  29.  
  30.  
  31. # ready, set, go!
  32. pruss.ecap.pwm.initialize( 2**32 )
  33. print(f'Initial position {shmem.current_pos} Target = {shmem.target_pos}')
  34. core_0.run()
  35. print('starting PRU0')
  36.  
  37. try:
  38.     shmem.hault_request = False
  39.     shmem.target_pos = 60
  40.     sleep(76)
  41.  
  42. except KeyboardInterrupt:
  43.     pass
  44.  
  45. finally:
  46.  
  47.     print( '', flush=True )
  48.     core_0.halt()
  49.     sleep( 0.01 )  # make sure that response has been receivedi
  50.    
  51.     print(f'Position {shmem.current_pos} Target = {shmem.target_pos}')
  52.     print('done hopefully you moved')
  53.  
Advertisement
Add Comment
Please, Sign In to add comment