Exemple #1
0
void motorSetup()
{
	/* Set pin mode for Hbridge output pins */
	MAP_PinTypeGPIO(AIN1, PIN_MODE_0, false); /* Ain 1 */
	MAP_PinTypeGPIO(AIN2, PIN_MODE_0, false); /* Bin 1 */
	MAP_PinTypeGPIO(BIN1, PIN_MODE_0, false);  /* Bin 2 */
	MAP_PinTypeGPIO(BIN2, PIN_MODE_0, false); /* Ain 2 */

	/* Get port name and bin number from GPIO number (TI lookup table) */
	GPIO_IF_GetPortNPin(AIN1x, &port_ain1, &pin_ain1);
	GPIO_IF_GetPortNPin(AIN2x, &port_ain2, &pin_ain2);
	GPIO_IF_GetPortNPin(BIN1x, &port_bin1, &pin_bin1);
	GPIO_IF_GetPortNPin(BIN2x, &port_bin2, &pin_bin2);

	/* Set pin direction */
	GPIODirModeSet(port_ain1, pin_ain1, 1);
	GPIODirModeSet(port_ain2, pin_ain2, 1);
	GPIODirModeSet(port_bin1, pin_bin1, 1);
	GPIODirModeSet(port_bin2, pin_bin2, 1);

	/* Set value to write to PIN */
	bitA1 = 1 << (AIN1x % 8);
	bitA2 = 1 << (AIN2x % 8);
	bitB1 = 1 << (BIN1x % 8);
	bitB2 = 1 << (BIN2x % 8);

	// Enable timer A peripheral
	MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0, PRCM_RUN_MODE_CLK);
	MAP_PRCMPeripheralReset(PRCM_TIMERA0);

	// Split channels and configure for periodic interrupts
	MAP_TimerConfigure(TIMERA0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);
	MAP_TimerPrescaleSet(TIMERA0_BASE, TIMER_A, 0);
	MAP_TimerPrescaleSet(TIMERA0_BASE, TIMER_B, 0);

	// Set compare interrupt
	MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMA_MATCH);
	MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMB_MATCH);

	// Configure compare interrupt, start with 0 speed
	MAP_TimerMatchSet(TIMERA0_BASE, TIMER_A, 0);
	MAP_TimerMatchSet(TIMERA0_BASE, TIMER_B, 0);

	// Set timeout interrupt
	MAP_TimerIntRegister(TIMERA0_BASE, TIMER_A, TimerBaseIntHandlerA);
	MAP_TimerIntRegister(TIMERA0_BASE, TIMER_B, TimerBaseIntHandlerB);
	MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMA_TIMEOUT);
	MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMB_TIMEOUT);

	// Turn on timers
	MAP_TimerLoadSet(TIMERA0_BASE, TIMER_A, MOTOR_PRESCALER);
	MAP_TimerLoadSet(TIMERA0_BASE, TIMER_B, MOTOR_PRESCALER);

	MAP_TimerEnable(TIMERA0_BASE, TIMER_A);
	MAP_TimerEnable(TIMERA0_BASE, TIMER_B);
}
Exemple #2
0
void motorSetup()
{
  pinMode(AIN1x, OUTPUT);
  pinMode(AIN2x, OUTPUT);
  pinMode(BIN1x, OUTPUT);
  pinMode(BIN2x, OUTPUT);

  bitA1 = digitalPinToBitMask(AIN1x);
  bitA2 = digitalPinToBitMask(AIN2x);
  bitB1 = digitalPinToBitMask(BIN1x);
  bitB2 = digitalPinToBitMask(BIN2x);
  
  portA1 = digitalPinToPort(AIN1x);
  portA2 = digitalPinToPort(AIN2x);
  portB1 = digitalPinToPort(BIN1x);
  portB2 = digitalPinToPort(BIN2x);
  
  baseA1 = (uint32_t) portBASERegister(portA1);
  baseA2 = (uint32_t) portBASERegister(portA2);
  baseB1 = (uint32_t) portBASERegister(portB1);
  baseB2 = (uint32_t) portBASERegister(portB2);
  
  // Enable timer A peripheral
  MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0, PRCM_RUN_MODE_CLK);
  MAP_PRCMPeripheralReset(PRCM_TIMERA0);
  
  // Split channels and configure for periodic interrupts
  MAP_TimerConfigure(TIMERA0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);
  MAP_TimerPrescaleSet(TIMERA0_BASE, TIMER_A, 0);
  MAP_TimerPrescaleSet(TIMERA0_BASE, TIMER_B, 0);

  // Set compare interrupt
  MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMA_MATCH);
  MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMB_MATCH);

  // Configure compare interrupt, start with 0 speed
  MAP_TimerMatchSet(TIMERA0_BASE, TIMER_A, 0);
  MAP_TimerMatchSet(TIMERA0_BASE, TIMER_B, 0);

  // Set timeout interrupt
  MAP_TimerIntRegister(TIMERA0_BASE, TIMER_A, TimerBaseIntHandlerA);
  MAP_TimerIntRegister(TIMERA0_BASE, TIMER_B, TimerBaseIntHandlerB);
  MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMA_TIMEOUT);
  MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMB_TIMEOUT);

  // Turn on timers
  MAP_TimerLoadSet(TIMERA0_BASE, TIMER_A, MOTOR_PRESCALER);
  MAP_TimerLoadSet(TIMERA0_BASE, TIMER_B, MOTOR_PRESCALER);
 
  MAP_TimerEnable(TIMERA0_BASE, TIMER_A);
  MAP_TimerEnable(TIMERA0_BASE, TIMER_B);
}
Exemple #3
0
void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
{
	/* Use TIMERA0B since it is not on any pin */

	tone_timer = digitalPinToTimer(pin);

	if(tone_timer == NOT_ON_TIMER)
		return;

	if(tone_state != 0 && pin != current_pin)
		return;

	g_duration = duration;
	current_pin = pin;
	tone_state = 2;

	MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0, PRCM_RUN_MODE_CLK);
	MAP_PRCMPeripheralReset(PRCM_TIMERA0);
	MAP_TimerConfigure(TIMERA0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC);
	MAP_TimerIntRegister(TIMERA0_BASE, TIMER_B, ToneIntHandler);
	MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMB_TIMEOUT);
	MAP_TimerPrescaleSet(TIMERA0_BASE, TIMER_B, 7);
	MAP_TimerLoadSet(TIMERA0_BASE, TIMER_B, (F_CPU / 8) / 1000);
	MAP_TimerEnable(TIMERA0_BASE, TIMER_B);

	PWMWrite(pin, 256, 128, frequency);
}
Exemple #4
0
void controller_setup(){
	// Enable timer A peripheral
  	MAP_PRCMPeripheralClkEnable(PRCM_TIMERA1, PRCM_RUN_MODE_CLK);
  	MAP_PRCMPeripheralReset(PRCM_TIMERA1);
  	
  	// Configure one channel for periodic interrupts
  	MAP_TimerConfigure(TIMERA1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC);
  	MAP_TimerPrescaleSet(TIMERA1_BASE, TIMER_A, IMU_CONTROLLER_PRESCALER);
	
  	// Set timeout interrupt
  	MAP_TimerIntRegister(TIMERA1_BASE, TIMER_A, ControllerIntHandler);
  	MAP_TimerIntEnable(TIMERA1_BASE, TIMER_TIMA_TIMEOUT);

  	// Turn on timers
  	MAP_TimerLoadSet(TIMERA1_BASE, TIMER_A, IMU_CONTROLLER_STARTUP); 
  	MAP_TimerEnable(TIMERA1_BASE, TIMER_A);
}
void OneMsTaskTimer::start(uint32_t timer_index) {
  uint32_t load = (F_CPU / 1000);
  //// !!!! count = 0;
  overflowing = 0;
  // Base address for first timer
  g_ulBase = TIMERA0_BASE + (timer_index <<12);
  // Configuring the timers
  MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0 + timer_index, PRCM_RUN_MODE_CLK);
  MAP_PRCMPeripheralReset(PRCM_TIMERA0 + timer_index);
  MAP_TimerConfigure(g_ulBase,TIMER_CFG_PERIODIC);
  MAP_TimerPrescaleSet(g_ulBase,TIMER_A,0);
  // Setup the interrupts for the timer timeouts.
  MAP_TimerIntRegister(g_ulBase, TIMER_A, OneMsTaskTimer_int);
  MAP_TimerIntEnable(g_ulBase, TIMER_TIMA_TIMEOUT);
  // Turn on the timers
  MAP_TimerLoadSet(g_ulBase,TIMER_A, load);
  // Enable the GPT 
  MAP_TimerEnable(g_ulBase,TIMER_A);
}
Exemple #6
0
void odometer_controller_setup(void){

	//acc_value_startup = get_accelerometer_default_offset();

	// Enable timer A peripheral
  	MAP_PRCMPeripheralClkEnable(PRCM_TIMERA3, PRCM_RUN_MODE_CLK);
  	MAP_PRCMPeripheralReset(PRCM_TIMERA3);
  	
  	// Configure one channel for periodic interrupts 
  	MAP_TimerConfigure(TIMERA3_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC);
  	MAP_TimerPrescaleSet(TIMERA3_BASE, TIMER_A, ODOMETER_CONTROLLER_PRESCALER);
	
  	// Set timeout interrupt
  	MAP_TimerIntRegister(TIMERA3_BASE, TIMER_A, OdometerControllerIntHandler);
  	MAP_TimerIntEnable(TIMERA3_BASE, TIMER_TIMA_TIMEOUT);

  	// Turn on timers
  	MAP_TimerLoadSet(TIMERA3_BASE, TIMER_A, ODOMETER_CONTROLLER_STARTUP); 
  	MAP_TimerEnable(TIMERA3_BASE, TIMER_A);
}
Exemple #7
0
//*****************************************************************************
//
//!    setting up the timer
//!
//! \param ulBase is the base address for the timer.
//! \param ulTimer selects between the TIMER_A or TIMER_B or TIMER_BOTH.
//! \param TimerBaseIntHandler is the pointer to the function that handles the
//!    interrupt for the Timer
//!
//! This function
//!     1. Register the function handler for the timer interrupt.
//!     2. enables the timer interrupt.
//!
//! \return none
//
//*****************************************************************************
void Timer_IF_IntSetup(unsigned long ulBase, unsigned long ulTimer, 
                   void (*TimerBaseIntHandler)(void))
{
  //
  // Setup the interrupts for the timer timeouts.
  //

#if defined(USE_TIRTOS) || defined(USE_FREERTOS) || defined(SL_PLATFORM_MULTI_THREADED) 
    // USE_TIRTOS: if app uses TI-RTOS (either networking/non-networking)
    // USE_FREERTOS: if app uses Free-RTOS (either networking/non-networking)
    // SL_PLATFORM_MULTI_THREADED: if app uses any OS + networking(simplelink)
      if(ulTimer == TIMER_BOTH)
      {
          osi_InterruptRegister(GetPeripheralIntNum(ulBase, TIMER_A),
                                   TimerBaseIntHandler, INT_PRIORITY_LVL_1);
          osi_InterruptRegister(GetPeripheralIntNum(ulBase, TIMER_B),
                                  TimerBaseIntHandler, INT_PRIORITY_LVL_1);
      }
      else
      {
          osi_InterruptRegister(GetPeripheralIntNum(ulBase, ulTimer),
                                   TimerBaseIntHandler, INT_PRIORITY_LVL_1);
      }
        
#else
	  MAP_IntPrioritySet(GetPeripheralIntNum(ulBase, ulTimer), INT_PRIORITY_LVL_1);
      MAP_TimerIntRegister(ulBase, ulTimer, TimerBaseIntHandler);
#endif
 

  if(ulTimer == TIMER_BOTH)
  {
    MAP_TimerIntEnable(ulBase, TIMER_TIMA_TIMEOUT|TIMER_TIMB_TIMEOUT);
  }
  else
  {
    MAP_TimerIntEnable(ulBase, ((ulTimer == TIMER_A) ? TIMER_TIMA_TIMEOUT : 
                                   TIMER_TIMB_TIMEOUT));
  }
}
Exemple #8
0
//*****************************************************************************
//
//! Main  Function
//
//*****************************************************************************
int main()
{

    //
    // Initialize Board configurations
    //
    BoardInit();

    //
    // Pinmux for UART
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
    InitTerm();

    //
    // Display Application Banner
    //
    DisplayBanner(APP_NAME);

    //
    // Enable pull down
    //
    MAP_PinConfigSet(PIN_05,PIN_TYPE_STD_PD,PIN_STRENGTH_6MA);


    //
    // Register timer interrupt hander
    //
    MAP_TimerIntRegister(TIMERA2_BASE,TIMER_A,TimerIntHandler);

    //
    // Configure the timer in edge count mode
    //
    MAP_TimerConfigure(TIMERA2_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME));

    //
    // Set the detection edge
    //
    MAP_TimerControlEvent(TIMERA2_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);

    //
    // Set the reload value
    //
    MAP_TimerLoadSet(TIMERA2_BASE,TIMER_A,0xffff);


    //
    // Enable capture event interrupt
    //
    MAP_TimerIntEnable(TIMERA2_BASE,TIMER_CAPA_EVENT);

    //
    // Enable Timer
    //
    MAP_TimerEnable(TIMERA2_BASE,TIMER_A);


    while(1)
    {
        //
        // Report the calculate frequency
        //
        Report("Frequency : %d Hz\n\n\r",g_ulFreq);

        //
        // Delay loop
        //
        MAP_UtilsDelay(80000000/5);
    }
}
Exemple #9
0
//*****************************************************************************
//
//! Main test implementation function 
//!
//! It uses 3 different timers to test that interrupts can be enabled
//! and disabled successfully and that preemption occurs as expected when
//! different priority levels are assigned.
//
//! \return Returns 1 on Success.
//
//*****************************************************************************
int
DoInterruptTest()
{
    tTestResult eResult;
    
    //
    // indicate that the test is started.
    //
    UART_PRINT("Interrupt test starting...\n\r\n\r");
    
    //
    // Assume we will pass until we determine otherwise.
    //
    eResult = TEST_PASSED;
    
    //
    // Perform any required initialization prior to performing the test.
    //
    InterruptTestInit();
    
    //
    // Set up the 3 timers we use in this test. Timer A0 - 500uS.
    // Timer A1 - 500 uS. Timer A2 - 500 uS
    //
    MAP_TimerConfigure(TIMERA0_BASE, TIMER_CFG_ONE_SHOT);
    MAP_TimerLoadSet(TIMERA0_BASE, TIMER_A,
                     MICROSECONDS_TO_TICKS(SLOW_TIMER_DELAY_uS/4));

    MAP_TimerConfigure(TIMERA1_BASE, TIMER_CFG_ONE_SHOT);
    MAP_TimerLoadSet(TIMERA1_BASE, TIMER_A,
                     MICROSECONDS_TO_TICKS(SLOW_TIMER_DELAY_uS/4));

    MAP_TimerConfigure(TIMERA2_BASE, TIMER_CFG_ONE_SHOT);
    MAP_TimerLoadSet(TIMERA2_BASE, TIMER_A,
                     MICROSECONDS_TO_TICKS(SLOW_TIMER_DELAY_uS/4));

    //
    // Hook our interrupt handlers
    //
    MAP_TimerIntRegister(TIMERA0_BASE, TIMER_A, TimerA0IntHandler);
    MAP_TimerIntRegister(TIMERA1_BASE, TIMER_A, TimerA1IntHandler);
    MAP_TimerIntRegister(TIMERA2_BASE, TIMER_A, TimerA2IntHandler);

    UART_PRINT("Equal Priorities Testing. A0=A1=A2 \n\r");
    UART_PRINT("Interrupt Triggering Order A0 => A1 => A2 \n\r");
    UART_PRINT("**********************************************\n\r");
    
    //
    // Scenario 1 - set three timers to the same interrupt priority.
    // In this case, we expect to see that the order of execuition of
    // interrupts are A0,A1,A2.
    //
    PerformIntTest(3, LOW_PRIORITY, LOW_PRIORITY,LOW_PRIORITY);

    //
    // Checking the Order of Execuition. A0,A1,A2.
    //
    if((g_ulA1IntCount == 0 && g_ulA2IntCount==0 ) || g_bA1CountChanged ||
       g_bA2CountChanged )
    {
        //
        // Something went wrong. Fail the test.
        //
        UART_PRINT("Interrupt failure.\n\r");
        eResult = TEST_FAILED;
        return 0;
    }

    //
    // Scenario 2 : Increasing Priorities
    // Priorities are set as: A0 < A1 < A2
    //
    if(eResult == TEST_PASSED)
    {

        UART_PRINT("Succesfully executed Equal Priority \n\r\n\r");
        UART_PRINT("Increasing Priority :  A0 < A1 < A2\n\r");
        UART_PRINT("Interrupt Triggering Order A0 => A1 => A2 \n\r");
        UART_PRINT("**********************************************\n\r");
    
        //
        // Perform the test for this scenario.
        //
        PerformIntTest(3, LOW_PRIORITY,MIDDLE_PRIORITY,
                                  HIGH_PRIORITY);

        //
        // Order of Execuition should be as: A2,A1,A0.
        //
        if((g_ulA1IntCount == 0) || !g_bA1CountChanged || !g_bA2CountChanged)
                                                                  
        {
            //
            // Something went wrong. Fail the test.
            //
            UART_PRINT("Interrupt failure. \n\r");
            eResult = TEST_FAILED;
            return 0;
        }
    }

    //
    // Scenario 3 - Decreasing Priorities
    // Priorities are set as: A0 > A1 > A2
    //
    if(eResult == TEST_PASSED)
    {
        UART_PRINT("Succesfully executed Increasing Priority \n\r\n\r");
        UART_PRINT("Decreasing Priority :  A0 > A1 > A2\n\r");
        UART_PRINT("Interrupt Triggering Order A0 => A1 => A2 \n\r");
        UART_PRINT("**********************************************\n\r");

        //
        // Perform the test for this scenario.
        //
        PerformIntTest(3, HIGH_PRIORITY, MIDDLE_PRIORITY, LOW_PRIORITY);
        
        //
        // Order of execuition should be : A0,A1,A2
        //
        if((g_ulA1IntCount == 0) || g_bA1CountChanged || g_bA2CountChanged)
        {
            //
            // Something went wrong. Fail the test.
            //
            UART_PRINT("Interrupt failure\n\r");

            eResult = TEST_FAILED;
            return 0;
        }
    }

    UART_PRINT("Succesfully executed Decreasing Priority \n\r\n\r");

    //
    // Perform any clean up required after the test has completed.
    //
    InterruptTestTerm();
    
    //
    // Let the user know that this test has completed.
    //
    UART_PRINT("Interrupt test ended.\n\r");
    return 1;
}