亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? zlg_cat1025.c

?? 周立功 SOPC嵌入式系統實驗教程配套光盤 I2C驅動
?? C
字號:
/****************************************Copyright (c)**************************************************
**                               Guangzhou ZHIYUAN ELECTRONIC CO.,LTD.
**                                      Research centre
**                         http://www.zyinside.com, http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			  zlg_cat1025.c
** Latest modified Date:  2005-11-30
** Latest Version:		  1.0
** Descriptions:		  Implement CAT1025 access routines
**                        
**
**------------------------------------------------------------------------------------------------------
** Created by:			  Jing.Zhang
** Created date:		  2005-11-08
** Version:				  1.0
** Descriptions:		  The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/

#include <fcntl.h>
#define  __GLOBAL_DEF__

#include "sys/alt_dev.h"
#include "sys/alt_irq.h"
#include "sys/ioctl.h"
#include "sys/alt_errno.h"

#include "oc_i2c_master.h"

#define  I2C_SPEED    (400000u)  // 400kbps

/*********************************************************************************************************
** Function name:			zlg_cat1025_read
**
** Descriptions:			zlg_cat1025_read() is called by the system read() function in order to
**                    read a block of data from the CAT1025
**
** input parameters:  len: the maximum length of the data to read                      
**					  ptr: indicates the destination address
**                    fd : the file descriptor for the device to be read from.
**
** Returned value:		the number of bytes actually read
**                    -1 means some error occur.
**
** Used global variables:	None
** Calling modules:			None
**
** NOTE:             This function will block on the devices receive register, until all 
**                   characters have been received. If the maximum length of the data is 
**                   larger than the capacity of CAT1025, Not more than capacity of CAT1025
**                   will be read.
** Created by:				Jing.Zhang
** Created Date:			2005/09/30
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
int zlg_cat1025_read(alt_fd* fd, char* ptr, int len)
{
  int count;
  
  zlg_cat1025_dev* dev = (zlg_cat1025_dev*) fd->dev;

  /* The parameters are valid */
  if(len <= 0 || fd == NULL || ptr == NULL)
  {
  	return -1;
  }

  /* The number of data could not be more than the capactity of CAT1025 */
  if(len > dev->capacity)
  {
  	  len = dev->capacity;
  }
  /*
   * When running in a multi threaded environment, obtain the "read_lock"
   * semaphore. This ensures that reading from the device is thread-safe.
   */

  ALT_SEM_PEND (dev->read_lock, 0);
/******** Implement Selective Read or Sequential Read timing *************/
  /* Send Slave address with start signal */
  I2C_SEND_BYTE_WITH_START(dev->base, dev->slave_addr);
  /* Send Byte address */
  I2C_SEND_BYTE(dev->base, dev->byte_addr);
  dev->byte_addr = 0;
  /* Send Slave address with start signal plus Read Command*/
  I2C_SEND_BYTE_WITH_START(dev->base, dev->slave_addr|0x01);
  /* if the length of data equals to 1 carry out byte read operation */
  if(1 == len)
  {
  	  *ptr = I2C_RECV_BYTE_WITH_STOP(dev->base);
  }
  else{
      for(count=0; count<len-1; count++)
      {
         ptr[count] = I2C_RECV_BYTE_WITH_ACK(dev->base);
      }
  }    
  ptr[count] = I2C_RECV_BYTE_WITH_STOP(dev->base);
   /*
   * Now that Read operation is complete, release the read
   * semaphore so that other threads can access the device.
   */

  ALT_SEM_POST (dev->read_lock);
  return len;
}


