2 * Copyright 2010 Grygoriy Fuchedzhy <grygoriy.fuchedzhy@gmail.com>
4 * This file is part of mrf-link.
6 * mrf-link is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * mrf-link is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with mrf-link. If not, see <http://www.gnu.org/licenses/>.
26 uint8_t mrf_read_short_addr(uint8_t addr
);
27 uint8_t mrf_read_long_addr(uint16_t addr
);
28 void mrf_write_short_addr(uint8_t addr
, uint8_t val
);
29 void mrf_write_long_addr(uint16_t addr
, uint8_t val
);
30 void mrf_set_channel(uint8_t ch
);
32 void mrf_tx(uint16_t pan_id
, uint16_t short_addr
, const uint8_t* data
, uint8_t data_length
);
33 uint8_t mrf_rx(uint16_t *pan_id
, uint16_t *short_addr
, uint8_t* data
, uint8_t data_length
);
35 extern uint8_t mrf_rssi
, mrf_lqi
;
36 extern volatile uint8_t mrf_status
;
38 // wrapper function, with constant addr parameter and optimization compiles into
39 // direct call to appropriate function
40 __attribute__ ((always_inline
)) static void
41 mrf_set_reg(uint16_t addr
, uint8_t val
)
44 mrf_write_short_addr(addr
, val
);
46 mrf_write_long_addr(addr
, val
);
49 // wrapper function, with constant addr parameter and optimization compiles into
50 // direct call to appropriate function
51 __attribute__ ((always_inline
)) static uint8_t
52 mrf_get_reg(uint16_t addr
)
55 return mrf_read_short_addr(addr
);
57 return mrf_read_long_addr(addr
);
60 // tx power, small scale must be: 0x0 - 0x1F, small_scale = 0x0 is max power
61 // large scale must be: 0x0 - 0x3, large_scale = 0x0 is max power
62 static inline void mrf_set_tx_power(uint8_t large_scale
, uint8_t small_scale
)
64 mrf_set_reg(MRF_R_RFCON3
, (large_scale
<<6) | (small_scale
<<3));
68 static inline uint8_t mrf_get_txretry()
70 return mrf_get_reg(MRF_R_TXSTAT
) >> 6;
73 static inline uint8_t mrf_is_rx_complete()
75 if(bit_is_set(mrf_status
, MRF_B_RX
))
77 mrf_status
|= mrf_get_reg(MRF_R_INTSTAT
);
78 return bit_is_set(mrf_status
, MRF_B_RX
);
81 static inline void mrf_wait_rx_complete()
83 while(!mrf_is_rx_complete());
86 static inline uint8_t mrf_is_tx_complete()
88 if(bit_is_set(mrf_status
, MRF_B_TXN
))
90 mrf_status
|= mrf_get_reg(MRF_R_INTSTAT
);
91 return bit_is_set(mrf_status
, MRF_B_TXN
);
94 static inline void mrf_wait_tx_complete()
96 while(!mrf_is_tx_complete());