Пример #1
0
void OneMsTaskTimer::start(uint32_t timer_index) {
  uint32_t load = (F_CPU / 1000);
  //// !!!! count = 0;
  overflowing = 0;
  // Base address for first timer
  g_ulBase = getTimerBase(timerToOffset(timer_index));
  timerAB = TIMER_A << timerToAB(timer_index);
  //Setup interrupts for duration, interrupting at 1kHz
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0+ timer_index);
  ROM_IntMasterEnable();
  ROM_TimerConfigure(g_ulBase, TIMER_CFG_PERIODIC);
  ROM_TimerLoadSet(g_ulBase, TIMER_A, F_CPU/1000);
  
  
  // Setup the interrupts for the timer timeouts.
  TimerIntRegister(g_ulBase, TIMER_A, OneMsTaskTimer_int);
  ROM_IntEnable(INT_TIMER0A+timer_index);
  ROM_TimerIntEnable(g_ulBase, TIMER_TIMA_TIMEOUT);
  ROM_TimerEnable(g_ulBase, TIMER_A);
  
}
Пример #2
0
int main(void) {

    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    
    //Set up the general purpose I/Os
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);    
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);//1024hz = 15625

    //Set up the input/output pins
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_1);
    GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6);
    
    //Set up the interrupt pins
    GPIOIntEnable(GPIO_PORTC_BASE, GPIO_INT_PIN_5 | GPIO_INT_PIN_6);
    GPIOIntRegister(GPIO_PORTC_BASE, interrupt_handler);
    GPIOIntTypeSet(GPIO_PORTC_BASE, (GPIO_PIN_5 | GPIO_PIN_6), GPIO_RISING_EDGE);

    //Just a quick toggle to make sure code is working
    toggle();
  
    //Timer Configuration
    TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
    TimerLoadSet(TIMER0_BASE, TIMER_A, frequency);
    TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
    TimerEnable(TIMER0_BASE, TIMER_A);

    //Timer Interrupt Enable
    TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    TimerIntRegister(TIMER0_BASE, TIMER_A, timer_interrupt);

    //Loop forever
    while(1){
          
      // if(TimerValueGet(TIMER0_BASE, TIMER_A) == 0){
      //           GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, pin_data);
      //           pin_data^=0x04;
      //     }
         }
}
Пример #3
0
//------------------------------------ Timer init ---------------------------------
void ir_timer_init(void) {

  // The Timer0 peripheral must be enabled for use.
  //
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

  //
  // The Timer0 peripheral must be enabled for use.
  // When  configured for a pair of half-width timers, each timer is separately configured.
  //
  ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_ONE_SHOT);

  // Calculate the number of timer counts/microsecond
  ulCountsPerMicrosecond = ROM_SysCtlClockGet() / 10000;

  // 0.10ms = timeout delay
  ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ulCountsPerMicrosecond);

  ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

  TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0AIntHandler );

  //
  // Configure the Timer0 interrupt for timer timeout.
  //
  ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

  //
  // Enable the Timer0 interrupt on the processor (NVIC).
  //
  ROM_IntEnable(INT_TIMER0A);

  gulTicks = 0;

  //
  // Enable Timer0A.
  //
  ROM_TimerEnable(TIMER0_BASE, TIMER_A);

}
Пример #4
0
void motor_init()
{
  unsigned long timer;

  //configure timer0 for one shot intervals and assign interrupt routine
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
  ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_ONE_SHOT);
  ROM_TimerControlStall(TIMER0_BASE, TIMER_A, true);
  TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0A_ISR);
  ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); 

  //setup RGB led outputs. 
  ROM_SysCtlPeripheralEnable(LED_PERIPH);
  ROM_GPIOPinTypeGPIOOutput(LED_PORT, LED_R | LED_G | LED_B );

  //enable peripherals used for motor
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
  
  //set motor pins to outputs
  ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, MOTOR_PORTA_PINS );
  ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, MOTOR_PORTB_PINS );
  ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, MOTOR_PORTD_PINS );
  ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, MOTOR_PORTE_PINS );


  //make sure motors are disabled and step pins are low
  motor_disable();
  motor_unstep();

  //start the timer.  the ISR will run at the minimum rate 
  //interval until there is a block to execute.
  timer=calculate_timer(MIN_STEP_RATE);
  ROM_TimerLoadSet(TIMER0_BASE,TIMER_A, timer);
  ROM_TimerEnable(TIMER0_BASE,TIMER_A);
}
Пример #5
0
void stepper_init(struct stepper *s){
	DAC082S085_init(&s->dac, SSI2_BASE);
	s->stepping_rate = 0;
	s->div = 1;

	// Enable the timer
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
	TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC);

	IntEnable(INT_TIMER2A);
	TimerIntRegister(TIMER2_BASE, TIMER_A, TIMER2IntHandler);
	TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT);

	//set up other necessary GPIO
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3); //AEN, BPH

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0); //BEN

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3); //APH
}
Пример #6
0
void confTimer(){

	//Inicializamos el TIMER2 para el ADC como Trigger a una frecuencia de 10Hz
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER2);
	TimerControlStall(TIMER2_BASE,TIMER_A,true);
	TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC);
	uint32_t ui32Period = SysCtlClockGet() *0.1;
	TimerLoadSet(TIMER2_BASE, TIMER_A, ui32Period -1);
	TimerControlTrigger(TIMER2_BASE,TIMER_A,true);
	TimerEnable(TIMER2_BASE, TIMER_A);

	//Inicializamos el TIMER4 para la pulsación larga con un periodo de 2 segundos
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
  SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER4);
  TimerConfigure(TIMER4_BASE, TIMER_CFG_ONE_SHOT);
  ui32Period = (SysCtlClockGet() *2) ;
  TimerLoadSet(TIMER4_BASE, TIMER_A, ui32Period -1);
  IntEnable(INT_TIMER4A);
  TimerIntRegister(TIMER4_BASE,TIMER_A,timerBotonHandler);
  IntPrioritySet(INT_TIMER4A,5<<5);
  TimerIntEnable(TIMER4_BASE, TIMER_TIMA_TIMEOUT);

}
int main()
{
	ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
   	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
   	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_BLUE);

	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    ROM_IntMasterEnable();

	ROM_TimerDisable(TIMER0_BASE, TIMER_A);
	ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
	ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet());

    ROM_IntEnable(INT_TIMER0A);
	ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0AIntHandler);

	ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_BLUE, led_value);

	ROM_TimerEnable(TIMER0_BASE, TIMER_A);
	while(1)
   	{}
}
Пример #8
0
int main(void) {
	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);	//Configure System Clock
