nbiot4  2.0.0.0
nbiot4.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 NBIOT4_H
29 #define NBIOT4_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 NBIOT4_CMD_AT "AT"
74 #define NBIOT4_CMD_ATE1 "ATE1"
75 #define NBIOT4_CMD_CFUN "AT+CFUN"
76 #define NBIOT4_CMD_CREG "AT+CREG"
77 #define NBIOT4_CMD_CEREG "AT+CEREG"
78 #define NBIOT4_CMD_CGDCONT "AT+CGDCONT"
79 #define NBIOT4_CMD_CSQ "AT+CSQ"
80 #define NBIOT4_CMD_COPS "AT+COPS"
81 #define NBIOT4_CMD_CMGS "AT+CMGS"
82 #define NBIOT4_CMD_CMGF "AT+CMGF"
83 #define NBIOT4_CMD_SIMSWAP "AT^SIMSWAP"
84 #define NBIOT4_CMD_TRB "AT+TRB"
85 #define NBIOT4_CMD_CIPMUX "AT+CIPMUX"
86 #define NBIOT4_CMD_CIPSTART "AT+CIPSTART"
87 #define NBIOT4_CMD_CIPCLOSE "AT+CIPCLOSE"
88 #define NBIOT4_CMD_CIPSEND "AT+CIPSEND"
89 #define NBIOT4_CMD_CIPHEAD "AT+CIPHEAD"
90 
95 #define NBIOT4_RSP_OK "OK"
96 #define NBIOT4_RSP_ERROR "ERROR"
97 #define NBIOT4_RSP_REBOOTING "REBOOTING"
98 
104 #define NBIOT4_RX_DRV_BUFFER_SIZE 256
105 #define NBIOT4_TX_DRV_BUFFER_SIZE 256
106  // nbiot4_set
108 
123 #define NBIOT4_MAP_MIKROBUS( cfg, mikrobus ) \
124  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
125  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
126  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
127  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
128  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_INT )
129  // nbiot4_map // nbiot4
132 
137 typedef struct
138 {
139  // Output pins
140  digital_out_t rst;
141  digital_out_t cs;
143  // Input pins
144  digital_in_t ring;
146  // Modules
147  uart_t uart;
149  // Buffers
150  uint8_t uart_rx_buffer[ NBIOT4_RX_DRV_BUFFER_SIZE ];
151  uint8_t uart_tx_buffer[ NBIOT4_TX_DRV_BUFFER_SIZE ];
153 } nbiot4_t;
154 
159 typedef struct
160 {
161  // Communication gpio pins
162  pin_name_t rx_pin;
163  pin_name_t tx_pin;
165  // Additional gpio pins
166  pin_name_t rst;
167  pin_name_t cs;
168  pin_name_t ring;
170  // Static variable
171  uint32_t baud_rate;
173  uart_data_bits_t data_bit;
174  uart_parity_t parity_bit;
175  uart_stop_bits_t stop_bit;
177 } nbiot4_cfg_t;
178 
183 typedef enum
184 {
190 
192 
209 
223 err_t nbiot4_init ( nbiot4_t *ctx, nbiot4_cfg_t *cfg );
224 
237 err_t nbiot4_generic_write ( nbiot4_t *ctx, uint8_t *data_in, uint16_t len );
238 
251 err_t nbiot4_generic_read ( nbiot4_t *ctx, uint8_t *data_out, uint16_t len );
252 
262 void nbiot4_set_rst_pin ( nbiot4_t *ctx, uint8_t state );
263 
273 void nbiot4_set_cs_pin ( nbiot4_t *ctx, uint8_t state );
274 
283 uint8_t nbiot4_get_ring_pin ( nbiot4_t *ctx );
284 
294 void nbiot4_send_cmd ( nbiot4_t *ctx, uint8_t *cmd );
295 
306 void nbiot4_send_cmd_with_par ( nbiot4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
307 
317 void nbiot4_send_cmd_check ( nbiot4_t *ctx, uint8_t *at_cmd_buf );
318 
328 void nbiot4_send_cmd_par_check ( nbiot4_t *ctx, uint8_t *at_cmd_buf );
329 
339 void nbiot4_set_sim_apn ( nbiot4_t *ctx, uint8_t *sim_apn );
340 
351 void nbiot4_send_sms_text ( nbiot4_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
352 
366 err_t nbiot4_send_sms_pdu ( nbiot4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 #endif // NBIOT4_H
372  // nbiot4
374 
375 // ------------------------------------------------------------------------ END
nbiot4_send_cmd
void nbiot4_send_cmd(nbiot4_t *ctx, uint8_t *cmd)
Send command function.
nbiot4_set_rst_pin
void nbiot4_set_rst_pin(nbiot4_t *ctx, uint8_t state)
NB IoT 4 set rst pin function.
nbiot4_init
err_t nbiot4_init(nbiot4_t *ctx, nbiot4_cfg_t *cfg)
NB IoT 4 initialization function.
nbiot4_cfg_setup
void nbiot4_cfg_setup(nbiot4_cfg_t *cfg)
NB IoT 4 configuration object setup function.
nbiot4_cfg_t::rst
pin_name_t rst
Definition: nbiot4.h:166
nbiot4_t::cs
digital_out_t cs
Definition: nbiot4.h:141
nbiot4_send_cmd_par_check
void nbiot4_send_cmd_par_check(nbiot4_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
nbiot4_generic_read
err_t nbiot4_generic_read(nbiot4_t *ctx, uint8_t *data_out, uint16_t len)
NB IoT 4 data reading function.
nbiot4_send_cmd_check
void nbiot4_send_cmd_check(nbiot4_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
NBIOT4_OK
@ NBIOT4_OK
Definition: nbiot4.h:185
nbiot4_t::rst
digital_out_t rst
Definition: nbiot4.h:140
nbiot4_return_value_t
nbiot4_return_value_t
NB IoT 4 Click return value data.
Definition: nbiot4.h:184
nbiot4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: nbiot4.h:173
NBIOT4_ERROR
@ NBIOT4_ERROR
Definition: nbiot4.h:186
nbiot4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: nbiot4.h:163
nbiot4_cfg_t
NB IoT 4 Click configuration object.
Definition: nbiot4.h:160
nbiot4_t::uart
uart_t uart
Definition: nbiot4.h:147
nbiot4_t::ring
digital_in_t ring
Definition: nbiot4.h:144
nbiot4_cfg_t::baud_rate
uint32_t baud_rate
Definition: nbiot4.h:171
nbiot4_t
NB IoT 4 Click context object.
Definition: nbiot4.h:138
nbiot4_set_cs_pin
void nbiot4_set_cs_pin(nbiot4_t *ctx, uint8_t state)
NB IoT 4 set cs pin function.
nbiot4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: nbiot4.h:162
NBIOT4_ERROR_UNKNOWN
@ NBIOT4_ERROR_UNKNOWN
Definition: nbiot4.h:189
nbiot4_set_sim_apn
void nbiot4_set_sim_apn(nbiot4_t *ctx, uint8_t *sim_apn)
Set sim card APN.
nbiot4_send_cmd_with_par
void nbiot4_send_cmd_with_par(nbiot4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
nbiot4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: nbiot4.h:175
nbiot4_get_ring_pin
uint8_t nbiot4_get_ring_pin(nbiot4_t *ctx)
NB IoT 4 get ring pin function.
nbiot4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: nbiot4.h:174
nbiot4_cfg_t::ring
pin_name_t ring
Definition: nbiot4.h:168
nbiot4_send_sms_pdu
err_t nbiot4_send_sms_pdu(nbiot4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 4 send SMS in PDU mode.
nbiot4_send_sms_text
void nbiot4_send_sms_text(nbiot4_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 4 send SMS in text mode.
nbiot4_cfg_t::cs
pin_name_t cs
Definition: nbiot4.h:167
NBIOT4_ERROR_CMD
@ NBIOT4_ERROR_CMD
Definition: nbiot4.h:188
nbiot4_cfg_t::uart_blocking
bool uart_blocking
Definition: nbiot4.h:172
NBIOT4_RX_DRV_BUFFER_SIZE
#define NBIOT4_RX_DRV_BUFFER_SIZE
NB IoT 4 driver buffer size.
Definition: nbiot4.h:104
nbiot4_generic_write
err_t nbiot4_generic_write(nbiot4_t *ctx, uint8_t *data_in, uint16_t len)
NB IoT 4 data writing function.
NBIOT4_TX_DRV_BUFFER_SIZE
#define NBIOT4_TX_DRV_BUFFER_SIZE
Definition: nbiot4.h:105
NBIOT4_ERROR_TIMEOUT
@ NBIOT4_ERROR_TIMEOUT
Definition: nbiot4.h:187