2013-05-09 2 views
1

팔 기반의 mini6410에서 간단한 프로젝트를하고 있습니다. 데비안 패키지를 미니에 설치했습니다. 내 프로젝트는 하나의 IR 모션 센서와 I USB 웹캠을 mini6410과 인터페이스하는 것입니다. 작업은 간단합니다. IR 센서로 움직임이 감지 될 때마다 웹캠이 30 초 동안 켜져 이미지를 저장하고 이전 이미지를 덮어 씁니다. 이미 arm-linux-gcc를 사용하여 Open CV 코드를 작성했습니다.open Cv 및 mini6410의 GPIO에서 문제가 발생했습니다.

IR 용 GPE 레지스터를 사용하고 있습니다.

여기 해결할 수없는 문제가 있습니다. 심지어 해결 방법을 모른다. OpenCv 코드는 cpp 파일 인 camera.cpp이고 I/O 포트를 처리하는 파일은 sensor.c라는 C 파일입니다. 이제 그 파일에서 GPE 레지스터가 1인지 아닌지를 확인하기 위해 폴링 (polling) 또는 어떤 메커니즘을 사용하는지 확인합니다. 그것이 하나라면 이미지를 캡처하기 시작하는 Open CV 코드를 시작해야합니다. 더욱이이 sensor.c 파일은 모듈로 컴파일되지 않고 mini6410에서 insmod됩니다.

그러나 C 파일에 C++ 코드를 작성하는 방법을 모릅니다. 당신은 C 파일에서 OpenCV를 호출하는 법을 모른다. 그것은 모듈이고이 안에는 CIP 코드를 쓰지 않고 네임 스페이스 std를 사용하고 네임 스페이스 cv doesnot work를 사용합니다.

저는 임베디드 스터디에 익숙하며 스스로 리눅스입니다. 그래서 가능한 해결책이 있는지 알고 싶었습니다. 두 파일의 코드를 첨부하고 있습니다.

이 sensor.c입니다

#include <linux/module.h> 
#include <linux/slab.h> 
#include <linux/input.h> 
#include <linux/init.h> 
#include <linux/errno.h> 
#include <linux/serio.h> 
#include <linux/delay.h> 
#include <linux/clk.h> 
#include <linux/wait.h> 
#include <linux/sched.h> 
#include <linux/cdev.h> 
#include <linux/miscdevice.h> 
#include <asm/io.h> 
#include <asm/irq.h> 
#include <asm/uaccess.h> 
#include <mach/map.h> 
#include <mach/regs-clock.h> 
#include <mach/regs-gpio.h> 
#include <plat/gpio-cfg.h> 
#include <mach/gpio-bank-q.h> 
#include <mach/gpio-bank-e.h> 
#include <mach/map.h> 
#include <plat/regs-timer.h> 
#include <mach/hardware.h> 
#include <linux/kernel.h> 
#include <linux/mm.h> 
#include <linux/fs.h> 
#include <linux/types.h> 
#include <linux/moduleparam.h> 
#include <linux/ioctl.h> 
#include <linux/cdev.h> 
#include <linux/string.h> 
#include <linux/list.h> 
#include <linux/pci.h> 
#include <asm/uaccess.h> 
#include <asm/atomic.h> 
#include <asm/unistd.h> 
#include <mach/gpio-bank-k.h> 

#define RLV 0x0FFF 

unsigned Gpe; 
unsigned sensor_value; 

typedef struct 
{ 
    int delay; 
} TIM_DEV; 
static TIM_DEV TimDev; 

static irqreturn_t INTHandler(int irq,void *TimDev) 
{ 
    Gpe = readl(S3C64XX_GPEDAT); 
    Gpe &= ~(0xF<<1); 
    readl(sensor_value, S3C64XX_GPEDAT); 

    while (sensor_value == 1) 
    {//1 means that IR sensor has detected a motion and given a value of +5 V 

     for (i = 0; i < 30; i++){ 
      //CV_function(); 
      // delay here such that delay(1 s) * 30 = 30 seconds  

     } 
    } 
    return IRQ_HANDLED; 
} 

static struct file_operations dev_fops = { 
    .owner  = THIS_MODULE, 
    .write   = MyWrite, 
}; 

static struct miscdevice misc = { 
    .minor = MISC_DYNAMIC_MINOR, 
    .name = DEVICE_NAME, 
    .fops = &dev_fops, 
}; 

