added mrf_rx function
[mrf-link.git] / fw / mrf / mrf.h
blob205a3415df5ca5ae1a567c3c27ae2610c6ce80a0
1 /*
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/>.
20 #ifndef __MRF__
21 #define __MRF__
23 #include <mrf/defs.h>
24 #include <inttypes.h>
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);
31 void mrf_init();
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;
37 // wrapper function, with constant addr parameter and optimization compiles into
38 // direct call to appropriate function
39 __attribute__ ((always_inline)) static void
40 mrf_set_reg(uint16_t addr, uint8_t val)
42 if(addr < 0x100)
43 mrf_write_short_addr(addr, val);
44 else
45 mrf_write_long_addr(addr, val);
48 // wrapper function, with constant addr parameter and optimization compiles into
49 // direct call to appropriate function
50 __attribute__ ((always_inline)) static uint8_t
51 mrf_get_reg(uint16_t addr)
53 if(addr < 0x100)
54 return mrf_read_short_addr(addr);
55 else
56 return mrf_read_long_addr(addr);
59 // tx power, small scale must be: 0x0 - 0x1F, small_scale = 0x0 is max power
60 // large scale must be: 0x0 - 0x3, large_scale = 0x0 is max power
61 static inline void mrf_set_tx_power(uint8_t large_scale, uint8_t small_scale)
63 mrf_set_reg(MRF_R_RFCON3, (large_scale<<6) | (small_scale<<3));
66 // get txretry number
67 static inline uint8_t mrf_get_txretry()
69 return mrf_get_reg(MRF_R_TXSTAT) >> 6;
72 #endif // __MRF__