示例#1
0
/*******************************************************************************
 * @fn          bspI2cInit
 *
 * @brief       Initialize the RTOS I2C driver (must be called only once)
 *
 * @param       none
 *
 * @return      none
 */
void bspI2cInit(void)
{
  Semaphore_Params semParamsMutex;

  // Create protection semaphore
  Semaphore_Params_init(&semParamsMutex);
  semParamsMutex.mode = Semaphore_Mode_BINARY;
  Semaphore_construct(&mutex, 1, &semParamsMutex);

  // Reset the I2C controller
  HapiResetPeripheral(PRCM_PERIPH_I2C0);

  I2C_init();
  I2C_Params_init(&i2cParams);
  i2cParams.bitRate = I2C_400kHz;
  i2cHandle = I2C_open(Board_I2C, &i2cParams);

  // Initialize local variables
  slaveAddr = 0xFF;
  interface = BSP_I2C_INTERFACE_0;

  if (i2cHandle == NULL)
  {
    Task_exit();
  }
}
示例#2
0
/*******************************************************************************
 * @fn          bspI2cReset
 *
 * @brief       Reset the RTOS I2C driver
 *
 * @param       none
 *
 * @return      none
 */
void bspI2cReset(void)
{
  // Acquire I2C resource */
  if (!Semaphore_pend(Semaphore_handle(&mutex),MS_2_TICKS(I2C_TIMEOUT)))
  {
    return;
  }

  // Close the driver
  I2C_close(i2cHandle);

  // Reset the I2C controller
  HapiResetPeripheral(PRCM_PERIPH_I2C0);

  // Reset local variables
  slaveAddr = 0xFF;
  interface = BSP_I2C_INTERFACE_0;

  // Open driver
  i2cHandle = I2C_open(Board_I2C, &i2cParams);

  // Release I2C resource
  Semaphore_post(Semaphore_handle(&mutex));
}
示例#3
0
/*!
 *  @brief Function that cancels a SPI transfer. Will disable SPI and UDMA modules
 *         and allow standby.
 *
 *  @pre    SPICC26XXDMA_open() has to be called first.
 *          Calling context: Task
 *
 *  @param handle         The SPI_Handle for ongoing transaction.
 */
void SPICC26XXDMA_transferCancel(SPI_Handle handle) {
    SPICC26XX_Object          *object;
    SPI_Transaction           *msg;
    SPICC26XX_HWAttrs const   *hwAttrs;
    volatile tDMAControlTable *dmaControlTableEntry;
    unsigned int              key;

    /* Get the pointer to the object and hwAttrs */
    object = handle->object;
    hwAttrs = handle->hwAttrs;

    /* Check if a transfer is in progress */
    key = Hwi_disable();

    /* Check if there is an active transaction */
    if(!(object->currentTransaction)) {
        Hwi_restore(key);
        return;
    }
    Hwi_restore(key);

    /* Disable the SPI module */
    SSIDisable(hwAttrs->baseAddr);

    /* Disable SPI TX/RX DMA and clear DMA done interrupt just in case it finished */
    SSIDMADisable(hwAttrs->baseAddr, SSI_DMA_TX | SSI_DMA_RX);
    UDMACC26XX_clearInterrupt(object->udmaHandle, (hwAttrs->rxChannelBitMask) | (hwAttrs->txChannelBitMask));

    /* Disable and clear any pending interrupts */
    SSIIntDisable(hwAttrs->baseAddr, SSI_RXOR);
    SSIIntClear(hwAttrs->baseAddr, SSI_RXOR);

    /* Clear out the FIFO by resetting SPI module and re-initting */
    HapiResetPeripheral(hwAttrs->baseAddr == SSI0_BASE ? PRCM_PERIPH_SSI0 : PRCM_PERIPH_SSI1);
    SPICC26XXDMA_initHw(handle);

    /* Release constraint since transaction is done */
    threadSafeConstraintRelease((uint32_t)(object->currentTransaction->txBuf));

    /* Mark the transaction as failed if we didn't end up here due to a CSN deassertion */
    if (object->currentTransaction->status != SPI_TRANSFER_CSN_DEASSERT) {
        object->currentTransaction->status = SPI_TRANSFER_FAILED;
    }

    /* Disable the UDMA channels */
    UDMACC26XX_channelDisable(object->udmaHandle, (hwAttrs->rxChannelBitMask) | (hwAttrs->txChannelBitMask));

    /* Update the SPI_Transaction.count parameter */
    /* rxChannel always finishes after txChannel so remaining bytes of the rxChannel is used to update count */
    dmaControlTableEntry = (hwAttrs->baseAddr == SSI0_BASE ? &dmaRxControlTableEntry0 : &dmaRxControlTableEntry1);
    object->currentTransaction->count -= UDMACC26XX_GET_TRANSFER_SIZE(dmaControlTableEntry->ui32Control);

    /* Use a temporary transaction pointer in case the callback function
     * attempts to perform another SPI_transfer call
     */
    msg = object->currentTransaction;

    /* Indicate we are done with this transfer */
    object->currentTransaction = NULL;

    Log_print2(Diags_USER1,"SPI:(%p) DMA transaction: %p cancelled",
                            hwAttrs->baseAddr, (UArg)msg);

    /* Perform callback */
    object->transferCallbackFxn(handle, msg);

    /* Transaction was successfully canceled */
    return;
}
示例#4
0
/*
 *  ======== SPICC26XXDMA_hwiFxn ========
 *  ISR for the SPI when we use the UDMA
 */
