コード例 #1
0
ファイル: sample_proc.c プロジェクト: Superkazuya/ASR_Project
//called in the interrupt
void sample_proc(int16_t _sample)
{
  static uint16_t i = 0;
  raw_buffer[i++] = HTONS(_sample);

  if(i < RAW_BUFSIZE)
    return;
  i = 0;
  if(raw_buffer == raw_buffer1)
  {
    rawbuf_status |= RAWBUF_FULL1;
    raw_buffer = raw_buffer2;
  }
  else
  {
    rawbuf_status |= RAWBUF_FULL2;
    raw_buffer = raw_buffer2;
  }
  EXTI_GenerateSWInterrupt(EXTI_Line0);
}
コード例 #2
0
ファイル: main.c プロジェクト: rabryan/stm32f4examples
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
        system_stm32f4xx.c file
     */

  /* Initialize LEDs mounted on STM32F4-Discovery board */
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED3);

  /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */
  EXTILine0_Config();

  /* Generate software interrupt: simulate a rising edge applied on EXTI0 line */
  EXTI_GenerateSWInterrupt(EXTI_Line0);

  while (1)
  {
  }
}
コード例 #3
0
ファイル: main.c プロジェクト: rmursh/MicroP-ECSE426
/**
* @brief  Initialize wireless 
* @param  
* @retval int 0
*/
void wireless_init() {
	
	
	GPIO_InitTypeDef GPIO_init_st;
	NVIC_InitTypeDef NVIC_init_st;
	EXTI_InitTypeDef EXTI_InitStructure;
	
	/* Enable SYSCFG clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
	
	//Configure GPIO pin 0 in input mode
	GPIO_init_st.GPIO_Mode = GPIO_Mode_IN;
	GPIO_init_st.GPIO_Pin = CC2500_SPI_INT_PIN;
	GPIO_init_st.GPIO_PuPd = GPIO_PuPd_DOWN;
	GPIO_init_st.GPIO_Speed = GPIO_High_Speed;
	GPIO_init_st.GPIO_OType = GPIO_OType_PP;
	GPIO_Init(CC2500_SPI_INT_GPIO_PORT, &GPIO_init_st);
	
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, CC2500_SPI_INT_EXTI_PIN_SOURCE);
	EXTI_InitStructure.EXTI_Line = CC2500_SPI_INT_EXTI_LINE;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);
	
	// configure NVIC
	NVIC_init_st.NVIC_IRQChannel = CC2500_SPI_INT_EXTI_IRQn;
	NVIC_init_st.NVIC_IRQChannelCmd = ENABLE;
	NVIC_init_st.NVIC_IRQChannelPreemptionPriority = 0x01;
	NVIC_init_st.NVIC_IRQChannelSubPriority = 0x01;
	NVIC_Init(&NVIC_init_st);
	
	NVIC_EnableIRQ(CC2500_SPI_INT_EXTI_IRQn);
	
	EXTI_GenerateSWInterrupt(EXTI_Line4);
	CC2500_Init();
}
コード例 #4
0
ファイル: stm32_audio_player.c プロジェクト: ADTL/ARMWork
/**
  * @brief  Manage end of buffer transfer for each device.
  * @param  Direction: could be DIRECTION_IN or DIRECTION_OUT
  * @param  pbuf: Pointer to the address of the current buffer
  * @param  pSize: pointer to the variable which holds current buffer size
  * @retval status
  */
void  AudioPlayer_XferCplt (uint8_t Direction, uint8_t** pbuf, uint32_t* pSize)
{
  if (AudioPlayerState == PLAYER_PLAYING)
  {
    /* Release previous buffer for write operation */
    AudioBuffers[RdBuffIdx].isReady = 0;
    
    /* Increment the buffer index */
    RdBuffIdx = (RdBuffIdx >= 2)? 0:(RdBuffIdx+1);
    
    if (!(AudioBuffers[RdBuffIdx].isReady))
    {
      RdBuffIdx = (RdBuffIdx > 0)? (RdBuffIdx-1):2;
    }
    
    /* Resume the audio stream */
    AUDIO_OUT_fops.AudioCmd((uint8_t*)AudioBuffers[RdBuffIdx].pBuf,  /* Samples buffer pointer */
                            AudioBuffers[RdBuffIdx].Size,  /* Number of samples in Bytes */
                            AUDIO_CMD_PLAY);               /* Command to be processed */
    
    /* Trigger the Main audio player task to update the next buffers */
    EXTI_GenerateSWInterrupt(EXTI_Line4);
  }
}
コード例 #5
0
/**
  * @brief  This function handles TIM3 global interrupt request.
  * @param  None
  * @retval None
  */
void TIM3_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
  {
    /* Get ADC values */
    uint32_t bat_level_value=ADC_ConvertedValueTabPointer[1]*/*41*/ADC_TO_MV_CONSTANT;
    uint32_t regulatedOutputCurrentValue=ADC_ConvertedValueTabPointer[2]*ADC_TO_MA_CONSTANT;
    uint32_t bat_current_value=ADC_ConvertedValueTabPointer[3]*/*32*/ADC_TO_MA_CONSTANT;
    /*
    printf("Bat Level: %d\n\r", bat_level_value);
    printf("Bat charge current: %d\n\r", bat_current_value);
    printf("Reg output Level: %d\n\r", ADC_ConvertedValueTabPointer[0]*ADC_TO_MV_CONSTANT);
    printf("Reg output current: %d\n\r", regulatedOutputCurrentValue);
    printf("Charger Level: %d\n\r", ADC_ConvertedValueTabPointer[4]*ADC_TO_MV_CONSTANT);
    */
    /* Check for the events related to the ADC values */
    /* PC is turned off (it was previously on) */
    if (state.regulatedOutputState==ON && regulatedOutputCurrentValue<CURRENT_ON_OFF_THRESHOLD && TurnOnDelyTime==0 && !noCurrentFlag /* && state.externalPowerSourceState==DISCONNECTED */ && pcOn)
    {
      NoCurrentTimeout=2;
      noCurrentFlag=true;
    }
    else if(noCurrentFlag && regulatedOutputCurrentValue>CURRENT_ON_OFF_THRESHOLD)
    {
      noCurrentFlag=false;
      if(!pcOn)
        pcOn=true;
    }
    if(noCurrentFlag && NoCurrentTimeout<=0 && pcOn)
    {
      /* Event EV.3 detected */
      noCurrentFlag=false;
      EXTI_GenerateSWInterrupt(EXTI_Line9);
    }
    /* Battery below KO level */
    if (state.batteryState==DISCHARGING && bat_level_value<BATTERY_KO_THRESHOLD && !batteryKoFlag)
    {
      BatteryKoTimeout=5;
      batteryKoFlag=true;
    }
    else if(batteryKoFlag)
    {
      if(bat_level_value>BATTERY_KO_THRESHOLD || state.externalPowerSourceState==CONNECTED)
        batteryKoFlag=false;
    }
    if(batteryKoFlag && BatteryKoTimeout<=0)
    {
      /* Event EV.6 detected */
      batteryKoFlag=false;
      EXTI_GenerateSWInterrupt(EXTI_Line6);
    }
    /* Battery charge to constant voltage mode */
    else if (state.batteryState==CHARGING_CC && bat_level_value>BAT_CC_CV_THRESHOLD)
    {
      /* Event EV.4 detected */
      EXTI_GenerateSWInterrupt(EXTI_Line8);
    }
    /* Battery fully charged */
    else if (state.batteryState==CHARGING_CV && bat_current_value<BAT_CURRENT_CHARGED_THRESHOLD)
    {
      /* Event EV.5 detected */
      EXTI_GenerateSWInterrupt(EXTI_Line7);
    }
    
    getBatteryLevel(4, 3300, 3600, state.batteryState, bat_level_value);
    
    TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
  }
}
コード例 #6
0
ファイル: hw_platform.c プロジェクト: joe3501/BlueRing
/**
* @brief  Initialize the IO
* @return   none
*/
static void platform_misc_port_init(void)
{
	GPIO_InitTypeDef	GPIO_InitStructure;
	EXTI_InitTypeDef	EXTI_InitStructure;
	NVIC_InitTypeDef	NVIC_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
	PWR_BackupAccessCmd(ENABLE);//允许修改RTC 和后备寄存器
	RCC_LSICmd(DISABLE);//关闭外部低速外部时钟信号功能 后,PC14 PC15 才可以当普通IO用。
	BKP_TamperPinCmd(DISABLE);//关闭入侵检测功能,也就是 PC13,也可以当普通IO 使用

	//USB_CHK -- PC.13
	GPIO_InitStructure.GPIO_Pin				= GPIO_Pin_13;
	GPIO_InitStructure.GPIO_Mode			= GPIO_Mode_IN_FLOATING;
	GPIO_InitStructure.GPIO_Speed			= GPIO_Speed_10MHz;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	/* Connect EXTI Line13 to PC.13 */
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);

	EXTI_ClearITPendingBit(EXTI_Line13);
	EXTI_InitStructure.EXTI_Line = EXTI_Line13;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure); 
	EXTI_GenerateSWInterrupt(EXTI_Line13);


	//ChargeState detect -- PC.14
	GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_14;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	/* Connect EXTI Line14 to PC.14 */
	//GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource14);

	//EXTI_ClearITPendingBit(EXTI_Line14);
	//EXTI_InitStructure.EXTI_Line = EXTI_Line14;
	//EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	//EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
	//EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	//EXTI_Init(&EXTI_InitStructure); 
	//EXTI_GenerateSWInterrupt(EXTI_Line14);

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);      
	NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	charge_detect_io_cnt = 0;
	last_charge_detect_io_cnt = 1;

	//LED-Red -- PA.4 	LED-Green -- PA.5	LED-Yellow -- PA.6
	GPIO_InitStructure.GPIO_Pin	= GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	GPIO_SetBits(GPIOA, GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6);

	//Beep -- PB.5  Trig  -- PB.12
	GPIO_InitStructure.GPIO_Pin	= GPIO_Pin_5 | GPIO_Pin_12;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_SetBits(GPIOB, GPIO_Pin_12);
	GPIO_ResetBits(GPIOB, GPIO_Pin_5);

	//RFU-IO2 -- PB.8		
	//GPIO_InitStructure.GPIO_Pin	= GPIO_Pin_8;
	//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	//GPIO_Init(GPIOB, &GPIO_InitStructure);
}
コード例 #7
0
ファイル: main.c プロジェクト: joelin3246/Project_2121034
//==============================================================================
//  設置外部中斷
//==============================================================================
void EXTI_Config(void)
{
  EXTI_InitTypeDef   EXTI_InitStructure;
  NVIC_InitTypeDef   NVIC_InitStructure;
  
  /* Enable SYSCFG clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  
  //=======================================================
  /* Connect EXTI0 Line to PA0 pin */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
  
  /* Configure EXTI0 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable and set EXTI1 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  EXTI_GenerateSWInterrupt(EXTI_Line0);
  
  /* Connect EXTI1 Line to PA1 pin */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
  
  /* Configure EXTI1 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line1;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable and set EXTI1 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  EXTI_GenerateSWInterrupt(EXTI_Line1);
  
  /* Connect EXTI2 Line to PA2 pin */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource2);
  
  /* Configure EXTI2 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line2;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable and set EXTI2 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI2_3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  EXTI_GenerateSWInterrupt(EXTI_Line2);
  //=======================================================
  
  /* Connect EXTI3 Line to PA3 pin */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource3);
  
  /* Configure EXTI3 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line3;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable and set EXTI3 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI2_3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  EXTI_GenerateSWInterrupt(EXTI_Line3);
  //----------------------------------------------------------------------------
  /* Connect EXTI4 Line to PA4 pin */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource4);
  
  /* Configure EXTI4 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line4;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable and set EXTI4 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  EXTI_GenerateSWInterrupt(EXTI_Line4);
  //----------------------------------------------------------------------------  
  /* Connect EXTI5 Line to PA5 pin */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource5);
  
  /* Configure EXTI5 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line5;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable and set EXTI5 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  EXTI_GenerateSWInterrupt(EXTI_Line5);
  //----------------------------------------------------------------------------  
  /* Connect EXTI6 Line to PA6 pin */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource6);
  
  /* Configure EXTI3 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line6;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable and set EXTI6 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  EXTI_GenerateSWInterrupt(EXTI_Line6);
  //----------------------------------------------------------------------------
  /* Connect EXTI7 Line to PA7 pin */
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource7);
  
  /* Configure EXTI7 line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line7;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable and set EXTI7 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  EXTI_GenerateSWInterrupt(EXTI_Line7);
}
コード例 #8
0
ファイル: main.c プロジェクト: vchchuang/mySTM32F407
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG , ENABLE);
   
   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC  | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOA, ENABLE );
   
   RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM3, ENABLE );

 
 
    volatile int i;
    int n = 1;
    
     
    GPIO_StructInit(&GPIO_InitStructure); // Reset init structure
    GPIO_StructInit(&GPIO_InitStructure2); // Reset init structure
    GPIO_StructInit(&GPIO_InitStructure3); // Reset init structure
 
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM3);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_TIM3);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM3);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_TIM3);
    
    //GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_TIM3);
    //GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_TIM3);

/**
	PWM
		Output	PortC 6 7 8 9
		AF TIM3				
								**/    
    

    // Setup Servo on STM32-Discovery Board to use PWM.
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7| GPIO_Pin_8| GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;            // Alt Function - Push Pull
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init( GPIOC, &GPIO_InitStructure );  
    

