comparison pru_rtaudio.p @ 40:419ce4ebfc4c staging

Further improvements in the PRU readibility (removed unnecssary defines and renamed r27_current back to reg_digital_current)
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 13 May 2015 12:23:37 +0100
parents 638bc1ae2500
children 579c86316008
comparison
equal deleted inserted replaced
39:638bc1ae2500 40:419ce4ebfc4c
187 // r1, r2, r3 are used for temporary storage 187 // r1, r2, r3 are used for temporary storage
188 #define MEM_DIGITAL_BASE 0x11000 //Base address for DIGITAL : Shared RAM + 0x400 188 #define MEM_DIGITAL_BASE 0x11000 //Base address for DIGITAL : Shared RAM + 0x400
189 #define MEM_DIGITAL_BUFFER1_OFFSET 0x400 //Start pointer to DIGITAL_BUFFER1, which is 256 words after. 189 #define MEM_DIGITAL_BUFFER1_OFFSET 0x400 //Start pointer to DIGITAL_BUFFER1, which is 256 words after.
190 // 256 is the maximum number of frames allowed 190 // 256 is the maximum number of frames allowed
191 191
192 #define r27_current r6 // Pointer to current storage location of DIGITAL 192 #define reg_digital_current r6 // Pointer to current storage location of DIGITAL
193 #define reg_num_channels r9 // Number of SPI ADC/DAC channels to use 193 #define reg_num_channels r9 // Number of SPI ADC/DAC channels to use
194 #define reg_frame_current r10 // Current frame count in SPI ADC/DAC transfer 194 #define reg_frame_current r10 // Current frame count in SPI ADC/DAC transfer
195 #define reg_frame_total r11 // Total frame count for SPI ADC/DAC 195 #define reg_frame_total r11 // Total frame count for SPI ADC/DAC
196 #define reg_dac_data r12 // Current dword for SPI DAC 196 #define reg_dac_data r12 // Current dword for SPI DAC
197 #define reg_adc_data r13 // Current dword for SPI ADC 197 #define reg_adc_data r13 // Current dword for SPI ADC
209 #define reg_comm_addr r25 // Memory address for communicating with ARM 209 #define reg_comm_addr r25 // Memory address for communicating with ARM
210 #define reg_spi_addr r26 // Base address for SPI 210 #define reg_spi_addr r26 // Base address for SPI
211 // r27, r28 used in macros 211 // r27, r28 used in macros
212 #define reg_mcasp_addr r29 // Base address for McASP 212 #define reg_mcasp_addr r29 // Base address for McASP
213 213
214 // DIGITAL new code starts here
215 //0 P8_07 36 0x890/090 66 gpio2[2] 214 //0 P8_07 36 0x890/090 66 gpio2[2]
216 //1 P8_08 37 0x894/094 67 gpio2[3] 215 //1 P8_08 37 0x894/094 67 gpio2[3]
217 //2 P8_09 39 0x89c/09c 69 gpio2[5] 216 //2 P8_09 39 0x89c/09c 69 gpio2[5]
218 //3 P8_10 38 0x898/098 68 gpio2[4] 217 //3 P8_10 38 0x898/098 68 gpio2[4]
219 //4 P8_11 13 0x834/034 45 gpio1[13] 218 //4 P8_11 13 0x834/034 45 gpio1[13]
227 //12 P8_27 56 0x8e0/0e0 86 gpio2[22] 226 //12 P8_27 56 0x8e0/0e0 86 gpio2[22]
228 //13 P8_28 58 0x8e8/0e8 88 gpio2[24] 227 //13 P8_28 58 0x8e8/0e8 88 gpio2[24]
229 //14 P8_29 57 0x8e4/0e4 87 gpio2[23] 228 //14 P8_29 57 0x8e4/0e4 87 gpio2[23]
230 //15 P8_30 59 0x8ec/0ec 89 gpio2[25] 229 //15 P8_30 59 0x8ec/0ec 89 gpio2[25]
231 230
232 //TODO during initialization, set the pinmuxers to mode 7, input enable
233
234 //generic GPIOs constants 231 //generic GPIOs constants
235 //#define GPIO1 0x4804c000 232 //#define GPIO1 0x4804c000
236 #define GPIO2 0x481ac000 233 #define GPIO2 0x481ac000
237 //#define GPIO_CLEARDATAOUT 0x190 //SETDATAOUT is CLEARDATAOUT+4 234 //#define GPIO_CLEARDATAOUT 0x190 //SETDATAOUT is CLEARDATAOUT+4
238 #define GPIO_OE 0x134 235 #define GPIO_OE 0x134
239 #define GPIO_DATAIN 0x138 236 #define GPIO_DATAIN 0x138
240
241 //gpioX_cleardataout must be adjacent to gpioX_setdataout
242 #define reg_gpio1_oe r2
243 #define reg_gpio2_oe r3
244 #define reg_gpio2_cleardataout r4
245 #define reg_gpio2_setdataout r5
246 #define reg_gpio1_cleardataout r7
247 #define reg_gpio1_setdataout r8
248 #define reg_digital r27 //will first contain digitalOut from render() and digitalIn to render() later
249 //aliases
250 #define reg_gpio1_datain r2
251 #define reg_gpio2_datain r3
252 237
253 .macro READ_GPIO_BITS 238 .macro READ_GPIO_BITS
254 .mparam gpio_data, gpio_num_bit, digital_bit, digital 239 .mparam gpio_data, gpio_num_bit, digital_bit, digital
255 QBBC DONE, digital, digital_bit //if the pin is set as an output, nothing to do here 240 QBBC DONE, digital, digital_bit //if the pin is set as an output, nothing to do here
256 QBBC CLEAR, gpio_data, gpio_num_bit 241 QBBC CLEAR, gpio_data, gpio_num_bit
498 //from here to GPIO_DONE takes 1.8us, while usually ADC_WAIT_FOR_FINISH only waits for 1.14us. 483 //from here to GPIO_DONE takes 1.8us, while usually ADC_WAIT_FOR_FINISH only waits for 1.14us.
499 //TODO: it would be better to split the DIGITAL stuff in two parts: 484 //TODO: it would be better to split the DIGITAL stuff in two parts:
500 //- one taking place during DAC_WRITE which sets the GPIO_OE 485 //- one taking place during DAC_WRITE which sets the GPIO_OE
501 //- and the other during ADC_WRITE which actually reads DATAIN and writes CLEAR/SET DATAOUT 486 //- and the other during ADC_WRITE which actually reads DATAIN and writes CLEAR/SET DATAOUT
502 //r27 is actually r27, so do not use r27 from here to ... 487 //r27 is actually r27, so do not use r27 from here to ...
503 LBBO r27, r27_current, 0, 4 488 LBBO r27, reg_digital_current, 0, 4
504 JAL r28.w0, DIGITAL // note that this is not called as a macro, but with JAL. r28 will contain the return address 489 JAL r28.w0, DIGITAL // note that this is not called as a macro, but with JAL. r28 will contain the return address
505 SBBO r27, r27_current, 0, 4 490 SBBO r27, reg_digital_current, 0, 4
506 //..here you can start using r27 again 491 //..here you can start using r27 again
507 ADD r27_current, r27_current, 4 //increment pointer 492 ADD reg_digital_current, reg_digital_current, 4 //increment pointer
508 GPIO_DONE: 493 GPIO_DONE:
509 ADC_WAIT_FOR_FINISH 494 ADC_WAIT_FOR_FINISH
510 ADC_RX out 495 ADC_RX out
511 ADC_CS_UNASSERT 496 ADC_CS_UNASSERT
512 .endm 497 .endm
820 LSL reg_mcasp_adc_current, reg_mcasp_adc_current, 1 805 LSL reg_mcasp_adc_current, reg_mcasp_adc_current, 1
821 ADC reg_mcasp_adc_current, reg_mcasp_adc_current, reg_mcasp_dac_current 806 ADC reg_mcasp_adc_current, reg_mcasp_adc_current, reg_mcasp_dac_current
822 MOV reg_frame_current, 0 807 MOV reg_frame_current, 0
823 QBBS DIGITAL_BASE_CHECK_SET, reg_flags, FLAG_BIT_BUFFER1 //check which buffer we are using for DIGITAL 808 QBBS DIGITAL_BASE_CHECK_SET, reg_flags, FLAG_BIT_BUFFER1 //check which buffer we are using for DIGITAL
824 // if we are here, we are using buffer0 809 // if we are here, we are using buffer0
825 MOV r27_current, MEM_DIGITAL_BASE 810 MOV reg_digital_current, MEM_DIGITAL_BASE
826 QBA DIGITAL_BASE_CHECK_DONE 811 QBA DIGITAL_BASE_CHECK_DONE
827 DIGITAL_BASE_CHECK_SET: //if we are here, we are using buffer1 812 DIGITAL_BASE_CHECK_SET: //if we are here, we are using buffer1
828 MOV r27_current, MEM_DIGITAL_BASE+MEM_DIGITAL_BUFFER1_OFFSET //so adjust offset appropriately 813 MOV reg_digital_current, MEM_DIGITAL_BASE+MEM_DIGITAL_BUFFER1_OFFSET //so adjust offset appropriately
829 DIGITAL_BASE_CHECK_DONE: 814 DIGITAL_BASE_CHECK_DONE:
830 815
831 WRITE_LOOP: 816 WRITE_LOOP:
832 // Write N channels to DAC from successive values in memory 817 // Write N channels to DAC from successive values in memory
833 // At the same time, read N channels from ADC 818 // At the same time, read N channels from ADC