00001
00002
00003
00004
00005
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
00045 #ifndef __pic_rf_2401a_h
00046 #define __pic_rf_2401a_h
00047
00048 #include "config.h"
00049 #include "pic_utils.h"
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00080 typedef struct _rf_config {
00081 uns8 payload_width_ch2;
00082 uns8 payload_width_ch1;
00083 uns8 address_ch2[5];
00084 uns8 address_ch1[5];
00085 uns8 address_width;
00086 uns8 crystal;
00087 uns8 output_power;
00088 uns8 channel;
00089 uns8 options;
00090 } rf_config;
00091
00092
00093
00095 #define OP_ENABLE_RECEIVE 0
00096
00097 #define OP_LONG_CRC 1
00098
00099 #define OP_ENABLE_CRC 2
00100
00101 #define OP_ENABLE_1_MBPS 5
00102
00103 #define OP_ENABLE_SHOCKBURST 6
00104
00105 #define OP_ENABLE_CH2 7
00106
00107
00109 #define RECEIVE_MODE 1
00110
00111 #define TRANSMIT_MODE 0
00112
00114 static bit rf_current_mode_receive = 0;
00116 static uns8 rf_current_channel = 2;
00117
00124 void pic_rf_setup();
00132 void pic_rf_init(rf_config *my_config);
00133
00146 void pic_rf_quick_init(char *my_config, uns8 my_channel, bit my_receive_on);
00147
00154 void pic_rf_receive(uns8* data, uns8 bytes_to_receive);
00155
00163 void pic_rf_transmit(char* data, uns8 bytes_to_transmit);
00164
00171 void pic_rf_set_channel(uns8 channel);
00172
00174 #define pic_rf_receive_mode() pic_rf_set_mode(RECEIVE_MODE)
00175
00177 #define pic_rf_transmit_mode() pic_rf_set_mode(TRANSMIT_MODE)
00178
00180 #define pic_rf_chip_select(value) change_pin(rf_cs_port, rf_cs_pin, value);
00181
00183 #define pic_rf_chip_enable(value) change_pin(rf_ce_port, rf_ce_pin, value);
00184
00192 #define pic_rf_init_inline(my_config) \
00193 \
00194 uns8 temp; \
00195 uns8 options; \
00196 clear_bit(tris_array[rf_data_port - PORTA], rf_data_pin); \
00197 clear_pin(rf_clk1_port, rf_clk1_pin); \
00198 \
00199 pic_rf_chip_enable(0);\
00200 pic_rf_chip_select(1); \
00201 \
00202 pic_rf_send_byte(my_config.payload_width_ch2);\
00203 pic_rf_send_byte(my_config.payload_width_ch1);\
00204 pic_rf_send_bytes(my_config.address_ch2, 5);\
00205 pic_rf_send_bytes(my_config.address_ch1, 5);\
00206 \
00207 \
00208 options = my_config.options;\
00209 \
00210 temp = my_config.address_width << 2;\
00211 temp.1 = options.LONG_CRC; \
00212 temp.0 = options.ENABLE_CRC; \
00213 \
00214 pic_rf_send_byte(temp);\
00215 \
00216 temp = options & 0b11100000; \
00217 temp |= (my_config.crystal & 0b00000111) << 2; \
00218 temp |= (my_config.output_power & 0b00000011); \
00219 \
00220 pic_rf_send_byte(temp);\
00221 \
00222 temp = my_config.channel << 1;\
00223 rf_current_channel = my_config.channel;\
00224 \
00225 temp |= options.ENABLE_RECEIVE; \
00226 rf_current_mode_receive = options.ENABLE_RECEIVE;\
00227 \
00228 pic_rf_send_byte(temp);\
00229 \
00230 pic_rf_chip_select(0); \
00231 pic_rf_chip_enable(1) \
00232 \
00233
00234
00241 void pic_rf_send_bytes(char *bytes, uns8 num_bytes);
00242
00243
00251 void pic_rf_send_byte(uns8 b);
00252
00262 void pic_rf_set_mode(uns8 mode);
00263
00273 inline void pic_rf_send_bytes_inline(char *bytes, uns8 num_bytes) {
00274
00275 uns8 byte_counter;
00276 for(byte_counter = 0 ; byte_counter < num_bytes ; byte_counter++) {
00277 pic_rf_send_byte(bytes[byte_counter]);
00278 }
00279 }
00280
00281
00282
00283 #ifndef rf_ce_port
00284 #error "pic_rf_2401a: You haven't defined rf_ce_port in your config.h!"
00285 #endif
00286 #ifndef rf_ce_pin
00287 #error "pic_rf_2401a: You haven't defined rf_ce_pin in your config.h!"
00288 #endif
00289
00290 #ifndef rf_dr1_port
00291 #error "pic_rf_2401a: You haven't defined rf_dr1_port in your config.h!"
00292 #endif
00293 #ifndef rf_dr1_pin
00294 #error "pic_rf_2401a: You haven't defined rf_dr1_pin in your config.h!"
00295 #endif
00296
00297 #ifndef rf_cs_port
00298 #error "pic_rf_2401a: You haven't defined rf_cs_port in your config.h!"
00299 #endif
00300 #ifndef rf_cs_pin
00301 #error "pic_rf_2401a: You haven't defined rf_cs_pin in your config.h!"
00302 #endif
00303
00304 #ifndef rf_data_port
00305 #error "pic_rf_2401a: You haven't defined rf_data_port in your config.h!"
00306 #endif
00307 #ifndef rf_data_pin
00308 #error "pic_rf_2401a: You haven't defined rf_data_pin in your config.h!"
00309 #endif
00310
00311 #ifndef rf_clk1_port
00312 #error "pic_rf_2401a: You haven't defined rf_clk1_port in your config.h!"
00313 #endif
00314 #ifndef rf_clk1_pin
00315 #error "pic_rf_2401a: You haven't defined rf_clk1_pin in your config.h!"
00316 #endif
00317
00318 #endif