/**
	Button
		Output PortB 4 5
						 **/

    /* GPIOA Configuration: CH1 (PB4) and CH2 (PB5) */
    GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 ;
    GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure2.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure2.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure2.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOB, &GPIO_InitStructure2);

    GPIOB->BSRRL = GPIO_Pin_4;
    GPIOB->BSRRL = GPIO_Pin_5;

/**
	Button
		Input PortA 2 3
						**/

    /* GPIOA Configuration: (PA2) and (PA3) */     //input
    GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 ;
    GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure2.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure2.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure2.GPIO_PuPd = GPIO_PuPd_DOWN ;
    GPIO_Init(GPIOA, &GPIO_InitStructure2); 
    
/**	
	Button A2 A3 Interrupt
	EXTI 2 3		
							**/ 

    //清空中断标志
    EXTI_ClearITPendingBit(EXTI_Line2);
    EXTI_ClearITPendingBit(EXTI_Line3);

    //选择中断管脚PA.2 PA.3 
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource2);
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource3);
  //    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);
  //   SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);
    
    
    EXTI_InitStructure.EXTI_Line = EXTI_Line2  ; //选择中断线路2 
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //设置为中断请求,非事件请求
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //设置中断触发方式为上下降沿触发
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;            //外部中断使能
    EXTI_Init(&EXTI_InitStructure);
    EXTI_GenerateSWInterrupt(EXTI_Line2);
    
    
    EXTI_InitStructure.EXTI_Line = EXTI_Line3 ; //选择中断线路2 
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //设置为中断请求,非事件请求
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //设置中断触发方式为上下降沿触发
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;            //外部中断使能
    EXTI_Init(&EXTI_InitStructure);
    EXTI_GenerateSWInterrupt(EXTI_Line3);
   
    
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);      //选择中断分组2
    NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn  ;     //选择中断通道2
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占式中断优先级设置为0
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;        //响应式中断优先级设置为0
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                                   //使能中断
    NVIC_Init(&NVIC_InitStructure);
    
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);    //选择中断分组2
    NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;     //选择中断通道2
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占式中断优先级设置为0
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;        //响应式中断优先级设置为0
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                                   //使能中断
    NVIC_Init(&NVIC_InitStructure);
    
    
