actions.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. """
  2. Actions performed on the board.
  3. Fore some more actions also see sequences.py
  4. """
  5. import time
  6. from communication import *
  7. from utils import wait_for_revolutions
  8. def acquire_data(board_id, filename, simulate=False):
  9. """
  10. Acquire data. This sets registers and reads data to a file
  11. :param board_id: the id of the board to acquire with
  12. :param filename: the file to write to
  13. :param simulate: whether to use the pilotbunch simulator or not
  14. """
  15. if simulate:
  16. start_pilot_bunch_emulator(board_id)
  17. start_acquisition(board_id)
  18. wait_for_revolutions(board_id)
  19. stop_acquisition(board_id)
  20. enable_transfer(board_id)
  21. pci.read(board_id, dma='dma0', destination=filename)
  22. flush_dma(board_id)
  23. def data_reset(board_id):
  24. """
  25. Reset data
  26. :param board_id: the board to reset
  27. :return:
  28. """
  29. log.vinfo('Data reset')
  30. pci.write(board_id, '000003f5', hex_mask='7')
  31. time.sleep(0.05)
  32. pci.write(board_id, '000003f0', hex_mask='7')
  33. time.sleep(0.05)
  34. def flush_dma(board_id, dma='dma0'):
  35. """
  36. Flush dma. This basically reads data to /dev/null
  37. :param board_id: the id to flush dma
  38. :param dma: the dma to flush
  39. """
  40. log.vinfo('Flushing DMA Pipeline')
  41. pci.write(board_id, '03f0', hex_mask='CF0')
  42. pci.read(board_id, dma=dma, destination='/dev/null')
  43. def stop_board(board_id):
  44. """
  45. Stop a board (turn it off)
  46. :param board_id: the board to work with
  47. """
  48. pci.write(board_id, '0x01', '0x9040')
  49. pci.stop_dma(board_id)
  50. def soft_reset(board_id):
  51. """
  52. Perform a soft reset on the board.
  53. :param board_id: the board to reset
  54. :return:
  55. """
  56. pci.write(board_id, '0x1', '0x9040', hex_mask='0x1')
  57. time.sleep(1)
  58. pci.write(board_id, '0x0', '0x9040', hex_mask='0x1')
  59. def start_pilot_bunch_emulator(board_id):
  60. """
  61. Start the pilot bunch emulator
  62. :param board_id: the board to start it for
  63. """
  64. log.vinfo('Start pilot bunch emulator')
  65. pci.write(board_id, '400003f0', hex_mask='400003F0')
  66. time.sleep(0.005)
  67. pci.write(board_id, '03f0', hex_mask='CF0')
  68. def start_acquisition(board_id):
  69. """
  70. Start an acquisition. This will only tell the board to acquire. It will not read data
  71. :param board_id: the id to acquire with
  72. """
  73. log.vinfo('Start acquisition')
  74. pci.write(board_id, '1', '4', hex_mask='1') # what's this? write value 1 to register 4???
  75. time.sleep(0.005)
  76. pci.write(board_id, '00bf0', hex_mask='CF0')
  77. def stop_acquisition(board_id):
  78. """
  79. Stop an acquisition. This will only stop the acquisition on the board.
  80. :param board_id: the board to stop for
  81. """
  82. log.vinfo('Stop acquisition')
  83. pci.write(board_id, '003f0', hex_mask='CF0')
  84. time.sleep(0.005)
  85. def enable_transfer(board_id):
  86. """
  87. Enable data transfer. This will not transfer data.
  88. :param board_id: the id of the board to transfer data from
  89. :return:
  90. """
  91. log.vinfo('Enable data transfer')
  92. pci.write(board_id, '007f0', hex_mask='CF0')
  93. time.sleep(0.005)