gsm2  2.0.0.0
gsm2.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 GSM2_H
36 #define GSM2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define GSM2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.stat = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.pwrkey = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
60  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
61 
68 #define GSM2_RETVAL uint8_t
69 
70 #define GSM2_OK 0x00
71 #define GSM2_INIT_ERROR 0xFF
72 
78 #define GSM2_PARSER_NO_ERROR 0x00
79 #define GSM2_PARSER_ERROR_REF 0x01
80 #define GSM2_PARSER_ERROR_CMD 0x02
81 #define GSM2_PARSER_ERROR_DATA 0x04
82 
88 #define GSM2_STATUS_DEVICE_READY 1
89 #define GSM2_STATUS_ACT_NETWORK_AND_BROKER 4
90 #define GSM2_STATUS_ACT_NETWORK 2
91 #define GSM2_STATUS_ACT_BROKER 3
92 #define GSM2_STATUS_DEVICE_BUSY 0
93 
99 #define GSM2_MODULE_POWER_ON 1
100 #define GSM2_MODULE_POWER_OFF 0
101 
107 #define GSM2_SINGLE_CMD_AT "AT"
108 #define GSM2_SINGLE_CMD_AT_W "AT+W"
109 #define GSM2_SINGLE_CMD_AT_R "AT+R"
110 #define GSM2_SINGLE_CMD_ATE0 "ATE0"
111 #define GSM2_SINGLE_CMD_ATE1 "ATE1"
112 #define GSM2_SINGLE_CMD_AT_RST "AT+RST"
113 #define GSM2_SINGLE_CMD_AT_CRST "AT+CRST"
114 #define GSM2_SINGLE_CMD_AT_GMR "AT+GMR"
115 #define GSM2_SINGLE_CMD_AT_GMSTA "AT+GMSTA"
116 #define GSM2_SINGLE_CMD_AT_PUB "AT+PUB"
117 
118 #define GSM2_SINGLE_CMD_SET_AT_LRSP_1 "AT+LRSP=1"
119 #define GSM2_SINGLE_CMD_SET_AT_LRSP_0 "AT+LRSP=0"
120 #define GSM2_SINGLE_CMD_SET_AT_CEN_1 "AT+CEN=1"
121 #define GSM2_SINGLE_CMD_SET_AT_CEN_0 "AT+CEN=0"
122 #define GSM2_SINGLE_CMD_SET_AT_NWC_1 "AT+NWC=1"
123 #define GSM2_SINGLE_CMD_SET_AT_NWC_0 "AT+NWC=0"
124 #define GSM2_SINGLE_CMD_SET_AT_BRC_1 "AT+BRC=1"
125 #define GSM2_SINGLE_CMD_SET_AT_BRC_0 "AT+BRC=0"
126 #define GSM2_SINGLE_CMD_SET_AT_GPEN_0 "AT+GPEN=0"
127 #define GSM2_SINGLE_CMD_SET_AT_GPEN_1 "AT+GPEN=1"
128 
129 #define GSM2_SINGLE_CMD_GET_AT_LRSP "AT+LRSP?"
130 #define GSM2_SINGLE_CMD_GET_AT_CEN "AT+CEN?"
131 #define GSM2_SINGLE_CMD_GET_AT_NWC "AT+NWC?"
132 #define GSM2_SINGLE_CMD_GET_AT_BRC "AT+BRC?"
133 #define GSM2_SINGLE_CMD_GET_AT_GPEN "AT+GPEN?"
134 #define GSM2_SINGLE_CMD_GET_AT_NWCR "AT+NWCR?"
135 #define GSM2_SINGLE_CMD_GET_AT_BRCR "AT+BRCR?"
136 #define GSM2_SINGLE_CMD_GET_AT_DSET "AT+DSET?"
137 
138 #define GSM2_SINGLE_CMD_TEST_AT_LRSP "AT+LRSP=?"
139 #define GSM2_SINGLE_CMD_TEST_AT_CEN "AT+CEN=?"
140 #define GSM2_SINGLE_CMD_TEST_AT_NWC "AT+NWC=?"
141 #define GSM2_SINGLE_CMD_TEST_AT_BRC "AT+BRC=?"
142 #define GSM2_SINGLE_CMD_TEST_AT_GPEN "AT+GPEN=?"
143 #define GSM2_SINGLE_CMD_TEST_AT_NWCR "AT+NWCR=?"
144 #define GSM2_SINGLE_CMD_TEST_AT_BRCR "AT+BRCR=?"
145 #define GSM2_SINGLE_CMD_TEST_AT_DSET "AT+DSET=?"
146 
147 #define GSM2_MULTI_CMD_AT_DSET "AT+DSET"
148 #define GSM2_MULTI_CMD_AT_BRCR "AT+BRCR"
149 #define GSM2_MULTI_CMD_AT_NWCR "AT+NWCR"
150 
156 #define DRV_RX_BUFFER_SIZE 500
157  // End group macro
160 // --------------------------------------------------------------- PUBLIC TYPES
168 typedef struct
169 {
170  // Output pins
171 
172  digital_out_t pwrkey;
173  digital_out_t rts;
174 
175  // Input pins
176 
177  digital_in_t stat;
178  digital_in_t ri;
179  digital_in_t cts;
180 
181  // Modules
182 
183  uart_t uart;
184 
185  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
186  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
187 
188 } gsm2_t;
189 
193 typedef struct
194 {
195  // Communication gpio pins
196 
197  pin_name_t rx_pin;
198  pin_name_t tx_pin;
199 
200  // Additional gpio pins
201 
202  pin_name_t stat;
203  pin_name_t pwrkey;
204  pin_name_t rts;
205  pin_name_t ri;
206  pin_name_t cts;
207 
208  // static variable
209 
210  uint32_t baud_rate; // Clock speed.
212  uart_data_bits_t data_bit; // Data bits.
213  uart_parity_t parity_bit; // Parity bit.
214  uart_stop_bits_t stop_bit; // Stop bits.
215 
216 } gsm2_cfg_t;
217 
221 // Actuator switch type
222 typedef uint8_t gsm2_actuator_sw_t;
223 
224 // Actuator counter type
225 typedef int16_t gsm2_actuator_cnt_t;
226 
227 // Actuator string type
228 typedef char gsm2_actuator_str_t;
229 
230 // Parser error type
231 typedef uint8_t gsm2_error_t;
232  // End types group
234 
235 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
236 
242 #ifdef __cplusplus
243 extern "C"{
244 #endif
245 
254 void gsm2_cfg_setup ( gsm2_cfg_t *cfg );
255 
263 GSM2_RETVAL gsm2_init ( gsm2_t *ctx, gsm2_cfg_t *cfg );
264 
272 void gsm2_module_power( gsm2_t *ctx );
273 
281 void gsm2_reset ( gsm2_t *ctx );
282 
292 void gsm2_generic_write ( gsm2_t *ctx, char *data_buf, uint16_t len );
293 
303 int32_t gsm2_generic_read ( gsm2_t *ctx, char *data_buf, uint16_t max_len );
304 
313 void gsm2_send_command ( gsm2_t *ctx, char *command );
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 #endif // _GSM2_H_
319  // End public_function group
322 
323 // ------------------------------------------------------------------------- END
gsm2_t::uart
uart_t uart
Definition: gsm2.h:183
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: gsm2.h:156
gsm2_send_command
void gsm2_send_command(gsm2_t *ctx, char *command)
Command function.
gsm2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gsm2.h:198
gsm2_cfg_t::stat
pin_name_t stat
Definition: gsm2.h:202
gsm2_error_t
uint8_t gsm2_error_t
Definition: gsm2.h:231
gsm2_cfg_t::ri
pin_name_t ri
Definition: gsm2.h:205
gsm2_t
Click ctx object definition.
Definition: gsm2.h:168
gsm2_cfg_t::cts
pin_name_t cts
Definition: gsm2.h:206
gsm2_cfg_setup
void gsm2_cfg_setup(gsm2_cfg_t *cfg)
Config Object Initialization function.
gsm2_actuator_str_t
char gsm2_actuator_str_t
Definition: gsm2.h:228
gsm2_actuator_sw_t
uint8_t gsm2_actuator_sw_t
Error type.
Definition: gsm2.h:222
gsm2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gsm2.h:197
gsm2_t::pwrkey
digital_out_t pwrkey
Definition: gsm2.h:172
gsm2_cfg_t::baud_rate
uint32_t baud_rate
Definition: gsm2.h:210
gsm2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gsm2.h:213
gsm2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gsm2.h:214
gsm2_cfg_t::rts
pin_name_t rts
Definition: gsm2.h:204
gsm2_t::cts
digital_in_t cts
Definition: gsm2.h:179
gsm2_module_power
void gsm2_module_power(gsm2_t *ctx)
Enables or disables module power.
gsm2_t::ri
digital_in_t ri
Definition: gsm2.h:178
gsm2_generic_read
int32_t gsm2_generic_read(gsm2_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
GSM2_RETVAL
#define GSM2_RETVAL
Definition: gsm2.h:68
gsm2_actuator_cnt_t
int16_t gsm2_actuator_cnt_t
Definition: gsm2.h:225
gsm2_cfg_t::uart_blocking
bool uart_blocking
Definition: gsm2.h:211
gsm2_cfg_t::pwrkey
pin_name_t pwrkey
Definition: gsm2.h:203
gsm2_cfg_t
Click configuration structure definition.
Definition: gsm2.h:193
gsm2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gsm2.h:212
gsm2_t::stat
digital_in_t stat
Definition: gsm2.h:177
gsm2_generic_write
void gsm2_generic_write(gsm2_t *ctx, char *data_buf, uint16_t len)
Generic write function.
gsm2_init
GSM2_RETVAL gsm2_init(gsm2_t *ctx, gsm2_cfg_t *cfg)
Initialization function.
gsm2_reset
void gsm2_reset(gsm2_t *ctx)
Reset module.
gsm2_t::rts
digital_out_t rts
Definition: gsm2.h:173