static void oneshot_event(void)
{
    shot_time = 0;
    if(pwmSwitch == 0)
    {
        pwmSwitch = 1;
        open_pwm(irreceiver_data->pwm_no);//on
    }
    else
    {
        pwmSwitch = 0;
        close_pwm(irreceiver_data->pwm_no);//off
    }
    
    //set next window timer
    send_idx++;
    if(send_idx < send_win.winNum)
    {
        set_timer_b_event(send_win.winArray[send_idx]);
    }
    else //pwm should be off
    {
        close_pwm(irreceiver_data->pwm_no);;
        pwmSwitch = 0;
        send_flag = 0;
    }
}
static void timer_b_interrupt(void)
{
    //char tmp[128];    

    time_count++;
    if(debug_timer == 1 && time_count % 10 == 0)
    {
        if(debug_timer_pwm == 0)
        {
            debug_timer_pwm = 1;
            open_pwm(irreceiver_data->pwm_no);;//on
        }
        else
        {
            debug_timer_pwm = 0;
            close_pwm(irreceiver_data->pwm_no);//off
        }
    }
    
    if(shot_time !=0 && (time_count*10) >= shot_time)
    {    
        //sprintf(tmp, "[%lu][%lu]", shot_time, time_count*10);
        //strcat(logbuf, tmp);
        oneshot_event();
    }
}
static void init_pwm(void)
{
    int pwm_level = 24000000/irreceiver_data->freq/2;
    unsigned int pwmReg = 0;
    int idx = irreceiver_data->pwm_no;
    if(PWM_A == idx)
    {
        pwmReg = PWM_PWM_A;
    }
    else if(PWM_B == idx)
    {
        pwmReg = PWM_PWM_B;
    }
    else if(PWM_C == idx)
    {
        pwmReg = PWM_PWM_C;
    }
    else if(PWM_D == idx)
    {
        pwmReg = PWM_PWM_D;
    }
    
    close_pwm(irreceiver_data->pwm_no);
    irreceiver_data->init_pwm_pinmux();
    
	WRITE_CBUS_REG_BITS(pwmReg, pwm_level, 0, 16);  //low
    WRITE_CBUS_REG_BITS(pwmReg, pwm_level, 16, 16);  //hi
}
Example #4
0
/*---------------------------------------------------------------------------------------------------------*/
int main (void)
{   
	unsigned int i=0;
    SYS_Init();  
	P20=0;P21=0;
	_GPIO_SET_PIN_MODE(P3,6,GPIO_PMD_OUTPUT);
	open_capture(); //open capture funcation
	open_pwm3();
	while(1)
	{
		if(LIGHT_RESISTANCES) //day
		{
			if(light_flag!=DAY) //night turn to day need close LED 
			{
				light_flag=DAY;
				close_pwm(0);
				close_pwm(1);
				clean_capture_flag(); //day close capture
			}
		}
		else  //night
		{
			if(light_flag!=NIGHT) //day turn to night
			{
				light_flag=NIGHT;
				open_pwm(0);  //open led0
				//open_pwm(1);
				if(!capture_start_enable)
					open_capture_flag();
			}
			else
			{
				if(capture_wave_count>=CAPTURE_ALL_TIME) //capture compelet once time
				{
					
					if(calculate_capture_frequency()==0) //have someone pass by, led1 light
					{
						open_pwm(1);
						open_timer0();
						open_capture_flag();
						while(timer0_100ms_count<50) // 3s
						{
							if(capture_wave_count>=CAPTURE_ALL_TIME) 
							{
								if(calculate_capture_frequency()==0) //have peope
								{
									timer0_100ms_count=0;
								}
								open_capture_flag();
							}
							if(LIGHT_RESISTANCES) //day
							{	
								open_capture_flag();
								break;
							}
						}
						close_timer0();
						close_pwm(1);
					}
					else
						open_capture_flag();
				}
			}
			
		}
		//delay some time for check light resistance	
		for(i=0;i<1000;i++);
	}
	//return 0;  
}