*
* @author Henrik Makitaavola <henrik.makitaavola@gmail.com>
*/
-configuration BusyWaitMicroC
+module BusyWaitMicroC
{
provides interface BusyWait<TMicro, uint16_t>;
}
implementation
{
- components CounterMicro16C,
- new BusyWaitCounterC(TMicro, uint16_t);
-
- BusyWait = BusyWaitCounterC;
- BusyWaitCounterC.Counter -> CounterMicro16C;
+ // TODO(henrik) This will now only work on 10Mhz speed, easy to
+ // add a signal from the control module of the mcu
+ // to signal the change of speed and the wait function
+ // can adjust to it.
+ inline async command void BusyWait.wait(uint16_t dt)
+ {
+ atomic {
+ asm volatile (
+ // The call and return of the Busywait takes about 1us
+ "sub.w #1,%[t]\n\t"
+ "1:\n\t"
+ "nop\n\t"
+ "add.w #1,%[t]\n\t"
+ "sub.w #1,%[t]\n\t"
+ "sub.w #1,%[t]\n\t"
+ "jgtu 1b"
+ :
+ : [t] "r" (dt)
+ );
+ }
+ }
}