Пример #1
0
/* Configure GPIO pins to be used as LED and push button */
static void configure_gpios()
{
	mdev_t *pinmux_dev, *gpio_dev;

	/* Initialize  pinmux driver */
	pinmux_drv_init();

	/* Open pinmux driver */
	pinmux_dev = pinmux_drv_open("MDEV_PINMUX");

	/* Initialize GPIO driver */
	gpio_drv_init();

	/* Open GPIO driver */
	gpio_dev = gpio_drv_open("MDEV_GPIO");

	/* Configure GPIO pin function for GPIO connected to LED */
	pinmux_drv_setfunc(pinmux_dev, gpio_led, GPIO_LED_FN);

	/* Configure GPIO pin direction as Output */
	gpio_drv_setdir(gpio_dev, gpio_led, GPIO_OUTPUT);
	/* Keep initial state of LED: ON */
	gpio_drv_write(gpio_dev, gpio_led, 0);

	/* Close drivers */
	pinmux_drv_close(pinmux_dev);
	gpio_drv_close(gpio_dev);
}
Пример #2
0
/* This function turns off the LED*/
static void gpio_led_off(void)
{
	mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO");
	/* Turn off LED by writing  1 in GPIO register */
	gpio_drv_write(gpio_dev, gpio_led, 1);
	gpio_drv_close(gpio_dev);
}
Пример #3
0
/* This function turns on the LED*/
static void gpio_led_on(void)
{
	mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO");
	/* Turn on LED by writing  0 in GPIO register */
	gpio_drv_write(gpio_dev, gpio_led, 0);
	gpio_drv_close(gpio_dev);
	gpio_led_state = 1;
}
Пример #4
0
static void gpio_led_off(void)
{
	mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO");
	/* Turn off LED by writing  1 in GPIO register */
	gpio_drv_write(gpio_dev, gpio_led, 1);
	gpio_drv_close(gpio_dev);
	gpio_led_state = 0;
	gpio_led_on();	//giving the control back to the calling function.
}
Пример #5
0
//function to blink the led the number of times equal to occurence of the word
static void gpio_led_on(wcount)	//passing the word count
{
	int count=wcount;	//setting the counter

	
	mdev_t *gpio_dev = gpio_drv_open("MDEV_GPIO");
	/* Turn on LED by writing  0 in GPIO register */
	gpio_drv_write(gpio_dev, gpio_led, 0);
	gpio_drv_close(gpio_dev);
	gpio_led_state = 1;
	gpio_led_off();	//turning off the led to give the binking effect
	count=count-1;	//decreasing the counter by 1 after glowing led
	while(count!=1)	//recursive function, to be visited till counter becomes 1(not 0 because counter starts from w,not w-1)
	{	
		gpio_led_on(count); //recursive function
	}
	
}
Пример #6
0
// configuring gpios
static void configure_gpios()
{
	mdev_t *pinmux_dev, *gpio_dev;

	/* Initialize  pinmux driver */
	pinmux_drv_init();

	/* Open pinmux driver */
	pinmux_dev = pinmux_drv_open("MDEV_PINMUX");

	/* Initialize GPIO driver */
	gpio_drv_init();

	/* Open GPIO driver */
	gpio_dev = gpio_drv_open("MDEV_GPIO");

	/* Configure GPIO pin function for GPIO connected to LED */
	pinmux_drv_setfunc(pinmux_dev, gpio_led, GPIO_LED_FN);

	/* Configure GPIO pin direction as Output */
	gpio_drv_setdir(gpio_dev, gpio_led, GPIO_OUTPUT);
	/* Keep initial state of LED: ON */
	gpio_drv_write(gpio_dev, gpio_led, 0);

	/* Configure GPIO pin function for GPIO connected to push button */
	pinmux_drv_setfunc(pinmux_dev, gpio_pushbutton, GPIO_PUSHBUTTON_FN);

	/* Configure GPIO pin direction as input */
	gpio_drv_setdir(gpio_dev, gpio_pushbutton, GPIO_INPUT);

	/* Register a callback for push button interrupt */
	gpio_drv_set_cb(gpio_dev, gpio_pushbutton, GPIO_INT_FALLING_EDGE,
			NULL,
			pushbutton_press);

	/* Close drivers */
	pinmux_drv_close(pinmux_dev);
	gpio_drv_close(gpio_dev);
}
/* Sensor input from IO should be read here and to be passed
	in curevent->event_curr_value variable to the upper layer

	This function will be called periodically by the upper layer
	hence you can poll your input here, and there is no need of
	callback IO interrupt, this is very usefull to sense variable
	data from analog sensors connected to ADC lines. Event this can
	be used to digital IO scanning and polling
*/
int ultrasonic_sensor_input_scan(struct sensor_info *curevent)
{
	int val;
	mdev_t *gpio_dev;
	unsigned int duration = 0;
	unsigned int fduration = 0;

	/* Open GPIO driver */
	gpio_dev = gpio_drv_open("MDEV_GPIO");

	/* Confiugre GPIO pin direction as Input */
	gpio_drv_setdir(gpio_dev, ULTRASONIC_SEN_IO, GPIO_OUTPUT);

	/* Ultrosonic distance reading
		Send one altrasonic pulse and wait for
		its return responce
		Then calculate the distance between transmistted
		and received input
	*/

	/* Send a pulse */
	gpio_drv_write(gpio_dev, ULTRASONIC_SEN_IO, 0);
	os_thread_sleep(1);
	gpio_drv_write(gpio_dev, ULTRASONIC_SEN_IO, 1);
	os_thread_sleep(1);
	gpio_drv_write(gpio_dev, ULTRASONIC_SEN_IO, 0);

	/* Confiugre GPIO pin direction as Input */
	gpio_drv_setdir(gpio_dev, ULTRASONIC_SEN_IO, GPIO_INPUT);

	/* Check the line is low */
	while(1) {
		gpio_drv_read(gpio_dev, ULTRASONIC_SEN_IO, &val);
		if (!val)
			break;
	};

	/* Check the line is going high */
	while(1) {
		gpio_drv_read(gpio_dev, ULTRASONIC_SEN_IO, &val);
		if (val)
			break;
	};
	duration = os_get_timestamp(); /* start pulse width measurement */

	/* Check the line is going low */
	while(1) {
		gpio_drv_read(gpio_dev, ULTRASONIC_SEN_IO, &val);
		if (!val)
			break;
	};
	fduration = os_get_timestamp(); /* stop pulse width measurement */

	if (fduration > duration) {
		duration = fduration - duration; /* distance in usec */
		/* Calibrate distance measured in centimeters */
		duration /= 29;
		duration /= 2;

		wmprintf("%s senval=%d cm\r\n", __FUNCTION__, duration);
		sprintf(curevent->event_curr_value, "%d", duration);
	}

	gpio_drv_close(gpio_dev);

	return 0;
}
Пример #8
0
__interrupt void TIM1_UPD_Interrupt(void)
{
//校正模式
    if (U8_CURR_WorkMode == D_CAL_START_MODE)  //该模式用于统计用电量标准值
    {
        if (U32_Cal_Times == D_TIME1_CAL_TIME)
        {
            U8_CURR_WorkMode = D_CAL_END_MODE;  //达到36s,计数停止
            U16_REF_001_E_Pluse_CNT = U16_E_Pluse_CNT;		//记录36S时间内的脉冲数,此脉冲数表示0.01度用电量,36s参考次数
        }
    }

//功率测量
    if (U16_P_TotalTimes >= D_TIME1_P_OVERFLOW)
    {
        B_P_OVERFLOW = TRUE; 		//溢出,
        B_P_Last_OVERFLOW = B_P_OVERFLOW;
        //清状态参数,重新开始测试
        U16_P_TotalTimes = 0;       //清溢出寄存器
        U16_P_OneCycleTime = 0;
        U16_P_CNT = 0;              //等待下一次中断开始计数
        B_P_TestOneCycle_Mode = 0;   //初始化为计数脉冲测量模式      
    }
    else if (U16_P_OneCycleTime == D_TIME1_100MS) //有无风险cycletime跳跃
    {
      if (U16_P_CNT < 2)
      {
        // 100ms内只有一次中断,说明周期>100ms,采用单周期测量模式 
        B_P_TestOneCycle_Mode = 1;
      }
      else
      {
         // 100ms内有2次或以上数量脉冲,说明周期<100ms,采用计数脉冲测量模式
         B_P_TestOneCycle_Mode = 0;   
      }
    }
    
//电压、电流测量
    if (B_VI_Test_Mode == 1)
    {
        //电压测量      
        if (U16_V_TotalTimes >= D_TIME1_V_OVERFLOW)
        {
            B_V_OVERFLOW = TRUE; 
            B_V_Last_OVERFLOW = B_V_OVERFLOW;
            //清状态参数,重新开始测试
            U16_V_TotalTimes = 0;       //清溢出寄存器
            U16_V_OneCycleTime = 0;
            U16_V_CNT = 0;
            B_V_TestOneCycle_Mode = 0;   //初始化为计数脉冲测量模式      
        }
        else if (U16_V_OneCycleTime == D_TIME1_100MS)
        {
          if (U16_V_CNT < 2)
          {
            // 100ms内只有一次中断,说明周期>100ms,采用单周期测量模式 
            B_V_TestOneCycle_Mode = 1;
          }
          else
          {
             // 100ms内有2次或以上数量脉冲,说明周期<100ms,采用计数脉冲测量模式
             B_V_TestOneCycle_Mode = 0;   
          }
        }
    }
    else
    {
        //电流测量
        if (U16_I_TotalTimes >= D_TIME1_I_OVERFLOW)
        {
            B_I_OVERFLOW = TRUE; 
            B_I_Last_OVERFLOW = B_I_OVERFLOW;
            //清状态参数,重新开始测试
            U16_I_TotalTimes = 0;       //清溢出寄存器
            U16_I_OneCycleTime = 0;
            U16_I_CNT = 0;
            B_I_TestOneCycle_Mode = 0;   //初始化为计数脉冲测量模式      
        }
        else if (U16_I_OneCycleTime == D_TIME1_100MS)
        {
          if (U16_I_CNT < 2)
          {
            // 100ms内只有一次中断,说明周期>100ms,采用单周期测量模式 
            B_I_TestOneCycle_Mode = 1;
          }
          else
          {
			 // 100ms内有2次或以上数量脉冲,说明周期<100ms,采用计数脉冲测量模式
			 B_I_TestOneCycle_Mode = 0;
          }
        }
    }
      

//电压、电流测量模式切换  B_VI_Test_Mode:(1:电压测量模式) (0:电流测试模式) 

    if (U16_VI_Test_Times == 0)
    {
        if (B_VI_Test_Mode == 1)
        {
            //转为电流测量模式
        	gpio_drv_write(gpio_dev,gpio_IV,GPIO_IO_LOW);
            B_VI_Test_Mode = 0;
            //IO_HLW8012_CF1_S = 0;  //拉低,用API处理
            U16_VI_Test_Times = D_TIME1_10S;
            
            //清状态参数
            U16_I_TotalTimes = 0;
            U16_I_OneCycleTime = 0;
            U16_I_CNT = 0;
            B_I_OVERFLOW = FALSE; 
        }
        else
        {
            //转为电压测量模式
        	gpio_drv_write(gpio_dev,gpio_IV,GPIO_IO_HIGH);
            B_VI_Test_Mode = 1;
            //IO_HLW8012_CF1_S = 1;  //拉高
            U16_VI_Test_Times = D_TIME1_1S;
            
            //清状态参数
            U16_V_TotalTimes = 0;
            U16_V_OneCycleTime = 0;
            U16_V_CNT = 0;
            B_V_OVERFLOW = FALSE; 
        }
    }
/*
//按键扫描,20mS一次
	U8_KeyScanTimes++;
  	if (U8_KeyScanTimes > D_TIME1_20MS)
  	{
      		B_KeyScanEn = TRUE;
	  	U8_KeyScanTimes = 0;
  	}
    
// 每0.5S串口发送一次数据
    U16_SendUart_Time++;
    if (U16_SendUart_Time == D_TIME1_500MS)
    {
        B_DIS_EN = TRUE;
        U16_SendUart_Time = 0;
    }

// Clear TIM1 INT FLAG   
   TIM1_SR1 = 0x00;
*/
}