Exemple #1
0
/******************************************************************************
 *
 * Function Name: initSysTime()
 *
 * Description:
 *    This function initializes the LPC's Timer 0 for use as the system timer.
 *
 * Calling Sequence: 
 *    void
 *
 * Returns:
 *    void
 *
 *****************************************************************************/
void initSysTime(void)
{
#if defined(SYSTIME_INT_MODE)
	uint8_t i;
#endif
	
	T0TCR = TxTCR_Counter_Reset;           // reset & disable timer 0
	// setup Timer 1 to count forever
	T0PR = T0_PCLK_DIV - 1;               // set the prescale divider
	T0CCR = 0;                            // disable compare registers
	T0EMR = 0;                            // disable external match register
#if defined(SYSTIME_INT_MODE)
	for ( i=0; i<SYSTIME_MAX_CALLBACKS; i++ ) {
	  gCallbackFunctions[i] = NULL;
	  gCallbackRates[i]     = 0;
	  gCallbackCounters[i]  = 0;
	}
	VICIntSelect &= ~(VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer0));
	VICIntEnClr  = VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer0);
	VICVectAddr4 = (uint32_t)sysTimeISR;
	VICVectPriority4 = 0x01;
	VICIntEnable = VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer0);
	T0MR0 = T0TC + SYSTIME_INT_DT - 1;
	T0MCR = TxMCR_MR0I;        // interrupt on cmp-match0
	T0IR  = TxIR_MR0_Interrupt; // clear match0 interrupt
#else
	T0MCR = 0;                            // disable match registers
#endif
	T0TCR = TxTCR_Counter_Enable;         // enable timer 0
	sysTICs = 0;
}
//Setup Timer0 Compare-Match Interrupt
//no prescaler timer runs at cclk = FOSC*PLL_M
void init_timer0 (void)
{
	//Compare-hit
	T0MR0 = (FOSC*3/TIMER_TEILER0)-1;
	//Interrupt and Reset on MR0
	T0MCR = TxMCR_MR0I | TxMCR_MR0R;
	//Timer0 Enable
	T0TCR = TxTCR_COUNTER_ENABLE;
	//initialize the interrupt vector
	VICIntSelect    &= ~VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer0);
	VICIntEnClr      = VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer0);
	VICVectAddr4     = (unsigned long)tc0_isr;
	VICVectPriority4 = 0x05;
	VICIntEnable     = VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer0);
}
void RTCInit( void )
{
  alarm_on 			= 0;
  RTC_AMR 			= 0;
  RTC_CIIR 			= 0;
  RTC_CCR 			= 0;
  RTC_SEC			= 0;
  RTC_MIN			= 0;
  RTC_HOUR			= 0;
  RTC_DOM			= 1;
  RTC_DOW			= 1;
  RTC_DOY			= 1;
  RTC_MONTH			= 1;
  RTC_YEAR			= 2010;


  RTC_PREINT 		= PREINT_RTC;
  RTC_PREFRAC 		= PREFRAC_RTC;

  //VICIntSelect    	&= ~VIC_CHAN_TO_MASK(VIC_CHAN_NUM_RTC);
  VICIntEnClr      	= VIC_CHAN_TO_MASKLOW(VIC_CHAN_NUM_RTC);
  VICVectAddr13     = (unsigned long)RTC_ISR;
  VICVectPriority13 = 0x0F;
  VICIntEnable    	= VIC_CHAN_TO_MASK(VIC_CHAN_NUM_RTC);
}
//Setup Timer1 Compare-Match Interrupt
//no prescaler timer runs at cclk = FOSC*PLL_M
void init_timer3 (void)
{
	//Compare-hit (10Khz)
	T3MR0 = (FOSC*3/TIMER_TEILER3)-1;
	//Interrupt and Reset on MR0
	T3MCR = TxMCR_MR0I | TxMCR_MR0R;
	//Timer3 Enable
	T3TCR = TxTCR_COUNTER_ENABLE;

	//initialize the interrupt vector
	VICIntSelect    &= ~VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer3);
	VICIntEnClr      = VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer3);
	VICVectAddr27     = (unsigned long)tc3_isr;
	VICVectPriority27 = 0x05;
	VICIntEnable     = VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer3);
}
//Setup Timer1 Compare-Match Interrupt
//no prescaler timer runs at cclk = FOSC*PLL_M
void init_timer1 (void)
{
	//Compare-hit (10Khz)
	T1MR0 = 1;

	T1PR = 110;
	//Interrupt and Reset on MR0
	T1MCR = TxMCR_MR0I | TxMCR_MR0R;
	//Timer1 Enable
	T1TCR = TxTCR_COUNTER_ENABLE;
	//initialize the interrupt vector
	VICIntSelect    &= ~VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer1);
	VICIntEnClr      = VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer1);
	VICVectAddr5     = (unsigned long)tc1_isr;
	VICVectPriority5 = 0x01;
	VICIntEnable     = VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer1);
}
Exemple #6
0
/*! \brief Initializes the encoder counting.

    Initializes the Timer 0 and 3 peripherals to count rising and falling
    edges of the encoder signals.  The A and B encoder signals are XORed on the
    connector board to get twice the resolution.  The Timer 1 interrupt is then
    used to sample the counted ticks and store them.  Timer 1 samples at 50Hz.
 */
