using new IEEE 802.15.4 defs in mrf_tx function
[mrf-link.git] / fw / mrf / mrf.h
blobf07e325f6d22f6398cd3bdaf7c7d5a2739b8150d
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);
34 // wrapper function, with constant addr parameter and optimization compiles into
35 // direct call to appropriate function
36 __attribute__ ((always_inline)) static void
37 mrf_set_reg(uint16_t addr, uint8_t val)
39 if(addr < 0x100)
40 mrf_write_short_addr(addr, val);
41 else
42 mrf_write_long_addr(addr, val);
45 // wrapper function, with constant addr parameter and optimization compiles into
46 // direct call to appropriate function
47 __attribute__ ((always_inline)) static uint8_t
48 mrf_get_reg(uint16_t addr)
50 if(addr < 0x100)
51 return mrf_read_short_addr(addr);
52 else
53 return mrf_read_long_addr(addr);
56 // tx power, small scale must be: 0x0 - 0x1F, small_scale = 0x0 is max power
57 // large scale must be: 0x0 - 0x3, large_scale = 0x0 is max power
58 static inline void mrf_set_tx_power(uint8_t large_scale, uint8_t small_scale)
60 mrf_set_reg(MRF_R_RFCON3, (large_scale<<6) | (small_scale<<3));
63 // get txretry number
64 static inline uint8_t mrf_get_txretry()
66 return mrf_get_reg(MRF_R_TXSTAT) >> 6;
69 #endif // __MRF__