gps4  2.0.0.0
gps4.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 GPS4_H
36 #define GPS4_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 GPS4_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70  cfg.fon = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_PWM )
73 
79 #define GPS4_RETVAL uint8_t
80 
81 #define GPS4_OK 0x00
82 #define GPS4_INIT_ERROR 0xFF
83 
89 #define GPS4_NEMA_GPGGA 1
90 #define GPS4_NEMA_GPGLL 3
91 #define GPS4_NEMA_GPGGA_NUM_ELEMENT 15
92 #define GPS4_NEMA_GPGLL_NUM_ELEMENT 5
93 
99 #define GPS4_GPGGA_TIME 1
100 #define GPS4_GPGGA_LATITUDE 2
101 #define GPS4_GPGGA_LATITUDE_SIDE 3
102 #define GPS4_GPGGA_LONGITUDE 4
103 #define GPS4_GPGGA_LONGITUDE_SIDE 5
104 #define GPS4_GPGGA_QUALITY_INDICATOR 6
105 #define GPS4_GPGGA_NUMBER_OF_SATELLITES 7
106 #define GPS4_GPGGA_H_DILUTION_OF_POS 8
107 #define GPS4_GPGGA_ALTITUDE 9
108 #define GPS4_GPGGA_ALTITUDE_UNIT 10
109 #define GPS4_GPGGA_GEOIDAL_SEPARATION 11
110 #define GPS4_GPGGA_GEOIDAL_SEPARATION_UNIT 12
111 #define GPS4_GPGGA_TIME_SINCE_LAST_DGPS 13
112 #define GPS4_GPGGA_DGPS_REFERENCE_STATION_ID 14
113 
119 #define GPS4_GPGLL_LATITUDE 1
120 #define GPS4_GPGLL_LATITUDE_SIDE 2
121 #define GPS4_GPGLL_LONGITUDE 3
122 #define GPS4_GPGLL_LONGITUDE_SIDE 4
123 
129 #define GPS4_ERROR_COMMAND_OR_ELEMENT 0xFF
130 #define GPS4_ERROR_START_OR_END_COMMAND 0x8F
131 #define GPS4_ERROR_NEXT_ELEMENT 0x4F
132 #define GPS4_ERROR_CURRENT_ELEMENT 0x2F
133 #define GPS4_NO_ERROR 0x00
134 
140 #define DRV_RX_BUFFER_SIZE 600
141 #define DRV_TX_BUFFER_SIZE 100
142  // End group macro
145 // --------------------------------------------------------------- PUBLIC TYPES
153 typedef struct
154 {
155  // Output pins
156 
157  digital_out_t rst;
158 
159  // Input pins
160 
161  digital_in_t fon;
162  digital_in_t stb;
163 
164  // Modules
165 
166  uart_t uart;
167 
168  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
169  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
170 
171 } gps4_t;
172 
176 typedef struct
177 {
178  // Communication gpio pins
179 
180  pin_name_t rx_pin;
181  pin_name_t tx_pin;
182 
183  // Additional gpio pins
184 
185  pin_name_t fon;
186  pin_name_t rst;
187  pin_name_t stb;
188 
189  // static variable
190 
191  uint32_t baud_rate; // Clock speed.
193  uart_data_bits_t data_bit; // Data bits.
194  uart_parity_t parity_bit; // Parity bit.
195  uart_stop_bits_t stop_bit; // Stop bits.
196 
197 } gps4_cfg_t;
198 
202 typedef uint8_t gps4_error_t;
203  // End types group
205 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
206 
212 #ifdef __cplusplus
213 extern "C"{
214 #endif
215 
225 
234 
240 
245 void gps4_module_reset ( gps4_t *ctx );
246 
252 void gps4_set_wkp_pin ( gps4_t *ctx, uint8_t state );
253 
259 void gps4_set_rst_pin ( gps4_t *ctx, uint8_t state );
260 
266 uint8_t gps4_get_pps_pin ( gps4_t *ctx );
267 
274 void gps4_generic_write ( gps4_t *ctx, char *data_buf, uint16_t len );
275 
283 int32_t gps4_generic_read ( gps4_t *ctx, char *data_buf, uint16_t max_len );
284 
294 (
295  char *rsp, uint8_t command,
296  uint8_t element, char *parser_buf
297 );
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 #endif // _GPS4_H_
303  // End public_function group
306 
307 // ------------------------------------------------------------------------- END
gps4_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps4.h:191
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: gps4.h:140
gps4_t::stb
digital_in_t stb
Definition: gps4.h:162
gps4_init
GPS4_RETVAL gps4_init(gps4_t *ctx, gps4_cfg_t *cfg)
Initialization function.
gps4_cfg_t::uart_blocking
bool uart_blocking
Definition: gps4.h:192
gps4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gps4.h:193
gps4_t::uart
uart_t uart
Definition: gps4.h:166
gps4_generic_write
void gps4_generic_write(gps4_t *ctx, char *data_buf, uint16_t len)
Generic write function.
gps4_module_reset
void gps4_module_reset(gps4_t *ctx)
Reset module.
gps4_get_pps_pin
uint8_t gps4_get_pps_pin(gps4_t *ctx)
Get PPS pin state.
gps4_cfg_t::stb
pin_name_t stb
Definition: gps4.h:187
gps4_t::rst
digital_out_t rst
Definition: gps4.h:157
gps4_t
Click ctx object definition.
Definition: gps4.h:154
gps4_cfg_t::fon
pin_name_t fon
Definition: gps4.h:185
GPS4_RETVAL
#define GPS4_RETVAL
Definition: gps4.h:79
gps4_generic_read
int32_t gps4_generic_read(gps4_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
gps4_error_t
uint8_t gps4_error_t
Error type.
Definition: gps4.h:202
gps4_module_wakeup
void gps4_module_wakeup(gps4_t *ctx)
Wake-up module.
gps4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps4.h:194
gps4_t::fon
digital_in_t fon
Definition: gps4.h:161
gps4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps4.h:180
gps4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gps4.h:181
gps4_cfg_t::rst
pin_name_t rst
Definition: gps4.h:186
gps4_set_wkp_pin
void gps4_set_wkp_pin(gps4_t *ctx, uint8_t state)
Set WKP ( wake-up ) pin state.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: gps4.h:141
gps4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps4.h:195
gps4_cfg_setup
void gps4_cfg_setup(gps4_cfg_t *cfg)
Config Object Initialization function.
gps4_cfg_t
Click configuration structure definition.
Definition: gps4.h:177
gps4_generic_parser
gps4_error_t gps4_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
gps4_set_rst_pin
void gps4_set_rst_pin(gps4_t *ctx, uint8_t state)
Set RST ( reset ) pin state.