Esempio n. 1
0
void Sysdelay(unsigned int milliSec)
{
#ifdef DELAY_USE_INTERRUPTS
    unsigned int countVal = TIMER_OVERFLOW - (milliSec * TIMER_1MS_COUNT);

    DMTimerCounterSet(SOC_DMTIMER_7_REGS, countVal);

    flagIsr = FALSE;

    /* Enable the DMTimer interrupts */
    DMTimerIntEnable(SOC_DMTIMER_7_REGS, DMTIMER_INT_OVF_EN_FLAG);

    /* Start the DMTimer */
    DMTimerEnable(SOC_DMTIMER_7_REGS);

    while(FALSE == flagIsr) ;

    /* Disable the DMTimer interrupts */
    DMTimerIntDisable(SOC_DMTIMER_7_REGS, DMTIMER_INT_OVF_EN_FLAG);

#else
    while(milliSec != 0)
    {
        DMTimerCounterSet(SOC_DMTIMER_7_REGS, 0);
        DMTimerEnable(SOC_DMTIMER_7_REGS);
        while(DMTimerCounterGet(SOC_DMTIMER_7_REGS) < TIMER_1MS_COUNT);
        DMTimerDisable(SOC_DMTIMER_7_REGS);
        milliSec--;
    }
 
#endif
}
Esempio n. 2
0
/**
 * /brief This function starts the timer.
 *
 * /milliSec Maximum value = TIMER_OVERFLOW/TIMER_1MS_COUNT.
 *
 * /NOTE  SysDelay functionality cannot be used till SysStopTimer is called.
 */
