nbiot2  2.1.0.0
nbiot2.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 NBIOT2_H
29 #define NBIOT2_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 #define NBIOT2_CMD_AT "AT"
70 #define NBIOT2_CMD_ATI "ATI"
71 #define NBIOT2_CMD_CGMR "AT+CGMR"
72 #define NBIOT2_CMD_CFUN "AT+CFUN"
73 #define NBIOT2_CMD_CREG "AT+CREG"
74 #define NBIOT2_CMD_CEREG "AT+CEREG"
75 #define NBIOT2_CMD_CGDCONT "AT+CGDCONT"
76 #define NBIOT2_CMD_CIMI "AT+CIMI"
77 #define NBIOT2_CMD_CGATT "AT+CGATT"
78 #define NBIOT2_CMD_CSQ "AT+CSQ"
79 #define NBIOT2_CMD_CESQ "AT+CESQ"
80 #define NBIOT2_CMD_COPS "AT+COPS"
81 #define NBIOT2_CMD_CSCON "AT+CSCON"
82 #define NBIOT2_CMD_CMEE "AT+CMEE"
83 #define NBIOT2_CMD_CMGS "AT+CMGS"
84 #define NBIOT2_CMD_CGACT "AT+CGACT"
85 #define NBIOT2_CMD_URAT "AT+URAT"
86 #define NBIOT2_CMD_UBANDMASK "AT+UBANDMASK"
87 #define NBIOT2_CMD_URATCONF "AT+URATCONF"
88 #define NBIOT2_CMD_UAUTHREQ "AT+UAUTHREQ"
89 #define NBIOT2_CMD_UUICC "AT+UUICC"
90 #define NBIOT2_CMD_UCGED "AT+UCGED"
91 #define NBIOT2_CMD_UCELLINFO "AT+UCELLINFO"
92 #define NBIOT2_CMD_UANTR "AT+UANTR"
93 #define NBIOT2_CMD_CMGF "AT+CMGF"
94 #define NBIOT2_CMD_QSPCHSC "AT+QSPCHSC"
95 #define NBIOT2_CMD_CPSMS "AT+CPSMS"
96 #define NBIOT2_CMD_QRST "AT+QRST"
97 #define NBIOT2_CMD_QBAND "AT+QBAND"
98 #define NBIOT2_CMD_QNBIOTEVENT "AT+QNBIOTEVENT"
99 #define NBIOT2_CMD_SM "AT+SM"
100 #define NBIOT2_CMD_QSCLK "AT+QSCLK"
101 #define NBIOT2_CMD_QIOPEN "AT+QIOPEN"
102 #define NBIOT2_CMD_QISEND "AT+QISEND"
103 #define NBIOT2_CMD_QIRD "AT+QIRD"
104 #define NBIOT2_CMD_QICLOSE "AT+QICLOSE"
105 
110 #define NBIOT2_PIN_STATE_HIGH 0x01
111 #define NBIOT2_PIN_STATE_LOW 0x00
112 
117 #define NBIOT2_RSP_OK "OK"
118 #define NBIOT2_RSP_ERROR "ERROR"
119 
125 #define NBIOT2_TX_DRV_BUFFER_SIZE 100
126 #define NBIOT2_RX_DRV_BUFFER_SIZE 300
127  // nbiot2_cmd
129 
144 #define NBIOT2_MAP_MIKROBUS( cfg, mikrobus ) \
145  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
146  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
147  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
148  cfg.wup = MIKROBUS( mikrobus, MIKROBUS_INT );
149  // nbiot2_map // nbiot2
152 
157 typedef struct
158 {
159  // Output pins
160  digital_out_t rst;
161  digital_out_t wup;
163  // Modules
164  uart_t uart;
166  // Buffers
167  char uart_rx_buffer[ NBIOT2_RX_DRV_BUFFER_SIZE ];
168  char uart_tx_buffer[ NBIOT2_TX_DRV_BUFFER_SIZE ];
170 } nbiot2_t;
171 
176 typedef struct
177 {
178  // Communication gpio pins
179  pin_name_t rx_pin;
180  pin_name_t tx_pin;
182  // Additional gpio pins
183  pin_name_t rst;
184  pin_name_t wup;
186  // Static variable
187  uint32_t baud_rate;
189  uart_data_bits_t data_bit;
190  uart_parity_t parity_bit;
191  uart_stop_bits_t stop_bit;
193 } nbiot2_cfg_t;
194 
199 typedef enum
200 {
205 
207 
224 
238 err_t nbiot2_init ( nbiot2_t *ctx, nbiot2_cfg_t *cfg );
239 
252 err_t nbiot2_generic_write ( nbiot2_t *ctx, char *data_in, uint16_t len );
253 
266 err_t nbiot2_generic_read ( nbiot2_t *ctx, char *data_out, uint16_t len );
267 
277 void nbiot2_set_rst_pin_state ( nbiot2_t *ctx, uint8_t state );
278 
288 void nbiot2_set_wup_pin_state ( nbiot2_t *ctx, uint8_t state );
289 
298 void nbiot2_hw_reset ( nbiot2_t *ctx );
299 
309 void nbiot2_send_cmd ( nbiot2_t *ctx, char *cmd );
310 
321 void nbiot2_send_cmd_with_parameter ( nbiot2_t *ctx, char *at_cmd_buf, char *param_buf );
322 
332 void nbiot2_send_cmd_check ( nbiot2_t *ctx, char *at_cmd_buf );
333 
343 void nbiot2_send_cmd_parameter_check ( nbiot2_t *ctx, char *at_cmd_buf );
344 
354 void nbiot2_set_apn( nbiot2_t *ctx, char *apn );
355 
366 void nbiot2_send_sms_text_mode ( nbiot2_t *ctx, char *phone_number, char *message_context );
367 
381 err_t nbiot2_send_sms_pdu ( nbiot2_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 #endif // NBIOT2_H
387  // nbiot2
389 
390 // ------------------------------------------------------------------------ END
nbiot2_send_sms_text_mode
void nbiot2_send_sms_text_mode(nbiot2_t *ctx, char *phone_number, char *message_context)
NB IoT 2 send SMS in text mode.
nbiot2_cfg_t::wup
pin_name_t wup
Definition: nbiot2.h:184
NBIOT2_RX_DRV_BUFFER_SIZE
#define NBIOT2_RX_DRV_BUFFER_SIZE
Definition: nbiot2.h:126
nbiot2_send_sms_pdu
err_t nbiot2_send_sms_pdu(nbiot2_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
NB IoT 2 send SMS in PDU mode.
nbiot2_set_wup_pin_state
void nbiot2_set_wup_pin_state(nbiot2_t *ctx, uint8_t state)
NB IoT 2 sets state of the WUP pin.
nbiot2_send_cmd_with_parameter
void nbiot2_send_cmd_with_parameter(nbiot2_t *ctx, char *at_cmd_buf, char *param_buf)
NB IoT 2 send command function with parameter.
nbiot2_set_rst_pin_state
void nbiot2_set_rst_pin_state(nbiot2_t *ctx, uint8_t state)
NB IoT 2 sets state of the RST pin.
NBIOT2_TX_DRV_BUFFER_SIZE
#define NBIOT2_TX_DRV_BUFFER_SIZE
NB IoT 2 driver buffer size.
Definition: nbiot2.h:125
nbiot2_t::rst
digital_out_t rst
Definition: nbiot2.h:160
nbiot2_hw_reset
void nbiot2_hw_reset(nbiot2_t *ctx)
NB IoT 2 hardware reset function.
nbiot2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: nbiot2.h:191
NBIOT2_ERROR
@ NBIOT2_ERROR
Definition: nbiot2.h:202
nbiot2_return_value_t
nbiot2_return_value_t
NB IoT 2 Click return value data.
Definition: nbiot2.h:200
nbiot2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: nbiot2.h:180
nbiot2_cfg_t::baud_rate
uint32_t baud_rate
Definition: nbiot2.h:187
nbiot2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: nbiot2.h:179
nbiot2_set_apn
void nbiot2_set_apn(nbiot2_t *ctx, char *apn)
NB IoT 2 set sim card APN.
nbiot2_generic_write
err_t nbiot2_generic_write(nbiot2_t *ctx, char *data_in, uint16_t len)
NB IoT 2 data writing function.
nbiot2_t::uart
uart_t uart
Definition: nbiot2.h:164
nbiot2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: nbiot2.h:189
nbiot2_cfg_t
NB IoT 2 Click configuration object.
Definition: nbiot2.h:177
nbiot2_generic_read
err_t nbiot2_generic_read(nbiot2_t *ctx, char *data_out, uint16_t len)
NB IoT 2 data reading function.
nbiot2_send_cmd
void nbiot2_send_cmd(nbiot2_t *ctx, char *cmd)
NB IoT 2 send command function.
nbiot2_send_cmd_check
void nbiot2_send_cmd_check(nbiot2_t *ctx, char *at_cmd_buf)
NB IoT 2 check the sent command.
NBIOT2_ERROR_TIMEOUT
@ NBIOT2_ERROR_TIMEOUT
Definition: nbiot2.h:204
nbiot2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: nbiot2.h:190
NBIOT2_OK
@ NBIOT2_OK
Definition: nbiot2.h:201
nbiot2_t::wup
digital_out_t wup
Definition: nbiot2.h:161
nbiot2_cfg_t::rst
pin_name_t rst
Definition: nbiot2.h:183
nbiot2_init
err_t nbiot2_init(nbiot2_t *ctx, nbiot2_cfg_t *cfg)
NB IoT 2 initialization function.
nbiot2_cfg_setup
void nbiot2_cfg_setup(nbiot2_cfg_t *cfg)
NB IoT 2 configuration object setup function.
nbiot2_send_cmd_parameter_check
void nbiot2_send_cmd_parameter_check(nbiot2_t *ctx, char *at_cmd_buf)
NB IoT 2 check the command parameters.
nbiot2_cfg_t::uart_blocking
bool uart_blocking
Definition: nbiot2.h:188
nbiot2_t
NB IoT 2 Click context object.
Definition: nbiot2.h:158
NBIOT2_ERROR_OVERFLOW
@ NBIOT2_ERROR_OVERFLOW
Definition: nbiot2.h:203