Csr location class shows location and satellite information, which supports H13467 + ST F103RB/NXP LCP1549 boards now.

Dependents:   CsrLocationDemo CsrLocationDemo

Fork of CsrLocation by jie zhao

Committer:
zhjcpi
Date:
Mon Aug 11 03:23:23 2014 +0000
Revision:
8:fa29f8455134
Parent:
7:1fde78f27d5b
Child:
9:e6f22b1a7797
Add wakeup pin input process.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zhjcpi 0:aba381fc8158 1
zhjcpi 0:aba381fc8158 2 /* CsrLocation class for mbed Microcontroller
zhjcpi 0:aba381fc8158 3 * Copyright 2014 CSR plc
zhjcpi 0:aba381fc8158 4 */
zhjcpi 0:aba381fc8158 5
zhjcpi 0:aba381fc8158 6
zhjcpi 0:aba381fc8158 7 #ifndef CSRLOCATION_H
zhjcpi 0:aba381fc8158 8 #define CSRLOCATION_H
zhjcpi 0:aba381fc8158 9
zhjcpi 0:aba381fc8158 10
zhjcpi 0:aba381fc8158 11 #define CSR_LOC_SDK_VER "CSR-LOC-SDK-0.5"
zhjcpi 0:aba381fc8158 12
zhjcpi 2:d4fe184925f2 13 typedef uint16_t CsrResult;
zhjcpi 0:aba381fc8158 14 #define CSR_RESULT_SUCCESS ((CsrResult) 0x0000)
zhjcpi 0:aba381fc8158 15 #define CSR_RESULT_FAILURE ((CsrResult) 0xFFFF)
zhjcpi 0:aba381fc8158 16
zhjcpi 3:71690f7bb480 17 #ifdef TARGET_LPC1768
zhjcpi 3:71690f7bb480 18 #define PINMAP_UART_DEBUG_TX USBTX
zhjcpi 3:71690f7bb480 19 #define PINMAP_UART_DEBUG_RX USBRX
zhjcpi 3:71690f7bb480 20 #define PINMAP_UART_LOC_TX D8
zhjcpi 3:71690f7bb480 21 #define PINMAP_UART_LOC_RX D9
zhjcpi 3:71690f7bb480 22 #define PINMAP_GPIO_LOC_ONOFF D11
zhjcpi 3:71690f7bb480 23 #define PINMAP_GPIO_LOC_RESET D12
zhjcpi 7:1fde78f27d5b 24 #define PINMAP_GPIO_BTN D6
zhjcpi 7:1fde78f27d5b 25 #define PINMAP_GPIO_TEST D10
zhjcpi 3:71690f7bb480 26 #define LOC_LED1 LED1
zhjcpi 3:71690f7bb480 27 #define LOC_LED2 LED2
zhjcpi 3:71690f7bb480 28 #define DBG_SERIAL_TYPE RawSerial
zhjcpi 3:71690f7bb480 29 #define LOC_SERIAL_TYPE RawSerial
zhjcpi 3:71690f7bb480 30 #elif defined(TARGET_LPC1549) || defined(TARGET_NUCLEO_F103RB)
zhjcpi 3:71690f7bb480 31 #define PINMAP_UART_DEBUG_TX D1
zhjcpi 3:71690f7bb480 32 #define PINMAP_UART_DEBUG_RX D0
zhjcpi 3:71690f7bb480 33 #define PINMAP_UART_LOC_TX D8
zhjcpi 3:71690f7bb480 34 #define PINMAP_UART_LOC_RX D2
zhjcpi 5:219dfc2905dc 35 #define PINMAP_GPIO_LOC_ONOFF D9
zhjcpi 5:219dfc2905dc 36 #define PINMAP_GPIO_LOC_WAKEUP D3
zhjcpi 3:71690f7bb480 37 #define PINMAP_GPIO_LOC_RESET D4
zhjcpi 7:1fde78f27d5b 38 #define PINMAP_GPIO_BTN D6
zhjcpi 7:1fde78f27d5b 39 #define PINMAP_GPIO_TEST D10
zhjcpi 6:aed3c66b39d9 40 #define LOC_LED1 D7
zhjcpi 6:aed3c66b39d9 41 #define LOC_LED2 D5
zhjcpi 3:71690f7bb480 42 #define DBG_SERIAL_TYPE Serial
zhjcpi 3:71690f7bb480 43 #define LOC_SERIAL_TYPE RawSerial
zhjcpi 3:71690f7bb480 44 #endif
zhjcpi 3:71690f7bb480 45
zhjcpi 3:71690f7bb480 46
zhjcpi 0:aba381fc8158 47 /* OSP protocol related definitions */
zhjcpi 0:aba381fc8158 48 #define MAX_VERSION_LENGTH 80
zhjcpi 0:aba381fc8158 49
zhjcpi 0:aba381fc8158 50 /* OSP message header */
zhjcpi 0:aba381fc8158 51 #define OSP_MSG_HEAD0 (0xA0)
zhjcpi 0:aba381fc8158 52 #define OSP_MSG_HEAD1 (0xA2)
zhjcpi 0:aba381fc8158 53 /* OSP message footer */
zhjcpi 0:aba381fc8158 54 #define OSP_MSG_TAIL0 (0xB0)
zhjcpi 0:aba381fc8158 55 #define OSP_MSG_TAIL1 (0xB3)
zhjcpi 0:aba381fc8158 56
zhjcpi 0:aba381fc8158 57 /* NMEA message header */
zhjcpi 0:aba381fc8158 58 #define NMEA_MSG_HEAD0 ('$')
zhjcpi 0:aba381fc8158 59 #define NMEA_MSG_HEAD1 ('G')
zhjcpi 0:aba381fc8158 60 /* NMEA message footer */
zhjcpi 0:aba381fc8158 61 #define NMEA_MSG_TAIL0 ('*')
zhjcpi 0:aba381fc8158 62
zhjcpi 2:d4fe184925f2 63 #define CSR_SWAPIN16(bytestream) (((uint16_t)*((bytestream)+0) << 8) | ((uint16_t)*((bytestream)+1)))
zhjcpi 0:aba381fc8158 64
zhjcpi 0:aba381fc8158 65 #define CSR_SWAPIN32(bytestream)\
zhjcpi 2:d4fe184925f2 66 ( ((uint32_t)*((bytestream)+0) << 24)\
zhjcpi 2:d4fe184925f2 67 | ((uint32_t)*((bytestream)+1) << 16)\
zhjcpi 2:d4fe184925f2 68 | ((uint32_t)*((bytestream)+2) << 8)\
zhjcpi 2:d4fe184925f2 69 | ((uint32_t)*((bytestream)+3) ))
zhjcpi 0:aba381fc8158 70
zhjcpi 0:aba381fc8158 71
zhjcpi 0:aba381fc8158 72 /* import macros for little endian: */
zhjcpi 0:aba381fc8158 73 /* NOTE: must use {} around these macros when calling in a loop */
zhjcpi 0:aba381fc8158 74 #define BINARY_IMPORT_UINT8(bytestream) ( *((bytestream)++))
zhjcpi 2:d4fe184925f2 75 #define BINARY_IMPORT_UINT16(bytestream) ((uint16_t) CSR_SWAPIN16((bytestream))); bytestream+=2
zhjcpi 2:d4fe184925f2 76 #define BINARY_IMPORT_UINT32(bytestream) ((uint32_t) CSR_SWAPIN32((bytestream))); bytestream+=4
zhjcpi 2:d4fe184925f2 77 #define BINARY_IMPORT_SINT32(bytestream) ((int32_t) CSR_SWAPIN32((bytestream))); bytestream+=4
zhjcpi 0:aba381fc8158 78
zhjcpi 0:aba381fc8158 79
zhjcpi 0:aba381fc8158 80 #define OSP_MAKE_MSG_ID(mid, sid) ((((mid) & 0xFF) << 8) | ((sid) & 0xFF))
zhjcpi 0:aba381fc8158 81
zhjcpi 0:aba381fc8158 82 #define OSP_MSG_SW_VERSION OSP_MAKE_MSG_ID(0x06, 0x0)
zhjcpi 0:aba381fc8158 83 #define OSP_MSG_OK_TO_SEND OSP_MAKE_MSG_ID(0x12, 0x0)
zhjcpi 0:aba381fc8158 84 #define OSP_MSG_GEODETIC_NAVIGATION OSP_MAKE_MSG_ID(0x29, 0x0)
zhjcpi 0:aba381fc8158 85 #define OSP_MSG_MULTI_CONSTELLATION OSP_MAKE_MSG_ID(0x43, 0x0)
zhjcpi 0:aba381fc8158 86 #define OSP_MSG_GNSS_NAV_DATA OSP_MAKE_MSG_ID(0x43, 0x01)
zhjcpi 0:aba381fc8158 87 #define OSP_MSG_GNSS_SAT_DATA OSP_MAKE_MSG_ID(0x43, 0x10)
zhjcpi 0:aba381fc8158 88 #define OSP_MSG_HW_CONFIG_REQ OSP_MAKE_MSG_ID(0x47, 0x0)
zhjcpi 0:aba381fc8158 89 #define OSP_MSG_PWR_MODE_RSP OSP_MAKE_MSG_ID(0x5A, 0x0)
zhjcpi 0:aba381fc8158 90 #define OSP_MSG_PWR_MODE_FPM_RSP OSP_MAKE_MSG_ID(0x5A, 0x0)
zhjcpi 0:aba381fc8158 91 #define OSP_MSG_PWR_MODE_LPM_RSP OSP_MAKE_MSG_ID(0x5A, 0x6)
zhjcpi 0:aba381fc8158 92
zhjcpi 0:aba381fc8158 93
zhjcpi 0:aba381fc8158 94 #define GNSS_SAT_DATA_NUM_OF_SATS (15)
zhjcpi 0:aba381fc8158 95 #define CODEC_GLO_MAX_CHANNELS (14)
zhjcpi 0:aba381fc8158 96 /* The end of OSP protocol definitions */
zhjcpi 0:aba381fc8158 97
zhjcpi 0:aba381fc8158 98
zhjcpi 0:aba381fc8158 99 #define LOC_MAX_GNSS_SVS (32)
zhjcpi 0:aba381fc8158 100 #define LOC_GLO_FREQ_OFFSET (77)
zhjcpi 0:aba381fc8158 101 #define LOC_GLO_FREQ_ID_START (70)
zhjcpi 0:aba381fc8158 102 #define LOC_GLO_FREQ_ID_END (83)
zhjcpi 0:aba381fc8158 103 #define LOC_NUM_OF_GLO_FREQ_CHANNELS (1+LOC_GLO_FREQ_ID_END-LOC_GLO_FREQ_ID_START)
zhjcpi 0:aba381fc8158 104
zhjcpi 0:aba381fc8158 105 #define MAX_PORT_NUM_STRING_LENGTH (16)
zhjcpi 0:aba381fc8158 106 #define MAX_SERIAL_BUF_LEN (2048)
zhjcpi 0:aba381fc8158 107 #define MAX_SERIAL_PKT_LEN (512)
zhjcpi 0:aba381fc8158 108
zhjcpi 0:aba381fc8158 109 #define BAUDRATE_NMEA 4800
zhjcpi 0:aba381fc8158 110 #define BAUDRATE_OSP 115200
zhjcpi 0:aba381fc8158 111
zhjcpi 0:aba381fc8158 112 #define PROTO_CHECK_TIMEOUT (2.0)
zhjcpi 0:aba381fc8158 113
zhjcpi 0:aba381fc8158 114 /** Indicates the outputted location information */
zhjcpi 0:aba381fc8158 115 #define LOC_OUTPUT_LOCATION (1)
zhjcpi 0:aba381fc8158 116 /* Indicates the outputted sv status information */
zhjcpi 0:aba381fc8158 117 #define LOC_OUTPUT_SV_STATUS (2)
zhjcpi 0:aba381fc8158 118
zhjcpi 3:71690f7bb480 119 #if 0
zhjcpi 3:71690f7bb480 120 #define CSR_LOG_INFO printf
zhjcpi 3:71690f7bb480 121 #else
zhjcpi 0:aba381fc8158 122 #define CSR_LOG_INFO(...) \
zhjcpi 0:aba381fc8158 123 {\
zhjcpi 0:aba381fc8158 124 if(csrLocInst.pSerialDebug != NULL)\
zhjcpi 0:aba381fc8158 125 {\
zhjcpi 0:aba381fc8158 126 (csrLocInst.pSerialDebug->printf(__VA_ARGS__));\
zhjcpi 0:aba381fc8158 127 }\
zhjcpi 0:aba381fc8158 128 }
zhjcpi 3:71690f7bb480 129 #endif
zhjcpi 0:aba381fc8158 130
zhjcpi 0:aba381fc8158 131 /** Location enent definitions */
zhjcpi 0:aba381fc8158 132 typedef enum
zhjcpi 0:aba381fc8158 133 {
zhjcpi 0:aba381fc8158 134 /** Start result event */
zhjcpi 0:aba381fc8158 135 CSR_LOC_EVENT_START_RESULT,
zhjcpi 0:aba381fc8158 136 /** Stop result event */
zhjcpi 0:aba381fc8158 137 CSR_LOC_EVENT_STOP_RESULT,
zhjcpi 0:aba381fc8158 138 }eCsrLocEventType;
zhjcpi 0:aba381fc8158 139
zhjcpi 0:aba381fc8158 140 /** Power mode selection */
zhjcpi 0:aba381fc8158 141 typedef enum
zhjcpi 0:aba381fc8158 142 {
zhjcpi 0:aba381fc8158 143 /** full power mode */
zhjcpi 0:aba381fc8158 144 PWR_FULL,
zhjcpi 0:aba381fc8158 145 /** Low power push to fix mode */
zhjcpi 0:aba381fc8158 146 PWR_PTF,
zhjcpi 0:aba381fc8158 147 }ePowerMode;
zhjcpi 0:aba381fc8158 148
zhjcpi 3:71690f7bb480 149 /** Power mode selection */
zhjcpi 3:71690f7bb480 150 typedef enum
zhjcpi 3:71690f7bb480 151 {
zhjcpi 3:71690f7bb480 152 /** NMEA protocol */
zhjcpi 3:71690f7bb480 153 PROTO_NMEA,
zhjcpi 3:71690f7bb480 154 /** OSP protocol */
zhjcpi 3:71690f7bb480 155 PROTO_OSP,
zhjcpi 3:71690f7bb480 156 }eProto;
zhjcpi 3:71690f7bb480 157
zhjcpi 0:aba381fc8158 158 /* Protocol detection state */
zhjcpi 0:aba381fc8158 159 typedef enum
zhjcpi 0:aba381fc8158 160 {
zhjcpi 0:aba381fc8158 161 STATE_START1, /* Indicates the first byte of the OSP or NMEA message header*/
zhjcpi 0:aba381fc8158 162 STATE_START2, /* Indicates the second byte of the OSP or NMEA message header */
zhjcpi 0:aba381fc8158 163 STATE_SIZE1, /* Indicates the first byte of the OSP message length */
zhjcpi 0:aba381fc8158 164 STATE_SIZE2, /* Indicates the second byte of the OSP message length */
zhjcpi 0:aba381fc8158 165 STATE_PAYLOAD, /* Indicates the start of payload of the OSP message */
zhjcpi 0:aba381fc8158 166 STATE_CHECKSUM1, /* Indicates the first byte of the OSP message checksum */
zhjcpi 0:aba381fc8158 167 STATE_CHECKSUM2, /* Indicates the second byte of the OSP message checksum */
zhjcpi 0:aba381fc8158 168 STATE_END1, /* Indicates the first byte of the OSP or NMEA message footer */
zhjcpi 0:aba381fc8158 169 STATE_END2 /* Indicates the second byte of the OSP message footer */
zhjcpi 0:aba381fc8158 170 }eProtoDetState;
zhjcpi 0:aba381fc8158 171
zhjcpi 0:aba381fc8158 172 /* Csr Location state */
zhjcpi 0:aba381fc8158 173 typedef enum
zhjcpi 0:aba381fc8158 174 {
zhjcpi 0:aba381fc8158 175 CSR_LOC_STATE_IDLE,
zhjcpi 0:aba381fc8158 176 CSR_LOC_STATE_RUN,
zhjcpi 0:aba381fc8158 177 }eCsrLocState;
zhjcpi 0:aba381fc8158 178
zhjcpi 0:aba381fc8158 179 /* Locatin chip protocol detection state */
zhjcpi 0:aba381fc8158 180 typedef enum
zhjcpi 0:aba381fc8158 181 {
zhjcpi 0:aba381fc8158 182 PROTO_STATE_DET_INVALID = 0,
zhjcpi 0:aba381fc8158 183 PROTO_STATE_DET_OSP,
zhjcpi 0:aba381fc8158 184 PROTO_STATE_DET_NMEA,
zhjcpi 3:71690f7bb480 185 // PROTO_STATE_SWI_OSP_FROM_NMEA,
zhjcpi 0:aba381fc8158 186 PROTO_STATE_DET_OSP_FROM_NMEA,
zhjcpi 3:71690f7bb480 187 // PROTO_STATE_SWI_NMEA_FROM_OSP,
zhjcpi 3:71690f7bb480 188 PROTO_STATE_DET_NMEA_FROM_OSP,
zhjcpi 0:aba381fc8158 189 PROTO_STATE_DET_OK,
zhjcpi 0:aba381fc8158 190 }eProtoState;
zhjcpi 0:aba381fc8158 191
zhjcpi 0:aba381fc8158 192 /* Locaiton chip status */
zhjcpi 0:aba381fc8158 193 typedef enum
zhjcpi 0:aba381fc8158 194 {
zhjcpi 0:aba381fc8158 195 /* Location chip is going to hibernation mode and cannot accept message any more */
zhjcpi 0:aba381fc8158 196 ENGINE_STATUS_NOTOK2SEND,
zhjcpi 0:aba381fc8158 197 /* Locaitn come back from hibernation mode and can accept message now */
zhjcpi 0:aba381fc8158 198 ENGINE_STATUS_OK2SEND
zhjcpi 0:aba381fc8158 199 }eEngineStatus;
zhjcpi 0:aba381fc8158 200
zhjcpi 0:aba381fc8158 201 /* OSP data type to be sent to location chip */
zhjcpi 0:aba381fc8158 202 typedef enum
zhjcpi 0:aba381fc8158 203 {
zhjcpi 0:aba381fc8158 204 SEND_DATA_TYPE_OSP_STOP_REQ,
zhjcpi 0:aba381fc8158 205 SEND_DATA_TYPE_OSP_VER_REQ,
zhjcpi 0:aba381fc8158 206 SEND_DATA_TYPE_OSP_LPM_REQ,
zhjcpi 0:aba381fc8158 207 SEND_DATA_TYPE_OSP_FPM_REQ,
zhjcpi 0:aba381fc8158 208 SEND_DATA_TYPE_OSP_SWITCH2NMEA_REQ,
zhjcpi 3:71690f7bb480 209 SEND_DATA_TYPE_NMEA_SWITCH2OSP_REQ,
zhjcpi 3:71690f7bb480 210 SEND_DATA_TYPE_NMEA_STOP_REQ
zhjcpi 0:aba381fc8158 211 }eSendDataType;
zhjcpi 0:aba381fc8158 212
zhjcpi 3:71690f7bb480 213 typedef struct GpsTime
zhjcpi 0:aba381fc8158 214 {
zhjcpi 0:aba381fc8158 215 /** Week part of GPS time */
zhjcpi 2:d4fe184925f2 216 uint16_t gps_week;
zhjcpi 0:aba381fc8158 217 /** Time of second part of GPS time */
zhjcpi 2:d4fe184925f2 218 uint32_t tow;
zhjcpi 3:71690f7bb480 219 }tGpsTime;
zhjcpi 3:71690f7bb480 220
zhjcpi 3:71690f7bb480 221 /** Structure to hold Position Response Message Information. */
zhjcpi 3:71690f7bb480 222 typedef struct LocPosResp
zhjcpi 3:71690f7bb480 223 {
zhjcpi 3:71690f7bb480 224 union
zhjcpi 3:71690f7bb480 225 {
zhjcpi 3:71690f7bb480 226 tGpsTime gpsTime;
zhjcpi 3:71690f7bb480 227 float utcTime;
zhjcpi 3:71690f7bb480 228 }u;
zhjcpi 0:aba381fc8158 229 /** Latitude */
zhjcpi 2:d4fe184925f2 230 double lat;
zhjcpi 0:aba381fc8158 231 /** Longitude */
zhjcpi 2:d4fe184925f2 232 double lon;
zhjcpi 0:aba381fc8158 233 /** Altitude */
zhjcpi 2:d4fe184925f2 234 double alt;
zhjcpi 0:aba381fc8158 235 } tLocPosResp;
zhjcpi 0:aba381fc8158 236
zhjcpi 0:aba381fc8158 237 /** Structure to hold Satellite Information. */
zhjcpi 0:aba381fc8158 238 typedef struct LocSvInfo
zhjcpi 0:aba381fc8158 239 {
zhjcpi 0:aba381fc8158 240 /** Prn or svId */
zhjcpi 2:d4fe184925f2 241 uint8_t prn;
zhjcpi 0:aba381fc8158 242 /** The ratio of carrier and noise */
zhjcpi 2:d4fe184925f2 243 float cno;
zhjcpi 0:aba381fc8158 244 /** elevation */
zhjcpi 2:d4fe184925f2 245 float elevation;
zhjcpi 0:aba381fc8158 246 /** azimuth */
zhjcpi 2:d4fe184925f2 247 float azimuth;
zhjcpi 0:aba381fc8158 248 /** satellite state */
zhjcpi 2:d4fe184925f2 249 uint16_t state;
zhjcpi 0:aba381fc8158 250 } tLocSvInfo;
zhjcpi 0:aba381fc8158 251
zhjcpi 0:aba381fc8158 252 /** Structure to hold Satellite Information for GLONASS */
zhjcpi 0:aba381fc8158 253 typedef struct LocGloSvInfo
zhjcpi 0:aba381fc8158 254 {
zhjcpi 0:aba381fc8158 255 /** Prn or svId */
zhjcpi 2:d4fe184925f2 256 uint8_t prn;
zhjcpi 0:aba381fc8158 257 /** Slot number */
zhjcpi 2:d4fe184925f2 258 uint8_t sno;
zhjcpi 0:aba381fc8158 259 /** The ratio of carrier and noise */
zhjcpi 2:d4fe184925f2 260 float cno;
zhjcpi 0:aba381fc8158 261 /** elevation */
zhjcpi 2:d4fe184925f2 262 float elevation;
zhjcpi 0:aba381fc8158 263 /** azimuth */
zhjcpi 2:d4fe184925f2 264 float azimuth;
zhjcpi 0:aba381fc8158 265 /** satellite state */
zhjcpi 2:d4fe184925f2 266 uint16_t state;
zhjcpi 0:aba381fc8158 267 } tLocGloSvInfo;
zhjcpi 0:aba381fc8158 268
zhjcpi 0:aba381fc8158 269 /** Structure to hold Satellite Status Information. */
zhjcpi 0:aba381fc8158 270 typedef struct LocSvStatus
zhjcpi 0:aba381fc8158 271 {
zhjcpi 0:aba381fc8158 272 /** Week part of GPS time */
zhjcpi 2:d4fe184925f2 273 uint16_t gps_week;
zhjcpi 0:aba381fc8158 274 /** Time of second part of GPS time */
zhjcpi 2:d4fe184925f2 275 uint32_t tow;
zhjcpi 0:aba381fc8158 276 /** Time of millisecond part of GPS time */
zhjcpi 2:d4fe184925f2 277 uint32_t tow_sub_ms;
zhjcpi 0:aba381fc8158 278
zhjcpi 0:aba381fc8158 279 /**Number of GPS SVs currently visible **/
zhjcpi 2:d4fe184925f2 280 uint8_t numOfSVs;
zhjcpi 0:aba381fc8158 281 /**Number of GLONASS SVs currently visible **/
zhjcpi 2:d4fe184925f2 282 uint8_t numOfGloSVs;
zhjcpi 0:aba381fc8158 283 /** GPS SVs information */
zhjcpi 0:aba381fc8158 284 tLocSvInfo svList[LOC_MAX_GNSS_SVS];
zhjcpi 0:aba381fc8158 285 /** GLONASS SVs information */
zhjcpi 0:aba381fc8158 286 tLocGloSvInfo gloSvList[LOC_NUM_OF_GLO_FREQ_CHANNELS];
zhjcpi 0:aba381fc8158 287 /** Bit mask indicating which SVs have ephemeris data **/
zhjcpi 2:d4fe184925f2 288 uint32_t ephemerisMask;
zhjcpi 0:aba381fc8158 289 /** Bit mask indicating which GLONASS SVs have ephemeris data **/
zhjcpi 2:d4fe184925f2 290 uint32_t gloEphemerisMask;
zhjcpi 0:aba381fc8158 291 /** Bit mask indicating which SVs were used in latest sent fix **/
zhjcpi 2:d4fe184925f2 292 uint32_t svUsedInFixMask;
zhjcpi 0:aba381fc8158 293 /** Bit mask indicating which GLONASS SVs were used in latest sent fix **/
zhjcpi 2:d4fe184925f2 294 uint32_t gloSvUsedInFixMask;
zhjcpi 0:aba381fc8158 295 /** Bit mask indicating which QZSS SVs were used in latest sent fix **/
zhjcpi 2:d4fe184925f2 296 uint32_t qzssSvUsedInFixMask;
zhjcpi 0:aba381fc8158 297 /** Bit mask indicating which SBAS SVs were used in latest sent fix **/
zhjcpi 2:d4fe184925f2 298 uint32_t sbasSvUsedInFixMask;
zhjcpi 0:aba381fc8158 299 } tLocSvStatus;
zhjcpi 0:aba381fc8158 300
zhjcpi 0:aba381fc8158 301
zhjcpi 0:aba381fc8158 302 /** Applicaiton register this out callback function and CsrLocaiton class will pass outputted information to application */
zhjcpi 2:d4fe184925f2 303 typedef void (*csr_app_output_callback)(uint32_t msgId, void * const pMsgData, uint32_t msgLength);
zhjcpi 0:aba381fc8158 304
zhjcpi 0:aba381fc8158 305 /** Applicaiton register this event callback function and CsrLocaiton class will pass internal porcessing event to application */
zhjcpi 2:d4fe184925f2 306 typedef void (*csr_app_event_callback)(eCsrLocEventType event, uint32_t data);
zhjcpi 0:aba381fc8158 307
zhjcpi 0:aba381fc8158 308 /** tCsrLocConfig structure
zhjcpi 0:aba381fc8158 309 * Application needs to decides and pass the configuration into CsrLocation class.
zhjcpi 0:aba381fc8158 310 */
zhjcpi 0:aba381fc8158 311 typedef struct CsrLocConfig
zhjcpi 0:aba381fc8158 312 {
zhjcpi 0:aba381fc8158 313 /** Debug serial port to print debug information */
zhjcpi 3:71690f7bb480 314 DBG_SERIAL_TYPE *pSerialDebug;
zhjcpi 0:aba381fc8158 315 /** location serail port to communicate between mbed host side and location chip */
zhjcpi 3:71690f7bb480 316 LOC_SERIAL_TYPE *pSerialLoc;
zhjcpi 0:aba381fc8158 317 /** GPIO pin to control location chip on, a rising edge is uset to activate location chip. Please note, before activate chip, reset pin should be pull high */
zhjcpi 0:aba381fc8158 318 DigitalOut *pPinOnoff;
zhjcpi 0:aba381fc8158 319 /** GPIO pin to control location chip reset, low level will keep location chip in hibernation state and high level will permit location chip to be activated */
zhjcpi 0:aba381fc8158 320 DigitalOut *pPinReset;
zhjcpi 8:fa29f8455134 321 /** GPIO pin to detect if the chip is still wakeup */
zhjcpi 8:fa29f8455134 322 DigitalIn *pWakeup;
zhjcpi 0:aba381fc8158 323 }tCsrLocConfig;
zhjcpi 0:aba381fc8158 324
zhjcpi 0:aba381fc8158 325 /* General OSP mesasge format */
zhjcpi 0:aba381fc8158 326 typedef struct OspMsg
zhjcpi 0:aba381fc8158 327 {
zhjcpi 2:d4fe184925f2 328 uint32_t msgId;
zhjcpi 2:d4fe184925f2 329 uint32_t length;
zhjcpi 2:d4fe184925f2 330 uint8_t payload[4];
zhjcpi 0:aba381fc8158 331 } tOspMsg;
zhjcpi 0:aba381fc8158 332
zhjcpi 0:aba381fc8158 333 /* keep the internal data of CsrLocation class */
zhjcpi 0:aba381fc8158 334 typedef struct CsrLocInst
zhjcpi 0:aba381fc8158 335 {
zhjcpi 2:d4fe184925f2 336 bool bStopFlag;
zhjcpi 2:d4fe184925f2 337 bool bPwrModeRsp;
zhjcpi 2:d4fe184925f2 338 bool bVerRsp;
zhjcpi 0:aba381fc8158 339
zhjcpi 3:71690f7bb480 340 eProto proto;
zhjcpi 0:aba381fc8158 341 eCsrLocState locState;
zhjcpi 0:aba381fc8158 342 eProtoState protoState;
zhjcpi 0:aba381fc8158 343 ePowerMode pwrMode;
zhjcpi 2:d4fe184925f2 344 uint32_t baudRate;
zhjcpi 2:d4fe184925f2 345 int32_t computedCheckSum;
zhjcpi 2:d4fe184925f2 346 int32_t checksum;
zhjcpi 2:d4fe184925f2 347 int32_t msgSize;
zhjcpi 2:d4fe184925f2 348 int32_t decodeIndex;
zhjcpi 0:aba381fc8158 349 eProtoDetState protoDetState;
zhjcpi 0:aba381fc8158 350 Timeout *pTimeoutChk; /* timeout process */
zhjcpi 2:d4fe184925f2 351 bool bTimeoutFlag;
zhjcpi 0:aba381fc8158 352 eEngineStatus engStatus;
zhjcpi 0:aba381fc8158 353
zhjcpi 0:aba381fc8158 354 tLocSvStatus svStatus; /* 2 kind of messages contribute the svStaus */
zhjcpi 0:aba381fc8158 355
zhjcpi 3:71690f7bb480 356 DBG_SERIAL_TYPE *pSerialDebug;
zhjcpi 3:71690f7bb480 357 LOC_SERIAL_TYPE *pSerialLoc;
zhjcpi 0:aba381fc8158 358 DigitalOut *pPinOnoff;
zhjcpi 0:aba381fc8158 359 DigitalOut *pPinReset;
zhjcpi 8:fa29f8455134 360 DigitalIn *pWakeup;
zhjcpi 0:aba381fc8158 361
zhjcpi 2:d4fe184925f2 362 uint8_t serialBuf[MAX_SERIAL_BUF_LEN]; /* buffer the serial data from uart callback function */
zhjcpi 2:d4fe184925f2 363 uint8_t serialPkt[MAX_SERIAL_PKT_LEN]; /* decoded osp data */
zhjcpi 2:d4fe184925f2 364 uint32_t in;
zhjcpi 2:d4fe184925f2 365 uint32_t out;
zhjcpi 0:aba381fc8158 366
zhjcpi 0:aba381fc8158 367 csr_app_output_callback appOutCb;
zhjcpi 0:aba381fc8158 368 csr_app_event_callback appEventCb;
zhjcpi 0:aba381fc8158 369 }tCsrLocInst;
zhjcpi 0:aba381fc8158 370
zhjcpi 0:aba381fc8158 371 /** CsrLocation class.
zhjcpi 0:aba381fc8158 372 * A location interface to control location chip and get position and satellite information.
zhjcpi 0:aba381fc8158 373 */
zhjcpi 0:aba381fc8158 374 class CsrLocation
zhjcpi 0:aba381fc8158 375 {
zhjcpi 0:aba381fc8158 376 public:
zhjcpi 0:aba381fc8158 377 /** Constructor: CsrLocaiton
zhjcpi 0:aba381fc8158 378 * Create the CsrLocation, accept specified configuration
zhjcpi 0:aba381fc8158 379 * @param pLocConfig Configuration including debug serial port, location communication serail port, onoff pin, reset pin
zhjcpi 0:aba381fc8158 380 */
zhjcpi 0:aba381fc8158 381 CsrLocation(tCsrLocConfig *pLocConfig);
zhjcpi 0:aba381fc8158 382
zhjcpi 0:aba381fc8158 383 /** Destructor: CsrLocation
zhjcpi 0:aba381fc8158 384 * Free allocated resource
zhjcpi 0:aba381fc8158 385 */
zhjcpi 0:aba381fc8158 386 ~CsrLocation();
zhjcpi 0:aba381fc8158 387
zhjcpi 0:aba381fc8158 388 /** Register output callback and enent callback functions
zhjcpi 0:aba381fc8158 389 * @param app_output_cb CsrLocation class output the loaction and satellite information to application
zhjcpi 0:aba381fc8158 390 * @param app_event_cb CsrLocation class output the start and stop result to application
zhjcpi 0:aba381fc8158 391 */
zhjcpi 0:aba381fc8158 392 void CsrLocRegOutput(csr_app_output_callback app_output_cb, csr_app_event_callback app_event_cb);
zhjcpi 0:aba381fc8158 393
zhjcpi 0:aba381fc8158 394 /** hw reset to get location chip into hibernation mode */
zhjcpi 0:aba381fc8158 395 void CsrLocReset(void);
zhjcpi 0:aba381fc8158 396
zhjcpi 0:aba381fc8158 397 /** Start location request, activate location chip */
zhjcpi 3:71690f7bb480 398 void CsrLocStart(ePowerMode pwrMode, eProto proto);
zhjcpi 0:aba381fc8158 399
zhjcpi 0:aba381fc8158 400 /** Process location data from chip and update location and satellite information */
zhjcpi 0:aba381fc8158 401 void CsrLocUpdate(void);
zhjcpi 0:aba381fc8158 402
zhjcpi 0:aba381fc8158 403 /** Stop location request, get location chip into hibernation mode */
zhjcpi 0:aba381fc8158 404 void CsrLocStop(void);
zhjcpi 0:aba381fc8158 405
zhjcpi 0:aba381fc8158 406 /** Speical for low power PTF mode.
zhjcpi 0:aba381fc8158 407 * During low power PTF mode, after reporting position, chip will go to hibernation mode automatically.
zhjcpi 0:aba381fc8158 408 * After 30 seconds, chip will recover and report position again. Then chip will go to hibernation mode again.
zhjcpi 0:aba381fc8158 409 * During the hibernation, application can call CsrLocLpmGetPos to get position immediately and no need to wait for the whole interval.
zhjcpi 0:aba381fc8158 410 */
zhjcpi 0:aba381fc8158 411 void CsrLocLpmGetPos(void);
zhjcpi 0:aba381fc8158 412
zhjcpi 0:aba381fc8158 413 /* A debug interface to switch location chip protocol from OSP at 115200bps to NMEA at 4800bps */
zhjcpi 0:aba381fc8158 414 void CsrLocDebugSwitch2Nmea(void);
zhjcpi 0:aba381fc8158 415
zhjcpi 0:aba381fc8158 416 private:
zhjcpi 0:aba381fc8158 417 /* Internal kept data */
zhjcpi 0:aba381fc8158 418 tCsrLocInst csrLocInst;
zhjcpi 0:aba381fc8158 419
zhjcpi 0:aba381fc8158 420 /* Initialize the serial port and open it */
zhjcpi 0:aba381fc8158 421 void _CsrLocUartInit(void);
zhjcpi 0:aba381fc8158 422
zhjcpi 0:aba381fc8158 423 /* Process the raw stream from location seraial port */
zhjcpi 0:aba381fc8158 424 void _CsrLocProcessRawStream(void);
zhjcpi 0:aba381fc8158 425
zhjcpi 3:71690f7bb480 426 /* Detect the OSP protocol detection timeout */
zhjcpi 3:71690f7bb480 427 void _CsrLocDetProtoOspTimeout(void);
zhjcpi 0:aba381fc8158 428
zhjcpi 0:aba381fc8158 429 /* Detect the NMEA protocol outputted from location serial port */
zhjcpi 3:71690f7bb480 430 void _CsrLocDetProtoNmeaTimeout(void);
zhjcpi 3:71690f7bb480 431
zhjcpi 3:71690f7bb480 432 /* Process the raw NMEA stream, remove the NMEA header, tail, and save the NMEA data into interal buffer */
zhjcpi 3:71690f7bb480 433 void _CsrLocProcessRawNmeaStream(uint8_t data);
zhjcpi 0:aba381fc8158 434
zhjcpi 0:aba381fc8158 435 /* Process the raw OSP stream, remove the OSP header, size, check sum, and save the OSP data into interal buffer */
zhjcpi 2:d4fe184925f2 436 void _CsrLocProcessRawOspStream(uint8_t data);
zhjcpi 0:aba381fc8158 437
zhjcpi 3:71690f7bb480 438 /* Process the saved nmea data and decode them */
zhjcpi 3:71690f7bb480 439 void _CsrLocProcessRawNmeaPkt(void);
zhjcpi 3:71690f7bb480 440
zhjcpi 0:aba381fc8158 441 /* Process the saved OSP data and decode them */
zhjcpi 0:aba381fc8158 442 void _CsrLocProcessRawOspPkt(void);
zhjcpi 0:aba381fc8158 443
zhjcpi 0:aba381fc8158 444 /* Calculate the OSP message size to allcate buffer to save the decoded OSP data */
zhjcpi 2:d4fe184925f2 445 uint32_t _CsrLocCalcMsgSize(void);
zhjcpi 0:aba381fc8158 446
zhjcpi 0:aba381fc8158 447 /* Decode OSP data into pakcet data structure */
zhjcpi 2:d4fe184925f2 448 CsrResult _CsrLocDecodeOspPkt( uint8_t *payload, uint32_t payload_length, uint32_t *message_id, void *message_structure, uint32_t *message_length);
zhjcpi 0:aba381fc8158 449
zhjcpi 0:aba381fc8158 450 /* Process the decode OSP packet and pass to application when needed */
zhjcpi 0:aba381fc8158 451 void _CsrLocProcessOspPkt(tOspMsg *pOspMsg);
zhjcpi 0:aba381fc8158 452
zhjcpi 0:aba381fc8158 453 /* Timeout process, such as detect OSP and NMEA protocol */
zhjcpi 0:aba381fc8158 454 void _CsrLocTimeout(void);
zhjcpi 0:aba381fc8158 455
zhjcpi 0:aba381fc8158 456 /* Location serial port data recevier */
zhjcpi 0:aba381fc8158 457 void _CsrLocRxHandler(void);
zhjcpi 0:aba381fc8158 458
zhjcpi 0:aba381fc8158 459 /* Send special OSP messges to location chip */
zhjcpi 0:aba381fc8158 460 void _CsrLocSendData(eSendDataType type);
zhjcpi 0:aba381fc8158 461
zhjcpi 0:aba381fc8158 462 /* Trigger a pulse on the onoff pin */
zhjcpi 0:aba381fc8158 463 void _CsrLocHwOnoff(void);
zhjcpi 0:aba381fc8158 464
zhjcpi 0:aba381fc8158 465 /* Trigger a reset on the reset pin */
zhjcpi 0:aba381fc8158 466 void _CsrLocHwReset(void);
zhjcpi 8:fa29f8455134 467
zhjcpi 8:fa29f8455134 468 /* Detect wakeup status on the wakeup pin */
zhjcpi 8:fa29f8455134 469 bool _CsrLocIsWakeup(void);
zhjcpi 8:fa29f8455134 470
zhjcpi 0:aba381fc8158 471 };
zhjcpi 0:aba381fc8158 472
zhjcpi 0:aba381fc8158 473
zhjcpi 0:aba381fc8158 474
zhjcpi 0:aba381fc8158 475 #endif /* CSRLOCATION_H */
zhjcpi 3:71690f7bb480 476