void SysStartTimer(unsigned int milliSec)
{
#ifdef DELAY_USE_INTERRUPTS
    unsigned int countVal = TIMER_OVERFLOW - (milliSec * TIMER_1MS_COUNT);

    DMTimerCounterSet(SOC_DMTIMER_7_REGS, countVal);

    flagIsr = FALSE;

    /* Enable the DMTimer interrupts */
    DMTimerIntEnable(SOC_DMTIMER_7_REGS, DMTIMER_INT_OVF_EN_FLAG);

    /* Start the DMTimer */
    DMTimerEnable(SOC_DMTIMER_7_REGS);
#else
    DMTimerCounterSet(SOC_DMTIMER_7_REGS, 0);
    DMTimerEnable(SOC_DMTIMER_7_REGS);
    flagIsr = milliSec;
#endif
}
Esempio n. 3
0
/*
** Timer 2 Interrupt Service Routine
*/
static void Timer2Isr(void)
{
	static unsigned int index = 0;
	
    /* Clear the status of the interrupt flags */
    DMTimerIntStatusClear(SOC_DMTIMER_2_REGS, DMTIMER_INT_OVF_EN_FLAG);
    
    tmr2Flag = TRUE;
	
	DMTimerCounterSet(SOC_DMTIMER_2_REGS, timerCount[index++%10]);
	
	DMTimerEnable(SOC_DMTIMER_2_REGS);	
	
}
unsigned int SysTimer(unsigned int flag)
{
    unsigned int timeInTicks=0;

    if(flag)
    {
            DMTimerCounterSet(SOC_DMTIMER_7_REGS, 0);
            DMTimerEnable(SOC_DMTIMER_7_REGS);
    }
    else
    {
            DMTimerDisable(SOC_DMTIMER_7_REGS);
            timeInTicks = DMTimerCounterGet(SOC_DMTIMER_7_REGS);
    }

    return timeInTicks;
}
Esempio n. 5
0
/******************************************************************************
**                          FUNCTION DEFINITIONS
*******************************************************************************/
int main(void)
{
    /* This function will enable clocks for the DMTimer2 instance */
    DMTimer2ModuleClkConfig();

    /* Initialize the UART console */
    ConsoleUtilsInit();

    /* Select the console type based on compile time check */
    ConsoleUtilsSetType(CONSOLE_UART);

    /* Enable IRQ in CPSR */
    IntMasterIRQEnable();

    /* Register DMTimer2 interrupts on to AINTC */
    DMTimerAintcConfigure();

    /* Perform the necessary configurations for DMTimer */
    DMTimerSetUp();

    /* Enable the DMTimer interrupts */
    DMTimerIntEnable(SOC_DMTIMER_2_REGS, DMTIMER_INT_OVF_EN_FLAG);

    ConsoleUtilsPrintf("Tencounter: ");

    /* Start the DMTimer */
    DMTimerEnable(SOC_DMTIMER_2_REGS);  

    while(cntValue)
    {
        if(flagIsr == 1)
        {
            ConsoleUtilsPrintf("\b%d",(cntValue - 1));
            cntValue--;
            flagIsr = 0;
        }
    }

    /* Stop the DMTimer */
    DMTimerDisable(SOC_DMTIMER_2_REGS); 

    PRINT_STATUS(S_PASS);

    /* Halt the program */
    while(1);
}
Esempio n. 6
0
/*
** Configure and start the Timer
*/
static void TimerSetupAndEnable(void)
{
    /* This function will enable clocks for the DMTimer2 instance */
    DMTimer2ModuleClkConfig();

    /* Load the counter with the initial count value */
    DMTimerCounterSet(TIMER_INST_BASE, TIMER_INITIAL_COUNT);

    /* Load the load register with the reload count value */
    DMTimerReloadSet(TIMER_INST_BASE, TIMER_RLD_COUNT);

    /* Configure the DMTimer for Auto-reload and compare mode */
    DMTimerModeConfigure(TIMER_INST_BASE, DMTIMER_AUTORLD_NOCMP_ENABLE);

    /* Enable the DMTimer interrupts */
    DMTimerIntEnable(TIMER_INST_BASE, DMTIMER_INT_OVF_EN_FLAG);

    /* Start the DMTimer */
    DMTimerEnable(TIMER_INST_BASE);

    IntSystemEnable(TIMER_INT_NUM);
}
Esempio n. 7
0
static void TouchScreenIsr()
{
    unsigned int wordsLeft = 0;
    unsigned int status;
    unsigned int arr_x[5] = {0,0,0,0,0};
    unsigned int arr_y[5] = {0,0,0,0,0};
    unsigned int x_data = 0;
    unsigned int y_data = 0;
    unsigned int i = 0;
    unsigned int sum = 0;

    status = TSCADCIntStatus(TSC_ADC_INSTANCE);

    if(status & TSCADC_FIFO1_THRESHOLD_INT)
    {
         wordsLeft = TSCADCFIFOWordCountRead(TSC_ADC_INSTANCE, TSCADC_FIFO_0);

         while(wordsLeft)
         {
              x_data = TSCADCFIFOADCDataRead(TSC_ADC_INSTANCE, TSCADC_FIFO_0);

              arr_x[i++] = x_data;

              wordsLeft = TSCADCFIFOWordCountRead(TSC_ADC_INSTANCE, TSCADC_FIFO_0);
         }

         sum = arr_x[1] + arr_x[2] + arr_x[3];

         sum = sum / 3;

         x_data = sum;

         wordsLeft = TSCADCFIFOWordCountRead(TSC_ADC_INSTANCE, TSCADC_FIFO_1);

         i = 0;

         while(wordsLeft)
         {
              y_data = TSCADCFIFOADCDataRead(TSC_ADC_INSTANCE, TSCADC_FIFO_1);

              arr_y[i++] = y_data;

              wordsLeft = TSCADCFIFOWordCountRead(TSC_ADC_INSTANCE, TSCADC_FIFO_1);
         }

         sum = arr_y[1] + arr_y[2] + arr_y[3];

         sum = sum / 3;

         y_data = sum;

    }

    x_val[Index] = x_data;
    y_val[Index] = y_data;

    Index = (Index + 0x01) & 0x01;

    /* Load the counter with the initial count value */
    DMTimerCounterSet(SOC_DMTIMER_2_REGS, 0);

    /* Start the DMTimer */
    DMTimerEnable(SOC_DMTIMER_2_REGS);

    TSCADCIntStatusClear(TSC_ADC_INSTANCE,  TSCADC_FIFO1_THRESHOLD_INT);

    IsTSPress = 1;

    StepEnable();
}
Esempio n. 8
0
/*
** ISR for Touch Screen
*/
static void TouchScreenIsr(void)
{
    volatile unsigned int wordsLeft = 0;
    unsigned int status;
    unsigned int i = 0;
    unsigned int prevVal_x = 0xFFFFFFFF;
    unsigned int prevVal_y = 0xFFFFFFFF;
    unsigned int currDiff_x;
    unsigned int currDiff_y;
    unsigned int prevDiff_x = 0xFFFFFFFF;
    unsigned int prevDiff_y = 0xFFFFFFFF;
    unsigned int readx1;
    unsigned int ready1;

    status = TSCADCIntStatus(SOC_ADC_TSC_0_REGS);
	
	wordsLeft = TSCADCFIFOWordCountRead(SOC_ADC_TSC_0_REGS, TSCADC_FIFO_1);

    if(status & TSCADC_FIFO1_THRESHOLD_INT)
    {
         for (i = 0; i < wordsLeft; i++) 
         { 
              readx1 = TSCADCFIFOADCDataRead(SOC_ADC_TSC_0_REGS, TSCADC_FIFO_0);
              readx1 = readx1 & 0xfff; 

              if (readx1 > prevVal_x) 
              {
                   currDiff_x = readx1 - prevVal_x; 
              }
              else 
              { 
                   currDiff_x = prevVal_x - readx1; 
              }
              if (currDiff_x < prevDiff_x) 
              { 
                   prevDiff_x = currDiff_x; 
                   xdata = readx1; 
              } 
              prevVal_x = readx1;
 
              ready1 = TSCADCFIFOADCDataRead(SOC_ADC_TSC_0_REGS, TSCADC_FIFO_1);
              ready1 &= 0xfff; 

              if (ready1 > prevVal_y) 
              {
                  currDiff_y = ready1 - prevVal_y; 
              }
              else
              { 
                  currDiff_y = prevVal_y - ready1; 
              }
              if (currDiff_y < prevDiff_y) 
              { 
                  prevDiff_y = currDiff_y; 
                  ydata = ready1; 
              } 
              prevVal_y = ready1; 
              wordsLeft = TSCADCFIFOWordCountRead(SOC_ADC_TSC_0_REGS, TSCADC_FIFO_1);			  
         } 

         x_data[dbidx] = xdata;
         y_data[dbidx] = ydata;
         dbidx = (dbidx + 1) & 0x01;
    }

    /* Restart the timer counter */
    DMTimerCounterSet(SOC_DMTIMER_3_REGS, 0);
    DMTimerEnable(SOC_DMTIMER_3_REGS);

    //TSCADCIntStatusClear(SOC_ADC_TSC_0_REGS,  TSCADC_FIFO1_THRESHOLD_INT);
	TSCADCIntStatusClear(SOC_ADC_TSC_0_REGS,   TSCADC_FIFO1_THRESHOLD_INT |
										   TSCADC_ASYNC_HW_PEN_EVENT_INT |
										   TSCADC_SYNC_PEN_EVENT_INT |
										   TSCADC_FIFO0_UNDER_FLOW_INT |
										   TSCADC_FIFO1_UNDER_FLOW_INT |
										   TSCADC_END_OF_SEQUENCE_INT |
										   TSCADC_FIFO0_THRESHOLD_INT |
										   TSCADC_FIFO0_OVER_RUN_INT |
										   TSCADC_FIFO1_OVER_RUN_INT |
										   TSCADC_OUT_OF_RANGE_INT |
										   TSCADC_PEN_UP_EVENT_INT);

    IsTSPress = 1;
    touchRelease = 0;
   
    StepEnable();
}
Esempio n. 9
0
/*
** Starts the Timer
*/
void Timer6Start(void)
{
    /* Start the DMTimer */
    DMTimerEnable(SOC_DMTIMER_6_REGS);
}