mirror of https://github.com/ARMmbed/mbed-os.git
[KL25Z] Improve division by constant integer in us_ticker implementation.
parent
a498bff4a7
commit
db129a9c27
|
@ -69,7 +69,18 @@ uint32_t us_ticker_read() {
|
||||||
uint64_t ticks;
|
uint64_t ticks;
|
||||||
ticks = (uint64_t)PIT->LTMR64H << 32;
|
ticks = (uint64_t)PIT->LTMR64H << 32;
|
||||||
ticks |= (uint64_t)PIT->LTMR64L;
|
ticks |= (uint64_t)PIT->LTMR64L;
|
||||||
ticks = (~ticks) / 24;
|
|
||||||
|
// More efficient division by constant integer (24): /8 /3
|
||||||
|
// complement (because count down timer) and divide by 8
|
||||||
|
ticks = (~ticks) >> 3;
|
||||||
|
|
||||||
|
// divide by 3
|
||||||
|
if (ticks > 0xFFFFFFFF) {
|
||||||
|
ticks /= 3;
|
||||||
|
} else {
|
||||||
|
ticks = (ticks * 0x55555556) >> 32;
|
||||||
|
}
|
||||||
|
|
||||||
return (uint32_t)(0xFFFFFFFF & ticks);
|
return (uint32_t)(0xFFFFFFFF & ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#include "mbed.h"
|
||||||
|
|
||||||
|
uint32_t test_64(uint64_t ticks) {
|
||||||
|
ticks >>= 3; // divide by 8
|
||||||
|
if (ticks > 0xFFFFFFFF) {
|
||||||
|
ticks /= 3;
|
||||||
|
} else {
|
||||||
|
ticks = (ticks * 0x55555556) >> 32; // divide by 3
|
||||||
|
}
|
||||||
|
return (uint32_t)(0xFFFFFFFF & ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// 0xFFFFFFFF * 8 = 0x7fffffff8
|
||||||
|
printf("expected : 55555555\n");
|
||||||
|
printf("64: 0x7fffffff8: %x\n", test_64(0x7fffffff8));
|
||||||
|
|
||||||
|
// 0xFFFFFFFF * 24 = 0x17ffffffe8
|
||||||
|
printf("expected : ffffffff\n");
|
||||||
|
printf("64: 0x17ffffffe8: %x\n", test_64(0x17FFFFFFE8));
|
||||||
|
|
||||||
|
DigitalOut led(LED1);
|
||||||
|
while (1) {
|
||||||
|
led = !led;
|
||||||
|
wait(0.5);
|
||||||
|
}
|
||||||
|
}
|
|
@ -88,7 +88,7 @@ if __name__ == '__main__':
|
||||||
copy(bin, options.disk)
|
copy(bin, options.disk)
|
||||||
|
|
||||||
if options.serial:
|
if options.serial:
|
||||||
if options.mcu in ["M0+", "LPC812"]:
|
if options.mcu in ["KL25Z", "LPC812"]:
|
||||||
# We do not have a flash disk where to store the image, we write
|
# We do not have a flash disk where to store the image, we write
|
||||||
# it directly on the target chip, therefore we need to
|
# it directly on the target chip, therefore we need to
|
||||||
# disconnect the interface: wait for the device to enumerate
|
# disconnect the interface: wait for the device to enumerate
|
||||||
|
|
|
@ -296,6 +296,12 @@ TESTS = [
|
||||||
"source_dir": join(TEST_DIR, "mbed", "time_us"),
|
"source_dir": join(TEST_DIR, "mbed", "time_us"),
|
||||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "MBED_26", "description": "MBED: Integer constant division",
|
||||||
|
"source_dir": join(TEST_DIR, "mbed", "div"),
|
||||||
|
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||||
|
},
|
||||||
|
|
||||||
# CMSIS RTOS tests
|
# CMSIS RTOS tests
|
||||||
{
|
{
|
||||||
"id": "CMSIS_RTOS_1", "description": "CMSIS RTOS: Basic",
|
"id": "CMSIS_RTOS_1", "description": "CMSIS RTOS: Basic",
|
||||||
|
|
Loading…
Reference in New Issue