c4glteapj  2.0.0.0
c4glteapj.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 C4GLTEAPJ_H
29 #define C4GLTEAPJ_H
30 
31 #ifdef __cplusplus
32 extern "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 C4GLTEAPJ_CMD_AT "AT"
74 #define C4GLTEAPJ_CMD_ATI "ATI"
75 #define C4GLTEAPJ_CMD_CGMR "AT+CGMR"
76 #define C4GLTEAPJ_CMD_CFUN "AT+CFUN"
77 #define C4GLTEAPJ_CMD_CREG "AT+CREG"
78 #define C4GLTEAPJ_CMD_CGREG "AT+CGREG"
79 #define C4GLTEAPJ_CMD_CGDCONT "AT+CGDCONT"
80 #define C4GLTEAPJ_CMD_CIMI "AT+CIMI"
81 #define C4GLTEAPJ_CMD_CMEE "AT+CMEE"
82 #define C4GLTEAPJ_CMD_CGATT "AT+CGATT"
83 #define C4GLTEAPJ_CMD_CSQ "AT+CSQ"
84 #define C4GLTEAPJ_CMD_COPS "AT+COPS"
85 #define C4GLTEAPJ_CMD_CMGS "AT+CMGS"
86 #define C4GLTEAPJ_CMD_CMGF "AT+CMGF"
87 
92 #define DRV_RX_BUFFER_SIZE 256
93 #define DRV_TX_BUFFER_SIZE 256
94  // c4glteapj_set
96 
111 #define C4GLTEAPJ_MAP_MIKROBUS( cfg, mikrobus ) \
112  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
113  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
114  cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
115  cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
116  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
117  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
118  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
119  // c4glteapj_map // c4glteapj
122 
127 typedef struct
128 {
129  // Output pins
130  digital_out_t pwk;
131  digital_out_t rts;
132 
133  // Input pins
134  digital_in_t sta;
135  digital_in_t ring;
136  digital_in_t cts;
137 
138  // Modules
139  uart_t uart;
141  // Buffers
142  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
143  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
145 } c4glteapj_t;
146 
151 typedef struct
152 {
153  // Communication gpio pins
154  pin_name_t rx_pin;
155  pin_name_t tx_pin;
157  // Additional gpio pins
158  pin_name_t sta;
159  pin_name_t pwk;
160  pin_name_t rts;
161  pin_name_t ring;
162  pin_name_t cts;
163 
164  // Static variable
165  uint32_t baud_rate;
167  uart_data_bits_t data_bit;
168  uart_parity_t parity_bit;
169  uart_stop_bits_t stop_bit;
172 
177 typedef enum
178 {
180  C4GLTEAPJ_ERROR = -1
181 
183 
200 
216 
226 
240 err_t c4glteapj_generic_write ( c4glteapj_t *ctx, char *data_buf, uint16_t len );
241 
255 err_t c4glteapj_generic_read ( c4glteapj_t *ctx, char *data_buf, uint16_t max_len );
256 
257 
267 void c4glteapj_set_rts_pin ( c4glteapj_t *ctx, uint8_t state );
268 
278 void c4glteapj_set_pwk_pin ( c4glteapj_t *ctx, uint8_t state );
279 
290 
301 
312 
322 void c4glteapj_send_cmd ( c4glteapj_t *ctx, char *cmd );
323 
334 void c4glteapj_send_cmd_with_parameter ( c4glteapj_t *ctx, char *at_cmd_buf, char *param_buf );
335 
345 void c4glteapj_send_cmd_check ( c4glteapj_t *ctx, char *at_cmd_buf );
346 
356 void c4glteapj_set_sim_apn ( c4glteapj_t *ctx, char *sim_apn );
357 
368 void c4glteapj_send_sms_text ( c4glteapj_t *ctx, char *phone_number, char *sms_text );
369 
383 err_t c4glteapj_send_sms_pdu ( c4glteapj_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 #endif // C4GLTEAPJ_H
389  // c4glteapj
391 
392 // ------------------------------------------------------------------------ END
c4glteapj_init
err_t c4glteapj_init(c4glteapj_t *ctx, c4glteapj_cfg_t *cfg)
4G LTE-APJ initialization function.
c4glteapj_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: c4glteapj.h:167
C4GLTEAPJ_OK
@ C4GLTEAPJ_OK
Definition: c4glteapj.h:179
c4glteapj_cfg_t::ring
pin_name_t ring
Definition: c4glteapj.h:161
c4glteapj_t::uart
uart_t uart
Definition: c4glteapj.h:139
c4glteapj_return_value_t
c4glteapj_return_value_t
4G LTE-APJ Click return value data.
Definition: c4glteapj.h:178
c4glteapj_cfg_t::pwk
pin_name_t pwk
Definition: c4glteapj.h:159
c4glteapj_generic_write
err_t c4glteapj_generic_write(c4glteapj_t *ctx, char *data_buf, uint16_t len)
4G LTE-APJ data writing function.
c4glteapj_set_pwk_pin
void c4glteapj_set_pwk_pin(c4glteapj_t *ctx, uint8_t state)
Sets state of the PWK pin.
c4glteapj_t::pwk
digital_out_t pwk
Definition: c4glteapj.h:130
c4glteapj_module_power_on
void c4glteapj_module_power_on(c4glteapj_t *ctx)
Power ON the module function.
c4glteapj_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: c4glteapj.h:168
c4glteapj_cfg_t::baud_rate
uint32_t baud_rate
Definition: c4glteapj.h:165
c4glteapj_t::sta
digital_in_t sta
Definition: c4glteapj.h:134
c4glteapj_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: c4glteapj.h:169
c4glteapj_generic_read
err_t c4glteapj_generic_read(c4glteapj_t *ctx, char *data_buf, uint16_t max_len)
4G LTE-APJ data reading function.
c4glteapj_t::cts
digital_in_t cts
Definition: c4glteapj.h:136
c4glteapj_t::ring
digital_in_t ring
Definition: c4glteapj.h:135
c4glteapj_cfg_t::rx_pin
pin_name_t rx_pin
Definition: c4glteapj.h:154
c4glteapj_get_cts_pin
uint8_t c4glteapj_get_cts_pin(c4glteapj_t *ctx)
CTS Pin Get function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
4G LTE-APJ driver buffer size.
Definition: c4glteapj.h:92
c4glteapj_cfg_t::tx_pin
pin_name_t tx_pin
Definition: c4glteapj.h:155
c4glteapj_send_cmd
void c4glteapj_send_cmd(c4glteapj_t *ctx, char *cmd)
Send command function.
c4glteapj_get_sta_pin
uint8_t c4glteapj_get_sta_pin(c4glteapj_t *ctx)
STA Pin Get function.
c4glteapj_cfg_t::sta
pin_name_t sta
Definition: c4glteapj.h:158
c4glteapj_cfg_t::rts
pin_name_t rts
Definition: c4glteapj.h:160
c4glteapj_cfg_t
4G LTE-APJ Click configuration object.
Definition: c4glteapj.h:152
c4glteapj_get_ring_pin
uint8_t c4glteapj_get_ring_pin(c4glteapj_t *ctx)
RING Pin Get function.
c4glteapj_send_sms_text
void c4glteapj_send_sms_text(c4glteapj_t *ctx, char *phone_number, char *sms_text)
4G LTE-APJ send SMS in text mode.
c4glteapj_set_rts_pin
void c4glteapj_set_rts_pin(c4glteapj_t *ctx, uint8_t state)
Sets state of the RTS pin.
c4glteapj_t::rts
digital_out_t rts
Definition: c4glteapj.h:131
c4glteapj_send_sms_pdu
err_t c4glteapj_send_sms_pdu(c4glteapj_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
4G LTE-APJ send SMS in PDU mode.
c4glteapj_t
4G LTE-APJ Click context object.
Definition: c4glteapj.h:128
c4glteapj_set_sim_apn
void c4glteapj_set_sim_apn(c4glteapj_t *ctx, char *sim_apn)
Set sim card APN.
c4glteapj_send_cmd_with_parameter
void c4glteapj_send_cmd_with_parameter(c4glteapj_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
C4GLTEAPJ_ERROR
@ C4GLTEAPJ_ERROR
Definition: c4glteapj.h:180
c4glteapj_cfg_t::uart_blocking
bool uart_blocking
Definition: c4glteapj.h:166
c4glteapj_send_cmd_check
void c4glteapj_send_cmd_check(c4glteapj_t *ctx, char *at_cmd_buf)
Check the sent command.
c4glteapj_cfg_setup
void c4glteapj_cfg_setup(c4glteapj_cfg_t *cfg)
4G LTE-APJ configuration object setup function.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: c4glteapj.h:93
c4glteapj_cfg_t::cts
pin_name_t cts
Definition: c4glteapj.h:162