Chinaunix首页 | 论坛 | 博客
  • 博客访问: 612499
  • 博文数量: 144
  • 博客积分: 5037
  • 博客等级: 大校
  • 技术积分: 1581
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-30 21:49
文章存档

2010年(16)

2009年(128)

分类: LINUX

2009-03-31 14:12:14

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/hardware.h>
#include <asm-arm/arch-s3c2410/gpio.h>
#include <fcntl.h>
#include <pthread.h>

#define msleep(x) usleep(x*1000)

int gpf_fd;

void *thread1(void *arg)
{
    while(1)
    {
        ioctl(gpf_fd, GPIO_SET_PIN, 4);
        msleep(250);
        ioctl(gpf_fd, GPIO_CLR_PIN, 4);
        msleep(250);
    }
}

void *thread2(void *arg)
{
    while(1)
    {
        ioctl(gpf_fd, GPIO_SET_PIN, 5);
        msleep(500);
        ioctl(gpf_fd, GPIO_CLR_PIN, 5);
        msleep(500);
    }
}

void *thread3(void *arg)
{
    while(1)
    {
        ioctl(gpf_fd, GPIO_SET_PIN, 6);
        sleep(1);
        ioctl(gpf_fd, GPIO_CLR_PIN, 6);
        sleep(1);
    }
}

int main(void)
{
    pthread_t tid1, tid2, tid3;
    void *tret;

    if((gpf_fd = open("/dev/gpf/0", O_RDWR)) < 0)
    {
        perror("open error!");
        exit(1);
    }

    if(ioctl(gpf_fd, GPIO_SET_MULTI_PIN_OUT, 0xF0) != 0)
    {
        perror("set error!");
        exit(1);
    }

    pthread_create(&tid1, NULL, thread1, NULL);
    msleep(1);
    pthread_create(&tid2, NULL, thread2, NULL);
    msleep(1);
    pthread_create(&tid3, NULL, thread3, NULL);
    msleep(1);
    while(1)
    {
        ioctl(gpf_fd, GPIO_SET_PIN, 7);
        msleep(1500);
        ioctl(gpf_fd, GPIO_CLR_PIN, 7);
        msleep(1500);
    }


// pthread_join(tid1, &tret);

// pthread_join(tid2, &tret);

}


驱动的编译:

arm-linux-gcc -c s3c2410-gpf.c -o s3c2410-gpf.o -I /home/skyily/tools/kernel/include/

阅读(952) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:关于用get_current_dir_name()时的一个警告

给主人留下些什么吧!~~