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

📄 ddcci.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 3 页
字号:
    DDC_COMP cc;                                         /* completion code */
    
    dbCallback = NULL;                 /* un-install debug message callback */
    
                            /************************************************/
                            /* Setup.                                       */
                            /************************************************/
                            
    if(( ciPort = port ) >= I2C_MAX_PORT )                      /* validate */
        return DDC_I2CPORT;

    if( DDC_PASS != ( cc = _ddcRestart()))    /* config and start I2C slave */
        return cc;
   
    ciTabSize = tabSize;            /* number of elements in dispatch table */
    ciTable   = dTable;                        /* pointer to dispatch table */

                            /************************************************/
                            /* Create an event signalled by the read call-  */
                            /* back to indicate a DDC/CI message has been   */
                            /* received.                                    */
                            /************************************************/

    RTA_EventCreate( &ciEvent, "CIev" );

                            /************************************************/
                            /* Start DDC/CI task.                           */
                            /************************************************/

    if( RTA_SUCCESS != RTA_TaskCreate( _ddcTask, &ciTaskID,
                            taskpri, ssize, "ddcc", 0 ))
        return DDC_TASK;

    return DDC_PASS;                                            /* complete */
}



/****************************************************************************/
/* Set state of "response available" flag.                                  */
/*                                                                          */
/* The flag is set when a reply message has been formatted in response to a */
/* host request. This signals the transmitter state machine to return the   */
/* response on the next slave read operation.                               */
/*                                                                          */
/* The flag is reset by the next slave read operation or when the next host */
/* message requiring a response is received.                                */
/****************************************************************************/

void ddcciRspAvailable( BOOL available )
{
    ciResponse = available;
}



/****************************************************************************/
/* Start/restart I2C slave operation.                                       */
/****************************************************************************/

DDC_COMP _ddcRestart( void )
{
    I2CINIT foo = ddcConfig;     /* because compiler won't allow &ddcConfig */

    I2C_Reset( ciPort );
    I2C_SetConfig( ciPort, &foo );                             /* configure */

    I2C_InstallSlaveReadCallback ( ciPort, _ddcReadCallback  );/* callbacks */
    I2C_InstallSlaveWriteCallback( ciPort, _ddcWriteCallback );
    
    I2C_SlaveSuspend( ciPort );         /* suspend operation before opening */
     
    if( PASS != I2C_SlaveOpen( ciPort, CI_ADDRESS ))                /* open */
       return DDC_OPEN;
       
    return DDC_PASS;
}



/****************************************************************************/
/* DDC/CI task.                                                             */
/*                                                                          */
/* After starting the slave, the task waits to be signalled by an event     */
/* from the receiver state machine. Since the API does not provide an event */
/* driven means to signal an I2C error, the task periodically breaks from   */
/* its wait to poll for an error.                                           */
/****************************************************************************/

void _ddcTask( void )
{
    int08 cc;                                            /* completion code */
    int08 tx;                                                /* table index */
    
    rsmState = RSM_IDLE;                  /* receiver state machine is idle */
    I2C_SlaveResume( ciPort );            /* task running, resume operation */
    
    for(;;)
    {
        cc = RTA_EventWaitForSetThenClear( ciEvent, TMR_ConvertMSToTicks( 1000 ));

                            /************************************************/
                            /* Find message handler.                        */
                            /************************************************/

        if( RTA_SUCCESS == cc ) 
        {
            for( tx = 0; tx < ciTabSize; tx++ )
            {
                if( ciTable[tx].code == ciRxMsg.code )/* if func code found */
                {
                    if( ciTable[tx].expLength == ( 0x7f &ciRxMsg.length ))
                    {
                            /************************************************/
                            /* Call message handler if message code is      */
                            /* found and message is of expected length.     */
                            /*                                              */
                            /* Report processing errors to debug port. Note */
                            /* that any error response required by DDC/CI   */
                            /* is formatted in the message handler.         */
                            /************************************************/

                        switch((*ciTable[tx].pHandler)( &ciRxMsg, &ciTxMsg ))
                        {
                            case DDC_PASS:
                                break;
                                
                            case DDC_NOINPUT:
                               _ddcMessage( "No active video source ");
                                break;
                               
                            case DDC_UNKNOWNVCP:
                               _ddcMessage( "Unknown VCP code" );
                                break;
                               
                            case DDC_HOSTVALUE:
                               _ddcMessage( "Invalid host setpoint" );
                                break;
                               
                            default:
                               _ddcMessage( "Unknown message processing error" );
                                break;
                        }
                    }
                            /************************************************/
                            /* Unexpected message length.                   */
                            /************************************************/

                    else
                    {
                        sprintf( dbMessage, "ddc code=0x%02x, Bad length=%d",
                            ciTable[tx].code, 0x7f & ciRxMsg.length );
                       _ddcMessage( dbMessage );
                    }
                
                    break;
                }
            }
                            /************************************************/
                            /* Message code not found.                      */
                            /************************************************/

            if( tx == ciTabSize )
            {
                sprintf( dbMessage, "Unknown ddc code=0x%02x", ciRxMsg.code );
               _ddcMessage( dbMessage );
            }
        }

                            /************************************************/
                            /* Poll for I2C error and reset port on error.  */
                            /************************************************/

        if( 0x01 & I2C_GetSlaveTaskStatus( ciPort ))
        {
            I2C_SlaveClose( ciPort );            /* explicit close required */
           _ddcRestart();                            /* configure and start */
           _ddcMessage( "DDC Slave restart" );
            I2C_SlaveResume( ciPort );                  /* resume operation */

        } 
    }
}



/****************************************************************************/
/* Place the i2c slave read and write callbacks in a separate section so    */
/* that the code may be located in ITCM at link time. This is required for  */
/* an application configuration which is executed from flash ROM.           */
/*                                                                          */
/* For such configurations the debug trace callback should not be used, ie. */
/* the application should not call ddcciDbCallback().                       */
/****************************************************************************/

#pragma arm section code="app_rt"



/****************************************************************************/
/* Call debug message callback.                                             */
/*                                                                          */
/* Application-independent call.                                            */
/****************************************************************************/

⌨️ 快捷键说明

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