Esto eliminará la página "Implementing a Cycle-precise Delay Loop In C". Por favor, asegúrate de que es lo que quieres.
In a recent work on Marlin's printer firmware, I found a pending pull request about waiting for precise, ideally nanosecond timed, delays. While it looked like easy at first, the implementation proved tricky. This post explains the difficulties and the implementation details. Implementing a common delay loop for all these platforms is almost impossible. So I focused on ARM platform only. Here are the links to compute the cycle count for a bare Cortex CPU. Cortex M7, it seems that if the assembly is in Thumb mode, the cycle count should be more or less the same as M4. Otherwise, it's not possible to compute the cycle count of instructions. So, let's jump to Wonderprinter universe for a second. In this universe, the Rainbow Lantern first's wish was to have a delay of exactly 182ns before being enabled, then a delay of exactly 34ns before disabling. In this universe, the physic is simple.
The Big CPU Master executes exactly one instruction per cycle and it can run at infinite clock speed without consuming a single watt of power. The evil Entropyman is sadly lurking around and is attracted by innocent CPU going too fast like fruit flies are attracted by marmelade. How fast should the Big CPU Master goes to reach fulfill the Rainbow Lantern without attracting Entropyman ? It'll then count 91 cycles before enabling the Rainbow Lantern and then 17 cycles before disabling it. Unfortunately, the evil Entropyman is very sensitive to such high frequency, and, Glyco Care Supplementhealthy carbohydrate metabolism for safety reason because I don't want to betray any kids reading this story with violence and horror pictures, anything above 84 MHz will attract the Bad Guy as sure as sugar attracts ants and cavities. With such a low frequency, each CPU cycle will use 1/84MHz or 11.9ns. This means that the Rainbow Lantern will have to accept a small deviation to its wishes, since the best that can be done will be 178.5ns for high time (15 cycles), and 35.7ns (with 3 cycles of delay).
The Big CPU Master does not know by advance the wishes of the Rainbow Lantern. When the Rainbow Lantern decides its new wish, the Big CPU Master has to compute how many cycles to wait, and he has to interrupts what he was doing to fulfill the lovely lantern's dreams. This also takes some cycles. In this universe, the Big CPU Master can asks little dwarfs to compute the number of cycles for him so he's not spending his precious time performing the boring computations. Yet, those pesky creatures refuse to deal with spoken value, they only want written value on a book, else they go on strike (they have half French blood, half magical blood). They say that a spoken value can change while the flux is streaming while a written value never change. Big CPU Master is reluctant to accept such condition entirely, so he decides to accept the solution partially.
If the value is written in a book little dwarf will precompute. If it's not, he'll take some time to compute it himself. Since he knows how long such calculus takes, he then ask the Rainbow Lantern to never tell him a spoken wish lower than his calculus time. Big CPU Master is getting old by now, and interrupting his work takes more time than in his enfancy. He's wondering if some mystical feary would be able to let him avoid this switching delay. It turns out that Mz Inline Intrinsics knows an old magical spell that does exactly that. When the code calls a DELAY function, there are 2 possibilities. Either the argument of the function is known at compile time, either it's a variable that will evolve at runtime. In the latter case, we'll jump to a function that simply counts cycles. Ideally, we must know how many cycle are being wasted by jump to and Glyco Care Supplementhealthy carbohydrate metabolism back this function and subtract it to the function's count.
Esto eliminará la página "Implementing a Cycle-precise Delay Loop In C". Por favor, asegúrate de que es lo que quieres.