//SSD
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);	//Enable Port D
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);	//Enable Port B
	GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,0x0F);
	GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,0xFF);
//S1 and S2
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);	//Enable Port F
//Mode 1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);		//Enable ADC0 Module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);	//Enable Port E
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);	//Select ADC Function of PE 1
	ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);	//Configure ADC0 Sequencer
	ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END);	//Configure the step of the sequencer
//Mode 2
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);	//Enable TIMER1 Module
	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4);	//Set PF4 as Input
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);		//Configuring the PF4
	GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_BOTH_EDGES);		//Setting Interrupt to trigger on both edges
	TimerConfigure(TIMER1_BASE,TIMER_CFG_PERIODIC);	//Configure TIMER1 into a Continuous Mode
	TimerIntRegister(TIMER1_BASE, TIMER_A, fast);	//Register interrupt if PF4 pressed for more than 1s
//Mode 3
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);	//Enable TIMER4 Module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);	//Enable WTIMER0 Module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);	//Enable Port C
	GPIOPinConfigure(GPIO_PC4_WT0CCP0);
	GPIOPinTypeTimer(GPIO_PORTC_BASE,GPIO_PIN_4);	//Set PC4 as a Timer Capture pin
	TimerIntRegister(TIMER4_BASE,TIMER_A,freqfind);	//Register a timer interrupt for TIMER4
	TimerConfigure(TIMER4_BASE,TIMER_CFG_PERIODIC);	//Configure Timer4 in continuous mode
	TimerConfigure(WTIMER0_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_CAP_COUNT);
	TimerControlEvent(WTIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);	//Configure WTIMER0 for Positive Edge Capture

	IntMasterEnable();
	GPIOPinWrite(GPIO_PORTB_BASE,0xFF,0x00);	//Initialize SSD to 0x00
	GPIOPinWrite(GPIO_PORTD_BASE, 0x0F, 0x00);	//Turn off all the digits of the SSD
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);	//Enable TIMER0 Module
	TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC);	//Configure TIMER0 into a Continuous Mode
	TimerIntRegister(TIMER0_BASE, TIMER_A, ssdmux);	//Register ISR for TIMER0 Interrupt to update SSD
	TimerLoadSet(TIMER0_BASE, TIMER_A,SysCtlClockGet()/3000);	//Set the refresh rate of the SSD
	IntEnable(INT_TIMER0A);
	TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT);	//Enable the timer interrupt
	TimerEnable(TIMER0_BASE,TIMER_A);	//Start the timer

	HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTF_BASE|GPIO_O_CR) = GPIO_PIN_0;	//Unlock PF0 from the NMI mode
	HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = 0;

	ssdset(0);
	mode1set();

	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);	//Setting PF0 to Input
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);		//Configuring the pins
	GPIOIntRegister(GPIO_PORTF_BASE, modeselect);		//Register Interrupt for Port F with ISR modeselect()
	GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_0);		//Clear any existing interrupts
	GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE);		//Setting Interrupt to trigger on falling edges
	GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0);		//Enable the GPIO Interrupts on Port F
	IntEnable(INT_GPIOF);	//Enable Interrupts on Port F

	while(1){
		switch(mode)	//Select operation according to mode
		{
		case 1: mode1();
				break;
		case 2: ssdsetHex(hex_count);
				if(fast_flag)
				{
					mode2();
					SysCtlDelay(SysCtlClockGet()/300);
				}
				break;
		case 3: mode3(); break;
		case 4: mode1(); break;
		case 5: ssdsetHex(hex_count);
				if(fast_flag)
				{
					mode2();
					SysCtlDelay(SysCtlClockGet()/300);
				} break;
				}
		SysCtlDelay(SysCtlClockGet()/3000);
	}
	return 0;
}
Пример #9
0
PROCESS_THREAD(hello_world_process, ev, data)
{

    //static struct etimer timer;
    PROCESS_BEGIN();
    //begintimer();
    //etimer_set(&timer, CLOCK_CONF_SECOND * 1);
    uint32_t ui32PrevCount = 0;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // (no ext 32k osc, no internal osc)
    //
    //SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);

    //
    // Set IO clock to the same as system clock
    //
    //SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);

    //
    // The Timer0 peripheral must be enabled for use.
    //
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);

    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for Timer operation.
    //
    //InitConsole();

    //
    // Display the example setup on the console.
    //
    printf(" 16-Bit Timer Interrupt ->\n\r");
    printf(" Timer = Timer0B\n\r");
    printf(" Mode = Periodic\n\r");
    printf(" Number of interrupts = %d \n\r", NUMBER_OF_INTS);
    printf(" Rate = 1ms\n\r");

    //
    // Configure Timer0B as a 16-bit periodic timer.
    //
    TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
                   GPTIMER_CFG_A_PERIODIC | GPTIMER_CFG_B_PWM);
    /*   TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
                       GPTIMER_CFG_A_PWM | GPTIMER_CFG_B_PWM);  */

    //
    // Set the Timer0B load value to 1ms.
    //
    TimerLoadSet(GPTIMER0_BASE, GPTIMER_B, sys_ctrl_get_sys_clock() / 100 );
    // TimerLoadSet(GPTIMER0_BASE, GPTIMER_B, SYS_CTRL_32MHZ );
    //
    // The following call will result in a dynamic interrupt table being used.
    // The table resides in RAM.
    // Alternatively SysTickIntHandler can be statically registred in your
    // application.
    //
    TimerIntRegister(GPTIMER0_BASE, GPTIMER_B, Timer0BIntHandler);

    //
    // Enable processor interrupts.
    //
    //IntMasterEnable();
    INTERRUPTS_ENABLE();
    //
    // Configure the Timer0B interrupt for timer timeout.
    //
    TimerIntEnable(GPTIMER0_BASE, GPTIMER_TIMB_TIMEOUT);

    //
    // Enable the Timer0B interrupt on the processor (NVIC).
    //
    IntEnable(INT_TIMER0B);

    //
    // Initialize the interrupt counter.
    //
    g_ui32Counter = 0;

    //
    // Enable Timer0B.
    //
    TimerEnable(GPTIMER0_BASE, GPTIMER_B);

    //
    // Loop forever while the Timer0B runs.
    //
    while(1)
    {
        //
        // If the interrupt count changed, print the new value
        //
        if(ui32PrevCount != g_ui32Counter)
        {
            //
            // Print the periodic interrupt counter.
            //
            printf("Number of interrupts: %d\r", g_ui32Counter);
            ui32PrevCount = g_ui32Counter;
        }
    }

    /*
      while(1) {
        	//PROCESS_YIELD();
     	//if(ev == PROCESS_EVENT_TIMER) {


    	printf(" Hello Hi \n\r" );
    	//etimer_set(&timer, CLOCK_SECOND);

        //}
      }
     */

    PROCESS_END();
}
Пример #10
0
void InitClocksGPIOAndTimer() {
	uint32_t ui32PWMClock;

	//
	// Enable lazy stacking for interrupt handlers.  This allows floating-point
	// instructions to be used within interrupt handlers, but at the expense of
	// extra stack usage.
	//
	ROM_FPULazyStackingEnable();

	//
	// Set the clocking to run directly from the crystal.
	//
	ROM_SysCtlClockSet(
	SYSCTL_SYSDIV_40 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
	ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

	// PWM Setup
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	GPIOPinConfigure(GPIO_PC4_M0PWM6);
	GPIOPinTypePWM(GPIO_PORTC_BASE, GPIO_PIN_4);
	GPIOPinConfigure(GPIO_PC5_M0PWM7);
	GPIOPinTypePWM(GPIO_PORTC_BASE, GPIO_PIN_5);

	ui32PWMClock = SysCtlClockGet();
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;

	PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, ui32Load);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6, PWM_LOW);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_7, PWM_LOW);

	// Started as not active
	PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, false);
	PWMOutputState(PWM0_BASE, PWM_OUT_7_BIT, false);
	PWMGenEnable(PWM0_BASE, PWM_GEN_3);

	// PWM Setup for IR LED
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPinConfigure(GPIO_PB6_M0PWM0);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
	PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
	PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 1050/8);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 525/8);

	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, false);
	PWMGenEnable(PWM0_BASE, PWM_GEN_0);

	//
	// Enable peripheral and register interrupt handler
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	GPIOIntRegister(GPIO_PORTA_BASE, GPIOMotionDetectorIsr);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	GPIOIntRegister(GPIO_PORTE_BASE, GPIOLightSwitchIsr);

