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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_uart.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define LTEIOT_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
74 
80 #define LTEIOT_RETVAL uint8_t
81 
82 #define LTEIOT_OK 0x00
83 #define LTEIOT_INIT_ERROR 0xFF
84 
90 #define LTEIOT_MODULE_POWER_ON 1
91 #define LTEIOT_MODULE_POWER_OFF 0
92 
98 #define LTEIOT_CMD_AT "AT"
99 #define LTEIOT_CMD_ATI "ATI"
100 #define LTEIOT_CMD_CGMR "AT+CGMR"
101 
102 #define LTEIOT_CMD_CFUN "AT+CFUN"
103 #define LTEIOT_CMD_CREG "AT+CREG"
104 #define LTEIOT_CMD_CEREG "AT+CEREG"
105 #define LTEIOT_CMD_CGDCONT "AT+CGDCONT"
106 #define LTEIOT_CMD_CIMI "AT+CIMI"
107 #define LTEIOT_CMD_CGATT "AT+CGATT"
108 #define LTEIOT_CMD_CSQ "AT+CSQ"
109 #define LTEIOT_CMD_CESQ "AT+CESQ"
110 #define LTEIOT_CMD_COPS "AT+COPS"
111 
117 #define DRV_RX_BUFFER_SIZE 500
118 #define DRV_TX_BUFFER_SIZE 100
119  // End group macro
122 // --------------------------------------------------------------- PUBLIC TYPES
130 typedef struct
131 {
132  // Output pins
133 
134  digital_out_t pwr;
135  digital_out_t rst;
136  digital_out_t rts;
137 
138  // Input pins
139 
140  digital_in_t ri;
141  digital_in_t cts;
142 
143  // Modules
144 
145  uart_t uart;
146 
147  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
148  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
149 
150 } lteiot_t;
151 
155 typedef struct
156 {
157  // Communication gpio pins
158 
159  pin_name_t rx_pin;
160  pin_name_t tx_pin;
161 
162  // Additional gpio pins
163 
164  pin_name_t pwr;
165  pin_name_t rst;
166  pin_name_t cts;
167  pin_name_t ri;
168  pin_name_t rts;
169 
170  // static variable
171 
172  uint32_t baud_rate; // Clock speed.
174  uart_data_bits_t data_bit; // Data bits.
175  uart_parity_t parity_bit; // Parity bit.
176  uart_stop_bits_t stop_bit; // Stop bits.
177 
178 } lteiot_cfg_t;
179  // End types group
181 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182 
188 #ifdef __cplusplus
189 extern "C"{
190 #endif
191 
202 
217 err_t lteiot_init ( lteiot_t *ctx, lteiot_cfg_t *cfg );
218 
232 err_t lteiot_generic_write ( lteiot_t *ctx, char *data_buf, uint16_t len );
233 
247 err_t lteiot_generic_read ( lteiot_t *ctx, char *data_buf, uint16_t max_len );
248 
256 void lteiot_power_on ( lteiot_t *ctx );
257 
266 void lteiot_set_rst ( lteiot_t *ctx, uint8_t state );
267 
276 void lteiot_set_rts ( lteiot_t *ctx, uint8_t state );
277 
286 uint8_t lteiot_get_cts ( lteiot_t *ctx );
287 
297 void lteiot_send_cmd ( lteiot_t *ctx, char *cmd );
298 
309 void lteiot_send_cmd_with_parameter ( lteiot_t *ctx, char *at_cmd_buf, char *param_buf );
310 
320 void lteiot_send_cmd_check ( lteiot_t *ctx, char *at_cmd_buf );
321 
331 void lteiot_send_cmd_parameter_check ( lteiot_t *ctx, char *at_cmd_buf );
332 
342 void lteiot_set_sim_apn ( lteiot_t *ctx, char *sim_apn );
343 
354 void lteiot_send_text_message ( lteiot_t *ctx, char *phone_number, char *message_context );
355 
356 #ifdef __cplusplus
357 }
358 #endif
359 #endif // _LTEIOT_H_
360  // End public_function group
363 
364 // ------------------------------------------------------------------------- END
lteiot_cfg_t::ri
pin_name_t ri
Definition: lteiot.h:167
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:117
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:160
lteiot_cfg_t::pwr
pin_name_t pwr
Definition: lteiot.h:164
lteiot_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot.h:173
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:168
lteiot_cfg_t::rst
pin_name_t rst
Definition: lteiot.h:165
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:145
lteiot_t::cts
digital_in_t cts
Definition: lteiot.h:141
lteiot_t::rts
digital_out_t rts
Definition: lteiot.h:136
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:140
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:131
lteiot_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot.h:159
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:176
lteiot_t::pwr
digital_out_t pwr
Definition: lteiot.h:134
lteiot_cfg_t::cts
pin_name_t cts
Definition: lteiot.h:166
lteiot_cfg_t
Click configuration structure definition.
Definition: lteiot.h:156
lteiot_t::rst
digital_out_t rst
Definition: lteiot.h:135
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:172
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:118
lteiot_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot.h:175
lteiot_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot.h:174