spirit  2.0.0.0
spirit.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 SPIRIT_H
36 #define SPIRIT_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define SPIRIT_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.cmd = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.shd = MIKROBUS( mikrobus, MIKROBUS_PWM )
58 
64 #define SPIRIT_RETVAL uint8_t
65 
66 #define SPIRIT_OK 0x00
67 #define SPIRIT_INIT_ERROR 0xFF
68 
74 #define SPIRIT_MODULE_POWER_ON 1
75 #define SPIRIT_MODULE_POWER_OFF 0
76 
82 #define DRV_RX_BUFFER_SIZE 500
83 #define DRV_TX_BUFFER_SIZE 200
84 
90 #define SPIRIT_OPERATING_MODE 0x01
91 #define SPIRIT_COMMAND_MODE 0x00
92 
93 #define SPIRIT_MODULE_WAKE_UP 0x01
94 #define SPIRIT_MODULE_SHUTDOWN 0x00
95 
101 #define SPIRIT_CMD_ENTER_COMMAND_MODE "+++"
102 #define SPIRIT_CMD_ENTER_OPERATING_MODE "ATO"
103 #define SPIRIT_CMD_READ_MODULE_VERSION "AT/V"
104 #define SPIRIT_CMD_READ_ALL_CONFIG_REG "AT/S"
105 #define SPIRIT_CMD_STORE_CURRENT_CONFIG "AT/C"
106 #define SPIRIT_CMD_RESET_CONFIG "ATR"
107 #define SPIRIT_CMD_RESET_MODULE "ATZ"
108 
114 #define SPIRIT_CMD_READ_INFO_PER "ATI0"
115 #define SPIRIT_CMD_READ_INFO_PSSI "ATI1"
116 #define SPIRIT_CMD_READ_INFO_LQI "ATI2"
117 #define SPIRIT_CMD_READ_INFO_PQI "ATI3"
118 #define SPIRIT_CMD_READ_INFO_SQI "ATI4"
119 #define SPIRIT_CMD_READ_INFO_PACKET_COUNT "ATI5"
120 #define SPIRIT_CMD_READ_INFO_PACKETS_LOST "ATI6"
121 
127 #define SPIRIT_CMD_CFG_BAUD_RATE "ATS00"
128 #define SPIRIT_CMD_CFG_FREQUENCY "ATS01"
129 #define SPIRIT_CMD_CFG_DATA_RATE "ATS02"
130 #define SPIRIT_CMD_CFG_MODULATION "ATS03"
131 #define SPIRIT_CMD_CFG_OUTPUT_POWER "ATS04"
132 #define SPIRIT_CMD_CFG_FREQ_DEVIATION "ATS05"
133 #define SPIRIT_CMD_CFG_RX_FILTER "ATS06"
134 #define SPIRIT_CMD_CFG_CS_MODE "ATS07"
135 #define SPIRIT_CMD_CFG_RSSI_THRESHOLD "ATS08"
136 #define SPIRIT_CMD_CFG_PREAMBLE_LEN "ATS09"
137 #define SPIRIT_CMD_CFG_SYNC_LENGTH "ATS10"
138 #define SPIRIT_CMD_CFG_SYNC_VALUE "ATS11"
139 #define SPIRIT_CMD_CFG_CRC_MODE "ATS12"
140 #define SPIRIT_CMD_CFG_WHITENING "ATS13"
141 #define SPIRIT_CMD_CFG_FEC "ATS14"
142 #define SPIRIT_CMD_CFG_SOURCE_ADDR "ATS15"
143 #define SPIRIT_CMD_CFG_DESTINATION_ADDR "ATS16"
144 #define SPIRIT_CMD_CFG_MULTICAST_ADDR "ATS17"
145 #define SPIRIT_CMD_CFG_BROADCAST_ADDR "ATS18"
146 #define SPIRIT_CMD_CFG_FILTER_CRC "ATS19"
147 #define SPIRIT_CMD_CFG_FILTER_SOURCE "ATS20"
148 #define SPIRIT_CMD_CFG_FILTER_DESTINATION "ATS21"
149 #define SPIRIT_CMD_CFG_FILTER_MULTICAST "ATS22"
150 #define SPIRIT_CMD_CFG_FILTER_BROADCAST "ATS23"
151 #define SPIRIT_CMD_CFG_TXRX_LED "ATS24"
152 #define SPIRIT_CMD_CFG_ESCAPE_SEQ "ATS26"
153 #define SPIRIT_CMD_CFG_SOURCE_FILT_MASK "ATS27"
154 #define SPIRIT_CMD_CFG_PAYLOAD_SIZE "ATS28"
155 
161 #define SPIRIT_PCFG_ENABLE "1"
162 #define SPIRIT_PCFG_DISABLE "0"
163 
169 #define SPIRIT_PCFG_BAUD_RATE_9600 "9600"
170 #define SPIRIT_PCFG_BAUD_RATE_19200 "19200"
171 #define SPIRIT_PCFG_BAUD_RATE_38400 "38400"
172 #define SPIRIT_PCFG_BAUD_RATE_56000 "56000"
173 #define SPIRIT_PCFG_BAUD_RATE_57600 "57600"
174 #define SPIRIT_PCFG_BAUD_RATE_115200 "115200"
175 #define SPIRIT_PCFG_BAUD_RATE_128000 "128000"
176 #define SPIRIT_PCFG_BAUD_RATE_256000 "256000"
177 
183 #define SPIRIT_PCFG_CSMODE_STATIC_SENSING "0"
184 #define SPIRIT_PCFG_CSMODE_DYNAMIC_SENSING_6dB "1"
185 #define SPIRIT_PCFG_CSMODE_DYNAMIC_SENSING_12dB "2"
186 #define SPIRIT_PCFG_CSMODE_DYNAMIC_SENSING_18dB "3"
187 
193 #define SPIRIT_PCFG_CRCMODE_POLY_0x07 "1"
194 #define SPIRIT_PCFG_CRCMODE_POLY_0x8005 "2"
195 #define SPIRIT_PCFG_CRCMODE_POLY_0x1021 "3"
196 #define SPIRIT_PCFG_CRCMODE_POLY_0x864CFB "4"
197 
203 #define SPIRIT_PCFG_TXRXLED_DISABLED "0"
204 #define SPIRIT_PCFG_TXRXLED_OPEN_DRAIN "1"
205 #define SPIRIT_PCFG_TXRXLED_PUSH_PULL "2"
206 
212 #define SPIRIT_PCFG_MODULATION_2_FSK "0"
213 #define SPIRIT_PCFG_MODULATION_GFSK05 "1"
214 #define SPIRIT_PCFG_MODULATION_GFSK1 "2"
215 #define SPIRIT_PCFG_MODULATION_GMSK "3"
216 #define SPIRIT_PCFG_MODULATION_OOK "4"
217 #define SPIRIT_PCFG_MODULATION_ASK "5"
218 
224 #define SPIRIT_CMD_SET_RF_TEST_MODE_DISABLE "AT/T0"
225 #define SPIRIT_CMD_SET_RF_TEST_MODE_PN9 "AT/T1"
226 #define SPIRIT_CMD_SET_RF_TEST_MODE_CW "AT/T2"
227  // End group macro
230 // --------------------------------------------------------------- PUBLIC TYPES
238 typedef struct
239 {
240  // Output pins
241 
242  digital_out_t rst;
243  digital_out_t cmd;
244  digital_out_t shd;
245 
246  // Modules
247 
248  uart_t uart;
249 
250  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
251  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
252 
253 } spirit_t;
254 
258 typedef struct
259 {
260  // Communication gpio pins
261 
262  pin_name_t rx_pin;
263  pin_name_t tx_pin;
264 
265  // Additional gpio pins
266 
267  pin_name_t rst;
268  pin_name_t cmd;
269  pin_name_t shd;
270 
271  // static variable
272 
273  uint32_t baud_rate; // Clock speed.
275  uart_data_bits_t data_bit; // Data bits.
276  uart_parity_t parity_bit; // Parity bit.
277  uart_stop_bits_t stop_bit; // Stop bits.
278 
279 } spirit_cfg_t;
280 
284 // Actuator string type
286 
287 // Parser error type
288 typedef uint8_t spirit_error_t;
289  // End types group
291 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
292 
298 #ifdef __cplusplus
299 extern "C"{
300 #endif
301 
310 void spirit_cfg_setup ( spirit_cfg_t *cfg );
311 
320 
327 void spirit_power_module ( spirit_t *ctx, uint8_t power_state );
328 
334 void spirit_reset ( spirit_t *ctx );
335 
342 void spirit_set_mode ( spirit_t *ctx, uint8_t mode );
343 
351 void spirit_generic_write ( spirit_t *ctx, char *data_buf, uint16_t len );
352 
362 int32_t spirit_generic_read ( spirit_t *ctx, char *data_buf, uint16_t max_len );
363 
373 void spirit_send_cmd ( spirit_t *ctx, char *cmd );
374 
385 void spirit_send_cmd_with_parameter ( spirit_t *ctx, char *at_cmd_buf, char *param_buf );
386 
396 void spirit_send_cmd_check ( spirit_t *ctx, char *at_cmd_buf );
397 
407 void spirit_send_cmd_parameter_check ( spirit_t *ctx, char *at_cmd_buf );
408 
409 #ifdef __cplusplus
410 }
411 #endif
412 #endif // _SPIRIT_H_
413  // End public_function group
416 
417 // ------------------------------------------------------------------------- END
spirit_t
Click ctx object definition.
Definition: spirit.h:238
spirit_set_mode
void spirit_set_mode(spirit_t *ctx, uint8_t mode)
Set mode function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: spirit.h:82
spirit_cfg_t::cmd
pin_name_t cmd
Definition: spirit.h:268
spirit_send_cmd_check
void spirit_send_cmd_check(spirit_t *ctx, char *at_cmd_buf)
Check the sent command.
spirit_t::shd
digital_out_t shd
Definition: spirit.h:244
spirit_cfg_t::tx_pin
pin_name_t tx_pin
Definition: spirit.h:263
spirit_cfg_t::shd
pin_name_t shd
Definition: spirit.h:269
spirit_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: spirit.h:275
spirit_generic_read
int32_t spirit_generic_read(spirit_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
spirit_cfg_t::baud_rate
uint32_t baud_rate
Definition: spirit.h:273
spirit_power_module
void spirit_power_module(spirit_t *ctx, uint8_t power_state)
Power module function.
spirit_init
SPIRIT_RETVAL spirit_init(spirit_t *ctx, spirit_cfg_t *cfg)
Initialization function.
spirit_actuator_str_t
char spirit_actuator_str_t
Error type.
Definition: spirit.h:285
spirit_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: spirit.h:277
SPIRIT_RETVAL
#define SPIRIT_RETVAL
Definition: spirit.h:64
spirit_cfg_t::rx_pin
pin_name_t rx_pin
Definition: spirit.h:262
spirit_reset
void spirit_reset(spirit_t *ctx)
Software reset function.
spirit_t::rst
digital_out_t rst
Definition: spirit.h:242
spirit_cfg_t::uart_blocking
bool uart_blocking
Definition: spirit.h:274
spirit_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: spirit.h:276
spirit_t::cmd
digital_out_t cmd
Definition: spirit.h:243
spirit_cfg_setup
void spirit_cfg_setup(spirit_cfg_t *cfg)
Config Object Initialization function.
spirit_error_t
uint8_t spirit_error_t
Definition: spirit.h:288
spirit_generic_write
void spirit_generic_write(spirit_t *ctx, char *data_buf, uint16_t len)
Generic write function.
spirit_cfg_t::rst
pin_name_t rst
Definition: spirit.h:267
spirit_cfg_t
Click configuration structure definition.
Definition: spirit.h:258
spirit_send_cmd_parameter_check
void spirit_send_cmd_parameter_check(spirit_t *ctx, char *at_cmd_buf)
Check the command parameters.
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_t::uart
uart_t uart
Definition: spirit.h:248
spirit_send_cmd
void spirit_send_cmd(spirit_t *ctx, char *cmd)
Send command function.