lteiot  2.0.0.0
lteiot.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 LTEIOT_H
36 #define LTEIOT_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define LTEIOT_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
59  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
60 
66 #define LTEIOT_RETVAL uint8_t
67 
68 #define LTEIOT_OK 0x00
69 #define LTEIOT_INIT_ERROR 0xFF
70 
76 #define LTEIOT_MODULE_POWER_ON 1
77 #define LTEIOT_MODULE_POWER_OFF 0
78 
84 #define LTEIOT_CMD_AT "AT"
85 #define LTEIOT_CMD_ATI "ATI"
86 #define LTEIOT_CMD_CGMR "AT+CGMR"
87 
88 #define LTEIOT_CMD_CFUN "AT+CFUN"
89 #define LTEIOT_CMD_CREG "AT+CREG"
90 #define LTEIOT_CMD_CEREG "AT+CEREG"
91 #define LTEIOT_CMD_CGDCONT "AT+CGDCONT"
92 #define LTEIOT_CMD_CIMI "AT+CIMI"
93 #define LTEIOT_CMD_CGATT "AT+CGATT"
94 #define LTEIOT_CMD_CSQ "AT+CSQ"
95 #define LTEIOT_CMD_CESQ "AT+CESQ"
96 #define LTEIOT_CMD_COPS "AT+COPS"
97 
103 #define DRV_RX_BUFFER_SIZE 500
104 #define DRV_TX_BUFFER_SIZE 100
105  // End group macro
108 // --------------------------------------------------------------- PUBLIC TYPES
116 typedef struct
117 {
118  // Output pins
119 
120  digital_out_t pwr;
121  digital_out_t rst;
122  digital_out_t rts;
123 
124  // Input pins
125 
126  digital_in_t ri;
127  digital_in_t cts;
128 
129  // Modules
130 
131  uart_t uart;
132 
133  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
134  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
135 
136 } lteiot_t;
137 
141 typedef struct
142 {
143  // Communication gpio pins
144 
145  pin_name_t rx_pin;
146  pin_name_t tx_pin;
147 
148  // Additional gpio pins
149 
150  pin_name_t pwr;
151  pin_name_t rst;
152  pin_name_t cts;
153  pin_name_t ri;
154  pin_name_t rts;
155 
156  // static variable
157 
158  uint32_t baud_rate; // Clock speed.
160  uart_data_bits_t data_bit; // Data bits.
161  uart_parity_t parity_bit; // Parity bit.
162  uart_stop_bits_t stop_bit; // Stop bits.
163 
164 } lteiot_cfg_t;
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
188 
203 err_t lteiot_init ( lteiot_t *ctx, lteiot_cfg_t *cfg );
204 
218 err_t lteiot_generic_write ( lteiot_t *ctx, char *data_buf, uint16_t len );
219 
233 err_t lteiot_generic_read ( lteiot_t *ctx, char *data_buf, uint16_t max_len );
234 
242 void lteiot_power_on ( lteiot_t *ctx );
243 
252 void lteiot_set_rst ( lteiot_t *ctx, uint8_t state );
253 
262 void lteiot_set_rts ( lteiot_t *ctx, uint8_t state );
263 
272 uint8_t lteiot_get_cts ( lteiot_t *ctx );
273 
283 void lteiot_send_cmd ( lteiot_t *ctx, char *cmd );
284 
295 void lteiot_send_cmd_with_parameter ( lteiot_t *ctx, char *at_cmd_buf, char *param_buf );
296 
306 void lteiot_send_cmd_check ( lteiot_t *ctx, char *at_cmd_buf );
307 
317 void lteiot_send_cmd_parameter_check ( lteiot_t *ctx, char *at_cmd_buf );
318 
328 void lteiot_set_sim_apn ( lteiot_t *ctx, char *sim_apn );
329 
340 void lteiot_send_text_message ( lteiot_t *ctx, char *phone_number, char *message_context );
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 #endif // _LTEIOT_H_
346  // End public_function group
349 
350 // ------------------------------------------------------------------------- END
lteiot_cfg_t::ri
pin_name_t ri
Definition: lteiot.h:153
lteiot_power_on
void lteiot_power_on(lteiot_t *ctx)
LTE IoT module power on.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: lteiot.h:103
lteiot_set_rst
void lteiot_set_rst(lteiot_t *ctx, uint8_t state)
Sets state of the RST pin.
lteiot_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot.h:146
lteiot_cfg_t::pwr
pin_name_t pwr
Definition: lteiot.h:150
lteiot_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot.h:159
lteiot_cfg_setup
void lteiot_cfg_setup(lteiot_cfg_t *cfg)
LTE IoT configuration object setup function.
lteiot_cfg_t::rts
pin_name_t rts
Definition: lteiot.h:154
lteiot_cfg_t::rst
pin_name_t rst
Definition: lteiot.h:151
lteiot_send_text_message
void lteiot_send_text_message(lteiot_t *ctx, char *phone_number, char *message_context)
LTE IoT send text message.
lteiot_init
err_t lteiot_init(lteiot_t *ctx, lteiot_cfg_t *cfg)
LTE IoT initialization function.
lteiot_get_cts
uint8_t lteiot_get_cts(lteiot_t *ctx)
CTS Pin Get function.
lteiot_t::uart
uart_t uart
Definition: lteiot.h:131
lteiot_t::cts
digital_in_t cts
Definition: lteiot.h:127
lteiot_t::rts
digital_out_t rts
Definition: lteiot.h:122
lteiot_send_cmd_with_parameter
void lteiot_send_cmd_with_parameter(lteiot_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
lteiot_t::ri
digital_in_t ri
Definition: lteiot.h:126
lteiot_set_sim_apn
void lteiot_set_sim_apn(lteiot_t *ctx, char *sim_apn)
Set sim card APN.
lteiot_set_rts
void lteiot_set_rts(lteiot_t *ctx, uint8_t state)
Sets state of the RTS pin.
lteiot_t
Click ctx object definition.
Definition: lteiot.h:117
lteiot_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot.h:145
lteiot_send_cmd_check
void lteiot_send_cmd_check(lteiot_t *ctx, char *at_cmd_buf)
Check the sent command.
lteiot_send_cmd_parameter_check
void lteiot_send_cmd_parameter_check(lteiot_t *ctx, char *at_cmd_buf)
Check the command parameters.
lteiot_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot.h:162
lteiot_t::pwr
digital_out_t pwr
Definition: lteiot.h:120
lteiot_cfg_t::cts
pin_name_t cts
Definition: lteiot.h:152
lteiot_cfg_t
Click configuration structure definition.
Definition: lteiot.h:142
lteiot_t::rst
digital_out_t rst
Definition: lteiot.h:121
lteiot_send_cmd
void lteiot_send_cmd(lteiot_t *ctx, char *cmd)
Send command function.
lteiot_generic_read
err_t lteiot_generic_read(lteiot_t *ctx, char *data_buf, uint16_t max_len)
LTE IoT data reading function.
lteiot_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot.h:158
lteiot_generic_write
err_t lteiot_generic_write(lteiot_t *ctx, char *data_buf, uint16_t len)
LTE IoT data writing function.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: lteiot.h:104
lteiot_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot.h:161
lteiot_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot.h:160