Device driver for the Novatel OEM615 GPS receiver

Committer:
sam_grove
Date:
Sat Apr 27 23:10:35 2013 +0000
Revision:
3:d55471d8417e
Parent:
2:35b6eb71a635
updated docs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:68a9bea384b5 1 /**
sam_grove 0:68a9bea384b5 2 * @file Oem615.cpp
sam_grove 0:68a9bea384b5 3 * @brief Device driver - Novatel OEM615 GPS
sam_grove 0:68a9bea384b5 4 * @author sam grove
sam_grove 0:68a9bea384b5 5 * @version 1.0
sam_grove 0:68a9bea384b5 6 * @see http://www.novatel.com/support/firmware-software-and-manuals/product-manuals-and-doc-updates/oem6-family/
sam_grove 0:68a9bea384b5 7 *
sam_grove 0:68a9bea384b5 8 * Copyright (c) 2013
sam_grove 0:68a9bea384b5 9 *
sam_grove 0:68a9bea384b5 10 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 0:68a9bea384b5 11 * you may not use this file except in compliance with the License.
sam_grove 0:68a9bea384b5 12 * You may obtain a copy of the License at
sam_grove 0:68a9bea384b5 13 *
sam_grove 0:68a9bea384b5 14 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 0:68a9bea384b5 15 *
sam_grove 0:68a9bea384b5 16 * Unless required by applicable law or agreed to in writing, software
sam_grove 0:68a9bea384b5 17 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 0:68a9bea384b5 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 0:68a9bea384b5 19 * See the License for the specific language governing permissions and
sam_grove 0:68a9bea384b5 20 * limitations under the License.
sam_grove 0:68a9bea384b5 21 */
sam_grove 0:68a9bea384b5 22
sam_grove 0:68a9bea384b5 23 #include "Oem615.h"
sam_grove 0:68a9bea384b5 24
sam_grove 0:68a9bea384b5 25 DigitalOut led_4(LED4);
sam_grove 0:68a9bea384b5 26
sam_grove 0:68a9bea384b5 27 //char const msg_0[] = "RESET";
sam_grove 0:68a9bea384b5 28 char const msg_1[] = "UNLOGALL COM1";
sam_grove 0:68a9bea384b5 29 //char const msg_2[] = "SERIALCONFIG COM1 115200 n 8 1 n off";
sam_grove 0:68a9bea384b5 30 char const msg_3[] = "LOG COM1 BESTPOSA ONTIME 1"; //messageID = 42
sam_grove 2:35b6eb71a635 31 char const msg_4[] = "LOG COM1 BESTVelA ONTIME 1"; //messageID = 99
sam_grove 0:68a9bea384b5 32 char const msg_5[] = "LOG COM1 RANGEA ONTIME 1"; //messageID = 43
sam_grove 0:68a9bea384b5 33 //char const msg_6[] = "LOG COM1 TIMEB ONTIME 1"; //messageID = 101
sam_grove 0:68a9bea384b5 34 char const msg_7[] = "SERIALCONFIG COM1 9600 n 8 1 n off";
sam_grove 0:68a9bea384b5 35 char const msg_8[] = "FREQUENCYOUT ENABLESYNC 100000 1000000";
sam_grove 0:68a9bea384b5 36 //char const msg_9[] = "CLOCKADJUST DISABLE";
sam_grove 0:68a9bea384b5 37
sam_grove 0:68a9bea384b5 38 DigitalOut led_2(LED2);
sam_grove 0:68a9bea384b5 39 DigitalOut led_3(LED3);
sam_grove 0:68a9bea384b5 40
sam_grove 0:68a9bea384b5 41 Oem615::Oem615(Serial &uart, DigitalOut &rst, DigitalOut &pwr, InterruptIn &pps, InterruptIn &varf)
sam_grove 0:68a9bea384b5 42 {
sam_grove 0:68a9bea384b5 43
sam_grove 0:68a9bea384b5 44 _uart = &uart;
sam_grove 0:68a9bea384b5 45 _rst = &rst;
sam_grove 0:68a9bea384b5 46 _pwr = &pwr;
sam_grove 0:68a9bea384b5 47 _pps = &pps;
sam_grove 0:68a9bea384b5 48 _varf = &varf;
sam_grove 0:68a9bea384b5 49
sam_grove 0:68a9bea384b5 50 return;
sam_grove 0:68a9bea384b5 51 }
sam_grove 0:68a9bea384b5 52
sam_grove 0:68a9bea384b5 53 void Oem615::init(void)
sam_grove 0:68a9bea384b5 54 {
sam_grove 0:68a9bea384b5 55 _rst->write(0);
sam_grove 0:68a9bea384b5 56 _pwr->write(1);
sam_grove 0:68a9bea384b5 57 _pps->mode(PullUp);
sam_grove 0:68a9bea384b5 58 _varf->mode(PullUp);
sam_grove 0:68a9bea384b5 59
sam_grove 0:68a9bea384b5 60 _uart->baud(9600);
sam_grove 0:68a9bea384b5 61
sam_grove 0:68a9bea384b5 62 return;
sam_grove 0:68a9bea384b5 63 }
sam_grove 0:68a9bea384b5 64
sam_grove 0:68a9bea384b5 65 void Oem615::enable(void)
sam_grove 0:68a9bea384b5 66 {
sam_grove 0:68a9bea384b5 67 LOG("Configuring OEM615 GPS receiver\n");
sam_grove 0:68a9bea384b5 68
sam_grove 0:68a9bea384b5 69 _rst->write(1);
sam_grove 0:68a9bea384b5 70 _pwr->write(0);
sam_grove 0:68a9bea384b5 71 for(int i=0; i<5; ++i)
sam_grove 0:68a9bea384b5 72 {
sam_grove 0:68a9bea384b5 73 LOG("GPS ready in %d\n", (5-i));
sam_grove 0:68a9bea384b5 74 wait(1.0f);
sam_grove 0:68a9bea384b5 75 }
sam_grove 0:68a9bea384b5 76
sam_grove 0:68a9bea384b5 77 LOG("%s\n", msg_7);
sam_grove 0:68a9bea384b5 78 _uart->printf("%s\n", msg_7);
sam_grove 0:68a9bea384b5 79 wait_ms(500);
sam_grove 0:68a9bea384b5 80
sam_grove 0:68a9bea384b5 81 LOG("%s\n", msg_1);
sam_grove 0:68a9bea384b5 82 _uart->printf("%s\n", msg_1);
sam_grove 0:68a9bea384b5 83 wait_ms(500);
sam_grove 0:68a9bea384b5 84
sam_grove 0:68a9bea384b5 85 LOG("%s\n", msg_3);
sam_grove 0:68a9bea384b5 86 _uart->printf("%s\n", msg_3);
sam_grove 0:68a9bea384b5 87 wait_ms(500);
sam_grove 0:68a9bea384b5 88
sam_grove 2:35b6eb71a635 89 LOG("%s\n", msg_4);
sam_grove 2:35b6eb71a635 90 _uart->printf("%s\n", msg_4);
sam_grove 2:35b6eb71a635 91 wait_ms(500);
sam_grove 0:68a9bea384b5 92
sam_grove 0:68a9bea384b5 93 LOG("%s\n", msg_5);
sam_grove 0:68a9bea384b5 94 _uart->printf("%s\n", msg_5);
sam_grove 0:68a9bea384b5 95 wait_ms(500);
sam_grove 0:68a9bea384b5 96
sam_grove 0:68a9bea384b5 97 // LOG("%s\n", msg_9);
sam_grove 0:68a9bea384b5 98 // _uart->printf("%s\n", msg_h9);
sam_grove 0:68a9bea384b5 99 // wait_ms(500);
sam_grove 0:68a9bea384b5 100
sam_grove 0:68a9bea384b5 101 LOG("%s\n", msg_8);
sam_grove 0:68a9bea384b5 102 _uart->printf("%s\n", msg_8);
sam_grove 0:68a9bea384b5 103 wait_ms(500);
sam_grove 0:68a9bea384b5 104
sam_grove 0:68a9bea384b5 105 // LOG("%s\n", msg_2);
sam_grove 0:68a9bea384b5 106 // _uart->printf("%s\n", msg_2);
sam_grove 0:68a9bea384b5 107 // _uart->baud(115200);
sam_grove 0:68a9bea384b5 108 // wait_ms(500);
sam_grove 0:68a9bea384b5 109
sam_grove 0:68a9bea384b5 110 // power up complete - enable the handlers
sam_grove 0:68a9bea384b5 111 _from_pps.start();
sam_grove 0:68a9bea384b5 112 _pps->rise(this, &Oem615::ppsHandler);
sam_grove 0:68a9bea384b5 113 _varf->rise(this, &Oem615::varfHandler);
sam_grove 0:68a9bea384b5 114 _uart->attach(this, &Oem615::uartRxHandler, Serial::RxIrq);
sam_grove 0:68a9bea384b5 115
sam_grove 0:68a9bea384b5 116 return;
sam_grove 0:68a9bea384b5 117 }
sam_grove 0:68a9bea384b5 118
sam_grove 0:68a9bea384b5 119 void Oem615::disable(void)
sam_grove 0:68a9bea384b5 120 {
sam_grove 0:68a9bea384b5 121 _pps->rise(NULL);
sam_grove 0:68a9bea384b5 122 _varf->rise(NULL);
sam_grove 0:68a9bea384b5 123 _uart->attach(NULL, Serial::RxIrq);
sam_grove 0:68a9bea384b5 124 _from_pps.stop();
sam_grove 0:68a9bea384b5 125 _rst->write(0);
sam_grove 0:68a9bea384b5 126 _pwr->write(1);
sam_grove 0:68a9bea384b5 127
sam_grove 0:68a9bea384b5 128 return;
sam_grove 0:68a9bea384b5 129 }
sam_grove 0:68a9bea384b5 130
sam_grove 0:68a9bea384b5 131 void Oem615::ppsHandler(void)
sam_grove 0:68a9bea384b5 132 {
sam_grove 0:68a9bea384b5 133 _from_pps.reset();
sam_grove 0:68a9bea384b5 134 led_2 = !led_2;
sam_grove 0:68a9bea384b5 135
sam_grove 0:68a9bea384b5 136 return;
sam_grove 0:68a9bea384b5 137 }
sam_grove 0:68a9bea384b5 138
sam_grove 0:68a9bea384b5 139 void Oem615::varfHandler(void)
sam_grove 0:68a9bea384b5 140 {
sam_grove 0:68a9bea384b5 141 static int cnt = 0;
sam_grove 0:68a9bea384b5 142 ++cnt;
sam_grove 0:68a9bea384b5 143 led_3 = (cnt%10) ? 0 : 1;
sam_grove 0:68a9bea384b5 144
sam_grove 0:68a9bea384b5 145 return;
sam_grove 0:68a9bea384b5 146 }
sam_grove 0:68a9bea384b5 147
sam_grove 0:68a9bea384b5 148 void Oem615::uartRxHandler(void)
sam_grove 0:68a9bea384b5 149 {
sam_grove 0:68a9bea384b5 150 while(1 == _uart->readable())
sam_grove 0:68a9bea384b5 151 {
sam_grove 0:68a9bea384b5 152 _rxbuf.data[_rxbuf.loc] = _uart->getc();
sam_grove 0:68a9bea384b5 153 ++_rxbuf.loc;
sam_grove 1:12cc9d13cc48 154 // protect the buffer from spilling over
sam_grove 1:12cc9d13cc48 155 _rxbuf.loc &= GPS_RXBUF_MASK;
sam_grove 0:68a9bea384b5 156 }
sam_grove 0:68a9bea384b5 157 led_4 = !led_4;
sam_grove 0:68a9bea384b5 158
sam_grove 0:68a9bea384b5 159 return;
sam_grove 0:68a9bea384b5 160 }
sam_grove 0:68a9bea384b5 161
sam_grove 0:68a9bea384b5 162
sam_grove 0:68a9bea384b5 163