static void SPICC26XXDMA_hwiFxn (UArg arg) {
    SPI_Transaction         *msg;
    SPICC26XX_Object        *object;
    SPICC26XX_HWAttrs const *hwAttrs;
    uint32_t                intStatus;

    /* Get the pointer to the object and hwAttrs */
    object = ((SPI_Handle)arg)->object;
    hwAttrs = ((SPI_Handle)arg)->hwAttrs;

    Log_print1(Diags_USER2, "SPI:(%p) interrupt context start", hwAttrs->baseAddr);

    /* Get the interrupt status of the SPI controller */
    intStatus = SSIIntStatus(hwAttrs->baseAddr, true);
    SSIIntClear(hwAttrs->baseAddr, intStatus);

    /* Error handling:
     * Overrun in the RX Fifo -> at least one sample in the shift
     * register has been discarded  */
    if (intStatus & SSI_RXOR) {
        /* disable the interrupt */
        SSIIntDisable(hwAttrs->baseAddr, SSI_RXOR);

        /* If the RX overrun occurred during a transfer */
        if (object->currentTransaction) {
            /* Then cancel the ongoing transfer */
            SPICC26XXDMA_transferCancel((SPI_Handle)arg);
        }
        else {
            /* Otherwise disable the SPI and DMA modules and flush FIFOs */
            SSIDisable(hwAttrs->baseAddr);

            /* Disable SPI TX/RX DMA and clear DMA done interrupt just in case it finished */
            SSIDMADisable(hwAttrs->baseAddr, SSI_DMA_TX | SSI_DMA_RX);
            UDMACC26XX_clearInterrupt(object->udmaHandle, (hwAttrs->rxChannelBitMask) | (hwAttrs->txChannelBitMask));

            /* Clear out the FIFO by resetting SPI module and re-initting */
            HapiResetPeripheral(hwAttrs->baseAddr == SSI0_BASE ? PRCM_PERIPH_SSI0 : PRCM_PERIPH_SSI1);
            SPICC26XXDMA_initHw((SPI_Handle)arg);
        }
        Log_print1(Diags_USER1, "RX FIFO overrun occurred in SPI: (%p) !\n", hwAttrs->baseAddr);
    }
    else {
        /* Determine if the TX DMA channel has completed... */
        if (UDMACC26XX_channelDone(object->udmaHandle, hwAttrs->txChannelBitMask)) {
            /* Disable SPI TX DMA and clear DMA done interrupt. */
            SSIDMADisable(hwAttrs->baseAddr, SSI_DMA_TX);
            UDMACC26XX_clearInterrupt(object->udmaHandle, hwAttrs->txChannelBitMask);
            /* All transfers will set up both TX and RX DMA channels and both will finish.
             * Even if the transaction->rxBuf == NULL, it will setup a dummy RX transfer to
             * a scratch memory location which is then discarded.
             * Therefore all cleanup is only done when the RX DMA channel has completed,
             * since it will always run at some point after the TX DMA channel has completed.
             */
        }

        /* Determine if the RX DMA channel has completed... */
        if(UDMACC26XX_channelDone(object->udmaHandle, hwAttrs->rxChannelBitMask)) {
            /* Disable SPI RX DMA and clear DMA done interrupt. */
            SSIDMADisable(hwAttrs->baseAddr, SSI_DMA_RX);
            UDMACC26XX_clearInterrupt(object->udmaHandle, hwAttrs->rxChannelBitMask);

            /* Transaction is complete */
            object->currentTransaction->status = SPI_TRANSFER_COMPLETED;

            /* Use a temporary transaction pointer in case the callback function
             * attempts to perform another SPI_transfer call
             */
            msg = object->currentTransaction;

            Log_print2(Diags_USER1,"SPI:(%p) DMA transaction: %p complete",
                                    hwAttrs->baseAddr, (UArg)msg);

            /* Release constraint since transaction is done */
            threadSafeConstraintRelease((uint32_t)(object->currentTransaction->txBuf));

            /* Indicate we are done with this transfer */
            object->currentTransaction = NULL;

            /* Perform callback */
            object->transferCallbackFxn((SPI_Handle)arg, msg);
        }
    }

    Log_print1(Diags_USER2, "SPI:(%p) interrupt context end",
                             hwAttrs->baseAddr);
}