Interrupts and violate variables

Jaap
Hi,

I am trying to get a little tryout program to work. It is basically a copy
of the lcd test/example code on the site.

I want to count the number of touches in the "touch" interrupt and have
have the main loop wait 2 second before displaying the number of touches
and clearing it. However it seems as if the variable is not shared between
the interrupt and the main code.

Can anyone tell me what I might be doing wrong?

This my code:
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"

volatile int click_count = 0;


U32 click_section;


#define REQCNT 30
#define ADCPRS 9  //YH 0627
#define LOOP 1

int combined_count=0;
volatile int combined_xdata, combined_ydata;
    

void __irq Combined_AdcTsAuto(void)
{
  int i;
  U32 saveAdcdly;
  
    if(rADCDAT0&0x8000)
    {
    //Uart_Printf("\nStylus Up!!\n");
    rADCTSC&=0xff;  // Set stylus down interrupt bit
    }
    //else 
    //Uart_Printf("\nStylus Down!!\n");

  rADCTSC=(1<<3)|(1<<2);         //Pull-up disable, Seq. X,Y postion
measure.
  saveAdcdly=rADCDLY;
  rADCDLY=40000;                 //Normal conversion mode delay about
(1/50M)*40000=0.8ms

  rADCCON|=0x1;                   //start ADC

    while(rADCCON & 0x1);    //check if Enable_start is low
    while(!(rADCCON & 0x8000));        //check if EC(End of Conversion)
flag is high, This line is necessary~!!
    
            while(!(rSRCPND & (BIT_ADC)));  //check if ADC is finished with
interrupt bit

            combined_xdata=(rADCDAT0&0x3ff);
            combined_ydata=(rADCDAT1&0x3ff);

   //YH 0627, To check Stylus Up Interrupt.
   rSUBSRCPND|=BIT_SUB_TC;
   ClearPending(BIT_ADC);
   rINTSUBMSK=~(BIT_SUB_TC);
   rINTMSK=~(BIT_ADC);
       
   rADCTSC =0xd3;    //Waiting for interrupt
   rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.

      while(1)    //to check Pen-up state
      {
       if(rSUBSRCPND & (BIT_SUB_TC))  //check if ADC is finished with
interrupt bit
         {
          //Uart_Printf("Stylus Up Interrupt~!\n");
          break;  //if Stylus is up(1) state
        }
      }  
      
  EnterCritical(&click_section);
    
  click_count++; // Increase the counter!
  
  ExitCritical(&click_section);
  

  rADCDLY=saveAdcdly; 
  rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal.
    rSUBSRCPND|=BIT_SUB_TC;
    rINTSUBMSK=~(BIT_SUB_TC);  // Unmask sub interrupt (TC)     
    ClearPending(BIT_ADC);
}




// Test
void Test_Combined(void)
{
  int jaap;

  // Start touch
    rADCDLY=50000;                  //Normal conversion mode delay about
(1/3.6864M)*50000=13.56ms
    rADCCON=(1<<14)+(ADCPRS<<6);   //ADCPRS En, ADCPRS Value

    Uart_Printf("ADC touch screen test\n");

    rADCTSC=0xd3;  //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En

    pISR_ADC = (int)Combined_AdcTsAuto;
  rINTMSK=~BIT_ADC;       //ADC Touch Screen Mask bit clear
  rINTSUBMSK=~(BIT_SUB_TC);

  Uart_Printf("\nType any key to exit!!!\n");
  Uart_Printf("\nStylus Down, please...... \n");
  // Started touch
  
  
  // Wait for a esc key on serial
  while( Uart_GetKey() != ESC_KEY )
  {
    EnterCritical(&click_section);
  
    for(jaap=0; jaap<click_count; jaap++)
    {
      Uart_Printf("LOOP!!!\n");
    }
    
    click_count = 0;
    
    Uart_Printf("Tic!!!\n");
    Delay(2000);
  };
  
  
  // Stop keyscan
  DisableIrq(BIT_EINT0|BIT_EINT2|BIT_EINT8_23);  
  // Stopped keyscan
}

P.S. I know my naming conventions are bad ;-)

Jaap
Never mind I just saw forgot to exit the critical section...

brox
Actually you don't need those 3 global variables above to be declared
volatile. Bad copypaste practice:)