/*********************************************************************************************************
** Function name:			zlg_cat1025_write
**
** Descriptions:			zlg_cat1025_write() is called by the system write() function in order to
**                    write a block of data to the CAT1025
**
** input parameters:	len: the length of the data to write                      
**						        ptr: indicates the source address
**                    fd : the file descriptor for the device to be read from.
**
** Returned value:		the number of bytes actually written 
**                    -1 means some error occur.
**         
** Used global variables:	None
** Calling modules:			  None
**
** NOTE:             This function will block on the devices transmit register, until all 
**                   characters have been transmitted. This is unless the device is being 
**                   accessed in non-blocking mode. In this case this function will return as 
**                   soon as the device reports that it is not ready to transmit.
** Created by:				Jing.Zhang
** Created Date:			2005/09/30
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
int zlg_cat1025_write (alt_fd* fd, const char* ptr, int len)
{
  int block;
  int count;

  zlg_cat1025_dev* dev = (zlg_cat1025_dev*) fd->dev;
  
  /* The parameters are valid */
  if(len <= 0 || fd == NULL || ptr == NULL)
  {
  	return -1;
  }
  block = !(fd->fd_flags & O_NONBLOCK);
  /* The number of data could not be more than a page */
  if(len > dev->page_size)
  {
  	  len = dev->page_size;
  }
  count = len - 1;
  
  /*
   * When running in a multi threaded environment, obtain the "write_lock"
   * semaphore. This ensures that writing to the device is thread-safe.
   */

  ALT_SEM_PEND (dev->write_lock, 0);
/******** Implement Byte Write or Page Write timing *************/

  /* Send Slave address with start signal */
  I2C_SEND_BYTE_WITH_START(dev->base, dev->slave_addr);
  /* Send Byte address */
  I2C_SEND_BYTE(dev->base, dev->byte_addr);
   dev->byte_addr = 0;
  /* if the length of data equals to 1 carry out byte write operation */
  if(1 == len)
  {
  	  I2C_SEND_BYTE_WITH_STOP(dev->base, *ptr);
  }
  else { /* the length of data is more than 1, carry out page write operation */
      do{
       	   I2C_SEND_BYTE(dev->base, *ptr++);
       	   count--;     
      } while (block && count);
      //Send last byte with stop signal  
    	I2C_SEND_BYTE_WITH_STOP(dev->base, *ptr);
  }
  
   /*
   * Now that Write operation is complete, release the write
   * semaphore so that other threads can access the device.
   */

  ALT_SEM_POST (dev->write_lock);
  if (count)
  {
    ALT_ERRNO = EWOULDBLOCK;
  }
  
  return (len - count);
}


