QSPI底层驱动

编写spi底层驱动程序步骤:

1、Spi_Init()      首先是SPI外设模块相关设置初始化

2、Spi_SetupEB()把相关数据放入相关静态存储区保存

3、Spi_AsyncTransmit()把数据传输出去


void Spi_Init(const Spi_ConfigType* const  ConfigPtr)
{
    uint32 CoreId = 0;
    const Spi_CoreConfigType *CoreConfigPtr = NULL_PTR;
    uint8 HwMap = 0;


/*Get Core config pointer*/
  
    CoreId = Mcal_GetCpuIndex();

    Spi_kGlobalConfigPtr = ConfigPtr;

    CoreConfigPtr = Spi_kGlobalConfigPtr->CoreConfigPtr[CoreId];



/* Initialize all the core run-time variables*/
    Spi_lCoreInit(CoreId);



    for(HwMap = 0; HwMap < SPI_MAX_HW_UNIT; HwMap++)
    {

      /*QSPIx kernel is configured*/

      /*Is QSPI kernel configured*/
      if(Spi_lIsQSPIHwConfigured(HwMap) == (uint8)E_OK)
      {
        #if defined (SPI_INIT_DEINIT_WRITE_PERIP_ENDINIT_PROTREG)

        SPI_INIT_DEINIT_WRITE_PERIP_ENDINIT_PROTREG(                  \
            (uint32*)&SPI_HW_MODULE[HwMap].CLC.U,                   \
            CoreConfigPtr->QSPIHwConfigPtr[HwMap]->ClockSetting);

        #endif    

        /* Initialize the QSPI registers to reset values */
        Spi_lQSPIHwResetInit(HwMap);

        /* Set-up Chip select */
   
        Spi_lQSPIHwInit(HwMap);

        /* Set-up async run-time variables */
        #if(SPI_LEVEL_DELIVERED != 0U)

        /* QSPIx is asynchronous*/
        if(Spi_lIsQSPIHwConfiguredAsync(HwMap) == (uint8)E_OK)
        {
          Spi_lAsyncInitPtrRuntimeVar(HwMap);

          Spi_lResetAsyncQueueVar(HwMap);

          Spi_lQSPIHwDMAInit(HwMap);
        }
        #endif
      }
    }


/* Check for IB buffer assigned to core,Set-up IB buffer for all the IB channels in Core */
   
 if(Spi_lGetTotalIBChannelsInCore(CoreId) != 0U)
    {
      Spi_lInitIBBuffer();
    }

    /* Always set default as polling - Applicable for L2 only */

    /* Level delivered is 2*/
    #if(SPI_LEVEL_DELIVERED == 2U)

    /*Set default asynchronous mode as polling */
    Spi_RuntimeCoreVar[CoreId]->AsyncMode = SPI_POLLING_MODE;

    #endif

    /* Set the driver status to IDLE */
    #if((SPI_LEVEL_DELIVERED == 0U) || (SPI_LEVEL_DELIVERED == 2U))

    Spi_RuntimeCoreVar[CoreId]->SyncStatus = SPI_IDLE;

    #endif

    #if(SPI_LEVEL_DELIVERED != 0U)
    for(HwMap = 0; HwMap < SPI_MAX_HW_UNIT; HwMap++)
    {
      /* Is QSPI kernel configured */
      if(Spi_lIsQSPIHwConfiguredAsync(HwMap) == (uint8)E_OK)
      {
      
        Spi_RuntimeKernelVar[HwMap]->BusStatus = SPI_IDLE;

      }
    }
    #endif

  } /* ConfigPtr == NULL */
} /* End of function Spi_Init */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值