irnss  2.0.0.0
irnss.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 IRNSS_H
29 #define IRNSS_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 
73 #define IRNSS_RSP_START "$"
74 #define IRNSS_RSP_DELIMITER ","
75 #define IRNSS_RSP_GNGGA "$GNGGA"
76 
81 #define IRNSS_GNGGA_ELEMENT_SIZE 15
82 #define IRNSS_GNGGA_TIME 1
83 #define IRNSS_GNGGA_LATITUDE 2
84 #define IRNSS_GNGGA_LATITUDE_SIDE 3
85 #define IRNSS_GNGGA_LONGITUDE 4
86 #define IRNSS_GNGGA_LONGITUDE_SIDE 5
87 #define IRNSS_GNGGA_QUALITY_INDICATOR 6
88 #define IRNSS_GNGGA_NUMBER_OF_SATELLITES 7
89 #define IRNSS_GNGGA_H_DILUTION_OF_POS 8
90 #define IRNSS_GNGGA_ALTITUDE 9
91 #define IRNSS_GNGGA_ALTITUDE_UNIT 10
92 #define IRNSS_GNGGA_GEOIDAL_SEPARATION 11
93 #define IRNSS_GNGGA_GEOIDAL_SEPARATION_UNIT 12
94 #define IRNSS_GNGGA_TIME_SINCE_LAST_DGPS 13
95 #define IRNSS_GNGGA_DGPS_REFERENCE_STATION_ID 14
96 
102 #define DRV_RX_BUFFER_SIZE 300
103 #define DRV_TX_BUFFER_SIZE 100
104  // irnss_set
106 
121 #define IRNSS_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
123  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
124  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
125  cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
126 
127  // irnss_map // irnss
129 
134 typedef struct
135 {
136  // Output pins
137  digital_out_t rst;
138  digital_out_t wkp;
140  // Modules
141  uart_t uart;
143  // Buffers
144  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
145  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
147 } irnss_t;
148 
153 typedef struct
154 {
155  // Communication gpio pins
156  pin_name_t rx_pin;
157  pin_name_t tx_pin;
159  // Additional gpio pins
160  pin_name_t rst;
161  pin_name_t wkp;
163  // Static variable
164  uint32_t baud_rate;
166  uart_data_bits_t data_bit;
167  uart_parity_t parity_bit;
168  uart_stop_bits_t stop_bit;
170 } irnss_cfg_t;
171 
176 typedef enum
177 {
178  IRNSS_OK = 0,
179  IRNSS_ERROR = -1
180 
182 
199 
213 err_t irnss_init ( irnss_t *ctx, irnss_cfg_t *cfg );
214 
227 err_t irnss_generic_write ( irnss_t *ctx, char *data_buf, uint16_t len );
228 
241 err_t irnss_generic_read ( irnss_t *ctx, char *data_buf, uint16_t max_len );
242 
253 void irnss_set_rst_pin_state ( irnss_t *ctx, uint8_t state );
254 
265 void irnss_set_wkp_pin_state ( irnss_t *ctx, uint8_t state );
266 
278 err_t irnss_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 #endif // IRNSS_H
284  // irnss
286 
287 // ------------------------------------------------------------------------ END
irnss_cfg_setup
void irnss_cfg_setup(irnss_cfg_t *cfg)
IRNSS configuration object setup function.
irnss_return_value_t
irnss_return_value_t
IRNSS Click return value data.
Definition: irnss.h:177
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
IRNSS driver buffer size.
Definition: irnss.h:102
irnss_t::rst
digital_out_t rst
Definition: irnss.h:137
irnss_cfg_t::baud_rate
uint32_t baud_rate
Definition: irnss.h:164
irnss_set_rst_pin_state
void irnss_set_rst_pin_state(irnss_t *ctx, uint8_t state)
Sets state of the rst pin setting.
irnss_cfg_t::tx_pin
pin_name_t tx_pin
Definition: irnss.h:157
irnss_parse_gngga
err_t irnss_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
IRNSS parse GNGGA function.
irnss_cfg_t::rx_pin
pin_name_t rx_pin
Definition: irnss.h:156
irnss_cfg_t::rst
pin_name_t rst
Definition: irnss.h:160
irnss_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: irnss.h:167
irnss_init
err_t irnss_init(irnss_t *ctx, irnss_cfg_t *cfg)
IRNSS initialization function.
irnss_generic_write
err_t irnss_generic_write(irnss_t *ctx, char *data_buf, uint16_t len)
IRNSS data writing function.
irnss_generic_read
err_t irnss_generic_read(irnss_t *ctx, char *data_buf, uint16_t max_len)
IRNSS data reading function.
IRNSS_OK
@ IRNSS_OK
Definition: irnss.h:178
IRNSS_ERROR
@ IRNSS_ERROR
Definition: irnss.h:179
irnss_t
IRNSS Click context object.
Definition: irnss.h:135
irnss_cfg_t::wkp
pin_name_t wkp
Definition: irnss.h:161
irnss_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: irnss.h:166
irnss_cfg_t::uart_blocking
bool uart_blocking
Definition: irnss.h:165
irnss_t::uart
uart_t uart
Definition: irnss.h:141
irnss_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: irnss.h:168
irnss_cfg_t
IRNSS Click configuration object.
Definition: irnss.h:154
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: irnss.h:103
irnss_t::wkp
digital_out_t wkp
Definition: irnss.h:138
irnss_set_wkp_pin_state
void irnss_set_wkp_pin_state(irnss_t *ctx, uint8_t state)
Sets state of the wkp pin setting.