/**
	Timer setting
	Tim3
					**/
    
    PrescalerValue = (uint16_t) ((SystemCoreClock /4) / 100000) - 1;
    
    // Let PWM frequency equal 100Hz.
    // Let period equal 1000. Therefore, timer runs from zero to 1000. Gives 0.1Hz resolution.
    // Solving for prescaler gives 240.
    TIM_TimeBaseStructInit( &TIM_TimeBaseInitStruct );
    TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
    TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInitStruct.TIM_Period = 3360 - 1;   // 0..2000
    TIM_TimeBaseInitStruct.TIM_Prescaler = 500; 
    TIM_TimeBaseInit( TIM3, &TIM_TimeBaseInitStruct );
 /**
		TIM_Prescaler = 500-1, TIM_Period = 1680-1 , TIMxCLK = 84MHz
		輸出脈波週期 = (TIM_Period + 1) * (TIM_Prescaler + 1) / TIMxCLK
		= ( 1680 - 1 +1 ) * ( 500 - 1 + 1 ) / 84000000 = 0.01s(100Hz)
																		**/   

    TIM_OCStructInit( &TIM_OCInitStruct );
    TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
    // Initial duty cycle equals 0%. Value can range from zero to 1000.
    TIM_OCInitStruct.TIM_Pulse = 3360 -1; // 0 .. 1680 (0=Always Off, 1680=Always On)
    
    
    TIM_OC1Init( TIM3, &TIM_OCInitStruct ); // Channel 1  Servo
    TIM_OC2Init( TIM3, &TIM_OCInitStruct ); // Channel 2  Servo
    TIM_OC3Init( TIM3, &TIM_OCInitStruct ); // Channel 3 PB7 Servo L
    TIM_OC4Init( TIM3, &TIM_OCInitStruct ); // Channel 4 PB8 Servo R
    TIM_Cmd( TIM3, ENABLE );

