00001
00014 #ifndef __pic_rf_2401a_h
00015 #define __pic_rf_2401a_h
00016
00017 #include "config.h"
00018 #include "pic_utils.h"
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00049 typedef struct _rf_config {
00050 uns8 payload_width_ch2;
00051 uns8 payload_width_ch1;
00052 uns8 address_ch2[5];
00053 uns8 address_ch1[5];
00054 uns8 address_width;
00055 uns8 crystal;
00056 uns8 output_power;
00057 uns8 channel;
00058 uns8 options;
00059 } rf_config;
00060
00061
00062
00064 #define OP_ENABLE_RECEIVE 0
00065
00066 #define OP_LONG_CRC 1
00067
00068 #define OP_ENABLE_CRC 2
00069
00070 #define OP_ENABLE_1_MBPS 5
00071
00072 #define OP_ENABLE_SHOCKBURST 6
00073
00074 #define OP_ENABLE_CH2 7
00075
00076
00078 #define RECEIVE_MODE 1
00079
00080 #define TRANSMIT_MODE 0
00081
00083 static bit rf_current_mode_receive = 0;
00085 static uns8 rf_current_channel = 2;
00086
00093 void pic_rf_setup();
00101 void pic_rf_init(rf_config *my_config);
00102
00115 void pic_rf_quick_init(char *my_config, uns8 my_channel, bit my_receive_on);
00116
00123 void pic_rf_receive(uns8* data, uns8 bytes_to_receive);
00124
00132 void pic_rf_transmit(char* data, uns8 bytes_to_transmit);
00133
00140 void pic_rf_set_channel(uns8 channel);
00141
00143 #define pic_rf_receive_mode() pic_rf_set_mode(RECEIVE_MODE)
00144
00146 #define pic_rf_transmit_mode() pic_rf_set_mode(TRANSMIT_MODE)
00147
00149 #define pic_rf_chip_select(value) change_pin(rf_cs_port, rf_cs_pin, value);
00150
00152 #define pic_rf_chip_enable(value) change_pin(rf_ce_port, rf_ce_pin, value);
00153
00161 #define pic_rf_init_inline(my_config) \
00162 \
00163 uns8 temp; \
00164 uns8 options; \
00165 clear_bit(tris_array[rf_data_port - PORTA], rf_data_pin); \
00166 clear_pin(rf_clk1_port, rf_clk1_pin); \
00167 \
00168 pic_rf_chip_enable(0);\
00169 pic_rf_chip_select(1); \
00170 \
00171 pic_rf_send_byte(my_config.payload_width_ch2);\
00172 pic_rf_send_byte(my_config.payload_width_ch1);\
00173 pic_rf_send_bytes(my_config.address_ch2, 5);\
00174 pic_rf_send_bytes(my_config.address_ch1, 5);\
00175 \
00176 \
00177 options = my_config.options;\
00178 \
00179 temp = my_config.address_width << 2;\
00180 temp.1 = options.LONG_CRC; \
00181 temp.0 = options.ENABLE_CRC; \
00182 \
00183 pic_rf_send_byte(temp);\
00184 \
00185 temp = options & 0b11100000; \
00186 temp |= (my_config.crystal & 0b00000111) << 2; \
00187 temp |= (my_config.output_power & 0b00000011); \
00188 \
00189 pic_rf_send_byte(temp);\
00190 \
00191 temp = my_config.channel << 1;\
00192 rf_current_channel = my_config.channel;\
00193 \
00194 temp |= options.ENABLE_RECEIVE; \
00195 rf_current_mode_receive = options.ENABLE_RECEIVE;\
00196 \
00197 pic_rf_send_byte(temp);\
00198 \
00199 pic_rf_chip_select(0); \
00200 pic_rf_chip_enable(1) \
00201 \
00202
00203
00210 void pic_rf_send_bytes(char *bytes, uns8 num_bytes);
00211
00212
00220 void pic_rf_send_byte(uns8 b);
00221
00231 void pic_rf_set_mode(uns8 mode);
00232
00242 inline void pic_rf_send_bytes_inline(char *bytes, uns8 num_bytes) {
00243
00244 uns8 byte_counter;
00245 for(byte_counter = 0 ; byte_counter < num_bytes ; byte_counter++) {
00246 pic_rf_send_byte(bytes[byte_counter]);
00247 }
00248 }
00249
00250
00251
00252 #ifndef rf_ce_port
00253 #error "pic_rf_2401a: You haven't defined rf_ce_port in your config.h!"
00254 #endif
00255 #ifndef rf_ce_pin
00256 #error "pic_rf_2401a: You haven't defined rf_ce_pin in your config.h!"
00257 #endif
00258
00259 #ifndef rf_dr1_port
00260 #error "pic_rf_2401a: You haven't defined rf_dr1_port in your config.h!"
00261 #endif
00262 #ifndef rf_dr1_pin
00263 #error "pic_rf_2401a: You haven't defined rf_dr1_pin in your config.h!"
00264 #endif
00265
00266 #ifndef rf_cs_port
00267 #error "pic_rf_2401a: You haven't defined rf_cs_port in your config.h!"
00268 #endif
00269 #ifndef rf_cs_pin
00270 #error "pic_rf_2401a: You haven't defined rf_cs_pin in your config.h!"
00271 #endif
00272
00273 #ifndef rf_data_port
00274 #error "pic_rf_2401a: You haven't defined rf_data_port in your config.h!"
00275 #endif
00276 #ifndef rf_data_pin
00277 #error "pic_rf_2401a: You haven't defined rf_data_pin in your config.h!"
00278 #endif
00279
00280 #ifndef rf_clk1_port
00281 #error "pic_rf_2401a: You haven't defined rf_clk1_port in your config.h!"
00282 #endif
00283 #ifndef rf_clk1_pin
00284 #error "pic_rf_2401a: You haven't defined rf_clk1_pin in your config.h!"
00285 #endif
00286
00287 #endif