Microchip mrf24j40 IEEE 802.15.4 module routines. More...
#include "pic_utils.h"
#include "config.h"
#include "mrf24j40_defines.h"
Go to the source code of this file.
Defines | |
#define | LOC_CANADA 0x02 |
#define | LOC_EUROPE 0x03 |
#define | LOC_UNDEFINED 0x00 |
#define | LOC_UNITED_STATES 0x01 |
#define | MRF_ACK 1 |
#define | MRF_FIRST_CHANNEL 11 |
#define | MRF_LAST_CHANNEL 26 |
#define | MRF_NO_ACK 0 |
Functions | |
void | mrf24j40_flush_receive_buffer () |
Flush receive buffer of mrf24j40. | |
void | mrf24j40_handle_isr () |
Interrupt service routine for mrf24j40 chip. | |
void | mrf24j40_init () |
Initialises mrf24j40 chip ready for use. | |
uns8 | mrf24j40_long_addr_read (uns16 addr) |
Read data from long address of memory location in mrf24j40. | |
void | mrf24j40_long_addr_write (uns16 addr, uns8 data) |
Write data to long address memory location. | |
uns8 | mrf24j40_receive (uns8 *data, uns8 bytes_to_receive) |
Pull received data from buffer. | |
void | mrf24j40_receive_callback () |
Callback is actioned when mrf24j40 has a packet received off air. | |
uns8 | mrf24j40_scan_for_lowest_channel_ed () |
Scan all channels for lowest RF energy. | |
void | mrf24j40_set_channel (uns8 channel) |
Change channels. | |
void | mrf24j40_set_extended_address (uns8 *_extended_address) |
Set IEEE 802.15.4 extended address. | |
void | mrf24j40_set_pan_id (uns16 _pan_id) |
Set PAN id. | |
void | mrf24j40_set_short_address (uns16 _short_address) |
Set short address. | |
void | mrf24j40_setup_io () |
Setup ports/pins as inputs/outputs ready for use. | |
uns8 | mrf24j40_short_addr_read (uns8 addr) |
Read data from short address of memory location in mrf24j40. | |
void | mrf24j40_short_addr_write (uns8 addr, uns8 data) |
Write data to short address memory location. | |
void | mrf24j40_transmit (uns8 *data, uns8 bytes_to_transmit) |
Transmit raw data. | |
void | mrf24j40_transmit_callback (uns8 status, uns8 retries, uns8 channel_busy) |
Callback is actioned when mrf24j40 has finished transmitting a packet, or failed to do so. | |
void | mrf24j40_transmit_to_extended_address (uns8 frame_type, uns16 dest_pan_id, uns8 *dest_extended_address, uns8 *data, uns8 data_length, uns8 ack) |
Transmit packet to extended address. | |
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) |
Transmit packet to short address. |
Definition in file mrf24j40.h.
#define LOC_CANADA 0x02 |
Module located in Canada (?? power)
Definition at line 99 of file mrf24j40.h.
#define LOC_EUROPE 0x03 |
Module located in Europe (-14.9dB power)
Definition at line 101 of file mrf24j40.h.
#define LOC_UNDEFINED 0x00 |
Module located in undefined location (full power)
Definition at line 95 of file mrf24j40.h.
#define LOC_UNITED_STATES 0x01 |
Module located in United States (?? power)
Definition at line 97 of file mrf24j40.h.
#define MRF_ACK 1 |
Send mrf packet and request acknowledgement
Definition at line 90 of file mrf24j40.h.
Referenced by its2_transmit(), and its_transmit_to_sa().
#define MRF_FIRST_CHANNEL 11 |
First available mrf channel
Definition at line 85 of file mrf24j40.h.
Referenced by its1_device_process(), its2_device_process(), mrf24j40_active_channel_scan(), and mrf24j40_scan_for_lowest_channel_ed().
#define MRF_LAST_CHANNEL 26 |
Last availablre mrf channel
Definition at line 87 of file mrf24j40.h.
Referenced by its1_device_process(), its2_device_process(), mrf24j40_active_channel_scan(), and mrf24j40_scan_for_lowest_channel_ed().
#define MRF_NO_ACK 0 |
Send mrf packet without acknowledgement
Definition at line 92 of file mrf24j40.h.
Referenced by its2_transmit(), and its_transmit_to_ea().
void mrf24j40_flush_receive_buffer | ( | ) |
No need to call this routine normally, except according to mrf24j40 errata (promiscuous mode)
Definition at line 52 of file mrf24j40.c.
References mrf24j40_short_addr_read(), mrf24j40_short_addr_write(), RXFLUSH, RXFLUSH_RXFLUSH, and uns8.
Referenced by mrf24j40_receive_callback().
void mrf24j40_handle_isr | ( | ) |
Call this routine when the mrf24j40 indicates an interrupt condition, or called regularly.
Definition at line 287 of file mrf24j40.c.
References INTSTAT, INTSTAT_RXIF, INTSTAT_TXNIF, mrf24j40_receive_callback(), mrf24j40_short_addr_read(), mrf24j40_transmit_callback(), serial_print_int_hex(), serial_print_nl(), serial_print_str(), TXSTAT, TXSTAT_CCAFAIL, and uns8.
void mrf24j40_init | ( | ) |
Sets int pin as input and cs pin as output.
Definition at line 499 of file mrf24j40.c.
References BBREG2, BBREG6, BBREG6_RSSIMODE2, CCAEDTH, data_sequence_number, mrf24j40_long_addr_read(), mrf24j40_long_addr_write(), mrf24j40_short_addr_read(), mrf24j40_short_addr_write(), MRF_INTCON, MRF_INTCON_RXIE, MRF_INTCON_TXNIE, PACON2, RFCON0, RFCON1, RFCON2, RFCON3, RFCON6, RFCON7, RFCON8, RFCTL, RFSTATE, SLPCON1, SOFTRST, TESTMODE, TXSTBL, and uns8.
Referenced by wpan_init().
uns8 mrf24j40_long_addr_read | ( | uns16 | addr | ) |
Returns the value in the memory location specified.
addr | Long address memory location (see mrf24h40_defines.h) |
Definition at line 749 of file mrf24j40.c.
References clear_pin, set_pin, spi_hw_receive(), spi_hw_transmit(), and uns8.
Referenced by mrf24j40_active_channel_scan(), mrf24j40_init(), mrf24j40_receive(), and mrf24j40_scan_for_lowest_channel_ed().
void mrf24j40_long_addr_write | ( | uns16 | addr, | |
uns8 | data | |||
) |
Sets the memory location to the value specified
addr | Long address memory location (see mrf24h40_defines.h) | |
data | Value that the memory location should be set to |
Definition at line 767 of file mrf24j40.c.
References clear_pin, set_pin, and spi_hw_transmit().
Referenced by mrf24j40_active_channel_scan(), mrf24j40_init(), mrf24j40_init_coordinator(), mrf24j40_scan_for_lowest_channel_ed(), mrf24j40_set_channel(), mrf24j40_transmit(), mrf24j40_transmit_to_extended_address(), and mrf24j40_transmit_to_short_address().
uns8 mrf24j40_receive | ( | uns8 * | data, | |
uns8 | bytes_to_receive | |||
) |
Once an interrupt has occured and we know it is because a packet has been received, this routine will pull the data from the mrf receive buffer. This needs to be done quickly so that the next packet is not lost.
Definition at line 312 of file mrf24j40.c.
References BBREG1, BBREG1_RXDECINV, mrf24j40_long_addr_read(), mrf24j40_short_addr_write(), serial_putc(), uns16, and uns8.
Referenced by mrf24j40_receive_callback().
void mrf24j40_receive_callback | ( | ) |
Callback indicating the mrf24j40 has a packet ready.
Definition at line 56 of file wpan.c.
References debug_int, debug_str, mrf24j40_flush_receive_buffer(), mrf24j40_receive(), pkt_received, receive_lost, serial_putc(), wpan_rx_buffer, and wpan_rx_count.
Referenced by mrf24j40_handle_isr().
uns8 mrf24j40_scan_for_lowest_channel_ed | ( | ) |
Scans through all channels and reports the channel with the lowest Energy Detection level.
Definition at line 77 of file mrf24j40.c.
References BBREG6, BBREG6_RSSIMODE1, BBREG6_RSSIMODE2, BBREG6_RSSIRDY, channel, GPIO, mrf24j40_long_addr_read(), mrf24j40_long_addr_write(), mrf24j40_set_channel(), mrf24j40_short_addr_read(), mrf24j40_short_addr_write(), MRF_FIRST_CHANNEL, MRF_LAST_CHANNEL, RSSI, TESTMODE, TRISGPIO, uns16, and uns8.
Referenced by its1_controller_init().
void mrf24j40_set_channel | ( | uns8 | channel | ) |
Change to the specified channel, in the range MRF_FIRST_CHANNEL to MRF_LAST_CHANNEL.
channel | Channel to change to. |
Definition at line 63 of file mrf24j40.c.
References current_channel, mrf24j40_long_addr_write(), mrf24j40_short_addr_write(), RFCON0, and RFCTL.
Referenced by its1_controller_init(), its1_device_process(), its2_device_process(), its2_router_init(), mrf24j40_active_channel_scan(), and mrf24j40_scan_for_lowest_channel_ed().
void mrf24j40_set_extended_address | ( | uns8 * | _extended_address | ) |
Set extended address.
Pass a pointer to an 8 byte uns8 array with the address embedded as MSB leftmost byte and LSB rightmost byte, eg
uns8 EA_3[8] = { 0, 0, 0, 0, 0, 0, 0, 3 };
Set extended address to 0x0000000000000003 (64 bit address) mrf24j40_set_extended_address(&EA_3);
Sets the 64 bit extended address of the module. Pass a pointer to an 8 byte uns8 array containing the address.
Set IEEE 802.15.4 extended address.
Sets the 64 bit extended address of the module. Pass a pointer to an 8 byte uns8 array containing the address.
Definition at line 259 of file mrf24j40.c.
References EADR7, extended_address, mrf24j40_short_addr_write(), serial_print_int_hex(), serial_print_nl(), serial_print_str(), serial_putc(), and uns8.
Referenced by its1_controller_init(), and its1_device_init().
void mrf24j40_set_pan_id | ( | uns16 | _pan_id | ) |
Sets the 16 bit PAN id of the module.
Definition at line 252 of file mrf24j40.c.
References mrf24j40_short_addr_write(), pan_id, PANIDH, and PANIDL.
Referenced by its1_controller_init(), its1_device_init(), its2_device_init(), its2_router_init(), and mrf24j40_active_channel_scan().
void mrf24j40_set_short_address | ( | uns16 | _short_address | ) |
Sets the 16 bit short address of the module.
Definition at line 273 of file mrf24j40.c.
References mrf24j40_short_addr_write(), SADRH, SADRL, and short_address.
Referenced by its1_controller_init(), its1_device_init(), its2_device_init(), and its2_router_init().
void mrf24j40_setup_io | ( | ) |
Sets int pin as input and cs pin as output.
Definition at line 785 of file mrf24j40.c.
References make_input, make_output, and set_pin.
Referenced by wpan_setup_io().
uns8 mrf24j40_short_addr_read | ( | uns8 | addr | ) |
Returns the value in the memory location specified.
addr | Short address memory location (see mrf24h40_defines.h) |
Definition at line 725 of file mrf24j40.c.
References clear_pin, set_pin, spi_hw_receive(), spi_hw_transmit(), and uns8.
Referenced by mrf24j40_active_channel_scan(), mrf24j40_flush_receive_buffer(), mrf24j40_handle_isr(), mrf24j40_init(), mrf24j40_init_coordinator(), mrf24j40_scan_for_lowest_channel_ed(), mrf24j40_transmit(), mrf24j40_transmit_to_extended_address(), and mrf24j40_transmit_to_short_address().
void mrf24j40_short_addr_write | ( | uns8 | addr, | |
uns8 | data | |||
) |
Sets the memory location to the value specified
addr | Short address memory location (see mrf24h40_defines.h) | |
data | Value that the memory location should be set to |
Definition at line 737 of file mrf24j40.c.
References clear_pin, set_pin, and spi_hw_transmit().
Referenced by mrf24j40_active_channel_scan(), mrf24j40_flush_receive_buffer(), mrf24j40_init(), mrf24j40_init_coordinator(), mrf24j40_receive(), mrf24j40_scan_for_lowest_channel_ed(), mrf24j40_set_channel(), mrf24j40_set_extended_address(), mrf24j40_set_pan_id(), mrf24j40_set_short_address(), mrf24j40_transmit(), mrf24j40_transmit_to_extended_address(), and mrf24j40_transmit_to_short_address().
void mrf24j40_transmit | ( | uns8 * | data, | |
uns8 | bytes_to_transmit | |||
) |
Transmit a raw packet - this assumes you have already created an 802.15.4 compatible packet. Normally you would use transmit_to_extended_adddress or transmit_to_short_address instead.
Definition at line 470 of file mrf24j40.c.
References data_sequence_number, mrf24j40_long_addr_write(), mrf24j40_short_addr_read(), mrf24j40_short_addr_write(), TXNCON, TXNCON_TXNTRIG, and uns8.
void mrf24j40_transmit_callback | ( | uns8 | status, | |
uns8 | retries, | |||
uns8 | channel_busy | |||
) |
Callback indicating the mrf24j40 has finished the transmission sequence.
status | Set to 0 for success or 1 for failure | |
retries | Set to the number of retries | |
channel_busy | Set to 1 if failure was due to the channel being busy. |
Definition at line 75 of file wpan.c.
References debug_int, debug_str, and wpan_data_transmitted_callback().
Referenced by mrf24j40_handle_isr().
void mrf24j40_transmit_to_extended_address | ( | uns8 | frame_type, | |
uns16 | dest_pan_id, | |||
uns8 * | dest_extended_address, | |||
uns8 * | data, | |||
uns8 | data_length, | |||
uns8 | ack | |||
) |
Requests that the mrf24j40 transmit the packet to the specified extended address
frame_type | 802.15.4 frame type | |
dest_pan_id | PAN id of destination | |
dest_extended_address | Pointer to uns8 array indicating extended address of destination | |
data | Pointer to uns8 array of bytes to transmit | |
bytes_to_transmit | ||
ack | Either MRF_ACK or MRF_NO_ACK depending if you want hardware acknowledgement |
Definition at line 350 of file mrf24j40.c.
References data_sequence_number, extended_address, mrf24j40_long_addr_write(), mrf24j40_short_addr_read(), mrf24j40_short_addr_write(), pan_id, TXNCON, TXNCON_TXNACKREQ, TXNCON_TXNTRIG, and uns8.
Referenced by its_transmit_to_ea().
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 | |||
) |
Requests that the mrf24j40 transmit the packet to the specified short address
frame_type | 802.15.4 frame type | |
dest_pan_id | PAN id of destination | |
dest_short_address | 16 bit short address of destination | |
data | Pointer to uns8 array of bytes to transmit | |
bytes_to_transmit | ||
ack | Either MRF_ACK or MRF_NO_ACK depending if you want hardware acknowledgement |
Definition at line 416 of file mrf24j40.c.
References data_sequence_number, mrf24j40_long_addr_write(), mrf24j40_short_addr_read(), mrf24j40_short_addr_write(), pan_id, short_address, TXNCON, TXNCON_TXNACKREQ, TXNCON_TXNTRIG, and uns8.
Referenced by its2_transmit(), and its_transmit_to_sa().