mosaic  2.1.0.0
mosaic.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 MOSAIC_H
29 #define MOSAIC_H
30 
31 #ifdef __cplusplus
32 extern "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 MOSAIC_CMD_SET_NMEA_OUTPUT "setNMEAOutput"
74 #define MOSAIC_CMD_GET_NMEA_VERSION "getNMEAVersion"
75 
80 #define MOSAIC_PROMPT_CMD "COM1>"
81 #define MOSAIC_PARAM_DELIMITER ","
82 #define MOSAIC_END_CMD "\r\n"
83 
88 #define MOSAIC_SNO_STREAM_1 "Stream1"
89 #define MOSAIC_SNO_STREAM_2 "Stream2"
90 #define MOSAIC_SNO_STREAM_3 "Stream3"
91 #define MOSAIC_SNO_STREAM_4 "Stream4"
92 #define MOSAIC_SNO_STREAM_5 "Stream5"
93 #define MOSAIC_SNO_STREAM_6 "Stream6"
94 #define MOSAIC_SNO_STREAM_7 "Stream7"
95 #define MOSAIC_SNO_STREAM_8 "Stream8"
96 #define MOSAIC_SNO_STREAM_9 "Stream9"
97 #define MOSAIC_SNO_STREAM_10 "Stream10"
98 #define MOSAIC_SNO_STREAM_ALL "all"
99 #define MOSAIC_SNO_CD_NONE "none"
100 #define MOSAIC_SNO_CD_COM1 "COM1"
101 #define MOSAIC_SNO_MESSAGES_NONE "none"
102 #define MOSAIC_SNO_MESSAGES_ALM "ALM"
103 #define MOSAIC_SNO_MESSAGES_DTM "DTM"
104 #define MOSAIC_SNO_MESSAGES_GBS "GBS"
105 #define MOSAIC_SNO_MESSAGES_GGA "GGA"
106 #define MOSAIC_SNO_MESSAGES_GLL "GLL"
107 #define MOSAIC_SNO_MESSAGES_GNS "GNS"
108 #define MOSAIC_SNO_MESSAGES_GRS "GRS"
109 #define MOSAIC_SNO_MESSAGES_GSA "GSA"
110 #define MOSAIC_SNO_MESSAGES_GST "GST"
111 #define MOSAIC_SNO_MESSAGES_GSV "GSV"
112 #define MOSAIC_SNO_MESSAGES_HDT "HDT"
113 #define MOSAIC_SNO_MESSAGES_RMC "RMC"
114 #define MOSAIC_SNO_MESSAGES_ROT "ROT"
115 #define MOSAIC_SNO_MESSAGES_VTG "VTG"
116 #define MOSAIC_SNO_MESSAGES_ZDA "ZDA"
117 #define MOSAIC_SNO_MESSAGES_HRP "HRP"
118 #define MOSAIC_SNO_MESSAGES_LLQ "LLQ"
119 #define MOSAIC_SNO_MESSAGES_RBP "RBP"
120 #define MOSAIC_SNO_MESSAGES_RBV "RBV"
121 #define MOSAIC_SNO_MESSAGES_RBD "RBD"
122 #define MOSAIC_SNO_MESSAGES_AVR "AVR"
123 #define MOSAIC_SNO_MESSAGES_GGK "GGK"
124 #define MOSAIC_SNO_MESSAGES_GFA "GFA"
125 #define MOSAIC_SNO_MESSAGES_GGQ "GGQ"
126 #define MOSAIC_SNO_MESSAGES_LLK "LLK"
127 #define MOSAIC_SNO_MESSAGES_GMP "GMP"
128 #define MOSAIC_SNO_MESSAGES_TXT_BASE "TXTbase"
129 #define MOSAIC_SNO_MESSAGES_TFM "TFM"
130 #define MOSAIC_SNO_MESSAGES_SNC "SNC"
131 #define MOSAIC_SNO_MESSAGES_THS "THS"
132 #define MOSAIC_SNO_INTERVAL_OFF "off"
133 #define MOSAIC_SNO_INTERVAL_ON_CHANGE "OnChange"
134 #define MOSAIC_SNO_INTERVAL_MSEC10 "msec10"
135 #define MOSAIC_SNO_INTERVAL_MSEC20 "msec20"
136 #define MOSAIC_SNO_INTERVAL_MSEC40 "msec40"
137 #define MOSAIC_SNO_INTERVAL_MSEC50 "msec50"
138 #define MOSAIC_SNO_INTERVAL_MSEC100 "msec100"
139 #define MOSAIC_SNO_INTERVAL_MSEC200 "msec200"
140 #define MOSAIC_SNO_INTERVAL_MSEC500 "msec500"
141 #define MOSAIC_SNO_INTERVAL_SEC1 "sec1"
142 #define MOSAIC_SNO_INTERVAL_SEC2 "sec2"
143 #define MOSAIC_SNO_INTERVAL_SEC5 "sec5"
144 #define MOSAIC_SNO_INTERVAL_SEC10 "sec10"
145 #define MOSAIC_SNO_INTERVAL_SEC15 "sec15"
146 #define MOSAIC_SNO_INTERVAL_SEC30 "sec30"
147 #define MOSAIC_SNO_INTERVAL_SEC60 "sec60"
148 #define MOSAIC_SNO_INTERVAL_MIN2 "min2"
149 #define MOSAIC_SNO_INTERVAL_MIN5 "min5"
150 #define MOSAIC_SNO_INTERVAL_MIN10 "min10"
151 #define MOSAIC_SNO_INTERVAL_MIN15 "min15"
152 #define MOSAIC_SNO_INTERVAL_MIN30 "min30"
153 #define MOSAIC_SNO_INTERVAL_MIN60 "min60"
154 
159 #define MOSAIC_NMEA_START "$"
160 #define MOSAIC_NMEA_DELIMITER ","
161 #define MOSAIC_NMEA_END "\r\n"
162 #define MOSAIC_NMEA_GGA "GGA"
163 
168 #define MOSAIC_GGA_ELEMENT_SIZE 15
169 #define MOSAIC_GGA_TIME 1
170 #define MOSAIC_GGA_LATITUDE 2
171 #define MOSAIC_GGA_LATITUDE_SIDE 3
172 #define MOSAIC_GGA_LONGITUDE 4
173 #define MOSAIC_GGA_LONGITUDE_SIDE 5
174 #define MOSAIC_GGA_QUALITY_INDICATOR 6
175 #define MOSAIC_GGA_NUMBER_OF_SATELLITES 7
176 #define MOSAIC_GGA_H_DILUTION_OF_POS 8
177 #define MOSAIC_GGA_ALTITUDE 9
178 #define MOSAIC_GGA_ALTITUDE_UNIT 10
179 #define MOSAIC_GGA_GEOIDAL_SEPARATION 11
180 #define MOSAIC_GGA_GEOIDAL_SEPARATION_UNIT 12
181 #define MOSAIC_GGA_TIME_SINCE_LAST_DGPS 13
182 #define MOSAIC_GGA_DGPS_REFERENCE_STATION_ID 14
183 
189 #define MOSAIC_RX_DRV_BUFFER_SIZE 400
190 #define MOSAIC_TX_DRV_BUFFER_SIZE 200
191  // mosaic_cmd
193 
208 #define MOSAIC_MAP_MIKROBUS( cfg, mikrobus ) \
209  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
210  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
211  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
212  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
213  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
214  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
215  // mosaic_map // mosaic
218 
223 typedef struct
224 {
225  // Output pins
226  digital_out_t rst;
227  digital_out_t cts;
229  // Input pins
230  digital_in_t rdy;
231  digital_in_t rts;
233  // Modules
234  uart_t uart;
236  // Buffers
237  uint8_t uart_rx_buffer[ MOSAIC_RX_DRV_BUFFER_SIZE ];
238  uint8_t uart_tx_buffer[ MOSAIC_TX_DRV_BUFFER_SIZE ];
240 } mosaic_t;
241 
246 typedef struct
247 {
248  // Communication gpio pins
249  pin_name_t rx_pin;
250  pin_name_t tx_pin;
252  // Additional gpio pins
253  pin_name_t rst;
254  pin_name_t cts;
255  pin_name_t rdy;
256  pin_name_t rts;
258  // Static variable
259  uint32_t baud_rate;
261  uart_data_bits_t data_bit;
262  uart_parity_t parity_bit;
263  uart_stop_bits_t stop_bit;
265 } mosaic_cfg_t;
266 
271 typedef enum
272 {
276 
278 
295 
309 err_t mosaic_init ( mosaic_t *ctx, mosaic_cfg_t *cfg );
310 
323 err_t mosaic_generic_write ( mosaic_t *ctx, uint8_t *data_in, uint16_t len );
324 
337 err_t mosaic_generic_read ( mosaic_t *ctx, uint8_t *data_out, uint16_t len );
338 
348 void mosaic_set_rst_pin ( mosaic_t *ctx, uint8_t state );
349 
359 void mosaic_set_cts_pin ( mosaic_t *ctx, uint8_t state );
360 
369 uint8_t mosaic_get_rdy_pin ( mosaic_t *ctx );
370 
379 uint8_t mosaic_get_rts_pin ( mosaic_t *ctx );
380 
390 void mosaic_send_cmd ( mosaic_t *ctx, uint8_t *cmd );
391 
402 void mosaic_send_cmd_with_par ( mosaic_t *ctx, uint8_t *cmd_buf, uint8_t *param_buf );
403 
414 void mosaic_enable_nmea_output ( mosaic_t *ctx, uint8_t *msg_param, uint8_t *interval );
415 
425 
437 err_t mosaic_parse_gga ( uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data );
438 
439 #ifdef __cplusplus
440 }
441 #endif
442 #endif // MOSAIC_H
443  // mosaic
445 
446 // ------------------------------------------------------------------------ END
mosaic_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: mosaic.h:263
mosaic_generic_write
err_t mosaic_generic_write(mosaic_t *ctx, uint8_t *data_in, uint16_t len)
Mosaic data writing function.
mosaic_cfg_t
Mosaic Click configuration object.
Definition: mosaic.h:247
mosaic_t::uart
uart_t uart
Definition: mosaic.h:234
mosaic_cfg_t::rx_pin
pin_name_t rx_pin
Definition: mosaic.h:249
MOSAIC_ERROR
@ MOSAIC_ERROR
Definition: mosaic.h:274
mosaic_disable_nmea_output
void mosaic_disable_nmea_output(mosaic_t *ctx)
Mosaic disable nmea output function.
mosaic_cfg_t::rst
pin_name_t rst
Definition: mosaic.h:253
mosaic_generic_read
err_t mosaic_generic_read(mosaic_t *ctx, uint8_t *data_out, uint16_t len)
Mosaic data reading function.
mosaic_cfg_t::tx_pin
pin_name_t tx_pin
Definition: mosaic.h:250
mosaic_t::cts
digital_out_t cts
Definition: mosaic.h:227
mosaic_cfg_t::rdy
pin_name_t rdy
Definition: mosaic.h:255
mosaic_cfg_t::baud_rate
uint32_t baud_rate
Definition: mosaic.h:259
mosaic_cfg_t::uart_blocking
bool uart_blocking
Definition: mosaic.h:260
mosaic_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: mosaic.h:261
mosaic_cfg_setup
void mosaic_cfg_setup(mosaic_cfg_t *cfg)
Mosaic configuration object setup function.
mosaic_init
err_t mosaic_init(mosaic_t *ctx, mosaic_cfg_t *cfg)
Mosaic initialization function.
mosaic_set_cts_pin
void mosaic_set_cts_pin(mosaic_t *ctx, uint8_t state)
Mosaic set cts pin function.
MOSAIC_TX_DRV_BUFFER_SIZE
#define MOSAIC_TX_DRV_BUFFER_SIZE
Definition: mosaic.h:190
mosaic_set_rst_pin
void mosaic_set_rst_pin(mosaic_t *ctx, uint8_t state)
Mosaic set rst pin function.
mosaic_get_rts_pin
uint8_t mosaic_get_rts_pin(mosaic_t *ctx)
Mosaic get rts pin function.
mosaic_cfg_t::rts
pin_name_t rts
Definition: mosaic.h:256
mosaic_send_cmd
void mosaic_send_cmd(mosaic_t *ctx, uint8_t *cmd)
Send command function.
mosaic_t::rst
digital_out_t rst
Definition: mosaic.h:226
mosaic_enable_nmea_output
void mosaic_enable_nmea_output(mosaic_t *ctx, uint8_t *msg_param, uint8_t *interval)
Mosaic enable nmea output function.
MOSAIC_ERROR_TIMEOUT
@ MOSAIC_ERROR_TIMEOUT
Definition: mosaic.h:275
MOSAIC_RX_DRV_BUFFER_SIZE
#define MOSAIC_RX_DRV_BUFFER_SIZE
Mosaic driver buffer size.
Definition: mosaic.h:189
mosaic_get_rdy_pin
uint8_t mosaic_get_rdy_pin(mosaic_t *ctx)
Mosaic get rdy pin function.
mosaic_return_value_t
mosaic_return_value_t
Mosaic Click return value data.
Definition: mosaic.h:272
mosaic_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: mosaic.h:262
mosaic_send_cmd_with_par
void mosaic_send_cmd_with_par(mosaic_t *ctx, uint8_t *cmd_buf, uint8_t *param_buf)
Send command function with parameter.
mosaic_parse_gga
err_t mosaic_parse_gga(uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data)
Mosaic parse GGA function.
mosaic_t::rts
digital_in_t rts
Definition: mosaic.h:231
mosaic_t
Mosaic Click context object.
Definition: mosaic.h:224
MOSAIC_OK
@ MOSAIC_OK
Definition: mosaic.h:273
mosaic_cfg_t::cts
pin_name_t cts
Definition: mosaic.h:254
mosaic_t::rdy
digital_in_t rdy
Definition: mosaic.h:230