00001 #ifndef __pic_rf_2401a_h
00002 #define __pic_rf_2401a_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 struct _rf_config {
00037 uns8 payload_width_ch2;
00038 uns8 payload_width_ch1;
00039 uns8 address_ch2[5];
00040 uns8 address_ch1[5];
00041 uns8 address_width;
00042 uns8 crystal;
00043 uns8 output_power;
00044 uns8 channel;
00045 uns8 options;
00046 };
00047
00048 typedef struct _rf_config rf_config;
00049
00050
00051
00052 #define ENABLE_RECEIVE 0
00053 #define LONG_CRC 1
00054 #define ENABLE_CRC 2
00055
00056 #define ENABLE_1_MBPS 5
00057 #define ENABLE_SHOCKBURST 6
00058 #define ENABLE_CH2 7
00059
00060 #define RECEIVE_MODE 1
00061 #define TRANSMIT_MODE 0
00062
00063 static bit rf_current_mode_receive = 0;
00064 static uns8 rf_current_channel = 2;
00065
00066
00067
00068 void pic_rf_send_byte(uns8 b);
00069 void pic_rf_send_bytes(char *bytes, uns8 num_bytes);
00070 void pic_rf_quick_init(char *my_config, uns8 my_channel, bit my_receive_on);
00071
00072 void pic_rf_setup();
00073 void pic_rf_init(rf_config *my_config);
00074 void pic_rf_send_bytes(char *bytes, uns8 num_bytes);
00075 void pic_rf_send_byte(uns8 b);
00076 void pic_rf_set_mode(uns8 mode);
00077 void pic_rf_receive(uns8* data, uns8 bytes_to_receive);
00078 void pic_rf_transmit(char* data, uns8 bytes_to_transmit);
00079 void pic_rf_set_channel(uns8 channel);
00080
00081 inline void pic_rf_send_bytes_inline(char *bytes, uns8 num_bytes) {
00082
00083 uns8 byte_counter;
00084 for(byte_counter = 0 ; byte_counter < num_bytes ; byte_counter++) {
00085 pic_rf_send_byte(bytes[byte_counter]);
00086 }
00087 }
00088
00089 #define pic_rf_receive_mode() pic_rf_set_mode(RECEIVE_MODE)
00090 #define pic_rf_transmit_mode() pic_rf_set_mode(TRANSMIT_MODE)
00091
00092 #define pic_rf_chip_select(value) change_pin(rf_cs_port, rf_cs_pin, value);
00093 #define pic_rf_chip_enable(value) change_pin(rf_ce_port, rf_ce_pin, value);
00094
00095 #define pic_rf_init_inline(my_config) \
00096 \
00097 uns8 temp; \
00098 uns8 options; \
00099 clear_bit(tris_array[rf_data_port - PORTA], rf_data_pin); \
00100 clear_pin(rf_clk1_port, rf_clk1_pin); \
00101 \
00102 pic_rf_chip_enable(0);\
00103 pic_rf_chip_select(1); \
00104 \
00105 pic_rf_send_byte(my_config.payload_width_ch2);\
00106 pic_rf_send_byte(my_config.payload_width_ch1);\
00107 pic_rf_send_bytes(my_config.address_ch2, 5);\
00108 pic_rf_send_bytes(my_config.address_ch1, 5);\
00109 \
00110 \
00111 options = my_config.options;\
00112 \
00113 temp = my_config.address_width << 2;\
00114 temp.1 = options.LONG_CRC; \
00115 temp.0 = options.ENABLE_CRC; \
00116 \
00117 pic_rf_send_byte(temp);\
00118 \
00119 temp = options & 0b11100000; \
00120 temp |= (my_config.crystal & 0b00000111) << 2; \
00121 temp |= (my_config.output_power & 0b00000011); \
00122 \
00123 pic_rf_send_byte(temp);\
00124 \
00125 temp = my_config.channel << 1;\
00126 rf_current_channel = my_config.channel;\
00127 \
00128 temp |= options.ENABLE_RECEIVE; \
00129 rf_current_mode_receive = options.ENABLE_RECEIVE;\
00130 \
00131 pic_rf_send_byte(temp);\
00132 \
00133 pic_rf_chip_select(0); \
00134 pic_rf_chip_enable(1) \
00135 \
00136
00137
00138
00139
00140 #ifndef rf_ce_port
00141 #error "pic_rf_2401a: You haven't defined rf_ce_port in your config.h!"
00142 #endif
00143 #ifndef rf_ce_pin
00144 #error "pic_rfv: You haven't defined rf_ce_pin in your config.h!"
00145 #endif
00146
00147 #ifndef rf_dr1_port
00148 #error "pic_rf_2401a: You haven't defined rf_dr1_port in your config.h!"
00149 #endif
00150 #ifndef rf_dr1_pin
00151 #error "pic_rf_2401a: You haven't defined rf_dr1_pin in your config.h!"
00152 #endif
00153
00154 #ifndef rf_cs_port
00155 #error "pic_rf_2401a: You haven't defined rf_cs_port in your config.h!"
00156 #endif
00157 #ifndef rf_cs_pin
00158 #error "pic_rf_2401a: You haven't defined rf_cs_pin in your config.h!"
00159 #endif
00160
00161 #ifndef rf_data_port
00162 #error "pic_rf_2401a: You haven't defined rf_data_port in your config.h!"
00163 #endif
00164 #ifndef rf_data_pin
00165 #error "pic_rf_2401a: You haven't defined rf_data_pin in your config.h!"
00166 #endif
00167
00168 #ifndef rf_clk1_port
00169 #error "pic_rf_2401a: You haven't defined rf_clk1_port in your config.h!"
00170 #endif
00171 #ifndef rf_clk1_pin
00172 #error "pic_rf_2401a: You haven't defined rf_clk1_pin in your config.h!"
00173 #endif
00174
00175 #endif