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

📄 iic_saa9730.c

📁 MIPS YAMON, a famous monitor inc. source, make file and PDF manuals.
💻 C
📖 第 1 页 / 共 3 页
字号:
 * *  Check status and control register for any detected errors. * * *  Parameters : *  ------------ * *  - * *  Return values : *  --------------- * *  'OK' = 0x00:              IIC service completed successfully *  ERROR_IIC_ADDRESS_ERROR:  IIC address error *  ERROR_IIC_DATA_ERROR:     IIC data error * * ************************************************************************/static INT32 IIC_SAA9730_check( void ) ;/************************************************************************ * *                          IIC_SAA9730_get_data *  Description : *  ------------- * *  Get data from BYTE2, BYTE1 and BYTE0 of Transfer Register and *  save it in user allocated buffer space. *   * *  Parameters : *  ------------ * *  - * * *  Return values : *  --------------- * *  - * ************************************************************************/static void IIC_SAA9730_get_data( void ) ;/************************************************************************ * *                          IIC_SAA9730_flush *  Description : *  ------------- * *  Flush out any command or data of command buffer into Transfer *  Register. *   * *  Parameters : *  ------------ * *  - * *  Return values : *  --------------- * *  'OK' = 0x00:              IIC service completed successfully *  ERROR_IIC_ADDRESS_ERROR:  IIC address error *  ERROR_IIC_DATA_ERROR:     IIC data error *  ERROR_IIC_TIMEOUT:        IIC service timed-out *  ************************************************************************/static INT32 IIC_SAA9730_flush( void ) ;/************************************************************************ * *                          IIC_SAA9730_add *  Description : *  ------------- * *  Add another data byte to command buffer and flush in case *  command buffer gets full. *   * *  Parameters : *  ------------ *  'data':                   pointer for next data byte to add *  'attrib':                 either 'nop', 'start', 'cont', 'stop' *  'read':                   'true' by read, 'false' by 'write'. * * *  Return values : *  --------------- * *  'OK' = 0x00:              IIC service completed successfully *  ERROR_IIC_ADDRESS_ERROR:  IIC address error *  ERROR_IIC_DATA_ERROR:     IIC data error *  ERROR_IIC_TIMEOUT:        IIC service timed-out * * ************************************************************************/static INT32 IIC_SAA9730_add( UINT8 *data,                       UINT8 attrib,                       UINT8 read ) ;/************************************************************************ * *                          IIC_SAA9730_wait *  Description : *  ------------- *   *  Await IIC-bus operation being completed *   * *  Parameters : *  ------------ * *  - * * *  Return values : *  --------------- * *  'OK' = 0x00:              IIC service completed successfully *  'ERROR_IIC_TIMEOUT'       IIC service timed-out * * ************************************************************************/static INT32 IIC_SAA9730_wait( void ) ;/************************************************************************ *      Implementation : Public functions ************************************************************************//************************************************************************ * *                          IIC_SAA9730_install *  Description : *  ------------- * *  Installs the IIC SAA9730 device drivers 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 : *  ------------ * *  - * * *  Return values : *  --------------- * *  'OK'(=0) *  'ERROR_IO_ILLEGAL_MAJOR':  Illegal major device number *  'ERROR_IO_NO_SPACE':       Device slot already allocated * ************************************************************************/INT32 IIC_SAA9730_install( void ){	/* pre-initialize local variables and install device services */	IO_install( SYS_MAJOR_IIC,                /* major device number */         (t_io_service) IIC_SAA9730_init,         /* 'init'  service     */                        NULL,                     /* 'open'  service  na */                        NULL,                     /* 'close' service  na */         (t_io_service) IIC_SAA9730_read,         /* 'read'  service     */         (t_io_service) IIC_SAA9730_write,        /* 'write' service     */         (t_io_service) IIC_SAA9730_ctrl ) ;      /* 'ctrl'  service     */	/* call our own 'init' service */	return IO_init( SYS_MAJOR_IIC, 0, NULL);}/************************************************************************ *      Implementation : Static functions ************************************************************************//************************************************************************ * *                          IIC_SAA9730_init *  Description : *  ------------- *  This service initializes the IIC driver and configures *  the IIC-bus speed via the 'syscon' parameter: * *  'SYSCON_COM_IIC_BAUDRATE_ID' *   * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    not used *  'p_param',   INOUT, not used * * *  Return values : *  --------------- * *  'OK'(=0) * * * ************************************************************************/staticINT32 IIC_SAA9730_init(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          void   *p_param )      /* INOUT: device parameter block       */{    int rcode ;    /* get base for SAA9730 */    rcode = SYSCON_read( SYSCON_BOARD_SAA9730_BASE_ID,                         &saa9730base,                         sizeof(saa9730base) ) ;    saa9730base = (void *)KSEG1( saa9730base );    /* reset command buffer */    IIC_SAA9730_reset() ;    /* STC-register: set speed = 103.125 KHz */    REG(saa9730base, IIC_STC) = IIC_STC_CLK_103125HZ << IIC_STC_CLK_SHF;    return( rcode ) ;}/************************************************************************ * *                          IIC_SAA9730_read *  Description : *  ------------- *  This service reads data from the specified IIC device into the *  user allocated variable, *p_param. * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    minor device number for multi device drivers *  'p_param',   INOUT, variable of type, t_IIC_read_descriptor. * * *  Return values : *  --------------- * *  'OK' = 0x00:              IIC device data read into user variable *  'ERROR_IIC_COMM_ERROR':   communication error detected * * ************************************************************************/staticINT32 IIC_SAA9730_read(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          t_IIC_read_descriptor *p_param )   /* INOUT: read buffer      */{    int i, rcode ;    UINT8 addr;    UINT8 *rdbuf ;    /* Prepare IIC-read: set slave address and 'read' flag */    addr = ((p_param->IICaddress) << 1) | 0x01 ;     /* Start IIC-read operation */    rcode = IIC_SAA9730_add( &addr, IIC_TFR_BYTEATTR_START, IIC_WRITECMD) ;    if (rcode != OK) return( rcode ) ;    /* Continue IIC-read operation */    rdbuf = p_param->buffer ;     for (i = 1; i < p_param->length ; i++)    {        rcode = IIC_SAA9730_add(rdbuf++, IIC_TFR_BYTEATTR_CONT, IIC_READCMD);        if (rcode != OK) return( rcode ) ;    }    /* Complete IIC-read operation */    rcode = IIC_SAA9730_add(rdbuf, IIC_TFR_BYTEATTR_STOP, IIC_READCMD);    if (rcode != OK) return( rcode ) ;    /* Get any remaining received data in command buffer */    rcode = IIC_SAA9730_flush() ;    return( rcode ) ;}/************************************************************************ * *                          IIC_SAA9730_write *  Description : *  ------------- *  This service writes user data to the specified IIC device. * *   * *  Parameters : *  ------------ * *  'major',     IN,    major device number *  'minor',     IN,    minor device number for multi device drivers *  'p_param',   INOUT, variable of type, t_IIC_write_descriptor. * * *  Return values : *  --------------- * *  'OK' = 0x00:              IIC service completed successfully *  'ERROR_IIC_COMM_ERROR':   communication error detected * * ************************************************************************/staticINT32 IIC_SAA9730_write(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          t_IIC_write_descriptor *p_param )   /* IN: write buffer       */{    int i, rcode ;    UINT8 addr;    UINT8 *wrbuf ;    /* Prepare IIC-write: set slave address and 'write' condition */    addr = ((p_param->IICaddress) << 1) & 0xFE ;     /* Start IIC-write operation */    rcode = IIC_SAA9730_add( &addr, IIC_TFR_BYTEATTR_START, IIC_WRITECMD) ;    if (rcode != OK) return( rcode ) ;    /* Continue IIC-write operation */    wrbuf = p_param->buffer ;     for (i = 1; i < p_param->length ; i++)    {        rcode = IIC_SAA9730_add(wrbuf++, IIC_TFR_BYTEATTR_CONT, IIC_WRITECMD);        if (rcode != OK) return( rcode ) ;    }    /* Complete IIC-write operation */    rcode = IIC_SAA9730_add(wrbuf, IIC_TFR_BYTEATTR_STOP, IIC_WRITECMD);    if (rcode != OK) return( rcode ) ;    /* Flush any remaining data in command buffer */    rcode = IIC_SAA9730_flush() ;    /*  Wait until write has finished */    if (rcode == OK)    {        rcode = -1 ;        while (rcode != OK)        {            IIC_SAA9730_add( &addr, IIC_TFR_BYTEATTR_START, IIC_WRITECMD) ;            IIC_SAA9730_add( &addr, IIC_TFR_BYTEATTR_STOP, IIC_WRITECMD);            rcode = IIC_SAA9730_flush() ;        }    }    return( rcode ) ;}/************************************************************************ * *                          IIC_SAA9730_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 *  'p_param',   INOUT, variable of type, t_IIC_ctrl_descriptor. * * *  Return values : *  --------------- * *  'OK' = 0x00:              IIC service completed successfully *  'ERROR_IIC_COMM_ERROR':   communication error detected * * ************************************************************************/staticINT32 IIC_SAA9730_ctrl(          UINT32 major,          /* IN: major device number             */          UINT32 minor,          /* IN: minor device number             */          t_IIC_ctrl_descriptor *p_param )   /* INOUT: IIC device data  */{    int i, rcode ;    t_IIC_write_read_descriptor *wrd ;    UINT8 addr;    UINT8 *buffer ;

⌨️ 快捷键说明

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