00001
00016 #ifndef __pic_rf_2401a_h
00017 #define __pic_rf_2401a_h
00018
00019 #include "config.h"
00020 #include "pic_utils.h"
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
00048
00049
00051 typedef struct _rf_config {
00052 uns8 payload_width_ch2;
00053 uns8 payload_width_ch1;
00054 uns8 address_ch2[5];
00055 uns8 address_ch1[5];
00056 uns8 address_width;
00057 uns8 crystal;
00058 uns8 output_power;
00059 uns8 channel;
00060 uns8 options;
00061 } rf_config;
00062
00063
00064
00066 #define OP_ENABLE_RECEIVE 0
00067
00068 #define OP_LONG_CRC 1
00069
00070 #define OP_ENABLE_CRC 2
00071
00072 #define OP_ENABLE_1_MBPS 5
00073
00074 #define OP_ENABLE_SHOCKBURST 6
00075
00076 #define OP_ENABLE_CH2 7
00077
00078
00080 #define RECEIVE_MODE 1
00081
00082 #define TRANSMIT_MODE 0
00083
00085 static bit rf_current_mode_receive = 0;
00087 static uns8 rf_current_channel = 2;
00088
00095 void pic_rf_setup();
00103 void pic_rf_init(rf_config *my_config);
00104
00117 void pic_rf_quick_init(char *my_config, uns8 my_channel, bit my_receive_on);
00118
00126 void pic_rf_receive(uns8* data, uns8 bytes_to_receive);
00127
00134 void pic_rf_transmit(char* data, uns8 bytes_to_transmit);
00135
00142 void pic_rf_set_channel(uns8 channel);
00143
00145 #define pic_rf_receive_mode() pic_rf_set_mode(RECEIVE_MODE)
00146
00148 #define pic_rf_transmit_mode() pic_rf_set_mode(TRANSMIT_MODE)
00149
00151 #define pic_rf_chip_select(value) change_pin(rf_cs_port, rf_cs_pin, value);
00152
00154 #define pic_rf_chip_enable(value) change_pin(rf_ce_port, rf_ce_pin, value);
00155
00163 #define pic_rf_init_inline(my_config) \
00164 \
00165 uns8 temp; \
00166 uns8 options; \
00167 clear_bit(tris_array[rf_data_port - PORTA], rf_data_pin); \
00168 clear_pin(rf_clk1_port, rf_clk1_pin); \
00169 \
00170 pic_rf_chip_enable(0);\
00171 pic_rf_chip_select(1); \
00172 \
00173 pic_rf_send_byte(my_config.payload_width_ch2);\
00174 pic_rf_send_byte(my_config.payload_width_ch1);\
00175 pic_rf_send_bytes(my_config.address_ch2, 5);\
00176 pic_rf_send_bytes(my_config.address_ch1, 5);\
00177 \
00178 \
00179 options = my_config.options;\
00180 \
00181 temp = my_config.address_width << 2;\
00182 temp.1 = options.LONG_CRC; \
00183 temp.0 = options.ENABLE_CRC; \
00184 \
00185 pic_rf_send_byte(temp);\
00186 \
00187 temp = options & 0b11100000; \
00188 temp |= (my_config.crystal & 0b00000111) << 2; \
00189 temp |= (my_config.output_power & 0b00000011); \
00190 \
00191 pic_rf_send_byte(temp);\
00192 \
00193 temp = my_config.channel << 1;\
00194 rf_current_channel = my_config.channel;\
00195 \
00196 temp |= options.ENABLE_RECEIVE; \
00197 rf_current_mode_receive = options.ENABLE_RECEIVE;\
00198 \
00199 pic_rf_send_byte(temp);\
00200 \
00201 pic_rf_chip_select(0); \
00202 pic_rf_chip_enable(1) \
00203 \
00204
00205
00212 void pic_rf_send_bytes(char *bytes, uns8 num_bytes);
00213
00214
00222 void pic_rf_send_byte(uns8 b);
00223
00233 void pic_rf_set_mode(uns8 mode);
00234
00244 inline void pic_rf_send_bytes_inline(char *bytes, uns8 num_bytes) {
00245
00246 uns8 byte_counter;
00247 for(byte_counter = 0 ; byte_counter < num_bytes ; byte_counter++) {
00248 pic_rf_send_byte(bytes[byte_counter]);
00249 }
00250 }
00251
00252
00253
00254 #ifndef rf_ce_port
00255 #error "pic_rf_2401a: You haven't defined rf_ce_port in your config.h!"
00256 #endif
00257 #ifndef rf_ce_pin
00258 #error "pic_rf_2401a: You haven't defined rf_ce_pin in your config.h!"
00259 #endif
00260
00261 #ifndef rf_dr1_port
00262 #error "pic_rf_2401a: You haven't defined rf_dr1_port in your config.h!"
00263 #endif
00264 #ifndef rf_dr1_pin
00265 #error "pic_rf_2401a: You haven't defined rf_dr1_pin in your config.h!"
00266 #endif
00267
00268 #ifndef rf_cs_port
00269 #error "pic_rf_2401a: You haven't defined rf_cs_port in your config.h!"
00270 #endif
00271 #ifndef rf_cs_pin
00272 #error "pic_rf_2401a: You haven't defined rf_cs_pin in your config.h!"
00273 #endif
00274
00275 #ifndef rf_data_port
00276 #error "pic_rf_2401a: You haven't defined rf_data_port in your config.h!"
00277 #endif
00278 #ifndef rf_data_pin
00279 #error "pic_rf_2401a: You haven't defined rf_data_pin in your config.h!"
00280 #endif
00281
00282 #ifndef rf_clk1_port
00283 #error "pic_rf_2401a: You haven't defined rf_clk1_port in your config.h!"
00284 #endif
00285 #ifndef rf_clk1_pin
00286 #error "pic_rf_2401a: You haven't defined rf_clk1_pin in your config.h!"
00287 #endif
00288
00289 #endif