/** 
	Project Testing
						**/

  while(1)  // Do not exit
  {

//Test 1

	if(TIM3->CCR4>0){
		for(i=0;i<16000000;i++);
		TIM3->CCR4 = 0;
	}
/*
//Test 2
	TIM3->CCR4 = 168;
	for(i=0;i<16000000;i++);
	TIM3->CCR4 = 336;
	for(i=0;i<16000000;i++);
	TIM3->CCR4 = 252;
	for(i=0;i<16000000;i++);

/*
//Test 3

    if (((brightness + n) >= 3000) || ((brightness + n) <= 0))
      n = -n; // if  brightness maximum/maximum change direction
 
        brightness += n;
 
   	TIM3->CCR1 = brightness; // set brightness
    TIM3->CCR2 = 1000 - brightness; // set brightness
    TIM3->CCR3 = 3000 - brightness; // set brightness
    TIM3->CCR4 = 3000 - brightness; // set brightness
 
    for(i=0;i<10000;i++);  // delay
    //Delay(250000);
    //Delay(1000000);
    //Delay(1000000);
*/  
   }
 
  return(0); // System will implode
/**
	Others
			**/
  
  if (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)
  {
    if ((*(__IO uint32_t*) TESTRESULT_ADDRESS) == ALLTEST_PASS)
    {
     
      /* Waiting User Button is pressed or Test Program condition verified */
      while ((STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)&&(TimingDelay != 0x00))
      {}
    }
    else
    {
      /* Waiting User Button is Released  or TimeOut*/
     
      while ((STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)&&(TimingDelay != 0x00))
      {}
      if (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET)
      {
        
      }
    }
    if (TimingDelay == 0x00)
    {
      /* Turn off LEDs available on STM32F4-Discovery ------------------------*/
      /* Waiting User Button is released */
      while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)
      {}
      
      /* Unlocks the FLASH control register access */
      FLASH_Unlock();
      
      /* Move discovery kit to detect negative and positive acceleration values 
      on X, Y and Z axis */
      Accelerometer_MEMS_Test();
      
      /* USB Hardware connection */
      USB_Test();
      
      /* Audio Hardware connection */
      Audio_Test();
      
      /* Microphone MEMS Hardware connection */
      Microphone_MEMS_Test();
      
      /* Write PASS code at last word in the flash memory */
      FLASH_ProgramWord(TESTRESULT_ADDRESS, ALLTEST_PASS);
      
      while(1)
      {
        /* Toggle Green LED: signaling the End of the Test program */
        STM_EVAL_LEDToggle(LED4);
        Delay(41999/2);
      }
    }
    else
    {
      Demo_Exec();
    }
  }
  else
  {    
    Demo_Exec();
  }
}