comparison pru_rtaudio.p @ 288:771a0920c626 prerelease

merge
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 18 May 2016 01:50:01 +0100
parents bfe2e929304b
children c6a15a8dee02
comparison
equal deleted inserted replaced
287:4815ed0f21de 288:771a0920c626
82 #define COMM_FRAME_COUNT 32 // How many frames have elapse since beginning 82 #define COMM_FRAME_COUNT 32 // How many frames have elapse since beginning
83 #define COMM_USE_SPI 36 // Whether or not to use SPI ADC and DAC 83 #define COMM_USE_SPI 36 // Whether or not to use SPI ADC and DAC
84 #define COMM_NUM_CHANNELS 40 // Low 2 bits indicate 8 [0x3], 4 [0x1] or 2 [0x0] channels 84 #define COMM_NUM_CHANNELS 40 // Low 2 bits indicate 8 [0x3], 4 [0x1] or 2 [0x0] channels
85 #define COMM_USE_DIGITAL 44 // Whether or not to use DIGITAL 85 #define COMM_USE_DIGITAL 44 // Whether or not to use DIGITAL
86 #define COMM_PRU_NUMBER 48 // Which PRU this code is running on 86 #define COMM_PRU_NUMBER 48 // Which PRU this code is running on
87 87 #define COMM_MUX_CONFIG 52 // Whether to use the mux capelet, and how many channels
88
89 // General constants for McASP peripherals (used for audio codec)
88 #define MCASP0_BASE 0x48038000 90 #define MCASP0_BASE 0x48038000
89 #define MCASP1_BASE 0x4803C000 91 #define MCASP1_BASE 0x4803C000
90 92
91 #define MCASP_PWRIDLESYSCONFIG 0x04 93 #define MCASP_PWRIDLESYSCONFIG 0x04
92 #define MCASP_PFUNC 0x10 94 #define MCASP_PFUNC 0x10
182 184
183 // Flags for the flags register 185 // Flags for the flags register
184 #define FLAG_BIT_BUFFER1 0 186 #define FLAG_BIT_BUFFER1 0
185 #define FLAG_BIT_USE_SPI 1 187 #define FLAG_BIT_USE_SPI 1
186 #define FLAG_BIT_MCASP_HWORD 2 // Whether we are on the high word for McASP transmission 188 #define FLAG_BIT_MCASP_HWORD 2 // Whether we are on the high word for McASP transmission
187 #define FLAG_BIT_USE_DIGITAL 3 189 #define FLAG_BIT_USE_DIGITAL 3
190
191 #define FLAG_BIT_MUX_CONFIG0 8 // Mux capelet configuration:
192 #define FLAG_BIT_MUX_CONFIG1 9 // 00 = off, 01 = 2 ch., 10 = 4 ch., 11 = 8 ch.
193 #define FLAG_MASK_MUX_CONFIG 0x0300
194
195 #define FLAG_BIT_MUX_STATE0 10 // Current state of the mux channels
196 #define FLAG_BIT_MUX_STATE1 11
197 #define FLAG_BIT_MUX_STATE2 12
198 #define FLAG_MASK_MUX_STATE 0x1C00
199
188 // Registers used throughout 200 // Registers used throughout
189 201
190 // r1, r2, r3 are used for temporary storage 202 // r1, r2, r3 are used for temporary storage
191 #define MEM_DIGITAL_BASE 0x11000 //Base address for DIGITAL : Shared RAM + 0x400 203 #define MEM_DIGITAL_BASE 0x11000 //Base address for DIGITAL : Shared RAM + 0x400
192 #define MEM_DIGITAL_BUFFER1_OFFSET 0x400 //Start pointer to DIGITAL_BUFFER1, which is 256 words after. 204 #define MEM_DIGITAL_BUFFER1_OFFSET 0x400 //Start pointer to DIGITAL_BUFFER1, which is 256 words after.
211 #define reg_flags r24 // Buffer ID (0 and 1) and other flags 223 #define reg_flags r24 // Buffer ID (0 and 1) and other flags
212 #define reg_comm_addr r25 // Memory address for communicating with ARM 224 #define reg_comm_addr r25 // Memory address for communicating with ARM
213 #define reg_spi_addr r26 // Base address for SPI 225 #define reg_spi_addr r26 // Base address for SPI
214 // r27, r28 used in macros 226 // r27, r28 used in macros
215 #define reg_mcasp_addr r29 // Base address for McASP 227 #define reg_mcasp_addr r29 // Base address for McASP
228 #define reg_pru1_mux_pins r30 // Register mapped directly to P8 pins (PRU1 only)
216 229
217 //0 P8_07 36 0x890/090 66 gpio2[2] 230 //0 P8_07 36 0x890/090 66 gpio2[2]
218 //1 P8_08 37 0x894/094 67 gpio2[3] 231 //1 P8_08 37 0x894/094 67 gpio2[3]
219 //2 P8_09 39 0x89c/09c 69 gpio2[5] 232 //2 P8_09 39 0x89c/09c 69 gpio2[5]
220 //3 P8_10 38 0x898/098 68 gpio2[4] 233 //3 P8_10 38 0x898/098 68 gpio2[4]
546 POLL: 559 POLL:
547 LBBO r28, reg_mcasp_addr, reg, 4 560 LBBO r28, reg_mcasp_addr, reg, 4
548 AND r28, r28, r27 561 AND r28, r28, r27
549 QBEQ POLL, r28, 0 562 QBEQ POLL, r28, 0
550 .endm 563 .endm
551 564
565 // Multiplexer Capelet: Increment channel on muxes 0-3
566 .macro MUX_INCREMENT_0_TO_3
567 MOV r28, FLAG_MASK_MUX_CONFIG
568 AND r28, reg_flags, r28 // Check flags
569 QBEQ DONE, r28, 0 // Skip if disabled
570 LSR r28, r28, FLAG_BIT_MUX_CONFIG0
571 AND r27, reg_pru1_mux_pins, 0x07 // Current mux channel in r30 bits 2-0
572 ADD r27, r27, 1 // Increment channel
573 AND r27, r27, 0x07 // Mask to 8 channels
574 QBEQ UPDATE, r28, 0x03
575 AND r27, r27, 0x03 // Mask to 4 channels
576 QBEQ UPDATE, r28, 0x02
577 AND r27, r27, 0x01 // Mask to 2 channels
578 UPDATE:
579 MOV r28, 0xFFFFFFF8
580 AND r28, reg_pru1_mux_pins, r28 // Mask out low 3 bits of r30
581 OR r28, r28, r27 // Combine with new value
582 MOV reg_pru1_mux_pins, r28 // Move back to r30 to propagate to pins
583 DONE:
584 .endm
585
586 // Multiplexer Capelet: Increment channel on muxes 4-7
587 .macro MUX_INCREMENT_4_TO_7
588 MOV r28, FLAG_MASK_MUX_CONFIG
589 AND r28, reg_flags, r28 // Check flags
590 QBEQ DONE, r28, 0 // Skip if disabled
591 LSR r28, r28, FLAG_BIT_MUX_CONFIG0
592 AND r27, reg_pru1_mux_pins, 0x38 // Current mux channel in r30 bits 5-3
593 ADD r27, r27, 8 // Increment channel (+1 LSB starting at bit 3)
594 AND r27, r27, 0x38 // Mask to 8 channels
595 QBEQ UPDATE, r28, 0x03
596 AND r27, r27, 0x18 // Mask to 4 channels
597 QBEQ UPDATE, r28, 0x02
598 AND r27, r27, 0x08 // Mask to 2 channels
599 UPDATE:
600 MOV r28, 0xFFFFFFC7
601 AND r28, reg_pru1_mux_pins, r28 // Mask out bits 5-3 of r30
602 OR r28, r28, r27 // Combine with new value
603 MOV reg_pru1_mux_pins, r28 // Move back to r30 to propagate to pins
604 DONE:
605 .endm
606
607
552 START: 608 START:
553 // Load useful registers for addressing SPI 609 // Load useful registers for addressing SPI
554 MOV reg_comm_addr, SHARED_COMM_MEM_BASE 610 MOV reg_comm_addr, SHARED_COMM_MEM_BASE
555 MOV reg_spi_addr, SPI_BASE 611 MOV reg_spi_addr, SPI_BASE
556 MOV reg_mcasp_addr, MCASP_BASE 612 MOV reg_mcasp_addr, MCASP_BASE
599 SBBO r2, r3, 0, 4 655 SBBO r2, r3, 0, 4
600 ADD r3, r3, 4 //increment pointer 656 ADD r3, r3, 4 //increment pointer
601 QBGT DIGITAL_INIT_BUFFER_LOOP, r3, r4 //loop until we reach the end of the buffer 657 QBGT DIGITAL_INIT_BUFFER_LOOP, r3, r4 //loop until we reach the end of the buffer
602 */ 658 */
603 DIGITAL_INIT_DONE: 659 DIGITAL_INIT_DONE:
660 // Check if we should use an external multiplexer capelet
661 // The valid values are 0 (off), 1 (2 ch), 2 (4 ch), 3 (8 ch)
662 // This can only happen on PRU1 because of how the pins are mapped
663 LBBO r2, reg_comm_addr, COMM_PRU_NUMBER, 4
664 QBNE MUX_INIT_DONE, r2, 1
665 LBBO r2, reg_comm_addr, COMM_MUX_CONFIG, 4
666 AND r2, r2, 0x03
667 QBEQ MUX_INIT_DONE, r2, 0
668 // If we get here, we are using the mux. Prepare flags and initial state.
669 LSL r2, r2, FLAG_BIT_MUX_CONFIG0
670 OR reg_flags, reg_flags, r2
671 // Clear lower 6 bits of r30 which controls the mux pins
672 MOV r2, 0xFFFFFFC0
673 AND reg_pru1_mux_pins, reg_pru1_mux_pins, r2
674 MUX_INIT_DONE:
675
604 // Find out whether we should use SPI ADC and DAC 676 // Find out whether we should use SPI ADC and DAC
605 LBBO r2, reg_comm_addr, COMM_USE_SPI, 4 677 LBBO r2, reg_comm_addr, COMM_USE_SPI, 4
606 QBEQ SPI_FLAG_CHECK_DONE, r2, 0 678 QBEQ SPI_FLAG_CHECK_DONE, r2, 0
607 SET reg_flags, reg_flags, FLAG_BIT_USE_SPI 679 SET reg_flags, reg_flags, FLAG_BIT_USE_SPI
608 SPI_FLAG_CHECK_DONE: 680 SPI_FLAG_CHECK_DONE:
965 1037
966 // Store 2 ADC words in memory 1038 // Store 2 ADC words in memory
967 SBCO reg_adc_data, C_ADC_DAC_MEM, reg_adc_current, 4 1039 SBCO reg_adc_data, C_ADC_DAC_MEM, reg_adc_current, 4
968 ADD reg_adc_current, reg_adc_current, 4 1040 ADD reg_adc_current, reg_adc_current, 4
969 1041
1042 // If enabled, update the multiplexer settings
1043 QBNE MUX_0_3_DONE, r1, 3 // Change mux settings for ch0-3 after reading ch. 3
1044 MUX_INCREMENT_0_TO_3
1045 MUX_0_3_DONE:
1046 QBNE MUX_4_7_DONE, r1, 7 // Change mux settings for ch4-7 after reading ch. 7
1047 MUX_INCREMENT_4_TO_7
1048 MUX_4_7_DONE:
1049
970 // Toggle the high/low word for McASP control (since we send one word out of 1050 // Toggle the high/low word for McASP control (since we send one word out of
971 // 32 bits for each pair of SPI channels) 1051 // 32 bits for each pair of SPI channels)
972 XOR reg_flags, reg_flags, (1 << FLAG_BIT_MCASP_HWORD) 1052 XOR reg_flags, reg_flags, (1 << FLAG_BIT_MCASP_HWORD)
973 1053
974 // Repeat 4 times for 8 channels (2 samples per loop, r1 += 1 already happened) 1054 // Repeat 4 times for 8 channels (2 samples per loop, r1 += 1 already happened)
985 XOR reg_flags, reg_flags, (1 << FLAG_BIT_MCASP_HWORD) 1065 XOR reg_flags, reg_flags, (1 << FLAG_BIT_MCASP_HWORD)
986 1066
987 ADD r1, r1, 2 1067 ADD r1, r1, 2
988 QBNE ADC_DAC_LOOP, r1, reg_num_channels 1068 QBNE ADC_DAC_LOOP, r1, reg_num_channels
989 1069
990 ADC_DAC_LOOP_DONE: 1070 ADC_DAC_LOOP_DONE:
991 // Increment number of frames, see if we have more to write 1071 // Increment number of frames, see if we have more to write
992 ADD reg_frame_current, reg_frame_current, 1 1072 ADD reg_frame_current, reg_frame_current, 1
993 QBNE WRITE_LOOP, reg_frame_current, reg_frame_total 1073 QBNE WRITE_LOOP, reg_frame_current, reg_frame_total
994 1074
995 WRITE_LOOP_DONE: 1075 WRITE_LOOP_DONE: