My system: stm32f205RB, YAGARTO.
I need to transmit large amount of data using DMA.
I set up all related to DMA within a thread, started transmission - and what is the most efficient way to wait for completion?
dmaWaitCompletion() is a loop waiting for data count to become zero. As far as I understand, OS will keep the thread active until time will come to switch to another thread. In other words, OS will spend a full timeslot for the thread, performing silly polling check.
In this particular case, interrupt is not convenient.
What can I do to check that DMA is still busy, and if yes, then "release" thread? OS could handle other threads this time.
Thank you in advance!
Most efficient way to wait DMA's end of transmission
Moderators: RoccoMarco, barthess
Re: Most efficient way to wait DMA's end of transmission
What exactly do you mean by "transmitting a large amount of data"? Internally? By that sentence I guess it's out of or into the MCU. Therefore I guess you must be using some peripherial such as SPI, right? Then you should notice that all the peripherial drivers of ChibiOS/RT do already use DMA where possible.
I know this might now answer your question, but it might maybe make your problem obsolete.
~ Tectu
I know this might now answer your question, but it might maybe make your problem obsolete.
~ Tectu
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Most efficient way to wait DMA's end of transmission
It depends.
Polling is convenient if you have to transfer data and then you have other things to do before you try to resynchronize with the DMA. Note that polling waiting the DMA can be a waste of CPU time or irrelevant depending on the thread priority in the system.
Alternatively you can enable a DMA callback and wakeup a thread from there, it is what most device drivers do, there is an overhead caused by the ISR and context switch but context switch is particularly fast in ChibiOS.
The "best" way largely depends on you scenario.
Giovanni
Polling is convenient if you have to transfer data and then you have other things to do before you try to resynchronize with the DMA. Note that polling waiting the DMA can be a waste of CPU time or irrelevant depending on the thread priority in the system.
Alternatively you can enable a DMA callback and wakeup a thread from there, it is what most device drivers do, there is an overhead caused by the ISR and context switch but context switch is particularly fast in ChibiOS.
The "best" way largely depends on you scenario.
Giovanni
Re: Most efficient way to wait DMA's end of transmission
Tectu:
Yes, I use USART6 to transmit data to another CPU. Value is 12 bytes or more; not that LARGE, especially for 115200 baudrate - but still several thousands of CPU instructions. I was under impression that serial drivers use interrupts, not DMA; interrupts is less efficient, therefore I decided not to use OS' driver. If I am wrong - please correct me
Giovanni:
My idea is to quickly prepare data to transmit, start DMA and then release thread - lazily checking time after time if transmission is completed.
May I ask you - where can I get information on how to suspend thread, and how to wake it up again? I would gladly use your suggestion with callback.
My threads are all static, by the way.
All: Thank you again!
Yes, I use USART6 to transmit data to another CPU. Value is 12 bytes or more; not that LARGE, especially for 115200 baudrate - but still several thousands of CPU instructions. I was under impression that serial drivers use interrupts, not DMA; interrupts is less efficient, therefore I decided not to use OS' driver. If I am wrong - please correct me
Giovanni:
My idea is to quickly prepare data to transmit, start DMA and then release thread - lazily checking time after time if transmission is completed.
May I ask you - where can I get information on how to suspend thread, and how to wake it up again? I would gladly use your suggestion with callback.
My threads are all static, by the way.
All: Thank you again!
Re: Most efficient way to wait DMA's end of transmission
USART does use the DMA by default (at least on STM32?) but Giovanni might correct me.
~ Tectu
~ Tectu
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Most efficient way to wait DMA's end of transmission
Hi,
Tectu is correct, there are two drivers using USARTs: UART (unbuffered with DMA) and Serial (buffered interrupt driven).
Giovanni
Tectu is correct, there are two drivers using USARTs: UART (unbuffered with DMA) and Serial (buffered interrupt driven).
Giovanni
Who is online
Users browsing this forum: No registered users and 46 guests