Mercurial > hg > beaglert
comparison pru_rtaudio.p @ 282:5b490c00488f prerelease
PRU update to support mux capelet
author | andrewm |
---|---|
date | Tue, 17 May 2016 17:54:35 +0100 |
parents | 33e0e4831763 |
children | bfe2e929304b |
comparison
equal
deleted
inserted
replaced
281:5f17da990d1b | 282:5b490c00488f |
---|---|
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 | |
552 START: | 586 START: |
553 // Load useful registers for addressing SPI | 587 // Load useful registers for addressing SPI |
554 MOV reg_comm_addr, SHARED_COMM_MEM_BASE | 588 MOV reg_comm_addr, SHARED_COMM_MEM_BASE |
555 MOV reg_spi_addr, SPI_BASE | 589 MOV reg_spi_addr, SPI_BASE |
556 MOV reg_mcasp_addr, MCASP_BASE | 590 MOV reg_mcasp_addr, MCASP_BASE |
599 SBBO r2, r3, 0, 4 | 633 SBBO r2, r3, 0, 4 |
600 ADD r3, r3, 4 //increment pointer | 634 ADD r3, r3, 4 //increment pointer |
601 QBGT DIGITAL_INIT_BUFFER_LOOP, r3, r4 //loop until we reach the end of the buffer | 635 QBGT DIGITAL_INIT_BUFFER_LOOP, r3, r4 //loop until we reach the end of the buffer |
602 */ | 636 */ |
603 DIGITAL_INIT_DONE: | 637 DIGITAL_INIT_DONE: |
638 // Check if we should use an external multiplexer capelet | |
639 // The valid values are 0 (off), 1 (2 ch), 2 (4 ch), 3 (8 ch) | |
640 // This can only happen on PRU1 because of how the pins are mapped | |
641 LBBO r2, reg_comm_addr, COMM_PRU_NUMBER, 4 | |
642 QBNE MUX_INIT_DONE, r2, 1 | |
643 LBBO r2, reg_comm_addr, COMM_MUX_CONFIG, 4 | |
644 AND r2, r2, 0x03 | |
645 QBEQ MUX_INIT_DONE, r2, 0 | |
646 // If we get here, we are using the mux. Prepare flags and initial state. | |
647 LSL r2, r2, FLAG_BIT_MUX_CONFIG0 | |
648 OR reg_flags, reg_flags, r2 | |
649 // Clear lower 6 bits of r30 which controls the mux pins | |
650 MOV r2, 0xFFFFFFC0 | |
651 AND reg_pru1_mux_pins, reg_pru1_mux_pins, r2 | |
652 MUX_INIT_DONE: | |
653 | |
604 // Find out whether we should use SPI ADC and DAC | 654 // Find out whether we should use SPI ADC and DAC |
605 LBBO r2, reg_comm_addr, COMM_USE_SPI, 4 | 655 LBBO r2, reg_comm_addr, COMM_USE_SPI, 4 |
606 QBEQ SPI_FLAG_CHECK_DONE, r2, 0 | 656 QBEQ SPI_FLAG_CHECK_DONE, r2, 0 |
607 SET reg_flags, reg_flags, FLAG_BIT_USE_SPI | 657 SET reg_flags, reg_flags, FLAG_BIT_USE_SPI |
608 SPI_FLAG_CHECK_DONE: | 658 SPI_FLAG_CHECK_DONE: |
965 | 1015 |
966 // Store 2 ADC words in memory | 1016 // Store 2 ADC words in memory |
967 SBCO reg_adc_data, C_ADC_DAC_MEM, reg_adc_current, 4 | 1017 SBCO reg_adc_data, C_ADC_DAC_MEM, reg_adc_current, 4 |
968 ADD reg_adc_current, reg_adc_current, 4 | 1018 ADD reg_adc_current, reg_adc_current, 4 |
969 | 1019 |
1020 // If enabled, update the multiplexer settings | |
1021 QBNE MUX_0_3_DONE, r1, 3 // Change mux settings for ch0-3 after reading ch. 3 | |
1022 MUX_INCREMENT_0_TO_3 | |
1023 MUX_0_3_DONE: | |
1024 | |
970 // Toggle the high/low word for McASP control (since we send one word out of | 1025 // Toggle the high/low word for McASP control (since we send one word out of |
971 // 32 bits for each pair of SPI channels) | 1026 // 32 bits for each pair of SPI channels) |
972 XOR reg_flags, reg_flags, (1 << FLAG_BIT_MCASP_HWORD) | 1027 XOR reg_flags, reg_flags, (1 << FLAG_BIT_MCASP_HWORD) |
973 | 1028 |
974 // Repeat 4 times for 8 channels (2 samples per loop, r1 += 1 already happened) | 1029 // 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) | 1040 XOR reg_flags, reg_flags, (1 << FLAG_BIT_MCASP_HWORD) |
986 | 1041 |
987 ADD r1, r1, 2 | 1042 ADD r1, r1, 2 |
988 QBNE ADC_DAC_LOOP, r1, reg_num_channels | 1043 QBNE ADC_DAC_LOOP, r1, reg_num_channels |
989 | 1044 |
990 ADC_DAC_LOOP_DONE: | 1045 ADC_DAC_LOOP_DONE: |
991 // Increment number of frames, see if we have more to write | 1046 // Increment number of frames, see if we have more to write |
992 ADD reg_frame_current, reg_frame_current, 1 | 1047 ADD reg_frame_current, reg_frame_current, 1 |
993 QBNE WRITE_LOOP, reg_frame_current, reg_frame_total | 1048 QBNE WRITE_LOOP, reg_frame_current, reg_frame_total |
994 | 1049 |
995 WRITE_LOOP_DONE: | 1050 WRITE_LOOP_DONE: |