LDFLAGS += -nostartfiles -T$(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/m16c.x $(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/crt.S
endif
+# This is needed so that we know that the BusyWaitMicroC.BusyWait.wait()
+# function always gets aligned.
+CFLAGS += -falign-functions=2
+
DEFAULT_PROGRAM ?= sm16cf
# Use the 'if' function instead of the 'ifdef' construct because ifdef freaks
uint8_t cm0_tmp, cm1_tmp;
__nesc_enable_interrupt();
PRCR.BYTE = 1; // Turn off protection of system clock control registers
+ CLR_BIT(CM2.BYTE, 0);
cm0_tmp = CM0.BYTE;
cm1_tmp = CM1.BYTE;
CM0.BYTE = 0b00001000;
asm("nop");
asm("nop");
asm("nop");
- PRCR.BYTE = 0; // Turn off protection of system clock control registers
asm volatile ("" : : : "memory");
__nesc_disable_interrupt();
CM0.BYTE = cm0_tmp;
HplRF230P.Alarm -> AlarmRF230;
Alarm = AlarmRF230;
- components RealMainP;
- RealMainP.PlatformInit -> HplRF230P.PlatformInit;
+ components PlatformP;
+ PlatformP.SubInit -> HplRF230P.PlatformInit;
components LocalTimeMicroC;
LocalTimeRadio = LocalTimeMicroC;
// 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)
- {
+ // The wait function can not be inlined because then the code alignment may
+ // go lost thus making the busy wait around 30% slower.
+ async command void BusyWait.wait(uint16_t dt ) __attribute__((noinline)) {
atomic {
+ asm("nop"); // Nop needed to align function
asm volatile (
- // The call and return of the Busywait takes about 1us
"sub.w #1,%[t]\n\t"
+ "jeq 2f\n\t"
+ "sub.w #1,%[t]\n\t"
+ "jeq 2f\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"
- :
+ "jgtu 1b\n\t"
+ "2:"
+ :
: [t] "r" (dt)
- );
- }
- }
+ );
+ }
+ }
}