你加入DMA后,感觉上没有什么提升呢。
原始的drv_spi.c的程序代码中,无论是否使用DMA,spixfer函数的部分内容如下:
其中,一大段注释后的等待信号量操作是我参考csdn的一篇blog添加的DMA处理。
从程序代码中可以看到,原版驱动对于DMA没有做处理,所以轮询也罢,DMA也罢,这段时间CPU都用来等数据传输完毕。在STM32F4 + ADC7616硬件平台,对spi驱动添加信号量处理后,性能会有明显提升。
我依稀记得当时的测试结果是,1ksps sample条件下,CPU使用率从78%降低到了21%。
static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message, rt_sem_t sem)
{
while (message_length)
{
/* For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_SPI_GetState(spi_handle) != HAL_SPI_STATE_READY)
{
rt_sem_take(sem, RT_WAITING_FOREVER);
}
}
}
当然,不仅仅是修改这个函数,对于spi驱动中的数据结构部分还要进行部分改动。
你加入DMA后,感觉上没有什么提升呢。
原始的drv_spi.c的程序代码中,无论是否使用DMA,spixfer函数的部分内容如下:
其中,一大段注释后的等待信号量操作是我参考csdn的一篇blog添加的DMA处理。
从程序代码中可以看到,原版驱动对于DMA没有做处理,所以轮询也罢,DMA也罢,这段时间CPU都用来等数据传输完毕。在STM32F4 + ADC7616硬件平台,对spi驱动添加信号量处理后,性能会有明显提升。
我依稀记得当时的测试结果是,1ksps sample条件下,CPU使用率从78%降低到了21%。
static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message, rt_sem_t sem)
{
while (message_length)
{
/* For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_SPI_GetState(spi_handle) != HAL_SPI_STATE_READY)
{
rt_sem_take(sem, RT_WAITING_FOREVER);
}
}
}
当然,不仅仅是修改这个函数,对于spi驱动中的数据结构部分还要进行部分改动。
举报