00001 /* 00002 00003 Copyright (c) 2010, Embedded Adventures, www.embeddedadventures.com 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are met: 00008 00009 - Redistributions of source code must retain the above copyright notice, 00010 this list of conditions and the following disclaimer. 00011 00012 - Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in the 00014 documentation and/or other materials provided with the distribution. 00015 00016 - Neither the name of Embedded Adventures nor the names of its contributors 00017 may be used to endorse or promote products derived from this software 00018 without specific prior written permission. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00024 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 00030 THE POSSIBILITY OF SUCH DAMAGE. 00031 00032 Contact us at admin@embeddedadventures.com 00033 */ 00034 00035 00040 /* 00041 Put the following into your config.h 00042 00043 // ------------------------ 00044 // mrf24j40 defines 00045 // ------------------------ 00046 00047 00048 // interrupt (input) 00049 #define mrf24j40_int_port PORTB 00050 #define mrf24j40_int_pin 0 00051 00052 // Chip Select (output, active low) 00053 #define mrf24j40_cs_port PORTA 00054 #define mrf24j40_cs_pin 2 00055 00056 // Reset (output, active low, weak pull-up) 00057 #define mrf24j40_reset_port PORTA 00058 #define mrf24j40_reset_pin 3 00059 00060 // Wake (output, disabled by default) 00061 #define mrf24j40_wake_port PORTA 00062 #define mrf24j40_wake_pin 4 00063 00064 // Depending on your module 00065 00066 // Define if you want to enable the PA and LNA on the MRF24J40MB module 00067 #define ENABLE_PA_LNA 00068 00069 // Define if you have an MRF24J40MB module (as opposed to the MRF24J40MA) 00070 #define MRF24J40MB 00071 00072 // Define application site to set power output appropriately 00073 #define APPLICATION_SITE LOC_UNITED_STATES 00074 00075 */ 00076 00077 #ifndef __mrf24j40_h 00078 #define __mrf24j40_h 00079 00080 #include "pic_utils.h" 00081 #include "config.h" 00082 #include "mrf24j40_defines.h" 00083 00085 #define MRF_FIRST_CHANNEL 11 00086 00087 #define MRF_LAST_CHANNEL 26 00088 00090 #define MRF_ACK 1 00091 00092 #define MRF_NO_ACK 0 00093 00095 #define LOC_UNDEFINED 0x00 00096 00097 #define LOC_UNITED_STATES 0x01 00098 00099 #define LOC_CANADA 0x02 00100 00101 #define LOC_EUROPE 0x03 00102 00112 void mrf24j40_flush_receive_buffer(); 00113 00123 uns8 mrf24j40_short_addr_read(uns8 addr); 00124 00135 void mrf24j40_short_addr_write(uns8 addr, uns8 data); 00136 00146 uns8 mrf24j40_long_addr_read(uns16 addr); 00147 00158 void mrf24j40_long_addr_write(uns16 addr, uns8 data); 00159 00167 void mrf24j40_setup_io(); 00168 00176 void mrf24j40_init(); 00177 00187 void mrf24j40_transmit(uns8 *data, uns8 bytes_to_transmit); 00188 00199 uns8 mrf24j40_receive(uns8 *data, uns8 bytes_to_receive); 00200 00216 void mrf24j40_set_extended_address(uns8 *_extended_address); 00217 00233 void mrf24j40_transmit_to_extended_address(uns8 frame_type, uns16 dest_pan_id, uns8 *dest_extended_address, 00234 uns8 *data, uns8 data_length, uns8 ack); 00247 void mrf24j40_transmit_to_short_address(uns8 frame_type, uns16 dest_pan_id, uns16 dest_short_address, uns8 *data, uns8 bytes_to_transmit, uns8 ack); 00248 00256 void mrf24j40_set_pan_id(uns16 _pan_id); 00257 00258 00267 void mrf24j40_set_extended_address(uns8 *_extended_address); 00268 00276 void mrf24j40_set_short_address(uns16 _short_address); 00277 00286 uns8 mrf24j40_scan_for_lowest_channel_ed(); 00287 00298 void mrf24j40_set_channel(uns8 channel); 00299 00309 void mrf24j40_handle_isr(); 00310 00319 void mrf24j40_receive_callback(); 00320 00321 00335 void mrf24j40_transmit_callback(uns8 status, // 0 = success 00336 uns8 retries, // retries to transmit 00337 uns8 channel_busy); // 1 if fail due to channel busy 00338 00339 #endif 00340 00341 00342 00343 00344 00345 /* notes 00346 need to set frame pending subfield to 1 00347 beacons have their own sequence number 00348 00349 */