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

📄 scidrv.c

📁 56f8300E系列dsp的BOOTloader
💻 C
📖 第 1 页 / 共 3 页
字号:
* Module:         sciBlockRead()
*
* Description:    Read data from SCI driver into user buffer
*
*                 In Blocking mode, "read" waits until all data will be
*                 available.
*
*
* Returns:        Actual read size
*
* Arguments:      hndl        - SCI Device descriptor returned by "sciOpen" call.
*                 pBuffer     - Char pointer to user buffer. 
*                 NBytes      - NBytes (in 8-bit bytes) of the data to be read 
*                               from SCI device; 
*
* Range Issues:   None
*
* Test Method:    sci.mcp
*
*****************************************************************************/

ssize_t sciBlockRead( handle_t hndl , void * pBuffer , size_t NBytes )
{
    struct  sSciDevice * pHandle = (struct sSciDevice *)hndl;
            ssize_t      n_bytes = NBytes;
            ssize_t      bytes;
    do
    {
        bytes   = sciNonBlockRead(hndl , pBuffer , n_bytes);
        n_bytes -= bytes;
        pBuffer = (unsigned char *)pBuffer + bytes;
    } 
    while( n_bytes );

    return NBytes;

}

/*****************************************************************************
*
* Module:         sciNonBlockWrite()
*
* Description:    Write user buffer out of SCI device.
*
*                 In NonBlocking mode, "sciWrite" starts the transfer operation
*                 and returns control to the application. It does not wait 
*                 while all data is transferred via SCI.
*
* Returns:        Actual number of bytes transmitted
*
* Arguments:      hndl     - SCI Device descriptor returned by "sciOpen" call.
*                 pBuffer  - Pointer to user buffer. 
*                 NBytes   - NBytes (in 8-bit bytes) of the data to be written
*                            out of SCI device; 
*
* Range Issues:   None
*
* Test Method:    sci.mcp
*
*****************************************************************************/

