⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pthread_gpio.c

📁 1、基于韩国at2041芯片开发的Linux环境的DVR代码。 2、以原来代码进行了修改。 3、主要修改网络通讯出现异常问题处理 4、硬盘覆盖录像不起作用
💻 C
字号:

/* set tabstop=4 */
/********************************************************************************
 *                                                                              *
 * Copyright(C) 2004  Penta-Micro                                               *
 *                                                                              *
 * ALL RIGHT RESERVED                                                           *
 *                                                                              *
 * This software is the property of Penta-Micro and is furnished under          *
 * license by Penta-Micro. This software may be used only in accordance         *	
 * with the terms of said license. This copyright notice may not be             *
 * removed, modified or obliterated without the prior written permission        *
 * of Penta-Micro.                                                              *
 *                                                                              *
 * This software may not be copyed, transmitted, provided to or otherwise       *
 * made available to any other person, company, corporation	or other entity     *
 * except as specified in the terms of said license.                            *
 *                                                                              *
 * No right, title, ownership or other interest in the software is hereby       *
 * granted or transferred.                                                      *
 *                                                                              *
 * The information contained herein is subject to change without notice and     *
 * should not be construed as a commitment by Penta-Micro.                      *
 *                                                                              *
 ********************************************************************************
 
  MODULE NAME:  PTHREAD_GPIO.C
  
  REVISION HISTORY:
  
  Date       Ver Name                  Description
  ---------- --- --------------------- -----------------------------------------
  12/09/2004 1.0 JiGwan Kang(xchannel)   Created  
 ...............................................................................
 
  DESCRIPTION:
  
  This Module contains definition for read/write GPIO 
  ( Sensor In/Out, Spot Select, Live Audio Select, Etc )
  
 ...............................................................................
*/  
 

/** ************************************************************************* ** 
 ** includes
 ** ************************************************************************* **/
#include <stdio.h>
#include <unistd.h>

#include "main.h" 
#include "pthread_gpio.h"

/** ************************************************************************* ** 
 ** defines
 ** ************************************************************************* **/
#define m_DEBUG(format, args...)  printf(format, ## args);fflush(stdout);
#define m_MSG(format, args...)      printf(format, ## args) 
#define m_ERROR(format, args...)  printf(format, ## args);fflush(stdout);


/** ************************************************************************* ** 
 ** typedefs
 ** ************************************************************************* **/

	 
/** ************************************************************************* ** 
 ** globals
 ** ************************************************************************* **/
extern PTHREAD_STATE 	*gp_state_thread;
extern SETUP_PARAM		*gp_setup_param;

  
/** ************************************************************************* ** 
 ** locals
 ** ************************************************************************* **/


/** ************************************************************************* ** 
 ** forward declarations
 ** ************************************************************************* **/



void *pthread_gpio(void *args)
{
	UNS16		ii;
	UNS32         cur_gpio_val;
	UNS32         sensor_pin_table[4] = { 0x02, 0x01, 0x80, 0x40 };
	BOOL          sensor_out_flag[4] = { 0, 0, 0, 0 };
      time_t          cur_time, start_time[4] = { 0, 0, 0, 0 };

	m_DEBUG("\t!!! pthread GPIO     !!!\n");
      while (1) {
      	ppc405_gpio_in(&cur_gpio_val);
        if (gp_state_thread->state_enc.state == BUSY) {
            for (ii = 0; ii < SENSOR_MAX_CH; ii++) {
                /* sensor in processing */
                if (gp_setup_param->enc_ch[ii].sensor.flag_in) {
                    if (cur_gpio_val & sensor_pin_table[ii]) {
                        if (gp_setup_param->enc_ch[ii].sensor.flag_in_noc)   /* Normal Close 0 -> 1 */
                            gp_state_thread->state_enc.enc_ch[ii].sensor = TRUE;
                        else
                            gp_state_thread->state_enc.enc_ch[ii].sensor = FALSE;
                    } else {
                        if (!gp_setup_param->enc_ch[ii].sensor.flag_in_noc)  /* Normal Open  1 -> 0 */
                            gp_state_thread->state_enc.enc_ch[ii].sensor = TRUE;
                        else
                            gp_state_thread->state_enc.enc_ch[ii].sensor = FALSE;                            
                    }
                    /* sensor out processing */
                    if (gp_setup_param->enc_ch[ii].sensor.flag_out) {
                        if (gp_state_thread->state_enc.enc_ch[ii].sensor == TRUE) {
                            if (!sensor_out_flag[ii]) {
                                if (gp_setup_param->enc_ch[ii].sensor.flag_out_noc) 
                                    set_sensor_out_ch(ii, TRUE);
                                else
                                    set_sensor_out_ch(ii, FALSE);
                                sensor_out_flag[ii] = TRUE;
                            }
                            time(&start_time[ii]);
                        }
                        if (sensor_out_flag[ii]) {
                            time(&cur_time);
                            /* duration time expired */
                            if (cur_time >= (start_time[ii]+gp_setup_param->enc_ch[ii].sensor.flag_out_duration)) {
                                if(gp_setup_param->enc_ch[ii].sensor.flag_out_noc)
                                    set_sensor_out_ch(ii, FALSE);
                                else
                                    set_sensor_out_ch(ii, TRUE);                                
                                sensor_out_flag[ii] = FALSE;
                            }
                        }
                    }
                }
            }
        }
        usleep(400000);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -