Text Compare
Produced: 3/9/2012 11:38:28 AM
   
Mode:  All  
Left file: E:\Program Files\pspdrivers_01_30_01\packages\ti\pspiom\spi\src\Spi_edma.c  
Right file: E:\Program Files\Texas Instruments\raghav_psp_bios_1_30_dev_view\pspdrivers_\packages\ti\pspiom\spi\src\Spi_edma.c  
/* = /*
* Spi_edma.c   * Spi_edma.c
*   *
* This file contains local functions for the SPI driver which contain implemen-   * This file contains local functions for the SPI driver which contain implemen-
* tation for EDMA operation specifc calls like starting an EDMA transfer for   * tation for EDMA operation specifc calls like starting an EDMA transfer for
* for SPI peripheral, EDMA completion and/or error callbacks etc   * for SPI peripheral, EDMA completion and/or error callbacks etc
*   *
* Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/   * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
*   *
*   *
*  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions   *  modification, are permitted provided that the following conditions
*  are met:   *  are met:
*   *
*    Redistributions of source code must retain the above copyright   *    Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.   *    notice, this list of conditions and the following disclaimer.
*   *
*    Redistributions in binary form must reproduce the above copyright   *    Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
*    documentation and/or other materials provided with the   *    documentation and/or other materials provided with the
*    distribution.   *    distribution.
*   *
*    Neither the name of Texas Instruments Incorporated nor the names of   *    Neither the name of Texas Instruments Incorporated nor the names of
*    its contributors may be used to endorse or promote products derived   *    its contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.   *    from this software without specific prior written permission.
*   *
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT   *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR   *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT   *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,   *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY   *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE   *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*   *
*/   */
     
/**   /**
*  \file   Spi_edma.c   *  \file   Spi_edma.c
*   *
*  \brief  This files contains the edma functions required for the Spi driver   *  \brief  This files contains the edma functions required for the Spi driver
*          to function in the EDMA mode.   *          to function in the EDMA mode.
     
*   (C) Copyright 2008, Texas Instruments, Inc   *   (C) Copyright 2008, Texas Instruments, Inc
*   *
*/   */
     
/* ========================================================================== */   /* ========================================================================== */
/*                          INCLUDE FILES                                     */   /*                          INCLUDE FILES                                     */
/* ========================================================================== */   /* ========================================================================== */
     
#include <std.h>   #include <std.h>
#include <assert.h>   #include <assert.h>
#include <sys.h>   #include <sys.h>
#include <iom.h>   #include <iom.h>
#include <bcache.h>   #include <bcache.h>
#include <sem.h>   #include <sem.h>
     
#ifdef Spi_EDMA_ENABLE   #ifdef Spi_EDMA_ENABLE
     
#include <ti/sdo/edma3/drv/edma3_drv.h>   #include <ti/sdo/edma3/drv/edma3_drv.h>
#include <ti/pspiom/spi/Spi.h>   #include <ti/pspiom/spi/Spi.h>
#include <ti/pspiom/gpio/Gpio.h>   #include <ti/pspiom/gpio/Gpio.h>
#include "SpiLocal.h"   #include "SpiLocal.h"
     
/* ========================================================================== */   /* ========================================================================== */
/*                        LOCAL FUNCTION PROTOTYPES                           */   /*                        LOCAL FUNCTION PROTOTYPES                           */
/* ========================================================================== */   /* ========================================================================== */
     
static Void SpiUpdateError(Spi_ChanObj *chanHandle,Uint32 intStatus);   static Void SpiUpdateError(Spi_ChanObj *chanHandle,Uint32 intStatus);
     
/* ========================================================================== */   /* ========================================================================== */
/*                       GLOBAL MODULE STATE                                  */   /*                       GLOBAL MODULE STATE                                  */
/* ========================================================================== */   /* ========================================================================== */
     
/* ========================================================================== */   /* ========================================================================== */
/*                       FUNCTION DEFINITIONS                                 */   /*                       FUNCTION DEFINITIONS                                 */
/* ========================================================================== */   /* ========================================================================== */
     
