内核发送广播给上层套接字接口应用

linux-3.10\drivers\media\platform\sunxi-vin\vin-video\vin_core.c
static unsigned char is_init_video_switch = 0;
#include <linux/switch.h>
static struct switch_dev videostatus_switch_dev = {
.name = “videoerr”,
};

#define VIDEOERR_DEF 200
static unsigned char need_send_videoerr = VIDEOERR_DEF;
void send_videoerr(int videonum)
{
if(videonum != VIDEOERR_DEF){
need_send_videoerr = videonum;
}
if(need_send_videoerr == VIDEOERR_DEF){
return;
}

	vin_err("need_send_videoerr=%d\n", need_send_videoerr);
	switch_set_state(&videostatus_switch_dev, need_send_videoerr);  //此处
	need_send_videoerr = VIDEOERR_DEF;  //此处
	msleep(100);
	switch_set_state(&videostatus_switch_dev, need_send_videoerr); //此处

}
EXPORT_SYMBOL(send_videoerr);
/*

  • the interrupt routine
    */
    static irqreturn_t vin_isr(int irq, void priv)
    {

    /
    exception handle */
    if ((status.buf_0_overflow) || (status.buf_1_overflow) ||
    (status.buf_2_overflow) || (status.hblank_overflow)) {
    if ((status.buf_0_overflow) || (status.buf_1_overflow) ||
    (status.buf_2_overflow)) {
    csic_dma_int_clear_status(vinc->vipp_sel,
    DMA_INT_BUF_0_OVERFLOW |
    DMA_INT_BUF_1_OVERFLOW |
    DMA_INT_BUF_2_OVERFLOW);
    vinc->vin_status.err_cnt++;
    vin_err(“video%d fifo overflow\n”, vinc->id);
    }
    if (status.hblank_overflow) {
    csic_dma_int_clear_status(vinc->vipp_sel,
    DMA_INT_HBLANK_OVERFLOW);
    vinc->vin_status.err_cnt++;
    vin_err(“video%d hblank overflow\n”, vinc->id);
    }
    vin_log(VIN_LOG_VIDEO, “reset csi dma%d module\n”, vinc->id);
    if (cap->frame.fmt.fourcc == V4L2_PIX_FMT_FBC) {
    csic_fbc_disable(vinc->vipp_sel);
    csic_fbc_enable(vinc->vipp_sel);
    } else {
    csic_dma_disable(vinc->vipp_sel);
    csic_dma_enable(vinc->vipp_sel);
    }
    need_send_videoerr = vinc->id; //此处
    }

    }
    lichee\linux-3.10\drivers\misc\neo\carstate.c
    else if(!strncmp(p, “videoerr”, 8)){
    int videoerr;
    p = memchr(p, ’ ', len);
    para(p, &p, len, &videoerr);
    printk(“carstate_videoerr=%d.\n”, videoerr);
    send_videoerr(videoerr);
    goto out;

    out:
    up(&sem);
    return count;
    }
    static void led_display(void)
    {
    static int timer = 0;
    timer++;
    //printk(KERN_ERR “carstate.c led_display() timer=%d\n”, timer);
    if(timer == LED_LOW){
    gpio_direction_output(gpio_led_status, 1);
    //if(video4open == 1)N123_signal_detect();
    if((N3Open_initOK==1) && (N3Video4_Open == 1))N123_signal_detect();
    if(video0open == 1)C2395_signal_detect();
    }else if(timer == LED_HIGH){
    timer = 0;
    gpio_direction_output(gpio_led_status, 0);
    }
    }

static ssize_t cmd_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
{
const char *p;
int len, total;
char buf[64];

memset(buf, 0, sizeof(buf));
if(down_interruptible(&sem)) {
	return -ERESTARTSYS;
}

if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
	return -EFAULT;

p = memchr(buf, '\n', count);
len = p ? p - buf : count;
total = len;

p = buf;
while(*p == ' ')p++;
printk(KERN_ERR "carstate: cmd_write:%s\n", p);
while(1)
{
	if (!strncmp(p, "-p", 2)) {

		p = memchr(p, ' ', len);
		if(!p){
			printk(KERN_ERR "carstate: muxcmd error for cmd %s.", buf);
			goto out;
		}
		while(*p == ' ')p++;

		if(!strncmp(p, "mute", 4)){ //此处
			int mute_status;
			p = memchr(p, ' ', len);
			para(p, &p, len, &mute_status);
			printk(KERN_ERR "carstate: mute_status=%d\n", mute_status);
			sound_switch(mute_status);
			goto out;

		}else if(!strncmp(p, "task", 4)){ //此处
			if(detect_task == NULL){
				detect_task = kthread_run(readstatus_work, NULL, "carstate_detect");
				if (IS_ERR(detect_task)) {
					printk(KERN_ERR "carstate: kthread_create failed\n");
				} else {
					printk(KERN_ERR "carstate: kthread_create succeed\n");
				}
			}
			goto out;

		}else if(!strncmp(p, "videonum", 8)){
			int video_number, pwr_status;
			p = memchr(p, ' ', len);
			para(p, &p, len, &video_number);
			para(p, &p, len, &pwr_status);
			printk(KERN_ERR "carstate: video%d power status=%d\n", video_number, pwr_status);
			switch(video_number){
				case 0:
					gpio_set_value(gpio_camera_adas, pwr_status);
					video0open = pwr_status; //此处
				break;

				case 4:
				case 9:
					gpio_set_value(gpio_camera_dsm, pwr_status);
					//video4open = pwr_status;
					N3Video4_Open = pwr_status;
					if(!pwr_status )N3Open_initOK=0; //此处
					printk(KERN_ERR "carstate: N3Open_initOK=%d,N3Video4_Open=%d\n", N3Open_initOK, N3Video4_Open);	
				break;

				case 5:
				case 10:
					gpio_set_value(gpio_camera_reverse, pwr_status);
				break;
			}
			goto out;


		}else if(!strncmp(p, "camerafps", 9)){


}else if(!strncmp(p, “videomirror”, 11)){
int videonum, videohflip;
p = memchr(p, ’ ', len);
para(p, &p, len, &videonum);
para(p, &p, len, &videohflip);
printk(“carstate_videonum=%d videohflip=%d.\n”, videonum, videohflip);
switch(videonum){
case 5:
if(videohflip == 1){
vin_video_flip_ctl(5, 1);
}else{
vin_video_flip_ctl(5, 0);
}
break;
}
goto out;

		}


}
static int readstatus_work(void *arg)
{
//int i;
//struct switcher_monitor *monitor;
//int state=0;

set_freezable();
printk(KERN_ERR "readstatus_work enter jiffies=%ld!\n", msecs_to_jiffies(WORK_INTERVAL));

while (1) {
	set_current_state(TASK_INTERRUPTIBLE);
	schedule_timeout(msecs_to_jiffies(WORK_INTERVAL));

	if (kthread_freezable_should_stop(NULL))
		break;

	led_display();
	send_videoerr(200); //此处


}
android\hardware\aw\camera\V4L2CameraDevice2.cpp
void V4L2CameraDevice::videoError(int videonum)
{
char cmd_buf[32]={0};
int fd = open("/dev/carstate", O_WRONLY | O_NONBLOCK);
if (fd == -1){
DCAMERA(“ERROR opening /dev/carstate: %s”, strerror(errno));
return;
}
sprintf(cmd_buf, “-p videoerr %d”, videonum);
write(fd, cmd_buf, 15);
DCAMERA("/dev/video%d, mCameraFd=%d, fd=%d, cmd_buf=%s", videonum, mCameraFd, fd, cmd_buf);
close(fd);
//usleep(200000);
}
int V4L2CameraDevice::v4l2WaitCameraReady()
{
fd_set fds;
struct timeval tv;
int r;

FD_ZERO(&fds);
FD_SET(mCameraFd, &fds);

/* Timeout */
tv.tv_sec  = 2;
tv.tv_usec = 0;

r = select(mCameraFd + 1, &fds, NULL, NULL, &tv);
if (r == -1) {
    DCAMERA("select err, %s, mCameraFd=%d, /dev/video%d, start mCurAvailBufferCnt=%d", strerror(errno), mCameraFd, mVideoNum, mCurAvailBufferCnt);
    return -1;

} else if (r == 0) {
    DCAMERA("select timeout, %s, mCameraFd=%d, /dev/video%d, start mCurAvailBufferCnt=%d", strerror(errno), mCameraFd, mVideoNum, mCurAvailBufferCnt);
	if (mCaptureThreadState == CAPTURE_STATE_STARTED){
		videoError(mVideoNum); //此处
	} else {
		DCAMERA("CaptureThread is not running, mCaptureThreadState=%d, /dev/video%d", mCaptureThreadState, mVideoNum);
	}
    return -1;
}

return 0;

}

©️2020 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值