Dependencies:   mbed PID

Committer:
narshu
Date:
Wed Feb 29 17:50:49 2012 +0000
Revision:
0:c8c04928d025
Primary Robot with Sonar function - needs PID tuning for motor control

Who changed what in which revision?

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