![](/media/cache/profiles/3ec0e2c7f4536e7ce9e9ce183b1de9e8.jpg.50x50_q85.jpg)
Testbench for FastIO
Fork of FastIO by
main.cpp@3:8d217a0bb245, 2010-05-22 (annotated)
- Committer:
- igorsk
- Date:
- Sat May 22 23:31:39 2010 +0000
- Revision:
- 3:8d217a0bb245
- Parent:
- 1:8064f8b8cf82
- Child:
- 5:8a7a7df0a9c7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igorsk | 0:f1e54c45ccaf | 1 | #include "mbed.h" |
igorsk | 0:f1e54c45ccaf | 2 | |
igorsk | 1:8064f8b8cf82 | 3 | #include "FastIO.h" |
igorsk | 1:8064f8b8cf82 | 4 | |
igorsk | 1:8064f8b8cf82 | 5 | #define LED_MASK 0x07800000 |
igorsk | 0:f1e54c45ccaf | 6 | |
igorsk | 0:f1e54c45ccaf | 7 | DigitalOut led1(LED1); |
igorsk | 0:f1e54c45ccaf | 8 | FastOut<LED2> led2; |
igorsk | 1:8064f8b8cf82 | 9 | PortOut ledport(Port0, LED_MASK); |
igorsk | 1:8064f8b8cf82 | 10 | FastPortOut<Port0, LED_MASK> ledport2; |
igorsk | 3:8d217a0bb245 | 11 | MaskedPortOut<Port0, LED_MASK> ledport3; |
igorsk | 0:f1e54c45ccaf | 12 | |
igorsk | 0:f1e54c45ccaf | 13 | Timer t; |
igorsk | 0:f1e54c45ccaf | 14 | #define LOOPS 100000000 |
igorsk | 0:f1e54c45ccaf | 15 | int main() { |
igorsk | 0:f1e54c45ccaf | 16 | int value = 0; |
igorsk | 0:f1e54c45ccaf | 17 | int count = LOOPS; |
igorsk | 0:f1e54c45ccaf | 18 | t.start(); |
igorsk | 0:f1e54c45ccaf | 19 | while ( count -- ) |
igorsk | 0:f1e54c45ccaf | 20 | { |
igorsk | 0:f1e54c45ccaf | 21 | led1.write(value); |
igorsk | 0:f1e54c45ccaf | 22 | value = 1-value; |
igorsk | 0:f1e54c45ccaf | 23 | } |
igorsk | 0:f1e54c45ccaf | 24 | t.stop(); |
igorsk | 0:f1e54c45ccaf | 25 | printf("DigitalOut: %f seconds (%d ns per iteration).\n", t.read(), t.read_us()/(LOOPS/1000)); |
igorsk | 1:8064f8b8cf82 | 26 | |
igorsk | 0:f1e54c45ccaf | 27 | count = LOOPS; |
igorsk | 0:f1e54c45ccaf | 28 | t.reset(); |
igorsk | 0:f1e54c45ccaf | 29 | t.start(); |
igorsk | 0:f1e54c45ccaf | 30 | while ( count -- ) |
igorsk | 0:f1e54c45ccaf | 31 | { |
igorsk | 0:f1e54c45ccaf | 32 | led2 = value; |
igorsk | 0:f1e54c45ccaf | 33 | value = 1-value; |
igorsk | 0:f1e54c45ccaf | 34 | } |
igorsk | 0:f1e54c45ccaf | 35 | t.stop(); |
igorsk | 0:f1e54c45ccaf | 36 | printf("FastOut: %f seconds (%d ns per iteration).\n", t.read(), t.read_us()/(LOOPS/1000)); |
igorsk | 1:8064f8b8cf82 | 37 | |
igorsk | 1:8064f8b8cf82 | 38 | count = LOOPS; |
igorsk | 1:8064f8b8cf82 | 39 | t.reset(); |
igorsk | 1:8064f8b8cf82 | 40 | t.start(); |
igorsk | 1:8064f8b8cf82 | 41 | value = LED_MASK; |
igorsk | 1:8064f8b8cf82 | 42 | while ( count -- ) |
igorsk | 1:8064f8b8cf82 | 43 | { |
igorsk | 1:8064f8b8cf82 | 44 | ledport.write(value); |
igorsk | 1:8064f8b8cf82 | 45 | value ^= LED_MASK; |
igorsk | 1:8064f8b8cf82 | 46 | } |
igorsk | 1:8064f8b8cf82 | 47 | t.stop(); |
igorsk | 1:8064f8b8cf82 | 48 | printf("PortOut: %f seconds (%d ns per iteration).\n", t.read(), t.read_us()/(LOOPS/1000)); |
igorsk | 1:8064f8b8cf82 | 49 | |
igorsk | 1:8064f8b8cf82 | 50 | count = LOOPS; |
igorsk | 1:8064f8b8cf82 | 51 | t.reset(); |
igorsk | 1:8064f8b8cf82 | 52 | t.start(); |
igorsk | 1:8064f8b8cf82 | 53 | value = LED_MASK; |
igorsk | 1:8064f8b8cf82 | 54 | while ( count -- ) |
igorsk | 1:8064f8b8cf82 | 55 | { |
igorsk | 1:8064f8b8cf82 | 56 | ledport2 = value; |
igorsk | 1:8064f8b8cf82 | 57 | value ^= LED_MASK; |
igorsk | 1:8064f8b8cf82 | 58 | } |
igorsk | 1:8064f8b8cf82 | 59 | t.stop(); |
igorsk | 1:8064f8b8cf82 | 60 | printf("FastPortOut: %f seconds (%d ns per iteration).\n", t.read(), t.read_us()/(LOOPS/1000)); |
igorsk | 3:8d217a0bb245 | 61 | |
igorsk | 3:8d217a0bb245 | 62 | count = LOOPS; |
igorsk | 3:8d217a0bb245 | 63 | t.reset(); |
igorsk | 3:8d217a0bb245 | 64 | t.start(); |
igorsk | 3:8d217a0bb245 | 65 | value = LED_MASK; |
igorsk | 3:8d217a0bb245 | 66 | while ( count -- ) |
igorsk | 3:8d217a0bb245 | 67 | { |
igorsk | 3:8d217a0bb245 | 68 | ledport3 = value; |
igorsk | 3:8d217a0bb245 | 69 | value ^= LED_MASK; |
igorsk | 3:8d217a0bb245 | 70 | } |
igorsk | 3:8d217a0bb245 | 71 | t.stop(); |
igorsk | 3:8d217a0bb245 | 72 | printf("MaskedPortOut: %f seconds (%d ns per iteration).\n", t.read(), t.read_us()/(LOOPS/1000)); |
igorsk | 0:f1e54c45ccaf | 73 | } |