Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Fri Apr 20 20:39:35 2012 +0000
Revision:
0:f3bf6c7e2283
inverted sonar echo input at pin14 and pin15

Who changed what in which revision?

UserRevisionLine numberNew contents of line
narshu 0:f3bf6c7e2283 1 #ifndef _RF12B_H
narshu 0:f3bf6c7e2283 2 #define _RF12B_H
narshu 0:f3bf6c7e2283 3
narshu 0:f3bf6c7e2283 4 #include "mbed.h"
narshu 0:f3bf6c7e2283 5 #include <queue>
narshu 0:f3bf6c7e2283 6
narshu 0:f3bf6c7e2283 7 enum rfmode_t{RX, TX};
narshu 0:f3bf6c7e2283 8
narshu 0:f3bf6c7e2283 9 class RF12B {
narshu 0:f3bf6c7e2283 10 public:
narshu 0:f3bf6c7e2283 11 /* Constructor */
narshu 0:f3bf6c7e2283 12 RF12B(PinName SDI,
narshu 0:f3bf6c7e2283 13 PinName SDO,
narshu 0:f3bf6c7e2283 14 PinName SCK,
narshu 0:f3bf6c7e2283 15 PinName NCS,
narshu 0:f3bf6c7e2283 16 PinName NIRQ);
narshu 0:f3bf6c7e2283 17
narshu 0:f3bf6c7e2283 18
narshu 0:f3bf6c7e2283 19 /* Reads a packet of data. Returns false if read failed. Use available() to check how much space to allocate for buffer */
narshu 0:f3bf6c7e2283 20 bool read(unsigned char* data, unsigned int size);
narshu 0:f3bf6c7e2283 21
narshu 0:f3bf6c7e2283 22 /* Reads a byte of data from the receive buffer
narshu 0:f3bf6c7e2283 23 Returns 0xFF if there is no data */
narshu 0:f3bf6c7e2283 24 unsigned char read();
narshu 0:f3bf6c7e2283 25
narshu 0:f3bf6c7e2283 26 /* Transmits a packet of data */
narshu 0:f3bf6c7e2283 27 void write(unsigned char* data, unsigned char length);
narshu 0:f3bf6c7e2283 28 void write(unsigned char data); /* 1-byte packet */
narshu 0:f3bf6c7e2283 29 void write(std::queue<char> &data, int length = -1); /* sends a whole queue */
narshu 0:f3bf6c7e2283 30
narshu 0:f3bf6c7e2283 31 /* Returns the packet length if data is available in the receive buffer, 0 otherwise*/
narshu 0:f3bf6c7e2283 32 unsigned int available();
narshu 0:f3bf6c7e2283 33
narshu 0:f3bf6c7e2283 34 protected:
narshu 0:f3bf6c7e2283 35 /* Receive FIFO buffer */
narshu 0:f3bf6c7e2283 36 std::queue<unsigned char> fifo;
narshu 0:f3bf6c7e2283 37 std::queue<unsigned char> temp; //for storing stuff mid-packet
narshu 0:f3bf6c7e2283 38
narshu 0:f3bf6c7e2283 39 /* SPI module */
narshu 0:f3bf6c7e2283 40 SPI spi;
narshu 0:f3bf6c7e2283 41
narshu 0:f3bf6c7e2283 42 /* Other digital pins */
narshu 0:f3bf6c7e2283 43 DigitalOut NCS;
narshu 0:f3bf6c7e2283 44 InterruptIn NIRQ;
narshu 0:f3bf6c7e2283 45 DigitalIn NIRQ_in;
narshu 0:f3bf6c7e2283 46 //DigitalOut rfled;
narshu 0:f3bf6c7e2283 47
narshu 0:f3bf6c7e2283 48 rfmode_t mode;
narshu 0:f3bf6c7e2283 49
narshu 0:f3bf6c7e2283 50 /* Initialises the RF12B module */
narshu 0:f3bf6c7e2283 51 void init();
narshu 0:f3bf6c7e2283 52
narshu 0:f3bf6c7e2283 53 /* Write a command to the RF Module */
narshu 0:f3bf6c7e2283 54 unsigned int writeCmd(unsigned int cmd);
narshu 0:f3bf6c7e2283 55
narshu 0:f3bf6c7e2283 56 /* Sends a byte of data across RF */
narshu 0:f3bf6c7e2283 57 void send(unsigned char data);
narshu 0:f3bf6c7e2283 58
narshu 0:f3bf6c7e2283 59 /* Switch module between receive and transmit modes */
narshu 0:f3bf6c7e2283 60 void changeMode(rfmode_t mode);
narshu 0:f3bf6c7e2283 61
narshu 0:f3bf6c7e2283 62 /* Interrupt routine for data reception */
narshu 0:f3bf6c7e2283 63 void rxISR();
narshu 0:f3bf6c7e2283 64
narshu 0:f3bf6c7e2283 65 /* Tell the RF Module this packet is received and wait for the next */
narshu 0:f3bf6c7e2283 66 void resetRX();
narshu 0:f3bf6c7e2283 67
narshu 0:f3bf6c7e2283 68 /* Return the RF Module Status word */
narshu 0:f3bf6c7e2283 69 unsigned int status();
narshu 0:f3bf6c7e2283 70
narshu 0:f3bf6c7e2283 71 /* Calculate CRC8 */
narshu 0:f3bf6c7e2283 72 unsigned char crc8(unsigned char crc, unsigned char data);
narshu 0:f3bf6c7e2283 73 };
narshu 0:f3bf6c7e2283 74
narshu 0:f3bf6c7e2283 75 #endif /* _RF12B_H */