gpio和多线程
来源:互联网 发布:镜子软件手机版 编辑:程序博客网 时间:2024/05/19 05:05
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdlib.h>#include <unistd.h>#include <termios.h>#include <errno.h>#include <pthread.h>#define __TIME_PRINTF__#define __MULTI_THREAD__#define __GPIO_OPERATION__#ifdef __TIME_PRINTF__ #include <time.h>#endif#ifdef __GPIO_OPERATION__#include "include/gpio.h"#define PATH_DEV "/dev/gpio"int fd_dev;int read_gpio(int fd/*, char *buf*/){ int count, i; user_gpio_set_t gpio[20]; memset(gpio, '0', 20*sizeof(user_gpio_set_t)); count = read(fd, gpio, 20*sizeof(user_gpio_set_t)); printf("read character number = %d\n", count); for (i = 0; i < 20; i++) { printf("[%d]: name = %s, data = %d.\n", i, gpio[i].gpio_name, gpio[i].data); } return 0;}#endifvoid *pthread_read_fn_0(void *arg){ time_t nowtime; struct tm *p_time; while (1) { //sleep(1); #ifdef __TIME_PRINTF__ time(&nowtime); p_time = localtime(&nowtime); #endif printf("pthread#0 loop:\n"); #ifdef __TIME_PRINTF__ printf("\tlocaltime = %s\n", asctime(p_time)); #endif #ifdef __GPIO_OPERATION__ read_gpio(fd_dev); #endif } return NULL;}#ifdef __MULTI_THREAD__void *pthread_read_fn_1(void *arg){ time_t nowtime; struct tm *p_time; while (1) { //sleep(1); #ifdef __TIME_PRINTF__ time(&nowtime); p_time = localtime(&nowtime); #endif printf("pthread#1 loop:\n"); #ifdef __TIME_PRINTF__ printf("\tlocaltime = %s\n", asctime(p_time)); #endif #ifdef __GPIO_OPERATION__ read_gpio(fd_dev); #endif } return NULL;}#endifint main(int argc, char **argv){#ifdef __GPIO_OPERATION__ //open device printf("open A10 gpio character device.\n"); fd_dev = open(PATH_DEV, O_RDWR); if (fd_dev < 0) { printf("gpio fail to open.\n"); return -1; } printf("device open; fd = %d.\n", fd_dev);#endif printf("start to read pthread.\n"); pthread_t pthread_read_0; pthread_create(&pthread_read_0, NULL, pthread_read_fn_0, NULL);#ifdef __MULTI_THREAD__ pthread_t pthread_read_1; pthread_create(&pthread_read_1, NULL, pthread_read_fn_1, NULL);#endif pthread_join(pthread_read_0, NULL);#ifdef __MULTI_THREAD__ pthread_join(pthread_read_1, NULL);#endif #ifdef __GPIO_OPERATION__ //close device close(fd_dev); printf("device close.\n");#endif return 0;}
0 0
- gpio和多线程
- BF533-GPIO和中断
- GPIO 和 SPI
- GPIO和SPI
- GPIO和门电路
- (one) GPIO和LED
- GPIO和门电路
- GPIO配置和管理
- stm篇--GPIO和串口
- STM32--GPIO和外部中断
- GPIO的描述和配置
- msm8996的gpio和irq
- S3C2440-GPIO和jlink配置
- 1.原理图GPIO和门电路
- gpio
- gpio
- GPIO
- GPIO
- ios中使用FMDB的几个小问题
- Charles使用教程
- Linux负载均衡软件LVS之二(安装篇)
- linux基本常用命令
- ios8 CLLOcationManager 定位与ios7的对比
- gpio和多线程
- task_struct结构
- js特殊字符过滤的示例代码--转自上学吧lhwanglei
- 一张图解释decorator原理
- 养生警惕:日常十个小动作让你疾病缠身
- 可移植版本的atol
- 软件设计之UML—UML中的六大关系
- HTTP协议详解
- Asp.Net MVC 路由