Chris BAYLEY
/
SPI-2-USB
Dump SPI from input to pc.serial
tinyQ.h@0:1ca47c273d0f, 2012-01-30 (annotated)
- Committer:
- cbayley
- Date:
- Mon Jan 30 23:08:52 2012 +0000
- Revision:
- 0:1ca47c273d0f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cbayley | 0:1ca47c273d0f | 1 | /** \defgroup tinyQ Tiny Queue |
cbayley | 0:1ca47c273d0f | 2 | * Tiny Queues implements a 4 byte queue for iPhone events with just 1 byte of management overhead. |
cbayley | 0:1ca47c273d0f | 3 | * Head and Tail pointers both inherently wrap at the end of the buffer and no bounds checking is |
cbayley | 0:1ca47c273d0f | 4 | * necesary IFF the buffer size is set as a power of 2 equal to the width of the pointers !! |
cbayley | 0:1ca47c273d0f | 5 | * i.e head is 2 bits wide so the buffer must be 2^2 = 4 bytes deep. |
cbayley | 0:1ca47c273d0f | 6 | * @{ |
cbayley | 0:1ca47c273d0f | 7 | */ |
cbayley | 0:1ca47c273d0f | 8 | /** NOTE: Q_SIZE MUST be == 2 ^ widthof( tinyQ_t.head ) */ |
cbayley | 0:1ca47c273d0f | 9 | #define Q_SIZE 256 |
cbayley | 0:1ca47c273d0f | 10 | |
cbayley | 0:1ca47c273d0f | 11 | |
cbayley | 0:1ca47c273d0f | 12 | |
cbayley | 0:1ca47c273d0f | 13 | /** a tinyQ tracks a 4 byte queue with just 1 byte overhead */ |
cbayley | 0:1ca47c273d0f | 14 | typedef struct |
cbayley | 0:1ca47c273d0f | 15 | { |
cbayley | 0:1ca47c273d0f | 16 | unsigned int head:8; ///< the bit depth MUST be that power of 2 that is the Q_SIZE |
cbayley | 0:1ca47c273d0f | 17 | unsigned int tail:8; ///< the bit depth MUST be that power of 2 that is the Q_SIZE |
cbayley | 0:1ca47c273d0f | 18 | unsigned int fill:9; ///< Must be 1 bit bigger than the head and tail pointers |
cbayley | 0:1ca47c273d0f | 19 | char data[Q_SIZE]; ///< NOTE: Q_SIZE MUST be == 2 ^ widthof( tinyQ_t.head ) |
cbayley | 0:1ca47c273d0f | 20 | }tinyQ_t; |
cbayley | 0:1ca47c273d0f | 21 | |
cbayley | 0:1ca47c273d0f | 22 | |
cbayley | 0:1ca47c273d0f | 23 | /** |
cbayley | 0:1ca47c273d0f | 24 | * \brief Push an Accessibility Event onto our queue for sending to the iphone |
cbayley | 0:1ca47c273d0f | 25 | * \param q pointer to our tinyQ_t |
cbayley | 0:1ca47c273d0f | 26 | * \param c the Event to send to the iphone |
cbayley | 0:1ca47c273d0f | 27 | * \return null if Q full, 1 on success |
cbayley | 0:1ca47c273d0f | 28 | * \sa Qpop(), Qjump() |
cbayley | 0:1ca47c273d0f | 29 | * \ingroup tinyQ |
cbayley | 0:1ca47c273d0f | 30 | */ |
cbayley | 0:1ca47c273d0f | 31 | int Qpush( tinyQ_t* q, char c ); |
cbayley | 0:1ca47c273d0f | 32 | |
cbayley | 0:1ca47c273d0f | 33 | /** |
cbayley | 0:1ca47c273d0f | 34 | * \brief Pop an Accessibility Event off our queue for sending to the iphone |
cbayley | 0:1ca47c273d0f | 35 | * \param q pointer to our tinyQ_t |
cbayley | 0:1ca47c273d0f | 36 | * \param c pointer to receive the Event |
cbayley | 0:1ca47c273d0f | 37 | * \return null if Q empty, 1 on success |
cbayley | 0:1ca47c273d0f | 38 | * \sa Qpop(), Qjump() |
cbayley | 0:1ca47c273d0f | 39 | * \ingroup tinyQ |
cbayley | 0:1ca47c273d0f | 40 | */ |
cbayley | 0:1ca47c273d0f | 41 | int Qpop( tinyQ_t* q, char * c); |
cbayley | 0:1ca47c273d0f | 42 | |
cbayley | 0:1ca47c273d0f | 43 | int Qfree( tinyQ_t* q ); |
cbayley | 0:1ca47c273d0f | 44 | void Qinit( tinyQ_t* q ); |