KISS Data Aquisition and Control System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

578 lines
20 KiB

  1. .origin 0 // start of program in PRU memory
  2. .entrypoint START // program entry point for the debugger
  3. #define CLOCK_CNTR_ADDR 0x00000000
  4. #define ADC_STATE_ADDR 0x00000004
  5. #define ADC_CNTRL_STR_ADDR 0x00000008
  6. #define ADC_CNTRL_CHANGE 0x0000000C
  7. #define ADC_ADDR 0x00000010
  8. #define ADC_SIZE 0x00000014
  9. #define ADC_SAMPLE_DIVISOR 0x00000018
  10. #define ADC_NUM_BLOCKS 0x0000001C
  11. #define BUFSIZE 0x20000 // 128K is optimal flash write size for bbone.
  12. #define NUMBUFS 8 // 1Mb shared memory space divided into 8 buffers
  13. #define SHARED_MEM_SIZE 0x100000
  14. #define BUF_HDR_SIZE 32 // 32 Byte header contained at start of 128k buffer
  15. #define SAMPLE_SIZE 24
  16. #define PRU0_R31_VEC_VALID 32 // allows notification of program completion
  17. #define PRU_EVTOUT_0 3 // the event number that is sent back
  18. // This map documents pin mapping to the ADS1287, and the associated registers
  19. // r30.t0 Power Down 8 Pin 8.45
  20. // r30.t1 Power Down 4 Pin 8.46
  21. // r30.t2 Power Down 7 Pin 8.43
  22. // r30.t3 Power Down 3 Pin 8.44
  23. // r30.t4 Power Down 6 Pin 8.41
  24. // r30.t5 Power Down 2 Pin 8.42
  25. // r30.t6 Power Down 5 Pin 8.39
  26. // r30.t7 Power Down 1 Pin 8.40
  27. // r30.t8 ADS1278 Board Enable Pin 8.27
  28. // r30.t9 SPI_CLK Pin 8.29
  29. // r31.t10 SPI DATA IN Pin 8.28
  30. // r31.t11 SPI DATA READY Pin 8.30
  31. // Register Use
  32. // R0 General Purpose / Indexing
  33. // R1 General Purpose
  34. #define CLOCK_COUNT r2 // Clock Counter used to determine SCLOCK frequency
  35. #define RUN_STATE r3 // Run State - can turn off data acq via this
  36. #define ADC_CNTRL_STR r4 // ADC Control string used to enable/disable daq channels and daq
  37. #define ADC_CHNG_FLG r5 // ADC Control Change flag used to indicate a settings change
  38. #define SMPL_BIT_CNTR r6 // Sample bit counter, used to count number of bits read
  39. #define CHAN_BITMASK r7 // Channel bitmask used to append channel in MSB of the sample
  40. #define SHR_MEM_PTR r8 // Pointer to the shared memory buffer used to store data
  41. #define SHR_MEM_SZ r9 // Size of shared memory buffer
  42. #define CURRENT_SAMPLE r14
  43. #define CURRENT_BUF r15 // Current 128K buffer we are writing to (0 - 9)
  44. #define CUR_BUF_ADRS r16 // Memory address of current 128K buffer
  45. #define CUR_BUF_LEFT r17 // This is the amount left of the current buffer in bytes
  46. #define _128K r18 // 128k stored in register
  47. #define NUM_BLOCKS r19 // Number of 128k blocks we are going to record
  48. #define SAMPLE1 r21
  49. #define SAMPLE2 r22
  50. #define SAMPLE3 r23
  51. #define SAMPLE4 r24
  52. #define SAMPLE5 r25
  53. #define SAMPLE6 r26
  54. #define SAMPLE7 r27
  55. #define SAMPLE8 r28
  56. START:
  57. // Clear all outputs to the ADS 1278
  58. CLR r30.t0
  59. CLR r30.t1
  60. CLR r30.t2
  61. CLR r30.t3
  62. CLR r30.t4
  63. CLR r30.t5
  64. CLR r30.t6
  65. CLR r30.t7
  66. CLR r30.t8
  67. // Clear all registers we are going to use, since we know that they can come up
  68. // with garbage in them
  69. MOV r0, 0
  70. MOV r1, 0
  71. MOV CLOCK_COUNT, 0 // R2
  72. MOV RUN_STATE, 0 // R3
  73. MOV ADC_CNTRL_STR, 0 // R4
  74. MOV ADC_CHNG_FLG, 0 // R5
  75. MOV SMPL_BIT_CNTR, 0 // R6
  76. MOV CHAN_BITMASK, 0 // R7
  77. MOV SHR_MEM_PTR, 0 // R8
  78. MOV SHR_MEM_SZ, 0 // R9
  79. MOV SKIP_CHN_BM, 0 // R10
  80. MOV CURRENT_SAMPLE, 0 // R11
  81. MOV DROP_SMPL_CNTR, 0 // R12
  82. MOV CURRENT_CHAN, 0 // R13
  83. MOV SAMPLE_DIVISOR, 0 // R14
  84. MOV SKIP_WRITE, 0 // R15
  85. MOV CURRENT_BUF, 0 // R16
  86. MOV CUR_BUF_ADRS, 0 // R17
  87. MOV CUR_BUF_LEFT, 0 // R18
  88. MOV _128K, 0 // R19
  89. MOV NUM_BLOCKS, 0 // R20
  90. MOV SAMPLE1 , 0 // R21
  91. MOV SAMPLE2 , 0 // R21
  92. MOV SAMPLE3 , 0 // R21
  93. MOV SAMPLE4 , 0 // R21
  94. MOV SAMPLE5 , 0 // R21
  95. MOV SAMPLE6 , 0 // R21
  96. MOV SAMPLE7 , 0 // R21
  97. MOV SAMPLE8 , 0 // R21
  98. // Enable the OCP master port -- allows transfer of data to Linux userspace
  99. LBCO r0, C4, 4, 4 // load PRU-ICSS CFG reg into r0
  100. CLR r0, r0, 4 // clear bit 4 (STANDBY_INIT)
  101. SBCO r0, C4, 4, 4 // store the modified r0 back at the load addr
  102. START_LOOP: // This is an easy place to halt the debugger
  103. MOV r1,ADC_STATE_ADDR
  104. LBBO RUN_STATE, r1, 0, 4 // the daq state is now loaded into r3.
  105. QBEQ START_LOOP, RUN_STATE, 0 // We hang out in a loop until told to read the adc
  106. MOV r1,ADC_ADDR //
  107. LBBO SHR_MEM_PTR, r1, 0, 4 // load the Linux address that is passed into r8 -- to store sample values
  108. MOV r1,ADC_SIZE //
  109. LBBO SHR_MEM_SZ, r1, 0, 4 // load the size that is passed into r9 -- the number of samples to take
  110. MOV r1,ADC_NUM_BLOCKS //
  111. LBBO NUM_BLOCKS, r1, 0, 4 // load the count of how many 128K blocks we are going to record
  112. MOV _128K, BUFSIZE
  113. MOV r1, SHARED_MEM_SIZE // Check to see that the shared mem size is correct.
  114. QBEQ MEM_BUF_ALLOCATED, SHR_MEM_SZ, r1
  115. HALT // If the buffer is not allocated, halt.
  116. MEM_BUF_ALLOCATED:
  117. MOV CUR_BUF_LEFT, _128K
  118. MOV r1,ADC_CNTRL_CHANGE // load the base address into r1
  119. LBBO ADC_CHNG_FLG, r1, 0, 4 // the ADC_CNTL_CHANGE is now loaded into R5
  120. QBBS CONFIG_CHANGE, ADC_CHNG_FLG.t0 // If bit 1 of ADC_CTRL_CHANGE is set, there is a config
  121. //change
  122. QBA CONFIG_DONE // Else no changes, goto CONFIG_DONE
  123. CONFIG_CHANGE:
  124. MOV r1, CLOCK_CNTR_ADDR
  125. LBBO CLOCK_COUNT, r1, 0, 4 // the clock delay is now loaded into r2.
  126. MOV r1, ADC_SAMPLE_DIVISOR // load the sample divisor into R14
  127. LBBO SAMPLE_DIVISOR, r1, 0, 4
  128. MOV r1,ADC_CNTRL_STR_ADDR
  129. LBBO ADC_CNTRL_STR, r1, 0, 4 // the ADC_CNTL_STR is now loaded into R4
  130. MOV r30.b0, 0 // Clear all of the power down pins
  131. CLR ADC_CHNG_FLG.t1 // Clear the change flag so we dont do the config every loop
  132. ENABLE_ADC_BOARD:
  133. QBBS ENABLE_ADC, ADC_CNTRL_STR.t8 //
  134. QBA RESET_DONE
  135. ENABLE_ADC:
  136. CLR r30.t8 // We turn off the DAQ to make sure that we clear it.
  137. MOV r0, 0xFF // Load a delay val into R0
  138. RESET_WAIT:
  139. SUB r0, r0, 1
  140. QBNE RESET_WAIT, r0, 0 // loop until the delay has expired (equals 0)
  141. SET r30.t8
  142. RESET_DONE:
  143. QBBS SET_PWDN1, ADC_CNTRL_STR.t0 // If bit 1 of ADC_CTRL_STR is 1, set PWDN4, Pin 46.
  144. QBA PWDN2
  145. SET_PWDN1:
  146. SET r30.t1
  147. PWDN2:
  148. QBBS SET_PWDN2, ADC_CNTRL_STR.t1 // If bit 2 of ADC_CTRL_STR is 1, set PWDN8, pin 45
  149. QBA PWDN3
  150. SET_PWDN2:
  151. SET r30.t0
  152. PWDN3:
  153. QBBS SET_PWDN3, ADC_CNTRL_STR.t2 // If bit 3 of ADC_CTRL_STR is 1, set PWDN3 , pin 44
  154. QBA PWDN4
  155. SET_PWDN3:
  156. SET r30.t3
  157. PWDN4:
  158. QBBS SET_PWDN4, ADC_CNTRL_STR.t3 // If bit 4 of ADC_CTRL_STR is 1, set PWDN7, pin 43
  159. QBA PWDN5
  160. SET_PWDN4:
  161. SET r30.t2
  162. PWDN5:
  163. QBBS SET_PWDN5, ADC_CNTRL_STR.t4 // If bit 5 of ADC_CTRL_STR is 1, set PWDN2, pin 42
  164. QBA PWDN6
  165. SET_PWDN5:
  166. SET r30.t5
  167. PWDN6:
  168. QBBS SET_PWDN6, ADC_CNTRL_STR.t5 // If bit 6 of ADC_CTRL_STR is 1, set PWDN6, Pin 41
  169. QBA PWDN7
  170. SET_PWDN6:
  171. SET r30.t4
  172. PWDN7:
  173. QBBS SET_PWDN7, ADC_CNTRL_STR.t6 // If bit 7 of ADC_CTRL_STR is 1, set PWDN1, Pin 40
  174. QBA PWDN8
  175. SET_PWDN7:
  176. SET r30.t7
  177. PWDN8:
  178. QBBS SET_PWDN8, ADC_CNTRL_STR.t7 // If bit 8 of ADC_CTRL_STR is 1, set PWDN5, Pin 39
  179. QBA CONFIG_DONE
  180. SET_PWDN8:
  181. SET r30.t6
  182. CONFIG_DONE:
  183. // We have just reset and then enabled the ADC, and enabled channels`. Wait a little bit before we try to read samples.
  184. MOV r0, 0x0F // Load a delay val into R0
  185. INIT_WAIT:
  186. SUB r0, r0, 1
  187. QBNE INIT_WAIT, r0, 0 // loop until the delay has expired (equals 0)
  188. //We kick off a clock pulse so we can see it on the logic analyzer for debug purposes
  189. SET r30.t9 // set the clock to be low
  190. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  191. DELAY_ON1:
  192. SUB r0, r0, 1
  193. QBNE DELAY_ON1, r0, 0 // loop until the delay has expired (equals 0)
  194. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  195. CLR r30.t9 // set the clock to be low
  196. DELAY_OFF1:
  197. SUB r0, r0, 1
  198. QBNE DELAY_OFF1, r0, 0 // loop until the delay has expired (equals 0)
  199. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  200. //We want to look at the first bit in the config bitmask.
  201. READ_NEXT_SAMPLE:
  202. MOV r1,ADC_STATE_ADDR //Check to see if we are still need to be running
  203. LBBO RUN_STATE, r1, 0, 4
  204. QBEQ CONTINUE_DAQ, RUN_STATE, 1
  205. HALT // We've been told to stop.
  206. CONTINUE_DAQ:
  207. MOV CHAN_BITMASK, 1
  208. MOV CURRENT_CHAN, 0
  209. MOV SMPL_BIT_CNTR, SAMPLE_SIZE // We're going to read 24 bits
  210. MOV SAMPLE1, 0
  211. MOV SAMPLE2, 0
  212. MOV SAMPLE3, 0
  213. MOV SAMPLE4, 0
  214. MOV SAMPLE5, 0
  215. MOV SAMPLE6, 0
  216. MOV SAMPLE7, 0
  217. MOV SAMPLE8, 0
  218. // We check data ready to make sure the ADC has had a chance to initialize and set dready high before sampling.
  219. DATA_READY_HIGH:
  220. QBBS DATA_READY_WAIT, R31.t11
  221. QBA DATA_READY_HIGH
  222. DATA_READY_WAIT:
  223. QBBC DATA_READY, r31.t11 // If Data Ready line clear, read a sample
  224. QBA DATA_READY_WAIT // Else hang out in a tight loop ...
  225. DATA_READY:
  226. READ_CHANNEL1:
  227. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  228. SET r30.t9 // set the clock line to be high
  229. DELAYON1:
  230. SUB r0, r0, 1
  231. QBNE DELAYON1, r0, 0
  232. CLR r30.t9 // set the clock to be low
  233. // Read Data In
  234. QBBC ZERO_BIT1, r31.t10 // Check to see whether Data In is a 0 or 1
  235. OR SAMPLE1, SAMPLE1, 0x00000001
  236. ZERO_BIT1:
  237. LSL SAMPLE1, SAMPLE1, 1 // Shift current sample contents left by one
  238. MOV r0, CLOCK_COUNT
  239. DELAYOFF1:
  240. SUB r0, r0, 1
  241. QBNE DELAYOFF, r0, 0 // loop until the delay has expired (equals 0)
  242. SUB SMPL_BIT_CNTR, SMPL_BIT_CNTR, 1 // See if we have read all 24 bits of the sample
  243. QBNE READ_CHANNEL1, SMPL_BIT_CNTR, 0
  244. //////////////////////////
  245. READ_CHANNEL2:
  246. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  247. SET r30.t9 // set the clock to be high
  248. DELAYON2:
  249. SUB r0, r0, 1
  250. QBNE DELAYON2, r0, 0
  251. // Reload the clock delay val into R0
  252. CLR r30.t9 // set the clock to be low
  253. // Read Data In
  254. QBBC ZERO_BIT2, r31.t10 // Check to see whether Data In is a 0 or 1
  255. OR SAMPLE2, SAMPLE2, 0x00000001
  256. ZERO_BIT2:
  257. LSL SAMPLE2, SAMPLE2, 1 // Shift current sample contents left by one
  258. SUB SMPL_BIT_CNTR, SMPL_BIT_CNTR, 1 // See if we have read all 24 bits of the sample
  259. MOV r0, CLOCK_COUNT
  260. DELAYOFF21:
  261. SUB r0, r0, 1
  262. QBNE DELAYOFF, r0, 0 // loop until the delay has expired (equals 0)
  263. QBNE READ_CHANNEL2, SMPL_BIT_CNTR, 0
  264. //////////////////////
  265. READ_CHANNEL3:
  266. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  267. SET r30.t9 // set the clock to be high
  268. DELAYON3:
  269. SUB r0, r0, 1
  270. QBNE DELAYON3, r0, 0
  271. // Reload the clock delay val into R0
  272. CLR r30.t9 // set the clock to be low
  273. // Read Data In
  274. QBBC ZERO_BIT3, r31.t10 // Check to see whether Data In is a 0 or 1
  275. OR SAMPLE3, SAMPLE3, 0x00000001
  276. ZERO_BIT3:
  277. LSL SAMPLE3, SAMPLE3, 1 // Shift current sample contents left by one
  278. SUB SMPL_BIT_CNTR, SMPL_BIT_CNTR, 1 // See if we have read all 24 bits of the sample
  279. MOV r0, CLOCK_COUNT
  280. DELAYOFF3:
  281. SUB r0, r0, 1
  282. QBNE DELAYOFF, r0, 0 // loop until the delay has expired (equals 0)
  283. QBNE READ_CHANNEL3, SMPL_BIT_CNTR, 0
  284. /////////////////////////
  285. READ_CHANNEL4:
  286. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  287. SET r30.t9 // set the clock to be high
  288. DELAYON4:
  289. SUB r0, r0, 1
  290. QBNE DELAYON4, r0, 0
  291. // Reload the clock delay val into R0
  292. CLR r30.t9 // set the clock to be low
  293. // Read Data In
  294. QBBC ZERO_BIT4, r31.t10 // Check to see whether Data In is a 0 or 1
  295. OR SAMPLE4, SAMPLE4, 0x00000001
  296. ZERO_BIT4:
  297. LSL SAMPLE4, SAMPLE4, 1 // Shift current sample contents left by one
  298. SUB SMPL_BIT_CNTR, SMPL_BIT_CNTR, 1 // See if we have read all 24 bits of the sample
  299. MOV r0, CLOCK_COUNT
  300. DELAYOFF4:
  301. SUB r0, r0, 1
  302. QBNE DELAYOFF, r0, 0 // loop until the delay has expired (equals 0)
  303. QBNE READ_CHANNEL4, SMPL_BIT_CNTR, 0
  304. /////////////////////////
  305. READ_CHANNEL5:
  306. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  307. SET r30.t9 // set the clock to be high
  308. DELAYON5:
  309. SUB r0, r0, 1
  310. QBNE DELAYON5, r0, 0
  311. // Reload the clock delay val into R0
  312. CLR r30.t9 // set the clock to be low
  313. // Read Data In
  314. QBBC ZERO_BIT5, r31.t10 // Check to see whether Data In is a 0 or 1
  315. OR SAMPLE5, SAMPLE5, 0x00000001
  316. ZERO_BIT5:
  317. LSL SAMPLE5, SAMPLE5, 1 // Shift current sample contents left by one
  318. SUB SMPL_BIT_CNTR, SMPL_BIT_CNTR, 1 // See if we have read all 24 bits of the sample
  319. MOV r0, CLOCK_COUNT
  320. DELAYOFF5:
  321. SUB r0, r0, 1
  322. QBNE DELAYOFF, r0, 0 // loop until the delay has expired (equals 0)
  323. QBNE READ_CHANNEL5, SMPL_BIT_CNTR, 0
  324. /////////////////////////
  325. READ_CHANNEL6:
  326. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  327. SET r30.t9 // set the clock to be high
  328. DELAYON6:
  329. SUB r0, r0, 1
  330. QBNE DELAYON6, r0, 0
  331. // Reload the clock delay val into R0
  332. CLR r30.t9 // set the clock to be low
  333. // Read Data In
  334. QBBC ZERO_BIT6, r31.t10 // Check to see whether Data In is a 0 or 1
  335. OR SAMPLE6, SAMPLE6, 0x00000001
  336. ZERO_BIT6:
  337. LSL SAMPLE6, SAMPLE6, 1 // Shift current sample contents left by one
  338. SUB SMPL_BIT_CNTR, SMPL_BIT_CNTR, 1 // See if we have read all 24 bits of the sample
  339. MOV r0, CLOCK_COUNT
  340. DELAYOFF6:
  341. SUB r0, r0, 1
  342. QBNE DELAYOFF, r0, 0 // loop until the delay has expired (equals 0)
  343. QBNE READ_CHANNEL6, SMPL_BIT_CNTR, 0
  344. /////////////////////////
  345. READ_CHANNEL7:
  346. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  347. SET r30.t9 // set the clock to be high
  348. DELAYON7:
  349. SUB r0, r0, 1
  350. QBNE DELAYON7, r0, 0
  351. // Reload the clock delay val into R0
  352. CLR r30.t9 // set the clock to be low
  353. // Read Data In
  354. QBBC ZERO_BIT7, r31.t10 // Check to see whether Data In is a 0 or 1
  355. OR SAMPLE7, SAMPLE7, 0x00000001
  356. ZERO_BIT7
  357. LSL SAMPLE7, SAMPLE7, 1 // Shift current sample contents left by one
  358. SUB SMPL_BIT_CNTR, SMPL_BIT_CNTR, 1 // See if we have read all 24 bits of the sample
  359. MOV r0, CLOCK_COUNT
  360. DELAYOFF7:
  361. SUB r0, r0, 1
  362. QBNE DELAYOFF, r0, 0 // loop until the delay has expired (equals 0)
  363. QBNE READ_CHANNEL7, SMPL_BIT_CNTR, 0
  364. /////////////////////////
  365. READ_CHANNEL8:
  366. MOV r0, CLOCK_COUNT // Reload the clock delay val into R0
  367. SET r30.t9 // set the clock to be high
  368. DELAYON8:
  369. SUB r0, r0, 1
  370. QBNE DELAYON8, r0, 0
  371. // Reload the clock delay val into R0
  372. CLR r30.t9 // set the clock to be low
  373. // Read Data In
  374. QBBC ZERO_BIT8, r31.t10 // Check to see whether Data In is a 0 or 1
  375. OR SAMPLE8, SAMPLE8, 0x00000001
  376. ZERO_BIT8:
  377. LSL SAMPLE8, SAMPLE8, 1 // Shift current sample contents left by one
  378. SUB SMPL_BIT_CNTR, SMPL_BIT_CNTR, 1 // See if we have read all 24 bits of the sample
  379. MOV r0, CLOCK_COUNT
  380. DELAYOFF8:
  381. SUB r0, r0, 1
  382. QBNE DELAYOFF, r0, 0 // loop until the delay has expired (equals 0)
  383. QBNE READ_CHANNEL8, SMPL_BIT_CNTR, 0
  384. /////////////////////////
  385. STORE_SAMPLE:
  386. LSR SAMPLE1, SAMPLE1, 1 // Need to shift the sample word back to the right by one
  387. LSR SAMPLE2, SAMPLE2, 1
  388. LSR SAMPLE3, SAMPLE3, 1
  389. LSR SAMPLE4, SAMPLE4, 1
  390. LSR SAMPLE5, SAMPLE5, 1
  391. LSR SAMPLE6, SAMPLE6, 1
  392. LSR SAMPLE7, SAMPLE7, 1
  393. LSR SAMPLE8, SAMPLE8, 1
  394. MOV SAMPLE1.b3, 0x01 // Stash the channel bitmask in the upper byte used to store the sample
  395. MOV SAMPLE2.b3, 0X02
  396. MOV SAMPLE3.b3, 0x03
  397. MOV SAMPLE4.b3, 0x04
  398. MOV SAMPLE5.b3, 0x05
  399. MOV SAMPLE6.b3, 0x06
  400. MOV SAMPLE7.b3, 0x07
  401. MOV SAMPLE8.b3, 0x08
  402. SBBO SAMPLE1, SHR_MEM_PTR, 0, 4 // store the sample value into shared memory space
  403. ADD SHR_MEM_PTR, SHR_MEM_PTR, 4 // Add 4 bytes per sample to the address pointer
  404. SBBO SAMPLE2, SHR_MEM_PTR, 0, 4 // store the sample value into shared memory space
  405. ADD SHR_MEM_PTR, SHR_MEM_PTR, 4 // Add 4 bytes per sample to the address pointer
  406. SBBO SAMPLE3, SHR_MEM_PTR, 0, 4 // store the sample value into shared memory space
  407. ADD SHR_MEM_PTR, SHR_MEM_PTR, 4 // Add 4 bytes per sample to the address pointer
  408. SBBO SAMPLE4, SHR_MEM_PTR, 0, 4 // store the sample value into shared memory space
  409. ADD SHR_MEM_PTR, SHR_MEM_PTR, 4 // Add 4 bytes per sample to the address pointer
  410. SBBO SAMPLE5, SHR_MEM_PTR, 0, 4 // store the sample value into shared memory space
  411. ADD SHR_MEM_PTR, SHR_MEM_PTR, 4 // Add 4 bytes per sample to the address pointer
  412. SBBO SAMPLE6, SHR_MEM_PTR, 0, 4 // store the sample value into shared memory space
  413. ADD SHR_MEM_PTR, SHR_MEM_PTR, 4 // Add 4 bytes per sample to the address pointer
  414. SBBO SAMPLE7, SHR_MEM_PTR, 0, 4 // store the sample value into shared memory space
  415. ADD SHR_MEM_PTR, SHR_MEM_PTR, 4 // Add 4 bytes per sample to the address pointer
  416. SBBO SAMPLE8, SHR_MEM_PTR, 0, 4 // store the sample value into shared memory space
  417. ADD SHR_MEM_PTR, SHR_MEM_PTR, 4 // Add 4 bytes per sample to the address pointer
  418. SUB CUR_BUF_LEFT, CUR_BUF_LEFT, 32 // reducing the number of samples - 4 bytes per sample, 8 channels
  419. QBEQ BUFFER_DONE, CUR_BUF_LEFT, 0 // See if we have taken 128kb of samples
  420. QBA READ_NEXT_SAMPLE // If we've looped thru all channels in the sample. wait for the next sample
  421. BUFFER_DONE:
  422. // Generate an interrupt to the Linux process to write the buffer to flash
  423. MOV r31.b0, PRU0_R31_VEC_VALID | PRU_EVTOUT_0
  424. HALT // Debug
  425. MOV CUR_BUF_LEFT, _128K
  426. // If we have recorded all of the buffers that we need to, then halt.
  427. SUB NUM_BLOCKS, NUM_BLOCKS, 1
  428. QBEQ END, NUM_BLOCKS, 0
  429. ADD CUR_BUF_ADRS, CUR_BUF_ADRS, _128K
  430. MOV r1, SHARED_MEM_SIZE
  431. QBEQ WRAP_TIME, CUR_BUF_ADRS, r1
  432. QBA READ_NEXT_SAMPLE
  433. WRAP_TIME:
  434. // Always wanted to be a rapper ;-0)
  435. // We have used all the shared memory to write samples, wrap back to the beginning.
  436. MOV CUR_BUF_ADRS, 0
  437. MOV r31.b0, PRU0_R31_VEC_VALID | PRU_EVTOUT_0
  438. HALT //DEBUG
  439. QBA READ_NEXT_SAMPLE
  440. // halt the pru program -- we reach here when the file is full.
  441. END:
  442. HALT