c3gsara 2.0.0.0
c3gsara.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 C3GSARA_H
29#define C3GSARA_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 C3GSARA_CMD_AT "AT"
74#define C3GSARA_CMD_ATI "ATI"
75#define C3GSARA_CMD_CFUN "AT+CFUN"
76#define C3GSARA_CMD_CREG "AT+CREG"
77#define C3GSARA_CMD_CGDCONT "AT+CGDCONT"
78#define C3GSARA_CMD_CSQ "AT+CSQ"
79#define C3GSARA_CMD_COPS "AT+COPS"
80#define C3GSARA_CMD_CMGS "AT+CMGS"
81#define C3GSARA_CMD_CMGF "AT+CMGF"
82#define C3GSARA_CMD_CGACT "AT+CGACT"
83#define C3GSARA_CMD_UPSDA "AT+UPSDA"
84#define C3GSARA_CMD_USOCR "AT+USOCR"
85#define C3GSARA_CMD_USOCO "AT+USOCO"
86#define C3GSARA_CMD_USOWR "AT+USOWR"
87#define C3GSARA_CMD_USORD "AT+USORD"
88#define C3GSARA_CMD_USORF "AT+USORF"
89#define C3GSARA_CMD_USOCL "AT+USOCL"
90
95#define C3GSARA_RSP_OK "OK"
96#define C3GSARA_RSP_ERROR "ERROR"
97
102#define C3GSARA_POWER_STATE_OFF 0
103#define C3GSARA_POWER_STATE_ON 1
104
110#define C3GSARA_RX_DRV_BUFFER_SIZE 256
111#define C3GSARA_TX_DRV_BUFFER_SIZE 256
112
113 // c3gsara_set
114
129#define C3GSARA_MAP_MIKROBUS( cfg, mikrobus ) \
130 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
131 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
132 cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
133 cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
134 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
135 cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
136 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
137
138 // c3gsara_map
139 // c3gsara
140
145typedef struct
146{
147 // Output pins
148 digital_out_t pwk;
149 digital_out_t rts;
151 // Input pins
152 digital_in_t sta;
153 digital_in_t ring;
154 digital_in_t cts;
156 // Modules
157 uart_t uart;
159 // Buffers
160 char uart_rx_buffer[ C3GSARA_RX_DRV_BUFFER_SIZE ];
161 char uart_tx_buffer[ C3GSARA_TX_DRV_BUFFER_SIZE ];
163} c3gsara_t;
164
169typedef struct
170{
171 // Communication gpio pins
172 pin_name_t rx_pin;
173 pin_name_t tx_pin;
175 // Additional gpio pins
176 pin_name_t sta;
177 pin_name_t pwk;
178 pin_name_t rts;
179 pin_name_t ring;
180 pin_name_t cts;
182 // Static variable
183 uint32_t baud_rate;
185 uart_data_bits_t data_bit;
186 uart_parity_t parity_bit;
187 uart_stop_bits_t stop_bit;
190
204
221
236
249err_t c3gsara_generic_write ( c3gsara_t *ctx, uint8_t *data_in, uint16_t len );
250
263err_t c3gsara_generic_read ( c3gsara_t *ctx, uint8_t *data_out, uint16_t len );
264
275void c3gsara_set_power_state ( c3gsara_t *ctx, uint8_t state );
276
286void c3gsara_set_rts_pin ( c3gsara_t *ctx, uint8_t state );
287
297void c3gsara_set_pwk_pin ( c3gsara_t *ctx, uint8_t state );
298
308
318
328
338void c3gsara_send_cmd ( c3gsara_t *ctx, uint8_t *cmd );
339
350void c3gsara_send_cmd_with_par ( c3gsara_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
351
361void c3gsara_send_cmd_check ( c3gsara_t *ctx, uint8_t *at_cmd_buf );
362
372void c3gsara_send_cmd_par_check ( c3gsara_t *ctx, uint8_t *at_cmd_buf );
373
383void c3gsara_set_sim_apn ( c3gsara_t *ctx, uint8_t *sim_apn );
384
395void c3gsara_send_sms_text ( c3gsara_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
396
410err_t c3gsara_send_sms_pdu ( c3gsara_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
411
412#ifdef __cplusplus
413}
414#endif
415#endif // C3GSARA_H
416
417 // c3gsara
418
419// ------------------------------------------------------------------------ END
c3gsara_return_value_t
3G SARA Click return value data.
Definition c3gsara.h:196
@ C3GSARA_ERROR_TIMEOUT
Definition c3gsara.h:199
@ C3GSARA_ERROR
Definition c3gsara.h:198
@ C3GSARA_OK
Definition c3gsara.h:197
@ C3GSARA_ERROR_CMD
Definition c3gsara.h:200
@ C3GSARA_ERROR_UNKNOWN
Definition c3gsara.h:201
#define C3GSARA_TX_DRV_BUFFER_SIZE
Definition c3gsara.h:111
#define C3GSARA_RX_DRV_BUFFER_SIZE
3G SARA driver buffer size.
Definition c3gsara.h:110
uint8_t c3gsara_get_cts_pin(c3gsara_t *ctx)
3G SARA get cts pin function.
void c3gsara_set_power_state(c3gsara_t *ctx, uint8_t state)
3G SARA set power state function.
void c3gsara_send_cmd_with_par(c3gsara_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
uint8_t c3gsara_get_sta_pin(c3gsara_t *ctx)
3G SARA get sta pin function.
void c3gsara_set_sim_apn(c3gsara_t *ctx, uint8_t *sim_apn)
Set sim card APN.
void c3gsara_cfg_setup(c3gsara_cfg_t *cfg)
3G SARA configuration object setup function.
void c3gsara_send_cmd_par_check(c3gsara_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
err_t c3gsara_generic_read(c3gsara_t *ctx, uint8_t *data_out, uint16_t len)
3G SARA data reading function.
void c3gsara_send_sms_text(c3gsara_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
3G SARA send SMS in text mode.
err_t c3gsara_generic_write(c3gsara_t *ctx, uint8_t *data_in, uint16_t len)
3G SARA data writing function.
uint8_t c3gsara_get_ring_pin(c3gsara_t *ctx)
3G SARA get ring pin function.
err_t c3gsara_send_sms_pdu(c3gsara_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
3G SARA send SMS in PDU mode.
void c3gsara_send_cmd_check(c3gsara_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
err_t c3gsara_init(c3gsara_t *ctx, c3gsara_cfg_t *cfg)
3G SARA initialization function.
void c3gsara_set_rts_pin(c3gsara_t *ctx, uint8_t state)
3G SARA set rts pin function.
void c3gsara_set_pwk_pin(c3gsara_t *ctx, uint8_t state)
3G SARA set pwk pin function.
void c3gsara_send_cmd(c3gsara_t *ctx, uint8_t *cmd)
Send command function.
3G SARA Click configuration object.
Definition c3gsara.h:170
pin_name_t sta
Definition c3gsara.h:176
pin_name_t rts
Definition c3gsara.h:178
uint32_t baud_rate
Definition c3gsara.h:183
pin_name_t pwk
Definition c3gsara.h:177
pin_name_t cts
Definition c3gsara.h:180
pin_name_t ring
Definition c3gsara.h:179
bool uart_blocking
Definition c3gsara.h:184
uart_data_bits_t data_bit
Definition c3gsara.h:185
pin_name_t tx_pin
Definition c3gsara.h:173
pin_name_t rx_pin
Definition c3gsara.h:172
uart_stop_bits_t stop_bit
Definition c3gsara.h:187
uart_parity_t parity_bit
Definition c3gsara.h:186
3G SARA Click context object.
Definition c3gsara.h:146
digital_in_t sta
Definition c3gsara.h:152
digital_out_t rts
Definition c3gsara.h:149
uart_t uart
Definition c3gsara.h:157
digital_in_t cts
Definition c3gsara.h:154
digital_out_t pwk
Definition c3gsara.h:148
digital_in_t ring
Definition c3gsara.h:153