Пример #1
0
void GPIO_Test_for_TE(void)
{
	if(sys_gpio_test)
	{
		sys_gpio_test = 0;

		GPIO_HAL_SetPinDir(PTA, 4, kGpioDigitalOutput); // INT1 pin
		GPIO_HAL_SetPinDir(PTB, 5, kGpioDigitalInput); // INT2 pin

		PORT_HAL_SetMuxMode(PORTB,3u,kPortMuxAsGpio);
		PORT_HAL_SetMuxMode(PORTB,4u,kPortMuxAsGpio);
		GPIO_HAL_SetPinDir(PTB, 3, kGpioDigitalOutput); // SCL pin
		GPIO_HAL_SetPinDir(PTB, 4, kGpioDigitalOutput); // SDA pin

		while(1)
		{
			if(GPIO_HAL_ReadPinInput(PTB, 5))
			{
				GPIO_HAL_ClearPinOutput(PTA, 4); // INT1 set low
				GPIO_HAL_SetPinOutput(PTB, 3); // SCL set high
				GPIO_HAL_ClearPinOutput(PTB, 4); // SDA set low
			}
			else
			{
				GPIO_HAL_SetPinOutput(PTA, 4); // INT1 set high
				GPIO_HAL_ClearPinOutput(PTB, 3); // SCL set low
				GPIO_HAL_SetPinOutput(PTB, 4); // SDA set high
			}

			delay_ms(100);
		}
	}
}
Пример #2
0
/*FUNCTION**********************************************************************
 *
 * Function Name : GPIO_DRV_ClearPinOutput
 * Description   : Set output level of individual GPIO pin to logic 0.
 *
 *END**************************************************************************/
void GPIO_DRV_ClearPinOutput(uint32_t pinName) 
{
    uint32_t gpioBaseAddr = g_gpioBaseAddr[GPIO_EXTRACT_PORT(pinName)];
    uint32_t pin = GPIO_EXTRACT_PIN(pinName);
   
    GPIO_HAL_ClearPinOutput(gpioBaseAddr, pin);
}
Пример #3
0
/*************************************************************************
 * Function Name: GPIO_init
 * Parameters: none
 * Return: none
 * Description: I/O pins configuration
 *************************************************************************/
void GPIO_init(void)
{
  // Brake control
  PORT_HAL_SetMuxMode(PORTE_BASE_PTR, 24, kPortMuxAsGpio);
  PORT_HAL_SetPullMode(PORTE_BASE_PTR, 24, kPortPullDown);
  GPIO_HAL_SetPinDir(GPIOE_BASE_PTR, 24, kGpioDigitalOutput);
  GPIO_HAL_ClearPinOutput(GPIOE_BASE_PTR, 24);

  // LED
  PORT_HAL_SetMuxMode(PORTD_BASE_PTR, 6, kPortMuxAsGpio);
  PORT_HAL_SetPullMode(PORTD_BASE_PTR, 6, kPortPullDown);
  GPIO_HAL_SetPinDir(GPIOD_BASE_PTR, 6, kGpioDigitalOutput);
  GPIO_HAL_SetPinOutput(GPIOD_BASE_PTR, 6);// Turn off LED

#if defined(KV10Z7_SERIES)
  // Push buttons: PTA4 = SW1, PTB0 = SW2
  PORT_HAL_SetMuxMode(PORTA_BASE_PTR, 4, kPortMuxAsGpio);
  PORT_HAL_SetPullMode(PORTA_BASE_PTR, 4, kPortPullDown);
  PORT_HAL_SetMuxMode(PORTB_BASE_PTR, 0, kPortMuxAsGpio);
  PORT_HAL_SetPullMode(PORTB_BASE_PTR, 0, kPortPullDown);
#elif (defined(KV10Z1287_SERIES) || defined(KV11Z7_SERIES))
  // Push buttons: PTE20 = SW3, PTA4 = SW2
  PORT_HAL_SetMuxMode(PORTE_BASE_PTR, 20, kPortMuxAsGpio);
  PORT_HAL_SetPullMode(PORTE_BASE_PTR, 20, kPortPullDown);
  PORT_HAL_SetMuxMode(PORTA_BASE_PTR, 4, kPortMuxAsGpio);
  PORT_HAL_SetPullMode(PORTA_BASE_PTR, 4, kPortPullDown);
#endif

}
/*FUNCTION**********************************************************************
 *
 * Function Name : GPIO_DRV_ClearPinOutput
 * Description   : Set output level of individual GPIO pin to logic 0.
 *
 *END**************************************************************************/
