gnss5  2.0.0.0
gnss5.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 GNSS5_H
29 #define GNSS5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 #define GNSS5_RSP_START "$"
70 #define GNSS5_RSP_DELIMITER ","
71 #define GNSS5_RSP_END_SEQ "\r\n"
72 #define GNSS5_RSP_GNGGA "$GNGGA"
73 
78 #define GNSS5_GNGGA_ELEMENT_SIZE 15
79 #define GNSS5_GNGGA_TIME 1
80 #define GNSS5_GNGGA_LATITUDE 2
81 #define GNSS5_GNGGA_LATITUDE_SIDE 3
82 #define GNSS5_GNGGA_LONGITUDE 4
83 #define GNSS5_GNGGA_LONGITUDE_SIDE 5
84 #define GNSS5_GNGGA_QUALITY_INDICATOR 6
85 #define GNSS5_GNGGA_NUMBER_OF_SATELLITES 7
86 #define GNSS5_GNGGA_H_DILUTION_OF_POS 8
87 #define GNSS5_GNGGA_ALTITUDE 9
88 #define GNSS5_GNGGA_ALTITUDE_UNIT 10
89 #define GNSS5_GNGGA_GEOIDAL_SEPARATION 11
90 #define GNSS5_GNGGA_GEOIDAL_SEPARATION_UNIT 12
91 #define GNSS5_GNGGA_TIME_SINCE_LAST_DGPS 13
92 #define GNSS5_GNGGA_DGPS_REFERENCE_STATION_ID 14
93 
99 #define GNSS5_DRV_TX_BUFFER_SIZE 100
100 #define GNSS5_DRV_RX_BUFFER_SIZE 1000
101  // gnss5_cmd
103 
118 #define GNSS5_MAP_MIKROBUS( cfg, mikrobus ) \
119  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
120  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
121  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
122  cfg.exi = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
123  cfg.pps = MIKROBUS( mikrobus, MIKROBUS_INT )
124  // gnss5_map // gnss5
127 
132 typedef struct
133 {
134  // Output pins
135  digital_out_t rst;
136 
137  // Input pins
138  digital_in_t exi;
139  digital_in_t pps;
140 
141  // Modules
142  uart_t uart;
144  // Buffers
145  char uart_rx_buffer[ GNSS5_DRV_RX_BUFFER_SIZE ];
146  char uart_tx_buffer[ GNSS5_DRV_TX_BUFFER_SIZE ];
148 } gnss5_t;
149 
154 typedef struct
155 {
156  // Communication gpio pins
157  pin_name_t rx_pin;
158  pin_name_t tx_pin;
160  // Additional gpio pins
161  pin_name_t rst;
162  pin_name_t exi;
163  pin_name_t pps;
164 
165  // Static variable
166  uint32_t baud_rate;
168  uart_data_bits_t data_bit;
169  uart_parity_t parity_bit;
170  uart_stop_bits_t stop_bit;
172 } gnss5_cfg_t;
173 
178 typedef enum
179 {
180  GNSS5_OK = 0,
181  GNSS5_ERROR = -1
182 
184 
201 
215 err_t gnss5_init ( gnss5_t *ctx, gnss5_cfg_t *cfg );
216 
229 err_t gnss5_generic_write ( gnss5_t *ctx, char *data_in, uint16_t len );
230 
243 err_t gnss5_generic_read ( gnss5_t *ctx, char *data_out, uint16_t len );
244 
254 
264 void gnss5_set_rst_pin ( gnss5_t *ctx, uint8_t state );
265 
274 uint8_t gnss5_get_exi_pin ( gnss5_t *ctx );
275 
284 uint8_t gnss5_get_pps_pin ( gnss5_t *ctx );
285 
297 err_t gnss5_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 #endif // GNSS5_H
303  // gnss5
305 
306 // ------------------------------------------------------------------------ END
gnss5_parse_gngga
err_t gnss5_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
GNSS 5 parse GNGGA function.
gnss5_get_pps_pin
uint8_t gnss5_get_pps_pin(gnss5_t *ctx)
GNSS 5 get PPS pin function.
GNSS5_OK
@ GNSS5_OK
Definition: gnss5.h:180
GNSS5_DRV_TX_BUFFER_SIZE
#define GNSS5_DRV_TX_BUFFER_SIZE
GNSS 5 driver buffer size.
Definition: gnss5.h:99
gnss5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gnss5.h:170
gnss5_cfg_setup
void gnss5_cfg_setup(gnss5_cfg_t *cfg)
GNSS 5 configuration object setup function.
gnss5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gnss5.h:169
gnss5_t::rst
digital_out_t rst
Definition: gnss5.h:135
gnss5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gnss5.h:168
gnss5_generic_read
err_t gnss5_generic_read(gnss5_t *ctx, char *data_out, uint16_t len)
GNSS 5 data reading function.
GNSS5_DRV_RX_BUFFER_SIZE
#define GNSS5_DRV_RX_BUFFER_SIZE
Definition: gnss5.h:100
gnss5_init
err_t gnss5_init(gnss5_t *ctx, gnss5_cfg_t *cfg)
GNSS 5 initialization function.
gnss5_cfg_t::uart_blocking
bool uart_blocking
Definition: gnss5.h:167
GNSS5_ERROR
@ GNSS5_ERROR
Definition: gnss5.h:181
gnss5_t
GNSS 5 Click context object.
Definition: gnss5.h:133
gnss5_cfg_t::pps
pin_name_t pps
Definition: gnss5.h:163
gnss5_t::exi
digital_in_t exi
Definition: gnss5.h:138
gnss5_t::uart
uart_t uart
Definition: gnss5.h:142
gnss5_get_exi_pin
uint8_t gnss5_get_exi_pin(gnss5_t *ctx)
GNSS 5 get EXI pin function.
gnss5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gnss5.h:158
gnss5_cfg_t::rst
pin_name_t rst
Definition: gnss5.h:161
gnss5_clear_ring_buffers
void gnss5_clear_ring_buffers(gnss5_t *ctx)
GNSS 5 clear ring buffers function.
gnss5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gnss5.h:157
gnss5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gnss5.h:166
gnss5_cfg_t::exi
pin_name_t exi
Definition: gnss5.h:162
gnss5_cfg_t
GNSS 5 Click configuration object.
Definition: gnss5.h:155
gnss5_t::pps
digital_in_t pps
Definition: gnss5.h:139
gnss5_set_rst_pin
void gnss5_set_rst_pin(gnss5_t *ctx, uint8_t state)
GNSS 5 set RST pin function.
gnss5_return_value_t
gnss5_return_value_t
GNSS 5 Click return value data.
Definition: gnss5.h:179
gnss5_generic_write
err_t gnss5_generic_write(gnss5_t *ctx, char *data_in, uint16_t len)
GNSS 5 data writing function.