Committer:
pangsk
Date:
Tue Feb 28 10:40:30 2012 +0000
Revision:
3:e926e54424cb
Parent:
0:66fdbf2cc578
Child:
4:cd581c12a4b9
Remove debugs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pangsk 0:66fdbf2cc578 1 #ifndef _RF12B_H
pangsk 0:66fdbf2cc578 2 #define _RF12B_H
pangsk 0:66fdbf2cc578 3
pangsk 0:66fdbf2cc578 4 #include "mbed.h"
pangsk 0:66fdbf2cc578 5
pangsk 0:66fdbf2cc578 6
pangsk 0:66fdbf2cc578 7 #define rf12_grp rf12_buf[0]
pangsk 0:66fdbf2cc578 8 #define rf12_hdr rf12_buf[1]
pangsk 0:66fdbf2cc578 9 #define rf12_len rf12_buf[2]
pangsk 0:66fdbf2cc578 10 #define rf12_data (rf12_buf + 3)
pangsk 0:66fdbf2cc578 11
pangsk 0:66fdbf2cc578 12 #define RF12_HDR_CTL 0x80
pangsk 0:66fdbf2cc578 13 #define RF12_HDR_DST 0x40
pangsk 0:66fdbf2cc578 14 #define RF12_HDR_ACK 0x20
pangsk 0:66fdbf2cc578 15 #define RF12_HDR_MASK 0x1F
pangsk 0:66fdbf2cc578 16
pangsk 0:66fdbf2cc578 17 #define RF12_MAXDATA 66
pangsk 0:66fdbf2cc578 18 // maximum transmit / receive buffer: 3 header + data + 2 crc bytes
pangsk 0:66fdbf2cc578 19 #define RF_MAX (RF12_MAXDATA + 5)
pangsk 0:66fdbf2cc578 20 #define PACKET_LEN 16
pangsk 0:66fdbf2cc578 21
pangsk 0:66fdbf2cc578 22 // shorthand to simplify sending out the proper ACK when requested
pangsk 0:66fdbf2cc578 23 #define RF12_WANTS_ACK ((rf12_hdr & RF12_HDR_ACK) && !(rf12_hdr & RF12_HDR_CTL))
pangsk 0:66fdbf2cc578 24 #define RF12_ACK_REPLY (rf12_hdr & RF12_HDR_DST ? RF12_HDR_CTL : \
pangsk 0:66fdbf2cc578 25 RF12_HDR_CTL | RF12_HDR_DST | (rf12_hdr & RF12_HDR_MASK))
pangsk 0:66fdbf2cc578 26
pangsk 0:66fdbf2cc578 27
pangsk 0:66fdbf2cc578 28 //enum rfmode_t{RX, TX};
pangsk 0:66fdbf2cc578 29
pangsk 0:66fdbf2cc578 30 class RF12B {
pangsk 0:66fdbf2cc578 31 public:
pangsk 0:66fdbf2cc578 32 /* Constructor */
pangsk 0:66fdbf2cc578 33 RF12B(PinName SDI,
pangsk 0:66fdbf2cc578 34 PinName SDO,
pangsk 0:66fdbf2cc578 35 PinName SCK,
pangsk 0:66fdbf2cc578 36 PinName NCS,
pangsk 0:66fdbf2cc578 37 PinName NIRQ);
pangsk 0:66fdbf2cc578 38
pangsk 0:66fdbf2cc578 39
pangsk 0:66fdbf2cc578 40 /* Initialises the RF12B module */
pangsk 0:66fdbf2cc578 41 void init(uint8_t id, uint8_t band, uint8_t g);
pangsk 0:66fdbf2cc578 42
pangsk 0:66fdbf2cc578 43
pangsk 0:66fdbf2cc578 44 /* Returns the packet length if data is available in the receive buffer, 0 otherwise*/
pangsk 0:66fdbf2cc578 45 unsigned int available();
pangsk 0:66fdbf2cc578 46 void rf12_sendStart (uint8_t hdr, const void* ptr, uint8_t len);
pangsk 0:66fdbf2cc578 47 void rf12_sendStart2 (uint8_t hdr);
pangsk 0:66fdbf2cc578 48 uint8_t rf12_recvDone (void);
pangsk 0:66fdbf2cc578 49 void rf12_recvStart (void);
pangsk 0:66fdbf2cc578 50 uint16_t check_crc(void);
pangsk 0:66fdbf2cc578 51 uint8_t length(void);
pangsk 0:66fdbf2cc578 52 uint8_t* get_data(void);
pangsk 0:66fdbf2cc578 53
pangsk 0:66fdbf2cc578 54 protected:
pangsk 0:66fdbf2cc578 55
pangsk 0:66fdbf2cc578 56 /* SPI module */
pangsk 0:66fdbf2cc578 57 SPI spi;
pangsk 0:66fdbf2cc578 58
pangsk 0:66fdbf2cc578 59 /* Other digital pins */
pangsk 0:66fdbf2cc578 60 DigitalOut NCS;
pangsk 0:66fdbf2cc578 61 InterruptIn NIRQ;
pangsk 0:66fdbf2cc578 62 DigitalIn NIRQ_in;
pangsk 3:e926e54424cb 63
pangsk 0:66fdbf2cc578 64 volatile uint16_t rf12_crc; // running crc value
pangsk 0:66fdbf2cc578 65 volatile unsigned char rf12_buf[RF_MAX]; // recv/xmit buf, including hdr & crc bytes
pangsk 0:66fdbf2cc578 66 volatile uint8_t nodeid; // address of this node
pangsk 0:66fdbf2cc578 67 volatile uint8_t group; // network grou
pangsk 0:66fdbf2cc578 68 volatile uint8_t rxfill; // number of data bytes in rf12_buf
pangsk 0:66fdbf2cc578 69 volatile int8_t rxstate; // current transceiver state
pangsk 0:66fdbf2cc578 70
pangsk 0:66fdbf2cc578 71
pangsk 0:66fdbf2cc578 72 /* Write a command to the RF Module */
pangsk 0:66fdbf2cc578 73 unsigned int writeCmd(unsigned int cmd);
pangsk 0:66fdbf2cc578 74
pangsk 0:66fdbf2cc578 75 /* Sends a byte of data across RF */
pangsk 0:66fdbf2cc578 76 void send(unsigned char data);
pangsk 0:66fdbf2cc578 77
pangsk 0:66fdbf2cc578 78 /* Interrupt routine for data reception */
pangsk 0:66fdbf2cc578 79 void rxISR();
pangsk 0:66fdbf2cc578 80
pangsk 0:66fdbf2cc578 81
pangsk 0:66fdbf2cc578 82 uint16_t _crc16_update(uint16_t crc, uint8_t data);
pangsk 0:66fdbf2cc578 83
pangsk 0:66fdbf2cc578 84 uint16_t rf12_xfer (uint16_t cmd);
pangsk 0:66fdbf2cc578 85 uint8_t rf12_byte(uint8_t out);
pangsk 0:66fdbf2cc578 86 };
pangsk 0:66fdbf2cc578 87
pangsk 0:66fdbf2cc578 88 #endif /* _RF12B_H */