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:
Thu Nov 17 15:31:35 2016 +0000
Revision:
23:43a36c66c574
Parent:
22:9b9cb0d95f51
Child:
29:76e8acbafc80
Removed direct usage of debug UART for debug.  Added check for debug uart NULL pointer.

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 23:43a36c66c574 22 @file WncControllerK64F.cpp
fkellermavnet 23:43a36c66c574 23 @purpose Contains K64F and mbed specifics to control the WNC modem using the WncController base class.
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 int WncControllerK64F::putc(char c)
fkellermavnet 0:98d149685c95 74 {
fkellermavnet 0:98d149685c95 75 return (m_pWncUart->putc(c));
fkellermavnet 0:98d149685c95 76 }
fkellermavnet 0:98d149685c95 77
fkellermavnet 0:98d149685c95 78 int WncControllerK64F::puts(const char * s)
fkellermavnet 0:98d149685c95 79 {
fkellermavnet 0:98d149685c95 80 return (m_pWncUart->puts(s));
fkellermavnet 0:98d149685c95 81 }
fkellermavnet 0:98d149685c95 82
fkellermavnet 0:98d149685c95 83 char WncControllerK64F::getc(void)
fkellermavnet 0:98d149685c95 84 {
fkellermavnet 0:98d149685c95 85 return (m_pWncUart->getc());
fkellermavnet 0:98d149685c95 86 }
fkellermavnet 0:98d149685c95 87
fkellermavnet 0:98d149685c95 88 int WncControllerK64F::charReady(void)
fkellermavnet 0:98d149685c95 89 {
fkellermavnet 0:98d149685c95 90 return (m_pWncUart->readable());
fkellermavnet 0:98d149685c95 91 }
fkellermavnet 0:98d149685c95 92
fkellermavnet 0:98d149685c95 93 int WncControllerK64F::dbgWriteChar(char b)
fkellermavnet 0:98d149685c95 94 {
fkellermavnet 0:98d149685c95 95 if (m_pDbgUart != NULL)
fkellermavnet 0:98d149685c95 96 return (m_pDbgUart->putc(b));
fkellermavnet 0:98d149685c95 97 else
fkellermavnet 0:98d149685c95 98 return (0);
fkellermavnet 0:98d149685c95 99 }
fkellermavnet 0:98d149685c95 100
fkellermavnet 0:98d149685c95 101 int WncControllerK64F::dbgWriteChars(const char * b)
fkellermavnet 0:98d149685c95 102 {
fkellermavnet 0:98d149685c95 103 if (m_pDbgUart != NULL)
fkellermavnet 0:98d149685c95 104 return (m_pDbgUart->puts(b));
fkellermavnet 0:98d149685c95 105 else
fkellermavnet 0:98d149685c95 106 return (0);
fkellermavnet 0:98d149685c95 107 }
fkellermavnet 0:98d149685c95 108
fkellermavnet 0:98d149685c95 109 bool WncControllerK64F::initWncModem(uint8_t powerUpTimeoutSecs)
fkellermavnet 0:98d149685c95 110 {
fkellermavnet 0:98d149685c95 111 // Hard reset the modem (doesn't go through
fkellermavnet 0:98d149685c95 112 // the signal level translator)
fkellermavnet 0:98d149685c95 113 *m_gpioPinList.mdm_reset = 0;
fkellermavnet 0:98d149685c95 114
fkellermavnet 0:98d149685c95 115 // disable signal level translator (necessary
fkellermavnet 0:98d149685c95 116 // for the modem to boot properly). All signals
fkellermavnet 0:98d149685c95 117 // except mdm_reset go through the level translator
fkellermavnet 0:98d149685c95 118 // and have internal pull-up/down in the module. While
fkellermavnet 0:98d149685c95 119 // the level translator is disabled, these pins will
fkellermavnet 0:98d149685c95 120 // be in the correct state.
fkellermavnet 0:98d149685c95 121 *m_gpioPinList.shield_3v3_1v8_sig_trans_ena = 0;
fkellermavnet 0:98d149685c95 122
fkellermavnet 0:98d149685c95 123 // While the level translator is disabled and ouptut pins
fkellermavnet 0:98d149685c95 124 // are tristated, make sure the inputs are in the same state
fkellermavnet 0:98d149685c95 125 // as the WNC Module pins so that when the level translator is
fkellermavnet 0:98d149685c95 126 // enabled, there are no differences.
fkellermavnet 0:98d149685c95 127 *m_gpioPinList.mdm_uart2_rx_boot_mode_sel = 1; // UART2_RX should be high
fkellermavnet 0:98d149685c95 128 *m_gpioPinList.mdm_power_on = 0; // powr_on should be low
fkellermavnet 0:98d149685c95 129 *m_gpioPinList.mdm_wakeup_in = 1; // wake-up should be high
fkellermavnet 0:98d149685c95 130 *m_gpioPinList.mdm_uart1_cts = 0; // indicate that it is ok to send
fkellermavnet 0:98d149685c95 131
fkellermavnet 0:98d149685c95 132 // Now, wait for the WNC Module to perform its initial boot correctly
fkellermavnet 0:98d149685c95 133 waitMs(1000);
fkellermavnet 0:98d149685c95 134
fkellermavnet 0:98d149685c95 135 // The WNC module initializes comms at 115200 8N1 so set it up
fkellermavnet 0:98d149685c95 136 m_pWncUart->baud(115200);
fkellermavnet 0:98d149685c95 137
fkellermavnet 0:98d149685c95 138 //Now, enable the level translator, the input pins should now be the
fkellermavnet 0:98d149685c95 139 //same as how the M14A module is driving them with internal pull ups/downs.
fkellermavnet 0:98d149685c95 140 //When enabled, there will be no changes in these 4 pins...
fkellermavnet 0:98d149685c95 141 *m_gpioPinList.shield_3v3_1v8_sig_trans_ena = 1;
fkellermavnet 20:fcc6b61a5610 142
fkellermavnet 20:fcc6b61a5610 143 bool res = waitForPowerOnModemToRespond(powerUpTimeoutSecs);
fkellermavnet 20:fcc6b61a5610 144
fkellermavnet 20:fcc6b61a5610 145 // Toggle wakeup to prevent future dropped 'A' of "AT", this was
fkellermavnet 20:fcc6b61a5610 146 // suggested by ATT.
fkellermavnet 20:fcc6b61a5610 147 if (res == true) {
fkellermavnet 23:43a36c66c574 148 dbgPuts("\r\nToggling Wakeup...");
fkellermavnet 20:fcc6b61a5610 149 waitMs(20);
fkellermavnet 20:fcc6b61a5610 150 *m_gpioPinList.mdm_wakeup_in = 0;
fkellermavnet 20:fcc6b61a5610 151 waitMs(2000);
fkellermavnet 20:fcc6b61a5610 152 *m_gpioPinList.mdm_wakeup_in = 1;
fkellermavnet 20:fcc6b61a5610 153 waitMs(20);
fkellermavnet 23:43a36c66c574 154 dbgPuts("Toggling complete.");
fkellermavnet 20:fcc6b61a5610 155 }
fkellermavnet 0:98d149685c95 156
fkellermavnet 20:fcc6b61a5610 157 return (res);
fkellermavnet 0:98d149685c95 158 }
fkellermavnet 0:98d149685c95 159
fkellermavnet 0:98d149685c95 160 void WncControllerK64F::waitMs(int t)
fkellermavnet 0:98d149685c95 161 {
fkellermavnet 0:98d149685c95 162 wait_ms(t);
fkellermavnet 0:98d149685c95 163 }
fkellermavnet 0:98d149685c95 164
fkellermavnet 0:98d149685c95 165 void WncControllerK64F::waitUs(int t)
fkellermavnet 0:98d149685c95 166 {
fkellermavnet 0:98d149685c95 167 wait_ms(t);
fkellermavnet 0:98d149685c95 168 }
fkellermavnet 0:98d149685c95 169
fkellermavnet 0:98d149685c95 170 int WncControllerK64F::getLogTimerTicks(void)
fkellermavnet 0:98d149685c95 171 {
fkellermavnet 0:98d149685c95 172 return (m_logTimer.read_us());
fkellermavnet 0:98d149685c95 173 }
fkellermavnet 0:98d149685c95 174
fkellermavnet 0:98d149685c95 175 void WncControllerK64F::startTimerA(void)
fkellermavnet 0:98d149685c95 176 {
fkellermavnet 0:98d149685c95 177 m_timerA.start();
fkellermavnet 0:98d149685c95 178 m_timerA.reset();
fkellermavnet 0:98d149685c95 179 }
fkellermavnet 0:98d149685c95 180
fkellermavnet 0:98d149685c95 181 void WncControllerK64F::stopTimerA(void)
fkellermavnet 0:98d149685c95 182 {
fkellermavnet 0:98d149685c95 183 m_timerA.stop();
fkellermavnet 0:98d149685c95 184 }
fkellermavnet 0:98d149685c95 185
fkellermavnet 0:98d149685c95 186 int WncControllerK64F::getTimerTicksA_mS(void)
fkellermavnet 0:98d149685c95 187 {
fkellermavnet 0:98d149685c95 188 return (m_timerA.read_ms());
fkellermavnet 0:98d149685c95 189 }
fkellermavnet 0:98d149685c95 190
fkellermavnet 0:98d149685c95 191 void WncControllerK64F::startTimerB(void)
fkellermavnet 0:98d149685c95 192 {
fkellermavnet 0:98d149685c95 193 m_timerB.start();
fkellermavnet 0:98d149685c95 194 m_timerB.reset();
fkellermavnet 0:98d149685c95 195 }
fkellermavnet 0:98d149685c95 196
fkellermavnet 0:98d149685c95 197 void WncControllerK64F::stopTimerB(void)
fkellermavnet 0:98d149685c95 198 {
fkellermavnet 0:98d149685c95 199 m_timerB.stop();
fkellermavnet 0:98d149685c95 200 }
fkellermavnet 0:98d149685c95 201
fkellermavnet 0:98d149685c95 202 int WncControllerK64F::getTimerTicksB_mS(void)
fkellermavnet 0:98d149685c95 203 {
fkellermavnet 0:98d149685c95 204 return (m_timerB.read_ms());
fkellermavnet 0:98d149685c95 205 }