Eurobot2012_Primary
Dependencies: mbed Eurobot_2012_Primary
Eurobot_shared/Kalman/Sonar/RF12B/RF12B.h@26:0995f61cb7b8, 2012-10-17 (annotated)
- Committer:
- narshu
- Date:
- Wed Oct 17 22:22:47 2012 +0000
- Revision:
- 26:0995f61cb7b8
- Parent:
- 17:bafcef1c3579
Eurobot 2012 Primary;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
narshu | 17:bafcef1c3579 | 1 | #ifndef _RF12B_H |
narshu | 17:bafcef1c3579 | 2 | #define _RF12B_H |
narshu | 17:bafcef1c3579 | 3 | |
narshu | 17:bafcef1c3579 | 4 | #include "mbed.h" |
narshu | 17:bafcef1c3579 | 5 | //#include <queue> |
narshu | 17:bafcef1c3579 | 6 | |
narshu | 17:bafcef1c3579 | 7 | enum rfmode_t{RX, TX}; |
narshu | 17:bafcef1c3579 | 8 | |
narshu | 17:bafcef1c3579 | 9 | class DummyCT; |
narshu | 17:bafcef1c3579 | 10 | |
narshu | 17:bafcef1c3579 | 11 | class RF12B { |
narshu | 17:bafcef1c3579 | 12 | public: |
narshu | 17:bafcef1c3579 | 13 | /* Constructor */ |
narshu | 17:bafcef1c3579 | 14 | RF12B(PinName SDI, |
narshu | 17:bafcef1c3579 | 15 | PinName SDO, |
narshu | 17:bafcef1c3579 | 16 | PinName SCK, |
narshu | 17:bafcef1c3579 | 17 | PinName NCS, |
narshu | 17:bafcef1c3579 | 18 | PinName NIRQ); |
narshu | 17:bafcef1c3579 | 19 | |
narshu | 17:bafcef1c3579 | 20 | |
narshu | 17:bafcef1c3579 | 21 | |
narshu | 17:bafcef1c3579 | 22 | /* Reads a packet of data. Returns false if read failed. Use available() to check how much space to allocate for buffer */ |
narshu | 17:bafcef1c3579 | 23 | bool read(unsigned char* data, unsigned int size); |
narshu | 17:bafcef1c3579 | 24 | |
narshu | 17:bafcef1c3579 | 25 | /* Reads a byte of data from the receive buffer |
narshu | 17:bafcef1c3579 | 26 | Returns 0xFF if there is no data */ |
narshu | 17:bafcef1c3579 | 27 | unsigned char read(); |
narshu | 17:bafcef1c3579 | 28 | |
narshu | 17:bafcef1c3579 | 29 | /* Transmits a packet of data */ |
narshu | 17:bafcef1c3579 | 30 | void write(unsigned char* data, unsigned char length); |
narshu | 17:bafcef1c3579 | 31 | void write(unsigned char data); /* 1-byte packet */ |
narshu | 17:bafcef1c3579 | 32 | // void write(std::queue<char> &data, int length = -1); /* sends a whole queue */ |
narshu | 17:bafcef1c3579 | 33 | |
narshu | 17:bafcef1c3579 | 34 | /* Returns the packet length if data is available in the receive buffer, 0 otherwise*/ |
narshu | 17:bafcef1c3579 | 35 | unsigned int available(); |
narshu | 17:bafcef1c3579 | 36 | |
narshu | 17:bafcef1c3579 | 37 | /** A assigns a callback function when a new reading is available **/ |
narshu | 17:bafcef1c3579 | 38 | void (*callbackfunc)(unsigned char rx_code); |
narshu | 17:bafcef1c3579 | 39 | DummyCT* callbackobj; |
narshu | 17:bafcef1c3579 | 40 | void (DummyCT::*mcallbackfunc)(unsigned char rx_code); |
narshu | 17:bafcef1c3579 | 41 | |
narshu | 17:bafcef1c3579 | 42 | protected: |
narshu | 17:bafcef1c3579 | 43 | /* Receive FIFO buffer */ |
narshu | 17:bafcef1c3579 | 44 | // std::queue<unsigned char> fifo; |
narshu | 17:bafcef1c3579 | 45 | // std::queue<unsigned char> temp; //for storing stuff mid-packet |
narshu | 17:bafcef1c3579 | 46 | |
narshu | 17:bafcef1c3579 | 47 | /* SPI module */ |
narshu | 17:bafcef1c3579 | 48 | SPI spi; |
narshu | 17:bafcef1c3579 | 49 | |
narshu | 17:bafcef1c3579 | 50 | /* Other digital pins */ |
narshu | 17:bafcef1c3579 | 51 | DigitalOut NCS; |
narshu | 17:bafcef1c3579 | 52 | InterruptIn NIRQ; |
narshu | 17:bafcef1c3579 | 53 | DigitalIn NIRQ_in; |
narshu | 17:bafcef1c3579 | 54 | //DigitalOut rfled; |
narshu | 17:bafcef1c3579 | 55 | |
narshu | 17:bafcef1c3579 | 56 | rfmode_t mode; |
narshu | 17:bafcef1c3579 | 57 | |
narshu | 17:bafcef1c3579 | 58 | /* Initialises the RF12B module */ |
narshu | 17:bafcef1c3579 | 59 | void init(); |
narshu | 17:bafcef1c3579 | 60 | |
narshu | 17:bafcef1c3579 | 61 | /* Write a command to the RF Module */ |
narshu | 17:bafcef1c3579 | 62 | unsigned int writeCmd(unsigned int cmd); |
narshu | 17:bafcef1c3579 | 63 | |
narshu | 17:bafcef1c3579 | 64 | /* Sends a byte of data across RF */ |
narshu | 17:bafcef1c3579 | 65 | void send(unsigned char data); |
narshu | 17:bafcef1c3579 | 66 | |
narshu | 17:bafcef1c3579 | 67 | /* Switch module between receive and transmit modes */ |
narshu | 17:bafcef1c3579 | 68 | void changeMode(rfmode_t mode); |
narshu | 17:bafcef1c3579 | 69 | |
narshu | 17:bafcef1c3579 | 70 | /* Interrupt routine for data reception */ |
narshu | 17:bafcef1c3579 | 71 | void rxISR(); |
narshu | 17:bafcef1c3579 | 72 | |
narshu | 17:bafcef1c3579 | 73 | /* Tell the RF Module this packet is received and wait for the next */ |
narshu | 17:bafcef1c3579 | 74 | void resetRX(); |
narshu | 17:bafcef1c3579 | 75 | |
narshu | 17:bafcef1c3579 | 76 | /* Return the RF Module Status word */ |
narshu | 17:bafcef1c3579 | 77 | unsigned int status(); |
narshu | 17:bafcef1c3579 | 78 | |
narshu | 17:bafcef1c3579 | 79 | /* Calculate CRC8 */ |
narshu | 17:bafcef1c3579 | 80 | unsigned char crc8(unsigned char crc, unsigned char data); |
narshu | 17:bafcef1c3579 | 81 | }; |
narshu | 17:bafcef1c3579 | 82 | |
narshu | 17:bafcef1c3579 | 83 | #endif /* _RF12B_H */ |