Home > other >  Dht11 drive test shows that the resource on tiny4412 temporary unavailable
Dht11 drive test shows that the resource on tiny4412 temporary unavailable

Time:12-05

For bosses to help me, why the test dht11 on tiny4412 driver, display the resource temporary unavailable?
Attach a program:
Driver:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include
#include
#include

/* define DHT11 access GPIO port */
# define DHT11_PIN EXYNOS4_GPX1 (7)

/* define a symbol, which is used to determine the temperature and humidity of the received data is correct */
The static unsigned char check_flag;
The static unsigned char dht11_data_buf [6].

/*
* read a bit data
*/
Static int dht11_read_one_bit (void)
{
Gpio_direction_input (DHT11_PIN);
Return gpio_get_value (DHT11_PIN);
}

/* set the pin is out and set the value of this pin */
The static void dht11_gpio_out (int value)
{
Gpio_direction_output (DHT11_PIN, value);
}

/* read a byte data from dht11 */
The static unsigned char dht11_read_byte (void)
{
int i=0;
int num;
Unsigned char flag=0;
Unsigned char data=https://bbs.csdn.net/topics/0;

For (num=0; Num & lt; 8; Num++)
{
I=0;
/* wait DHT11 pins into high level */
while(! Gpio_get_value (DHT11_PIN))
{
Udelay (10);
i++;
If (I & gt; 10)
break;
}
Flag=0 x00;
Udelay (28);
If (gpio_get_value (DHT11_PIN))
{
Flag=0 x01;
}
I=0;
While (gpio_get_value (DHT11_PIN))
{
Udelay (10);
i++;
If (I & gt; 12)
break;
}
The data & lt; <=1;
Data |=flag;
}
Return the data.
}

/* * read data format:
* 8 bit: humidity integer
* 8 bit: humidity decimal
* 8 bit: temperature integer
* 8 bit: temperature decimal
* 8 bit: check code
* buf store data:
* dht11_data_buf [0] : humidity integer
* dht11_data_buf [1] : humidity decimal
* dht11_data_buf [2] : temperature integer
* dht11_data_buf [3] : temperature decimal
* dht11_data_buf [4] : check code
* dht11_data_buf [5] : self calculate the check code
*/
The static void dht11_read_data (void)
{
int i=0;

Dht11_gpio_out (0);
Mdelay (30);
Dht11_gpio_out (1);
Udelay (20);

If (dht11_read_one_bit ()==0)
{
while(! Gpio_get_value (DHT11_PIN))/* wait IO mouth into a high level */
{
Udelay (5);
i++;
If (I & gt; 20)
{
Printk (" err dht11_read_data % d! \ n ", __LINE__);
break;
}
}
I=0;
While (gpio_get_value (DHT11_PIN))/* wait IO mouth into a low level */
{
Udelay (5);
i++;
If (I & gt; 20)
{
Printk (" err dht11_read_data % d! \ n ", __LINE__);
break;
}
}
For (I=0; I & lt; 5; I++) temperature and humidity data read/* */
Dht11_data_buf [I]=dht11_read_byte ();

/* to read the data validation */
Dht11_data_buf [5]=dht11_data_buf dht11_data_buf [0] + [1] + dht11_data_buf + dht11_data_buf [2] [3].

/* judge read calibration values and calculated values are the same */
If (dht11_data_buf [4]==dht11_data_buf [5])/* is same to sign a value of 0 XFF */
{
Check_flag=0 XFF;
}
Else if (dht11_data_buf [4].=dht11_data_buf [5])/* are not identical, to sign a value of 0 */
{
Check_flag=0 x00;
Printk (" dht11 check fail \ n ");
}
}
}

Miscellaneous equipment/* open, write here is empty function */
Static int dht11_open (struct inode * inode, struct file * file)
{
return 0;
}

/* read function of miscellaneous equipment */
The static ssize_t dht11_read (struct file, the file * char * buffer, the __user size_t size, loff_t * offset)
{
Int ret.
Unsigned long flags;

/* because DHT11 timing requirements is very high, so to make the code into the critical region while reading the temperature and humidity, preventing the kernel scheduling and grab */
Local_irq_save (flags);
Dht11_read_data ();
Local_irq_restore (flags);

If (check_flag==0 XFF)
{
/* will read the temperature and humidity data copies to user space */
Ret=copy_to_user (buffer, dht11_data_buf, sizeof (dht11_data_buf));
If (ret & lt; 0)
{
Printk (" copy to user err \ n ");
The return - EAGAIN;
}
The else
{
return 0;
}
}
The else
{
The return - EAGAIN;
}
}

/* release function, write here is empty function */
Static int dht11_release (struct inode * inode, struct file * file)
{
return 0;
}

/* definition of miscellaneous equipment operation structure and initialize a member function pointer */
The static const struct file_operations dht11_fops={
The owner=THIS_MODULE,
The open=dht11_open,
Read=dht11_read,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related