/**   /**
*  \brief  This function initiates Edma mode of operation.SPI Edma Rx & Tx   *  \brief  This function initiates Edma mode of operation.SPI Edma Rx & Tx
*          channels are configured and spi Edma interrupt in enable here   *          channels are configured and spi Edma interrupt in enable here
*          to get Rx and Tx events.   *          to get Rx and Tx events.
*   *
*  \param  handle      [IN]   Handle of the SPI Driver Object   *  \param  handle      [IN]   Handle of the SPI Driver Object
*  \param  chipSelect  [IN]   chip seclect for the spi   *  \param  chipSelect  [IN]   chip seclect for the spi
*  \param  dataformat  [IN]   data format to be used for the transaction   *  \param  dataformat  [IN]   data format to be used for the transaction
*  \param  flags       [IN]   flags to be used for the transfer operation   *  \param  flags       [IN]   flags to be used for the transfer operation
*   *
*  \return          IOM_COMPLETED if successful<br>   *  \return          IOM_COMPLETED if successful<br>
*                   Suitable error code if failure   *                   Suitable error code if failure
*   *
*/   */
Int Spi_localEdmaTransfer(Spi_Object      *instHandle,   Int Spi_localEdmaTransfer(Spi_Object      *instHandle,
                          Spi_DataParam   *dataParam)                             Spi_DataParam   *dataParam)
{   {
    Uint32                spidat1      = 0;       Uint32                spidat1      = 0;
    Spi_ChanObj          *chanHandle   = NULL;       Spi_ChanObj          *chanHandle   = NULL;
    Uint32                acntFlag     = 1u;       Uint32                acntFlag     = 1u;
    volatile Uint16      *spiDat1Cfg   = NULL;       volatile Uint16      *spiDat1Cfg   = NULL;
    EDMA3_DRV_PaRAMRegs   paramSet     = {0,0,0,0,0,0,0,0,0,0,0,0};       EDMA3_DRV_PaRAMRegs   paramSet     = {0,0,0,0,0,0,0,0,0,0,0,0};
    Int32                 status       = IOM_COMPLETED;       Int32                 status       = IOM_COMPLETED;
     
    assert(NULL != instHandle);       assert(NULL != instHandle);
    assert(NULL != dataParam);       assert(NULL != dataParam);
    chanHandle = instHandle->currentActiveChannel;       chanHandle = instHandle->currentActiveChannel;
    assert(NULL != chanHandle);       assert(NULL != chanHandle);
     
    /* Activate the GPIO chip select here. However, if CSHOLD is not set, then*       /* Activate the GPIO chip select here. However, if CSHOLD is not set, then*
     * raise an error. The reason is, for word-by-word transfer, we cannot    *        * raise an error. The reason is, for word-by-word transfer, we cannot    *
     * control the CS, as the master who is doing the data transfer is EDMA   *        * control the CS, as the master who is doing the data transfer is EDMA   *
     * Controller. The SPI driver can only activate the CS at start of        *        * Controller. The SPI driver can only activate the CS at start of        *
     * transfer (EDMA start) and at the end of the transfer (EDMA end - in the*        * transfer (EDMA start) and at the end of the transfer (EDMA end - in the*
     * callback)                                                              */        * callback)                                                              */
    if ((Spi_CSHOLD != (dataParam->flags & Spi_CSHOLD))       if ((Spi_CSHOLD != (dataParam->flags & Spi_CSHOLD))
       && (Spi_GPIO_CS == (dataParam->flags & Spi_GPIO_CS)))          && (Spi_GPIO_CS == (dataParam->flags & Spi_GPIO_CS)))
    {       {
        status = IOM_EBADARGS;           status = IOM_EBADARGS;
    }       }
         
    if (IOM_COMPLETED == status)       if (IOM_COMPLETED == status)
    {       {
        /* Extract data control param values to upload to SPIDAT1                 *           /* Extract data control param values to upload to SPIDAT1                 *
         * before read/write transfer starts                                      */            * before read/write transfer starts                                      */
        spidat1 = Spi_localControlDataConfig(           spidat1 = Spi_localControlDataConfig(
                      chanHandle,                         chanHandle,
                      dataParam->chipSelect,                         dataParam->chipSelect,
                      dataParam->dataFormat,                         dataParam->dataFormat,
                      dataParam->gpioPinNum,                         dataParam->gpioPinNum,
                      dataParam->flags);                         dataParam->flags);
                 
        spiDat1Cfg = (((volatile Uint16 *)           spiDat1Cfg = (((volatile Uint16 *)
                           (&(instHandle->deviceInfo.baseAddress)->SPIDAT1))+1);                              (&(instHandle->deviceInfo.baseAddress)->SPIDAT1))+1);
        assert(NULL != spiDat1Cfg);           assert(NULL != spiDat1Cfg);
     
        /* write the upper 16 bits which contain the configurations to the SPIDAT1*           /* write the upper 16 bits which contain the configurations to the SPIDAT1*
         * upper 16bits                                                           */            * upper 16bits                                                           */
        *spiDat1Cfg = (Uint16)(spidat1 >> 16);           *spiDat1Cfg = (Uint16)(spidat1 >> 16);
    }       }
     
    /* clear if any pending events in the EDMA event register for this channel*/       /* clear if any pending events in the EDMA event register for this channel*/
    if (IOM_COMPLETED == status)       if (IOM_COMPLETED == status)
    {       {
        status = EDMA3_DRV_clearErrorBits(           status = EDMA3_DRV_clearErrorBits(
                      instHandle->hEdma,                         instHandle->hEdma,
                      instHandle->deviceInfo.txDmaEventNumber);                         instHandle->deviceInfo.txDmaEventNumber);
    }       }
     
    if (IOM_COMPLETED == status)       if (IOM_COMPLETED == status)
    {       {
        /* read and remove the stale data                                     */           /* read and remove the stale data                                     */
        while (CSL_SPI_SPIBUF_RXEMPTY_MASK           while (CSL_SPI_SPIBUF_RXEMPTY_MASK
            != ((instHandle->deviceInfo.baseAddress)->SPIBUF               != ((instHandle->deviceInfo.baseAddress)->SPIBUF
                & CSL_SPI_SPIBUF_RXEMPTY_MASK))                   & CSL_SPI_SPIBUF_RXEMPTY_MASK))
        {           {
            (*chanHandle->rxBuffer) =               (*chanHandle->rxBuffer) =
                (Uint8)(instHandle->deviceInfo.baseAddress)->SPIBUF;                   (Uint8)(instHandle->deviceInfo.baseAddress)->SPIBUF;
        }           }
     
        /* check the number of bytes to be transferred per sync event         */           /* check the number of bytes to be transferred per sync event         */
        if (TRUE == chanHandle->charLength16Bits)           if (TRUE == chanHandle->charLength16Bits)
        {           {
            acntFlag = 2u;               acntFlag = 2u;
        }           }
        else           else
        {           {
            acntFlag = 1u;               acntFlag = 1u;
        }           }
     
        if ((TRUE == chanHandle->rxBufFlag) && (TRUE == instHandle->enableCache))           if ((TRUE == chanHandle->rxBufFlag) && (TRUE == instHandle->enableCache))
        {           {
            BCACHE_wbInv((Ptr)chanHandle->rxBuffer,chanHandle->rxBufferLen,TRUE);                      BCACHE_wbInv((Ptr)chanHandle->rxBuffer,chanHandle->rxBufferLen,TRUE);       
        }           }
     
        /* Get the paramset for the receive channel and then update with the  *           /* Get the paramset for the receive channel and then update with the  *
         * transfer parameters                                                */            * transfer parameters                                                */
        /* Get the PaRAM set for default parameters                           */           /* Get the PaRAM set for default parameters                           */
        EDMA3_DRV_getPaRAM (           EDMA3_DRV_getPaRAM (
            instHandle->hEdma,               instHandle->hEdma,
            instHandle->deviceInfo.rxDmaEventNumber,               instHandle->deviceInfo.rxDmaEventNumber,
            &paramSet);               &paramSet);
     
        /* configure the source and destination address                       */           /* configure the source and destination address                       */
        paramSet.srcAddr = (Uint32)(&((instHandle->deviceInfo.baseAddress)->SPIBUF));           paramSet.srcAddr = (Uint32)(&((instHandle->deviceInfo.baseAddress)->SPIBUF));
        paramSet.destAddr = (Uint32)(chanHandle->rxBuffer);           paramSet.destAddr = (Uint32)(chanHandle->rxBuffer);
     
        /* configure the source and destination indexes                       */           /* configure the source and destination indexes                       */
        paramSet.srcBIdx  = 0;           paramSet.srcBIdx  = 0;
        paramSet.srcCIdx  = 0;           paramSet.srcCIdx  = 0;
        paramSet.destCIdx = 0;           paramSet.destCIdx = 0;
     
        /* dont increment the address in case the buffer is not  user supplied*           /* dont increment the address in case the buffer is not  user supplied*
         * buffer.                                                            */            * buffer.                                                            */
        if (FALSE == chanHandle->rxBufFlag)           if (FALSE == chanHandle->rxBufFlag)
        {           {
            paramSet.destBIdx = 0;               paramSet.destBIdx = 0;
        }           }
        else           else
        {           {
            paramSet.destBIdx = 1; <>             paramSet.destBIdx = acntFlag;
        } =         }
     
        /* Configuring aCnt, bCnt, cCnt and bCntReload                        */           /* Configuring aCnt, bCnt, cCnt and bCntReload                        */
        if ((acntFlag > 0xFFFFu ) || (chanHandle->rxBufferLen > 0xFFFF ))           if ((acntFlag > 0xFFFFu ) || (chanHandle->rxBufferLen > 0xFFFF ))
        {           {
            status = IOM_EBADIO;               status = IOM_EBADIO;
        }           }
        else           else
        {           {
            paramSet.aCnt = (unsigned short)acntFlag;               paramSet.aCnt = (unsigned short)acntFlag;
            paramSet.bCnt = (unsigned short)chanHandle->rxBufferLen; <>             paramSet.bCnt = ((unsigned short)chanHandle->rxBufferLen)/acntFlag;
        } =         }
               
        paramSet.cCnt       = (Uint16)1;           paramSet.cCnt       = (Uint16)1;
        paramSet.bCntReload = 0;           paramSet.bCntReload = 0;
     
        /* configure the OPT field of the EDMA paramset                       */           /* configure the OPT field of the EDMA paramset                       */
        /* Linking is disabled                                                */           /* Linking is disabled                                                */
        paramSet.linkAddr   = 0xFFFFu;           paramSet.linkAddr   = 0xFFFFu;
     
        /* Src & Dest are in INCR modes                                       */           /* Src & Dest are in INCR modes                                       */
        paramSet.opt &= 0xFFFFFFFCu;           paramSet.opt &= 0xFFFFFFFCu;
     
        /* FIFO width is 8 bit                                                */           /* FIFO width is 8 bit                                                */
        paramSet.opt &= 0xFFFFF8FFu;           paramSet.opt &= 0xFFFFF8FFu;
     
        /* EDMA3_DRV_SYNC_A                                                   */           /* EDMA3_DRV_SYNC_A                                                   */
        paramSet.opt &= 0xFFFFFFFBu;           paramSet.opt &= 0xFFFFFFFBu;
     
        /* EDMA3_DRV_OPT_FIELD_TCINTEN                                        */           /* EDMA3_DRV_OPT_FIELD_TCINTEN                                        */
        paramSet.opt |= (1 << Spi_OPT_TCINTEN_SHIFT);           paramSet.opt |= (1 << Spi_OPT_TCINTEN_SHIFT);
     
        /* update the paramset with the new values                            */           /* update the paramset with the new values                            */
        if (IOM_COMPLETED == status)           if (IOM_COMPLETED == status)
        {           {
            /* Now, write the PaRAM Set.                                      */               /* Now, write the PaRAM Set.                                      */
            status = EDMA3_DRV_setPaRAM(               status = EDMA3_DRV_setPaRAM(
                         instHandle->hEdma,                            instHandle->hEdma,
                         instHandle->deviceInfo.rxDmaEventNumber,                            instHandle->deviceInfo.rxDmaEventNumber,
                         &paramSet);                            &paramSet);
        }           }
     
        /* enable the transfer                                                */           /* enable the transfer                                                */
        if (IOM_COMPLETED != status)           if (IOM_COMPLETED != status)
        {           {
            SYS_printf("\nSPI Test: EDMA Param Setting failed" );               SYS_printf("\nSPI Test: EDMA Param Setting failed" );
        }           }
        else           else
        {           {
            status = EDMA3_DRV_enableTransfer(               status = EDMA3_DRV_enableTransfer(
                        instHandle->hEdma,                           instHandle->hEdma,
                        instHandle->deviceInfo.rxDmaEventNumber,                           instHandle->deviceInfo.rxDmaEventNumber,
                        EDMA3_DRV_TRIG_MODE_EVENT);                           EDMA3_DRV_TRIG_MODE_EVENT);
        }           }
     
        if (IOM_COMPLETED != status)           if (IOM_COMPLETED != status)
        {           {
            SYS_printf("\nSPI Test: EDMA Transfer Enable failed" );               SYS_printf("\nSPI Test: EDMA Transfer Enable failed" );
        }           }
     
     
        /* now update the paramset for the TX transfer channel                */           /* now update the paramset for the TX transfer channel                */
        if ((TRUE == chanHandle->txBufFlag) && (TRUE == instHandle->enableCache))           if ((TRUE == chanHandle->txBufFlag) && (TRUE == instHandle->enableCache))
        {           {
            /* Write intialization for DMA mode                               */               /* Write intialization for DMA mode                               */
            BCACHE_wbInv((Ptr)chanHandle->txBuffer,chanHandle->txBufferLen,TRUE);               BCACHE_wbInv((Ptr)chanHandle->txBuffer,chanHandle->txBufferLen,TRUE);
        }           }
     
        /* Get the PaRAM set for default parameters                           */           /* Get the PaRAM set for default parameters                           */
        EDMA3_DRV_getPaRAM (instHandle->hEdma,           EDMA3_DRV_getPaRAM (instHandle->hEdma,
             instHandle->deviceInfo.txDmaEventNumber,                instHandle->deviceInfo.txDmaEventNumber,
             &paramSet);                &paramSet);
     
        /* configure the source and destination address                       */           /* configure the source and destination address                       */
        paramSet.srcAddr = (Uint32)(chanHandle->txBuffer);           paramSet.srcAddr = (Uint32)(chanHandle->txBuffer);
        paramSet.destAddr = (Uint32)(&((instHandle->deviceInfo.baseAddress)->SPIDAT1));           paramSet.destAddr = (Uint32)(&((instHandle->deviceInfo.baseAddress)->SPIDAT1));
     
        /* configure the source and destination indexes                       */           /* configure the source and destination indexes                       */
        if (TRUE == chanHandle->txBufFlag)           if (TRUE == chanHandle->txBufFlag)
        {           {
            paramSet.srcBIdx = 1; <>             paramSet.srcBIdx = acntFlag;
        } =         }
        else           else
        {           {
            paramSet.srcBIdx = 0;               paramSet.srcBIdx = 0;
        }           }
        paramSet.srcCIdx   = 0;           paramSet.srcCIdx   = 0;
        paramSet.destBIdx  = 0;           paramSet.destBIdx  = 0;
        paramSet.destCIdx  = 0;           paramSet.destCIdx  = 0;
     
        /* Configuring aCnt, bCnt, cCnt and bCntReload                        */           /* Configuring aCnt, bCnt, cCnt and bCntReload                        */
        if ((acntFlag > 0xFFFFu ) || (chanHandle->txBufferLen> 0xFFFFu))           if ((acntFlag > 0xFFFFu ) || (chanHandle->txBufferLen> 0xFFFFu))
        {           {
            status = IOM_EBADIO;               status = IOM_EBADIO;
        }           }
        else           else
        {           {
            paramSet.aCnt = (Uint16)acntFlag;               paramSet.aCnt = (Uint16)acntFlag;
            paramSet.bCnt = (Uint16)chanHandle->txBufferLen; <>             paramSet.bCnt = ((Uint16)chanHandle->txBufferLen)/acntFlag;
        } =         }
     
        paramSet.cCnt       = (Uint16)1;           paramSet.cCnt       = (Uint16)1;
        paramSet.bCntReload = 0;           paramSet.bCntReload = 0;
     
        /* Linking is disable                                                 */           /* Linking is disable                                                 */
        paramSet.linkAddr   = 0xFFFFu;           paramSet.linkAddr   = 0xFFFFu;
     
        /* Src & Dest are in INCR modes                                       */           /* Src & Dest are in INCR modes                                       */
        paramSet.opt &= 0xFFFFFFFCu;           paramSet.opt &= 0xFFFFFFFCu;
     
        /* FIFO width is 8 bit                                                */           /* FIFO width is 8 bit                                                */
        paramSet.opt &= 0xFFFFF8FFu;           paramSet.opt &= 0xFFFFF8FFu;
     
        /* EDMA3_DRV_SYNC_A                                                   */           /* EDMA3_DRV_SYNC_A                                                   */
        paramSet.opt &= 0xFFFFFFFBu;           paramSet.opt &= 0xFFFFFFFBu;
     
        /* EDMA3_DRV_OPT_FIELD_TCINTEN                                        */           /* EDMA3_DRV_OPT_FIELD_TCINTEN                                        */
        paramSet.opt |= (1 << Spi_OPT_TCINTEN_SHIFT);           paramSet.opt |= (1 << Spi_OPT_TCINTEN_SHIFT);
     
        if (IOM_COMPLETED == status)           if (IOM_COMPLETED == status)
        {           {
            /* Now, write the PaRAM Set.                                      */               /* Now, write the PaRAM Set.                                      */
            status = EDMA3_DRV_setPaRAM(instHandle->hEdma,               status = EDMA3_DRV_setPaRAM(instHandle->hEdma,
                         instHandle->deviceInfo.txDmaEventNumber,                            instHandle->deviceInfo.txDmaEventNumber,
                         &paramSet);                            &paramSet);
        }           }
     
        /* Shall handle only overrun in the interrupt handler                 */           /* Shall handle only overrun in the interrupt handler                 */
        (instHandle->deviceInfo.baseAddress)->SPIINT0 |=           (instHandle->deviceInfo.baseAddress)->SPIINT0 |=
                 CSL_SPI_SPIINT0_OVRNINTENA_MASK;                    CSL_SPI_SPIINT0_OVRNINTENA_MASK;
     
        if (IOM_COMPLETED != status)           if (IOM_COMPLETED != status)
        {           {
            SYS_printf("SPI Test: EDMA Param Setting failed\n");               SYS_printf("SPI Test: EDMA Param Setting failed\n");
        }           }
        else           else
        {           {
            Spi_localGpioPinToggle(chanHandle, Spi_LOW);               Spi_localGpioPinToggle(chanHandle, Spi_LOW);
                         
            /* Provide delay between CS active and actual IO               /* Provide delay between CS active and actual IO
               as desired by the used   */                  as desired by the used   */
            if(Spi_GPIO_CS == (dataParam->flags & Spi_GPIO_CS))               if(Spi_GPIO_CS == (dataParam->flags & Spi_GPIO_CS))
            {               {
                Spi_localgenericDelay(dataParam->csToTxDelay);                                              Spi_localgenericDelay(dataParam->csToTxDelay);                           
            }               }
                 
            EDMA3_DRV_enableTransfer(               EDMA3_DRV_enableTransfer(
                (instHandle->hEdma),                   (instHandle->hEdma),
                instHandle->deviceInfo.txDmaEventNumber,                   instHandle->deviceInfo.txDmaEventNumber,
                EDMA3_DRV_TRIG_MODE_EVENT);                   EDMA3_DRV_TRIG_MODE_EVENT);
        }           }
     
        if (IOM_COMPLETED != status)           if (IOM_COMPLETED != status)
        {           {
            SYS_printf("SPI Test: EDMA Transfer Enable failed\n");               SYS_printf("SPI Test: EDMA Transfer Enable failed\n");
        }           }
     
        /* Enable SPI for transaction                                         */           /* Enable SPI for transaction                                         */
        (instHandle->deviceInfo.baseAddress)->SPIGCR1 |=           (instHandle->deviceInfo.baseAddress)->SPIGCR1 |=
            (((Uint32)CSL_SPI_SPIGCR1_ENABLE_ENABLE)               (((Uint32)CSL_SPI_SPIGCR1_ENABLE_ENABLE)
                << ((Uint32)CSL_SPI_SPIGCR1_ENABLE_SHIFT));                   << ((Uint32)CSL_SPI_SPIGCR1_ENABLE_SHIFT));
                 
        (instHandle->deviceInfo.baseAddress)->SPIINT0 |=           (instHandle->deviceInfo.baseAddress)->SPIINT0 |=
           (CSL_SPI_SPIINT0_DMAREQEN_ENABLE              (CSL_SPI_SPIINT0_DMAREQEN_ENABLE
            << CSL_SPI_SPIINT0_DMAREQEN_SHIFT);               << CSL_SPI_SPIINT0_DMAREQEN_SHIFT);
     
    }       }
     
    /* return the function return code                                        */       /* return the function return code                                        */
    return (status) ;       return (status) ;
}   }
     
