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

📄 iic_piix4.c

📁 MIPS YAMON, a famous monitor inc. source, make file and PDF manuals.
💻 C
📖 第 1 页 / 共 2 页
字号:
 *  'minor',     IN,    minor device number for multi device drivers *  'param',     INOUT, variable of type, t_IIC_write_descriptor. * *  Return values : *  --------------- * *  'OK' = 0x00:              IIC service completed successfully *  'ERROR_IIC_COMM_ERROR':   communication error detected * ************************************************************************/static INT32 iic_piix4_write(    UINT32 major,		/* IN: major device number             */    UINT32 minor,		/* IN: minor device number             */    t_IIC_write_descriptor *param )	     /* IN: write buffer       */{    UINT8			writecount;    UINT8			prom_offset;    UINT8			*bufptr;    if (param->length <= 1)    {        return ERROR_IIC_DATA_ERROR;      }    bufptr = param->buffer;    prom_offset = *bufptr++;    writecount = param->length - 1;    /* Poll for ready and acknowledge SMBus interrupts */    iic_piix4_poll();    for (;writecount-- ; prom_offset++, bufptr++)    {        /* Setup slave address and write command */        SMB_WRITE( PIIX4_SMBHSTADD_OFS,                   (param->IICaddress << PIIX4_SMBHSTADD_ADDR_SHF) &                   ~PIIX4_SMBHSTADD_READ_BIT );        /* Setup command (= offset in slave) */        SMB_WRITE( PIIX4_SMBHSTCMD_OFS, prom_offset );        /* Setup data to write */        SMB_WRITE( PIIX4_SMBHSTDAT0_OFS, *bufptr );        /* Start Byte Data operation */        SMB_WRITE( PIIX4_SMBHSTCNT_OFS,                   (PIIX4_SMBHSTCNT_CP_BDRW << PIIX4_SMBHSTCNT_CP_SHF) |                   PIIX4_SMBHSTCNT_START_BIT );        /* Wait for operation */        sys_wait_ms(5);        /* Poll for done and acknowledge SMBus interrupts */        iic_piix4_poll();    }    return OK;}/************************************************************************ * *                          iic_piix4_ctrl *  Description : *  ------------- *  This service comprise following aggregated IIC services: *   1) 'write_read' IIC device. *   2) 'test'       IIC device. * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    minor device number for multi device drivers *  'param',   INOUT, variable of type, t_IIC_ctrl_descriptor. * *  Return values : *  --------------- * *  'OK' = 0x00:              IIC service completed successfully *  'ERROR_IIC_COMM_ERROR':   communication error detected * ************************************************************************/static INT32 iic_piix4_ctrl(    UINT32 major,		/* IN: major device number             */    UINT32 minor,		/* IN: minor device number             */    t_IIC_ctrl_descriptor *param )	     /* INOUT: IIC device data */{    t_IIC_write_read_descriptor *descr;    INT32			rcode;    UINT8			readcount;    UINT8			prom_offset;    UINT8			*bufptr;    rcode = OK;    switch( param->command )    {      case IIC_CTRL_TEST :        /* TEST command: (TBD not ready) */	rcode = OK;	break;      case IIC_CTRL_WRITE_READ :        /* WRITE-READ command: */	descr = (t_IIC_write_read_descriptor *)param->data;	if( (descr->write_length != 1) ||	    (descr->read_length  == 0) )	{	    rcode = ERROR_IIC_DATA_ERROR;              break;	}	readcount = descr->read_length;	prom_offset = descr->write_buffer[0];	bufptr = descr->read_buffer;        /* Poll for ready and acknowledge SMBus interrupts */        iic_piix4_poll();	for (;readcount-- ; prom_offset++, bufptr++)	{            /* Setup slave address and read command */            SMB_WRITE( PIIX4_SMBHSTADD_OFS,                       (param->IICaddress << PIIX4_SMBHSTADD_ADDR_SHF) |                       PIIX4_SMBHSTADD_READ_BIT );            /* Setup command (= offset in slave) */            SMB_WRITE( PIIX4_SMBHSTCMD_OFS, prom_offset );	    /* Start Byte Data operation */	    SMB_WRITE( PIIX4_SMBHSTCNT_OFS, 		       (PIIX4_SMBHSTCNT_CP_BDRW << PIIX4_SMBHSTCNT_CP_SHF) |		       PIIX4_SMBHSTCNT_START_BIT );            /* Poll for done and acknowledge SMBus interrupts */            iic_piix4_poll();            /* read data byte */            SMB_READ( PIIX4_SMBHSTDAT0_OFS, bufptr );        }	break;	      default :        rcode = ERROR_IIC_UNKNOWN_COMMAND;	break;    }    return rcode;}/************************************************************************ * *                          iic_piix4_poll *  Description : *  ------------- *  This routine polls the SMBus to be not busy *    and acknowledges any SMBus interrupt. * ************************************************************************/static void iic_piix4_poll( void ){    volatile UINT8 status;    for (;;)    {        sys_wait_ms(1);        SMB_READ( PIIX4_SMBHSTSTS_OFS, &status );        if (status & PIIX4_SMBHSTSTS_BUSY_BIT) continue;        status &= ( PIIX4_SMBHSTSTS_FAILED_BIT |                    PIIX4_SMBHSTSTS_COL_BIT    |                    PIIX4_SMBHSTSTS_DE_BIT     |                    PIIX4_SMBHSTSTS_INT_BIT );        if (status == 0) break;        SMB_WRITE( PIIX4_SMBHSTSTS_OFS, status);    }}/************************************************************************ *      Implementation : Public functions ************************************************************************//************************************************************************ * *                          iic_piix4_install *  Description : *  ------------- * *  Installs the IIC PIIX4 device driver services in  *  the IO system at the reserved device slot, found in the *  'sysdev.h' file, which defines all major device numbers. * *  Note: *  This service is the only public declared interface function; all *  provided device driver services are static declared, but this *  function installs the function pointers in the io-system to *  enable the provided public driver services. * *  Parameters : *  ------------ * *  None * *  Return values : *  --------------- * *  'OK'(=0) *  'ERROR_IO_ILLEGAL_MAJOR':  Illegal major device number *  'ERROR_IO_NO_SPACE':       Device slot already allocated * ************************************************************************/INT32 iic_piix4_install(void){	/* pre-initialize local variables and install device services */	IO_install(         SYS_MAJOR_IIC,        /* major device number */             (t_io_service) iic_piix4_init,  	  /* 'init'  service     */                            NULL,                 /* 'open'  service  na */                            NULL,                 /* 'close' service  na */             (t_io_service) iic_piix4_read,	  /* 'read'  service     */             (t_io_service) iic_piix4_write,	  /* 'write' service     */             (t_io_service) iic_piix4_ctrl );	  /* 'ctrl'  service     */	/* call our own 'init' service */	return IO_init( SYS_MAJOR_IIC, 0, NULL);}

⌨️ 快捷键说明

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