gsm3  2.0.0.0
gsm3.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 GSM3_H
36 #define GSM3_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 GSM3_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
60  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
61 
67 #define GSM3_RETVAL uint8_t
68 
69 #define GSM3_OK 0x00
70 #define GSM3_INIT_ERROR 0xFF
71 
77 #define GSM3_PARSER_NO_ERROR 0x00
78 #define GSM3_PARSER_ERROR_REF 0x01
79 #define GSM3_PARSER_ERROR_CMD 0x02
80 #define GSM3_PARSER_ERROR_DATA 0x04
81 
87 #define GSM3_STATUS_DEVICE_READY 1
88 #define GSM3_STATUS_ACT_NETWORK_AND_BROKER 4
89 #define GSM3_STATUS_ACT_NETWORK 2
90 #define GSM3_STATUS_ACT_BROKER 3
91 #define GSM3_STATUS_DEVICE_BUSY 0
92 
98 #define GSM3_MODULE_POWER_ON 1
99 #define GSM3_MODULE_POWER_OFF 0
100 
106 #define GSM3_SINGLE_CMD_AT "AT"
107 #define GSM3_SINGLE_CMD_AT_W "AT+W"
108 #define GSM3_SINGLE_CMD_AT_R "AT+R"
109 #define GSM3_SINGLE_CMD_ATE0 "ATE0"
110 #define GSM3_SINGLE_CMD_ATE1 "ATE1"
111 #define GSM3_SINGLE_CMD_AT_RST "AT+RST"
112 #define GSM3_SINGLE_CMD_AT_CRST "AT+CRST"
113 #define GSM3_SINGLE_CMD_AT_GMR "AT+GMR"
114 #define GSM3_SINGLE_CMD_AT_GMSTA "AT+GMSTA"
115 #define GSM3_SINGLE_CMD_AT_PUB "AT+PUB"
116 
117 #define GSM3_SINGLE_CMD_SET_AT_LRSP_1 "AT+LRSP=1"
118 #define GSM3_SINGLE_CMD_SET_AT_LRSP_0 "AT+LRSP=0"
119 #define GSM3_SINGLE_CMD_SET_AT_CEN_1 "AT+CEN=1"
120 #define GSM3_SINGLE_CMD_SET_AT_CEN_0 "AT+CEN=0"
121 #define GSM3_SINGLE_CMD_SET_AT_NWC_1 "AT+NWC=1"
122 #define GSM3_SINGLE_CMD_SET_AT_NWC_0 "AT+NWC=0"
123 #define GSM3_SINGLE_CMD_SET_AT_BRC_1 "AT+BRC=1"
124 #define GSM3_SINGLE_CMD_SET_AT_BRC_0 "AT+BRC=0"
125 #define GSM3_SINGLE_CMD_SET_AT_GPEN_0 "AT+GPEN=0"
126 #define GSM3_SINGLE_CMD_SET_AT_GPEN_1 "AT+GPEN=1"
127 
128 #define GSM3_SINGLE_CMD_GET_AT_LRSP "AT+LRSP?"
129 #define GSM3_SINGLE_CMD_GET_AT_CEN "AT+CEN?"
130 #define GSM3_SINGLE_CMD_GET_AT_NWC "AT+NWC?"
131 #define GSM3_SINGLE_CMD_GET_AT_BRC "AT+BRC?"
132 #define GSM3_SINGLE_CMD_GET_AT_GPEN "AT+GPEN?"
133 #define GSM3_SINGLE_CMD_GET_AT_NWCR "AT+NWCR?"
134 #define GSM3_SINGLE_CMD_GET_AT_BRCR "AT+BRCR?"
135 #define GSM3_SINGLE_CMD_GET_AT_DSET "AT+DSET?"
136 
137 #define GSM3_SINGLE_CMD_TEST_AT_LRSP "AT+LRSP=?"
138 #define GSM3_SINGLE_CMD_TEST_AT_CEN "AT+CEN=?"
139 #define GSM3_SINGLE_CMD_TEST_AT_NWC "AT+NWC=?"
140 #define GSM3_SINGLE_CMD_TEST_AT_BRC "AT+BRC=?"
141 #define GSM3_SINGLE_CMD_TEST_AT_GPEN "AT+GPEN=?"
142 #define GSM3_SINGLE_CMD_TEST_AT_NWCR "AT+NWCR=?"
143 #define GSM3_SINGLE_CMD_TEST_AT_BRCR "AT+BRCR=?"
144 #define GSM3_SINGLE_CMD_TEST_AT_DSET "AT+DSET=?"
145 
146 #define GSM3_MULTI_CMD_AT_DSET "AT+DSET"
147 #define GSM3_MULTI_CMD_AT_BRCR "AT+BRCR"
148 #define GSM3_MULTI_CMD_AT_NWCR "AT+NWCR"
149 
155 #define DRV_RX_BUFFER_SIZE 500
156  // End group macro
159 // --------------------------------------------------------------- PUBLIC TYPES
167 typedef struct
168 {
169  // Output pins
170 
171  digital_out_t rst;
172  digital_out_t rts;
173  digital_out_t pwk;
174 
175  // Input pins
176 
177  digital_in_t sta;
178  digital_in_t cts;
179 
180  // Modules
181 
182  uart_t uart;
183 
184  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
185  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
186 
187 } gsm3_t;
188 
192 typedef struct
193 {
194  // Communication gpio pins
195 
196  pin_name_t rx_pin;
197  pin_name_t tx_pin;
198 
199  // Additional gpio pins
200 
201  pin_name_t sta;
202  pin_name_t rst;
203  pin_name_t rts;
204  pin_name_t pwk;
205  pin_name_t cts;
206 
207  // static variable
208 
209  uint32_t baud_rate; // Clock speed.
211  uart_data_bits_t data_bit; // Data bits.
212  uart_parity_t parity_bit; // Parity bit.
213  uart_stop_bits_t stop_bit; // Stop bits.
214 
215 } gsm3_cfg_t;
216 
220 // Actuator switch type
221 typedef uint8_t gsm3_actuator_sw_t;
222 
223 // Actuator counter type
224 typedef int16_t gsm3_actuator_cnt_t;
225 
226 // Actuator string type
227 typedef char gsm3_actuator_str_t;
228 
229 // Parser error type
230 typedef uint8_t gsm3_error_t;
231  // End types group
233 
234 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
235 
241 #ifdef __cplusplus
242 extern "C"{
243 #endif
244 
253 void gsm3_cfg_setup ( gsm3_cfg_t *cfg );
254 
262 GSM3_RETVAL gsm3_init ( gsm3_t *ctx, gsm3_cfg_t *cfg );
263 
271 void gsm3_module_power( gsm3_t *ctx );
272 
280 void gsm3_reset ( gsm3_t *ctx );
281 
291 void gsm3_generic_write ( gsm3_t *ctx, char *data_buf, uint16_t len );
292 
302 int32_t gsm3_generic_read ( gsm3_t *ctx, char *data_buf, uint16_t max_len );
303 
312 void gsm3_send_command ( gsm3_t *ctx, char *command );
313 
314 #ifdef __cplusplus
315 }
316 #endif
317 #endif // _GSM3_H_
318  // End public_function group
321 
322 // ------------------------------------------------------------------------- END
pin_name_t cts
Definition: gsm3.h:205
void gsm3_module_power(gsm3_t *ctx)
Enables or disables module power.
bool uart_blocking
Definition: gsm3.h:210
int32_t gsm3_generic_read(gsm3_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
Click ctx object definition.
Definition: gsm3.h:167
char gsm3_actuator_str_t
Definition: gsm3.h:227
Click configuration structure definition.
Definition: gsm3.h:192
pin_name_t rx_pin
Definition: gsm3.h:196
void gsm3_generic_write(gsm3_t *ctx, char *data_buf, uint16_t len)
Generic write function.
pin_name_t sta
Definition: gsm3.h:201
digital_in_t sta
Definition: gsm3.h:177
void gsm3_send_command(gsm3_t *ctx, char *command)
Command function.
uart_stop_bits_t stop_bit
Definition: gsm3.h:213
GSM3_RETVAL gsm3_init(gsm3_t *ctx, gsm3_cfg_t *cfg)
Initialization function.
uart_data_bits_t data_bit
Definition: gsm3.h:211
uint8_t gsm3_actuator_sw_t
Error type.
Definition: gsm3.h:221
pin_name_t rts
Definition: gsm3.h:203
uint8_t gsm3_error_t
Definition: gsm3.h:230
pin_name_t tx_pin
Definition: gsm3.h:197
pin_name_t rst
Definition: gsm3.h:202
digital_in_t cts
Definition: gsm3.h:178
#define DRV_RX_BUFFER_SIZE
Definition: gsm3.h:155
#define GSM3_RETVAL
Definition: gsm3.h:67
uint32_t baud_rate
Definition: gsm3.h:209
uart_parity_t parity_bit
Definition: gsm3.h:212
int16_t gsm3_actuator_cnt_t
Definition: gsm3.h:224
digital_out_t rst
Definition: gsm3.h:171
void gsm3_reset(gsm3_t *ctx)
Reset module.
void gsm3_cfg_setup(gsm3_cfg_t *cfg)
Config Object Initialization function.
uart_t uart
Definition: gsm3.h:182
digital_out_t pwk
Definition: gsm3.h:173
pin_name_t pwk
Definition: gsm3.h:204
digital_out_t rts
Definition: gsm3.h:172