/*********************************************************************************************************
** Function name:			zlg_cat1025_lseek
**
** Descriptions:			Move around within a file
**
** input parameters:	dir: dir is ignored here                      
**						        ptr: indicates the byte address of cat1025
**                    fd : the file descriptor for the device to be read from.
**
** Returned value:		-1 : the address is beyond the capacity
**                    0  : successfully!
**         
** Used global variables:	None
** Calling modules:			  None
**
**
** Created by:				Jing.Zhang
** Created Date:			2005/09/30
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
int zlg_cat1025_lseek(alt_fd* fd, int ptr, int dir)
{
  int err = -1;
  zlg_cat1025_dev* dev = (zlg_cat1025_dev*) fd->dev;
  if(ptr > dev->capacity)
  {
     dev->byte_addr = ptr;
     err = 1;
  }
  return err;
  
}

/*********************************************************************************************************
** Function name:			zlg_cat1025_init
**
** Descriptions:			Initialize the I2C Open Core. The frequency of SCL is set as freq
**                    Interrupt will not be enabled now.
**                    zlg_cat1025_init() is called by the auto-generated function 
**                    alt_sys_init() in order to initialise a particular instance of this device  
**
** input parameters:	dev: a pointer to I2C device                      
**						
** Returned value:		None 
**         
** Used global variables:	None
** Calling modules:			  None
**
** Created by:				Jing.Zhang
** Created Date:			2005/09/30
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void zlg_cat1025_init(int base, zlg_cat1025_dev* dev)
{
  
  alt_u32 prescale;
	// Calculate the prescale value
	prescale = dev->cpu_freq/((I2C_SPEED<<2) + I2C_SPEED);
  // Setup prescaler for the freq of SCL with sysclk of ALT_CPU_FREQ
  IOWR_OC_I2C_PRERLO(base, prescale & 0xff);
  IOWR_OC_I2C_PRERHI(base,(prescale & 0xff00)>>8);
  // Enable core and  disable interrupt
  IOWR_OC_I2C_CTR(base, 0x80);
  /* 
   * Initialise the read and write semaphores used to protect
   * access to the device when running in a multi-threaded environment.
   */
  ALT_SEM_CREATE (&dev->read_lock, 1);  
  ALT_SEM_CREATE (&dev->write_lock, 1);
  // register drivers into HAL
  alt_dev_reg(&dev->dev);
   
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲va天堂va国产va久| 懂色一区二区三区免费观看| 黑人巨大精品欧美一区| 9色porny自拍视频一区二区| 精品国偷自产国产一区| 亚洲一级片在线观看| 成人黄色免费短视频| 日韩精品中文字幕一区二区三区| 亚洲伦理在线精品| 国产成a人无v码亚洲福利| 6080亚洲精品一区二区| 亚洲色图一区二区| 高清在线成人网| 欧美精品一区二区三区高清aⅴ | 国产精品国产a| 狠狠色丁香久久婷婷综合丁香| 欧美日韩在线电影| 亚洲线精品一区二区三区八戒| 成人少妇影院yyyy| 日本一区二区三区电影| 国产精品一二三| 精品国产乱码久久久久久闺蜜 | 欧美日韩精品一区二区三区四区| 亚洲丝袜制服诱惑| 成人黄色av电影| 中文字幕一区二区不卡| gogogo免费视频观看亚洲一| 国产日韩欧美在线一区| 国产一区二区三区四区在线观看| 精品国产sm最大网站免费看| 老司机一区二区| 日韩欧美电影在线| 精品一区二区三区在线播放视频| 日韩欧美国产一区二区三区| 人妖欧美一区二区| 欧美电影免费观看高清完整版在| 捆绑变态av一区二区三区| 欧美一级片免费看| 美国一区二区三区在线播放| 日韩午夜精品电影| 国产精品1区2区3区| 国产女同互慰高潮91漫画| 国产69精品久久久久毛片| 国产精品久久久久久福利一牛影视| jlzzjlzz欧美大全| 亚洲国产精品久久久男人的天堂| 欧美精品久久久久久久久老牛影院 | 国产欧美日韩在线看| 成人激情校园春色| 亚洲高清视频中文字幕| 欧美一区日本一区韩国一区| 久久精品国产**网站演员| 国产亚洲欧美在线| 91麻豆免费看| 婷婷久久综合九色综合绿巨人 | 亚洲美女区一区| 欧美欧美欧美欧美首页| 精品一区二区影视| 亚洲人亚洲人成电影网站色| 91精品国产色综合久久不卡电影| 国产一区二三区| 樱花影视一区二区| 欧美一级黄色大片| 成人中文字幕电影| 一本色道久久综合狠狠躁的推荐| 亚洲综合无码一区二区| 麻豆精品蜜桃视频网站| 中文天堂在线一区| 欧美色成人综合| 风间由美一区二区三区在线观看 | 国产欧美日本一区二区三区| 日本精品裸体写真集在线观看| 久久成人免费网| 亚洲另类一区二区| 久久久久国色av免费看影院| 欧美亚洲高清一区二区三区不卡| 久久国内精品自在自线400部| 中文字幕一区二区三| 日韩欧美一级二级| 91久久精品日日躁夜夜躁欧美| 精品制服美女丁香| 午夜一区二区三区在线观看| 中文字幕成人av| 欧美成人a在线| 欧美欧美午夜aⅴ在线观看| 成人激情开心网| 国产精品一区在线| 中文一区二区完整视频在线观看| 狠狠网亚洲精品| 国产精品女人毛片| 欧美va亚洲va国产综合| 91久久精品一区二区二区| av福利精品导航| 亚洲一区二区三区四区的| 亚洲精品在线电影| 色婷婷综合激情| 韩国成人福利片在线播放| 日本一区二区三级电影在线观看| 亚洲女同ⅹxx女同tv| 中文字幕一区二区三区蜜月| 日韩视频免费直播| 亚洲午夜一区二区| 水野朝阳av一区二区三区| 777精品伊人久久久久大香线蕉| 99精品一区二区三区| 国产成人三级在线观看| 狠狠色狠狠色合久久伊人| 九九九精品视频| 久久精品久久99精品久久| 日韩国产高清影视| 天天色天天爱天天射综合| 亚洲电影一区二区三区| 亚洲国产成人精品视频| 一区二区三区高清不卡| 一区二区免费在线播放| 亚洲天堂av老司机| 亚洲精品少妇30p| 亚洲激情自拍偷拍| 亚洲国产中文字幕| 视频一区二区三区在线| 乱一区二区av| 国产精品一区免费视频| 国产成人av资源| 成人教育av在线| 色哦色哦哦色天天综合| 在线一区二区三区四区五区| 欧美日韩精品一区二区| 欧美一区二区免费观在线| 日韩三级精品电影久久久| 久久精品一区蜜桃臀影院| 国产亚洲一区二区三区在线观看| 欧美国产成人在线| 亚洲激情中文1区| 天天综合天天综合色| 久久99精品国产麻豆婷婷洗澡| 国产精品一区二区三区四区| 丁香六月久久综合狠狠色| 一本大道久久a久久综合| 欧美日韩电影一区| 久久久亚洲午夜电影| 亚洲男人都懂的| 蜜臀久久久99精品久久久久久| 激情五月婷婷综合| av电影在线观看不卡| 欧美夫妻性生活| 国产亚洲美州欧州综合国| 亚洲欧洲精品一区二区精品久久久| 一区二区三区**美女毛片| 日本欧美肥老太交大片| 国产丶欧美丶日本不卡视频| 在线观看亚洲专区| 国产亚洲综合性久久久影院| 亚洲综合一二区| 国产精品一区二区三区四区| 日本伦理一区二区| 久久一区二区视频| 亚洲午夜三级在线| 国产乱人伦偷精品视频免下载| 一本久久a久久免费精品不卡| 日韩欧美一级片| 尤物视频一区二区| 国产高清精品久久久久| 欧美女孩性生活视频| 中文成人综合网| 久久精品久久99精品久久| 91国在线观看| 国产精品国产精品国产专区不片| 日本午夜一区二区| 色婷婷激情一区二区三区| 国产日韩精品一区二区浪潮av| 视频一区在线播放| 91麻豆国产自产在线观看| 久久久噜噜噜久久中文字幕色伊伊| 一区二区三区电影在线播| 夫妻av一区二区| 久久久综合网站| 久久狠狠亚洲综合| 在线不卡欧美精品一区二区三区| 中文字幕在线不卡视频| 久久精品国产亚洲高清剧情介绍| 欧亚洲嫩模精品一区三区| 国产精品免费网站在线观看| 久久99精品国产麻豆婷婷洗澡| 在线成人av影院| 亚洲成人免费看| 欧美无砖砖区免费| 综合分类小说区另类春色亚洲小说欧美| 国产伦精品一区二区三区免费迷| 91精品国产福利| 亚洲成av人**亚洲成av**| 欧洲生活片亚洲生活在线观看| 国产精品超碰97尤物18| 国产91精品入口| 国产精品你懂的在线| 成人一级片网址| 亚洲欧洲日韩av| 色呦呦日韩精品| 亚洲一卡二卡三卡四卡| 欧美日韩国产综合视频在线观看 | 日本特黄久久久高潮|