c5gnbiot  2.0.0.0
c5gnbiot.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 C5GNBIOT_H
36 #define C5GNBIOT_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define C5GNBIOT_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.on = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
69 
75 #define C5GNBIOT_MODULE_POWER_ON 1
76 #define C5GNBIOT_MODULE_POWER_OFF 0
77 
83 #define C5GNBIOT_CMD_AT "AT"
84 #define C5GNBIOT_CMD_ATI "ATI"
85 #define C5GNBIOT_CMD_CGMR "AT+CGMR"
86 
87 #define C5GNBIOT_CMD_CFUN "AT+CFUN"
88 #define C5GNBIOT_CMD_CREG "AT+CREG"
89 #define C5GNBIOT_CMD_CEREG "AT+CEREG"
90 #define C5GNBIOT_CMD_CGDCONT "AT+CGDCONT"
91 #define C5GNBIOT_CMD_CIMI "AT+CIMI"
92 #define C5GNBIOT_CMD_CGATT "AT+CGATT"
93 #define C5GNBIOT_CMD_CESQ "AT+CESQ"
94 #define C5GNBIOT_CMD_COPS "AT+COPS"
95 #define C5GNBIOT_CMD_CMGS "AT+CMGS"
96 
102 #define DRV_RX_BUFFER_SIZE 300
103 #define DRV_TX_BUFFER_SIZE 300
104  // End group macro
107 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Output pins
118 
119  digital_out_t on;
120  digital_out_t rts;
121 
122  // Input pins
123 
124  digital_in_t cts;
125 
126  // Modules
127 
128  uart_t uart;
129 
130  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
131  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
132 
133 } c5gnbiot_t;
134 
138 typedef struct
139 {
140  // Communication gpio pins
141 
142  pin_name_t rx_pin;
143  pin_name_t tx_pin;
144 
145  // Additional gpio pins
146 
147  pin_name_t on;
148  pin_name_t cts;
149  pin_name_t rts;
150 
151  // static variable
152 
153  uint32_t baud_rate; // Clock speed.
155  uart_data_bits_t data_bit; // Data bits.
156  uart_parity_t parity_bit; // Parity bit.
157  uart_stop_bits_t stop_bit; // Stop bits.
158 
160 
165 typedef enum
166 {
168  C5GNBIOT_ERROR = -1
169 
171  // End types group
173 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174 
180 #ifdef __cplusplus
181 extern "C"{
182 #endif
183 
194 
210 
224 err_t c5gnbiot_generic_write ( c5gnbiot_t *ctx, char *data_buf, uint16_t len );
225 
239 err_t c5gnbiot_generic_read ( c5gnbiot_t *ctx, char *data_buf, uint16_t max_len );
240 
249 
258 void c5gnbiot_set_on ( c5gnbiot_t *ctx, uint8_t state );
259 
268 void c5gnbiot_set_rts ( c5gnbiot_t *ctx, uint8_t state );
269 
278 uint8_t c5gnbiot_get_cts ( c5gnbiot_t *ctx );
279 
289 void c5gnbiot_send_cmd ( c5gnbiot_t *ctx, char *cmd );
290 
301 void c5gnbiot_send_cmd_with_parameter ( c5gnbiot_t *ctx, char *at_cmd_buf, char *param_buf );
302 
312 void c5gnbiot_send_cmd_check ( c5gnbiot_t *ctx, char *at_cmd_buf );
313 
323 void c5gnbiot_send_cmd_parameter_check ( c5gnbiot_t *ctx, char *at_cmd_buf );
324 
334 void c5gnbiot_set_sim_apn ( c5gnbiot_t *ctx, char *sim_apn );
335 
349 err_t c5gnbiot_send_text_message ( c5gnbiot_t *ctx, char *service_center_number,
350  char *phone_number, char *sms_text );
351 
352 #ifdef __cplusplus
353 }
354 #endif
355 #endif // _C5GNBIOT_H_
356  // End public_function group
359 
360 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: c5gnbiot.h:102
c5gnbiot_t
Click ctx object definition.
Definition: c5gnbiot.h:116
c5gnbiot_t::on
digital_out_t on
Definition: c5gnbiot.h:119
c5gnbiot_cfg_t::baud_rate
uint32_t baud_rate
Definition: c5gnbiot.h:153
c5gnbiot_set_sim_apn
void c5gnbiot_set_sim_apn(c5gnbiot_t *ctx, char *sim_apn)
Set sim card APN.
c5gnbiot_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: c5gnbiot.h:155
c5gnbiot_generic_read
err_t c5gnbiot_generic_read(c5gnbiot_t *ctx, char *data_buf, uint16_t max_len)
5G NB IoT data reading function.
c5gnbiot_send_cmd_with_parameter
void c5gnbiot_send_cmd_with_parameter(c5gnbiot_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
c5gnbiot_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: c5gnbiot.h:156
c5gnbiot_generic_write
err_t c5gnbiot_generic_write(c5gnbiot_t *ctx, char *data_buf, uint16_t len)
5G NB IoT data writing function.
c5gnbiot_cfg_setup
void c5gnbiot_cfg_setup(c5gnbiot_cfg_t *cfg)
5G NB IoT configuration object setup function.
c5gnbiot_t::cts
digital_in_t cts
Definition: c5gnbiot.h:124
c5gnbiot_cfg_t::uart_blocking
bool uart_blocking
Definition: c5gnbiot.h:154
c5gnbiot_return_value_t
c5gnbiot_return_value_t
5G NB IoT Click return value data.
Definition: c5gnbiot.h:166
c5gnbiot_send_cmd_parameter_check
void c5gnbiot_send_cmd_parameter_check(c5gnbiot_t *ctx, char *at_cmd_buf)
Check the command parameters.
c5gnbiot_get_cts
uint8_t c5gnbiot_get_cts(c5gnbiot_t *ctx)
CTS Pin Get function.
c5gnbiot_send_cmd
void c5gnbiot_send_cmd(c5gnbiot_t *ctx, char *cmd)
Send command function.
c5gnbiot_cfg_t
Click configuration structure definition.
Definition: c5gnbiot.h:139
c5gnbiot_set_rts
void c5gnbiot_set_rts(c5gnbiot_t *ctx, uint8_t state)
Sets state of the RTS pin.
c5gnbiot_send_text_message
err_t c5gnbiot_send_text_message(c5gnbiot_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
5G NB IoT send SMS in PDU mode.
c5gnbiot_send_cmd_check
void c5gnbiot_send_cmd_check(c5gnbiot_t *ctx, char *at_cmd_buf)
Check the sent command.
c5gnbiot_init
err_t c5gnbiot_init(c5gnbiot_t *ctx, c5gnbiot_cfg_t *cfg)
5G NB IoT initialization function.
c5gnbiot_cfg_t::on
pin_name_t on
Definition: c5gnbiot.h:147
c5gnbiot_t::uart
uart_t uart
Definition: c5gnbiot.h:128
c5gnbiot_cfg_t::tx_pin
pin_name_t tx_pin
Definition: c5gnbiot.h:143
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: c5gnbiot.h:103
c5gnbiot_cfg_t::rx_pin
pin_name_t rx_pin
Definition: c5gnbiot.h:142
c5gnbiot_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: c5gnbiot.h:157
c5gnbiot_t::rts
digital_out_t rts
Definition: c5gnbiot.h:120
C5GNBIOT_ERROR
@ C5GNBIOT_ERROR
Definition: c5gnbiot.h:168
c5gnbiot_cfg_t::cts
pin_name_t cts
Definition: c5gnbiot.h:148
C5GNBIOT_OK
@ C5GNBIOT_OK
Definition: c5gnbiot.h:167
c5gnbiot_set_on
void c5gnbiot_set_on(c5gnbiot_t *ctx, uint8_t state)
Sets state of the ON pin.
c5gnbiot_power_on
void c5gnbiot_power_on(c5gnbiot_t *ctx)
5G NB IoT module power on.
c5gnbiot_cfg_t::rts
pin_name_t rts
Definition: c5gnbiot.h:149