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