nbiot5  2.0.0.0
nbiot5.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 NBIOT5_H
29 #define NBIOT5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define NBIOT5_CMD_AT "AT"
60 #define NBIOT5_CMD_CFUN "AT+CFUN"
61 #define NBIOT5_CMD_CEREG "AT+CEREG"
62 #define NBIOT5_CMD_CGDCONT "AT+CGDCONT"
63 #define NBIOT5_CMD_CSQ "AT+CSQ"
64 #define NBIOT5_CMD_COPS "AT+COPS"
65 #define NBIOT5_CMD_CMGS "AT+CMGS"
66 #define NBIOT5_CMD_CMGF "AT+CMGF"
67 #define NBIOT5_CMD_ESOC "AT+ESOC"
68 #define NBIOT5_CMD_ESOCON "AT+ESOCON"
69 #define NBIOT5_CMD_ESOSEND "AT+ESOSEND"
70 #define NBIOT5_CMD_ESOCL "AT+ESOCL"
71 
76 #define NBIOT5_RSP_OK "OK"
77 #define NBIOT5_RSP_ERROR "ERROR"
78 
84 #define NBIOT5_RX_DRV_BUFFER_SIZE 256
85 #define NBIOT5_TX_DRV_BUFFER_SIZE 256
86  // nbiot5_set
88 
103 #define NBIOT5_MAP_MIKROBUS( cfg, mikrobus ) \
104  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
105  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
106  cfg.wup = MIKROBUS( mikrobus, MIKROBUS_AN ); \
107  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
108  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
109  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
110  // nbiot5_map // nbiot5
113 
118 typedef struct
119 {
120  // Output pins
121  digital_out_t rst;
122  digital_out_t cs;
123  digital_out_t wup;
124  digital_out_t en;
126  // Modules
127  uart_t uart;
129  // Buffers
130  uint8_t uart_rx_buffer[ NBIOT5_RX_DRV_BUFFER_SIZE ];
131  uint8_t uart_tx_buffer[ NBIOT5_TX_DRV_BUFFER_SIZE ];
133 } nbiot5_t;
134 
139 typedef struct
140 {
141  // Communication gpio pins
142  pin_name_t rx_pin;
143  pin_name_t tx_pin;
145  // Additional gpio pins
146  pin_name_t rst;
147  pin_name_t cs;
148  pin_name_t wup;
149  pin_name_t en;
151  // Static variable
152  uint32_t baud_rate;
154  uart_data_bits_t data_bit;
155  uart_parity_t parity_bit;
156  uart_stop_bits_t stop_bit;
158 } nbiot5_cfg_t;
159 
164 typedef enum
165 {
171 
173 
190 
204 err_t nbiot5_init ( nbiot5_t *ctx, nbiot5_cfg_t *cfg );
205 
218 err_t nbiot5_generic_write ( nbiot5_t *ctx, uint8_t *data_in, uint16_t len );
219 
232 err_t nbiot5_generic_read ( nbiot5_t *ctx, uint8_t *data_out, uint16_t len );
233 
243 void nbiot5_set_rst_pin ( nbiot5_t *ctx, uint8_t state );
244 
254 void nbiot5_set_cs_pin ( nbiot5_t *ctx, uint8_t state );
255 
265 void nbiot5_set_wup_pin ( nbiot5_t *ctx, uint8_t state );
266 
276 void nbiot5_set_en_pin ( nbiot5_t *ctx, uint8_t state );
277 
287 void nbiot5_send_cmd ( nbiot5_t *ctx, uint8_t *cmd );
288 
299 void nbiot5_send_cmd_with_par ( nbiot5_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
300 
310 void nbiot5_send_cmd_check ( nbiot5_t *ctx, uint8_t *at_cmd_buf );
311 
321 void nbiot5_send_cmd_par_check ( nbiot5_t *ctx, uint8_t *at_cmd_buf );
322 
332 void nbiot5_set_sim_apn ( nbiot5_t *ctx, uint8_t *sim_apn );
333 
344 void nbiot5_send_sms_text ( nbiot5_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
345 
359 err_t nbiot5_send_sms_pdu ( nbiot5_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
360 
361 #ifdef __cplusplus
362 }
363 #endif
364 #endif // NBIOT5_H
365  // nbiot5
367 
368 // ------------------------------------------------------------------------ END
nbiot5_set_cs_pin
void nbiot5_set_cs_pin(nbiot5_t *ctx, uint8_t state)
NB IoT 5 set cs pin function.
nbiot5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: nbiot5.h:143
NBIOT5_ERROR_TIMEOUT
@ NBIOT5_ERROR_TIMEOUT
Definition: nbiot5.h:168
NBIOT5_ERROR_UNKNOWN
@ NBIOT5_ERROR_UNKNOWN
Definition: nbiot5.h:170
nbiot5_generic_write
err_t nbiot5_generic_write(nbiot5_t *ctx, uint8_t *data_in, uint16_t len)
NB IoT 5 data writing function.
nbiot5_set_en_pin
void nbiot5_set_en_pin(nbiot5_t *ctx, uint8_t state)
NB IoT 5 set en pin function.
nbiot5_t::wup
digital_out_t wup
Definition: nbiot5.h:123
nbiot5_init
err_t nbiot5_init(nbiot5_t *ctx, nbiot5_cfg_t *cfg)
NB IoT 5 initialization function.
NBIOT5_ERROR_CMD
@ NBIOT5_ERROR_CMD
Definition: nbiot5.h:169
nbiot5_set_rst_pin
void nbiot5_set_rst_pin(nbiot5_t *ctx, uint8_t state)
NB IoT 5 set rst pin function.
nbiot5_cfg_t::en
pin_name_t en
Definition: nbiot5.h:149
nbiot5_return_value_t
nbiot5_return_value_t
NB IoT 5 Click return value data.
Definition: nbiot5.h:165
NBIOT5_RX_DRV_BUFFER_SIZE
#define NBIOT5_RX_DRV_BUFFER_SIZE
NB IoT 5 driver buffer size.
Definition: nbiot5.h:84
nbiot5_cfg_t::wup
pin_name_t wup
Definition: nbiot5.h:148
nbiot5_set_wup_pin
void nbiot5_set_wup_pin(nbiot5_t *ctx, uint8_t state)
NB IoT 5 set wup pin function.
nbiot5_send_cmd_with_par
void nbiot5_send_cmd_with_par(nbiot5_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
nbiot5_cfg_t::baud_rate
uint32_t baud_rate
Definition: nbiot5.h:152
nbiot5_cfg_t
NB IoT 5 Click configuration object.
Definition: nbiot5.h:140
nbiot5_send_cmd
void nbiot5_send_cmd(nbiot5_t *ctx, uint8_t *cmd)
Send command function.
nbiot5_t
NB IoT 5 Click context object.
Definition: nbiot5.h:119
nbiot5_cfg_setup
void nbiot5_cfg_setup(nbiot5_cfg_t *cfg)
NB IoT 5 configuration object setup function.
nbiot5_send_sms_text
void nbiot5_send_sms_text(nbiot5_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 5 send SMS in text mode.
nbiot5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: nbiot5.h:156
nbiot5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: nbiot5.h:155
NBIOT5_ERROR
@ NBIOT5_ERROR
Definition: nbiot5.h:167
nbiot5_set_sim_apn
void nbiot5_set_sim_apn(nbiot5_t *ctx, uint8_t *sim_apn)
Set sim card APN.
nbiot5_cfg_t::cs
pin_name_t cs
Definition: nbiot5.h:147
nbiot5_cfg_t::rst
pin_name_t rst
Definition: nbiot5.h:146
nbiot5_send_sms_pdu
err_t nbiot5_send_sms_pdu(nbiot5_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 5 send SMS in PDU mode.
NBIOT5_OK
@ NBIOT5_OK
Definition: nbiot5.h:166
nbiot5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: nbiot5.h:142
nbiot5_t::rst
digital_out_t rst
Definition: nbiot5.h:121
nbiot5_t::cs
digital_out_t cs
Definition: nbiot5.h:122
NBIOT5_TX_DRV_BUFFER_SIZE
#define NBIOT5_TX_DRV_BUFFER_SIZE
Definition: nbiot5.h:85
nbiot5_cfg_t::uart_blocking
bool uart_blocking
Definition: nbiot5.h:153
nbiot5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: nbiot5.h:154
nbiot5_t::en
digital_out_t en
Definition: nbiot5.h:124
nbiot5_generic_read
err_t nbiot5_generic_read(nbiot5_t *ctx, uint8_t *data_out, uint16_t len)
NB IoT 5 data reading function.
nbiot5_t::uart
uart_t uart
Definition: nbiot5.h:127
nbiot5_send_cmd_par_check
void nbiot5_send_cmd_par_check(nbiot5_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
nbiot5_send_cmd_check
void nbiot5_send_cmd_check(nbiot5_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.