/**   /**
*  \brief  This function is called in response to the completion of transmit.   *  \brief  This function is called in response to the completion of transmit.
*          This is the Callback for the EDMA transmit completion event.   *          This is the Callback for the EDMA transmit completion event.
*          Tx channel transfer for Edma is disable done here.   *          Tx channel transfer for Edma is disable done here.
*   *
*  \param  tcc         [IN]   Transmit interrupt event channel   *  \param  tcc         [IN]   Transmit interrupt event channel
*  \param  edmaStatus  [IN]   Transfer status whether transfer completed or not   *  \param  edmaStatus  [IN]   Transfer status whether transfer completed or not
*  \param  appData     [IN]   Data passed Edma during initiation   *  \param  appData     [IN]   Data passed Edma during initiation
*   *
*/   */
Void Spi_localCallbackTransmit(Uns                tcc,   Void Spi_localCallbackTransmit(Uns                tcc,
                               EDMA3_RM_TccStatus edmaStatus,                                  EDMA3_RM_TccStatus edmaStatus,
                               Ptr                appData)                                  Ptr                appData)
{   {
    Spi_Object            *instHandle    = NULL;       Spi_Object            *instHandle    = NULL;
    Spi_ChanObj           *chanHandle    = NULL;       Spi_ChanObj           *chanHandle    = NULL;
    Uns                    ch_Tx         = tcc;       Uns                    ch_Tx         = tcc;
    Uint32                 intStatus     = 0x00;       Uint32                 intStatus     = 0x00;
     
    assert(NULL != appData);       assert(NULL != appData);
    instHandle = (Spi_Object *)appData;       instHandle = (Spi_Object *)appData;
    assert(NULL != instHandle);       assert(NULL != instHandle);
    chanHandle = instHandle->currentActiveChannel;       chanHandle = instHandle->currentActiveChannel;
     
    if(NULL != chanHandle)       if(NULL != chanHandle)
    {       {
     
        /* Disable edma transfer                                              */           /* Disable edma transfer                                              */
        EDMA3_DRV_disableLogicalChannel(           EDMA3_DRV_disableLogicalChannel(
            instHandle->hEdma,               instHandle->hEdma,
            ch_Tx,               ch_Tx,
            EDMA3_DRV_TRIG_MODE_EVENT);               EDMA3_DRV_TRIG_MODE_EVENT);
                 
        EDMA3_DRV_setOptField(           EDMA3_DRV_setOptField(
            instHandle->hEdma,               instHandle->hEdma,
            ch_Tx,               ch_Tx,
            EDMA3_DRV_OPT_FIELD_TCC,               EDMA3_DRV_OPT_FIELD_TCC,
            ch_Tx);               ch_Tx);
                 
        if (Spi_RX_EDMA_CALLBACK_OCCURED == instHandle->edmaCbCheck)           if (Spi_RX_EDMA_CALLBACK_OCCURED == instHandle->edmaCbCheck)
        {           {
            intStatus = (instHandle->deviceInfo.baseAddress)->SPIFLG;               intStatus = (instHandle->deviceInfo.baseAddress)->SPIFLG;
            SpiUpdateError(chanHandle,intStatus);               SpiUpdateError(chanHandle,intStatus);
                 
            (instHandle->deviceInfo.baseAddress)->SPIINT0 &=               (instHandle->deviceInfo.baseAddress)->SPIINT0 &=
                (CSL_SPI_SPIINT0_DMAREQEN_DISABLE                   (CSL_SPI_SPIINT0_DMAREQEN_DISABLE
                << CSL_SPI_SPIINT0_DMAREQEN_SHIFT);                   << CSL_SPI_SPIINT0_DMAREQEN_SHIFT);
                 
            /* Disable the spi enable pin                                     */               /* Disable the spi enable pin                                     */
            (instHandle->deviceInfo.baseAddress)->SPIGCR1 &=               (instHandle->deviceInfo.baseAddress)->SPIGCR1 &=
                (~(CSL_SPI_SPIGCR1_ENABLE_MASK));                   (~(CSL_SPI_SPIGCR1_ENABLE_MASK));
                                         
            instHandle->edmaCbCheck = 0x0;               instHandle->edmaCbCheck = 0x0;
                 
            if(NULL != chanHandle->activeIOP)               if(NULL != chanHandle->activeIOP)
            {               {
                if(EDMA3_RM_XFER_COMPLETE != edmaStatus)                   if(EDMA3_RM_XFER_COMPLETE != edmaStatus)
                {                   {
                    /* Ensure to clear the error bits of EDMA channel         */                       /* Ensure to clear the error bits of EDMA channel         */
                    EDMA3_DRV_clearErrorBits(instHandle->hEdma, ch_Tx);                       EDMA3_DRV_clearErrorBits(instHandle->hEdma, ch_Tx);
                    chanHandle->activeIOP->status = (Int32)edmaStatus;                       chanHandle->activeIOP->status = (Int32)edmaStatus;
                    instHandle->stats.txBytes += chanHandle->activeIOP->size;                       instHandle->stats.txBytes += chanHandle->activeIOP->size;
                }                   }
                /* The CS sould be deactivated here - this is where EDMA      *                   /* The CS sould be deactivated here - this is where EDMA      *
                * notifies of the transfer completion                         */                   * notifies of the transfer completion                         */
                Spi_localGpioPinToggle(chanHandle, Spi_HIGH);                                  Spi_localGpioPinToggle(chanHandle, Spi_HIGH);               
                spi_localCompleteIOedmaCallback(instHandle);                   spi_localCompleteIOedmaCallback(instHandle);
            }               }
        }           }
        else           else
        {           {
            if((EDMA3_RM_XFER_COMPLETE == edmaStatus)&&               if((EDMA3_RM_XFER_COMPLETE == edmaStatus)&&
               (NULL != chanHandle) &&                  (NULL != chanHandle) &&
               (NULL != chanHandle->activeIOP))                  (NULL != chanHandle->activeIOP))
            {               {
                instHandle->edmaCbCheck = Spi_TX_EDMA_CALLBACK_OCCURED;                   instHandle->edmaCbCheck = Spi_TX_EDMA_CALLBACK_OCCURED;
            }               }
        }           }
    }       }
}   }
     
