处理GPIO用户空间的ARM9嵌入式Linux AM1808 [英] Handle GPIO in User Space ARM9 Embedded Linux AM1808

查看:243
本文介绍了处理GPIO用户空间的ARM9嵌入式Linux AM1808的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要我的接口GSM模块基于ARM9的AM1808。

I have to interface my GSM module with the AM1808 based on ARM9.

我已经分配的所有GPIO引脚到Da850.c以及mux.h文件。我成功创建的uImage和我的闪存插入的图像。

I have assigned all the GPIO pins to the Da850.c as well as mux.h files. I successfully created a uImage and inserted that image in my flash.

我需要处理一些GPIO从用户应用。

I need to handle some of that GPIO from User application.

我知道,我们可以从Kerel空间处理GPIO,但我需要从用户空间来处理。

I know that we can handle the GPIO from the Kerel space but i need to handle from the user space.

至于例子中,我分配了一个GPIO为电源键GSM模块。我需要通过应用程序来改变销装置(高或低)。

As for example I have assigned a GPIO for power key to GSM module. I need to change the pin means (HIGH or LOW) through application.

好吧,我已经写了下面code,从用户空间访问,

Ok i have written a following code to access it from the User Space,

#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#include "GSMpwr.h"
#define BS_GSM_PWR_REGISTER 0x01E26014
#define BS_DCDS_MASK    0x00000004

int fd;  // Memory device descriptor
unsigned long *pPWR;

unsigned short GetGSMpwr(void)
{
    #if defined __HOST_ARM
    unsigned long dcd_value = *pPWR;
    return (pwr_value >> 7) & 0x01;
    #endif
}

void InitializeGSMpwr(void) 
{
    #if defined __HOST_ARM
    int page_size = getpagesize();
    unsigned int MAP_addr;
    unsigned int reg_addr;
    unsigned char *pTemp;             // Pointer to GSMpwr register

/*
 * Open memory and get pointer to GSMpwr register in the FPGA
 */

if((fd = open("/dev/mem", O_RDWR | O_SYNC)) < 0)
{
        printf("failed to open /dev/mem");
        return;
}
else
{
    MAP_addr = (BS_GSM_PWR_REGISTER & ~(page_size - 1));
    pTemp = (unsigned char *)mmap(NULL, page_size,(PROT_READ |      PROT_WRITE),MAP_SHARED,fd,MAP_addr);

    if((pTemp == MAP_FAILED) || (pTemp == NULL))
    {
        printf("failed to map /dev/mem");
        return;
    }
    else
    {
    printf("Memory Mapped at Address %p. \n",pTemp);
    }

virt_addr = map_base + (control & MAP_MASK);



    reg_addr = (BS_GSM_PWR_REGISTER & (page_size - 1));
    pPWR = (unsigned long*)(pTemp + reg_addr);
    printf("GSM PWR PIN mapped in Application\n");
}

我只能通过这种code读了针,现在我想使用该引脚为输出,并且想去高低与3秒的时间间隔。

I can only read that pin through this code, Now i want to use that pin as an output and want to go high and low with the time interval of 3sec.

推荐答案

最简单的方法是利用在的sysfs ,在那里你可以控制所有的出口GPIO的GPIO支持。请看看Linux的内核GPIO文档,特别的为了用户SYSFS接口的一部分。

The easiest way is to utilize GPIO support in sysfs, where you could control all the exported GPIO's. Please have a look at the Linux kernel GPIO documentation, in particular, Sysfs Interface for Userspace part.

在你在 sysfs的启用GPIO支持 GPIO_SYSFS )的GPIO控制是一样简单:

After you have enabled GPIO support in sysfs (GPIO_SYSFS), the GPIO control would be as easy as:

示例

GPIO=22

cd /sys/class/gpio
ls
echo $GPIO > /sys/class/gpio/export
ls

上gpio22不存在的第一个LS通知,但并导出GPIO 22后的用​​户空间。

Notice on the first ls that gpio22 doesn't exist, but does after you export GPIO 22 to user space.

cd /sys/class/gpio/gpio$GPIO
ls

有文件设置的方向和检索的当前值。

There are files to set the direction and retrieve the current value.

echo "in" > direction
cat value

您可以输出配置GPIO和设置的值也是如此。

You can configure the GPIO for output and set the value as well.

echo "out" > direction
echo 1 > value

例子是从这里 服用。

Example is taken from here.

这篇关于处理GPIO用户空间的ARM9嵌入式Linux AM1808的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