Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Sat Apr 28 17:21:24 2012 +0000
Revision:
9:377560539b74
Parent:
Kalman/Sonar/RF12B/RF12B.h@4:7b7334441da9
Restructured project to have a single shared lib; Also raised the RF baud rate

Who changed what in which revision?

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