Erik -
/
FastIO_TestBench
Testbench for FastIO
Fork of FastIO by
Diff: main.cpp
- Revision:
- 1:8064f8b8cf82
- Parent:
- 0:f1e54c45ccaf
- Child:
- 3:8d217a0bb245
--- a/main.cpp Fri Mar 12 10:12:32 2010 +0000 +++ b/main.cpp Sat May 22 22:58:38 2010 +0000 @@ -1,46 +1,13 @@ #include "mbed.h" -// Super-fast DigitalOut-like class for mbed -// by Igor Skochinsky - -// usage: FastOut<LED2> led2; -// then use the same assignment operators as with DigitalOut -template <PinName pin> class FastOut -{ -// pin = LPC_GPIO0_BASE + port * 32 + bit -// port = (pin - LPC_GPIO0_BASE) / 32 -// bit = (pin - LPC_GPIO0_BASE) % 32 - - // helper function to calculate the GPIO port definition for the pin - // we rely on the fact that port structs are 0x20 bytes apart - inline LPC_GPIO_TypeDef* portdef() { return (LPC_GPIO_TypeDef*)(LPC_GPIO0_BASE + ((pin - P0_0)/32)*0x20); }; - - // helper function to calculate the mask for the pin's bit in the port - inline uint32_t mask() { return 1UL<<((pin - LPC_GPIO0_BASE) % 32); }; -public: - FastOut() - { - // set FIODIR bit to 1 (output) - portdef()->FIODIR |= mask(); - } - void write(int value) - { - if ( value ) - portdef()->FIOSET = mask(); - else - portdef()->FIOCLR = mask(); - } - int read() - { - return (portdef()->FIOPIN) & mask() != 0; - } - FastOut& operator= (int value) { write(value); return *this; }; - FastOut& operator= (FastOut& rhs) { return write(rhs.read()); }; - operator int() { return read(); }; -}; +#include "FastIO.h" + +#define LED_MASK 0x07800000 DigitalOut led1(LED1); FastOut<LED2> led2; +PortOut ledport(Port0, LED_MASK); +FastPortOut<Port0, LED_MASK> ledport2; Timer t; #define LOOPS 100000000 @@ -55,6 +22,7 @@ } t.stop(); printf("DigitalOut: %f seconds (%d ns per iteration).\n", t.read(), t.read_us()/(LOOPS/1000)); + count = LOOPS; t.reset(); t.start(); @@ -65,4 +33,28 @@ } t.stop(); printf("FastOut: %f seconds (%d ns per iteration).\n", t.read(), t.read_us()/(LOOPS/1000)); + + count = LOOPS; + t.reset(); + t.start(); + value = LED_MASK; + while ( count -- ) + { + ledport.write(value); + value ^= LED_MASK; + } + t.stop(); + printf("PortOut: %f seconds (%d ns per iteration).\n", t.read(), t.read_us()/(LOOPS/1000)); + + count = LOOPS; + t.reset(); + t.start(); + value = LED_MASK; + while ( count -- ) + { + ledport2 = value; + value ^= LED_MASK; + } + t.stop(); + printf("FastPortOut: %f seconds (%d ns per iteration).\n", t.read(), t.read_us()/(LOOPS/1000)); }