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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_uart.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define GPS_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70  cfg.reset = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.tmpls = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define GPS_RETVAL uint8_t
79 
80 #define GPS_OK 0x00
81 #define GPS_INIT_ERROR 0xFF
82 
88 #define GPS_NEMA_GPGGA 1
89 #define GPS_NEMA_GPGLL 3
90 #define GPS_NEMA_GPGGA_NUM_ELEMENT 15
91 #define GPS_NEMA_GPGLL_NUM_ELEMENT 5
92 
98 #define GPS_GPGGA_TIME 1
99 #define GPS_GPGGA_LATITUDE 2
100 #define GPS_GPGGA_LATITUDE_SIDE 3
101 #define GPS_GPGGA_LONGITUDE 4
102 #define GPS_GPGGA_LONGITUDE_SIDE 5
103 #define GPS_GPGGA_QUALITY_INDICATOR 6
104 #define GPS_GPGGA_NUMBER_OF_SATELLITES 7
105 #define GPS_GPGGA_H_DILUTION_OF_POS 8
106 #define GPS_GPGGA_ALTITUDE 9
107 #define GPS_GPGGA_ALTITUDE_UNIT 10
108 #define GPS_GPGGA_GEOIDAL_SEPARATION 11
109 #define GPS_GPGGA_GEOIDAL_SEPARATION_UNIT 12
110 #define GPS_GPGGA_TIME_SINCE_LAST_DGPS 13
111 #define GPS_GPGGA_DGPS_REFERENCE_STATION_ID 14
112 
118 #define GPS_GPGLL_LATITUDE 1
119 #define GPS_GPGLL_LATITUDE_SIDE 2
120 #define GPS_GPGLL_LONGITUDE 3
121 #define GPS_GPGLL_LONGITUDE_SIDE 4
122 
128 #define GPS_ERROR_COMMAND_OR_ELEMENT 0xFF
129 #define GPS_ERROR_START_OR_END_COMMAND 0x8F
130 #define GPS_ERROR_NEXT_ELEMENT 0x4F
131 #define GPS_ERROR_CURRENT_ELEMENT 0x2F
132 #define GPS_NO_ERROR 0x00
133 
139 #define DRV_RX_BUFFER_SIZE 600
140 #define DRV_TX_BUFFER_SIZE 100
141  // End group macro
144 // --------------------------------------------------------------- PUBLIC TYPES
152 typedef struct
153 {
154  // Output pins
155 
156  digital_out_t reset;
157 
158  // Input pins
159 
160  digital_in_t tmpls;
161 
162  // Modules
163 
164  uart_t uart;
165 
166  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
167  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
168 
169 } gps_t;
170 
174 typedef struct
175 {
176  // Communication gpio pins
177 
178  pin_name_t rx_pin;
179  pin_name_t tx_pin;
180 
181  // Additional gpio pins
182 
183  pin_name_t reset;
184  pin_name_t tmpls;
185 
186  // static variable
187 
188  uint32_t baud_rate; // Clock speed.
190  uart_data_bits_t data_bit; // Data bits.
191  uart_parity_t parity_bit; // Parity bit.
192  uart_stop_bits_t stop_bit; // Stop bits.
193 
194 } gps_cfg_t;
195 
199 typedef uint8_t gps_error_t;
200  // End types group
202 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
203 
209 #ifdef __cplusplus
210 extern "C"{
211 #endif
212 
221 void gps_cfg_setup ( gps_cfg_t *cfg );
222 
231 
236 void gps_module_wakeup ( gps_t *ctx );
237 
243 void gps_set_rst_pin ( gps_t *ctx, uint8_t state );
244 
250 uint8_t gps_get_tmpls_pin ( gps_t *ctx );
251 
258 void gps_generic_write ( gps_t *ctx, char *data_buf, uint16_t len );
259 
267 int32_t gps_generic_read ( gps_t *ctx, char *data_buf, uint16_t max_len );
268 
278 (
279  char *rsp, uint8_t command,
280  uint8_t element, char *parser_buf
281 );
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 #endif // _GPS_H_
287  // End public_function group
290 
291 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: gps.h:139
gps_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps.h:188
gps_t::reset
digital_out_t reset
Definition: gps.h:156
gps_error_t
uint8_t gps_error_t
Error type.
Definition: gps.h:199
GPS_RETVAL
#define GPS_RETVAL
Definition: gps.h:78
gps_t::tmpls
digital_in_t tmpls
Definition: gps.h:160
gps_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gps.h:179
gps_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps.h:191
gps_cfg_t::uart_blocking
bool uart_blocking
Definition: gps.h:189
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:190
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:164
gps_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps.h:178
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:183
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: gps.h:140
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:192
gps_t
Click ctx object definition.
Definition: gps.h:153
gps_cfg_t::tmpls
pin_name_t tmpls
Definition: gps.h:184
gps_cfg_t
Click configuration structure definition.
Definition: gps.h:175