/**   /**
*  \brief  This function is called in response to the completion of receive.   *  \brief  This function is called in response to the completion of receive.
*          This is the Callback for the EDMA receive completion event.   *          This is the Callback for the EDMA receive completion event.
*          Rx channel transfer for Edma is disable done here.   *          Rx channel transfer for Edma is disable done here.
*   *
*  \param  tcc         [IN]    receive interrupt event channel   *  \param  tcc         [IN]    receive interrupt event channel
*  \param  edmaStatus  [IN]    receive status whether transfer completed or not   *  \param  edmaStatus  [IN]    receive status whether transfer completed or not
*  \param  appData     [IN]    Data passed Edma during initiation   *  \param  appData     [IN]    Data passed Edma during initiation
*   *
*/   */
Void Spi_localCallbackReceive(Uns                tcc,   Void Spi_localCallbackReceive(Uns                tcc,
                               EDMA3_RM_TccStatus edmaStatus,                                  EDMA3_RM_TccStatus edmaStatus,
                               Ptr                appData)                                  Ptr                appData)
{   {
    Spi_Object            *instHandle  = NULL;       Spi_Object            *instHandle  = NULL;
    Spi_ChanObj           *chanHandle  = NULL;       Spi_ChanObj           *chanHandle  = NULL;
    Uns                    chan_Rx     = tcc;       Uns                    chan_Rx     = tcc;
    Uint32                 intStatus   = 0x00;       Uint32                 intStatus   = 0x00;
     
    assert(NULL != appData);       assert(NULL != appData);
    instHandle =  (Spi_Object *)appData;       instHandle =  (Spi_Object *)appData;
    assert(NULL != instHandle);       assert(NULL != instHandle);
    chanHandle = instHandle->currentActiveChannel;       chanHandle = instHandle->currentActiveChannel;
         
    if(NULL != chanHandle)       if(NULL != chanHandle)
    {       {
     
        EDMA3_DRV_disableLogicalChannel(           EDMA3_DRV_disableLogicalChannel(
            instHandle->hEdma,               instHandle->hEdma,
            chan_Rx,               chan_Rx,
            EDMA3_DRV_TRIG_MODE_EVENT);               EDMA3_DRV_TRIG_MODE_EVENT);
                 
        EDMA3_DRV_setOptField (           EDMA3_DRV_setOptField (
            (instHandle->hEdma),               (instHandle->hEdma),
            chan_Rx,               chan_Rx,
            EDMA3_DRV_OPT_FIELD_TCC,               EDMA3_DRV_OPT_FIELD_TCC,
            chan_Rx);               chan_Rx);
                 
        if (EDMA3_RM_XFER_COMPLETE != edmaStatus)           if (EDMA3_RM_XFER_COMPLETE != edmaStatus)
        {           {
            /* Ensure to clear the error bits of EDMA channel                 */               /* Ensure to clear the error bits of EDMA channel                 */
            EDMA3_DRV_clearErrorBits(instHandle->hEdma, chan_Rx);               EDMA3_DRV_clearErrorBits(instHandle->hEdma, chan_Rx);
        }           }
                 
        if (Spi_TX_EDMA_CALLBACK_OCCURED == instHandle->edmaCbCheck)           if (Spi_TX_EDMA_CALLBACK_OCCURED == instHandle->edmaCbCheck)
        {           {
            intStatus = (instHandle->deviceInfo.baseAddress)->SPIFLG;               intStatus = (instHandle->deviceInfo.baseAddress)->SPIFLG;
     
            SpiUpdateError(chanHandle,intStatus);               SpiUpdateError(chanHandle,intStatus);
     
            (instHandle->deviceInfo.baseAddress)->SPIINT0 &=               (instHandle->deviceInfo.baseAddress)->SPIINT0 &=
                (CSL_SPI_SPIINT0_DMAREQEN_DISABLE                   (CSL_SPI_SPIINT0_DMAREQEN_DISABLE
                 << CSL_SPI_SPIINT0_DMAREQEN_SHIFT);                    << CSL_SPI_SPIINT0_DMAREQEN_SHIFT);
                 
            /* Disable the spi enable pin                                     */               /* Disable the spi enable pin                                     */
            (instHandle->deviceInfo.baseAddress)->SPIGCR1 &=               (instHandle->deviceInfo.baseAddress)->SPIGCR1 &=
                (~(CSL_SPI_SPIGCR1_ENABLE_MASK));                   (~(CSL_SPI_SPIGCR1_ENABLE_MASK));
                                         
            instHandle->edmaCbCheck = 0x0;               instHandle->edmaCbCheck = 0x0;
                 
            if(NULL != chanHandle->activeIOP)               if(NULL != chanHandle->activeIOP)
            {               {
                if(EDMA3_RM_XFER_COMPLETE != edmaStatus)                   if(EDMA3_RM_XFER_COMPLETE != edmaStatus)
                {                   {
                    chanHandle->activeIOP->status = (Int32)edmaStatus;                       chanHandle->activeIOP->status = (Int32)edmaStatus;
                    instHandle->stats.rxBytes += chanHandle->activeIOP->size;                       instHandle->stats.rxBytes += chanHandle->activeIOP->size;
                }                   }
                /* The CS sould be deactivated here - this is where EDMA      *                   /* The CS sould be deactivated here - this is where EDMA      *
                * notifies of the transfer completion                         */                   * notifies of the transfer completion                         */
                Spi_localGpioPinToggle(chanHandle, Spi_HIGH);                              Spi_localGpioPinToggle(chanHandle, Spi_HIGH);           
                spi_localCompleteIOedmaCallback(instHandle);                   spi_localCompleteIOedmaCallback(instHandle);
            }               }
        }           }
        else           else
        {           {
            if((EDMA3_RM_XFER_COMPLETE == edmaStatus)&&               if((EDMA3_RM_XFER_COMPLETE == edmaStatus)&&
               (NULL != chanHandle) &&                  (NULL != chanHandle) &&
               (NULL != chanHandle->activeIOP))                  (NULL != chanHandle->activeIOP))
            {                      {       
                instHandle->edmaCbCheck = Spi_RX_EDMA_CALLBACK_OCCURED;                   instHandle->edmaCbCheck = Spi_RX_EDMA_CALLBACK_OCCURED;
            }               }
        }           }
    }       }
}   }
     