void EncoderInit(void)
{
	// 1. Power up timers 0, 1, and 3
	PCONP |= PCONP_PCTIM0 | PCONP_PCTIM1 | PCONP_PCTIM3;

	// 2. Make the peripheral clocks 72 MHz = divided by one
	PCLKSEL0 |= PCLKSEL0_TIM0_DIV1 | PCLKSEL0_TIM1_DIV1;
	PCLKSEL1 |= PCLKSEL1_TIM3_DIV1;

	// 3. Select pin functions.  Make P3.23 be CAP0 and P0.23 be CAP3.0.
	PINSEL7 |= (PINSEL7_CAP00);
	PINSEL1 |= (PINSEL1_CAP30);

	// 4. Setup timer counter
	T0CTCR = CTCR_CM_RF | CTCR_CAP_SEL_0;  // Timer is counter mode on rise/fall
										   // Start the counting on channel 0
	T0TCR = TCR_CR;						   // Reset timer0 counter
	T0PR = 0;							   // Increment TC after every rise/fall

	T3CTCR = CTCR_CM_RF | CTCR_CAP_SEL_0;  // Timer is counter mode on rise/fall
										   // Start the counting on channel 0
	T3TCR = TCR_CR;						   // Reset timer3 counter
	T3PR = 0;							   // Increment TC after every rise/fall

	// 5. Setup timer1 for a sample period of 20msec for counting
	T1TCR = TCR_CR;							// Reset timer1 counter
	T1CTCR = CTCR_TM;						// Timer 1 is in timer mode
	T1MR0 = MCR_20MS;						// Match at 20ms
	T1MCR = MCR_MR0I | MCR_MR0S | MCR_MR0R;	// On match, interrupt,reset,stop TC

	// Setup T1 Interrupt
	VICIntSelect &= ~VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer1);	// Change to IRQ
	VICIntEnClr |= VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer1); 	// Disable interrupt
	VICVectAddr5 = (uint32_t)(void *)EncoderISR;			// Assign the ISR
	VICVectPriority5 = 0xE;									// Set the priority
	VICIntEnable |= VIC_CHAN_TO_MASK(VIC_CHAN_NUM_Timer1);	// Enable the INT

	// 6. Enable the Timer counters
	T0TCR = TCR_CE;
	T3TCR = TCR_CE;
	T1TCR = TCR_CE;

	// 7. Setup direction inputs (input is 0)
	FIO3DIR &= ~LEFT_IN & ~RIGHT_IN;
}
Exemple #7
0
// Setup UART0 for the IMU at 38400 baud on P0.2 and P0.3
void Uart0Init(void)
{
	// 1. Turn on UART0 peripheral
	PCONP |= PCONP_UART0;

	// 2. Select the peripheral clock divider
	//    For baud rate of 38400 use divider of 1 so PCLK = 72MHz
	//    BR = PCLK / (16 * (256*DLM+DLL) * (1 + DIV/MULT))
	//    DLM = 0, DLL = 78, DIV = 1, MULT = 2
	//    So BR = 38461.5
	PCLKSEL0 |= PCLKSEL0_UART0_DIV1;

	// 3. Set the DLAB bit to write to the baud registers
	U0LCR = UART_DLAB;
	U0DLL = 52;//78;//26;
	U0DLM = 0;
	U0FDR = 0x21;
	U0LCR = UART_8BIT;

	// 4. Enable UART FIFO
	U0FCR |= UART_FIFO_EN | UART_RX_FIFO_RST | UART_TX_FIFO_RST;

	// 5. Enable Peripheral Pins P0.2(TXD0) & P0.3(RXD0)
	PINSEL0 |= PINSEL0_TXD0 | PINSEL0_RXD0;

	// 6. Enable transmit (no handshaking required)
	U0TER |= UART_TXEN;

	// 7. Setup Interrupts
	VICIntSelect &= ~VIC_CHAN_TO_MASK(VIC_CHAN_NUM_UART0);			// Change to IRQ
	VICIntEnClr |= VIC_CHAN_TO_MASK(VIC_CHAN_NUM_UART0); 				// Disable interrupt
	VICVectAddr6 = (uint32_t)(void *)Uart0ISR;	// Assign the ISR
	VICVectPriority6 = 0xE;							// Set the priority
	VICIntEnable |= VIC_CHAN_TO_MASK(VIC_CHAN_NUM_UART0);				// Enable the interrupt
	U0IER = UART_RXDAIE;							// Enable RX Data interrupt
	uart0_rx_insert = uart0_rx_extract = 0;			// Initialize buffer positions
	uart0_tx_insert = uart0_tx_extract = 0;
	uart0_tx_running = 0;
}