Library for controlling the WNC 14A2A from the K64F Freedom Board. It fulfills platform specific pure virtual methods from the WncControllerLibrary.

Dependencies:   WncControllerLibrary

Dependents:   WNC14A2AInterface

Fork of WncControllerK64F by Fred Kellerman

Use this interface to connect to and interact with the WNC M14A2A LTE Cellular Data Module which is provided by Wistron NeWeb Corporation (WNC) when using ARMmbed v5. The interface provides a Networking interface that can be used with the AT&T Cellular IoT Starter Kit that is sold by Avnet (http://cloudconnectkits.org/product/att-cellular-iot-starter-kit).

To demonstrate the use of the Interface, a series of example programs have been provided. Links to these examples are provided below. All examples can be compiled using both the on-line compiler and the ARMmbed CLI (command line interface, see https://github.com/ARMmbed/mbed-cli)

NOTE: This library/class is specific to the AT&T Cellular IoT Starter Kit which uses a FRDM-K64F. The users mbed.org compiler should be configured to use the FRDM-K64F platform.

Example Programs

Import the example programs below and follow the README.md in each to run the example program.

  • several examples of the interface using easy_connect.
  • SMS demonstration program that demonstrates SMS usage
  • Sockets demonstration program demonstrating using TCP sockets to interact with others
  • As new example program are developed, this README will be updated

WNC FIRWARE VERSION

The WNCInterface class currently supports the following version(s):

  • MPSS: M14A2A_v11.21.162331 APSS: M14A2A_v11.27.162331

License

This library is released under the Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License and may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Committer:
fkellermavnet
Date:
Wed Nov 16 18:18:56 2016 +0000
Revision:
22:9b9cb0d95f51
Parent:
20:fcc6b61a5610
Child:
23:43a36c66c574
Added check for NULL for debug uart for toggle of wake-pin.

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 15:68d73d402cb0 66 m_pWncUart->putc(c);
fkellermavnet 0:98d149685c95 67 }
fkellermavnet 15:68d73d402cb0 68 if (m_pWncUart->readable())
fkellermavnet 15:68d73d402cb0 69 pUart->putc(m_pWncUart->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 20:fcc6b61a5610 143
fkellermavnet 20:fcc6b61a5610 144 bool res = waitForPowerOnModemToRespond(powerUpTimeoutSecs);
fkellermavnet 20:fcc6b61a5610 145
fkellermavnet 20:fcc6b61a5610 146 // Toggle wakeup to prevent future dropped 'A' of "AT", this was
fkellermavnet 20:fcc6b61a5610 147 // suggested by ATT.
fkellermavnet 20:fcc6b61a5610 148 if (res == true) {
fkellermavnet 22:9b9cb0d95f51 149 if (m_pDbgUart != NULL)
fkellermavnet 22:9b9cb0d95f51 150 m_pDbgUart->puts("\r\nToggling Wakeup...\r\n");
fkellermavnet 20:fcc6b61a5610 151 waitMs(20);
fkellermavnet 20:fcc6b61a5610 152 *m_gpioPinList.mdm_wakeup_in = 0;
fkellermavnet 20:fcc6b61a5610 153 waitMs(2000);
fkellermavnet 20:fcc6b61a5610 154 *m_gpioPinList.mdm_wakeup_in = 1;
fkellermavnet 20:fcc6b61a5610 155 waitMs(20);
fkellermavnet 22:9b9cb0d95f51 156 if (m_pDbgUart != NULL)
fkellermavnet 22:9b9cb0d95f51 157 m_pDbgUart->puts("Toggling complete.\r\n");
fkellermavnet 20:fcc6b61a5610 158 }
fkellermavnet 0:98d149685c95 159
fkellermavnet 20:fcc6b61a5610 160 return (res);
fkellermavnet 0:98d149685c95 161 }
fkellermavnet 0:98d149685c95 162
fkellermavnet 0:98d149685c95 163 void WncControllerK64F::waitMs(int t)
fkellermavnet 0:98d149685c95 164 {
fkellermavnet 0:98d149685c95 165 wait_ms(t);
fkellermavnet 0:98d149685c95 166 }
fkellermavnet 0:98d149685c95 167
fkellermavnet 0:98d149685c95 168 void WncControllerK64F::waitUs(int t)
fkellermavnet 0:98d149685c95 169 {
fkellermavnet 0:98d149685c95 170 wait_ms(t);
fkellermavnet 0:98d149685c95 171 }
fkellermavnet 0:98d149685c95 172
fkellermavnet 0:98d149685c95 173 int WncControllerK64F::getLogTimerTicks(void)
fkellermavnet 0:98d149685c95 174 {
fkellermavnet 0:98d149685c95 175 return (m_logTimer.read_us());
fkellermavnet 0:98d149685c95 176 }
fkellermavnet 0:98d149685c95 177
fkellermavnet 0:98d149685c95 178 void WncControllerK64F::startTimerA(void)
fkellermavnet 0:98d149685c95 179 {
fkellermavnet 0:98d149685c95 180 m_timerA.start();
fkellermavnet 0:98d149685c95 181 m_timerA.reset();
fkellermavnet 0:98d149685c95 182 }
fkellermavnet 0:98d149685c95 183
fkellermavnet 0:98d149685c95 184 void WncControllerK64F::stopTimerA(void)
fkellermavnet 0:98d149685c95 185 {
fkellermavnet 0:98d149685c95 186 m_timerA.stop();
fkellermavnet 0:98d149685c95 187 }
fkellermavnet 0:98d149685c95 188
fkellermavnet 0:98d149685c95 189 int WncControllerK64F::getTimerTicksA_mS(void)
fkellermavnet 0:98d149685c95 190 {
fkellermavnet 0:98d149685c95 191 return (m_timerA.read_ms());
fkellermavnet 0:98d149685c95 192 }
fkellermavnet 0:98d149685c95 193
fkellermavnet 0:98d149685c95 194 void WncControllerK64F::startTimerB(void)
fkellermavnet 0:98d149685c95 195 {
fkellermavnet 0:98d149685c95 196 m_timerB.start();
fkellermavnet 0:98d149685c95 197 m_timerB.reset();
fkellermavnet 0:98d149685c95 198 }
fkellermavnet 0:98d149685c95 199
fkellermavnet 0:98d149685c95 200 void WncControllerK64F::stopTimerB(void)
fkellermavnet 0:98d149685c95 201 {
fkellermavnet 0:98d149685c95 202 m_timerB.stop();
fkellermavnet 0:98d149685c95 203 }
fkellermavnet 0:98d149685c95 204
fkellermavnet 0:98d149685c95 205 int WncControllerK64F::getTimerTicksB_mS(void)
fkellermavnet 0:98d149685c95 206 {
fkellermavnet 0:98d149685c95 207 return (m_timerB.read_ms());
fkellermavnet 0:98d149685c95 208 }