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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WncControllerK64F.cpp Source File

WncControllerK64F.cpp

00001 /*
00002     Copyright (c) 2016 Fred Kellerman
00003  
00004     Permission is hereby granted, free of charge, to any person obtaining a copy
00005     of this software and associated documentation files (the "Software"), to deal
00006     in the Software without restriction, including without limitation the rights
00007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008     copies of the Software, and to permit persons to whom the Software is
00009     furnished to do so, subject to the following conditions:
00010  
00011     The above copyright notice and this permission notice shall be included in
00012     all copies or substantial portions of the Software.
00013  
00014     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020     THE SOFTWARE.
00021     
00022     @file          WncControllerK64F.cpp
00023     @purpose       Contains K64F and mbed specifics to control the WNC modem using the WncController base class.
00024     @version       1.0
00025     @date          July 2016
00026     @author        Fred Kellerman
00027 */
00028 
00029 #include "WncControllerK64F.h"
00030 
00031 using namespace WncControllerK64F_fk;
00032 
00033 WncControllerK64F::WncControllerK64F(struct WncGpioPinListK64F * pPins, BufferedSerial * wnc_uart, WNCDebug * debug_uart)
00034 {
00035     m_logTimer.start(); // Start the log timer now!    
00036     m_pDbgUart = debug_uart;
00037     m_pWncUart = wnc_uart;
00038     m_gpioPinList = *pPins;
00039 }
00040 
00041 bool WncControllerK64F::enterWncTerminalMode(BufferedSerial * pUart, bool echoOn)
00042 {
00043     if (pUart == NULL)
00044         return (false);  // Need a uart!
00045         
00046     string * resp;
00047     AtCmdErr_e r = sendWncCmd("AT", &resp, 500);
00048     if (r == WNC_AT_CMD_TIMEOUT)
00049         return (false);
00050     
00051     pUart->puts("\r\nEntering WNC Terminal Mode - press <CTRL>-Q to exit!\r\n");
00052     
00053     while (1) {
00054         if (pUart->readable()) {
00055             char c = pUart->getc();
00056             if (c == '\x11') {
00057                 pUart->puts("\r\nExiting WNC Terminal Mode!\r\n");
00058                 // Cleanup in case user doesn't finish command:
00059                 sendWncCmd("AT", &resp, 300);
00060                 // Above AT may fail but should get WNC back in sync
00061                 return (sendWncCmd("AT", &resp, 500) == WNC_AT_CMD_OK);
00062             }
00063             if (echoOn == true) {
00064                 pUart->putc(c);
00065             }
00066             m_pWncUart->putc(c);
00067         }
00068         if (m_pWncUart->readable())
00069             pUart->putc(m_pWncUart->getc());
00070     }
00071 }
00072 
00073 int WncControllerK64F::putc(char c)
00074 {
00075     return (m_pWncUart->putc(c));
00076 }
00077 
00078 int WncControllerK64F::puts(const char * s)
00079 {
00080     return (m_pWncUart->puts(s));
00081 }
00082 
00083 char WncControllerK64F::getc(void)
00084 {
00085     return (m_pWncUart->getc());
00086 }
00087 
00088 int WncControllerK64F::charReady(void)
00089 {
00090     return (m_pWncUart->readable());
00091 }
00092 
00093 int WncControllerK64F::dbgWriteChar(char b)
00094 {
00095     if (m_pDbgUart != NULL)
00096         return (m_pDbgUart->putc(b));
00097     else
00098         return (0);
00099 }
00100 
00101 int WncControllerK64F::dbgWriteChars(const char * b)
00102 {
00103     if (m_pDbgUart != NULL)
00104         return (m_pDbgUart->puts(b));
00105     else
00106         return (0);
00107 }
00108 
00109 bool WncControllerK64F::initWncModem(uint8_t powerUpTimeoutSecs)
00110 {
00111     // Hard reset the modem (doesn't go through
00112     // the signal level translator)
00113     *m_gpioPinList.mdm_reset = 0;
00114 
00115     // disable signal level translator (necessary
00116     // for the modem to boot properly).  All signals
00117     // except mdm_reset go through the level translator
00118     // and have internal pull-up/down in the module. While
00119     // the level translator is disabled, these pins will
00120     // be in the correct state.
00121     *m_gpioPinList.shield_3v3_1v8_sig_trans_ena = 0;
00122 
00123     // While the level translator is disabled and ouptut pins
00124     // are tristated, make sure the inputs are in the same state
00125     // as the WNC Module pins so that when the level translator is
00126     // enabled, there are no differences.
00127     *m_gpioPinList.mdm_uart2_rx_boot_mode_sel = 1;   // UART2_RX should be high
00128     *m_gpioPinList.mdm_power_on = 0;                 // powr_on should be low
00129     *m_gpioPinList.mdm_wakeup_in = 1;                // wake-up should be high
00130     *m_gpioPinList.mdm_uart1_cts = 0;                // indicate that it is ok to send
00131 
00132     // Now, wait for the WNC Module to perform its initial boot correctly
00133     waitMs(1000);
00134 
00135     // The WNC module initializes comms at 115200 8N1 so set it up
00136     m_pWncUart->baud(115200);
00137 
00138     //Now, enable the level translator, the input pins should now be the
00139     //same as how the M14A module is driving them with internal pull ups/downs.
00140     //When enabled, there will be no changes in these 4 pins...
00141     *m_gpioPinList.shield_3v3_1v8_sig_trans_ena = 1;
00142     
00143     bool res = waitForPowerOnModemToRespond(powerUpTimeoutSecs);
00144     
00145     // Toggle wakeup to prevent future dropped 'A' of "AT", this was
00146     //  suggested by ATT.
00147     if (res == true) {
00148         dbgPuts("\r\nToggling Wakeup...");
00149         waitMs(20);
00150         *m_gpioPinList.mdm_wakeup_in = 0;
00151         waitMs(2000);
00152         *m_gpioPinList.mdm_wakeup_in = 1;
00153         waitMs(20);
00154         dbgPuts("Toggling complete.");
00155     }
00156 
00157     return (res);
00158 }
00159 
00160 void WncControllerK64F::waitMs(int t)
00161 {
00162     wait_ms(t);
00163 }
00164 
00165 void WncControllerK64F::waitUs(int t)
00166 {
00167     wait_us(t);
00168 }
00169 
00170 int  WncControllerK64F::getLogTimerTicks(void)
00171 {
00172     return (m_logTimer.read_us());
00173 }
00174 
00175 void WncControllerK64F::startTimerA(void)
00176 {
00177     m_timerA.start();
00178     m_timerA.reset();
00179 }
00180 
00181 void WncControllerK64F::stopTimerA(void)
00182 {
00183     m_timerA.stop();
00184 }
00185 
00186 int  WncControllerK64F::getTimerTicksA_mS(void)
00187 {
00188     return (m_timerA.read_ms());
00189 }
00190 
00191 void WncControllerK64F::startTimerB(void)
00192 {
00193     m_timerB.start();
00194     m_timerB.reset();
00195 }
00196 
00197 void WncControllerK64F::stopTimerB(void)
00198 {
00199     m_timerB.stop();
00200 }
00201 
00202 int  WncControllerK64F::getTimerTicksB_mS(void)
00203 {
00204     return (m_timerB.read_ms());
00205 }
00206