gps  2.0.0.0
gps.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 GPS_H
36 #define GPS_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 GPS_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.reset = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.tmpls = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define GPS_RETVAL uint8_t
75 
76 #define GPS_OK 0x00
77 #define GPS_INIT_ERROR 0xFF
78 
84 #define GPS_NEMA_GPGGA 1
85 #define GPS_NEMA_GPGLL 3
86 #define GPS_NEMA_GPGGA_NUM_ELEMENT 15
87 #define GPS_NEMA_GPGLL_NUM_ELEMENT 5
88 
94 #define GPS_GPGGA_TIME 1
95 #define GPS_GPGGA_LATITUDE 2
96 #define GPS_GPGGA_LATITUDE_SIDE 3
97 #define GPS_GPGGA_LONGITUDE 4
98 #define GPS_GPGGA_LONGITUDE_SIDE 5
99 #define GPS_GPGGA_QUALITY_INDICATOR 6
100 #define GPS_GPGGA_NUMBER_OF_SATELLITES 7
101 #define GPS_GPGGA_H_DILUTION_OF_POS 8
102 #define GPS_GPGGA_ALTITUDE 9
103 #define GPS_GPGGA_ALTITUDE_UNIT 10
104 #define GPS_GPGGA_GEOIDAL_SEPARATION 11
105 #define GPS_GPGGA_GEOIDAL_SEPARATION_UNIT 12
106 #define GPS_GPGGA_TIME_SINCE_LAST_DGPS 13
107 #define GPS_GPGGA_DGPS_REFERENCE_STATION_ID 14
108 
114 #define GPS_GPGLL_LATITUDE 1
115 #define GPS_GPGLL_LATITUDE_SIDE 2
116 #define GPS_GPGLL_LONGITUDE 3
117 #define GPS_GPGLL_LONGITUDE_SIDE 4
118 
124 #define GPS_ERROR_COMMAND_OR_ELEMENT 0xFF
125 #define GPS_ERROR_START_OR_END_COMMAND 0x8F
126 #define GPS_ERROR_NEXT_ELEMENT 0x4F
127 #define GPS_ERROR_CURRENT_ELEMENT 0x2F
128 #define GPS_NO_ERROR 0x00
129 
135 #define DRV_RX_BUFFER_SIZE 600
136 #define DRV_TX_BUFFER_SIZE 100
137  // End group macro
140 // --------------------------------------------------------------- PUBLIC TYPES
148 typedef struct
149 {
150  // Output pins
151 
152  digital_out_t reset;
153 
154  // Input pins
155 
156  digital_in_t tmpls;
157 
158  // Modules
159 
160  uart_t uart;
161 
162  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
163  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
164 
165 } gps_t;
166 
170 typedef struct
171 {
172  // Communication gpio pins
173 
174  pin_name_t rx_pin;
175  pin_name_t tx_pin;
176 
177  // Additional gpio pins
178 
179  pin_name_t reset;
180  pin_name_t tmpls;
181 
182  // static variable
183 
184  uint32_t baud_rate; // Clock speed.
186  uart_data_bits_t data_bit; // Data bits.
187  uart_parity_t parity_bit; // Parity bit.
188  uart_stop_bits_t stop_bit; // Stop bits.
189 
190 } gps_cfg_t;
191 
195 typedef uint8_t gps_error_t;
196  // End types group
198 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
199 
205 #ifdef __cplusplus
206 extern "C"{
207 #endif
208 
217 void gps_cfg_setup ( gps_cfg_t *cfg );
218 
227 
232 void gps_module_wakeup ( gps_t *ctx );
233 
239 void gps_set_rst_pin ( gps_t *ctx, uint8_t state );
240 
246 uint8_t gps_get_tmpls_pin ( gps_t *ctx );
247 
254 void gps_generic_write ( gps_t *ctx, char *data_buf, uint16_t len );
255 
263 int32_t gps_generic_read ( gps_t *ctx, char *data_buf, uint16_t max_len );
264 
274 (
275  char *rsp, uint8_t command,
276  uint8_t element, char *parser_buf
277 );
278 
279 #ifdef __cplusplus
280 }
281 #endif
282 #endif // _GPS_H_
283  // End public_function group
286 
287 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: gps.h:135
gps_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps.h:184
gps_t::reset
digital_out_t reset
Definition: gps.h:152
gps_error_t
uint8_t gps_error_t
Error type.
Definition: gps.h:195
GPS_RETVAL
#define GPS_RETVAL
Definition: gps.h:74
gps_t::tmpls
digital_in_t tmpls
Definition: gps.h:156
gps_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gps.h:175
gps_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps.h:187
gps_cfg_t::uart_blocking
bool uart_blocking
Definition: gps.h:185
gps_get_tmpls_pin
uint8_t gps_get_tmpls_pin(gps_t *ctx)
uint8_t gps_get_tmpls_pin ( gps_t *ctx );
gps_cfg_setup
void gps_cfg_setup(gps_cfg_t *cfg)
Config Object Initialization function.
gps_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gps.h:186
gps_init
GPS_RETVAL gps_init(gps_t *ctx, gps_cfg_t *cfg)
Initialization function.
gps_generic_parser
gps_error_t gps_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
gps_t::uart
uart_t uart
Definition: gps.h:160
gps_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps.h:174
gps_generic_write
void gps_generic_write(gps_t *ctx, char *data_buf, uint16_t len)
Generic write function.
gps_module_wakeup
void gps_module_wakeup(gps_t *ctx)
Wake-up module.
gps_generic_read
int32_t gps_generic_read(gps_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
gps_cfg_t::reset
pin_name_t reset
Definition: gps.h:179
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: gps.h:136
gps_set_rst_pin
void gps_set_rst_pin(gps_t *ctx, uint8_t state)
Set RST ( reset ) pin state.
gps_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps.h:188
gps_t
Click ctx object definition.
Definition: gps.h:149
gps_cfg_t::tmpls
pin_name_t tmpls
Definition: gps.h:180
gps_cfg_t
Click configuration structure definition.
Definition: gps.h:171