Mercurial > hg > beaglert
comparison pru_rtaudio.p @ 16:670be80463a3 matrix_gpio
- analog matrixIn/matrixOut are now mapped as floats from 0 to 1
- use of an external PRU code can be enabled with -P <filename>
- 16 channels of programmable GPIO can be accessed straight from render() either writing directly to the matrixGpio[] array or using digitalWrite(),
digitalRead(), setDigitalDirection() macros from Utilities.h .
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 27 Apr 2015 13:01:57 +0100 |
parents | 6adb088196a7 |
children | c98863e63174 |
comparison
equal
deleted
inserted
replaced
15:901d205d1a3c | 16:670be80463a3 |
---|---|
79 #define COMM_LED_ADDRESS 24 // Which memory address to find the status LED on | 79 #define COMM_LED_ADDRESS 24 // Which memory address to find the status LED on |
80 #define COMM_LED_PIN_MASK 28 // Which pin to write to change LED | 80 #define COMM_LED_PIN_MASK 28 // Which pin to write to change LED |
81 #define COMM_FRAME_COUNT 32 // How many frames have elapse since beginning | 81 #define COMM_FRAME_COUNT 32 // How many frames have elapse since beginning |
82 #define COMM_USE_SPI 36 // Whether or not to use SPI ADC and DAC | 82 #define COMM_USE_SPI 36 // Whether or not to use SPI ADC and DAC |
83 #define COMM_NUM_CHANNELS 40 // Low 2 bits indicate 8 [0x3], 4 [0x1] or 2 [0x0] channels | 83 #define COMM_NUM_CHANNELS 40 // Low 2 bits indicate 8 [0x3], 4 [0x1] or 2 [0x0] channels |
84 | 84 #define COMM_USE_MATRIX_GPIO 44 // Whether or not to use MATRIX_GPIO |
85 | |
85 #define MCASP0_BASE 0x48038000 | 86 #define MCASP0_BASE 0x48038000 |
86 #define MCASP1_BASE 0x4803C000 | 87 #define MCASP1_BASE 0x4803C000 |
87 | 88 |
88 #define MCASP_PWRIDLESYSCONFIG 0x04 | 89 #define MCASP_PWRIDLESYSCONFIG 0x04 |
89 #define MCASP_PFUNC 0x10 | 90 #define MCASP_PFUNC 0x10 |
178 | 179 |
179 // Flags for the flags register | 180 // Flags for the flags register |
180 #define FLAG_BIT_BUFFER1 0 | 181 #define FLAG_BIT_BUFFER1 0 |
181 #define FLAG_BIT_USE_SPI 1 | 182 #define FLAG_BIT_USE_SPI 1 |
182 #define FLAG_BIT_MCASP_HWORD 2 // Whether we are on the high word for McASP transmission | 183 #define FLAG_BIT_MCASP_HWORD 2 // Whether we are on the high word for McASP transmission |
183 | 184 #define FLAG_BIT_USE_MATRIX_GPIO 3 |
185 /*#define FLAG_BIT_MATRIX_GPIO_BUFFER 4 //Whether we are using buffer located at | |
186 // 0: MEM_MATRIX_GPIO_BASE or | |
187 */ // 1: MEM_MATRIX_GPIO_BASE + 512 | |
184 // Registers used throughout | 188 // Registers used throughout |
185 | 189 |
186 // r1, r2, r3 are used for temporary storage | 190 // r1, r2, r3 are used for temporary storage |
191 #define MEM_MATRIX_GPIO_BASE 0x11000 //Base address for MATRIX_GPIO : Shared RAM + 0x400 | |
192 #define MEM_MATRIX_GPIO_BUFFER1_OFFSET 0x400 //Start pointer to MATRIX_GPIO_BUFFER1, which is 256 words after. | |
193 // 256 is the maximum number of frames allowed | |
194 | |
195 #define reg_matrix_gpio_current r6 // Pointer to current storage location of MATRIX_GPIO | |
187 #define reg_num_channels r9 // Number of SPI ADC/DAC channels to use | 196 #define reg_num_channels r9 // Number of SPI ADC/DAC channels to use |
188 #define reg_frame_current r10 // Current frame count in SPI ADC/DAC transfer | 197 #define reg_frame_current r10 // Current frame count in SPI ADC/DAC transfer |
189 #define reg_frame_total r11 // Total frame count for SPI ADC/DAC | 198 #define reg_frame_total r11 // Total frame count for SPI ADC/DAC |
190 #define reg_dac_data r12 // Current dword for SPI DAC | 199 #define reg_dac_data r12 // Current dword for SPI DAC |
191 #define reg_adc_data r13 // Current dword for SPI ADC | 200 #define reg_adc_data r13 // Current dword for SPI ADC |
203 #define reg_comm_addr r25 // Memory address for communicating with ARM | 212 #define reg_comm_addr r25 // Memory address for communicating with ARM |
204 #define reg_spi_addr r26 // Base address for SPI | 213 #define reg_spi_addr r26 // Base address for SPI |
205 // r27, r28 used in macros | 214 // r27, r28 used in macros |
206 #define reg_mcasp_addr r29 // Base address for McASP | 215 #define reg_mcasp_addr r29 // Base address for McASP |
207 | 216 |
217 // MATRIX_GPIO new code starts here | |
218 //0 P8_07 36 0x890/090 66 gpio2[2] | |
219 //1 P8_08 37 0x894/094 67 gpio2[3] | |
220 //2 P8_09 39 0x89c/09c 69 gpio2[5] | |
221 //3 P8_10 38 0x898/098 68 gpio2[4] | |
222 //4 P8_11 13 0x834/034 45 gpio1[13] | |
223 //5 P8_12 12 0x830/030 44 gpio1[12] | |
224 //6 P9_12 30 0x878/078 60 gpio1[28] | |
225 //7 P9_14 18 0x848/048 50 gpio1[18] | |
226 //8 P8_15 15 0x83c/03c 47 gpio1[15] | |
227 //9 P8_16 14 0x838/038 46 gpio1[14] | |
228 //10 P9_16 19 0x84c/04c 51 gpio1[19] | |
229 //11 P8_18 35 0x88c/08c 65 gpio2[1] | |
230 //12 P8_27 56 0x8e0/0e0 86 gpio2[22] | |
231 //13 P8_28 58 0x8e8/0e8 88 gpio2[24] | |
232 //14 P8_29 57 0x8e4/0e4 87 gpio2[23] | |
233 //15 P8_30 59 0x8ec/0ec 89 gpio2[25] | |
234 | |
235 //TODO during initialization, set the pinmuxers to mode 7, input enable | |
236 | |
237 //generic GPIOs constants | |
238 //#define GPIO1 0x4804c000 | |
239 #define GPIO2 0x481ac000 | |
240 //#define GPIO_CLEARDATAOUT 0x190 //SETDATAOUT is CLEARDATAOUT+4 | |
241 #define GPIO_OE 0x134 | |
242 #define GPIO_DATAIN 0x138 | |
243 | |
244 //gpioX_oe must be adjacent to gpioX_datain | |
245 //gpioX_cleardataout must be adjacent to gpioX_setdataout | |
246 #define reg_gpio1_oe r2 | |
247 #define reg_gpio2_oe r3 | |
248 #define reg_gpio2_cleardataout r4 | |
249 #define reg_gpio2_setdataout r5 | |
250 #define reg_gpio1_cleardataout r7 | |
251 #define reg_gpio1_setdataout r8 | |
252 #define reg_matrix_gpio r27 //will first contain matrixGpioOut from render() and matrixGpioIn to render() later | |
253 //aliases | |
254 #define reg_gpio1_datain reg_gpio1_oe | |
255 #define reg_gpio2_datain reg_gpio2_oe | |
256 | |
257 .macro SET_GPIO1_BITS | |
258 .mparam gpio_num_bit, matrix_gpio_bit | |
259 SET_GPIO_BITS reg_gpio1_oe, reg_gpio1_setdataout, reg_gpio1_cleardataout, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio | |
260 .endm | |
261 .macro SET_GPIO2_BITS | |
262 .mparam gpio_num_bit, matrix_gpio_bit | |
263 SET_GPIO_BITS reg_gpio2_oe, reg_gpio2_setdataout, reg_gpio2_cleardataout, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio | |
264 .endm | |
265 .macro READ_GPIO1_BITS | |
266 .mparam gpio_num_bit, matrix_gpio_bit | |
267 READ_GPIO_BITS reg_gpio1_datain, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio | |
268 .endm | |
269 .macro READ_GPIO2_BITS | |
270 .mparam gpio_num_bit, matrix_gpio_bit | |
271 READ_GPIO_BITS reg_gpio2_datain, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio | |
272 .endm | |
273 | |
274 .macro READ_GPIO_BITS | |
275 .mparam gpio_data, gpio_num_bit, matrix_gpio_bit, matrix_gpio | |
276 QBBC DONE, matrix_gpio, matrix_gpio_bit //if the pin is set as an output, nothing to do here | |
277 SET r30.t14 | |
278 QBBC CLEAR, gpio_data, gpio_num_bit | |
279 SET matrix_gpio, matrix_gpio_bit+16 | |
280 QBA DONE | |
281 CLEAR: | |
282 CLR matrix_gpio, matrix_gpio_bit+16 | |
283 QBA DONE | |
284 DONE: | |
285 CLR r30.t14 | |
286 .endm | |
287 | |
288 .macro SET_GPIO_BITS | |
289 .mparam gpio_oe, gpio_setdataout, gpio_cleardataout, gpio_num_bit, matrix_gpio_bit, matrix_gpio //sets the bits in GPIO_OE, GPIO_SETDATAOUT and GPIO_CLEARDATAOUT | |
290 //Remember that the GPIO_OE Output data enable register behaves as follows for each bit: | |
291 //0 = The corresponding GPIO pin is configured as an output. | |
292 //1 = The corresponding GPIO pin is configured as an input. | |
293 QBBS SETINPUT, matrix_gpio, matrix_gpio_bit | |
294 CLR gpio_oe, gpio_num_bit //if it is an output, configure pin as output | |
295 QBBC CLEARDATAOUT, matrix_gpio, matrix_gpio_bit+16 // check the output value. If it is 0, branch | |
296 SET gpio_setdataout, gpio_num_bit //if it is 1, set output to high | |
297 QBA DONE | |
298 CLEARDATAOUT: | |
299 SET gpio_cleardataout, gpio_num_bit // set output to low | |
300 QBA DONE | |
301 SETINPUT: //if it is an input, set the relevant bit | |
302 SET gpio_oe, gpio_num_bit | |
303 QBA DONE | |
304 DONE: | |
305 .endm | |
306 | |
307 .macro PROCESS_GPIO1_BITS | |
308 //- sets appropriate bits for output in reg_gpio1_oe, reg_gpio1_cleardataout, reg_gpio1_data | |
309 //- sets appropriate bits in reg_matrix_gpio to reflect the input values | |
310 .mparam gpio_num_bit, matrix_gpio_bit | |
311 // params to SET_GPIO_BITS gpio_oe, gpio_setdataout, gpio_cleardataout, gpio_num_bit, matrix_gpio_bit, matrix_gpio //sets the bits in GPIO_OE, GPIO_SETDATAOUT and GPIO_CLEARDATAOUT | |
312 SET_GPIO_BITS reg_gpio1_oe, reg_gpio1_setdataout, reg_gpio1_cleardataout, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio | |
313 READ_GPIO_BITS reg_gpio1_oe, reg_gpio1_datain, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio | |
314 .endm | |
315 | |
316 .macro PROCESS_GPIO2_BITS | |
317 //- sets appropriate bits for output in reg_gpio2_oe, reg_gpio2_cleardataout, reg_gpio2_data | |
318 //- sets appropriate bits in reg_matrix_gpio to reflect the input values | |
319 .mparam gpio_num_bit, matrix_gpio_bit | |
320 SET_GPIO_BITS reg_gpio2_oe, reg_gpio2_setdataout, reg_gpio2_cleardataout, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio | |
321 READ_GPIO_BITS reg_gpio2_oe, reg_gpio2_datain, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio | |
322 .endm | |
323 | |
324 QBA START // when first starting, go to START, skipping this section. | |
325 | |
326 MATRIX_GPIO: | |
327 //reg_matrix_gpio is now the input word passed in render(), one word per frame | |
328 //[31:16]: data(1=high, 0=low), [15:0]: direction (0=output, 1=input) ) | |
329 //Preparing the gpio_oe, gpio_cleardataout and gpio_setdataout for each module | |
330 | |
331 //load current status of GPIO_OE in reg_gpioX_oe | |
332 MOV reg_gpio1_oe, GPIO1 | GPIO_OE | |
333 //takes ...ns to go through the next two instructions | |
334 LBBO reg_gpio1_oe, reg_gpio1_oe, 0, 4 | |
335 //GPIO1-start | |
336 //process oe and datain and prepare dataout for GPIO1 | |
337 LDI reg_gpio1_setdataout, 0 | |
338 LDI reg_gpio1_cleardataout, 0 | |
339 //map GPIO_MATRIX to gpio1 pins, affects reg_gpio1_oe, reg_gpio1_cleardataout, reg_gpio1_data, reg_matrix_gpio | |
340 SET_GPIO1_BITS 13, 4 | |
341 SET_GPIO1_BITS 12, 5 | |
342 SET_GPIO1_BITS 28, 6 | |
343 SET_GPIO1_BITS 18, 7 | |
344 SET_GPIO1_BITS 15, 8 | |
345 SET_GPIO1_BITS 14, 9 | |
346 SET_GPIO1_BITS 19, 10 | |
347 //set the output enable register for gpio1. | |
348 MOV reg_gpio2_oe, GPIO1 | GPIO_OE //reg_gpio2_oe is now unused. It is here used as a temp | |
349 SBBO reg_gpio1_oe, reg_gpio2_oe, 0, 4 //takes two cycles (10ns) | |
350 //GPIO1-end | |
351 | |
352 // reg_gpio1_oe is now unused, its register is taken by gpio2_cleardataout | |
353 // reg_gpio1_datain now unused, its register is taken by gpio2_setdataout | |
354 //GPIO2-start | |
355 //load current status of GPIO_OE in reg_gpioX_oe | |
356 MOV reg_gpio2_oe, GPIO2 | GPIO_OE | |
357 //takes ...ns to go through the next two instructions | |
358 LBBO reg_gpio2_oe, reg_gpio1_oe, 0, 4 | |
359 //process oe and datain and prepare dataout for GPIO2 | |
360 LDI reg_gpio2_setdataout, 0 | |
361 LDI reg_gpio2_cleardataout, 0 | |
362 //map GPIO_MATRIX to gpio2 pins, affects reg_gpio2_oe, reg_gpio2_cleardataout, reg_gpio2_data, reg_matrix_gpio | |
363 SET_GPIO2_BITS 2, 0 | |
364 SET_GPIO2_BITS 3, 1 | |
365 SET_GPIO2_BITS 5, 2 | |
366 SET_GPIO2_BITS 4, 3 | |
367 SET_GPIO2_BITS 1, 11 | |
368 SET_GPIO2_BITS 22, 12 | |
369 SET_GPIO2_BITS 24, 13 | |
370 SET_GPIO2_BITS 23, 14 | |
371 SET_GPIO2_BITS 25, 15 | |
372 //set the output enable register for gpio2. | |
373 MOV reg_gpio1_oe, GPIO2 | GPIO_OE //reg_gpio1_oe is now unused. It is here used as a temp | |
374 SBBO reg_gpio2_oe, reg_gpio1_oe, 0, 4 //takes two cycles (10ns) | |
375 //GPIO2-end | |
376 | |
377 //load current inputs in reg_gpioX_datain | |
378 MOV reg_gpio1_datain, GPIO1 | GPIO_DATAIN | |
379 MOV reg_gpio2_datain, GPIO2 | GPIO_DATAIN | |
380 //takes ...ns to go through the next two instructions | |
381 LBBO reg_gpio1_datain, reg_gpio1_datain, 0, 4 | |
382 LBBO reg_gpio2_datain, reg_gpio2_datain, 0, 4 | |
383 //TODO: read inputs | |
384 READ_GPIO1_BITS 13, 4 | |
385 READ_GPIO1_BITS 12, 5 | |
386 READ_GPIO1_BITS 28, 6 | |
387 READ_GPIO1_BITS 18, 7 | |
388 READ_GPIO1_BITS 15, 8 | |
389 READ_GPIO1_BITS 14, 9 | |
390 READ_GPIO1_BITS 19, 10 | |
391 READ_GPIO2_BITS 2, 0 | |
392 READ_GPIO2_BITS 3, 1 | |
393 READ_GPIO2_BITS 5, 2 | |
394 READ_GPIO2_BITS 4, 3 | |
395 READ_GPIO2_BITS 1, 11 | |
396 READ_GPIO2_BITS 22, 12 | |
397 READ_GPIO2_BITS 24, 13 | |
398 READ_GPIO2_BITS 23, 14 | |
399 READ_GPIO2_BITS 25, 15 | |
400 //reg_gpio2_oe is now unused, so reg_temp1 is available for temporary storage from now on | |
401 //reg_gpio2_datain is now unsued, so reg_temp2 is available for temporary storage from now on | |
402 | |
403 //now all the setdataout and cleardataout are ready to be written to the GPIO register. | |
404 //CLEARDATAOUT and SETDATAOUT are consecutive positions in memory, so we write 8 bytes to CLEARDATAOUT. | |
405 //We can do this because we chose reg_gpio1_cleardataout and reg_gpioX_setdataout to be consecutive | |
406 //load the memory addresses to be written to | |
407 MOV reg_gpio1_datain, GPIO1 | GPIO_CLEARDATAOUT //reg_gpio1_datain is now unused and is used here as a temp | |
408 MOV reg_gpio2_datain, GPIO2 | GPIO_CLEARDATAOUT //reg_gpio2_datain is now unused and is used here as a temp | |
409 //write 8 bytes for each GPIO | |
410 //takes 30ns in total to go through the followint two lines | |
411 SBBO reg_gpio1_cleardataout, reg_gpio1_datain, 0, 8 // takes 145ns to be effective when going low, 185ns when going high | |
412 SBBO reg_gpio2_cleardataout, reg_gpio2_datain, 0, 8 //takes 95ns to be effective when going low, 130ns when going high | |
413 //reversing the order of the two lines above will swap the performances between the GPIO modules | |
414 //i.e.: the first line will always take 145ns/185ns and the second one will always take 95ns/130ns, | |
415 //regardless of whether the order is gpio1-gpio2 or gpio2-gpio1 | |
416 JMP r28.w0 // go back to ADC_WRITE_GPIO | |
417 | |
418 // MATRIX_GPIO new code ends here | |
419 | |
208 | 420 |
209 // Bring CS line low to write to DAC | 421 // Bring CS line low to write to DAC |
210 .macro DAC_CS_ASSERT | 422 .macro DAC_CS_ASSERT |
211 MOV r27, DAC_CS_PIN | 423 MOV r27, DAC_CS_PIN |
212 MOV r28, DAC_GPIO + GPIO_CLEARDATAOUT | 424 MOV r28, DAC_GPIO + GPIO_CLEARDATAOUT |
284 // Complete ADC write+read with chip select | 496 // Complete ADC write+read with chip select |
285 .macro ADC_WRITE | 497 .macro ADC_WRITE |
286 .mparam in, out | 498 .mparam in, out |
287 ADC_CS_ASSERT | 499 ADC_CS_ASSERT |
288 ADC_TX in | 500 ADC_TX in |
501 ADC_WAIT_FOR_FINISH | |
502 ADC_RX out | |
503 ADC_CS_UNASSERT | |
504 .endm | |
505 | |
506 // Complete ADC write+read with chip select and also performs IO for matrix_gpio | |
507 .macro ADC_WRITE_GPIO | |
508 .mparam in, out, do_gpio | |
509 ADC_CS_ASSERT | |
510 ADC_TX in | |
511 QBBC GPIO_DONE, reg_flags, FLAG_BIT_USE_MATRIX_GPIO //skip if MATRIX_GPIO is disabled | |
512 AND r27, do_gpio, 0x3 // only do a MATRIX_GPIO every 2 SPI I/O | |
513 QBNE GPIO_DONE, r27, 0 | |
514 //from here to GPIO_DONE takes 1.8us, while usually ADC_WAIT_FOR_FINISH only waits for 1.14us. | |
515 //TODO: it would be better to split the MATRIX_GPIO stuff in two parts: | |
516 //- one taking place during DAC_WRITE which sets the GPIO_OE | |
517 //- and the other during ADC_WRITE which actually reads DATAIN and writes CLEAR/SET DATAOUT | |
518 //reg_matrix_gpio is actually r27, so do not use r27 from here to ... | |
519 LBBO reg_matrix_gpio, reg_matrix_gpio_current, 0, 4 | |
520 JAL r28.w0, MATRIX_GPIO | |
521 SBBO reg_matrix_gpio, reg_matrix_gpio_current, 0, 4 | |
522 //..here you can start using r27 again | |
523 ADD reg_matrix_gpio_current, reg_matrix_gpio_current, 4 //increment pointer | |
524 GPIO_DONE: | |
289 ADC_WAIT_FOR_FINISH | 525 ADC_WAIT_FOR_FINISH |
290 ADC_RX out | 526 ADC_RX out |
291 ADC_CS_UNASSERT | 527 ADC_CS_UNASSERT |
292 .endm | 528 .endm |
293 | 529 |
333 AND r28, r28, r27 | 569 AND r28, r28, r27 |
334 QBEQ POLL, r28, 0 | 570 QBEQ POLL, r28, 0 |
335 .endm | 571 .endm |
336 | 572 |
337 START: | 573 START: |
574 MOV r30, 0 | |
338 // Set up c24 and c25 offsets with CTBIR register | 575 // Set up c24 and c25 offsets with CTBIR register |
339 // Thus C24 points to start of PRU0 RAM | 576 // Thus C24 points to start of PRU0 RAM |
340 MOV r3, 0x22020 // CTBIR0 | 577 MOV r3, 0x22020 // CTBIR0 |
341 MOV r2, 0 | 578 MOV r2, 0 |
342 SBBO r2, r3, 0, 4 | 579 SBBO r2, r3, 0, 4 |
360 MOV reg_flags, 0 | 597 MOV reg_flags, 0 |
361 | 598 |
362 // Default number of channels in case SPI disabled | 599 // Default number of channels in case SPI disabled |
363 LDI reg_num_channels, 8 | 600 LDI reg_num_channels, 8 |
364 | 601 |
602 // Find out whether we should use MATRIX_GPIO | |
603 LBBO r2, reg_comm_addr, COMM_USE_MATRIX_GPIO, 4 | |
604 QBEQ MATRIX_GPIO_FLAG_CHECK_DONE, r2, 0 | |
605 SET reg_flags, reg_flags, FLAG_BIT_USE_MATRIX_GPIO | |
606 // SET reg_flags, reg_flags, FLAG_BIT_MATRIX_GPIO_BUFFER //set the flag, so that in WRITE_ONE_BUFFER we will start from buffer0 | |
607 MATRIX_GPIO_FLAG_CHECK_DONE: | |
365 // Find out whether we should use SPI ADC and DAC | 608 // Find out whether we should use SPI ADC and DAC |
366 LBBO r2, reg_comm_addr, COMM_USE_SPI, 4 | 609 LBBO r2, reg_comm_addr, COMM_USE_SPI, 4 |
367 QBEQ SPI_FLAG_CHECK_DONE, r2, 0 | 610 QBEQ SPI_FLAG_CHECK_DONE, r2, 0 |
368 SET reg_flags, reg_flags, FLAG_BIT_USE_SPI | 611 SET reg_flags, reg_flags, FLAG_BIT_USE_SPI |
369 | 612 |
539 MCASP_REG_READ_EXT MCASP_RBUF, r2 | 782 MCASP_REG_READ_EXT MCASP_RBUF, r2 |
540 | 783 |
541 WRITE_ONE_BUFFER: | 784 WRITE_ONE_BUFFER: |
542 // Write a single buffer of DAC samples and read a buffer of ADC samples | 785 // Write a single buffer of DAC samples and read a buffer of ADC samples |
543 // Load starting positions | 786 // Load starting positions |
787 SET r30.t15 | |
544 MOV reg_dac_current, reg_dac_buf0 // DAC: reg_dac_current is current pointer | 788 MOV reg_dac_current, reg_dac_buf0 // DAC: reg_dac_current is current pointer |
545 LMBD r2, reg_num_channels, 1 // 1, 2 or 3 for 2, 4 or 8 channels | 789 LMBD r2, reg_num_channels, 1 // 1, 2 or 3 for 2, 4 or 8 channels |
546 LSL reg_adc_current, reg_frame_total, r2 | 790 LSL reg_adc_current, reg_frame_total, r2 |
547 LSL reg_adc_current, reg_adc_current, 2 // N * 2 * 2 * bufsize | 791 LSL reg_adc_current, reg_adc_current, 2 // N * 2 * 2 * bufsize |
548 ADD reg_adc_current, reg_adc_current, reg_dac_current // ADC: starts N * 2 * 2 * bufsize beyond DAC | 792 ADD reg_adc_current, reg_adc_current, reg_dac_current // ADC: starts N * 2 * 2 * bufsize beyond DAC |
549 MOV reg_mcasp_dac_current, reg_mcasp_buf0 // McASP: set current DAC pointer | 793 MOV reg_mcasp_dac_current, reg_mcasp_buf0 // McASP: set current DAC pointer |
550 LSL reg_mcasp_adc_current, reg_frame_total, r2 // McASP ADC: starts (N/2)*2*2*bufsize beyond DAC | 794 LSL reg_mcasp_adc_current, reg_frame_total, r2 // McASP ADC: starts (N/2)*2*2*bufsize beyond DAC |
551 LSL reg_mcasp_adc_current, reg_mcasp_adc_current, 1 | 795 LSL reg_mcasp_adc_current, reg_mcasp_adc_current, 1 |
552 ADC reg_mcasp_adc_current, reg_mcasp_adc_current, reg_mcasp_dac_current | 796 ADC reg_mcasp_adc_current, reg_mcasp_adc_current, reg_mcasp_dac_current |
553 MOV reg_frame_current, 0 | 797 MOV reg_frame_current, 0 |
554 | 798 QBBS MATRIX_GPIO_BASE_CHECK_SET, reg_flags, FLAG_BIT_BUFFER1 //check which buffer we are using for MATRIX_GPIO |
799 // if we are here, we are using buffer0 | |
800 MOV r2, 0 //so adjust offset appropriately | |
801 QBA MATRIX_GPIO_BASE_CHECK_DONE | |
802 MATRIX_GPIO_BASE_CHECK_SET: //if we are here, we are using buffer1 | |
803 MOV r2, MEM_MATRIX_GPIO_BUFFER1_OFFSET //so adjust offset appropriately | |
804 MATRIX_GPIO_BASE_CHECK_DONE: | |
805 MOV reg_matrix_gpio_current, MEM_MATRIX_GPIO_BASE | |
806 ADD reg_matrix_gpio_current, reg_matrix_gpio_current, r2 | |
807 | |
808 CLR r30.t15 | |
555 WRITE_LOOP: | 809 WRITE_LOOP: |
556 // Write N channels to DAC from successive values in memory | 810 // Write N channels to DAC from successive values in memory |
557 // At the same time, read N channels from ADC | 811 // At the same time, read N channels from ADC |
558 // Unrolled by a factor of 2 to get high and low words | 812 // Unrolled by a factor of 2 to get high and low words |
559 MOV r1, 0 | 813 MOV r1, 0 |
649 SUB r7, reg_num_channels, 1 | 903 SUB r7, reg_num_channels, 1 |
650 AND r8, r8, r7 | 904 AND r8, r8, r7 |
651 LSL r8, r8, AD7699_CHANNEL_OFFSET | 905 LSL r8, r8, AD7699_CHANNEL_OFFSET |
652 MOV r7, AD7699_CFG_MASK | 906 MOV r7, AD7699_CFG_MASK |
653 OR r7, r7, r8 | 907 OR r7, r7, r8 |
654 ADC_WRITE r7, r7 | 908 //ssssssssssssssssssssssssssss |
909 ADC_WRITE_GPIO r7, r7, r1 | |
655 | 910 |
656 // Mask out only the relevant 16 bits and store in reg_adc_data | 911 // Mask out only the relevant 16 bits and store in reg_adc_data |
657 MOV r2, 0xFFFF | 912 MOV r2, 0xFFFF |
658 AND reg_adc_data, r7, r2 | 913 AND reg_adc_data, r7, r2 |
659 | 914 |
721 MOV reg_dac_buf0, reg_dac_buf1 | 976 MOV reg_dac_buf0, reg_dac_buf1 |
722 MOV reg_dac_buf1, r2 | 977 MOV reg_dac_buf1, r2 |
723 MOV r2, reg_mcasp_buf0 | 978 MOV r2, reg_mcasp_buf0 |
724 MOV reg_mcasp_buf0, reg_mcasp_buf1 | 979 MOV reg_mcasp_buf0, reg_mcasp_buf1 |
725 MOV reg_mcasp_buf1, r2 | 980 MOV reg_mcasp_buf1, r2 |
981 XOR reg_flags, reg_flags, (1 << FLAG_BIT_BUFFER1) //flip the buffer flag | |
726 | 982 |
727 // Notify ARM of buffer swap | 983 // Notify ARM of buffer swap |
728 XOR reg_flags, reg_flags, (1 << FLAG_BIT_BUFFER1) | |
729 AND r2, reg_flags, (1 << FLAG_BIT_BUFFER1) // Mask out every but low bit | 984 AND r2, reg_flags, (1 << FLAG_BIT_BUFFER1) // Mask out every but low bit |
730 SBBO r2, reg_comm_addr, COMM_CURRENT_BUFFER, 4 | 985 SBBO r2, reg_comm_addr, COMM_CURRENT_BUFFER, 4 |
731 | 986 |
732 // Increment the frame count in the comm buffer (for status monitoring) | 987 // Increment the frame count in the comm buffer (for status monitoring) |
733 LBBO r2, reg_comm_addr, COMM_FRAME_COUNT, 4 | 988 LBBO r2, reg_comm_addr, COMM_FRAME_COUNT, 4 |
750 MOV r1, GPIO_CLEARDATAOUT | 1005 MOV r1, GPIO_CLEARDATAOUT |
751 ADD r3, r3, r1 // Address for GPIO clear register | 1006 ADD r3, r3, r1 // Address for GPIO clear register |
752 SBBO r2, r3, 0, 4 // Clear GPIO pin | 1007 SBBO r2, r3, 0, 4 // Clear GPIO pin |
753 LED_BLINK_DONE: | 1008 LED_BLINK_DONE: |
754 | 1009 |
755 QBBC TESTLOW, reg_flags, FLAG_BIT_BUFFER1 | |
756 MOV r2, 1 << 28 | |
757 MOV r3, GPIO1 + GPIO_SETDATAOUT | |
758 SBBO r2, r3, 0, 4 | |
759 QBA TESTDONE | |
760 TESTLOW: | |
761 MOV r2, 1 << 28 | |
762 MOV r3, GPIO1 + GPIO_CLEARDATAOUT | |
763 SBBO r2, r3, 0, 4 | |
764 TESTDONE: | |
765 | |
766 // Check if we should finish: flag is zero as long as it should run | 1010 // Check if we should finish: flag is zero as long as it should run |
767 LBBO r2, reg_comm_addr, COMM_SHOULD_STOP, 4 | 1011 LBBO r2, reg_comm_addr, COMM_SHOULD_STOP, 4 |
768 QBEQ WRITE_ONE_BUFFER, r2, 0 | 1012 QBEQ WRITE_ONE_BUFFER, r2, 0 |
769 | 1013 |
770 CLEANUP: | 1014 CLEANUP: |