/**   /**
*  \brief Function used after edma callback   *  \brief Function used after edma callback
*   *
*  This function will be called after the completion of edma callback. This   *  This function will be called after the completion of edma callback. This
*  function requests the next channel and also calls the app callback function.   *  function requests the next channel and also calls the app callback function.
*   *
*  \param   instHandle  [IN]   Pointer to the spi driver instance object   *  \param   instHandle  [IN]   Pointer to the spi driver instance object
*   *
*  \return  None   *  \return  None
*   *
*  \enter  instHandle must be a valid pointer and should not be null.   *  \enter  instHandle must be a valid pointer and should not be null.
*   *
*  \leave  Not Implemented.   *  \leave  Not Implemented.
*/   */
void spi_localCompleteIOedmaCallback (Spi_Object *instHandle)   void spi_localCompleteIOedmaCallback (Spi_Object *instHandle)
{   {
    volatile Uint8     *spiDat1    = NULL;       volatile Uint8     *spiDat1    = NULL;
    Spi_ChanObj        *chanHandle = NULL;       Spi_ChanObj        *chanHandle = NULL;
    Spi_DataParam      *dataParam  = NULL;       Spi_DataParam      *dataParam  = NULL;
    IOM_Packet         *ioPacket   = NULL;       IOM_Packet         *ioPacket   = NULL;
    EDMA3_DRV_PaRAMRegs paramSet   = {0};       EDMA3_DRV_PaRAMRegs paramSet   = {0};
    Uint32              edmaNum    = 0x00;       Uint32              edmaNum    = 0x00;
#ifdef BIOS_PWRM_ENABLE   #ifdef BIOS_PWRM_ENABLE
    PWRM_Status         status     = PWRM_SOK;       PWRM_Status         status     = PWRM_SOK;
    Uint32              count      = 0x00;       Uint32              count      = 0x00;
#endif   #endif
    Int32               retVal     = IOM_COMPLETED;       Int32               retVal     = IOM_COMPLETED;
     
    assert(NULL != instHandle);       assert(NULL != instHandle);
     
    chanHandle = instHandle->currentActiveChannel;       chanHandle = instHandle->currentActiveChannel;
    assert(NULL != chanHandle);       assert(NULL != chanHandle);
    ioPacket = chanHandle->activeIOP;       ioPacket = chanHandle->activeIOP;
    dataParam  = (Spi_DataParam *)chanHandle->activeIOP->addr;       dataParam  = (Spi_DataParam *)chanHandle->activeIOP->addr;
    assert(NULL != dataParam);       assert(NULL != dataParam);
     
    /* check if CSHOLD needs to be enable after the transmission also.        *       /* check if CSHOLD needs to be enable after the transmission also.        *
     * If No or if there is any eror disable CSHOLD value, else do nothing    */        * If No or if there is any eror disable CSHOLD value, else do nothing    */
    if ((dataParam->flags & Spi_CSHOLD_FOR_MULTI_TRANSCEIVE) !=       if ((dataParam->flags & Spi_CSHOLD_FOR_MULTI_TRANSCEIVE) !=
        Spi_CSHOLD_FOR_MULTI_TRANSCEIVE)           Spi_CSHOLD_FOR_MULTI_TRANSCEIVE)
    {       {
        /* Pointing to the MSByte of SPIDAT1 to reset CSHOLD bit              */           /* Pointing to the MSByte of SPIDAT1 to reset CSHOLD bit              */
        spiDat1 =           spiDat1 =
            ((volatile Uint8*)&((instHandle->deviceInfo.baseAddress)->SPIDAT1))+3u;               ((volatile Uint8*)&((instHandle->deviceInfo.baseAddress)->SPIDAT1))+3u;
                         
        assert(NULL != spiDat1);           assert(NULL != spiDat1);
     
        *spiDat1 &= ~(Spi_SPIDAT1_CSHOLD_8BIT_MASK);           *spiDat1 &= ~(Spi_SPIDAT1_CSHOLD_8BIT_MASK);
    }       }
     
    /* Mask off interrupts                                                    */       /* Mask off interrupts                                                    */
    (instHandle->deviceInfo.baseAddress)->SPIINT0 &=       (instHandle->deviceInfo.baseAddress)->SPIINT0 &=
         (~(Spi_INTERRUPT_MASK));            (~(Spi_INTERRUPT_MASK));
     
    /* Update size parameters of the IOP                                      */       /* Update size parameters of the IOP                                      */
    if (TRUE == chanHandle->txBufFlag)       if (TRUE == chanHandle->txBufFlag)
    {       {
        edmaNum = instHandle->deviceInfo.txDmaEventNumber;           edmaNum = instHandle->deviceInfo.txDmaEventNumber;
    }       }
    else       else
    {       {
        edmaNum = instHandle->deviceInfo.rxDmaEventNumber;           edmaNum = instHandle->deviceInfo.rxDmaEventNumber;
    }       }
         
    /* check how many bytes were transferred before the EDMA was stopped      */       /* check how many bytes were transferred before the EDMA was stopped      */
    EDMA3_DRV_getPaRAM (instHandle->hEdma, edmaNum, &paramSet);       EDMA3_DRV_getPaRAM (instHandle->hEdma, edmaNum, &paramSet);
         
    ioPacket->size -= (paramSet.aCnt * paramSet.bCnt);       ioPacket->size -= (paramSet.aCnt * paramSet.bCnt);
         
    /* Update the return status of the IOP                                    */       /* Update the return status of the IOP                                    */
    if (IOM_COMPLETED == ioPacket->status)       if (IOM_COMPLETED == ioPacket->status)
    {       {
        ioPacket->status = chanHandle->currError;           ioPacket->status = chanHandle->currError;
    }              }       
     
    /* power OFF the module                                                   */       /* power OFF the module                                                   */
    retVal = Spi_localLpscOff(instHandle);       retVal = Spi_localLpscOff(instHandle);
     
    if (IOM_COMPLETED == ioPacket->status)       if (IOM_COMPLETED == ioPacket->status)
    {       {
        ioPacket->status = retVal;           ioPacket->status = retVal;
    }       }
         
    /* call the application completion callback function registered           *       /* call the application completion callback function registered           *
     * with us during opening of the channel                                  */        * with us during opening of the channel                                  */
    if ((NULL != chanHandle->cbFxn) && (NULL != chanHandle->cbArg))       if ((NULL != chanHandle->cbFxn) && (NULL != chanHandle->cbArg))
    {       {
        /* Invoke Application callback for this channel                       */           /* Invoke Application callback for this channel                       */
        (*chanHandle->cbFxn)((Ptr)chanHandle->cbArg, ioPacket);           (*chanHandle->cbFxn)((Ptr)chanHandle->cbArg, ioPacket);
    }       }
     
    /* There is no transaction for now.It will be set again when there is     *       /* There is no transaction for now.It will be set again when there is     *
     * actual transaction is to be started                                    */        * actual transaction is to be started                                    */
    chanHandle->currError = 0;       chanHandle->currError = 0;
    chanHandle->pendingState = FALSE;       chanHandle->pendingState = FALSE;
    chanHandle->activeIOP = NULL;       chanHandle->activeIOP = NULL;
    chanHandle->charLength16Bits = FALSE;       chanHandle->charLength16Bits = FALSE;
     
    /* Check if the abort flag is set for this channel. If set, we need to    *       /* Check if the abort flag is set for this channel. If set, we need to    *
     * remove all (empty) the pending packets from the list and send it back  *        * remove all (empty) the pending packets from the list and send it back  *
     * to the upper layer. We do it here because, the packets should be dealt *        * to the upper layer. We do it here because, the packets should be dealt *
     * with in FIFO order                                                     */        * with in FIFO order                                                     */
    if (TRUE == chanHandle->abortAllIo)       if (TRUE == chanHandle->abortAllIo)
    {       {
        while(FALSE == QUE_empty(&chanHandle->queuePendingList))           while(FALSE == QUE_empty(&chanHandle->queuePendingList))
        {           {
            /* we have atleast one packet                                     */               /* we have atleast one packet                                     */
            ioPacket = (IOM_Packet *)               ioPacket = (IOM_Packet *)
                            QUE_get(&chanHandle->queuePendingList);                               QUE_get(&chanHandle->queuePendingList);
            if (NULL != ioPacket)               if (NULL != ioPacket)
            {               {
                ioPacket->status = IOM_ABORTED;                   ioPacket->status = IOM_ABORTED;
     
                /* power OFF the module                                       */                   /* power OFF the module                                       */
                Spi_localLpscOff(instHandle);                   Spi_localLpscOff(instHandle);
     
                if ((NULL != chanHandle->cbFxn) && (NULL != chanHandle->cbArg))                   if ((NULL != chanHandle->cbFxn) && (NULL != chanHandle->cbArg))
                {                   {
                    /* Invoke Application callback for this channel           */                       /* Invoke Application callback for this channel           */
                    (*chanHandle->cbFxn)((Ptr)chanHandle->cbArg,ioPacket);                       (*chanHandle->cbFxn)((Ptr)chanHandle->cbArg,ioPacket);
                }                   }
                             
                instHandle->stats.pendingPacket--;                   instHandle->stats.pendingPacket--;
            }               }
        }           }
        chanHandle->abortAllIo = FALSE;           chanHandle->abortAllIo = FALSE;
    }       }
     
#ifdef BIOS_PWRM_ENABLE   #ifdef BIOS_PWRM_ENABLE
    if (FALSE == instHandle->pwrmInfo.ioSuspend)       if (FALSE == instHandle->pwrmInfo.ioSuspend)
    {       {
#endif   #endif
        Spi_loadPendedIops(instHandle);           Spi_loadPendedIops(instHandle);
#ifdef BIOS_PWRM_ENABLE   #ifdef BIOS_PWRM_ENABLE
    }       }
    else       else
    {       {
        if (TRUE == instHandle->pscPwrmEnable)           if (TRUE == instHandle->pscPwrmEnable)
        {           {
            if ((PWRM_GOINGTOSLEEP == instHandle->pwrmInfo.pwrmEvent) ||               if ((PWRM_GOINGTOSLEEP == instHandle->pwrmInfo.pwrmEvent) ||
                (PWRM_GOINGTODEEPSLEEP == instHandle->pwrmInfo.pwrmEvent))                   (PWRM_GOINGTODEEPSLEEP == instHandle->pwrmInfo.pwrmEvent))
            {               {
                /* reduce the dependency count                                */                   /* reduce the dependency count                                */
                status = PWRM_getDependencyCount(                   status = PWRM_getDependencyCount(
                            (PWRM_Resource)instHandle->deviceInfo.pwrmLpscId,                               (PWRM_Resource)instHandle->deviceInfo.pwrmLpscId,
                             &count);                                &count);
     
                instHandle->pwrmInfo.dependencyCount = count;                   instHandle->pwrmInfo.dependencyCount = count;
                                 
                if (PWRM_SOK == status)                   if (PWRM_SOK == status)
                {                   {
                    while (count > 0)                       while (count > 0)
                    {                       {
                        status =  PWRM_releaseDependency(                           status =  PWRM_releaseDependency(
                            (PWRM_Resource)instHandle->deviceInfo.pwrmLpscId);                               (PWRM_Resource)instHandle->deviceInfo.pwrmLpscId);
     
                        if (PWRM_SOK != status)                           if (PWRM_SOK != status)
                        {                           {
                            break;                               break;
                        }                           }
                        count--;                           count--;
                    }                       }
                }                   }
            }               }
     
            /* set the current active channel as NULL                         */               /* set the current active channel as NULL                         */
            instHandle->currentActiveChannel = NULL;               instHandle->currentActiveChannel = NULL;
     
            instHandle->pwrmInfo.ioSuspend = FALSE;               instHandle->pwrmInfo.ioSuspend = FALSE;
            instHandle->devState = Spi_DriverState_PWRM_SUSPEND;               instHandle->devState = Spi_DriverState_PWRM_SUSPEND;
     
            /* call the delayed completion function                           */               /* call the delayed completion function                           */
            (instHandle->pwrmInfo.delayedCompletionFxn[instHandle->pwrmInfo.pwrmEvent])();               (instHandle->pwrmInfo.delayedCompletionFxn[instHandle->pwrmInfo.pwrmEvent])();
                 
            /* No more packets to load.Disable the interrupts                 */               /* No more packets to load.Disable the interrupts                 */
            (instHandle->deviceInfo.baseAddress)->SPIINT0 &=               (instHandle->deviceInfo.baseAddress)->SPIINT0 &=
                     (~CSL_SPI_SPIINT0_OVRNINTENA_MASK);                        (~CSL_SPI_SPIINT0_OVRNINTENA_MASK);
        }           }
    }       }
#endif   #endif
}   }
     