void GPIO_DRV_ClearPinOutput(uint32_t pinName)
{
    GPIO_Type * gpioBase = g_gpioBase[GPIO_EXTRACT_PORT(pinName)];
    uint32_t pin = GPIO_EXTRACT_PIN(pinName);

    GPIO_HAL_ClearPinOutput(gpioBase, pin);
}
Пример #5
0
/*!
 * @brief Show a few demo speeds and ramps, called every 1 ms
 *
 * @param sM_Drive BLDC motor variables structure pointer
 */
void Demonstration(MCSTRUC_BLDC_SNLS_INT_T * sM_Drive)
{
    Frac16 f16RequiredSpeedNew, f16RequiredSpeedOld;

    // Push buttons signal filtering
#if defined(KV10Z7_SERIES)
    if (!FGPIO_HAL_ReadPinInput(FGPIOA_BASE_PTR,4))    // STATUS_SW1
#elif (defined(KV10Z1287_SERIES) || defined(KV11Z7_SERIES))
    if (!FGPIO_HAL_ReadPinInput(FGPIOE_BASE_PTR,20))    // STATUS_SW3
#endif
    {
        if (uw16Sw1FiltCnt <= PUSH_TIME_FILTER) uw16Sw1FiltCnt++;
        else uw16SwStatus |= 1;
    }
    else
    {
        if (0 < uw16Sw1FiltCnt) uw16Sw1FiltCnt--;
        else uw16SwStatus &= ~1;
    }

#if defined(KV10Z7_SERIES)
    if (!FGPIO_HAL_ReadPinInput(FGPIOB_BASE_PTR,0))    // STATUS_SW2
#elif (defined(KV10Z1287_SERIES) || defined(KV11Z7_SERIES))
    if (!FGPIO_HAL_ReadPinInput(FGPIOA_BASE_PTR,4))    // STATUS_SW2
#endif
    {
        if (uw16Sw2FiltCnt <= PUSH_TIME_FILTER) uw16Sw2FiltCnt++;
        else uw16SwStatus |= 2;
    }
    else
    {
        if (0 < uw16Sw2FiltCnt) uw16Sw2FiltCnt--;
        else uw16SwStatus &= ~2;
    }

    // Push buttons processing
    switch (uw16SwStatus)
    {
        case 0:
            uw16Sw1Cnt = 0;
            uw16Sw2Cnt = 0;
            uw16SwBothCnt = 0;
            break;

        case 1:       // Switch 1 only
            if (0 < uw16Sw1Cnt)
            {
                uw16Sw1Cnt--;
            }
            else
            {
                uw16Sw1Cnt = PUSH_TIME_SHORT;
                // Increase speed
                if (uw16DemonstrationStatus == 0)
                {
                    f16RequiredSpeedOld = sM_Drive->f16SpeedRequired;
                    f16RequiredSpeedNew = f16RequiredSpeedOld;
                    f16RequiredSpeedNew = MLIB_AddSat_F16(f16RequiredSpeedNew, FRAC16(DEMONSTRATION_SPEED_STEP));
                    sM_Drive->f16SpeedRequired = f16RequiredSpeedNew;
                }
            }
            uw16Sw2Cnt = 0;
            uw16SwBothCnt = 0;
            break;

        case 2:       // Switch 2 only
            if (0 < uw16Sw2Cnt)
            {
                uw16Sw2Cnt--;
            }
            else
            {
                uw16Sw2Cnt = PUSH_TIME_SHORT;
                // Decrease speed
                if (uw16DemonstrationStatus == 0)
                {
                    f16RequiredSpeedOld = sM_Drive->f16SpeedRequired;
                    f16RequiredSpeedNew = f16RequiredSpeedOld;
                    f16RequiredSpeedNew = MLIB_SubSat_F16(f16RequiredSpeedNew, FRAC16(DEMONSTRATION_SPEED_STEP));
                    sM_Drive->f16SpeedRequired = f16RequiredSpeedNew;
                }
            }

            uw16Sw1Cnt = 0;
            uw16SwBothCnt = 0;
            break;

        case 3:       // Both Switches
            if (uw16SwBothCnt < 0x7fff) uw16SwBothCnt++;
            if (uw16SwBothCnt == PUSH_TIME_LONG)
            {
                if (uw16DemonstrationStatus == 0)
                {
                    uw16DemonstrationStatus = 1;
                    uw32DemoTime = 0;
                }
                else
                {
                    uw16DemonstrationStatus = 0;
                    // Set default ramp
                    sM_Drive->f32trSpeedRamp.f32RampDown = SPEED_LOOP_RAMP_DOWN;
                    sM_Drive->f32trSpeedRamp.f32RampUp   = SPEED_LOOP_RAMP_UP;
                    GPIO_HAL_SetPinOutput(GPIOD_BASE_PTR, 6);//DEMO_LED_OFF;
                }
            }
            uw16Sw1Cnt = 0;
            uw16Sw2Cnt = 0;
            break;
    }

    // Demonstration mode
    if (uw16DemonstrationStatus == 1)
    {
        uw32DemoTime++;

        if (uw32DemoTime & 128) GPIO_HAL_SetPinOutput(GPIOD_BASE_PTR, 6);   //DEMO_LED_OFF;
        else                    GPIO_HAL_ClearPinOutput(GPIOD_BASE_PTR, 6); //DEMO_LED_ON;

        switch (uw32DemoTime)
        {
            case 500:
                sM_Drive->f32trSpeedRamp.f32RampDown = FRAC32(0.25 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f32trSpeedRamp.f32RampUp   = FRAC32(0.25 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f16SpeedRequired = FRAC16(0.6);
                break;

            case 3000:
                sM_Drive->f32trSpeedRamp.f32RampDown = FRAC32(1.0 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f32trSpeedRamp.f32RampUp   = FRAC32(1.0 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f16SpeedRequired = FRAC16(-0.8);
                break;

            case 5500:
                sM_Drive->f16SpeedRequired = FRAC16(0.8);
                break;

            case 7500:
                sM_Drive->f16SpeedRequired = FRAC16(0.2);
                break;

            case 11000:
                sM_Drive->f16SpeedRequired = FRAC16(0.8);
                break;

            case 13000:
                sM_Drive->f16SpeedRequired = FRAC16(0.4);
                break;

            case 15000:
                sM_Drive->f32trSpeedRamp.f32RampDown = FRAC32(0.025 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f32trSpeedRamp.f32RampUp   = FRAC32(0.025 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f16SpeedRequired = FRAC16(0.1);
                break;

            case 25000:
                sM_Drive->f32trSpeedRamp.f32RampDown = FRAC32(0.0125 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f32trSpeedRamp.f32RampUp   = FRAC32(0.0125 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f16SpeedRequired = FRAC16(0.8);
                break;

            case 28000:
                sM_Drive->f32trSpeedRamp.f32RampDown = FRAC32(0.0625 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f32trSpeedRamp.f32RampUp   = FRAC32(0.0625 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f16SpeedRequired = FRAC16(-0.8);
                break;

            case 30500:
                sM_Drive->f32trSpeedRamp.f32RampDown = FRAC32(0.125 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f32trSpeedRamp.f32RampUp   = FRAC32(0.125 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f16SpeedRequired = FRAC16(0.8);
                break;

            case 34000:
                sM_Drive->f16SpeedRequired = FRAC16(0.1);
                break;

            case 50000:
                sM_Drive->f32trSpeedRamp.f32RampDown = FRAC32(0.25 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f32trSpeedRamp.f32RampUp   = FRAC32(0.25 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f16SpeedRequired = FRAC16(-0.18);
                break;

            case 54000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.22);
                break;

            case 58000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.18);
                break;

            case 62000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.2);
                break;

            case 66000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.22);
                break;

            case 70000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.2);
                break;

            case 74000:
                sM_Drive->f32trSpeedRamp.f32RampDown = FRAC32(1.0 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f32trSpeedRamp.f32RampUp   = FRAC32(1.0 * DEMONSTRATION_SPEED_RAMP_GAIN);
                sM_Drive->f16SpeedRequired = FRAC16(-0.18);
                break;

            case 78000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.2);
                break;

            case 85000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.1);
                break;

            case 90000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.8);
                break;

            case 92000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.2);
                break;
            case 95000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.8);
                break;

            case 98000:
                sM_Drive->f16SpeedRequired = FRAC16(-0.2);
                break;

            case 108000:
                uw32DemoTime = 0;
                break;
        }
    }
}
Пример #6
0
void timer0(void)
 {
 
   GPIO_HAL_SetPinOutput(PTB,9);  // debugging signal high during Timer0 
                                    // interrupt on PTB9
/************************************************/    
//  Determine Timer0 state and task groups
/************************************************/   
   timer_state++;          // increment timer_state each time
   if (timer_state == 0)   
   {
      long_time_state++;   // increment long time state every 25.6 ms

   }

/*******************************************************************/
/*      100 us Group                                                 */
/*******************************************************************/
//  II.  100 us Group

//     A. Update Fast Software timers 
   if (swtimer0 > 0)     // if not yet expired, 
      (swtimer0)--;        // then decrement fast timer (1 ms to 256 ms)
   if (swtimer1 > 0)     // if not yet expired, 
      (swtimer1)--;        // then decrement fast timer (1 ms to 256 ms)
  
//    B.   Update Sensors


/*******************************************************************/
/*      200 us Group                                                 */
/*******************************************************************/   

   if ((timer_state & 0x01) != 0)  // 2 ms group, odds only
   {
      ;                           
   } // end  2 ms group

/*******************************************************************/
/*      400 us Group                                                 */
/*******************************************************************/   
   else if ((timer_state & 0x02) != 0)
   {
//   IV.  400 us group  
//           timer states 2,6,10,14,18,22,...254 

//      A.  Medium Software timers
      if (swtimer2 > 0)  // if not yet expired, every other time 
         (swtimer2)--;     // then decrement med timer  (4 ms to 1024 ms)
      if (swtimer3 > 0) // if not yet expired, every other time 
         (swtimer3)--;        // then decrement med timer  (4 ms to 1024 ms)

//      B.  
   } // end 4 ms group
   
/*******************************************************************/
/*      800 us Group                                                 */
/*******************************************************************/   
   else if ((timer_state & 0x04) != 0)
   {
//   V.   8 ms group
//           timer states 4, 12, 20, 28 ... 252   every 1/8

//     A.  Set 
   }   // end 8 ms group
   
/*******************************************************************/
/*      1.6 ms Group                                                 */
/*******************************************************************/   
   else if ((timer_state & 0x08) != 0)
   {
// VI   1.6 ms group
//           timer states 8, 24, 40, 56, .... 248  every 1/16

   }   // end 1.6 ms group
   
/*******************************************************************/
/*      3.2 ms Group                                                 */
/*******************************************************************/   
   else if ((timer_state & 0x10) != 0)
   {
// VII  3.2 ms group
//          timer states 16, 48, 80, 112, 144, 176, 208, 240

//    A. Slow Software Timers
      if (swtimer4 > 0)  // if not yet expired, every 32nd time
         (swtimer4)--;        // then decrement slow timer (32 ms to 8 s)
      if (swtimer5 > 0) // if not yet expired, every 32nd time
         (swtimer5)--;        // then decrement slow timer (32 ms to 8 s)
         
//    B.  Update
    
   }   // end 3.2 ms group
   
/*******************************************************************/
/*      6.4 ms Group A                                              */
/*******************************************************************/   
   else if ((timer_state & 0x20) != 0)
   {
// VIII 6.4 ms group A
//           timer states 32, 96, 160, 224 

//    A. Very Slow Software Timers
      if (swtimer6 > 0)  // if not yet expired, every 64th 
                                            // time 
         (swtimer6)--;        // then decrement very slow timer (6.4 ms to 1.6s)

      if (swtimer7 > 0)  // if not yet expired, every 64th 
                                            // time 
         (swtimer7)--;        // then decrement very slow timer (64 ms to 1.6s)

//    B.  Update

   }   // end 6.4 ms group A
   
/*******************************************************************/
/*      6.4 ms Group B                                              */
/*******************************************************************/   
   else 
   {
// IX.  6.4 ms group B
//       timer states 0, 64, 128, 192

//    A.  Update

//    A. Display timer and flag
      display_timer--; // decrement display timer every 6.4 ms.  Total time is      
                      // 256*6.4ms = 1.6384 seconds. 
      if (display_timer == 1)
         display_flag = 1;     // every 1.6384 seconds, now OK to display


//    B. Heartbeat/ LED outputs
//   Generate Outputs  ************************************
 
    //ECEN 5003 add code as indicated
    // Create an 0.5 second RED LED heartbeat here. 
 
 

   }   // end 6.4 ms group B
   
/*******************************************************************/
/*      Long Time Group                                            */
/*******************************************************************/      
   if (((long_time_state & 0x01) != 0) && (timer_state == 0))  
                              // every other long time, every 51.2 ms
   {
// X.   Long time group
//
//  clear_watchdog_timer();
     }
// Re-enable interrupts and return
   
   timer0_count++;
   GPIO_HAL_ClearPinOutput(PTB,9);  // debugging signal high during 
                                    //   Timer0 interrupt on PTB9
    // unmask Timer interrupt   

    // enables timer interrupt again
  
}