Example #1
0
/*
 * Setup the timer 0 to generate the tick interrupts at the required frequency.
 */
static void prvSetupTimerInterrupt( void )
{
	unsigned long ulCompareMatch;
	

	/* Calculate the match value required for our wanted tick rate. */
	ulCompareMatch = 1000000 / configTICK_RATE_HZ;

	/* Protect against divide by zero.  Using an if() statement still results
	in a warning - hence the #if. */
	#if portPRESCALE_VALUE != 0
	{
		ulCompareMatch /= ( portPRESCALE_VALUE + 1 );
	}
	#endif

	irqBlock();

	pRegs->CTL = 0x003E0000;
	pRegs->LOD = 1000 - 1;
	pRegs->RLD = 1000 - 1;
	pRegs->DIV = portTIMER_PRESCALE;
	pRegs->CLI = 0;
	pRegs->CTL = 0x003E00A2;

	irqRegister(64, vTickISR, NULL);

	irqEnable(64);

	irqUnblock();
}
Example #2
0
// Initialize touch input
void touchInit(uint32_t channelMask)
{
   int i;

   // Turn on clock gating for TSI and configure touch input
   clkEnable(CLK_TSI);

   TSI0_GENCS |= ( TSI_GENCS_ESOR_MASK    // Enable end of scan interrupt
                 | TSI_GENCS_MODE(0)      // Capacitive sensing
                 | TSI_GENCS_REFCHRG(4)   // Reference charge 4 uA
                 | TSI_GENCS_DVOLT(0)     // Voltage rails
                 | TSI_GENCS_EXTCHRG(7)   // External osc charge
                 | TSI_GENCS_PS(4)        // Pre-scalar divide by 4
                 | TSI_GENCS_NSCN(11)     // Scans per electrode
                 | TSI_GENCS_TSIIEN_MASK  // Input interrupt enable
                 | TSI_GENCS_STPE_MASK    // Enable in STOP mode
                 );

   TSI0_GENCS |= TSI_GENCS_TSIEN_MASK;

   // Read initial (baseline) values for each enabled channel
   sEnableMask = channelMask;
   for (i = (NUM_CHANNELS - 1); i >= 0; i--)
   {
      if ((1 << i) & sEnableMask)
      {
         scanStart(i);
         while (!(TSI0_GENCS & TSI_GENCS_EOSF_MASK)) // Wait until done
         ;

         sBaseCounts[i] = scanData();
      }
   }

   // Enable TSI interrupts and start the scan timer
   irqRegister(INT_TSI0, tsiIrqHandler, 0);
   irqEnable(INT_TSI0);

   {
      osTimerDef_t tDef;
      
      tDef.ptimer = startTimerCb;
      tDef.millisec = TOUCH_SCAN_TIME;
      tDef.name = "touch";

      sStartTimer = osTimerCreate(&tDef, osTimerPeriodic, 0);
      osTimerStart(sStartTimer, TOUCH_SCAN_TIME);
   }
}