gsm4 2.0.0.0
gsm4.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 GSM4_H
29#define GSM4_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
73#define GSM4_CMD_AT "AT"
74#define GSM4_CMD_CFUN "AT+CFUN"
75#define GSM4_CMD_CREG "AT+CREG"
76#define GSM4_CMD_CGDCONT "AT+CGDCONT"
77#define GSM4_CMD_CSQ "AT+CSQ"
78#define GSM4_CMD_COPS "AT+COPS"
79#define GSM4_CMD_CMGS "AT+CMGS"
80#define GSM4_CMD_CMGF "AT+CMGF"
81#define GSM4_CMD_CGACT "AT+CGACT"
82#define GSM4_CMD_UPSDA "AT+UPSDA"
83#define GSM4_CMD_USOCR "AT+USOCR"
84#define GSM4_CMD_USOCO "AT+USOCO"
85#define GSM4_CMD_USOWR "AT+USOWR"
86#define GSM4_CMD_USORD "AT+USORD"
87#define GSM4_CMD_USORF "AT+USORF"
88#define GSM4_CMD_USOCL "AT+USOCL"
89
94#define GSM4_RSP_OK "OK"
95#define GSM4_RSP_ERROR "ERROR"
96
102#define GSM4_RX_DRV_BUFFER_SIZE 256
103#define GSM4_TX_DRV_BUFFER_SIZE 256
104
105 // gsm4_set
106
121#define GSM4_MAP_MIKROBUS( cfg, mikrobus ) \
122 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
123 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
124 cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
125 cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
126 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
127 cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
128 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
129
130 // gsm4_map
131 // gsm4
132
137typedef struct
138{
139 // Output pins
140 digital_out_t pwr;
141 digital_out_t rts;
143 // Input pins
144 digital_in_t sta;
145 digital_in_t ring;
146 digital_in_t cts;
148 // Modules
149 uart_t uart;
151 // Buffers
152 uint8_t uart_rx_buffer[ GSM4_RX_DRV_BUFFER_SIZE ];
153 uint8_t uart_tx_buffer[ GSM4_TX_DRV_BUFFER_SIZE ];
155} gsm4_t;
156
161typedef struct
162{
163 // Communication gpio pins
164 pin_name_t rx_pin;
165 pin_name_t tx_pin;
167 // Additional gpio pins
168 pin_name_t pwr;
169 pin_name_t rts;
170 pin_name_t ring;
171 pin_name_t sta;
172 pin_name_t cts;
174 // Static variable
175 uint32_t baud_rate;
177 uart_data_bits_t data_bit;
178 uart_parity_t parity_bit;
179 uart_stop_bits_t stop_bit;
181} gsm4_cfg_t;
182
196
213
227err_t gsm4_init ( gsm4_t *ctx, gsm4_cfg_t *cfg );
228
241err_t gsm4_generic_write ( gsm4_t *ctx, uint8_t *data_in, uint16_t len );
242
255err_t gsm4_generic_read ( gsm4_t *ctx, uint8_t *data_out, uint16_t len );
256
266void gsm4_set_rts_pin ( gsm4_t *ctx, uint8_t state );
267
277void gsm4_set_pwr_pin ( gsm4_t *ctx, uint8_t state );
278
287uint8_t gsm4_get_cts_pin ( gsm4_t *ctx );
288
297uint8_t gsm4_get_sta_pin ( gsm4_t *ctx );
298
307uint8_t gsm4_get_ring_pin ( gsm4_t *ctx );
308
318void gsm4_send_cmd ( gsm4_t *ctx, uint8_t *cmd );
319
330void gsm4_send_cmd_with_par ( gsm4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
331
341void gsm4_send_cmd_check ( gsm4_t *ctx, uint8_t *at_cmd_buf );
342
352void gsm4_send_cmd_par_check ( gsm4_t *ctx, uint8_t *at_cmd_buf );
353
363void gsm4_set_sim_apn ( gsm4_t *ctx, uint8_t *sim_apn );
364
375void gsm4_send_sms_text ( gsm4_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
376
390err_t gsm4_send_sms_pdu ( gsm4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
391
392#ifdef __cplusplus
393}
394#endif
395#endif // GSM4_H
396
397 // gsm4
398
399// ------------------------------------------------------------------------ END
#define GSM4_RX_DRV_BUFFER_SIZE
GSM 4 driver buffer size.
Definition gsm4.h:102
#define GSM4_TX_DRV_BUFFER_SIZE
Definition gsm4.h:103
uint8_t gsm4_get_cts_pin(gsm4_t *ctx)
GSM 4 get cts pin function.
void gsm4_set_rts_pin(gsm4_t *ctx, uint8_t state)
GSM 4 set rts pin function.
void gsm4_send_sms_text(gsm4_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
GSM 4 send SMS in text mode.
void gsm4_send_cmd(gsm4_t *ctx, uint8_t *cmd)
Send command function.
void gsm4_set_sim_apn(gsm4_t *ctx, uint8_t *sim_apn)
Set sim card APN.
void gsm4_cfg_setup(gsm4_cfg_t *cfg)
GSM 4 configuration object setup function.
uint8_t gsm4_get_sta_pin(gsm4_t *ctx)
GSM 4 get sta pin function.
err_t gsm4_init(gsm4_t *ctx, gsm4_cfg_t *cfg)
GSM 4 initialization function.
void gsm4_send_cmd_par_check(gsm4_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
uint8_t gsm4_get_ring_pin(gsm4_t *ctx)
GSM 4 get ring pin function.
void gsm4_set_pwr_pin(gsm4_t *ctx, uint8_t state)
GSM 4 set pwr pin function.
err_t gsm4_generic_write(gsm4_t *ctx, uint8_t *data_in, uint16_t len)
GSM 4 data writing function.
void gsm4_send_cmd_check(gsm4_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
void gsm4_send_cmd_with_par(gsm4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
err_t gsm4_send_sms_pdu(gsm4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
GSM 4 send SMS in PDU mode.
err_t gsm4_generic_read(gsm4_t *ctx, uint8_t *data_out, uint16_t len)
GSM 4 data reading function.
gsm4_return_value_t
GSM 4 Click return value data.
Definition gsm4.h:188
@ GSM4_OK
Definition gsm4.h:189
@ GSM4_ERROR_UNKNOWN
Definition gsm4.h:193
@ GSM4_ERROR
Definition gsm4.h:190
@ GSM4_ERROR_TIMEOUT
Definition gsm4.h:191
@ GSM4_ERROR_CMD
Definition gsm4.h:192
GSM 4 Click configuration object.
Definition gsm4.h:162
pin_name_t sta
Definition gsm4.h:171
pin_name_t rts
Definition gsm4.h:169
uint32_t baud_rate
Definition gsm4.h:175
pin_name_t cts
Definition gsm4.h:172
pin_name_t ring
Definition gsm4.h:170
bool uart_blocking
Definition gsm4.h:176
uart_data_bits_t data_bit
Definition gsm4.h:177
pin_name_t tx_pin
Definition gsm4.h:165
pin_name_t pwr
Definition gsm4.h:168
pin_name_t rx_pin
Definition gsm4.h:164
uart_stop_bits_t stop_bit
Definition gsm4.h:179
uart_parity_t parity_bit
Definition gsm4.h:178
GSM 4 Click context object.
Definition gsm4.h:138
digital_in_t sta
Definition gsm4.h:144
digital_out_t pwr
Definition gsm4.h:140
digital_out_t rts
Definition gsm4.h:141
uart_t uart
Definition gsm4.h:149
digital_in_t cts
Definition gsm4.h:146
digital_in_t ring
Definition gsm4.h:145