Advertisement
Guest User

Untitled

a guest
Oct 26th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #!/usr/bin/python3
  2. from uio.utils import fix_ctypes_struct
  3. from uio.ti.icss import Icss
  4. from uio.ti.pwmss import Pwmss
  5. from ctypes import c_uint32 as uint32, c_uint16 as uint16, c_int32 as int32, Structure
  6. from sys import exit
  7. from time import sleep
  8.  
  9.  
  10. class Message( Structure ):
  11. _fields_ = [
  12. ("position", uint32), # in encoder pulsest 1140 per Revo
  13. ("force", int32), # in grams
  14. ]
  15.  
  16.  
  17.  
  18. def check_core():
  19. if not core_1.halted:
  20. return
  21. if core_1.state.crashed:
  22. msg = f'core crashed at pc={core.pc}'
  23. elif shmem.abort_file == 0:
  24. msg = f'core halted at pc={core.pc}'
  25. else:
  26. # FIXME figure out better way to read C-string from PRU memory
  27. abort_file = core_1.read( ctypes.c_char * 32, shmem.abort_file ).value
  28. abort_file = abort_file.decode("ascii")
  29. msg = f'core aborted at pc={core.pc} ({abort_file}:{shmem.abort_line})'
  30. # dump some potentially interesting information:
  31. exit( msg )
  32.  
  33.  
  34. # variable declarations
  35. print('delacaring variables')
  36. divider = 1
  37. frequency= 10000
  38. pruss = Icss( "/dev/uio/pruss/module" )
  39. period = round( 100e6 / divider / frequency )
  40. motor = Pwmss( "/dev/uio/pwmss1" ).pwm
  41. core_0 = pruss.core0
  42. core_1 = pruss.core1
  43. position = pruss.dram0.map( uint32 )
  44.  
  45. # initializing subsystems
  46. print('intiatilizing subsystem')
  47. pruss.initialize()
  48. pruss.uart.initialize(baudrate = 460800)
  49. motor.initialize(period,divider)
  50. core_0.load('fw/decoder.bin' )
  51. core_1.load('fw-c/find_top.out')
  52.  
  53. # Starting process
  54. print(' statrting find max procedure')
  55. core_0.run()
  56. core_1.run()
  57.  
  58. sleep(3)
  59.  
  60. print(check_core())
  61.  
  62. # stoppping
  63. pruss.uart.io.write( b'FFV\r', discard=True, flush=True )
  64. sleep( 0.1 )
  65. pruss.uart.io.discard()
  66. core_1.halt()
  67. core_0.halt()
  68.  
  69. print(f'top position is {position.value}')
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement