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 
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 GPS4_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.fon = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_PWM )
69 
75 #define GPS4_RETVAL uint8_t
76 
77 #define GPS4_OK 0x00
78 #define GPS4_INIT_ERROR 0xFF
79 
85 #define GPS4_NEMA_GPGGA 1
86 #define GPS4_NEMA_GPGLL 3
87 #define GPS4_NEMA_GPGGA_NUM_ELEMENT 15
88 #define GPS4_NEMA_GPGLL_NUM_ELEMENT 5
89 
95 #define GPS4_GPGGA_TIME 1
96 #define GPS4_GPGGA_LATITUDE 2
97 #define GPS4_GPGGA_LATITUDE_SIDE 3
98 #define GPS4_GPGGA_LONGITUDE 4
99 #define GPS4_GPGGA_LONGITUDE_SIDE 5
100 #define GPS4_GPGGA_QUALITY_INDICATOR 6
101 #define GPS4_GPGGA_NUMBER_OF_SATELLITES 7
102 #define GPS4_GPGGA_H_DILUTION_OF_POS 8
103 #define GPS4_GPGGA_ALTITUDE 9
104 #define GPS4_GPGGA_ALTITUDE_UNIT 10
105 #define GPS4_GPGGA_GEOIDAL_SEPARATION 11
106 #define GPS4_GPGGA_GEOIDAL_SEPARATION_UNIT 12
107 #define GPS4_GPGGA_TIME_SINCE_LAST_DGPS 13
108 #define GPS4_GPGGA_DGPS_REFERENCE_STATION_ID 14
109 
115 #define GPS4_GPGLL_LATITUDE 1
116 #define GPS4_GPGLL_LATITUDE_SIDE 2
117 #define GPS4_GPGLL_LONGITUDE 3
118 #define GPS4_GPGLL_LONGITUDE_SIDE 4
119 
125 #define GPS4_ERROR_COMMAND_OR_ELEMENT 0xFF
126 #define GPS4_ERROR_START_OR_END_COMMAND 0x8F
127 #define GPS4_ERROR_NEXT_ELEMENT 0x4F
128 #define GPS4_ERROR_CURRENT_ELEMENT 0x2F
129 #define GPS4_NO_ERROR 0x00
130 
136 #define DRV_RX_BUFFER_SIZE 600
137 #define DRV_TX_BUFFER_SIZE 100
138  // End group macro
141 // --------------------------------------------------------------- PUBLIC TYPES
149 typedef struct
150 {
151  // Output pins
152 
153  digital_out_t rst;
154 
155  // Input pins
156 
157  digital_in_t fon;
158  digital_in_t stb;
159 
160  // Modules
161 
162  uart_t uart;
163 
164  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
165  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
166 
167 } gps4_t;
168 
172 typedef struct
173 {
174  // Communication gpio pins
175 
176  pin_name_t rx_pin;
177  pin_name_t tx_pin;
178 
179  // Additional gpio pins
180 
181  pin_name_t fon;
182  pin_name_t rst;
183  pin_name_t stb;
184 
185  // static variable
186 
187  uint32_t baud_rate; // Clock speed.
189  uart_data_bits_t data_bit; // Data bits.
190  uart_parity_t parity_bit; // Parity bit.
191  uart_stop_bits_t stop_bit; // Stop bits.
192 
193 } gps4_cfg_t;
194 
198 typedef uint8_t gps4_error_t;
199  // End types group
201 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
202 
208 #ifdef __cplusplus
209 extern "C"{
210 #endif
211 
221 
230 
236 
241 void gps4_module_reset ( gps4_t *ctx );
242 
248 void gps4_set_wkp_pin ( gps4_t *ctx, uint8_t state );
249 
255 void gps4_set_rst_pin ( gps4_t *ctx, uint8_t state );
256 
262 uint8_t gps4_get_pps_pin ( gps4_t *ctx );
263 
270 void gps4_generic_write ( gps4_t *ctx, char *data_buf, uint16_t len );
271 
279 int32_t gps4_generic_read ( gps4_t *ctx, char *data_buf, uint16_t max_len );
280 
290 (
291  char *rsp, uint8_t command,
292  uint8_t element, char *parser_buf
293 );
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 #endif // _GPS4_H_
299  // End public_function group
302 
303 // ------------------------------------------------------------------------- END
gps4_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps4.h:187
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: gps4.h:136
gps4_t::stb
digital_in_t stb
Definition: gps4.h:158
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:188
gps4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gps4.h:189
gps4_t::uart
uart_t uart
Definition: gps4.h:162
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:183
gps4_t::rst
digital_out_t rst
Definition: gps4.h:153
gps4_t
Click ctx object definition.
Definition: gps4.h:150
gps4_cfg_t::fon
pin_name_t fon
Definition: gps4.h:181
GPS4_RETVAL
#define GPS4_RETVAL
Definition: gps4.h:75
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:198
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:190
gps4_t::fon
digital_in_t fon
Definition: gps4.h:157
gps4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps4.h:176
gps4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gps4.h:177
gps4_cfg_t::rst
pin_name_t rst
Definition: gps4.h:182
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:137
gps4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps4.h:191
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:173
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.