WncControllerK64F

Dependencies:   WncController

Fork of WncControllerK64F by Fred Kellerman

Committer:
fkellermavnet
Date:
Fri Sep 16 14:47:17 2016 +0000
Revision:
13:ef379cdd57aa
Parent:
0:98d149685c95
Child:
15:68d73d402cb0
term mode interface change.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fkellermavnet 0:98d149685c95 1 /*
fkellermavnet 0:98d149685c95 2 Copyright (c) 2016 Fred Kellerman
fkellermavnet 0:98d149685c95 3
fkellermavnet 0:98d149685c95 4 Permission is hereby granted, free of charge, to any person obtaining a copy
fkellermavnet 0:98d149685c95 5 of this software and associated documentation files (the "Software"), to deal
fkellermavnet 0:98d149685c95 6 in the Software without restriction, including without limitation the rights
fkellermavnet 0:98d149685c95 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
fkellermavnet 0:98d149685c95 8 copies of the Software, and to permit persons to whom the Software is
fkellermavnet 0:98d149685c95 9 furnished to do so, subject to the following conditions:
fkellermavnet 0:98d149685c95 10
fkellermavnet 0:98d149685c95 11 The above copyright notice and this permission notice shall be included in
fkellermavnet 0:98d149685c95 12 all copies or substantial portions of the Software.
fkellermavnet 0:98d149685c95 13
fkellermavnet 0:98d149685c95 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fkellermavnet 0:98d149685c95 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fkellermavnet 0:98d149685c95 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fkellermavnet 0:98d149685c95 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fkellermavnet 0:98d149685c95 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fkellermavnet 0:98d149685c95 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
fkellermavnet 0:98d149685c95 20 THE SOFTWARE.
fkellermavnet 0:98d149685c95 21
fkellermavnet 0:98d149685c95 22 @file WncController.cpp
fkellermavnet 0:98d149685c95 23 @purpose Controls WNC Cellular Modem
fkellermavnet 0:98d149685c95 24 @version 1.0
fkellermavnet 0:98d149685c95 25 @date July 2016
fkellermavnet 0:98d149685c95 26 @author Fred Kellerman
fkellermavnet 0:98d149685c95 27 */
fkellermavnet 0:98d149685c95 28
fkellermavnet 0:98d149685c95 29 #include "WncControllerK64F.h"
fkellermavnet 0:98d149685c95 30
fkellermavnet 0:98d149685c95 31 using namespace WncControllerK64F_fk;
fkellermavnet 0:98d149685c95 32
fkellermavnet 0:98d149685c95 33 WncControllerK64F::WncControllerK64F(struct WncGpioPinListK64F * pPins, MODSERIAL * wnc_uart, MODSERIAL * debug_uart)
fkellermavnet 0:98d149685c95 34 {
fkellermavnet 0:98d149685c95 35 m_logTimer.start(); // Start the log timer now!
fkellermavnet 0:98d149685c95 36 m_pDbgUart = debug_uart;
fkellermavnet 0:98d149685c95 37 m_pWncUart = wnc_uart;
fkellermavnet 0:98d149685c95 38 m_gpioPinList = *pPins;
fkellermavnet 0:98d149685c95 39 }
fkellermavnet 0:98d149685c95 40
fkellermavnet 13:ef379cdd57aa 41 bool WncControllerK64F::enterWncTerminalMode(MODSERIAL * pUart, bool echoOn)
fkellermavnet 0:98d149685c95 42 {
fkellermavnet 13:ef379cdd57aa 43 if (pUart == NULL)
fkellermavnet 13:ef379cdd57aa 44 return (false); // Need a uart!
fkellermavnet 13:ef379cdd57aa 45
fkellermavnet 0:98d149685c95 46 string * resp;
fkellermavnet 0:98d149685c95 47 AtCmdErr_e r = sendWncCmd("AT", &resp, 500);
fkellermavnet 0:98d149685c95 48 if (r == WNC_AT_CMD_TIMEOUT)
fkellermavnet 0:98d149685c95 49 return (false);
fkellermavnet 0:98d149685c95 50
fkellermavnet 13:ef379cdd57aa 51 pUart->puts("\r\nEntering WNC Terminal Mode - press <CTRL>-Q to exit!\r\n");
fkellermavnet 0:98d149685c95 52
fkellermavnet 0:98d149685c95 53 while (1) {
fkellermavnet 13:ef379cdd57aa 54 if (pUart->readable()) {
fkellermavnet 13:ef379cdd57aa 55 char c = pUart->getc();
fkellermavnet 0:98d149685c95 56 if (c == '\x11') {
fkellermavnet 13:ef379cdd57aa 57 pUart->puts("\r\nExiting WNC Terminal Mode!\r\n");
fkellermavnet 0:98d149685c95 58 // Cleanup in case user doesn't finish command:
fkellermavnet 0:98d149685c95 59 sendWncCmd("AT", &resp, 300);
fkellermavnet 0:98d149685c95 60 // Above AT may fail but should get WNC back in sync
fkellermavnet 0:98d149685c95 61 return (sendWncCmd("AT", &resp, 500) == WNC_AT_CMD_OK);
fkellermavnet 0:98d149685c95 62 }
fkellermavnet 0:98d149685c95 63 if (echoOn == true) {
fkellermavnet 13:ef379cdd57aa 64 pUart->putc(c);
fkellermavnet 0:98d149685c95 65 }
fkellermavnet 13:ef379cdd57aa 66 pUart->putc(c);
fkellermavnet 0:98d149685c95 67 }
fkellermavnet 13:ef379cdd57aa 68 if (pUart->readable())
fkellermavnet 13:ef379cdd57aa 69 pUart->putc(pUart->getc());
fkellermavnet 0:98d149685c95 70 }
fkellermavnet 0:98d149685c95 71 }
fkellermavnet 0:98d149685c95 72
fkellermavnet 0:98d149685c95 73
fkellermavnet 0:98d149685c95 74 int WncControllerK64F::putc(char c)
fkellermavnet 0:98d149685c95 75 {
fkellermavnet 0:98d149685c95 76 return (m_pWncUart->putc(c));
fkellermavnet 0:98d149685c95 77 }
fkellermavnet 0:98d149685c95 78
fkellermavnet 0:98d149685c95 79 int WncControllerK64F::puts(const char * s)
fkellermavnet 0:98d149685c95 80 {
fkellermavnet 0:98d149685c95 81 return (m_pWncUart->puts(s));
fkellermavnet 0:98d149685c95 82 }
fkellermavnet 0:98d149685c95 83
fkellermavnet 0:98d149685c95 84 char WncControllerK64F::getc(void)
fkellermavnet 0:98d149685c95 85 {
fkellermavnet 0:98d149685c95 86 return (m_pWncUart->getc());
fkellermavnet 0:98d149685c95 87 }
fkellermavnet 0:98d149685c95 88
fkellermavnet 0:98d149685c95 89 int WncControllerK64F::charReady(void)
fkellermavnet 0:98d149685c95 90 {
fkellermavnet 0:98d149685c95 91 return (m_pWncUart->readable());
fkellermavnet 0:98d149685c95 92 }
fkellermavnet 0:98d149685c95 93
fkellermavnet 0:98d149685c95 94 int WncControllerK64F::dbgWriteChar(char b)
fkellermavnet 0:98d149685c95 95 {
fkellermavnet 0:98d149685c95 96 if (m_pDbgUart != NULL)
fkellermavnet 0:98d149685c95 97 return (m_pDbgUart->putc(b));
fkellermavnet 0:98d149685c95 98 else
fkellermavnet 0:98d149685c95 99 return (0);
fkellermavnet 0:98d149685c95 100 }
fkellermavnet 0:98d149685c95 101
fkellermavnet 0:98d149685c95 102 int WncControllerK64F::dbgWriteChars(const char * b)
fkellermavnet 0:98d149685c95 103 {
fkellermavnet 0:98d149685c95 104 if (m_pDbgUart != NULL)
fkellermavnet 0:98d149685c95 105 return (m_pDbgUart->puts(b));
fkellermavnet 0:98d149685c95 106 else
fkellermavnet 0:98d149685c95 107 return (0);
fkellermavnet 0:98d149685c95 108 }
fkellermavnet 0:98d149685c95 109
fkellermavnet 0:98d149685c95 110 bool WncControllerK64F::initWncModem(uint8_t powerUpTimeoutSecs)
fkellermavnet 0:98d149685c95 111 {
fkellermavnet 0:98d149685c95 112 // Hard reset the modem (doesn't go through
fkellermavnet 0:98d149685c95 113 // the signal level translator)
fkellermavnet 0:98d149685c95 114 *m_gpioPinList.mdm_reset = 0;
fkellermavnet 0:98d149685c95 115
fkellermavnet 0:98d149685c95 116 // disable signal level translator (necessary
fkellermavnet 0:98d149685c95 117 // for the modem to boot properly). All signals
fkellermavnet 0:98d149685c95 118 // except mdm_reset go through the level translator
fkellermavnet 0:98d149685c95 119 // and have internal pull-up/down in the module. While
fkellermavnet 0:98d149685c95 120 // the level translator is disabled, these pins will
fkellermavnet 0:98d149685c95 121 // be in the correct state.
fkellermavnet 0:98d149685c95 122 *m_gpioPinList.shield_3v3_1v8_sig_trans_ena = 0;
fkellermavnet 0:98d149685c95 123
fkellermavnet 0:98d149685c95 124 // While the level translator is disabled and ouptut pins
fkellermavnet 0:98d149685c95 125 // are tristated, make sure the inputs are in the same state
fkellermavnet 0:98d149685c95 126 // as the WNC Module pins so that when the level translator is
fkellermavnet 0:98d149685c95 127 // enabled, there are no differences.
fkellermavnet 0:98d149685c95 128 *m_gpioPinList.mdm_uart2_rx_boot_mode_sel = 1; // UART2_RX should be high
fkellermavnet 0:98d149685c95 129 *m_gpioPinList.mdm_power_on = 0; // powr_on should be low
fkellermavnet 0:98d149685c95 130 *m_gpioPinList.mdm_wakeup_in = 1; // wake-up should be high
fkellermavnet 0:98d149685c95 131 *m_gpioPinList.mdm_uart1_cts = 0; // indicate that it is ok to send
fkellermavnet 0:98d149685c95 132
fkellermavnet 0:98d149685c95 133 // Now, wait for the WNC Module to perform its initial boot correctly
fkellermavnet 0:98d149685c95 134 waitMs(1000);
fkellermavnet 0:98d149685c95 135
fkellermavnet 0:98d149685c95 136 // The WNC module initializes comms at 115200 8N1 so set it up
fkellermavnet 0:98d149685c95 137 m_pWncUart->baud(115200);
fkellermavnet 0:98d149685c95 138
fkellermavnet 0:98d149685c95 139 //Now, enable the level translator, the input pins should now be the
fkellermavnet 0:98d149685c95 140 //same as how the M14A module is driving them with internal pull ups/downs.
fkellermavnet 0:98d149685c95 141 //When enabled, there will be no changes in these 4 pins...
fkellermavnet 0:98d149685c95 142 *m_gpioPinList.shield_3v3_1v8_sig_trans_ena = 1;
fkellermavnet 0:98d149685c95 143
fkellermavnet 0:98d149685c95 144 return (waitForPowerOnModemToRespond(powerUpTimeoutSecs));
fkellermavnet 0:98d149685c95 145 }
fkellermavnet 0:98d149685c95 146
fkellermavnet 0:98d149685c95 147 void WncControllerK64F::waitMs(int t)
fkellermavnet 0:98d149685c95 148 {
fkellermavnet 0:98d149685c95 149 wait_ms(t);
fkellermavnet 0:98d149685c95 150 }
fkellermavnet 0:98d149685c95 151
fkellermavnet 0:98d149685c95 152 void WncControllerK64F::waitUs(int t)
fkellermavnet 0:98d149685c95 153 {
fkellermavnet 0:98d149685c95 154 wait_ms(t);
fkellermavnet 0:98d149685c95 155 }
fkellermavnet 0:98d149685c95 156
fkellermavnet 0:98d149685c95 157 int WncControllerK64F::getLogTimerTicks(void)
fkellermavnet 0:98d149685c95 158 {
fkellermavnet 0:98d149685c95 159 return (m_logTimer.read_us());
fkellermavnet 0:98d149685c95 160 }
fkellermavnet 0:98d149685c95 161
fkellermavnet 0:98d149685c95 162 void WncControllerK64F::startTimerA(void)
fkellermavnet 0:98d149685c95 163 {
fkellermavnet 0:98d149685c95 164 m_timerA.start();
fkellermavnet 0:98d149685c95 165 m_timerA.reset();
fkellermavnet 0:98d149685c95 166 }
fkellermavnet 0:98d149685c95 167
fkellermavnet 0:98d149685c95 168 void WncControllerK64F::stopTimerA(void)
fkellermavnet 0:98d149685c95 169 {
fkellermavnet 0:98d149685c95 170 m_timerA.stop();
fkellermavnet 0:98d149685c95 171 }
fkellermavnet 0:98d149685c95 172
fkellermavnet 0:98d149685c95 173 int WncControllerK64F::getTimerTicksA_mS(void)
fkellermavnet 0:98d149685c95 174 {
fkellermavnet 0:98d149685c95 175 return (m_timerA.read_ms());
fkellermavnet 0:98d149685c95 176 }
fkellermavnet 0:98d149685c95 177
fkellermavnet 0:98d149685c95 178 void WncControllerK64F::startTimerB(void)
fkellermavnet 0:98d149685c95 179 {
fkellermavnet 0:98d149685c95 180 m_timerB.start();
fkellermavnet 0:98d149685c95 181 m_timerB.reset();
fkellermavnet 0:98d149685c95 182 }
fkellermavnet 0:98d149685c95 183
fkellermavnet 0:98d149685c95 184 void WncControllerK64F::stopTimerB(void)
fkellermavnet 0:98d149685c95 185 {
fkellermavnet 0:98d149685c95 186 m_timerB.stop();
fkellermavnet 0:98d149685c95 187 }
fkellermavnet 0:98d149685c95 188
fkellermavnet 0:98d149685c95 189 int WncControllerK64F::getTimerTicksB_mS(void)
fkellermavnet 0:98d149685c95 190 {
fkellermavnet 0:98d149685c95 191 return (m_timerB.read_ms());
fkellermavnet 0:98d149685c95 192 }