lteiot5  2.0.0.0
lteiot5.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 LTEIOT5_H
29 #define LTEIOT5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 // TODO -- dodati makroe koji definisu adrese registara
70  // lteiot5_reg
72 
87 #define LTEIOT5_CMD_AT "AT"
88 #define LTEIOT5_CMD_ATI "ATI"
89 #define LTEIOT5_CMD_CGMR "AT+CGMR"
90 
91 #define LTEIOT5_CMD_CFUN "AT+CFUN"
92 #define LTEIOT5_CMD_CREG "AT+CREG"
93 #define LTEIOT5_CMD_CEREG "AT+CEREG"
94 #define LTEIOT5_CMD_CGDCONT "AT+CGDCONT"
95 #define LTEIOT5_CMD_CIMI "AT+CIMI"
96 #define LTEIOT5_CMD_CGATT "AT+CGATT"
97 #define LTEIOT5_CMD_CSQ "AT+CSQ"
98 #define LTEIOT5_CMD_CESQ "AT+CESQ"
99 #define LTEIOT5_CMD_COPS "AT+COPS"
100 #define LTEIOT5_CMD_URAT "AT+URAT"
101 #define LTEIOT5_CMD_UBANDMASK "AT+UBANDMASK"
102 #define LTEIOT5_CMD_URATCONF "AT+URATCONF"
103 #define LTEIOT5_CMD_UAUTHREQ "AT+UAUTHREQ"
104 #define LTEIOT5_CMD_UUICC "AT+UUICC"
105 #define LTEIOT5_CMD_UCGED "AT+UCGED"
106 #define LTEIOT5_CMD_UCELLINFO "AT+UCELLINFO"
107 #define LTEIOT5_CMD_UANTR "AT+UANTR"
108 
109 // "AT+CGMR"
110 
116 #define DRV_RX_BUFFER_SIZE 500
117 #define DRV_TX_BUFFER_SIZE 150
118  // lteiot5_set
120 
135 #define LTEIOT5_MAP_MIKROBUS( cfg, mikrobus ) \
136  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
137  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
138  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
139  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
140  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
141  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
142  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
143  // lteiot5_map // lteiot5
146 
151 typedef struct
152 {
153  // Output pins
154 
155  digital_out_t pwr;
156  digital_out_t rst;
157  digital_out_t rts;
159  // Input pins
160 
161  digital_in_t ri;
162  digital_in_t cts;
164  // Modules
165 
166  uart_t uart;
168  // Buffers
169 
170  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
171  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
173 } lteiot5_t;
174 
179 typedef struct
180 {
181  // Communication gpio pins
182 
183  pin_name_t rx_pin;
184  pin_name_t tx_pin;
186  // Additional gpio pins
187 
188  pin_name_t pwr;
189  pin_name_t rst;
190  pin_name_t rts;
191  pin_name_t ri;
192  pin_name_t cts;
194  // Static variable
195 
196  uint32_t baud_rate;
198  uart_data_bits_t data_bit;
199  uart_parity_t parity_bit;
200  uart_stop_bits_t stop_bit;
202 } lteiot5_cfg_t;
203 
220 
235 err_t lteiot5_init ( lteiot5_t *ctx, lteiot5_cfg_t *cfg );
236 
251 
265 err_t lteiot5_generic_write ( lteiot5_t *ctx, char *data_buf, uint16_t len );
266 
280 err_t lteiot5_generic_read ( lteiot5_t *ctx, char *data_buf, uint16_t max_len );
281 
290 
298 void lteiot5_reset ( lteiot5_t *ctx );
299 
308 void lteiot5_set_pwr ( lteiot5_t *ctx, uint8_t state );
309 
318 void lteiot5_set_rst ( lteiot5_t *ctx, uint8_t state );
319 
328 void lteiot5_set_rts ( lteiot5_t *ctx, uint8_t state );
329 
338 uint8_t lteiot5_get_ri ( lteiot5_t *ctx );
339 
348 uint8_t lteiot5_get_cts ( lteiot5_t *ctx );
349 
359 void lteiot5_send_cmd ( lteiot5_t *ctx, char *cmd );
360 
371 void lteiot5_send_cmd_with_parameter ( lteiot5_t *ctx, char *at_cmd_buf, char *param_buf );
372 
382 void lteiot5_send_cmd_check ( lteiot5_t *ctx, char *at_cmd_buf );
383 
393 void lteiot5_send_cmd_parameter_check ( lteiot5_t *ctx, char *at_cmd_buf );
394 
404 void lteiot5_set_sim_apn ( lteiot5_t *ctx, char *sim_apn );
405 
416 void lteiot5_send_text_message ( lteiot5_t *ctx, char *phone_number, char *message_context );
417 
418 #ifdef __cplusplus
419 }
420 #endif
421 #endif // LTEIOT5_H
422  // lteiot5
424 
425 // ------------------------------------------------------------------------ END
lteiot5_send_text_message
void lteiot5_send_text_message(lteiot5_t *ctx, char *phone_number, char *message_context)
LTE IoT 5 send text message.
lteiot5_generic_write
err_t lteiot5_generic_write(lteiot5_t *ctx, char *data_buf, uint16_t len)
LTE IoT 5 data writing function.
lteiot5_send_cmd
void lteiot5_send_cmd(lteiot5_t *ctx, char *cmd)
Send command function.
lteiot5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot5.h:200
lteiot5_set_rst
void lteiot5_set_rst(lteiot5_t *ctx, uint8_t state)
Sets state of the RST pin.
lteiot5_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot5.h:196
lteiot5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot5.h:183
lteiot5_cfg_t::rst
pin_name_t rst
Definition: lteiot5.h:189
lteiot5_t::ri
digital_in_t ri
Definition: lteiot5.h:161
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
LTE IoT 5 driver buffer size.
Definition: lteiot5.h:116
lteiot5_cfg_t::ri
pin_name_t ri
Definition: lteiot5.h:191
lteiot5_init
err_t lteiot5_init(lteiot5_t *ctx, lteiot5_cfg_t *cfg)
LTE IoT 5 initialization function.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: lteiot5.h:117
lteiot5_set_pwr
void lteiot5_set_pwr(lteiot5_t *ctx, uint8_t state)
Sets state of the PWR pin.
lteiot5_cfg_t::cts
pin_name_t cts
Definition: lteiot5.h:192
lteiot5_cfg_t
LTE IoT 5 Click configuration object.
Definition: lteiot5.h:180
lteiot5_default_cfg
err_t lteiot5_default_cfg(lteiot5_t *ctx)
LTE IoT 5 default configuration function.
lteiot5_cfg_t::pwr
pin_name_t pwr
Definition: lteiot5.h:188
lteiot5_t
LTE IoT 5 Click context object.
Definition: lteiot5.h:152
lteiot5_t::rst
digital_out_t rst
Definition: lteiot5.h:156
lteiot5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot5.h:199
lteiot5_t::cts
digital_in_t cts
Definition: lteiot5.h:162
lteiot5_send_cmd_with_parameter
void lteiot5_send_cmd_with_parameter(lteiot5_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
lteiot5_get_cts
uint8_t lteiot5_get_cts(lteiot5_t *ctx)
CTS Pin Get function.
lteiot5_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot5.h:197
lteiot5_set_rts
void lteiot5_set_rts(lteiot5_t *ctx, uint8_t state)
Sets state of the RTS pin.
lteiot5_get_ri
uint8_t lteiot5_get_ri(lteiot5_t *ctx)
RI Pin Get function.
lteiot5_send_cmd_parameter_check
void lteiot5_send_cmd_parameter_check(lteiot5_t *ctx, char *at_cmd_buf)
Check the command parameters.
lteiot5_cfg_setup
void lteiot5_cfg_setup(lteiot5_cfg_t *cfg)
LTE IoT 5 configuration object setup function.
lteiot5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot5.h:184
lteiot5_t::rts
digital_out_t rts
Definition: lteiot5.h:157
lteiot5_t::pwr
digital_out_t pwr
Definition: lteiot5.h:155
lteiot5_generic_read
err_t lteiot5_generic_read(lteiot5_t *ctx, char *data_buf, uint16_t max_len)
LTE IoT 5 data reading function.
lteiot5_t::uart
uart_t uart
Definition: lteiot5.h:166
lteiot5_reset
void lteiot5_reset(lteiot5_t *ctx)
LTE IoT 5 power on.
lteiot5_set_sim_apn
void lteiot5_set_sim_apn(lteiot5_t *ctx, char *sim_apn)
Set sim card APN.
lteiot5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot5.h:198
lteiot5_cfg_t::rts
pin_name_t rts
Definition: lteiot5.h:190
lteiot5_power_on
void lteiot5_power_on(lteiot5_t *ctx)
LTE IoT 5 power on.
lteiot5_send_cmd_check
void lteiot5_send_cmd_check(lteiot5_t *ctx, char *at_cmd_buf)
Check the sent command.