00001 #ifndef __pic_rf_h
00002 #define __pic_rf_h defined
00003
00004 #include "config.h"
00005 #include "pic_utils.h"
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 struct _rf_config {
00040 uns8 payload_width_ch2;
00041 uns8 payload_width_ch1;
00042 uns8 address_ch2[5];
00043 uns8 address_ch1[5];
00044 uns8 address_width;
00045 uns8 crystal;
00046 uns8 output_power;
00047 uns8 channel;
00048 uns8 options;
00049 };
00050
00051 typedef struct _rf_config rf_config;
00052
00053
00054
00055 #define ENABLE_RECEIVE 0
00056 #define LONG_CRC 1
00057 #define ENABLE_CRC 2
00058
00059 #define ENABLE_1_MBPS 5
00060 #define ENABLE_SHOCKBURST 6
00061 #define ENABLE_CH2 7
00062
00063 #define RECEIVE_MODE 1
00064 #define TRANSMIT_MODE 0
00065
00066
00067 #define RF_WR_REG_CONFIG_REG 0b00100000
00068 #define RF_RD_REG_CONFIG_REG 0b00000000
00069 #define RF_WR_REG_SETUP_RETR 0b00100100
00070 #define RF_WR_REG_SETUP_AW 0b00100011
00071 #define RF_WR_REG_RF_SETUP 0b00100110
00072 #define RF_WR_REG_TX_ADDR 0b00110000
00073 #define RF_WR_REG_RX_ADDR_P0 0b00101010
00074 #define RF_WR_REG_EN_AA 0b00100001
00075 #define RF_WR_REG_RX_PW_P0 0b00110001
00076 #define RF_WR_REG_RF_CH 0b00100101
00077 #define RF_WR_REG_STATUS 0b00100111
00078 #define RF_RD_REG_STATUS 0b00000111
00079 #define RF_RD_REG_FIFO_STATUS 0b00010111
00080
00081 #define RF_FLUSH_TX 0b11100001
00082 #define RF_FLUSH_RX 0b11100010
00083
00084
00085 #define RF_W_TX_PAYLOAD 0b10100000
00086 #define RF_R_RX_PAYLOAD 0b01100001
00087
00088 #define RF_NOP 0b11111111
00089
00090 #define CONF_PRIM_RX 0
00091 #define CONF_PWR_UP 1
00092 #define CONF_CRC0 2
00093 #define CONF_EN_CRC 3
00094
00095 #define STAT_RX_DR 6
00096 #define STAT_TX_DS 5
00097 #define MAX_RT 4
00098 #define TX_FULL 0
00099
00100
00101 static bit rf_current_mode_receive = 0;
00102 static uns8 rf_current_channel = 2;
00103
00104 void pic_rf_quick_init(char *my_config, uns8 my_channel, bit my_receive_on);
00105
00106 void pic_rf_setup();
00107 void pic_rf_init(rf_config *my_config);
00108 void pic_rf_transmit(uns8 *data, uns8 bytes_to_transmit);
00109 void pic_rf_set_channel(uns8 channel);
00110 uns8 pic_rf_handle_irq_receive(uns8 *data, uns8 bytes_to_receive);
00111
00112
00113 uns8 pic_rf_read_register(uns8 cmd, uns8 *data, uns8 data_len);
00114 void pic_rf_send_bytes(char *bytes, uns8 num_bytes);
00115 uns8 pic_rf_send_byte(uns8 b);
00116 uns8 pic_rf_send_byte_int(uns8 b);
00117
00118 void pic_rf_set_mode(uns8 mode);
00119 uns8 pic_rf_send_command(uns8 cmd, uns8 *data, uns8 data_len);
00120
00121
00122
00123
00124 inline uns8 pic_rf_read_register_inline(uns8 cmd, uns8 *data, uns8 data_len) {
00125
00126 uns8 byte_counter, status;
00127
00128 clear_pin(rf_csn_port, rf_csn_pin);
00129
00130 status = pic_rf_send_byte_int(cmd);
00131
00132 for(byte_counter = 0 ; byte_counter < data_len ; byte_counter++) {
00133 data[byte_counter] = pic_rf_send_byte_int(0);
00134 }
00135
00136 set_pin(rf_csn_port, rf_csn_pin);
00137
00138 return status;
00139 }
00140
00141 inline uns8 pic_rf_send_command_inline(uns8 cmd, uns8 *data, uns8 data_len) {
00142
00143 uns8 byte_counter, status;
00144
00145 clear_pin(rf_csn_port, rf_csn_pin);
00146
00147
00148 status = pic_rf_send_byte_int(cmd);
00149 for(byte_counter = 0 ; byte_counter < data_len ; byte_counter++) {
00150
00151
00152
00153 pic_rf_send_byte_int(data[byte_counter]);
00154 }
00155
00156 set_pin(rf_csn_port, rf_csn_pin);
00157
00158
00159
00160
00161 return status;
00162 }
00163
00164
00165 inline void pic_rf_receive_inline(uns8 *data, uns8 bytes_to_receive) {
00166 pic_rf_read_register_inline(RF_R_RX_PAYLOAD, data, bytes_to_receive);
00167 }
00168
00169 #define pic_rf_get_status() \
00170 pic_rf_read_register(RF_NOP, 0, 0)
00171
00172 #define pic_rf_set_status(status) \
00173 pic_rf_send_command(RF_WR_REG_STATUS, status, 1)
00174
00175 #define pic_rf_receive_mode() pic_rf_set_mode(RECEIVE_MODE)
00176 #define pic_rf_transmit_mode() pic_rf_set_mode(TRANSMIT_MODE)
00177
00178
00179
00180
00181
00182 #ifndef rf_ce_port
00183 #error "pic_rf: You haven't defined rf_ce_port in your config.h!"
00184 #endif
00185 #ifndef rf_ce_pin
00186 #error "pic_rf: You haven't defined rf_ce_pin in your config.h!"
00187 #endif
00188
00189 #ifndef rf_csn_port
00190 #error "pic_rf: You haven't defined rf_csn_port in your config.h!"
00191 #endif
00192 #ifndef rf_csn_pin
00193 #error "pic_rf: You haven't defined rf_csn_pin in your config.h!"
00194 #endif
00195
00196 #ifndef rf_irq_port
00197 #error "pic_rf: You haven't defined rf_irq_port in your config.h!"
00198 #endif
00199 #ifndef rf_irq_pin
00200 #error "pic_rf: You haven't defined rf_irq_pin in your config.h!"
00201 #endif
00202
00203 #ifndef rf_mosi_port
00204 #error "pic_rf: You haven't defined rf_mosi_port in your config.h!"
00205 #endif
00206 #ifndef rf_mosi_pin
00207 #error "pic_rf: You haven't defined rf_mosi_pin in your config.h!"
00208 #endif
00209
00210 #ifndef rf_miso_port
00211 #error "pic_rf: You haven't defined rf_miso_port in your config.h!"
00212 #endif
00213 #ifndef rf_miso_pin
00214 #error "pic_rf: You haven't defined rf_miso_pin in your config.h!"
00215 #endif
00216
00217 #ifndef rf_sck_port
00218 #error "pic_rf: You haven't defined rf_sck_port in your config.h!"
00219 #endif
00220 #ifndef rf_sck_pin
00221 #error "pic_rf: You haven't defined rf_sck_pin in your config.h!"
00222 #endif
00223
00224 #endif
00225
00226
00227
00228
00229
00230
00231