Processing of gpio interruptions under WinCE

Source: Internet
Author: User

In the audio driver code I am in charge of, I used PXA270 gpio34 to detect headphone insertion and removal. the original driver has a bug, that is, when the headset is inserted, the headset and the Horn are both ringing, and it is obvious that the headset insertion event is not responding. so I started to use the detection gpio signal pull high or pull low and the detection of the headset insertion event, but there is a problem with this, there is a delay, after inserting the headset, the speaker will be switched off in a second or two. in order to change this method, after consultation, we decided to adopt the method of interruption to do this, which can ensure that there is no such detection delay.

Add the following code to the initcodec function of hwctxt. cpp of the audio driver (wm9705:

If (m_pgpioregs = NULL)
{
Physical_address iophysicalbase = {bulverde_base_reg_pa_gpio, 0 };
M_pgpioregs = (pbulverde_gpio_reg) mmmapiospace (iophysicalbase, sizeof (bulverde_gpio_reg), false );

}

Setthreadpriority (getcurrentthread (), thread_priority_normal );

// Create the headphone event
Gheadphoneintrevent = createevent (null, false, false, null );

// Interrupt initialize and connect sysintr with event.

If (! (Interruptinitialize (sysintr_headphone_detect, gheadphoneintrevent, null, 0 ))){
Wav_dbgmsg (text ("[audio] intialize the interrupt gheadphoneintrevent error \ r \ n "));

}

// Create the interrupt thread
Gheadphoneintrthread = createthread (null, 0, (lpthread_start_routine) headphoneintrthread, this, 0, null );
If (! Gheadphoneintrthread)
{
Wav_dbgmsg (text ("create the detect thread failure -- \ r \ n "));
}

Sysintr_headphone_detect is defined in bsp_cfg.h. The specific definition is as follows:

# Define sysintr_headphone_detect (sysintr_firmware + 19) // chose a unused intr

The specific interrupt handling functions are as follows:

Int winapi headphoneintrthread (void)
{

While (1)
{
Waitforsingleobject (gheadphoneintrevent, infinite );

 
// If gpio34 is high, means headphone is inserted
If (m_pgpioregs-> gplr1 & xllp_bit_2)
{

Headphone_detect = 1;
// Wav_dbgmsg (text ("[audio] In headphoneintrthread headphone in -- \ r \ n "));
Wmaudiomutesignal (devicetorw, wm_audio_headphone, false); // open headphone output
Wmaudiomutesignal (devicetorw, wm_audio_lineout, true); // mute the lineout output
}
Else
{

Headphone_detect = 0;
// Wav_dbgmsg (text ("[audio] In headphoneintrthread headphone out -- \ r \ n "));
Wmaudiomutesignal (devicetorw, wm_audio_headphone, true );
Wmaudiomutesignal (devicetorw, wm_audio_lineout, false );

}

Interruptdone (sysintr_headphone_detect );
}
}

But how does sysintr_headphone_detect relate to the actual interruption? The specific operation is in intr. C. The file is located in \ project \ platform \ mainstoneii \ SRC \ kernel \ OAL.

Oalintrstatictranslate (sysintr_headphone_detect, irq_headphone_detect );
This statement associates sysintr_headphoone_detect with the real interrupt number, and the definition of irq_headphone_detect is also here: # define irq_headphone_detect (irq_bulverde_max + 15)

Note that irq_headphone_detect and # define irq_gpio0_pcmcia_s1_csc (irq_bulverde_max + 15) are the same here, because PCMCIA is useless in the system, so we use this interrupt for our headphone. so don't forget to comment out the following sentence, or your system will not know who the interruption is.

// Oalintrstatictranslate (sysintr_pccard_csc_s1, irq_gpio0_pcmcia_s1_csc );

Then add the headphone IRQ processing to the bspintrenableirq function:

If (IRQ = irq_headphone_detect)
{
// Wav_dbgmsg (text ("[audio] setting gpio for headphone in bspintrenableirq \ r \ n "));

G_pgpioregs-> gafrstml & = ~ Xllp_gpio_af_bit_ffrxd_mask; // gpio34 as gpio
G_pgpioregs-> gpdr1 & = ~ Xllp_bit_2; // gpio34 as HPS Input

// Set the falling edge and rising EDG to work
G_pgpioregs-> gfer1 | = xllp_bit_2;
G_pgpioregs-> grer1 | = xllp_bit_2;
}

Similarly, in the bspintrdisableirq function, add the code to process headphone IRQ:

Else if (IRQ = irq_headphone_detect)
{

// Clear the falling edge and rising to start the interrupt
G_pgpioregs-> gfer1 & = ~ Xllp_bit_2;
G_pgpioregs-> grer1 & = ~ Xllp_bit_2;
}

In the bspintractiveirq function, we can know that this function is used: This function is called from interrupt handler to give BSP chance to translate IRQ in case of secondary interrupt controller. we can see that the headphone IRQ function is gpioxx2interrupthandler (). handle headphone in this function
The IRQ code is as follows:

Else if (g_pgpioregs-> gedr1 & xllp_bit_2)

{// Set the gpio edge Status Register
G_pgpioregs-> gedr1 | = xllp_bit_2;
// Return IRQ to enbale the event
Return irq_headphone_detect;
}

The returned interrupt number can trigger the event. In this case, waitforsingleobject (gheadphoneintrevent, infinite) in the interrupt handler; you can see that the interrupt has occurred; otherwise, it will wait here.

In this way, the gpio Interrupt Processing under wince is completed after detection.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.