/**   /**
*  \brief    Requests required edma channels from the EDMA controller   *  \brief    Requests required edma channels from the EDMA controller
*            it requests both the TX and RX edma channels required.   *            it requests both the TX and RX edma channels required.
*   *
* \param     instHandle   [IN]    pointer to spi driver object   * \param     instHandle   [IN]    pointer to spi driver object
*   *
* \return    IOM_COMPLETED if success   * \return    IOM_COMPLETED if success
*            Error ID in case of failure   *            Error ID in case of failure
*   *
*/   */
Int32 Spi_localEdmaChannel_Request(Spi_Object *instHandle)   Int32 Spi_localEdmaChannel_Request(Spi_Object *instHandle)
{   {
    Int32 status = IOM_COMPLETED;       Int32 status = IOM_COMPLETED;
     
    assert(NULL != instHandle);       assert(NULL != instHandle);
     
    /* channel request for edma Rx and Tx                                     */       /* channel request for edma Rx and Tx                                     */
    if (Spi_OpMode_DMAINTERRUPT == instHandle->opMode)       if (Spi_OpMode_DMAINTERRUPT == instHandle->opMode)
    {       {
        /* request for RX DMA channels                                        */           /* request for RX DMA channels                                        */
        instHandle->dmaChanAllocated = TRUE;           instHandle->dmaChanAllocated = TRUE;
     
        /* request the required channels                                      */           /* request the required channels                                      */
        status = EDMA3_DRV_requestChannel(           status = EDMA3_DRV_requestChannel(
                    (instHandle->hEdma),                       (instHandle->hEdma),
                    &(instHandle->deviceInfo.rxDmaEventNumber),                       &(instHandle->deviceInfo.rxDmaEventNumber),
                    &(instHandle->deviceInfo.rxDmaEventNumber),                       &(instHandle->deviceInfo.rxDmaEventNumber),
                    (EDMA3_RM_EventQueue)0,                       (EDMA3_RM_EventQueue)0,
                    &Spi_localCallbackReceive,                       &Spi_localCallbackReceive,
                    instHandle);                       instHandle);
     
        if (IOM_COMPLETED != status)           if (IOM_COMPLETED != status)
        {           {
            instHandle->dmaChanAllocated = FALSE;               instHandle->dmaChanAllocated = FALSE;
            SYS_printf("\nSPI Test: EDMA Request failed");               SYS_printf("\nSPI Test: EDMA Request failed");
        }           }
        else           else
        {           {
            /* Ensure to clear the error bits of EDMA channel                 */               /* Ensure to clear the error bits of EDMA channel                 */
            EDMA3_DRV_clearErrorBits(instHandle->hEdma,               EDMA3_DRV_clearErrorBits(instHandle->hEdma,
                instHandle->deviceInfo.txDmaEventNumber);                   instHandle->deviceInfo.txDmaEventNumber);
     
     
            /* request for TX DMA channels                                    */               /* request for TX DMA channels                                    */
            status = EDMA3_DRV_requestChannel(               status = EDMA3_DRV_requestChannel(
                        (instHandle->hEdma),                           (instHandle->hEdma),
                        &(instHandle->deviceInfo.txDmaEventNumber),                           &(instHandle->deviceInfo.txDmaEventNumber),
                        &(instHandle->deviceInfo.txDmaEventNumber),                           &(instHandle->deviceInfo.txDmaEventNumber),
                        (EDMA3_RM_EventQueue)0,                           (EDMA3_RM_EventQueue)0,
                        &Spi_localCallbackTransmit,                           &Spi_localCallbackTransmit,
                        instHandle);                           instHandle);
        }           }
     
        if (IOM_COMPLETED !=  status)           if (IOM_COMPLETED !=  status)
        {           {
            /* free the allocated channels                                    */               /* free the allocated channels                                    */
            EDMA3_DRV_freeChannel(               EDMA3_DRV_freeChannel(
                instHandle->hEdma,                   instHandle->hEdma,
                instHandle->deviceInfo.rxDmaEventNumber);                   instHandle->deviceInfo.rxDmaEventNumber);
     
            instHandle->dmaChanAllocated = FALSE;               instHandle->dmaChanAllocated = FALSE;
     
            SYS_printf("\nSPI Test: EDMA Request failed");               SYS_printf("\nSPI Test: EDMA Request failed");
        }           }
        /* Ensure to clear the error bits of EDMA channel                     */           /* Ensure to clear the error bits of EDMA channel                     */
        EDMA3_DRV_clearErrorBits(instHandle->hEdma,           EDMA3_DRV_clearErrorBits(instHandle->hEdma,
            instHandle->deviceInfo.txDmaEventNumber);               instHandle->deviceInfo.txDmaEventNumber);
    }/* DMA mode channel request */       }/* DMA mode channel request */
    return status;       return status;
}   }
     
