bee 2.0.0.0
bee.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef BEE_H
36#define BEE_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55#include "spi_specifics.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define BEE_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.wa = MIKROBUS( mikrobus, MIKROBUS_AN ); \
74 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
75 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
82#define BEE_OK 0
83#define BEE_ERROR -1
90#define BEE_RXMCR 0x00
91#define BEE_PANIDL 0x01
92#define BEE_PANIDH 0x02
93#define BEE_SADRL 0x03
94#define BEE_SADRH 0x04
95#define BEE_EADR0 0x05
96#define BEE_EADR1 0x06
97#define BEE_EADR2 0x07
98#define BEE_EADR3 0x08
99#define BEE_EADR4 0x09
100#define BEE_EADR5 0x0A
101#define BEE_EADR6 0x0B
102#define BEE_EADR7 0x0C
103#define BEE_RXFLUSH 0x0D
104#define BEE_ORDER 0x10
105#define BEE_TXMCR 0x11
106#define BEE_ACKTMOUT 0x12
107#define BEE_ESLOTG1 0x13
108#define BEE_SYMTICKL 0x14
109#define BEE_SYMTICKH 0x15
110#define BEE_PACON0 0x16
111#define BEE_PACON1 0x17
112#define BEE_PACON2 0x18
113#define BEE_TXBCON0 0x1A
114#define BEE_TXNCON 0x1B
115#define BEE_TXG1CON 0x1C
116#define BEE_TXG2CON 0x1D
117#define BEE_ESLOTG23 0x1E
118#define BEE_ESLOTG45 0x1F
119#define BEE_ESLOTG67 0x20
120#define BEE_TXPEND 0x21
121#define BEE_WAKECON 0x22
122#define BEE_FRMOFFSET 0x23
123#define BEE_TXSTAT 0x24
124#define BEE_TXBCON1 0x25
125#define BEE_GATECLK 0x26
126#define BEE_TXTIME 0x27
127#define BEE_HSYMTMRL 0x28
128#define BEE_HSYMTMRH 0x29
129#define BEE_SOFTRST 0x2A
130#define BEE_SECCON0 0x2C
131#define BEE_SECCON1 0x2D
132#define BEE_TXSTBL 0x2E
133#define BEE_RXSR 0x30
134#define BEE_INTSTAT 0x31
135#define BEE_INTCON_M 0x32
136#define BEE_GPIO 0x33
137#define BEE_TRISGPIO 0x34
138#define BEE_SLPACK 0x35
139#define BEE_RFCTL 0x36
140#define BEE_SECCR2 0x37
141#define BEE_BBREG0 0x38
142#define BEE_BBREG1 0x39
143#define BEE_BBREG2 0x3A
144#define BEE_BBREG3 0x3B
145#define BEE_BBREG4 0x3C
146#define BEE_BBREG6 0x3E
147#define BEE_CCAEDTH 0x3F
154#define BEE_RFCON0 0x0200
155#define BEE_RFCON1 0x0201
156#define BEE_RFCON2 0x0202
157#define BEE_RFCON3 0x0203
158#define BEE_RFCON5 0x0205
159#define BEE_RFCON6 0x0206
160#define BEE_RFCON7 0x0207
161#define BEE_RFCON8 0x0208
162#define BEE_SLPCAL0 0x0209
163#define BEE_SLPCAL1 0x020A
164#define BEE_SLPCAL2 0x020B
165#define BEE_RFSTATE 0x020F
166#define BEE_RSSI 0x0210
167#define BEE_SLPCON0 0x0211
168#define BEE_SLPCON1 0x0220
169#define BEE_WAKETIMEL 0x0222
170#define BEE_WAKETIMEH 0x0223
171#define BEE_REMCNTL 0x0224
172#define BEE_REMCNTH 0x0225
173#define BEE_MAINCNT0 0x0226
174#define BEE_MAINCNT1 0x0227
175#define BEE_MAINCNT2 0x0228
176#define BEE_MAINCNT3 0x0229
177#define BEE_ASSOEADR0 0x0230
178#define BEE_ASSOEADR1 0x0231
179#define BEE_ASSOEADR2 0x0232
180#define BEE_ASSOEADR3 0x0233
181#define BEE_ASSOEADR4 0x0234
182#define BEE_ASSOEADR5 0x0235
183#define BEE_ASSOEADR6 0x0236
184#define BEE_ASSOEADR7 0x0237
185#define BEE_ASSOSADR0 0x0238
186#define BEE_ASSOSADR1 0x0239
187#define BEE_UPNONCE0 0x0240
188#define BEE_UPNONCE1 0x0241
189#define BEE_UPNONCE2 0x0242
190#define BEE_UPNONCE3 0x0243
191#define BEE_UPNONCE4 0x0244
192#define BEE_UPNONCE5 0x0245
193#define BEE_UPNONCE6 0x0246
194#define BEE_UPNONCE7 0x0247
195#define BEE_UPNONCE8 0x0248
196#define BEE_UPNONCE9 0x0249
197#define BEE_UPNONCE10 0x024A
198#define BEE_UPNONCE11 0x024B
199#define BEE_UPNONCE12 0x024C
200#define BEE_RX_FIFO 0x0300
201#define BEE_DATA_LENGHT 6
202#define BEE_HEADER_LENGHT 11
213#define BEE_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
214#define BEE_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
215
216 // End group macro
217// --------------------------------------------------------------- PUBLIC TYPES
226typedef struct
227{
228 // Output pins
229 digital_out_t wa;
230 digital_out_t rst;
231
232 // Input pins
233 digital_in_t int_pin;
234
235 // Modules
236 spi_master_t spi;
237 pin_name_t chip_select;
238
239} bee_t;
240
244typedef struct
245{
246 // Communication gpio pins
247 pin_name_t miso;
248 pin_name_t mosi;
249 pin_name_t sck;
250 pin_name_t cs;
251
252 // Additional gpio pins
253 pin_name_t wa;
254 pin_name_t rst;
255 pin_name_t int_pin;
256
257 // static variable
258 uint32_t spi_speed;
259 spi_master_mode_t spi_mode;
260 spi_master_chip_select_polarity_t cs_polarity;
261
262} bee_cfg_t;
263
264 // End types group
265// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
266
271#ifdef __cplusplus
272extern "C"{
273#endif
274
284
293err_t bee_init ( bee_t *ctx, bee_cfg_t *cfg );
294
306void bee_generic_transfer ( bee_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
307
319void bee_write_byte_short ( bee_t *ctx, uint8_t reg_address, uint8_t write_data );
320
331uint8_t bee_read_byte_short ( bee_t *ctx, uint8_t reg_address );
332
343void bee_write_byte_long ( bee_t *ctx, uint16_t reg_address, uint8_t write_data );
344
354uint8_t bee_read_byte_long ( bee_t *ctx, uint16_t reg_address );
355
369void bee_hw_reset ( bee_t *ctx );
370
383void bee_power_reset ( bee_t *ctx );
384
397void bee_bb_reset ( bee_t *ctx );
398
411void bee_mac_reset ( bee_t *ctx );
412
425void bee_soft_reset ( bee_t *ctx );
426
439void bee_rf_reset ( bee_t *ctx );
440
459
474void bee_set_channel ( bee_t *ctx, uint8_t n_channel );
475
497void bee_set_cca_mode ( bee_t *ctx, uint8_t cca_mode );
498
511void bee_set_rssi_mode ( bee_t *ctx, uint8_t rssi_mode );
512
524
536
548
558void bee_set_ack ( bee_t *ctx );
559
569void bee_set_not_ack ( bee_t *ctx );
570
581
592
607
625
646void bee_set_reception_mode ( bee_t *ctx, uint8_t r_mode );
647
666void bee_set_frame_format_filter ( bee_t *ctx, uint8_t fff_mode );
667
679
689void bee_set_short_address ( bee_t *ctx, uint8_t *short_address );
690
701void bee_set_long_address ( bee_t *ctx, uint8_t *long_address );
702
713void bee_set_pan_id ( bee_t *ctx, uint8_t *pan_id );
714
726
738void bee_hw_wake_up ( bee_t *ctx );
739
749void bee_enable_pll ( bee_t *ctx );
750
760void bee_disable_pll ( bee_t *ctx );
761
772void bee_set_tx_power ( bee_t *ctx, uint8_t tx_power );
773
798void bee_basic_init ( bee_t *ctx );
799
815
830
845
856void bee_read_rx_fifo ( bee_t *ctx, uint8_t *rx_data );
857
869void bee_write_tx_normal_fifo ( bee_t *ctx, uint16_t address_tx_normal_fifo, uint8_t *tx_data );
870
883uint8_t bee_interrupt ( bee_t *ctx );
884
885#ifdef __cplusplus
886}
887#endif
888#endif // _BEE_H_
889
890 // End public_function group
892
893// ------------------------------------------------------------------------- END
void bee_generic_transfer(bee_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void bee_basic_init(bee_t *ctx)
Basic initialization module function.
void bee_soft_reset(bee_t *ctx)
Soft reset function.
void bee_set_ack(bee_t *ctx)
Set ACK request function.
void bee_power_reset(bee_t *ctx)
Power reset function.
void bee_write_byte_short(bee_t *ctx, uint8_t reg_address, uint8_t write_data)
Write the byte of data to the short register address function.
void bee_set_reception_mode(bee_t *ctx, uint8_t r_mode)
Set reception mode function.
void bee_read_rx_fifo(bee_t *ctx, uint8_t *rx_data)
Read RX FIFO function.
uint8_t bee_interrupt_activity(bee_t *ctx)
Check interrupt activity function.
void bee_set_short_address(bee_t *ctx, uint8_t *short_address)
Set short address function.
void bee_disable_pll(bee_t *ctx)
Disable PLL function.
uint8_t bee_read_byte_long(bee_t *ctx, uint16_t reg_address)
Read the byte of data from the long register address function.
void bee_set_pan_id(bee_t *ctx, uint8_t *pan_id)
Set PAN ID function.
void bee_write_tx_normal_fifo(bee_t *ctx, uint16_t address_tx_normal_fifo, uint8_t *tx_data)
Write TX normal FIFO function.
void bee_bb_reset(bee_t *ctx)
Baseband reset function.
void bee_hw_wake_up(bee_t *ctx)
Hardware Wake Up function.
void bee_rf_reset(bee_t *ctx)
RF state machine reset function.
uint8_t bee_read_byte_short(bee_t *ctx, uint8_t reg_address)
Read the byte of data from the short register address function.
void bee_set_tx_power(bee_t *ctx, uint8_t tx_power)
Set scale control for Tx power function.
void bee_set_ifs_default(bee_t *ctx)
Set default interframe spacing function.
void bee_nonbeacon_device(bee_t *ctx)
Set nonbeacon device function.
void bee_set_cca_mode(bee_t *ctx, uint8_t cca_mode)
Set CCA mode function.
void bee_hw_reset(bee_t *ctx)
Hardware reset function.
void bee_flush_rx_fifo_pointer(bee_t *ctx)
Set flush RX FIFO pointer function.
void bee_enable_interrupt(bee_t *ctx)
Enable interrupt function.
void bee_mac_reset(bee_t *ctx)
MAC reset function.
void bee_set_long_address(bee_t *ctx, uint8_t *long_address)
Set long address function.
void bee_nonbeacon_init(bee_t *ctx)
Initialization nonbeacon module function.
void bee_disabl_encrypt(bee_t *ctx)
Disable encrypt function.
void bee_enable_immediate_wake_up(bee_t *ctx)
Enable Immediate Wake-up mode function.
void bee_cfg_setup(bee_cfg_t *cfg)
Config Object Initialization function.
void bee_enable_encrypt(bee_t *ctx)
Set enable encrypt function.
void bee_write_byte_long(bee_t *ctx, uint16_t reg_address, uint8_t write_data)
Write the byte of data to the long register address function.
void bee_set_ifs_recomended(bee_t *ctx)
Set interframe spacing function.
void bee_set_channel(bee_t *ctx, uint8_t n_channel)
Set channel function.
err_t bee_init(bee_t *ctx, bee_cfg_t *cfg)
Initialization function.
void bee_set_not_ack(bee_t *ctx)
Set not ACK request function.
void bee_set_frame_format_filter(bee_t *ctx, uint8_t fff_mode)
Set frame format filter function.
void bee_enable_pll(bee_t *ctx)
Enable PLL function.
void bee_nonbeacon_coordinator_device(bee_t *ctx)
Set device as coordinator function.
void bee_start_transmit(bee_t *ctx)
Start transmission function.
uint8_t bee_interrupt(bee_t *ctx)
Get interrupt state function.
void bee_nonbeacon_pan_coordinator_device(bee_t *ctx)
Set device as PAN coordinator function.
void bee_set_rssi_mode(bee_t *ctx, uint8_t rssi_mode)
Set RSSI mode function.
This file contains SPI specific macros, functions, etc.
Click configuration structure definition.
Definition bee.h:245
pin_name_t wa
Definition bee.h:253
spi_master_chip_select_polarity_t cs_polarity
Definition bee.h:260
pin_name_t sck
Definition bee.h:249
spi_master_mode_t spi_mode
Definition bee.h:259
pin_name_t mosi
Definition bee.h:248
uint32_t spi_speed
Definition bee.h:258
pin_name_t int_pin
Definition bee.h:255
pin_name_t miso
Definition bee.h:247
pin_name_t rst
Definition bee.h:254
pin_name_t cs
Definition bee.h:250
Click ctx object definition.
Definition bee.h:227
spi_master_t spi
Definition bee.h:236
digital_out_t wa
Definition bee.h:229
digital_in_t int_pin
Definition bee.h:233
digital_out_t rst
Definition bee.h:230
pin_name_t chip_select
Definition bee.h:237