comparison core/PRU.cpp @ 38:a9af130097e8 staging

GPIO pins are initialised as inputs by ARM to avoid spikes at startup, through gpio_set_dir. The buffers are set to 0x000ffff during initialisation. LastDigitalBuffer is initialized to 0x0000ffff.
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 12 May 2015 23:48:37 +0100
parents 182ae9367104
children 4255ecbb9bec 4cd9a8ca5745 579c86316008
comparison
equal deleted inserted replaced
35:46571f8f04a1 38:a9af130097e8
54 #define PRU_LED_ADDRESS 6 54 #define PRU_LED_ADDRESS 6
55 #define PRU_LED_PIN_MASK 7 55 #define PRU_LED_PIN_MASK 7
56 #define PRU_FRAME_COUNT 8 56 #define PRU_FRAME_COUNT 8
57 #define PRU_USE_SPI 9 57 #define PRU_USE_SPI 9
58 #define PRU_SPI_NUM_CHANNELS 10 58 #define PRU_SPI_NUM_CHANNELS 10
59 #define PRU_USE_GPIO_ANALOG 11 59 #define PRU_USE_DIGITAL 11
60 60
61 short int digitalPins[NUM_DIGITALS]={ 61 short int digitalPins[NUM_DIGITALS]={
62 GPIO_NO_BIT_0, 62 GPIO_NO_BIT_0,
63 GPIO_NO_BIT_1, 63 GPIO_NO_BIT_1,
64 GPIO_NO_BIT_2, 64 GPIO_NO_BIT_2,
168 if(use_digital){ 168 if(use_digital){
169 printf("gNumDigitalChannels: %d;\n",gNumDigitalChannels); 169 printf("gNumDigitalChannels: %d;\n",gNumDigitalChannels);
170 for(int i=0; i<gNumDigitalChannels; i++){ 170 for(int i=0; i<gNumDigitalChannels; i++){
171 if(gpio_export(digitalPins[i])) { 171 if(gpio_export(digitalPins[i])) {
172 if(gRTAudioVerbose) 172 if(gRTAudioVerbose)
173 cout << "Warning: couldn't export digital GPIO pin " << digitalPins[i] << "\n"; 173 cerr << "Warning: couldn't export digital GPIO pin " << digitalPins[i] << "\n"; // this is left as a warning because if the pin has been exported by somebody else, can still be used
174 } 174 }
175 if(gpio_set_dir(digitalPins[i], OUTPUT_PIN)) { 175 if(gpio_set_dir(digitalPins[i], INPUT_PIN)) {
176 if(gRTAudioVerbose) 176 if(gRTAudioVerbose)
177 cout << "Couldn't set direction on digital GPIO pin " << digitalPins[i] << "\n"; 177 cerr << "Error: Couldn't set direction on digital GPIO pin " << digitalPins[i] << "\n";
178 return -1;
179 }
180 if(gpio_set_value(digitalPins[i], HIGH)) {
181 if(gRTAudioVerbose)
182 cout << "Couldn't set value on digital GPIO pin " << digitalPins[i] << "\n";
183 return -1; 178 return -1;
184 } 179 }
185 } 180 }
186 digital_enabled=true; 181 digital_enabled=true;
187 } 182 }
359 else { 354 else {
360 pru_buffer_comm[PRU_USE_SPI] = 0; 355 pru_buffer_comm[PRU_USE_SPI] = 0;
361 pru_buffer_comm[PRU_SPI_NUM_CHANNELS] = 0; 356 pru_buffer_comm[PRU_SPI_NUM_CHANNELS] = 0;
362 } 357 }
363 if(digital_enabled) { 358 if(digital_enabled) {
364 pru_buffer_comm[PRU_USE_GPIO_ANALOG] = 1; 359 pru_buffer_comm[PRU_USE_DIGITAL] = 1;
365 pru_buffer_comm[NUM_DIGITALS] = spi_num_channels; 360 //TODO: add mask
366 } 361 }
367 else { 362 else {
368 pru_buffer_comm[PRU_USE_GPIO_ANALOG] = 0; 363 pru_buffer_comm[PRU_USE_DIGITAL] = 0;
369 pru_buffer_comm[NUM_DIGITALS] = 0; 364
370 } 365 }
371 366
372 /* Clear ADC and DAC memory */ 367 /* Clear ADC and DAC memory.*/
368 //TODO: this initialisation should only address the memory effectively used by these buffers, i.e.:depend on the number of frames
369 // (otherwise might cause issues if we move memory locations later on)
373 if(spi_enabled) { 370 if(spi_enabled) {
374 for(int i = 0; i < PRU_MEM_DAC_LENGTH / 2; i++) 371 for(int i = 0; i < PRU_MEM_DAC_LENGTH / 2; i++)
375 pru_buffer_spi_dac[i] = 0; 372 pru_buffer_spi_dac[i] = 0;
373 if(digital_enabled){
374 for(int i = 0; i < PRU_MEM_DIGITAL_OFFSET*2; i++)
375 pru_buffer_digital[i] = 0x0000ffff; // set to all inputs, to avoid unexpected spikes
376 }
376 } 377 }
377 for(int i = 0; i < PRU_MEM_MCASP_LENGTH / 2; i++) 378 for(int i = 0; i < PRU_MEM_MCASP_LENGTH / 2; i++)
378 pru_buffer_audio_dac[i] = 0; 379 pru_buffer_audio_dac[i] = 0;
379 //TODO: maybe the lines below are to be deleted, as we removed the test code from pru_rtaudio.p ? 380 //TODO: maybe the lines below are to be deleted, as we removed the test code from pru_rtaudio.p ?
380 /* If using GPIO test pin for Xenomai (for debugging), initialise the pointer now */ 381 /* If using GPIO test pin for Xenomai (for debugging), initialise the pointer now */
458 } 459 }
459 if(lastDigitalBuffer == 0) { 460 if(lastDigitalBuffer == 0) {
460 rt_printf("Error: couldn't allocate digital buffers\n"); 461 rt_printf("Error: couldn't allocate digital buffers\n");
461 return; 462 return;
462 } 463 }
463 464
465 for(unsigned int n=0; n<digital_buffer_frames; n++){ //initialize lastDigitalFrames to all inputs
466 lastDigitalBuffer[n]= 0x0000ffff;
467 }
464 while(!gShouldStop) { 468 while(!gShouldStop) {
465 // Wait for PRU to move to buffer 1 469 // Wait for PRU to move to buffer 1
466 while(pru_buffer_comm[PRU_CURRENT_BUFFER] == 0 && !gShouldStop) { 470 while(pru_buffer_comm[PRU_CURRENT_BUFFER] == 0 && !gShouldStop) {
467 rt_task_sleep(sleepTime); 471 rt_task_sleep(sleepTime);
468 } 472 }