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
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 NPLC_CMD_COMMAND_MODE "+++"
60 #define NPLC_CMD_DATA_MODE "ATO"
61 #define NPLC_CMD_S100 "ATS100"
62 #define NPLC_CMD_S110 "ATS110"
63 #define NPLC_CMD_S111 "ATS111"
64 #define NPLC_CMD_S112 "ATS112"
65 #define NPLC_CMD_S113 "ATS113"
66 #define NPLC_CMD_S114 "ATS114"
67 #define NPLC_CMD_S300 "ATS300"
68 #define NPLC_CMD_S301 "ATS301"
69 #define NPLC_CMD_S302 "ATS302"
70 #define NPLC_CMD_S305 "ATS305"
71 #define NPLC_CMD_S306 "ATS306"
72 #define NPLC_CMD_FWI "AT+FWI"
73 #define NPLC_CMD_X "ATX"
74 #define NPLC_CMD_Z "ATZ"
75 #define NPLC_CMD_F "AT&F"
76 #define NPLC_CMD_W "AT&W"
77 #define NPLC_CMD_H "AT&H"
78 #define NPLC_CMD_V "AT&V"
84 #define NPLC_MODE_COMMAND 0
85 #define NPLC_MODE_DATA 1
86 
92 #define NPLC_DRV_BUFFER_SIZE 200
93  // nplc_cmd
95 
110 #define NPLC_MAP_MIKROBUS( cfg, mikrobus ) \
111  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
112  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
113  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_AN ); \
114  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
115  cfg.md1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
116  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
117  // nplc_map // nplc
120 
125 typedef struct
126 {
127  // Output pins
128  digital_out_t cts;
129  digital_out_t rst;
130  digital_out_t md1;
132  // Input pins
133  digital_in_t rts;
135  // Modules
136  uart_t uart;
138  // Buffers
139  char uart_rx_buffer[ NPLC_DRV_BUFFER_SIZE ];
140  char uart_tx_buffer[ NPLC_DRV_BUFFER_SIZE ];
142 } nplc_t;
143 
148 typedef struct
149 {
150  // Communication gpio pins
151  pin_name_t rx_pin;
152  pin_name_t tx_pin;
154  // Additional gpio pins
155  pin_name_t cts;
156  pin_name_t rst;
157  pin_name_t md1;
158  pin_name_t rts;
160  // Static variable
161  uint32_t baud_rate;
163  uart_data_bits_t data_bit;
164  uart_parity_t parity_bit;
165  uart_stop_bits_t stop_bit;
167 } nplc_cfg_t;
168 
173 typedef enum
174 {
175  NPLC_OK = 0,
176  NPLC_ERROR = -1
177 
179 
196 
210 err_t nplc_init ( nplc_t *ctx, nplc_cfg_t *cfg );
211 
224 err_t nplc_generic_write ( nplc_t *ctx, char *data_in, uint16_t len );
225 
238 err_t nplc_generic_read ( nplc_t *ctx, char *data_out, uint16_t len );
239 
249 void nplc_set_rst_pin ( nplc_t *ctx, uint8_t state );
250 
260 void nplc_set_md1_pin ( nplc_t *ctx, uint8_t state );
261 
271 void nplc_set_cts_pin ( nplc_t *ctx, uint8_t state );
272 
281 uint8_t nplc_get_rts_pin ( nplc_t *ctx );
282 
291 void nplc_hw_reset ( nplc_t *ctx );
292 
301 void nplc_sw_reset ( nplc_t *ctx );
302 
312 
322 
333 void nplc_set_mode ( nplc_t *ctx, uint8_t mode );
334 
344 void nplc_send_cmd ( nplc_t *ctx, char *cmd );
345 
357 void nplc_write_s_register ( nplc_t *ctx, char *s_reg, char *param_buf );
358 
369 void nplc_read_s_register ( nplc_t *ctx, char *s_reg );
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 #endif // NPLC_H
375  // nplc
377 
378 // ------------------------------------------------------------------------ END
nplc_cfg_t::uart_blocking
bool uart_blocking
Definition: nplc.h:162
nplc_sw_reset
void nplc_sw_reset(nplc_t *ctx)
N-PLC sw reset function.
nplc_cfg_t
N-PLC Click configuration object.
Definition: nplc.h:149
nplc_hw_reset
void nplc_hw_reset(nplc_t *ctx)
N-PLC hw reset function.
nplc_return_value_t
nplc_return_value_t
N-PLC Click return value data.
Definition: nplc.h:174
nplc_factory_reset
void nplc_factory_reset(nplc_t *ctx)
N-PLC factory reset function.
nplc_set_cts_pin
void nplc_set_cts_pin(nplc_t *ctx, uint8_t state)
N-PLC set cts pin function.
nplc_set_md1_pin
void nplc_set_md1_pin(nplc_t *ctx, uint8_t state)
N-PLC set md1 pin function.
nplc_t::rts
digital_in_t rts
Definition: nplc.h:133
nplc_set_mode
void nplc_set_mode(nplc_t *ctx, uint8_t mode)
N-PLC set mode function.
nplc_cfg_t::rst
pin_name_t rst
Definition: nplc.h:156
nplc_cfg_t::md1
pin_name_t md1
Definition: nplc.h:157
nplc_t
N-PLC Click context object.
Definition: nplc.h:126
nplc_cfg_t::tx_pin
pin_name_t tx_pin
Definition: nplc.h:152
nplc_cfg_t::baud_rate
uint32_t baud_rate
Definition: nplc.h:161
NPLC_DRV_BUFFER_SIZE
#define NPLC_DRV_BUFFER_SIZE
N-PLC driver buffer size.
Definition: nplc.h:92
nplc_init
err_t nplc_init(nplc_t *ctx, nplc_cfg_t *cfg)
N-PLC initialization function.
nplc_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: nplc.h:163
nplc_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: nplc.h:164
nplc_send_cmd
void nplc_send_cmd(nplc_t *ctx, char *cmd)
N-PLC send command function.
nplc_generic_read
err_t nplc_generic_read(nplc_t *ctx, char *data_out, uint16_t len)
N-PLC data reading function.
nplc_t::cts
digital_out_t cts
Definition: nplc.h:128
NPLC_OK
@ NPLC_OK
Definition: nplc.h:175
nplc_read_s_register
void nplc_read_s_register(nplc_t *ctx, char *s_reg)
N-PLC read s register function.
nplc_generic_write
err_t nplc_generic_write(nplc_t *ctx, char *data_in, uint16_t len)
N-PLC data writing function.
nplc_t::rst
digital_out_t rst
Definition: nplc.h:129
nplc_get_rts_pin
uint8_t nplc_get_rts_pin(nplc_t *ctx)
N-PLC get rts pin function.
nplc_cfg_t::cts
pin_name_t cts
Definition: nplc.h:155
nplc_write_s_register
void nplc_write_s_register(nplc_t *ctx, char *s_reg, char *param_buf)
N-PLC write s register function.
nplc_firmware_version
void nplc_firmware_version(nplc_t *ctx)
N-PLC firmware version function.
nplc_cfg_setup
void nplc_cfg_setup(nplc_cfg_t *cfg)
N-PLC configuration object setup function.
nplc_cfg_t::rx_pin
pin_name_t rx_pin
Definition: nplc.h:151
NPLC_ERROR
@ NPLC_ERROR
Definition: nplc.h:176
nplc_t::md1
digital_out_t md1
Definition: nplc.h:130
nplc_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: nplc.h:165
nplc_set_rst_pin
void nplc_set_rst_pin(nplc_t *ctx, uint8_t state)
N-PLC set rst pin function.
nplc_t::uart
uart_t uart
Definition: nplc.h:136
nplc_cfg_t::rts
pin_name_t rts
Definition: nplc.h:158