gsm4  2.0.0.0
gsm4.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 GSM4_H
36 #define GSM4_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 GSM4_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.rst = 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 
67 #define GSM4_RETVAL uint8_t
68 
69 #define GSM4_OK 0x00
70 #define GSM4_INIT_ERROR 0xFF
71 
77 #define GSM4_PARSER_NO_ERROR 0x00
78 #define GSM4_PARSER_ERROR_REF 0x01
79 #define GSM4_PARSER_ERROR_CMD 0x02
80 #define GSM4_PARSER_ERROR_DATA 0x04
81 
87 #define GSM4_STATUS_DEVICE_READY 1
88 #define GSM4_STATUS_ACT_NETWORK_AND_BROKER 4
89 #define GSM4_STATUS_ACT_NETWORK 2
90 #define GSM4_STATUS_ACT_BROKER 3
91 #define GSM4_STATUS_DEVICE_BUSY 0
92 
98 #define GSM4_MODULE_POWER_ON 1
99 #define GSM4_MODULE_POWER_OFF 0
100 
106 #define GSM4_SINGLE_CMD_AT "AT"
107 #define GSM4_SINGLE_CMD_AT_W "AT+W"
108 #define GSM4_SINGLE_CMD_AT_R "AT+R"
109 #define GSM4_SINGLE_CMD_ATE0 "ATE0"
110 #define GSM4_SINGLE_CMD_ATE1 "ATE1"
111 #define GSM4_SINGLE_CMD_AT_RST "AT+RST"
112 #define GSM4_SINGLE_CMD_AT_CRST "AT+CRST"
113 #define GSM4_SINGLE_CMD_AT_GMR "AT+GMR"
114 #define GSM4_SINGLE_CMD_AT_GMSTA "AT+GMSTA"
115 #define GSM4_SINGLE_CMD_AT_PUB "AT+PUB"
116 
117 #define GSM4_SINGLE_CMD_SET_AT_LRSP_1 "AT+LRSP=1"
118 #define GSM4_SINGLE_CMD_SET_AT_LRSP_0 "AT+LRSP=0"
119 #define GSM4_SINGLE_CMD_SET_AT_CEN_1 "AT+CEN=1"
120 #define GSM4_SINGLE_CMD_SET_AT_CEN_0 "AT+CEN=0"
121 #define GSM4_SINGLE_CMD_SET_AT_NWC_1 "AT+NWC=1"
122 #define GSM4_SINGLE_CMD_SET_AT_NWC_0 "AT+NWC=0"
123 #define GSM4_SINGLE_CMD_SET_AT_BRC_1 "AT+BRC=1"
124 #define GSM4_SINGLE_CMD_SET_AT_BRC_0 "AT+BRC=0"
125 #define GSM4_SINGLE_CMD_SET_AT_GPEN_0 "AT+GPEN=0"
126 #define GSM4_SINGLE_CMD_SET_AT_GPEN_1 "AT+GPEN=1"
127 
128 #define GSM4_SINGLE_CMD_GET_AT_LRSP "AT+LRSP?"
129 #define GSM4_SINGLE_CMD_GET_AT_CEN "AT+CEN?"
130 #define GSM4_SINGLE_CMD_GET_AT_NWC "AT+NWC?"
131 #define GSM4_SINGLE_CMD_GET_AT_BRC "AT+BRC?"
132 #define GSM4_SINGLE_CMD_GET_AT_GPEN "AT+GPEN?"
133 #define GSM4_SINGLE_CMD_GET_AT_NWCR "AT+NWCR?"
134 #define GSM4_SINGLE_CMD_GET_AT_BRCR "AT+BRCR?"
135 #define GSM4_SINGLE_CMD_GET_AT_DSET "AT+DSET?"
136 
137 #define GSM4_SINGLE_CMD_TEST_AT_LRSP "AT+LRSP=?"
138 #define GSM4_SINGLE_CMD_TEST_AT_CEN "AT+CEN=?"
139 #define GSM4_SINGLE_CMD_TEST_AT_NWC "AT+NWC=?"
140 #define GSM4_SINGLE_CMD_TEST_AT_BRC "AT+BRC=?"
141 #define GSM4_SINGLE_CMD_TEST_AT_GPEN "AT+GPEN=?"
142 #define GSM4_SINGLE_CMD_TEST_AT_NWCR "AT+NWCR=?"
143 #define GSM4_SINGLE_CMD_TEST_AT_BRCR "AT+BRCR=?"
144 #define GSM4_SINGLE_CMD_TEST_AT_DSET "AT+DSET=?"
145 
146 #define GSM4_MULTI_CMD_AT_DSET "AT+DSET"
147 #define GSM4_MULTI_CMD_AT_BRCR "AT+BRCR"
148 #define GSM4_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 
174  // Input pins
175 
176  digital_in_t stat;
177  digital_in_t ri;
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 } gsm4_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 stat;
202  pin_name_t rst;
203  pin_name_t rts;
204  pin_name_t ri;
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 } gsm4_cfg_t;
216 
220 // Actuator switch type
221 typedef uint8_t gsm4_actuator_sw_t;
222 
223 // Actuator counter type
224 typedef int16_t gsm4_actuator_cnt_t;
225 
226 // Actuator string type
227 typedef char gsm4_actuator_str_t;
228 
229 // Parser error type
230 typedef uint8_t gsm4_error_t;
231  // End types group
233 
234 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
235 
241 #ifdef __cplusplus
242 extern "C"{
243 #endif
244 
254 
271 
279 void gsm4_reset ( gsm4_t *ctx );
280 
290 void gsm4_generic_write ( gsm4_t *ctx, char *data_buf, uint16_t len );
291 
301 int16_t gsm4_generic_read ( gsm4_t *ctx, char *data_buf, uint16_t max_len );
302 
311 void gsm4_send_command ( gsm4_t *ctx, char *command );
312 
313 #ifdef __cplusplus
314 }
315 #endif
316 #endif // _GSM4_H_
317  // End public_function group
320 
321 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: gsm4.h:155
gsm4_t::rts
digital_out_t rts
Definition: gsm4.h:172
gsm4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gsm4.h:211
gsm4_cfg_t::baud_rate
uint32_t baud_rate
Definition: gsm4.h:209
gsm4_cfg_setup
void gsm4_cfg_setup(gsm4_cfg_t *cfg)
Config Object Initialization function.
gsm4_t::uart
uart_t uart
Definition: gsm4.h:182
gsm4_t
Click ctx object definition.
Definition: gsm4.h:168
gsm4_cfg_t::rts
pin_name_t rts
Definition: gsm4.h:203
gsm4_init
GSM4_RETVAL gsm4_init(gsm4_t *ctx, gsm4_cfg_t *cfg)
Initialization function.
gsm4_reset
void gsm4_reset(gsm4_t *ctx)
Reset module.
gsm4_actuator_cnt_t
int16_t gsm4_actuator_cnt_t
Definition: gsm4.h:224
gsm4_cfg_t::stat
pin_name_t stat
Definition: gsm4.h:201
gsm4_error_t
uint8_t gsm4_error_t
Definition: gsm4.h:230
gsm4_generic_read
int16_t gsm4_generic_read(gsm4_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
gsm4_cfg_t::ri
pin_name_t ri
Definition: gsm4.h:204
gsm4_cfg_t::cts
pin_name_t cts
Definition: gsm4.h:205
gsm4_generic_write
void gsm4_generic_write(gsm4_t *ctx, char *data_buf, uint16_t len)
Generic write function.
gsm4_actuator_str_t
char gsm4_actuator_str_t
Definition: gsm4.h:227
gsm4_module_power
void gsm4_module_power(gsm4_t *ctx)
Enables or disables module power.
gsm4_t::rst
digital_out_t rst
Definition: gsm4.h:171
gsm4_t::cts
digital_in_t cts
Definition: gsm4.h:178
gsm4_t::ri
digital_in_t ri
Definition: gsm4.h:177
gsm4_t::stat
digital_in_t stat
Definition: gsm4.h:176
gsm4_cfg_t::rst
pin_name_t rst
Definition: gsm4.h:202
gsm4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gsm4.h:212
gsm4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gsm4.h:213
gsm4_cfg_t
Click configuration structure definition.
Definition: gsm4.h:193
GSM4_RETVAL
#define GSM4_RETVAL
Definition: gsm4.h:67
gsm4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gsm4.h:197
gsm4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gsm4.h:196
gsm4_actuator_sw_t
uint8_t gsm4_actuator_sw_t
Error type.
Definition: gsm4.h:221
gsm4_send_command
void gsm4_send_command(gsm4_t *ctx, char *command)
Command function.
gsm4_cfg_t::uart_blocking
bool uart_blocking
Definition: gsm4.h:210