static int __init dev_init(void) 
{ 
    int ret; 
    unsigned TimerControl; 
    unsigned TimerINTControl; 
    unsigned TimerCNTB; 
    unsigned TimerCMPB; 
    unsigned TimerCFG1; 
    unsigned Ge; 

    TimerControl = readl(S3C_TCON); 
    TimerINTControl = readl(S3C_TINT_CSTAT); 
    TimerCNTB = readl(S3C_TCNTB(0)); 
    TimerCMPB = readl(S3C_TCMPB(0)); 
    TimerCFG1 = readl(S3C_TCFG1); 
    TimerCFG1 &= ~(S3C_TCFG1_MUX0_MASK);   
    TimerCNTB = RLV; 
    TimerCMPB = 0; 
    writel(TimerCNTB, S3C_TCNTB(0)); 
    writel(TimerCMPB, S3C_TCMPB(0)); 
    writel(TimerCFG1, S3C_TCFG1);   
    TimerControl |= S3C_TCON_T0MANUALUPD;  
    TimerINTControl |= S3C_TINT_CSTAT_T0INTEN; 
    writel(TimerControl, S3C_TCON);   
    writel(TimerINTControl, S3C_TINT_CSTAT);  
    TimerControl = readl(S3C_TCON); 
    TimerControl |= S3C_TCON_T0RELOAD;  
    TimerControl &= ~S3C_TCON_T0MANUALUPD;  
    TimerControl |= S3C_TCON_T0START;  
    writel(TimerControl, S3C_TCON);   

//////////////Here I am configuring my GPE as input///////////// 
    Ge = readl(S3C64XX_GPECON); 
    Ge &= ~(0xFFFF<<4); 
    Ge |= (0x0000<<4); 
    writel(Ge, S3C64XX_GPECON); 

///////////// 
    misc_register(&misc); 
    ret = request_irq(IRQ_TIMER0, INTHandler, IRQF_SHARED, DEVICE_NAME, &TimDev); 
    if (ret) 
    { 
     return ret; 
    } 
    return ret; 
} 

static void __exit dev_exit(void) 
{ 
    free_irq(IRQ_TIMER0, &TimDev); 
    misc_deregister(&misc); 
} 

module_init(dev_init); 
module_exit(dev_exit); 
MODULE_LICENSE("GPL"); 
MODULE_AUTHOR("XYZ"); 

이 어떤 방법으로 내이 위의 코드를 가지고 있어야 sensor.c 파일에서 루프 camera.cpp

#include <opencv2/objdetect/objdetect.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 

#include <iostream> 
#include <stdio.h> 

using namespace std; 
using namespace cv; 


int main(int argc, const char** argv) 
    {CvCapture* capture = 0; 
    Mat frame, frameCopy, image; 
    capture = cvCaptureFromCAM(2); 
    if(!capture) 
    { 
     cout << "No camera detected" << endl; 
    } 
     if(capture) 
     { 
      cout << "In capture ..." << endl; 

      IplImage* iplImg = cvQueryFrame(capture); 
      frame = iplImg; 

      if(frame.empty()) 
       break; 
      if(iplImg->origin == IPL_ORIGIN_TL) 
       frame.copyTo(frameCopy); 
      else 
       flip(frame, frameCopy, 0); 
      cvSaveImage("image.jpg" ,iplImg); 
     } 
    cvReleaseCapture(&capture); 
    return 0; 
} 

는 IS

나는 당신이 아이디어를 얻길 바랍니다. 감사합니다.

답변

0

t에서 누락 된 링크 코드는 위의 사용자 공간 코드가 장치 드라이버가 감지 한 GPIO 핀의 변경 사항에 대한 알림을 얻을 수있는 메커니즘입니다.

이를 달성하기 위해 두 가지 분명한 방법이 있습니다 :

  1. 플랫폼의 GPIO 자원에 GPIO 핀을 통합하고 사용자 공간에서 일반 sysfs 메커니즘을 사용하여이. Linux kernel GPIO documentation은 커널과 사용자 공간 측면을 모두 설명합니다.
  2. 드라이버에서 GPIO 라인에 대해 sysfs 노드를 노출 시키도록하십시오. sysfs은 Linux 드라이버 모델의 기본 요소입니다. 나는 Linux Device Drivers 3rd Edition의 철저한 읽기를 제안합니다.

두 방법의 사용자 공간 측면과 유사하다 : 당신은 당신의 모듈이 내 보낸 sysfs 자원을 열고 다음 이벤트가 발생할 때까지 하나 poll() 또는 select() 차단 사용합니다.

관련 문제