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 
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 NBIOT4_CMD_AT "AT"
70 #define NBIOT4_CMD_ATE1 "ATE1"
71 #define NBIOT4_CMD_CFUN "AT+CFUN"
72 #define NBIOT4_CMD_CREG "AT+CREG"
73 #define NBIOT4_CMD_CEREG "AT+CEREG"
74 #define NBIOT4_CMD_CGDCONT "AT+CGDCONT"
75 #define NBIOT4_CMD_CSQ "AT+CSQ"
76 #define NBIOT4_CMD_COPS "AT+COPS"
77 #define NBIOT4_CMD_CMGS "AT+CMGS"
78 #define NBIOT4_CMD_CMGF "AT+CMGF"
79 #define NBIOT4_CMD_SIMSWAP "AT^SIMSWAP"
80 #define NBIOT4_CMD_TRB "AT+TRB"
81 #define NBIOT4_CMD_CIPMUX "AT+CIPMUX"
82 #define NBIOT4_CMD_CIPSTART "AT+CIPSTART"
83 #define NBIOT4_CMD_CIPCLOSE "AT+CIPCLOSE"
84 #define NBIOT4_CMD_CIPSEND "AT+CIPSEND"
85 #define NBIOT4_CMD_CIPHEAD "AT+CIPHEAD"
86 
91 #define NBIOT4_RSP_OK "OK"
92 #define NBIOT4_RSP_ERROR "ERROR"
93 #define NBIOT4_RSP_REBOOTING "REBOOTING"
94 
100 #define NBIOT4_RX_DRV_BUFFER_SIZE 256
101 #define NBIOT4_TX_DRV_BUFFER_SIZE 256
102  // nbiot4_set
104 
119 #define NBIOT4_MAP_MIKROBUS( cfg, mikrobus ) \
120  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
121  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
122  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
123  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
124  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_INT )
125  // nbiot4_map // nbiot4
128 
133 typedef struct
134 {
135  // Output pins
136  digital_out_t rst;
137  digital_out_t cs;
139  // Input pins
140  digital_in_t ring;
142  // Modules
143  uart_t uart;
145  // Buffers
146  uint8_t uart_rx_buffer[ NBIOT4_RX_DRV_BUFFER_SIZE ];
147  uint8_t uart_tx_buffer[ NBIOT4_TX_DRV_BUFFER_SIZE ];
149 } nbiot4_t;
150 
155 typedef struct
156 {
157  // Communication gpio pins
158  pin_name_t rx_pin;
159  pin_name_t tx_pin;
161  // Additional gpio pins
162  pin_name_t rst;
163  pin_name_t cs;
164  pin_name_t ring;
166  // Static variable
167  uint32_t baud_rate;
169  uart_data_bits_t data_bit;
170  uart_parity_t parity_bit;
171  uart_stop_bits_t stop_bit;
173 } nbiot4_cfg_t;
174 
179 typedef enum
180 {
186 
188 
205 
219 err_t nbiot4_init ( nbiot4_t *ctx, nbiot4_cfg_t *cfg );
220 
233 err_t nbiot4_generic_write ( nbiot4_t *ctx, uint8_t *data_in, uint16_t len );
234 
247 err_t nbiot4_generic_read ( nbiot4_t *ctx, uint8_t *data_out, uint16_t len );
248 
258 void nbiot4_set_rst_pin ( nbiot4_t *ctx, uint8_t state );
259 
269 void nbiot4_set_cs_pin ( nbiot4_t *ctx, uint8_t state );
270 
279 uint8_t nbiot4_get_ring_pin ( nbiot4_t *ctx );
280 
290 void nbiot4_send_cmd ( nbiot4_t *ctx, uint8_t *cmd );
291 
302 void nbiot4_send_cmd_with_par ( nbiot4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
303 
313 void nbiot4_send_cmd_check ( nbiot4_t *ctx, uint8_t *at_cmd_buf );
314 
324 void nbiot4_send_cmd_par_check ( nbiot4_t *ctx, uint8_t *at_cmd_buf );
325 
335 void nbiot4_set_sim_apn ( nbiot4_t *ctx, uint8_t *sim_apn );
336 
347 void nbiot4_send_sms_text ( nbiot4_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
348 
362 err_t nbiot4_send_sms_pdu ( nbiot4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 #endif // NBIOT4_H
368  // nbiot4
370 
371 // ------------------------------------------------------------------------ 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:162
nbiot4_t::cs
digital_out_t cs
Definition: nbiot4.h:137
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:181
nbiot4_t::rst
digital_out_t rst
Definition: nbiot4.h:136
nbiot4_return_value_t
nbiot4_return_value_t
NB IoT 4 Click return value data.
Definition: nbiot4.h:180
nbiot4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: nbiot4.h:169
NBIOT4_ERROR
@ NBIOT4_ERROR
Definition: nbiot4.h:182
nbiot4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: nbiot4.h:159
nbiot4_cfg_t
NB IoT 4 Click configuration object.
Definition: nbiot4.h:156
nbiot4_t::uart
uart_t uart
Definition: nbiot4.h:143
nbiot4_t::ring
digital_in_t ring
Definition: nbiot4.h:140
nbiot4_cfg_t::baud_rate
uint32_t baud_rate
Definition: nbiot4.h:167
nbiot4_t
NB IoT 4 Click context object.
Definition: nbiot4.h:134
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:158
NBIOT4_ERROR_UNKNOWN
@ NBIOT4_ERROR_UNKNOWN
Definition: nbiot4.h:185
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:171
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:170
nbiot4_cfg_t::ring
pin_name_t ring
Definition: nbiot4.h:164
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:163
NBIOT4_ERROR_CMD
@ NBIOT4_ERROR_CMD
Definition: nbiot4.h:184
nbiot4_cfg_t::uart_blocking
bool uart_blocking
Definition: nbiot4.h:168
NBIOT4_RX_DRV_BUFFER_SIZE
#define NBIOT4_RX_DRV_BUFFER_SIZE
NB IoT 4 driver buffer size.
Definition: nbiot4.h:100
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:101
NBIOT4_ERROR_TIMEOUT
@ NBIOT4_ERROR_TIMEOUT
Definition: nbiot4.h:183