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

📄 hw_fm31xxx_api.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:  HW_FM31XXX_API.C    REVISION HISTORY:    Date       Ver Name                           Description  ---------- --- --------------------- -----------------------------------------  08/25/2005 1.0 JiGwanKang(xchannel)  Created    ...............................................................................   DESCRIPTION:    This Module contains definition for NVRAM and RTC (for FM31xxx) function.   ...............................................................................*/   /** ************************************************************************* **  ** includes ** ************************************************************************* **/#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <asm/ioctl.h>#include <asm/errno.h>#include <linux/i2c.h>#include <linux/i2c-dev.h>#include <time.h> /* for struct tm */#include "hw_fm31xxx_api.h"/** ************************************************************************* **  ** defines ** ************************************************************************* **///#define m_DEBUG(format, args...)  printf(format, ## args) #define m_DEBUG(format, args...)  #define m_MSG(format, args...)	printf(format, ## args) #define m_ERROR(format, args...)  printf(format, ## args);fflush(stdout);/** ************************************************************************* **  ** typedefs ** ************************************************************************* **/	 /** ************************************************************************* **  ** globals ** ************************************************************************* **/  /** ************************************************************************* **  ** locals ** ************************************************************************* **/static S32	fd_fm31;/** ************************************************************************* **  ** forward declarations ** ************************************************************************* **/RETURN fm31xxx_open(void) {	if ((fd_fm31 = open("/dev/i2c-0", O_RDWR)) < 0) {		m_ERROR("Open FM31xxx Fail\n");		return FAILURE;	}	return SUCCESS;}void fm31xxx_close(void){	close(fd_fm31);}RETURN fm31xxx_write_reg(UNS8 sub_addr, UNS8 data){	UNS8	buf[2];			if (ioctl(fd_fm31, I2C_SLAVE_FORCE, FM31xxx_RTC_ADDR) < 0) {		m_ERROR("hw_fm31xxx_api.c: set slave addr error\n");				return FAILURE;	}	buf[0] = sub_addr;	buf[1] = data;		if (write(fd_fm31, buf , 2) != 2) {		m_ERROR("hw_fm31xxx_api.c: write data error\n");				return FAILURE;	}		return SUCCESS;}	RETURN set_cur_time(struct tm *tmp){	struct fm31xxx_st bbclk;	UNS8	reg, data, temp_date[8];	time_t tmp_t;		memset(&bbclk,0x00,sizeof(bbclk));	/* Gregorian Day */	tmp_t = mktime(tmp);	tmp = localtime(&tmp_t);	bbclk.sec10=tmp->tm_sec/10;	bbclk.sec=tmp->tm_sec%10;	bbclk.min10=tmp->tm_min/10;	bbclk.min=tmp->tm_min%10;	bbclk.hr10=tmp->tm_hour/10;	bbclk.hr=tmp->tm_hour%10;	bbclk.day= tmp->tm_wday + 1;		bbclk.date10=tmp->tm_mday/10;	bbclk.date=tmp->tm_mday%10;	bbclk.month10=(tmp->tm_mon+1)/10;	bbclk.month=(tmp->tm_mon+1)%10;	bbclk.year10=(tmp->tm_year-100)/10;	bbclk.year=(tmp->tm_year-100)%10;	fm31xxx_write_reg(0x01, 0x01);	fm31xxx_write_reg(0x00, 0x00);	fm31xxx_write_reg(0x00, 0x02);	temp_date[0] = 0x02;	memcpy(temp_date+1, &bbclk, sizeof(bbclk));	if (write(fd_fm31, temp_date , sizeof(temp_date) ) != sizeof(temp_date)) {		m_ERROR("hw_fm31xxx_api.c: write data error\n");				return FAILURE;	}	return SUCCESS;}RETURN get_cur_time(struct tm *tmp){	UNS8	buf[2];		struct fm31xxx_st bbclk;	UNS8 temp_date[7];	fm31xxx_write_reg(0x01, 0x01);	fm31xxx_write_reg(0x00, 0x00);	fm31xxx_write_reg(0x00, 0x01);	buf[0] = 0x02;	if (write(fd_fm31, buf , 1) != 1) {		m_ERROR("hw_fm31xxx_api.c: write data error\n");				return FAILURE;	}		if(read(fd_fm31, temp_date, 7) != 7)	{		m_ERROR("hw_fm31xxx_api.c: read data error\n");				return FAILURE;	}	memcpy(&bbclk, temp_date, 7);	tmp->tm_sec=10*bbclk.sec10+bbclk.sec;	tmp->tm_min=10*bbclk.min10+bbclk.min;	tmp->tm_hour=10*bbclk.hr10+bbclk.hr;	tmp->tm_wday=bbclk.day;	tmp->tm_mday=10*bbclk.date10+bbclk.date;	tmp->tm_mon=10*bbclk.month10+bbclk.month;	tmp->tm_year=10*bbclk.year10+bbclk.year + 2000;	tmp->tm_yday = 0;	tmp->tm_isdst= 0;		return SUCCESS;}RETURN set_nvram_para(S32 offset, S32 size, UNS32 *value){	UNS16   ii;	UNS8	buf[2];		if (ioctl(fd_fm31, I2C_SLAVE_FORCE, FM31xxx_NVRAM_ADDR) < 0) {		m_ERROR("hw_fm31xxx_api.c: set slave addr error\n");				return FAILURE;	}	offset &= 0x7fff;		buf[0] = (offset >> 8) & 0x7f;	buf[1] = offset & 0xff;		for(ii=0;ii < size;ii++)  		buf[2+ii] = (*value >> (((size - 1) - ii) * 8)) & 0xff;		if (write(fd_fm31, buf , size+2 ) != (size+2)) {		m_ERROR("hw_fm31xxx_api.c: write data error\n");				return FAILURE;	}		return SUCCESS;}S32 get_nvram_para(S32 offset, S32 size){	S32       result = 0;	UNS16   ii;	UNS8	buf[4];		if(ioctl(fd_fm31, I2C_SLAVE_FORCE, FM31xxx_NVRAM_ADDR) < 0)	{		m_ERROR("hw_fm31xxx_api.c: set slave addr error\n");				return FAILURE;	}	offset &= 0x7fff;		buf[0] = (offset >> 8) & 0x7f;	buf[1] = offset & 0xff;		if(write(fd_fm31, buf, 2) != 2)	{		m_ERROR("hw_fm31xxx_api.c: sub addr write data error\n");				return FAILURE;	}		if(read(fd_fm31, buf, size) != size)	{		m_ERROR("hw_fm31xxx_api.c: read data error\n");				return FAILURE;	}	for(ii=0;ii<size;ii++)		result |= buf[(size-1) - ii] << (ii*8);	return result;}/* end of hw_nvram_api.c */

⌨️ 快捷键说明

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