ssize_t sciNonBlockWrite( handle_t hndl, const void * pBuffer, size_t NBytes )
{   
    /*
        NBytes          - size in bytes
        pBuffer (R3)    - is a byte pointer     
    */

    asm(move.w   M01, B );  /* save modulo context in B */

#if __m56800E_lmm__ 
    asm(move.w A0,A);
    asm(move.w  A1,Y0);
#else
	asm(nop);
	asm(nop);
#endif
    asm(move.w      Y0, A);

    /* transferting size*/
    asm(move.l      X:(R2 + #(sSciDevice_offset_qSend + sQueue_offset_begin)) , Y); /* Y0 : = begin, Y1 := end */
    asm(move.w      X:(R2 + #(sSciDevice_offset_qSend + sQueue_offset_mask)) , X0); 
    asm(sub         Y0, Y1);
    asm(add         X0, Y1);    /* Y1 := size - 1 - (begin - end) */
    asm(inc.w       Y1);
    asm(cmp         Y1, A);
    asm(tgt         Y1, A);
    /* set up modulo  */
    asm(moveu.w     X0, M01); /* load queue size */
    /* setup buffer pointer */
    asm(and.w       Y0, X0);    /* B := moduled begin (Y0) */
    asm(add.w       X:(R2 + #(sSciDevice_offset_qSend + sQueue_offset_bufferOffset)),X0);
    asm(adda        #BASE_CIRCULAR_BUFFER_ADDRESS, X0, R0);
    
    /* transfert data from *pBuffer to *Queue.pBuffer */
    asm(do          A, end_transferting);
        asm(moveu.bp    X:(R3)+, X0);   /* R3 is a byte pointer */
        asm(nop);
        asm(nop);
        asm(move.w      X0, P:(R0)+);
    asm(end_transferting:);
    
    /* update queue pointers */
    asm(add         A, Y0);     /* update begin */
    asm(move.w      Y0, X:(R2+ #(sSciDevice_offset_qSend + sQueue_offset_begin)));  /* save begin iterator */
#if 1
    asm(moveu.w     X:(R2 + #sSciDevice_offset_Base), R4);  /* SCI base  */
#else
    asm(move.l      X:(R2 + #sSciDevice_offset_Base), R4);  /* SCI base  */
#endif  
    /* Enable Tx interrupt, adda        #BSP_PERIPH_OFF, R4 */
    asm(bfset       #SCI_SCICR_TEIE, X:(R4 + #(BSP_PERIPH_OFF + arch_sSCI_offset_ControlReg) ));

#if __m56800E_lmm__ 
    asm(move.w A1,A0);
    asm(clr.w  A1);
#else
    asm(move.w      A, Y0);
	asm(nop);
#endif

 
    asm(moveu.w  B, M01 );  /* restore modulo context */
    
    /* asm(rts); */
};

/*****************************************************************************
*
* Module:         sciBlockWrite()
*
* Description:    Write user buffer out of SCI device.
*
*                 In Blocking mode, "sciWrite" waits while all required data
*                 is transferred.
*
* Returns:        Actual number of bytes transmitted
*
* Arguments:      hndl     - SCI Device descriptor returned by "sciOpen" call.
*                 pBuffer  - Pointer to user buffer. 
*                 NBytes   - NBytes (in 8-bit bytes) of the data to be written
*                            out of SCI device; 
*
* Range Issues:   None
*
* Test Method:    sci.mcp
*
*****************************************************************************/

ssize_t sciBlockWrite( handle_t hndl , const void * pBuffer , size_t NBytes )
{
    struct  sSciDevice * pHandle = (struct sSciDevice *)hndl;
            ssize_t      n_bytes = NBytes;
            ssize_t      bytes;
   
    do
    {
        bytes   = sciNonBlockWrite(hndl , pBuffer , n_bytes);
        n_bytes -= bytes;
        pBuffer = (unsigned char * )pBuffer + bytes;
    } 
    while( n_bytes );

    return NBytes;
}

/*****************************************************************************
*  Some ioctl calls cancel current SCI driver operations.
*
*****************************************************************************/

/*****************************************************************************
*
* Module:         sciIoctlSCI_GET_COUNT_READ()
*
* Description:    return count of chars which can be read
*                 
* Returns:        count
*                 
* Arguments:      hndl - device context
*
* Range Issues:   None
*
* Test Method:    sci.mcp
*
*****************************************************************************/
unsigned int sciIoctlSCI_GET_COUNT_READ( handle_t hndl , unsigned long params )
{
    struct sSciDevice * pHandle = (struct sSciDevice *)hndl;

    return pHandle->qReceive.begin - pHandle->qReceive.end;
}

/*****************************************************************************
*
* Module:         sciIoctlSCI_GET_COUNT_WRITE()
*
* Description:    return count of chars which can be written
*                 
* Returns:        count
*                 
* Arguments:      hndl - device context
*
* Range Issues:   None
*
* Test Method:    sci.mcp
*
*****************************************************************************/
unsigned int sciIoctlSCI_GET_COUNT_WRITE( handle_t hndl , unsigned long params )
{
    struct sSciDevice * pHandle = (struct sSciDevice *)hndl;

    return pHandle->qSend.mask + 1 - (pHandle->qSend.begin - pHandle->qSend.end);
}

/*****************************************************************************
*
* Module:         sciIoctlSCI_GET_WRITE_BUFFER_SIZE()
*
* Description:    return write buffer size
*                 
* Returns:        count
*                 
* Arguments:      hndl - device context
*
* Range Issues:   None
*
* Test Method:    sci.mcp
*
*****************************************************************************/
unsigned int sciIoctlSCI_GET_WRITE_BUFFER_SIZE( handle_t hndl , unsigned long params )
{
    struct sSciDevice * pHandle = (struct sSciDevice *)hndl;

    return pHandle->qSend.mask + 1;
}

/*****************************************************************************
*
* Module:         sciIoctlSCI_GET_READ_BUFFER_SIZE()
*
* Description:    return write buffer size
*                 
* Returns:        count
*                 
* Arguments:      hndl - device context
*
* Range Issues:   None
*
* Test Method:    sci.mcp
*
*****************************************************************************/
unsigned int sciIoctlSCI_GET_READ_BUFFER_SIZE( handle_t hndl, unsigned long params )
{
    struct sSciDevice * pHandle = (struct sSciDevice *)hndl;

    return pHandle->qReceive.mask + 1;
}

/*****************************************************************************
*
* Module:         sciIoctlSCI_DEVICE_RESET()
*
* Description:    Reset SCI device and set new configuration. 
*                 
* Returns:        None
*                 
* Arguments:      hndl - device context
*
* Range Issues:   None
*
* Test Method:    sci.mcp
*
*****************************************************************************/
unsigned int sciIoctlSCI_DEVICE_RESET( handle_t hndl, unsigned long params )
{
   struct sSciDevice * pHandle = (struct sSciDevice *)hndl;

   sciIoctlSCI_DEVICE_OFF( hndl, NULL );
   sciIoctlSCI_DEVICE_ON( hndl, NULL );
}

/*****************************************************************************
*
* Module:         sciIoctlSCI_GET_STATUS()
*
* Description:    Read SCI device status               
*
* Returns:        device status
*
* Arguments:      hndl - device descriptor
*
* Range Issues:   None
*
* Test Method:    sci.mcp
*
*****************************************************************************/
unsigned int sciIoctlSCI_GET_STATUS( handle_t hndl, unsigned long params )
{
    struct  sSciDevice *   pHandle      = (struct sSciDevice *)hndl;
            unsigned int   ReturnValue  = 0;
            
    scidrvHWDisableRxInterrupts( pHandle->Base );
    
    ReturnValue = SCI_STATUS_EXCEPTION_EXIST | periphMemRead( &pHandle->Base->StatusReg ) &
                           (SCI_SCISR_OR | SCI_SCISR_NF | SCI_SCISR_FE | SCI_SCISR_PF);
    
    scidrvHWEnableRxInterrupts( pHandle->Base );
         

⌨️ 快捷键说明

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