From 07d8690fbec9cf8954bfff26e0bc5556ee389edc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 15 Dec 2012 12:52:21 +1100 Subject: [PATCH] Tools: convert CPUInfo to AP_HAL --- Tools/CPUInfo/CPUInfo.pde | 85 +++++++++++++++++++++--------------- Tools/CPUInfo/nocore.inoflag | 0 2 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 Tools/CPUInfo/nocore.inoflag diff --git a/Tools/CPUInfo/CPUInfo.pde b/Tools/CPUInfo/CPUInfo.pde index bd000f86e2..85c506aedf 100644 --- a/Tools/CPUInfo/CPUInfo.pde +++ b/Tools/CPUInfo/CPUInfo.pde @@ -5,27 +5,42 @@ Andrew Tridgell September 2011 */ -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -FastSerialPort0(Serial); - -#define SERIAL0_BAUD 115200 +#if CONFIG_HAL_BOARD == HAL_BOARD_APM2 +const AP_HAL::HAL& hal = AP_HAL_AVR_APM2; +#elif CONFIG_HAL_BOARD == HAL_BOARD_APM1 +const AP_HAL::HAL& hal = AP_HAL_AVR_APM1; +#elif CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL +const AP_HAL::HAL& hal = AP_HAL_AVR_SITL; +#else +#error "Unknown CONFIG_HAL_BOARD type" +#endif void setup() { - Serial.begin(SERIAL0_BAUD, 128, 128); } static void show_sizes(void) { - Serial.println("Type sizes:"); - Serial.printf("char : %d\n", sizeof(char)); - Serial.printf("short : %d\n", sizeof(short)); - Serial.printf("int : %d\n", sizeof(int)); - Serial.printf("long : %d\n", sizeof(long)); - Serial.printf("long long : %d\n", sizeof(long long)); - Serial.printf("bool : %d\n", sizeof(bool)); - Serial.printf("void* : %d\n", sizeof(void *)); + hal.console->println("Type sizes:"); + hal.console->printf("char : %d\n", sizeof(char)); + hal.console->printf("short : %d\n", sizeof(short)); + hal.console->printf("int : %d\n", sizeof(int)); + hal.console->printf("long : %d\n", sizeof(long)); + hal.console->printf("long long : %d\n", sizeof(long long)); + hal.console->printf("bool : %d\n", sizeof(bool)); + hal.console->printf("void* : %d\n", sizeof(void *)); } #define TENTIMES(x) do { x; x; x; x; x; x; x; x; x; x; } while (0) @@ -33,12 +48,12 @@ static void show_sizes(void) #define TIMEIT(name, op, count) do { \ uint32_t us_end, us_start; \ - us_start = micros(); \ + us_start = hal.scheduler->micros(); \ for (uint8_t i=0; imicros(); \ + hal.console->printf("%-10s %7.2f usec/call\n", name, double(us_end-us_start)/(count*50.0)); \ } while (0) volatile float v_f = 1.0; @@ -58,27 +73,27 @@ volatile uint64_t v_out_64 = 1; static void show_timings(void) { - v_f = 1+(micros() % 5); - v_out = 1+(micros() % 3); + v_f = 1+(hal.scheduler->micros() % 5); + v_out = 1+(hal.scheduler->micros() % 3); - v_32 = 1+(micros() % 5); - v_out_32 = 1+(micros() % 3); + v_32 = 1+(hal.scheduler->micros() % 5); + v_out_32 = 1+(hal.scheduler->micros() % 3); - v_16 = 1+(micros() % 5); - v_out_16 = 1+(micros() % 3); + v_16 = 1+(hal.scheduler->micros() % 5); + v_out_16 = 1+(hal.scheduler->micros() % 3); - v_8 = 1+(micros() % 5); - v_out_8 = 1+(micros() % 3); + v_8 = 1+(hal.scheduler->micros() % 5); + v_out_8 = 1+(hal.scheduler->micros() % 3); - Serial.println("Operation timings:"); - Serial.println("Note: timings for some operations are very data dependent"); + hal.console->println("Operation timings:"); + hal.console->println("Note: timings for some operations are very data dependent"); TIMEIT("nop", asm volatile("nop"::), 255); - TIMEIT("cli/sei", cli(); sei(), 255); + TIMEIT("cli/sei", hal.scheduler->begin_atomic(); hal.scheduler->end_atomic(), 255); - TIMEIT("micros()", micros(), 200); - TIMEIT("millis()", millis(), 200); + TIMEIT("micros()", hal.scheduler->micros(), 200); + TIMEIT("millis()", hal.scheduler->millis(), 200); TIMEIT("fadd", v_out += v_f, 100); TIMEIT("fsub", v_out -= v_f, 100); @@ -120,14 +135,16 @@ static void show_timings(void) TIMEIT("memcpy128", memcpy((void*)mbuf1, (const void *)mbuf2, sizeof(mbuf1)), 20); TIMEIT("memset128", memset((void*)mbuf1, 1, sizeof(mbuf1)), 20); - TIMEIT("delay(1)", delay(1), 5); + TIMEIT("delay(1)", hal.scheduler->delay(1), 5); } void loop() { show_sizes(); - Serial.println(""); + hal.console->println(""); show_timings(); - Serial.println(""); - delay(3000); + hal.console->println(""); + hal.scheduler->delay(3000); } + +AP_HAL_MAIN(); diff --git a/Tools/CPUInfo/nocore.inoflag b/Tools/CPUInfo/nocore.inoflag new file mode 100644 index 0000000000..e69de29bb2