#ifdef RUN_AS_MASTER
	GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5);
	GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_5, GPIO_BOTH_EDGES);
#else
	GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_2);
	GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);
#endif

	GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_4);
	GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_RISING_EDGE);

	//
	// Enable the pin interrupts.
	//
	GPIOIntEnable(GPIO_PORTA_BASE, GPIO_INT_PIN_2 | GPIO_INT_PIN_5);
	GPIOIntEnable(GPIO_PORTE_BASE, GPIO_INT_PIN_4);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_A_ONE_SHOT);
	TimerConfigure(TIMER1_BASE, TIMER_CFG_A_ONE_SHOT);
	TimerIntRegister(TIMER0_BASE, TIMER_A, IRTimerIsr);
	TimerIntRegister(TIMER1_BASE, TIMER_A, IdleTimerIsr);
	ulPeriod = (SysCtlClockGet()); // once per second

	TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod);
	TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod * LIGHTS_ON_PERIOD_SEC);
	TimerLoadSet(TIMER1_BASE, TIMER_B, ulPeriod * 3);

	IntEnable(INT_TIMER0A);
	IntEnable(INT_TIMER1A);
	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

	//
	// Enable the GPIO port that is used for the on-board LED.
	//
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	//
	// Enable the GPIO pin for blue LED component (PF2).
	//
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

	g_ulCountsPerMicrosecond = ROM_SysCtlClockGet() / 1000000;
	// 10ms = timeout delay
	g_ulIRPeriod = g_ulCountsPerMicrosecond * IR_TIMEOUT_VAL;
}
Пример #11
0
//*****************************************************************************
//
// Timer Interrupt Register
//
// Registers a desired function as the interrupt handler for a timer.
//
//*****************************************************************************
void Timer_IntRegister(void (*pfnHandler)(void))
{
	TimerIntRegister(TIMER0_BASE, TIMER_A, pfnHandler);
}
Пример #12
0
//  void setup(void) runs ONCE when the program just STARTS
void setup()
{
  // First SET the SYSTEM CLOCK to 80 [MHz]
  //  Sets the Clock DIVIDER to 2.5, so that SYS_CLOCK runs at 200/2.5 ==> 80 [MHz]
  SysCtlClockSet( SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

  uint32_t Timer0_Period;
  // Enable & Configure Serial(UART0) to BAUDRATE = 9216000
  Serial.begin(BAUDRATE);  

  // Configure PINS for LED OUTPUT
  pinMode(RED,OUTPUT);
  pinMode(BLUE,OUTPUT);
  pinMode(GREEN,OUTPUT);

  // Set LED OUTPUT pins to OFF initially
  digitalWrite(RED,LOW);
  digitalWrite(BLUE,LOW);
  digitalWrite(GREEN,LOW);
  state_led=0;  // initialize the STATE to STATE0

    // Initialize the 'Wire' class for the I2C-bus.
  Wire.begin();

  // Clear the 'sleep' bit to start the sensor.
  MPU9150_writeSensor(MPU9150_PWR_MGMT_1, 0);
  int temp0;
  temp0=  MPU9150_readSensor(0x1c);
  temp0 |= (0x10);
  temp0 &=~(0x08);

  
  MPU9150_writeSensor(0x1c,temp0);
  
  MPU9150_writeSensor(0x19,0x0f);
  MPU9150_setupCompass();

  
  SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0); // Enable Timer0

    TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // Set Timer0 mode PERIODIC



    // Timer0_Period ==> 80e6 * A / B, (1/2)=0.5
  Timer0_Period = ( 80000000 * A ) / B;      
  TimerLoadSet( TIMER0_BASE, TIMER_A, Timer0_Period-1);


  // REGISTER ISR to TIMER0 INTERRUPT
  TimerIntRegister( TIMER0_BASE, TIMER_A, Timer0_isr );

  // Enable Interrupts from Timer0_A
  IntEnable( INT_TIMER0A);


  // Set Timer Interrupt Condition and Enable Timer Interrupt
  TimerIntEnable( TIMER0_BASE, TIMER_TIMA_TIMEOUT);

  // Enable INTERRUPTS for the SYSTEM
  IntMasterEnable();

  // Start Timer0	
  TimerEnable(TIMER0_BASE, TIMER_A);        
}
Пример #13
0
void joystick_init(void) {

	// Register Joystick button isr
	GPIOPinTypeGPIOInput(JOY_PORT, JOY_MASK);
	GPIOPadConfigSet(JOY_PORT, JOY_MASK, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
	GPIOIntTypeSet(JOY_PORT, JOY_MASK, GPIO_BOTH_EDGES);
	GPIOPortIntRegister(JOY_PORT, button_handler);
	GPIOPinIntEnable(JOY_PORT, JOY_MASK);

    //
    // The ADC0 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

    //
    // Select the analog ADC function for these pins.
    //
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3);

    // Use sequences 0 and 1 for x and y.
    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

    // Single ended sample on CH3 (X) and CH4 (Y).
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH4 | ADC_CTL_IE | ADC_CTL_END);

    // Enable the sequences.
    ADCSequenceEnable(ADC0_BASE, 0);
    ADCSequenceEnable(ADC0_BASE, 1);

    // Register ISRs.
    ADCIntRegister(ADC0_BASE, 0, x_handler);
    ADCIntRegister(ADC0_BASE, 1, y_handler);
    ADCIntEnable(ADC0_BASE, 0);
    ADCIntEnable(ADC0_BASE, 1);

    // Trigger the first conversion (auto-center)
	ADCProcessorTrigger(ADC0_BASE, 0);
	ADCProcessorTrigger(ADC0_BASE, 1);

	// Configure timer
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
	TimerConfigure(JOY_TIMER, TIMER_CFG_PERIODIC);


