コード例 #1
0
ファイル: spi_dspi.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION****************************************************************
*
* Function Name    : _dspi_isr
* Returned Value   : SPI interrupt routine
* Comments         :
*   State machine transferring data between buffers and DSPI FIFO.
*
*END*********************************************************************/
static void _dspi_isr
    (
        /* [IN] The address of the device specific information */
        void                          *parameter
    )
{
    DSPI_INFO_STRUCT_PTR               dspi_info_ptr = parameter;
    VDSPI_REG_STRUCT_PTR               dspi_ptr = dspi_info_ptr->DSPI_PTR;

    uint32_t                            data;

    /* drain RX FIFO */
    if (DSPI_CTAR_FMSZ_GET(dspi_ptr->CTAR[0]) > 7)
    {
        /* frame is larger than a single byte */
        while (dspi_ptr->SR & DSPI_SR_RFDF_MASK)
        {
            data = DSPI_POPR_RXDATA_GET(dspi_ptr->POPR);
            dspi_ptr->SR = DSPI_SR_RFDF_MASK;
            if (dspi_info_ptr->RX_LEN)
            {
                dspi_info_ptr->RX_LEN--;
                if (dspi_info_ptr->RX_BUF)
                {
                    dspi_info_ptr->RX_BUF[0] = data>>8;
                    dspi_info_ptr->RX_BUF[1] = data&0xff;
                    dspi_info_ptr->RX_BUF += 2;
                }
            }
        }
コード例 #2
0
ファイル: spi_pol_dspi.c プロジェクト: jewlenchow/MQX_3.8.1
/*FUNCTION****************************************************************
*
* Function Name    : _dspi_polled_tx_rx_master
* Returned Value   : number of frames transferred
* Comments         :
*   Actual transmit and receive function.
*   Overrun prevention used, no need to update statistics in this function
*
*END*********************************************************************/
static uint_32 _dspi_polled_tx_rx_master
    (
        /* [IN] Device specific context structure */
        DSPI_INFO_STRUCT_PTR         io_info_ptr,

        /* [IN] Data to transmit */
        uint_8_ptr                   output,

        /* [OUT] Received data */
        uint_8_ptr                   input,

        /* [IN] Length of transfer in bytes */
        uint_32                      len
    )
{
    VDSPI_REG_STRUCT_PTR             dspi_ptr = io_info_ptr->DSPI_PTR;

    uint_32                          out_len;
    uint_32                          in_len;
    uint_32                          frames;

    uint_32                          command;
    uint_32                          data;

    in_len = out_len = len;
    command = DSPI_PUSHR_CONT_MASK | DSPI_PUSHR_PCS(io_info_ptr->CS) | DSPI_PUSHR_CTAS(0);
    data = 0; /* dummy patern to send in rx only mode */

    /* Is frame larger than a single byte? */
    if (DSPI_CTAR_FMSZ_GET(dspi_ptr->CTAR[0]) > 7)
    {
        while (in_len)
        {
            if ((dspi_ptr->SR & DSPI_SR_TFFF_MASK) && ((in_len-out_len)<DSPI_POLLED_FIFO_DEPTH) && out_len)
            {
                if (output)
                    data = *output++;
                out_len--;
                if (out_len)
                {
                    if (output)
                        data = (data << 8) | *output++;
                    out_len--;
                }
                dspi_ptr->PUSHR = command | DSPI_PUSHR_TXDATA(data);
                dspi_ptr->SR |= DSPI_SR_TFFF_MASK;
            }

            if (dspi_ptr->SR & DSPI_SR_RFDF_MASK)
            {
                data = DSPI_POPR_RXDATA_GET(dspi_ptr->POPR);
                dspi_ptr->SR |= DSPI_SR_RFDF_MASK;
                if (input)
                    *input++ = data >> 8;
                in_len--;
                if (in_len)
                {
                    if (input)
                        *input++ = data & 0xff;
                    in_len--;
                }
            }
        }
        frames = (len+1)/2;
    }