spirit  2.0.0.0
spirit.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef SPIRIT_H
29 #define SPIRIT_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
49 // -------------------------------------------------------------- PUBLIC MACROS
59 #define SPIRIT_MAP_MIKROBUS( cfg, mikrobus ) \
60  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
61  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
62  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
63  cfg.cmd = MIKROBUS( mikrobus, MIKROBUS_CS ); \
64  cfg.shd = MIKROBUS( mikrobus, MIKROBUS_PWM )
65 
71 #define SPIRIT_MODULE_POWER_ON 1
72 #define SPIRIT_MODULE_POWER_OFF 0
73 
79 #define DRV_RX_BUFFER_SIZE 500
80 #define DRV_TX_BUFFER_SIZE 200
81 
87 #define SPIRIT_OPERATING_MODE 0x01
88 #define SPIRIT_COMMAND_MODE 0x00
89 
90 #define SPIRIT_MODULE_WAKE_UP 0x01
91 #define SPIRIT_MODULE_SHUTDOWN 0x00
92 
98 #define SPIRIT_CMD_ENTER_COMMAND_MODE "+++"
99 #define SPIRIT_CMD_ENTER_OPERATING_MODE "ATO"
100 #define SPIRIT_CMD_READ_MODULE_VERSION "AT/V"
101 #define SPIRIT_CMD_READ_ALL_CONFIG_REG "AT/S"
102 #define SPIRIT_CMD_STORE_CURRENT_CONFIG "AT/C"
103 #define SPIRIT_CMD_RESET_CONFIG "ATR"
104 #define SPIRIT_CMD_RESET_MODULE "ATZ"
105 
111 #define SPIRIT_CMD_READ_INFO_PER "ATI0"
112 #define SPIRIT_CMD_READ_INFO_PSSI "ATI1"
113 #define SPIRIT_CMD_READ_INFO_LQI "ATI2"
114 #define SPIRIT_CMD_READ_INFO_PQI "ATI3"
115 #define SPIRIT_CMD_READ_INFO_SQI "ATI4"
116 #define SPIRIT_CMD_READ_INFO_PACKET_COUNT "ATI5"
117 #define SPIRIT_CMD_READ_INFO_PACKETS_LOST "ATI6"
118 
124 #define SPIRIT_CMD_CFG_BAUD_RATE "ATS00"
125 #define SPIRIT_CMD_CFG_FREQUENCY "ATS01"
126 #define SPIRIT_CMD_CFG_DATA_RATE "ATS02"
127 #define SPIRIT_CMD_CFG_MODULATION "ATS03"
128 #define SPIRIT_CMD_CFG_OUTPUT_POWER "ATS04"
129 #define SPIRIT_CMD_CFG_FREQ_DEVIATION "ATS05"
130 #define SPIRIT_CMD_CFG_RX_FILTER "ATS06"
131 #define SPIRIT_CMD_CFG_CS_MODE "ATS07"
132 #define SPIRIT_CMD_CFG_RSSI_THRESHOLD "ATS08"
133 #define SPIRIT_CMD_CFG_PREAMBLE_LEN "ATS09"
134 #define SPIRIT_CMD_CFG_SYNC_LENGTH "ATS10"
135 #define SPIRIT_CMD_CFG_SYNC_VALUE "ATS11"
136 #define SPIRIT_CMD_CFG_CRC_MODE "ATS12"
137 #define SPIRIT_CMD_CFG_WHITENING "ATS13"
138 #define SPIRIT_CMD_CFG_FEC "ATS14"
139 #define SPIRIT_CMD_CFG_SOURCE_ADDR "ATS15"
140 #define SPIRIT_CMD_CFG_DESTINATION_ADDR "ATS16"
141 #define SPIRIT_CMD_CFG_MULTICAST_ADDR "ATS17"
142 #define SPIRIT_CMD_CFG_BROADCAST_ADDR "ATS18"
143 #define SPIRIT_CMD_CFG_FILTER_CRC "ATS19"
144 #define SPIRIT_CMD_CFG_FILTER_SOURCE "ATS20"
145 #define SPIRIT_CMD_CFG_FILTER_DESTINATION "ATS21"
146 #define SPIRIT_CMD_CFG_FILTER_MULTICAST "ATS22"
147 #define SPIRIT_CMD_CFG_FILTER_BROADCAST "ATS23"
148 #define SPIRIT_CMD_CFG_TXRX_LED "ATS24"
149 #define SPIRIT_CMD_CFG_ESCAPE_SEQ "ATS26"
150 #define SPIRIT_CMD_CFG_SOURCE_FILT_MASK "ATS27"
151 #define SPIRIT_CMD_CFG_PAYLOAD_SIZE "ATS28"
152 
158 #define SPIRIT_PCFG_ENABLE "1"
159 #define SPIRIT_PCFG_DISABLE "0"
160 
166 #define SPIRIT_PCFG_BAUD_RATE_9600 "9600"
167 #define SPIRIT_PCFG_BAUD_RATE_19200 "19200"
168 #define SPIRIT_PCFG_BAUD_RATE_38400 "38400"
169 #define SPIRIT_PCFG_BAUD_RATE_56000 "56000"
170 #define SPIRIT_PCFG_BAUD_RATE_57600 "57600"
171 #define SPIRIT_PCFG_BAUD_RATE_115200 "115200"
172 #define SPIRIT_PCFG_BAUD_RATE_128000 "128000"
173 #define SPIRIT_PCFG_BAUD_RATE_256000 "256000"
174 
180 #define SPIRIT_PCFG_CSMODE_STATIC_SENSING "0"
181 #define SPIRIT_PCFG_CSMODE_DYNAMIC_SENSING_6dB "1"
182 #define SPIRIT_PCFG_CSMODE_DYNAMIC_SENSING_12dB "2"
183 #define SPIRIT_PCFG_CSMODE_DYNAMIC_SENSING_18dB "3"
184 
190 #define SPIRIT_PCFG_CRCMODE_POLY_0x07 "1"
191 #define SPIRIT_PCFG_CRCMODE_POLY_0x8005 "2"
192 #define SPIRIT_PCFG_CRCMODE_POLY_0x1021 "3"
193 #define SPIRIT_PCFG_CRCMODE_POLY_0x864CFB "4"
194 
200 #define SPIRIT_PCFG_TXRXLED_DISABLED "0"
201 #define SPIRIT_PCFG_TXRXLED_OPEN_DRAIN "1"
202 #define SPIRIT_PCFG_TXRXLED_PUSH_PULL "2"
203 
209 #define SPIRIT_PCFG_MODULATION_2_FSK "0"
210 #define SPIRIT_PCFG_MODULATION_GFSK05 "1"
211 #define SPIRIT_PCFG_MODULATION_GFSK1 "2"
212 #define SPIRIT_PCFG_MODULATION_GMSK "3"
213 #define SPIRIT_PCFG_MODULATION_OOK "4"
214 #define SPIRIT_PCFG_MODULATION_ASK "5"
215 
221 #define SPIRIT_CMD_SET_RF_TEST_MODE_DISABLE "AT/T0"
222 #define SPIRIT_CMD_SET_RF_TEST_MODE_PN9 "AT/T1"
223 #define SPIRIT_CMD_SET_RF_TEST_MODE_CW "AT/T2"
224 
230 typedef struct
231 {
232  // Output pins
233  digital_out_t rst;
234  digital_out_t cmd;
235  digital_out_t shd;
237  // Modules
238  uart_t uart;
240  // Buffers
241  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
242  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
244 } spirit_t;
245 
250 typedef struct
251 {
252  // Communication gpio pins
253 
254  pin_name_t rx_pin;
255  pin_name_t tx_pin;
257  // Additional gpio pins
258 
259  pin_name_t rst;
260  pin_name_t cmd;
261  pin_name_t shd;
263  // Static variable
264 
265  uint32_t baud_rate;
267  uart_data_bits_t data_bit;
268  uart_parity_t parity_bit;
269  uart_stop_bits_t stop_bit;
271 } spirit_cfg_t;
272 
277 typedef enum
278 {
280  SPIRIT_ERROR = -1
281 
283 
300 
315 err_t spirit_init ( spirit_t *ctx, spirit_cfg_t *cfg );
316 
325 void spirit_power_module ( spirit_t *ctx, uint8_t power_state );
326 
334 void spirit_reset ( spirit_t *ctx );
335 
344 void spirit_set_mode ( spirit_t *ctx, uint8_t mode );
345 
359 void spirit_generic_write ( spirit_t *ctx, char *data_buf, uint16_t len );
360 
374 int32_t spirit_generic_read ( spirit_t *ctx, char *data_buf, uint16_t max_len );
375 
385 void spirit_send_cmd ( spirit_t *ctx, char *cmd );
386 
397 void spirit_send_cmd_with_parameter ( spirit_t *ctx, char *at_cmd_buf, char *param_buf );
398 
408 void spirit_send_cmd_check ( spirit_t *ctx, char *at_cmd_buf );
409 
419 void spirit_send_cmd_parameter_check ( spirit_t *ctx, char *at_cmd_buf );
420 
421 #ifdef __cplusplus
422 }
423 #endif
424 #endif // SPIRIT_H
425  // spirit
427 
428 // ------------------------------------------------------------------------ END
spirit_t
SPIRIT Click context object.
Definition: spirit.h:231
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: spirit.h:79
SPIRIT_ERROR
@ SPIRIT_ERROR
Definition: spirit.h:280
spirit_cfg_t::cmd
pin_name_t cmd
Definition: spirit.h:260
SPIRIT_OK
@ SPIRIT_OK
Definition: spirit.h:279
spirit_generic_read
int32_t spirit_generic_read(spirit_t *ctx, char *data_buf, uint16_t max_len)
SPIRIT data reading function.
spirit_send_cmd_with_parameter
void spirit_send_cmd_with_parameter(spirit_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
spirit_cfg_t::baud_rate
uint32_t baud_rate
Definition: spirit.h:265
spirit_t::uart
uart_t uart
Definition: spirit.h:238
spirit_cfg_t::shd
pin_name_t shd
Definition: spirit.h:261
spirit_send_cmd_parameter_check
void spirit_send_cmd_parameter_check(spirit_t *ctx, char *at_cmd_buf)
Check the command parameters.
spirit_return_value_t
spirit_return_value_t
SPIRIT Click return value data.
Definition: spirit.h:278
spirit_cfg_t::rx_pin
pin_name_t rx_pin
Definition: spirit.h:254
spirit_cfg_setup
void spirit_cfg_setup(spirit_cfg_t *cfg)
SPIRIT configuration object setup function.
spirit_t::rst
digital_out_t rst
Definition: spirit.h:233
spirit_send_cmd
void spirit_send_cmd(spirit_t *ctx, char *cmd)
Send command function.
spirit_t::cmd
digital_out_t cmd
Definition: spirit.h:234
spirit_cfg_t::uart_blocking
bool uart_blocking
Definition: spirit.h:266
spirit_t::shd
digital_out_t shd
Definition: spirit.h:235
spirit_set_mode
void spirit_set_mode(spirit_t *ctx, uint8_t mode)
Set mode function.
spirit_init
err_t spirit_init(spirit_t *ctx, spirit_cfg_t *cfg)
SPIRIT initialization function.
spirit_generic_write
void spirit_generic_write(spirit_t *ctx, char *data_buf, uint16_t len)
SPIRIT data writing function.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: spirit.h:80
spirit_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: spirit.h:269
spirit_cfg_t
SPIRIT Click configuration object.
Definition: spirit.h:251
spirit_reset
void spirit_reset(spirit_t *ctx)
Software reset function.
spirit_cfg_t::tx_pin
pin_name_t tx_pin
Definition: spirit.h:255
spirit_cfg_t::rst
pin_name_t rst
Definition: spirit.h:259
spirit_power_module
void spirit_power_module(spirit_t *ctx, uint8_t power_state)
Power module function.
spirit_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: spirit.h:267
spirit_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: spirit.h:268
spirit_send_cmd_check
void spirit_send_cmd_check(spirit_t *ctx, char *at_cmd_buf)
Check the sent command.