//	//Register Jog Z buttons
//	GPIOPinTypeGPIOInput(JOG_Z_PORT, JOG_Z_MASK);
//	GPIOIntTypeSet(JOG_Z_PORT, JOG_Z_MASK, GPIO_BOTH_EDGES);
//	GPIOPortIntRegister(JOG_Z_PORT, jog_z_handler);
//	GPIOPinIntEnable(JOG_Z_PORT, JOG_Z_MASK);
//	GPIOPadConfigSet(JOG_Z_PORT,JOG_Z_MASK,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPD);

	// Create a 10ms timer callback
	TimerLoadSet64(JOY_TIMER, SysCtlClockGet() / 500);
	TimerIntRegister(JOY_TIMER, TIMER_A, joystick_isr);
	TimerIntEnable(JOY_TIMER, TIMER_TIMA_TIMEOUT);
	IntPrioritySet(INT_TIMER3A, CONFIG_JOY_PRIORITY);
	TimerEnable(JOY_TIMER, TIMER_A);
}
Пример #14
0
int main(void) {
  SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);//1024hz = 15625
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
  GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);
  GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_3);
  GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
  GPIOPinConfigure(GPIO_PB1_U1TX);
  GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1);
  UARTConfigSetExpClk(b1, SysCtlClockGet(), 9600, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
  UARTEnable(b1);

  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);


  GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, (GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_1));
  GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
  frequency = SysCtlClockGet()/2;

  changeCursorUnderscore();
  toggleLED();


  //Clear Display
  clearDisplay();
  //putPhrase("Hello World!");
  //Timer Configuration
  TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
  TimerLoadSet(TIMER0_BASE, TIMER_A, frequency);
  TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
  TimerEnable(TIMER0_BASE, TIMER_A);

  //Timer Interrupt Enable
  TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  TimerIntRegister(TIMER0_BASE, TIMER_A, timer_interrupt);


  while(1){
    if(flag = 1){  
    //Reset the line read
      code = 0;

    //Turn on the scan for a line
      if(counter == 0) GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, 0x8);
      if(counter == 1) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4, 0x10);
      if(counter == 2) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0x20);
      if(counter == 3) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0x40);

    //Check which button on the line was pressed
      if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_5) == 0x20) {
        code = 1;
        temp = log_code;
      }
      if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_6) == 0x40) {
        code = 2;
        temp = log_code;
      }
      if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_7) == 0x80) {
        code = 3;
        temp = log_code;
      }

    //Turn off the scan for a line
      if(counter == 0) GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, 0x0);
      if(counter == 1) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4, 0x0);
      if(counter == 2) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0x0);
      if(counter == 3) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0x0);

    //Check the next line on the next run and if overflows, reset


    //Calculate the index_code for the lookup table
      index_code = temp + code;
      key_char = lookup_table[index_code];
      log_code = log_code + 4;
      if(log_code > 12){
        log_code = 0;
      }

      counter++;
      if(counter > 3) counter = 0;
      if(key_char != 'x'){
        //toggleLED();
        putChar(key_char);
      //SysCtlDelay(100000);
        index_code = 0;
      }
      flag = 0;
    }
  }

}