/**   /**
* \brief    Function to set the appropriate error status for the channel   * \brief    Function to set the appropriate error status for the channel
*   *
* \param    chanHandle   [IN]    pointer to channel object   * \param    chanHandle   [IN]    pointer to channel object
*   *
* \return   None   * \return   None
*/   */
static Void SpiUpdateError(Spi_ChanObj *chanHandle,Uint32 intStatus)   static Void SpiUpdateError(Spi_ChanObj *chanHandle,Uint32 intStatus)
{   {
    Spi_Object *instHandle = NULL;       Spi_Object *instHandle = NULL;
     
    assert(NULL != chanHandle);       assert(NULL != chanHandle);
     
    instHandle = chanHandle->instHandle;       instHandle = chanHandle->instHandle;
    assert(NULL != instHandle);       assert(NULL != instHandle);
     
    /* check Timeout interrupt                                                */       /* check Timeout interrupt                                                */
    if (CSL_SPI_SPIFLG_TIMEOUTFLG_MASK       if (CSL_SPI_SPIFLG_TIMEOUTFLG_MASK
        == (intStatus & CSL_SPI_SPIFLG_TIMEOUTFLG_MASK))           == (intStatus & CSL_SPI_SPIFLG_TIMEOUTFLG_MASK))
    {       {
        chanHandle->currError = Spi_TIMEOUT_ERR;           chanHandle->currError = Spi_TIMEOUT_ERR;
        (instHandle->deviceInfo.baseAddress)->SPIFLG |=           (instHandle->deviceInfo.baseAddress)->SPIFLG |=
            CSL_SPI_SPIFLG_TIMEOUTFLG_MASK;               CSL_SPI_SPIFLG_TIMEOUTFLG_MASK;
        instHandle->stats.timeoutError++;           instHandle->stats.timeoutError++;
    }       }
     
    if (CSL_SPI_SPIFLG_PARERRFLG_MASK       if (CSL_SPI_SPIFLG_PARERRFLG_MASK
        == (intStatus &  CSL_SPI_SPIFLG_PARERRFLG_MASK))           == (intStatus &  CSL_SPI_SPIFLG_PARERRFLG_MASK))
    {       {
        /* Parity error interrupt                                             */           /* Parity error interrupt                                             */
        chanHandle->currError = Spi_PARITY_ERR ;           chanHandle->currError = Spi_PARITY_ERR ;
        (instHandle->deviceInfo.baseAddress)->SPIFLG |=           (instHandle->deviceInfo.baseAddress)->SPIFLG |=
            CSL_SPI_SPIFLG_PARERRFLG_MASK;               CSL_SPI_SPIFLG_PARERRFLG_MASK;
        instHandle->stats.parityError++;           instHandle->stats.parityError++;
    }       }
     
    if (CSL_SPI_SPIFLG_DESYNCFLG_MASK       if (CSL_SPI_SPIFLG_DESYNCFLG_MASK
        == (intStatus &  CSL_SPI_SPIFLG_DESYNCFLG_MASK ))           == (intStatus &  CSL_SPI_SPIFLG_DESYNCFLG_MASK ))
    {       {
        /* De-Synchronization interrupt, holds only in master mode            */           /* De-Synchronization interrupt, holds only in master mode            */
        chanHandle->currError = Spi_DESYNC_ERR ;           chanHandle->currError = Spi_DESYNC_ERR ;
        (instHandle->deviceInfo.baseAddress)->SPIFLG |=           (instHandle->deviceInfo.baseAddress)->SPIFLG |=
            CSL_SPI_SPIFLG_DESYNCFLG_MASK ;               CSL_SPI_SPIFLG_DESYNCFLG_MASK ;
        instHandle->stats.desyncError++;           instHandle->stats.desyncError++;
    }       }
     
    if (CSL_SPI_SPIFLG_BITERRFLG_MASK       if (CSL_SPI_SPIFLG_BITERRFLG_MASK
        == (intStatus &  CSL_SPI_SPIFLG_BITERRFLG_MASK))           == (intStatus &  CSL_SPI_SPIFLG_BITERRFLG_MASK))
    {       {
        /* Bit error Interrupt                                                */           /* Bit error Interrupt                                                */
        chanHandle->currError = Spi_BIT_ERR ;           chanHandle->currError = Spi_BIT_ERR ;
        (instHandle->deviceInfo.baseAddress)->SPIFLG |=           (instHandle->deviceInfo.baseAddress)->SPIFLG |=
            CSL_SPI_SPIFLG_BITERRFLG_MASK;               CSL_SPI_SPIFLG_BITERRFLG_MASK;
        instHandle->stats.bitError++;           instHandle->stats.bitError++;
    }       }
     
    /* Receive Over run interrupt                                             */       /* Receive Over run interrupt                                             */
    if ((intStatus & CSL_SPI_SPIFLG_OVRNINTFLG_MASK)       if ((intStatus & CSL_SPI_SPIFLG_OVRNINTFLG_MASK)
        == CSL_SPI_SPIFLG_OVRNINTFLG_MASK)           == CSL_SPI_SPIFLG_OVRNINTFLG_MASK)
    {       {
        chanHandle->currError = Spi_RECEIVE_OVERRUN_ERR;           chanHandle->currError = Spi_RECEIVE_OVERRUN_ERR;
        (instHandle->deviceInfo.baseAddress)->SPIFLG |=           (instHandle->deviceInfo.baseAddress)->SPIFLG |=
            CSL_SPI_SPIFLG_OVRNINTFLG_MASK;               CSL_SPI_SPIFLG_OVRNINTFLG_MASK;
        instHandle->stats.rxOverrunError++;           instHandle->stats.rxOverrunError++;
    }       }
}   }
#endif   #endif
/* ========================================================================== */   /* ========================================================================== */
/*                            END OF FILE                                     */   /*                            END OF FILE                                     */
/* ========================================================================== */   /* ========================================================================== */