nplc 2.1.0.0
nplc.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 NPLC_H
29#define NPLC_H
30
31#ifdef __cplusplus
32extern "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 NPLC_CMD_COMMAND_MODE "+++"
74#define NPLC_CMD_DATA_MODE "ATO"
75#define NPLC_CMD_S100 "ATS100"
76#define NPLC_CMD_S110 "ATS110"
77#define NPLC_CMD_S111 "ATS111"
78#define NPLC_CMD_S112 "ATS112"
79#define NPLC_CMD_S113 "ATS113"
80#define NPLC_CMD_S114 "ATS114"
81#define NPLC_CMD_S300 "ATS300"
82#define NPLC_CMD_S301 "ATS301"
83#define NPLC_CMD_S302 "ATS302"
84#define NPLC_CMD_S305 "ATS305"
85#define NPLC_CMD_S306 "ATS306"
86#define NPLC_CMD_FWI "AT+FWI"
87#define NPLC_CMD_X "ATX"
88#define NPLC_CMD_Z "ATZ"
89#define NPLC_CMD_F "AT&F"
90#define NPLC_CMD_W "AT&W"
91#define NPLC_CMD_H "AT&H"
92#define NPLC_CMD_V "AT&V"
98#define NPLC_MODE_COMMAND 0
99#define NPLC_MODE_DATA 1
100
106#define NPLC_DRV_BUFFER_SIZE 200
107
108 // nplc_cmd
109
124#define NPLC_MAP_MIKROBUS( cfg, mikrobus ) \
125 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
126 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
127 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_AN ); \
128 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
129 cfg.md1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
130 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
131
132 // nplc_map
133 // nplc
134
139typedef struct
140{
141 // Output pins
142 digital_out_t cts;
143 digital_out_t rst;
144 digital_out_t md1;
146 // Input pins
147 digital_in_t rts;
149 // Modules
150 uart_t uart;
152 // Buffers
153 char uart_rx_buffer[ NPLC_DRV_BUFFER_SIZE ];
154 char uart_tx_buffer[ NPLC_DRV_BUFFER_SIZE ];
156} nplc_t;
157
162typedef struct
163{
164 // Communication gpio pins
165 pin_name_t rx_pin;
166 pin_name_t tx_pin;
168 // Additional gpio pins
169 pin_name_t cts;
170 pin_name_t rst;
171 pin_name_t md1;
172 pin_name_t rts;
174 // Static variable
175 uint32_t baud_rate;
177 uart_data_bits_t data_bit;
178 uart_parity_t parity_bit;
179 uart_stop_bits_t stop_bit;
181} nplc_cfg_t;
182
187typedef enum
188{
190 NPLC_ERROR = -1
191
193
210
224err_t nplc_init ( nplc_t *ctx, nplc_cfg_t *cfg );
225
238err_t nplc_generic_write ( nplc_t *ctx, char *data_in, uint16_t len );
239
252err_t nplc_generic_read ( nplc_t *ctx, char *data_out, uint16_t len );
253
263void nplc_set_rst_pin ( nplc_t *ctx, uint8_t state );
264
274void nplc_set_md1_pin ( nplc_t *ctx, uint8_t state );
275
285void nplc_set_cts_pin ( nplc_t *ctx, uint8_t state );
286
295uint8_t nplc_get_rts_pin ( nplc_t *ctx );
296
305void nplc_hw_reset ( nplc_t *ctx );
306
315void nplc_sw_reset ( nplc_t *ctx );
316
326
336
347void nplc_set_mode ( nplc_t *ctx, uint8_t mode );
348
358void nplc_send_cmd ( nplc_t *ctx, char *cmd );
359
371void nplc_write_s_register ( nplc_t *ctx, char *s_reg, char *param_buf );
372
383void nplc_read_s_register ( nplc_t *ctx, char *s_reg );
384
385#ifdef __cplusplus
386}
387#endif
388#endif // NPLC_H
389
390 // nplc
391
392// ------------------------------------------------------------------------ END
#define NPLC_DRV_BUFFER_SIZE
N-PLC driver buffer size.
Definition nplc.h:106
void nplc_send_cmd(nplc_t *ctx, char *cmd)
N-PLC send command function.
void nplc_hw_reset(nplc_t *ctx)
N-PLC hw reset function.
err_t nplc_init(nplc_t *ctx, nplc_cfg_t *cfg)
N-PLC initialization function.
void nplc_factory_reset(nplc_t *ctx)
N-PLC factory reset function.
void nplc_firmware_version(nplc_t *ctx)
N-PLC firmware version function.
void nplc_read_s_register(nplc_t *ctx, char *s_reg)
N-PLC read s register function.
uint8_t nplc_get_rts_pin(nplc_t *ctx)
N-PLC get rts pin function.
void nplc_set_cts_pin(nplc_t *ctx, uint8_t state)
N-PLC set cts pin function.
void nplc_set_mode(nplc_t *ctx, uint8_t mode)
N-PLC set mode function.
void nplc_set_rst_pin(nplc_t *ctx, uint8_t state)
N-PLC set rst pin function.
void nplc_set_md1_pin(nplc_t *ctx, uint8_t state)
N-PLC set md1 pin function.
err_t nplc_generic_write(nplc_t *ctx, char *data_in, uint16_t len)
N-PLC data writing function.
err_t nplc_generic_read(nplc_t *ctx, char *data_out, uint16_t len)
N-PLC data reading function.
void nplc_write_s_register(nplc_t *ctx, char *s_reg, char *param_buf)
N-PLC write s register function.
void nplc_sw_reset(nplc_t *ctx)
N-PLC sw reset function.
void nplc_cfg_setup(nplc_cfg_t *cfg)
N-PLC configuration object setup function.
nplc_return_value_t
N-PLC Click return value data.
Definition nplc.h:188
@ NPLC_OK
Definition nplc.h:189
@ NPLC_ERROR
Definition nplc.h:190
N-PLC Click configuration object.
Definition nplc.h:163
pin_name_t rts
Definition nplc.h:172
uint32_t baud_rate
Definition nplc.h:175
pin_name_t cts
Definition nplc.h:169
pin_name_t md1
Definition nplc.h:171
bool uart_blocking
Definition nplc.h:176
uart_data_bits_t data_bit
Definition nplc.h:177
pin_name_t tx_pin
Definition nplc.h:166
pin_name_t rx_pin
Definition nplc.h:165
uart_stop_bits_t stop_bit
Definition nplc.h:179
uart_parity_t parity_bit
Definition nplc.h:178
pin_name_t rst
Definition nplc.h:170
N-PLC Click context object.
Definition nplc.h:140
uart_t uart
Definition nplc.h:150
digital_in_t rts
Definition nplc.h:147
digital_out_t rst
Definition nplc.h:143
digital_out_t cts
Definition nplc.h:142
digital_out_t md1
Definition nplc.h:144